From 8c30f31702202aed1b7e8c21b204a44ac2dc37cc Mon Sep 17 00:00:00 2001 From: Stefano Karapetsas Date: Sat, 24 Nov 2012 18:18:51 +0100 Subject: cpufreq: migrate to gsettings --- cpufreq/Makefile.am | 20 ++- cpufreq/README | 3 - cpufreq/cpufreq-applet.schemas.in | 36 ----- ...org.mate.panel.applet.cpufreq.gschema.xml.in.in | 20 +++ cpufreq/src/Makefile.am | 4 +- cpufreq/src/cpufreq-applet.c | 12 +- cpufreq/src/cpufreq-prefs.c | 150 +++++---------------- cpufreq/src/cpufreq-prefs.h | 3 +- 8 files changed, 71 insertions(+), 177 deletions(-) delete mode 100644 cpufreq/cpufreq-applet.schemas.in create mode 100644 cpufreq/org.mate.panel.applet.cpufreq.gschema.xml.in.in diff --git a/cpufreq/Makefile.am b/cpufreq/Makefile.am index f2b4f80e..e6a63607 100644 --- a/cpufreq/Makefile.am +++ b/cpufreq/Makefile.am @@ -1,10 +1,11 @@ SUBDIRS = help pixmaps src -schemasdir = @MATECONF_SCHEMA_FILE_DIR@ -schemas_in_files = cpufreq-applet.schemas.in -schemas_DATA = $(schemas_in_files:.schemas.in=.schemas) +@INTLTOOL_XML_NOMERGE_RULE@ +gsettings_SCHEMAS = org.mate.panel.applet.cpufreq.gschema.xml +@GSETTINGS_RULES@ -@INTLTOOL_SCHEMAS_RULE@ +%.gschema.xml.in: %.gschema.xml.in.in Makefile + $(AM_V_GEN) $(SED) -e 's^\@GETTEXT_PACKAGE\@^$(GETTEXT_PACKAGE)^g' < $< > $@ appletdir = $(datadir)/mate-panel/applets applet_in_files = org.mate.applets.CPUFreqApplet.mate-panel-applet.in @@ -32,23 +33,20 @@ builder_DATA = cpufreq-preferences.ui uidir = $(datadir)/mate-2.0/ui ui_DATA = cpufreq-applet-menu.xml -if MATECONF_SCHEMAS_INSTALL -install-data-local: - -MATECONF_CONFIG_SOURCE=$(MATECONF_SCHEMA_CONFIG_SOURCE) $(MATECONFTOOL) --makefile-install-rule $(top_builddir)/cpufreq/$(schemas_DATA) ; -endif - CLEANFILES = \ $(applet_DATA) \ $(applet_DATA).in \ $(service_DATA) \ - cpufreq-applet.schemas \ + $(gsettings_SCHEMAS_in) \ + $(gsettings_SCHEMAS) \ + *.gschema.valid \ *.bak \ *.gladep EXTRA_DIST = \ org.mate.applets.CPUFreqApplet.mate-panel-applet.in.in \ $(service_in_files) \ - $(schemas_in_files) \ + $(gsettings_SCHEMAS_in_in) \ $(builder_DATA) \ $(ui_DATA) diff --git a/cpufreq/README b/cpufreq/README index 45b6e2f2..a4d516af 100644 --- a/cpufreq/README +++ b/cpufreq/README @@ -13,10 +13,7 @@ FEATURES PREREQUISITES ------------- - - MATE 2 libraries - MATE Panel libraries - - MATE-VFS libraries - - MateConf FREQUENCY SELECTOR diff --git a/cpufreq/cpufreq-applet.schemas.in b/cpufreq/cpufreq-applet.schemas.in deleted file mode 100644 index 88ed4684..00000000 --- a/cpufreq/cpufreq-applet.schemas.in +++ /dev/null @@ -1,36 +0,0 @@ - - - - - /schemas/apps/cpufreq-applet/prefs/cpu - cpufreq-applet - int - 0 - - CPU to Monitor - Set the CPU to monitor. In a single processor system you don't have to change it. - - - - /schemas/apps/cpufreq-applet/prefs/show_mode - cpufreq-applet - int - 2 - - Mode to show cpu usage - A 0 value means to show the applet in graphic mode (pixmap only), 1 to show the applet in text mode (not to show the pixmap) and 2 to show the applet in graphic and text mode. - - - - /schemas/apps/cpufreq-applet/prefs/show_text_mode - cpufreq-applet - int - 1 - - The type of text to display (if the text is enabled). - A 0 value means to show cpu frequency, 1 to show frequency and units, and 2 to show percentage instead of frequency. - - - - - diff --git a/cpufreq/org.mate.panel.applet.cpufreq.gschema.xml.in.in b/cpufreq/org.mate.panel.applet.cpufreq.gschema.xml.in.in new file mode 100644 index 00000000..7f306a7e --- /dev/null +++ b/cpufreq/org.mate.panel.applet.cpufreq.gschema.xml.in.in @@ -0,0 +1,20 @@ + + + + + 0 + CPU to Monitor + Set the CPU to monitor. In a single processor system you don't have to change it. + + + 2 + Mode to show cpu usage + A 0 value means to show the applet in graphic mode (pixmap only), 1 to show the applet in text mode (not to show the pixmap) and 2 to show the applet in graphic and text mode. + + + 1 + The type of text to display (if the text is enabled). + A 0 value means to show cpu frequency, 1 to show frequency and units, and 2 to show percentage instead of frequency. + + + diff --git a/cpufreq/src/Makefile.am b/cpufreq/src/Makefile.am index db5679d0..d51e1529 100644 --- a/cpufreq/src/Makefile.am +++ b/cpufreq/src/Makefile.am @@ -6,7 +6,7 @@ SUBDIRS = $(selector_SUBDIR) INCLUDES = \ -DCPUFREQ_MENU_UI_DIR=\""$(datadir)/mate-2.0/ui"\" \ - $(MATE_APPLETS3_CFLAGS) \ + $(MATE_APPLETS4_CFLAGS) \ $(LIBGLADE_CFLAGS) \ $(DBUS_CFLAGS) @@ -30,7 +30,7 @@ cpufreq_applet_SOURCES = \ cpufreq-monitor-cpuinfo.c cpufreq-monitor-cpuinfo.h cpufreq_applet_LDADD = \ - $(MATE_APPLETS3_LIBS) \ + $(MATE_APPLETS4_LIBS) \ $(LIBGLADE_LIBS) \ $(LIBCPUFREQ_LIBS) \ $(DBUS_LIBS) diff --git a/cpufreq/src/cpufreq-applet.c b/cpufreq/src/cpufreq-applet.c index 6937fd04..acc24ddb 100644 --- a/cpufreq/src/cpufreq-applet.c +++ b/cpufreq/src/cpufreq-applet.c @@ -25,8 +25,9 @@ #include #include +#include #include -#include +#include #include #include #include @@ -942,21 +943,18 @@ cpufreq_applet_setup (CPUFreqApplet *applet) gchar *ui_path; AtkObject *atk_obj; gchar *prefs_key; + GSettings *settings; g_set_application_name (_("CPU Frequency Scaling Monitor")); gtk_window_set_default_icon_name ("mate-cpu-frequency-applet"); - mate_panel_applet_add_preferences (MATE_PANEL_APPLET (applet), - "/schemas/apps/cpufreq-applet/prefs", NULL); - /* Preferences */ if (applet->prefs) g_object_unref (applet->prefs); - prefs_key = mate_panel_applet_get_preferences_key (MATE_PANEL_APPLET (applet)); - applet->prefs = cpufreq_prefs_new (prefs_key); - g_free (prefs_key); + settings = mate_panel_applet_settings_new (MATE_PANEL_APPLET (applet), "org.mate.panel.applet.cpufreq"); + applet->prefs = cpufreq_prefs_new (settings); g_signal_connect (G_OBJECT (applet->prefs), "notify::cpu", diff --git a/cpufreq/src/cpufreq-prefs.c b/cpufreq/src/cpufreq-prefs.c index cf057829..38c0ca07 100644 --- a/cpufreq/src/cpufreq-prefs.c +++ b/cpufreq/src/cpufreq-prefs.c @@ -25,22 +25,21 @@ #include #include -#include +#include #include "cpufreq-prefs.h" #include "cpufreq-utils.h" enum { PROP_0, - PROP_MATECONF_KEY, + PROP_GSETTINGS, PROP_CPU, PROP_SHOW_MODE, PROP_SHOW_TEXT_MODE, }; struct _CPUFreqPrefsPrivate { - MateConfClient *mateconf_client; - gchar *mateconf_key; + GSettings *settings; guint cpu; CPUFreqShowMode show_mode; @@ -82,8 +81,7 @@ cpufreq_prefs_init (CPUFreqPrefs *prefs) { prefs->priv = CPUFREQ_PREFS_GET_PRIVATE (prefs); - prefs->priv->mateconf_client = mateconf_client_get_default (); - prefs->priv->mateconf_key = NULL; + prefs->priv->settings = NULL; prefs->priv->cpu = 0; } @@ -100,10 +98,10 @@ cpufreq_prefs_class_init (CPUFreqPrefsClass *klass) /* Properties */ g_object_class_install_property (g_object_class, - PROP_MATECONF_KEY, - g_param_spec_string ("mateconf-key", - "MateConfKey", - "The applet mateconf key", + PROP_GSETTINGS, + g_param_spec_string ("gsettings", + "GSettings", + "The applet gsettings object", NULL, G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); @@ -141,14 +139,9 @@ cpufreq_prefs_finalize (GObject *object) { CPUFreqPrefs *prefs = CPUFREQ_PREFS (object); - if (prefs->priv->mateconf_client) { - g_object_unref (prefs->priv->mateconf_client); - prefs->priv->mateconf_client = NULL; - } - - if (prefs->priv->mateconf_key) { - g_free (prefs->priv->mateconf_key); - prefs->priv->mateconf_key = NULL; + if (prefs->priv->settings) { + g_object_unref (prefs->priv->settings); + prefs->priv->settings = NULL; } if (prefs->priv->dialog) { @@ -169,25 +162,17 @@ cpufreq_prefs_set_property (GObject *object, gboolean update_sensitivity = FALSE; switch (prop_id) { - case PROP_MATECONF_KEY: - prefs->priv->mateconf_key = g_value_dup_string (value); + case PROP_GSETTINGS: + prefs->priv->settings = g_value_get_object (value); break; case PROP_CPU: { guint cpu; cpu = g_value_get_uint (value); if (prefs->priv->cpu != cpu) { - gchar *key; - prefs->priv->cpu = cpu; - key = g_strjoin ("/", - prefs->priv->mateconf_key, - "cpu", - NULL); - mateconf_client_set_int (prefs->priv->mateconf_client, - key, prefs->priv->cpu, - NULL); - g_free (key); + g_settings_set_int (prefs->priv->settings, + "cpu", prefs->priv->cpu); } } break; @@ -196,18 +181,10 @@ cpufreq_prefs_set_property (GObject *object, mode = g_value_get_enum (value); if (prefs->priv->show_mode != mode) { - gchar *key; - update_sensitivity = TRUE; prefs->priv->show_mode = mode; - key = g_strjoin ("/", - prefs->priv->mateconf_key, - "show_mode", - NULL); - mateconf_client_set_int (prefs->priv->mateconf_client, - key, prefs->priv->show_mode, - NULL); - g_free (key); + g_settings_set_int (prefs->priv->settings, + "show-mode", prefs->priv->show_mode); } } break; @@ -216,18 +193,10 @@ cpufreq_prefs_set_property (GObject *object, mode = g_value_get_enum (value); if (prefs->priv->show_text_mode != mode) { - gchar *key; - update_sensitivity = TRUE; prefs->priv->show_text_mode = mode; - key = g_strjoin ("/", - prefs->priv->mateconf_key, - "show_text_mode", - NULL); - mateconf_client_set_int (prefs->priv->mateconf_client, - key, prefs->priv->show_text_mode, - NULL); - g_free (key); + g_settings_set_int (prefs->priv->settings, + "show-text-mode", prefs->priv->show_text_mode); } } break; @@ -248,7 +217,7 @@ cpufreq_prefs_get_property (GObject *object, CPUFreqPrefs *prefs = CPUFREQ_PREFS (object); switch (prop_id) { - case PROP_MATECONF_KEY: + case PROP_GSETTINGS: /* Is not readable */ break; case PROP_CPU: @@ -268,72 +237,23 @@ cpufreq_prefs_get_property (GObject *object, static void cpufreq_prefs_setup (CPUFreqPrefs *prefs) { - guint cpu; - CPUFreqShowMode show_mode; - CPUFreqShowTextMode show_text_mode; - gchar *key; - GError *error = NULL; - - g_assert (MATECONF_IS_CLIENT (prefs->priv->mateconf_client)); - g_assert (prefs->priv->mateconf_key != NULL); - - key = g_strjoin ("/", prefs->priv->mateconf_key, "cpu", NULL); - cpu = mateconf_client_get_int (prefs->priv->mateconf_client, - key, &error); - g_free (key); - /* In case anything went wrong with mateconf, get back to the default */ - if (error) { - g_warning ("%s", error->message); - cpu = 0; - g_error_free (error); - error = NULL; - } - prefs->priv->cpu = cpu; - - key = g_strjoin ("/", prefs->priv->mateconf_key, "show_mode", NULL); - show_mode = mateconf_client_get_int (prefs->priv->mateconf_client, - key, &error); - g_free (key); - /* In case anything went wrong with mateconf, get back to the default */ - if (error || - show_mode < CPUFREQ_MODE_GRAPHIC || - show_mode > CPUFREQ_MODE_BOTH) { - show_mode = CPUFREQ_MODE_BOTH; - if (error) { - g_warning ("%s", error->message); - g_error_free (error); - error = NULL; - } - } - prefs->priv->show_mode = show_mode; - - key = g_strjoin ("/", prefs->priv->mateconf_key, "show_text_mode", NULL); - show_text_mode = mateconf_client_get_int (prefs->priv->mateconf_client, - key, &error); - g_free (key); - /* In case anything went wrong with mateconf, get back to the default */ - if (error || - show_text_mode < CPUFREQ_MODE_TEXT_FREQUENCY || - show_text_mode > CPUFREQ_MODE_TEXT_PERCENTAGE) { - show_text_mode = CPUFREQ_MODE_TEXT_FREQUENCY_UNIT; - if (error) { - g_warning ("%s", error->message); - g_error_free (error); - error = NULL; - } - } - prefs->priv->show_text_mode = show_text_mode; + g_assert (G_IS_SETTINGS (prefs->priv->settings)); + g_assert (prefs->priv->settings != NULL); + + prefs->priv->cpu = g_settings_get_int (prefs->priv->settings, "cpu"); + prefs->priv->show_mode = g_settings_get_int (prefs->priv->settings, "show-mode"); + prefs->priv->show_text_mode = g_settings_get_int (prefs->priv->settings, "show-text-mode"); } CPUFreqPrefs * -cpufreq_prefs_new (const gchar *mateconf_key) +cpufreq_prefs_new (GSettings *settings) { CPUFreqPrefs *prefs; - g_return_val_if_fail (mateconf_key != NULL, NULL); + g_return_val_if_fail (settings != NULL, NULL); prefs = CPUFREQ_PREFS (g_object_new (CPUFREQ_TYPE_PREFS, - "mateconf-key", mateconf_key, + "gsettings", settings, NULL)); cpufreq_prefs_setup (prefs); @@ -373,14 +293,10 @@ static gboolean cpufreq_prefs_key_is_writable (CPUFreqPrefs *prefs, const gchar *key) { gboolean writable; - gchar *fullkey; - g_assert (prefs->priv->mateconf_client != NULL); + g_assert (prefs->priv->settings != NULL); - fullkey = g_strjoin ("/", prefs->priv->mateconf_key, key, NULL); - writable = mateconf_client_key_is_writable (prefs->priv->mateconf_client, - fullkey, NULL); - g_free (fullkey); + writable = g_settings_is_writable (prefs->priv->settings, key); return writable; } @@ -498,12 +414,12 @@ static void cpufreq_prefs_dialog_update_sensitivity (CPUFreqPrefs *prefs) { gtk_widget_set_sensitive (prefs->priv->show_mode_combo, - cpufreq_prefs_key_is_writable (prefs, "show_mode")); + cpufreq_prefs_key_is_writable (prefs, "show-mode")); if (prefs->priv->show_mode != CPUFREQ_MODE_GRAPHIC) { gboolean key_writable; - key_writable = cpufreq_prefs_key_is_writable (prefs, "show_text_mode"); + key_writable = cpufreq_prefs_key_is_writable (prefs, "show-text-mode"); gtk_widget_set_sensitive (prefs->priv->show_freq, (TRUE && key_writable)); diff --git a/cpufreq/src/cpufreq-prefs.h b/cpufreq/src/cpufreq-prefs.h index 6a695cb6..760d9621 100644 --- a/cpufreq/src/cpufreq-prefs.h +++ b/cpufreq/src/cpufreq-prefs.h @@ -24,6 +24,7 @@ #include #include +#include #include "cpufreq-applet.h" G_BEGIN_DECLS @@ -51,7 +52,7 @@ struct _CPUFreqPrefsClass { GType cpufreq_prefs_get_type (void) G_GNUC_CONST; -CPUFreqPrefs *cpufreq_prefs_new (const gchar *mateconf_key); +CPUFreqPrefs *cpufreq_prefs_new (GSettings *settings); guint cpufreq_prefs_get_cpu (CPUFreqPrefs *prefs); CPUFreqShowMode cpufreq_prefs_get_show_mode (CPUFreqPrefs *prefs); -- cgit v1.2.1