[gnome-applets/wip/gnome-3.10+: 20/48] gweather: update applet
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-applets/wip/gnome-3.10+: 20/48] gweather: update applet
- Date: Mon, 11 Aug 2014 17:03:11 +0000 (UTC)
commit 81d337e7cc9eca75e06d1385f7eaf1fefa400d53
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Sun Jul 6 16:01:10 2014 +0300
gweather: update applet
- Completely port to GSettings removing remaining gconf usage.
- Fix preferences dialog:
* Location list expanding to current selected location.
* Settings for temperature, wind speed, pressure and visiblity
units.
gweather/Makefile.am | 20 +++--
gweather/gweather-applet.c | 31 ++++--
gweather/gweather-dialog.c | 21 ++---
gweather/gweather-pref.c | 111 +++++++++++++++-----
gweather/main.c | 15 +--
...gnome.gnome-applets.gweather.gschema.xml.in.in} | 2 +-
po/POTFILES.in | 2 +-
po/POTFILES.skip | 1 +
8 files changed, 132 insertions(+), 71 deletions(-)
---
diff --git a/gweather/Makefile.am b/gweather/Makefile.am
index 265a4e6..6614088 100644
--- a/gweather/Makefile.am
+++ b/gweather/Makefile.am
@@ -58,21 +58,27 @@ org.gnome.panel.applet.GWeatherAppletFactory.service: $(service_in_files)
-e "s|\ LIBEXECDIR\@|$(libexecdir)|" \
$< > $@
-%.gschema.xml.in: %.gschema.xml.in.in
- $(AM_V_GEN)sed -e "s|\ GETTEXT_PACKAGE\@|$(GETTEXT_PACKAGE)|" $< > $@
+gsettings_schemas_in_in = \
+ org.gnome.gnome-applets.gweather.gschema.xml.in.in
@INTLTOOL_XML_NOMERGE_RULE@
- GSETTINGS_RULES@
+gsettings_schemas_in = $(gsettings_schemas_in_in:.xml.in.in=.xml.in)
+gsettings_SCHEMAS = $(gsettings_schemas_in:.xml.in=.xml)
+
+%.gschema.xml.in: %.gschema.xml.in.in Makefile
+ $(AM_V_GEN) $(SED) -e 's^\ GETTEXT_PACKAGE\@^$(GETTEXT_PACKAGE)^g' < $< > $@
-gsettings_SCHEMAS = $(builddir)/org.gnome.applets.GWeatherApplet.gschema.xml
+ GSETTINGS_RULES@
-CLEANFILES = $(applet_DATA) $(applet_DATA).in $(service_DATA)
+CLEANFILES = $(applet_DATA) $(applet_DATA).in $(service_DATA) \
+ $(gsettings_SCHEMAS_in) \
+ $(gsettings_SCHEMAS) \
+ *.gschema.valid
EXTRA_DIST = \
org.gnome.applets.GWeatherApplet.panel-applet.in.in \
- org.gnome.applets.GWeatherApplet.gschema.xml.in.in \
- org.gnome.applets.GWeatherApplet.gschema.xml \
+ $(gsettings_schemas_in_in) \
$(service_in_files) \
$(ui_DATA)
diff --git a/gweather/gweather-applet.c b/gweather/gweather-applet.c
index 8c22eac..3b5f817 100644
--- a/gweather/gweather-applet.c
+++ b/gweather/gweather-applet.c
@@ -21,9 +21,7 @@
#include <arpa/nameser.h>
#include <resolv.h>
-#include <gconf/gconf-client.h>
#include <panel-applet.h>
-#include <panel-applet-gconf.h>
#include <gdk/gdkkeysyms.h>
@@ -150,7 +148,11 @@ static void place_widgets (GWeatherApplet *gw_applet)
}
/* Create the weather icon */
- icon_name = gweather_info_get_icon_name (gw_applet->gweather_info);
+ if (gw_applet->gweather_info) {
+ icon_name = gweather_info_get_icon_name (gw_applet->gweather_info);
+ } else {
+ icon_name = "image-missing";
+ }
gw_applet->image = gtk_image_new_from_icon_name(icon_name, GTK_ICON_SIZE_BUTTON);
if (icon_name != NULL) {
@@ -165,7 +167,8 @@ static void place_widgets (GWeatherApplet *gw_applet)
gw_applet->label = gtk_label_new("--");
/* Update temperature text */
- temp = gweather_info_get_temp_summary(gw_applet->gweather_info);
+ if (gw_applet->gweather_info)
+ temp = gweather_info_get_temp_summary(gw_applet->gweather_info);
if (temp)
gtk_label_set_text(GTK_LABEL(gw_applet->label), temp);
@@ -496,20 +499,24 @@ void gweather_update (GWeatherApplet *gw_applet)
const gchar *icon_name;
GWeatherForecastType type;
- icon_name = gweather_info_get_icon_name(gw_applet->gweather_info);
- gtk_image_set_from_icon_name (GTK_IMAGE (gw_applet->image),
- icon_name, GTK_ICON_SIZE_BUTTON);
gtk_widget_set_tooltip_text (GTK_WIDGET(gw_applet->applet), _("Updating..."));
/* Set preferred forecast type */
type = g_settings_get_boolean (gw_applet->applet_settings, "detailed") ?
- GWEATHER_FORECAST_ZONE : GWEATHER_FORECAST_STATE;
+ GWEATHER_FORECAST_ZONE : GWEATHER_FORECAST_STATE;
/* Update current conditions */
- g_object_unref(gw_applet->gweather_info);
- gw_applet->gweather_info = gweather_info_new(NULL, /* default location */
- type);
- g_signal_connect(gw_applet->gweather_info, "updated", G_CALLBACK (update_finish), gw_applet);
+ if (gw_applet->gweather_info) {
+ g_object_unref (gw_applet->gweather_info);
+ }
+
+ gw_applet->gweather_info = gweather_info_new(NULL, type);
+ g_signal_connect (gw_applet->gweather_info, "updated",
+ G_CALLBACK (update_finish), gw_applet);
+
+ icon_name = gweather_info_get_icon_name (gw_applet->gweather_info);
+ gtk_image_set_from_icon_name (GTK_IMAGE (gw_applet->image),
+ icon_name, GTK_ICON_SIZE_BUTTON);
}
#ifdef HAVE_NETWORKMANAGER
diff --git a/gweather/gweather-dialog.c b/gweather/gweather-dialog.c
index 3f693fb..9ae5865 100644
--- a/gweather/gweather-dialog.c
+++ b/gweather/gweather-dialog.c
@@ -18,8 +18,6 @@
#include <stdlib.h>
#include <assert.h>
-#include <gconf/gconf-client.h>
-
#define GWEATHER_I_KNOW_THIS_IS_UNSTABLE
#include "gweather.h"
@@ -57,8 +55,8 @@ enum
G_DEFINE_TYPE (GWeatherDialog, gweather_dialog, GTK_TYPE_DIALOG);
#define GWEATHER_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GWEATHER_TYPE_DIALOG,
GWeatherDialogPrivate))
-#define MONOSPACE_FONT_DIR "/desktop/gnome/interface"
-#define MONOSPACE_FONT_KEY MONOSPACE_FONT_DIR "/monospace_font_name"
+#define MONOSPACE_GSCHEMA "org.gnome.desktop.interface"
+#define MONOSPACE_FONT_KEY "monospace-font-name"
static void
response_cb (GWeatherDialog *dialog,
@@ -504,18 +502,13 @@ gweather_dialog_create (GWeatherDialog *dialog)
static PangoFontDescription *get_system_monospace_font (void)
{
PangoFontDescription *desc = NULL;
- GConfClient *conf;
- char *name;
-
- conf = gconf_client_get_default ();
- name = gconf_client_get_string (conf, MONOSPACE_FONT_KEY, NULL);
+ GSettings *settings = g_settings_new (MONOSPACE_GSCHEMA);
+ char *name = g_settings_get_string (settings, MONOSPACE_FONT_KEY);
- if (name) {
- desc = pango_font_description_from_string (name);
- g_free (name);
- }
+ desc = pango_font_description_from_string (name);
- g_object_unref (conf);
+ g_free (name);
+ g_object_unref (settings);
return desc;
}
diff --git a/gweather/gweather-pref.c b/gweather/gweather-pref.c
index 6810b6e..7379bf5 100644
--- a/gweather/gweather-pref.c
+++ b/gweather/gweather-pref.c
@@ -25,9 +25,9 @@
#include <locale.h>
#include <panel-applet.h>
-#include <gconf/gconf-client.h>
#define GWEATHER_I_KNOW_THIS_IS_UNSTABLE
+#include <libgweather/gweather-enum-types.h>
#include "gweather-xml.h"
#include "gweather.h"
@@ -150,6 +150,67 @@ bind_update_interval_set (const GValue *value,
return g_variant_new_int32 (g_value_get_double (value) * 60);
}
+static gboolean
+string_to_enum (GValue *value,
+ GVariant *variant,
+ gpointer user_data)
+{
+ GType (* get_type) (void) = user_data;
+ GEnumClass *klass;
+ GEnumValue *eval = NULL;
+ const char *s;
+ guint i;
+
+ g_variant_get (variant, "&s", &s);
+
+ klass = g_type_class_ref (get_type ());
+ for (i = 0; i < klass->n_values; ++i) {
+ if (strcmp (klass->values[i].value_nick, s) != 0)
+ continue;
+
+ eval = &klass->values[i];
+ break;
+ }
+
+ if (eval)
+ g_value_set_int (value, eval->value - 1);
+
+ g_type_class_unref (klass);
+
+ return eval != NULL;
+}
+
+static GVariant *
+enum_to_string (const GValue *value,
+ const GVariantType *expected_type,
+ gpointer user_data)
+{
+ GType (* get_type) (void) = user_data;
+ GEnumClass *klass;
+ GEnumValue *eval = NULL;
+ int val;
+ guint i;
+ GVariant *variant = NULL;
+
+ val = g_value_get_int (value) + 1;
+
+ klass = g_type_class_ref (get_type ());
+ for (i = 0; i < klass->n_values; ++i) {
+ if (klass->values[i].value != val)
+ continue;
+
+ eval = &klass->values[i];
+ break;
+ }
+
+ if (eval)
+ variant = g_variant_new_string (eval->value_nick);
+
+ g_type_class_unref (klass);
+
+ return variant;
+}
+
/* Update pref dialog from gweather_pref */
static gboolean update_dialog (GWeatherPref *pref)
{
@@ -171,21 +232,29 @@ static gboolean update_dialog (GWeatherPref *pref)
gtk_widget_set_sensitive(pref->priv->basic_update_spin,
g_settings_get_boolean (gw_applet->applet_settings, "auto-update"));
- g_settings_bind (gw_applet->lib_settings, "temperature-unit",
+ g_settings_bind_with_mapping (gw_applet->lib_settings, "temperature-unit",
pref->priv->basic_temp_combo, "active",
- G_SETTINGS_BIND_DEFAULT);
+ G_SETTINGS_BIND_DEFAULT,
+ string_to_enum, enum_to_string,
+ gweather_temperature_unit_get_type, NULL);
- g_settings_bind (gw_applet->lib_settings, "speed-unit",
+ g_settings_bind_with_mapping (gw_applet->lib_settings, "speed-unit",
pref->priv->basic_speed_combo, "active",
- G_SETTINGS_BIND_DEFAULT);
+ G_SETTINGS_BIND_DEFAULT,
+ string_to_enum, enum_to_string,
+ gweather_speed_unit_get_type, NULL);
- g_settings_bind (gw_applet->lib_settings, "pressure-unit",
+ g_settings_bind_with_mapping (gw_applet->lib_settings, "pressure-unit",
pref->priv->basic_pres_combo, "active",
- G_SETTINGS_BIND_DEFAULT);
+ G_SETTINGS_BIND_DEFAULT,
+ string_to_enum, enum_to_string,
+ gweather_pressure_unit_get_type, NULL);
- g_settings_bind (gw_applet->lib_settings, "distance-unit",
+ g_settings_bind_with_mapping (gw_applet->lib_settings, "distance-unit",
pref->priv->basic_dist_combo, "active",
- G_SETTINGS_BIND_DEFAULT);
+ G_SETTINGS_BIND_DEFAULT,
+ string_to_enum, enum_to_string,
+ gweather_distance_unit_get_type, NULL);
#ifdef RADARMAP
has_radar = g_settings_get_boolean (gw_applet->applet_settings, "enable-radar-map");
@@ -251,16 +320,16 @@ compare_location (GtkTreeModel *model,
GtkTreeView *view;
gchar *name = NULL;
gchar *default_loc = NULL;
- gboolean retval = FALSE;
+ gboolean retval = TRUE;
gtk_tree_model_get (model, iter, GWEATHER_XML_COL_LOCATION_NAME, &name, -1);
if (!name)
retval = FALSE;
g_settings_get (pref->priv->applet->lib_settings, "default-location", "(ssm(dd))",
- &default_loc, NULL, NULL);
+ &default_loc, NULL, NULL, NULL, NULL);
- if (strcmp(name, default_loc))
+ if (g_strcmp0(name, default_loc))
retval = FALSE;
if (retval) {
@@ -332,20 +401,6 @@ auto_update_toggled (GtkToggleButton *button, GWeatherPref *pref)
}
}
-#if 0
-static void
-detailed_toggled (GtkToggleButton *button, GWeatherPref *pref)
-{
- GWeatherApplet *gw_applet = pref->priv->applet;
- gboolean toggled;
-
- toggled = gtk_toggle_button_get_active(button);
- gw_applet->gweather_pref.detailed = toggled;
- gweather_gconf_set_bool(gw_applet->gconf, "enable_detailed_forecast",
- toggled, NULL);
-}
-#endif
-
static void temp_combo_changed_cb (GtkComboBox *combo, GWeatherPref *pref)
{
GWeatherApplet *gw_applet = pref->priv->applet;
@@ -724,6 +779,7 @@ gweather_pref_create (GWeatherPref *pref)
temp_combo = gtk_combo_box_text_new ();
pref->priv->basic_temp_combo = temp_combo;
gtk_label_set_mnemonic_widget (GTK_LABEL (temp_label), temp_combo);
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (temp_combo), _("Default"));
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (temp_combo), _("Kelvin"));
/* TRANSLATORS: Celsius is sometimes referred Centigrade */
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (temp_combo), _("Celsius"));
@@ -740,6 +796,7 @@ gweather_pref_create (GWeatherPref *pref)
speed_combo = gtk_combo_box_text_new ();
pref->priv->basic_speed_combo = speed_combo;
gtk_label_set_mnemonic_widget (GTK_LABEL (speed_label), speed_combo);
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (speed_combo), _("Default"));
/* TRANSLATOR: The wind speed unit "meters per second" */
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (speed_combo), _("m/s"));
/* TRANSLATOR: The wind speed unit "kilometers per hour" */
@@ -762,6 +819,7 @@ gweather_pref_create (GWeatherPref *pref)
pres_combo = gtk_combo_box_text_new ();
pref->priv->basic_pres_combo = pres_combo;
gtk_label_set_mnemonic_widget (GTK_LABEL (pres_label), pres_combo);
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (pres_combo), _("Default"));
/* TRANSLATOR: The pressure unit "kiloPascals" */
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (pres_combo), _("kPa"));
/* TRANSLATOR: The pressure unit "hectoPascals" */
@@ -786,6 +844,7 @@ gweather_pref_create (GWeatherPref *pref)
dist_combo = gtk_combo_box_text_new ();
pref->priv->basic_dist_combo = dist_combo;
gtk_label_set_mnemonic_widget (GTK_LABEL (dist_label), dist_combo);
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dist_combo), _("Default"));
/* TRANSLATOR: The distance unit "meters" */
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (dist_combo), _("meters"));
/* TRANSLATOR: The distance unit "kilometers" */
diff --git a/gweather/main.c b/gweather/main.c
index ba77cc4..33f1a2d 100644
--- a/gweather/main.c
+++ b/gweather/main.c
@@ -27,22 +27,17 @@
static gboolean
gweather_applet_new(PanelApplet *applet, const gchar *iid, gpointer data)
{
- GWeatherApplet *gw_applet;
+ GWeatherApplet *gw_applet = g_new0(GWeatherApplet, 1);
- char *prefs_key = panel_applet_get_preferences_key(applet);
-
- gw_applet = g_new0(GWeatherApplet, 1);
-
gw_applet->applet = applet;
gw_applet->gweather_info = NULL;
gw_applet->lib_settings = g_settings_new("org.gnome.GWeather");
- gw_applet->applet_settings = panel_applet_settings_new(applet, "org.gnome.applets.GWeatherApplet");
- g_free (prefs_key);
- gweather_applet_create(gw_applet);
+ gw_applet->applet_settings = panel_applet_settings_new(applet, "org.gnome.gnome-applets.gweather");
- gweather_update(gw_applet);
+ gweather_applet_create(gw_applet);
+ gweather_update(gw_applet);
- return TRUE;
+ return TRUE;
}
static gboolean
diff --git a/gweather/org.gnome.applets.GWeatherApplet.gschema.xml.in.in
b/gweather/org.gnome.gnome-applets.gweather.gschema.xml.in.in
similarity index 96%
rename from gweather/org.gnome.applets.GWeatherApplet.gschema.xml.in.in
rename to gweather/org.gnome.gnome-applets.gweather.gschema.xml.in.in
index e4a312b..608096c 100644
--- a/gweather/org.gnome.applets.GWeatherApplet.gschema.xml.in.in
+++ b/gweather/org.gnome.gnome-applets.gweather.gschema.xml.in.in
@@ -1,5 +1,5 @@
<schemalist gettext-domain="@GETTEXT_PACKAGE@">
- <schema id="org.gnome.applets.GWeatherApplet">
+ <schema id="org.gnome.gnome-applets.gweather">
<key name="auto-update" type="b">
<default>true</default>
<_summary>Update the data automatically</_summary>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index af0440d..bcd211a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -38,7 +38,7 @@ gweather/gweather-applet.c
gweather/gweather-dialog.c
gweather/gweather-pref.c
gweather/main.c
-gweather/org.gnome.applets.GWeatherApplet.gschema.xml.in.in
+gweather/org.gnome.applets.gweather.gschema.xml.in.in
[type: gettext/ini]gweather/org.gnome.applets.GWeatherApplet.panel-applet.in.in
[type: gettext/ini]invest-applet/data/org.gnome.applets.InvestApplet.panel-applet.in.in
[type: gettext/glade]invest-applet/data/financialchart.ui
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 5d4cbbb..9aca018 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -12,6 +12,7 @@ drivemount/drivemount/org.gnome.applets.DriveMountApplet.panel-applet.in
geyes/org.gnome.applets.GeyesApplet.panel-applet.in
geyes/org.gnome.gnome-applets.geyes.gschema.xml.in
gweather/org.gnome.applets.GWeatherApplet.panel-applet.in
+gweather/org.gnome.gnome-applets.gweather.gschema.xml.in
gweather/Locations.xml.in
invest-applet/data/Invest_Applet.server.in
mini-commander/src/org.gnome.applets.MiniCommanderApplet.panel-applet.in
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]