diff options
-rw-r--r-- | Makefile.am | 56 | ||||
-rw-r--r-- | SensorsApplet.server.in.in | 25 | ||||
-rw-r--r-- | SensorsApplet.xml | 12 | ||||
-rw-r--r-- | configure.ac | 15 | ||||
-rw-r--r-- | org.mate.applets.sensors-applet.mate-panel-applet.in.in | 10 | ||||
-rw-r--r-- | org.mate.panel.applet.SensorsAppletFactory.service.in | 3 | ||||
-rw-r--r-- | org.mate.sensors-applet.gschema.xml.in.in | 40 | ||||
-rw-r--r-- | org.mate.sensors-applet.sensor.gschema.xml.in.in | 68 | ||||
-rw-r--r-- | po/POTFILES.in | 7 | ||||
-rw-r--r-- | sensors-applet/Makefile.am | 8 | ||||
-rw-r--r-- | sensors-applet/about-dialog.c | 3 | ||||
-rw-r--r-- | sensors-applet/active-sensor.c | 64 | ||||
-rw-r--r-- | sensors-applet/main.c | 17 | ||||
-rw-r--r-- | sensors-applet/prefs-dialog.c | 71 | ||||
-rw-r--r-- | sensors-applet/sensor-config-dialog.c | 2 | ||||
-rw-r--r-- | sensors-applet/sensors-applet-mateconf.c | 491 | ||||
-rw-r--r-- | sensors-applet/sensors-applet-mateconf.h | 91 | ||||
-rw-r--r-- | sensors-applet/sensors-applet-settings.c | 142 | ||||
-rw-r--r-- | sensors-applet/sensors-applet-settings.h | 56 | ||||
-rw-r--r-- | sensors-applet/sensors-applet.c | 233 | ||||
-rw-r--r-- | sensors-applet/sensors-applet.h | 10 |
21 files changed, 557 insertions, 867 deletions
diff --git a/Makefile.am b/Makefile.am index 92e4a14..9fa1568 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,28 +1,54 @@ SUBDIRS = sensors-applet lib plugins pixmaps po help -serverdir = $(libdir)/matecomponent/servers -server_in_files = SensorsApplet.server.in -server_DATA = $(server_in_files:.server.in=.server) +appletdir = $(datadir)/mate-panel/applets +applet_in_files = org.mate.applets.sensors-applet.mate-panel-applet.in +applet_DATA = $(applet_in_files:.mate-panel-applet.in=.mate-panel-applet) -$(server_in_files): $(server_in_files:.server.in=.server.in.in) Makefile - sed -e "s|\@DATADIR\@|$(datadir)|" -e "s|\@LIBEXECDIR\@|$(libexecdir)|" -e "s|\@PACKAGE\@|$(PACKAGE)|" $< > $@ +$(applet_in_files): $(applet_in_files).in Makefile + $(AM_V_GEN)sed \ + -e "s|\@LIBEXECDIR\@|$(libexecdir)|" \ + $< > $@ -@INTLTOOL_SERVER_RULE@ +%.mate-panel-applet: %.mate-panel-applet.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache -uidir = $(datadir)/mate-2.0/ui +uidir = $(datadir)/mate-sensors-applet/ui ui_DATA = SensorsApplet.xml -CLEANFILES = $(server_in_files) \ - $(server_DATA) - -EXTRA_DIST = $(ui_DATA) \ - $(server_DATA:.server=.server.in.in) \ - intltool-merge.in intltool-extract.in intltool-update.in \ - mate-doc-utils.make +servicedir = $(datadir)/dbus-1/services +service_in_files = org.mate.panel.applet.SensorsAppletFactory.service.in +service_DATA = $(service_in_files:.service.in=.service) + +org.mate.panel.applet.SensorsAppletFactory.service: $(service_in_files) + $(AM_V_GEN)sed \ + -e "s|\@LIBEXECDIR\@|$(libexecdir)|" \ + $< > $@ + +@INTLTOOL_XML_NOMERGE_RULE@ +gsettings_SCHEMAS = \ + org.mate.sensors-applet.gschema.xml \ + org.mate.sensors-applet.sensor.gschema.xml +@GSETTINGS_RULES@ + +%.gschema.xml.in: %.gschema.xml.in.in Makefile + $(AM_V_GEN) $(SED) \ + -e 's^\@GETTEXT_PACKAGE\@^$(GETTEXT_PACKAGE)^g' \ + < $< > $@ + +CLEANFILES = $(applet_DATA) \ + $(applet_DATA).in \ + $(service_DATA) \ + $(gsettings_SCHEMAS_in) \ + $(gsettings_SCHEMAS) \ + *.gschema.valid + +EXTRA_DIST = $(ui_DATA) \ + $(applet_in_files).in \ + $(service_in_files) \ + $(gsettings_SCHEMAS_in_in) DISTCLEANFILES = mate-doc-utils.make \ intltool-extract \ intltool-merge \ intltool-update -DISTCHECK_CONFIGURE_FLAGS = --disable-scrollkeeper
\ No newline at end of file +DISTCHECK_CONFIGURE_FLAGS = --disable-scrollkeeper diff --git a/SensorsApplet.server.in.in b/SensorsApplet.server.in.in deleted file mode 100644 index 42524f3..0000000 --- a/SensorsApplet.server.in.in +++ /dev/null @@ -1,25 +0,0 @@ -<oaf_info> -<oaf_server iid="OAFIID:SensorsApplet_Factory" type="exe" location="@LIBEXECDIR@/@PACKAGE@"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:MateComponent/GenericFactory:1.0"/> - <item value="IDL:MateComponent/Unknown:1.0"/> - </oaf_attribute> - <oaf_attribute name="name" type="string" value="Sensors Applet Factory"/> - <oaf_attribute name="description" type="string" value="Factory to create the Sensors Applet"/> -</oaf_server> - -<oaf_server iid="OAFIID:SensorsApplet" type="factory" - location="OAFIID:SensorsApplet_Factory"> - - <oaf_attribute name="repo_ids" type="stringv"> - <item value="IDL:MATE/Vertigo/MatePanelAppletShell:1.0"/> - <item value="IDL:MateComponent/Control:1.0"/> - <item value="IDL:MateComponent/Unknown:1.0"/> - </oaf_attribute> - <oaf_attribute name="name" type="string" _value="Hardware Sensors Monitor"/> - <oaf_attribute name="description" type="string" _value="Display temperature, fan speed and voltage sensor readings"/> - <oaf_attribute name="panel:category" type="string" value="System & Hardware"/> - <oaf_attribute name="panel:icon" type="string" value="mate-sensors-applet"/> -</oaf_server> -</oaf_info> diff --git a/SensorsApplet.xml b/SensorsApplet.xml index 5cd219e..8b37a39 100644 --- a/SensorsApplet.xml +++ b/SensorsApplet.xml @@ -1,9 +1,3 @@ -<Root> - <popups> - <popup name="button3"> - <menuitem name="Preferences Item" verb="Preferences" _label="_Preferences" pixtype="stock" pixname="gtk-properties" /> - <menuitem name="Help Item" verb="Help" _label="_Help" pixtype="stock" pixname="gtk-help" /> - <menuitem name="About Item" verb="About" _label="_About" pixtype="stock" pixname="gtk-about" /> - </popup> - </popups> -</Root> +<menuitem name="Preferences Item" action="Preferences"/> +<menuitem name="Help Item" action="Help"/> +<menuitem name="About Item" action="About"/> diff --git a/configure.ac b/configure.ac index 4210b3b..53d17b2 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,5 @@ # ================= initialization =================== # -# if doing version bump - make sure you update sensors-applet-mateconf -# version checking to add old version if no changes to config AC_INIT([MATE Sensors Applet], [1.4.0], [http://www.mate-desktop.org], [mate-sensors-applet]) @@ -48,17 +46,15 @@ AC_CHECK_HEADERS( dlfcn.h ) -GLIB_REQUIRED=2.14.0 +GLIB_REQUIRED=2.26.0 GTK_REQUIRED=2.14.0 LIBPANEL_REQUIRED=1.1.0 -LIBMATE_REQUIRED=1.1.0 -LIBMATEUI_REQUIRED=1.1.0 LIBMATENOTIFY_REQUIRED=1.1.0 LIBCAIRO_REQUIRED=1.0.4 LIBDBUSGLIB_REQUIRED=0.80 LIBATASMART_REQUIRED=0.16 -PKG_CHECK_MODULES(GLIB, glib-2.0 >= $GLIB_REQUIRED) +PKG_CHECK_MODULES(GLIB, glib-2.0 >= $GLIB_REQUIRED gio-2.0) AC_SUBST(GLIB_CFLAGS) AC_SUBST(GLIB_LIBS) @@ -66,9 +62,7 @@ PKG_CHECK_MODULES(GTK, gtk+-2.0 >= $GTK_REQUIRED) AC_SUBST(GTK_CFLAGS) AC_SUBST(GTK_LIBS) -PKG_CHECK_MODULES(MATE, libmate-2.0 >= $LIBMATE_REQUIRED - libmateui-2.0 >= $LIBMATEUI_REQUIRED - libmatepanelapplet-2.0 >= $LIBPANEL_REQUIRED) +PKG_CHECK_MODULES(MATE, libmatepanelapplet-4.0 >= $LIBPANEL_REQUIRED) AC_SUBST(MATE_CFLAGS) AC_SUBST(MATE_LIBS) @@ -256,6 +250,9 @@ MATE_COMPILE_WARNINGS(maximum) # ================ mate-doc-utils stuff ============= # MATE_DOC_INIT +# ================ GSettings stuff ============= # +GLIB_GSETTINGS + # ==================== plugin stuff ================== # PLUGIN_LIBTOOL_FLAGS="-module -avoid-version" AC_SUBST(PLUGIN_LIBTOOL_FLAGS) diff --git a/org.mate.applets.sensors-applet.mate-panel-applet.in.in b/org.mate.applets.sensors-applet.mate-panel-applet.in.in new file mode 100644 index 0000000..b231b4f --- /dev/null +++ b/org.mate.applets.sensors-applet.mate-panel-applet.in.in @@ -0,0 +1,10 @@ +[Applet Factory] +Id=SensorsAppletFactory +Location=@LIBEXECDIR@/mate-sensors-applet +_Name=Sensors Applet Factory +_Description=Sensors Applet Factory + +[SensorsApplet] +_Name=Hardware Sensors Monitor +_Description=Displays temperature, fan speed and voltage sensor readings +Icon=mate-sensors-applet diff --git a/org.mate.panel.applet.SensorsAppletFactory.service.in b/org.mate.panel.applet.SensorsAppletFactory.service.in new file mode 100644 index 0000000..bfc5310 --- /dev/null +++ b/org.mate.panel.applet.SensorsAppletFactory.service.in @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=org.mate.panel.applet.SensorsAppletFactory +Exec=@LIBEXECDIR@/mate-sensors-applet diff --git a/org.mate.sensors-applet.gschema.xml.in.in b/org.mate.sensors-applet.gschema.xml.in.in new file mode 100644 index 0000000..bd905ad --- /dev/null +++ b/org.mate.sensors-applet.gschema.xml.in.in @@ -0,0 +1,40 @@ +<schemalist gettext-domain="@GETTEXT_PACKAGE@"> + <schema id="org.mate.sensors-applet"> + <key name="font-size" type="i"> + <default>0</default> + <_summary>Font size in points</_summary> + </key> + <key name="hide-units" type="b"> + <default>false</default> + <_summary>Specify if show or hide sensor units</_summary> + </key> + <key name="display-mode" type="i"> + <default>1</default> + <_summary>Set if display icons or text labels</_summary> + </key> + <key name="layout-mode" type="i"> + <default>0</default> + <_summary>Set value beside or below label</_summary> + </key> + <key name="temperature-scale" type="i"> + <default>1</default> + <_summary>Show temperature in Kelvin, Celsius or Fahrenheit </_summary> + </key> + <key name="display-notifications" type="b"> + <default>true</default> + <_summary>Whether to display notifications</_summary> + </key> + <key name="timeout-delay" type="i"> + <default>2000</default> + <_summary>Delay (in ms) between refreshes</_summary> + </key> + <key name="graph-size" type="i"> + <default>42</default> + <_summary>The size of the graph in pixels (width if horizontal, height if vertical)</_summary> + </key> + <key name="sensors-list" type="as"> + <default>[]</default> + <_summary>List of sensors</_summary> + </key> + </schema> +</schemalist> diff --git a/org.mate.sensors-applet.sensor.gschema.xml.in.in b/org.mate.sensors-applet.sensor.gschema.xml.in.in new file mode 100644 index 0000000..dc8bb8b --- /dev/null +++ b/org.mate.sensors-applet.sensor.gschema.xml.in.in @@ -0,0 +1,68 @@ +<schemalist gettext-domain="@GETTEXT_PACKAGE@"> + <schema id="org.mate.sensors-applet.sensor"> + <key name="path" type="s"> + <default>''</default> + <_summary>Path to filename</_summary> + </key> + <key name="id" type="s"> + <default>''</default> + <_summary>Sensor device ids</_summary> + </key> + <key name="interface" type="s"> + <default>''</default> + <_summary>The sensor device interface</_summary> + </key> + <key name="label" type="s"> + <default>''</default> + <_summary>User defined label</_summary> + </key> + <key name="enabled" type="b"> + <default>true</default> + <_summary>Whether a sensor is enabled or not</_summary> + </key> + <key name="low-value" type="d"> + <default>0</default> + <_summary>Low value</_summary> + </key> + <key name="high-value" type="d"> + <default>0</default> + <_summary>High value</_summary> + </key> + <key name="alarm-enabled" type="b"> + <default>false</default> + <_summary>Whether the sensor has its alarm enabled</_summary> + </key> + <key name="low-alarm-command" type="s"> + <default>''</default> + <_summary>Command to execute when the alarm is activated</_summary> + </key> + <key name="high-alarm-command" type="s"> + <default>''</default> + <_summary>Command to execute when the alarm is activated</_summary> + </key> + <key name="alarm-timeout" type="i"> + <default>0</default> + <_summary>How often each alarm should be sounded (in seconds)</_summary> + </key> + <key name="sensor-type" type="i"> + <default>0</default> + <_summary>Used to identify a sensor in a list</_summary> + </key> + <key name="multiplier" type="d"> + <default>1</default> + <_summary>Multiplier</_summary> + </key> + <key name="offset" type="d"> + <default>0</default> + <_summary>Offset</_summary> + </key> + <key name="icon-type" type="i"> + <default>0</default> + <_summary>Icon type</_summary> + </key> + <key name="graph-color" type="s"> + <default>'#ff0000'</default> + <_summary>Color of the graph for the sensor</_summary> + </key> + </schema> +</schemalist> diff --git a/po/POTFILES.in b/po/POTFILES.in index 0a7f17d..36556b2 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,5 +1,6 @@ -SensorsApplet.server.in.in -SensorsApplet.xml +org.mate.applets.sensors-applet.mate-panel-applet.in.in +org.mate.sensors-applet.gschema.xml.in.in +org.mate.sensors-applet.sensor.gschema.xml.in.in plugins/pmu-sys/pmu-sys-plugin.c plugins/i2c-sys/i2c-sys-plugin.c plugins/i8k/i8k-plugin.c @@ -18,4 +19,4 @@ sensors-applet/active-sensor.c sensors-applet/about-dialog.c sensors-applet/sensor-config-dialog.c sensors-applet/sensors-applet.c -sensors-applet/sensors-applet-mateconf.c +sensors-applet/sensors-applet-settings.c diff --git a/sensors-applet/Makefile.am b/sensors-applet/Makefile.am index ce3cb01..7ea2099 100644 --- a/sensors-applet/Makefile.am +++ b/sensors-applet/Makefile.am @@ -1,9 +1,13 @@ ## Process this file with automake to produce Makefile.in + +uidir = $(datadir)/mate-sensors-applet/ui + INCLUDES = -DMATELOCALEDIR=\""$(datadir)/locale/"\" \ -DG_LOG_DOMAIN=\""Sensors Applet"\" \ -DPIXMAPS_DIR=\""$(datadir)/pixmaps/$(PACKAGE)/"\" \ -DDATADIR=\""$(datadir)"\" \ -DLIBDIR=\""$(libdir)"\" \ + -DUIDIR=\""$(pkgdatadir)/ui"\" \ -DSENSORS_APPLET_PLUGIN_DIR=\""$(libdir)/$(PACKAGE)/plugins/"\" \ -DSYSCONFDIR=\""$(sysconfdir)"\" \ -DPREFIX=\""$(prefix)"\" \ @@ -35,8 +39,8 @@ mate_sensors_applet_SOURCES = main.c \ sensors-applet-sensor.h \ sensors-applet-plugins.c \ sensors-applet-plugins.h \ - sensors-applet-mateconf.c \ - sensors-applet-mateconf.h \ + sensors-applet-settings.c \ + sensors-applet-settings.h \ $(libmatenotify_SRC) # install headers for plugins to use diff --git a/sensors-applet/about-dialog.c b/sensors-applet/about-dialog.c index cdb9d23..39603b2 100644 --- a/sensors-applet/about-dialog.c +++ b/sensors-applet/about-dialog.c @@ -20,7 +20,8 @@ #include "config.h" #endif /* HAVE_CONFIG_H */ -#include <mate.h> +#include <glib/gi18n.h> +#include <gtk/gtk.h> #include "about-dialog.h" void about_dialog_open(SensorsApplet *sensors_applet) { diff --git a/sensors-applet/active-sensor.c b/sensors-applet/active-sensor.c index f7cb83c..94cc707 100644 --- a/sensors-applet/active-sensor.c +++ b/sensors-applet/active-sensor.c @@ -24,12 +24,14 @@ #include <string.h> #endif /* HAVE_STRING_H */ -#include <mateconf/mateconf-client.h> -#include <mate.h> +#include <glib.h> +#include <glib/gi18n.h> +#include <gtk/gtk.h> +#include <gio/gio.h> #include "active-sensor.h" #include "sensors-applet-plugins.h" -#include "sensors-applet-mateconf.h" +#include "sensors-applet-settings.h" typedef enum { VERY_LOW_SENSOR_VALUE = 0, @@ -73,18 +75,21 @@ static SensorValueRange sensor_value_range(gdouble sensor_value, static gboolean active_sensor_execute_alarm(ActiveSensor *active_sensor, NotifType notif_type) { - int pid; + gboolean ret; + GError *error = NULL; sensors_applet_notify_active_sensor(active_sensor, notif_type); g_debug("EXECUTING %s ALARM: %s", (notif_type == LOW_ALARM ? "LOW" : "HIGH"), active_sensor->alarm_command[notif_type]); - pid = mate_execute_shell(NULL, - active_sensor->alarm_command[notif_type]); - g_debug("Command executed in shell with pid %d", pid); + ret = g_spawn_command_line_async (active_sensor->alarm_command[notif_type], &error); + g_debug("Command executed in shell"); + + if (error) + g_error_free (error); - return (pid != -1); + return ret; } static gboolean active_sensor_execute_low_alarm(ActiveSensor *active_sensor) { @@ -460,8 +465,7 @@ ActiveSensor *active_sensor_new(SensorsApplet *sensors_applet, /* need to set size according to orientation */ orient = mate_panel_applet_get_orient(active_sensor->sensors_applet->applet); - graph_size = mate_panel_applet_mateconf_get_int(active_sensor->sensors_applet->applet, - GRAPH_SIZE, NULL); + graph_size = g_settings_get_int(active_sensor->sensors_applet->settings, GRAPH_SIZE); horizontal = ((orient == MATE_PANEL_APPLET_ORIENT_UP) || (orient == MATE_PANEL_APPLET_ORIENT_DOWN)); @@ -527,8 +531,7 @@ void active_sensor_update(ActiveSensor *active_sensor, gchar *tooltip = NULL; gchar *value_tooltip = NULL; - /* hidden mateconf options */ - MateConfClient *client; + /* hidden gsettings options */ gint font_size = 0; gboolean hide_units = FALSE; @@ -584,29 +587,16 @@ void active_sensor_update(ActiveSensor *active_sensor, * note this is not unique */ sensor_value = -1; } else { - /* use hidden mateconf key for hide_units */ - - if ((client = mateconf_client_get_default()) != NULL) { - hide_units = mateconf_client_get_bool(client, - "/apps/sensors-applet/" HIDE_UNITS, - &error); - if (error) { - g_debug("Could not get hide units from MateConf - assuming false"); - hide_units = FALSE; - g_error_free(error); - error = NULL; - } - - g_object_unref(client); - } + /* use hidden gsettings key for hide_units */ + hide_units = g_settings_get_boolean(sensors_applet->settings, HIDE_UNITS); /* scale value and set text using this * value */ switch (sensor_type) { case TEMP_SENSOR: - scale = (TemperatureScale)mate_panel_applet_mateconf_get_int(sensors_applet->applet, TEMPERATURE_SCALE, NULL); + scale = (TemperatureScale) g_settings_get_int(sensors_applet->settings, TEMPERATURE_SCALE); /* scale value */ sensor_value = sensors_applet_convert_temperature(sensor_value, CELSIUS, @@ -661,24 +651,10 @@ void active_sensor_update(ActiveSensor *active_sensor, g_free(value_tooltip); /* only do icons and labels / graphs if needed */ - display_mode = mate_panel_applet_mateconf_get_int(sensors_applet->applet, - DISPLAY_MODE, - NULL); + display_mode = g_settings_get_int (sensors_applet->settings, DISPLAY_MODE); /* most users wont have a font size set */ - if ((client = mateconf_client_get_default()) != NULL) { - font_size = mateconf_client_get_int(client, - "/apps/sensors-applet/" FONT_SIZE, - &error); - if (error) { - g_debug("Could not get font size from MateConf - assuming default size"); - font_size = 0; - g_error_free(error); - error = NULL; - } - - g_object_unref(client); - } + font_size = g_settings_get_int (sensors_applet->settings, FONT_SIZE); /* do icon if needed */ diff --git a/sensors-applet/main.c b/sensors-applet/main.c index c3f7784..dc3a2ed 100644 --- a/sensors-applet/main.c +++ b/sensors-applet/main.c @@ -24,12 +24,12 @@ #include <string.h> #include "sensors-applet.h" -static gboolean sensors_applet_fill(MatePanelApplet *applet, - const gchar *iid, +static gboolean sensors_applet_fill(MatePanelApplet *applet, + const gchar *iid, gpointer data) { SensorsApplet *sensors_applet; gboolean retval = FALSE; - if (strcmp(iid, "OAFIID:SensorsApplet") == 0) { + if (strcmp(iid, "SensorsApplet") == 0) { sensors_applet = g_new0(SensorsApplet, 1); sensors_applet->applet = applet; sensors_applet_init(sensors_applet); @@ -38,9 +38,8 @@ static gboolean sensors_applet_fill(MatePanelApplet *applet, return retval; } -MATE_PANEL_APPLET_MATECOMPONENT_FACTORY ("OAFIID:SensorsApplet_Factory", - PANEL_TYPE_APPLET, - PACKAGE, - PACKAGE_VERSION, - sensors_applet_fill, - NULL); +MATE_PANEL_APPLET_OUT_PROCESS_FACTORY ("SensorsAppletFactory", + PANEL_TYPE_APPLET, + "SensorsApplet", + sensors_applet_fill, + NULL); diff --git a/sensors-applet/prefs-dialog.c b/sensors-applet/prefs-dialog.c index 7789996..386af34 100644 --- a/sensors-applet/prefs-dialog.c +++ b/sensors-applet/prefs-dialog.c @@ -20,8 +20,9 @@ #include "config.h" #endif /* HAVE_CONFIG_H */ -#include <libmate/libmate.h> -#include "sensors-applet-mateconf.h" +#include <glib/gi18n.h> +#include <gio/gio.h> +#include "sensors-applet-settings.h" #include "prefs-dialog.h" #include "sensor-config-dialog.h" @@ -29,13 +30,11 @@ #define NEW_TEMP_SCALE 1 /* when a user closes the prefs-dialog we assume that applet is now - setup, so store all values in mateconf */ + setup, so store all values in gsettings */ void prefs_dialog_close(SensorsApplet *sensors_applet) { if (sensors_applet->sensors != NULL) { - if (sensors_applet_mateconf_save_sensors(sensors_applet)) - mate_panel_applet_mateconf_set_bool(sensors_applet->applet, - IS_SETUP, TRUE, NULL); + sensors_applet_settings_save_sensors(sensors_applet); } if (sensors_applet->prefs_dialog) { gtk_widget_destroy(GTK_WIDGET(sensors_applet->prefs_dialog->dialog)); @@ -44,7 +43,7 @@ void prefs_dialog_close(SensorsApplet *sensors_applet) { } if (sensors_applet->timeout_id == 0) { - sensors_applet->timeout_id = g_timeout_add_seconds(mate_panel_applet_mateconf_get_int(sensors_applet->applet, TIMEOUT, NULL) / 1000, (GSourceFunc)sensors_applet_update_active_sensors, sensors_applet); + sensors_applet->timeout_id = g_timeout_add_seconds(g_settings_get_int (sensors_applet->settings, TIMEOUT) / 1000, (GSourceFunc)sensors_applet_update_active_sensors, sensors_applet); } @@ -125,7 +124,7 @@ static void prefs_dialog_timeout_changed(GtkSpinButton *button, PrefsDialog *prefs_dialog) { gint value; value = (gint)(gtk_spin_button_get_value(button) * 1000); - mate_panel_applet_mateconf_set_int(prefs_dialog->sensors_applet->applet, TIMEOUT, value, NULL); + g_settings_set_int (prefs_dialog->sensors_applet->settings, TIMEOUT, value); } static void prefs_dialog_display_mode_changed(GtkComboBox *display_mode_combo_box, @@ -149,10 +148,9 @@ static void prefs_dialog_display_mode_changed(GtkComboBox *display_mode_combo_bo gtk_widget_set_sensitive(GTK_WIDGET(prefs_dialog->graph_size_spinbutton), (display_mode == DISPLAY_GRAPH)); - mate_panel_applet_mateconf_set_int(prefs_dialog->sensors_applet->applet, - DISPLAY_MODE, - gtk_combo_box_get_active(display_mode_combo_box), - NULL); + g_settings_set_int (prefs_dialog->sensors_applet->settings, + DISPLAY_MODE, + gtk_combo_box_get_active(display_mode_combo_box)); sensors_applet_display_layout_changed(prefs_dialog->sensors_applet); } @@ -160,10 +158,9 @@ static void prefs_dialog_display_mode_changed(GtkComboBox *display_mode_combo_bo static void prefs_dialog_layout_mode_changed(GtkComboBox *layout_mode_combo_box, PrefsDialog *prefs_dialog) { - mate_panel_applet_mateconf_set_int(prefs_dialog->sensors_applet->applet, - LAYOUT_MODE, - gtk_combo_box_get_active(layout_mode_combo_box), - NULL); + g_settings_set_int (prefs_dialog->sensors_applet->settings, + LAYOUT_MODE, + gtk_combo_box_get_active(layout_mode_combo_box)); sensors_applet_display_layout_changed(prefs_dialog->sensors_applet); } @@ -175,16 +172,14 @@ static void prefs_dialog_temperature_scale_changed(GtkComboBox *temperature_scal TemperatureScale scales[2]; GtkTreeModel *model; - scales[OLD_TEMP_SCALE] = (TemperatureScale)mate_panel_applet_mateconf_get_int(prefs_dialog->sensors_applet->applet, - TEMPERATURE_SCALE, - NULL); + scales[OLD_TEMP_SCALE] = (TemperatureScale) g_settings_get_int (prefs_dialog->sensors_applet->settings, + TEMPERATURE_SCALE); scales[NEW_TEMP_SCALE] = (TemperatureScale)gtk_combo_box_get_active(temperature_scale_combo_box); - mate_panel_applet_mateconf_set_int(prefs_dialog->sensors_applet->applet, - TEMPERATURE_SCALE, - scales[NEW_TEMP_SCALE], - NULL); + g_settings_set_int (prefs_dialog->sensors_applet->settings, + TEMPERATURE_SCALE, + scales[NEW_TEMP_SCALE]); /* now go thru and convert all low and high sensor values in * the tree to either celcius or Fahrenheit */ @@ -205,10 +200,9 @@ static void prefs_dialog_display_notifications_toggled(GtkCheckButton *display_n gboolean notify; notify = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(display_notifications)); - mate_panel_applet_mateconf_set_bool(prefs_dialog->sensors_applet->applet, - DISPLAY_NOTIFICATIONS, - notify, - NULL); + g_settings_set_boolean(prefs_dialog->sensors_applet->settings, + DISPLAY_NOTIFICATIONS, + notify); if (notify) { sensors_applet_update_active_sensors(prefs_dialog->sensors_applet); @@ -222,7 +216,7 @@ static void prefs_dialog_graph_size_changed(GtkSpinButton *button, PrefsDialog *prefs_dialog) { gint value; value = (gint)(gtk_spin_button_get_value(button)); - mate_panel_applet_mateconf_set_int(prefs_dialog->sensors_applet->applet, GRAPH_SIZE, value, NULL); + g_settings_set_int(prefs_dialog->sensors_applet->settings, GRAPH_SIZE, value); /* notify change of number of samples */ sensors_applet_graph_size_changed(prefs_dialog->sensors_applet); @@ -472,7 +466,7 @@ void prefs_dialog_open(SensorsApplet *sensors_applet) { gtk_combo_box_append_text(prefs_dialog->display_mode_combo_box, _("graph only")); - display_mode = mate_panel_applet_mateconf_get_int(sensors_applet->applet, DISPLAY_MODE, NULL); + display_mode = g_settings_get_int(sensors_applet->settings, DISPLAY_MODE); gtk_combo_box_set_active(prefs_dialog->display_mode_combo_box, display_mode); g_signal_connect(prefs_dialog->display_mode_combo_box, @@ -503,7 +497,7 @@ void prefs_dialog_open(SensorsApplet *sensors_applet) { gtk_combo_box_append_text(prefs_dialog->layout_mode_combo_box, _("beside labels / icons")); gtk_combo_box_append_text(prefs_dialog->layout_mode_combo_box, _("below labels / icons")); - gtk_combo_box_set_active(prefs_dialog->layout_mode_combo_box, mate_panel_applet_mateconf_get_int(sensors_applet->applet, LAYOUT_MODE, NULL)); + gtk_combo_box_set_active(prefs_dialog->layout_mode_combo_box, g_settings_get_int(sensors_applet->settings, LAYOUT_MODE)); g_signal_connect(prefs_dialog->layout_mode_combo_box, "changed", @@ -528,7 +522,7 @@ void prefs_dialog_open(SensorsApplet *sensors_applet) { gtk_combo_box_append_text(prefs_dialog->temperature_scale_combo_box, _("Celsius")); gtk_combo_box_append_text(prefs_dialog->temperature_scale_combo_box, _("Fahrenheit")); - gtk_combo_box_set_active(prefs_dialog->temperature_scale_combo_box, mate_panel_applet_mateconf_get_int(sensors_applet->applet, TEMPERATURE_SCALE, NULL)); + gtk_combo_box_set_active(prefs_dialog->temperature_scale_combo_box, g_settings_get_int(sensors_applet->settings, TEMPERATURE_SCALE)); g_signal_connect(prefs_dialog->temperature_scale_combo_box, "changed", @@ -543,9 +537,7 @@ void prefs_dialog_open(SensorsApplet *sensors_applet) { NULL); prefs_dialog->graph_size_adjust = g_object_new(GTK_TYPE_ADJUSTMENT, - "value", (gdouble)mate_panel_applet_mateconf_get_int(sensors_applet->applet, - GRAPH_SIZE, - NULL), + "value", (gdouble)g_settings_get_int(sensors_applet->settings, GRAPH_SIZE), "lower", 1.0, "upper", 100.0, "step-increment", 1.0, @@ -557,9 +549,7 @@ void prefs_dialog_open(SensorsApplet *sensors_applet) { "adjustment", prefs_dialog->graph_size_adjust, "climb-rate", 1.0, "digits", 0, - "value", (gdouble)mate_panel_applet_mateconf_get_int(sensors_applet->applet, - GRAPH_SIZE, - NULL), + "value", (gdouble)g_settings_get_int(sensors_applet->settings, GRAPH_SIZE), "width-chars", 4, NULL); @@ -604,7 +594,7 @@ void prefs_dialog_open(SensorsApplet *sensors_applet) { "adjustment", prefs_dialog->timeout_adjust, "climb-rate", 0.5, "digits", 1, - "value", (gdouble) mate_panel_applet_mateconf_get_int(sensors_applet->applet, TIMEOUT, NULL) / 1000.0, + "value", (gdouble) g_settings_get_int(sensors_applet->settings, TIMEOUT) / 1000.0, "width-chars", 4, NULL); @@ -635,9 +625,8 @@ void prefs_dialog_open(SensorsApplet *sensors_applet) { "label", _("Display _notifications"), NULL); gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(prefs_dialog->display_notifications), - mate_panel_applet_mateconf_get_bool(sensors_applet->applet, - DISPLAY_NOTIFICATIONS, - NULL)); + g_settings_get_boolean(sensors_applet->settings, + DISPLAY_NOTIFICATIONS)); g_signal_connect(prefs_dialog->display_notifications, "toggled", G_CALLBACK(prefs_dialog_display_notifications_toggled), diff --git a/sensors-applet/sensor-config-dialog.c b/sensors-applet/sensor-config-dialog.c index c053c19..dd9f3c7 100644 --- a/sensors-applet/sensor-config-dialog.c +++ b/sensors-applet/sensor-config-dialog.c @@ -20,7 +20,7 @@ #include "config.h" #endif /* HAVE_CONFIG_H */ -#include <mate.h> +#include <glib/gi18n.h> #include "sensor-config-dialog.h" #include "sensors-applet.h" diff --git a/sensors-applet/sensors-applet-mateconf.c b/sensors-applet/sensors-applet-mateconf.c deleted file mode 100644 index 5039a95..0000000 --- a/sensors-applet/sensors-applet-mateconf.c +++ /dev/null @@ -1,491 +0,0 @@ -/* - * Copyright (C) 2005-2009 Alex Murray <[email protected]> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif /* HAVE_CONFIG_H */ - -#include "sensors-applet.h" -#include "sensors-applet-mateconf.h" - -#define DEFAULT_TIMEOUT 2000 -#define DEFAULT_GRAPH_SIZE 42 - -static const gchar * const compatible_versions[] = { - PACKAGE_VERSION, /* always list current version */ - "1.1.1", - "1.1.0", - "1.0.7", - "1.1.0", -}; - -#define NUM_COMPATIBLE_VERSIONS G_N_ELEMENTS(compatible_versions) - -typedef enum { - SENSORS_APPLET_MATECONF_ERROR = 0, - SENSORS_APPLET_VERSION_ERROR, -} SensorsAppletMateConfError; - -static const gchar * const error_titles[] = { - N_("An error occurred loading the stored sensors data"), - N_("Incompatible sensors configuration found") -}; - -static const gchar * const error_messages[] = { - N_("An error has occurred when loading the stored sensors data. " - "The default values will be used to recover from this error."), - - N_("Unfortunately the previous configuration for MATE Sensors Applet " - "is not compatible with this version. The existing sensors data " - "will be overwritten with the default values for this new version.") -}; - -/* function to be called if an error occurs - when loading values from mateconf */ -static void sensors_applet_mateconf_error_occurred(SensorsAppletMateConfError error) { - GtkWidget *dialog; - gchar *markup; - - g_debug("Error occurred: %s", error_titles[error]); - markup = g_markup_printf_escaped("<span size=\"large\" weight=\"bold\">%s</span>\n\n%s", _(error_titles[error]), _(error_messages[error])); - - dialog = gtk_message_dialog_new_with_markup(NULL, /* no parent window */ - GTK_DIALOG_MODAL, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_OK, - "%s", markup); - - g_free(markup); - - /* runs dialog as modal and doesn't return until user clicks - * button */ - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(GTK_WIDGET(dialog)); -} - - -static void sensors_applet_mateconf_set_defaults(SensorsApplet *sensors_applet) { - mate_panel_applet_mateconf_set_int(sensors_applet->applet, DISPLAY_MODE, DISPLAY_ICON_WITH_VALUE, NULL); - mate_panel_applet_mateconf_set_int(sensors_applet->applet, LAYOUT_MODE, VALUE_BESIDE_LABEL, NULL); - mate_panel_applet_mateconf_set_int(sensors_applet->applet, TEMPERATURE_SCALE, CELSIUS, NULL); - mate_panel_applet_mateconf_set_int(sensors_applet->applet, TIMEOUT, DEFAULT_TIMEOUT, NULL); - mate_panel_applet_mateconf_set_int(sensors_applet->applet, GRAPH_SIZE, DEFAULT_GRAPH_SIZE, NULL); -#ifdef HAVE_LIBMATENOTIFY - mate_panel_applet_mateconf_set_bool(sensors_applet->applet, DISPLAY_NOTIFICATIONS, TRUE, NULL); -#endif - mate_panel_applet_mateconf_set_bool(sensors_applet->applet, IS_SETUP, FALSE, NULL); - -} - -/** - * Returns TRUE is old_version is one of the compatible versions - */ -static gboolean sensors_applet_mateconf_is_compatible(const gchar *old_version) { - guint i; - for (i = 0; i < NUM_COMPATIBLE_VERSIONS; i++) { - if (g_ascii_strcasecmp(old_version, compatible_versions[i]) == 0) { - return TRUE; - } - } - return FALSE; -} - - -void sensors_applet_mateconf_setup(SensorsApplet *sensors_applet) { - gboolean setup = FALSE; - gchar *old_version; - GError *error = NULL; - - /* need to convert old num_samples value to new GRAPH_SIZE - * parameter */ - gint num_samples; - if ((num_samples = mate_panel_applet_mateconf_get_int(sensors_applet->applet, - "num_samples", - NULL))) { - g_debug("Convering old num_samples value %d into graph_size", num_samples); - mate_panel_applet_mateconf_set_int(sensors_applet->applet, - GRAPH_SIZE, - (num_samples + GRAPH_FRAME_EXTRA_WIDTH), - NULL); - /* reset num_samples to zero */ - mate_panel_applet_mateconf_set_int(sensors_applet->applet, - "num_samples", - 0, - NULL); - - } - - /* convert old alarm_commands to high and low if exist */ - GSList *alarm_commands; - if ((alarm_commands = mate_panel_applet_mateconf_get_list(sensors_applet->applet, - "alarm_commands", - MATECONF_VALUE_STRING, - NULL))) { - - g_debug("Converting old alarm commands to new high and low commands"); - - mate_panel_applet_mateconf_set_list(sensors_applet->applet, - LOW_ALARM_COMMANDS, - MATECONF_VALUE_STRING, - alarm_commands, - NULL); - mate_panel_applet_mateconf_set_list(sensors_applet->applet, - HIGH_ALARM_COMMANDS, - MATECONF_VALUE_STRING, - alarm_commands, - NULL); - /* reset old list to null */ - mate_panel_applet_mateconf_set_list(sensors_applet->applet, - "alarm_commands", - MATECONF_VALUE_STRING, - NULL, - NULL); - g_slist_foreach(alarm_commands, (GFunc)g_free, NULL); - g_slist_free(alarm_commands); - - } - - setup = mate_panel_applet_mateconf_get_bool(sensors_applet->applet, - IS_SETUP, &error); - if (error) { - g_debug("Previous configuration not found: %s, setting up manually", error->message); - g_error_free(error); - error = NULL; - setup = FALSE; - } - - - if (setup) { - /* see if setup version matches */ - old_version = mate_panel_applet_mateconf_get_string(sensors_applet->applet, - SENSORS_APPLET_VERSION, - &error); - /* if versions don't match or there is no saved - * version string then need to overwrite old config */ - if (error) { - g_debug("Error getting old version string: %s", error->message); - g_error_free(error); - error = NULL; - old_version = NULL; - } - - if (old_version) { - if (sensors_applet_mateconf_is_compatible(old_version)) { - /* previously setup and versions match so use - * old values */ - g_debug("MateConf data is compatible. Trying to set up sensors from mateconf data"); - if (sensors_applet_mateconf_setup_sensors(sensors_applet)) { - g_debug("done setting up from mateconf"); - } else { - g_debug("Setting mateconf defaults only"); - sensors_applet_mateconf_set_defaults(sensors_applet); - } - g_free(old_version); - - return; - - - } - g_free(old_version); - - } - sensors_applet_notify(sensors_applet, MATECONF_READ_ERROR); - - - sensors_applet_mateconf_error_occurred(SENSORS_APPLET_VERSION_ERROR); - } - - /* use defaults */ - g_debug("Setting mateconf defaults only"); - sensors_applet_mateconf_set_defaults(sensors_applet); -} - -enum { - PATHS_INDEX = 0, - IDS_INDEX, - LABELS_INDEX, - INTERFACES_INDEX, - SENSOR_TYPES_INDEX, - ENABLES_INDEX, - LOW_VALUES_INDEX, - HIGH_VALUES_INDEX, - ALARM_ENABLES_INDEX, - LOW_ALARM_COMMANDS_INDEX, - HIGH_ALARM_COMMANDS_INDEX, - ALARM_TIMEOUTS_INDEX, - MULTIPLIERS_INDEX, - OFFSETS_INDEX, - ICON_TYPES_INDEX, - GRAPH_COLORS_INDEX, - NUM_KEYS -}; - -const gchar * const keys[NUM_KEYS] = { - PATHS, - IDS, - LABELS, - INTERFACES, - SENSOR_TYPES, - ENABLES, - LOW_VALUES, - HIGH_VALUES, - ALARM_ENABLES, - LOW_ALARM_COMMANDS, - HIGH_ALARM_COMMANDS, - ALARM_TIMEOUTS, - MULTIPLIERS, - OFFSETS, - ICON_TYPES, - GRAPH_COLORS, -}; - -/* MUST CORRESPOND TO ABOVE KEYS */ -const MateConfValueType key_types[NUM_KEYS] = { - MATECONF_VALUE_STRING, /* PATHS */ - MATECONF_VALUE_STRING, /* IDS, */ - MATECONF_VALUE_STRING, /* LABELS */ - MATECONF_VALUE_STRING, /* INTERFACES, */ - MATECONF_VALUE_INT, /* SENSOR_TYPES, */ - MATECONF_VALUE_BOOL, /* ENABLES, */ - MATECONF_VALUE_INT, /* LOW_VALUES, */ - MATECONF_VALUE_INT, /* HIGH_VALUES, */ - MATECONF_VALUE_BOOL, /* ALARM_ENABLES, */ - MATECONF_VALUE_STRING, /* LOW_ALARM_COMMANDS, */ - MATECONF_VALUE_STRING, /* HIGH_ALARM_COMMANDS, */ - MATECONF_VALUE_INT, /* ALARM_TIMEOUTS, */ - MATECONF_VALUE_INT, /* MULTIPLIERS, */ - MATECONF_VALUE_INT, /* OFFSETS, */ - MATECONF_VALUE_INT, /* ICON_TYPES, */ - MATECONF_VALUE_STRING /* GRAPH_COLORS, */ -}; - -void sensors_applet_mateconf_set_current_to_lists(GSList *current[], - GSList *lists[], - int len) { - for (len--; len >= 0; len--) { - current[len] = lists[len]; - } -} - -int sensors_applet_mateconf_current_not_null(GSList *current[], - int len) { - for (len--; len >= 0; len--) { - if (NULL == current[len]) { - return FALSE; - } - } - return TRUE; -} -void sensors_applet_mateconf_current_get_next(GSList *current[], - int len) { - for (len--; len >= 0; len--) { - current[len] = g_slist_next(current[len]); - } -} - -void sensors_applet_mateconf_free_lists(GSList *lists[], - int len) { - for (len--; len >= 0; len--) { - if (key_types[len] == MATECONF_VALUE_STRING) { - g_slist_foreach(lists[len], (GFunc)g_free, NULL); - } - g_slist_free(lists[len]); - } - -} - -/* gets called if are already setup so we don't have to manually go - through and find sensors etc again */ -gboolean sensors_applet_mateconf_setup_sensors(SensorsApplet *sensors_applet) { - /* everything gets stored except alarm timeout indexes, which - we set to -1, and visible which we set to false for all - parent nodes and true for all child nodes */ - int i; - GSList *lists[NUM_KEYS] = {NULL}; - - GSList *current[NUM_KEYS] = {NULL}; - - GError *error = NULL; - - for (i = 0; i < NUM_KEYS; i++) { - lists[i] = mate_panel_applet_mateconf_get_list(sensors_applet->applet, - keys[i], - key_types[i], - &error); - if (error || NULL == lists[i]) { - sensors_applet_notify(sensors_applet, MATECONF_READ_ERROR); - - sensors_applet_mateconf_error_occurred(SENSORS_APPLET_MATECONF_ERROR); - if (error) { - g_error_free(error); - } - return FALSE; - } - } - - for (sensors_applet_mateconf_set_current_to_lists(current, - lists, - NUM_KEYS); - sensors_applet_mateconf_current_not_null(current, - NUM_KEYS); - sensors_applet_mateconf_current_get_next(current, - NUM_KEYS)) { - - - g_debug("trying to add sensor from mateconf data: %s\n", (gchar *)(current[IDS_INDEX]->data)); - /* need to ensure correct order */ - sensors_applet_add_sensor(sensors_applet, - (gchar *)(current[PATHS_INDEX]->data), - (gchar *)(current[IDS_INDEX]->data), - (gchar *)(current[LABELS_INDEX]->data), - (gchar *)(current[INTERFACES_INDEX]->data), - GPOINTER_TO_UINT(current[SENSOR_TYPES_INDEX]->data), - GPOINTER_TO_INT(current[ENABLES_INDEX]->data), - (gdouble)(GPOINTER_TO_INT(current[LOW_VALUES_INDEX]->data) / 1000.0), - (gdouble)(GPOINTER_TO_INT(current[HIGH_VALUES_INDEX]->data) / 1000.0), - GPOINTER_TO_INT(current[ALARM_ENABLES_INDEX]->data), - (gchar *)(current[LOW_ALARM_COMMANDS_INDEX]->data), - (gchar *)(current[HIGH_ALARM_COMMANDS_INDEX]->data), - GPOINTER_TO_INT(current[ALARM_TIMEOUTS_INDEX]->data), - (gdouble)(GPOINTER_TO_INT(current[MULTIPLIERS_INDEX]->data) / 1000.0), - (gdouble)(GPOINTER_TO_INT(current[OFFSETS_INDEX]->data) / 1000.0), - (SensorType)GPOINTER_TO_UINT(current[ICON_TYPES_INDEX]->data), - (gchar *)(current[GRAPH_COLORS_INDEX]->data) - - ); - - } - sensors_applet_mateconf_free_lists(lists, - NUM_KEYS); - - return TRUE; -} - - -gboolean sensors_applet_mateconf_save_sensors(SensorsApplet *sensors_applet) { - /* write everything to mateconf except VISIBLE and - ALARM_TIMEOUT_INDEX */ - /* for stepping through GtkTreeStore data structure */ - GtkTreeIter interfaces_iter, sensors_iter; - gboolean not_end_of_interfaces = TRUE, not_end_of_sensors = TRUE; - - /* make sure all are initialized to null - since list of - * intializers is horter than number of element, rest get set - * to 0 (ie NULL) */ - GSList *lists[NUM_KEYS] = {NULL}; - int i; - gchar *current_path, *current_id, *current_label, *current_interface, - *current_low_alarm_command, *current_high_alarm_command, - *current_graph_color; - gboolean current_enable, current_alarm_enable; - gdouble current_low_value, current_high_value, current_multiplier, - current_offset; - guint current_alarm_timeout, current_sensor_type, - current_icon_type; - - GError *error = NULL; - - /* now step through the GtkTreeStore sensors to - find which sensors are enabled */ - for (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(sensors_applet->sensors), &interfaces_iter); not_end_of_interfaces; not_end_of_interfaces = gtk_tree_model_iter_next(GTK_TREE_MODEL(sensors_applet->sensors), &interfaces_iter)) { - // store a mateconf key for this interface - gtk_tree_model_get(GTK_TREE_MODEL(sensors_applet->sensors), - &interfaces_iter, - ID_COLUMN, ¤t_id, - -1); - - mate_panel_applet_mateconf_set_bool(sensors_applet->applet, current_id, TRUE, NULL); - g_free(current_id); - - /* reset sensors sentinel */ - not_end_of_sensors = TRUE; - - for (gtk_tree_model_iter_children(GTK_TREE_MODEL(sensors_applet->sensors), &sensors_iter, &interfaces_iter); not_end_of_sensors; not_end_of_sensors = gtk_tree_model_iter_next(GTK_TREE_MODEL(sensors_applet->sensors), &sensors_iter)) { - gtk_tree_model_get(GTK_TREE_MODEL(sensors_applet->sensors), - &sensors_iter, - PATH_COLUMN, ¤t_path, - ID_COLUMN, ¤t_id, - LABEL_COLUMN, ¤t_label, - INTERFACE_COLUMN, ¤t_interface, - SENSOR_TYPE_COLUMN, ¤t_sensor_type, - ENABLE_COLUMN, ¤t_enable, - LOW_VALUE_COLUMN, ¤t_low_value, - HIGH_VALUE_COLUMN, ¤t_high_value, - ALARM_ENABLE_COLUMN, ¤t_alarm_enable, - LOW_ALARM_COMMAND_COLUMN, ¤t_low_alarm_command, - HIGH_ALARM_COMMAND_COLUMN, ¤t_high_alarm_command, - ALARM_TIMEOUT_COLUMN, ¤t_alarm_timeout, - MULTIPLIER_COLUMN, ¤t_multiplier, - OFFSET_COLUMN, ¤t_offset, - ICON_TYPE_COLUMN, ¤t_icon_type, - GRAPH_COLOR_COLUMN, ¤t_graph_color, - -1); - - /* prepend values as this is faster then just - reverse list when finished */ - lists[PATHS_INDEX] = g_slist_prepend(lists[PATHS_INDEX], current_path); - lists[IDS_INDEX] = g_slist_prepend(lists[IDS_INDEX], current_id); - lists[LABELS_INDEX] = g_slist_prepend(lists[LABELS_INDEX], current_label); - lists[INTERFACES_INDEX] = g_slist_prepend(lists[INTERFACES_INDEX], current_interface); - lists[ENABLES_INDEX] = g_slist_prepend(lists[ENABLES_INDEX], GINT_TO_POINTER(current_enable)); - lists[LOW_VALUES_INDEX] = g_slist_prepend(lists[LOW_VALUES_INDEX], GINT_TO_POINTER((gint)(current_low_value * 1000))); - lists[HIGH_VALUES_INDEX] = g_slist_prepend(lists[HIGH_VALUES_INDEX], GINT_TO_POINTER((gint)(current_high_value * 1000))); - lists[ALARM_ENABLES_INDEX] = g_slist_prepend(lists[ALARM_ENABLES_INDEX], GINT_TO_POINTER(current_alarm_enable)); - lists[LOW_ALARM_COMMANDS_INDEX] = g_slist_prepend(lists[LOW_ALARM_COMMANDS_INDEX], current_low_alarm_command); - lists[HIGH_ALARM_COMMANDS_INDEX] = g_slist_prepend(lists[HIGH_ALARM_COMMANDS_INDEX], current_high_alarm_command); - lists[ALARM_TIMEOUTS_INDEX] = g_slist_prepend(lists[ALARM_TIMEOUTS_INDEX], GINT_TO_POINTER(current_alarm_timeout)); - lists[SENSOR_TYPES_INDEX] = g_slist_prepend(lists[SENSOR_TYPES_INDEX], GUINT_TO_POINTER(current_sensor_type)); - lists[MULTIPLIERS_INDEX] = g_slist_prepend(lists[MULTIPLIERS_INDEX], GINT_TO_POINTER((gint)(current_multiplier * 1000))); - lists[OFFSETS_INDEX] = g_slist_prepend(lists[OFFSETS_INDEX], GINT_TO_POINTER((gint)(current_offset * 1000))); - lists[ICON_TYPES_INDEX] = g_slist_prepend(lists[ICON_TYPES_INDEX], GUINT_TO_POINTER(current_icon_type)); - lists[GRAPH_COLORS_INDEX] = g_slist_prepend(lists[GRAPH_COLORS_INDEX], current_graph_color); - } - } - - /* keep lists in original order */ - for (i = 0; i < NUM_KEYS; i++) { - if (lists[i] != NULL) { - lists[i] = g_slist_reverse(lists[i]); - - mate_panel_applet_mateconf_set_list(sensors_applet->applet, - keys[i], - key_types[i], - lists[i], &error); - if (error) { - sensors_applet_notify(sensors_applet, MATECONF_WRITE_ERROR); - - g_error_free(error); - return FALSE; - } - } else { - g_debug("list %s is NULL", keys[i]); - } - - } - - sensors_applet_mateconf_free_lists(lists, - NUM_KEYS); - - /* store current version to identify config data */ - mate_panel_applet_mateconf_set_string(sensors_applet->applet, - SENSORS_APPLET_VERSION, - PACKAGE_VERSION, &error); - - return TRUE; -} - diff --git a/sensors-applet/sensors-applet-mateconf.h b/sensors-applet/sensors-applet-mateconf.h deleted file mode 100644 index be74941..0000000 --- a/sensors-applet/sensors-applet-mateconf.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2005-2009 Alex Murray <[email protected]> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef SENSORS_APPLET_MATECONF_H -#define SENSORS_APPLET_MATECONF_H - -#include "sensors-applet.h" -#include <mate-panel-applet-mateconf.h> - -#define FONT_SIZE "font-size" /* hidden mateconf option specifying font - * size in points */ - -#define HIDE_UNITS "hide-units" /* hidden mateconf option specifying not to - * show sensor units */ - -#define IS_SETUP "setup" /* have we actually set up this instance of - * the applet (gets set to true after - * closing prefences dialog) */ - -#define DISPLAY_MODE "display_mode" /* display icons or text labels?*/ - -#define LAYOUT_MODE "layout_mode" /* value beside or below label */ -#define TEMPERATURE_SCALE "temperature_scale" /* Kelvin, - Celsius or - Fahrenheit */ -#define DISPLAY_NOTIFICATIONS "display_notifications" /* whether to - * display - * notifications */ -#define TIMEOUT "timeout_delay" /* delay (in ms) between refreshes */ -#define GRAPH_SIZE "graph_size" /* the size of the graph in pixels - - * either width if horizontal, or - * height if vertical */ -#define PATHS "paths" /* full paths to filenames */ -#define IDS "ids" /* a list of the sensor device ids */ -#define INTERFACES "interfaces" /* a list of the sensor device - * interface for each sensor */ -#define LABELS "labels" /* user defined labels for each sensor */ -#define ENABLES "sensor_enables" /* list of booleans corresponding to - * the filenames of whether a sensor - * is enabled or not */ -#define LOW_VALUES "low_values" /* stored as ints (1000 * double - * value) for accuracy, since can - * only do ints easily */ -#define HIGH_VALUES "high_values" /* stored as ints (1000 * double - * value) for accuracy, since can - * only do ints easily */ -#define ALARM_ENABLES "alarm_enables" /* list of whether each sensor - * has its alarm enabled */ -#define LOW_ALARM_COMMANDS "low_alarm_commands" /* list of commands to execute - * when each alarm is - * activated */ -#define HIGH_ALARM_COMMANDS "high_alarm_commands" /* list of commands to execute - * when each alarm is - * activated */ - -#define ALARM_TIMEOUTS "alarm_timeouts" /* list of how often each - alarm should be sounded (in - seconds) */ - -#define SENSOR_TYPES "sensor_types" /* used to identify a sensor in a - list */ - -#define MULTIPLIERS "multipliers" -#define OFFSETS "offsets" -#define ICON_TYPES "icon_types" -#define GRAPH_COLORS "graph_colors" - -#define SENSORS_APPLET_VERSION "sensors_applet_version" /* version of - * config - * data */ - -gboolean sensors_applet_mateconf_save_sensors(SensorsApplet *sensors_applet); -gboolean sensors_applet_mateconf_setup_sensors(SensorsApplet *sensors_applet); -void sensors_applet_mateconf_setup(SensorsApplet *sensors_applet); - -#endif /* SENSORS_APPLET_MATECONF_H*/ diff --git a/sensors-applet/sensors-applet-settings.c b/sensors-applet/sensors-applet-settings.c new file mode 100644 index 0000000..6b0d92f --- /dev/null +++ b/sensors-applet/sensors-applet-settings.c @@ -0,0 +1,142 @@ +/* + * Copyright (C) 2005-2009 Alex Murray <[email protected]> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif /* HAVE_CONFIG_H */ + +#include <glib.h> +#include "sensors-applet.h" +#include "sensors-applet-settings.h" + +gchar* sensors_applet_settings_get_unique_id (const gchar *interface, const gchar *id, const gchar *path) { + gchar *unique_id; + gchar *unique_id_hash; + GChecksum *checksum; + guint8 digest[16]; + gsize digest_len = sizeof (digest); + + unique_id = g_strdup_printf ("%s/%s/%s", interface, id, path); + + checksum = g_checksum_new (G_CHECKSUM_MD5); + g_checksum_update (checksum, (const guchar *) unique_id, strlen (unique_id)); + g_checksum_get_digest (checksum, digest, &digest_len); + g_assert (digest_len == 16); + + unique_id_hash = g_strdup (g_checksum_get_string (checksum)); + + g_checksum_free (checksum); + g_free (unique_id); + + return unique_id_hash; +} + +gboolean sensors_applet_settings_save_sensors(SensorsApplet *sensors_applet) { + /* write everything to GSettings except VISIBLE and + ALARM_TIMEOUT_INDEX */ + /* for stepping through GtkTreeStore data structure */ + GtkTreeIter interfaces_iter, sensors_iter; + gboolean not_end_of_interfaces = TRUE, not_end_of_sensors = TRUE; + gchar *applet_path; + + int i; + gchar *current_path, *current_id, *current_label, *current_interface, + *current_low_alarm_command, *current_high_alarm_command, + *current_graph_color; + gboolean current_enable, current_alarm_enable; + gdouble current_low_value, current_high_value, current_multiplier, + current_offset; + guint current_alarm_timeout, current_sensor_type, + current_icon_type; + + applet_path = mate_panel_applet_get_preferences_path (sensors_applet->applet); + + /* now step through the GtkTreeStore sensors to + find which sensors are enabled */ + for (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(sensors_applet->sensors), &interfaces_iter); not_end_of_interfaces; not_end_of_interfaces = gtk_tree_model_iter_next(GTK_TREE_MODEL(sensors_applet->sensors), &interfaces_iter)) { + gtk_tree_model_get(GTK_TREE_MODEL(sensors_applet->sensors), + &interfaces_iter, + ID_COLUMN, ¤t_id, + -1); + + //mate_panel_applet_mateconf_set_bool(sensors_applet->applet, current_id, TRUE, NULL); + g_free(current_id); + + /* reset sensors sentinel */ + not_end_of_sensors = TRUE; + + for (gtk_tree_model_iter_children(GTK_TREE_MODEL(sensors_applet->sensors), &sensors_iter, &interfaces_iter); not_end_of_sensors; not_end_of_sensors = gtk_tree_model_iter_next(GTK_TREE_MODEL(sensors_applet->sensors), &sensors_iter)) { + gtk_tree_model_get(GTK_TREE_MODEL(sensors_applet->sensors), + &sensors_iter, + PATH_COLUMN, ¤t_path, + ID_COLUMN, ¤t_id, + LABEL_COLUMN, ¤t_label, + INTERFACE_COLUMN, ¤t_interface, + SENSOR_TYPE_COLUMN, ¤t_sensor_type, + ENABLE_COLUMN, ¤t_enable, + LOW_VALUE_COLUMN, ¤t_low_value, + HIGH_VALUE_COLUMN, ¤t_high_value, + ALARM_ENABLE_COLUMN, ¤t_alarm_enable, + LOW_ALARM_COMMAND_COLUMN, ¤t_low_alarm_command, + HIGH_ALARM_COMMAND_COLUMN, ¤t_high_alarm_command, + ALARM_TIMEOUT_COLUMN, ¤t_alarm_timeout, + MULTIPLIER_COLUMN, ¤t_multiplier, + OFFSET_COLUMN, ¤t_offset, + ICON_TYPE_COLUMN, ¤t_icon_type, + GRAPH_COLOR_COLUMN, ¤t_graph_color, + -1); + + gchar *path = g_strdup_printf ("%s%s/", + applet_path, + sensors_applet_settings_get_unique_id (current_interface, + current_id, + current_path)); + + GSettings *settings; + settings = g_settings_new_with_path ("org.mate.sensors-applet.sensor", + path); + g_free (path); + + g_settings_delay (settings); + g_settings_set_string (settings, PATH, current_path); + g_settings_set_string (settings, ID, current_id); + g_settings_set_string (settings, LABEL, current_label); + g_settings_set_string (settings, INTERFACE, current_interface); + g_settings_set_int (settings, SENSOR_TYPE, current_sensor_type); + g_settings_set_boolean (settings, ENABLED, current_enable); + g_settings_set_double (settings, LOW_VALUE, current_low_value); + g_settings_set_double (settings, HIGH_VALUE, current_high_value); + g_settings_set_boolean (settings, ALARM_ENABLED, current_alarm_enable); + g_settings_set_string (settings, LOW_ALARM_COMMAND, current_low_alarm_command); + g_settings_set_string (settings, HIGH_ALARM_COMMAND, current_high_alarm_command); + g_settings_set_int (settings, ALARM_TIMEOUT, current_alarm_timeout); + g_settings_set_double (settings, MULTIPLIER, current_multiplier); + g_settings_set_double (settings, OFFSET, current_offset); + g_settings_set_int (settings, ICON_TYPE, current_icon_type); + g_settings_set_string (settings, GRAPH_COLOR, current_graph_color); + g_settings_apply (settings); + g_object_unref (settings); + + } + } + + g_free (applet_path); + + return TRUE; +} + diff --git a/sensors-applet/sensors-applet-settings.h b/sensors-applet/sensors-applet-settings.h new file mode 100644 index 0000000..89f6ce0 --- /dev/null +++ b/sensors-applet/sensors-applet-settings.h @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2005-2009 Alex Murray <[email protected]> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef SENSORS_APPLET_SETTINGS_H +#define SENSORS_APPLET_SETTINGS_H + +#include "sensors-applet.h" +#include <mate-panel-applet.h> +#include <mate-panel-applet-gsettings.h> + +#define FONT_SIZE "font-size" +#define HIDE_UNITS "hide-units" +#define DISPLAY_MODE "display-mode" +#define LAYOUT_MODE "layout-mode" +#define TEMPERATURE_SCALE "temperature-scale" +#define DISPLAY_NOTIFICATIONS "display-notifications" +#define TIMEOUT "timeout-delay" +#define GRAPH_SIZE "graph-size" +#define SENSORS_LIST "sensors-list" + +#define PATH "path" +#define ID "id" +#define INTERFACE "interface" +#define LABEL "label" +#define ENABLED "enabled" +#define LOW_VALUE "low-value" +#define HIGH_VALUE "high-value" +#define ALARM_ENABLED "alarm-enabled" +#define LOW_ALARM_COMMAND "low-alarm-command" +#define HIGH_ALARM_COMMAND "high-alarm-command" +#define ALARM_TIMEOUT "alarm-timeout" +#define SENSOR_TYPE "sensor-type" +#define MULTIPLIER "multiplier" +#define OFFSET "offset" +#define ICON_TYPE "icon-type" +#define GRAPH_COLOR "graph-color" + +gchar* sensors_applet_settings_get_unique_id (const gchar *interface, const gchar *id, const gchar *path); +gboolean sensors_applet_settings_save_sensors(SensorsApplet *sensors_applet); + +#endif /* SENSORS_APPLET_SETTINGS_H*/ diff --git a/sensors-applet/sensors-applet.c b/sensors-applet/sensors-applet.c index 2e0d3b9..63ed3f9 100644 --- a/sensors-applet/sensors-applet.c +++ b/sensors-applet/sensors-applet.c @@ -28,11 +28,12 @@ #include <unistd.h> #endif /* HAVE_UNISTD_H */ -#include <mate.h> +#include <glib/gi18n.h> #include <glib/gprintf.h> +#include <gio/gio.h> #include "sensors-applet.h" #include "active-sensor.h" -#include "sensors-applet-mateconf.h" +#include "sensors-applet-settings.h" #include "sensors-applet-plugins.h" #ifdef HAVE_LIBMATENOTIFY @@ -51,9 +52,8 @@ #define ROW_SPACING 0 /* callbacks for panel menu */ -static void prefs_cb(MateComponentUIComponent *uic, - gpointer *data, - const gchar *verbname) { +static void prefs_cb(GtkAction *action, + gpointer *data) { SensorsApplet *sensors_applet; sensors_applet = (SensorsApplet *)data; @@ -65,18 +65,16 @@ static void prefs_cb(MateComponentUIComponent *uic, prefs_dialog_open(sensors_applet); } -static void about_cb(MateComponentUIComponent *uic, - gpointer data, - const gchar *verbname) { +static void about_cb(GtkAction *action, + gpointer data) { SensorsApplet *sensors_applet; sensors_applet = (SensorsApplet *)data; about_dialog_open(sensors_applet); } -static void help_cb(MateComponentUIComponent *uic, - gpointer data, - const gchar *verbname) { +static void help_cb(GtkAction *action, + gpointer data) { GError *error = NULL; @@ -105,6 +103,11 @@ static void destroy_cb(GtkWidget *widget, gpointer data) { g_source_remove(sensors_applet->timeout_id); } + if (sensors_applet->settings ) { + g_object_unref (sensors_applet->settings); + sensors_applet->settings = NULL; + } + // destroy all active sensors g_list_foreach(sensors_applet->active_sensors, (GFunc)active_sensor_destroy, @@ -212,9 +215,7 @@ static void style_set_cb(GtkWidget *widget, g_debug("set-style occurred"); - display_mode = mate_panel_applet_mateconf_get_int(sensors_applet->applet, - DISPLAY_MODE, - NULL); + display_mode = g_settings_get_int (sensors_applet->settings, DISPLAY_MODE); if (sensors_applet->sensors) { for (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(sensors_applet->sensors), &interfaces_iter); not_end_of_interfaces; not_end_of_interfaces = gtk_tree_model_iter_next(GTK_TREE_MODEL(sensors_applet->sensors), &interfaces_iter)) { @@ -255,11 +256,16 @@ static void style_set_cb(GtkWidget *widget, } -static const MateComponentUIVerb sensors_applet_menu_verbs[] = { - MATECOMPONENT_UI_UNSAFE_VERB("Preferences", prefs_cb), - MATECOMPONENT_UI_UNSAFE_VERB ("Help", help_cb), - MATECOMPONENT_UI_UNSAFE_VERB("About", about_cb), - MATECOMPONENT_UI_VERB_END +static const GtkActionEntry sensors_applet_menu_actions[] = { + { "Preferences", GTK_STOCK_PROPERTIES, N_("_Preferences"), + NULL, NULL, + G_CALLBACK(prefs_cb) }, + { "Help", GTK_STOCK_HELP, N_("_Help"), + NULL, NULL, + G_CALLBACK(help_cb) }, + { "About", GTK_STOCK_ABOUT, N_("_About"), + NULL, NULL, + G_CALLBACK(about_cb) } }; #ifdef HAVE_LIBMATENOTIFY @@ -272,58 +278,6 @@ static void notif_closed_cb(NotifyNotification *notification, } #endif // HAVE_LIBMATENOTIFY -void sensors_applet_notify(SensorsApplet *sensors_applet, - NotifType notif_type) -{ -#ifdef HAVE_LIBMATENOTIFY - gchar *message; - gchar *summary; - GError *error = NULL; - g_assert(sensors_applet); - - if (!notify_is_initted()) { - if (!notify_init(PACKAGE)) { - return; - } - } - - if (sensors_applet->notification) { - g_debug("notification already shown, not showing another one..."); - return; - } - - switch (notif_type) { - case MATECONF_READ_ERROR: - summary = g_strdup_printf(_("Error restoring saved sensor configuration.")); - message = g_strdup_printf(_("An error occurred while trying to restore the saved sensor configuration. The previous configuration has been lost and will need to be re-entered.")); - break; - - case MATECONF_WRITE_ERROR: - summary = g_strdup_printf(_("Error saving sensor configuration.")); - message = g_strdup_printf(_("An error occurred while trying to save the current sensor configuration. ")); - break; - } - - sensors_applet->notification = notify_notification_new(summary, - message, - GTK_STOCK_DIALOG_WARNING, - GTK_WIDGET(sensors_applet->applet)); - g_free(summary); - g_free(message); - - g_signal_connect(sensors_applet->notification, - "closed", - G_CALLBACK(notif_closed_cb), - sensors_applet); - g_debug("showing notification"); - if (!notify_notification_show(sensors_applet->notification, &error)) { - g_debug("Error showing notification: %s", error->message); - g_error_free(error); - } -#endif // HAVE_LIBMATENOTIFY -} - - void sensors_applet_notify_active_sensor(ActiveSensor *active_sensor, NotifType notif_type) { #ifdef HAVE_LIBMATENOTIFY @@ -347,9 +301,7 @@ void sensors_applet_notify_active_sensor(ActiveSensor *active_sensor, NotifType sensors_applet = active_sensor->sensors_applet; - if (!mate_panel_applet_mateconf_get_bool(sensors_applet->applet, - DISPLAY_NOTIFICATIONS, - NULL)) { + if (!g_settings_get_boolean (sensors_applet->settings, DISPLAY_NOTIFICATIONS)) { g_debug("Wanted to display notification, but user has disabled them"); return; } @@ -411,9 +363,7 @@ void sensors_applet_notify_active_sensor(ActiveSensor *active_sensor, NotifType case TEMP_SENSOR: unit_type_title = _("Temperature"); unit_type = _("temperature"); - temp_scale = (TemperatureScale)mate_panel_applet_mateconf_get_int(active_sensor->sensors_applet->applet, - TEMPERATURE_SCALE, - NULL); + temp_scale = (TemperatureScale) g_settings_get_int (active_sensor->sensors_applet->settings, TEMPERATURE_SCALE); switch (temp_scale) { case CELSIUS: @@ -457,9 +407,7 @@ void sensors_applet_notify_active_sensor(ActiveSensor *active_sensor, NotifType case SENSOR_INTERFACE_ERROR: summary = g_strdup_printf(_("Error updating sensor %s"), sensor_label); message = g_strdup_printf(_("An error occurred while trying to update the value of the sensor %s located at %s."), sensor_label, sensor_path); - timeout_msecs = mate_panel_applet_mateconf_get_int(active_sensor->sensors_applet->applet, - TIMEOUT, - NULL); + timeout_msecs = g_settings_get_int (active_sensor->sensors_applet->settings, TIMEOUT); break; @@ -599,10 +547,8 @@ static void sensors_applet_pack_display(SensorsApplet *sensors_applet) { /* otherwise can acess active_sensors without any worries */ num_active_sensors = g_list_length(sensors_applet->active_sensors); - display_mode = (DisplayMode)mate_panel_applet_mateconf_get_int(sensors_applet->applet, - DISPLAY_MODE, NULL); - layout_mode = (LayoutMode)mate_panel_applet_mateconf_get_int(sensors_applet->applet, - LAYOUT_MODE, NULL); + display_mode = (DisplayMode) g_settings_get_int (sensors_applet->settings, DISPLAY_MODE); + layout_mode = (LayoutMode) g_settings_get_int (sensors_applet->settings, LAYOUT_MODE); horizontal = (((mate_panel_applet_get_orient(sensors_applet->applet) == MATE_PANEL_APPLET_ORIENT_UP) || @@ -1099,8 +1045,6 @@ gboolean sensors_applet_add_sensor(SensorsApplet *sensors_applet, g_debug("Added sensor interface %s to tree", interface); } - icon = sensors_applet_load_icon(icon_type); - /* then add sensor as a child under interface node - ie assume * we either found it or created it - the inteface node that @@ -1111,28 +1055,70 @@ gboolean sensors_applet_add_sensor(SensorsApplet *sensors_applet, &sensors_iter, &interfaces_iter); - gtk_tree_store_set(sensors_applet->sensors, - &sensors_iter, - PATH_COLUMN, path, - ID_COLUMN, id, - LABEL_COLUMN, label, - INTERFACE_COLUMN, interface, - SENSOR_TYPE_COLUMN, type, - ENABLE_COLUMN, enable, - VISIBLE_COLUMN, TRUE, - LOW_VALUE_COLUMN, low_value, - HIGH_VALUE_COLUMN, high_value, - ALARM_ENABLE_COLUMN, alarm_enable, - ALARM_TIMEOUT_COLUMN, alarm_timeout, - LOW_ALARM_COMMAND_COLUMN, low_alarm_command, - HIGH_ALARM_COMMAND_COLUMN, high_alarm_command, - MULTIPLIER_COLUMN, multiplier, - OFFSET_COLUMN, offset, - ICON_TYPE_COLUMN, icon_type, - ICON_PIXBUF_COLUMN, icon, - GRAPH_COLOR_COLUMN, graph_color, - -1); - g_debug("added sensor %s to tree", path); + /* if sensor is already in settings, load values from there */ + gchar *applet_path = mate_panel_applet_get_preferences_path (sensors_applet->applet); + gchar *settings_path = g_strdup_printf ("%s%s/", + applet_path, + sensors_applet_settings_get_unique_id (interface, + id, + path)); + GSettings *settings = g_settings_new_with_path ("org.mate.sensors-applet.sensor", settings_path); + g_free (applet_path); + g_free (settings_path); + + gchar *settings_id = g_settings_get_string (settings, ID); + + if (settings_id != NULL && settings_id[0] != '\0') { + icon = sensors_applet_load_icon(g_settings_get_int (settings, ICON_TYPE)); + gtk_tree_store_set(sensors_applet->sensors, + &sensors_iter, + PATH_COLUMN, g_settings_get_string (settings, PATH), + ID_COLUMN, settings_id, + LABEL_COLUMN, g_settings_get_string (settings, LABEL), + INTERFACE_COLUMN, g_settings_get_string (settings, INTERFACE), + SENSOR_TYPE_COLUMN, g_settings_get_int (settings, SENSOR_TYPE), + ENABLE_COLUMN, g_settings_get_boolean (settings, ENABLED), + VISIBLE_COLUMN, TRUE, + LOW_VALUE_COLUMN, g_settings_get_double (settings, LOW_VALUE), + HIGH_VALUE_COLUMN, g_settings_get_double (settings, HIGH_VALUE), + ALARM_ENABLE_COLUMN, g_settings_get_boolean (settings, ALARM_ENABLED), + ALARM_TIMEOUT_COLUMN, g_settings_get_int (settings, ALARM_TIMEOUT), + LOW_ALARM_COMMAND_COLUMN, g_settings_get_string (settings, LOW_ALARM_COMMAND), + HIGH_ALARM_COMMAND_COLUMN, g_settings_get_string (settings, HIGH_ALARM_COMMAND), + MULTIPLIER_COLUMN, g_settings_get_double (settings, MULTIPLIER), + OFFSET_COLUMN, g_settings_get_double (settings, OFFSET), + ICON_TYPE_COLUMN, g_settings_get_int (settings, ICON_TYPE), + ICON_PIXBUF_COLUMN, icon, + GRAPH_COLOR_COLUMN, g_settings_get_string (settings, GRAPH_COLOR), + -1); + g_free (settings_id); + } + else { + icon = sensors_applet_load_icon(icon_type); + gtk_tree_store_set(sensors_applet->sensors, + &sensors_iter, + PATH_COLUMN, path, + ID_COLUMN, id, + LABEL_COLUMN, label, + INTERFACE_COLUMN, interface, + SENSOR_TYPE_COLUMN, type, + ENABLE_COLUMN, enable, + VISIBLE_COLUMN, TRUE, + LOW_VALUE_COLUMN, low_value, + HIGH_VALUE_COLUMN, high_value, + ALARM_ENABLE_COLUMN, alarm_enable, + ALARM_TIMEOUT_COLUMN, alarm_timeout, + LOW_ALARM_COMMAND_COLUMN, low_alarm_command, + HIGH_ALARM_COMMAND_COLUMN, high_alarm_command, + MULTIPLIER_COLUMN, multiplier, + OFFSET_COLUMN, offset, + ICON_TYPE_COLUMN, icon_type, + ICON_PIXBUF_COLUMN, icon, + GRAPH_COLOR_COLUMN, graph_color, + -1); + } + g_object_unref (settings); + g_debug("added sensor %s to tree", path); /* remove reference to icon as tree now has ref */ g_object_unref(icon); @@ -1302,9 +1288,7 @@ void sensors_applet_graph_size_changed(SensorsApplet *sensors_applet) { if (sensors_applet->active_sensors) { - graph_size = mate_panel_applet_mateconf_get_int(sensors_applet->applet, - GRAPH_SIZE, - NULL); + graph_size = g_settings_get_int (sensors_applet->settings, GRAPH_SIZE); if (mate_panel_applet_get_orient(sensors_applet->applet) == MATE_PANEL_APPLET_ORIENT_UP || mate_panel_applet_get_orient(sensors_applet->applet) == @@ -1375,6 +1359,9 @@ void sensors_applet_init(SensorsApplet *sensors_applet) { g_assert(sensors_applet); g_assert(sensors_applet->applet); + GtkActionGroup *action_group; + gchar *ui_path; + /* plugin functions are stored as name -> get_value_function pairs so * use standard string functions on hash table */ sensors_applet->plugins = g_hash_table_new(g_str_hash, @@ -1395,9 +1382,9 @@ void sensors_applet_init(SensorsApplet *sensors_applet) { G_CALLBACK(destroy_cb), sensors_applet); - - /* if not setup, write defaults to mateconf */ - sensors_applet_mateconf_setup(sensors_applet); + /* init gsettings */ + sensors_applet->settings = mate_panel_applet_settings_new (sensors_applet->applet, + "org.mate.sensors-applet"); /* now do any setup needed manually */ sensors_applet_plugins_load_all(sensors_applet); @@ -1413,12 +1400,16 @@ void sensors_applet_init(SensorsApplet *sensors_applet) { } /* only do menu and signal connections if sensors are found */ - mate_panel_applet_setup_menu_from_file(sensors_applet->applet, - DATADIR, - SENSORS_APPLET_MENU_FILE, - NULL, - sensors_applet_menu_verbs, - sensors_applet); + action_group = gtk_action_group_new ("Sensors Applet Actions"); + gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE); + gtk_action_group_add_actions (action_group, + sensors_applet_menu_actions, + G_N_ELEMENTS (sensors_applet_menu_actions), + sensors_applet); + ui_path = g_build_filename (UIDIR, SENSORS_APPLET_MENU_FILE, NULL); + mate_panel_applet_setup_menu_from_file (sensors_applet->applet, ui_path, action_group); + g_free (ui_path); + g_object_unref (action_group); g_signal_connect(sensors_applet->applet, "style-set", G_CALLBACK(style_set_cb), @@ -1441,7 +1432,7 @@ void sensors_applet_init(SensorsApplet *sensors_applet) { sensors_applet_update_active_sensors(sensors_applet); sensors_applet_pack_display(sensors_applet); - sensors_applet->timeout_id = g_timeout_add_seconds(mate_panel_applet_mateconf_get_int(sensors_applet->applet, TIMEOUT, NULL) / 1000, + sensors_applet->timeout_id = g_timeout_add_seconds(g_settings_get_int(sensors_applet->settings, TIMEOUT) / 1000, (GSourceFunc)sensors_applet_update_active_sensors, sensors_applet); gtk_widget_show_all(GTK_WIDGET(sensors_applet->applet)); diff --git a/sensors-applet/sensors-applet.h b/sensors-applet/sensors-applet.h index 62abfcb..0cd35ec 100644 --- a/sensors-applet/sensors-applet.h +++ b/sensors-applet/sensors-applet.h @@ -60,7 +60,7 @@ static const gchar * const stock_icons[NUM_ICONS] = { /* enumeration used to identify columns in the GtkTreeStore data - * structure and to access specific mateconf keys too. + * structure */ enum { PATH_COLUMN = 0, @@ -110,8 +110,6 @@ typedef enum { LOW_ALARM = 0, HIGH_ALARM, SENSOR_INTERFACE_ERROR, - MATECONF_READ_ERROR, - MATECONF_WRITE_ERROR, NUM_NOTIFS } NotifType; @@ -137,6 +135,9 @@ struct _SensorsApplet { * list of labels and sensor values into this container */ GtkWidget *table; GList *active_sensors; + + GSettings *settings; + #ifdef HAVE_LIBMATENOTIFY NotifyNotification *notification; #endif // HAVE_LIBMATENOTIFY @@ -169,8 +170,7 @@ void sensors_applet_reorder_sensors(SensorsApplet *sensors_applet); gdouble sensors_applet_convert_temperature(gdouble value, TemperatureScale old, TemperatureScale new); -void sensors_applet_notify(SensorsApplet *sensors_applet, - NotifType notif_type); + void sensors_applet_notify_end(ActiveSensor *active_sensor, NotifType notif_type); void sensors_applet_notify_end_all(SensorsApplet *sensors_applet); void sensors_applet_notify_active_sensor(ActiveSensor *active_sensor, NotifType notif_type); |