Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=gfpm.git;a=commitdiff;h=58954c7f8d9246dafb54047b81fd4587ca9c70d3
commit 58954c7f8d9246dafb54047b81fd4587ca9c70d3 Author: Priyank <priy...@frugalware.org> Date: Sat May 30 17:07:26 2009 +0530 Convert error messages returned by pacman_strerror() to UTF-8 * Fixes problem of accents not being displayed correctly for some languages like fr_FR and hu_HU * Closes #2738 diff --git a/src/gfpm-interface.c b/src/gfpm-interface.c index 1d5e68d..50e5ebd 100644 --- a/src/gfpm-interface.c +++ b/src/gfpm-interface.c @@ -494,8 +494,11 @@ cb_gfpm_apply_btn_clicked (GtkButton *button, gpointer data) gfpm_progress_install) == -1) { gchar *str; - str = g_strdup_printf (_("Failed to init transaction (%s)\n"), pacman_strerror(pm_errno)); + gchar *p_error_utf8 = gfpm_convert_to_utf8 (pacman_strerror(pm_errno)); + str = g_strdup_printf (_("Failed to init transaction (%s)\n"), p_error_utf8); errorstr = g_string_append (errorstr, str); + if (p_error_utf8) + g_free (p_error_utf8); if (pm_errno == PM_ERR_HANDLE_LOCK) g_string_printf (errorstr, "%s", lck_error); if (gfpm_question (_("Error"), errorstr->str) == GTK_RESPONSE_YES) @@ -562,8 +565,11 @@ cb_gfpm_apply_btn_clicked (GtkButton *button, gpointer data) itry: if (pacman_trans_init(PM_TRANS_TYPE_SYNC, flags, gfpm_progress_event, cb_gfpm_trans_conv, gfpm_progress_install) == -1) { gchar *str; - str = g_strdup_printf (_("Failed to init transaction (%s)\n"), pacman_strerror(pm_errno)); + gchar *p_error_utf8 = gfpm_convert_to_utf8 (pacman_strerror(pm_errno)); + str = g_strdup_printf (_("Failed to init transaction (%s)\n"), p_error_utf8); errorstr = g_string_append (errorstr, str); + if (p_error_utf8) + g_free (p_error_utf8); if (pm_errno == PM_ERR_HANDLE_LOCK) g_string_printf (errorstr, "%s", lck_error); if (gfpm_question (_("Error"), errorstr->str) == GTK_RESPONSE_YES) @@ -1215,9 +1221,11 @@ gfpm_trans_prepare (PM_LIST *list) PM_LIST *i; GList *pkgs = NULL; gchar *str = NULL; - str = g_strdup_printf (_("Failed to prepare transaction (%s)\n"), pacman_strerror (pm_errno)); + gchar *p_error_utf8 = gfpm_convert_to_utf8 (pacman_strerror(pm_errno)); + str = g_strdup_printf (_("Failed to prepare transaction (%s)\n"), p_error_utf8); gfpm_error (_("Error"), str); g_free (str); + g_free (p_error_utf8); int t = (long)pacman_trans_getinfo (PM_TRANS_TYPE); switch ((long)pm_errno) { @@ -1230,9 +1238,9 @@ gfpm_trans_prepare (PM_LIST *list) if (t == PM_TRANS_TYPE_REMOVE) { val = g_strdup_printf ("%s : %s %s", - (char*)pacman_dep_getinfo (m, PM_DEP_TARGET), - _("is required by"), - (char*)pacman_dep_getinfo (m, PM_DEP_NAME)); + (char*)pacman_dep_getinfo (m, PM_DEP_TARGET), + _("is required by"), + (char*)pacman_dep_getinfo (m, PM_DEP_NAME)); depstring = g_string_append (depstring, val); } else @@ -1298,9 +1306,11 @@ gfpm_trans_commit (PM_LIST **list) PM_LIST *i; GList *pkgs = NULL; gchar *str = NULL; - str = g_strdup_printf (_("Failed to commit transaction (%s)\n"), pacman_strerror (pm_errno)); + gchar *p_error_utf8 = gfpm_convert_to_utf8 (pacman_strerror(pm_errno)); + str = g_strdup_printf (_("Failed to commit transaction (%s)\n"), p_error_utf8); gfpm_error (_("Error"), str); g_free (str); + g_free (p_error_utf8); switch ((long)pm_errno) { @@ -1411,17 +1421,21 @@ cb_gfpm_refresh_button_clicked (GtkButton *button, gpointer data) { gchar *str; GString *errorstr = g_string_new (""); - str = g_strdup_printf (_("Failed to init transaction (%s)\n"), pacman_strerror(pm_errno)); + gchar *p_error_utf8 = gfpm_convert_to_utf8 (pacman_strerror(pm_errno)); + str = g_strdup_printf (_("Failed to init transaction (%s)\n"), p_error_utf8); errorstr = g_string_append (errorstr, str); if (pm_errno == PM_ERR_HANDLE_LOCK) errorstr = g_string_append (errorstr, _("If you're sure a package manager is not already running, you can delete /tmp/pacman-g2.lck")); gfpm_error (_("Error"), errorstr->str); + g_free (p_error_utf8); return; } if (pacman_trans_sysupgrade()==-1) { - g_print ("error %s", pacman_strerror(pm_errno)); + gchar *p_error_utf8 = gfpm_convert_to_utf8 (pacman_strerror(pm_errno)); + g_print ("Error: %s\n", p_error_utf8); + g_free (p_error_utf8); } packages = pacman_trans_getinfo (PM_TRANS_PACKAGES); @@ -2089,9 +2103,11 @@ cb_gfpm_clear_cache_apply_clicked (GtkButton *button, gpointer data) gfpm_message ("Gfpm", _("Finished clearing the cache")); else { - errstr = g_strdup_printf (_("Failed to clean the cache (%s)"), pacman_strerror(pm_errno)); + gchar *p_error_utf8 = gfpm_convert_to_utf8 (pacman_strerror(pm_errno)); + errstr = g_strdup_printf (_("Failed to clean the cache (%s)"), p_error_utf8); gfpm_error (_("Error clearing cache"), errstr); g_free (errstr); + g_free (p_error_utf8); } } return; @@ -2107,9 +2123,11 @@ cb_gfpm_clear_cache_apply_clicked (GtkButton *button, gpointer data) gfpm_message ("Gfpm", _("Finished clearing the cache")); else { - errstr = g_strdup_printf (_("Failed to clean the cache (%s)"), pacman_strerror(pm_errno)); - gfpm_message (_("Error clearing cache"), errstr); + gchar *p_error_utf8 = gfpm_convert_to_utf8 (pacman_strerror(pm_errno)); + errstr = g_strdup_printf (_("Failed to clean the cache (%s)"), p_error_utf8); + gfpm_error (_("Error clearing cache"), errstr); g_free (errstr); + g_free (p_error_utf8); } } return; @@ -2145,12 +2163,14 @@ cb_gfpm_install_file_clicked (GtkButton *button, gpointer data) flags |= PM_TRANS_FLAG_FORCE; if (pacman_trans_init(type, flags, gfpm_progress_event, cb_gfpm_trans_conv, gfpm_progress_install) == -1) { - str = g_strdup_printf (_("Failed to init transaction (%s)\n"), pacman_strerror(pm_errno)); + gchar *p_error_utf8 = gfpm_convert_to_utf8 (pacman_strerror(pm_errno)); + str = g_strdup_printf (_("Failed to init transaction (%s)\n"), p_error_utf8); errorstr = g_string_append (errorstr, str); if (pm_errno == PM_ERR_HANDLE_LOCK) { errorstr = g_string_append (errorstr, _("If you're sure a package manager is not already running, you can delete /tmp/pacman-g2.lck")); gfpm_error (_("Error"), errorstr->str); + g_free (p_error_utf8); } return; } @@ -2164,9 +2184,11 @@ cb_gfpm_install_file_clicked (GtkButton *button, gpointer data) } if (pacman_trans_commit(&trans_data) == -1) { - str = g_strdup_printf (_("Failed to commit transaction (%s)\n"), pacman_strerror (pm_errno)); + gchar *p_error_utf8 = gfpm_convert_to_utf8 (pacman_strerror(pm_errno)); + str = g_strdup_printf (_("Failed to commit transaction (%s)\n"), p_error_utf8); gfpm_error (_("Error"), str); g_free (str); + g_free (p_error_utf8); goto cleanup; } else diff --git a/src/gfpm-util.c b/src/gfpm-util.c index 3cc4d25..3b7e9ca 100644 --- a/src/gfpm-util.c +++ b/src/gfpm-util.c @@ -100,3 +100,21 @@ gfpm_update_iconcache (void) return; } +gchar * +gfpm_convert_to_utf8 (const char *str) +{ + gchar *ret = NULL; + GError *error = NULL; + if (str) + { + ret = g_convert (str, strlen(str), "UTF-8", "", NULL, NULL, &error); + if (ret == NULL) + { + g_print ("Error converting string to utf-8: %s\n", error->message); + } + } + + return ret; +} + + diff --git a/src/gfpm-util.h b/src/gfpm-util.h index 444d232..d671256 100644 --- a/src/gfpm-util.h +++ b/src/gfpm-util.h @@ -22,4 +22,7 @@ gint gfpm_check_if_package_updatable (const gchar *); void gfpm_update_iconcache (void); +/* Converts a string to UTF-8. Returned string must be freed */ +gchar * gfpm_convert_to_utf8 (const char *str); + #endif _______________________________________________ Frugalware-git mailing list Frugalware-git@frugalware.org http://frugalware.org/mailman/listinfo/frugalware-git