[gnome-photos/wip/rishi/online-miners: 27/27] google-miner
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/online-miners: 27/27] google-miner
- Date: Sun, 28 Mar 2021 02:35:09 +0000 (UTC)
commit a6261c0f34a57f68c2433395f69be76776e8db51
Author: Debarshi Ray <debarshir gnome org>
Date: Sat Mar 20 21:39:38 2021 +0100
google-miner
https://gitlab.gnome.org/GNOME/gnome-photos/-/issues/83
po/POTFILES.in | 1 +
src/meson.build | 24 ++
src/photos-online-miner-google-main.c | 42 ++++
src/photos-online-miner-google.c | 410 ++++++++++++++++++++++++++++++++++
src/photos-online-miner-google.h | 34 +++
5 files changed, 511 insertions(+)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index d0b3cbf9..8bacea48 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-google.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..97f29498 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -418,6 +418,30 @@ executable(
install_rpath: photos_libdir,
)
+gnome_photos_online_miner_google_sources = files(
+ 'photos-online-miner-google.c',
+ 'photos-online-miner-google-main.c',
+)
+
+deps = [
+ gio_dep,
+ gio_unix_dep,
+ glib_dep,
+ gobject_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..b22ce3a8
--- /dev/null
+++ b/src/photos-online-miner-google.c
@@ -0,0 +1,410 @@
+/*
+ * 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 <glib/gi18n.h>
+
+#include "photos-debug.h"
+#include "photos-error.h"
+#include "photos-online-miner-dbus.h"
+#include "photos-online-miner-google.h"
+
+
+struct _PhotosOnlineMinerGoogle
+{
+ GApplication parent_instance;
+ GDBusConnection *connection;
+ GHashTable *cancellables;
+ PhotosOnlineMinerDBus *skeleton;
+ gchar *address;
+};
+
+
+G_DEFINE_TYPE (PhotosOnlineMinerGoogle, photos_online_miner_google, 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 const gchar *ONLINE_MINER_PATH = "/org/gnome/Photos/OnlineMiner";
+
+
+static gboolean
+photos_online_miner_google_authorize_authenticated_peer (PhotosOnlineMinerGoogle *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_google_handle_cancel (PhotosOnlineMinerGoogle *self,
+ GDBusMethodInvocation *invocation,
+ guint serial)
+{
+ GCancellable *cancellable;
+ GDBusConnection *connection;
+ GDBusMethodInvocation *invocation_ongoing;
+ GHashTableIter iter;
+
+ g_return_val_if_fail (PHOTOS_IS_ONLINE_MINER_GOOGLE (self), FALSE);
+ g_return_val_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation), FALSE);
+
+ photos_debug (PHOTOS_DEBUG_ONLINE_MINER, "PhotosOnlineMinerGoogle handling Cancel for %u", serial);
+ g_application_hold (G_APPLICATION (self));
+
+ connection = g_dbus_method_invocation_get_connection (invocation);
+
+ g_hash_table_iter_init (&iter, self->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 (self->skeleton, invocation);
+ goto out;
+ }
+ }
+
+ g_dbus_method_invocation_return_error_literal (invocation, PHOTOS_ERROR, 0, "Invalid serial");
+
+ out:
+ photos_debug (PHOTOS_DEBUG_ONLINE_MINER, "PhotosOnlineMinerGoogle completed Cancel");
+ g_application_release (G_APPLICATION (self));
+ return TRUE;
+}
+
+
+static void
+photos_online_miner_google_handle_insert_shared_content_insert_shared_content (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ PhotosOnlineMinerGoogle *self = PHOTOS_ONLINE_MINER_GOOGLE (source_object);
+ g_autoptr (GDBusMethodInvocation) invocation = G_DBUS_METHOD_INVOCATION (user_data);
+
+ /* { */
+ /* 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 (self->skeleton, invocation);
+
+ out:
+ photos_debug (PHOTOS_DEBUG_ONLINE_MINER, "PhotosOnlineMinerGoogle completed InsertSharedContent");
+ g_application_release (G_APPLICATION (self));
+ g_hash_table_remove (self->cancellables, invocation);
+}
+
+
+static gboolean
+photos_online_miner_google_handle_insert_shared_content (PhotosOnlineMinerGoogle *self,
+ GDBusMethodInvocation *invocation,
+ const gchar *account_id,
+ const gchar *shared_id,
+ const gchar *source_urn)
+{
+ g_autoptr (GCancellable) cancellable = NULL;
+
+ g_return_val_if_fail (PHOTOS_IS_ONLINE_MINER_GOOGLE (self), FALSE);
+ 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);
+
+ photos_debug (PHOTOS_DEBUG_ONLINE_MINER, "PhotosOnlineMinerGoogle handling InsertSharedContent");
+
+ cancellable = g_cancellable_new ();
+ g_hash_table_insert (self->cancellables, g_object_ref (invocation), g_object_ref (cancellable));
+
+ g_application_hold (G_APPLICATION (self));
+
+ return TRUE;
+}
+
+
+static void
+photos_online_miner_google_handle_refresh_db_refresh_db (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ PhotosOnlineMinerGoogle *self = PHOTOS_ONLINE_MINER_GOOGLE (source_object);
+ g_autoptr (GDBusMethodInvocation) invocation = G_DBUS_METHOD_INVOCATION (user_data);
+
+ /* { */
+ /* g_autoptr (GError) error = NULL; */
+
+ /* if (!photos_online_miner_google_refresh_db_finish (self, res, &error)) */
+ /* { */
+ /* g_dbus_method_invocation_take_error (invocation, g_steal_pointer (&error)); */
+ /* goto out; */
+ /* } */
+ /* } */
+
+ photos_online_miner_dbus_complete_refresh_db (self->skeleton, invocation);
+
+ out:
+ photos_debug (PHOTOS_DEBUG_ONLINE_MINER, "PhotosOnlineMinerGoogle completed RefreshDB");
+ g_application_release (G_APPLICATION (self));
+ g_hash_table_remove (self->cancellables, invocation);
+}
+
+
+static gboolean
+photos_online_miner_google_handle_refresh_db (PhotosOnlineMinerGoogle *self, GDBusMethodInvocation
*invocation)
+{
+ g_autoptr (GCancellable) cancellable = NULL;
+
+ g_return_val_if_fail (PHOTOS_IS_ONLINE_MINER_GOOGLE (self), FALSE);
+ g_return_val_if_fail (G_IS_DBUS_METHOD_INVOCATION (invocation), FALSE);
+
+ photos_debug (PHOTOS_DEBUG_ONLINE_MINER, "PhotosOnlineMinerGoogle handling RefreshDB");
+
+ cancellable = g_cancellable_new ();
+ g_hash_table_insert (self->cancellables, g_object_ref (invocation), g_object_ref (cancellable));
+
+ g_application_hold (G_APPLICATION (self));
+
+ return TRUE;
+}
+
+
+static gboolean
+photos_online_miner_google_dbus_register (GApplication *application,
+ GDBusConnection *connection,
+ const gchar *object_path,
+ GError **error)
+{
+ PhotosOnlineMinerGoogle *self = PHOTOS_ONLINE_MINER_GOOGLE (application);
+ g_autoptr (GDBusAuthObserver) observer = NULL;
+ gboolean ret_val = FALSE;
+
+ g_return_val_if_fail (self->skeleton == NULL, FALSE);
+
+ if (!G_APPLICATION_CLASS (photos_online_miner_google_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_google_authorize_authenticated_peer),
+ self);
+
+ self->connection = g_dbus_connection_new_for_address_sync (self->address,
+ G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
+ observer,
+ NULL,
+ error);
+ if (self->connection == NULL)
+ goto out;
+
+ self->skeleton = photos_online_miner_dbus_skeleton_new ();
+ g_signal_connect_swapped (self->skeleton,
+ "handle-cancel",
+ G_CALLBACK (photos_online_miner_google_handle_cancel),
+ self);
+ g_signal_connect_swapped (self->skeleton,
+ "handle-insert-shared-content",
+ G_CALLBACK (photos_online_miner_google_handle_insert_shared_content),
+ self);
+ g_signal_connect_swapped (self->skeleton,
+ "handle-refresh-db",
+ G_CALLBACK (photos_online_miner_google_handle_refresh_db),
+ self);
+
+ if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (self->skeleton),
+ self->connection,
+ ONLINE_MINER_PATH,
+ error))
+ {
+ g_clear_object (&self->skeleton);
+ goto out;
+ }
+
+ ret_val = TRUE;
+
+ out:
+ return ret_val;
+}
+
+
+static void
+photos_online_miner_google_dbus_unregister (GApplication *application,
+ GDBusConnection *connection,
+ const gchar *object_path)
+{
+ PhotosOnlineMinerGoogle *self = PHOTOS_ONLINE_MINER_GOOGLE (application);
+
+ if (self->skeleton != NULL)
+ {
+ g_dbus_interface_skeleton_unexport_from_connection (G_DBUS_INTERFACE_SKELETON (self->skeleton),
+ self->connection);
+ g_clear_object (&self->skeleton);
+ }
+
+ G_APPLICATION_CLASS (photos_online_miner_google_parent_class)->dbus_unregister (application,
+ connection,
+ object_path);
+}
+
+
+static gint
+photos_online_miner_google_handle_local_options (GApplication *application, GVariantDict *options)
+{
+ PhotosOnlineMinerGoogle *self = PHOTOS_ONLINE_MINER_GOOGLE (application);
+ gint ret_val = EXIT_FAILURE;
+
+ if (g_variant_dict_lookup (options, "address", "s", &self->address))
+ ret_val = -1;
+
+ return ret_val;
+}
+
+
+static void
+photos_online_miner_google_shutdown (GApplication *application)
+{
+ photos_debug (PHOTOS_DEBUG_ONLINE_MINER, "PhotosOnlineMinerGoogle exiting");
+ G_APPLICATION_CLASS (photos_online_miner_google_parent_class)->shutdown (application);
+}
+
+
+static void
+photos_online_miner_google_startup (GApplication *application)
+{
+ G_APPLICATION_CLASS (photos_online_miner_google_parent_class)->startup (application);
+ photos_debug (PHOTOS_DEBUG_ONLINE_MINER, "PhotosOnlineMinerGoogle ready");
+}
+
+
+static void
+photos_online_miner_google_dispose (GObject *object)
+{
+ PhotosOnlineMinerGoogle *self = PHOTOS_ONLINE_MINER_GOOGLE (object);
+
+ g_assert (self->skeleton == NULL);
+
+ g_clear_object (&self->connection);
+ g_clear_pointer (&self->cancellables, g_hash_table_unref);
+
+ 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_free (self->address);
+
+ G_OBJECT_CLASS (photos_online_miner_google_parent_class)->finalize (object);
+}
+
+
+static void
+photos_online_miner_google_init (PhotosOnlineMinerGoogle *self)
+{
+ setlocale (LC_ALL, "");
+
+ bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain (GETTEXT_PACKAGE);
+
+ self->cancellables = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, g_object_unref);
+ g_application_add_main_option_entries (G_APPLICATION (self), COMMAND_LINE_OPTIONS);
+}
+
+
+static void
+photos_online_miner_google_class_init (PhotosOnlineMinerGoogleClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ GApplicationClass *application_class = G_APPLICATION_CLASS (class);
+
+ object_class->dispose = photos_online_miner_google_dispose;
+ object_class->finalize = photos_online_miner_google_finalize;
+ application_class->dbus_register = photos_online_miner_google_dbus_register;
+ application_class->dbus_unregister = photos_online_miner_google_dbus_unregister;
+ application_class->handle_local_options = photos_online_miner_google_handle_local_options;
+ application_class->shutdown = photos_online_miner_google_shutdown;
+ application_class->startup = photos_online_miner_google_startup;
+}
+
+
+GApplication *
+photos_online_miner_google_new (void)
+{
+ return g_object_new (PHOTOS_TYPE_ONLINE_MINER_GOOGLE,
+ "flags", G_APPLICATION_IS_SERVICE | G_APPLICATION_NON_UNIQUE,
+ "inactivity-timeout", INACTIVITY_TIMEOUT,
+ NULL);
+}
diff --git a/src/photos-online-miner-google.h b/src/photos-online-miner-google.h
new file mode 100644
index 00000000..c9927fff
--- /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 <gio/gio.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,
+ GApplication);
+
+GApplication *photos_online_miner_google_new (void);
+
+G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]