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
=== modified file '.bzrignore'
--- .bzrignore 2010-07-14 16:37:01 +0000
+++ .bzrignore 2010-08-31 12:59:38 +0000
@@ -7,3 +7,5 @@
7indicator-datetime-[0-9].[0-9].[0-9].tar.gz7indicator-datetime-[0-9].[0-9].[0-9].tar.gz
8data/indicator-datetime.service8data/indicator-datetime.service
9data/org.ayatana.indicator.datetime.gschema.valid9data/org.ayatana.indicator.datetime.gschema.valid
10src/datetime-service-client.h
11src/datetime-service-server.h
1012
=== modified file 'src/Makefile.am'
--- src/Makefile.am 2010-07-22 19:13:36 +0000
+++ src/Makefile.am 2010-08-31 12:59:38 +0000
@@ -2,6 +2,9 @@
2libexec_PROGRAMS = indicator-datetime-service2libexec_PROGRAMS = indicator-datetime-service
33
4indicator_datetime_service_SOURCES = \4indicator_datetime_service_SOURCES = \
5 datetime-interface.c \
6 datetime-interface.h \
7 datetime-server.h \
5 calendar-menu-item.c \8 calendar-menu-item.c \
6 calendar-menu-item.h \9 calendar-menu-item.h \
7 datetime-service.c \10 datetime-service.c \
@@ -9,13 +12,15 @@
9indicator_datetime_service_CFLAGS = \12indicator_datetime_service_CFLAGS = \
10 -Wall \13 -Wall \
11 -Werror \14 -Werror \
12 $(INDICATOR_CFLAGS)15 $(INDICATOR_CFLAGS) \
16 -DTIMEZONE_FILE="\"/etc/timezone\""
13indicator_datetime_service_LDADD = \17indicator_datetime_service_LDADD = \
14 $(INDICATOR_LIBS)18 $(INDICATOR_LIBS)
1519
16datetimelibdir = $(INDICATORDIR)20datetimelibdir = $(INDICATORDIR)
17datetimelib_LTLIBRARIES = libdatetime.la21datetimelib_LTLIBRARIES = libdatetime.la
18libdatetime_la_SOURCES = \22libdatetime_la_SOURCES = \
23 datetime-client.h \
19 dbus-shared.h \24 dbus-shared.h \
20 indicator-datetime.c25 indicator-datetime.c
21libdatetime_la_CFLAGS = \26libdatetime_la_CFLAGS = \
@@ -27,4 +32,26 @@
27 -module \32 -module \
28 -avoid-version33 -avoid-version
2934
30EXTRA_DIST = $(libdatetime_la_SOURCES)35datetime-service-client.h: $(srcdir)/datetime-service.xml
36 dbus-binding-tool \
37 --prefix=_datetime_service_client \
38 --mode=glib-client \
39 --output=datetime-service-client.h \
40 $(srcdir)/datetime-service.xml
41
42datetime-service-server.h: $(srcdir)/datetime-service.xml
43 dbus-binding-tool \
44 --prefix=_datetime_service_server \
45 --mode=glib-server \
46 --output=datetime-service-server.h \
47 $(srcdir)/datetime-service.xml
48
49BUILT_SOURCES = \
50 datetime-service-client.h \
51 datetime-service-server.h
52
53CLEANFILES = \
54 $(BUILT_SOURCES)
55
56EXTRA_DIST = \
57 datetime-service.xml
3158
=== added file 'src/datetime-interface.c'
--- src/datetime-interface.c 1970-01-01 00:00:00 +0000
+++ src/datetime-interface.c 2010-08-31 12:59:38 +0000
@@ -0,0 +1,98 @@
1/*
2An indicator to time and date related information in the menubar.
3
4Copyright 2010 Canonical Ltd.
5
6Authors:
7 Ted Gould <ted@canonical.com>
8
9This program is free software: you can redistribute it and/or modify it
10under the terms of the GNU General Public License version 3, as published
11by the Free Software Foundation.
12
13This program is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranties of
15MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
16PURPOSE. See the GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License along
19with this program. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#ifdef HAVE_CONFIG_H
23#include "config.h"
24#endif
25
26#include "datetime-interface.h"
27#include "datetime-service-server.h"
28#include "dbus-shared.h"
29
30enum {
31 UPDATE_TIME,
32 LAST_SIGNAL
33};
34
35static guint signals[LAST_SIGNAL] = { 0 };
36
37static void datetime_interface_class_init (DatetimeInterfaceClass *klass);
38static void datetime_interface_init (DatetimeInterface *self);
39static void datetime_interface_dispose (GObject *object);
40static void datetime_interface_finalize (GObject *object);
41
42G_DEFINE_TYPE (DatetimeInterface, datetime_interface, G_TYPE_OBJECT);
43
44static void
45datetime_interface_class_init (DatetimeInterfaceClass *klass)
46{
47 GObjectClass *object_class = G_OBJECT_CLASS (klass);
48
49 object_class->dispose = datetime_interface_dispose;
50 object_class->finalize = datetime_interface_finalize;
51
52 signals[UPDATE_TIME] = g_signal_new("update-time",
53 G_TYPE_FROM_CLASS(klass),
54 G_SIGNAL_RUN_LAST,
55 G_STRUCT_OFFSET (DatetimeInterfaceClass, update_time),
56 NULL, NULL,
57 g_cclosure_marshal_VOID__VOID,
58 G_TYPE_NONE, 0, G_TYPE_NONE);
59
60 dbus_g_object_type_install_info(DATETIME_INTERFACE_TYPE, &dbus_glib__datetime_service_server_object_info);
61
62 return;
63}
64
65static void
66datetime_interface_init (DatetimeInterface *self)
67{
68 DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
69 dbus_g_connection_register_g_object(connection,
70 SERVICE_OBJ,
71 G_OBJECT(self));
72
73 return;
74}
75
76static void
77datetime_interface_dispose (GObject *object)
78{
79
80 G_OBJECT_CLASS (datetime_interface_parent_class)->dispose (object);
81 return;
82}
83
84static void
85datetime_interface_finalize (GObject *object)
86{
87
88 G_OBJECT_CLASS (datetime_interface_parent_class)->finalize (object);
89 return;
90}
91
92void
93datetime_interface_update (DatetimeInterface *self)
94{
95 g_return_if_fail(IS_DATETIME_INTERFACE(self));
96 g_signal_emit(G_OBJECT(self), signals[UPDATE_TIME], 0, TRUE);
97 return;
98}
099
=== added file 'src/datetime-interface.h'
--- src/datetime-interface.h 1970-01-01 00:00:00 +0000
+++ src/datetime-interface.h 2010-08-31 12:59:38 +0000
@@ -0,0 +1,55 @@
1/*
2An indicator to time and date related information in the menubar.
3
4Copyright 2010 Canonical Ltd.
5
6Authors:
7 Ted Gould <ted@canonical.com>
8
9This program is free software: you can redistribute it and/or modify it
10under the terms of the GNU General Public License version 3, as published
11by the Free Software Foundation.
12
13This program is distributed in the hope that it will be useful, but
14WITHOUT ANY WARRANTY; without even the implied warranties of
15MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
16PURPOSE. See the GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License along
19with this program. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#ifndef __DATETIME_INTERFACE_H__
23#define __DATETIME_INTERFACE_H__
24
25#include <glib.h>
26#include <glib-object.h>
27
28G_BEGIN_DECLS
29
30#define DATETIME_INTERFACE_TYPE (datetime_interface_get_type ())
31#define DATETIME_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DATETIME_INTERFACE_TYPE, DatetimeInterface))
32#define DATETIME_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DATETIME_INTERFACE_TYPE, DatetimeInterfaceClass))
33#define IS_DATETIME_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DATETIME_INTERFACE_TYPE))
34#define IS_DATETIME_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DATETIME_INTERFACE_TYPE))
35#define DATETIME_INTERFACE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DATETIME_INTERFACE_TYPE, DatetimeInterfaceClass))
36
37typedef struct _DatetimeInterface DatetimeInterface;
38typedef struct _DatetimeInterfaceClass DatetimeInterfaceClass;
39
40struct _DatetimeInterfaceClass {
41 GObjectClass parent_class;
42
43 void (*update_time) (void);
44};
45
46struct _DatetimeInterface {
47 GObject parent;
48};
49
50GType datetime_interface_get_type (void);
51void datetime_interface_update (DatetimeInterface *self);
52
53G_END_DECLS
54
55#endif
056
=== modified file 'src/datetime-service.c'
--- src/datetime-service.c 2010-07-22 19:14:47 +0000
+++ src/datetime-service.c 2010-08-31 12:59:38 +0000
@@ -23,17 +23,22 @@
23#include <libindicator/indicator-service.h>23#include <libindicator/indicator-service.h>
2424
25#include <glib/gi18n.h>25#include <glib/gi18n.h>
26#include <gio/gio.h>
2627
27#include <libdbusmenu-glib/server.h>28#include <libdbusmenu-glib/server.h>
28#include <libdbusmenu-glib/client.h>29#include <libdbusmenu-glib/client.h>
29#include <libdbusmenu-glib/menuitem.h>30#include <libdbusmenu-glib/menuitem.h>
3031
32#include "datetime-interface.h"
31#include "dbus-shared.h"33#include "dbus-shared.h"
3234
35static void setup_timer (void);
36
33static IndicatorService * service = NULL;37static IndicatorService * service = NULL;
34static GMainLoop * mainloop = NULL;38static GMainLoop * mainloop = NULL;
35static DbusmenuServer * server = NULL;39static DbusmenuServer * server = NULL;
36static DbusmenuMenuitem * root = NULL;40static DbusmenuMenuitem * root = NULL;
41static DatetimeInterface * dbus = NULL;
3742
38/* Global Items */43/* Global Items */
39static DbusmenuMenuitem * date = NULL;44static DbusmenuMenuitem * date = NULL;
@@ -136,7 +141,6 @@
136 dbusmenu_menuitem_child_append(root, date);141 dbusmenu_menuitem_child_append(root, date);
137142
138 g_idle_add(update_datetime, NULL);143 g_idle_add(update_datetime, NULL);
139 /* TODO: Set up updating daily */
140 }144 }
141145
142 if (calendar == NULL) {146 if (calendar == NULL) {
@@ -166,6 +170,68 @@
166 return;170 return;
167}171}
168172
173/* Run when the timezone file changes */
174static void
175timezone_changed (GFileMonitor * monitor, GFile * file, GFile * otherfile, GFileMonitorEvent event, gpointer user_data)
176{
177 datetime_interface_update(DATETIME_INTERFACE(user_data));
178 update_datetime(NULL);
179 setup_timer();
180 return;
181}
182
183/* Set up monitoring the timezone file */
184static void
185build_timezone (DatetimeInterface * dbus)
186{
187 GFile * timezonefile = g_file_new_for_path(TIMEZONE_FILE);
188 GFileMonitor * monitor = g_file_monitor_file(timezonefile, G_FILE_MONITOR_NONE, NULL, NULL);
189 if (monitor != NULL) {
190 g_signal_connect(G_OBJECT(monitor), "changed", G_CALLBACK(timezone_changed), dbus);
191 g_debug("Monitoring timezone file: '" TIMEZONE_FILE "'");
192 } else {
193 g_warning("Unable to monitor timezone file: '" TIMEZONE_FILE "'");
194 }
195 return;
196}
197
198/* Source ID for the timer */
199static guint timer = 0;
200
201/* Execute at a given time, update and setup a new
202 timer to go again. */
203static gboolean
204timer_func (gpointer user_data)
205{
206 timer = 0;
207 /* Reset up each time to reduce error */
208 setup_timer();
209 update_datetime(NULL);
210 return FALSE;
211}
212
213/* Sets up the time to launch the timer to update the
214 date in the datetime entry */
215static void
216setup_timer (void)
217{
218 if (timer != 0) {
219 g_source_remove(timer);
220 timer = 0;
221 }
222
223 time_t t;
224 t = time(NULL);
225 struct tm * ltime = localtime(&t);
226
227 timer = g_timeout_add_seconds(((23 - ltime->tm_hour) * 60 * 60) +
228 ((59 - ltime->tm_min) * 60) +
229 ((60 - ltime->tm_sec)) + 60 /* one minute past */,
230 timer_func, NULL);
231
232 return;
233}
234
169/* Repsonds to the service object saying it's time to shutdown.235/* Repsonds to the service object saying it's time to shutdown.
170 It stops the mainloop. */236 It stops the mainloop. */
171static void 237static void
@@ -198,9 +264,19 @@
198 dbusmenu_server_set_root(server, root);264 dbusmenu_server_set_root(server, root);
199 build_menus(root);265 build_menus(root);
200266
267 /* Setup dbus interface */
268 dbus = g_object_new(DATETIME_INTERFACE_TYPE, NULL);
269
270 /* Setup timezone watch */
271 build_timezone(dbus);
272
273 /* Setup the timer */
274 setup_timer();
275
201 mainloop = g_main_loop_new(NULL, FALSE);276 mainloop = g_main_loop_new(NULL, FALSE);
202 g_main_loop_run(mainloop);277 g_main_loop_run(mainloop);
203278
279 g_object_unref(G_OBJECT(dbus));
204 g_object_unref(G_OBJECT(service));280 g_object_unref(G_OBJECT(service));
205 g_object_unref(G_OBJECT(server));281 g_object_unref(G_OBJECT(server));
206 g_object_unref(G_OBJECT(root));282 g_object_unref(G_OBJECT(root));
207283
=== added file 'src/datetime-service.xml'
--- src/datetime-service.xml 1970-01-01 00:00:00 +0000
+++ src/datetime-service.xml 2010-08-31 12:59:38 +0000
@@ -0,0 +1,11 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<node name="/">
3 <interface name="org.ayatana.indicator.datetime.service">
4
5<!-- Methods -->
6
7<!-- Signals -->
8 <signal name="UpdateTime" />
9
10 </interface>
11</node>
012
=== modified file 'src/dbus-shared.h'
--- src/dbus-shared.h 2010-07-22 19:13:36 +0000
+++ src/dbus-shared.h 2010-08-31 12:59:38 +0000
@@ -20,9 +20,9 @@
20*/20*/
2121
2222
23#define SERVICE_NAME "org.ayatana.indicator.datetime"23#define SERVICE_NAME "org.ayatana.indicator.datetime"
24#define SERVICE_IFACE "org.ayatana.indicator.datetime.service"24#define SERVICE_IFACE "org.ayatana.indicator.datetime.service"
25#define SERVICE_OBJ "/org/ayatana/indicator/datetime/service"25#define SERVICE_OBJ "/org/ayatana/indicator/datetime/service"
26#define SERVICE_VERSION 126#define SERVICE_VERSION 1
2727
28#define MENU_OBJ "/org/ayatana/indicator/datetime/menu"28#define MENU_OBJ "/org/ayatana/indicator/datetime/menu"
2929
=== modified file 'src/indicator-datetime.c'
--- src/indicator-datetime.c 2010-07-22 19:13:36 +0000
+++ src/indicator-datetime.c 2010-08-31 12:59:38 +0000
@@ -29,6 +29,9 @@
29#include <glib/gi18n-lib.h>29#include <glib/gi18n-lib.h>
30#include <gio/gio.h>30#include <gio/gio.h>
3131
32/* DBus Stuff */
33#include <dbus/dbus-glib.h>
34
32/* Indicator Stuff */35/* Indicator Stuff */
33#include <libindicator/indicator.h>36#include <libindicator/indicator.h>
34#include <libindicator/indicator-object.h>37#include <libindicator/indicator-object.h>
@@ -79,6 +82,7 @@
79 IndicatorServiceManager * sm;82 IndicatorServiceManager * sm;
80 DbusmenuGtkMenu * menu;83 DbusmenuGtkMenu * menu;
8184
85 DBusGProxy * service_proxy;
82 IdoCalendarMenuItem *ido_calendar;86 IdoCalendarMenuItem *ido_calendar;
8387
84 GSettings * settings;88 GSettings * settings;
@@ -138,6 +142,7 @@
138static struct tm * update_label (IndicatorDatetime * io);142static struct tm * update_label (IndicatorDatetime * io);
139static void guess_label_size (IndicatorDatetime * self);143static void guess_label_size (IndicatorDatetime * self);
140static void setup_timer (IndicatorDatetime * self, struct tm * ltime);144static void setup_timer (IndicatorDatetime * self, struct tm * ltime);
145static void update_time (DBusGProxy * proxy, gpointer user_data);
141146
142/* Indicator Module Config */147/* Indicator Module Config */
143INDICATOR_SET_VERSION148INDICATOR_SET_VERSION
@@ -223,6 +228,8 @@
223 self->priv->show_day = FALSE;228 self->priv->show_day = FALSE;
224 self->priv->custom_string = g_strdup(DEFAULT_TIME_FORMAT);229 self->priv->custom_string = g_strdup(DEFAULT_TIME_FORMAT);
225230
231 self->priv->service_proxy = NULL;
232
226 self->priv->sm = NULL;233 self->priv->sm = NULL;
227 self->priv->menu = NULL;234 self->priv->menu = NULL;
228235
@@ -262,6 +269,21 @@
262269
263 self->priv->sm = indicator_service_manager_new_version(SERVICE_NAME, SERVICE_VERSION);270 self->priv->sm = indicator_service_manager_new_version(SERVICE_NAME, SERVICE_VERSION);
264271
272 DBusGConnection * session = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
273 if (session != NULL) {
274 self->priv->service_proxy = dbus_g_proxy_new_for_name(session,
275 SERVICE_NAME,
276 SERVICE_OBJ,
277 SERVICE_IFACE);
278
279 dbus_g_proxy_add_signal(self->priv->service_proxy, "UpdateTime", G_TYPE_INVALID);
280 dbus_g_proxy_connect_signal(self->priv->service_proxy,
281 "UpdateTime",
282 G_CALLBACK(update_time),
283 self,
284 NULL);
285 }
286
265 return;287 return;
266}288}
267289
@@ -300,6 +322,11 @@
300 self->priv->settings = NULL;322 self->priv->settings = NULL;
301 }323 }
302324
325 if (self->priv->service_proxy != NULL) {
326 g_object_unref(self->priv->service_proxy);
327 self->priv->service_proxy = NULL;
328 }
329
303 G_OBJECT_CLASS (indicator_datetime_parent_class)->dispose (object);330 G_OBJECT_CLASS (indicator_datetime_parent_class)->dispose (object);
304 return;331 return;
305}332}
@@ -537,6 +564,17 @@
537 return ltime;564 return ltime;
538}565}
539566
567/* Recieves the signal from the service that we should update
568 the time right now. Usually from a timezone switch. */
569static void
570update_time (DBusGProxy * proxy, gpointer user_data)
571{
572 IndicatorDatetime * self = INDICATOR_DATETIME(user_data);
573 struct tm * ltime = update_label(self);
574 setup_timer(self, ltime);
575 return;
576}
577
540/* Runs every minute and updates the time */578/* Runs every minute and updates the time */
541gboolean579gboolean
542timer_func (gpointer user_data)580timer_func (gpointer user_data)

Subscribers

People subscribed via source and target branches

to all changes: