aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--composer/ChangeLog17
-rw-r--r--composer/e-msg-composer.c109
-rw-r--r--composer/e-msg-composer.h5
-rw-r--r--mail/ChangeLog8
-rw-r--r--mail/em-composer-prefs.c50
5 files changed, 132 insertions, 57 deletions
diff --git a/composer/ChangeLog b/composer/ChangeLog
index 185de38ec4..de52aea8b1 100644
--- a/composer/ChangeLog
+++ b/composer/ChangeLog
@@ -1,3 +1,20 @@
+2008-11-05 Matthew Barnes <mbarnes@redhat.com>
+
+ ** Fixes part of bug #559371
+
+ * e-msg-composer.c (e_load_spell_languages):
+ New function loads a list of GtkhtmlSpellLanguage structs from
+ GConf, taking care of details like converting language codes to
+ structs and ensuring the returned list is non-empty.
+
+ * e-msg-composer.c (e_save_spell_languages):
+ New function saves a list of GtkhtmlSpellLanguage structs to
+ GConf, taking care of details like converting the structs to
+ language codes.
+
+ * e-msg-composer.c (msg_composer_constructor):
+ Simplify the logic by using e_load_spell_languages().
+
2008-11-04 Matthew Barnes <mbarnes@redhat.com>
** Fixes bug #554450
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index 44e24e70e9..a7d19ac579 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -2086,10 +2086,9 @@ msg_composer_constructor (GType type,
GObject *object;
EMsgComposer *composer;
GtkToggleAction *action;
- GList *spell_languages = NULL;
+ GList *spell_languages;
GConfClient *client;
GArray *array;
- GSList *list;
gboolean active;
guint binding_id;
@@ -2156,21 +2155,7 @@ msg_composer_constructor (GType type,
client, COMPOSER_GCONF_REQUEST_RECEIPT_KEY, NULL);
gtk_toggle_action_set_active (action, active);
- list = gconf_client_get_list (
- client, COMPOSER_GCONF_SPELL_LANGUAGES_KEY,
- GCONF_VALUE_STRING, NULL);
- while (list != NULL) {
- gchar *language_code = list->data;
- const GtkhtmlSpellLanguage *language;
-
- language = gtkhtml_spell_language_lookup (language_code);
- if (language != NULL)
- spell_languages = g_list_prepend (
- spell_languages, (gpointer) language);
-
- list = g_slist_delete_link (list, list);
- g_free (language_code);
- }
+ spell_languages = e_load_spell_languages ();
gtkhtml_editor_set_spell_languages (
GTKHTML_EDITOR (composer), spell_languages);
g_list_free (spell_languages);
@@ -4786,3 +4771,93 @@ e_msg_composer_set_send_options (EMsgComposer *composer,
composer->priv->send_invoked = send_enable;
}
+
+GList *
+e_load_spell_languages (void)
+{
+ GConfClient *client;
+ GList *spell_languages = NULL;
+ GSList *list;
+ const gchar *key;
+ GError *error = NULL;
+
+ /* Ask GConf for a list of spell check language codes. */
+ client = gconf_client_get_default ();
+ key = COMPOSER_GCONF_SPELL_LANGUAGES_KEY;
+ list = gconf_client_get_list (client, key, GCONF_VALUE_STRING, &error);
+ g_object_unref (client);
+
+ /* Convert the codes to spell language structs. */
+ while (list != NULL) {
+ gchar *language_code = list->data;
+ const GtkhtmlSpellLanguage *language;
+
+ language = gtkhtml_spell_language_lookup (language_code);
+ if (language != NULL)
+ spell_languages = g_list_prepend (
+ spell_languages, (gpointer) language);
+
+ list = g_slist_delete_link (list, list);
+ g_free (language_code);
+ }
+
+ spell_languages = g_list_reverse (spell_languages);
+
+ /* Pick a default spell language if GConf came back empty. */
+ if (spell_languages == NULL) {
+ const GtkhtmlSpellLanguage *language;
+
+ language = gtkhtml_spell_language_lookup (NULL);
+
+ spell_languages = g_list_prepend (
+ spell_languages, (gpointer) language);
+
+ /* Don't overwrite the stored spell check language
+ * codes if there was a problem retrieving them. */
+ if (error == NULL)
+ e_save_spell_languages (spell_languages);
+ }
+
+ if (error != NULL) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
+
+ return spell_languages;
+}
+
+void
+e_save_spell_languages (GList *spell_languages)
+{
+ GConfClient *client;
+ GSList *list = NULL;
+ const gchar *key;
+ GError *error = NULL;
+
+ /* Build a list of spell check language codes. */
+ while (spell_languages != NULL) {
+ const GtkhtmlSpellLanguage *language;
+ const gchar *language_code;
+
+ language = spell_languages->data;
+ language_code = gtkhtml_spell_language_get_code (language);
+ list = g_slist_prepend (list, (gpointer) language_code);
+
+ spell_languages = g_list_next (spell_languages);
+ }
+
+ list = g_slist_reverse (list);
+
+ /* Save the language codes to GConf. */
+ client = gconf_client_get_default ();
+ key = COMPOSER_GCONF_SPELL_LANGUAGES_KEY;
+ gconf_client_set_list (client, key, GCONF_VALUE_STRING, list, &error);
+ g_object_unref (client);
+
+ g_slist_free (list);
+
+ if (error != NULL) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
+}
diff --git a/composer/e-msg-composer.h b/composer/e-msg-composer.h
index f0ef682999..f6b2ca7cc0 100644
--- a/composer/e-msg-composer.h
+++ b/composer/e-msg-composer.h
@@ -155,7 +155,10 @@ struct _EAttachmentBar *
e_msg_composer_get_attachment_bar
(EMsgComposer *composer);
-gboolean e_msg_composer_is_exiting (EMsgComposer *composer);
+gboolean e_msg_composer_is_exiting (EMsgComposer *composer);
+
+GList * e_load_spell_languages (void);
+void e_save_spell_languages (GList *spell_languages);
G_END_DECLS
diff --git a/mail/ChangeLog b/mail/ChangeLog
index b9caa225db..8b6af8fe12 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,11 @@
+2008-11-05 Matthew Barnes <mbarnes@redhat.com>
+
+ ** Fixes part of bug #559371
+
+ * em-composer-prefs.c (spell_language_save), (spell_setup):
+ Simplify the logic by using e_load_spell_languages() and
+ e_save_spell_languages().
+
2008-11-04 Milan Crha <mcrha@redhat.com>
** Fix for bug #386036
diff --git a/mail/em-composer-prefs.c b/mail/em-composer-prefs.c
index 75a6781759..5c5b491afb 100644
--- a/mail/em-composer-prefs.c
+++ b/mail/em-composer-prefs.c
@@ -584,46 +584,41 @@ spell_language_toggled_cb (GtkCellRendererToggle *renderer,
static void
spell_language_save (EMComposerPrefs *prefs)
{
- GSList *list = NULL;
- GConfClient *client;
+ GList *spell_languages = NULL;
GtkTreeModel *model;
GtkTreeIter iter;
- const gchar *key;
gboolean valid;
model = prefs->language_model;
- /* Build a list of active languages. */
+ /* Build a list of active spell languages. */
valid = gtk_tree_model_get_iter_first (model, &iter);
while (valid) {
const GtkhtmlSpellLanguage *language;
- const gchar *code;
gboolean active;
gtk_tree_model_get (
model, &iter, 0, &active, 2, &language, -1);
- code = gtkhtml_spell_language_get_code (language);
if (active)
- list = g_slist_prepend (list, (gpointer) code);
+ spell_languages = g_list_prepend (
+ spell_languages, (gpointer) language);
valid = gtk_tree_model_iter_next (model, &iter);
}
- list = g_slist_reverse (list);
+ spell_languages = g_list_reverse (spell_languages);
/* Update the GConf value. */
- client = mail_config_get_gconf_client ();
- key = "/apps/evolution/mail/composer/spell_languages";
- gconf_client_set_list (client, key, GCONF_VALUE_STRING, list, NULL);
+ e_save_spell_languages (spell_languages);
- g_slist_free (list);
+ g_list_free (spell_languages);
}
static void
spell_setup (EMComposerPrefs *prefs)
{
const GList *available_languages;
- GSList *active_languages, *iter;
+ GList *active_languages;
GConfClient *client;
GtkListStore *store;
GdkColor color;
@@ -634,27 +629,7 @@ spell_setup (EMComposerPrefs *prefs)
store = GTK_LIST_STORE (prefs->language_model);
available_languages = gtkhtml_spell_language_get_available ();
- /* Retrieve a list of language codes from GConf. */
- key = "/apps/evolution/mail/composer/spell_languages";
- active_languages = gconf_client_get_list (
- client, key, GCONF_VALUE_STRING, NULL);
-
- /* Convert the list to GtkhtmlSpellLanguages. */
- for (iter = active_languages; iter != NULL; iter = iter->next) {
- gchar *code = iter->data;
-
- iter->data = (gpointer) gtkhtml_spell_language_lookup (code);
- g_free (code);
- }
-
- /* Make sure we have _something_ active. */
- if (active_languages == NULL) {
- const GtkhtmlSpellLanguage *default_language;
-
- default_language = gtkhtml_spell_language_lookup (NULL);
- active_languages = g_slist_prepend (
- active_languages, (gpointer) default_language);
- }
+ active_languages = e_load_spell_languages ();
/* Populate the GtkListStore. */
while (available_languages != NULL) {
@@ -665,7 +640,7 @@ spell_setup (EMComposerPrefs *prefs)
language = available_languages->data;
name = gtkhtml_spell_language_get_name (language);
- active = (g_slist_find (active_languages, language) != NULL);
+ active = (g_list_find (active_languages, language) != NULL);
gtk_list_store_append (store, &tree_iter);
@@ -676,10 +651,7 @@ spell_setup (EMComposerPrefs *prefs)
available_languages = available_languages->next;
}
- /* Update the GConf list in case we used a default language. */
- spell_language_save (prefs);
-
- g_slist_free (active_languages);
+ g_list_free (active_languages);
key = "/apps/evolution/mail/composer/spell_color";
string = gconf_client_get_string (client, key, NULL);