From 22fb11bd6b8b4dca696e16baf6619c50399abd14 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 19 Jun 2013 01:26:32 -0500 Subject: in the gnome control center datetime panel, use g_bus_watch_name() to see if com.canonical.indicator.datetime is available. --- src/datetime-prefs.c | 55 ++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 25 deletions(-) (limited to 'src/datetime-prefs.c') diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c index d7f0def..ef0a553 100644 --- a/src/datetime-prefs.c +++ b/src/datetime-prefs.c @@ -58,6 +58,7 @@ struct _IndicatorDatetimePanel struct _IndicatorDatetimePanelPrivate { + guint name_watch_id; GtkBuilder * builder; GDBusProxy * proxy; GtkWidget * auto_radio; @@ -286,33 +287,30 @@ proxy_ready (GObject *object, GAsyncResult *res, IndicatorDatetimePanel * self) } } +#define WIG(name) GTK_WIDGET (gtk_builder_get_object(self->priv->builder, name)) + static void -service_name_owner_changed (GDBusProxy * proxy, GParamSpec *pspec, gpointer user_data) +set_show_clock_check_sensitive (IndicatorDatetimePanel * self, + gboolean sensitive) { - GtkWidget * widget = GTK_WIDGET (user_data); - gchar * owner = g_dbus_proxy_get_name_owner (proxy); - - gtk_widget_set_sensitive (widget, (owner != NULL)); - - g_free (owner); + gtk_widget_set_sensitive (WIG("showClockCheck"), sensitive); } static void -service_proxy_ready (GObject *object, GAsyncResult *res, gpointer user_data) +on_bus_name_appeared (GDBusConnection * connection G_GNUC_UNUSED, + const char * name G_GNUC_UNUSED, + const char * name_owner, + gpointer self) { - GError * error = NULL; - - GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish (res, &error); - - if (error != NULL) { - g_critical("Could not grab DBus proxy for indicator-datetime-service: %s", error->message); - g_error_free(error); - return; - } + set_show_clock_check_sensitive (self, name_owner && *name_owner); +} - /* And now, do initial proxy configuration */ - g_signal_connect (proxy, "notify::g-name-owner", G_CALLBACK (service_name_owner_changed), user_data); - service_name_owner_changed (proxy, NULL, user_data); +static void +on_bus_name_vanished (GDBusConnection * connection G_GNUC_UNUSED, + const char * name G_GNUC_UNUSED, + gpointer self) +{ + set_show_clock_check_sensitive (self, FALSE); } static gboolean @@ -656,7 +654,6 @@ indicator_datetime_panel_init (IndicatorDatetimePanel * self) GSettings * conf = g_settings_new (SETTINGS_INTERFACE); -#define WIG(name) GTK_WIDGET (gtk_builder_get_object (self->priv->builder, name)) /* Add policykit button */ GtkWidget * polkit_button = gtk_lock_button_new (NULL); @@ -745,10 +742,13 @@ indicator_datetime_panel_init (IndicatorDatetimePanel * self) but that doesn't yet claim a name on the bus. Presumably the service would have been started by any such indicator, so this will at least tell us if there *was* a datetime module run this session. */ - g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, NULL, - SERVICE_NAME, SERVICE_OBJ, SERVICE_IFACE, - NULL, (GAsyncReadyCallback)service_proxy_ready, - WIG ("showClockCheck")); + self->priv->name_watch_id = g_bus_watch_name (G_BUS_TYPE_SESSION, + BUS_NAME, + G_BUS_NAME_WATCHER_FLAGS_NONE, + on_bus_name_appeared, + on_bus_name_vanished, + self, + NULL); #undef WIG @@ -772,6 +772,11 @@ indicator_datetime_panel_dispose (GObject * object) priv->loc_dlg = NULL; } + if (priv->name_watch_id != 0) { + g_bus_unwatch_name (priv->name_watch_id); + priv->name_watch_id = 0; + } + if (priv->save_time_id) { g_source_remove (priv->save_time_id); priv->save_time_id = 0; -- cgit v1.2.3