From e156eaea70d4e06dc3935a067223587de71e2d71 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 30 Aug 2010 16:55:36 -0500 Subject: Create the service proxy and give it a lifecycle --- src/indicator-datetime.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/indicator-datetime.c') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index 7034fb8..a72fe6f 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -29,6 +29,9 @@ with this program. If not, see . #include #include +/* DBus Stuff */ +#include + /* Indicator Stuff */ #include #include @@ -78,6 +81,8 @@ struct _IndicatorDatetimePrivate { IndicatorServiceManager * sm; DbusmenuGtkMenu * menu; + DBusGProxy * service_proxy; + GSettings * settings; }; @@ -220,6 +225,8 @@ indicator_datetime_init (IndicatorDatetime *self) self->priv->show_day = FALSE; self->priv->custom_string = g_strdup(DEFAULT_TIME_FORMAT); + self->priv->service_proxy = NULL; + self->priv->sm = NULL; self->priv->menu = NULL; @@ -259,6 +266,16 @@ 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); + + /* TODO: Add signal handler */ + } + return; } @@ -297,6 +314,11 @@ indicator_datetime_dispose (GObject *object) self->priv->settings = NULL; } + if (self->priv->service_proxy != NULL) { + g_object_unref(self->priv->service_proxy); + self->priv->service_proxy = NULL; + } + G_OBJECT_CLASS (indicator_datetime_parent_class)->dispose (object); return; } -- cgit v1.2.3 From 7890c71cf87b7bc95a34d1203db3fba81fa267b2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 30 Aug 2010 21:42:37 -0500 Subject: Add in a signal handler for the update time signal --- src/indicator-datetime.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/indicator-datetime.c') diff --git a/src/indicator-datetime.c b/src/indicator-datetime.c index a72fe6f..10d1329 100644 --- a/src/indicator-datetime.c +++ b/src/indicator-datetime.c @@ -140,6 +140,7 @@ 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); /* Indicator Module Config */ INDICATOR_SET_VERSION @@ -273,7 +274,12 @@ indicator_datetime_init (IndicatorDatetime *self) SERVICE_OBJ, SERVICE_IFACE); - /* TODO: Add signal handler */ + 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); } return; @@ -556,6 +562,17 @@ 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. */ +static void +update_time (DBusGProxy * proxy, gpointer user_data) +{ + IndicatorDatetime * self = INDICATOR_DATETIME(user_data); + struct tm * ltime = update_label(self); + setup_timer(self, ltime); + return; +} + /* Runs every minute and updates the time */ gboolean timer_func (gpointer user_data) -- cgit v1.2.3