[gnome-photos/sam/tracker3] Use TrackerNotifier to monitor for local changes
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/sam/tracker3] Use TrackerNotifier to monitor for local changes
- Date: Sun, 2 Aug 2020 15:34:23 +0000 (UTC)
commit 121695cb3c7e88d0c88c0af5bfd7fec5356a8f8c
Author: Sam Thursfield <sam afuera me uk>
Date: Sun Aug 2 15:57:42 2020 +0200
Use TrackerNotifier to monitor for local changes
Closes https://gitlab.gnome.org/GNOME/gnome-photos/-/issues/59
src/meson.build | 12 -
src/photos-item-manager.c | 56 +++--
src/photos-tracker-change-event.c | 136 -----------
src/photos-tracker-change-event.h | 64 -----
src/photos-tracker-change-monitor.c | 468 ------------------------------------
src/photos-tracker-change-monitor.h | 42 ----
src/photos-tracker-queue.c | 65 +++--
src/photos-tracker-queue.h | 2 +
src/photos-tracker-resources.xml | 31 ---
9 files changed, 63 insertions(+), 813 deletions(-)
---
diff --git a/src/meson.build b/src/meson.build
index eb538a87..fef9f759 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -118,8 +118,6 @@ sources = files(
'photos-tool-filter-button.c',
'photos-tool-filters.c',
'photos-tool.c',
- 'photos-tracker-change-event.c',
- 'photos-tracker-change-monitor.c',
'photos-tracker-collection-view-controller.c',
'photos-tracker-collections-controller.c',
'photos-tracker-controller.c',
@@ -340,16 +338,6 @@ sources += gnome.gdbus_codegen(
autocleanup: 'all',
)
-tracker_resources = 'photos-tracker-resources'
-
-sources += gnome.gdbus_codegen(
- tracker_resources,
- tracker_resources + '.xml',
- interface_prefix: 'org.freedesktop.Tracker3.',
- namespace: 'Tracker',
- autocleanup: 'all',
-)
-
cflags = [
'-DPACKAGE_LIBEXEC_DIR="@0@"'.format(photos_libexecdir),
'-DPACKAGE_LOCALE_DIR="@0@"'.format(photos_localedir),
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index a431ebb7..549606e5 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -41,8 +41,6 @@
#include "photos-query.h"
#include "photos-search-context.h"
#include "photos-single-item-job.h"
-#include "photos-tracker-change-event.h"
-#include "photos-tracker-change-monitor.h"
#include "photos-tracker-queue.h"
#include "photos-utils.h"
@@ -60,7 +58,7 @@ struct _PhotosItemManager
PhotosBaseItem *active_collection;
PhotosBaseManager **item_mngr_chldrn;
PhotosLoadState load_state;
- PhotosTrackerChangeMonitor *monitor;
+ TrackerNotifier *notifier;
PhotosTrackerQueue *queue;
PhotosWindowMode mode;
gboolean fullscreen;
@@ -529,21 +527,23 @@ photos_item_manager_item_created (PhotosItemManager *self, const gchar *urn)
static void
-photos_item_manager_changes_pending_foreach (gpointer key, gpointer value, gpointer user_data)
+photos_item_manager_changes_pending_foreach (gpointer data,
+ gpointer user_data)
{
PhotosItemManager *self = PHOTOS_ITEM_MANAGER (user_data);
- PhotosTrackerChangeEvent *change_event = (PhotosTrackerChangeEvent *) value;
- PhotosTrackerChangeEventType change_type;
+ TrackerNotifierEvent *event = (TrackerNotifierEvent *) data;
+ TrackerNotifierEventType change_type;
const gchar *change_urn;
- change_type = photos_tracker_change_event_get_type (change_event);
- change_urn = photos_tracker_change_event_get_urn (change_event);
+ change_type = tracker_notifier_event_get_event_type (event);
+ change_urn = tracker_notifier_event_get_urn (event);
- if (change_type == PHOTOS_TRACKER_CHANGE_EVENT_CHANGED)
+ if (change_type == TRACKER_NOTIFIER_EVENT_UPDATE)
{
GObject *object;
object = photos_base_manager_get_object_by_id (PHOTOS_BASE_MANAGER (self), change_urn);
+ g_message ("UPDATE event for %s, object %p", change_urn, object);
if (object != NULL)
{
photos_base_item_refresh (PHOTOS_BASE_ITEM (object));
@@ -557,15 +557,17 @@ photos_item_manager_changes_pending_foreach (gpointer key, gpointer value, gpoin
}
}
}
- else if (change_type == PHOTOS_TRACKER_CHANGE_EVENT_CREATED)
+ else if (change_type == TRACKER_NOTIFIER_EVENT_CREATE)
{
+ g_message ("CREATE event for %s", change_urn);
photos_item_manager_item_created (self, change_urn);
}
- else if (change_type == PHOTOS_TRACKER_CHANGE_EVENT_DELETED)
+ else if (change_type == TRACKER_NOTIFIER_EVENT_DELETE)
{
GObject *object;
object = photos_base_manager_get_object_by_id (PHOTOS_BASE_MANAGER (self), change_urn);
+ g_message ("DELETE event for %s, object %p", change_urn, object);
if (object != NULL)
{
photos_base_item_destroy (PHOTOS_BASE_ITEM (object));
@@ -577,9 +579,13 @@ photos_item_manager_changes_pending_foreach (gpointer key, gpointer value, gpoin
static void
-photos_item_manager_changes_pending (PhotosItemManager *self, GHashTable *changes)
+photos_item_manager_changes_pending (PhotosItemManager *self,
+ const gchar *service,
+ const gchar *graph,
+ GPtrArray *events,
+ gpointer user_data)
{
- g_hash_table_foreach (changes, photos_item_manager_changes_pending_foreach, self);
+ g_ptr_array_foreach (events, photos_item_manager_changes_pending_foreach, self);
}
@@ -1038,7 +1044,7 @@ photos_item_manager_dispose (GObject *object)
g_clear_object (&self->active_object);
g_clear_object (&self->loader_cancellable);
g_clear_object (&self->active_collection);
- g_clear_object (&self->monitor);
+ g_clear_object (&self->notifier);
g_clear_object (&self->queue);
G_OBJECT_CLASS (photos_item_manager_parent_class)->dispose (object);
@@ -1093,20 +1099,24 @@ photos_item_manager_init (PhotosItemManager *self)
self->mode = PHOTOS_WINDOW_MODE_NONE;
- self->monitor = photos_tracker_change_monitor_dup_singleton (NULL, NULL);
- if (G_LIKELY (self->monitor != NULL))
- g_signal_connect_object (self->monitor,
- "changes-pending",
- G_CALLBACK (photos_item_manager_changes_pending),
- self,
- G_CONNECT_SWAPPED);
-
{
g_autoptr (GError) error = NULL;
self->queue = photos_tracker_queue_dup_singleton (NULL, &error);
if (G_UNLIKELY (error != NULL))
- g_warning ("Unable to create PhotosTrackerQueue: %s", error->message);
+ {
+ g_warning ("Unable to create PhotosTrackerQueue: %s", error->message);
+ self->notifier = NULL;
+ }
+ else
+ {
+ self->notifier = photos_tracker_queue_get_notifier (self->queue);
+ g_signal_connect_object (self->notifier,
+ "events",
+ G_CALLBACK (photos_item_manager_changes_pending),
+ self,
+ G_CONNECT_SWAPPED);
+ }
}
self->fullscreen = FALSE;
diff --git a/src/photos-tracker-queue.c b/src/photos-tracker-queue.c
index 32e3fb18..83f1b181 100644
--- a/src/photos-tracker-queue.c
+++ b/src/photos-tracker-queue.c
@@ -37,7 +37,8 @@ struct _PhotosTrackerQueue
GObject parent_instance;
GError *initialization_error;
GQueue *queue;
- TrackerSparqlConnection *connection;
+ TrackerSparqlConnection *local_connection;
+ TrackerSparqlConnection *miner_fs_connection;
gboolean is_initialized;
gboolean running;
gboolean miner_fs_ready;
@@ -187,7 +188,7 @@ photos_tracker_queue_check (PhotosTrackerQueue *self)
switch (data->query_type)
{
case PHOTOS_TRACKER_QUERY_SELECT:
- tracker_sparql_connection_query_async (self->connection,
+ tracker_sparql_connection_query_async (self->local_connection,
sparql,
data->cancellable,
photos_tracker_queue_collector,
@@ -195,7 +196,7 @@ photos_tracker_queue_check (PhotosTrackerQueue *self)
break;
case PHOTOS_TRACKER_QUERY_UPDATE:
- tracker_sparql_connection_update_async (self->connection,
+ tracker_sparql_connection_update_async (self->local_connection,
sparql,
data->cancellable,
photos_tracker_queue_collector,
@@ -203,7 +204,7 @@ photos_tracker_queue_check (PhotosTrackerQueue *self)
break;
case PHOTOS_TRACKER_QUERY_UPDATE_BLANK:
- tracker_sparql_connection_update_blank_async (self->connection,
+ tracker_sparql_connection_update_blank_async (self->local_connection,
sparql,
data->cancellable,
photos_tracker_queue_collector,
@@ -219,13 +220,12 @@ photos_tracker_queue_check (PhotosTrackerQueue *self)
static const gchar *
photos_tracker_queue_start_session_miner_fs (PhotosTrackerQueue *self, GError **error)
{
- g_autoptr(TrackerSparqlConnection) miner_fs = NULL;
const gchar *busname = "org.freedesktop.Tracker3.Miner.Files";
- miner_fs = tracker_sparql_connection_bus_new (busname, NULL, NULL, error);
+ photos_debug (PHOTOS_DEBUG_TRACKER, "Connecting to %s", busname);
+ self->miner_fs_connection = tracker_sparql_connection_bus_new (busname, NULL, NULL, error);
if (*error)
{
- /* Creating the connection should always succeed, so this is weird. */
g_warning ("Unable to create connection for session-wide Tracker indexer: %s", (*error)->message);
return NULL;
}
@@ -236,30 +236,10 @@ photos_tracker_queue_start_session_miner_fs (PhotosTrackerQueue *self, GError **
static const gchar *
photos_tracker_queue_start_local_miner_fs (PhotosTrackerQueue *self, GError **error)
{
- GDBusConnection *bus;
const gchar *busname = "org.gnome.Photos.Tracker3.Miner.Files";
- bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
-
- if (*error)
- {
- g_critical ("Could not connect to session bus: %s", (*error)->message);
- return NULL;
- }
-
- photos_debug (PHOTOS_DEBUG_TRACKER, "Contacting %s", busname);
- g_dbus_connection_call_sync (bus,
- busname,
- "/org/freedesktop/Tracker3/Miner/Files",
- "org.freedesktop.DBus.Peer",
- "Ping",
- NULL,
- NULL,
- G_DBUS_CALL_FLAGS_NONE,
- 5000, /* Startup timeout for miner-fs in msec */
- NULL,
- error);
-
+ photos_debug (PHOTOS_DEBUG_TRACKER, "Connecting to %s", busname);
+ self->miner_fs_connection = tracker_sparql_connection_bus_new (busname, NULL, NULL, error);
if (*error)
{
g_critical ("Could not start local Tracker indexer at %s: %s", busname, (*error)->message);
@@ -298,7 +278,8 @@ photos_tracker_queue_dispose (GObject *object)
{
PhotosTrackerQueue *self = PHOTOS_TRACKER_QUEUE (object);
- g_clear_object (&self->connection);
+ g_clear_object (&self->local_connection);
+ g_clear_object (&self->miner_fs_connection);
G_OBJECT_CLASS (photos_tracker_queue_parent_class)->dispose (object);
}
@@ -396,7 +377,7 @@ photos_tracker_queue_initable_init (GInitable *initable, GCancellable *cancellab
if (self->is_initialized)
{
- if (self->connection != NULL)
+ if (self->local_connection != NULL && self->miner_fs_connection != NULL)
ret_val = TRUE;
else
g_assert_nonnull (self->initialization_error);
@@ -418,11 +399,11 @@ photos_tracker_queue_initable_init (GInitable *initable, GCancellable *cancellab
store = g_file_new_build_filename (g_get_user_data_dir (), "gnome-photos", NULL);
photos_debug (PHOTOS_DEBUG_TRACKER, "Opening local database at %s", g_file_peek_path (store));
- self->connection = tracker_sparql_connection_new (tracker_flags,
- store,
- tracker_sparql_get_ontology_nepomuk (),
- cancellable,
- &self->initialization_error);
+ self->local_connection = tracker_sparql_connection_new (tracker_flags,
+ store,
+ tracker_sparql_get_ontology_nepomuk (),
+ cancellable,
+ &self->initialization_error);
if (G_UNLIKELY (self->initialization_error != NULL))
goto out;
@@ -444,7 +425,8 @@ photos_tracker_queue_initable_init (GInitable *initable, GCancellable *cancellab
else
{
photos_debug (PHOTOS_DEBUG_TRACKER, "Initialization failed due to %s",
self->initialization_error->message);
- g_clear_object (&self->connection);
+ g_clear_object (&self->miner_fs_connection);
+ g_clear_object (&self->local_connection);
ret_val = FALSE;
}
@@ -493,6 +475,15 @@ photos_tracker_queue_get_miner_fs_busname (PhotosTrackerQueue *self)
return self->miner_fs_busname;
}
+TrackerNotifier *
+photos_tracker_queue_get_notifier (PhotosTrackerQueue *self)
+{
+ /* We want notifications on filesystem changes, we don't need them for the
+ * local database which we manage ourselves.
+ */
+ return tracker_sparql_connection_create_notifier (self->miner_fs_connection);
+}
+
void
photos_tracker_queue_select (PhotosTrackerQueue *self,
PhotosQuery *query,
diff --git a/src/photos-tracker-queue.h b/src/photos-tracker-queue.h
index 2a7118fc..20a62e26 100644
--- a/src/photos-tracker-queue.h
+++ b/src/photos-tracker-queue.h
@@ -24,6 +24,7 @@
#define PHOTOS_TRACKER_QUEUE_H
#include <gio/gio.h>
+#include <libtracker-sparql/tracker-sparql.h>
#include "photos-query.h"
@@ -35,6 +36,7 @@ G_DECLARE_FINAL_TYPE (PhotosTrackerQueue, photos_tracker_queue, PHOTOS, TRACKER_
PhotosTrackerQueue *photos_tracker_queue_dup_singleton (GCancellable *cancellable, GError
**error);
const gchar * photos_tracker_queue_get_miner_fs_busname (PhotosTrackerQueue *self);
+TrackerNotifier * photos_tracker_queue_get_notifier (PhotosTrackerQueue *self);
void photos_tracker_queue_select (PhotosTrackerQueue *self,
PhotosQuery *query,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]