[gnome-panel] Clock Applet: port to modern GNOME technologies
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel] Clock Applet: port to modern GNOME technologies
- Date: Thu, 21 Jun 2012 17:31:04 +0000 (UTC)
commit cd1a0db671b6eb57efcf2770287882e625ae1753
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Mon Mar 5 22:44:35 2012 +0100
Clock Applet: port to modern GNOME technologies
This is a big commit that updates the Clock Applet to use modern
libraries. This includes using GSettings instead of GConf, using
GDateTime instead of the equivalents from libc and using the new
API in libgweather.
https://bugzilla.gnome.org/show_bug.cgi?id=677512
applets/clock/Makefile.am | 21 -
applets/clock/calendar-window.c | 298 +---
applets/clock/calendar-window.h | 12 +-
applets/clock/clock-face.c | 31 +-
applets/clock/clock-location-tile.c | 215 ++--
applets/clock/clock-location-tile.h | 4 +-
applets/clock/clock-location.c | 443 +----
applets/clock/clock-location.h | 47 +-
applets/clock/clock-map.c | 2 +-
applets/clock/clock-menu.xml | 1 -
applets/clock/clock-utils.c | 5 +-
applets/clock/clock-utils.h | 13 +-
applets/clock/clock.c | 1784 +++-----------------
applets/clock/clock.schemas.in | 313 ----
configure.ac | 2 +-
data/Makefile.am | 3 +-
...nome.gnome-panel.applet.clock.gschema.xml.in.in | 39 +-
17 files changed, 524 insertions(+), 2709 deletions(-)
---
diff --git a/applets/clock/Makefile.am b/applets/clock/Makefile.am
index b23ca97..e522e1f 100644
--- a/applets/clock/Makefile.am
+++ b/applets/clock/Makefile.am
@@ -169,28 +169,8 @@ clock-resources.c: clock.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourc
clock-resources.h: clock.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/clock.gresource.xml)
$(AM_V_GEN)$(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) --generate --c-name clock $<
-schemasdir = $(GCONF_SCHEMA_FILE_DIR)
-schemas_in_files = clock.schemas.in
-schemas_DATA = $(schemas_in_files:.schemas.in=.schemas)
-
- INTLTOOL_SCHEMAS_RULE@
-
-if GCONF_SCHEMAS_INSTALL
-install-data-local:
- if test -z "$(DESTDIR)" ; then \
- for p in $(schemas_DATA) ; do \
- GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-install-rule $(top_builddir)/applets/clock/$$p ; \
- done \
- fi
-uninstall-local:
- for p in $(schema_DATA) ; do \
- GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) $(GCONFTOOL) --makefile-uninstall-rule $(top_builddir)/applets/clock/$$p ; \
- done
-endif
-
EXTRA_DIST = \
org.gnome.panel.ClockApplet.panel-applet.in.in \
- $(schemas_in_files) \
$(ui_FILES) \
clock.gresource.xml \
clock-marshallers.list \
@@ -201,7 +181,6 @@ CLEANFILES = \
$(applet_DATA) \
$(applet_DATA).in \
$(service_DATA) \
- $(schemas_DATA) \
$(polkit_DATA) \
$(dbus_services_DATA)
diff --git a/applets/clock/calendar-window.c b/applets/clock/calendar-window.c
index 9fd5c0e..6c9a31a 100644
--- a/applets/clock/calendar-window.c
+++ b/applets/clock/calendar-window.c
@@ -40,7 +40,7 @@
#include <string.h>
#include <glib/gi18n.h>
-#include <gconf/gconf-client.h>
+#include <gio/gio.h>
#define GNOME_DESKTOP_USE_UNSTABLE_API
#include <libgnome-desktop/gnome-desktop-utils.h>
@@ -56,19 +56,15 @@
#define CALENDAR_WINDOW_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CALENDAR_TYPE_WINDOW, CalendarWindowPrivate))
-#define KEY_LOCATIONS_EXPANDED "expand_locations"
+#define KEY_LOCATIONS_EXPANDED "expand-locations"
#ifdef HAVE_LIBECAL
-/* For the following value, take into account the KEY_* that are not inside this #ifdef! */
-# define N_CALENDAR_WINDOW_GCONF_PREFS 5
-# define KEY_APPOINTMENTS_EXPANDED "expand_appointments"
-# define KEY_BIRTHDAYS_EXPANDED "expand_birthdays"
-# define KEY_TASKS_EXPANDED "expand_tasks"
-# define KEY_WEATHER_EXPANDED "expand_weather"
+# define KEY_APPOINTMENTS_EXPANDED "expand-appointments"
+# define KEY_BIRTHDAYS_EXPANDED "expand-birthdays"
+# define KEY_TASKS_EXPANDED "expand-tasks"
+# define KEY_WEATHER_EXPANDED "expand-weather"
# define SCHEMA_CALENDAR_APP "org.gnome.desktop.default-applications.office.calendar"
# define SCHEMA_TASKS_APP "org.gnome.desktop.default-applications.office.tasks"
-#else
-# define N_CALENDAR_WINDOW_GCONF_PREFS 1
#endif
enum {
@@ -81,18 +77,17 @@ static guint signals[LAST_SIGNAL];
struct _CalendarWindowPrivate {
GtkWidget *calendar;
- char *prefs_dir;
+ GSettings *settings;
gboolean invert_order;
gboolean show_weeks;
- time_t *current_time;
gboolean locked_down;
GtkWidget *locations_list;
#ifdef HAVE_LIBECAL
- ClockFormat time_format;
+ GDesktopClockFormat time_format;
CalendarClient *client;
@@ -110,8 +105,6 @@ struct _CalendarWindowPrivate {
GtkTreeModelFilter *birthdays_filter;
GtkTreeModelFilter *tasks_filter;
GtkTreeModelFilter *weather_filter;
-
- GConfClient *gconfclient;
#endif /* HAVE_LIBECAL */
};
@@ -121,20 +114,13 @@ enum {
PROP_0,
PROP_INVERTORDER,
PROP_SHOWWEEKS,
-#ifdef HAVE_LIBECAL
- PROP_TIMEFORMAT,
-#endif
- PROP_CURRENTTIMEP,
- PROP_PREFSDIR,
+ PROP_SETTINGS,
PROP_LOCKEDDOWN
};
-static time_t *calendar_window_get_current_time_p (CalendarWindow *calwin);
-static void calendar_window_set_current_time_p (CalendarWindow *calwin,
- time_t *current_time);
-static const char *calendar_window_get_prefs_dir (CalendarWindow *calwin);
-static void calendar_window_set_prefs_dir (CalendarWindow *calwin,
- const char *prefs_dir);
+static GSettings *calendar_window_get_settings (CalendarWindow *calwin);
+static void calendar_window_set_settings (CalendarWindow *calwin,
+ GSettings *settings);
static gboolean calendar_window_get_locked_down (CalendarWindow *calwin);
static void calendar_window_set_locked_down (CalendarWindow *calwin,
gboolean locked_down);
@@ -296,7 +282,7 @@ enum {
};
static char *
-format_time (ClockFormat format,
+format_time (GDesktopClockFormat format,
time_t t,
guint year,
guint month,
@@ -316,7 +302,7 @@ format_time (ClockFormat format,
if (year == (tm->tm_year + 1900) &&
month == tm->tm_mon &&
day == tm->tm_mday) {
- if (format == CLOCK_FORMAT_12)
+ if (format == G_DESKTOP_CLOCK_FORMAT_12H)
/* Translators: This is a strftime format string.
* It is used to display the time in 12-hours format
* (eg, like in the US: 8:10 am). The %p expands to
@@ -479,23 +465,30 @@ filter_out_tasks (GtkTreeModel *model,
{
gint64 start_time64;
gint64 completed_time64;
- time_t start_time;
- time_t completed_time;
- time_t one_day_ago;
+ GDateTime *start_time;
+ GDateTime *completed_time;
+ GDateTime *one_day_ago;
+ GDateTime *current_time;
gboolean visible;
gtk_tree_model_get (model, iter,
TASK_COLUMN_START_TIME, &start_time64,
TASK_COLUMN_COMPLETED_TIME, &completed_time64,
-1);
- start_time = start_time64;
- completed_time = completed_time64;
- one_day_ago = *(calwin->priv->current_time) - (24 * 60 * 60);
+ current_time = g_date_time_new_now_local ();
+ start_time = g_date_time_new_from_unix_local (start_time64);
+ completed_time = g_date_time_new_from_unix_local (completed_time64);
+ one_day_ago = g_date_time_add_days (completed_time, -1);
- visible = !start_time || start_time <= *(calwin->priv->current_time);
+ visible = g_date_time_compare (start_time, current_time) <= 0;
if (visible)
- visible = !completed_time || completed_time >= one_day_ago;
+ visible = g_date_time_compare (completed_time, one_day_ago) >= 0;
+
+ g_date_time_unref (start_time);
+ g_date_time_unref (completed_time);
+ g_date_time_unref (one_day_ago);
+ g_date_time_unref (current_time);
return visible;
}
@@ -509,6 +502,7 @@ modify_task_text_attributes (GtkTreeModel *model,
{
gint64 due_time64;
time_t due_time;
+ time_t current_time;
PangoAttrList *attr_list;
PangoAttribute *attr;
GtkTreeIter child_iter;
@@ -530,7 +524,8 @@ modify_task_text_attributes (GtkTreeModel *model,
-1);
due_time = due_time64;
- if (due_time && due_time > *(calwin->priv->current_time))
+ current_time = time(NULL);
+ if (due_time && due_time > current_time)
return;
attr_list = pango_attr_list_new ();
@@ -1305,78 +1300,6 @@ setup_list_size_constraint (GtkWidget *widget,
gtk_widget_set_size_request (widget, req.width, req_height);
}
-static void
-expander_activated (GtkExpander *expander,
- CalendarWindow *calwin)
-{
- const char *key;
-
- key = (const gchar*)g_object_get_data (G_OBJECT (expander), "gconf-key");
-
- if (gconf_client_key_is_writable (calwin->priv->gconfclient,
- key, NULL)) {
- gconf_client_set_bool (calwin->priv->gconfclient, key,
- gtk_expander_get_expanded (expander),
- NULL);
- }
-}
-
-static void
-expanded_changed (GConfClient *client,
- guint cnxn_id,
- GConfEntry *entry,
- GtkExpander *expander)
-{
- gboolean value;
-
- if (!entry->value || entry->value->type != GCONF_VALUE_BOOL)
- return;
-
- value = gconf_value_get_bool (entry->value);
-
- gtk_expander_set_expanded (expander, value);
-}
-
-static void
-remove_listener (gpointer data)
-{
- GConfClient *client;
-
- client = gconf_client_get_default ();
- gconf_client_notify_remove (client, GPOINTER_TO_UINT (data));
- g_object_unref (client);
-}
-
-static void
-connect_expander_with_gconf (CalendarWindow *calwin,
- GtkWidget *expander,
- const char *relative_key)
-{
- char *key;
- gboolean expanded;
- guint listener;
-
- key = g_strdup_printf ("%s/%s",
- calwin->priv->prefs_dir, relative_key);
-
- g_object_set_data_full (G_OBJECT (expander), "gconf-key", (gpointer)key, g_free);
-
- expanded = gconf_client_get_bool (calwin->priv->gconfclient, key,
- NULL);
- gtk_expander_set_expanded (GTK_EXPANDER (expander), expanded);
-
- g_signal_connect_after (expander, "activate",
- G_CALLBACK (expander_activated),
- calwin);
-
- listener = gconf_client_notify_add (
- calwin->priv->gconfclient, key,
- (GConfClientNotifyFunc) expanded_changed,
- expander, NULL, NULL);
-
- g_object_set_data_full (G_OBJECT (expander), "listener-id",
- GUINT_TO_POINTER (listener), remove_listener);
-}
#endif /* HAVE_LIBECAL */
static void
@@ -1490,7 +1413,7 @@ calendar_window_create_calendar (CalendarWindow *calwin)
{
GtkWidget *calendar;
GtkCalendarDisplayOptions options;
- struct tm *tm;
+ GDateTime *now;
calendar = gtk_calendar_new ();
options = gtk_calendar_get_display_options (GTK_CALENDAR (calendar));
@@ -1500,12 +1423,15 @@ calendar_window_create_calendar (CalendarWindow *calwin)
options &= ~(GTK_CALENDAR_SHOW_WEEK_NUMBERS);
gtk_calendar_set_display_options (GTK_CALENDAR (calendar), options);
- tm = localtime (calwin->priv->current_time);
+ now = g_date_time_new_now_local ();
gtk_calendar_select_month (GTK_CALENDAR (calendar),
- tm->tm_mon,
- tm->tm_year + 1900);
- gtk_calendar_select_day (GTK_CALENDAR (calendar), tm->tm_mday);
+ g_date_time_get_month (now),
+ g_date_time_get_year (now));
+ gtk_calendar_select_day (GTK_CALENDAR (calendar),
+ g_date_time_get_day_of_month (now));
+
+ g_date_time_unref (now);
return calendar;
}
@@ -1605,7 +1531,8 @@ create_hig_frame (CalendarWindow *calwin,
}
#ifdef HAVE_LIBECAL
- connect_expander_with_gconf (calwin, expander, key);
+ g_settings_bind (calwin->priv->settings, key, expander, "expanded",
+ G_SETTINGS_BIND_DEFAULT);
#endif
return vbox;
@@ -1687,8 +1614,7 @@ calendar_window_constructor (GType type,
calwin = CALENDAR_WINDOW (obj);
- g_assert (calwin->priv->current_time != NULL);
- g_assert (calwin->priv->prefs_dir != NULL);
+ g_assert (calwin->priv->settings != NULL);
calendar_window_fill (calwin);
@@ -1716,19 +1642,9 @@ calendar_window_get_property (GObject *object,
g_value_set_boolean (value,
calendar_window_get_show_weeks (calwin));
break;
-#ifdef HAVE_LIBECAL
- case PROP_TIMEFORMAT:
- g_value_set_enum (value,
- calendar_window_get_time_format (calwin));
- break;
-#endif
- case PROP_CURRENTTIMEP:
- g_value_set_pointer (value,
- calendar_window_get_current_time_p (calwin));
- break;
- case PROP_PREFSDIR:
- g_value_set_string (value,
- calendar_window_get_prefs_dir (calwin));
+ case PROP_SETTINGS:
+ g_value_set_object (value,
+ calendar_window_get_settings (calwin));
break;
case PROP_LOCKEDDOWN:
g_value_set_boolean (value,
@@ -1761,19 +1677,9 @@ calendar_window_set_property (GObject *object,
calendar_window_set_show_weeks (calwin,
g_value_get_boolean (value));
break;
-#ifdef HAVE_LIBECAL
- case PROP_TIMEFORMAT:
- calendar_window_set_time_format (calwin,
- g_value_get_enum (value));
- break;
-#endif
- case PROP_CURRENTTIMEP:
- calendar_window_set_current_time_p (calwin,
- g_value_get_pointer (value));
- break;
- case PROP_PREFSDIR:
- calendar_window_set_prefs_dir (calwin,
- g_value_get_string (value));
+ case PROP_SETTINGS:
+ calendar_window_set_settings (calwin,
+ g_value_get_object (value));
break;
case PROP_LOCKEDDOWN:
calendar_window_set_locked_down (calwin,
@@ -1821,9 +1727,7 @@ calendar_window_dispose (GObject *object)
g_object_unref (calwin->priv->weather_filter);
calwin->priv->weather_filter = NULL;
- if (calwin->priv->gconfclient)
- g_object_unref (calwin->priv->gconfclient);
- calwin->priv->gconfclient = NULL;
+ g_clear_object (&calwin->priv->settings);
#endif /* HAVE_LIBECAL */
G_OBJECT_CLASS (calendar_window_parent_class)->dispose (object);
@@ -1868,33 +1772,13 @@ calendar_window_class_init (CalendarWindowClass *klass)
FALSE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
-#ifdef HAVE_LIBECAL
- g_object_class_install_property (
- gobject_class,
- PROP_TIMEFORMAT,
- g_param_spec_enum ("time-format",
- "Time Format",
- "Time format used to display time",
- CLOCK_TYPE_FORMAT,
- clock_locale_format (),
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
-#endif
-
g_object_class_install_property (
gobject_class,
- PROP_CURRENTTIMEP,
- g_param_spec_pointer ("current-time",
- "Current Time",
- "Pointer to a variable containing the current time",
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
- g_object_class_install_property (
- gobject_class,
- PROP_PREFSDIR,
- g_param_spec_string ("prefs-dir",
- "Preferences Directory",
- "Preferences directory in GConf",
- NULL,
+ PROP_SETTINGS,
+ g_param_spec_object ("settings",
+ "Applet settings",
+ "",
+ G_TYPE_SETTINGS,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (
@@ -1924,22 +1808,19 @@ calendar_window_init (CalendarWindow *calwin)
#ifdef HAVE_LIBECAL
calwin->priv->previous_selection = NULL;
- calwin->priv->gconfclient = gconf_client_get_default ();
#endif
}
GtkWidget *
-calendar_window_new (time_t *static_current_time,
- const char *prefs_dir,
+calendar_window_new (GSettings *applet_settings,
gboolean invert_order)
{
CalendarWindow *calwin;
calwin = g_object_new (CALENDAR_TYPE_WINDOW,
"type", GTK_WINDOW_TOPLEVEL,
- "current-time", static_current_time,
"invert-order", invert_order,
- "prefs-dir", prefs_dir,
+ "settings", applet_settings,
NULL);
return GTK_WIDGET (calwin);
@@ -2021,27 +1902,28 @@ calendar_window_set_show_weeks (CalendarWindow *calwin,
g_object_notify (G_OBJECT (calwin), "show-weeks");
}
-ClockFormat
+GDesktopClockFormat
calendar_window_get_time_format (CalendarWindow *calwin)
{
g_return_val_if_fail (CALENDAR_IS_WINDOW (calwin),
- CLOCK_FORMAT_INVALID);
+ G_DESKTOP_CLOCK_FORMAT_24H);
#ifdef HAVE_LIBECAL
return calwin->priv->time_format;
#else
- return CLOCK_FORMAT_INVALID;
+ return G_DESKTOP_CLOCK_FORMAT_24H;
#endif
}
void
-calendar_window_set_time_format (CalendarWindow *calwin,
- ClockFormat time_format)
+calendar_window_set_time_format (CalendarWindow *calwin,
+ GDesktopClockFormat time_format)
{
g_return_if_fail (CALENDAR_IS_WINDOW (calwin));
#ifdef HAVE_LIBECAL
- if (time_format != CLOCK_FORMAT_12 && time_format != CLOCK_FORMAT_24)
+ if (time_format != G_DESKTOP_CLOCK_FORMAT_12H &&
+ time_format != G_DESKTOP_CLOCK_FORMAT_24H)
time_format = clock_locale_format ();
if (time_format == calwin->priv->time_format)
@@ -2051,62 +1933,26 @@ calendar_window_set_time_format (CalendarWindow *calwin,
/* Time to display for appointments has changed */
if (calwin->priv->appointments_model)
handle_appointments_changed (calwin);
-
- g_object_notify (G_OBJECT (calwin), "time-format");
#endif
}
-static time_t *
-calendar_window_get_current_time_p (CalendarWindow *calwin)
-{
- g_return_val_if_fail (CALENDAR_IS_WINDOW (calwin), NULL);
-
- return calwin->priv->current_time;
-}
-
-static void
-calendar_window_set_current_time_p (CalendarWindow *calwin,
- time_t *current_time)
-{
- g_return_if_fail (CALENDAR_IS_WINDOW (calwin));
-
- if (current_time == calwin->priv->current_time)
- return;
-
- calwin->priv->current_time = current_time;
-
- g_object_notify (G_OBJECT (calwin), "current-time");
-}
-
-static const char *
-calendar_window_get_prefs_dir (CalendarWindow *calwin)
+static GSettings *
+calendar_window_get_settings (CalendarWindow *calwin)
{
g_return_val_if_fail (CALENDAR_IS_WINDOW (calwin), NULL);
- return calwin->priv->prefs_dir;
+ return calwin->priv->settings;
}
static void
-calendar_window_set_prefs_dir (CalendarWindow *calwin,
- const char *prefs_dir)
+calendar_window_set_settings (CalendarWindow *calwin,
+ GSettings *settings)
{
g_return_if_fail (CALENDAR_IS_WINDOW (calwin));
- if (!calwin->priv->prefs_dir && (!prefs_dir || !prefs_dir [0]))
- return;
-
- if (calwin->priv->prefs_dir && prefs_dir && prefs_dir [0] &&
- !strcmp (calwin->priv->prefs_dir, prefs_dir))
- return;
-
- if (calwin->priv->prefs_dir)
- g_free (calwin->priv->prefs_dir);
- calwin->priv->prefs_dir = NULL;
-
- if (prefs_dir && prefs_dir [0])
- calwin->priv->prefs_dir = g_strdup (prefs_dir);
-
- g_object_notify (G_OBJECT (calwin), "prefs-dir");
+ /* This only ever called once, so we can ignore the previous
+ value. */
+ calwin->priv->settings = g_object_ref (settings);
}
static gboolean
diff --git a/applets/clock/calendar-window.h b/applets/clock/calendar-window.h
index 0de882b..407e083 100644
--- a/applets/clock/calendar-window.h
+++ b/applets/clock/calendar-window.h
@@ -29,6 +29,9 @@
#define CALENDAR_WINDOW_H
#include <gtk/gtk.h>
+#include <gio/gio.h>
+#include <gdesktop-enums.h>
+
#include "clock-utils.h"
G_BEGIN_DECLS
@@ -57,8 +60,7 @@ struct _CalendarWindowClass {
};
GType calendar_window_get_type (void) G_GNUC_CONST;
-GtkWidget *calendar_window_new (time_t *static_current_time,
- const char *prefs_dir,
+GtkWidget *calendar_window_new (GSettings *applet_settings,
gboolean invert_order);
void calendar_window_refresh (CalendarWindow *calwin);
@@ -71,9 +73,9 @@ void calendar_window_set_invert_order (CalendarWindow *calwin,
gboolean calendar_window_get_show_weeks (CalendarWindow *calwin);
void calendar_window_set_show_weeks (CalendarWindow *calwin,
gboolean show_weeks);
-ClockFormat calendar_window_get_time_format (CalendarWindow *calwin);
-void calendar_window_set_time_format (CalendarWindow *calwin,
- ClockFormat time_format);
+GDesktopClockFormat calendar_window_get_time_format (CalendarWindow *calwin);
+void calendar_window_set_time_format (CalendarWindow *calwin,
+ GDesktopClockFormat time_format);
G_END_DECLS
diff --git a/applets/clock/clock-face.c b/applets/clock/clock-face.c
index 7ffe1fe..2e95b11 100644
--- a/applets/clock/clock-face.c
+++ b/applets/clock/clock-face.c
@@ -51,7 +51,7 @@ typedef enum {
struct _ClockFacePrivate
{
- struct tm time; /* the time on the clock face */
+ GDateTime *time; /* the time on the clock face */
int minute_offset; /* the offset of the minutes hand */
ClockFaceSize size;
@@ -137,9 +137,9 @@ clock_face_draw (GtkWidget *this, cairo_t *cr)
}
/* clock hands */
- hours = priv->time.tm_hour;
- minutes = priv->time.tm_min + priv->minute_offset;
- seconds = priv->time.tm_sec;
+ hours = g_date_time_get_hour (priv->time);
+ minutes = g_date_time_get_minute (priv->time) + priv->minute_offset;
+ seconds = g_date_time_get_seconds (priv->time);
cairo_set_line_width (cr, 1);
@@ -280,17 +280,17 @@ update_time_and_face (ClockFace *this,
{
ClockFacePrivate *priv;
ClockFaceTimeOfDay timeofday;
+ int hour;
priv = this->priv;
+ if (priv->time)
+ g_date_time_unref (priv->time);
/* update the time */
- if (priv->location) {
- clock_location_localtime (priv->location, &priv->time);
- } else {
- time_t timet;
- time (&timet);
- localtime_r (&timet, &priv->time);
- }
+ if (priv->location)
+ priv->time = clock_location_localtime (priv->location);
+ else
+ priv->time = g_date_time_new_now_local ();
/* FIXME this should be a gconf setting
* Or we could use some code from clock-sun.c?
@@ -300,13 +300,14 @@ update_time_and_face (ClockFace *this,
* evening 17-22
* night 22-7
*/
- if (priv->time.tm_hour < 7)
+ hour = g_date_time_get_hour (priv->time);
+ if (hour < 7)
timeofday = CLOCK_FACE_NIGHT;
- else if (priv->time.tm_hour < 9)
+ else if (hour < 9)
timeofday = CLOCK_FACE_MORNING;
- else if (priv->time.tm_hour < 17)
+ else if (hour < 17)
timeofday = CLOCK_FACE_DAY;
- else if (priv->time.tm_hour < 22)
+ else if (hour < 22)
timeofday = CLOCK_FACE_EVENING;
else
timeofday = CLOCK_FACE_NIGHT;
diff --git a/applets/clock/clock-location-tile.c b/applets/clock/clock-location-tile.c
index 100cf8a..2134486 100644
--- a/applets/clock/clock-location-tile.c
+++ b/applets/clock/clock-location-tile.c
@@ -30,7 +30,7 @@ static guint signals[LAST_SIGNAL];
typedef struct {
ClockLocation *location;
- struct tm last_refresh;
+ GDateTime *last_refresh;
long last_offset;
ClockFaceSize size;
@@ -57,7 +57,7 @@ static void clock_location_tile_finalize (GObject *);
#define PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CLOCK_LOCATION_TILE_TYPE, ClockLocationTilePrivate))
static void clock_location_tile_fill (ClockLocationTile *this);
-static void update_weather_icon (ClockLocation *loc, WeatherInfo *info, gpointer data);
+static void update_weather_icon (ClockLocation *loc, GWeatherInfo *info, gpointer data);
static gboolean weather_tooltip (GtkWidget *widget,
gint x, gint y,
gboolean keyboard_mode,
@@ -124,7 +124,7 @@ clock_location_tile_init (ClockLocationTile *this)
priv->location = NULL;
- memset (&(priv->last_refresh), 0, sizeof (struct tm));
+ priv->last_refresh = NULL;
priv->last_offset = 0;
priv->size = CLOCK_FACE_SMALL;
@@ -139,6 +139,11 @@ clock_location_tile_finalize (GObject *g_obj)
{
ClockLocationTilePrivate *priv = PRIVATE (g_obj);
+ if (priv->last_refresh) {
+ g_date_time_unref (priv->last_refresh);
+ priv->last_refresh = NULL;
+ }
+
if (priv->location) {
g_signal_handler_disconnect (priv->location, priv->location_weather_updated_id);
priv->location_weather_updated_id = 0;
@@ -361,80 +366,74 @@ static gboolean
clock_needs_face_refresh (ClockLocationTile *this)
{
ClockLocationTilePrivate *priv = PRIVATE (this);
- struct tm now;
+ GDateTime *now;
+ gboolean retval;
- clock_location_localtime (priv->location, &now);
+ if (!priv->last_refresh)
+ return TRUE;
- if (now.tm_year > priv->last_refresh.tm_year
- || now.tm_mon > priv->last_refresh.tm_mon
- || now.tm_mday > priv->last_refresh.tm_mday
- || now.tm_hour > priv->last_refresh.tm_hour
- || now.tm_min > priv->last_refresh.tm_min) {
- return TRUE;
+ now = clock_location_localtime (priv->location);
+
+ retval = FALSE;
+ if (g_date_time_get_year (now) > g_date_time_get_year (priv->last_refresh)
+ || g_date_time_get_month (now) > g_date_time_get_month (priv->last_refresh)
+ || g_date_time_get_day_of_month (now) > g_date_time_get_day_of_month (priv->last_refresh)
+ || g_date_time_get_hour (now) > g_date_time_get_hour (priv->last_refresh)
+ || g_date_time_get_minute (now) > g_date_time_get_minute (priv->last_refresh)) {
+ retval = TRUE;
}
if ((priv->size == CLOCK_FACE_LARGE)
- && now.tm_sec > priv->last_refresh.tm_sec) {
- return TRUE;
+ && g_date_time_get_second (now) > g_date_time_get_second (priv->last_refresh)) {
+ retval = TRUE;
}
- return FALSE;
+ g_date_time_unref (now);
+ return retval;
}
static gboolean
clock_needs_label_refresh (ClockLocationTile *this)
{
ClockLocationTilePrivate *priv = PRIVATE (this);
- struct tm now;
+ GDateTime *now;
long offset;
+ gboolean retval;
- clock_location_localtime (priv->location, &now);
+ now = clock_location_localtime (priv->location);
offset = clock_location_get_offset (priv->location);
- if (now.tm_year > priv->last_refresh.tm_year
- || now.tm_mon > priv->last_refresh.tm_mon
- || now.tm_mday > priv->last_refresh.tm_mday
- || now.tm_hour > priv->last_refresh.tm_hour
- || now.tm_min > priv->last_refresh.tm_min
+ retval = FALSE;
+ if (g_date_time_get_year (now) > g_date_time_get_year (priv->last_refresh)
+ || g_date_time_get_month (now) > g_date_time_get_month (priv->last_refresh)
+ || g_date_time_get_day_of_month (now) > g_date_time_get_day_of_month (priv->last_refresh)
+ || g_date_time_get_hour (now) > g_date_time_get_hour (priv->last_refresh)
+ || g_date_time_get_minute (now) > g_date_time_get_minute (priv->last_refresh)
|| offset != priv->last_offset) {
- return TRUE;
+ retval = TRUE;
}
- return FALSE;
-}
-
-static void
-copy_tm (struct tm *from, struct tm *to)
-{
- to->tm_sec = from->tm_sec;
- to->tm_min = from->tm_min;
- to->tm_hour = from->tm_hour;
- to->tm_mday = from->tm_mday;
- to->tm_mon = from->tm_mon;
- to->tm_year = from->tm_year;
- to->tm_wday = from->tm_wday;
- to->tm_yday = from->tm_yday;
+ g_date_time_unref (now);
+ return retval;
}
static char *
-format_time (struct tm *now,
- char *tzname,
- ClockFormat clock_format,
+format_time (GDateTime *now,
+ const char *tzname,
+ GDesktopClockFormat clock_format,
long offset)
{
- char buf[256];
- char *format;
- time_t local_t;
- struct tm local_now;
- char *utf8;
+ const char *format;
+ GDateTime *local_now;
+ char *buf;
char *tmp;
long hours, minutes;
- time (&local_t);
- localtime_r (&local_t, &local_now);
+ local_now = g_date_time_new_now_local ();
- if (local_now.tm_wday != now->tm_wday) {
- if (clock_format == CLOCK_FORMAT_12) {
+ if (g_date_time_get_day_of_week (local_now) !=
+ g_date_time_get_day_of_week (now)) {
+ if (clock_format == G_DESKTOP_CLOCK_FORMAT_12H) {
/* Translators: This is a strftime format string.
* It is used to display the time in 12-hours format
* (eg, like in the US: 8:10 am), when the local
@@ -453,7 +452,7 @@ format_time (struct tm *now,
}
}
else {
- if (clock_format == CLOCK_FORMAT_12) {
+ if (clock_format == G_DESKTOP_CLOCK_FORMAT_12H) {
/* Translators: This is a strftime format string.
* It is used to display the time in 12-hours format
* (eg, like in the US: 8:10 am). The %p expands to
@@ -468,10 +467,9 @@ format_time (struct tm *now,
}
}
- if (strftime (buf, sizeof (buf), format, now) <= 0) {
- strcpy (buf, "???");
- }
+ g_date_time_unref (local_now);
+ buf = g_date_time_format (now, format);
hours = offset / 3600;
minutes = labs (offset % 3600) / 60;
@@ -485,21 +483,19 @@ format_time (struct tm *now,
tmp = g_strdup_printf ("%s <small>%s</small>", buf, tzname);
}
- utf8 = g_locale_to_utf8 (tmp, -1, NULL, NULL, NULL);
-
- g_free (tmp);
-
- return utf8;
+ g_free (buf);
+ return tmp;
}
static char *
-convert_time_to_str (time_t now, ClockFormat clock_format)
+convert_time_to_str (time_t now, GDesktopClockFormat clock_format, const char *timezone)
{
const gchar *format;
- struct tm *tm;
- gchar buf[128];
+ GTimeZone *tz;
+ GDateTime *utc, *local;
+ char *ret;
- if (clock_format == CLOCK_FORMAT_12) {
+ if (clock_format == G_DESKTOP_CLOCK_FORMAT_12H) {
/* Translators: This is a strftime format string.
* It is used to display the time in 12-hours format (eg, like
* in the US: 8:10 am). The %p expands to am/pm.
@@ -514,18 +510,27 @@ convert_time_to_str (time_t now, ClockFormat clock_format)
format = _("%H:%M");
}
- tm = localtime (&now);
- strftime (buf, sizeof (buf) - 1, format, tm);
+ tz = g_time_zone_new (timezone);
+
+ utc = g_date_time_new_from_unix_utc (now);
+ local = g_date_time_to_timezone (utc, tz);
+
+ ret = g_date_time_format (local, format);
+
+ g_date_time_unref (utc);
+ g_date_time_unref (local);
+ g_time_zone_unref (tz);
- return g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
+ return ret;
}
void
clock_location_tile_refresh (ClockLocationTile *this, gboolean force_refresh)
{
ClockLocationTilePrivate *priv = PRIVATE (this);
- gchar *tmp, *tzname;
- struct tm now;
+ gchar *tmp;
+ const char *tzname;
+ GDateTime *now;
long offset;
int format;
@@ -552,14 +557,16 @@ clock_location_tile_refresh (ClockLocationTile *this, gboolean force_refresh)
return;
}
- clock_location_localtime (priv->location, &now);
+ now = clock_location_localtime (priv->location);
tzname = clock_location_get_tzname (priv->location);
- copy_tm (&now, &(priv->last_refresh));
+ if (priv->last_refresh)
+ g_date_time_unref (priv->last_refresh);
+ priv->last_refresh = g_date_time_ref (now);
priv->last_offset = clock_location_get_offset (priv->location);
tmp = g_strdup_printf ("<big><b>%s</b></big>",
- clock_location_get_display_name (priv->location));
+ clock_location_get_name (priv->location));
gtk_label_set_markup (GTK_LABEL (priv->city_label), tmp);
g_free (tmp);
@@ -567,7 +574,7 @@ clock_location_tile_refresh (ClockLocationTile *this, gboolean force_refresh)
offset = - priv->last_offset;
- tmp = format_time (&now, tzname, format, offset);
+ tmp = format_time (now, tzname, format, offset);
gtk_label_set_markup (GTK_LABEL (priv->time_label), tmp);
@@ -575,41 +582,43 @@ clock_location_tile_refresh (ClockLocationTile *this, gboolean force_refresh)
}
void
-weather_info_setup_tooltip (WeatherInfo *info, ClockLocation *location, GtkTooltip *tooltip,
- ClockFormat clock_format)
+weather_info_setup_tooltip (GWeatherInfo *info, ClockLocation *location, GtkTooltip *tooltip,
+ GDesktopClockFormat clock_format)
{
GdkPixbuf *pixbuf = NULL;
GtkIconTheme *theme = NULL;
- const gchar *conditions, *wind;
+ gchar *conditions, *sky, *wind;
gchar *temp, *apparent;
gchar *line1, *line2, *line3, *line4, *tip;
const gchar *icon_name;
- const gchar *sys_timezone;
time_t sunrise_time, sunset_time;
gchar *sunrise_str, *sunset_str;
+ const char *timezone;
+ gdouble unused;
+ GWeatherWindDirection unused2;
- icon_name = weather_info_get_icon_name (info);
+ icon_name = gweather_info_get_icon_name (info);
theme = gtk_icon_theme_get_default ();
pixbuf = gtk_icon_theme_load_icon (theme, icon_name, 48,
GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);
if (pixbuf)
gtk_tooltip_set_icon (tooltip, pixbuf);
- conditions = weather_info_get_conditions (info);
- if (strcmp (conditions, "-") != 0)
+ conditions = gweather_info_get_conditions (info);
+ sky = gweather_info_get_sky (info);
+ if (strcmp (conditions, "-") != 0) {
line1 = g_strdup_printf (_("%s, %s"),
- conditions,
- weather_info_get_sky (info));
- else
- line1 = g_strdup (weather_info_get_sky (info));
+ conditions, sky);
+ g_free (sky);
+ } else {
+ line1 = sky;
+ }
+ g_free (conditions);
- /* we need to g_strdup() since both functions return the same address
- * of a static buffer */
- temp = g_strdup (weather_info_get_temp (info));
- apparent = g_strdup (weather_info_get_apparent (info));
+ temp = gweather_info_get_temp (info);
+ apparent = gweather_info_get_apparent (info);
if (strcmp (apparent, temp) != 0 &&
- /* FMQ: it's broken to read from another module's translations; add some API to libgweather. */
- strcmp (apparent, dgettext ("gnome-applets-2.0", "Unknown")) != 0)
+ gweather_info_get_value_apparent (info, GWEATHER_TEMP_UNIT_DEFAULT, &unused))
/* Translators: The two strings are temperatures. */
line2 = g_strdup_printf (_("%s, feels like %s"), temp, apparent);
else
@@ -617,21 +626,19 @@ weather_info_setup_tooltip (WeatherInfo *info, ClockLocation *location, GtkToolt
g_free (temp);
g_free (apparent);
- wind = weather_info_get_wind (info);
- if (strcmp (apparent, dgettext ("gnome-applets-2.0", "Unknown")) != 0)
+ wind = gweather_info_get_wind (info);
+ if (gweather_info_get_value_wind (info, GWEATHER_SPEED_UNIT_DEFAULT, &unused, &unused2))
line3 = g_strdup_printf ("%s\n", wind);
else
line3 = g_strdup ("");
- sys_timezone = getenv ("TZ");
- setenv ("TZ", clock_location_get_timezone (location), 1);
- tzset ();
- if (weather_info_get_value_sunrise (info, &sunrise_time))
- sunrise_str = convert_time_to_str (sunrise_time, clock_format);
+ timezone = clock_location_get_timezone (location);
+ if (gweather_info_get_value_sunrise (info, &sunrise_time))
+ sunrise_str = convert_time_to_str (sunrise_time, clock_format, timezone);
else
sunrise_str = g_strdup ("???");
- if (weather_info_get_value_sunset (info, &sunset_time))
- sunset_str = convert_time_to_str (sunset_time, clock_format);
+ if (gweather_info_get_value_sunset (info, &sunset_time))
+ sunset_str = convert_time_to_str (sunset_time, clock_format, timezone);
else
sunset_str = g_strdup ("???");
line4 = g_strdup_printf (_("Sunrise: %s / Sunset: %s"),
@@ -639,12 +646,6 @@ weather_info_setup_tooltip (WeatherInfo *info, ClockLocation *location, GtkToolt
g_free (sunrise_str);
g_free (sunset_str);
- if (sys_timezone)
- setenv ("TZ", sys_timezone, 1);
- else
- unsetenv ("TZ");
- tzset ();
-
tip = g_strdup_printf ("<b>%s</b>\n%s\n%s%s", line1, line2, line3, line4);
gtk_tooltip_set_markup (tooltip, tip);
g_free (line1);
@@ -664,12 +665,12 @@ weather_tooltip (GtkWidget *widget,
{
ClockLocationTile *tile = data;
ClockLocationTilePrivate *priv = PRIVATE (tile);
- WeatherInfo *info;
+ GWeatherInfo *info;
int clock_format;
info = clock_location_get_weather_info (priv->location);
- if (!info || !weather_info_is_valid (info))
+ if (!info || !gweather_info_is_valid (info))
return FALSE;
g_signal_emit (tile, signals[NEED_CLOCK_FORMAT], 0, &clock_format);
@@ -680,7 +681,7 @@ weather_tooltip (GtkWidget *widget,
}
static void
-update_weather_icon (ClockLocation *loc, WeatherInfo *info, gpointer data)
+update_weather_icon (ClockLocation *loc, GWeatherInfo *info, gpointer data)
{
ClockLocationTile *tile = data;
ClockLocationTilePrivate *priv = PRIVATE (tile);
@@ -688,10 +689,10 @@ update_weather_icon (ClockLocation *loc, WeatherInfo *info, gpointer data)
GtkIconTheme *theme = NULL;
const gchar *icon_name;
- if (!info || !weather_info_is_valid (info))
+ if (!info || !gweather_info_is_valid (info))
return;
- icon_name = weather_info_get_icon_name (info);
+ icon_name = gweather_info_get_icon_name (info);
theme = gtk_icon_theme_get_default ();
pixbuf = gtk_icon_theme_load_icon (theme, icon_name, 16,
GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);
diff --git a/applets/clock/clock-location-tile.h b/applets/clock/clock-location-tile.h
index 628a8b5..0b235ed 100644
--- a/applets/clock/clock-location-tile.h
+++ b/applets/clock/clock-location-tile.h
@@ -37,8 +37,8 @@ ClockLocationTile *clock_location_tile_new (ClockLocation *loc,
ClockLocation *clock_location_tile_get_location (ClockLocationTile *this);
-void weather_info_setup_tooltip (WeatherInfo *info, ClockLocation *location, GtkTooltip *tip,
- ClockFormat clock_format);
+void weather_info_setup_tooltip (GWeatherInfo *info, ClockLocation *location, GtkTooltip *tip,
+ GDesktopClockFormat clock_format);
void clock_location_tile_refresh (ClockLocationTile *this,
gboolean force_refresh);
diff --git a/applets/clock/clock-location.c b/applets/clock/clock-location.c
index f4c7b6e..c4748ba 100644
--- a/applets/clock/clock-location.c
+++ b/applets/clock/clock-location.c
@@ -29,24 +29,18 @@ G_DEFINE_TYPE (ClockLocation, clock_location, G_TYPE_OBJECT)
typedef struct {
gchar *name;
- gchar *city;
- SystemTimezone *systz;
-
- gchar *timezone;
-
- gchar *tzname;
+ GWeatherLocation *world;
+ GWeatherLocation *loc;
- gfloat latitude;
- gfloat longitude;
+ SystemTimezone *systz;
- gchar *weather_code;
- WeatherInfo *weather_info;
- guint weather_timeout;
- guint weather_retry_time;
+ gdouble latitude;
+ gdouble longitude;
- TempUnit temperature_unit;
- SpeedUnit speed_unit;
+ GWeatherInfo *weather_info;
+ gint weather_timeout;
+ gint weather_retry_time;
} ClockLocationPrivate;
#define WEATHER_TIMEOUT_BASE 30
@@ -62,51 +56,19 @@ enum {
static guint location_signals[LAST_SIGNAL] = { 0 };
static void clock_location_finalize (GObject *);
-static void clock_location_set_tz (ClockLocation *this);
-static void clock_location_unset_tz (ClockLocation *this);
static void setup_weather_updates (ClockLocation *loc);
static void add_to_network_monitor (ClockLocation *loc);
static void remove_from_network_monitor (ClockLocation *loc);
-static gchar *clock_location_get_valid_weather_code (const gchar *code);
-
#define PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CLOCK_LOCATION_TYPE, ClockLocationPrivate))
ClockLocation *
-clock_location_find_and_ref (GList *locations,
- const gchar *name,
- const gchar *city,
- const gchar *timezone,
- gfloat latitude,
- gfloat longitude,
- const gchar *code)
-{
- GList *l;
- ClockLocationPrivate *priv;
-
- for (l = locations; l != NULL; l = l->next) {
- priv = PRIVATE (l->data);
-
- if (priv->latitude == latitude &&
- priv->longitude == longitude &&
- g_strcmp0 (priv->weather_code, code) == 0 &&
- g_strcmp0 (priv->timezone, timezone) == 0 &&
- g_strcmp0 (priv->city, city) == 0 &&
- g_strcmp0 (priv->name, name) == 0)
- break;
- }
-
- if (l != NULL)
- return g_object_ref (CLOCK_LOCATION (l->data));
- else
- return NULL;
-}
-
-ClockLocation *
-clock_location_new (const gchar *name, const gchar *city,
- const gchar *timezone,
- gfloat latitude, gfloat longitude,
- const gchar *code, WeatherPrefs *prefs)
+clock_location_new (GWeatherLocation *world,
+ const char *name,
+ const char *metar_code,
+ gboolean override_latlon,
+ gdouble latitude,
+ gdouble longitude)
{
ClockLocation *this;
ClockLocationPrivate *priv;
@@ -114,22 +76,21 @@ clock_location_new (const gchar *name, const gchar *city,
this = g_object_new (CLOCK_LOCATION_TYPE, NULL);
priv = PRIVATE (this);
- priv->name = g_strdup (name);
- priv->city = g_strdup (city);
- priv->timezone = g_strdup (timezone);
+ priv->world = gweather_location_ref (world);
+ priv->loc = gweather_location_find_by_station_code (priv->world,
+ metar_code);
- /* initialize priv->tzname */
- clock_location_set_tz (this);
- clock_location_unset_tz (this);
-
- priv->latitude = latitude;
- priv->longitude = longitude;
-
- priv->weather_code = clock_location_get_valid_weather_code (code);
+ if (name && *name) {
+ priv->name = g_strdup (name);
+ } else {
+ priv->name = g_strdup (gweather_location_get_name (priv->loc));
+ }
- if (prefs) {
- priv->temperature_unit = prefs->temperature_unit;
- priv->speed_unit = prefs->speed_unit;
+ if (override_latlon) {
+ priv->latitude = latitude;
+ priv->longitude = longitude;
+ } else {
+ gweather_location_get_coords (priv->loc, &priv->latitude, &priv->longitude);
}
setup_weather_updates (this);
@@ -172,20 +133,10 @@ clock_location_init (ClockLocation *this)
{
ClockLocationPrivate *priv = PRIVATE (this);
- priv->name = NULL;
- priv->city = NULL;
-
priv->systz = system_timezone_new ();
- priv->timezone = NULL;
-
- priv->tzname = NULL;
-
priv->latitude = 0;
priv->longitude = 0;
-
- priv->temperature_unit = TEMP_UNIT_CENTIGRADE;
- priv->speed_unit = SPEED_UNIT_MS;
}
static void
@@ -195,61 +146,28 @@ clock_location_finalize (GObject *g_obj)
remove_from_network_monitor (CLOCK_LOCATION (g_obj));
- if (priv->name) {
- g_free (priv->name);
- priv->name = NULL;
- }
+ g_free (priv->name);
- if (priv->city) {
- g_free (priv->city);
- priv->city = NULL;
- }
+ gweather_location_unref (priv->world);
+ gweather_location_unref (priv->loc);
+
+ if (priv->weather_timeout)
+ g_source_remove (priv->weather_timeout);
if (priv->systz) {
g_object_unref (priv->systz);
priv->systz = NULL;
}
- if (priv->timezone) {
- g_free (priv->timezone);
- priv->timezone = NULL;
- }
-
- if (priv->tzname) {
- g_free (priv->tzname);
- priv->tzname = NULL;
- }
-
- if (priv->weather_code) {
- g_free (priv->weather_code);
- priv->weather_code = NULL;
- }
-
if (priv->weather_info) {
- weather_info_free (priv->weather_info);
+ g_object_unref (priv->weather_info);
priv->weather_info = NULL;
}
- if (priv->weather_timeout) {
- g_source_remove (priv->weather_timeout);
- priv->weather_timeout = 0;
- }
-
G_OBJECT_CLASS (clock_location_parent_class)->finalize (g_obj);
}
const gchar *
-clock_location_get_display_name (ClockLocation *loc)
-{
- ClockLocationPrivate *priv = PRIVATE (loc);
-
- if (priv->name && priv->name[0])
- return priv->name;
- else
- return priv->city;
-}
-
-const gchar *
clock_location_get_name (ClockLocation *loc)
{
ClockLocationPrivate *priv = PRIVATE (loc);
@@ -270,59 +188,38 @@ clock_location_set_name (ClockLocation *loc, const gchar *name)
priv->name = g_strdup (name);
}
-const gchar *
+gchar *
clock_location_get_city (ClockLocation *loc)
{
ClockLocationPrivate *priv = PRIVATE (loc);
- return priv->city;
-}
-
-void
-clock_location_set_city (ClockLocation *loc, const gchar *city)
-{
- ClockLocationPrivate *priv = PRIVATE (loc);
-
- if (priv->city) {
- g_free (priv->city);
- priv->city = NULL;
- }
-
- priv->city = g_strdup (city);
+ return gweather_location_get_city_name (priv->loc);
}
-gchar *
+const gchar *
clock_location_get_timezone (ClockLocation *loc)
{
ClockLocationPrivate *priv = PRIVATE (loc);
+ GWeatherTimezone *tz;
- return priv->timezone;
-}
-
-void
-clock_location_set_timezone (ClockLocation *loc, const gchar *timezone)
-{
- ClockLocationPrivate *priv = PRIVATE (loc);
-
- if (priv->timezone) {
- g_free (priv->timezone);
- priv->timezone = NULL;
- }
-
- priv->timezone = g_strdup (timezone);
+ tz = gweather_location_get_timezone (priv->loc);
+ return gweather_timezone_get_name (tz);
}
-gchar *
+const gchar *
clock_location_get_tzname (ClockLocation *loc)
{
ClockLocationPrivate *priv = PRIVATE (loc);
+ GWeatherTimezone *tz;
- return priv->tzname;
+ tz = gweather_location_get_timezone (priv->loc);
+ return gweather_timezone_get_tzid (tz);
}
void
-clock_location_get_coords (ClockLocation *loc, gfloat *latitude,
- gfloat *longitude)
+clock_location_get_coords (ClockLocation *loc,
+ gdouble *latitude,
+ gdouble *longitude)
{
ClockLocationPrivate *priv = PRIVATE (loc);
@@ -330,105 +227,36 @@ clock_location_get_coords (ClockLocation *loc, gfloat *latitude,
*longitude = priv->longitude;
}
-void
-clock_location_set_coords (ClockLocation *loc, gfloat latitude,
- gfloat longitude)
+GDateTime *
+clock_location_localtime (ClockLocation *loc)
{
ClockLocationPrivate *priv = PRIVATE (loc);
+ GWeatherTimezone *wtz;
+ GTimeZone *tz;
+ GDateTime *dt;
- priv->latitude = latitude;
- priv->longitude = longitude;
-}
-
-static void
-clock_location_set_tzname (ClockLocation *this, const char *tzname)
-{
- ClockLocationPrivate *priv = PRIVATE (this);
+ wtz = gweather_location_get_timezone (priv->loc);
- if (priv->tzname) {
- if (strcmp (priv->tzname, tzname) == 0) {
- return;
- }
+ tz = g_time_zone_new (gweather_timezone_get_tzid (wtz));
+ dt = g_date_time_new_now (tz);
- g_free (priv->tzname);
- priv->tzname = NULL;
- }
-
- if (tzname) {
- priv->tzname = g_strdup (tzname);
- } else {
- priv->tzname = NULL;
- }
-}
-
-static void
-clock_location_set_tz (ClockLocation *this)
-{
- ClockLocationPrivate *priv = PRIVATE (this);
-
- time_t now_t;
- struct tm now;
-
- if (priv->timezone == NULL) {
- return;
- }
-
- setenv ("TZ", priv->timezone, 1);
- tzset();
-
- now_t = time (NULL);
- localtime_r (&now_t, &now);
-
- if (now.tm_isdst > 0) {
- clock_location_set_tzname (this, tzname[1]);
- } else {
- clock_location_set_tzname (this, tzname[0]);
- }
-}
-
-static void
-clock_location_unset_tz (ClockLocation *this)
-{
- ClockLocationPrivate *priv = PRIVATE (this);
- const char *env_timezone;
-
- if (priv->timezone == NULL) {
- return;
- }
-
- env_timezone = system_timezone_get_env (priv->systz);
-
- if (env_timezone) {
- setenv ("TZ", env_timezone, 1);
- } else {
- unsetenv ("TZ");
- }
- tzset();
-}
-
-void
-clock_location_localtime (ClockLocation *loc, struct tm *tm)
-{
- time_t now;
-
- clock_location_set_tz (loc);
-
- time (&now);
- localtime_r (&now, tm);
-
- clock_location_unset_tz (loc);
+ g_time_zone_unref (tz);
+ return dt;
}
gboolean
clock_location_is_current_timezone (ClockLocation *loc)
{
ClockLocationPrivate *priv = PRIVATE (loc);
+ GWeatherTimezone *wtz;
const char *zone;
+ wtz = gweather_location_get_timezone (priv->loc);
+
zone = system_timezone_get (priv->systz);
if (zone)
- return strcmp (zone, priv->timezone) == 0;
+ return strcmp (zone, gweather_timezone_get_tzid (wtz)) == 0;
else
return clock_location_get_offset (loc) == 0;
}
@@ -462,34 +290,10 @@ glong
clock_location_get_offset (ClockLocation *loc)
{
ClockLocationPrivate *priv = PRIVATE (loc);
- glong sys_timezone, local_timezone;
- glong offset;
- time_t t;
- struct tm *tm;
-
- t = time (NULL);
-
- unsetenv ("TZ");
- tm = localtime (&t);
- sys_timezone = timezone;
+ GWeatherTimezone *wtz;
- if (tm->tm_isdst > 0) {
- sys_timezone -= 3600;
- }
-
- setenv ("TZ", priv->timezone, 1);
- tm = localtime (&t);
- local_timezone = timezone;
-
- if (tm->tm_isdst > 0) {
- local_timezone -= 3600;
- }
-
- offset = local_timezone - sys_timezone;
-
- clock_location_unset_tz (loc);
-
- return offset;
+ wtz = gweather_location_get_timezone (priv->loc);
+ return gweather_timezone_get_offset (wtz);
}
typedef struct {
@@ -540,6 +344,7 @@ clock_location_make_current (ClockLocation *loc,
{
ClockLocationPrivate *priv = PRIVATE (loc);
MakeCurrentData *mcdata;
+ GWeatherTimezone *wtz;
if (loc == current_location) {
if (destroy)
@@ -570,40 +375,21 @@ clock_location_make_current (ClockLocation *loc,
mcdata->data = data;
mcdata->destroy = destroy;
- set_system_timezone_async (priv->timezone,
+ wtz = gweather_location_get_timezone (priv->loc);
+ set_system_timezone_async (gweather_timezone_get_tzid (wtz),
make_current_cb,
mcdata);
}
-static gchar *
-clock_location_get_valid_weather_code (const gchar *code)
-{
- if (!code || code[0] == '\0')
- return g_strdup (WEATHER_EMPTY_CODE);
- else
- return g_strdup (code);
-}
-
const gchar *
clock_location_get_weather_code (ClockLocation *loc)
{
ClockLocationPrivate *priv = PRIVATE (loc);
- return priv->weather_code;
-}
-
-void
-clock_location_set_weather_code (ClockLocation *loc, const gchar *code)
-{
- ClockLocationPrivate *priv = PRIVATE (loc);
-
- g_free (priv->weather_code);
- priv->weather_code = clock_location_get_valid_weather_code (code);
-
- setup_weather_updates (loc);
+ return gweather_location_get_code (priv->loc);
}
-WeatherInfo *
+GWeatherInfo *
clock_location_get_weather_info (ClockLocation *loc)
{
ClockLocationPrivate *priv = PRIVATE (loc);
@@ -619,7 +405,7 @@ set_weather_update_timeout (ClockLocation *loc)
ClockLocationPrivate *priv = PRIVATE (loc);
guint timeout;
- if (!weather_info_network_error (priv->weather_info)) {
+ if (!gweather_info_network_error (priv->weather_info)) {
/* The last update succeeded; set the next update to
* happen in half an hour, and reset the retry timer.
*/
@@ -643,7 +429,7 @@ set_weather_update_timeout (ClockLocation *loc)
}
static void
-weather_info_updated (WeatherInfo *info, gpointer data)
+weather_info_updated (GWeatherInfo *info, gpointer data)
{
ClockLocation *loc = data;
ClockLocationPrivate *priv = PRIVATE (loc);
@@ -658,43 +444,11 @@ update_weather_info (gpointer data)
{
ClockLocation *loc = data;
ClockLocationPrivate *priv = PRIVATE (loc);
- WeatherPrefs prefs = {
- FORECAST_STATE,
- FALSE,
- NULL,
- TEMP_UNIT_CENTIGRADE,
- SPEED_UNIT_MS,
- PRESSURE_UNIT_MB,
- DISTANCE_UNIT_KM
- };
-
- prefs.temperature_unit = priv->temperature_unit;
- prefs.speed_unit = priv->speed_unit;
-
- weather_info_abort (priv->weather_info);
- weather_info_update (priv->weather_info,
- &prefs, weather_info_updated, loc);
- return TRUE;
-}
+ gweather_info_abort (priv->weather_info);
+ gweather_info_update (priv->weather_info);
-static gchar *
-rad2dms (gfloat lat, gfloat lon)
-{
- gchar h, h2;
- gfloat d, deg, min, d2, deg2, min2;
-
- h = lat > 0 ? 'N' : 'S';
- d = fabs (lat);
- deg = floor (d);
- min = floor (60 * (d - deg));
- h2 = lon > 0 ? 'E' : 'W';
- d2 = fabs (lon);
- deg2 = floor (d2);
- min2 = floor (60 * (d2 - deg2));
- return g_strdup_printf ("%02d-%02d%c %02d-%02d%c",
- (int)deg, (int)min, h,
- (int)deg2, (int)min2, h2);
+ return TRUE;
}
static GList *locations = NULL;
@@ -779,60 +533,23 @@ static void
setup_weather_updates (ClockLocation *loc)
{
ClockLocationPrivate *priv = PRIVATE (loc);
- WeatherLocation *wl;
- WeatherPrefs prefs = {
- FORECAST_STATE,
- FALSE,
- NULL,
- TEMP_UNIT_CENTIGRADE,
- SPEED_UNIT_MS,
- PRESSURE_UNIT_MB,
- DISTANCE_UNIT_KM
- };
-
- gchar *dms;
-
- prefs.temperature_unit = priv->temperature_unit;
- prefs.speed_unit = priv->speed_unit;
- if (priv->weather_info) {
- weather_info_free (priv->weather_info);
- priv->weather_info = NULL;
- }
+ g_clear_object (&priv->weather_info);
if (priv->weather_timeout) {
g_source_remove (priv->weather_timeout);
priv->weather_timeout = 0;
}
- if (!priv->weather_code ||
- strcmp (priv->weather_code, WEATHER_EMPTY_CODE) == 0)
- return;
-
- dms = rad2dms (priv->latitude, priv->longitude);
- wl = weather_location_new (priv->city, priv->weather_code,
- NULL, NULL, dms, NULL, NULL);
-
priv->weather_info =
- weather_info_new (wl, &prefs, weather_info_updated, loc);
+ gweather_info_new_for_world (priv->world,
+ priv->loc,
+ GWEATHER_FORECAST_LIST);
+ g_signal_connect (priv->weather_info, "updated",
+ G_CALLBACK (weather_info_updated), loc);
set_weather_update_timeout (loc);
- weather_location_free (wl);
- g_free (dms);
-
add_to_network_monitor (loc);
}
-void
-clock_location_set_weather_prefs (ClockLocation *loc,
- WeatherPrefs *prefs)
-{
- ClockLocationPrivate *priv = PRIVATE (loc);
-
- priv->temperature_unit = prefs->temperature_unit;
- priv->speed_unit = prefs->speed_unit;
-
- update_weather_info (loc);
-}
-
diff --git a/applets/clock/clock-location.h b/applets/clock/clock-location.h
index 2b25d97..c14ebb4 100644
--- a/applets/clock/clock-location.h
+++ b/applets/clock/clock-location.h
@@ -4,7 +4,7 @@
#include <time.h>
#include <glib.h>
#include <glib-object.h>
-#include <libgweather/weather.h>
+#include <libgweather/gweather-weather.h>
G_BEGIN_DECLS
@@ -24,44 +24,30 @@ typedef struct
{
GObjectClass g_object_class;
- void (* weather_updated) (ClockLocation *location, WeatherInfo *info);
+ void (* weather_updated) (ClockLocation *location, GWeatherInfo *info);
void (* set_current) (ClockLocation *location);
} ClockLocationClass;
GType clock_location_get_type (void);
-ClockLocation *clock_location_new (const gchar *name, const gchar *city,
- const gchar *timezone,
- gfloat latitude, gfloat longitude,
- const gchar *code,
- WeatherPrefs *prefs);
+ClockLocation *clock_location_new (GWeatherLocation *world,
+ const gchar *name,
+ const gchar *metar_code,
+ gboolean override_latlon,
+ gdouble latitude,
+ gdouble longitude);
-ClockLocation *clock_location_find_and_ref (GList *locations,
- const gchar *name,
- const gchar *city,
- const gchar *timezone,
- gfloat latitude,
- gfloat longitude,
- const gchar *code);
+const gchar *clock_location_get_tzname (ClockLocation *loc);
-gchar *clock_location_get_tzname (ClockLocation *loc);
-
-const gchar *clock_location_get_display_name (ClockLocation *loc);
-
-const gchar *clock_location_get_name (ClockLocation *loc);
+const char *clock_location_get_name (ClockLocation *loc);
void clock_location_set_name (ClockLocation *loc, const gchar *name);
-const gchar *clock_location_get_city (ClockLocation *loc);
-void clock_location_set_city (ClockLocation *loc, const gchar *city);
-
-gchar *clock_location_get_timezone (ClockLocation *loc);
-void clock_location_set_timezone (ClockLocation *loc, const gchar *timezone);
-
-void clock_location_get_coords (ClockLocation *loc, gfloat *latitude, gfloat *longitude);
-void clock_location_set_coords (ClockLocation *loc, gfloat latitude, gfloat longitude);
+gchar *clock_location_get_city (ClockLocation *loc);
+const gchar *clock_location_get_timezone (ClockLocation *loc);
+void clock_location_get_coords (ClockLocation *loc, gdouble *latitude, gdouble *longitude);
-void clock_location_localtime (ClockLocation *loc, struct tm *tm);
+GDateTime *clock_location_localtime (ClockLocation *loc);
gboolean clock_location_is_current (ClockLocation *loc);
void clock_location_make_current (ClockLocation *loc,
@@ -71,10 +57,7 @@ void clock_location_make_current (ClockLocation *loc,
gboolean clock_location_is_current_timezone (ClockLocation *loc);
const gchar *clock_location_get_weather_code (ClockLocation *loc);
-void clock_location_set_weather_code (ClockLocation *loc, const gchar *code);
-WeatherInfo *clock_location_get_weather_info (ClockLocation *loc);
-void clock_location_set_weather_prefs (ClockLocation *loc,
- WeatherPrefs *weather_prefs);
+GWeatherInfo *clock_location_get_weather_info (ClockLocation *loc);
glong clock_location_get_offset (ClockLocation *loc);
diff --git a/applets/clock/clock-map.c b/applets/clock/clock-map.c
index a644d25..1b4cdf3 100644
--- a/applets/clock/clock-map.c
+++ b/applets/clock/clock-map.c
@@ -417,7 +417,7 @@ clock_map_mark (ClockMap *this, gfloat latitude, gfloat longitude, gint mark)
static gboolean
clock_map_place_location (ClockMap *this, ClockLocation *loc, gboolean hilight)
{
- gfloat latitude, longitude;
+ gdouble latitude, longitude;
gint marker;
clock_location_get_coords (loc, &latitude, &longitude);
diff --git a/applets/clock/clock-menu.xml b/applets/clock/clock-menu.xml
index 7e0f683..2b44c97 100644
--- a/applets/clock/clock-menu.xml
+++ b/applets/clock/clock-menu.xml
@@ -1,5 +1,4 @@
<menuitem name="Clock Copy Time Item" action="ClockCopyTime" />
-<menuitem name="Clock Copy Date Item" action="ClockCopyDate" />
<separator/>
<menuitem name="Clock Configure Item" action="ClockConfig" />
<menuitem name="Clock Preferences Item" action="ClockPreferences" />
diff --git a/applets/clock/clock-utils.c b/applets/clock/clock-utils.c
index 4292be2..45c00e9 100644
--- a/applets/clock/clock-utils.c
+++ b/applets/clock/clock-utils.c
@@ -54,11 +54,12 @@ clock_locale_supports_am_pm (void)
#endif
}
-ClockFormat
+GDesktopClockFormat
clock_locale_format (void)
{
return clock_locale_supports_am_pm () ?
- CLOCK_FORMAT_12 : CLOCK_FORMAT_24;
+ G_DESKTOP_CLOCK_FORMAT_12H :
+ G_DESKTOP_CLOCK_FORMAT_24H;
}
void
diff --git a/applets/clock/clock-utils.h b/applets/clock/clock-utils.h
index fb3bea0..a429798 100644
--- a/applets/clock/clock-utils.h
+++ b/applets/clock/clock-utils.h
@@ -28,21 +28,12 @@
#define __CLOCK_UTILS_H__
#include <gtk/gtk.h>
+#include <gdesktop-enums.h>
G_BEGIN_DECLS
-/* Needs to match the indices in the combo of the prefs dialog */
-typedef enum {
- CLOCK_FORMAT_INVALID = 0,
- CLOCK_FORMAT_12,
- CLOCK_FORMAT_24,
- CLOCK_FORMAT_UNIX,
- CLOCK_FORMAT_INTERNET,
- CLOCK_FORMAT_CUSTOM
-} ClockFormat;
-
gboolean clock_locale_supports_am_pm (void);
-ClockFormat clock_locale_format (void);
+GDesktopClockFormat clock_locale_format (void);
void clock_utils_display_help (GtkWidget *widget,
const char *doc_id,
diff --git a/applets/clock/clock.c b/applets/clock/clock.c
index 2b02eb6..90ee62b 100644
--- a/applets/clock/clock.c
+++ b/applets/clock/clock.c
@@ -42,20 +42,22 @@
#include <locale.h>
#include <panel-applet.h>
-#include <panel-applet-gconf.h>
#include <glib/gi18n.h>
+#include <gio/gio.h>
#include <gio/gdesktopappinfo.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <gdk/gdkx.h>
-#include <gconf/gconf-client.h>
-#include <libgweather/gweather-prefs.h>
+#define GNOME_DESKTOP_USE_UNSTABLE_API
+#include <libgnome-desktop/gnome-wall-clock.h>
+
#include <libgweather/gweather-xml.h>
#include <libgweather/location-entry.h>
#include <libgweather/timezone-menu.h>
+#include <libgweather/gweather-enum-types.h>
#include "clock.h"
@@ -66,32 +68,6 @@
#include "clock-utils.h"
#include "system-timezone.h"
-#define INTERNETSECOND (864)
-#define INTERNETBEAT (86400)
-
-#define NEVER_SENSITIVE "never_sensitive"
-
-#define N_GCONF_PREFS 11 /* Keep this in sync with the number of keys below! */
-#define KEY_FORMAT "format"
-#define KEY_SHOW_SECONDS "show_seconds"
-#define KEY_SHOW_DATE "show_date"
-#define KEY_SHOW_WEATHER "show_weather"
-#define KEY_SHOW_TEMPERATURE "show_temperature"
-#define KEY_CUSTOM_FORMAT "custom_format"
-#define KEY_SHOW_WEEK "show_week_numbers"
-#define KEY_CITIES "cities"
-#define KEY_TEMPERATURE_UNIT "temperature_unit"
-#define KEY_SPEED_UNIT "speed_unit"
-
-static GConfEnumStringPair format_type_enum_map [] = {
- { CLOCK_FORMAT_12, "12-hour" },
- { CLOCK_FORMAT_24, "24-hour" },
- { CLOCK_FORMAT_UNIX, "unix" },
- { CLOCK_FORMAT_INTERNET, "internet" },
- { CLOCK_FORMAT_CUSTOM, "custom" },
- { 0, NULL }
-};
-
enum {
COL_CITY_NAME = 0,
COL_CITY_TZ,
@@ -143,27 +119,18 @@ struct _ClockData {
GtkWidget *map_widget;
/* preferences */
- ClockFormat format;
- char *custom_format;
- gboolean showseconds;
- gboolean showdate;
- gboolean showweek;
- gboolean show_weather;
- gboolean show_temperature;
-
- gboolean use_temperature_default;
- gboolean use_speed_default;
- TempUnit temperature_unit;
- SpeedUnit speed_unit;
+ GSettings *applet_settings;
+ GSettings *weather_settings;
+ GSettings *clock_settings;
/* Locations */
+ GWeatherLocation *world;
GList *locations;
GList *location_tiles;
/* runtime data */
time_t current_time;
- char *timeformat;
- guint timeout;
+ GnomeWallClock *wall_clock;
PanelAppletOrient orient;
int size;
GtkAllocation old_allocation;
@@ -181,15 +148,11 @@ struct _ClockData {
gboolean custom_format_shown;
gboolean can_handle_format_12;
-
- guint listeners [N_GCONF_PREFS];
};
-static void update_clock (ClockData * cd);
+static void update_clock (GnomeWallClock *, GParamSpec *, ClockData * cd);
static void update_tooltip (ClockData * cd);
static void update_panel_weather (ClockData *cd);
-static int clock_timeout_callback (gpointer data);
-static float get_itime (time_t current_time);
static void set_atk_name_description (GtkWidget *widget,
const char *name,
@@ -280,219 +243,6 @@ calculate_minimum_width (GtkWidget *widget,
return width;
}
-static void
-clock_set_timeout (ClockData *cd,
- time_t now)
-{
- int timeouttime;
-
- if (cd->format == CLOCK_FORMAT_INTERNET) {
- int itime_ms;
-
- itime_ms = ((unsigned int) (get_itime (now) * 1000));
-
- if (!cd->showseconds)
- timeouttime = (999 - itime_ms % 1000) * 86.4 + 1;
- else {
- struct timeval tv;
- gettimeofday (&tv, NULL);
- itime_ms += (tv.tv_usec * 86.4) / 1000;
- timeouttime = ((999 - itime_ms % 1000) * 86.4) / 100 + 1;
- }
- } else {
- struct timeval tv;
- struct tm *tm;
-
- gettimeofday (&tv, NULL);
- /* We can't expect the timer resolution to be < 10ms, so add
- * 15ms to make sure we're fine; see
- * https://bugzilla.gnome.org/show_bug.cgi?id=585668 */
- timeouttime = (G_USEC_PER_SEC - tv.tv_usec)/1000+15;
-
- /* timeout of one minute if we don't care about the seconds */
- if (cd->format != CLOCK_FORMAT_UNIX &&
- !cd->showseconds) {
- /* we use localtime() to handle leap seconds, see
- * https://bugzilla.gnome.org/show_bug.cgi?id=604317 */
- tm = localtime (&now);
- if (tm->tm_sec < 60)
- timeouttime += 1000 * (59 - tm->tm_sec);
- }
- }
-
- cd->timeout = g_timeout_add (timeouttime,
- clock_timeout_callback,
- cd);
-}
-
-static int
-clock_timeout_callback (gpointer data)
-{
- ClockData *cd = data;
- time_t new_time;
-
- time (&new_time);
-
- if (!cd->showseconds &&
- cd->format != CLOCK_FORMAT_UNIX &&
- cd->format != CLOCK_FORMAT_CUSTOM) {
- if (cd->format == CLOCK_FORMAT_INTERNET &&
- (unsigned int)get_itime (new_time) !=
- (unsigned int)get_itime (cd->current_time)) {
- update_clock (cd);
- } else if ((cd->format == CLOCK_FORMAT_12 ||
- cd->format == CLOCK_FORMAT_24) &&
- new_time / 60 != cd->current_time / 60) {
- update_clock (cd);
- }
- } else {
- update_clock (cd);
- }
-
- clock_set_timeout (cd, new_time);
-
- return FALSE;
-}
-
-static float
-get_itime (time_t current_time)
-{
- struct tm *tm;
- float itime;
- time_t bmt;
-
- /* BMT (Biel Mean Time) is GMT+1 */
- bmt = current_time + 3600;
- tm = gmtime (&bmt);
- itime = (tm->tm_hour*3600.0 + tm->tm_min*60.0 + tm->tm_sec)/86.4;
-
- return itime;
-}
-
-/* adapted from panel-toplevel.c */
-static int
-calculate_minimum_height (GtkWidget *widget,
- PanelAppletOrient orientation)
-{
- GtkStateFlags state;
- GtkStyleContext *style_context;
- const PangoFontDescription *font_desc;
- PangoContext *pango_context;
- PangoFontMetrics *metrics;
- GtkBorder padding;
- int focus_width = 0;
- int focus_pad = 0;
- int ascent;
- int descent;
- int thickness;
-
- state = gtk_widget_get_state_flags (widget);
- style_context = gtk_widget_get_style_context (widget);
- font_desc = gtk_style_context_get_font (style_context, state);
-
- pango_context = gtk_widget_get_pango_context (widget);
- metrics = pango_context_get_metrics (pango_context,
- font_desc,
- pango_context_get_language (pango_context));
-
- ascent = pango_font_metrics_get_ascent (metrics);
- descent = pango_font_metrics_get_descent (metrics);
-
- pango_font_metrics_unref (metrics);
-
- gtk_style_context_get_padding (style_context, state, &padding);
- gtk_style_context_get_style (style_context,
- "focus-line-width", &focus_width,
- "focus-padding", &focus_pad,
- NULL);
-
- if (orientation == PANEL_APPLET_ORIENT_UP
- || orientation == PANEL_APPLET_ORIENT_DOWN) {
- thickness = padding.top + padding.bottom;
- } else {
- thickness = padding.left + padding.right;
- }
-
- return PANGO_PIXELS (ascent + descent) + 2 * (focus_width + focus_pad) + thickness;
-}
-
-static gboolean
-use_two_line_format (ClockData *cd)
-{
- if (cd->size >= 2 * calculate_minimum_height (cd->panel_button, cd->orient))
- return TRUE;
-
- return FALSE;
-}
-
-static char *
-get_updated_timeformat (ClockData *cd)
-{
- /* Show date in another line if panel is vertical, or
- * horizontal but large enough to hold two lines of text
- */
- char *result;
- const char *time_format;
- const char *date_format;
- char *clock_format;
-
- if (cd->format == CLOCK_FORMAT_12)
- /* Translators: This is a strftime format string.
- * It is used to display the time in 12-hours format (eg, like
- * in the US: 8:10 am). The %p expands to am/pm. */
- time_format = cd->showseconds ? _("%l:%M:%S %p") : _("%l:%M %p");
- else
- /* Translators: This is a strftime format string.
- * It is used to display the time in 24-hours format (eg, like
- * in France: 20:10). */
- time_format = cd->showseconds ? _("%H:%M:%S") : _("%H:%M");
-
- if (!cd->showdate)
- clock_format = g_strdup (time_format);
-
- else {
- /* Translators: This is a strftime format string.
- * It is used to display the date. Replace %e with %d if, when
- * the day of the month as a decimal number is a single digit,
- * it should begin with a 0 in your locale (e.g. "May 01"
- * instead of "May 1"). */
- date_format = _("%a %b %e");
-
- if (use_two_line_format (cd))
- /* translators: reverse the order of these arguments
- * if the time should come before the
- * date on a clock in your locale.
- */
- clock_format = g_strdup_printf (_("%1$s\n%2$s"),
- date_format,
- time_format);
- else
- /* translators: reverse the order of these arguments
- * if the time should come before the
- * date on a clock in your locale.
- */
- clock_format = g_strdup_printf (_("%1$s, %2$s"),
- date_format,
- time_format);
- }
-
- result = g_locale_from_utf8 (clock_format, -1, NULL, NULL, NULL);
- g_free (clock_format);
-
- /* let's be paranoid */
- if (!result)
- result = g_strdup ("???");
-
- return result;
-}
-
-static void
-update_timeformat (ClockData *cd)
-{
- g_free (cd->timeformat);
- cd->timeformat = get_updated_timeformat (cd);
-}
-
/* sets accessible name and description for the widget */
static void
set_atk_name_description (GtkWidget *widget,
@@ -525,87 +275,13 @@ update_location_tiles (ClockData *cd)
}
}
-static char *
-format_time (ClockData *cd)
-{
- struct tm *tm;
- char hour[256];
- char *utf8;
-
- utf8 = NULL;
-
- tm = localtime (&cd->current_time);
-
- if (cd->format == CLOCK_FORMAT_UNIX) {
- if (use_two_line_format (cd)) {
- utf8 = g_strdup_printf ("%lu\n%05lu",
- (unsigned long)(cd->current_time / 100000L),
- (unsigned long)(cd->current_time % 100000L));
- } else {
- utf8 = g_strdup_printf ("%lu",
- (unsigned long)cd->current_time);
- }
- } else if (cd->format == CLOCK_FORMAT_INTERNET) {
- float itime = get_itime (cd->current_time);
- if (cd->showseconds)
- utf8 = g_strdup_printf ("@%3.2f", itime);
- else
- utf8 = g_strdup_printf ("@%3d", (unsigned int) itime);
- } else if (cd->format == CLOCK_FORMAT_CUSTOM) {
- char *timeformat = g_locale_from_utf8 (cd->custom_format, -1,
- NULL, NULL, NULL);
- if (!timeformat)
- strcpy (hour, "???");
- else if (strftime (hour, sizeof (hour), timeformat, tm) <= 0)
- strcpy (hour, "???");
- g_free (timeformat);
-
- utf8 = g_locale_to_utf8 (hour, -1, NULL, NULL, NULL);
- } else {
- if (strftime (hour, sizeof (hour), cd->timeformat, tm) <= 0)
- strcpy (hour, "???");
-
- utf8 = g_locale_to_utf8 (hour, -1, NULL, NULL, NULL);
- }
-
- if (!utf8)
- utf8 = g_strdup (hour);
-
- return utf8;
-}
-
-static gchar *
-format_time_24 (ClockData *cd)
-{
- struct tm *tm;
- gchar buf[128];
-
- tm = localtime (&cd->current_time);
- strftime (buf, sizeof (buf) - 1, "%k:%M:%S", tm);
- return g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
-}
-
static void
-update_clock (ClockData * cd)
+update_clock (GnomeWallClock *wall_clock, GParamSpec *pspec, ClockData * cd)
{
- gboolean use_markup;
- char *utf8;
-
- use_markup = FALSE;
-
- time (&cd->current_time);
- utf8 = format_time (cd);
+ const char *clock;
- use_markup = FALSE;
- if (pango_parse_markup (utf8, -1, 0, NULL, NULL, NULL, NULL))
- use_markup = TRUE;
-
- if (use_markup)
- gtk_label_set_markup (GTK_LABEL (cd->clockw), utf8);
- else
- gtk_label_set_text (GTK_LABEL (cd->clockw), utf8);
-
- g_free (utf8);
+ clock = gnome_wall_clock_get_clock (cd->wall_clock);
+ gtk_label_set_text (GTK_LABEL (cd->clockw), clock);
update_orient (cd);
gtk_widget_queue_resize (cd->panel_button);
@@ -620,48 +296,24 @@ update_clock (ClockData * cd)
static void
update_tooltip (ClockData * cd)
{
- if (!cd->showdate) {
- struct tm *tm;
- char date[256];
- char *utf8, *loc;
- char *zone;
- time_t now_t;
- struct tm now;
- char *tip;
-
- tm = localtime (&cd->current_time);
+ gboolean show_date;
- utf8 = NULL;
+ show_date = g_settings_get_boolean (cd->clock_settings, "clock-show-date");
+ if (!show_date) {
+ GDateTime *dt;
+ char *tip, *format;
- /* Show date in tooltip. */
+ dt = g_date_time_new_now_local ();
/* Translators: This is a strftime format string.
* It is used to display a date. Please leave "%%s" as it is:
* it will be used to insert the timezone name later. */
- loc = g_locale_from_utf8 (_("%A %B %d (%%s)"), -1, NULL, NULL, NULL);
- if (!loc)
- strcpy (date, "???");
- else if (strftime (date, sizeof (date), loc, tm) <= 0)
- strcpy (date, "???");
- g_free (loc);
-
- utf8 = g_locale_to_utf8 (date, -1, NULL, NULL, NULL);
-
- /* Add the timezone name */
-
- tzset ();
- time (&now_t);
- localtime_r (&now_t, &now);
-
- if (now.tm_isdst > 0) {
- zone = tzname[1];
- } else {
- zone = tzname[0];
- }
-
- tip = g_strdup_printf (utf8, zone);
+ format = g_date_time_format (dt, _("%A %B %d (%%s)"));
+ tip = g_strdup_printf (format, g_date_time_get_timezone_abbreviation (dt));
gtk_widget_set_tooltip_text (cd->panel_button, tip);
- g_free (utf8);
+
+ g_date_time_unref (dt);
+ g_free (format);
g_free (tip);
} else {
#ifdef HAVE_LIBECAL
@@ -683,40 +335,6 @@ update_tooltip (ClockData * cd)
}
static void
-refresh_clock (ClockData *cd)
-{
- unfix_size (cd);
- update_clock (cd);
-}
-
-static void
-refresh_clock_timeout(ClockData *cd)
-{
- unfix_size (cd);
-
- update_timeformat (cd);
-
- if (cd->timeout)
- g_source_remove (cd->timeout);
-
- update_clock (cd);
-
- clock_set_timeout (cd, cd->current_time);
-}
-
-/**
- * This is like refresh_clock_timeout(), except that we only care about whether
- * the time actually changed. We don't care about the format.
- */
-static void
-refresh_click_timeout_time_only (ClockData *cd)
-{
- if (cd->timeout)
- g_source_remove (cd->timeout);
- clock_timeout_callback (cd);
-}
-
-static void
free_locations (ClockData *cd)
{
GList *l;
@@ -731,20 +349,11 @@ free_locations (ClockData *cd)
static void
destroy_clock (GtkWidget * widget, ClockData *cd)
{
- GConfClient *client;
- int i;
-
- client = gconf_client_get_default ();
-
- for (i = 0; i < N_GCONF_PREFS; i++)
- gconf_client_notify_remove (
- client, cd->listeners [i]);
+ g_clear_object (&cd->applet_settings);
+ g_clear_object (&cd->clock_settings);
+ g_clear_object (&cd->weather_settings);
- g_object_unref (G_OBJECT (client));
-
- if (cd->timeout)
- g_source_remove (cd->timeout);
- cd->timeout = 0;
+ g_clear_object (&cd->wall_clock);
if (cd->props)
gtk_widget_destroy (cd->props);
@@ -758,19 +367,11 @@ destroy_clock (GtkWidget * widget, ClockData *cd)
g_object_unref (cd->datetime_appinfo);
cd->datetime_appinfo = NULL;
- g_free (cd->timeformat);
- g_free (cd->custom_format);
-
free_locations (cd);
g_list_free (cd->location_tiles);
cd->location_tiles = NULL;
- if (cd->systz) {
- g_object_unref (cd->systz);
- cd->systz = NULL;
- }
-
if (cd->cities_store) {
g_object_unref (cd->cities_store);
cd->cities_store = NULL;
@@ -820,22 +421,18 @@ static GtkWidget *
create_calendar (ClockData *cd)
{
GtkWidget *window;
- char *prefs_dir;
- prefs_dir = panel_applet_get_preferences_key (PANEL_APPLET (cd->applet));
- window = calendar_window_new (&cd->current_time,
- prefs_dir,
+ window = calendar_window_new (cd->applet_settings,
cd->orient == PANEL_APPLET_ORIENT_UP);
- g_free (prefs_dir);
g_object_bind_property (cd->applet, "locked-down",
window, "locked-down",
G_BINDING_DEFAULT|G_BINDING_SYNC_CREATE);
calendar_window_set_show_weeks (CALENDAR_WINDOW (window),
- cd->showweek);
+ g_settings_get_boolean (cd->applet_settings, "show-weeks"));
calendar_window_set_time_format (CALENDAR_WINDOW (window),
- cd->format);
+ g_settings_get_enum (cd->clock_settings, "clock-format"));
gtk_window_set_screen (GTK_WINDOW (window),
gtk_widget_get_screen (cd->applet));
@@ -982,8 +579,8 @@ sort_locations_by_name (gconstpointer a, gconstpointer b)
ClockLocation *loc_a = (ClockLocation *) a;
ClockLocation *loc_b = (ClockLocation *) b;
- const char *name_a = clock_location_get_display_name (loc_a);
- const char *name_b = clock_location_get_display_name (loc_b);
+ const char *name_a = clock_location_get_name (loc_a);
+ const char *name_b = clock_location_get_name (loc_b);
return strcmp (name_a, name_b);
}
@@ -1014,7 +611,7 @@ create_cities_store (ClockData *cd)
gtk_list_store_append (cd->cities_store, &iter);
gtk_list_store_set (cd->cities_store, &iter,
- COL_CITY_NAME, clock_location_get_display_name (loc),
+ COL_CITY_NAME, clock_location_get_name (loc),
/* FIXME: translate the timezone */
COL_CITY_TZ, clock_location_get_timezone (loc),
COL_CITY_LOC, loc,
@@ -1037,42 +634,17 @@ sort_locations_by_time (gconstpointer a, gconstpointer b)
ClockLocation *loc_a = (ClockLocation *) a;
ClockLocation *loc_b = (ClockLocation *) b;
- struct tm tm_a;
- struct tm tm_b;
+ GDateTime *dt1;
+ GDateTime *dt2;
gint ret;
- clock_location_localtime (loc_a, &tm_a);
- clock_location_localtime (loc_b, &tm_b);
-
- ret = (tm_a.tm_year == tm_b.tm_year) ? 0 : 1;
- if (ret) {
- return (tm_a.tm_year < tm_b.tm_year) ? -1 : 1;
- }
-
- ret = (tm_a.tm_mon == tm_b.tm_mon) ? 0 : 1;
- if (ret) {
- return (tm_a.tm_mon < tm_b.tm_mon) ? -1 : 1;
- }
-
- ret = (tm_a.tm_mday == tm_b.tm_mday) ? 0 : 1;
- if (ret) {
- return (tm_a.tm_mday < tm_b.tm_mday) ? -1 : 1;
- }
-
- ret = (tm_a.tm_hour == tm_b.tm_hour) ? 0 : 1;
- if (ret) {
- return (tm_a.tm_hour < tm_b.tm_hour) ? -1 : 1;
- }
+ dt1 = clock_location_localtime (loc_a);
+ dt2 = clock_location_localtime (loc_b);
- ret = (tm_a.tm_min == tm_b.tm_min) ? 0 : 1;
- if (ret) {
- return (tm_a.tm_min < tm_b.tm_min) ? -1 : 1;
- }
+ ret = g_date_time_compare (dt1, dt2);
- ret = (tm_a.tm_sec == tm_b.tm_sec) ? 0 : 1;
- if (ret) {
- return (tm_a.tm_sec < tm_b.tm_sec) ? -1 : 1;
- }
+ g_date_time_unref (dt1);
+ g_date_time_unref (dt2);
return ret;
}
@@ -1090,12 +662,12 @@ location_tile_pressed_cb (ClockLocationTile *tile, gpointer data)
g_object_unref (loc);
}
-static ClockFormat
+static int
location_tile_need_clock_format_cb(ClockLocationTile *tile, gpointer data)
{
ClockData *cd = data;
- return cd->format;
+ return g_settings_get_enum (cd->clock_settings, "clock-format");
}
static void
@@ -1235,7 +807,7 @@ toggle_calendar (GtkWidget *button,
{
/* if time is wrong, the user might try to fix it by clicking on the
* clock */
- refresh_click_timeout_time_only (cd);
+ update_clock (NULL, NULL, cd);
update_calendar_popup (cd);
}
@@ -1345,7 +917,7 @@ weather_tooltip (GtkWidget *widget,
ClockData *cd)
{
GList *locations, *l;
- WeatherInfo *info;
+ GWeatherInfo *info;
locations = cd->locations;
@@ -1353,10 +925,11 @@ weather_tooltip (GtkWidget *widget,
ClockLocation *location = l->data;
if (clock_location_is_current (location)) {
info = clock_location_get_weather_info (location);
- if (!info || !weather_info_is_valid (info))
+ if (!info || !gweather_info_is_valid (info))
continue;
- weather_info_setup_tooltip (info, location, tooltip, cd->format);
+ weather_info_setup_tooltip (info, location, tooltip,
+ g_settings_get_enum (cd->clock_settings, "clock-format"));
return TRUE;
}
@@ -1368,6 +941,10 @@ weather_tooltip (GtkWidget *widget,
static void
create_clock_widget (ClockData *cd)
{
+ cd->wall_clock = g_object_new (GNOME_TYPE_WALL_CLOCK, NULL);
+ g_signal_connect (cd->wall_clock, "notify::clock",
+ G_CALLBACK (update_clock), cd);
+
/* Main toggle button */
cd->panel_button = create_main_clock_button ();
g_signal_connect (cd->panel_button, "button_press_event",
@@ -1396,9 +973,13 @@ create_clock_widget (ClockData *cd)
/* Weather widgets */
cd->panel_weather_icon = gtk_image_new ();
gtk_box_pack_start (GTK_BOX (cd->weather_obox), cd->panel_weather_icon, FALSE, FALSE, 0);
+ g_settings_bind (cd->applet_settings, "show-weather", cd->panel_weather_icon, "visible",
+ G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_NO_SENSITIVITY);
cd->panel_temperature_label = gtk_label_new (NULL);
gtk_box_pack_start (GTK_BOX (cd->weather_obox), cd->panel_temperature_label, FALSE, FALSE, 0);
+ g_settings_bind (cd->applet_settings, "show-temperature", cd->panel_temperature_label, "visible",
+ G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_NO_SENSITIVITY);
/* Main label for time display */
cd->clockw = create_main_clock_label (cd);
@@ -1420,7 +1001,7 @@ create_clock_widget (ClockData *cd)
update_panel_weather (cd);
/* Refresh the clock so that it paints its first state */
- refresh_clock_timeout (cd);
+ update_clock (NULL, NULL, cd);
applet_change_orient (PANEL_APPLET (cd->applet),
panel_applet_get_orient (PANEL_APPLET (cd->applet)),
cd);
@@ -1491,7 +1072,7 @@ applet_change_orient (PanelApplet *applet,
gtk_orientable_set_orientation (GTK_ORIENTABLE (cd->weather_obox), o);
unfix_size (cd);
- update_clock (cd);
+ update_clock (NULL, NULL, cd);
update_calendar_popup (cd);
}
@@ -1519,109 +1100,21 @@ panel_button_change_pixel_size (GtkWidget *widget,
cd->size = new_size;
unfix_size (cd);
- update_timeformat (cd);
- update_clock (cd);
+ update_clock (NULL, NULL, cd);
}
static void
copy_time (GtkAction *action,
ClockData *cd)
{
- char string[256];
- char *utf8;
-
- if (cd->format == CLOCK_FORMAT_UNIX) {
- g_snprintf (string, sizeof(string), "%lu",
- (unsigned long)cd->current_time);
- } else if (cd->format == CLOCK_FORMAT_INTERNET) {
- float itime = get_itime (cd->current_time);
- if (cd->showseconds)
- g_snprintf (string, sizeof (string), "@%3.2f", itime);
- else
- g_snprintf (string, sizeof (string), "@%3d",
- (unsigned int) itime);
- } else {
- struct tm *tm;
- char *format;
-
- if (cd->format == CLOCK_FORMAT_CUSTOM) {
- format = g_locale_from_utf8 (cd->custom_format, -1,
- NULL, NULL, NULL);
- } else if (cd->format == CLOCK_FORMAT_12) {
- if (cd->showseconds)
- /* Translators: This is a strftime format
- * string.
- * It is used to display the time in 12-hours
- * format with a leading 0 if needed (eg, like
- * in the US: 08:10 am). The %p expands to
- * am/pm. */
- format = g_locale_from_utf8 (_("%I:%M:%S %p"), -1, NULL, NULL, NULL);
- else
- /* Translators: This is a strftime format
- * string.
- * It is used to display the time in 12-hours
- * format with a leading 0 if needed (eg, like
- * in the US: 08:10 am). The %p expands to
- * am/pm. */
- format = g_locale_from_utf8 (_("%I:%M %p"), -1, NULL, NULL, NULL);
- } else {
- if (cd->showseconds)
- /* Translators: This is a strftime format
- * string.
- * It is used to display the time in 24-hours
- * format (eg, like in France: 20:10). */
- format = g_locale_from_utf8 (_("%H:%M:%S"), -1, NULL, NULL, NULL);
- else
- /* Translators: This is a strftime format
- * string.
- * It is used to display the time in 24-hours
- * format (eg, like in France: 20:10). */
- format = g_locale_from_utf8 (_("%H:%M"), -1, NULL, NULL, NULL);
- }
-
- tm = localtime (&cd->current_time);
+ const char *time;
- if (!format)
- strcpy (string, "???");
- else if (strftime (string, sizeof (string), format, tm) <= 0)
- strcpy (string, "???");
- g_free (format);
- }
+ time = gnome_wall_clock_get_clock (cd->wall_clock);
- utf8 = g_locale_to_utf8 (string, -1, NULL, NULL, NULL);
gtk_clipboard_set_text (gtk_clipboard_get (GDK_SELECTION_PRIMARY),
- utf8, -1);
+ time, -1);
gtk_clipboard_set_text (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD),
- utf8, -1);
- g_free (utf8);
-}
-
-static void
-copy_date (GtkAction *action,
- ClockData *cd)
-{
- struct tm *tm;
- char string[256];
- char *utf8, *loc;
-
- tm = localtime (&cd->current_time);
-
- /* Translators: This is a strftime format string.
- * It is used to display a date in the full format (so that people can
- * copy and paste it elsewhere). */
- loc = g_locale_from_utf8 (_("%A, %B %d %Y"), -1, NULL, NULL, NULL);
- if (!loc)
- strcpy (string, "???");
- else if (strftime (string, sizeof (string), loc, tm) <= 0)
- strcpy (string, "???");
- g_free (loc);
-
- utf8 = g_locale_to_utf8 (string, -1, NULL, NULL, NULL);
- gtk_clipboard_set_text (gtk_clipboard_get (GDK_SELECTION_PRIMARY),
- utf8, -1);
- gtk_clipboard_set_text (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD),
- utf8, -1);
- g_free (utf8);
+ time, -1);
}
static void
@@ -1698,98 +1191,36 @@ static const GtkActionEntry clock_menu_actions [] = {
{ "ClockPreferences", GTK_STOCK_PROPERTIES, N_("_Preferences"),
NULL, NULL,
G_CALLBACK (verb_display_properties_dialog) },
- { "ClockCopyTime", GTK_STOCK_COPY, N_("Copy _Time"),
+ { "ClockCopyTime", GTK_STOCK_COPY, N_("Copy Date and _Time"),
NULL, NULL,
G_CALLBACK (copy_time) },
- { "ClockCopyDate", GTK_STOCK_COPY, N_("Copy _Date"),
- NULL, NULL,
- G_CALLBACK (copy_date) },
{ "ClockConfig", GTK_STOCK_PREFERENCES, N_("Ad_just Date & Time"),
NULL, NULL,
G_CALLBACK (config_date) }
};
static void
-format_changed (GConfClient *client,
- guint cnxn_id,
- GConfEntry *entry,
+format_changed (GSettings *settings,
+ const char *key,
ClockData *clock)
{
- const char *value;
- int new_format;
-
- if (!entry->value || entry->value->type != GCONF_VALUE_STRING)
- return;
-
- value = gconf_value_get_string (entry->value);
- if (!gconf_string_to_enum (format_type_enum_map, value, &new_format))
- return;
-
- if (!clock->can_handle_format_12 && new_format == CLOCK_FORMAT_12)
- new_format = CLOCK_FORMAT_24;
-
- if (new_format == clock->format)
- return;
-
- clock->format = new_format;
- refresh_clock_timeout (clock);
-
if (clock->calendar_popup != NULL) {
- calendar_window_set_time_format (CALENDAR_WINDOW (clock->calendar_popup), clock->format);
+ calendar_window_set_time_format (CALENDAR_WINDOW (clock->calendar_popup),
+ g_settings_get_enum (settings, "clock-format"));
position_calendar_popup (clock);
}
}
static void
-show_seconds_changed (GConfClient *client,
- guint cnxn_id,
- GConfEntry *entry,
- ClockData *clock)
-{
- gboolean value;
-
- if (!entry->value || entry->value->type != GCONF_VALUE_BOOL)
- return;
-
- value = gconf_value_get_bool (entry->value);
-
- clock->showseconds = (value != 0);
- refresh_clock_timeout (clock);
-}
-
-static void
-show_date_changed (GConfClient *client,
- guint cnxn_id,
- GConfEntry *entry,
- ClockData *clock)
-{
- gboolean value;
-
- if (!entry->value || entry->value->type != GCONF_VALUE_BOOL)
- return;
-
- value = gconf_value_get_bool (entry->value);
-
- clock->showdate = (value != 0);
- update_timeformat (clock);
- refresh_clock (clock);
-}
-
-static void
update_panel_weather (ClockData *cd)
{
- if (cd->show_weather)
- gtk_widget_show (cd->panel_weather_icon);
- else
- gtk_widget_hide (cd->panel_weather_icon);
+ gboolean show_weather, show_temperature;
- if (cd->show_temperature)
- gtk_widget_show (cd->panel_temperature_label);
- else
- gtk_widget_hide (cd->panel_temperature_label);
+ show_weather = g_settings_get_boolean (cd->applet_settings, "show-weather");
+ show_temperature = g_settings_get_boolean (cd->applet_settings, "show-temperature");
- if ((cd->show_weather || cd->show_temperature) &&
+ if ((show_weather || show_temperature) &&
g_list_length (cd->locations) > 0)
gtk_widget_show (cd->weather_obox);
else
@@ -1799,49 +1230,9 @@ update_panel_weather (ClockData *cd)
}
static void
-update_weather_bool_value_and_toggle_from_gconf (ClockData *cd, GConfEntry *entry,
- gboolean *value_loc, const char *widget_name)
-{
- GtkWidget *widget;
- gboolean value;
-
- if (!entry->value || entry->value->type != GCONF_VALUE_BOOL)
- return;
-
- value = gconf_value_get_bool (entry->value);
-
- *value_loc = (value != 0);
-
- widget = _clock_get_widget (cd, widget_name);
-
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget),
- *value_loc);
-
- update_panel_weather (cd);
-}
-
-static void
-show_weather_changed (GConfClient *client,
- guint cnxn_id,
- GConfEntry *entry,
- ClockData *cd)
-{
- update_weather_bool_value_and_toggle_from_gconf (cd, entry, &cd->show_weather, "weather_check");
-}
-
-static void
-show_temperature_changed (GConfClient *client,
- guint cnxn_id,
- GConfEntry *entry,
- ClockData *cd)
-{
- update_weather_bool_value_and_toggle_from_gconf (cd, entry, &cd->show_temperature, "temperature_check");
-}
-
-static void
-location_weather_updated_cb (ClockLocation *location,
- WeatherInfo *info,
- gpointer data)
+location_weather_updated_cb (ClockLocation *location,
+ GWeatherInfo *info,
+ gpointer data)
{
ClockData *cd = data;
const gchar *icon_name;
@@ -1849,19 +1240,19 @@ location_weather_updated_cb (ClockLocation *location,
GtkIconTheme *theme;
GdkPixbuf *pixbuf;
- if (!info || !weather_info_is_valid (info))
+ if (!info || !gweather_info_is_valid (info))
return;
if (!clock_location_is_current (location))
return;
- icon_name = weather_info_get_icon_name (info);
+ icon_name = gweather_info_get_icon_name (info);
/* FIXME: mmh, screen please? Also, don't hardcode to 16 */
theme = gtk_icon_theme_get_default ();
pixbuf = gtk_icon_theme_load_icon (theme, icon_name, 16,
GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);
- temp = weather_info_get_temp_summary (info);
+ temp = gweather_info_get_temp_summary (info);
gtk_image_set_from_pixbuf (GTK_IMAGE (cd->panel_weather_icon), pixbuf);
gtk_label_set_text (GTK_LABEL (cd->panel_temperature_label), temp);
@@ -1872,7 +1263,7 @@ location_set_current_cb (ClockLocation *loc,
gpointer data)
{
ClockData *cd = data;
- WeatherInfo *info;
+ GWeatherInfo *info;
info = clock_location_get_weather_info (loc);
location_weather_updated_cb (loc, info, cd);
@@ -1884,7 +1275,9 @@ location_set_current_cb (ClockLocation *loc,
}
static void
-locations_changed (ClockData *cd)
+locations_changed (GSettings *settings,
+ const char *key,
+ ClockData *cd)
{
GList *l;
ClockLocation *loc;
@@ -1924,482 +1317,41 @@ locations_changed (ClockData *cd)
create_cities_section (cd);
}
-
-static void
-set_locations (ClockData *cd, GList *locations)
-{
- free_locations (cd);
- cd->locations = locations;
- locations_changed (cd);
-}
-
-typedef struct {
- GList *cities;
- ClockData *cd;
-} LocationParserData;
-
-/* Parser for our serialized locations in gconf */
-static void
-location_start_element (GMarkupParseContext *context,
- const gchar *element_name,
- const gchar **attribute_names,
- const gchar **attribute_values,
- gpointer user_data,
- GError **error)
-{
- ClockLocation *loc;
- LocationParserData *data = user_data;
- ClockData *cd = data->cd;
- WeatherPrefs prefs;
- const gchar *att_name;
-
- gchar *name = NULL;
- gchar *city = NULL;
- gchar *timezone = NULL;
- gfloat latitude = 0.0;
- gfloat longitude = 0.0;
- gchar *code = NULL;
- gboolean current = FALSE;
-
- int index = 0;
-
- prefs.temperature_unit = cd->temperature_unit;
- prefs.speed_unit = cd->speed_unit;
-
- if (strcmp (element_name, "location") != 0) {
- return;
- }
-
- setlocale (LC_NUMERIC, "POSIX");
-
- for (att_name = attribute_names[index]; att_name != NULL;
- att_name = attribute_names[++index]) {
- if (strcmp (att_name, "name") == 0) {
- name = (gchar *)attribute_values[index];
- } else if (strcmp (att_name, "city") == 0) {
- city = (gchar *)attribute_values[index];
- } else if (strcmp (att_name, "timezone") == 0) {
- timezone = (gchar *)attribute_values[index];
- } else if (strcmp (att_name, "latitude") == 0) {
- sscanf (attribute_values[index], "%f", &latitude);
- } else if (strcmp (att_name, "longitude") == 0) {
- sscanf (attribute_values[index], "%f", &longitude);
- } else if (strcmp (att_name, "code") == 0) {
- code = (gchar *)attribute_values[index];
- }
- else if (strcmp (att_name, "current") == 0) {
- if (strcmp (attribute_values[index], "true") == 0) {
- current = TRUE;
- }
- }
- }
-
- setlocale (LC_NUMERIC, "");
-
- if ((!name && !city) || !timezone) {
- return;
- }
-
- /* migration from the old configuration, when name == city */
- if (!city)
- city = name;
-
- loc = clock_location_find_and_ref (cd->locations, name, city,
- timezone, latitude, longitude, code);
- if (!loc)
- loc = clock_location_new (name, city, timezone,
- latitude, longitude, code, &prefs);
-
- if (current && clock_location_is_current_timezone (loc))
- clock_location_make_current (loc, NULL, NULL, NULL);
-
- data->cities = g_list_append (data->cities, loc);
-}
-
-static GMarkupParser location_parser = {
- location_start_element, NULL, NULL, NULL, NULL
-};
-
-static void
-cities_changed (GConfClient *client,
- guint cnxn_id,
- GConfEntry *entry,
- ClockData *cd)
-{
- LocationParserData data;
-
- GSList *cur = NULL;
-
- GMarkupParseContext *context;
-
- data.cities = NULL;
- data.cd = cd;
-
- if (!entry->value || entry->value->type != GCONF_VALUE_LIST)
- return;
-
- context = g_markup_parse_context_new (&location_parser, 0, &data, NULL);
-
- cur = gconf_value_get_list (entry->value);
-
- while (cur) {
- const char *str = gconf_value_get_string (cur->data);
- g_markup_parse_context_parse (context, str, strlen (str), NULL);
-
- cur = cur->next;
- }
-
- g_markup_parse_context_free (context);
-
- set_locations (cd, data.cities);
- create_cities_store (cd);
-}
-
-static void
-update_temperature_combo (ClockData *cd)
-{
- GtkWidget *widget;
- int active_index;
-
- widget = _clock_get_widget (cd, "temperature_combo");
-
- if (cd->use_temperature_default)
- active_index = 0;
- else
- active_index = cd->temperature_unit - 1;
-
- gtk_combo_box_set_active (GTK_COMBO_BOX (widget), active_index);
-}
-
-static void
-update_weather_locations (ClockData *cd)
-{
- GList *locations, *l;
- WeatherPrefs prefs = {
- FORECAST_STATE,
- FALSE,
- NULL,
- TEMP_UNIT_CENTIGRADE,
- SPEED_UNIT_MS,
- PRESSURE_UNIT_MB,
- DISTANCE_UNIT_KM
- };
-
- prefs.temperature_unit = cd->temperature_unit;
- prefs.speed_unit = cd->speed_unit;
-
- locations = cd->locations;
-
- for (l = locations; l; l = l->next) {
- clock_location_set_weather_prefs (l->data, &prefs);
- }
-}
-
-static void
-clock_migrate_to_26 (ClockData *clock)
-{
- gboolean unixtime;
- gboolean internettime;
- int hourformat;
-
- internettime = panel_applet_gconf_get_bool (PANEL_APPLET (clock->applet),
- "internet_time",
- NULL);
- unixtime = panel_applet_gconf_get_bool (PANEL_APPLET (clock->applet),
- "unix_time",
- NULL);
- hourformat = panel_applet_gconf_get_int (PANEL_APPLET (clock->applet),
- "hour_format",
- NULL);
-
- if (unixtime)
- clock->format = CLOCK_FORMAT_UNIX;
- else if (internettime)
- clock->format = CLOCK_FORMAT_INTERNET;
- else if (hourformat == 12)
- clock->format = CLOCK_FORMAT_12;
- else if (hourformat == 24)
- clock->format = CLOCK_FORMAT_24;
-
- /* It's still possible that we have none of the old keys, in which case
- * we're not migrating from 2.6, but the config is simply wrong. So
- * don't set the format key in this case. */
- if (clock->format != CLOCK_FORMAT_INVALID)
- panel_applet_gconf_set_string (PANEL_APPLET (clock->applet),
- KEY_FORMAT,
- gconf_enum_to_string (format_type_enum_map,
- clock->format),
- NULL);
-}
-
-static void
-clock_timezone_changed (SystemTimezone *systz,
- const char *new_tz,
- ClockData *cd)
-{
- /* This will refresh the current location */
- save_cities_store (cd);
-
- refresh_click_timeout_time_only (cd);
-}
-
-static void
-parse_and_set_temperature_string (const char *str, ClockData *cd)
-{
- gint value = 0;
- gboolean use_default = FALSE;
-
- value = gweather_prefs_parse_temperature (str, &use_default);
-
- cd->use_temperature_default = use_default;
- cd->temperature_unit = value;
-}
-
-static void
-parse_and_set_speed_string (const char *str, ClockData *cd)
-{
- gint value = 0;
- gboolean use_default = FALSE;
-
- value = gweather_prefs_parse_speed (str, &use_default);
-
- cd->use_speed_default = use_default;
- cd->speed_unit = value;
-}
-
-static void
-temperature_unit_changed (GConfClient *client,
- guint cnxn_id,
- GConfEntry *entry,
- ClockData *cd)
-{
- const gchar *value;
-
- if (!entry->value || entry->value->type != GCONF_VALUE_STRING)
- return;
-
- value = gconf_value_get_string (entry->value);
- parse_and_set_temperature_string (value, cd);
- update_temperature_combo (cd);
- update_weather_locations (cd);
-}
-
static void
-update_speed_combo (ClockData *cd)
-{
- GtkWidget *widget;
- int active_index;
-
- widget = _clock_get_widget (cd, "wind_speed_combo");
-
- if (cd->use_speed_default)
- active_index = 0;
- else
- active_index = cd->speed_unit - 1;
-
- gtk_combo_box_set_active (GTK_COMBO_BOX (widget), active_index);
-}
-
-static void
-speed_unit_changed (GConfClient *client,
- guint cnxn_id,
- GConfEntry *entry,
- ClockData *cd)
-{
- const gchar *value;
-
- if (!entry->value || entry->value->type != GCONF_VALUE_STRING)
- return;
-
- value = gconf_value_get_string (entry->value);
- parse_and_set_speed_string (value, cd);
- update_speed_combo (cd);
- update_weather_locations (cd);
-}
-
-static void
-custom_format_changed (GConfClient *client,
- guint cnxn_id,
- GConfEntry *entry,
- ClockData *clock)
-{
- const char *value;
-
- if (!entry->value || entry->value->type != GCONF_VALUE_STRING)
- return;
-
- value = gconf_value_get_string (entry->value);
-
- g_free (clock->custom_format);
- clock->custom_format = g_strdup (value);
-
- if (clock->format == CLOCK_FORMAT_CUSTOM)
- refresh_clock (clock);
-}
-
-static void
-show_week_changed (GConfClient *client,
- guint cnxn_id,
- GConfEntry *entry,
+show_week_changed (GSettings *settings,
+ const char *key,
ClockData *clock)
{
- gboolean value;
-
- if (!entry->value || entry->value->type != GCONF_VALUE_BOOL)
- return;
-
- value = gconf_value_get_bool (entry->value);
-
- if (clock->showweek == (value != 0))
- return;
-
- clock->showweek = (value != 0);
-
if (clock->calendar_popup != NULL) {
- calendar_window_set_show_weeks (CALENDAR_WINDOW (clock->calendar_popup), clock->showweek);
+ calendar_window_set_show_weeks (CALENDAR_WINDOW (clock->calendar_popup),
+ g_settings_get_boolean (settings, "show-weeks"));
position_calendar_popup (clock);
}
}
-static guint
-setup_gconf_preference (ClockData *cd, GConfClient *client, const char *key_name, GConfClientNotifyFunc callback)
-{
- char *key;
- guint id;
-
- key = panel_applet_gconf_get_full_key (PANEL_APPLET (cd->applet),
- key_name);
- id = gconf_client_notify_add (client, key,
- callback,
- cd, NULL, NULL);
- g_free (key);
-
- return id;
-}
-
static void
-setup_gconf (ClockData *cd)
-{
- struct {
- const char *key_name;
- GConfClientNotifyFunc callback;
- } prefs[] = {
- { KEY_FORMAT, (GConfClientNotifyFunc) format_changed },
- { KEY_SHOW_SECONDS, (GConfClientNotifyFunc) show_seconds_changed },
- { KEY_SHOW_DATE, (GConfClientNotifyFunc) show_date_changed },
- { KEY_SHOW_WEATHER, (GConfClientNotifyFunc) show_weather_changed },
- { KEY_SHOW_TEMPERATURE, (GConfClientNotifyFunc) show_temperature_changed },
- { KEY_CUSTOM_FORMAT, (GConfClientNotifyFunc) custom_format_changed },
- { KEY_SHOW_WEEK, (GConfClientNotifyFunc) show_week_changed },
- { KEY_CITIES, (GConfClientNotifyFunc) cities_changed },
- { KEY_TEMPERATURE_UNIT, (GConfClientNotifyFunc) temperature_unit_changed },
- { KEY_SPEED_UNIT, (GConfClientNotifyFunc) speed_unit_changed },
- };
-
- GConfClient *client;
- int i;
-
- client = gconf_client_get_default ();
-
- for (i = 0; i < G_N_ELEMENTS (prefs); i++)
- cd->listeners[i] = setup_gconf_preference (cd, client, prefs[i].key_name, prefs[i].callback);
-
- g_object_unref (G_OBJECT (client));
-}
-
-static GList *
-parse_gconf_cities (ClockData *cd, GSList *values)
+load_cities (ClockData *cd)
{
- GSList *cur = values;
- LocationParserData data;
- GMarkupParseContext *context;
-
- data.cities = NULL;
- data.cd = cd;
-
- context =
- g_markup_parse_context_new (&location_parser, 0, &data, NULL);
-
- while (cur) {
- const char *str = (char *)cur->data;
- g_markup_parse_context_parse (context, str, strlen(str), NULL);
-
- cur = cur->next;
- }
-
- g_markup_parse_context_free (context);
-
- return data.cities;
-}
-
-static void
-load_gconf_settings (ClockData *cd)
-{
- PanelApplet *applet;
- int format;
- char *format_str;
- char *value;
- GError *error;
- GSList *values = NULL;
- GList *cities = NULL;
-
- applet = PANEL_APPLET (cd->applet);
-
- cd->format = CLOCK_FORMAT_INVALID;
-
- format_str = panel_applet_gconf_get_string (applet, KEY_FORMAT, NULL);
- if (format_str &&
- gconf_string_to_enum (format_type_enum_map, format_str, &format))
- cd->format = format;
- else
- clock_migrate_to_26 (cd);
-
- g_free (format_str);
-
- if (cd->format == CLOCK_FORMAT_INVALID)
- cd->format = clock_locale_format ();
-
- cd->custom_format = panel_applet_gconf_get_string (applet, KEY_CUSTOM_FORMAT, NULL);
- cd->showseconds = panel_applet_gconf_get_bool (applet, KEY_SHOW_SECONDS, NULL);
-
- error = NULL;
- cd->showdate = panel_applet_gconf_get_bool (applet, KEY_SHOW_DATE, &error);
- if (error) {
- g_error_free (error);
- /* if on a small screen don't show date by default */
- if (gdk_screen_width () <= 800)
- cd->showdate = FALSE;
- else
- cd->showdate = TRUE;
- }
-
- cd->show_weather = panel_applet_gconf_get_bool (applet, KEY_SHOW_WEATHER, NULL);
- cd->show_temperature = panel_applet_gconf_get_bool (applet, KEY_SHOW_TEMPERATURE, NULL);
- cd->showweek = panel_applet_gconf_get_bool (applet, KEY_SHOW_WEEK, NULL);
- cd->timeformat = NULL;
-
- cd->can_handle_format_12 = (clock_locale_format () == CLOCK_FORMAT_12);
- if (!cd->can_handle_format_12 && cd->format == CLOCK_FORMAT_12)
- cd->format = CLOCK_FORMAT_24;
+ GVariantIter *iter;
+ const char *name;
+ const char *code;
+ gboolean latlon_override;
+ gdouble latitude, longitude;
- value = panel_applet_gconf_get_string (applet, KEY_TEMPERATURE_UNIT, NULL);
- parse_and_set_temperature_string (value, cd);
- g_free (value);
+ g_settings_get (cd->applet_settings, "cities", "a(ssm(dd))", &iter);
- value = panel_applet_gconf_get_string (applet, KEY_SPEED_UNIT, NULL);
- parse_and_set_speed_string (value, cd);
- g_free (value);
+ while (g_variant_iter_loop (iter, "(&s&sm(dd))", &name, &code, &latlon_override,
+ &latitude, &longitude)) {
+ ClockLocation *loc;
- values = panel_applet_gconf_get_list (PANEL_APPLET (cd->applet), KEY_CITIES,
- GCONF_VALUE_STRING, NULL);
+ loc = clock_location_new (cd->world,
+ name, code,
+ latlon_override, latitude, longitude);
- if (g_slist_length (values) == 0) {
- cities = NULL;
- } else {
- cities = parse_gconf_cities (cd, values);
+ cd->locations = g_list_prepend (cd->locations, loc);
}
- set_locations (cd, cities);
+ cd->locations = g_list_reverse (cd->locations);
}
static gboolean
@@ -2409,17 +1361,29 @@ fill_clock_applet (PanelApplet *applet)
GtkActionGroup *action_group;
GtkAction *action;
- panel_applet_add_preferences (applet, CLOCK_SCHEMA_DIR, NULL);
panel_applet_set_flags (applet, PANEL_APPLET_EXPAND_MINOR);
cd = g_new0 (ClockData, 1);
+
+ cd->applet_settings = panel_applet_settings_new (applet, "org.gnome.gnome-panel.applet.clock");
+ cd->clock_settings = g_settings_new ("org.gnome.desktop.interface");
+ cd->weather_settings = g_settings_new ("org.gnome.GWeather");
+
+ g_signal_connect (cd->clock_settings, "changed::clock-format",
+ G_CALLBACK (format_changed), cd);
+ g_signal_connect (cd->clock_settings, "changed::clock-show-weeks",
+ G_CALLBACK (show_week_changed), cd);
+ g_signal_connect (cd->applet_settings, "changed::cities",
+ G_CALLBACK (locations_changed), cd);
+
cd->fixed_width = -1;
cd->fixed_height = -1;
cd->applet = GTK_WIDGET (applet);
- setup_gconf (cd);
- load_gconf_settings (cd);
+ cd->world = gweather_location_new_world (FALSE);
+ load_cities (cd);
+ locations_changed (NULL, NULL, cd);
cd->builder = gtk_builder_new ();
gtk_builder_set_translation_domain (cd->builder, GETTEXT_PACKAGE);
@@ -2468,191 +1432,11 @@ fill_clock_applet (PanelApplet *applet)
g_object_bind_property (cd->applet, "locked-down",
action, "visible",
G_BINDING_DEFAULT|G_BINDING_INVERT_BOOLEAN|G_BINDING_SYNC_CREATE);
-
- cd->systz = system_timezone_new ();
- g_signal_connect (cd->systz, "changed",
- G_CALLBACK (clock_timezone_changed), cd);
-
g_object_unref (action_group);
return TRUE;
}
-/* FIXME old clock applet */
-#if 0
-static void
-setup_writability_sensitivity (ClockData *clock, GtkWidget *w, GtkWidget *label, const char *key)
-{
- /* FMQ: was used from old preferences dialog; fix this up */
- char *fullkey;
- GConfClient *client;
-
- client = gconf_client_get_default ();
-
- fullkey = panel_applet_gconf_get_full_key
- (PANEL_APPLET (clock->applet), key);
-
- if ( ! gconf_client_key_is_writable (client, fullkey, NULL)) {
- g_object_set_data (G_OBJECT (w), NEVER_SENSITIVE,
- GINT_TO_POINTER (1));
- gtk_widget_set_sensitive (w, FALSE);
- if (label != NULL) {
- g_object_set_data (G_OBJECT (label), NEVER_SENSITIVE,
- GINT_TO_POINTER (1));
- gtk_widget_set_sensitive (label, FALSE);
- }
- }
-
- g_free (fullkey);
-
- g_object_unref (G_OBJECT (client));
-}
-
-static void
-update_properties_for_format (ClockData *cd,
- GtkComboBox *combo,
- ClockFormat format)
-{
-
- /* show the custom format things the first time we actually
- * have a custom format set in GConf, but after that don't
- * unshow it if the format changes
- */
- if (!cd->custom_format_shown &&
- (cd->format == CLOCK_FORMAT_CUSTOM ||
- (cd->custom_format && cd->custom_format [0]))) {
- gtk_widget_show (cd->custom_hbox);
- gtk_widget_show (cd->custom_label);
- gtk_widget_show (cd->custom_entry);
-
- gtk_combo_box_append_text (combo, _("Custom format"));
-
- cd->custom_format_shown = TRUE;
- }
-
- /* Some combinations of options do not make sense */
- switch (format) {
- case CLOCK_FORMAT_12:
- case CLOCK_FORMAT_24:
- gtk_widget_set_sensitive (cd->showseconds_check, TRUE);
- gtk_widget_set_sensitive (cd->showdate_check, TRUE);
- gtk_widget_set_sensitive (cd->custom_entry, FALSE);
- gtk_widget_set_sensitive (cd->custom_label, FALSE);
- break;
- case CLOCK_FORMAT_UNIX:
- gtk_widget_set_sensitive (cd->showseconds_check, FALSE);
- gtk_widget_set_sensitive (cd->showdate_check, FALSE);
- gtk_widget_set_sensitive (cd->custom_entry, FALSE);
- gtk_widget_set_sensitive (cd->custom_label, FALSE);
- break;
- case CLOCK_FORMAT_INTERNET:
- gtk_widget_set_sensitive (cd->showseconds_check, TRUE);
- gtk_widget_set_sensitive (cd->showdate_check, FALSE);
- gtk_widget_set_sensitive (cd->custom_entry, FALSE);
- gtk_widget_set_sensitive (cd->custom_label, FALSE);
- break;
- case CLOCK_FORMAT_CUSTOM:
- gtk_widget_set_sensitive (cd->showseconds_check, FALSE);
- gtk_widget_set_sensitive (cd->showdate_check, FALSE);
- gtk_widget_set_sensitive (cd->custom_entry, TRUE);
- gtk_widget_set_sensitive (cd->custom_label, TRUE);
- break;
- default:
- g_assert_not_reached ();
- break;
- }
-}
-
-static void
-set_format_cb (GtkComboBox *combo,
- ClockData *cd)
-{
- /* FMQ: was used from old preferences dialog; fix this up */
- ClockFormat format;
-
- /* valid values begin from 1 */
- if (cd->can_handle_format_12)
- format = gtk_combo_box_get_active (combo) + 1;
- else
- format = gtk_combo_box_get_active (combo) + 2;
-
- update_properties_for_format (cd, combo, format);
-
- if (cd->format != format)
- panel_applet_gconf_set_string (PANEL_APPLET (cd->applet),
- KEY_FORMAT,
- gconf_enum_to_string (format_type_enum_map, format),
- NULL);
-}
-#endif
-
-static void
-set_show_seconds_cb (GtkWidget *w,
- ClockData *clock)
-{
- panel_applet_gconf_set_bool (PANEL_APPLET (clock->applet),
- KEY_SHOW_SECONDS,
- gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w)),
- NULL);
-}
-
-static void
-set_show_date_cb (GtkWidget *w,
- ClockData *clock)
-{
- panel_applet_gconf_set_bool (PANEL_APPLET (clock->applet),
- KEY_SHOW_DATE,
- gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w)),
- NULL);
-}
-
-static void
-set_show_weather_cb (GtkWidget *w,
- ClockData *clock)
-{
- panel_applet_gconf_set_bool (PANEL_APPLET (clock->applet),
- KEY_SHOW_WEATHER,
- gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w)),
- NULL);
-}
-
-static void
-set_show_temperature_cb (GtkWidget *w,
- ClockData *clock)
-{
- panel_applet_gconf_set_bool (PANEL_APPLET (clock->applet),
- KEY_SHOW_TEMPERATURE,
- gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w)),
- NULL);
-}
-
-#if 0
-static void
-set_show_zones_cb (GtkWidget *w,
- ClockData *clock)
-{
- panel_applet_gconf_set_bool (PANEL_APPLET (clock->applet),
- KEY_SHOW_ZONES,
- GTK_TOGGLE_BUTTON (w)->active,
- NULL);
-}
-#endif
-
-/* FIXME old clock applet */
-#if 0
-static void
-set_custom_format_cb (GtkEntry *entry,
- ClockData *cd)
-{
- /* FMQ: was used from old preferences dialog; fix this up */
- const char *custom_format;
-
- custom_format = gtk_entry_get_text (entry);
- panel_applet_gconf_set_string (PANEL_APPLET (cd->applet),
- KEY_CUSTOM_FORMAT, custom_format, NULL);
-}
-#endif
-
static void
prefs_locations_changed (GtkTreeSelection *selection, ClockData *cd)
{
@@ -2663,60 +1447,38 @@ prefs_locations_changed (GtkTreeSelection *selection, ClockData *cd)
gtk_widget_set_sensitive (cd->prefs_location_remove_button, n > 0);
}
-static gchar *
-loc_to_string (ClockLocation *loc)
+static GVariant *
+location_serialize (ClockLocation *loc)
{
- const gchar *name, *city;
- gfloat latitude, longitude;
- gchar *ret;
-
- name = clock_location_get_name (loc);
- city = clock_location_get_city (loc);
- clock_location_get_coords (loc, &latitude, &longitude);
-
- setlocale (LC_NUMERIC, "POSIX");
-
- ret = g_markup_printf_escaped
- ("<location name=\"%s\" city=\"%s\" timezone=\"%s\" latitude=\"%f\" longitude=\"%f\" code=\"%s\" current=\"%s\"/>",
- name ? name : "",
- city ? city : "",
- clock_location_get_timezone (loc),
- latitude, longitude,
- clock_location_get_weather_code (loc),
- clock_location_is_current (loc) ? "true" : "false");
+ gdouble lat, lon;
- setlocale (LC_NUMERIC, "");
-
- return ret;
+ clock_location_get_coords (loc, &lat, &lon);
+ return g_variant_new ("(ssm(dd))",
+ clock_location_get_name (loc),
+ clock_location_get_weather_code (loc),
+ TRUE, lat, lon);
}
static void
save_cities_store (ClockData *cd)
{
ClockLocation *loc;
- GList *node = cd->locations;
-
- GSList *root = NULL;
- GSList *list = NULL;
-
- while (node) {
- loc = CLOCK_LOCATION (node->data);
- list = g_slist_prepend (list, loc_to_string (loc));
- node = node->next;
- }
-
- list = g_slist_reverse (list);
- panel_applet_gconf_set_list (PANEL_APPLET (cd->applet),
- KEY_CITIES, GCONF_VALUE_STRING, list, NULL);
+ GVariantBuilder builder;
+ GList *list;
- root = list;
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a(ssm(dd))"));
+ list = cd->locations;
while (list) {
- g_free (list->data);
- list = g_slist_next (list);
+ loc = CLOCK_LOCATION (list->data);
+ g_variant_builder_add_value (&builder,
+ location_serialize (loc));
+
+ list = list->next;
}
- g_slist_free (root);
+ g_settings_set_value (cd->applet_settings, "cities",
+ g_variant_builder_end (&builder));
}
static void
@@ -2738,6 +1500,11 @@ run_prefs_edit_save (GtkButton *button, ClockData *cd)
gfloat lat = 0;
gfloat lon = 0;
+ if (loc) {
+ cd->locations = g_list_remove (cd->locations, loc);
+ g_object_unref (loc);
+ }
+
timezone = gweather_timezone_menu_get_tzid (cd->zone_combo);
if (!timezone) {
edit_hide (NULL, cd);
@@ -2749,11 +1516,12 @@ run_prefs_edit_save (GtkButton *button, ClockData *cd)
name = NULL;
gloc = gweather_location_entry_get_location (cd->location_entry);
- if (gloc) {
- city = gweather_location_get_city_name (gloc);
- weather_code = gweather_location_get_code (gloc);
+ if (!gloc) {
+ edit_hide (NULL, cd);
+ return;
}
+ weather_code = gweather_location_get_code (gloc);
if (gweather_location_entry_has_custom_text (cd->location_entry)) {
name = gtk_editable_get_chars (GTK_EDITABLE (cd->location_entry), 0, -1);
}
@@ -2769,27 +1537,14 @@ run_prefs_edit_save (GtkButton *button, ClockData *cd)
lon = -lon;
}
- if (loc) {
- clock_location_set_timezone (loc, timezone);
- clock_location_set_name (loc, name);
- clock_location_set_city (loc, city);
- clock_location_set_coords (loc, lat, lon);
- clock_location_set_weather_code (loc, weather_code);
- } else {
- WeatherPrefs prefs;
-
- prefs.temperature_unit = cd->temperature_unit;
- prefs.speed_unit = cd->speed_unit;
-
- loc = clock_location_new (name, city, timezone, lat, lon, weather_code, &prefs);
- /* has the side-effect of setting the current location if
- * there's none and this one can be considered as a current one
- */
- clock_location_is_current (loc);
-
- cd->locations = g_list_append (cd->locations, loc);
- }
- g_free (name);
+ loc = clock_location_new (cd->world, name, weather_code, TRUE, lat, lon);
+ /* has the side-effect of setting the current location if
+ * there's none and this one can be considered as a current one
+ */
+ clock_location_is_current (loc);
+
+ cd->locations = g_list_append (cd->locations, loc);
+
g_free (city);
/* This will update everything related to locations to take into
@@ -2962,8 +1717,6 @@ prefs_hide (GtkWidget *widget, ClockData *cd)
tree = _clock_get_widget (cd, "cities_list");
gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree)));
-
- refresh_click_timeout_time_only (cd);
}
static gboolean
@@ -3035,7 +1788,7 @@ edit_tree_row (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpoint
ClockLocation *loc;
const char *name;
gchar *tmp;
- gfloat lat, lon;
+ gdouble lat, lon;
/* fill the dialog with this location's data, show it */
GtkWidget *edit_window = _clock_get_widget (cd, "edit-location-window");
@@ -3106,85 +1859,38 @@ run_prefs_locations_edit (GtkButton *unused, ClockData *cd)
static void
set_12hr_format_radio_cb (GtkWidget *widget, ClockData *cd)
{
- const gchar *val;
- ClockFormat format;
+ GDesktopClockFormat format;
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
- format = CLOCK_FORMAT_12;
+ format = G_DESKTOP_CLOCK_FORMAT_12H;
else
- format = CLOCK_FORMAT_24;
-
- val = gconf_enum_to_string (format_type_enum_map, format);
+ format = G_DESKTOP_CLOCK_FORMAT_24H;
- panel_applet_gconf_set_string (PANEL_APPLET (cd->applet),
- KEY_FORMAT, val, NULL);
-}
-
-static void
-temperature_combo_changed (GtkComboBox *combo, ClockData *cd)
-{
- int value;
- int old_value;
- const gchar *str;
-
- value = gtk_combo_box_get_active (combo) + 1;
-
- if (cd->use_temperature_default)
- old_value = TEMP_UNIT_DEFAULT;
- else
- old_value = cd->temperature_unit;
-
- if (value == old_value)
- return;
-
- str = gweather_prefs_temp_enum_to_string (value);
-
- panel_applet_gconf_set_string (PANEL_APPLET (cd->applet),
- KEY_TEMPERATURE_UNIT, str, NULL);
-}
-
-static void
-speed_combo_changed (GtkComboBox *combo, ClockData *cd)
-{
- int value;
- int old_value;
- const gchar *str;
-
- value = gtk_combo_box_get_active (combo) + 1;
-
- if (cd->use_speed_default)
- old_value = SPEED_UNIT_DEFAULT;
- else
- old_value = cd->speed_unit;
-
- if (value == old_value)
- return;
-
- str = gweather_prefs_speed_enum_to_string (value);
-
- panel_applet_gconf_set_string (PANEL_APPLET (cd->applet),
- KEY_SPEED_UNIT, str, NULL);
+ g_settings_set_enum (cd->clock_settings, "clock-format", format);
}
static void
fill_prefs_window (ClockData *cd)
{
- static const int temperatures[] = {
- TEMP_UNIT_DEFAULT,
- TEMP_UNIT_KELVIN,
- TEMP_UNIT_CENTIGRADE,
- TEMP_UNIT_FAHRENHEIT,
- -1
+ struct int_char_pair {
+ int v;
+ const char *c;
};
- static const int speeds[] = {
- SPEED_UNIT_DEFAULT,
- SPEED_UNIT_MS,
- SPEED_UNIT_KPH,
- SPEED_UNIT_MPH,
- SPEED_UNIT_KNOTS,
- SPEED_UNIT_BFT,
- -1
+ static const struct int_char_pair temperatures[] = {
+ { GWEATHER_TEMP_UNIT_KELVIN, N_("Kelvin") },
+ { GWEATHER_TEMP_UNIT_CENTIGRADE, N_("Celsius") },
+ { GWEATHER_TEMP_UNIT_FAHRENHEIT, N_("Fahrenheit") },
+ { -1 }
+ };
+
+ static const struct int_char_pair speeds[] = {
+ { GWEATHER_SPEED_UNIT_MS, N_("Meters per second (m/s)") },
+ { GWEATHER_SPEED_UNIT_KPH, N_("Kilometers per hour (kph)") },
+ { GWEATHER_SPEED_UNIT_MPH, N_("Miles per hour (mph)") },
+ { GWEATHER_SPEED_UNIT_KNOTS, N_("Knots") },
+ { GWEATHER_SPEED_UNIT_BFT, N_("Beaufort scale") },
+ { -1 }
};
GtkWidget *radio_12hr;
@@ -3194,13 +1900,15 @@ fill_prefs_window (ClockData *cd)
GtkTreeViewColumn *col;
GtkListStore *store;
GtkTreeIter iter;
+ GEnumClass *enum_class;
int i;
/* Set the 12 hour / 24 hour widget */
radio_12hr = _clock_get_widget (cd, "12hr_radio");
radio_24hr = _clock_get_widget (cd, "24hr_radio");
- if (cd->format == CLOCK_FORMAT_12)
+ if (g_settings_get_enum (cd->clock_settings, "clock-format") ==
+ G_DESKTOP_CLOCK_FORMAT_12H)
widget = radio_12hr;
else
widget = radio_24hr;
@@ -3212,27 +1920,23 @@ fill_prefs_window (ClockData *cd)
/* Set the "Show Date" checkbox */
widget = _clock_get_widget (cd, "date_check");
- g_signal_connect (widget, "toggled",
- G_CALLBACK (set_show_date_cb), cd);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), cd->showdate);
+ g_settings_bind (cd->clock_settings, "clock-show-date", widget, "active",
+ G_SETTINGS_BIND_DEFAULT);
/* Set the "Show Seconds" checkbox */
widget = _clock_get_widget (cd, "seconds_check");
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), cd->showseconds);
- g_signal_connect (widget, "toggled",
- G_CALLBACK (set_show_seconds_cb), cd);
+ g_settings_bind (cd->clock_settings, "clock-show-seconds", widget, "active",
+ G_SETTINGS_BIND_DEFAULT);
/* Set the "Show weather" checkbox */
widget = _clock_get_widget (cd, "weather_check");
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), cd->show_weather);
- g_signal_connect (widget, "toggled",
- G_CALLBACK (set_show_weather_cb), cd);
+ g_settings_bind (cd->applet_settings, "show-weather", widget, "active",
+ G_SETTINGS_BIND_DEFAULT);
/* Set the "Show temperature" checkbox */
widget = _clock_get_widget (cd, "temperature_check");
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), cd->show_temperature);
- g_signal_connect (widget, "toggled",
- G_CALLBACK (set_show_temperature_cb), cd);
+ g_settings_bind (cd->applet_settings, "show-temperature", widget, "active",
+ G_SETTINGS_BIND_DEFAULT);
/* Fill the Cities list */
widget = _clock_get_widget (cd, "cities_list");
@@ -3253,37 +1957,43 @@ fill_prefs_window (ClockData *cd)
/* Temperature combo */
widget = _clock_get_widget (cd, "temperature_combo");
- store = gtk_list_store_new (1, G_TYPE_STRING);
+ store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
gtk_combo_box_set_model (GTK_COMBO_BOX (widget), GTK_TREE_MODEL (store));
+ gtk_combo_box_set_id_column (GTK_COMBO_BOX (widget), 0);
renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (widget), renderer, TRUE);
- gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (widget), renderer, "text", 0, NULL);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (widget), renderer, "text", 1, NULL);
- for (i = 0; temperatures[i] != -1; i++)
+ enum_class = g_type_class_ref (GWEATHER_TYPE_TEMPERATURE_UNIT);
+ for (i = 0; temperatures[i].v != -1; i++)
gtk_list_store_insert_with_values (store, &iter, -1,
- 0, gweather_prefs_get_temp_display_name (temperatures[i]),
+ 0, g_enum_get_value (enum_class, temperatures[i].v)->value_nick,
+ 1, gettext (temperatures[i].c),
-1);
+ g_type_class_unref (enum_class);
- update_temperature_combo (cd);
- g_signal_connect (widget, "changed",
- G_CALLBACK (temperature_combo_changed), cd);
+ g_settings_bind (cd->weather_settings, "temperature-unit", widget, "active-id",
+ G_SETTINGS_BIND_DEFAULT);
/* Wind speed combo */
widget = _clock_get_widget (cd, "wind_speed_combo");
- store = gtk_list_store_new (1, G_TYPE_STRING);
+ store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
gtk_combo_box_set_model (GTK_COMBO_BOX (widget), GTK_TREE_MODEL (store));
+ gtk_combo_box_set_id_column (GTK_COMBO_BOX (widget), 0);
renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (widget), renderer, TRUE);
- gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (widget), renderer, "text", 0, NULL);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (widget), renderer, "text", 1, NULL);
- for (i = 0; speeds[i] != -1; i++)
+ enum_class = g_type_class_ref (GWEATHER_TYPE_SPEED_UNIT);
+ for (i = 0; speeds[i].v != -1; i++)
gtk_list_store_insert_with_values (store, &iter, -1,
- 0, gweather_prefs_get_speed_display_name (speeds[i]),
+ 0, g_enum_get_value (enum_class, speeds[i].v)->value_nick,
+ 1, gettext (speeds[i].c),
-1);
+ g_type_class_unref (enum_class);
- update_speed_combo (cd);
- g_signal_connect (widget, "changed",
- G_CALLBACK (speed_combo_changed), cd);
+ g_settings_bind (cd->weather_settings, "speed-unit", widget, "active-id",
+ G_SETTINGS_BIND_DEFAULT);
}
static void
@@ -3300,7 +2010,6 @@ ensure_prefs_window_is_created (ClockData *cd)
GtkWidget *location_name_label;
GtkWidget *timezone_label;
GtkTreeSelection *selection;
- GWeatherLocation *world;
if (cd->prefs_window)
return;
@@ -3360,10 +2069,8 @@ ensure_prefs_window_is_created (ClockData *cd)
edit_ok_button = _clock_get_widget (cd, "edit-location-ok-button");
- world = gweather_location_new_world (FALSE);
-
location_box = _clock_get_widget (cd, "edit-location-name-box");
- cd->location_entry = GWEATHER_LOCATION_ENTRY (gweather_location_entry_new (world));
+ cd->location_entry = GWEATHER_LOCATION_ENTRY (gweather_location_entry_new (cd->world));
gtk_widget_show (GTK_WIDGET (cd->location_entry));
gtk_container_add (GTK_CONTAINER (location_box), GTK_WIDGET (cd->location_entry));
gtk_label_set_mnemonic_widget (GTK_LABEL (location_name_label),
@@ -3375,7 +2082,7 @@ ensure_prefs_window_is_created (ClockData *cd)
G_CALLBACK (location_name_changed), cd);
zone_box = _clock_get_widget (cd, "edit-location-timezone-box");
- cd->zone_combo = GWEATHER_TIMEZONE_MENU (gweather_timezone_menu_new (world));
+ cd->zone_combo = GWEATHER_TIMEZONE_MENU (gweather_timezone_menu_new (cd->world));
gtk_widget_show (GTK_WIDGET (cd->zone_combo));
gtk_container_add (GTK_CONTAINER (zone_box), GTK_WIDGET (cd->zone_combo));
gtk_label_set_mnemonic_widget (GTK_LABEL (timezone_label),
@@ -3384,8 +2091,6 @@ ensure_prefs_window_is_created (ClockData *cd)
g_signal_connect (G_OBJECT (cd->zone_combo), "notify::tzid",
G_CALLBACK (location_timezone_changed), cd);
- gweather_location_unref (world);
-
g_signal_connect (G_OBJECT (edit_cancel_button), "clicked",
G_CALLBACK (edit_hide), cd);
@@ -3417,77 +2122,6 @@ display_properties_dialog (ClockData *cd, gboolean start_in_locations_page)
gtk_window_set_screen (GTK_WINDOW (cd->prefs_window),
gtk_widget_get_screen (cd->applet));
gtk_window_present (GTK_WINDOW (cd->prefs_window));
-
- refresh_click_timeout_time_only (cd);
-
- /* FMQ: cd->props was the old preferences window; remove references to it */
- /* FMQ: connect to the Help button by hand; look at properties_response_cb() for the help code */
-#if 0
- /* FMQ: check the code below; replace the proper parts */
- GtkWidget *hbox;
- GtkWidget *vbox;
- GtkWidget *combo;
- GtkWidget *label;
-
- gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("24 hour"));
- gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("UNIX time"));
- gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Internet time"));
-
- gtk_box_pack_start (GTK_BOX (hbox), combo, FALSE, FALSE, 0);
- gtk_widget_show (combo);
-
- cd->custom_hbox = gtk_hbox_new (FALSE, 12);
- gtk_box_pack_start (GTK_BOX (vbox), cd->custom_hbox, TRUE, TRUE, 0);
-
- cd->custom_label = gtk_label_new_with_mnemonic (_("Custom _format:"));
- gtk_label_set_use_markup (GTK_LABEL (cd->custom_label), TRUE);
- gtk_label_set_justify (GTK_LABEL (cd->custom_label),
- GTK_JUSTIFY_LEFT);
- gtk_misc_set_alignment (GTK_MISC (cd->custom_label), 0, 0.5);
- gtk_box_pack_start (GTK_BOX (cd->custom_hbox),
- cd->custom_label,
- FALSE, FALSE, 0);
-
- cd->custom_entry = gtk_entry_new ();
- gtk_box_pack_start (GTK_BOX (cd->custom_hbox),
- cd->custom_entry,
- FALSE, FALSE, 0);
- gtk_entry_set_text (GTK_ENTRY (cd->custom_entry),
- cd->custom_format);
- g_signal_connect (cd->custom_entry, "changed",
- G_CALLBACK (set_custom_format_cb),
- cd);
-
- g_signal_connect (cd->props, "destroy",
- G_CALLBACK (gtk_widget_destroyed),
- &cd->props);
- g_signal_connect (cd->props, "response",
- G_CALLBACK (properties_response_cb),
- cd);
-
- cd->custom_format_shown = FALSE;
- update_properties_for_format (cd, GTK_COMBO_BOX (combo), cd->format);
-
- /* valid values begin from 1 */
- if (cd->can_handle_format_12)
- gtk_combo_box_set_active (GTK_COMBO_BOX (combo),
- cd->format - 1);
- else
- gtk_combo_box_set_active (GTK_COMBO_BOX (combo),
- cd->format - 2);
-
- g_signal_connect (combo, "changed",
- G_CALLBACK (set_format_cb), cd);
-
- /* Now set up the sensitivity based on gconf key writability */
- setup_writability_sensitivity (cd, combo, label, KEY_FORMAT);
- setup_writability_sensitivity (cd, cd->custom_entry, cd->custom_label,
- KEY_CUSTOM_FORMAT);
- setup_writability_sensitivity (cd, cd->showseconds_check, NULL, KEY_SHOW_SECONDS);
- setup_writability_sensitivity (cd, cd->showdate_check, NULL, KEY_SHOW_DATE);
-
- gtk_widget_show (cd->props);
-#endif
}
static void
diff --git a/configure.ac b/configure.ac
index b101019..1058ff8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -75,7 +75,7 @@ TELEPATHY_GLIB_REQUIRED=0.14.0
LIBECAL_REQUIRED=3.5.3
LIBEDATASERVER_REQUIRED=3.5.3
CAIRO_REQUIRED=1.0.0
-GWEATHER_REQUIRED=2.91.0
+GWEATHER_REQUIRED=3.5.1
DBUS_GLIB_REQUIRED=0.80
dnl pkg-config dependency checks
diff --git a/data/Makefile.am b/data/Makefile.am
index c724043..83f82e2 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -3,7 +3,8 @@ SUBDIRS = 16x16 22x22 24x24 32x32 48x48 scalable
gsettings_applets_schemas_in_in = \
org.gnome.gnome-panel.applet.fish.gschema.xml.in.in \
org.gnome.gnome-panel.applet.window-list.gschema.xml.in.in \
- org.gnome.gnome-panel.applet.workspace-switcher.gschema.xml.in.in
+ org.gnome.gnome-panel.applet.workspace-switcher.gschema.xml.in.in \
+ org.gnome.gnome-panel.applet.clock.gschema.xml.in.in
gsettings_panel_schemas_in_in = \
org.gnome.gnome-panel.gschema.xml.in.in \
diff --git a/data/org.gnome.gnome-panel.applet.clock.gschema.xml.in.in b/data/org.gnome.gnome-panel.applet.clock.gschema.xml.in.in
index 12b1899..3e876dc 100644
--- a/data/org.gnome.gnome-panel.applet.clock.gschema.xml.in.in
+++ b/data/org.gnome.gnome-panel.applet.clock.gschema.xml.in.in
@@ -1,25 +1,5 @@
<schemalist gettext-domain="@GETTEXT_PACKAGE@">
<schema id="org.gnome.gnome-panel.applet.clock">
- <key name="format" type="s">
- <default l10n="messages" context="format">''</default>
- <_summary>Hour format</_summary>
- <_description>This key specifies the hour format used by the clock applet. Possible values are "12-hour", "24-hour", "internet", "unix" and "custom". If set to "internet", the clock will display Internet time. The Internet time system divides the day into 1000 ".beats". There are no time zones in this system, so time is the same all over the world. If set to "unix", the clock will display time in seconds since Epoch, i.e. 1970-01-01. If set to "custom", the clock will display time according to the format specified in the custom_format key.</_description>
- </key>
- <key name="custom-format" type="s">
- <default>''</default>
- <_summary>Custom format of the clock</_summary>
- <_description>This key specifies the format used by the clock applet when the format key is set to "custom". You can use conversion specifiers understood by strftime() to obtain a specific format. See the strftime() manual for more information.</_description>
- </key>
- <key name="show-seconds" type="b">
- <default>false</default>
- <_summary>Show time with seconds</_summary>
- <_description>If true, display seconds in time.</_description>
- </key>
- <key name="show-date" type="b">
- <default>true</default>
- <_summary>Show date in clock</_summary>
- <_description>If true, display date in the clock, in addition to time.</_description>
- </key>
<key name="show-tooltip" type="b">
<default>true</default>
<_summary>Show date in tooltip</_summary>
@@ -35,7 +15,7 @@
<_summary>Show temperature in clock</_summary>
<_description>If true, show the temperature next to the weather icon.</_description>
</key>
- <key name="show-week-numbers" type="b">
+ <key name="show-weeks" type="b">
<default>true</default>
<_summary>Show week numbers in calendar</_summary>
<_description>If true, show week numbers in the calendar.</_description>
@@ -65,20 +45,13 @@
<_summary>Expand list of locations</_summary>
<_description>If true, expand the list of locations in the calendar window.</_description>
</key>
- <key name="cities" type="as">
+ <key name="cities" type="a(ssm(dd))">
<default>[]</default>
<_summary>List of locations</_summary>
- <_description>A list of locations to display in the calendar window.</_description>
- </key>
- <key name="temperature-unit" type="s">
- <default>'Default'</default>
- <_summary>Temperature unit</_summary>
- <_description>The unit to use when showing temperatures.</_description>
- </key>
- <key name="speed-unit" type="s">
- <default>'Default'</default>
- <_summary>Speed unit</_summary>
- <_description>The unit to use when showing wind speed.</_description>
+ <_description>
+ A list of locations to display in the calendar window. Each location is a tuple of
+ display name, METAR code and coordinates.
+ </_description>
</key>
</schema>
</schemalist>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]