[epiphany/overview: 8/26] Add EphyOverview widget



commit 395afe8fa717862201a3bb91f062d9f133ad8214
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

 src/Makefile.am     |    2 +
 src/ephy-overview.c |  197 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/ephy-overview.h |   60 ++++++++++++++++
 3 files changed, 259 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 17c3523..7e9e451 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -29,6 +29,7 @@ NOINST_H_FILES = \
 	ephy-link-action.h			\
 	ephy-lockdown.h				\
 	ephy-location-controller.h		\
+	ephy-overview.h				\
 	ephy-navigation-history-action.h	\
 	ephy-page-menu-action.h			\
 	ephy-password-info.h			\
@@ -70,6 +71,7 @@ libephymain_la_SOURCES = \
 	ephy-link-action.c			\
 	ephy-location-controller.c		\
 	ephy-lockdown.c				\
+	ephy-overview.c				\
 	ephy-navigation-history-action.c	\
 	ephy-notebook.c				\
 	ephy-page-menu-action.c			\
diff --git a/src/ephy-overview.c b/src/ephy-overview.c
new file mode 100644
index 0000000..b0409e4
--- /dev/null
+++ b/src/ephy-overview.c
@@ -0,0 +1,197 @@
+/* -*- 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-active-store.h"
+#include "ephy-frecent-store.h"
+#include "ephy-history-service.h"
+#include "ephy-overview.h"
+#include "ephy-shell.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))
+
+enum
+{
+  PROP_0,
+  PROP_PARENT_WINDOW,
+};
+
+struct _EphyOverviewPrivate
+{
+  EphyWindow *parent_window;
+  GtkWidget *upper_view;
+  GtkWidget *bottom_view;
+};
+
+G_DEFINE_TYPE (EphyOverview, ephy_overview, GTK_TYPE_GRID)
+
+static void
+ephy_overview_set_property (GObject *object,
+                            guint prop_id,
+                            const GValue *value,
+                            GParamSpec *pspec)
+{
+  EphyOverview *overview = EPHY_OVERVIEW (object);
+
+  switch (prop_id)
+  {
+  case PROP_PARENT_WINDOW:
+    overview->priv->parent_window = g_value_get_object (value);
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    break;
+  }
+}
+
+static void
+ephy_overview_get_property (GObject *object,
+                            guint prop_id,
+                            GValue *value,
+                            GParamSpec *pspec)
+{
+  EphyOverview *overview = EPHY_OVERVIEW (object);
+
+  switch (prop_id)
+  {
+  case PROP_PARENT_WINDOW:
+    g_value_set_object (value, overview->priv->parent_window);
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+    break;
+  }
+}
+
+static void
+main_view_item_activated (GtkWidget *widget,
+                          gchar *id,
+                          GtkTreePath *path,
+                          EphyWindow *window)
+{
+  guint position;
+  GtkTreeModel *model;
+  GtkTreeIter iter;
+  char *url;
+
+  model = gd_main_view_get_model (GD_MAIN_VIEW (widget));
+  gtk_tree_model_get_iter (model, &iter, path);
+  if (EPHY_IS_ACTIVE_STORE (model)) {
+    gtk_tree_model_get (model, &iter,
+                        EPHY_ACTIVE_STORE_TAB_POS, &position,
+                        -1);
+    gtk_notebook_set_current_page (GTK_NOTEBOOK (ephy_window_get_notebook (window)),
+                                   position);
+    ephy_window_set_overview_mode (window, FALSE);
+  } else {
+    gtk_tree_model_get (model, &iter,
+                        EPHY_OVERVIEW_STORE_URI, &url,
+                        -1);
+    ephy_shell_new_tab (ephy_shell, window, NULL, url,
+                        EPHY_NEW_TAB_OPEN_PAGE |
+                        EPHY_NEW_TAB_JUMP |
+                        EPHY_NEW_TAB_IN_EXISTING_WINDOW);
+    g_free (url);
+  }
+}
+
+static void
+ephy_overview_constructed (GObject *object)
+{
+  EphyHistoryService *service;
+  EphyOverviewStore *store;
+  EphyNotebook *notebook;
+  EphyOverview *self = EPHY_OVERVIEW (object);
+
+  if (G_OBJECT_CLASS (ephy_overview_parent_class)->constructed)
+    G_OBJECT_CLASS (ephy_overview_parent_class)->constructed (object);
+
+  service = EPHY_HISTORY_SERVICE (ephy_embed_shell_get_global_history_service (EPHY_EMBED_SHELL (ephy_shell)));
+
+  self->priv->upper_view = GTK_WIDGET (gd_main_view_new (GD_MAIN_VIEW_ICON));
+  g_signal_connect (self->priv->upper_view, "item-activated",
+                    G_CALLBACK (main_view_item_activated), self->priv->parent_window);
+  store = EPHY_OVERVIEW_STORE (ephy_frecent_store_new ());
+  g_object_set (G_OBJECT (store),
+                "history-service", service,
+                NULL);
+  gd_main_view_set_model (GD_MAIN_VIEW (self->priv->upper_view),
+                          GTK_TREE_MODEL (store));
+  gtk_grid_attach (GTK_GRID (self), self->priv->upper_view,
+                   0, 0, 1, 1);
+  gtk_widget_set_vexpand (self->priv->upper_view, FALSE);
+  gtk_widget_set_size_request (self->priv->upper_view, -1, 320);
+
+  self->priv->bottom_view = GTK_WIDGET (gd_main_view_new (GD_MAIN_VIEW_ICON));
+  g_signal_connect (self->priv->bottom_view, "item-activated",
+                    G_CALLBACK (main_view_item_activated),
+                    self->priv->parent_window);
+  notebook = EPHY_NOTEBOOK (ephy_window_get_notebook (EPHY_WINDOW (self->priv->parent_window)));
+  store = EPHY_OVERVIEW_STORE (ephy_active_store_new (notebook));
+  g_object_set (G_OBJECT (store),
+                "history-service", service,
+                NULL);
+  gd_main_view_set_model (GD_MAIN_VIEW (self->priv->bottom_view),
+                          GTK_TREE_MODEL (store));
+  gtk_grid_attach (GTK_GRID (self), self->priv->bottom_view,
+                   0, 1, 1, 1);
+
+  gtk_widget_show_all (GTK_WIDGET (self));
+}
+
+static void
+ephy_overview_class_init (EphyOverviewClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->set_property = ephy_overview_set_property;
+  object_class->get_property = ephy_overview_get_property;
+  object_class->constructed  = ephy_overview_constructed;
+
+  g_object_class_install_property (object_class,
+                                   PROP_PARENT_WINDOW,
+                                   g_param_spec_object ("parent-window",
+                                                        "Parent window",
+                                                        "parent window",
+                                                        EPHY_TYPE_WINDOW,
+                                                        G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB));
+
+  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 (EphyWindow *parent_window)
+{
+  return g_object_new (EPHY_TYPE_OVERVIEW,
+                       "parent-window", parent_window,
+                       NULL);
+}
diff --git a/src/ephy-overview.h b/src/ephy-overview.h
new file mode 100644
index 0000000..40bffe3
--- /dev/null
+++ b/src/ephy-overview.h
@@ -0,0 +1,60 @@
+/* -*- 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 "ephy-window.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           (EphyWindow *parent_window);
+
+G_END_DECLS
+
+#endif /* _EPHY_OVERVIEW_H */



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