[epiphany/overview: 5/12] Add EphyActiveStore class files
- From: Claudio Saavedra <csaavedra src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/overview: 5/12] Add EphyActiveStore class files
- Date: Thu, 5 Apr 2012 14:16:33 +0000 (UTC)
commit be5b15fa0ed9e74c4d14f319f5f467f6b88bd445
Author: Claudio Saavedra <csaavedra igalia com>
Date: Wed Feb 22 17:45:41 2012 +0200
Add EphyActiveStore class files
This EphyOverviewStore subclass is fed by a EphyNotebook and keeps track
of changes in the pages that are part of it.
src/Makefile.am | 2 +
src/ephy-active-store.c | 390 +++++++++++++++++++++++++++++++++++++++++++++++
src/ephy-active-store.h | 70 +++++++++
3 files changed, 462 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 9e34a65..378e266 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -18,6 +18,7 @@ header_DATA = \
NOINST_H_FILES = \
ephy-action-helper.h \
+ ephy-active-store.h \
ephy-combined-stop-reload-action.h \
ephy-encoding-dialog.h \
ephy-encoding-menu.h \
@@ -53,6 +54,7 @@ INST_H_FILES = \
libephymain_la_SOURCES = \
ephy-action-helper.c \
+ ephy-active-store.c \
ephy-completion-model.c \
ephy-completion-model.h \
ephy-combined-stop-reload-action.c \
diff --git a/src/ephy-active-store.c b/src/ephy-active-store.c
new file mode 100644
index 0000000..b064e79
--- /dev/null
+++ b/src/ephy-active-store.c
@@ -0,0 +1,390 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * Copyright  2012 Igalia S.L.
+ *
+ * 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 2, 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include "ephy-notebook.h"
+#include "ephy-active-store.h"
+#include "ephy-snapshot-service.h"
+
+#define EPHY_ACTIVE_STORE_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_ACTIVE_STORE, EphyActiveStorePrivate))
+
+struct _EphyActiveStorePrivate
+{
+ EphyNotebook *notebook;
+};
+
+enum
+{
+ PROP_0,
+ PROP_NOTEBOOK
+};
+
+G_DEFINE_TYPE (EphyActiveStore, ephy_active_store, EPHY_TYPE_OVERVIEW_STORE)
+
+static void
+ephy_active_store_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EphyActiveStore *store = EPHY_ACTIVE_STORE (object);
+
+ switch (prop_id)
+ {
+ case PROP_NOTEBOOK:
+ ephy_active_store_set_notebook (store, g_value_get_object (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+ephy_active_store_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EphyActiveStore *store = EPHY_ACTIVE_STORE (object);
+
+ switch (prop_id)
+ {
+ case PROP_NOTEBOOK:
+ g_value_set_object (value, store->priv->notebook);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+ephy_active_store_class_init (EphyActiveStoreClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->get_property = ephy_active_store_get_property;
+ object_class->set_property = ephy_active_store_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_NOTEBOOK,
+ g_param_spec_object ("notebook",
+ "Notebook",
+ "The notebook holding the active pages",
+ EPHY_TYPE_NOTEBOOK,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+ g_type_class_add_private (object_class, sizeof (EphyActiveStorePrivate));
+}
+
+static void
+ephy_active_store_init (EphyActiveStore *self)
+{
+ GType types[EPHY_ACTIVE_STORE_NCOLS];
+
+ self->priv = EPHY_ACTIVE_STORE_GET_PRIVATE (self);
+
+ types[EPHY_OVERVIEW_STORE_ID] = G_TYPE_STRING;
+ types[EPHY_OVERVIEW_STORE_URI] = G_TYPE_STRING;
+ types[EPHY_OVERVIEW_STORE_TITLE] = G_TYPE_STRING;
+ types[EPHY_OVERVIEW_STORE_AUTHOR] = G_TYPE_STRING;
+ types[EPHY_OVERVIEW_STORE_SNAPSHOT] = GDK_TYPE_PIXBUF;
+ types[EPHY_OVERVIEW_STORE_LAST_VISIT] = G_TYPE_LONG;
+ types[EPHY_OVERVIEW_STORE_SELECTED] = G_TYPE_BOOLEAN;
+ types[EPHY_ACTIVE_STORE_TAB_POS] = G_TYPE_UINT;
+
+ gtk_list_store_set_column_types (GTK_LIST_STORE (self),
+ EPHY_ACTIVE_STORE_NCOLS, types);
+
+ gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self),
+ EPHY_ACTIVE_STORE_TAB_POS,
+ GTK_SORT_ASCENDING);
+}
+
+typedef void (* BindingFunc) (GtkTreeModel *model, GtkTreeIter *iter, GValue *value, gpointer data);
+
+typedef struct
+{
+ GtkTreeModel *model;
+ const char *property_name;
+ GtkTreeRowReference *row_ref;
+ guint column;
+ gboolean is_child_property;
+ BindingFunc func;
+ gpointer data;
+} Binding;
+
+static void
+on_object_notify (GObject *object,
+ GParamSpec *pspec,
+ Binding* binding)
+{
+ GValue value = G_VALUE_INIT;
+ GType type;
+ GtkTreeIter iter;
+ GtkTreePath *path;
+ const char *p_name;
+
+ p_name = g_intern_string (pspec->name);
+
+ if (p_name != binding->property_name)
+ return;
+
+ type = gtk_tree_model_get_column_type (binding->model,
+ binding->column);
+ g_value_init (&value, type);
+
+ if (binding->is_child_property) {
+ GtkWidget *widget = GTK_WIDGET (object);
+ GtkContainer *container = GTK_CONTAINER (gtk_widget_get_parent (widget));
+
+ gtk_container_child_get_property (container, widget,
+ binding->property_name, &value);
+ } else {
+ g_object_get_property (object, binding->property_name, &value);
+ }
+ path = gtk_tree_row_reference_get_path (binding->row_ref);
+ gtk_tree_model_get_iter (binding->model, &iter, path);
+ gtk_tree_path_free (path);
+
+ gtk_list_store_set_value (GTK_LIST_STORE (binding->model), &iter,
+ binding->column, &value);
+ if (binding->func)
+ (*binding->func) (binding->model, &iter, &value, binding->data);
+}
+
+static void
+bind_object_property_with_model_row_full (GtkTreeModel *model,
+ GtkTreeIter *iter,
+ guint column,
+ GObject *object,
+ const gchar *property,
+ gboolean is_child_property,
+ BindingFunc func,
+ gpointer data)
+{
+ GtkTreePath *path;
+ GParamSpec *pspec;
+ Binding* binding = g_slice_new0 (Binding);
+
+ binding->model = model;
+ binding->property_name = g_intern_string (property);
+ binding->column = column;
+ binding->func = func;
+ binding->data = data;
+ binding->is_child_property = is_child_property;
+
+ path = gtk_tree_model_get_path (model, iter);
+ binding->row_ref = gtk_tree_row_reference_new (model, path);
+
+ gtk_tree_path_free (path);
+ g_signal_connect (object, is_child_property ? "child-notify" : "notify",
+ G_CALLBACK (on_object_notify), binding);
+
+ if (is_child_property)
+ pspec = gtk_container_class_find_child_property (G_OBJECT_GET_CLASS (object),
+ property);
+ else
+ pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object),
+ property);
+
+ on_object_notify (object, pspec, binding);
+}
+
+static void
+bind_object_property_with_model_row (GtkTreeModel *model,
+ GtkTreeIter *iter,
+ guint column,
+ GObject *object,
+ const gchar *property)
+{
+ bind_object_property_with_model_row_full (model, iter, column,
+ object, property, FALSE,
+ NULL, NULL);
+}
+
+static void
+webview_uri_changed (GtkTreeModel *model,
+ GtkTreeIter *iter,
+ GValue *value,
+ gpointer data)
+{
+ ephy_overview_store_peek_snapshot (EPHY_OVERVIEW_STORE (model), iter);
+}
+
+static void
+ephy_active_store_add_from_embed (EphyActiveStore *store,
+ EphyEmbed *embed,
+ gint position)
+{
+ GtkTreeIter iter;
+ EphyWebView *webview;
+
+ webview = ephy_embed_get_web_view (embed);
+
+ gtk_list_store_insert (GTK_LIST_STORE (store), &iter, position);
+ bind_object_property_with_model_row_full (GTK_TREE_MODEL (store), &iter,
+ EPHY_OVERVIEW_STORE_URI,
+ G_OBJECT (webview), "uri", FALSE,
+ webview_uri_changed, NULL);
+ bind_object_property_with_model_row (GTK_TREE_MODEL (store), &iter,
+ EPHY_OVERVIEW_STORE_TITLE,
+ G_OBJECT (webview), "title");
+ bind_object_property_with_model_row_full (GTK_TREE_MODEL (store), &iter,
+ EPHY_ACTIVE_STORE_TAB_POS,
+ G_OBJECT (embed), "position", TRUE,
+ NULL, NULL);
+
+}
+
+static void
+bindings_drop (GObject *object)
+{
+ g_signal_handlers_disconnect_matched (object,
+ G_SIGNAL_MATCH_FUNC,
+ 0, 0, NULL, on_object_notify,
+ NULL);
+}
+
+typedef struct {
+ GtkTreeIter iter;
+ const gchar *cmp_uri;
+} HelperCtx;
+
+static gboolean
+foreach_helper (GtkTreeModel *model,
+ GtkTreePath *path,
+ GtkTreeIter *iter,
+ HelperCtx *ctx)
+{
+ const gchar *cmp_uri;
+ gchar *uri;
+
+ gtk_tree_model_get (model, iter,
+ EPHY_OVERVIEW_STORE_URI, &uri, -1);
+ cmp_uri = g_intern_string (uri);
+ g_free (uri);
+
+ if (ctx->cmp_uri == cmp_uri) {
+ ctx->iter = *iter;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static void
+ephy_active_store_remove_from_embed (EphyActiveStore *store,
+ EphyEmbed *embed)
+{
+ GtkTreeIter iter;
+ EphyWebView *webview;
+ HelperCtx *ctx;
+
+ webview = ephy_embed_get_web_view (embed);
+ ctx = g_slice_new0 (HelperCtx);
+ ctx->cmp_uri = g_intern_string (webkit_web_view_get_uri (WEBKIT_WEB_VIEW (webview)));
+ gtk_tree_model_foreach (GTK_TREE_MODEL (store),
+ (GtkTreeModelForeachFunc) foreach_helper,
+ ctx);
+ iter = ctx->iter;
+ g_slice_free (HelperCtx, ctx);
+
+ gtk_list_store_remove (GTK_LIST_STORE (store), &iter);
+
+ bindings_drop (G_OBJECT (webview));
+ bindings_drop (G_OBJECT (embed));
+}
+
+static void
+notebook_page_added_cb (EphyNotebook *notebook,
+ EphyEmbed *embed,
+ guint position,
+ EphyActiveStore *store)
+{
+ ephy_active_store_add_from_embed (store, embed, position);
+}
+
+static void
+notebook_page_removed_cb (EphyNotebook *notebook,
+ EphyEmbed *embed,
+ guint position,
+ EphyActiveStore *store)
+{
+ ephy_active_store_remove_from_embed (store, embed);
+}
+
+static void
+ephy_active_store_populate_helper (EphyEmbed *widget,
+ EphyActiveStore *store)
+{
+ ephy_active_store_add_from_embed (store, widget, G_MAXINT);
+}
+
+static void
+ephy_active_store_populate (EphyActiveStore *store)
+{
+ gtk_container_foreach (GTK_CONTAINER (store->priv->notebook),
+ (GtkCallback) ephy_active_store_populate_helper,
+ store);
+}
+
+void
+ephy_active_store_set_notebook (EphyActiveStore *store,
+ EphyNotebook *notebook)
+{
+ EphyActiveStorePrivate *priv;
+
+ g_return_if_fail (EPHY_IS_ACTIVE_STORE (store));
+ g_return_if_fail (EPHY_IS_NOTEBOOK (notebook));
+
+ if (store->priv->notebook == notebook)
+ return;
+
+ priv = store->priv;
+
+ if (priv->notebook) {
+ g_signal_handlers_disconnect_by_func (priv->notebook,
+ notebook_page_added_cb,
+ store);
+ g_signal_handlers_disconnect_by_func (priv->notebook,
+ notebook_page_removed_cb,
+ store);
+ g_object_unref (priv->notebook);
+ gtk_list_store_clear (GTK_LIST_STORE (store));
+ }
+
+ priv->notebook = g_object_ref (notebook);
+
+ g_signal_connect (notebook, "page-added",
+ G_CALLBACK (notebook_page_added_cb), store);
+ g_signal_connect (notebook, "page-removed",
+ G_CALLBACK (notebook_page_removed_cb), store);
+ ephy_active_store_populate (store);
+}
+
+EphyActiveStore *
+ephy_active_store_new (EphyNotebook *notebook)
+{
+ return g_object_new (EPHY_TYPE_ACTIVE_STORE,
+ "notebook", notebook,
+ NULL);
+}
diff --git a/src/ephy-active-store.h b/src/ephy-active-store.h
new file mode 100644
index 0000000..deb43b8
--- /dev/null
+++ b/src/ephy-active-store.h
@@ -0,0 +1,70 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ * Copyright  2012 Igalia S.L.
+ *
+ * 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 2, 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author: Claudio Saavedra <csaavedra igalia com>
+ */
+
+#ifndef _EPHY_ACTIVE_STORE_H
+#define _EPHY_ACTIVE_STORE_H
+
+#include <glib-object.h>
+
+#include "ephy-notebook.h"
+#include "ephy-overview-store.h"
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_ACTIVE_STORE (ephy_active_store_get_type())
+#define EPHY_ACTIVE_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EPHY_TYPE_ACTIVE_STORE, EphyActiveStore))
+#define EPHY_ACTIVE_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EPHY_TYPE_ACTIVE_STORE, EphyActiveStoreClass))
+#define EPHY_IS_ACTIVE_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EPHY_TYPE_ACTIVE_STORE))
+#define EPHY_IS_ACTIVE_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EPHY_TYPE_ACTIVE_STORE))
+#define EPHY_ACTIVE_STORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EPHY_TYPE_ACTIVE_STORE, EphyActiveStoreClass))
+
+typedef struct _EphyActiveStore EphyActiveStore;
+typedef struct _EphyActiveStoreClass EphyActiveStoreClass;
+typedef struct _EphyActiveStorePrivate EphyActiveStorePrivate;
+
+struct _EphyActiveStore
+{
+ EphyOverviewStore parent;
+
+ /*< priv >*/
+ EphyActiveStorePrivate *priv;
+};
+
+struct _EphyActiveStoreClass
+{
+ EphyOverviewStoreClass parent_class;
+};
+
+enum {
+ EPHY_ACTIVE_STORE_TAB_POS = EPHY_OVERVIEW_STORE_NCOLS,
+ EPHY_ACTIVE_STORE_NCOLS
+};
+
+GType ephy_active_store_get_type (void) G_GNUC_CONST;
+
+void ephy_active_store_set_notebook (EphyActiveStore *store,
+ EphyNotebook *notebook);
+
+EphyActiveStore* ephy_active_store_new (EphyNotebook *notebook);
+
+G_END_DECLS
+
+#endif /* _EPHY_ACTIVE_STORE_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]