* 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"
#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 {
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 *
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);
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);
}
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);
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)
{
}
for (node = node->xmlChildrenNode; node != NULL; node = node->next) {
- xmlChar *category, *icon, *searchable;
+ xmlChar *category, *icon_file, *is_default;
category = xmlGetProp (node, (xmlChar *) "a");
- icon = xmlGetProp (node, (xmlChar *) "icon");
- 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,
- NULL,
- (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);
- xmlFree (searchable);
+ xmlFree (icon_file);
+ xmlFree (is_default);
}
xmlFreeDoc (doc);
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);
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";
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);
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++;
}
}
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);
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:
*
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);
}
* 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);
}
/**
if (!initialized)
initialize_categories ();
- return (g_hash_table_lookup (categories_table, category) != NULL);
+ return (categories_lookup (category) != NULL);
}
/**
if (!initialized)
initialize_categories ();
- cat_info = g_hash_table_lookup (categories_table, category);
+ cat_info = categories_lookup (category);
if (cat_info == NULL)
return NULL;
* 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;
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 ();
}
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;
}
/**