From 4cab2afb2670c941accf38428cab81cf281aa63b Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 15 Dec 2010 11:55:27 -0500 Subject: use LC_TIME to look up date-related translations --- src/indicator-datetime.c | 93 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 68 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index acdc340..83e32d0 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -23,6 +23,10 @@ with this program. If not, see . #include "config.h" #endif +#include +#include +#include + /* GStuff */ #include #include @@ -119,8 +123,14 @@ enum { SETTINGS_TIME_CUSTOM = 3 }; -#define DEFAULT_TIME_12_FORMAT "%l:%M %p" -#define DEFAULT_TIME_24_FORMAT "%H:%M" +/* TRANSLATORS: A format string for the strftime function for + a clock showing 12-hour time without seconds. */ +#define DEFAULT_TIME_12_FORMAT N_("%l:%M %p") + +/* TRANSLATORS: A format string for the strftime function for + a clock showing 24-hour time without seconds. */ +#define DEFAULT_TIME_24_FORMAT N_("%H:%M") + #define DEFAULT_TIME_FORMAT DEFAULT_TIME_12_FORMAT #define INDICATOR_DATETIME_GET_PRIVATE(o) \ @@ -840,6 +850,53 @@ style_changed (GtkWidget * widget, GtkStyle * oldstyle, gpointer data) return; } +/* Translate msg according to the locale specified by LC_TIME */ +static char * +T_(const char *msg) +{ + /* General strategy here is to make sure LANGUAGE is empty (since that + trumps all LC_* vars) and then to temporarily swap LC_TIME and + LC_MESSAGES. Then have gettext translate msg. + + We strdup the strings because the setlocale & *env functions do not + guarantee anything about the storage used for the string, and thus + the string may not be portably safe after multiple calls. + + Note that while you might think g_dcgettext would do the trick here, + that actually looks in /usr/share/locale/XX/LC_TIME, not the + LC_MESSAGES directory, so we won't find any translation there. + */ + char *message_locale = g_strdup(setlocale(LC_MESSAGES, NULL)); + char *time_locale = g_strdup(setlocale(LC_TIME, NULL)); + char *language = g_strdup(g_getenv("LANGUAGE")); + char *rv; + g_unsetenv("LANGUAGE"); + setlocale(LC_MESSAGES, time_locale); + + /* Get the LC_TIME version */ + rv = _(msg); + + /* Put everything back the way it was */ + setlocale(LC_MESSAGES, message_locale); + g_setenv("LANGUAGE", language, 1); + g_free(message_locale); + g_free(time_locale); + g_free(language); + return rv; +} + +static gboolean +is_locale_12h() +{ + static const char *formats_24h[] = {"%H", "%R", "%T", "%OH", "%k", NULL}; + const char *t_fmt = nl_langinfo(T_FMT); + int i; + for (i = 0; formats_24h[i]; ++i) + if (strstr(t_fmt, formats_24h[i])) + return FALSE; + return TRUE; +} + /* Tries to figure out what our format string should be. Lots of translator comments in here. */ static gchar * @@ -852,17 +909,7 @@ generate_format_string (IndicatorDatetime * self) gboolean twelvehour = TRUE; if (self->priv->time_mode == SETTINGS_TIME_LOCALE) { - /* TRANSLATORS: This string is used to determine the default - clock style for your locale. If it is the string '12' then - the default will be a 12-hour clock using AM/PM string. If - it is '24' then it will be a 24-hour clock. Users may over - ride this setting so it's still important to translate the - other strings no matter how this is set. */ - const gchar * locale_default = _("12"); - - if (g_strcmp0(locale_default, "24") == 0) { - twelvehour = FALSE; - } + twelvehour = is_locale_12h(); } else if (self->priv->time_mode == SETTINGS_TIME_24_HOUR) { twelvehour = FALSE; } @@ -872,21 +919,17 @@ generate_format_string (IndicatorDatetime * self) if (self->priv->show_seconds) { /* TRANSLATORS: A format string for the strftime function for a clock showing 12-hour time with seconds. */ - time_string = _("%l:%M:%S %p"); + time_string = T_("%l:%M:%S %p"); } else { - /* TRANSLATORS: A format string for the strftime function for - a clock showing 12-hour time. */ - time_string = _(DEFAULT_TIME_12_FORMAT); + time_string = T_(DEFAULT_TIME_12_FORMAT); } } else { if (self->priv->show_seconds) { /* TRANSLATORS: A format string for the strftime function for a clock showing 24-hour time with seconds. */ - time_string = _("%H:%M:%S"); + time_string = T_("%H:%M:%S"); } else { - /* TRANSLATORS: A format string for the strftime function for - a clock showing 24-hour time. */ - time_string = _(DEFAULT_TIME_24_FORMAT); + time_string = T_(DEFAULT_TIME_24_FORMAT); } } @@ -903,15 +946,15 @@ generate_format_string (IndicatorDatetime * self) if (self->priv->show_date && self->priv->show_day) { /* TRANSLATORS: This is a format string passed to strftime to represent the day of the week, the month and the day of the month. */ - date_string = _("%a %b %e"); + date_string = T_("%a %b %e"); } else if (self->priv->show_date) { /* TRANSLATORS: This is a format string passed to strftime to represent the month and the day of the month. */ - date_string = _("%b %e"); + date_string = T_("%b %e"); } else if (self->priv->show_day) { /* TRANSLATORS: This is a format string passed to strftime to represent the day of the week. */ - date_string = _("%a"); + date_string = T_("%a"); } /* Check point, we should have a date string */ @@ -920,7 +963,7 @@ generate_format_string (IndicatorDatetime * self) /* TRANSLATORS: This is a format string passed to strftime to combine the date and the time. The value of "%s, %s" would result in a string like this in US English 12-hour time: 'Fri Jul 16, 11:50 AM' */ - return g_strdup_printf(_("%s, %s"), date_string, time_string); + return g_strdup_printf(T_("%s, %s"), date_string, time_string); } static gboolean -- cgit v1.2.3 From 0a7a68160740fdacc7a62b7c201c21f2845a4518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 23 Dec 2010 00:22:36 +0100 Subject: Check if the custom time format string shows seconds If it happens, update the label each second, not only every minute. So now you can also put any custom string showing seconds, getting correctly updated. --- src/indicator-datetime.c | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index acdc340..75b857d 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -75,6 +75,7 @@ struct _IndicatorDatetimePrivate { gboolean show_date; gboolean show_day; gchar * custom_string; + gboolean custom_show_seconds; guint idle_measure; gint max_width; @@ -126,6 +127,18 @@ enum { #define INDICATOR_DATETIME_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_DATETIME_TYPE, IndicatorDatetimePrivate)) +enum { + STRFTIME_MASK_NONE = 0, /* Hours or minutes as we always test those */ + STRFTIME_MASK_SECONDS = 1 << 0, /* Seconds count */ + STRFTIME_MASK_AMPM = 1 << 1, /* AM/PM counts */ + STRFTIME_MASK_WEEK = 1 << 2, /* Day of the week maters (Sat, Sun, etc.) */ + STRFTIME_MASK_DAY = 1 << 3, /* Day of the month counts (Feb 1st) */ + STRFTIME_MASK_MONTH = 1 << 4, /* Which month matters */ + STRFTIME_MASK_YEAR = 1 << 5, /* Which year matters */ + /* Last entry, combines all previous */ + STRFTIME_MASK_ALL = (STRFTIME_MASK_SECONDS | STRFTIME_MASK_AMPM | STRFTIME_MASK_WEEK | STRFTIME_MASK_DAY | STRFTIME_MASK_MONTH | STRFTIME_MASK_YEAR) +}; + GType indicator_datetime_get_type (void); static void indicator_datetime_class_init (IndicatorDatetimeClass *klass); @@ -143,6 +156,7 @@ static struct tm * update_label (IndicatorDatetime * io); static void guess_label_size (IndicatorDatetime * self); static void setup_timer (IndicatorDatetime * self, struct tm * ltime); static void update_time (DBusGProxy * proxy, gpointer user_data); +static gint generate_strftime_bitmask (const char *time_str); /* Indicator Module Config */ INDICATOR_SET_VERSION @@ -225,6 +239,7 @@ indicator_datetime_init (IndicatorDatetime *self) self->priv->show_date = FALSE; self->priv->show_day = FALSE; self->priv->custom_string = g_strdup(DEFAULT_TIME_FORMAT); + self->priv->custom_show_seconds = FALSE; self->priv->time_string = generate_format_string(self); @@ -404,6 +419,7 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec if (newval != self->priv->time_mode) { update = TRUE; self->priv->time_mode = newval; + setup_timer(self, NULL); } break; } @@ -440,6 +456,8 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec self->priv->custom_string = NULL; } self->priv->custom_string = g_strdup(newstr); + gint time_mask = generate_strftime_bitmask(newstr); + self->priv->custom_show_seconds = (time_mask & STRFTIME_MASK_SECONDS); if (self->priv->time_mode == SETTINGS_TIME_CUSTOM) { update = TRUE; setup_timer(self, NULL); @@ -595,7 +613,8 @@ setup_timer (IndicatorDatetime * self, struct tm * ltime) self->priv->timer = 0; } - if (self->priv->show_seconds) { + if (self->priv->show_seconds || + (self->priv->time_mode == SETTINGS_TIME_CUSTOM && self->priv->custom_show_seconds)) { self->priv->timer = g_timeout_add_seconds(1, timer_func, self); } else { if (ltime == NULL) { @@ -634,18 +653,6 @@ struct _strftime_type_t { gint mask; }; -enum { - STRFTIME_MASK_NONE = 0, /* Hours or minutes as we always test those */ - STRFTIME_MASK_SECONDS = 1 << 0, /* Seconds count */ - STRFTIME_MASK_AMPM = 1 << 1, /* AM/PM counts */ - STRFTIME_MASK_WEEK = 1 << 2, /* Day of the week maters (Sat, Sun, etc.) */ - STRFTIME_MASK_DAY = 1 << 3, /* Day of the month counts (Feb 1st) */ - STRFTIME_MASK_MONTH = 1 << 4, /* Which month matters */ - STRFTIME_MASK_YEAR = 1 << 5, /* Which year matters */ - /* Last entry, combines all previous */ - STRFTIME_MASK_ALL = (STRFTIME_MASK_SECONDS | STRFTIME_MASK_AMPM | STRFTIME_MASK_WEEK | STRFTIME_MASK_DAY | STRFTIME_MASK_MONTH | STRFTIME_MASK_YEAR) -}; - /* A table taken from the man page of strftime to what the different characters can effect. These are worst case in that we need to test the length based on all these things to ensure that we have @@ -691,21 +698,21 @@ const static strftime_type_t strftime_type[] = { ensure that we can figure out which of the things we need to check in determining the length. */ static gint -generate_strftime_bitmask (IndicatorDatetime * self) +generate_strftime_bitmask (const char *time_str) { gint retval = 0; - glong strlength = g_utf8_strlen(self->priv->time_string, -1); + glong strlength = g_utf8_strlen(time_str, -1); gint i; - g_debug("Evaluating bitmask for '%s'", self->priv->time_string); + g_debug("Evaluating bitmask for '%s'", time_str); for (i = 0; i < strlength; i++) { - if (self->priv->time_string[i] == '%' && i + 1 < strlength) { - gchar evalchar = self->priv->time_string[i + 1]; + if (time_str[i] == '%' && i + 1 < strlength) { + gchar evalchar = time_str[i + 1]; /* If we're using alternate formats we need to skip those characters */ if (evalchar == 'E' || evalchar == 'O') { if (i + 2 < strlength) { - evalchar = self->priv->time_string[i + 2]; + evalchar = time_str[i + 2]; } else { continue; } @@ -799,7 +806,7 @@ guess_label_size (IndicatorDatetime * self) GtkStyle * style = gtk_widget_get_style(GTK_WIDGET(self->priv->label)); PangoContext * context = gtk_widget_get_pango_context(GTK_WIDGET(self->priv->label)); gint * max_width = &(self->priv->max_width); - gint posibilitymask = generate_strftime_bitmask(self); + gint posibilitymask = generate_strftime_bitmask(self->priv->time_string); /* Build the array of possibilities that we want to test */ GArray * timevals = g_array_new(FALSE, TRUE, sizeof(struct tm)); -- cgit v1.2.3 From 0c85942be07ac17ede7fe4499db60733a3dbf801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 23 Dec 2010 00:24:51 +0100 Subject: Set label justification to center, and connect to "screen-changed" signal Update gravity on screen change! --- src/indicator-datetime.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 75b857d..5c5f6fd 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -847,6 +847,22 @@ style_changed (GtkWidget * widget, GtkStyle * oldstyle, gpointer data) return; } + +static void +update_text_gravity (GtkWidget *widget, GdkScreen *previous_screen, gpointer data) +{ + IndicatorDatetime * self = INDICATOR_DATETIME(data); + if (self->priv->label == NULL) return; + + PangoLayout *layout; + PangoContext *context; + + layout = gtk_label_get_layout (GTK_LABEL(self->priv->label)); + context = pango_layout_get_context(layout); + pango_context_set_base_gravity(context, PANGO_GRAVITY_AUTO); +} + + /* Tries to figure out what our format string should be. Lots of translator comments in here. */ static gchar * @@ -966,8 +982,10 @@ get_label (IndicatorObject * io) /* If there's not a label, we'll build ourselves one */ if (self->priv->label == NULL) { self->priv->label = GTK_LABEL(gtk_label_new("Time")); + gtk_label_set_justify (GTK_LABEL(self->priv->label), GTK_JUSTIFY_CENTER); g_object_ref(G_OBJECT(self->priv->label)); g_signal_connect(G_OBJECT(self->priv->label), "style-set", G_CALLBACK(style_changed), self); + g_signal_connect(G_OBJECT(self->priv->label), "screen-changed", G_CALLBACK(update_text_gravity), self); guess_label_size(self); update_label(self); gtk_widget_show(GTK_WIDGET(self->priv->label)); -- cgit v1.2.3 From 0ce656f73bb9426e97f3d1785c92571b6cb01671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 23 Dec 2010 00:26:53 +0100 Subject: Reset the label max width when guessing it. This should reduce the indicator size when a smaller (custom) text has been added. --- src/indicator-datetime.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 5c5f6fd..5bf20e9 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -808,6 +808,9 @@ guess_label_size (IndicatorDatetime * self) gint * max_width = &(self->priv->max_width); gint posibilitymask = generate_strftime_bitmask(self->priv->time_string); + /* Reset max width */ + *max_width = 0; + /* Build the array of possibilities that we want to test */ GArray * timevals = g_array_new(FALSE, TRUE, sizeof(struct tm)); build_timeval_array(timevals, posibilitymask); -- cgit v1.2.3 From 1231e651a4e628b9fa7aedc28fa5345faf3b6876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 23 Dec 2010 00:32:36 +0100 Subject: Add markup support to clock label This adds exactly the same markup support to the indicator-datetime label respect to the clock gnome panel applet. Now formats like the ones below can be correctly set: %I:%M %p %a %d %b%n%I:%M %p %a %I:%M %p --- src/indicator-datetime.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 5bf20e9..c325f49 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -557,9 +557,10 @@ update_label (IndicatorDatetime * io) if (self->priv->label == NULL) return NULL; - gchar longstr[128]; + gchar longstr[256]; time_t t; struct tm *ltime; + gboolean use_markup; t = time(NULL); ltime = localtime(&t); @@ -569,10 +570,18 @@ update_label (IndicatorDatetime * io) return NULL; } - strftime(longstr, 128, self->priv->time_string, ltime); + strftime(longstr, 256, self->priv->time_string, ltime); gchar * utf8 = g_locale_to_utf8(longstr, -1, NULL, NULL, NULL); - gtk_label_set_label(self->priv->label, utf8); + + if (pango_parse_markup(utf8, -1, 0, NULL, NULL, NULL, NULL)) + use_markup = TRUE; + + if (use_markup) + gtk_label_set_markup(self->priv->label, utf8); + else + gtk_label_set_text(self->priv->label, utf8); + g_free(utf8); if (self->priv->idle_measure == 0) { @@ -636,7 +645,12 @@ static gint measure_string (GtkStyle * style, PangoContext * context, const gchar * string) { PangoLayout * layout = pango_layout_new(context); - pango_layout_set_text(layout, string, -1); + + if (pango_parse_markup(string, -1, 0, NULL, NULL, NULL, NULL)) + pango_layout_set_markup(layout, string, -1); + else + pango_layout_set_text(layout, string, -1); + pango_layout_set_font_description(layout, style->font_desc); gint width; @@ -818,9 +832,9 @@ guess_label_size (IndicatorDatetime * self) g_debug("Checking against %d posible times", timevals->len); gint check_time; for (check_time = 0; check_time < timevals->len; check_time++) { - gchar longstr[128]; - strftime(longstr, 128, self->priv->time_string, &(g_array_index(timevals, struct tm, check_time))); - + gchar longstr[256]; + strftime(longstr, 256, self->priv->time_string, &(g_array_index(timevals, struct tm, check_time))); + gchar * utf8 = g_locale_to_utf8(longstr, -1, NULL, NULL, NULL); gint length = measure_string(style, context, utf8); g_free(utf8); -- cgit v1.2.3 From 9402dbecd6db1b004a0cb5e894260106b1a5f537 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 6 Jan 2011 23:03:06 -0600 Subject: A couple of slight cleanups --- src/indicator-datetime.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 83e32d0..718bebc 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -878,23 +878,29 @@ T_(const char *msg) /* Put everything back the way it was */ setlocale(LC_MESSAGES, message_locale); - g_setenv("LANGUAGE", language, 1); + g_setenv("LANGUAGE", language, TRUE); g_free(message_locale); g_free(time_locale); g_free(language); return rv; } +/* Check the system locale setting to see if the format is 24-hour + time or 12-hour time */ static gboolean is_locale_12h() { static const char *formats_24h[] = {"%H", "%R", "%T", "%OH", "%k", NULL}; - const char *t_fmt = nl_langinfo(T_FMT); - int i; - for (i = 0; formats_24h[i]; ++i) - if (strstr(t_fmt, formats_24h[i])) - return FALSE; - return TRUE; + const char *t_fmt = nl_langinfo(T_FMT); + int i; + + for (i = 0; formats_24h[i]; ++i) { + if (strstr(t_fmt, formats_24h[i])) { + return FALSE; + } + } + + return TRUE; } /* Tries to figure out what our format string should be. Lots -- cgit v1.2.3 From 4132432b89cedf30cae89042a296ac299cef2161 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Mon, 10 Jan 2011 15:16:49 -0600 Subject: first, untested pass at gdbus port --- src/Makefile.am | 29 ++++++------ src/datetime-interface.c | 119 ++++++++++++++++++++++++++++++++++++++++++++--- src/datetime-interface.h | 6 ++- src/indicator-datetime.c | 88 ++++++++++++++++++++++++++--------- 4 files changed, 196 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index ebe466d..5e3625d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,7 +4,7 @@ libexec_PROGRAMS = indicator-datetime-service indicator_datetime_service_SOURCES = \ datetime-interface.c \ datetime-interface.h \ - datetime-service-server.h \ + gen-datetime-service.xml.c \ calendar-menu-item.c \ calendar-menu-item.h \ datetime-service.c \ @@ -20,7 +20,7 @@ indicator_datetime_service_LDADD = \ datetimelibdir = $(INDICATORDIR) datetimelib_LTLIBRARIES = libdatetime.la libdatetime_la_SOURCES = \ - datetime-service-client.h \ + gen-datetime-service.xml.h \ dbus-shared.h \ indicator-datetime.c libdatetime_la_CFLAGS = \ @@ -32,23 +32,20 @@ libdatetime_la_LDFLAGS = \ -module \ -avoid-version -datetime-service-client.h: $(srcdir)/datetime-service.xml - dbus-binding-tool \ - --prefix=_datetime_service_client \ - --mode=glib-client \ - --output=datetime-service-client.h \ - $(srcdir)/datetime-service.xml +gen-%.xml.c: %.xml + @echo "Building $@ from $<" + @echo "const char * _$(subst -,_,$(subst .,_,$(basename $<))) = " > $@ + @sed -e "s:\":\\\\\":g" -e s:^:\": -e s:\$$:\\\\n\": $< >> $@ + @echo ";" >> $@ -datetime-service-server.h: $(srcdir)/datetime-service.xml - dbus-binding-tool \ - --prefix=_datetime_service_server \ - --mode=glib-server \ - --output=datetime-service-server.h \ - $(srcdir)/datetime-service.xml +gen-%.xml.h: %.xml + @echo "Building $@ from $<" + @echo "extern const char * _$(subst -,_,$(subst .,_,$(basename $<)));" > $@ BUILT_SOURCES = \ - datetime-service-client.h \ - datetime-service-server.h + gen-datetime-service.xml.c \ + gen-datetime-service.xml.h + CLEANFILES = \ $(BUILT_SOURCES) diff --git a/src/datetime-interface.c b/src/datetime-interface.c index c58c5af..2bb56b0 100644 --- a/src/datetime-interface.c +++ b/src/datetime-interface.c @@ -23,21 +23,44 @@ with this program. If not, see . #include "config.h" #endif +#include + #include "datetime-interface.h" -#include "datetime-service-server.h" +#include "gen-datetime-service.xml.h" #include "dbus-shared.h" +/** + DatetimeInterfacePrivate: + @dbus_registration: The handle for this object being registered + on dbus. + + Structure to define the memory for the private area + of the datetime interface instance. +*/ +struct _DatetimeInterfacePrivate { + GDBusConnection * bus; + GCancellable * bus_cancel; + guint dbus_registration; +}; + +#define DATETIME_INTERFACE_GET_PRIVATE(o) (DATETIME_INTERFACE(o)->priv) + enum { UPDATE_TIME, LAST_SIGNAL }; +/* GDBus Stuff */ +static GDBusNodeInfo * node_info = NULL; +static GDBusInterfaceInfo * interface_info = NULL; + static guint signals[LAST_SIGNAL] = { 0 }; static void datetime_interface_class_init (DatetimeInterfaceClass *klass); static void datetime_interface_init (DatetimeInterface *self); static void datetime_interface_dispose (GObject *object); static void datetime_interface_finalize (GObject *object); +static void bus_get_cb (GObject * object, GAsyncResult * res, gpointer user_data); G_DEFINE_TYPE (DatetimeInterface, datetime_interface, G_TYPE_OBJECT); @@ -46,6 +69,8 @@ datetime_interface_class_init (DatetimeInterfaceClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + g_type_class_add_private (klass, sizeof (DatetimeInterfacePrivate)); + object_class->dispose = datetime_interface_dispose; object_class->finalize = datetime_interface_finalize; @@ -57,7 +82,24 @@ datetime_interface_class_init (DatetimeInterfaceClass *klass) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0, G_TYPE_NONE); - dbus_g_object_type_install_info(DATETIME_INTERFACE_TYPE, &dbus_glib__datetime_service_server_object_info); + /* Setting up the DBus interfaces */ + if (node_info == NULL) { + GError * error = NULL; + + node_info = g_dbus_node_info_new_for_xml(_datetime_service, &error); + if (error != NULL) { + g_error("Unable to parse Datetime Service Interface description: %s", error->message); + g_error_free(error); + } + } + + if (interface_info == NULL) { + interface_info = g_dbus_node_info_lookup_interface(node_info, SERVICE_IFACE); + + if (interface_info == NULL) { + g_error("Unable to find interface '" SERVICE_IFACE "'"); + } + } return; } @@ -65,17 +107,82 @@ datetime_interface_class_init (DatetimeInterfaceClass *klass) static void datetime_interface_init (DatetimeInterface *self) { - DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); - dbus_g_connection_register_g_object(connection, - SERVICE_OBJ, - G_OBJECT(self)); + self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, DATETIME_INTERFACE_TYPE, DatetimeInterfacePrivate); + + self->priv->bus = NULL; + self->priv->bus_cancel = NULL; + self->priv->dbus_registration = 0; + + self->priv->bus_cancel = g_cancellable_new(); + g_bus_get(G_BUS_TYPE_SESSION, + self->priv->bus_cancel, + bus_get_cb, + self); return; } +static void +bus_get_cb (GObject * object, GAsyncResult * res, gpointer user_data) +{ + GError * error = NULL; + GDBusConnection * connection = g_bus_get_finish(res, &error); + + if (error != NULL) { + g_error("OMG! Unable to get a connection to DBus: %s", error->message); + g_error_free(error); + return; + } + + DatetimeInterfacePrivate * priv = DATETIME_INTERFACE_GET_PRIVATE(user_data); + + g_warn_if_fail(priv->bus == NULL); + priv->bus = connection; + + if (priv->bus_cancel != NULL) { + g_object_unref(priv->bus_cancel); + priv->bus_cancel = NULL; + } + + /* Now register our object on our new connection */ + priv->dbus_registration = g_dbus_connection_register_object(connection, + SERVICE_OBJ, + interface_info, + NULL, + user_data, + NULL, + &error); + + if (error != NULL) { + g_error("Unable to register the object to DBus: %s", error->message); + g_error_free(error); + return; + } + + return; +} + static void datetime_interface_dispose (GObject *object) { + DatetimeInterfacePrivate * priv = DATETIME_INTERFACE_GET_PRIVATE(object); + + if (priv->dbus_registration != 0) { + g_dbus_connection_unregister_object(priv->bus, priv->dbus_registration); + /* Don't care if it fails, there's nothing we can do */ + priv->dbus_registration = 0; + } + + if (priv->bus != NULL) { + g_object_unref(priv->bus); + priv->bus = NULL; + } + + if (priv->bus_cancel != NULL) { + g_cancellable_cancel(priv->bus_cancel); + g_object_unref(priv->bus_cancel); + priv->bus_cancel = NULL; + } G_OBJECT_CLASS (datetime_interface_parent_class)->dispose (object); return; diff --git a/src/datetime-interface.h b/src/datetime-interface.h index 60ead1b..ae85605 100644 --- a/src/datetime-interface.h +++ b/src/datetime-interface.h @@ -34,8 +34,9 @@ G_BEGIN_DECLS #define IS_DATETIME_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DATETIME_INTERFACE_TYPE)) #define DATETIME_INTERFACE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DATETIME_INTERFACE_TYPE, DatetimeInterfaceClass)) -typedef struct _DatetimeInterface DatetimeInterface; -typedef struct _DatetimeInterfaceClass DatetimeInterfaceClass; +typedef struct _DatetimeInterface DatetimeInterface; +typedef struct _DatetimeInterfacePrivate DatetimeInterfacePrivate; +typedef struct _DatetimeInterfaceClass DatetimeInterfaceClass; struct _DatetimeInterfaceClass { GObjectClass parent_class; @@ -45,6 +46,7 @@ struct _DatetimeInterfaceClass { struct _DatetimeInterface { GObject parent; + DatetimeInterfacePrivate * priv; }; GType datetime_interface_get_type (void); diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 718bebc..981f2c0 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -33,9 +33,6 @@ with this program. If not, see . #include #include -/* DBus Stuff */ -#include - /* Indicator Stuff */ #include #include @@ -86,7 +83,8 @@ struct _IndicatorDatetimePrivate { IndicatorServiceManager * sm; DbusmenuGtkMenu * menu; - DBusGProxy * service_proxy; + GCancellable * service_proxy_cancel; + GDBusProxy * service_proxy; IdoCalendarMenuItem *ido_calendar; GSettings * settings; @@ -152,7 +150,9 @@ static gchar * generate_format_string (IndicatorDatetime * self); static struct tm * update_label (IndicatorDatetime * io); static void guess_label_size (IndicatorDatetime * self); static void setup_timer (IndicatorDatetime * self, struct tm * ltime); -static void update_time (DBusGProxy * proxy, gpointer user_data); +static void update_time (IndicatorDatetime * self); +static void receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant parameters, gpointer user_data); +static void service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data); /* Indicator Module Config */ INDICATOR_SET_VERSION @@ -279,21 +279,53 @@ indicator_datetime_init (IndicatorDatetime *self) self->priv->sm = indicator_service_manager_new_version(SERVICE_NAME, SERVICE_VERSION); - DBusGConnection * session = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); - if (session != NULL) { - self->priv->service_proxy = dbus_g_proxy_new_for_name(session, - SERVICE_NAME, - SERVICE_OBJ, - SERVICE_IFACE); - - dbus_g_proxy_add_signal(self->priv->service_proxy, "UpdateTime", G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->service_proxy, - "UpdateTime", - G_CALLBACK(update_time), - self, - NULL); + self->priv->service_proxy_cancel = g_cancellable_new(); + + g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + SERVICE_NAME, + SERVICE_OBJ, + SERVICE_IFACE, + self->priv->service_proxy_cancel, + service_proxy_cb, + self); + + return; +} + +/* Callback from trying to create the proxy for the serivce, this + could include starting the service. Sometime it'll fail and + we'll try to start that dang service again! */ +static void +service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) +{ + GError * error = NULL; + + IndicatorDatetime * self = INDICATOR_DATETIME(user_data); + g_return_if_fail(self != NULL); + + GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error); + + IndicatorDatetimePrivate * priv = INDICATOR_DATETIME_GET_PRIVATE(self); + + if (priv->service_proxy_cancel != NULL) { + g_object_unref(priv->service_proxy_cancel); + priv->service_proxy_cancel = NULL; + } + + if (error != NULL) { + g_warning("Could not grab DBus proxy for %s: %s", SERVICE_NAME, error->message); + g_error_free(error); + return; } + /* Okay, we're good to grab the proxy at this point, we're + sure that it's ours. */ + priv->service_proxy = proxy; + + g_signal_connect(proxy, "g-signal", G_CALLBACK(receive_signal), self); + return; } @@ -574,17 +606,29 @@ update_label (IndicatorDatetime * io) return ltime; } -/* Recieves the signal from the service that we should update - the time right now. Usually from a timezone switch. */ +/* Update the time right now. Usually the result of a timezone switch. */ static void -update_time (DBusGProxy * proxy, gpointer user_data) +update_time (IndicatorDatetime * self) { - IndicatorDatetime * self = INDICATOR_DATETIME(user_data); struct tm * ltime = update_label(self); setup_timer(self, ltime); return; } +/* Receives all signals from the service, routed to the appropriate functions */ +static void +receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, + GVariant parameters, gpointer user_data) +{ + IndicatorDatetime * self = INDICATOR_DATETIME(user_data); + + if (g_strcmp0(signal_name, "UpdateTime") == 0) { + update_time(self); + } + + return; +} + /* Runs every minute and updates the time */ gboolean timer_func (gpointer user_data) -- cgit v1.2.3 From cef82e736ede231269bfc3d90571d2555c03a7d9 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Mon, 10 Jan 2011 16:20:55 -0600 Subject: fix signal emission; g-signal receiver parameter definition --- src/datetime-interface.c | 36 +++++++++++++++++++----------------- src/indicator-datetime.c | 6 +++--- 2 files changed, 22 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/datetime-interface.c b/src/datetime-interface.c index 2bb56b0..5939061 100644 --- a/src/datetime-interface.c +++ b/src/datetime-interface.c @@ -45,17 +45,10 @@ struct _DatetimeInterfacePrivate { #define DATETIME_INTERFACE_GET_PRIVATE(o) (DATETIME_INTERFACE(o)->priv) -enum { - UPDATE_TIME, - LAST_SIGNAL -}; - /* GDBus Stuff */ static GDBusNodeInfo * node_info = NULL; static GDBusInterfaceInfo * interface_info = NULL; -static guint signals[LAST_SIGNAL] = { 0 }; - static void datetime_interface_class_init (DatetimeInterfaceClass *klass); static void datetime_interface_init (DatetimeInterface *self); static void datetime_interface_dispose (GObject *object); @@ -74,14 +67,6 @@ datetime_interface_class_init (DatetimeInterfaceClass *klass) object_class->dispose = datetime_interface_dispose; object_class->finalize = datetime_interface_finalize; - signals[UPDATE_TIME] = g_signal_new("update-time", - G_TYPE_FROM_CLASS(klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (DatetimeInterfaceClass, update_time), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0, G_TYPE_NONE); - /* Setting up the DBus interfaces */ if (node_info == NULL) { GError * error = NULL; @@ -145,7 +130,7 @@ bus_get_cb (GObject * object, GAsyncResult * res, gpointer user_data) } /* Now register our object on our new connection */ - priv->dbus_registration = g_dbus_connection_register_object(connection, + priv->dbus_registration = g_dbus_connection_register_object(priv->bus, SERVICE_OBJ, interface_info, NULL, @@ -200,6 +185,23 @@ void datetime_interface_update (DatetimeInterface *self) { g_return_if_fail(IS_DATETIME_INTERFACE(self)); - g_signal_emit(G_OBJECT(self), signals[UPDATE_TIME], 0, TRUE); + + DatetimeInterfacePrivate * priv = DATETIME_INTERFACE_GET_PRIVATE(self); + GError * error = NULL; + + g_dbus_connection_emit_signal (priv->bus, + NULL, + SERVICE_OBJ, + SERVICE_IFACE, + "UpdateTime", + NULL, + &error); + + if (error != NULL) { + g_error("Unable to send UpdateTime signal: %s", error->message); + g_error_free(error); + return; + } + return; } diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 981f2c0..7e0b62d 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -151,7 +151,7 @@ static struct tm * update_label (IndicatorDatetime * io); static void guess_label_size (IndicatorDatetime * self); static void setup_timer (IndicatorDatetime * self, struct tm * ltime); static void update_time (IndicatorDatetime * self); -static void receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant parameters, gpointer user_data); +static void receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data); static void service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data); /* Indicator Module Config */ @@ -315,7 +315,7 @@ service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) } if (error != NULL) { - g_warning("Could not grab DBus proxy for %s: %s", SERVICE_NAME, error->message); + g_error("Could not grab DBus proxy for %s: %s", SERVICE_NAME, error->message); g_error_free(error); return; } @@ -618,7 +618,7 @@ update_time (IndicatorDatetime * self) /* Receives all signals from the service, routed to the appropriate functions */ static void receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, - GVariant parameters, gpointer user_data) + GVariant * parameters, gpointer user_data) { IndicatorDatetime * self = INDICATOR_DATETIME(user_data); -- cgit v1.2.3 From 9c6c6273c3d53e1581e176d8fe5fe50932ad592c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 17 Jan 2011 11:42:47 -0600 Subject: Switching dbus names and interfaces --- src/datetime-service.xml | 2 +- src/dbus-shared.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/datetime-service.xml b/src/datetime-service.xml index 1207ebb..eda064f 100644 --- a/src/datetime-service.xml +++ b/src/datetime-service.xml @@ -1,6 +1,6 @@ - + diff --git a/src/dbus-shared.h b/src/dbus-shared.h index 357beb5..e6dc241 100644 --- a/src/dbus-shared.h +++ b/src/dbus-shared.h @@ -20,12 +20,12 @@ with this program. If not, see . */ -#define SERVICE_NAME "org.ayatana.indicator.datetime" -#define SERVICE_IFACE "org.ayatana.indicator.datetime.service" -#define SERVICE_OBJ "/org/ayatana/indicator/datetime/service" +#define SERVICE_NAME "com.canonical.indicator.datetime" +#define SERVICE_IFACE "com.canonical.indicator.datetime.service" +#define SERVICE_OBJ "/com/canonical/indicator/datetime/service" #define SERVICE_VERSION 1 -#define MENU_OBJ "/org/ayatana/indicator/datetime/menu" +#define MENU_OBJ "/com/canonical/indicator/datetime/menu" #define DBUSMENU_CALENDAR_MENUITEM_TYPE "x-canonical-calendar-item" -- cgit v1.2.3 From b52833fecbe711340e9854691bbd5af1f0fda46c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 17 Jan 2011 11:48:18 -0600 Subject: Changing the GSettings interface --- src/indicator-datetime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index c3b7e4a..377cf17 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -108,7 +108,7 @@ enum { #define PROP_SHOW_DATE_S "show-date" #define PROP_CUSTOM_TIME_FORMAT_S "custom-time-format" -#define SETTINGS_INTERFACE "org.ayatana.indicator.datetime" +#define SETTINGS_INTERFACE "com.canonical.indicator.datetime" #define SETTINGS_TIME_FORMAT_S "time-format" #define SETTINGS_SHOW_SECONDS_S "show-seconds" #define SETTINGS_SHOW_DAY_S "show-day" -- cgit v1.2.3 From 5d546ac1d21e12538076d136b899b92c937cb479 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 17 Jan 2011 11:59:06 -0600 Subject: Adding a log domain --- src/Makefile.am | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 5e3625d..7a290c6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,7 +13,8 @@ indicator_datetime_service_CFLAGS = \ -Wall \ -Werror \ $(SERVICE_CFLAGS) \ - -DTIMEZONE_FILE="\"/etc/timezone\"" + -DTIMEZONE_FILE="\"/etc/timezone\"" \ + -DG_LOG_DOMAIN=\"Indicator-Datetime\" indicator_datetime_service_LDADD = \ $(SERVICE_LIBS) @@ -25,7 +26,8 @@ libdatetime_la_SOURCES = \ indicator-datetime.c libdatetime_la_CFLAGS = \ $(INDICATOR_CFLAGS) \ - -Wall -Werror + -Wall -Werror \ + -DG_LOG_DOMAIN=\"Indicator-Datetime\" libdatetime_la_LIBADD = \ $(INDICATOR_LIBS) libdatetime_la_LDFLAGS = \ -- cgit v1.2.3 From 2fdb33981e70fa164dbcb098bad1b7231e9698d8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 27 Jan 2011 16:34:06 -0600 Subject: Fixing type callback prototype and bumping dbusmenu version --- src/indicator-datetime.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 377cf17..c386300 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -1058,7 +1058,8 @@ generate_format_string (IndicatorDatetime * self) static gboolean new_calendar_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, - DbusmenuClient * client) + DbusmenuClient * client, + gpointer user_data) { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); -- cgit v1.2.3 From ac1f538f4529019f9142b226f2da7957dcaac57a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 31 Jan 2011 21:12:12 -0600 Subject: Make no proxy a warning --- src/indicator-datetime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index c386300..521c9e9 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -330,7 +330,7 @@ service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data) } if (error != NULL) { - g_error("Could not grab DBus proxy for %s: %s", SERVICE_NAME, error->message); + g_warning("Could not grab DBus proxy for %s: %s", SERVICE_NAME, error->message); g_error_free(error); return; } -- cgit v1.2.3 From 10fb9c744b01451f037466c941f018257a674878 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 31 Jan 2011 21:29:05 -0600 Subject: Make sure to clear the address when clients change. --- src/datetime-service.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src') diff --git a/src/datetime-service.c b/src/datetime-service.c index 8a31940..04a808a 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -393,6 +393,8 @@ geo_create_address (GeoclueMasterClient * master, GeoclueAddress * address, GErr return; } + g_warn_if_fail(geo_address == NULL); + g_debug("Created Geoclue Address"); geo_address = address; g_object_ref(G_OBJECT(geo_address)); @@ -420,6 +422,13 @@ geo_client_invalid (GeoclueMasterClient * client, gpointer user_data) { g_warning("Master client invalid, rebuilding."); + /* Client changes we can assume the address is invalid */ + if (geo_address != NULL) { + g_object_unref(G_OBJECT(geo_address)); + } + geo_address = NULL; + + /* And our master client is invalid */ if (geo_master != NULL) { g_object_unref(G_OBJECT(geo_master)); } @@ -470,6 +479,12 @@ geo_create_client (GeoclueMaster * master, GeoclueMasterClient * client, gchar * geo_master = client; g_object_ref(G_OBJECT(geo_master)); + /* New client, make sure we don't have an address hanging on */ + if (geo_address != NULL) { + g_object_unref(G_OBJECT(geo_address)); + } + geo_address = NULL; + geoclue_master_client_set_requirements_async(geo_master, GEOCLUE_ACCURACY_LEVEL_REGION, 0, -- cgit v1.2.3 From 004f46321f23d5967f698dd1201bc19b8a422dbf Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 1 Feb 2011 09:35:04 -0600 Subject: Adding more comments --- src/datetime-service.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/datetime-service.c b/src/datetime-service.c index 04a808a..db887a9 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -393,6 +393,9 @@ geo_create_address (GeoclueMasterClient * master, GeoclueAddress * address, GErr return; } + /* We shouldn't have created a new address if we already had one + so this is a warning. But, it really is only a mem-leak so we + don't need to error out. */ g_warn_if_fail(geo_address == NULL); g_debug("Created Geoclue Address"); @@ -422,7 +425,8 @@ geo_client_invalid (GeoclueMasterClient * client, gpointer user_data) { g_warning("Master client invalid, rebuilding."); - /* Client changes we can assume the address is invalid */ + /* Client changes we can assume the address is now invalid so we + need to unreference the one we had. */ if (geo_address != NULL) { g_object_unref(G_OBJECT(geo_address)); } @@ -453,6 +457,8 @@ geo_address_change (GeoclueMasterClient * client, gchar * a, gchar * b, gchar * { g_warning("Address provider changed. Let's change"); + /* If the address is supposed to have changed we need to drop the old + address before starting to get the new one. */ if (geo_address != NULL) { g_object_unref(G_OBJECT(geo_address)); } -- cgit v1.2.3 From 96ab5fe4d0dc4d8221e05116f6babcaf66cf2379 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 1 Feb 2011 09:39:28 -0600 Subject: Put the geo_address clean up in a small helper function. --- src/datetime-service.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/datetime-service.c b/src/datetime-service.c index db887a9..2a9ccdb 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -384,6 +384,23 @@ geo_address_cb (GeoclueAddress * address, int timestamp, GHashTable * addy_data, return; } +/* Clean up the reference we kept to the address and make sure to + drop the signals incase someone else has one. */ +static void +geo_address_clean (void) +{ + if (geo_address == NULL) { + return; + } + + g_signal_handlers_disconnect_by_func(G_OBJECT(geo_address), geo_address_cb, NULL); + g_object_unref(G_OBJECT(geo_address)); + + geo_address = NULL; + + return; +} + /* Callback from creating the address */ static void geo_create_address (GeoclueMasterClient * master, GeoclueAddress * address, GError * error, gpointer user_data) @@ -397,6 +414,7 @@ geo_create_address (GeoclueMasterClient * master, GeoclueAddress * address, GErr so this is a warning. But, it really is only a mem-leak so we don't need to error out. */ g_warn_if_fail(geo_address == NULL); + geo_address_clean(); g_debug("Created Geoclue Address"); geo_address = address; @@ -427,10 +445,7 @@ geo_client_invalid (GeoclueMasterClient * client, gpointer user_data) /* Client changes we can assume the address is now invalid so we need to unreference the one we had. */ - if (geo_address != NULL) { - g_object_unref(G_OBJECT(geo_address)); - } - geo_address = NULL; + geo_address_clean(); /* And our master client is invalid */ if (geo_master != NULL) { @@ -459,10 +474,7 @@ geo_address_change (GeoclueMasterClient * client, gchar * a, gchar * b, gchar * /* If the address is supposed to have changed we need to drop the old address before starting to get the new one. */ - if (geo_address != NULL) { - g_object_unref(G_OBJECT(geo_address)); - } - geo_address = NULL; + geo_address_clean(); geoclue_master_client_create_address_async(geo_master, geo_create_address, NULL); @@ -486,10 +498,7 @@ geo_create_client (GeoclueMaster * master, GeoclueMasterClient * client, gchar * g_object_ref(G_OBJECT(geo_master)); /* New client, make sure we don't have an address hanging on */ - if (geo_address != NULL) { - g_object_unref(G_OBJECT(geo_address)); - } - geo_address = NULL; + geo_address_clean(); geoclue_master_client_set_requirements_async(geo_master, GEOCLUE_ACCURACY_LEVEL_REGION, -- cgit v1.2.3 From 5de989fb1e270fbc9381b432e49df6790f985258 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 1 Feb 2011 09:48:29 -0600 Subject: Changing the clean up of the client to be in a function and drop the signals as well. --- src/datetime-service.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/datetime-service.c b/src/datetime-service.c index 2a9ccdb..59308dd 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -401,6 +401,24 @@ geo_address_clean (void) return; } +/* Clean up and remove all signal handlers from the client as we + unreference it as well. */ +static void +geo_client_clean (void) +{ + if (geo_master == NULL) { + return; + } + + g_signal_handlers_disconnect_by_func(G_OBJECT(geo_master), geo_client_invalid, NULL); + g_signal_handlers_disconnect_by_func(G_OBJECT(geo_master), geo_address_change, NULL); + g_object_unref(G_OBJECT(geo_master)); + + geo_master = NULL; + + return; +} + /* Callback from creating the address */ static void geo_create_address (GeoclueMasterClient * master, GeoclueAddress * address, GError * error, gpointer user_data) @@ -448,10 +466,7 @@ geo_client_invalid (GeoclueMasterClient * client, gpointer user_data) geo_address_clean(); /* And our master client is invalid */ - if (geo_master != NULL) { - g_object_unref(G_OBJECT(geo_master)); - } - geo_master = NULL; + geo_client_clean(); GeoclueMaster * master = geoclue_master_get_default(); geoclue_master_create_client_async(master, geo_create_client, NULL); -- cgit v1.2.3 From e5e4415f3629352b5bc294acfec9593228d068ee Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 1 Feb 2011 09:49:45 -0600 Subject: Putting the clear functions in shutdown so the objects get cleaned up nicely there as well. --- src/datetime-service.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/datetime-service.c b/src/datetime-service.c index 59308dd..04e3d6b 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -582,6 +582,9 @@ main (int argc, char ** argv) mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); + geo_address_clean(); + geo_client_clean(); + g_object_unref(G_OBJECT(master)); g_object_unref(G_OBJECT(dbus)); g_object_unref(G_OBJECT(service)); -- cgit v1.2.3 From c67f50916bd8cfe718ceed73ee95912d898df3d1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 1 Feb 2011 09:52:10 -0600 Subject: Forgot to bring up the prototypes. --- src/datetime-service.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/datetime-service.c b/src/datetime-service.c index 04e3d6b..9f795d1 100644 --- a/src/datetime-service.c +++ b/src/datetime-service.c @@ -40,6 +40,8 @@ with this program. If not, see . static void geo_create_client (GeoclueMaster * master, GeoclueMasterClient * client, gchar * path, GError * error, gpointer user_data); static void setup_timer (void); +static void geo_client_invalid (GeoclueMasterClient * client, gpointer user_data); +static void geo_address_change (GeoclueMasterClient * client, gchar * a, gchar * b, gchar * c, gchar * d, gpointer user_data); static IndicatorService * service = NULL; static GMainLoop * mainloop = NULL; -- cgit v1.2.3