Merge lp:~ted/indicator-datetime/date-and-update into lp:indicator-datetime/0.3

Proposed by Ted Gould
Status: Merged
Merged at revision: 19
Proposed branch: lp:~ted/indicator-datetime/date-and-update
Merge into: lp:indicator-datetime/0.3
Diff against target: 479 lines (+313/-6)
8 files modified
.bzrignore (+2/-0)
src/Makefile.am (+29/-2)
src/datetime-interface.c (+98/-0)
src/datetime-interface.h (+55/-0)
src/datetime-service.c (+77/-1)
src/datetime-service.xml (+11/-0)
src/dbus-shared.h (+3/-3)
src/indicator-datetime.c (+38/-0)
To merge this branch: bzr merge lp:~ted/indicator-datetime/date-and-update
Reviewer Review Type Date Requested Status
Cody Russell (community) Approve
Aurélien Gâteau (community) Needs Fixing
Review via email: mp+34152@code.launchpad.net

Description of the change

Updates updates updates.

This makes the indicator update on two cases. The day changing (for a date change) and timezone changing. It fixes bugs, I need to find the numbers :)

To post a comment you must log in.
Revision history for this message
Aurélien Gâteau (agateau) wrote :

There are conflict marks in src/Makefile.am and src/indicator-datetime.c

review: Needs Fixing
Revision history for this message
Ted Gould (ted) wrote :

Merged in trunk and solved conflicts in r31

31. By Ted Gould

Updating to trunk

Revision history for this message
Cody Russell (bratsche) wrote :

Looks fine to me.

Revision history for this message
Cody Russell (bratsche) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2010-07-14 16:37:01 +0000
3+++ .bzrignore 2010-08-31 12:59:38 +0000
4@@ -7,3 +7,5 @@
5 indicator-datetime-[0-9].[0-9].[0-9].tar.gz
6 data/indicator-datetime.service
7 data/org.ayatana.indicator.datetime.gschema.valid
8+src/datetime-service-client.h
9+src/datetime-service-server.h
10
11=== modified file 'src/Makefile.am'
12--- src/Makefile.am 2010-07-22 19:13:36 +0000
13+++ src/Makefile.am 2010-08-31 12:59:38 +0000
14@@ -2,6 +2,9 @@
15 libexec_PROGRAMS = indicator-datetime-service
16
17 indicator_datetime_service_SOURCES = \
18+ datetime-interface.c \
19+ datetime-interface.h \
20+ datetime-server.h \
21 calendar-menu-item.c \
22 calendar-menu-item.h \
23 datetime-service.c \
24@@ -9,13 +12,15 @@
25 indicator_datetime_service_CFLAGS = \
26 -Wall \
27 -Werror \
28- $(INDICATOR_CFLAGS)
29+ $(INDICATOR_CFLAGS) \
30+ -DTIMEZONE_FILE="\"/etc/timezone\""
31 indicator_datetime_service_LDADD = \
32 $(INDICATOR_LIBS)
33
34 datetimelibdir = $(INDICATORDIR)
35 datetimelib_LTLIBRARIES = libdatetime.la
36 libdatetime_la_SOURCES = \
37+ datetime-client.h \
38 dbus-shared.h \
39 indicator-datetime.c
40 libdatetime_la_CFLAGS = \
41@@ -27,4 +32,26 @@
42 -module \
43 -avoid-version
44
45-EXTRA_DIST = $(libdatetime_la_SOURCES)
46+datetime-service-client.h: $(srcdir)/datetime-service.xml
47+ dbus-binding-tool \
48+ --prefix=_datetime_service_client \
49+ --mode=glib-client \
50+ --output=datetime-service-client.h \
51+ $(srcdir)/datetime-service.xml
52+
53+datetime-service-server.h: $(srcdir)/datetime-service.xml
54+ dbus-binding-tool \
55+ --prefix=_datetime_service_server \
56+ --mode=glib-server \
57+ --output=datetime-service-server.h \
58+ $(srcdir)/datetime-service.xml
59+
60+BUILT_SOURCES = \
61+ datetime-service-client.h \
62+ datetime-service-server.h
63+
64+CLEANFILES = \
65+ $(BUILT_SOURCES)
66+
67+EXTRA_DIST = \
68+ datetime-service.xml
69
70=== added file 'src/datetime-interface.c'
71--- src/datetime-interface.c 1970-01-01 00:00:00 +0000
72+++ src/datetime-interface.c 2010-08-31 12:59:38 +0000
73@@ -0,0 +1,98 @@
74+/*
75+An indicator to time and date related information in the menubar.
76+
77+Copyright 2010 Canonical Ltd.
78+
79+Authors:
80+ Ted Gould <ted@canonical.com>
81+
82+This program is free software: you can redistribute it and/or modify it
83+under the terms of the GNU General Public License version 3, as published
84+by the Free Software Foundation.
85+
86+This program is distributed in the hope that it will be useful, but
87+WITHOUT ANY WARRANTY; without even the implied warranties of
88+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
89+PURPOSE. See the GNU General Public License for more details.
90+
91+You should have received a copy of the GNU General Public License along
92+with this program. If not, see <http://www.gnu.org/licenses/>.
93+*/
94+
95+#ifdef HAVE_CONFIG_H
96+#include "config.h"
97+#endif
98+
99+#include "datetime-interface.h"
100+#include "datetime-service-server.h"
101+#include "dbus-shared.h"
102+
103+enum {
104+ UPDATE_TIME,
105+ LAST_SIGNAL
106+};
107+
108+static guint signals[LAST_SIGNAL] = { 0 };
109+
110+static void datetime_interface_class_init (DatetimeInterfaceClass *klass);
111+static void datetime_interface_init (DatetimeInterface *self);
112+static void datetime_interface_dispose (GObject *object);
113+static void datetime_interface_finalize (GObject *object);
114+
115+G_DEFINE_TYPE (DatetimeInterface, datetime_interface, G_TYPE_OBJECT);
116+
117+static void
118+datetime_interface_class_init (DatetimeInterfaceClass *klass)
119+{
120+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
121+
122+ object_class->dispose = datetime_interface_dispose;
123+ object_class->finalize = datetime_interface_finalize;
124+
125+ signals[UPDATE_TIME] = g_signal_new("update-time",
126+ G_TYPE_FROM_CLASS(klass),
127+ G_SIGNAL_RUN_LAST,
128+ G_STRUCT_OFFSET (DatetimeInterfaceClass, update_time),
129+ NULL, NULL,
130+ g_cclosure_marshal_VOID__VOID,
131+ G_TYPE_NONE, 0, G_TYPE_NONE);
132+
133+ dbus_g_object_type_install_info(DATETIME_INTERFACE_TYPE, &dbus_glib__datetime_service_server_object_info);
134+
135+ return;
136+}
137+
138+static void
139+datetime_interface_init (DatetimeInterface *self)
140+{
141+ DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
142+ dbus_g_connection_register_g_object(connection,
143+ SERVICE_OBJ,
144+ G_OBJECT(self));
145+
146+ return;
147+}
148+
149+static void
150+datetime_interface_dispose (GObject *object)
151+{
152+
153+ G_OBJECT_CLASS (datetime_interface_parent_class)->dispose (object);
154+ return;
155+}
156+
157+static void
158+datetime_interface_finalize (GObject *object)
159+{
160+
161+ G_OBJECT_CLASS (datetime_interface_parent_class)->finalize (object);
162+ return;
163+}
164+
165+void
166+datetime_interface_update (DatetimeInterface *self)
167+{
168+ g_return_if_fail(IS_DATETIME_INTERFACE(self));
169+ g_signal_emit(G_OBJECT(self), signals[UPDATE_TIME], 0, TRUE);
170+ return;
171+}
172
173=== added file 'src/datetime-interface.h'
174--- src/datetime-interface.h 1970-01-01 00:00:00 +0000
175+++ src/datetime-interface.h 2010-08-31 12:59:38 +0000
176@@ -0,0 +1,55 @@
177+/*
178+An indicator to time and date related information in the menubar.
179+
180+Copyright 2010 Canonical Ltd.
181+
182+Authors:
183+ Ted Gould <ted@canonical.com>
184+
185+This program is free software: you can redistribute it and/or modify it
186+under the terms of the GNU General Public License version 3, as published
187+by the Free Software Foundation.
188+
189+This program is distributed in the hope that it will be useful, but
190+WITHOUT ANY WARRANTY; without even the implied warranties of
191+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
192+PURPOSE. See the GNU General Public License for more details.
193+
194+You should have received a copy of the GNU General Public License along
195+with this program. If not, see <http://www.gnu.org/licenses/>.
196+*/
197+
198+#ifndef __DATETIME_INTERFACE_H__
199+#define __DATETIME_INTERFACE_H__
200+
201+#include <glib.h>
202+#include <glib-object.h>
203+
204+G_BEGIN_DECLS
205+
206+#define DATETIME_INTERFACE_TYPE (datetime_interface_get_type ())
207+#define DATETIME_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DATETIME_INTERFACE_TYPE, DatetimeInterface))
208+#define DATETIME_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DATETIME_INTERFACE_TYPE, DatetimeInterfaceClass))
209+#define IS_DATETIME_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DATETIME_INTERFACE_TYPE))
210+#define IS_DATETIME_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DATETIME_INTERFACE_TYPE))
211+#define DATETIME_INTERFACE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DATETIME_INTERFACE_TYPE, DatetimeInterfaceClass))
212+
213+typedef struct _DatetimeInterface DatetimeInterface;
214+typedef struct _DatetimeInterfaceClass DatetimeInterfaceClass;
215+
216+struct _DatetimeInterfaceClass {
217+ GObjectClass parent_class;
218+
219+ void (*update_time) (void);
220+};
221+
222+struct _DatetimeInterface {
223+ GObject parent;
224+};
225+
226+GType datetime_interface_get_type (void);
227+void datetime_interface_update (DatetimeInterface *self);
228+
229+G_END_DECLS
230+
231+#endif
232
233=== modified file 'src/datetime-service.c'
234--- src/datetime-service.c 2010-07-22 19:14:47 +0000
235+++ src/datetime-service.c 2010-08-31 12:59:38 +0000
236@@ -23,17 +23,22 @@
237 #include <libindicator/indicator-service.h>
238
239 #include <glib/gi18n.h>
240+#include <gio/gio.h>
241
242 #include <libdbusmenu-glib/server.h>
243 #include <libdbusmenu-glib/client.h>
244 #include <libdbusmenu-glib/menuitem.h>
245
246+#include "datetime-interface.h"
247 #include "dbus-shared.h"
248
249+static void setup_timer (void);
250+
251 static IndicatorService * service = NULL;
252 static GMainLoop * mainloop = NULL;
253 static DbusmenuServer * server = NULL;
254 static DbusmenuMenuitem * root = NULL;
255+static DatetimeInterface * dbus = NULL;
256
257 /* Global Items */
258 static DbusmenuMenuitem * date = NULL;
259@@ -136,7 +141,6 @@
260 dbusmenu_menuitem_child_append(root, date);
261
262 g_idle_add(update_datetime, NULL);
263- /* TODO: Set up updating daily */
264 }
265
266 if (calendar == NULL) {
267@@ -166,6 +170,68 @@
268 return;
269 }
270
271+/* Run when the timezone file changes */
272+static void
273+timezone_changed (GFileMonitor * monitor, GFile * file, GFile * otherfile, GFileMonitorEvent event, gpointer user_data)
274+{
275+ datetime_interface_update(DATETIME_INTERFACE(user_data));
276+ update_datetime(NULL);
277+ setup_timer();
278+ return;
279+}
280+
281+/* Set up monitoring the timezone file */
282+static void
283+build_timezone (DatetimeInterface * dbus)
284+{
285+ GFile * timezonefile = g_file_new_for_path(TIMEZONE_FILE);
286+ GFileMonitor * monitor = g_file_monitor_file(timezonefile, G_FILE_MONITOR_NONE, NULL, NULL);
287+ if (monitor != NULL) {
288+ g_signal_connect(G_OBJECT(monitor), "changed", G_CALLBACK(timezone_changed), dbus);
289+ g_debug("Monitoring timezone file: '" TIMEZONE_FILE "'");
290+ } else {
291+ g_warning("Unable to monitor timezone file: '" TIMEZONE_FILE "'");
292+ }
293+ return;
294+}
295+
296+/* Source ID for the timer */
297+static guint timer = 0;
298+
299+/* Execute at a given time, update and setup a new
300+ timer to go again. */
301+static gboolean
302+timer_func (gpointer user_data)
303+{
304+ timer = 0;
305+ /* Reset up each time to reduce error */
306+ setup_timer();
307+ update_datetime(NULL);
308+ return FALSE;
309+}
310+
311+/* Sets up the time to launch the timer to update the
312+ date in the datetime entry */
313+static void
314+setup_timer (void)
315+{
316+ if (timer != 0) {
317+ g_source_remove(timer);
318+ timer = 0;
319+ }
320+
321+ time_t t;
322+ t = time(NULL);
323+ struct tm * ltime = localtime(&t);
324+
325+ timer = g_timeout_add_seconds(((23 - ltime->tm_hour) * 60 * 60) +
326+ ((59 - ltime->tm_min) * 60) +
327+ ((60 - ltime->tm_sec)) + 60 /* one minute past */,
328+ timer_func, NULL);
329+
330+ return;
331+}
332+
333 /* Repsonds to the service object saying it's time to shutdown.
334 It stops the mainloop. */
335 static void
336@@ -198,9 +264,19 @@
337 dbusmenu_server_set_root(server, root);
338 build_menus(root);
339
340+ /* Setup dbus interface */
341+ dbus = g_object_new(DATETIME_INTERFACE_TYPE, NULL);
342+
343+ /* Setup timezone watch */
344+ build_timezone(dbus);
345+
346+ /* Setup the timer */
347+ setup_timer();
348+
349 mainloop = g_main_loop_new(NULL, FALSE);
350 g_main_loop_run(mainloop);
351
352+ g_object_unref(G_OBJECT(dbus));
353 g_object_unref(G_OBJECT(service));
354 g_object_unref(G_OBJECT(server));
355 g_object_unref(G_OBJECT(root));
356
357=== added file 'src/datetime-service.xml'
358--- src/datetime-service.xml 1970-01-01 00:00:00 +0000
359+++ src/datetime-service.xml 2010-08-31 12:59:38 +0000
360@@ -0,0 +1,11 @@
361+<?xml version="1.0" encoding="UTF-8"?>
362+<node name="/">
363+ <interface name="org.ayatana.indicator.datetime.service">
364+
365+<!-- Methods -->
366+
367+<!-- Signals -->
368+ <signal name="UpdateTime" />
369+
370+ </interface>
371+</node>
372
373=== modified file 'src/dbus-shared.h'
374--- src/dbus-shared.h 2010-07-22 19:13:36 +0000
375+++ src/dbus-shared.h 2010-08-31 12:59:38 +0000
376@@ -20,9 +20,9 @@
377 */
378
379
380-#define SERVICE_NAME "org.ayatana.indicator.datetime"
381-#define SERVICE_IFACE "org.ayatana.indicator.datetime.service"
382-#define SERVICE_OBJ "/org/ayatana/indicator/datetime/service"
383+#define SERVICE_NAME "org.ayatana.indicator.datetime"
384+#define SERVICE_IFACE "org.ayatana.indicator.datetime.service"
385+#define SERVICE_OBJ "/org/ayatana/indicator/datetime/service"
386 #define SERVICE_VERSION 1
387
388 #define MENU_OBJ "/org/ayatana/indicator/datetime/menu"
389
390=== modified file 'src/indicator-datetime.c'
391--- src/indicator-datetime.c 2010-07-22 19:13:36 +0000
392+++ src/indicator-datetime.c 2010-08-31 12:59:38 +0000
393@@ -29,6 +29,9 @@
394 #include <glib/gi18n-lib.h>
395 #include <gio/gio.h>
396
397+/* DBus Stuff */
398+#include <dbus/dbus-glib.h>
399+
400 /* Indicator Stuff */
401 #include <libindicator/indicator.h>
402 #include <libindicator/indicator-object.h>
403@@ -79,6 +82,7 @@
404 IndicatorServiceManager * sm;
405 DbusmenuGtkMenu * menu;
406
407+ DBusGProxy * service_proxy;
408 IdoCalendarMenuItem *ido_calendar;
409
410 GSettings * settings;
411@@ -138,6 +142,7 @@
412 static struct tm * update_label (IndicatorDatetime * io);
413 static void guess_label_size (IndicatorDatetime * self);
414 static void setup_timer (IndicatorDatetime * self, struct tm * ltime);
415+static void update_time (DBusGProxy * proxy, gpointer user_data);
416
417 /* Indicator Module Config */
418 INDICATOR_SET_VERSION
419@@ -223,6 +228,8 @@
420 self->priv->show_day = FALSE;
421 self->priv->custom_string = g_strdup(DEFAULT_TIME_FORMAT);
422
423+ self->priv->service_proxy = NULL;
424+
425 self->priv->sm = NULL;
426 self->priv->menu = NULL;
427
428@@ -262,6 +269,21 @@
429
430 self->priv->sm = indicator_service_manager_new_version(SERVICE_NAME, SERVICE_VERSION);
431
432+ DBusGConnection * session = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
433+ if (session != NULL) {
434+ self->priv->service_proxy = dbus_g_proxy_new_for_name(session,
435+ SERVICE_NAME,
436+ SERVICE_OBJ,
437+ SERVICE_IFACE);
438+
439+ dbus_g_proxy_add_signal(self->priv->service_proxy, "UpdateTime", G_TYPE_INVALID);
440+ dbus_g_proxy_connect_signal(self->priv->service_proxy,
441+ "UpdateTime",
442+ G_CALLBACK(update_time),
443+ self,
444+ NULL);
445+ }
446+
447 return;
448 }
449
450@@ -300,6 +322,11 @@
451 self->priv->settings = NULL;
452 }
453
454+ if (self->priv->service_proxy != NULL) {
455+ g_object_unref(self->priv->service_proxy);
456+ self->priv->service_proxy = NULL;
457+ }
458+
459 G_OBJECT_CLASS (indicator_datetime_parent_class)->dispose (object);
460 return;
461 }
462@@ -537,6 +564,17 @@
463 return ltime;
464 }
465
466+/* Recieves the signal from the service that we should update
467+ the time right now. Usually from a timezone switch. */
468+static void
469+update_time (DBusGProxy * proxy, gpointer user_data)
470+{
471+ IndicatorDatetime * self = INDICATOR_DATETIME(user_data);
472+ struct tm * ltime = update_label(self);
473+ setup_timer(self, ltime);
474+ return;
475+}
476+
477 /* Runs every minute and updates the time */
478 gboolean
479 timer_func (gpointer user_data)

Subscribers

People subscribed via source and target branches

to all changes: