[gnome-photos/wip/rishi/online-miners] google-miner
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/online-miners] google-miner
- Date: Tue, 30 Mar 2021 21:03:22 +0000 (UTC)
commit 10ab58c70508ccb71c9b2f201c9505475589576e
Author: Debarshi Ray <debarshir gnome org>
Date: Wed Mar 24 02:08:32 2021 +0100
google-miner
https://gitlab.gnome.org/GNOME/gnome-photos/-/issues/83
po/POTFILES.in | 1 +
src/meson.build | 27 ++
src/photos-online-miner-google-main.c | 42 +++
src/photos-online-miner-google.c | 111 +++++++
src/photos-online-miner-google.h | 34 ++
src/photos-online-miner.c | 589 ++++++++++++++++++++++++++++++++++
src/photos-online-miner.h | 42 +++
7 files changed, 846 insertions(+)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index d0b3cbf9..6044c785 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -24,6 +24,7 @@ src/photos-item-manager.c
src/photos-local-item.c
src/photos-main-toolbar.c
src/photos-main-window.c
+src/photos-online-miner.c
src/photos-organize-collection-dialog.c
src/photos-preview-menu.ui
src/photos-preview-nav-buttons.c
diff --git a/src/meson.build b/src/meson.build
index de6ac503..f9d23812 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -418,6 +418,33 @@ executable(
install_rpath: photos_libdir,
)
+gnome_photos_online_miner_google_sources = files(
+ 'photos-online-miner.c',
+ 'photos-online-miner-google.c',
+ 'photos-online-miner-google-main.c',
+)
+
+deps = [
+ gio_dep,
+ gio_unix_dep,
+ glib_dep,
+ gobject_dep,
+ goa_dep,
+ libdazzle_dep,
+ libgnome_photos_dep,
+]
+
+executable(
+ meson.project_name() + '-online-miner-google',
+ gnome_photos_online_miner_google_sources,
+ include_directories: top_inc,
+ dependencies: deps,
+ c_args: cflags,
+ install: true,
+ install_dir: photos_libexecdir,
+ install_rpath: photos_libdir,
+)
+
gnome_photos_thumbnailer_sources = files(
'photos-pixbuf.c',
'photos-thumbnailer.c',
diff --git a/src/photos-online-miner-google-main.c b/src/photos-online-miner-google-main.c
new file mode 100644
index 00000000..db99dc29
--- /dev/null
+++ b/src/photos-online-miner-google-main.c
@@ -0,0 +1,42 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2021 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 as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "config.h"
+
+#include <glib.h>
+
+#include "photos-debug.h"
+#include "photos-online-miner-google.h"
+
+
+gint
+main (gint argc, gchar *argv[])
+{
+ g_autoptr (GApplication) app = NULL;
+ gint exit_status = 0;
+
+ photos_debug_init ();
+
+ g_set_prgname (PACKAGE_TARNAME "-online-miner-google");
+
+ app = photos_online_miner_google_new ();
+ exit_status = g_application_run (app, argc, argv);
+
+ return exit_status;
+}
diff --git a/src/photos-online-miner-google.c b/src/photos-online-miner-google.c
new file mode 100644
index 00000000..42102295
--- /dev/null
+++ b/src/photos-online-miner-google.c
@@ -0,0 +1,111 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2021 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 as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "config.h"
+
+#include "photos-debug.h"
+#include "photos-error.h"
+#include "photos-online-miner-google.h"
+
+
+struct _PhotosOnlineMinerGoogle
+{
+ PhotosOnlineMiner parent_instance;
+};
+
+
+G_DEFINE_TYPE (PhotosOnlineMinerGoogle, photos_online_miner_google, PHOTOS_TYPE_ONLINE_MINER);
+
+
+static void
+photos_online_miner_google_refresh_db_async (PhotosOnlineMiner *online_miner,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ PhotosOnlineMinerGoogle *self = PHOTOS_ONLINE_MINER_GOOGLE (online_miner);
+ g_autoptr (GTask) task = NULL;
+
+ task = g_task_new (self, cancellable, callback, user_data);
+ g_task_set_source_tag (task, photos_online_miner_google_refresh_db_async);
+
+ g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, "RefreshDB not supported");
+}
+
+
+static gboolean
+photos_online_miner_google_refresh_db_finish (PhotosOnlineMiner *online_miner, GAsyncResult *res, GError
**error)
+{
+ PhotosOnlineMinerGoogle *self = PHOTOS_ONLINE_MINER_GOOGLE (online_miner);
+ GTask *task;
+
+ g_return_val_if_fail (g_task_is_valid (res, self), FALSE);
+ task = G_TASK (res);
+
+ g_return_val_if_fail (g_task_get_source_tag (task) == photos_online_miner_google_refresh_db_async, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ return g_task_propagate_boolean (task, error);
+}
+
+
+static void
+photos_online_miner_google_dispose (GObject *object)
+{
+ PhotosOnlineMinerGoogle *self = PHOTOS_ONLINE_MINER_GOOGLE (object);
+
+ G_OBJECT_CLASS (photos_online_miner_google_parent_class)->dispose (object);
+}
+
+
+static void
+photos_online_miner_google_finalize (GObject *object)
+{
+ PhotosOnlineMinerGoogle *self = PHOTOS_ONLINE_MINER_GOOGLE (object);
+
+ G_OBJECT_CLASS (photos_online_miner_google_parent_class)->finalize (object);
+}
+
+
+static void
+photos_online_miner_google_init (PhotosOnlineMinerGoogle *self)
+{
+}
+
+
+static void
+photos_online_miner_google_class_init (PhotosOnlineMinerGoogleClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ PhotosOnlineMinerClass *online_miner_class = PHOTOS_ONLINE_MINER_CLASS (class);
+
+ online_miner_class->provider_type = "google";
+
+ object_class->dispose = photos_online_miner_google_dispose;
+ object_class->finalize = photos_online_miner_google_finalize;
+ online_miner_class->refresh_db_async = photos_online_miner_google_refresh_db_async;
+ online_miner_class->refresh_db_finish = photos_online_miner_google_refresh_db_finish;
+}
+
+
+GApplication *
+photos_online_miner_google_new (void)
+{
+ return g_object_new (PHOTOS_TYPE_ONLINE_MINER_GOOGLE, NULL);
+}
diff --git a/src/photos-online-miner-google.h b/src/photos-online-miner-google.h
new file mode 100644
index 00000000..c5124c8b
--- /dev/null
+++ b/src/photos-online-miner-google.h
@@ -0,0 +1,34 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2021 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 as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "photos-online-miner.h"
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_ONLINE_MINER_GOOGLE (photos_online_miner_google_get_type ())
+G_DECLARE_FINAL_TYPE (PhotosOnlineMinerGoogle,
+ photos_online_miner_google,
+ PHOTOS,
+ ONLINE_MINER_GOOGLE,
+ PhotosOnlineMiner);
+
+GApplication *photos_online_miner_google_new (void);
+
+G_END_DECLS
diff --git a/src/photos-online-miner.c b/src/photos-online-miner.c
new file mode 100644
index 00000000..d1e5658e
--- /dev/null
+++ b/src/photos-online-miner.c
@@ -0,0 +1,589 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2021 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 as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "config.h"
+
+#include <locale.h>
+#include <stdlib.h>
+
+#include <dazzle.h>
+#include <glib/gi18n.h>
+#include <goa/goa.h>
+
+#include "photos-debug.h"
+#include "photos-error.h"
+#include "photos-online-miner-dbus.h"
+#include "photos-online-miner.h"
+
+
+typedef struct _PhotosOnlineMinerPrivate PhotosOnlineMinerPrivate;
+
+struct _PhotosOnlineMinerPrivate
+{
+ GApplication parent_instance;
+ GDBusConnection *connection;
+ GError *client_error;
+ GHashTable *cancellables;
+ GoaClient *client;
+ PhotosOnlineMinerDBus *skeleton;
+ gchar *address;
+};
+
+
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (PhotosOnlineMiner, photos_online_miner, G_TYPE_APPLICATION);
+
+
+enum
+{
+ INACTIVITY_TIMEOUT = 12000 /* ms */
+};
+
+static const GOptionEntry COMMAND_LINE_OPTIONS[] =
+{
+ { "address", 0, G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, NULL, N_("D-Bus address to use"), NULL},
+ { NULL }
+};
+
+static DzlTaskCache *refresh_db_cache;
+static const gchar *ONLINE_MINER_PATH = "/org/gnome/Photos/OnlineMiner";
+
+
+static gboolean
+photos_online_miner_authorize_authenticated_peer (PhotosOnlineMiner *self,
+ GIOStream *iostream,
+ GCredentials *credentials)
+{
+ g_autoptr (GCredentials) own_credentials = NULL;
+ gboolean ret_val = FALSE;
+
+ if (credentials == NULL)
+ goto out;
+
+ own_credentials = g_credentials_new ();
+
+ {
+ g_autoptr (GError) error = NULL;
+
+ if (!g_credentials_is_same_user (credentials, own_credentials, &error))
+ {
+ g_warning ("Unable to authorize peer: %s", error->message);
+ goto out;
+ }
+ }
+
+ ret_val = TRUE;
+
+ out:
+ return ret_val;
+}
+
+
+static gboolean
+photos_online_miner_handle_cancel (PhotosOnlineMiner *self, GDBusMethodInvocation *invocation, guint serial)
+{
+ PhotosOnlineMinerPrivate *priv;
+ GCancellable *cancellable;
+ GDBusConnection *connection;
+ GDBusMethodInvocation *invocation_ongoing;
+ GHashTableIter iter;
+ const gchar *type_name;
+
+ g_return_val_if_fail (PHOTOS_IS_ONLINE_MINER (self), FALSE);
+ priv = photos_online_miner_get_instance_private (self);
+
+ g_return_val_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation), FALSE);
+
+ type_name = G_OBJECT_TYPE_NAME (self);
+ photos_debug (PHOTOS_DEBUG_ONLINE_MINER, "%s handling Cancel for %u", type_name, serial);
+
+ g_application_hold (G_APPLICATION (self));
+
+ connection = g_dbus_method_invocation_get_connection (invocation);
+
+ g_hash_table_iter_init (&iter, priv->cancellables);
+ while (g_hash_table_iter_next (&iter, (gpointer *) &invocation_ongoing, (gpointer *) &cancellable))
+ {
+ GDBusConnection *connection_ongoing;
+ GDBusMessage *message_ongoing;
+ guint32 serial_ongoing;
+
+ connection_ongoing = g_dbus_method_invocation_get_connection (invocation_ongoing);
+ message_ongoing = g_dbus_method_invocation_get_message (invocation_ongoing);
+ serial_ongoing = g_dbus_message_get_serial (message_ongoing);
+
+ if (connection == connection_ongoing && (guint32) serial == serial_ongoing)
+ {
+ g_cancellable_cancel (cancellable);
+ photos_online_miner_dbus_complete_cancel (priv->skeleton, invocation);
+ goto out;
+ }
+ }
+
+ g_dbus_method_invocation_return_error_literal (invocation, PHOTOS_ERROR, 0, "Invalid serial");
+
+ out:
+ photos_debug (PHOTOS_DEBUG_ONLINE_MINER, "%s completed Cancel", type_name);
+ g_application_release (G_APPLICATION (self));
+ return TRUE;
+}
+
+
+static void
+photos_online_miner_handle_insert_shared_content_insert_shared_content (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ PhotosOnlineMiner *self = PHOTOS_ONLINE_MINER (source_object);
+ PhotosOnlineMinerPrivate *priv;
+ g_autoptr (GDBusMethodInvocation) invocation = G_DBUS_METHOD_INVOCATION (user_data);
+ const gchar *type_name;
+
+ priv = photos_online_miner_get_instance_private (self);
+
+ /* { */
+ /* g_autoptr (GError) error = NULL; */
+
+ /* if (!photos_online_miner_google_insert_shared_content_finish (self, res, &error)) */
+ /* { */
+ /* g_dbus_method_invocation_take_error (invocation, g_steal_pointer (&error)); */
+ /* goto out; */
+ /* } */
+ /* } */
+
+ photos_online_miner_dbus_complete_insert_shared_content (priv->skeleton, invocation);
+
+ out:
+ type_name = G_OBJECT_TYPE_NAME (self);
+ photos_debug (PHOTOS_DEBUG_ONLINE_MINER, "%s completed InsertSharedContent", type_name);
+
+ g_application_release (G_APPLICATION (self));
+ g_hash_table_remove (priv->cancellables, invocation);
+}
+
+
+static gboolean
+photos_online_miner_handle_insert_shared_content (PhotosOnlineMiner *self,
+ GDBusMethodInvocation *invocation,
+ const gchar *account_id,
+ const gchar *shared_id,
+ const gchar *source_urn)
+{
+ PhotosOnlineMinerPrivate *priv;
+ g_autoptr (GCancellable) cancellable = NULL;
+ const gchar *type_name;
+
+ g_return_val_if_fail (PHOTOS_IS_ONLINE_MINER (self), FALSE);
+ priv = photos_online_miner_get_instance_private (self);
+
+ g_return_val_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation), FALSE);
+ g_return_val_if_fail (account_id != NULL && account_id[0] != '\0', FALSE);
+ g_return_val_if_fail (shared_id != NULL && shared_id[0] != '\0', FALSE);
+ g_return_val_if_fail (source_urn != NULL && source_urn[0] != '\0', FALSE);
+
+ type_name = G_OBJECT_TYPE_NAME (self);
+ photos_debug (PHOTOS_DEBUG_ONLINE_MINER, "%s handling InsertSharedContent", type_name);
+
+ cancellable = g_cancellable_new ();
+ g_hash_table_insert (priv->cancellables, g_object_ref (invocation), g_object_ref (cancellable));
+
+ g_application_hold (G_APPLICATION (self));
+
+ return TRUE;
+}
+
+
+static void
+photos_online_miner_refresh_db_async (PhotosOnlineMiner *self,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_return_if_fail (PHOTOS_IS_ONLINE_MINER (self));
+ g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
+
+ PHOTOS_ONLINE_MINER_GET_CLASS (self)->refresh_db_async (self, cancellable, callback, user_data);
+}
+
+
+static gboolean
+photos_online_miner_refresh_db_finish (PhotosOnlineMiner *self, GAsyncResult *res, GError **error)
+{
+ g_return_val_if_fail (PHOTOS_IS_ONLINE_MINER (self), FALSE);
+ g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ return PHOTOS_ONLINE_MINER_GET_CLASS (self)->refresh_db_finish (self, res, error);
+}
+
+
+static void
+photos_online_miner_handle_refresh_db_task_cache_populate_refresh_db (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ PhotosOnlineMiner *self = PHOTOS_ONLINE_MINER (source_object);
+ g_autoptr (GTask) task = G_TASK (user_data);
+
+ {
+ g_autoptr (GError) error = NULL;
+
+ if (!photos_online_miner_refresh_db_finish (self, res, &error))
+ {
+ g_task_return_error (task, g_steal_pointer (&error));
+ goto out;
+ }
+ }
+
+ g_task_return_pointer (task, GINT_TO_POINTER (TRUE), NULL);
+
+ out:
+ return;
+}
+
+
+static void
+photos_online_miner_handle_refresh_db_task_cache_populate (DzlTaskCache *cache,
+ gconstpointer key,
+ GTask *task,
+ gpointer user_data)
+{
+ PhotosOnlineMiner *self = PHOTOS_ONLINE_MINER ((gpointer) key);
+ GCancellable *cancellable;
+ g_autolist (GoaObject) accounts = NULL;
+ GList *accounts_selected = NULL;
+ GList *l;
+
+ cancellable = g_task_get_cancellable (task);
+
+ accounts = goa_client_get_accounts (priv->client);
+ for (l = accounts; l != NULL; l = l->next)
+ {
+ GoaAccount *account;
+ GoaObject *object = GOA_OBJECT (l->data);
+ const gchar *provider_type;
+
+ account = goa_object_peek_account (object);
+ if (account == NULL)
+ continue;
+
+ provider_type = goa_account_get_provider_type (account);
+ if (g_strcmp0 (provider_type, PHOTOS_ONLINE_MINER_GET_CLASS (self)->provider_type) != 0)
+ continue;
+
+ accounts_selected = g_list_prepend (accounts_selected, g_object_ref (object));
+ }
+
+ photos_online_miner_refresh_db_async (self,
+ cancellable,
+ photos_online_miner_handle_refresh_db_task_cache_populate_refresh_db,
+ g_object_ref (task));
+}
+
+
+static void
+photos_online_miner_handle_refresh_db_task_cache_get (GObject *source_object, GAsyncResult *res, gpointer
user_data)
+{
+ PhotosOnlineMiner *self;
+ PhotosOnlineMinerPrivate *priv;
+ DzlTaskCache *cache = DZL_TASK_CACHE (source_object);
+ g_autoptr (GDBusMethodInvocation) invocation = G_DBUS_METHOD_INVOCATION (user_data);
+ const gchar *method_name;
+ const gchar *type_name;
+
+ g_assert (cache == refresh_db_cache);
+
+ self = PHOTOS_ONLINE_MINER (g_application_get_default ());
+ priv = photos_online_miner_get_instance_private (self);
+
+ {
+ g_autoptr (GError) error = NULL;
+
+ /* Semantically, this should return a gboolean, but DzlTaskCache
+ * doesn't support gboolean return values, only gpointers. It's
+ * easier to rely on the GError than converting the gpointer into
+ * a gboolean.
+ */
+ dzl_task_cache_get_finish (cache, res, &error);
+ if (error != NULL)
+ {
+ g_dbus_method_invocation_take_error (invocation, g_steal_pointer (&error));
+ goto out;
+ }
+ }
+
+ photos_online_miner_dbus_complete_refresh_db (priv->skeleton, invocation);
+
+ out:
+ method_name = g_dbus_method_invocation_get_method_name (invocation);
+ type_name = G_OBJECT_TYPE_NAME (self);
+ photos_debug (PHOTOS_DEBUG_ONLINE_MINER, "%s completed %s", type_name, method_name);
+
+ g_application_release (G_APPLICATION (self));
+ dzl_task_cache_evict (cache, self);
+ g_hash_table_remove (priv->cancellables, invocation);
+}
+
+
+static gboolean
+photos_online_miner_handle_refresh_db (PhotosOnlineMiner *self, GDBusMethodInvocation *invocation)
+{
+ PhotosOnlineMinerPrivate *priv;
+ g_autoptr (GCancellable) cancellable = NULL;
+ const gchar *method_name;
+ const gchar *type_name;
+
+ g_return_val_if_fail (PHOTOS_IS_ONLINE_MINER (self), FALSE);
+ priv = photos_online_miner_get_instance_private (self);
+
+ g_return_val_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation), FALSE);
+
+ method_name = g_dbus_method_invocation_get_method_name (invocation);
+ type_name = G_OBJECT_TYPE_NAME (self);
+ photos_debug (PHOTOS_DEBUG_ONLINE_MINER, "%s handling %s", type_name, method_name);
+
+ if (G_UNLIKELY (priv->client == NULL))
+ {
+ g_dbus_method_invocation_take_error (invocation, g_error_copy (self->client_error));
+ goto out;
+ }
+
+ cancellable = g_cancellable_new ();
+ g_hash_table_insert (priv->cancellables, g_object_ref (invocation), g_object_ref (cancellable));
+
+ g_application_hold (G_APPLICATION (self));
+ dzl_task_cache_get_async (refresh_db_cache,
+ self,
+ FALSE,
+ cancellable,
+ photos_online_miner_handle_refresh_db_task_cache_get,
+ g_object_ref (invocation));
+
+ out:
+ return TRUE;
+}
+
+
+static gboolean
+photos_online_miner_dbus_register (GApplication *application,
+ GDBusConnection *connection,
+ const gchar *object_path,
+ GError **error)
+{
+ PhotosOnlineMiner *self = PHOTOS_ONLINE_MINER (application);
+ PhotosOnlineMinerPrivate *priv;
+ g_autoptr (GDBusAuthObserver) observer = NULL;
+ gboolean ret_val = FALSE;
+
+ priv = photos_online_miner_get_instance_private (self);
+
+ g_return_val_if_fail (priv->skeleton == NULL, FALSE);
+
+ if (!G_APPLICATION_CLASS (photos_online_miner_parent_class)->dbus_register (application,
+ connection,
+ object_path,
+ error))
+ {
+ goto out;
+ }
+
+ observer = g_dbus_auth_observer_new ();
+ g_signal_connect_swapped (observer,
+ "authorize-authenticated-peer",
+ G_CALLBACK (photos_online_miner_authorize_authenticated_peer),
+ self);
+
+ priv->connection = g_dbus_connection_new_for_address_sync (priv->address,
+ G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
+ observer,
+ NULL,
+ error);
+ if (priv->connection == NULL)
+ goto out;
+
+ priv->skeleton = photos_online_miner_dbus_skeleton_new ();
+ g_signal_connect_swapped (priv->skeleton, "handle-cancel", G_CALLBACK (photos_online_miner_handle_cancel),
self);
+ g_signal_connect_swapped (priv->skeleton,
+ "handle-insert-shared-content",
+ G_CALLBACK (photos_online_miner_handle_insert_shared_content),
+ self);
+ g_signal_connect_swapped (priv->skeleton,
+ "handle-refresh-db",
+ G_CALLBACK (photos_online_miner_handle_refresh_db),
+ self);
+
+ if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (priv->skeleton),
+ priv->connection,
+ ONLINE_MINER_PATH,
+ error))
+ {
+ g_clear_object (&priv->skeleton);
+ goto out;
+ }
+
+ ret_val = TRUE;
+
+ out:
+ return ret_val;
+}
+
+
+static void
+photos_online_miner_dbus_unregister (GApplication *application,
+ GDBusConnection *connection,
+ const gchar *object_path)
+{
+ PhotosOnlineMiner *self = PHOTOS_ONLINE_MINER (application);
+ PhotosOnlineMinerPrivate *priv;
+
+ priv = photos_online_miner_get_instance_private (self);
+
+ if (priv->skeleton != NULL)
+ {
+ g_dbus_interface_skeleton_unexport_from_connection (G_DBUS_INTERFACE_SKELETON (priv->skeleton),
+ priv->connection);
+ g_clear_object (&priv->skeleton);
+ }
+
+ G_APPLICATION_CLASS (photos_online_miner_parent_class)->dbus_unregister (application, connection,
object_path);
+}
+
+
+static gint
+photos_online_miner_handle_local_options (GApplication *application, GVariantDict *options)
+{
+ PhotosOnlineMiner *self = PHOTOS_ONLINE_MINER (application);
+ PhotosOnlineMinerPrivate *priv;
+ gint ret_val = EXIT_FAILURE;
+
+ priv = photos_online_miner_get_instance_private (self);
+
+ if (g_variant_dict_lookup (options, "address", "s", &priv->address))
+ ret_val = -1;
+
+ return ret_val;
+}
+
+
+static void
+photos_online_miner_shutdown (GApplication *application)
+{
+ const gchar *type_name;
+
+ type_name = G_OBJECT_TYPE_NAME (application);
+ photos_debug (PHOTOS_DEBUG_ONLINE_MINER, "%s exiting", type_name);
+
+ G_APPLICATION_CLASS (photos_online_miner_parent_class)->shutdown (application);
+}
+
+
+static void
+photos_online_miner_startup (GApplication *application)
+{
+ const gchar *type_name;
+
+ G_APPLICATION_CLASS (photos_online_miner_parent_class)->startup (application);
+
+ type_name = G_OBJECT_TYPE_NAME (application);
+ photos_debug (PHOTOS_DEBUG_ONLINE_MINER, "%s ready", type_name);
+}
+
+
+static void
+photos_online_miner_dispose (GObject *object)
+{
+ PhotosOnlineMiner *self = PHOTOS_ONLINE_MINER (object);
+ PhotosOnlineMinerPrivate *priv;
+
+ priv = photos_online_miner_get_instance_private (self);
+
+ g_assert (priv->skeleton == NULL);
+
+ dzl_task_cache_evict (refresh_db_cache, self);
+
+ g_clear_object (&priv->connection);
+ g_clear_object (&priv->client);
+ g_clear_pointer (&priv->cancellables, g_hash_table_unref);
+
+ G_OBJECT_CLASS (photos_online_miner_parent_class)->dispose (object);
+}
+
+
+static void
+photos_online_miner_finalize (GObject *object)
+{
+ PhotosOnlineMiner *self = PHOTOS_ONLINE_MINER (object);
+ PhotosOnlineMinerPrivate *priv;
+
+ priv = photos_online_miner_get_instance_private (self);
+
+ g_clear_error (&self->client_error);
+ g_free (priv->address);
+
+ G_OBJECT_CLASS (photos_online_miner_parent_class)->finalize (object);
+}
+
+
+static void
+photos_online_miner_init (PhotosOnlineMiner *self)
+{
+ PhotosOnlineMinerPrivate *priv;
+
+ priv = photos_online_miner_get_instance_private (self);
+
+ setlocale (LC_ALL, "");
+
+ bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain (GETTEXT_PACKAGE);
+
+ g_application_add_main_option_entries (G_APPLICATION (self), COMMAND_LINE_OPTIONS);
+ g_application_set_flags (G_APPLICATION (self), G_APPLICATION_IS_SERVICE | G_APPLICATION_NON_UNIQUE);
+ g_application_set_inactivity_timeout (G_APPLICATION (self), INACTIVITY_TIMEOUT);
+
+ priv->cancellables = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, g_object_unref);
+ priv->client = goa_client_new_sync (NULL, &self->client_error);
+}
+
+
+static void
+photos_online_miner_class_init (PhotosOnlineMinerClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ GApplicationClass *application_class = G_APPLICATION_CLASS (class);
+
+ object_class->dispose = photos_online_miner_dispose;
+ object_class->finalize = photos_online_miner_finalize;
+ application_class->dbus_register = photos_online_miner_dbus_register;
+ application_class->dbus_unregister = photos_online_miner_dbus_unregister;
+ application_class->handle_local_options = photos_online_miner_handle_local_options;
+ application_class->shutdown = photos_online_miner_shutdown;
+ application_class->startup = photos_online_miner_startup;
+
+ refresh_db_cache = dzl_task_cache_new (g_direct_hash,
+ g_direct_equal,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ 0,
+ photos_online_miner_handle_refresh_db_task_cache_populate,
+ NULL,
+ NULL);
+ dzl_task_cache_set_name (refresh_db_cache, "RefreshDB cache");
+}
diff --git a/src/photos-online-miner.h b/src/photos-online-miner.h
new file mode 100644
index 00000000..1ee50e74
--- /dev/null
+++ b/src/photos-online-miner.h
@@ -0,0 +1,42 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2021 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 as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_ONLINE_MINER (photos_online_miner_get_type ())
+G_DECLARE_DERIVABLE_TYPE (PhotosOnlineMiner, photos_online_miner, PHOTOS, ONLINE_MINER, GApplication);
+
+struct _PhotosOnlineMinerClass
+{
+ GApplicationClass parent_class;
+
+ const gchar *provider_type;
+
+ /* virtual methods */
+ void (*refresh_db_async) (PhotosOnlineMiner *self,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+ gboolean (*refresh_db_finish) (PhotosOnlineMiner *self, GAsyncResult *res, GError **error);
+};
+
+G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]