aboutsummaryrefslogtreecommitdiffstats
path: root/composer
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2008-11-06 00:16:13 +0800
committerMatthew Barnes <mbarnes@src.gnome.org>2008-11-06 00:16:13 +0800
commit3849f9da5a83643e5ea4c78294d377c381df692a (patch)
tree61e7c66346604af9787b000687c643698088f57f /composer
parent7007a0191dfcfeb1769d76a2b3085be0bc4f10fb (diff)
downloadgsoc2013-evolution-3849f9da5a83643e5ea4c78294d377c381df692a.tar
gsoc2013-evolution-3849f9da5a83643e5ea4c78294d377c381df692a.tar.gz
gsoc2013-evolution-3849f9da5a83643e5ea4c78294d377c381df692a.tar.bz2
gsoc2013-evolution-3849f9da5a83643e5ea4c78294d377c381df692a.tar.lz
gsoc2013-evolution-3849f9da5a83643e5ea4c78294d377c381df692a.tar.xz
gsoc2013-evolution-3849f9da5a83643e5ea4c78294d377c381df692a.tar.zst
gsoc2013-evolution-3849f9da5a83643e5ea4c78294d377c381df692a.zip
** Fixes part of bug #559371
2008-11-05 Matthew Barnes <mbarnes@redhat.com> ** Fixes part of bug #559371 * composer/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. * composer/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. * composer/e-msg-composer.c (msg_composer_constructor): * mail/em-composer-prefs.c (spell_language_save), (spell_setup): Simplify the logic by using e_load_spell_languages() and e_save_spell_languages(). svn path=/trunk/; revision=36743
Diffstat (limited to 'composer')
-rw-r--r--composer/ChangeLog17
-rw-r--r--composer/e-msg-composer.c109
-rw-r--r--composer/e-msg-composer.h5
3 files changed, 113 insertions, 18 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