[epiphany/wip/sync: 71/74] sync: Remove dependency on embed
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/sync: 71/74] sync: Remove dependency on embed
- Date: Sun, 6 Aug 2017 14:33:03 +0000 (UTC)
commit 37f1a7bf7a2808e3034c342a4edf11872dc30f0a
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date: Tue Aug 1 17:39:25 2017 +0300
sync: Remove dependency on embed
embed/ephy-embed-shell.c | 54 ++++++++++++++++++-
lib/sync/ephy-open-tabs-manager.c | 111 ++++++++++++++++++++++++++-----------
lib/sync/ephy-open-tabs-manager.h | 3 +-
lib/sync/ephy-sync-service.c | 9 +--
lib/sync/ephy-tabs-catalog.c | 75 +++++++++++++++++++++++++
lib/sync/ephy-tabs-catalog.h | 50 +++++++++++++++++
lib/sync/meson.build | 4 +-
src/ephy-shell.c | 2 +-
8 files changed, 266 insertions(+), 42 deletions(-)
---
diff --git a/embed/ephy-embed-shell.c b/embed/ephy-embed-shell.c
index 88c3526..ac09eea 100644
--- a/embed/ephy-embed-shell.c
+++ b/embed/ephy-embed-shell.c
@@ -25,6 +25,7 @@
#include "ephy-about-handler.h"
#include "ephy-dbus-util.h"
#include "ephy-debug.h"
+#include "ephy-embed-container.h"
#include "ephy-embed-prefs.h"
#include "ephy-embed-type-builtins.h"
#include "ephy-embed-utils.h"
@@ -35,6 +36,7 @@
#include "ephy-profile-utils.h"
#include "ephy-settings.h"
#include "ephy-snapshot-service.h"
+#include "ephy-tabs-catalog.h"
#include "ephy-uri-tester-shared.h"
#include "ephy-web-app-utils.h"
#include "ephy-web-extension-proxy.h"
@@ -94,7 +96,57 @@ static GParamSpec *object_properties[N_PROPERTIES] = { NULL, };
static EphyEmbedShell *embed_shell = NULL;
-G_DEFINE_TYPE_WITH_PRIVATE (EphyEmbedShell, ephy_embed_shell, GTK_TYPE_APPLICATION)
+static void ephy_embed_shell_tabs_catalog_iface_init (EphyTabsCatalogInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (EphyEmbedShell, ephy_embed_shell, GTK_TYPE_APPLICATION,
+ G_ADD_PRIVATE (EphyEmbedShell)
+ G_IMPLEMENT_INTERFACE (EPHY_TYPE_TABS_CATALOG,
+ ephy_embed_shell_tabs_catalog_iface_init))
+
+static GSList *
+tabs_catalog_get_tabs_info (EphyTabsCatalog *catalog)
+{
+ EphyEmbedShell *embed_shell = EPHY_EMBED_SHELL (catalog);
+ WebKitFaviconDatabase *database;
+ GList *windows;
+ GList *tabs;
+ GSList *tabs_info = NULL;
+ const char *title;
+ const char *url;
+ char *favicon;
+
+ windows = gtk_application_get_windows (GTK_APPLICATION (embed_shell));
+ database = webkit_web_context_get_favicon_database (ephy_embed_shell_get_web_context (embed_shell));
+
+ for (GList *l = windows; l && l->data; l = l->next) {
+ tabs = ephy_embed_container_get_children (l->data);
+
+ for (GList *t = tabs; t && t->data; t = t->next) {
+ title = ephy_embed_get_title (t->data);
+
+ if (!g_strcmp0 (title, _(BLANK_PAGE_TITLE)) || !g_strcmp0 (title, _(OVERVIEW_PAGE_TITLE)))
+ continue;
+
+ url = ephy_web_view_get_display_address (ephy_embed_get_web_view (t->data));
+ favicon = webkit_favicon_database_get_favicon_uri (database, url);
+
+ tabs_info = g_slist_prepend (tabs_info,
+ ephy_tab_info_new (title, url, favicon));
+
+ g_free (favicon);
+ }
+
+ g_list_free (tabs);
+ }
+
+ return tabs_info;
+}
+
+static void
+ephy_embed_shell_tabs_catalog_iface_init (EphyTabsCatalogInterface *iface)
+{
+ iface->get_tabs_info = tabs_catalog_get_tabs_info;
+}
static void
ephy_embed_shell_dispose (GObject *object)
diff --git a/lib/sync/ephy-open-tabs-manager.c b/lib/sync/ephy-open-tabs-manager.c
index 9ed8aba..49fc56a 100644
--- a/lib/sync/ephy-open-tabs-manager.c
+++ b/lib/sync/ephy-open-tabs-manager.c
@@ -21,9 +21,6 @@
#include "config.h"
#include "ephy-open-tabs-manager.h"
-#include "ephy-embed-container.h"
-#include "ephy-embed-shell.h"
-#include "ephy-embed-utils.h"
#include "ephy-settings.h"
#include "ephy-sync-utils.h"
#include "ephy-synchronizable-manager.h"
@@ -31,6 +28,8 @@
struct _EphyOpenTabsManager {
GObject parent_instance;
+ EphyTabsCatalog *catalog;
+
/* A list of EphyOpenTabsRecord objects describing the open tabs
* of other sync clients. This is updated at every sync. */
GSList *remote_records;
@@ -42,6 +41,50 @@ G_DEFINE_TYPE_WITH_CODE (EphyOpenTabsManager, ephy_open_tabs_manager, G_TYPE_OBJ
G_IMPLEMENT_INTERFACE (EPHY_TYPE_SYNCHRONIZABLE_MANAGER,
ephy_synchronizable_manager_iface_init))
+enum {
+ PROP_0,
+ PROP_TABS_CATALOG,
+ LAST_PROP
+};
+
+static GParamSpec *obj_properties[LAST_PROP];
+
+static void
+ephy_open_tabs_manager_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EphyOpenTabsManager *self = EPHY_OPEN_TABS_MANAGER (object);
+
+ switch (prop_id) {
+ case PROP_TABS_CATALOG:
+ if (self->catalog)
+ g_object_unref (self->catalog);
+ self->catalog = g_object_ref (g_value_get_object (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+ephy_open_tabs_manager_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EphyOpenTabsManager *self = EPHY_OPEN_TABS_MANAGER (object);
+
+ switch (prop_id) {
+ case PROP_TABS_CATALOG:
+ g_value_set_object (value, self->catalog);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
static void
ephy_open_tabs_manager_finalize (GObject *object)
{
@@ -53,11 +96,33 @@ ephy_open_tabs_manager_finalize (GObject *object)
}
static void
+ephy_open_tabs_manager_dispose (GObject *object)
+{
+ EphyOpenTabsManager *self = EPHY_OPEN_TABS_MANAGER (object);
+
+ g_clear_object (&self->catalog);
+
+ G_OBJECT_CLASS (ephy_open_tabs_manager_parent_class)->dispose (object);
+}
+
+static void
ephy_open_tabs_manager_class_init (EphyOpenTabsManagerClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->set_property = ephy_open_tabs_manager_set_property;
+ object_class->get_property = ephy_open_tabs_manager_get_property;
+ object_class->dispose = ephy_open_tabs_manager_dispose;
object_class->finalize = ephy_open_tabs_manager_finalize;
+
+ obj_properties[PROP_TABS_CATALOG] =
+ g_param_spec_object ("tabs-catalog",
+ "Tabs catalog",
+ "Tabs Catalog",
+ EPHY_TYPE_TABS_CATALOG,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (object_class, LAST_PROP, obj_properties);
}
static void
@@ -66,55 +131,37 @@ ephy_open_tabs_manager_init (EphyOpenTabsManager *self)
}
EphyOpenTabsManager *
-ephy_open_tabs_manager_new (void)
+ephy_open_tabs_manager_new (EphyTabsCatalog *catalog)
{
- return EPHY_OPEN_TABS_MANAGER (g_object_new (EPHY_TYPE_OPEN_TABS_MANAGER, NULL));
+ return EPHY_OPEN_TABS_MANAGER (g_object_new (EPHY_TYPE_OPEN_TABS_MANAGER,
+ "tabs-catalog", catalog,
+ NULL));
}
EphyOpenTabsRecord *
ephy_open_tabs_manager_get_local_tabs (EphyOpenTabsManager *self)
{
EphyOpenTabsRecord *local_tabs;
- WebKitFaviconDatabase *database;
- EphyEmbedShell *embed_shell;
- GList *windows;
- GList *tabs;
- char *favicon;
+ EphyTabInfo *info;
+ GSList *tabs_info;
char *id;
char *name;
- const char *title;
- const char *url;
g_return_val_if_fail (EPHY_IS_OPEN_TABS_MANAGER (self), NULL);
- embed_shell = ephy_embed_shell_get_default ();
- windows = gtk_application_get_windows (GTK_APPLICATION (embed_shell));
- database = webkit_web_context_get_favicon_database (ephy_embed_shell_get_web_context (embed_shell));
id = ephy_sync_utils_get_device_id ();
name = ephy_sync_utils_get_device_name ();
local_tabs = ephy_open_tabs_record_new (id, name);
- for (GList *l = windows; l && l->data; l = l->next) {
- tabs = ephy_embed_container_get_children (l->data);
-
- for (GList *t = tabs; t && t->data; t = t->next) {
- title = ephy_embed_get_title (t->data);
-
- if (!g_strcmp0 (title, _(BLANK_PAGE_TITLE)) || !g_strcmp0 (title, _(OVERVIEW_PAGE_TITLE)))
- continue;
-
- url = ephy_web_view_get_display_address (ephy_embed_get_web_view (t->data));
- favicon = webkit_favicon_database_get_favicon_uri (database, url);
- ephy_open_tabs_record_add_tab (local_tabs, title, url, favicon);
-
- g_free (favicon);
- }
-
- g_list_free (tabs);
+ tabs_info = ephy_tabs_catalog_get_tabs_info (self->catalog);
+ for (GSList *l = tabs_info; l && l->data; l = l->next) {
+ info = (EphyTabInfo *)l->data;
+ ephy_open_tabs_record_add_tab (local_tabs, info->title, info->url, info->favicon);
}
g_free (id);
g_free (name);
+ g_slist_free_full (tabs_info, (GDestroyNotify)ephy_tab_info_free);
return local_tabs;
}
diff --git a/lib/sync/ephy-open-tabs-manager.h b/lib/sync/ephy-open-tabs-manager.h
index 166539e..a588329 100644
--- a/lib/sync/ephy-open-tabs-manager.h
+++ b/lib/sync/ephy-open-tabs-manager.h
@@ -21,6 +21,7 @@
#pragma once
#include "ephy-open-tabs-record.h"
+#include "ephy-tabs-catalog.h"
#include <glib-object.h>
@@ -30,7 +31,7 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (EphyOpenTabsManager, ephy_open_tabs_manager, EPHY, OPEN_TABS_MANAGER, GObject)
-EphyOpenTabsManager *ephy_open_tabs_manager_new (void);
+EphyOpenTabsManager *ephy_open_tabs_manager_new (EphyTabsCatalog *catalog);
EphyOpenTabsRecord *ephy_open_tabs_manager_get_local_tabs (EphyOpenTabsManager *self);
GSList *ephy_open_tabs_manager_get_remote_tabs (EphyOpenTabsManager *self);
void ephy_open_tabs_manager_clear_cache (EphyOpenTabsManager *self);
diff --git a/lib/sync/ephy-sync-service.c b/lib/sync/ephy-sync-service.c
index 0115132..677fcd0 100644
--- a/lib/sync/ephy-sync-service.c
+++ b/lib/sync/ephy-sync-service.c
@@ -22,7 +22,6 @@
#include "ephy-sync-service.h"
#include "ephy-debug.h"
-#include "ephy-embed-prefs.h"
#include "ephy-notification.h"
#include "ephy-settings.h"
#include "ephy-sync-crypto.h"
@@ -30,6 +29,7 @@
#include <glib/gi18n.h>
#include <json-glib/json-glib.h>
+#include <libsoup/soup.h>
#include <string.h>
#define EPHY_STORAGE_VERSION 5
@@ -1611,15 +1611,14 @@ static void
ephy_sync_service_constructed (GObject *object)
{
EphySyncService *self = EPHY_SYNC_SERVICE (object);
- WebKitSettings *settings;
- const char *user_agent;
G_OBJECT_CLASS (ephy_sync_service_parent_class)->constructed (object);
if (self->sync_periodically) {
- settings = ephy_embed_prefs_get_settings ();
- user_agent = webkit_settings_get_user_agent (settings);
+ char *user_agent = g_settings_get_string (EPHY_SETTINGS_WEB,
+ EPHY_PREFS_WEB_USER_AGENT);
g_object_set (self->session, "user-agent", user_agent, NULL);
+ g_free (user_agent);
g_signal_connect (EPHY_SETTINGS_SYNC, "changed::"EPHY_PREFS_SYNC_FREQUENCY,
G_CALLBACK (sync_frequency_changed_cb), self);
diff --git a/lib/sync/ephy-tabs-catalog.c b/lib/sync/ephy-tabs-catalog.c
new file mode 100644
index 0000000..3d7cb84
--- /dev/null
+++ b/lib/sync/ephy-tabs-catalog.c
@@ -0,0 +1,75 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * Copyright © 2017 Gabriel Ivascu <ivascu gabriel59 gmail com>
+ *
+ * This file is part of Epiphany.
+ *
+ * Epiphany 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.
+ *
+ * Epiphany 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 Epiphany. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include "ephy-tabs-catalog.h"
+
+G_DEFINE_INTERFACE (EphyTabsCatalog, ephy_tabs_catalog, G_TYPE_OBJECT);
+
+static void
+ephy_tabs_catalog_default_init (EphyTabsCatalogInterface *iface)
+{
+ iface->get_tabs_info = ephy_tabs_catalog_get_tabs_info;
+}
+
+/**
+ * ephy_tabs_catalog_get_tabs_info:
+ * @catalog: an #EphyTabsCatalog
+ *
+ * Returns the title, URL and favicon URI of every tab of @catalog.
+ *
+ * Return value: (transfer full): a #GSList of #EphyTabInfo
+ **/
+GSList *
+ephy_tabs_catalog_get_tabs_info (EphyTabsCatalog *catalog)
+{
+ EphyTabsCatalogInterface *iface;
+
+ g_return_val_if_fail (EPHY_IS_TABS_CATALOG (catalog), NULL);
+
+ iface = EPHY_TABS_CATALOG_GET_IFACE (catalog);
+ return iface->get_tabs_info (catalog);
+}
+
+EphyTabInfo *
+ephy_tab_info_new (const char *title,
+ const char *url,
+ const char *favicon)
+{
+ EphyTabInfo *info;
+
+ info = g_slice_new (EphyTabInfo);
+ info->title = g_strdup (title);
+ info->url = g_strdup (url);
+ info->favicon = g_strdup (favicon);
+
+ return info;
+}
+
+void
+ephy_tab_info_free (EphyTabInfo *info)
+{
+ g_return_if_fail (info);
+
+ g_free (info->title);
+ g_free (info->url);
+ g_free (info->favicon);
+ g_slice_free (EphyTabInfo, info);
+}
diff --git a/lib/sync/ephy-tabs-catalog.h b/lib/sync/ephy-tabs-catalog.h
new file mode 100644
index 0000000..b4669d9
--- /dev/null
+++ b/lib/sync/ephy-tabs-catalog.h
@@ -0,0 +1,50 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * Copyright © 2017 Gabriel Ivascu <ivascu gabriel59 gmail com>
+ *
+ * This file is part of Epiphany.
+ *
+ * Epiphany 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.
+ *
+ * Epiphany 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 Epiphany. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_TABS_CATALOG (ephy_tabs_catalog_get_type ())
+
+G_DECLARE_INTERFACE (EphyTabsCatalog, ephy_tabs_catalog, EPHY, TABS_CATALOG, GObject)
+
+struct _EphyTabsCatalogInterface {
+ GTypeInterface parent_iface;
+
+ GSList * (*get_tabs_info) (EphyTabsCatalog *catalog);
+};
+
+GSList *ephy_tabs_catalog_get_tabs_info (EphyTabsCatalog *catalog);
+
+typedef struct {
+ char *title;
+ char *url;
+ char *favicon;
+} EphyTabInfo;
+
+EphyTabInfo *ephy_tab_info_new (const char *title,
+ const char *url,
+ const char *favicon);
+void ephy_tab_info_free (EphyTabInfo *info);
+
+G_END_DECLS
diff --git a/lib/sync/meson.build b/lib/sync/meson.build
index ae6f72d..6851b6c 100644
--- a/lib/sync/meson.build
+++ b/lib/sync/meson.build
@@ -9,7 +9,8 @@ libephysync_sources = [
'ephy-sync-crypto.c',
'ephy-sync-service.c',
'ephy-synchronizable-manager.c',
- 'ephy-synchronizable.c'
+ 'ephy-synchronizable.c',
+ 'ephy-tabs-catalog.c'
]
libephysync_deps = [
@@ -29,7 +30,6 @@ libephysync_includes = include_directories(
'../history',
'../widgets',
'../..',
- '../../embed',
'debug'
)
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index 4830102..ed931cd 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -941,7 +941,7 @@ ephy_shell_get_open_tabs_manager (EphyShell *shell)
g_return_val_if_fail (EPHY_IS_SHELL (shell), NULL);
if (shell->open_tabs_manager == NULL)
- shell->open_tabs_manager = ephy_open_tabs_manager_new ();
+ shell->open_tabs_manager = ephy_open_tabs_manager_new (EPHY_TABS_CATALOG (shell));
return shell->open_tabs_manager;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]