gtranslator r3807 - in trunk: . src src/dialogs



Author: psanxiao
Date: Fri Oct  3 12:15:12 2008
New Revision: 3807
URL: http://svn.gnome.org/viewvc/gtranslator?rev=3807&view=rev

Log:
2008-10-03  Pablo Sanxiao  <psanxiao gmail com>

	* src/dialogs/header-dialog.c:
	Now comments tab in header dialog is editable
	* src/po.{ch}:
	Now if there are changes in the header, it's
	refreshed in Runtime.



Modified:
   trunk/ChangeLog
   trunk/src/dialogs/header-dialog.c
   trunk/src/po.c
   trunk/src/po.h

Modified: trunk/src/dialogs/header-dialog.c
==============================================================================
--- trunk/src/dialogs/header-dialog.c	(original)
+++ trunk/src/dialogs/header-dialog.c	Fri Oct  3 12:15:12 2008
@@ -92,6 +92,23 @@
 }
 
 static void
+prj_comment_changed (GtkTextBuffer *buffer,
+		     GtranslatorHeader *header)
+{
+        const gchar *text;
+	GtkTextIter start, end;
+	gchar *text_utf8;
+	
+	gtranslator_header_set_header_changed (header, TRUE);
+
+	gtk_text_buffer_get_bounds(buffer, &start, &end);
+	text = gtk_text_buffer_get_text(buffer, &start, &end, TRUE);	
+
+	if (text)
+	  gtranslator_header_set_comment(header, g_strdup(text));
+}
+
+static void
 prj_id_version_changed(GObject    *gobject,
 		    GParamSpec *arg1,
 		    GtranslatorHeader *header)
@@ -284,6 +301,8 @@
 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dlg->priv->take_my_options),
 				     gtranslator_prefs_manager_get_take_my_options());
 
+	gtk_text_view_set_editable (GTK_TEXT_VIEW (dlg->priv->prj_comment), TRUE);
+
 	gtk_widget_set_sensitive(dlg->priv->pot_date, FALSE);
 	gtk_widget_set_sensitive(dlg->priv->po_date, FALSE);
 	gtk_widget_set_sensitive(dlg->priv->charset, FALSE);
@@ -311,6 +330,7 @@
 	GtranslatorPo *po;
 	GtranslatorTab *tab;
 	GtranslatorHeader *header;
+	GtkTextBuffer *buffer;
 
 	tab = gtranslator_window_get_active_tab (window);
 	po = gtranslator_tab_get_po (tab);
@@ -352,6 +372,12 @@
 	
 	gtk_window_present (GTK_WINDOW (dlg));
 
+	buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (GTR_HEADER_DIALOG (dlg)->priv->prj_comment));
+
+	g_signal_connect(buffer, "changed",
+			 G_CALLBACK(prj_comment_changed),
+			 header);
+
 	/*
          * Connect signals to edit Project information on Header dialog
          */

Modified: trunk/src/po.c
==============================================================================
--- trunk/src/po.c	(original)
+++ trunk/src/po.c	Fri Oct  3 12:15:12 2008
@@ -428,6 +428,7 @@
 		gchar *space1, *space2, *space3;
 
 		comment = g_strdup(po_message_comments(message));
+		gtranslator_header_set_comment (priv->header, (const gchar *)comment);
 		
 		prj_id_version = po_header_field(msgstr, "Project-Id-Version");
 		rmbt = po_header_field(msgstr, "Report-Msgid-Bugs-To");
@@ -566,13 +567,11 @@
  * It saves the header's values into the msgstr
  **/
 void
-gtranslator_po_save_header_in_msg (GtranslatorPo *po)
+gtranslator_po_save_header_in_msg (GtranslatorPo *po, GtranslatorHeader *header)
 {
 	po_message_iterator_t iter;
 	po_message_t message;
 	
-	GtranslatorHeader *header;	
-
 	const char *msgstr,
 		   *header_comment;
 	const char *prev_translator;
@@ -603,10 +602,6 @@
 	take_my_options = gtranslator_prefs_manager_get_take_my_options ();
 
 	/*
-	 * Get header's fields
-	 */
-	header = gtranslator_po_get_header(po);
-	/*
          * Save the previous translator to update the header's comment
          */
 	prev_translator = gtranslator_header_get_prev_translator(header);
@@ -659,7 +654,7 @@
 	/*
          * Update the header's comment
          */
-	comments = po_message_comments (message);
+	comments = gtranslator_header_get_comment (header);
 	comments_lines = g_strsplit (comments, "\n", -1);
 	
 	/*
@@ -682,7 +677,6 @@
 	 */
 	if ((g_utf8_collate (prev_translator, aux) == 0) && 
 	    (g_utf8_collate (comments_translator_values[g_strv_length (comments_translator_values)-1], comp_year) != 0)) {
-	  
 	  if (g_str_has_suffix (comments_lines[j], ".")) {
 	    line_without_dot = g_strndup (comments_lines[j], g_utf8_strlen(comments_lines[j], -1) -1);  
 	    line = g_strconcat (line_without_dot, ", ", year, ".", NULL);
@@ -700,8 +694,7 @@
 	    new_comments = g_strconcat (new_comments, comments_lines[k], "\n", NULL);
 	    k++;
 	    }
-	  po_message_set_comments (message, new_comments);
-	  
+	  gtranslator_header_set_comment (header, (const gchar *)new_comments);
 	  g_free (line);
 	  g_free (new_comments);
 	}    
@@ -709,20 +702,26 @@
 	/*
 	 * Current translator is not in the comments.
 	 */
-	if (g_utf8_collate (prev_translator, aux) != 0) {
+	if ((g_utf8_collate (prev_translator, aux) != 0) || (prev_translator == NULL)) {
 	  
-	  header_comment = po_message_comments (message);
+	  header_comment = gtranslator_header_get_comment (header);
 	  aux2 = g_strconcat(header_comment, gtranslator_header_get_translator(header), " ", "<",
 			     gtranslator_header_get_tr_email(header), ">", ",", " ", year, ".", NULL);
 	  
-	  po_message_set_comments (message, aux2);
+	  gtranslator_header_set_comment (header, (const gchar *)aux2);
+	  gtranslator_header_set_prev_translator (header, aux);
 	  g_free (aux2);
 	}
 	g_free (aux);
 	
 	/*
          * Write the header's fields
-         */
+         */  
+	gtranslator_po_set_header (po, header);
+	
+	comments = gtranslator_header_get_comment (header);
+	po_message_set_comments (message, comments);
+
 	msgstr = po_header_set_field (msgstr, "Project-Id-Version",
 				      gtranslator_header_get_prj_id_version(header));
 	msgstr = po_header_set_field (msgstr, "PO-Revision-Date",
@@ -763,7 +762,8 @@
 	struct po_xerror_handler handler;
 	gchar *msg_error;
 	gchar *filename;
-	
+	GtranslatorHeader *header;
+
 	/*
 	 * Initialice the handler error.
 	 */
@@ -805,7 +805,8 @@
 	/*
 	 * Save header fields into msg
 	 */
-	gtranslator_po_save_header_in_msg (po);	
+	header = gtranslator_po_get_header (po);
+	gtranslator_po_save_header_in_msg (po, header);	
 	
 	if (!po_file_write (gtranslator_po_get_po_file (po),
 			    filename, &handler))
@@ -1156,6 +1157,13 @@
 	return po->priv->header;
 }
 
+void
+gtranslator_po_set_header(GtranslatorPo *po,
+			  GtranslatorHeader *header)
+{
+  po->priv->header = header;
+}
+
 /**
  * gtranslator_po_get_translated_count:
  * @po: a #GtranslatorPo

Modified: trunk/src/po.h
==============================================================================
--- trunk/src/po.h	(original)
+++ trunk/src/po.h	Fri Oct  3 12:15:12 2008
@@ -102,7 +102,8 @@
 							 GFile *filename,
 							 GError **error);
 
-void		gtranslator_po_save_header_in_msg	(GtranslatorPo *po);
+void		gtranslator_po_save_header_in_msg	(GtranslatorPo *po,
+							 GtranslatorHeader *header);
 
 void		gtranslator_po_save_file           	(GtranslatorPo *po,
 							GError **error);
@@ -148,6 +149,9 @@
 GtranslatorHeader  
 		*gtranslator_po_get_header		(GtranslatorPo *po);
 
+void             gtranslator_po_set_header              (GtranslatorPo *po, 
+							 GtranslatorHeader *header);
+
 gint             gtranslator_po_get_translated_count	(GtranslatorPo *po);
 
 gint             gtranslator_po_get_fuzzy_count		(GtranslatorPo *po);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]