Merge lp:~mterry/indicator-datetime/karl-plus-trunk into lp:indicator-datetime/0.3
- karl-plus-trunk
- Merge into trunk
Proposed by
Michael Terry
Status: | Merged |
---|---|
Merged at revision: | 48 |
Proposed branch: | lp:~mterry/indicator-datetime/karl-plus-trunk |
Merge into: | lp:indicator-datetime/0.3 |
Diff against target: |
327 lines (+99/-43) 3 files modified
src/datetime-service.c (+32/-39) src/dbus-shared.h (+8/-1) src/indicator-datetime.c (+59/-3) |
To merge this branch: | bzr merge lp:~mterry/indicator-datetime/karl-plus-trunk |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Indicator Applet Developers | Pending | ||
Review via email: mp+51344@code.launchpad.net |
Commit message
Description of the change
This is klattimer's ~karl-qdh/
To post a comment you must log in.
- 67. By Michael Terry
-
add in some fixes from karl's branch
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/datetime-service.c' |
2 | --- src/datetime-service.c 2011-02-25 16:41:56 +0000 |
3 | +++ src/datetime-service.c 2011-02-25 18:38:13 +0000 |
4 | @@ -127,7 +127,7 @@ |
5 | } else { |
6 | g_debug("Timezones are different"); |
7 | } |
8 | - |
9 | + |
10 | gboolean show = g_settings_get_boolean (conf, SETTINGS_SHOW_LOCATIONS_S); |
11 | |
12 | if (geo_location != NULL && current_location != NULL) { |
13 | @@ -222,6 +222,7 @@ |
14 | |
15 | check_timezone_sync(); |
16 | |
17 | + if (error != NULL) g_error_free(error); |
18 | return; |
19 | } |
20 | |
21 | @@ -266,52 +267,35 @@ |
22 | } |
23 | } |
24 | |
25 | +static gboolean |
26 | +month_changed_cb (DbusmenuMenuitem * menuitem, GVariant *variant, guint timestamp) |
27 | +{ |
28 | + // TODO: * Decode the month/year from the string we received |
29 | + // * Check what our current month/year are |
30 | + // * Set some globals so when we-re-run update appointment menu items it gets the right start date |
31 | + // * update appointment menu items |
32 | + g_debug("Received month changed : %s", g_variant_get_string(variant, NULL)); |
33 | + return TRUE; |
34 | +} |
35 | + |
36 | /* Looks for the calendar application and enables the item if |
37 | we have one */ |
38 | static gboolean |
39 | check_for_calendar (gpointer user_data) |
40 | { |
41 | g_return_val_if_fail (calendar != NULL, FALSE); |
42 | + |
43 | + if (!g_settings_get_boolean(conf, SETTINGS_SHOW_CALENDAR_S)) return FALSE; |
44 | |
45 | gchar *evo = g_find_program_in_path("evolution"); |
46 | if (evo != NULL) { |
47 | g_debug("Found the calendar application: %s", evo); |
48 | dbusmenu_menuitem_property_set_bool(calendar, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); |
49 | dbusmenu_menuitem_property_set_bool(calendar, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); |
50 | -/* |
51 | - GError *gerror = NULL; |
52 | - // TODO: In reality we should iterate sources of calendar, but getting the local one doens't lag for > a minute |
53 | - g_debug("Setting up ecal."); |
54 | - if (!ecal) |
55 | - ecal = e_cal_new_system_calendar(); |
56 | - |
57 | - if (!ecal) { |
58 | - g_debug("e_cal_new_system_calendar failed"); |
59 | - ecal = NULL; |
60 | - } |
61 | - g_debug("Open calendar."); |
62 | - if (!e_cal_open(ecal, FALSE, &gerror) ) { |
63 | - g_debug("e_cal_open: %s\n", gerror->message); |
64 | - g_free(ecal); |
65 | - ecal = NULL; |
66 | - } |
67 | - g_debug("Get calendar timezone."); |
68 | - if (!e_cal_get_timezone(ecal, "UTC", &tzone, &gerror)) { |
69 | - g_debug("failed to get time zone\n"); |
70 | - g_free(ecal); |
71 | - ecal = NULL; |
72 | - } |
73 | - |
74 | - This timezone represents the timezone of the calendar, this might be different to the current UTC offset. |
75 | - * this means we'll have some geoclue interaction going on, and possibly the user will be involved in setting |
76 | - * their location manually, case in point: trains have satellite links which often geoclue to sweden, |
77 | - * this shouldn't automatically set the location and mess up all the appointments for the user. |
78 | - |
79 | - if (ecal) ecal_timezone = icaltimezone_get_tzid(tzone); |
80 | - */ |
81 | + |
82 | DbusmenuMenuitem * separator = dbusmenu_menuitem_new(); |
83 | dbusmenu_menuitem_property_set(separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); |
84 | - dbusmenu_menuitem_child_add_position(root, separator, 3); |
85 | + dbusmenu_menuitem_child_add_position(root, separator, 2); |
86 | |
87 | add_appointment = dbusmenu_menuitem_new(); |
88 | dbusmenu_menuitem_property_set (add_appointment, DBUSMENU_MENUITEM_PROP_LABEL, _("Add Appointment")); |
89 | @@ -320,9 +304,12 @@ |
90 | g_signal_connect(G_OBJECT(add_appointment), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(activate_cb), "evolution -c calendar"); |
91 | dbusmenu_menuitem_child_add_position (root, add_appointment, 3); |
92 | |
93 | - update_appointment_menu_items(NULL); |
94 | - g_signal_connect(root, DBUSMENU_MENUITEM_SIGNAL_ABOUT_TO_SHOW, G_CALLBACK(update_appointment_menu_items), NULL); |
95 | - |
96 | + // Update the calendar items every 5 minutes if it updates the first time |
97 | + if (update_appointment_menu_items(NULL)) |
98 | + g_timeout_add_seconds(60*5, update_appointment_menu_items, NULL); |
99 | + |
100 | + // Connect to event::month-changed |
101 | + g_signal_connect(calendar, "event::month-changed", G_CALLBACK(month_changed_cb), NULL); |
102 | g_free(evo); |
103 | } else { |
104 | g_debug("Unable to find calendar app."); |
105 | @@ -337,6 +324,7 @@ |
106 | static gboolean |
107 | update_timezone_menu_items(gpointer user_data) { |
108 | g_debug("Updating timezone menu items"); |
109 | + |
110 | gchar ** locations = g_settings_get_strv(conf, SETTINGS_LOCATIONS_S); |
111 | if (locations == NULL) { |
112 | g_debug("No locations configured (NULL)"); |
113 | @@ -403,7 +391,7 @@ |
114 | else component_name = "Calendar"; |
115 | |
116 | gchar *password = e_passwords_get_password (component_name, key); |
117 | - |
118 | + |
119 | if (password == NULL) { |
120 | password = e_passwords_ask_password ( |
121 | _("Enter password"), |
122 | @@ -471,6 +459,9 @@ |
123 | update_appointment_menu_items (gpointer user_data) { |
124 | // FFR: we should take into account short term timers, for instance |
125 | // tea timers, pomodoro timers etc... that people may add, this is hinted to in the spec. |
126 | + if (calendar == NULL) return FALSE; |
127 | + if (!g_settings_get_boolean(conf, SETTINGS_SHOW_EVENTS_S)) return FALSE; |
128 | + |
129 | time_t t1, t2; |
130 | gchar *query, *is, *ie, *ad; |
131 | GList *objects = NULL, *l; |
132 | @@ -523,7 +514,6 @@ |
133 | g_signal_connect (G_OBJECT(source), "changed", G_CALLBACK (update_appointment_menu_items), NULL); |
134 | ECal *ecal = e_cal_new(source, E_CAL_SOURCE_TYPE_EVENT); |
135 | e_cal_set_auth_func (ecal, (ECalAuthFunc) auth_func, NULL); |
136 | - //icaltimezone * tzone; |
137 | |
138 | if (!e_cal_open(ecal, FALSE, &gerror)) { |
139 | g_debug("Failed to get ecal sources %s", gerror->message); |
140 | @@ -536,7 +526,8 @@ |
141 | if (!e_cal_get_object_list_as_comp(ecal, query, &objects, &gerror)) { |
142 | g_debug("Failed to get objects\n"); |
143 | g_free(ecal); |
144 | - return FALSE; |
145 | + gerror = NULL; |
146 | + continue; |
147 | } |
148 | g_debug("Number of objects returned: %d", g_list_length(objects)); |
149 | |
150 | @@ -681,6 +672,8 @@ |
151 | if (i == 4) break; // See above FIXME regarding query result limit |
152 | i++; |
153 | } |
154 | + |
155 | + if (gerror != NULL) g_error_free(gerror); |
156 | g_object_unref(allobjects); |
157 | g_debug("End of objects"); |
158 | return TRUE; |
159 | |
160 | === modified file 'src/dbus-shared.h' |
161 | --- src/dbus-shared.h 2011-02-23 20:13:42 +0000 |
162 | +++ src/dbus-shared.h 2011-02-25 18:38:13 +0000 |
163 | @@ -27,7 +27,14 @@ |
164 | |
165 | #define MENU_OBJ "/com/canonical/indicator/datetime/menu" |
166 | |
167 | -#define DBUSMENU_CALENDAR_MENUITEM_TYPE "x-canonical-calendar-item" |
168 | +#define DBUSMENU_CALENDAR_MENUITEM_TYPE "x-canonical-calendar-item" |
169 | + |
170 | +// The following properties are not *really* properties, but are just |
171 | +// a way of accessing the calendar from the service |
172 | +#define CALENDAR_MENUITEM_PROP_MARK "calendar-mark" |
173 | +#define CALENDAR_MENUITEM_PROP_UNMARK "calendar-unmark" |
174 | +#define CALENDAR_MENUITEM_PROP_CLEAR_MARKS "calendar-clear-marks" |
175 | + |
176 | |
177 | #define APPOINTMENT_MENUITEM_TYPE "appointment-item" |
178 | #define APPOINTMENT_MENUITEM_PROP_LABEL "appointment-label" |
179 | |
180 | === modified file 'src/indicator-datetime.c' |
181 | --- src/indicator-datetime.c 2011-02-23 20:30:30 +0000 |
182 | +++ src/indicator-datetime.c 2011-02-25 18:38:13 +0000 |
183 | @@ -25,6 +25,7 @@ |
184 | |
185 | /* GStuff */ |
186 | #include <glib.h> |
187 | +#include <glib/gprintf.h> |
188 | #include <glib-object.h> |
189 | #include <glib/gi18n-lib.h> |
190 | #include <gio/gio.h> |
191 | @@ -36,7 +37,7 @@ |
192 | |
193 | /* DBusMenu */ |
194 | #include <libdbusmenu-gtk/menu.h> |
195 | -#include <libido/idocalendarmenuitem.h> |
196 | +#include <libido/libido.h> |
197 | #include <libdbusmenu-gtk/menuitem.h> |
198 | |
199 | #include "utils.h" |
200 | @@ -77,6 +78,9 @@ |
201 | gchar * custom_string; |
202 | gboolean custom_show_seconds; |
203 | |
204 | + gboolean show_week_numbers; |
205 | + gint week_start; |
206 | + |
207 | guint idle_measure; |
208 | gint max_width; |
209 | |
210 | @@ -100,7 +104,8 @@ |
211 | PROP_SHOW_SECONDS, |
212 | PROP_SHOW_DAY, |
213 | PROP_SHOW_DATE, |
214 | - PROP_CUSTOM_TIME_FORMAT |
215 | + PROP_CUSTOM_TIME_FORMAT, |
216 | + PROP_SHOW_WEEK_NUMBERS |
217 | }; |
218 | |
219 | typedef struct _indicator_item_t indicator_item_t; |
220 | @@ -118,6 +123,7 @@ |
221 | #define PROP_SHOW_DAY_S "show-day" |
222 | #define PROP_SHOW_DATE_S "show-date" |
223 | #define PROP_CUSTOM_TIME_FORMAT_S "custom-time-format" |
224 | +#define PROP_SHOW_WEEK_NUMBERS_S "show-week-numbers" |
225 | |
226 | #define INDICATOR_DATETIME_GET_PRIVATE(o) \ |
227 | (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_DATETIME_TYPE, IndicatorDatetimePrivate)) |
228 | @@ -222,6 +228,13 @@ |
229 | DEFAULT_TIME_FORMAT, |
230 | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); |
231 | |
232 | + g_object_class_install_property (object_class, |
233 | + PROP_SHOW_WEEK_NUMBERS, |
234 | + g_param_spec_boolean(PROP_SHOW_WEEK_NUMBERS_S, |
235 | + "Whether to show the week numbers in the calendar.", |
236 | + "Shows the week numbers in the monthly calendar in indicator-datetime's menu.", |
237 | + FALSE, /* default */ |
238 | + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); |
239 | return; |
240 | } |
241 | |
242 | @@ -280,6 +293,11 @@ |
243 | self, |
244 | PROP_CUSTOM_TIME_FORMAT_S, |
245 | G_SETTINGS_BIND_DEFAULT); |
246 | + g_settings_bind(self->priv->settings, |
247 | + SETTINGS_SHOW_WEEK_NUMBERS_S, |
248 | + self, |
249 | + PROP_SHOW_WEEK_NUMBERS_S, |
250 | + G_SETTINGS_BIND_DEFAULT); |
251 | } else { |
252 | g_warning("Unable to get settings for '" SETTINGS_INTERFACE "'"); |
253 | } |
254 | @@ -506,6 +524,18 @@ |
255 | } |
256 | break; |
257 | } |
258 | + case PROP_SHOW_WEEK_NUMBERS: { |
259 | + if (g_value_get_boolean(value) != self->priv->show_week_numbers) { |
260 | + GtkCalendarDisplayOptions flags = ido_calendar_menu_item_get_display_options (self->priv->ido_calendar); |
261 | + if (g_value_get_boolean(value) == TRUE) |
262 | + flags |= GTK_CALENDAR_SHOW_WEEK_NUMBERS; |
263 | + else |
264 | + flags &= ~GTK_CALENDAR_SHOW_WEEK_NUMBERS; |
265 | + ido_calendar_menu_item_set_display_options (self->priv->ido_calendar, flags); |
266 | + self->priv->show_week_numbers = g_value_get_boolean(value); |
267 | + } |
268 | + break; |
269 | + } |
270 | default: |
271 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); |
272 | return; |
273 | @@ -561,6 +591,9 @@ |
274 | case PROP_CUSTOM_TIME_FORMAT: |
275 | g_value_set_string(value, self->priv->custom_string); |
276 | break; |
277 | + case PROP_SHOW_WEEK_NUMBERS: |
278 | + g_value_set_boolean(value, self->priv->show_week_numbers); |
279 | + break; |
280 | default: |
281 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); |
282 | return; |
283 | @@ -1055,6 +1088,15 @@ |
284 | timezone_update_labels(mi_data); |
285 | } else if (!g_strcmp0(prop, TIMEZONE_MENUITEM_PROP_RADIO)) { |
286 | gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mi_data->gmi), g_variant_get_boolean(value)); |
287 | + |
288 | + // Properties for marking and unmarking the calendar |
289 | + |
290 | + } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_MARK)) { |
291 | + ido_calendar_menu_item_mark_day (IDO_CALENDAR_MENU_ITEM (mi_data), g_variant_get_int16(value)); |
292 | + } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_UNMARK)) { |
293 | + ido_calendar_menu_item_unmark_day (IDO_CALENDAR_MENU_ITEM (mi_data), g_variant_get_int16(value)); |
294 | + } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_CLEAR_MARKS)) { |
295 | + ido_calendar_menu_item_clear_marks (IDO_CALENDAR_MENU_ITEM (mi_data)); |
296 | } else { |
297 | g_warning("Indicator Item property '%s' unknown", prop); |
298 | } |
299 | @@ -1138,6 +1180,20 @@ |
300 | return TRUE; |
301 | } |
302 | |
303 | +static void |
304 | +month_changed_cb (IdoCalendarMenuItem *ido, |
305 | + gpointer user_data) |
306 | +{ |
307 | + gchar datestring[20]; |
308 | + guint d,m,y; |
309 | + DbusmenuMenuitem * item = DBUSMENU_MENUITEM (user_data); |
310 | + ido_calendar_menu_item_get_date(ido, &y, &m, &d); |
311 | + g_sprintf(datestring, "%d-%d-%d", y, m, d); |
312 | + GVariant *variant = g_variant_new_string(datestring); |
313 | + guint timestamp = (guint)time(NULL); |
314 | + dbusmenu_menuitem_handle_event(DBUSMENU_MENUITEM(item), "event::month-changed", variant, timestamp); |
315 | + g_debug("Got month changed signal: %s", datestring); |
316 | +} |
317 | |
318 | static gboolean |
319 | new_calendar_item (DbusmenuMenuitem * newitem, |
320 | @@ -1162,7 +1218,7 @@ |
321 | self->priv->ido_calendar = ido; |
322 | |
323 | dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(ido), parent); |
324 | - |
325 | + g_signal_connect_after(ido, "month-changed", G_CALLBACK(month_changed_cb), (gpointer)newitem); |
326 | return TRUE; |
327 | } |
328 |