Merge lp:~charlesk/indicator-datetime/lp-772340 into lp:indicator-datetime/0.4

Proposed by Charles Kerr
Status: Merged
Approved by: Charles Kerr
Approved revision: 170
Merge reported by: Charles Kerr
Merged at revision: not available
Proposed branch: lp:~charlesk/indicator-datetime/lp-772340
Merge into: lp:indicator-datetime/0.4
Diff against target: 268 lines (+65/-64)
1 file modified
src/datetime-service.c (+65/-64)
To merge this branch: bzr merge lp:~charlesk/indicator-datetime/lp-772340
Reviewer Review Type Date Requested Status
Lars Karlitski (community) Approve
Review via email: mp+98469@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Lars Karlitski (larsu) wrote :

Great work, it's much cleaner now!

Two small comments:

* comp_instance_new:
  - instead of putting it on two line, it's customary to do
      ci->source = g_object_ref (comp);

* comp_instance_free:
  - NULL check of 'ci' is missing

review: Needs Fixing
Revision history for this message
Charles Kerr (charlesk) wrote :

lars, thanks for those suggestions, I used them both in the merge.

I hadn't realized "foo = g_object_ref (bar)" was an idiom but it makes good sense; I'll start doing that from here on out.

Revision history for this message
Lars Karlitski (larsu) :
review: Approve

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 2012-03-16 18:53:17 +0000
3+++ src/datetime-service.c 2012-03-20 18:03:34 +0000
4@@ -273,7 +273,7 @@
5
6 if (error != NULL) {
7 g_warning("Could not set timezone for SettingsDaemon: %s", error->message);
8- g_error_free(error);
9+ g_clear_error (&error);
10 return;
11 }
12
13@@ -289,7 +289,7 @@
14
15 if (error != NULL) {
16 g_warning("Could not grab DBus proxy for SettingsDaemon: %s", error->message);
17- g_error_free(error);
18+ g_clear_error (&error);
19 g_free (zone);
20 return;
21 }
22@@ -363,7 +363,7 @@
23 g_debug("Issuing command '%s'", command);
24 if (!g_spawn_command_line_async(command, &error)) {
25 g_warning("Unable to start %s: %s", (char *)command, error->message);
26- g_error_free(error);
27+ g_clear_error (&error);
28 }
29 }
30
31@@ -532,7 +532,7 @@
32 GSList *accounts_list = gconf_client_get_list (gconf, "/apps/evolution/mail/accounts", GCONF_VALUE_STRING, NULL);
33 const guint n = g_slist_length (accounts_list);
34 g_debug ("found %u evolution accounts", n);
35- g_slist_free (accounts_list);
36+ g_slist_free_full (accounts_list, g_free);
37 return n > 0;
38 }
39
40@@ -613,22 +613,42 @@
41 }
42
43 static gint
44-compare_comp_instances (gconstpointer a,
45- gconstpointer b)
46-{
47- const struct comp_instance *ci_a = a;
48- const struct comp_instance *ci_b = b;
49- time_t d = ci_a->start - ci_b->start;
50- if (d < 0) return -1;
51- else if (d > 0) return 1;
52- return 0;
53+compare_comp_instances (gconstpointer ga, gconstpointer gb)
54+{
55+ const struct comp_instance * a = ga;
56+ const struct comp_instance * b = gb;
57+
58+ /* sort by start time */
59+ if (a->start < b->start) return -1;
60+ if (a->start > b->start) return 1;
61+ return 0;
62+}
63+
64+static struct comp_instance*
65+comp_instance_new (ECalComponent * comp, time_t start, time_t end, ESource * source)
66+{
67+ g_object_ref(comp);
68+ g_debug("Using times start %s, end %s", ctime(&start), ctime(&end));
69+
70+ struct comp_instance *ci = g_new (struct comp_instance, 1);
71+ ci->comp = comp;
72+ ci->source = source;
73+ ci->start = start;
74+ ci->end = end;
75+ return ci;
76+}
77+static void
78+comp_instance_free (struct comp_instance* ci)
79+{
80+ g_object_unref (ci->comp);
81+ g_free (ci);
82 }
83
84 static gboolean
85-populate_appointment_instances (ECalComponent *comp,
86- time_t instance_start,
87- time_t instance_end,
88- gpointer data)
89+populate_appointment_instances (ECalComponent * comp,
90+ time_t start,
91+ time_t end,
92+ gpointer data)
93 {
94 g_debug("Appending item %p", comp);
95
96@@ -638,20 +658,9 @@
97 icalproperty_status status;
98 e_cal_component_get_status (comp, &status);
99 if (status == ICAL_STATUS_COMPLETED || status == ICAL_STATUS_CANCELLED) return FALSE;
100-
101- g_object_ref(comp);
102
103- struct comp_instance *ci;
104- ci = g_new (struct comp_instance, 1);
105-
106- g_debug("Using times start %s, end %s", ctime(&instance_start), ctime(&instance_end));
107-
108- ci->comp = comp;
109- ci->source = E_SOURCE(data);
110- ci->start = instance_start;
111- ci->end = instance_end;
112-
113- comp_instances = g_list_append(comp_instances, ci);
114+ struct comp_instance *ci = comp_instance_new (comp, start, end, E_SOURCE(data));
115+ comp_instances = g_list_append (comp_instances, ci);
116 return TRUE;
117 }
118
119@@ -719,25 +728,18 @@
120
121 if (!e_cal_get_sources(&sources, E_CAL_SOURCE_TYPE_EVENT, &gerror)) {
122 g_debug("Failed to get ecal sources\n");
123+ g_clear_error (&gerror);
124 return FALSE;
125 }
126
127- // Free comp_instances if not NULL
128- if (comp_instances != NULL) {
129- g_debug("Freeing comp_instances: may be an overlap\n");
130- for (l = comp_instances; l; l = l->next) {
131- const struct comp_instance *ci = l->data;
132- g_object_unref(ci->comp);
133- }
134- g_list_free(comp_instances);
135- comp_instances = NULL;
136+ // clear any previous comp_instances
137+ g_list_free_full (comp_instances, (GDestroyNotify)comp_instance_free);
138+ comp_instances = NULL;
139
140- }
141 GSList *cal_list = gconf_client_get_list(gconf, "/apps/evolution/calendar/display/selected_calendars", GCONF_VALUE_STRING, &gerror);
142 if (gerror) {
143 g_debug("Failed to get evolution preference for enabled calendars");
144- g_error_free(gerror);
145- gerror = NULL;
146+ g_clear_error (&gerror);
147 cal_list = NULL;
148 }
149
150@@ -759,39 +761,33 @@
151 }
152 if (current_zone && !e_cal_set_default_timezone(ecal, current_zone, &gerror)) {
153 g_debug("Failed to set ecal default timezone %s", gerror->message);
154- g_error_free(gerror);
155- gerror = NULL;
156+ g_clear_error (&gerror);
157 g_object_unref(ecal);
158 continue;
159 }
160
161 if (!e_cal_open(ecal, FALSE, &gerror)) {
162 g_debug("Failed to get ecal sources %s", gerror->message);
163- g_error_free(gerror);
164- gerror = NULL;
165+ g_clear_error (&gerror);
166 g_object_unref(ecal);
167 continue;
168 }
169+
170 const gchar *ecal_uid = e_source_peek_uid(source);
171- gboolean match = FALSE;
172 g_debug("Checking ecal_uid is enabled: %s", ecal_uid);
173- for (i = 0; i<g_slist_length(cal_list);i++) {
174- char *cuid = (char *)g_slist_nth_data(cal_list, i);
175- if (g_strcmp0(cuid, ecal_uid) == 0) {
176- match = TRUE;
177- break;
178- }
179- }
180- if (!match) {
181+ const gboolean in_list = g_slist_find_custom (cal_list, ecal_uid, (GCompareFunc)g_strcmp0) != NULL;
182+ if (!in_list) {
183 g_object_unref(ecal);
184 continue;
185 }
186+
187 g_debug("ecal_uid is enabled, generating instances");
188-
189- e_cal_generate_instances (ecal, t1, t2, (ECalRecurInstanceFn) populate_appointment_instances, (gpointer) source);
190+ e_cal_generate_instances (ecal, t1, t2, (ECalRecurInstanceFn) populate_appointment_instances, source);
191 g_object_unref(ecal);
192 }
193 }
194+ g_slist_free_full (cal_list, g_free);
195+
196 g_debug("Number of ECalComponents returned: %d", g_list_length(comp_instances));
197 GList *sorted_comp_instances = g_list_sort(comp_instances, compare_comp_instances);
198 comp_instances = NULL;
199@@ -1000,6 +996,7 @@
200 }
201
202 dbusmenu_menuitem_property_set_image (item, APPOINTMENT_MENUITEM_PROP_ICON, pixbuf);
203+ g_clear_object (&pixbuf);
204 } else {
205 g_debug("Creating pixbuf from surface failed");
206 }
207@@ -1009,15 +1006,15 @@
208 g_debug("Adding appointment: %p", item);
209 }
210
211- if (gerror != NULL) g_error_free(gerror);
212- for (l = sorted_comp_instances; l; l = l->next) {
213- const struct comp_instance *ci = l->data;
214- g_object_unref(ci->comp);
215- }
216- g_list_free(sorted_comp_instances);
217+ g_clear_error (&gerror);
218+
219+ g_list_free_full (sorted_comp_instances, (GDestroyNotify)comp_instance_free);
220+ sorted_comp_instances = NULL;
221
222 GVariant * marks = g_variant_builder_end (&markeddays);
223 dbusmenu_menuitem_property_set_variant (calendar, CALENDAR_MENUITEM_PROP_MARKS, marks);
224+
225+ g_clear_object (&sources);
226
227 updating_appointments = FALSE;
228 g_debug("End of objects");
229@@ -1204,7 +1201,7 @@
230
231 if (error != NULL) {
232 g_warning("Could not grab DBus proxy for ConsoleKit: %s", error->message);
233- g_error_free(error);
234+ g_clear_error (&error);
235 return;
236 }
237
238@@ -1217,6 +1214,7 @@
239 {
240 if (error != NULL) {
241 g_warning("Unable to get Geoclue address: %s", error->message);
242+ g_clear_error (&error);
243 return;
244 }
245
246@@ -1278,6 +1276,7 @@
247 {
248 if (error != NULL) {
249 g_warning("Unable to create GeoClue address: %s", error->message);
250+ g_clear_error (&error);
251 return;
252 }
253
254@@ -1304,6 +1303,7 @@
255 {
256 if (error != NULL) {
257 g_warning("Unable to set Geoclue requirements: %s", error->message);
258+ g_clear_error (&error);
259 }
260 return;
261 }
262@@ -1366,6 +1366,7 @@
263
264 if (error != NULL) {
265 g_warning("Unable to get a GeoClue client! '%s' Geolocation based timezone support will not be available.", error->message);
266+ g_clear_error (&error);
267 return;
268 }
269

Subscribers

People subscribed via source and target branches