pidgin: e647892e: Mark theme prefs as translatable, refact...

datallah at pidgin.im datallah at pidgin.im
Wed Sep 16 23:01:44 EDT 2009


-----------------------------------------------------------------
Revision: e647892e0121d2c49477b86f9deccb02fcafb7f9
Ancestor: 84b4f3d9c0a8e1306eb70e9db0003177e2782269
Author: datallah at pidgin.im
Date: 2009-09-17T02:56:23
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/e647892e0121d2c49477b86f9deccb02fcafb7f9

Modified files:
        pidgin/gtkprefs.c

ChangeLog: 

Mark theme prefs as translatable, refactor slightly for consistency and plug a small leak.

-------------- next part --------------
============================================================
--- pidgin/gtkprefs.c	3f643bf7a046e540c7ff35289b2a9e29d7f81208
+++ pidgin/gtkprefs.c	2252dbded59cd1a37749cf72fa072426ba45aad1
@@ -459,13 +459,24 @@ theme_refresh_theme_list(void)
 	return row_ref;
 }
 
+static gchar *
+get_theme_markup(const char *name, gboolean custom, const char *author,
+				 const char *description)
+{
+
+	return g_strdup_printf("<b>%s</b>%s%s%s%s\n<span foreground='dim grey'>%s</span>",
+						   name, custom ? " " : "", custom ? _("(Custom)") : "",
+						   author != NULL ? " - " : "", author != NULL ? author : "",
+						   description != NULL ? description : "");
+}
+
 /* Rebuild the markup for the sound theme selection for "(Custom)" themes */
 static void
 pref_sound_generate_markup(void)
 {
 	gboolean print_custom, customized;
-	const gchar *name, *author, *description, *current_theme;
-	gchar *markup;
+	const gchar *author, *description, *current_theme;
+	gchar *name, *markup;
 	PurpleSoundTheme *theme;
 	GtkTreeIter iter;
 
@@ -476,23 +487,24 @@ pref_sound_generate_markup(void)
 		do {
 			gtk_tree_model_get(GTK_TREE_MODEL(prefs_sound_themes), &iter, 2, &name, -1);
 
-			print_custom = customized && g_str_equal(current_theme, name);
+			print_custom = customized && name && g_str_equal(current_theme, name);
 
-			if (!name || *name == '\0')
-				markup = g_strdup_printf("<b>(Default)</b>%s%s - None\n<span foreground='dim grey'>The default Pidgin sound theme</span>",
-							 print_custom ? " " : "", print_custom ? "(Custom)" : "");
-			else {
+			if (!name || *name == '\0') {
+				g_free(name);
+				name = g_strdup(_("(Default)"));
+				author = _("None");
+				description = _("The default Pidgin sound theme");
+			} else {
 				theme = PURPLE_SOUND_THEME(purple_theme_manager_find_theme(name, "sound"));
 				author = purple_theme_get_author(PURPLE_THEME(theme));
 				description = purple_theme_get_description(PURPLE_THEME(theme));
-
-				markup = g_strdup_printf("<b>%s</b>%s%s%s%s\n<span foreground='dim grey'>%s</span>",
-							 name, print_custom ? " " : "", print_custom ? "(Custom)" : "",
-							 author != NULL ? " - " : "", author != NULL ? author : "", description != NULL ? description : "");
 			}
 
+			markup = get_theme_markup(name, print_custom, author, description);
+
 			gtk_list_store_set(prefs_sound_themes, &iter, 1, markup, -1);
 
+			g_free(name);
 			g_free(markup);
 
 		} while (gtk_tree_model_iter_next(GTK_TREE_MODEL(prefs_sound_themes), &iter));
@@ -514,7 +526,8 @@ prefs_themes_sort(PurpleTheme *theme)
 		if (image_full != NULL){
 			pixbuf = gdk_pixbuf_new_from_file_at_scale(image_full, PREFS_OPTIMAL_ICON_SIZE, PREFS_OPTIMAL_ICON_SIZE, TRUE, NULL);
 			g_free(image_full);
-		} else pixbuf = NULL;
+		} else
+			pixbuf = NULL;
 
 		gtk_list_store_append(prefs_sound_themes, &iter);
 		gtk_list_store_set(prefs_sound_themes, &iter, 0, pixbuf, 2, purple_theme_get_name(theme), -1);
@@ -527,20 +540,21 @@ prefs_themes_sort(PurpleTheme *theme)
 
 		if (PIDGIN_IS_BLIST_THEME(theme))
 			store = prefs_blist_themes;
-		else store = prefs_status_icon_themes;
+		else
+			store = prefs_status_icon_themes;
 
 		image_full = purple_theme_get_image_full(theme);
 		if (image_full != NULL){
 			pixbuf = gdk_pixbuf_new_from_file_at_scale(image_full, PREFS_OPTIMAL_ICON_SIZE, PREFS_OPTIMAL_ICON_SIZE, TRUE, NULL);
 			g_free(image_full);
-		} else pixbuf = NULL;
+		} else
+			pixbuf = NULL;
 
 		name = purple_theme_get_name(theme);
 		author = purple_theme_get_author(theme);
 		description = purple_theme_get_description(theme);
 
-		markup = g_strdup_printf("<b>%s</b>%s%s\n<span foreground='dim grey'>%s</span>", name, author != NULL ? " - " : "",
-					 author != NULL ? author : "", description != NULL ? description : "");
+		markup = get_theme_markup(name, FALSE, author, description);
 
 		gtk_list_store_append(store, &iter);
 		gtk_list_store_set(store, &iter, 0, pixbuf, 1, markup, 2, name, -1);
@@ -579,16 +593,16 @@ prefs_themes_refresh(void)
 prefs_themes_refresh(void)
 {
 	GdkPixbuf *pixbuf = NULL;
-	gchar *filename;
+	gchar *tmp;
 	GtkTreeIter iter;
 
 	prefs_sound_themes_loading = TRUE;
 	/* refresh the list of themes in the manager */
 	purple_theme_manager_refresh();
 
-	filename = g_build_filename(DATADIR, "icons", "hicolor", "32x32", "apps", "pidgin.png", NULL);
-	pixbuf = gdk_pixbuf_new_from_file_at_scale(filename, PREFS_OPTIMAL_ICON_SIZE, PREFS_OPTIMAL_ICON_SIZE, TRUE, NULL);
-	g_free(filename);
+	tmp = g_build_filename(DATADIR, "icons", "hicolor", "32x32", "apps", "pidgin.png", NULL);
+	pixbuf = gdk_pixbuf_new_from_file_at_scale(tmp, PREFS_OPTIMAL_ICON_SIZE, PREFS_OPTIMAL_ICON_SIZE, TRUE, NULL);
+	g_free(tmp);
 
 	/* sound themes */
 	gtk_list_store_clear(prefs_sound_themes);
@@ -598,16 +612,18 @@ prefs_themes_refresh(void)
 	/* blist themes */
 	gtk_list_store_clear(prefs_blist_themes);
 	gtk_list_store_append(prefs_blist_themes, &iter);
-	gtk_list_store_set(prefs_blist_themes, &iter, 0, pixbuf, 1,
-	                   "<b>(Default)</b> - None\n<span color='dim grey'>"
-	                   "The default Pidgin buddy list theme</span>", 2, "", -1);
+	tmp = get_theme_markup(_("(Default)"), FALSE, _("None"),
+		_("The default Pidgin buddy list theme"));
+	gtk_list_store_set(prefs_blist_themes, &iter, 0, pixbuf, 1, tmp, 2, "", -1);
+	g_free(tmp);
 
 	/* status icon themes */
 	gtk_list_store_clear(prefs_status_icon_themes);
 	gtk_list_store_append(prefs_status_icon_themes, &iter);
-	gtk_list_store_set(prefs_status_icon_themes, &iter, 0, pixbuf, 1,
-	                   "<b>(Default)</b> - None\n<span color='dim grey'>"
-	                   "The default Pidgin status icon theme</span>", 2, "", -1);
+	tmp = get_theme_markup(_("(Default)"), FALSE, _("None"),
+		_("The default Pidgin status icon theme"));
+	gtk_list_store_set(prefs_status_icon_themes, &iter, 0, pixbuf, 1, tmp, 2, "", -1);
+	g_free(tmp);
 	g_object_unref(G_OBJECT(pixbuf));
 
 	purple_theme_manager_for_each_theme(prefs_themes_sort);
@@ -714,7 +730,8 @@ theme_install_theme(char *path, struct t
 
 	if ((is_smiley_theme = g_str_equal(type, "smiley")))
 		destdir = g_build_filename(purple_user_dir(), "smileys", NULL);
-	else destdir = g_build_filename(purple_user_dir(), "themes", "temp", NULL);
+	else
+		destdir = g_build_filename(purple_user_dir(), "themes", "temp", NULL);
 
 	/* We'll check this just to make sure. This also lets us do something different on
 	 * other platforms, if need be */
@@ -741,6 +758,7 @@ theme_install_theme(char *path, struct t
 		}
 #else
 		if(!winpidgin_gz_untar(path, destdir)) {
+			purple_notify_error(NULL, NULL, _("Theme failed to unpack."), NULL);
 			g_free(destdir);
 			g_free(type);
 			g_free(original_name);
@@ -980,7 +998,7 @@ prefs_set_sound_theme_cb(GtkComboBox *co
 		purple_prefs_set_string(PIDGIN_PREFS_ROOT "/sound/theme", new_theme);
 
 		/* New theme removes all customization */
-		for(i=0; i <  PURPLE_NUM_SOUNDS; i++){
+		for(i = 0; i < PURPLE_NUM_SOUNDS; i++){
 			pref = g_strdup_printf(PIDGIN_PREFS_ROOT "/sound/file/%s",
 						pidgin_sound_get_event_option(i));
 			purple_prefs_set_path(pref, "");


More information about the Commits mailing list