[epiphany/wip/history-rewrite: 13/14] Move the host and urls views from embed to lib/widgets



commit 0728ccd1f9304588ea0634b8f8f63dc6018aff72
Author: Xan Lopez <xan igalia com>
Date:   Tue Mar 6 21:20:23 2012 +0100

    Move the host and urls views from embed to lib/widgets
    
    Since that's their natural place. Also create a base class to hold the
    common code they share.

 embed/Makefile.am                                  |   10 +-
 embed/ephy-history-store.h                         |   66 -------
 embed/ephy-history-view.c                          |  182 --------------------
 embed/ephy-hosts-view.c                            |  165 ------------------
 lib/widgets/Makefile.am                            |   11 ++
 lib/widgets/ephy-history-view.c                    |  131 ++++++++++++++
 {embed => lib/widgets}/ephy-history-view.h         |    0
 {embed => lib/widgets}/ephy-hosts-store.c          |    3 -
 {embed => lib/widgets}/ephy-hosts-store.h          |    0
 lib/widgets/ephy-hosts-view.c                      |   55 ++++++
 {embed => lib/widgets}/ephy-hosts-view.h           |    8 +-
 .../widgets/ephy-urls-store.c                      |   48 +++---
 lib/widgets/ephy-urls-store.h                      |   66 +++++++
 lib/widgets/ephy-urls-view.c                       |   96 ++++++++++
 lib/widgets/ephy-urls-view.h                       |   56 ++++++
 15 files changed, 442 insertions(+), 455 deletions(-)
---
diff --git a/embed/Makefile.am b/embed/Makefile.am
index 30f44c3..fee25a9 100644
--- a/embed/Makefile.am
+++ b/embed/Makefile.am
@@ -26,11 +26,7 @@ INST_H_FILES = \
 	ephy-embed-shell.h		\
 	ephy-embed-utils.h              \
 	ephy-history.h			\
-	ephy-history-store.h		\
-	ephy-history-view.h		\
-	ephy-permission-manager.h   \
-	ephy-hosts-store.h		\
-	ephy-hosts-view.h		\
+	ephy-permission-manager.h       \
 	ephy-web-view.h
 
 
@@ -52,13 +48,9 @@ libephyembed_la_SOURCES = \
 	ephy-encodings.c		\
 	ephy-favicon-cache.c		\
 	ephy-history.c			\
-	ephy-history-store.c		\
-	ephy-history-view.c		\
 	ephy-permission-manager.c	\
 	ephy-request-about.c		\
 	ephy-embed-prefs.c		\
-	ephy-hosts-store.c		\
-	ephy-hosts-view.c		\
 	ephy-web-app-utils.c		\
 	ephy-web-view.c			\
 	$(INST_H_FILES)			\
diff --git a/lib/widgets/Makefile.am b/lib/widgets/Makefile.am
index f581674..9f751e0 100644
--- a/lib/widgets/Makefile.am
+++ b/lib/widgets/Makefile.am
@@ -3,6 +3,12 @@ noinst_LTLIBRARIES = libephywidgets.la
 libephywidgets_la_SOURCES = \
 	ephy-download-widget.c			\
 	ephy-download-widget.h			\
+	ephy-history-view.c			\
+	ephy-history-view.h			\
+	ephy-hosts-store.c			\
+	ephy-hosts-store.h			\
+	ephy-hosts-view.c			\
+	ephy-hosts-view.h			\
 	ephy-location-entry.c			\
 	ephy-location-entry.h			\
 	ephy-middle-clickable-button.c		\
@@ -15,6 +21,10 @@ libephywidgets_la_SOURCES = \
 	ephy-tree-model-node.h			\
 	ephy-tree-model-sort.c			\
 	ephy-tree-model-sort.h			\
+	ephy-urls-store.c			\
+	ephy-urls-store.h			\
+	ephy-urls-view.c			\
+	ephy-urls-view.h			\
 	ephy-zoom-action.h			\
 	ephy-zoom-action.c			\
 	nautilus-floating-bar.c			\
@@ -28,6 +38,7 @@ libephywidgets_la_CPPFLAGS = \
 	-I$(top_srcdir)/lib		\
 	-I$(top_srcdir)/embed		\
 	-I$(top_srcdir)/lib/egg		\
+	-I$(top_srcdir)/lib/history	\
 	-DSHARE_DIR=\"$(pkgdatadir)\"	\
 	$(AM_CPPFLAGS)
 
diff --git a/lib/widgets/ephy-history-view.c b/lib/widgets/ephy-history-view.c
new file mode 100644
index 0000000..145f3ca
--- /dev/null
+++ b/lib/widgets/ephy-history-view.c
@@ -0,0 +1,131 @@
+/* -*- 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-history-view.h"
+
+#include "ephy-gui.h"
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+G_DEFINE_TYPE (EphyHistoryView, ephy_history_view, GTK_TYPE_TREE_VIEW)
+
+
+static gboolean
+button_event_modifies_selection (GdkEventButton *event)
+{
+  return (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) != 0;
+}
+
+static gboolean
+ephy_history_view_button_press_cb (GtkWidget *treeview,
+                                   GdkEventButton *event,
+                                   EphyHistoryView *view)
+{
+  GtkTreeSelection *selection;
+  GtkTreePath *path = NULL;
+  gboolean path_is_selected, call_parent = TRUE;
+
+  if (event->window != gtk_tree_view_get_bin_window (GTK_TREE_VIEW (treeview)))
+    return GTK_WIDGET_CLASS (ephy_history_view_parent_class)->button_press_event (treeview, event);
+
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+  if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (treeview),
+                                     event->x,
+                                     event->y,
+                                     &path,
+                                     NULL, NULL, NULL)) {
+    path_is_selected = gtk_tree_selection_path_is_selected (selection, path);
+
+    if (!gtk_widget_is_focus (GTK_WIDGET (treeview)))
+      gtk_widget_grab_focus (GTK_WIDGET (treeview));
+
+    if (event->button == 3 && path_is_selected)
+      call_parent = FALSE;
+
+    if (!button_event_modifies_selection (event) &&
+        event->button == 1 && path_is_selected &&
+        gtk_tree_selection_count_selected_rows (selection) > 1)
+      call_parent = FALSE;
+
+    if (call_parent)
+      GTK_WIDGET_CLASS (ephy_history_view_parent_class)->button_press_event (treeview, event);
+
+    if (event->button == 3) {
+      gboolean retval;
+
+      g_signal_emit_by_name (view, "popup_menu", &retval);
+    }
+    gtk_tree_path_free (path);
+  } else
+    gtk_tree_selection_unselect_all (selection);
+
+  return FALSE;
+}
+
+static void
+ephy_history_view_class_init (EphyHistoryViewClass *klass)
+{
+}
+
+static void
+ephy_history_view_init (EphyHistoryView *self)
+{
+  GtkTreeSelection *selection;
+
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (self));
+  gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
+
+  g_signal_connect_object (self, "button_press_event",
+                           G_CALLBACK (ephy_history_view_button_press_cb),
+                           self, 0);
+}
+
+void
+ephy_history_view_popup (EphyHistoryView *view, GtkWidget *menu)
+{
+  GdkEvent *event;
+
+  g_return_if_fail (EPHY_IS_HISTORY_VIEW (view));
+
+  event = gtk_get_current_event ();
+
+  if (event) {
+    if (event->type == GDK_KEY_PRESS) {
+      GdkEventKey *key = (GdkEventKey *) event;
+
+      gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
+                      ephy_gui_menu_position_tree_selection,
+                      view, 0, key->time);
+      gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
+    } else if (event->type == GDK_BUTTON_PRESS) {
+      GdkEventButton *button = (GdkEventButton *) event;
+
+      gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL,
+                      NULL, button->button, button->time);
+    }
+
+    gdk_event_free (event);
+  }
+}
+
+
diff --git a/embed/ephy-history-view.h b/lib/widgets/ephy-history-view.h
similarity index 100%
rename from embed/ephy-history-view.h
rename to lib/widgets/ephy-history-view.h
diff --git a/embed/ephy-hosts-store.c b/lib/widgets/ephy-hosts-store.c
similarity index 99%
rename from embed/ephy-hosts-store.c
rename to lib/widgets/ephy-hosts-store.c
index ca84f4b..77d6a93 100644
--- a/embed/ephy-hosts-store.c
+++ b/lib/widgets/ephy-hosts-store.c
@@ -20,11 +20,8 @@
  */
 
 #include "config.h"
-
 #include "ephy-hosts-store.h"
 
-#include <gtk/gtk.h>
-
 G_DEFINE_TYPE (EphyHostsStore, ephy_hosts_store, GTK_TYPE_LIST_STORE)
 
 static void
diff --git a/embed/ephy-hosts-store.h b/lib/widgets/ephy-hosts-store.h
similarity index 100%
rename from embed/ephy-hosts-store.h
rename to lib/widgets/ephy-hosts-store.h
diff --git a/lib/widgets/ephy-hosts-view.c b/lib/widgets/ephy-hosts-view.c
new file mode 100644
index 0000000..7ed6b44
--- /dev/null
+++ b/lib/widgets/ephy-hosts-view.c
@@ -0,0 +1,55 @@
+/* -*- 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.
+ *
+ */
+
+#include "config.h"
+#include "ephy-hosts-view.h"
+
+#include "ephy-gui.h"
+#include "ephy-hosts-store.h"
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+
+G_DEFINE_TYPE (EphyHostsView, ephy_hosts_view, EPHY_TYPE_HISTORY_VIEW)
+
+static void
+ephy_hosts_view_class_init (EphyHostsViewClass *klass)
+{
+}
+
+static void
+ephy_hosts_view_init (EphyHostsView *self)
+{
+  GtkTreeViewColumn *column;
+
+  column = gtk_tree_view_column_new_with_attributes (_("Sites"),
+                                                     gtk_cell_renderer_text_new (),
+                                                     "text", EPHY_HOSTS_STORE_COLUMN_TITLE,
+                                                     NULL);
+  gtk_tree_view_append_column (GTK_TREE_VIEW (self), column);
+}
+
+GtkWidget *
+ephy_hosts_view_new (void)
+{
+  return g_object_new (EPHY_TYPE_HOSTS_VIEW, NULL);
+}
+
diff --git a/embed/ephy-hosts-view.h b/lib/widgets/ephy-hosts-view.h
similarity index 90%
rename from embed/ephy-hosts-view.h
rename to lib/widgets/ephy-hosts-view.h
index 534903c..393ad4e 100644
--- a/embed/ephy-hosts-view.h
+++ b/lib/widgets/ephy-hosts-view.h
@@ -22,6 +22,8 @@
 #ifndef _EPHY_HOSTS_VIEW_H
 #define _EPHY_HOSTS_VIEW_H
 
+#include "ephy-history-view.h"
+
 #include <gtk/gtk.h>
 
 G_BEGIN_DECLS
@@ -39,18 +41,16 @@ typedef struct _EphyHostsViewPrivate EphyHostsViewPrivate;
 
 struct _EphyHostsView
 {
-  GtkTreeView parent;
+  EphyHistoryView parent;
 };
 
 struct _EphyHostsViewClass
 {
-  GtkTreeViewClass parent_class;
+  EphyHistoryViewClass parent_class;
 };
 
 GType      ephy_hosts_view_get_type      (void) G_GNUC_CONST;
 GtkWidget *ephy_hosts_view_new           (void);
-void       ephy_hosts_view_popup         (EphyHostsView *view, GtkWidget *menu);
-GList *    ephy_hosts_view_get_selection (EphyHostsView *view);
 
 G_END_DECLS
 
diff --git a/embed/ephy-history-store.c b/lib/widgets/ephy-urls-store.c
similarity index 57%
rename from embed/ephy-history-store.c
rename to lib/widgets/ephy-urls-store.c
index 37ccaaf..f859e72 100644
--- a/embed/ephy-history-store.c
+++ b/lib/widgets/ephy-urls-store.c
@@ -20,43 +20,39 @@
  */
 
 #include "config.h"
-
-#include "ephy-history-store.h"
-
-#include "ephy-history-types.h"
+#include "ephy-urls-store.h"
 
 #include <gtk/gtk.h>
 
-G_DEFINE_TYPE (EphyHistoryStore, ephy_history_store, GTK_TYPE_LIST_STORE)
+G_DEFINE_TYPE (EphyURLsStore, ephy_urls_store, GTK_TYPE_LIST_STORE)
 
 static void
-ephy_history_store_class_init (EphyHistoryStoreClass *klass)
+ephy_urls_store_class_init (EphyURLsStoreClass *klass)
 {
 }
 
 static void
-ephy_history_store_init (EphyHistoryStore *self)
+ephy_urls_store_init (EphyURLsStore *self)
 {
-  GType types[EPHY_HISTORY_STORE_N_COLUMNS];
+  GType types[EPHY_URLS_STORE_N_COLUMNS];
 
-  types[EPHY_HISTORY_STORE_COLUMN_TITLE]   = G_TYPE_STRING;
-  types[EPHY_HISTORY_STORE_COLUMN_ADDRESS] = G_TYPE_STRING;
-  types[EPHY_HISTORY_STORE_COLUMN_DATE]    = G_TYPE_INT;
+  types[EPHY_URLS_STORE_COLUMN_TITLE]   = G_TYPE_STRING;
+  types[EPHY_URLS_STORE_COLUMN_ADDRESS] = G_TYPE_STRING;
+  types[EPHY_URLS_STORE_COLUMN_DATE]    = G_TYPE_INT;
 
   gtk_list_store_set_column_types (GTK_LIST_STORE (self),
-                                   EPHY_HISTORY_STORE_N_COLUMNS,
+                                   EPHY_URLS_STORE_N_COLUMNS,
                                    types);
 }
 
-EphyHistoryStore *
-ephy_history_store_new (void)
+EphyURLsStore *
+ephy_urls_store_new (void)
 {
-  return g_object_new (EPHY_TYPE_HISTORY_STORE,
-                       NULL);
+  return g_object_new (EPHY_TYPE_URLS_STORE, NULL);
 }
 
 void
-ephy_history_store_add_urls (EphyHistoryStore *store,
+ephy_urls_store_add_urls (EphyURLsStore *store,
                              GList *urls)
 {
   EphyHistoryURL *url;
@@ -66,25 +62,25 @@ ephy_history_store_add_urls (EphyHistoryStore *store,
     url = (EphyHistoryURL *)iter->data;
     gtk_list_store_insert_with_values (GTK_LIST_STORE (store),
                                        NULL, G_MAXINT,
-                                       EPHY_HISTORY_STORE_COLUMN_TITLE, url->title,
-                                       EPHY_HISTORY_STORE_COLUMN_ADDRESS, url->url,
-                                       EPHY_HISTORY_STORE_COLUMN_DATE, url->last_visit_time,
+                                       EPHY_URLS_STORE_COLUMN_TITLE, url->title,
+                                       EPHY_URLS_STORE_COLUMN_ADDRESS, url->url,
+                                       EPHY_URLS_STORE_COLUMN_DATE, url->last_visit_time,
                                        -1);
   }
 }
 
 void
-ephy_history_store_add_url (EphyHistoryStore *store, EphyHistoryURL *url)
+ephy_urls_store_add_url (EphyURLsStore *store, EphyHistoryURL *url)
 {
   GList *urls = NULL;
   urls = g_list_append (urls, url);
-  ephy_history_store_add_urls (store, urls);
+  ephy_urls_store_add_urls (store, urls);
   g_list_free (urls);
 }
 
 EphyHistoryURL *
-ephy_history_store_get_url_from_path (EphyHistoryStore *store,
-				      GtkTreePath *path)
+ephy_urls_store_get_url_from_path (EphyURLsStore *store,
+                                   GtkTreePath *path)
 {
   GtkTreeIter iter;
 
@@ -92,8 +88,8 @@ ephy_history_store_get_url_from_path (EphyHistoryStore *store,
 
   gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path);
   gtk_tree_model_get (GTK_TREE_MODEL (store), &iter,
-                      EPHY_HISTORY_STORE_COLUMN_TITLE, &url->title,
-                      EPHY_HISTORY_STORE_COLUMN_ADDRESS, &url->url,
+                      EPHY_URLS_STORE_COLUMN_TITLE, &url->title,
+                      EPHY_URLS_STORE_COLUMN_ADDRESS, &url->url,
                       -1);
   return url;
 }
diff --git a/lib/widgets/ephy-urls-store.h b/lib/widgets/ephy-urls-store.h
new file mode 100644
index 0000000..1a0453d
--- /dev/null
+++ b/lib/widgets/ephy-urls-store.h
@@ -0,0 +1,66 @@
+/* -*- 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_URLS_STORE_H
+#define _EPHY_URLS_STORE_H
+
+#include "ephy-history-types.h"
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_URLS_STORE            (ephy_urls_store_get_type())
+#define EPHY_URLS_STORE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), EPHY_TYPE_URLS_STORE, EphyURLsStore))
+#define EPHY_URLS_STORE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), EPHY_TYPE_URLS_STORE, EphyURLsStoreClass))
+#define EPHY_IS_URLS_STORE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EPHY_TYPE_URLS_STORE))
+#define EPHY_IS_URLS_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EPHY_TYPE_URLS_STORE))
+#define EPHY_URLS_STORE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), EPHY_TYPE_URLS_STORE, EphyURLsStoreClass))
+
+typedef struct _EphyURLsStore           EphyURLsStore;
+typedef struct _EphyURLsStoreClass      EphyURLsStoreClass;
+typedef struct _EphyURLsStorePrivate    EphyURLsStorePrivate;
+
+typedef enum {
+  EPHY_URLS_STORE_COLUMN_TITLE = 0,
+  EPHY_URLS_STORE_COLUMN_ADDRESS,
+  EPHY_URLS_STORE_COLUMN_DATE,
+  EPHY_URLS_STORE_N_COLUMNS
+} EphyURLsStoreColumn;
+
+struct _EphyURLsStore {
+  GtkListStore parent;
+};
+
+struct _EphyURLsStoreClass {
+  GtkListStoreClass parent_class;
+};
+
+GType             ephy_urls_store_get_type          (void) G_GNUC_CONST;
+EphyURLsStore*    ephy_urls_store_new               (void);
+void              ephy_urls_store_add_urls          (EphyURLsStore *store, GList *urls);
+void              ephy_urls_store_add_url           (EphyURLsStore *store, EphyHistoryURL *url);
+void              ephy_urls_store_add_visits        (EphyURLsStore *store, GList *visits);
+EphyHistoryURL*   ephy_urls_store_get_url_from_path (EphyURLsStore *store, GtkTreePath *path);
+
+G_END_DECLS
+
+#endif /* _EPHY_URLS_STORE_H */
diff --git a/lib/widgets/ephy-urls-view.c b/lib/widgets/ephy-urls-view.c
new file mode 100644
index 0000000..10a8100
--- /dev/null
+++ b/lib/widgets/ephy-urls-view.c
@@ -0,0 +1,96 @@
+/* -*- 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.
+ *
+ */
+
+#include "config.h"
+#include "ephy-urls-view.h"
+
+#include "ephy-gui.h"
+#include "ephy-urls-store.h"
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+G_DEFINE_TYPE (EphyURLsView, ephy_urls_view, EPHY_TYPE_HISTORY_VIEW)
+
+static void
+ephy_urls_view_class_init (EphyURLsViewClass *klass)
+{
+}
+
+static void
+ephy_urls_view_init (EphyURLsView *self)
+{
+  GtkTreeViewColumn *column;
+
+  column = gtk_tree_view_column_new_with_attributes (_("Title"),
+                                                     g_object_new (GTK_TYPE_CELL_RENDERER_TEXT,
+                                                                   "ellipsize-set", TRUE,
+                                                                   "ellipsize", PANGO_ELLIPSIZE_END, NULL),
+                                                     "text", EPHY_URLS_STORE_COLUMN_TITLE,
+                                                     NULL);
+  gtk_tree_view_append_column (GTK_TREE_VIEW (self), column);
+
+  column = gtk_tree_view_column_new_with_attributes (_("Address"),
+                                                     g_object_new (GTK_TYPE_CELL_RENDERER_TEXT,
+                                                                   "ellipsize-set", TRUE,
+                                                                   "ellipsize", PANGO_ELLIPSIZE_END, NULL),
+                                                     "text", EPHY_URLS_STORE_COLUMN_ADDRESS,
+                                                     NULL);
+  gtk_tree_view_append_column (GTK_TREE_VIEW (self), column);
+
+  column = gtk_tree_view_column_new_with_attributes (_("Date"),
+                                                     gtk_cell_renderer_text_new (),
+                                                     "text", EPHY_URLS_STORE_COLUMN_DATE,
+                                                     NULL);
+  gtk_tree_view_append_column (GTK_TREE_VIEW (self), column);
+}
+
+GtkWidget *
+ephy_urls_view_new (void)
+{
+  return g_object_new (EPHY_TYPE_URLS_VIEW, NULL);
+}
+
+static void
+get_selection (GtkTreeModel *model,
+               GtkTreePath *path,
+               GtkTreeIter *iter,
+               gpointer *data)
+{
+  EphyHistoryURL *url;
+
+  url = ephy_urls_store_get_url_from_path (EPHY_URLS_STORE (model), path);
+  *data = g_list_prepend (*data, url);
+}
+
+GList *
+ephy_urls_view_get_selection (EphyURLsView *view)
+{
+  GtkTreeSelection *selection;
+  GList *list = NULL;
+
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
+  gtk_tree_selection_selected_foreach (selection,
+                                       (GtkTreeSelectionForeachFunc) get_selection,
+                                       &list);
+
+  return g_list_reverse (list);
+}
diff --git a/lib/widgets/ephy-urls-view.h b/lib/widgets/ephy-urls-view.h
new file mode 100644
index 0000000..9bcee24
--- /dev/null
+++ b/lib/widgets/ephy-urls-view.h
@@ -0,0 +1,56 @@
+/* -*- 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_URLS_VIEW_H
+#define _EPHY_URLS_VIEW_H
+
+#include "ephy-history-view.h"
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_URLS_VIEW            (ephy_urls_view_get_type())
+#define EPHY_URLS_VIEW(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), EPHY_TYPE_URLS_VIEW, EphyURLsView))
+#define EPHY_URLS_VIEW_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), EPHY_TYPE_URLS_VIEW, EphyURLsViewClass))
+#define EPHY_IS_URLS_VIEW(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EPHY_TYPE_URLS_VIEW))
+#define EPHY_IS_URLS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EPHY_TYPE_URLS_VIEW))
+#define EPHY_URLS_VIEW_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), EPHY_TYPE_URLS_VIEW, EphyURLsViewClass))
+
+typedef struct _EphyURLsView            EphyURLsView;
+typedef struct _EphyURLsViewClass       EphyURLsViewClass;
+typedef struct _EphyURLsViewPrivate     EphyURLsViewPrivate;
+
+struct _EphyURLsView {
+  EphyHistoryView parent;
+};
+
+struct _EphyURLsViewClass {
+  EphyHistoryViewClass parent_class;
+};
+
+GType       ephy_urls_view_get_type      (void) G_GNUC_CONST;
+GtkWidget * ephy_urls_view_new           (void);
+GList *     ephy_urls_view_get_selection (EphyURLsView *view);
+
+G_END_DECLS
+
+#endif /* _EPHY_URLS_VIEW_H */



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