[epiphany/in-tab-overview: 19/23] Add EphyOverview widget



commit b8a468a6290b67c76e3e9634124bf8231d4fd9e4
Author: Claudio Saavedra <csaavedra igalia com>
Date:   Thu Apr 5 16:18:24 2012 +0300

    Add EphyOverview widget
    
    This widget entails two GdMainViews, one for the frecency model and
    one for the active model.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=455173

 embed/Makefile.am     |    2 +
 embed/ephy-overview.c |  143 +++++++++++++++++++++++++++++++++++++++++++++++++
 embed/ephy-overview.h |   58 ++++++++++++++++++++
 3 files changed, 203 insertions(+), 0 deletions(-)
---
diff --git a/embed/Makefile.am b/embed/Makefile.am
index f2e7ddc..610a710 100644
--- a/embed/Makefile.am
+++ b/embed/Makefile.am
@@ -27,6 +27,7 @@ INST_H_FILES = \
 	ephy-embed-single.h		\
 	ephy-embed-shell.h		\
 	ephy-embed-utils.h              \
+	ephy-overview.h			\
 	ephy-permission-manager.h       \
 	ephy-web-view.h
 
@@ -50,6 +51,7 @@ libephyembed_la_SOURCES = \
 	ephy-encoding.c			\
 	ephy-encodings.c		\
 	ephy-file-monitor.c		\
+	ephy-overview.c			\
 	ephy-permission-manager.c	\
 	ephy-request-about.c		\
 	ephy-embed-prefs.c		\
diff --git a/embed/ephy-overview.c b/embed/ephy-overview.c
new file mode 100644
index 0000000..00265e2
--- /dev/null
+++ b/embed/ephy-overview.c
@@ -0,0 +1,143 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
+/* vim: set sw=2 ts=2 sts=2 et: */
+/*
+ *  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-overview.h"
+
+#include "ephy-embed-shell.h"
+#include "ephy-frecent-store.h"
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#define EPHY_OVERVIEW_GET_PRIVATE(object) (G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_OVERVIEW, EphyOverviewPrivate))
+
+struct _EphyOverviewPrivate
+{
+  GtkWidget *frecent_view;
+};
+
+G_DEFINE_TYPE (EphyOverview, ephy_overview, GTK_TYPE_GRID)
+
+static gboolean
+frecent_view_item_deleted (GtkWidget *widget,
+                           gchar *path,
+                           gpointer data)
+{
+  EphyFrecentStore *store;
+  GtkTreeIter iter;
+  GtkTreePath *tree_path;
+
+  store = EPHY_FRECENT_STORE (gd_main_view_get_model (GD_MAIN_VIEW (widget)));
+  tree_path = gtk_tree_path_new_from_string (path);
+  gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, tree_path);
+  ephy_frecent_store_set_hidden (store, &iter);
+  gtk_tree_path_free (tree_path);
+
+  return TRUE;
+}
+
+static void
+main_view_item_activated (GtkWidget *widget,
+                          gchar *id,
+                          GtkTreePath *path,
+                          EphyOverview *overview)
+{
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  char *url;
+
+  model = gd_main_view_get_model (GD_MAIN_VIEW (widget));
+  gtk_tree_model_get_iter (model, &iter, path);
+  gtk_tree_model_get (model, &iter,
+                      EPHY_OVERVIEW_STORE_URI, &url,
+                      -1);
+  g_signal_emit_by_name (overview, "open-link", url);
+  g_free (url);
+}
+
+static void
+ephy_overview_constructed (GObject *object)
+{
+  EphyOverviewStore *store;
+  EphyOverview *self = EPHY_OVERVIEW (object);
+  GtkWidget *widget;
+
+  if (G_OBJECT_CLASS (ephy_overview_parent_class)->constructed)
+    G_OBJECT_CLASS (ephy_overview_parent_class)->constructed (object);
+
+  self->priv->frecent_view = GTK_WIDGET (gd_main_view_new (GD_MAIN_VIEW_ICON));
+  gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (self->priv->frecent_view),
+                                       GTK_SHADOW_NONE);
+  widget = gtk_bin_get_child (GTK_BIN (self->priv->frecent_view));
+  gtk_widget_set_valign (widget, GTK_ALIGN_CENTER);
+  gtk_widget_set_halign (widget, GTK_ALIGN_CENTER);
+  gtk_icon_view_set_columns (GTK_ICON_VIEW (widget), 5);
+
+  g_signal_connect (self->priv->frecent_view, "item-activated",
+                    G_CALLBACK (main_view_item_activated), object);
+  g_signal_connect (self->priv->frecent_view, "item-deleted",
+                    G_CALLBACK (frecent_view_item_deleted), NULL);
+
+  store = EPHY_OVERVIEW_STORE (ephy_embed_shell_get_frecent_store (ephy_embed_shell_get_default ()));
+  gd_main_view_set_model (GD_MAIN_VIEW (self->priv->frecent_view),
+                          GTK_TREE_MODEL (store));
+  gtk_grid_attach (GTK_GRID (self), self->priv->frecent_view,
+                   0, 0, 1, 1);
+  gtk_widget_set_vexpand (self->priv->frecent_view, TRUE);
+  gtk_widget_set_size_request (self->priv->frecent_view, -1, 320);
+
+  gtk_widget_show_all (GTK_WIDGET (self));
+}
+
+static void
+ephy_overview_class_init (EphyOverviewClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->constructed  = ephy_overview_constructed;
+
+  g_signal_new ("open-link",
+                EPHY_TYPE_OVERVIEW,
+                G_SIGNAL_RUN_LAST,
+                0, NULL, NULL,
+                g_cclosure_marshal_generic,
+                G_TYPE_NONE,
+                1,
+                G_TYPE_STRING);
+
+  g_type_class_add_private (object_class, sizeof (EphyOverviewPrivate));
+}
+
+static void
+ephy_overview_init (EphyOverview *self)
+{
+  self->priv = EPHY_OVERVIEW_GET_PRIVATE (self);
+  gtk_orientable_set_orientation (GTK_ORIENTABLE (self),
+                                  GTK_ORIENTATION_VERTICAL);
+}
+
+GtkWidget *
+ephy_overview_new (void)
+{
+  return g_object_new (EPHY_TYPE_OVERVIEW,
+                       NULL);
+}
diff --git a/embed/ephy-overview.h b/embed/ephy-overview.h
new file mode 100644
index 0000000..0b99016
--- /dev/null
+++ b/embed/ephy-overview.h
@@ -0,0 +1,58 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
+/* vim: set sw=2 ts=2 sts=2 et: */
+/*
+ *  Copyright  2011, 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.
+ *
+ */
+
+#ifndef _EPHY_OVERVIEW_H
+#define _EPHY_OVERVIEW_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_OVERVIEW ephy_overview_get_type()
+
+#define EPHY_OVERVIEW(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), EPHY_TYPE_OVERVIEW, EphyOverview))
+#define EPHY_OVERVIEW_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), EPHY_TYPE_OVERVIEW, EphyOverviewClass))
+#define EPHY_IS_OVERVIEW(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EPHY_TYPE_OVERVIEW))
+#define EPHY_IS_OVERVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EPHY_TYPE_OVERVIEW))
+#define EPHY_OVERVIEW_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), EPHY_TYPE_OVERVIEW, EphyOverviewClass))
+
+typedef struct _EphyOverview            EphyOverview;
+typedef struct _EphyOverviewClass       EphyOverviewClass;
+typedef struct _EphyOverviewPrivate     EphyOverviewPrivate;
+
+struct _EphyOverview {
+  GtkGrid parent;
+
+  /*< private >*/
+  EphyOverviewPrivate *priv;
+};
+
+struct _EphyOverviewClass {
+  GtkGridClass parent_class;
+
+};
+
+GType       ephy_overview_get_type      (void) G_GNUC_CONST;
+GtkWidget * ephy_overview_new           (void);
+
+G_END_DECLS
+
+#endif /* _EPHY_OVERVIEW_H */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]