[evolution-data-server/gnome-2-30] Bug 601535 - Categories not translated in menus
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/gnome-2-30] Bug 601535 - Categories not translated in menus
- Date: Sat, 19 Jun 2010 00:35:42 +0000 (UTC)
commit 1ba62f655446f87021aced6e9b009e752651b456
Author: Matthew Barnes <mbarnes redhat com>
Date: Fri Jun 18 20:17:53 2010 -0400
Bug 601535 - Categories not translated in menus
.../reference/camel/tmpl/camel-cipher-context.sgml | 2 +
docs/reference/camel/tmpl/camel-imap-store.sgml | 3 +
libedataserver/e-categories.c | 185 +++++++++++--------
3 files changed, 112 insertions(+), 78 deletions(-)
---
diff --git a/docs/reference/camel/tmpl/camel-cipher-context.sgml b/docs/reference/camel/tmpl/camel-cipher-context.sgml
index 8c8c25a..c953424 100644
--- a/docs/reference/camel/tmpl/camel-cipher-context.sgml
+++ b/docs/reference/camel/tmpl/camel-cipher-context.sgml
@@ -300,6 +300,8 @@ CamelCipherContext
@email:
@cert_data:
@gpointer cert_data:
+ gpointer cert_data:
+ gpointer cert_data:
@gpointer cert_data:
diff --git a/docs/reference/camel/tmpl/camel-imap-store.sgml b/docs/reference/camel/tmpl/camel-imap-store.sgml
index d70e22a..22e3b42 100644
--- a/docs/reference/camel/tmpl/camel-imap-store.sgml
+++ b/docs/reference/camel/tmpl/camel-imap-store.sgml
@@ -64,6 +64,9 @@ CamelImapStore
</para>
@CamelImapStore *store, struct _CamelImapMsg *m:
+ CamelImapStore *store, struct _CamelImapMsg *m:
+
+ CamelImapStore *store, struct _CamelImapMsg *m:
@CamelImapStore *store, struct _CamelImapMsg *m:
@size:
@Returns:
diff --git a/libedataserver/e-categories.c b/libedataserver/e-categories.c
index 771ca0a..a1b9245 100644
--- a/libedataserver/e-categories.c
+++ b/libedataserver/e-categories.c
@@ -17,13 +17,9 @@
* Boston, MA 02110-1301, USA.
*/
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
+#include <config.h>
#include <string.h>
#include <libxml/parser.h>
-#include <glib.h>
#include <glib/gi18n-lib.h>
#include <gconf/gconf-client.h>
#include "e-categories.h"
@@ -31,9 +27,10 @@
#include "libedataserver-private.h"
typedef struct {
- gchar *category;
+ gchar *display_name; /* localized category name */
+ gchar *clocale_name; /* only for default categories */
gchar *icon_file;
- gboolean searchable;
+ gboolean is_default;
} CategoryInfo;
typedef struct {
@@ -129,9 +126,11 @@ build_categories_filename (void)
static void
free_category_info (CategoryInfo *cat_info)
{
- g_free (cat_info->category);
+ g_free (cat_info->display_name);
+ g_free (cat_info->clocale_name);
g_free (cat_info->icon_file);
- g_free (cat_info);
+
+ g_slice_free (CategoryInfo, cat_info);
}
static gchar *
@@ -172,9 +171,12 @@ hash_to_xml_string (gpointer key, gpointer value, gpointer user_data)
GString *string = user_data;
gchar *category;
- g_string_append_len (string, "\t<category", 10);
+ g_string_append_len (string, " <category", 10);
- category = escape_string (cat_info->category);
+ if (cat_info->is_default)
+ category = escape_string (cat_info->clocale_name);
+ else
+ category = escape_string (cat_info->display_name);
g_string_append_printf (string, " a=\"%s\"", category);
g_free (category);
@@ -183,7 +185,7 @@ hash_to_xml_string (gpointer key, gpointer value, gpointer user_data)
string, " icon=\"%s\"", cat_info->icon_file);
g_string_append_printf (
- string, " searchable=\"%d\"", cat_info->searchable);
+ string, " default=\"%d\"", cat_info->is_default);
g_string_append_len (string, "/>\n", 3);
}
@@ -204,7 +206,7 @@ idle_saver_cb (gpointer user_data)
g_debug ("Saving categories to \"%s\"", filename);
- /* build the file contents */
+ /* Build the file contents. */
buffer = g_string_new ("<categories>\n");
g_hash_table_foreach (categories_table, hash_to_xml_string, buffer);
g_string_append_len (buffer, "</categories>\n", 14);
@@ -241,6 +243,47 @@ save_categories (void)
idle_id = g_idle_add (idle_saver_cb, NULL);
}
+static void
+categories_add_full (const gchar *category,
+ const gchar *icon_file,
+ gboolean is_default)
+{
+ CategoryInfo *cat_info;
+ gchar *collation_key;
+
+ cat_info = g_slice_new (CategoryInfo);
+ if (is_default) {
+ const gchar *display_name;
+ display_name = g_dgettext (GETTEXT_PACKAGE, category);
+ cat_info->display_name = g_strdup (display_name);
+ cat_info->clocale_name = g_strdup (category);
+ } else {
+ cat_info->display_name = g_strdup (category);
+ cat_info->clocale_name = NULL;
+ }
+ cat_info->icon_file = g_strdup (icon_file);
+ cat_info->is_default = is_default;
+
+ collation_key = g_utf8_collate_key (cat_info->display_name, -1);
+ g_hash_table_insert (categories_table, collation_key, cat_info);
+
+ changed = TRUE;
+ save_categories ();
+}
+
+static CategoryInfo *
+categories_lookup (const gchar *category)
+{
+ CategoryInfo *cat_info;
+ gchar *collation_key;
+
+ collation_key = g_utf8_collate_key (category, -1);
+ cat_info = g_hash_table_lookup (categories_table, collation_key);
+ g_free (collation_key);
+
+ return cat_info;
+}
+
static gint
parse_categories (const gchar *contents, gsize length)
{
@@ -262,38 +305,27 @@ parse_categories (const gchar *contents, gsize length)
}
for (node = node->xmlChildrenNode; node != NULL; node = node->next) {
- xmlChar *category, *icon, *searchable;
- #ifndef EDS_DISABLE_DEPRECATED
- xmlChar *color;
- #endif
+ xmlChar *category, *icon_file, *is_default;
category = xmlGetProp (node, (xmlChar *) "a");
- icon = xmlGetProp (node, (xmlChar *) "icon");
- #ifndef EDS_DISABLE_DEPRECATED
- color = xmlGetProp (node, (xmlChar *) "color");
- #endif
- searchable = xmlGetProp (node, (xmlChar *) "searchable");
+ icon_file = xmlGetProp (node, (xmlChar *) "icon");
+ is_default = xmlGetProp (node, (xmlChar *) "default");
+
+ /* Default categories used to be called "searchable". */
+ if (is_default == NULL)
+ is_default = xmlGetProp (
+ node, (xmlChar *) "searchable");
if (category != NULL) {
- e_categories_add (
- (gchar *) category,
- #ifndef EDS_DISABLE_DEPRECATED
- (gchar *) color,
- #else
- NULL,
- #endif
- (gchar *) icon,
- (searchable != NULL) &&
- strcmp ((gchar *) searchable, "0") != 0);
+ categories_add_full (
+ (gchar *) category, (gchar *) icon_file,
+ g_strcmp0 ((gchar *) is_default, "1") == 0);
n_added++;
}
xmlFree (category);
- xmlFree (icon);
- #ifndef EDS_DISABLE_DEPRECATED
- xmlFree (color);
- #endif
- xmlFree (searchable);
+ xmlFree (icon_file);
+ xmlFree (is_default);
}
xmlFreeDoc (doc);
@@ -343,8 +375,8 @@ migrate_old_icon_file (gpointer key, gpointer value, gpointer user_data)
return;
/* We can't be sure where the old icon files were stored, but
- * a good guess is (E_DATA_SERVER_IMAGESDIR "-2.x"). Convert
- * any such paths to just E_DATA_SERVER_IMAGESDIR. */
+ * a good guess is (E_DATA_SERVER_IMAGESDIR "-2.x"). Convert
+ * any such paths to just E_DATA_SERVER_IMAGESDIR. */
if (g_str_has_prefix (info->icon_file, E_DATA_SERVER_IMAGESDIR)) {
basename = g_path_get_basename (info->icon_file);
g_free (info->icon_file);
@@ -358,8 +390,8 @@ static gboolean
migrate_old_categories (void)
{
/* Try migrating old category settings from GConf to the new
- * category XML file. If successful, unset the old GConf key
- * so that this is a one-time-only operation. */
+ * category XML file. If successful, unset the old GConf key
+ * so that this is a one-time-only operation. */
const gchar *key = "/apps/evolution/general/category_master_list";
@@ -378,7 +410,7 @@ migrate_old_categories (void)
if (n_added == 0)
goto exit;
- /* default icon files are now in an unversioned directory */
+ /* Default icon files are now in an unversioned directory. */
g_hash_table_foreach (categories_table, migrate_old_icon_file, NULL);
gconf_client_unset (client, key, NULL);
@@ -394,17 +426,18 @@ static void
load_default_categories (void)
{
DefaultCategory *cat_info = default_categories;
- gchar *icon_file = NULL;
- /* Note: All default categories are searchable. */
while (cat_info->category != NULL) {
+ gchar *icon_file = NULL;
+
if (cat_info->icon_file != NULL)
- icon_file = g_build_filename (E_DATA_SERVER_IMAGESDIR, cat_info->icon_file, NULL);
- e_categories_add (
- _ (cat_info->category),
- NULL, icon_file, TRUE);
+ icon_file = g_build_filename (
+ E_DATA_SERVER_IMAGESDIR,
+ cat_info->icon_file, NULL);
+
+ categories_add_full (cat_info->category, icon_file, TRUE);
+
g_free (icon_file);
- icon_file = NULL;
cat_info++;
}
}
@@ -443,8 +476,11 @@ initialize_categories (void)
initialized = TRUE;
+ bindtextdomain (GETTEXT_PACKAGE, E_DATA_SERVER_LOCALEDIR);
+
categories_table = g_hash_table_new_full (
- g_str_hash, g_str_equal, g_free,
+ g_str_hash, g_str_equal,
+ (GDestroyNotify) g_free,
(GDestroyNotify) free_category_info);
listeners = g_object_new (e_changed_listener_get_type (), NULL);
@@ -470,14 +506,6 @@ initialize_categories (void)
save_categories ();
}
-static void
-add_hash_to_list (gpointer key, gpointer value, gpointer user_data)
-{
- GList **list = user_data;
-
- *list = g_list_prepend (*list, key);
-}
-
/**
* e_categories_get_list:
*
@@ -490,12 +518,19 @@ add_hash_to_list (gpointer key, gpointer value, gpointer user_data)
GList *
e_categories_get_list (void)
{
+ GHashTableIter iter;
GList *list = NULL;
+ gpointer key, value;
if (!initialized)
initialize_categories ();
- g_hash_table_foreach (categories_table, add_hash_to_list, &list);
+ g_hash_table_iter_init (&iter, categories_table);
+
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
+ CategoryInfo *cat_info = value;
+ list = g_list_prepend (list, cat_info->display_name);
+ }
return g_list_sort (list, (GCompareFunc) g_utf8_collate);
}
@@ -511,25 +546,17 @@ e_categories_get_list (void)
* configuration database.
*/
void
-e_categories_add (const gchar *category, const gchar *unused, const gchar *icon_file, gboolean searchable)
+e_categories_add (const gchar *category,
+ const gchar *unused,
+ const gchar *icon_file,
+ gboolean searchable)
{
- CategoryInfo *cat_info;
-
g_return_if_fail (category != NULL);
if (!initialized)
initialize_categories ();
- /* add the new category */
- cat_info = g_new0 (CategoryInfo, 1);
- cat_info->category = g_strdup (category);
- cat_info->icon_file = g_strdup (icon_file);
- cat_info->searchable = searchable;
-
- g_hash_table_insert (categories_table, g_strdup (category), cat_info);
-
- changed = TRUE;
- save_categories ();
+ categories_add_full (category, icon_file, FALSE);
}
/**
@@ -568,7 +595,7 @@ e_categories_exist (const gchar *category)
if (!initialized)
initialize_categories ();
- return (g_hash_table_lookup (categories_table, category) != NULL);
+ return (categories_lookup (category) != NULL);
}
#ifndef EDS_DISABLE_DEPRECATED
@@ -619,7 +646,7 @@ e_categories_get_icon_file_for (const gchar *category)
if (!initialized)
initialize_categories ();
- cat_info = g_hash_table_lookup (categories_table, category);
+ cat_info = categories_lookup (category);
if (cat_info == NULL)
return NULL;
@@ -634,7 +661,8 @@ e_categories_get_icon_file_for (const gchar *category)
* Sets the icon file associated with the given category.
*/
void
-e_categories_set_icon_file_for (const gchar *category, const gchar *icon_file)
+e_categories_set_icon_file_for (const gchar *category,
+ const gchar *icon_file)
{
CategoryInfo *cat_info;
@@ -643,11 +671,12 @@ e_categories_set_icon_file_for (const gchar *category, const gchar *icon_file)
if (!initialized)
initialize_categories ();
- cat_info = g_hash_table_lookup (categories_table, category);
+ cat_info = categories_lookup (category);
g_return_if_fail (cat_info != NULL);
g_free (cat_info->icon_file);
cat_info->icon_file = g_strdup (icon_file);
+
changed = TRUE;
save_categories ();
}
@@ -670,11 +699,11 @@ e_categories_is_searchable (const gchar *category)
if (!initialized)
initialize_categories ();
- cat_info = g_hash_table_lookup (categories_table, category);
+ cat_info = categories_lookup (category);
if (cat_info == NULL)
return FALSE;
- return cat_info->searchable;
+ return cat_info->is_default;
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]