[gnome-photos] tracker-queue: Make it fallible
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] tracker-queue: Make it fallible
- Date: Mon, 30 Dec 2013 15:13:07 +0000 (UTC)
commit f82b495a1ff5e73b1de58b91db998106b90fa818
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Dec 27 18:02:25 2013 +0100
tracker-queue: Make it fallible
PhotosTrackerQueue will not work if we fail to get a
TrackerSparqlConnection. This can happen if tracker-store is not
running.
Fixes: https://bugzilla.gnome.org/704947
src/photos-camera-cache.c | 2 +-
src/photos-collection-icon-watcher.c | 2 +-
src/photos-create-collection-job.c | 2 +-
src/photos-delete-item-job.c | 2 +-
src/photos-fetch-collection-state-job.c | 2 +-
src/photos-fetch-collections-job.c | 2 +-
src/photos-offset-controller.c | 2 +-
src/photos-set-collection-job.c | 2 +-
src/photos-single-item-job.c | 2 +-
src/photos-tracker-change-monitor.c | 2 +-
src/photos-tracker-controller.c | 2 +-
src/photos-tracker-queue.c | 46 ++++++++++++++++++++++---------
src/photos-tracker-queue.h | 2 +-
src/photos-update-mtime-job.c | 2 +-
src/photos-utils.c | 4 +-
15 files changed, 48 insertions(+), 28 deletions(-)
---
diff --git a/src/photos-camera-cache.c b/src/photos-camera-cache.c
index 64e5950..e02fdce 100644
--- a/src/photos-camera-cache.c
+++ b/src/photos-camera-cache.c
@@ -155,7 +155,7 @@ photos_camera_cache_init (PhotosCameraCache *self)
priv = self->priv;
priv->cache = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free);
- priv->queue = photos_tracker_queue_dup_singleton ();
+ priv->queue = photos_tracker_queue_dup_singleton (NULL, NULL);
}
diff --git a/src/photos-collection-icon-watcher.c b/src/photos-collection-icon-watcher.c
index d8b5186..1fa71ef 100644
--- a/src/photos-collection-icon-watcher.c
+++ b/src/photos-collection-icon-watcher.c
@@ -388,7 +388,7 @@ photos_collection_icon_watcher_init (PhotosCollectionIconWatcher *self)
priv->item_connections = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref);
priv->item_mngr = photos_item_manager_dup_singleton ();
- priv->queue = photos_tracker_queue_dup_singleton ();
+ priv->queue = photos_tracker_queue_dup_singleton (NULL, NULL);
}
diff --git a/src/photos-create-collection-job.c b/src/photos-create-collection-job.c
index ca33b28..d3cd93b 100644
--- a/src/photos-create-collection-job.c
+++ b/src/photos-create-collection-job.c
@@ -157,7 +157,7 @@ photos_create_collection_job_init (PhotosCreateCollectionJob *self)
self->priv = photos_create_collection_job_get_instance_private (self);
priv = self->priv;
- priv->queue = photos_tracker_queue_dup_singleton ();
+ priv->queue = photos_tracker_queue_dup_singleton (NULL, NULL);
}
diff --git a/src/photos-delete-item-job.c b/src/photos-delete-item-job.c
index 46bde65..5b1036c 100644
--- a/src/photos-delete-item-job.c
+++ b/src/photos-delete-item-job.c
@@ -123,7 +123,7 @@ photos_delete_item_job_init (PhotosDeleteItemJob *self)
self->priv = photos_delete_item_job_get_instance_private (self);
priv = self->priv;
- priv->queue = photos_tracker_queue_dup_singleton ();
+ priv->queue = photos_tracker_queue_dup_singleton (NULL, NULL);
}
diff --git a/src/photos-fetch-collection-state-job.c b/src/photos-fetch-collection-state-job.c
index ac5f60c..82f3cbd 100644
--- a/src/photos-fetch-collection-state-job.c
+++ b/src/photos-fetch-collection-state-job.c
@@ -232,7 +232,7 @@ photos_fetch_collection_state_job_init (PhotosFetchCollectionStateJob *self)
priv->col_mngr = photos_collection_manager_dup_singleton ();
priv->item_mngr = photos_item_manager_dup_singleton ();
priv->sel_cntrlr = photos_selection_controller_dup_singleton ();
- priv->queue = photos_tracker_queue_dup_singleton ();
+ priv->queue = photos_tracker_queue_dup_singleton (NULL, NULL);
}
diff --git a/src/photos-fetch-collections-job.c b/src/photos-fetch-collections-job.c
index 84360ae..9042527 100644
--- a/src/photos-fetch-collections-job.c
+++ b/src/photos-fetch-collections-job.c
@@ -179,7 +179,7 @@ photos_fetch_collections_job_init (PhotosFetchCollectionsJob *self)
self->priv = photos_fetch_collections_job_get_instance_private (self);
priv = self->priv;
- priv->queue = photos_tracker_queue_dup_singleton ();
+ priv->queue = photos_tracker_queue_dup_singleton (NULL, NULL);
}
diff --git a/src/photos-offset-controller.c b/src/photos-offset-controller.c
index a673fb0..657f8cc 100644
--- a/src/photos-offset-controller.c
+++ b/src/photos-offset-controller.c
@@ -119,7 +119,7 @@ photos_offset_controller_init (PhotosOffsetController *self)
self->priv = photos_offset_controller_get_instance_private (self);
priv = self->priv;
- priv->queue = photos_tracker_queue_dup_singleton ();
+ priv->queue = photos_tracker_queue_dup_singleton (NULL, NULL);
}
diff --git a/src/photos-set-collection-job.c b/src/photos-set-collection-job.c
index 609bd7d..2f7e880 100644
--- a/src/photos-set-collection-job.c
+++ b/src/photos-set-collection-job.c
@@ -164,7 +164,7 @@ photos_set_collection_job_init (PhotosSetCollectionJob *self)
priv = self->priv;
priv->sel_cntrlr = photos_selection_controller_dup_singleton ();
- priv->queue = photos_tracker_queue_dup_singleton ();
+ priv->queue = photos_tracker_queue_dup_singleton (NULL, NULL);
}
diff --git a/src/photos-single-item-job.c b/src/photos-single-item-job.c
index 63041a6..592b3a2 100644
--- a/src/photos-single-item-job.c
+++ b/src/photos-single-item-job.c
@@ -169,7 +169,7 @@ photos_single_item_job_init (PhotosSingleItemJob *self)
self->priv = photos_single_item_job_get_instance_private (self);
priv = self->priv;
- priv->queue = photos_tracker_queue_dup_singleton ();
+ priv->queue = photos_tracker_queue_dup_singleton (NULL, NULL);
}
diff --git a/src/photos-tracker-change-monitor.c b/src/photos-tracker-change-monitor.c
index e9f1fd0..bbe63b4 100644
--- a/src/photos-tracker-change-monitor.c
+++ b/src/photos-tracker-change-monitor.c
@@ -303,7 +303,7 @@ photos_tracker_change_monitor_init (PhotosTrackerChangeMonitor *self)
g_free,
(GDestroyNotify) photos_tracker_change_event_free);
- priv->queue = photos_tracker_queue_dup_singleton ();
+ 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",
diff --git a/src/photos-tracker-controller.c b/src/photos-tracker-controller.c
index 703a4c2..03c24ae 100644
--- a/src/photos-tracker-controller.c
+++ b/src/photos-tracker-controller.c
@@ -340,7 +340,7 @@ photos_tracker_controller_init (PhotosTrackerController *self)
G_CALLBACK (photos_tracker_controller_refresh_for_object),
self);
- priv->queue = photos_tracker_queue_dup_singleton ();
+ priv->queue = photos_tracker_queue_dup_singleton (NULL, NULL);
}
diff --git a/src/photos-tracker-queue.c b/src/photos-tracker-queue.c
index 79eff15..eb89a19 100644
--- a/src/photos-tracker-queue.c
+++ b/src/photos-tracker-queue.c
@@ -38,8 +38,12 @@ struct _PhotosTrackerQueuePrivate
gboolean running;
};
+static void photos_tracker_queue_initable_iface_init (GInitableIface *iface);
-G_DEFINE_TYPE_WITH_PRIVATE (PhotosTrackerQueue, photos_tracker_queue, G_TYPE_OBJECT);
+
+G_DEFINE_TYPE_WITH_CODE (PhotosTrackerQueue, photos_tracker_queue, G_TYPE_OBJECT,
+ G_ADD_PRIVATE (PhotosTrackerQueue)
+ G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, photos_tracker_queue_initable_iface_init));
typedef enum
@@ -209,21 +213,11 @@ static void
photos_tracker_queue_init (PhotosTrackerQueue *self)
{
PhotosTrackerQueuePrivate *priv = self->priv;
- GError *error;
self->priv = photos_tracker_queue_get_instance_private (self);
priv = self->priv;
priv->queue = g_queue_new ();
-
- error = NULL;
- priv->connection = tracker_sparql_connection_get (NULL, &error);
- if (error != NULL)
- {
- g_warning ("Unable to connect to the Tracker database: %s", error->message);
- g_error_free (error);
- return;
- }
}
@@ -238,10 +232,36 @@ photos_tracker_queue_class_init (PhotosTrackerQueueClass *class)
}
+static gboolean
+photos_tracker_queue_initable_init (GInitable *initable, GCancellable *cancellable, GError **error)
+{
+ PhotosTrackerQueue *self = PHOTOS_TRACKER_QUEUE (initable);
+ PhotosTrackerQueuePrivate *priv = self->priv;
+ gboolean ret_val = TRUE;
+
+ if (G_LIKELY (priv->connection != NULL))
+ goto out;
+
+ priv->connection = tracker_sparql_connection_get (cancellable, error);
+ if (G_UNLIKELY (priv->connection == NULL))
+ ret_val = FALSE;
+
+ out:
+ return ret_val;
+}
+
+
+static void
+photos_tracker_queue_initable_iface_init (GInitableIface *iface)
+{
+ iface->init = photos_tracker_queue_initable_init;
+}
+
+
PhotosTrackerQueue *
-photos_tracker_queue_dup_singleton (void)
+photos_tracker_queue_dup_singleton (GCancellable *cancellable, GError **error)
{
- return g_object_new (PHOTOS_TYPE_TRACKER_QUEUE, NULL);
+ return g_initable_new (PHOTOS_TYPE_TRACKER_QUEUE, cancellable, error, NULL);
}
diff --git a/src/photos-tracker-queue.h b/src/photos-tracker-queue.h
index 6563c4d..eac6951 100644
--- a/src/photos-tracker-queue.h
+++ b/src/photos-tracker-queue.h
@@ -68,7 +68,7 @@ struct _PhotosTrackerQueueClass
GType photos_tracker_queue_get_type (void) G_GNUC_CONST;
-PhotosTrackerQueue *photos_tracker_queue_dup_singleton (void);
+PhotosTrackerQueue *photos_tracker_queue_dup_singleton (GCancellable *cancellable, GError
**error);
void photos_tracker_queue_select (PhotosTrackerQueue *self,
const gchar *sparql,
diff --git a/src/photos-update-mtime-job.c b/src/photos-update-mtime-job.c
index 85a2c14..4ce603f 100644
--- a/src/photos-update-mtime-job.c
+++ b/src/photos-update-mtime-job.c
@@ -124,7 +124,7 @@ photos_update_mtime_job_init (PhotosUpdateMtimeJob *self)
self->priv = photos_update_mtime_job_get_instance_private (self);
priv = self->priv;
- priv->queue = photos_tracker_queue_dup_singleton ();
+ priv->queue = photos_tracker_queue_dup_singleton (NULL, NULL);
}
diff --git a/src/photos-utils.c b/src/photos-utils.c
index 209f2a5..e9bec14 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -657,7 +657,7 @@ photos_utils_set_edited_name (const gchar *urn, const gchar *title)
gchar *sparql;
sparql = g_strdup_printf ("INSERT OR REPLACE { <%s> nie:title \"%s\" }", urn, title);
- queue = photos_tracker_queue_dup_singleton ();
+ queue = photos_tracker_queue_dup_singleton (NULL, NULL);
photos_tracker_queue_update (queue, sparql, NULL, photos_utils_update_executed, g_strdup (urn), g_free);
g_object_unref (queue);
g_free (sparql);
@@ -674,7 +674,7 @@ photos_utils_set_favorite (const gchar *urn, gboolean is_favorite)
(is_favorite) ? "INSERT OR REPLACE" : "DELETE",
urn);
- queue = photos_tracker_queue_dup_singleton ();
+ queue = photos_tracker_queue_dup_singleton (NULL, NULL);
photos_tracker_queue_update (queue, sparql, NULL, photos_utils_update_executed, g_strdup (urn), g_free);
g_object_unref (queue);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]