quick-lounge-applet r240 - in trunk: . src



Author: paobac
Date: Mon Feb  2 16:17:18 2009
New Revision: 240
URL: http://svn.gnome.org/viewvc/quick-lounge-applet?rev=240&view=rev

Log:
2009-02-02  Paolo Bacchilega  <paobac svn gnome org>

	* src/quick-box.c: 
	* src/qck-desktop-entry-dialog.c: 
	* src/file-utils.h: 
	* src/file-utils.c: 
	
	find a suitable locale when setting a locale string.


Modified:
   trunk/ChangeLog
   trunk/src/file-utils.c
   trunk/src/file-utils.h
   trunk/src/qck-desktop-entry-dialog.c
   trunk/src/quick-box.c

Modified: trunk/src/file-utils.c
==============================================================================
--- trunk/src/file-utils.c	(original)
+++ trunk/src/file-utils.c	Mon Feb  2 16:17:18 2009
@@ -609,15 +609,45 @@
 }
 
 
+char *
+_g_key_file_get_locale_string (GKeyFile    *file,
+			       const char  *group_name,
+                               const char  *key,
+                               const char **languages,
+                               GError     **error)
+{
+	char *value = NULL;
+	
+	for (i = 0; (value == NULL) && (languages[i] != NULL); i++) {
+		const char *locale;
+		
+		if (strcmp (languages[i], "C") == 0)
+			locale = NULL;
+		else
+			locale = languages[i];
+		
+		if (*error != NULL)
+			g_clear_error (error);		
+		
+		value = g_key_file_get_locale_string (file, group_name, key, locale, error);		
+	}
+	
+	return value;
+}
+
+
 gboolean
 _g_desktop_entry_equal (GKeyFile *file1,
 			GKeyFile *file2)
 {
+	char     **languages;
 	gboolean   terminal1;
 	char      *value1;
 	gboolean   terminal2;
 	char      *value2;
-		
+	
+	languages = (char **) g_get_language_names ();
+	
 	terminal1 = g_key_file_get_boolean (file1, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TERMINAL, NULL);
 	terminal2 = g_key_file_get_boolean (file2, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TERMINAL, NULL);	
 	if (terminal1 != terminal2) 
@@ -631,8 +661,8 @@
 		return FALSE;
 	}
 	
-	value1 = g_key_file_get_locale_string (file1, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, NULL, NULL);
-	value2 = g_key_file_get_locale_string (file2, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, NULL, NULL);
+	value1 = _g_key_file_get_locale_string (file1, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, languages, NULL);
+	value2 = _g_key_file_get_locale_string (file2, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, languages, NULL);
 	if (g_strcmp0 (value1, value2) != 0) {
 		g_free (value1);
 		g_free (value2);
@@ -647,8 +677,8 @@
 		return FALSE;
 	}
 	
-	value1 = g_key_file_get_locale_string (file1, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, NULL, NULL);
-	value2 = g_key_file_get_locale_string (file2, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, NULL, NULL);
+	value1 = _g_key_file_get_locale_string (file1, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, languages, NULL);
+	value2 = _g_key_file_get_locale_string (file2, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, languages, NULL);
 	if (g_strcmp0 (value1, value2) != 0) {
 		g_free (value1);
 		g_free (value2);

Modified: trunk/src/file-utils.h
==============================================================================
--- trunk/src/file-utils.h	(original)
+++ trunk/src/file-utils.h	Mon Feb  2 16:17:18 2009
@@ -66,6 +66,11 @@
 						   GCancellable      *cancellable,
 						   GError           **error);
 GKeyFile *          _g_key_file_dup               (GKeyFile          *file);
+char *              _g_key_file_get_locale_string (GKeyFile          *file,
+						   const char        *group_name,
+                                                   const char        *key,
+                                                   const char       **languages,
+                                                   GError            **error);
 gboolean            _g_desktop_entry_equal        (GKeyFile          *file1,
 						   GKeyFile          *file2);
 

Modified: trunk/src/qck-desktop-entry-dialog.c
==============================================================================
--- trunk/src/qck-desktop-entry-dialog.c	(original)
+++ trunk/src/qck-desktop-entry-dialog.c	Mon Feb  2 16:17:18 2009
@@ -360,15 +360,18 @@
 qck_desktop_entry_dialog_update (QckDesktopEntryDialog *self,
 				 GKeyFile              *entry)
 {
+	char     **languages;
 	gboolean   terminal;
 	char      *name;
 	char      *exec;
 	char      *comment;
 	
+	languages = (char **) g_get_language_names ();
+	
 	terminal = g_key_file_get_boolean (entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_TERMINAL, NULL);
-	name = g_key_file_get_locale_string (entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, NULL, NULL);
+	name = _g_key_file_get_locale_string (entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, languages, NULL);
 	exec = g_key_file_get_string (entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_EXEC, NULL);
-	comment = g_key_file_get_locale_string (entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, NULL, NULL);
+	comment = _g_key_file_get_locale_string (entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, languages, NULL);
 	
 	gtk_combo_box_set_active (GTK_COMBO_BOX (self->priv->type_combobox), terminal ? 1 : 0);
 	gtk_entry_set_text (GTK_ENTRY (GET_WIDGET ("name_entry")), name ? name : "");

Modified: trunk/src/quick-box.c
==============================================================================
--- trunk/src/quick-box.c	(original)
+++ trunk/src/quick-box.c	Mon Feb  2 16:17:18 2009
@@ -1167,17 +1167,20 @@
 static void
 display_popup_menu (QuickBox *quick_box)
 {
-	GtkWidget *popup_menu = NULL;
-	GtkWidget *item;
-	GList     *children = NULL, *scan;
-	gboolean   menu_empty = TRUE;
-
+	GtkWidget  *popup_menu = NULL;
+	GtkWidget  *item;
+	GList      *children = NULL, *scan;
+	gboolean    menu_empty = TRUE;
+	char      **languages;
+	
 	if (quick_box->priv->popup_menu != NULL) {
 		gtk_menu_shell_deactivate (GTK_MENU_SHELL (quick_box->priv->popup_menu));
 		quick_box->priv->popup_menu = NULL;
 		return;
 	}
 
+	languages = (char **) g_get_language_names ();
+
 	children = gtk_container_get_children (GTK_CONTAINER (quick_box));
 
 	for (scan = children; scan; scan = scan->next) {
@@ -1221,7 +1224,7 @@
 
 		/**/
 
-		name = g_key_file_get_locale_string (desktop_entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, NULL, NULL); 
+		name = _g_key_file_get_locale_string (desktop_entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, languages, NULL); 
 		item = gtk_image_menu_item_new_with_label (name);
 
 		icon = g_key_file_get_string (desktop_entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_ICON, NULL);
@@ -1232,7 +1235,7 @@
 
 		/**/
 
-		comment = g_key_file_get_locale_string (desktop_entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, NULL, NULL);
+		comment = _g_key_file_get_locale_string (desktop_entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, languages, NULL);
 		
 		if ((comment != NULL) && (strcmp (comment, "") != 0))
 			tip = g_strdup (comment);
@@ -1608,6 +1611,7 @@
 {
 	char       *filename;
 	GKeyFile   *desktop_entry;
+	char      **languages;
 	char       *name;
 	GtkWidget  *button;
 	char       *comment;
@@ -1625,9 +1629,11 @@
 
 	g_free (filename);
 	
+	languages = (char **) g_get_language_names ();
+	
 	icon_path = g_key_file_get_string (desktop_entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_ICON, NULL);
 	child_size = get_child_size (quick_box);
-	name = g_key_file_get_locale_string (desktop_entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, NULL, NULL);
+	name = _g_key_file_get_locale_string (desktop_entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, languages, NULL);
 	button = quick_button_new (icon_path, child_size, name, quick_box->priv->icon_theme);
 	
 	if (button == NULL) 
@@ -1657,7 +1663,7 @@
 
 	/* tip */
 
-	comment = g_key_file_get_locale_string (desktop_entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, NULL, NULL);
+	comment = _g_key_file_get_locale_string (desktop_entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, languages, NULL);
 	tip = g_strconcat (name,
 			   ((comment != NULL) && (*comment != 0)) ? "\n" : NULL,
 			   ((comment != NULL) && (*comment != 0)) ? comment: NULL,
@@ -1929,11 +1935,12 @@
 			QuickButton *quick_button,
 			GKeyFile    *desktop_entry)
 {
-	GKeyFile *new_desktop_entry;
-	char     *icon;
-	char     *name;
-	char     *comment;
-	char     *tip;
+	GKeyFile  *new_desktop_entry;
+	char      *icon;
+	char     **languages;
+	char      *name;
+	char      *comment;
+	char      *tip;
 
 	g_return_if_fail (QUICK_IS_BOX (quick_box));
 	g_return_if_fail (QUICK_IS_BUTTON (quick_button));
@@ -1948,10 +1955,12 @@
 	icon = g_key_file_get_string (new_desktop_entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_ICON, NULL);
 	quick_button_set_pixmap (quick_button, icon, get_child_size (quick_box));
 	
-	name = g_key_file_get_locale_string (new_desktop_entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, NULL, NULL);
+	languages = (char **) g_get_language_names ();
+	
+	name = _g_key_file_get_locale_string (new_desktop_entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_NAME, languages, NULL);
 	quick_button_set_text (quick_button, name);
 
-	comment = g_key_file_get_locale_string (new_desktop_entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, NULL, NULL);
+	comment = _g_key_file_get_locale_string (new_desktop_entry, G_KEY_FILE_DESKTOP_GROUP, G_KEY_FILE_DESKTOP_KEY_COMMENT, languages, NULL);
 	tip = g_strconcat (name, 
 			   ((comment != NULL) && (*comment != 0)) ? "\n" : NULL, 
 			   comment, 



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