Merge lp:~ted/indicator-application/repeating-items into lp:indicator-application/0.4

Proposed by Ted Gould
Status: Merged
Merged at revision: 189
Proposed branch: lp:~ted/indicator-application/repeating-items
Merge into: lp:indicator-application/0.4
Diff against target: 115 lines (+57/-2)
1 file modified
src/indicator-application.c (+57/-2)
To merge this branch: bzr merge lp:~ted/indicator-application/repeating-items
Reviewer Review Type Date Requested Status
Conor Curran (community) Approve
Review via email: mp+53102@code.launchpad.net

Description of the change

Fixes the duplicate indicators by handling the case when signals are emitted while we have a GetApplications in flight. We basically ignore the signals and recall the GetApplications to ensure that the response is in the correct state. This can delay startup in a few cases, but gaurantees that we won't end up in an inconsistent state.

To post a comment you must log in.
Revision history for this message
Conor Curran (cjcurran) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/indicator-application.c'
--- src/indicator-application.c 2011-02-25 03:53:44 +0000
+++ src/indicator-application.c 2011-03-11 22:44:29 +0000
@@ -86,6 +86,7 @@
86 GList * applications;86 GList * applications;
87 GHashTable * theme_dirs;87 GHashTable * theme_dirs;
88 guint disconnect_kill;88 guint disconnect_kill;
89 GCancellable * get_apps_cancel;
89};90};
9091
91typedef struct _ApplicationEntry ApplicationEntry;92typedef struct _ApplicationEntry ApplicationEntry;
@@ -166,6 +167,8 @@
166167
167 priv->theme_dirs = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);168 priv->theme_dirs = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
168169
170 priv->get_apps_cancel = NULL;
171
169 return;172 return;
170}173}
171174
@@ -178,6 +181,12 @@
178 g_source_remove(priv->disconnect_kill);181 g_source_remove(priv->disconnect_kill);
179 }182 }
180183
184 if (priv->get_apps_cancel != NULL) {
185 g_cancellable_cancel(priv->get_apps_cancel);
186 g_object_unref(priv->get_apps_cancel);
187 priv->get_apps_cancel = NULL;
188 }
189
181 while (priv->applications != NULL) {190 while (priv->applications != NULL) {
182 application_removed(INDICATOR_APPLICATION(object),191 application_removed(INDICATOR_APPLICATION(object),
183 0);192 0);
@@ -290,10 +299,20 @@
290299
291 g_signal_connect(proxy, "g-signal", G_CALLBACK(receive_signal), self);300 g_signal_connect(proxy, "g-signal", G_CALLBACK(receive_signal), self);
292301
302 /* We shouldn't be in a situation where we've already
303 called this function. It doesn't *hurt* anything, but
304 man we should look into it more. */
305 if (priv->get_apps_cancel != NULL) {
306 g_warning("Already getting applications? Odd.");
307 return;
308 }
309
310 priv->get_apps_cancel = g_cancellable_new();
311
293 /* Query it for existing applications */312 /* Query it for existing applications */
294 g_debug("Request current apps");313 g_debug("Request current apps");
295 g_dbus_proxy_call(priv->service_proxy, "GetApplications", NULL,314 g_dbus_proxy_call(priv->service_proxy, "GetApplications", NULL,
296 G_DBUS_CALL_FLAGS_NONE, -1, NULL,315 G_DBUS_CALL_FLAGS_NONE, -1, priv->get_apps_cancel,
297 get_applications, self);316 get_applications, self);
298317
299 return;318 return;
@@ -730,6 +749,22 @@
730 GVariant * parameters, gpointer user_data)749 GVariant * parameters, gpointer user_data)
731{750{
732 IndicatorApplication * self = INDICATOR_APPLICATION(user_data);751 IndicatorApplication * self = INDICATOR_APPLICATION(user_data);
752 IndicatorApplicationPrivate * priv = INDICATOR_APPLICATION_GET_PRIVATE(self);
753
754 /* If we're in the middle of a GetApplications call and we get
755 any of these our state is probably going to just be confused. Let's
756 cancel the call we had and try again to try and get a clear answer */
757 if (priv->get_apps_cancel != NULL) {
758 g_cancellable_cancel(priv->get_apps_cancel);
759 g_object_unref(priv->get_apps_cancel);
760
761 priv->get_apps_cancel = g_cancellable_new();
762
763 g_dbus_proxy_call(priv->service_proxy, "GetApplications", NULL,
764 G_DBUS_CALL_FLAGS_NONE, -1, priv->get_apps_cancel,
765 get_applications, self);
766 return;
767 }
733768
734 if (g_strcmp0(signal_name, "ApplicationAdded") == 0) {769 if (g_strcmp0(signal_name, "ApplicationAdded") == 0) {
735 const gchar * iconname;770 const gchar * iconname;
@@ -791,15 +826,35 @@
791826
792 result = g_dbus_proxy_call_finish(priv->service_proxy, res, &error);827 result = g_dbus_proxy_call_finish(priv->service_proxy, res, &error);
793828
829 /* No one can cancel us anymore, we've completed! */
830 if (priv->get_apps_cancel != NULL) {
831 if (error == NULL || error->domain != G_IO_ERROR || error->code != G_IO_ERROR_CANCELLED) {
832 g_object_unref(priv->get_apps_cancel);
833 priv->get_apps_cancel = NULL;
834 }
835 }
836
837 /* If we got an error, print it and exit out */
794 if (error != NULL) {838 if (error != NULL) {
795 g_warning("Unable to get application list: %s", error->message);839 g_warning("Unable to get application list: %s", error->message);
840 g_error_free(error);
796 return;841 return;
797 }842 }
798843
844 /* Remove all applications that we previously had
845 as we're going to repopulate the list. */
846 while (priv->applications != NULL) {
847 application_removed(self, 0);
848 }
849
850 /* Get our new applications that we got in the request */
799 g_variant_get(result, "(a(sisossss))", &iter);851 g_variant_get(result, "(a(sisossss))", &iter);
800 while ((child = g_variant_iter_next_value (iter)))852 while ((child = g_variant_iter_next_value (iter))) {
801 get_applications_helper(self, child);853 get_applications_helper(self, child);
854 g_variant_unref(child);
855 }
802 g_variant_iter_free (iter);856 g_variant_iter_free (iter);
857 g_variant_unref(result);
803858
804 return;859 return;
805}860}

Subscribers

People subscribed via source and target branches