Merge lp:~karl-qdh/indicator-datetime/resetdate into lp:indicator-datetime/0.3

Proposed by Karl Lattimer on 2011-03-30
Status: Merged
Merged at revision: 94
Proposed branch: lp:~karl-qdh/indicator-datetime/resetdate
Merge into: lp:indicator-datetime/0.3
Diff against target: 251 lines (+116/-17)
2 files modified
src/datetime-service.c (+42/-9)
src/indicator-datetime.c (+74/-8)
To merge this branch: bzr merge lp:~karl-qdh/indicator-datetime/resetdate
Reviewer Review Type Date Requested Status
Ted Gould 2011-03-30 Pending
Review via email: mp+55482@code.launchpad.net

Description of the change

Used the suggested arrays for marking/unmarking days but there's no change, the signal is still not received by the indicator, restarted everything in various ways and nothing seems to get it working.

To post a comment you must log in.
81. By Karl Lattimer on 2011-03-30

Made marking work when you change month, still needs more work to get it to do it on startup properly.

82. By Karl Lattimer on 2011-03-30

Move start timer into an idle so we have a chance to actually create the menu items

83. By Karl Lattimer on 2011-03-30

Potential fix for suspend issue suggested by njpatel

84. By Karl Lattimer on 2011-03-30

Might not like that signal notation

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-03-29 16:58:28 +0000
3+++ src/datetime-service.c 2011-03-30 15:04:58 +0000
4@@ -316,6 +316,28 @@
5 return TRUE;
6 }
7
8+static gboolean
9+close_menu_cb (DbusmenuMenuitem * menuitem, gchar *name, GVariant *variant)
10+{
11+ if (calendar == NULL) return FALSE;
12+ g_debug("Resetting date on menu close");
13+ start_time_appointments = 0;
14+ // TODO create a variant which will be an array of 3 ints {y,m,d}
15+ GVariant *date_variant;
16+ time_t curtime;
17+ struct tm *t1;
18+ time(&curtime);
19+ t1 = localtime(&curtime);
20+ GVariant *date[3];
21+ date[0] = g_variant_new_uint32(t1->tm_year + 1900);
22+ date[1] = g_variant_new_uint32(t1->tm_mon);
23+ date[2] = g_variant_new_uint32(t1->tm_mday);
24+ date_variant = g_variant_new_array(NULL, date, 3);
25+
26+ dbusmenu_menuitem_property_set_variant (calendar, CALENDAR_MENUITEM_PROP_SET_DATE, date_variant);
27+ return TRUE;
28+}
29+
30 static guint ecaltimer = 0;
31
32 static void
33@@ -331,6 +353,12 @@
34 {
35 if (ecaltimer != 0) g_source_remove(ecaltimer);
36 }
37+static gboolean
38+idle_start_ecal_timer (gpointer data)
39+{
40+ start_ecal_timer();
41+ return FALSE;
42+}
43
44 static void
45 show_events_changed (void)
46@@ -389,7 +417,7 @@
47 if (g_settings_get_boolean(conf, SETTINGS_SHOW_EVENTS_S)) {
48 dbusmenu_menuitem_property_set_bool(add_appointment, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
49 dbusmenu_menuitem_property_set_bool(events_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE);
50- start_ecal_timer();
51+ g_idle_add((GSourceFunc)idle_start_ecal_timer, NULL);
52 } else {
53 dbusmenu_menuitem_property_set_bool(add_appointment, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
54 dbusmenu_menuitem_property_set_bool(events_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE);
55@@ -600,16 +628,13 @@
56 month_start.tm_mon = start_tm->tm_mon;
57 month_start.tm_mday = 1;
58 t1 = mktime(&month_start);
59- highlightdays = days[mon];
60+ highlightdays = days[start_month];
61 }
62 }
63
64 g_debug("Will highlight %d days from %s", highlightdays, ctime(&t1));
65
66- t2 = t1 + (time_t) (highlightdays * 24 * 60 * 60);
67-
68- // Remove all highlights from the calendar widget
69- dbusmenu_menuitem_property_set (calendar, CALENDAR_MENUITEM_PROP_CLEAR_MARKS, NULL);
70+ t2 = t1 + (time_t) (highlightdays * 24 * 60 * 60);
71
72 if (!e_cal_get_sources(&sources, E_CAL_SOURCE_TYPE_EVENT, &gerror)) {
73 g_debug("Failed to get ecal sources\n");
74@@ -682,6 +707,9 @@
75 apt_output = SETTINGS_TIME_LOCALE;
76 }
77
78+ GVariantBuilder markeddays;
79+ g_variant_builder_init (&markeddays, G_VARIANT_TYPE_ARRAY);
80+
81 i = 0;
82 for (l = sorted_comp_instances; l; l = l->next) {
83 struct comp_instance *ci = l->data;
84@@ -703,9 +731,8 @@
85 const int dyear = due->tm_year;
86
87 // Mark day
88- g_debug("Marking date %s", ctime(&ci->start));
89- dbusmenu_menuitem_property_set_int (calendar, CALENDAR_MENUITEM_PROP_MARK, due->tm_mday);
90-
91+ g_debug("Adding marked date %s, %d", ctime(&ci->start), dmday);
92+ g_variant_builder_add (&markeddays, "i", dmday);
93
94 // If the appointment time is less than the selected date,
95 // don't create an appointment item for it.
96@@ -833,6 +860,9 @@
97 }
98 g_list_free(sorted_comp_instances);
99
100+ GVariant * marks = g_variant_builder_end (&markeddays);
101+ dbusmenu_menuitem_property_set_variant (calendar, CALENDAR_MENUITEM_PROP_MARK, marks);
102+
103 updating_appointments = FALSE;
104 g_debug("End of objects");
105 return TRUE;
106@@ -1219,6 +1249,9 @@
107
108 build_menus(root);
109
110+ // Connect to the close signal to reset the calendar date
111+ g_signal_connect(root, "event::closed", G_CALLBACK(close_menu_cb), NULL);
112+
113 /* Cache the timezone */
114 update_current_timezone();
115
116
117=== modified file 'src/indicator-datetime.c'
118--- src/indicator-datetime.c 2011-03-29 15:43:58 +0000
119+++ src/indicator-datetime.c 2011-03-30 15:04:58 +0000
120@@ -169,7 +169,9 @@
121 static void guess_label_size (IndicatorDatetime * self);
122 static void setup_timer (IndicatorDatetime * self, GDateTime * datetime);
123 static void update_time (IndicatorDatetime * self);
124+static void session_active_change_cb (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data);
125 static void receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name, GVariant * parameters, gpointer user_data);
126+static void system_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data);
127 static void service_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data);
128 static gint generate_strftime_bitmask (const char *time_str);
129 static void timezone_update_labels (indicator_item_t * mi_data);
130@@ -352,8 +354,34 @@
131 service_proxy_cb,
132 self);
133
134+ g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
135+ G_DBUS_PROXY_FLAGS_NONE,
136+ NULL,
137+ "org.freedesktop.ConsoleKit",
138+ "/org/freedesktop/ConsoleKit/Manager",
139+ "org.freedesktop.ConsoleKit.Manager",
140+ NULL, system_proxy_cb, self);
141 return;
142 }
143+/* for hooking into console kit signal on wake from suspend */
144+static void
145+system_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data)
146+{
147+ GError * error = NULL;
148+
149+ IndicatorDatetime * self = INDICATOR_DATETIME(user_data);
150+ g_return_if_fail(self != NULL);
151+
152+ GDBusProxy * proxy = g_dbus_proxy_new_for_bus_finish(res, &error);
153+
154+ if (error != NULL) {
155+ g_warning("Could not grab DBus proxy for %s: %s", SERVICE_NAME, error->message);
156+ g_error_free(error);
157+ return;
158+ }
159+ g_signal_connect(proxy, "g-signal", G_CALLBACK(session_active_change_cb), self);
160+
161+}
162
163 /* Callback from trying to create the proxy for the serivce, this
164 could include starting the service. Sometime it'll fail and
165@@ -776,6 +804,18 @@
166 return;
167 }
168
169+static void
170+session_active_change_cb (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name,
171+ GVariant * parameters, gpointer user_data)
172+{
173+ // Just returned from suspend
174+ IndicatorDatetime * self = INDICATOR_DATETIME(user_data);
175+ if (g_strcmp0(signal_name, "ActiveChanged") == 0) {
176+ update_time(self);
177+ }
178+ return;
179+}
180+
181 /* Receives all signals from the service, routed to the appropriate functions */
182 static void
183 receive_signal (GDBusProxy * proxy, gchar * sender_name, gchar * signal_name,
184@@ -1148,18 +1188,45 @@
185 timezone_update_labels(mi_data);
186 } else if (!g_strcmp0(prop, TIMEZONE_MENUITEM_PROP_RADIO)) {
187 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mi_data->gmi), g_variant_get_boolean(value));
188-
189- // Properties for marking and unmarking the calendar
190-
191- } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_MARK)) {
192- ido_calendar_menu_item_mark_day (IDO_CALENDAR_MENU_ITEM (mi_data), g_variant_get_int16(value));
193+ } else {
194+ g_warning("Indicator Item property '%s' unknown", prop);
195+ }
196+ return;
197+}
198+// Properties for marking and unmarking the calendar
199+static void
200+calendar_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant *value, IdoCalendarMenuItem * mi_data)
201+{
202+ g_debug("Changing calendar property");
203+ if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_MARK)) {
204+ ido_calendar_menu_item_clear_marks (IDO_CALENDAR_MENU_ITEM (mi_data));
205+ g_debug("Marks: Cleared");
206+ GVariantIter *iter;
207+ gint day;
208+
209+ g_variant_get (value, "ai", &iter);
210+ while (g_variant_iter_loop (iter, "i", &day)) {
211+ ido_calendar_menu_item_mark_day (IDO_CALENDAR_MENU_ITEM (mi_data), day);
212+ g_debug("Marks: Marked day: %d", day);
213+ }
214+ g_variant_iter_free (iter);
215 } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_UNMARK)) {
216- ido_calendar_menu_item_unmark_day (IDO_CALENDAR_MENU_ITEM (mi_data), g_variant_get_int16(value));
217+ GVariantIter *iter;
218+ gint day;
219+
220+ g_variant_get (value, "ai", &iter);
221+ while (g_variant_iter_loop (iter, "i", &day)) {
222+ g_debug("Unmarked day: %d", day);
223+ ido_calendar_menu_item_unmark_day (IDO_CALENDAR_MENU_ITEM (mi_data), day);
224+ }
225+ g_variant_iter_free (iter);
226 } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_CLEAR_MARKS)) {
227 ido_calendar_menu_item_clear_marks (IDO_CALENDAR_MENU_ITEM (mi_data));
228+ g_debug("Cleared Marks");
229 } else if (!g_strcmp0(prop, CALENDAR_MENUITEM_PROP_SET_DATE)) {
230 gsize size = 3;
231 const gint * array = g_variant_get_fixed_array(value, &size, sizeof(gint));
232+ g_debug("Setting date y-m-d: %d-%d-%d", array[0], array[1], array[2]);
233 ido_calendar_menu_item_set_date (IDO_CALENDAR_MENU_ITEM (mi_data), array[0], array[1], array[2]);
234 } else {
235 g_warning("Indicator Item property '%s' unknown", prop);
236@@ -1239,8 +1306,6 @@
237 dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(mi_data->gmi), parent);
238
239 g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(indicator_prop_change_cb), mi_data);
240- g_signal_connect_swapped(G_OBJECT(newitem), "destroyed", G_CALLBACK(g_free), mi_data);
241-
242 return TRUE;
243 }
244
245@@ -1334,6 +1399,7 @@
246 g_signal_connect_after(ido, "day-selected", G_CALLBACK(day_selected_cb), (gpointer)newitem);
247 g_signal_connect_after(ido, "day-selected-double-click", G_CALLBACK(day_selected_double_click_cb), (gpointer)newitem);
248
249+ g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(calendar_prop_change_cb), ido);
250 return TRUE;
251 }
252

Subscribers

People subscribed via source and target branches