[gnome-photos] tracker-change-monitor: Make it fallible



commit 696672b030dfdada2f8a6f65811244e067b9edc8
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Dec 30 13:13:55 2013 +0100

    tracker-change-monitor: Make it fallible
    
    PhotosTrackerChangeMonitor will not work if we fail to get a
    TrackerSparqlConnection or TrackerResources. This can hapen if
    tracker-store is not running.
    
    Fixes: https://bugzilla.gnome.org/704947

 src/photos-embed.c                  |   17 +++++---
 src/photos-item-manager.c           |    5 +-
 src/photos-tracker-change-monitor.c |   70 +++++++++++++++++++++++++++--------
 src/photos-tracker-change-monitor.h |    8 ++--
 4 files changed, 71 insertions(+), 29 deletions(-)
---
diff --git a/src/photos-embed.c b/src/photos-embed.c
index 866684b..77db8d4 100644
--- a/src/photos-embed.c
+++ b/src/photos-embed.c
@@ -256,7 +256,9 @@ photos_embed_hide_no_results_page (PhotosEmbed *self)
 {
   PhotosEmbedPrivate *priv = self->priv;
 
-  g_signal_handlers_disconnect_by_func (priv->monitor, photos_embed_changes_pending, self);
+  if (G_LIKELY (priv->monitor != NULL))
+    g_signal_handlers_disconnect_by_func (priv->monitor, photos_embed_changes_pending, self);
+
   photos_embed_restore_last_page (self);
 }
 
@@ -280,11 +282,12 @@ photos_embed_count_changed (PhotosEmbed *self, gint count)
 
   if (count == 0)
     {
-      g_signal_connect_object (priv->monitor,
-                               "changes-pending",
-                               G_CALLBACK (photos_embed_changes_pending),
-                               self,
-                               G_CONNECT_SWAPPED);
+      if (G_LIKELY (priv->monitor != NULL))
+        g_signal_connect_object (priv->monitor,
+                                 "changes-pending",
+                                 G_CALLBACK (photos_embed_changes_pending),
+                                 self,
+                                 G_CONNECT_SWAPPED);
       gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "no-results");
     }
   else
@@ -552,7 +555,7 @@ photos_embed_init (PhotosEmbed *self)
   querying = photos_tracker_controller_get_query_status (priv->trk_ovrvw_cntrlr);
   photos_embed_query_status_changed (priv->trk_ovrvw_cntrlr, querying, self);
 
-  priv->monitor = photos_tracker_change_monitor_dup_singleton ();
+  priv->monitor = photos_tracker_change_monitor_dup_singleton (NULL, NULL);
 
   gtk_widget_show (GTK_WIDGET (self));
 }
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index 3d23ebe..b5ee500 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -222,8 +222,9 @@ photos_item_manager_init (PhotosItemManager *self)
   priv->collection_path = g_queue_new ();
   priv->col_mngr = photos_collection_manager_dup_singleton ();
 
-  priv->monitor = photos_tracker_change_monitor_dup_singleton ();
-  g_signal_connect (priv->monitor, "changes-pending", G_CALLBACK (photos_item_manager_changes_pending), 
self);
+  priv->monitor = photos_tracker_change_monitor_dup_singleton (NULL, NULL);
+  if (G_LIKELY (priv->monitor != NULL))
+    g_signal_connect (priv->monitor, "changes-pending", G_CALLBACK (photos_item_manager_changes_pending), 
self);
 }
 
 
diff --git a/src/photos-tracker-change-monitor.c b/src/photos-tracker-change-monitor.c
index bbe63b4..3bca59d 100644
--- a/src/photos-tracker-change-monitor.c
+++ b/src/photos-tracker-change-monitor.c
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2012 Red Hat, Inc.
+ * Copyright © 2012, 2013 Red Hat, Inc.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -51,8 +51,12 @@ enum
 
 static guint signals[LAST_SIGNAL] = { 0 };
 
+static void photos_tracker_change_monitor_initable_iface_init (GInitableIface *iface);
 
-G_DEFINE_TYPE_WITH_PRIVATE (PhotosTrackerChangeMonitor, photos_tracker_change_monitor, G_TYPE_OBJECT);
+
+G_DEFINE_TYPE_WITH_CODE (PhotosTrackerChangeMonitor, photos_tracker_change_monitor, G_TYPE_OBJECT,
+                         G_ADD_PRIVATE (PhotosTrackerChangeMonitor)
+                         G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, 
photos_tracker_change_monitor_initable_iface_init));
 
 
 typedef struct _PhotosTrackerChangeMonitorQueryData PhotosTrackerChangeMonitorQueryData;
@@ -302,18 +306,6 @@ photos_tracker_change_monitor_init (PhotosTrackerChangeMonitor *self)
                                          g_str_equal,
                                          g_free,
                                          (GDestroyNotify) photos_tracker_change_event_free);
-
-  priv->queue = photos_tracker_queue_dup_singleton (NULL, NULL);
-  priv->resource_service = tracker_resources_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
-                                                                     G_DBUS_PROXY_FLAGS_NONE,
-                                                                     "org.freedesktop.Tracker1",
-                                                                     "/org/freedesktop/Tracker1/Resources",
-                                                                     NULL,
-                                                                     NULL);
-  g_signal_connect (priv->resource_service,
-                    "graph-updated",
-                    G_CALLBACK (photos_tracker_change_monitor_graph_updated),
-                    self);
 }
 
 
@@ -338,8 +330,54 @@ photos_tracker_change_monitor_class_init (PhotosTrackerChangeMonitorClass *class
 }
 
 
+static gboolean
+photos_tracker_change_monitor_initable_init (GInitable *initable, GCancellable *cancellable, GError **error)
+{
+  PhotosTrackerChangeMonitor *self = PHOTOS_TRACKER_CHANGE_MONITOR (initable);
+  PhotosTrackerChangeMonitorPrivate *priv = self->priv;
+  gboolean ret_val = TRUE;
+
+  if (G_LIKELY (priv->queue != NULL && priv->resource_service != NULL))
+    goto out;
+
+  priv->queue = photos_tracker_queue_dup_singleton (cancellable, error);
+  if (G_UNLIKELY (priv->queue == NULL))
+    {
+      ret_val = FALSE;
+      goto out;
+    }
+
+  priv->resource_service = tracker_resources_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+                                                                     G_DBUS_PROXY_FLAGS_NONE,
+                                                                     "org.freedesktop.Tracker1",
+                                                                     "/org/freedesktop/Tracker1/Resources",
+                                                                     cancellable,
+                                                                     error);
+  if (G_UNLIKELY (priv->resource_service == NULL))
+    {
+      ret_val = FALSE;
+      goto out;
+    }
+
+  g_signal_connect (priv->resource_service,
+                    "graph-updated",
+                    G_CALLBACK (photos_tracker_change_monitor_graph_updated),
+                    self);
+
+ out:
+  return ret_val;
+}
+
+
+static void
+photos_tracker_change_monitor_initable_iface_init (GInitableIface *iface)
+{
+  iface->init = photos_tracker_change_monitor_initable_init;
+}
+
+
 PhotosTrackerChangeMonitor *
-photos_tracker_change_monitor_dup_singleton (void)
+photos_tracker_change_monitor_dup_singleton (GCancellable *cancellable, GError **error)
 {
-  return g_object_new (PHOTOS_TYPE_TRACKER_CHANGE_MONITOR, NULL);
+  return g_initable_new (PHOTOS_TYPE_TRACKER_CHANGE_MONITOR, cancellable, error, NULL);
 }
diff --git a/src/photos-tracker-change-monitor.h b/src/photos-tracker-change-monitor.h
index 032f0ce..84fcf2f 100644
--- a/src/photos-tracker-change-monitor.h
+++ b/src/photos-tracker-change-monitor.h
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2012 Red Hat, Inc.
+ * Copyright © 2012, 2013 Red Hat, Inc.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -25,8 +25,7 @@
 #ifndef PHOTOS_TRACKER_CHANGE_MONITOR_H
 #define PHOTOS_TRACKER_CHANGE_MONITOR_H
 
-#include <glib.h>
-#include <glib-object.h>
+#include <gio/gio.h>
 
 G_BEGIN_DECLS
 
@@ -72,7 +71,8 @@ struct _PhotosTrackerChangeMonitorClass
 
 GType                        photos_tracker_change_monitor_get_type         (void) G_GNUC_CONST;
 
-PhotosTrackerChangeMonitor  *photos_tracker_change_monitor_dup_singleton    (void);
+PhotosTrackerChangeMonitor  *photos_tracker_change_monitor_dup_singleton    (GCancellable *cancellable,
+                                                                             GError **error);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]