diff options
author | Stefano Karapetsas <[email protected]> | 2013-01-25 13:41:13 -0800 |
---|---|---|
committer | Stefano Karapetsas <[email protected]> | 2013-01-25 13:41:13 -0800 |
commit | bbf4c3447a09a5e4be8307e3df3b3405781bead2 (patch) | |
tree | bc924a2c5961e629a55bd046765bc7c45e2b5ad0 /mate-dictionary | |
parent | 3f783bbd74e1f94e97f91829480b32b05b6480c8 (diff) | |
parent | cc8a689bdeb46b3c9fe8247a72b05c8d97762474 (diff) | |
download | mate-utils-bbf4c3447a09a5e4be8307e3df3b3405781bead2.tar.bz2 mate-utils-bbf4c3447a09a5e4be8307e3df3b3405781bead2.tar.xz |
Merge pull request #18 from bhull2010/master
Port mate-dictionary to Gsettings
Diffstat (limited to 'mate-dictionary')
-rw-r--r-- | mate-dictionary/data/Makefile.am | 39 | ||||
-rw-r--r-- | mate-dictionary/data/mate-dictionary-preferences.ui | 11 | ||||
-rw-r--r-- | mate-dictionary/data/mate-dictionary.1 | 2 | ||||
-rw-r--r-- | mate-dictionary/data/mate-dictionary.convert | 5 | ||||
-rw-r--r-- | mate-dictionary/data/mate-dictionary.schemas.in | 201 | ||||
-rw-r--r-- | mate-dictionary/data/org.mate.dictionary.gschema.xml.in | 25 | ||||
-rw-r--r-- | mate-dictionary/libgdict/gdict-source.c | 6 | ||||
-rw-r--r-- | mate-dictionary/src/Makefile.am | 20 | ||||
-rw-r--r-- | mate-dictionary/src/gdict-app.c | 18 | ||||
-rw-r--r-- | mate-dictionary/src/gdict-app.h | 4 | ||||
-rw-r--r-- | mate-dictionary/src/gdict-applet.c | 164 | ||||
-rw-r--r-- | mate-dictionary/src/gdict-common.c | 12 | ||||
-rw-r--r-- | mate-dictionary/src/gdict-common.h | 6 | ||||
-rw-r--r-- | mate-dictionary/src/gdict-pref-dialog.c | 154 | ||||
-rw-r--r-- | mate-dictionary/src/gdict-pref-dialog.h | 22 | ||||
-rw-r--r-- | mate-dictionary/src/gdict-print.c | 24 | ||||
-rw-r--r-- | mate-dictionary/src/gdict-source-dialog.c | 13 | ||||
-rw-r--r-- | mate-dictionary/src/gdict-window.c | 786 | ||||
-rw-r--r-- | mate-dictionary/src/gdict-window.h | 16 |
19 files changed, 628 insertions, 900 deletions
diff --git a/mate-dictionary/data/Makefile.am b/mate-dictionary/data/Makefile.am index 2e38a96c..55f553df 100644 --- a/mate-dictionary/data/Makefile.am +++ b/mate-dictionary/data/Makefile.am @@ -7,7 +7,7 @@ gdictapp_in_files = mate-dictionary.desktop.in gdictapp_DATA = $(gdictapp_in_files:.desktop.in=.desktop) $(gdictapp_in_files): $(gdictapp_in_files:.desktop.in=.desktop.in.in) - @sed -e "s|\@VERSION\@|@VERSION@|" $< > $@ + $(AM_V_GEN)sed -e "s|\@VERSION\@|@VERSION@|" $< > $@ @INTLTOOL_DESKTOP_RULE@ @@ -22,8 +22,10 @@ dictsource_DATA = $(dictsource_in_files:.desktop.in=.desktop) @INTLTOOL_DESKTOP_RULE@ builderdir = $(datadir)/mate-dictionary -builder_DATA = mate-dictionary-preferences.ui \ - mate-dictionary-source.ui +builder_DATA = \ + mate-dictionary-preferences.ui \ + mate-dictionary-source.ui \ + $(NULL) uidir = $(datadir)/mate-dictionary ui_DATA = mate-dictionary-ui.xml @@ -39,27 +41,29 @@ server_in_files = MATE_DictionaryApplet.server.in server_DATA = $(server_in_files:.server.in=.server) $(server_in_files): $(server_in_files:.server.in=.server.in.in) - @sed \ - -e "s|\@VERSION\@|@VERSION@|" \ - -e "s|\@LIBEXECDIR\@|$(libexecdir)|" \ + $(AM_V_GEN)sed \ + -e "s|\@VERSION\@|@VERSION@|" \ + -e "s|\@LIBEXECDIR\@|$(libexecdir)|" \ $< > $@ - @INTLTOOL_SERVER_RULE@ endif # BUILD_GDICT_APPLET -schemadir = $(MATECONF_SCHEMA_FILE_DIR) -schemas_in_file = mate-dictionary.schemas.in -schema_DATA = $(schemas_in_file:.schemas.in=.schemas) -@INTLTOOL_SCHEMAS_RULE@ +gsettingsschema_in_files = org.mate.dictionary.gschema.xml.in +gsettings_SCHEMAS = $(gsettingsschema_in_files:.xml.in=.xml) +@INTLTOOL_XML_NOMERGE_RULE@ +@GSETTINGS_RULES@ + +convertdir = $(datadir)/MateConf/gsettings +convert_DATA = mate-dictionary.convert EXTRA_DIST = \ MATE_DictionaryApplet.server.in.in \ mate-dictionary.desktop.in.in \ $(dictsource_in_files) \ $(man_MANS) \ - $(schemas_in_file) \ + $(gsettingsschema_in_files) \ $(builder_DATA) \ $(ui_DATA) \ $(appletui_DATA) \ @@ -71,14 +75,5 @@ CLEANFILES = \ $(server_DATA) \ $(gdictapp_in_files) \ $(gdictapp_DATA) \ - $(schema_DATA) \ + $(gsettings_SCHEMAS) \ $(NULL) - -if MATECONF_SCHEMAS_INSTALL -install-data-local: - if test -z "$(DESTDIR)" ; then \ - MATECONF_CONFIG_SOURCE=$(MATECONF_SCHEMA_CONFIG_SOURCE) $(MATECONFTOOL) --makefile-install-rule $(schema_DATA) ; \ - fi -else -install-data-local: -endif diff --git a/mate-dictionary/data/mate-dictionary-preferences.ui b/mate-dictionary/data/mate-dictionary-preferences.ui index 1f04df8f..d7fa1db1 100644 --- a/mate-dictionary/data/mate-dictionary-preferences.ui +++ b/mate-dictionary/data/mate-dictionary-preferences.ui @@ -102,6 +102,17 @@ <property name="focus_on_click">True</property> </object> </child> + <child> + <object class="GtkButton" id="edit_button"> + <property name="visible">True</property> + <property name="can_default">True</property> + <property name="can_focus">True</property> + <property name="label">gtk-edit</property> + <property name="use_stock">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="focus_on_click">True</property> + </object> + </child> </object> <packing> <property name="padding">0</property> diff --git a/mate-dictionary/data/mate-dictionary.1 b/mate-dictionary/data/mate-dictionary.1 index ceabc30a..59b7d969 100644 --- a/mate-dictionary/data/mate-dictionary.1 +++ b/mate-dictionary/data/mate-dictionary.1 @@ -43,7 +43,7 @@ on the console without launching the GUI. .B \-\-help Display help information. .SH CONFIGURATION -All the configuration is handled using MateConf. +All the configuration is handled using Gsettings. .SH AUTHOR .B MATE Dictionary was originally written by Spiros Papadimitriou (<[email protected]>), Mike diff --git a/mate-dictionary/data/mate-dictionary.convert b/mate-dictionary/data/mate-dictionary.convert new file mode 100644 index 00000000..01b919a0 --- /dev/null +++ b/mate-dictionary/data/mate-dictionary.convert @@ -0,0 +1,5 @@ +[org.mate.dictionary] +database = /apps/mate-dictionary/database +strategy = /apps/mate-dictionary/strategy +print-font = /apps/mate-dictionary/print-font +source-name = /apps/mate-dictionary/source-name diff --git a/mate-dictionary/data/mate-dictionary.schemas.in b/mate-dictionary/data/mate-dictionary.schemas.in deleted file mode 100644 index 0d204ecd..00000000 --- a/mate-dictionary/data/mate-dictionary.schemas.in +++ /dev/null @@ -1,201 +0,0 @@ -<mateconfschemafile> - <schemalist> - <schema> - <key>/schemas/apps/mate-dictionary/server</key> - <applyto>/apps/mate-dictionary/server</applyto> - <owner>mate-dictionary</owner> - <type>string</type> - <default>dict.org</default> - <locale name="C"> - <short>Dictionary server (Deprecated)</short> - <long>The dictionary server to connect to. The default server is - dict.org. See http://www.dict.org for details on other servers. - This key is deprecated and no longer in use.</long> - </locale> - </schema> - - <schema> - <key>/schemas/apps/mate-dictionary/port</key> - <applyto>/apps/mate-dictionary/port</applyto> - <owner>mate-dictionary</owner> - <type>int</type> - <default>2628</default> - <locale name="C"> - <short>Port used to connect to server (Deprecated)</short> - <long>The port number to connect to. The default port is 2628. - This key is deprecated and no longer in use.</long> - </locale> - </schema> - - <schema> - <key>/schemas/apps/mate-dictionary/smart</key> - <applyto>/apps/mate-dictionary/smart</applyto> - <owner>mate-dictionary</owner> - <type>bool</type> - <default>TRUE</default> - <locale name="C"> - <short>Use smart lookup (Deprecated)</short> - <long>Specify whether to use smart lookup. This key is dependant - on whether the dictionary server supports this option. The default - is TRUE. This key is deprecated and no longer in use.</long> - </locale> - </schema> - - <schema> - <key>/schemas/apps/mate-dictionary/database</key> - <applyto>/apps/mate-dictionary/database</applyto> - <owner>mate-dictionary</owner> - <type>string</type> - <default>!</default> - <locale name="C"> - <short>The default database to use</short> - <long>The name of the default individual database or meta-database to - use on a dictionary source. An exclamation mark ("!") means that all - the databases present in a dictionary source should be searched</long> - </locale> - </schema> - - <schema> - <key>/schemas/apps/mate-dictionary/strategy</key> - <applyto>/apps/mate-dictionary/strategy</applyto> - <owner>mate-dictionary</owner> - <type>string</type> - <default>exact</default> - <locale name="C"> - <short>The default search strategy to use</short> - <long>The name of the default search strategy to use on a dictionary - source, if available. The default strategy is 'exact', that is match - exact words.</long> - </locale> - </schema> - - <schema> - <key>/schemas/apps/mate-dictionary/print-font</key> - <applyto>/apps/mate-dictionary/print-font</applyto> - <owner>mate-dictionary</owner> - <type>string</type> - <default>Serif 12</default> - <locale name="C"> - <short>The font to be used when printing</short> - <long>The font to be used when printing a definition.</long> - </locale> - </schema> - - <schema> - <key>/schemas/apps/mate-dictionary/source-name</key> - <applyto>/apps/mate-dictionary/source-name</applyto> - <owner>mate-dictionary</owner> - <type>string</type> - <default>Default</default> - <locale name="C"> - <short>The name of the dictionary source used</short> - <long>The name of the dictionary source used to retrieve the - definitions of words.</long> - </locale> - </schema> - - <schema> - <key>/schemas/apps/mate-dictionary/default-window-width</key> - <applyto>/apps/mate-dictionary/default-window-width</applyto> - <owner>mate-dictionary</owner> - <type>int</type> - <default>-1</default> - <locale name="C"> - <short>The default width of the application window</short> - <long>This key defines the window width and it's used to remember - the size of the dictionary window across sessions. Setting it - to -1 will make the dictionary window use a width based on the - font size.</long> - </locale> - </schema> - - <schema> - <key>/schemas/apps/mate-dictionary/default-window-height</key> - <applyto>/apps/mate-dictionary/default-window-height</applyto> - <owner>mate-dictionary</owner> - <type>int</type> - <default>-1</default> - <locale name="C"> - <short>The default height of the application window</short> - <long>This key defines the window height and it's used to remember - the size of the dictionary window across sessions. Setting it - to -1 will make the dictionary window use a height based on the - font size.</long> - </locale> - </schema> - - <schema> - <key>/schemas/apps/mate-dictionary/window-is-maximized</key> - <applyto>/apps/mate-dictionary/window-is-maximized</applyto> - <owner>mate-dictionary</owner> - <type>bool</type> - <default>FALSE</default> - <locale name="C"> - <short>Whether the application window should be maximized</short> - <long>This key defines whether the window should be maximized and it's - used to remember the state of the dictionary window across sessions. - Setting it to TRUE will make the window always appear as - maximized.</long> - </locale> - </schema> - - <schema> - <key>/schemas/apps/mate-dictionary/sidebar-visible</key> - <applyto>/apps/mate-dictionary/sidebar-visible</applyto> - <owner>mate-dictionary</owner> - <type>bool</type> - <default>FALSE</default> - <locale name="C"> - <short>Whether the sidebar should be visible</short> - <long>This key defines whether the sidebar should be visible - and it's used to remember the state of the sidebar across - sessions. Setting it to TRUE will make the sidebar always - be displayed.</long> - </locale> - </schema> - - <schema> - <key>/schemas/apps/mate-dictionary/statusbar-visible</key> - <applyto>/apps/mate-dictionary/statusbar-visible</applyto> - <owner>mate-dictionary</owner> - <type>bool</type> - <default>FALSE</default> - <locale name="C"> - <short>Whether the statusbar should be visible</short> - <long>This key defines whether the statusbar should be visible - and it's used to remember the state of the statusbar across - sessions. Setting it to TRUE will make the statusbar always - be displayed.</long> - </locale> - </schema> - - <schema> - <key>/schemas/apps/mate-dictionary/sidebar-page</key> - <applyto>/apps/mate-dictionary/sidebar-page</applyto> - <owner>mate-dictionary</owner> - <type>string</type> - <default>speller</default> - <locale name="C"> - <short>The page of the sidebar to show</short> - <long>This key defines which page of the sidebar should be - displayed and it's used to remember the setting across - sessions.. It can be "speller" or "databases".</long> - </locale> - </schema> - - <schema> - <key>/schemas/apps/mate-dictionary/sidebar-width</key> - <applyto>/apps/mate-dictionary/sidebar-width</applyto> - <owner>mate-dictionary</owner> - <type>int</type> - <default>-1</default> - <locale name="C"> - <short>The width of the sidebar</short> - <long>This key defines the width of the sidebar and it's - used to remember the setting across sessions.</long> - </locale> - </schema> - - </schemalist> - -</mateconfschemafile> diff --git a/mate-dictionary/data/org.mate.dictionary.gschema.xml.in b/mate-dictionary/data/org.mate.dictionary.gschema.xml.in new file mode 100644 index 00000000..e6f5add2 --- /dev/null +++ b/mate-dictionary/data/org.mate.dictionary.gschema.xml.in @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> +<schemalist> + <schema id="org.mate.dictionary" path="/org/mate/dictionary/" gettext-domain="@GETTEXT_PACKAGE@"> + <key name="database" type="s"> + <default>'!'</default> + <_summary>The default database to use</_summary> + <_description>The name of the default individual database or meta-database to use on a dictionary source. An exclamation mark ("!") means that all the databases present in a dictionary source should be searched</_description> + </key> + <key name="strategy" type="s"> + <default>'exact'</default> + <_summary>The default search strategy to use</_summary> + <_description>The name of the default search strategy to use on a dictionary source, if available. The default strategy is 'exact', that is match exact words.</_description> + </key> + <key name="print-font" type="s"> + <default>'Serif 12'</default> + <_summary>The font to be used when printing</_summary> + <_description>The font to be used when printing a definition.</_description> + </key> + <key name="source-name" type="s"> + <default>'Default'</default> + <_summary>The name of the dictionary source used</_summary> + <_description>The name of the dictionary source used to retrieve the definitions of words.</_description> + </key> + </schema> +</schemalist> diff --git a/mate-dictionary/libgdict/gdict-source.c b/mate-dictionary/libgdict/gdict-source.c index 97040a31..7c37d615 100644 --- a/mate-dictionary/libgdict/gdict-source.c +++ b/mate-dictionary/libgdict/gdict-source.c @@ -244,7 +244,7 @@ gdict_source_class_init (GdictSourceClass *klass) PROP_NAME, g_param_spec_string ("name", _("Name"), - _("The display name of this dictonary source"), + _("The display name of this dictionary source"), NULL, (G_PARAM_READABLE | G_PARAM_WRITABLE))); /** @@ -272,7 +272,7 @@ gdict_source_class_init (GdictSourceClass *klass) PROP_DATABASE, g_param_spec_string ("database", _("Database"), - _("The default database of this dictonary source"), + _("The default database of this dictionary source"), NULL, (G_PARAM_READABLE | G_PARAM_WRITABLE))); /** @@ -286,7 +286,7 @@ gdict_source_class_init (GdictSourceClass *klass) PROP_STRATEGY, g_param_spec_string ("strategy", _("Strategy"), - _("The default strategy of this dictonary source"), + _("The default strategy of this dictionary source"), NULL, (G_PARAM_READABLE | G_PARAM_WRITABLE))); /** diff --git a/mate-dictionary/src/Makefile.am b/mate-dictionary/src/Makefile.am index ddde3d26..57242f06 100644 --- a/mate-dictionary/src/Makefile.am +++ b/mate-dictionary/src/Makefile.am @@ -35,15 +35,21 @@ mate_dictionary_SOURCES = \ gdict-window.h \ main.c \ $(NULL) + mate_dictionary_CFLAGS = \ -I$(top_builddir)/mate-dictionary \ -I$(top_srcdir)/mate-dictionary \ - $(MATE_UTILS_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(GIO_CFLAGS) \ + $(GTK_CFLAGS) \ $(NULL) + mate_dictionary_LDADD = \ -lm \ $(top_builddir)/mate-dictionary/libgdict/libmatedict.la \ - $(MATE_UTILS_LIBS) \ + $(GLIB_LIBS) \ + $(GIO_LIBS) \ + $(GTK_LIBS) \ $(NULL) if BUILD_GDICT_APPLET @@ -66,17 +72,23 @@ mate_dictionary_applet_SOURCES = \ gdict-source-dialog.c \ gdict-source-dialog.h \ $(NULL) + mate_dictionary_applet_CFLAGS = \ -I$(top_builddir)/mate-dictionary \ -I$(top_srcdir)/mate-dictionary \ - $(MATE_UTILS_CFLAGS) \ $(APPLET_CFLAGS) \ + $(GLIB_CFLAGS) \ + $(GIO_CFLAGS) \ + $(GTK_CFLAGS) \ $(NULL) + mate_dictionary_applet_LDADD = \ -lm \ $(top_builddir)/mate-dictionary/libgdict/libmatedict.la \ - $(MATE_UTILS_LIBS) \ $(APPLET_LIBS) \ + $(GLIB_LIBS) \ + $(GIO_LIBS) \ + $(GTK_LIBS) \ $(NULL) endif # BUILD_GDICT_APPLET diff --git a/mate-dictionary/src/gdict-app.c b/mate-dictionary/src/gdict-app.c index 646fda3f..20a1ae06 100644 --- a/mate-dictionary/src/gdict-app.c +++ b/mate-dictionary/src/gdict-app.c @@ -320,7 +320,7 @@ gdict_look_up_word_and_quit (GdictApp *app) void gdict_init (int *argc, char ***argv) { - GError *mateconf_error, *err = NULL; + GError *err = NULL; GOptionContext *context; gchar *loader_path; gchar **lookup_words = NULL; @@ -391,20 +391,8 @@ gdict_init (int *argc, char ***argv) exit (1); } - - mateconf_error = NULL; - singleton->mateconf_client = mateconf_client_get_default (); - mateconf_client_add_dir (singleton->mateconf_client, - GDICT_MATECONF_DIR, - MATECONF_CLIENT_PRELOAD_ONELEVEL, - &mateconf_error); - if (mateconf_error) - { - g_warning ("Unable to access MateConf: %s\n", mateconf_error->message); - - g_error_free (mateconf_error); - g_object_unref (singleton->mateconf_client); - } + + singleton->settings = g_settings_new ("org.mate.dictionary"); /* add user's path for fetching dictionary sources */ singleton->loader = gdict_source_loader_new (); diff --git a/mate-dictionary/src/gdict-app.h b/mate-dictionary/src/gdict-app.h index d11167b5..2307c9f7 100644 --- a/mate-dictionary/src/gdict-app.h +++ b/mate-dictionary/src/gdict-app.h @@ -23,8 +23,8 @@ #ifndef __GDICT_APP_H__ #define __GDICT_APP_H__ +#include <gio/gio.h> #include <gtk/gtk.h> -#include <mateconf/mateconf-client.h> #include <libgdict/gdict.h> #include "gdict-window.h" @@ -43,7 +43,7 @@ struct _GdictApp { GObject parent_instance; - MateConfClient *mateconf_client; + GSettings *settings; GSList *lookup_words; GSList *match_words; diff --git a/mate-dictionary/src/gdict-applet.c b/mate-dictionary/src/gdict-applet.c index fc3addaf..3efb0d36 100644 --- a/mate-dictionary/src/gdict-applet.c +++ b/mate-dictionary/src/gdict-applet.c @@ -26,10 +26,10 @@ #include <string.h> #include <glib/gi18n.h> +#include <gio/gio.h> #include <gdk/gdkkeysyms.h> #include <gdk-pixbuf/gdk-pixbuf.h> #include <gtk/gtk.h> -#include <mateconf/mateconf-client.h> #include "gdict-applet.h" #include "gdict-about.h" @@ -53,9 +53,8 @@ struct _GdictAppletPrivate guint size; GtkOrientation orient; - MateConfClient *mateconf_client; - guint notify_id; - guint font_notify_id; + GSettings *settings; + GSettings *desktop_settings; gchar *database; gchar *strategy; @@ -850,12 +849,11 @@ gdict_applet_set_database (GdictApplet *applet, g_free (priv->database); - if (database) + if (database != NULL && *database != '\0') priv->database = g_strdup (database); else - priv->database = gdict_mateconf_get_string_with_default (priv->mateconf_client, - GDICT_MATECONF_DATABASE_KEY, - GDICT_DEFAULT_DATABASE); + priv->database = g_settings_get_string (priv->settings, + GDICT_SETTINGS_DATABASE_KEY); if (priv->defbox) gdict_defbox_set_database (GDICT_DEFBOX (priv->defbox), priv->database); @@ -869,12 +867,11 @@ gdict_applet_set_strategy (GdictApplet *applet, g_free (priv->strategy); - if (strategy) + if (strategy != NULL && *strategy != '\0') priv->strategy = g_strdup (strategy); else - priv->strategy = gdict_mateconf_get_string_with_default (priv->mateconf_client, - GDICT_MATECONF_STRATEGY_KEY, - GDICT_DEFAULT_STRATEGY); + priv->strategy = g_settings_get_string (priv->settings, + GDICT_SETTINGS_STRATEGY_KEY); } static GdictContext * @@ -939,12 +936,11 @@ gdict_applet_set_print_font (GdictApplet *applet, g_free (priv->print_font); - if (print_font) + if (print_font != NULL && *print_font != '\0') priv->print_font = g_strdup (print_font); else - priv->print_font = gdict_mateconf_get_string_with_default (priv->mateconf_client, - GDICT_MATECONF_PRINT_FONT_KEY, - GDICT_DEFAULT_PRINT_FONT); + priv->print_font = g_settings_get_string (priv->settings, + GDICT_SETTINGS_PRINT_FONT_KEY); } static void @@ -955,12 +951,11 @@ gdict_applet_set_defbox_font (GdictApplet *applet, g_free (priv->defbox_font); - if (defbox_font) + if (defbox_font != NULL && *defbox_font != '\0') priv->defbox_font = g_strdup (defbox_font); else - priv->defbox_font = gdict_mateconf_get_string_with_default (priv->mateconf_client, - DOCUMENT_FONT_KEY, - GDICT_DEFAULT_DEFBOX_FONT); + priv->defbox_font = g_settings_get_string (priv->desktop_settings, + DOCUMENT_FONT_KEY); if (priv->defbox) gdict_defbox_set_font_name (GDICT_DEFBOX (priv->defbox), @@ -1016,59 +1011,40 @@ gdict_applet_set_source_name (GdictApplet *applet, g_free (priv->source_name); - if (source_name) + if (source_name != NULL && *source_name != '\0') priv->source_name = g_strdup (source_name); else - priv->source_name = gdict_mateconf_get_string_with_default (priv->mateconf_client, - GDICT_MATECONF_SOURCE_KEY, - GDICT_DEFAULT_SOURCE_NAME); + priv->source_name = g_settings_get_string (priv->settings, + GDICT_SETTINGS_SOURCE_KEY); context = get_context_from_loader (applet); gdict_applet_set_context (applet, context); } static void -gdict_applet_mateconf_notify_cb (MateConfClient *client, - guint cnxn_id, - MateConfEntry *entry, - gpointer user_data) +gdict_applet_settings_changed_cb (GSettings *settings, + const gchar *key, GdictApplet *applet) { - GdictApplet *applet = GDICT_APPLET (user_data); - if (strcmp (entry->key, GDICT_MATECONF_PRINT_FONT_KEY) == 0) + if (g_strcmp0 (key, GDICT_SETTINGS_PRINT_FONT_KEY) == 0) { - if (entry->value && (entry->value->type == MATECONF_VALUE_STRING)) - gdict_applet_set_print_font (applet, mateconf_value_get_string (entry->value)); - else - gdict_applet_set_print_font (applet, GDICT_DEFAULT_PRINT_FONT); + gdict_applet_set_print_font (applet, NULL); } - else if (strcmp (entry->key, GDICT_MATECONF_SOURCE_KEY) == 0) + else if (g_strcmp0 (key, GDICT_SETTINGS_SOURCE_KEY) == 0) { - if (entry->value && (entry->value->type == MATECONF_VALUE_STRING)) - gdict_applet_set_source_name (applet, mateconf_value_get_string (entry->value)); - else - gdict_applet_set_source_name (applet, GDICT_DEFAULT_SOURCE_NAME); + gdict_applet_set_source_name (applet, NULL); } - else if (strcmp (entry->key, GDICT_MATECONF_DATABASE_KEY) == 0) + else if (g_strcmp0 (key, GDICT_SETTINGS_DATABASE_KEY) == 0) { - if (entry->value && (entry->value->type == MATECONF_VALUE_STRING)) - gdict_applet_set_database (applet, mateconf_value_get_string (entry->value)); - else - gdict_applet_set_database (applet, GDICT_DEFAULT_DATABASE); + gdict_applet_set_database (applet, NULL); } - else if (strcmp (entry->key, GDICT_MATECONF_STRATEGY_KEY) == 0) + else if (g_strcmp0 (key, GDICT_SETTINGS_STRATEGY_KEY) == 0) { - if (entry->value && (entry->value->type == MATECONF_VALUE_STRING)) - gdict_applet_set_strategy (applet, mateconf_value_get_string (entry->value)); - else - gdict_applet_set_strategy (applet, GDICT_DEFAULT_STRATEGY); + gdict_applet_set_strategy (applet, NULL); } - else if (strcmp (entry->key, DOCUMENT_FONT_KEY) == 0) + else if (g_strcmp0 (key, DOCUMENT_FONT_KEY) == 0) { - if (entry->value && (entry->value->type == MATECONF_VALUE_STRING)) - gdict_applet_set_defbox_font (applet, mateconf_value_get_string (entry->value)); - else - gdict_applet_set_defbox_font (applet, GDICT_DEFAULT_DEFBOX_FONT); + gdict_applet_set_defbox_font (applet, NULL); } } @@ -1081,23 +1057,26 @@ gdict_applet_finalize (GObject *object) if (priv->idle_draw_id) g_source_remove (priv->idle_draw_id); - if (priv->notify_id) - mateconf_client_notify_remove (priv->mateconf_client, priv->notify_id); + if (priv->settings != NULL) + { + g_object_unref (priv->settings); + priv->settings = NULL; + } + + if (priv->desktop_settings != NULL) + { + g_object_unref (priv->desktop_settings); + priv->desktop_settings = NULL; + } - if (priv->font_notify_id) - mateconf_client_notify_remove (priv->mateconf_client, priv->font_notify_id); - - if (priv->mateconf_client) - g_object_unref (priv->mateconf_client); - if (priv->context) { if (priv->lookup_start_id) { g_signal_handler_disconnect (priv->context, priv->lookup_start_id); - g_signal_handler_disconnect (priv->context, priv->lookup_end_id); - g_signal_handler_disconnect (priv->context, priv->error_id); - } + g_signal_handler_disconnect (priv->context, priv->lookup_end_id); + g_signal_handler_disconnect (priv->context, priv->error_id); + } g_object_unref (priv->context); } @@ -1139,7 +1118,6 @@ gdict_applet_init (GdictApplet *applet) { GdictAppletPrivate *priv; gchar *data_dir; - GError *mateconf_error; priv = GDICT_APPLET_GET_PRIVATE (applet); applet->priv = priv; @@ -1156,52 +1134,16 @@ gdict_applet_init (GdictApplet *applet) mate_panel_applet_set_flags (MATE_PANEL_APPLET (applet), MATE_PANEL_APPLET_EXPAND_MINOR); - - /* get the default mateconf client */ - if (!priv->mateconf_client) - priv->mateconf_client = mateconf_client_get_default (); - - mateconf_error = NULL; - mateconf_client_add_dir (priv->mateconf_client, - GDICT_MATECONF_DIR, - MATECONF_CLIENT_PRELOAD_ONELEVEL, - &mateconf_error); - if (mateconf_error) - { - gdict_show_gerror_dialog (NULL, - _("Unable to connect to MateConf"), - mateconf_error); - mateconf_error = NULL; - } - - priv->notify_id = mateconf_client_notify_add (priv->mateconf_client, - GDICT_MATECONF_DIR, - gdict_applet_mateconf_notify_cb, - applet, NULL, - &mateconf_error); - if (mateconf_error) - { - gdict_show_gerror_dialog (NULL, - _("Unable to get notification for preferences"), - mateconf_error); - mateconf_error = NULL; - } - - priv->font_notify_id = mateconf_client_notify_add (priv->mateconf_client, - DOCUMENT_FONT_KEY, - gdict_applet_mateconf_notify_cb, - applet, NULL, - &mateconf_error); - if (mateconf_error) - { - gdict_show_gerror_dialog (NULL, - _("Unable to get notification for the document font"), - mateconf_error); + priv->settings = g_settings_new (GDICT_SETTINGS_SCHEMA); + priv->desktop_settings = g_settings_new (DESKTOP_SETTINGS_SCHEMA); + + g_signal_connect (priv->settings, "changed", + G_CALLBACK (gdict_applet_settings_changed_cb), applet); + + g_signal_connect (priv->desktop_settings, "changed", + G_CALLBACK (gdict_applet_settings_changed_cb), applet); - mateconf_error = NULL; - } - #ifndef GDICT_APPLET_STAND_ALONE mate_panel_applet_set_background_widget (MATE_PANEL_APPLET (applet), GTK_WIDGET (applet)); @@ -1237,7 +1179,7 @@ gdict_applet_init (GdictApplet *applet) /* force first draw */ gdict_applet_draw (applet); - /* force retrieval of the configuration from MateConf */ + /* force retrieval of the configuration from settings */ gdict_applet_set_source_name (applet, NULL); gdict_applet_set_defbox_font (applet, NULL); gdict_applet_set_print_font (applet, NULL); diff --git a/mate-dictionary/src/gdict-common.c b/mate-dictionary/src/gdict-common.c index dfc1dd75..1686a87e 100644 --- a/mate-dictionary/src/gdict-common.c +++ b/mate-dictionary/src/gdict-common.c @@ -187,15 +187,3 @@ gdict_show_gerror_dialog (GtkWindow *parent, g_error_free (error); error = NULL; } - -gchar * -gdict_mateconf_get_string_with_default (MateConfClient *client, - const gchar *key, - const gchar *def) -{ - gchar *val; - - val = mateconf_client_get_string (client, key, NULL); - return val ? val : g_strdup (def); -} - diff --git a/mate-dictionary/src/gdict-common.h b/mate-dictionary/src/gdict-common.h index ded4c51b..800fc9d6 100644 --- a/mate-dictionary/src/gdict-common.h +++ b/mate-dictionary/src/gdict-common.h @@ -24,7 +24,6 @@ #define __GDICT_COMMON_H__ #include <gtk/gtk.h> -#include <mateconf/mateconf-client.h> G_BEGIN_DECLS @@ -38,11 +37,6 @@ void gdict_show_gerror_dialog (GtkWindow *parent, const gchar *message, GError *error); -gchar * gdict_mateconf_get_string_with_default (MateConfClient *client, - const gchar *key, - const gchar *def); - - G_END_DECLS #endif /* __GDICT_COMMON_H__ */ diff --git a/mate-dictionary/src/gdict-pref-dialog.c b/mate-dictionary/src/gdict-pref-dialog.c index e430e4e1..72d06b9a 100644 --- a/mate-dictionary/src/gdict-pref-dialog.c +++ b/mate-dictionary/src/gdict-pref-dialog.c @@ -34,7 +34,7 @@ #endif #include <glib/gi18n.h> -#include <mateconf/mateconf-client.h> +#include <gio/gio.h> #include "gdict-source-dialog.h" #include "gdict-pref-dialog.h" @@ -66,8 +66,7 @@ struct _GdictPrefDialog GtkBuilder *builder; - MateConfClient *mateconf_client; - guint notify_id; + GSettings *settings; gchar *active_source; GdictSourceLoader *loader; @@ -79,6 +78,7 @@ struct _GdictPrefDialog GtkWidget *sources_view; GtkWidget *sources_add; GtkWidget *sources_remove; + GtkWidget *sources_edit; gchar *print_font; GtkWidget *font_button; @@ -204,14 +204,10 @@ source_renderer_toggled_cb (GtkCellRendererToggle *renderer, { g_free (dialog->active_source); dialog->active_source = g_strdup (name); - - mateconf_client_set_string (dialog->mateconf_client, - GDICT_MATECONF_SOURCE_KEY, - dialog->active_source, - NULL); - + + g_settings_set_string (dialog->settings, GDICT_SETTINGS_SOURCE_KEY, dialog->active_source); update_sources_view (dialog); - + g_free (name); } @@ -405,6 +401,46 @@ out: } static void +source_edit_clicked_cb (GtkButton *button, + GdictPrefDialog *dialog) +{ + GtkTreeSelection *selection; + GtkTreeModel *model; + GtkTreeIter iter; + gboolean is_selected; + gchar *name, *description; + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->sources_view)); + if (!selection) + return; + + is_selected = gtk_tree_selection_get_selected (selection, &model, &iter); + if (!is_selected) + return; + + gtk_tree_model_get (model, &iter, SOURCES_NAME_COLUMN, &name, -1); + if (!name) + return; + else + { + GtkWidget *edit_dialog; + + edit_dialog = gdict_source_dialog_new (GTK_WINDOW (dialog), + _("Edit Dictionary Source"), + GDICT_SOURCE_DIALOG_EDIT, + dialog->loader, + name); + gtk_dialog_run (GTK_DIALOG (edit_dialog)); + + gtk_widget_destroy (edit_dialog); + } + + g_free (name); + + update_sources_view (dialog); +} + +static void set_source_loader (GdictPrefDialog *dialog, GdictSourceLoader *loader) { @@ -434,52 +470,8 @@ font_button_font_set_cb (GtkWidget *font_button, g_free (dialog->print_font); dialog->print_font = g_strdup (font); - - mateconf_client_set_string (dialog->mateconf_client, - GDICT_MATECONF_PRINT_FONT_KEY, - dialog->print_font, - NULL); -} -static void -gdict_pref_dialog_mateconf_notify_cb (MateConfClient *client, - guint cnxn_id, - MateConfEntry *entry, - gpointer user_data) -{ - GdictPrefDialog *dialog = GDICT_PREF_DIALOG (user_data); - - if (strcmp (entry->key, GDICT_MATECONF_SOURCE_KEY) == 0) - { - if (entry->value && entry->value->type == MATECONF_VALUE_STRING) - { - g_free (dialog->active_source); - dialog->active_source = g_strdup (mateconf_value_get_string (entry->value)); - } - else - { - g_free (dialog->active_source); - dialog->active_source = g_strdup (GDICT_DEFAULT_SOURCE_NAME); - } - - update_sources_view (dialog); - } - else if (strcmp (entry->key, GDICT_MATECONF_PRINT_FONT_KEY) == 0) - { - if (entry->value && entry->value->type == MATECONF_VALUE_STRING) - { - g_free (dialog->print_font); - dialog->print_font = g_strdup (mateconf_value_get_string (entry->value)); - } - else - { - g_free (dialog->print_font); - dialog->print_font = g_strdup (GDICT_DEFAULT_PRINT_FONT); - } - - gtk_font_button_set_font_name (GTK_FONT_BUTTON (dialog->font_button), - dialog->print_font); - } + g_settings_set_string (dialog->settings, GDICT_SETTINGS_PRINT_FONT_KEY, dialog->print_font); } static void @@ -531,11 +523,8 @@ gdict_pref_dialog_finalize (GObject *object) { GdictPrefDialog *dialog = GDICT_PREF_DIALOG (object); - if (dialog->notify_id); - mateconf_client_notify_remove (dialog->mateconf_client, dialog->notify_id); - - if (dialog->mateconf_client) - g_object_unref (dialog->mateconf_client); + if (dialog->settings) + g_object_unref (dialog->settings); if (dialog->builder) g_object_unref (dialog->builder); @@ -615,8 +604,7 @@ gdict_pref_dialog_init (GdictPrefDialog *dialog) gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), 2); - gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); - + /* add buttons */ gtk_dialog_add_button (GTK_DIALOG (dialog), "gtk-help", @@ -625,17 +613,7 @@ gdict_pref_dialog_init (GdictPrefDialog *dialog) "gtk-close", GTK_RESPONSE_ACCEPT); - dialog->mateconf_client = mateconf_client_get_default (); - mateconf_client_add_dir (dialog->mateconf_client, - GDICT_MATECONF_DIR, - MATECONF_CLIENT_PRELOAD_ONELEVEL, - NULL); - dialog->notify_id = mateconf_client_notify_add (dialog->mateconf_client, - GDICT_MATECONF_DIR, - gdict_pref_dialog_mateconf_notify_cb, - dialog, - NULL, - NULL); + dialog->settings = g_settings_new (GDICT_SETTINGS_SCHEMA); /* get the UI from the GtkBuilder file */ dialog->builder = gtk_builder_new (); @@ -657,9 +635,7 @@ gdict_pref_dialog_init (GdictPrefDialog *dialog) dialog->sources_view = GTK_WIDGET (gtk_builder_get_object (dialog->builder, "sources_treeview")); build_sources_view (dialog); - dialog->active_source = gdict_mateconf_get_string_with_default (dialog->mateconf_client, - GDICT_MATECONF_SOURCE_KEY, - GDICT_DEFAULT_SOURCE_NAME); + dialog->active_source = g_settings_get_string (dialog->settings, GDICT_SETTINGS_SOURCE_KEY); dialog->sources_add = GTK_WIDGET (gtk_builder_get_object (dialog->builder, "add_button")); gtk_widget_set_tooltip_text (dialog->sources_add, @@ -672,13 +648,14 @@ gdict_pref_dialog_init (GdictPrefDialog *dialog) _("Remove the currently selected dictionary source")); g_signal_connect (dialog->sources_remove, "clicked", G_CALLBACK (source_remove_clicked_cb), dialog); - - font = mateconf_client_get_string (dialog->mateconf_client, - GDICT_MATECONF_PRINT_FONT_KEY, - NULL); - if (!font) - font = g_strdup (GDICT_DEFAULT_PRINT_FONT); - + + dialog->sources_edit = GTK_WIDGET (gtk_builder_get_object (dialog->builder, "edit_button")); + gtk_widget_set_tooltip_text (dialog->sources_edit, + _("Edit the currently selected dictionary source")); + g_signal_connect (dialog->sources_edit, "clicked", + G_CALLBACK (source_edit_clicked_cb), dialog); + + font = g_settings_get_string (dialog->settings, GDICT_SETTINGS_PRINT_FONT_KEY); dialog->font_button = GTK_WIDGET (gtk_builder_get_object (dialog->builder, "print_font_button")); gtk_font_button_set_font_name (GTK_FONT_BUTTON (dialog->font_button), font); gtk_widget_set_tooltip_text (dialog->font_button, @@ -708,12 +685,12 @@ gdict_show_pref_dialog (GtkWidget *parent, g_return_if_fail (GTK_IS_WIDGET (parent)); g_return_if_fail (GDICT_IS_SOURCE_LOADER (loader)); - if (parent) + if (parent != NULL) dialog = g_object_get_data (G_OBJECT (parent), "gdict-pref-dialog"); else dialog = global_dialog; - if (!dialog) + if (dialog == NULL) { dialog = g_object_new (GDICT_TYPE_PREF_DIALOG, "source-loader", loader, @@ -726,7 +703,7 @@ gdict_show_pref_dialog (GtkWidget *parent, G_CALLBACK (gtk_widget_hide_on_delete), NULL); - if (parent && GTK_IS_WINDOW (parent)) + if (parent != NULL && GTK_IS_WINDOW (parent)) { gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent)); gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE); @@ -738,7 +715,6 @@ gdict_show_pref_dialog (GtkWidget *parent, global_dialog = dialog; } - gtk_window_set_screen (GTK_WINDOW (dialog), - gtk_widget_get_screen (parent)); - gtk_window_present (GTK_WINDOW (dialog)); + gtk_window_set_screen (GTK_WINDOW (dialog), gtk_widget_get_screen (parent)); + gtk_window_present (GTK_WINDOW (dialog)); } diff --git a/mate-dictionary/src/gdict-pref-dialog.h b/mate-dictionary/src/gdict-pref-dialog.h index 5abb345a..1b25884d 100644 --- a/mate-dictionary/src/gdict-pref-dialog.h +++ b/mate-dictionary/src/gdict-pref-dialog.h @@ -36,20 +36,14 @@ G_BEGIN_DECLS #define GDICT_DEFAULT_PRINT_FONT "Serif 10" #define GDICT_DEFAULT_SOURCE_NAME "Default" -#define GDICT_MATECONF_DIR "/apps/mate-dictionary" -#define GDICT_MATECONF_DATABASE_KEY GDICT_MATECONF_DIR "/database" -#define GDICT_MATECONF_STRATEGY_KEY GDICT_MATECONF_DIR "/strategy" -#define GDICT_MATECONF_PRINT_FONT_KEY GDICT_MATECONF_DIR "/print-font" -#define GDICT_MATECONF_SOURCE_KEY GDICT_MATECONF_DIR "/source-name" -#define GDICT_MATECONF_WINDOW_WIDTH_KEY GDICT_MATECONF_DIR "/default-window-width" -#define GDICT_MATECONF_WINDOW_HEIGHT_KEY GDICT_MATECONF_DIR "/default-window-height" -#define GDICT_MATECONF_WINDOW_IS_MAXIMIZED_KEY GDICT_MATECONF_DIR "/window-is-maximized" -#define GDICT_MATECONF_SIDEBAR_VISIBLE_KEY GDICT_MATECONF_DIR "/sidebar-visible" -#define GDICT_MATECONF_SIDEBAR_PAGE_KEY GDICT_MATECONF_DIR "/sidebar-page" -#define GDICT_MATECONF_SIDEBAR_WIDTH_KEY GDICT_MATECONF_DIR "/sidebar-width" -#define GDICT_MATECONF_STATUSBAR_VISIBLE_KEY GDICT_MATECONF_DIR "/statusbar-visible" - -#define DOCUMENT_FONT_KEY "/desktop/mate/interface/document_font_name" +#define GDICT_SETTINGS_SCHEMA "org.mate.dictionary" +#define GDICT_SETTINGS_DATABASE_KEY "database" +#define GDICT_SETTINGS_STRATEGY_KEY "strategy" +#define GDICT_SETTINGS_PRINT_FONT_KEY "print-font" +#define GDICT_SETTINGS_SOURCE_KEY "source-name" + +#define DESKTOP_SETTINGS_SCHEMA "org.mate.interface" +#define DOCUMENT_FONT_KEY "document-font-name" typedef struct _GdictPrefDialog GdictPrefDialog; typedef struct _GdictPrefDialogClass GdictPrefDialogClass; diff --git a/mate-dictionary/src/gdict-print.c b/mate-dictionary/src/gdict-print.c index 734f1a54..9e18bd6d 100644 --- a/mate-dictionary/src/gdict-print.c +++ b/mate-dictionary/src/gdict-print.c @@ -28,10 +28,9 @@ #include <string.h> #include <math.h> -#include <gtk/gtk.h> #include <glib/gi18n.h> - -#include <mateconf/mateconf-client.h> +#include <gio/gio.h> +#include <gtk/gtk.h> #include <libgdict/gdict.h> @@ -178,19 +177,12 @@ end_print (GtkPrintOperation *operation, static gchar * get_print_font (void) { - MateConfClient *client; - gchar *print_font; - - client = mateconf_client_get_default (); - print_font = mateconf_client_get_string (client, - GDICT_MATECONF_PRINT_FONT_KEY, - NULL); - if (!print_font) - print_font = g_strdup (GDICT_DEFAULT_PRINT_FONT); - - g_object_unref (client); - - return print_font; + static GSettings *settings = NULL; + + if (settings == NULL) + settings = g_settings_new ("org.mate.dictionary"); + + return g_settings_get_string (settings, "print-font"); } void diff --git a/mate-dictionary/src/gdict-source-dialog.c b/mate-dictionary/src/gdict-source-dialog.c index 0bebcb22..203da54f 100644 --- a/mate-dictionary/src/gdict-source-dialog.c +++ b/mate-dictionary/src/gdict-source-dialog.c @@ -34,7 +34,7 @@ #endif #include <glib/gi18n.h> -#include <mateconf/mateconf-client.h> +#include <gio/gio.h> #include "gdict-source-dialog.h" #include "gdict-common.h" @@ -51,9 +51,8 @@ struct _GdictSourceDialog GtkBuilder *builder; - MateConfClient *mateconf_client; - guint notify_id; - + GSettings *settings; + GdictSourceLoader *loader; GdictSource *source; gchar *source_name; @@ -499,8 +498,8 @@ gdict_source_dialog_finalize (GObject *object) { GdictSourceDialog *dialog = GDICT_SOURCE_DIALOG (object); - if (dialog->mateconf_client) - g_object_unref (dialog->mateconf_client); + if (dialog->settings) + g_object_unref (dialog->settings); if (dialog->builder) g_object_unref (dialog->builder); @@ -718,8 +717,6 @@ gdict_source_dialog_init (GdictSourceDialog *dialog) { gtk_widget_set_size_request (GTK_WIDGET (dialog), 400, 300); gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); - - gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); dialog->transport = GDICT_SOURCE_TRANSPORT_INVALID; diff --git a/mate-dictionary/src/gdict-window.c b/mate-dictionary/src/gdict-window.c index 83b74968..b967fe92 100644 --- a/mate-dictionary/src/gdict-window.c +++ b/mate-dictionary/src/gdict-window.c @@ -28,6 +28,7 @@ #include <stdlib.h> #include <string.h> #include <math.h> +#include <errno.h> #include <gtk/gtk.h> #include <glib.h> @@ -68,10 +69,14 @@ enum PROP_ACTION, PROP_SOURCE_LOADER, PROP_SOURCE_NAME, + PROP_DATABASE, + PROP_STRATEGY, PROP_PRINT_FONT, PROP_DEFBOX_FONT, PROP_WORD, - PROP_WINDOW_ID + PROP_WINDOW_ID, + + LAST_PROP }; enum @@ -81,6 +86,7 @@ enum LAST_SIGNAL }; +static GParamSpec *gdict_window_properties[LAST_PROP] = { NULL, }; static guint gdict_window_signals[LAST_SIGNAL] = { 0 }; static const GtkTargetEntry drop_types[] = @@ -117,37 +123,27 @@ gdict_window_dispose (GObject *gobject) { GdictWindow *window = GDICT_WINDOW (gobject); - if (window->notify_id) + if (window->desktop_settings != NULL) { - mateconf_client_notify_remove (window->mateconf_client, window->notify_id); - window->notify_id = 0; + g_object_unref (window->desktop_settings); + window->desktop_settings = NULL; } - if (window->font_notify_id) - { - mateconf_client_notify_remove (window->mateconf_client, - window->font_notify_id); - window->font_notify_id = 0; - } - - if (window->mateconf_client) + if (window->settings != NULL) { - g_object_unref (window->mateconf_client); - window->mateconf_client = NULL; + g_object_unref (window->settings); + + window->settings = NULL; } if (window->context) { if (window->lookup_start_id) { - g_signal_handler_disconnect (window->context, - window->lookup_start_id); - g_signal_handler_disconnect (window->context, - window->definition_id); - g_signal_handler_disconnect (window->context, - window->lookup_end_id); - g_signal_handler_disconnect (window->context, - window->error_id); + g_signal_handler_disconnect (window->context, window->lookup_start_id); + g_signal_handler_disconnect (window->context, window->definition_id); + g_signal_handler_disconnect (window->context, window->lookup_end_id); + g_signal_handler_disconnect (window->context, window->error_id); window->lookup_start_id = 0; window->definition_id = 0; @@ -236,21 +232,22 @@ gdict_window_set_sidebar_visible (GdictWindow *window, gboolean is_visible) { g_assert (GDICT_IS_WINDOW (window)); - + + is_visible = !!is_visible; + if (is_visible != window->sidebar_visible) { GtkAction *action; - if (is_visible) + window->sidebar_visible = is_visible; + + if (window->sidebar_visible) gtk_widget_show (window->sidebar_frame); else gtk_widget_hide (window->sidebar_frame); - action = gtk_action_group_get_action (window->action_group, - "ViewSidebar"); - gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), is_visible); - - window->sidebar_visible = is_visible; + action = gtk_action_group_get_action (window->action_group, "ViewSidebar"); + gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), window->sidebar_visible); } } @@ -260,20 +257,21 @@ gdict_window_set_statusbar_visible (GdictWindow *window, { g_assert (GDICT_IS_WINDOW (window)); + is_visible = !!is_visible; + if (is_visible != window->statusbar_visible) { GtkAction *action; - if (is_visible) + window->statusbar_visible = is_visible; + + if (window->statusbar_visible) gtk_widget_show (window->status); else gtk_widget_hide (window->status); - action = gtk_action_group_get_action (window->action_group, - "ViewStatusbar"); - gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), is_visible); - - window->statusbar_visible = is_visible; + action = gtk_action_group_get_action (window->action_group, "ViewStatusbar"); + gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), window->statusbar_visible); } } @@ -446,14 +444,15 @@ static void gdict_window_set_database (GdictWindow *window, const gchar *database) { + if (g_strcmp0 (window->database, database) == 0) + return; + g_free (window->database); - if (database) + if (database != NULL && *database != '\0') window->database = g_strdup (database); else - window->database = gdict_mateconf_get_string_with_default (window->mateconf_client, - GDICT_MATECONF_DATABASE_KEY, - GDICT_DEFAULT_DATABASE); + window->database = g_settings_get_string (window->settings, GDICT_SETTINGS_DATABASE_KEY); if (window->defbox) gdict_defbox_set_database (GDICT_DEFBOX (window->defbox), @@ -462,20 +461,23 @@ gdict_window_set_database (GdictWindow *window, if (window->db_chooser) gdict_database_chooser_set_current_database (GDICT_DATABASE_CHOOSER (window->db_chooser), window->database); + + g_object_notify_by_pspec (G_OBJECT (window), gdict_window_properties[PROP_DATABASE]); } static void gdict_window_set_strategy (GdictWindow *window, const gchar *strategy) { + if (g_strcmp0 (window->strategy, strategy) == 0) + return; + g_free (window->strategy); - if (strategy && strategy[0] != '\0') + if (strategy != NULL && *strategy != '\0') window->strategy = g_strdup (strategy); else - window->strategy = gdict_mateconf_get_string_with_default (window->mateconf_client, - GDICT_MATECONF_STRATEGY_KEY, - GDICT_DEFAULT_STRATEGY); + window->strategy = g_settings_get_string (window->settings, GDICT_SETTINGS_STRATEGY_KEY); if (window->speller) gdict_speller_set_strategy (GDICT_SPELLER (window->speller), @@ -484,6 +486,8 @@ gdict_window_set_strategy (GdictWindow *window, if (window->strat_chooser) gdict_strategy_chooser_set_current_strategy (GDICT_STRATEGY_CHOOSER (window->strat_chooser), window->strategy); + + g_object_notify_by_pspec (G_OBJECT (window), gdict_window_properties[PROP_STRATEGY]); } static GdictContext * @@ -555,16 +559,12 @@ gdict_window_set_defbox_font (GdictWindow *window, { g_free (window->defbox_font); - if (defbox_font) + if (defbox_font != NULL && *defbox_font != '\0') window->defbox_font = g_strdup (defbox_font); else - window->defbox_font = gdict_mateconf_get_string_with_default (window->mateconf_client, - DOCUMENT_FONT_KEY, - GDICT_DEFAULT_DEFBOX_FONT); + window->defbox_font = g_settings_get_string (window->desktop_settings, DOCUMENT_FONT_KEY); - if (window->defbox) - gdict_defbox_set_font_name (GDICT_DEFBOX (window->defbox), - window->defbox_font); + gdict_defbox_set_font_name (GDICT_DEFBOX (window->defbox), window->defbox_font); } static void @@ -573,12 +573,10 @@ gdict_window_set_print_font (GdictWindow *window, { g_free (window->print_font); - if (print_font) + if (print_font != NULL && *print_font != '\0') window->print_font = g_strdup (print_font); else - window->print_font = gdict_mateconf_get_string_with_default (window->mateconf_client, - GDICT_MATECONF_PRINT_FONT_KEY, - GDICT_DEFAULT_PRINT_FONT); + window->print_font = g_settings_get_string (window->settings, GDICT_SETTINGS_PRINT_FONT_KEY); } static void @@ -675,12 +673,10 @@ gdict_window_set_source_name (GdictWindow *window, g_free (window->source_name); - if (source_name) + if (source_name != NULL && *source_name != '\0') window->source_name = g_strdup (source_name); else - window->source_name = gdict_mateconf_get_string_with_default (window->mateconf_client, - GDICT_MATECONF_SOURCE_KEY, - GDICT_DEFAULT_SOURCE_NAME); + window->source_name = g_settings_get_string (window->settings, GDICT_SETTINGS_SOURCE_KEY); context = get_context_from_loader (window); gdict_window_set_context (window, context); @@ -689,7 +685,7 @@ gdict_window_set_source_name (GdictWindow *window, gdict_source_chooser_set_current_source (GDICT_SOURCE_CHOOSER (window->source_chooser), window->source_name); - g_object_notify (G_OBJECT (window), "source-name"); + g_object_notify_by_pspec (G_OBJECT (window), gdict_window_properties[PROP_SOURCE_NAME]); } static void @@ -714,6 +710,12 @@ gdict_window_set_property (GObject *object, case PROP_SOURCE_NAME: gdict_window_set_source_name (window, g_value_get_string (value)); break; + case PROP_DATABASE: + gdict_window_set_database (window, g_value_get_string (value)); + break; + case PROP_STRATEGY: + gdict_window_set_strategy (window, g_value_get_string (value)); + break; case PROP_WORD: gdict_window_set_word (window, g_value_get_string (value), NULL); break; @@ -748,6 +750,12 @@ gdict_window_get_property (GObject *object, case PROP_SOURCE_NAME: g_value_set_string (value, window->source_name); break; + case PROP_DATABASE: + g_value_set_string (value, window->database); + break; + case PROP_STRATEGY: + g_value_set_string (value, window->strategy); + break; case PROP_WORD: g_value_set_string (value, window->word); break; @@ -767,43 +775,161 @@ gdict_window_get_property (GObject *object, } static void +gdict_window_store_state (GdictWindow *window) +{ + gchar *state_dir, *state_file; + GKeyFile *state_key; + gchar *data; + gsize data_len; + GError *error; + const gchar *page_id; + + state_dir = g_build_filename (g_get_user_config_dir (), + "mate", + "mate-dictionary", + NULL); + + if (g_mkdir (state_dir, 0700) == -1) + { + if (errno != EEXIST) + { + g_warning ("Unable to create a cache directory: %s", g_strerror (errno)); + g_free (state_dir); + return; + } + } + + state_file = g_build_filename (state_dir, "window.ini", NULL); + state_key = g_key_file_new (); + + /* store the default size of the window and its state, so that + * it's picked up by newly created windows + */ + g_key_file_set_integer (state_key, "WindowState", "Width", window->current_width); + g_key_file_set_integer (state_key, "WindowState", "Height", window->current_height); + g_key_file_set_boolean (state_key, "WindowState", "IsMaximized", window->is_maximized); + g_key_file_set_boolean (state_key, "WindowState", "SidebarVisible", window->sidebar_visible); + g_key_file_set_boolean (state_key, "WindowState", "StatusbarVisible", window->statusbar_visible); + g_key_file_set_integer (state_key, "WindowState", "SidebarWidth", window->sidebar_width); + + page_id = gdict_sidebar_current_page (GDICT_SIDEBAR (window->sidebar)); + if (page_id == NULL) + page_id = GDICT_SIDEBAR_SPELLER_PAGE; + + g_key_file_set_string (state_key, "WindowState", "SidebarPage", page_id); + + error = NULL; + data = g_key_file_to_data (state_key, &data_len, &error); + if (error != NULL) + { + g_warning ("Unable to create the window state file: %s", error->message); + g_error_free (error); + } + else + { + g_file_set_contents (state_file, data, data_len, &error); + if (error != NULL) + { + g_warning ("Unable to write the window state file: %s", error->message); + g_error_free (error); + } + + g_free (data); + } + + g_key_file_free (state_key); + g_free (state_file); + g_free (state_dir); +} + +static void +gdict_window_load_state (GdictWindow *window) +{ + gchar *state_file; + GKeyFile *state_key; + gchar *data; + gsize data_len; + GError *error; + + state_file = g_build_filename (g_get_user_config_dir (), + "mate", + "mate-dictionary", + "window.ini", + NULL); + state_key = g_key_file_new (); + + error = NULL; + g_key_file_load_from_file (state_key, state_file, 0, &error); + if (error != NULL) + { + g_warning ("Unable to load the window state file: %s", error->message); + g_error_free (error); + g_key_file_free (state_key); + g_free (state_file); + return; + } + + window->default_width = g_key_file_get_integer (state_key, "WindowState", "Width", &error); + if (error != NULL) + { + g_clear_error (&error); + window->default_width = -1; + } + + window->default_height = g_key_file_get_integer (state_key, "WindowState", "Height", &error); + if (error != NULL) + { + g_clear_error (&error); + window->default_height = -1; + } + + window->is_maximized = g_key_file_get_boolean (state_key, "WindowState", "IsMaximized", &error); + if (error != NULL) + { + g_clear_error (&error); + window->is_maximized = FALSE; + } + + window->sidebar_visible = g_key_file_get_boolean (state_key, "WindowState", "SidebarVisible", &error); + if (error != NULL) + { + g_clear_error (&error); + window->sidebar_visible = FALSE; + } + + window->statusbar_visible = g_key_file_get_boolean (state_key, "WindowState", "StatusbarVisible", &error); + if (error != NULL) + { + g_clear_error (&error); + window->statusbar_visible = FALSE; + } + + window->sidebar_width = g_key_file_get_integer (state_key, "WindowState", "SidebarWidth", &error); + if (error != NULL) + { + g_clear_error (&error); + window->sidebar_width = -1; + } + + window->sidebar_page = g_key_file_get_string (state_key, "WindowState", "SidebarPage", &error); + if (error != NULL) + { + g_clear_error (&error); + window->sidebar_page = NULL; + } + + g_key_file_free (state_key); + g_free (state_file); +} + +static void gdict_window_cmd_file_new (GtkAction *action, GdictWindow *window) { GtkWidget *new_window; gchar *word = NULL; - - /* store the default size of the window and its state, so that - * it's picked up by the newly created window - */ - mateconf_client_set_int (window->mateconf_client, - GDICT_MATECONF_WINDOW_WIDTH_KEY, - window->default_width, - NULL); - mateconf_client_set_int (window->mateconf_client, - GDICT_MATECONF_WINDOW_HEIGHT_KEY, - window->default_height, - NULL); - mateconf_client_set_bool (window->mateconf_client, - GDICT_MATECONF_WINDOW_IS_MAXIMIZED_KEY, - window->is_maximized, - NULL); - mateconf_client_set_bool (window->mateconf_client, - GDICT_MATECONF_SIDEBAR_VISIBLE_KEY, - window->sidebar_visible, - NULL); - mateconf_client_set_int (window->mateconf_client, - GDICT_MATECONF_SIDEBAR_WIDTH_KEY, - window->sidebar_width, - NULL); - mateconf_client_set_string (window->mateconf_client, - GDICT_MATECONF_SIDEBAR_PAGE_KEY, - gdict_sidebar_current_page (GDICT_SIDEBAR (window->sidebar)), - NULL); - mateconf_client_set_bool (window->mateconf_client, - GDICT_MATECONF_STATUSBAR_VISIBLE_KEY, - window->statusbar_visible, - NULL); + + gdict_window_store_state (window); word = gdict_defbox_get_selected_word (GDICT_DEFBOX (window->defbox)); if (word) @@ -904,36 +1030,8 @@ gdict_window_cmd_file_close_window (GtkAction *action, { g_assert (GDICT_IS_WINDOW (window)); - /* store the default size of the window and its state */ - mateconf_client_set_int (window->mateconf_client, - GDICT_MATECONF_WINDOW_WIDTH_KEY, - window->default_width, - NULL); - mateconf_client_set_int (window->mateconf_client, - GDICT_MATECONF_WINDOW_HEIGHT_KEY, - window->default_height, - NULL); - mateconf_client_set_bool (window->mateconf_client, - GDICT_MATECONF_WINDOW_IS_MAXIMIZED_KEY, - window->is_maximized, - NULL); - mateconf_client_set_bool (window->mateconf_client, - GDICT_MATECONF_SIDEBAR_VISIBLE_KEY, - window->sidebar_visible, - NULL); - mateconf_client_set_int (window->mateconf_client, - GDICT_MATECONF_SIDEBAR_WIDTH_KEY, - window->sidebar_width, - NULL); - mateconf_client_set_string (window->mateconf_client, - GDICT_MATECONF_SIDEBAR_PAGE_KEY, - gdict_sidebar_current_page (GDICT_SIDEBAR (window->sidebar)), - NULL); - mateconf_client_set_bool (window->mateconf_client, - GDICT_MATECONF_STATUSBAR_VISIBLE_KEY, - window->statusbar_visible, - NULL); - + gdict_window_store_state (window); + /* if this was called from the uimanager, destroy the widget; * otherwise, if it was called from the delete_event, the widget * will destroy itself. @@ -1000,27 +1098,32 @@ gdict_window_cmd_edit_preferences (GtkAction *action, } static void -gdict_window_cmd_view_sidebar (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_view_sidebar (GtkToggleAction *action, + GdictWindow *window) { g_assert (GDICT_IS_WINDOW (window)); + window->sidebar_visible = gtk_toggle_action_get_active (action); + if (window->sidebar_visible) - gdict_window_set_sidebar_visible (window, FALSE); + gtk_widget_show (window->sidebar_frame); else - gdict_window_set_sidebar_visible (window, TRUE); + gtk_widget_hide (window->sidebar_frame); } static void -gdict_window_cmd_view_statusbar (GtkAction *action, - GdictWindow *window) +gdict_window_cmd_view_statusbar (GtkToggleAction *action, + GdictWindow *window) { g_assert (GDICT_IS_WINDOW (window)); + window->statusbar_visible = gtk_toggle_action_get_active (action); + if (window->statusbar_visible) - gdict_window_set_statusbar_visible (window, FALSE); + gtk_widget_show (window->status); else - gdict_window_set_statusbar_visible (window, TRUE); + gtk_widget_hide (window->status); + } static void @@ -1271,62 +1374,6 @@ gdict_window_state_event_cb (GtkWidget *widget, } static void -gdict_window_mateconf_notify_cb (MateConfClient *client, - guint cnxn_id, - MateConfEntry *entry, - gpointer user_data) -{ - GdictWindow *window; - - window = GDICT_WINDOW (user_data); - - if (strcmp (entry->key, GDICT_MATECONF_PRINT_FONT_KEY) == 0) - { - if (entry->value && (entry->value->type == MATECONF_VALUE_STRING)) - gdict_window_set_print_font (window, mateconf_value_get_string (entry->value)); - else - gdict_window_set_print_font (window, GDICT_DEFAULT_PRINT_FONT); - } - else if (strcmp (entry->key, GDICT_MATECONF_SOURCE_KEY) == 0) - { - if (entry->value && (entry->value->type == MATECONF_VALUE_STRING)) - gdict_window_set_source_name (window, mateconf_value_get_string (entry->value)); - else - gdict_window_set_source_name (window, GDICT_DEFAULT_SOURCE_NAME); - } - else if (strcmp (entry->key, GDICT_MATECONF_DATABASE_KEY) == 0) - { - if (entry->value && (entry->value->type == MATECONF_VALUE_STRING)) - gdict_window_set_database (window, mateconf_value_get_string (entry->value)); - else - gdict_window_set_database (window, GDICT_DEFAULT_DATABASE); - } - else if (strcmp (entry->key, DOCUMENT_FONT_KEY) == 0) - { - if (entry->value && (entry->value->type == MATECONF_VALUE_STRING)) - gdict_window_set_defbox_font (window, mateconf_value_get_string (entry->value)); - else - gdict_window_set_defbox_font (window, GDICT_DEFAULT_DEFBOX_FONT); - } - else if (strcmp (entry->key, GDICT_MATECONF_SIDEBAR_VISIBLE_KEY) == 0) - { - if (entry->value && (entry->value->type == MATECONF_VALUE_BOOL)) - gdict_window_set_sidebar_visible (window, - mateconf_value_get_bool (entry->value)); - else - gdict_window_set_sidebar_visible (window, FALSE); - } - else if (strcmp (entry->key, GDICT_MATECONF_STATUSBAR_VISIBLE_KEY) == 0) - { - if (entry->value && (entry->value->type == MATECONF_VALUE_BOOL)) - gdict_window_set_statusbar_visible (window, - mateconf_value_get_bool (entry->value)); - else - gdict_window_set_statusbar_visible (window, FALSE); - } -} - -static void lookup_word (GdictWindow *window, gpointer dummy) { @@ -1438,6 +1485,9 @@ sidebar_page_changed_cb (GdictSidebar *sidebar, page_id = gdict_sidebar_current_page (sidebar); + g_free (window->sidebar_page); + window->sidebar_page = g_strdup (page_id); + switch (page_id[0]) { case 's': @@ -1491,38 +1541,8 @@ gdict_window_link_clicked (GdictDefbox *defbox, GdictWindow *window) { GtkWidget *new_window; - - /* store the default size of the window and its state, so that - * it's picked up by the newly created window - */ - mateconf_client_set_int (window->mateconf_client, - GDICT_MATECONF_WINDOW_WIDTH_KEY, - window->default_width, - NULL); - mateconf_client_set_int (window->mateconf_client, - GDICT_MATECONF_WINDOW_HEIGHT_KEY, - window->default_height, - NULL); - mateconf_client_set_bool (window->mateconf_client, - GDICT_MATECONF_WINDOW_IS_MAXIMIZED_KEY, - window->is_maximized, - NULL); - mateconf_client_set_bool (window->mateconf_client, - GDICT_MATECONF_SIDEBAR_VISIBLE_KEY, - window->sidebar_visible, - NULL); - mateconf_client_set_int (window->mateconf_client, - GDICT_MATECONF_SIDEBAR_WIDTH_KEY, - window->sidebar_width, - NULL); - mateconf_client_set_string (window->mateconf_client, - GDICT_MATECONF_SIDEBAR_PAGE_KEY, - gdict_sidebar_current_page (GDICT_SIDEBAR (window->sidebar)), - NULL); - mateconf_client_set_bool (window->mateconf_client, - GDICT_MATECONF_STATUSBAR_VISIBLE_KEY, - window->statusbar_visible, - NULL); + + gdict_window_store_state (window); new_window = gdict_window_new (GDICT_WINDOW_ACTION_LOOKUP, window->loader, @@ -1567,8 +1587,8 @@ gdict_window_size_allocate (GtkWidget *widget, if (!window->is_maximized) { - window->default_width = allocation->width; - window->default_height = allocation->height; + window->current_width = allocation->width; + window->current_height = allocation->height; } if (GTK_WIDGET_CLASS (gdict_window_parent_class)->size_allocate) @@ -1595,17 +1615,6 @@ set_window_default_size (GdictWindow *window) /* make sure that the widget is realized */ gtk_widget_realize (widget); - /* recover the state from MateConf */ - width = mateconf_client_get_int (window->mateconf_client, - GDICT_MATECONF_WINDOW_WIDTH_KEY, - NULL); - height = mateconf_client_get_int (window->mateconf_client, - GDICT_MATECONF_WINDOW_HEIGHT_KEY, - NULL); - is_maximized = mateconf_client_get_bool (window->mateconf_client, - GDICT_MATECONF_WINDOW_IS_MAXIMIZED_KEY, - NULL); - /* XXX - the user wants mate-dictionary to resize itself, so * we compute the minimum safe geometry needed for displaying * the text returned by a dictionary server, which is based @@ -1613,10 +1622,11 @@ set_window_default_size (GdictWindow *window) * I know, but dictionary servers return pre-formatted text * and we can't reformat it ourselves. */ - if (width == -1 || height == -1) + if (window->default_width == -1 || window->default_height == -1) { /* Size based on the font size */ GtkWidget *defbox = window->defbox; + gint width, height; font_size = pango_font_description_get_size (gtk_widget_get_style (defbox)->font_desc); font_size = PANGO_PIXELS (font_size); @@ -1636,14 +1646,17 @@ set_window_default_size (GdictWindow *window) gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); width = MIN (width, monitor.width * 3 / 4); height = MIN (height, monitor.height * 3 / 4); + + window->default_width = width; + window->default_height = height; } /* Set default size */ gtk_window_set_default_size (GTK_WINDOW (widget), - width, - height); + window->default_width, + window->default_height); - if (is_maximized) + if (window->is_maximized) gtk_window_maximize (GTK_WINDOW (widget)); } @@ -1681,7 +1694,6 @@ gdict_window_constructor (GType type, { GObject *object; GdictWindow *window; - gint width, height, sidebar_width; gboolean is_maximized; GtkWidget *hbox; GtkWidget *handle; @@ -1697,11 +1709,14 @@ gdict_window_constructor (GType type, gboolean statusbar_visible; GtkAllocation allocation; - object = G_OBJECT_CLASS (gdict_window_parent_class)->constructor (type, - n_construct_properties, - construct_params); + object = G_OBJECT_CLASS (gdict_window_parent_class)->constructor (type, n_construct_properties, construct_params); window = GDICT_WINDOW (object); - + + window->in_construction = TRUE; + + /* recover the state */ + gdict_window_load_state (window); + gtk_widget_push_composite_child (); window->main_box = gtk_vbox_new (FALSE, 0); @@ -1815,6 +1830,7 @@ gdict_window_constructor (GType type, g_signal_connect (window->sidebar, "closed", G_CALLBACK (sidebar_closed_cb), window); + gtk_widget_show (window->sidebar); /* Speller */ window->speller = gdict_speller_new (); @@ -1843,6 +1859,11 @@ gdict_window_constructor (GType type, window->db_chooser); gtk_widget_show (window->db_chooser); + /* bind the database property to the database setting */ + g_settings_bind (window->settings, GDICT_SETTINGS_DATABASE_KEY, + window, "database", + G_SETTINGS_BIND_DEFAULT); + /* Strategy chooser */ if (window->context) gdict_strategy_chooser_set_context (GDICT_STRATEGY_CHOOSER (window->strat_chooser), @@ -1856,6 +1877,11 @@ gdict_window_constructor (GType type, window->strat_chooser); gtk_widget_show (window->strat_chooser); + /* bind the strategy property to the strategy setting */ + g_settings_bind (window->settings, GDICT_SETTINGS_STRATEGY_KEY, + window, "strategy", + G_SETTINGS_BIND_DEFAULT); + /* Source chooser */ window->source_chooser = gdict_source_chooser_new_with_loader (window->loader); g_signal_connect (window->source_chooser, "source-activated", @@ -1867,8 +1893,12 @@ gdict_window_constructor (GType type, window->source_chooser); gtk_widget_show (window->source_chooser); + /* bind the source-name property to the source setting */ + g_settings_bind (window->settings, GDICT_SETTINGS_SOURCE_KEY, + window, "source-name", + G_SETTINGS_BIND_DEFAULT); + gtk_container_add (GTK_CONTAINER (frame2), window->sidebar); - gtk_widget_show (window->sidebar); gtk_paned_pack1 (GTK_PANED (handle), frame1, TRUE, FALSE); gtk_paned_pack2 (GTK_PANED (handle), frame2, FALSE, TRUE); @@ -1878,86 +1908,72 @@ gdict_window_constructor (GType type, gtk_widget_show (window->defbox_frame); + if (window->sidebar_visible) + { + GtkAction *action; + + action = gtk_action_group_get_action (window->action_group, "ViewSidebar"); + gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE); + gtk_widget_show (window->sidebar_frame); + } + window->status = gtk_statusbar_new (); - gtk_statusbar_set_has_resize_grip (GTK_STATUSBAR (window->status), TRUE); gtk_box_pack_end (GTK_BOX (window->main_box), window->status, FALSE, FALSE, 0); - statusbar_visible = mateconf_client_get_bool (window->mateconf_client, - GDICT_MATECONF_STATUSBAR_VISIBLE_KEY, - NULL); - gdict_window_set_statusbar_visible (window, statusbar_visible); + if (window->statusbar_visible) + { + GtkAction *action; + + action = gtk_action_group_get_action (window->action_group, "ViewStatusbar"); + gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE); + gtk_widget_show (window->status); + } window->progress = gtk_progress_bar_new (); gtk_box_pack_end (GTK_BOX (window->status), window->progress, FALSE, FALSE, 0); - /* retrieve the font size from mateconf */ - font_name = gdict_mateconf_get_string_with_default (window->mateconf_client, - DOCUMENT_FONT_KEY, - GDICT_DEFAULT_DEFBOX_FONT); - + /* retrieve the document font size */ + font_name = g_settings_get_string (window->desktop_settings, DOCUMENT_FONT_KEY); gdict_window_set_defbox_font (window, font_name); font_desc = pango_font_description_from_string (font_name); g_free (font_name); - sidebar_visible = mateconf_client_get_bool (window->mateconf_client, - GDICT_MATECONF_SIDEBAR_VISIBLE_KEY, - NULL); - gdict_window_set_sidebar_visible (window, sidebar_visible); - - /* retrieve the window state from mateconf */ - is_maximized = mateconf_client_get_bool (window->mateconf_client, - GDICT_MATECONF_WINDOW_IS_MAXIMIZED_KEY, - NULL); - - width = mateconf_client_get_int (window->mateconf_client, - GDICT_MATECONF_WINDOW_WIDTH_KEY, - NULL); - height = mateconf_client_get_int (window->mateconf_client, - GDICT_MATECONF_WINDOW_HEIGHT_KEY, - NULL); - sidebar_width = mateconf_client_get_int (window->mateconf_client, - GDICT_MATECONF_SIDEBAR_WIDTH_KEY, - NULL); - sidebar_page = mateconf_client_get_string (window->mateconf_client, - GDICT_MATECONF_SIDEBAR_PAGE_KEY, - NULL); + g_settings_bind (window->desktop_settings, DOCUMENT_FONT_KEY, + window, "defbox-font", + G_SETTINGS_BIND_GET); /* if the (width, height) tuple is not defined, use the font to * calculate the right window geometry */ - if (width == -1 || height == -1) + if (window->default_width == -1 || window->default_height == -1) { gint font_size; + gint width, height; font_size = pango_font_description_get_size (font_desc); font_size = PANGO_PIXELS (font_size); width = MAX (GDICT_WINDOW_COLUMNS * font_size, GDICT_WINDOW_MIN_WIDTH); height = MAX (GDICT_WINDOW_ROWS * font_size, GDICT_WINDOW_MIN_HEIGHT); - } - else - { + window->default_width = width; window->default_height = height; } pango_font_description_free (font_desc); - window->is_maximized = is_maximized; - gtk_window_set_title (GTK_WINDOW (window), _("Dictionary")); gtk_window_set_default_size (GTK_WINDOW (window), - width, - height); - if (is_maximized) + window->default_width, + window->default_height); + if (window->is_maximized) gtk_window_maximize (GTK_WINDOW (window)); gtk_widget_get_allocation (GTK_WIDGET (window), &allocation); - gtk_paned_set_position (GTK_PANED (handle), allocation.width - sidebar_width); - if (sidebar_page) - { - gdict_sidebar_view_page (GDICT_SIDEBAR (window->sidebar), sidebar_page); - g_free (sidebar_page); - } + gtk_paned_set_position (GTK_PANED (handle), allocation.width - window->sidebar_width); + if (window->sidebar_page != NULL) + gdict_sidebar_view_page (GDICT_SIDEBAR (window->sidebar), window->sidebar_page); + else + gdict_sidebar_view_page (GDICT_SIDEBAR (window->sidebar), GDICT_SIDEBAR_SPELLER_PAGE); g_signal_connect (window, "delete-event", G_CALLBACK (gdict_window_delete_event_cb), @@ -1972,7 +1988,9 @@ gdict_window_constructor (GType type, gtk_widget_grab_focus (window->entry); gtk_widget_pop_composite_child (); - + + window->in_construction = FALSE; + return object; } @@ -1982,67 +2000,74 @@ gdict_window_class_init (GdictWindowClass *klass) GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - gobject_class->finalize = gdict_window_finalize; - gobject_class->dispose = gdict_window_dispose; - gobject_class->set_property = gdict_window_set_property; - gobject_class->get_property = gdict_window_get_property; - gobject_class->constructor = gdict_window_constructor; - - widget_class->style_set = gdict_window_style_set; - widget_class->size_allocate = gdict_window_size_allocate; - - g_object_class_install_property (gobject_class, - PROP_ACTION, - g_param_spec_enum ("action", - "Action", - "The default action performed by the window", - GDICT_TYPE_WINDOW_ACTION, - GDICT_WINDOW_ACTION_CLEAR, - (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY))); - g_object_class_install_property (gobject_class, - PROP_SOURCE_LOADER, - g_param_spec_object ("source-loader", - "Source Loader", - "The GdictSourceLoader to be used to load dictionary sources", - GDICT_TYPE_SOURCE_LOADER, - (G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY))); - g_object_class_install_property (gobject_class, - PROP_SOURCE_NAME, - g_param_spec_string ("source-name", - "Source Name", - "The name of the GdictSource to be used", - GDICT_DEFAULT_SOURCE_NAME, - (G_PARAM_READABLE | G_PARAM_WRITABLE))); - g_object_class_install_property (gobject_class, - PROP_PRINT_FONT, - g_param_spec_string ("print-font", - "Print Font", - "The font name to be used when printing", - GDICT_DEFAULT_PRINT_FONT, - (G_PARAM_READABLE | G_PARAM_WRITABLE))); - g_object_class_install_property (gobject_class, - PROP_DEFBOX_FONT, - g_param_spec_string ("defbox-font", - "Defbox Font", - "The font name to be used by the defbox widget", - GDICT_DEFAULT_DEFBOX_FONT, - (G_PARAM_READABLE | G_PARAM_WRITABLE))); - g_object_class_install_property (gobject_class, - PROP_WORD, - g_param_spec_string ("word", - "Word", - "The word to search", - NULL, - (G_PARAM_READABLE | G_PARAM_WRITABLE))); - g_object_class_install_property (gobject_class, - PROP_WINDOW_ID, - g_param_spec_uint ("window-id", - "Window ID", - "The unique identifier for this window", - 0, - G_MAXUINT, - 0, - G_PARAM_READABLE)); + gdict_window_properties[PROP_ACTION] = + g_param_spec_enum ("action", + "Action", + "The default action performed by the window", + GDICT_TYPE_WINDOW_ACTION, + GDICT_WINDOW_ACTION_CLEAR, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS | + G_PARAM_CONSTRUCT_ONLY); + + gdict_window_properties[PROP_SOURCE_LOADER] = + g_param_spec_object ("source-loader", + "Source Loader", + "The GdictSourceLoader to be used to load dictionary sources", + GDICT_TYPE_SOURCE_LOADER, + G_PARAM_READWRITE | + G_PARAM_STATIC_STRINGS | + G_PARAM_CONSTRUCT_ONLY); + + gdict_window_properties[PROP_SOURCE_NAME] = + g_param_spec_string ("source-name", + "Source Name", + "The name of the GdictSource to be used", + GDICT_DEFAULT_SOURCE_NAME, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + + gdict_window_properties[PROP_DATABASE] = + g_param_spec_string ("database", + "Database", + "The name of the database to search", + GDICT_DEFAULT_DATABASE, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + + gdict_window_properties[PROP_STRATEGY] = + g_param_spec_string ("strategy", + "Strategy", + "The name of the strategy", + GDICT_DEFAULT_STRATEGY, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + + gdict_window_properties[PROP_PRINT_FONT] = + g_param_spec_string ("print-font", + "Print Font", + "The font name to be used when printing", + GDICT_DEFAULT_PRINT_FONT, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + + gdict_window_properties[PROP_DEFBOX_FONT] = + g_param_spec_string ("defbox-font", + "Defbox Font", + "The font name to be used by the defbox widget", + GDICT_DEFAULT_DEFBOX_FONT, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + + gdict_window_properties[PROP_WORD] = + g_param_spec_string ("word", + "Word", + "The word to search", + NULL, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + + gdict_window_properties[PROP_WINDOW_ID] = + g_param_spec_uint ("window-id", + "Window ID", + "The unique identifier for this window", + 0, G_MAXUINT, + 0, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); gdict_window_signals[CREATED] = g_signal_new ("created", @@ -2053,58 +2078,32 @@ gdict_window_class_init (GdictWindowClass *klass) g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, GDICT_TYPE_WINDOW); + + gobject_class->finalize = gdict_window_finalize; + gobject_class->dispose = gdict_window_dispose; + gobject_class->set_property = gdict_window_set_property; + gobject_class->get_property = gdict_window_get_property; + gobject_class->constructor = gdict_window_constructor; + + g_object_class_install_properties (gobject_class, + LAST_PROP, + gdict_window_properties); + + widget_class->style_set = gdict_window_style_set; + widget_class->size_allocate = gdict_window_size_allocate; } static void gdict_window_init (GdictWindow *window) { - GError *mateconf_error; - window->action = GDICT_WINDOW_ACTION_CLEAR; window->loader = NULL; window->context = NULL; - window->mateconf_client = mateconf_client_get_default (); + window->settings = g_settings_new (GDICT_SETTINGS_SCHEMA); + window->desktop_settings = g_settings_new (DESKTOP_SETTINGS_SCHEMA); - mateconf_error = NULL; - mateconf_client_add_dir (window->mateconf_client, - GDICT_MATECONF_DIR, - MATECONF_CLIENT_PRELOAD_NONE, - &mateconf_error); - if (mateconf_error) - { - gdict_show_gerror_dialog (NULL, - _("Unable to connect to MateConf"), - mateconf_error); - } - - window->notify_id = mateconf_client_notify_add (window->mateconf_client, - GDICT_MATECONF_DIR, - gdict_window_mateconf_notify_cb, - window, - NULL, - &mateconf_error); - if (mateconf_error) - { - gdict_show_gerror_dialog (NULL, - _("Unable to get notification for preferences"), - mateconf_error); - } - - window->font_notify_id = mateconf_client_notify_add (window->mateconf_client, - DOCUMENT_FONT_KEY, - gdict_window_mateconf_notify_cb, - window, - NULL, - &mateconf_error); - if (mateconf_error) - { - gdict_show_gerror_dialog (NULL, - _("Unable to get notification for the document font"), - mateconf_error); - } - window->word = NULL; window->source_name = NULL; window->print_font = NULL; @@ -2116,6 +2115,9 @@ gdict_window_init (GdictWindow *window) window->default_width = -1; window->default_height = -1; window->is_maximized = FALSE; + window->sidebar_visible = FALSE; + window->statusbar_visible = FALSE; + window->sidebar_page = NULL; window->window_id = (gulong) time (NULL); @@ -2153,6 +2155,7 @@ gdict_window_new (GdictWindowAction action, gtk_entry_set_text (GTK_ENTRY (window->entry), word); gdict_window_set_word (window, word, NULL); break; + case GDICT_WINDOW_ACTION_MATCH: { GdictSource *source; @@ -2182,9 +2185,12 @@ gdict_window_new (GdictWindowAction action, gdict_speller_match (GDICT_SPELLER (window->speller), word); } + break; + case GDICT_WINDOW_ACTION_CLEAR: gdict_defbox_clear (GDICT_DEFBOX (window->defbox)); break; + default: g_assert_not_reached (); break; diff --git a/mate-dictionary/src/gdict-window.h b/mate-dictionary/src/gdict-window.h index ee68d6a2..f2353e92 100644 --- a/mate-dictionary/src/gdict-window.h +++ b/mate-dictionary/src/gdict-window.h @@ -23,9 +23,9 @@ #ifndef __GDICT_WINDOW_H__ #define __GDICT_WINDOW_H__ +#include <gio/gio.h> #include <gdk-pixbuf/gdk-pixbuf.h> #include <gtk/gtk.h> -#include <mateconf/mateconf-client.h> #include <libgdict/gdict.h> G_BEGIN_DECLS @@ -94,20 +94,24 @@ struct _GdictWindow gchar *strategy; gchar *print_font; gchar *defbox_font; - - MateConfClient *mateconf_client; - guint notify_id; - guint font_notify_id; + + GSettings *settings; + GSettings *desktop_settings; GdkCursor *busy_cursor; gint default_width; gint default_height; + gint current_width; + gint current_height; gint sidebar_width; - + + gchar *sidebar_page; + guint is_maximized : 1; guint sidebar_visible : 1; guint statusbar_visible : 1; + guint in_construction : 1; gulong window_id; }; |