diff options
author | Xan Lopez <xan@igalia.com> | 2012-03-07 04:20:23 +0800 |
---|---|---|
committer | Xan Lopez <xan@igalia.com> | 2012-03-07 04:49:47 +0800 |
commit | 8cc5c6df39c67e756d2cdc2aabeceb1928808187 (patch) | |
tree | d8f388f8261c6ad146246abbaf2f1c285d8e1be9 /embed | |
parent | 59c3c6334c070dc7b9e34c3171dbb99374826705 (diff) | |
download | gsoc2013-epiphany-8cc5c6df39c67e756d2cdc2aabeceb1928808187.tar gsoc2013-epiphany-8cc5c6df39c67e756d2cdc2aabeceb1928808187.tar.gz gsoc2013-epiphany-8cc5c6df39c67e756d2cdc2aabeceb1928808187.tar.bz2 gsoc2013-epiphany-8cc5c6df39c67e756d2cdc2aabeceb1928808187.tar.lz gsoc2013-epiphany-8cc5c6df39c67e756d2cdc2aabeceb1928808187.tar.xz gsoc2013-epiphany-8cc5c6df39c67e756d2cdc2aabeceb1928808187.tar.zst gsoc2013-epiphany-8cc5c6df39c67e756d2cdc2aabeceb1928808187.zip |
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.
Diffstat (limited to 'embed')
-rw-r--r-- | embed/Makefile.am | 10 | ||||
-rw-r--r-- | embed/ephy-history-store.c | 99 | ||||
-rw-r--r-- | embed/ephy-history-store.h | 66 | ||||
-rw-r--r-- | embed/ephy-history-view.c | 182 | ||||
-rw-r--r-- | embed/ephy-history-view.h | 56 | ||||
-rw-r--r-- | embed/ephy-hosts-store.c | 101 | ||||
-rw-r--r-- | embed/ephy-hosts-store.h | 69 | ||||
-rw-r--r-- | embed/ephy-hosts-view.c | 165 | ||||
-rw-r--r-- | embed/ephy-hosts-view.h | 57 |
9 files changed, 1 insertions, 804 deletions
diff --git a/embed/Makefile.am b/embed/Makefile.am index 30f44c379..fee25a9c1 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/embed/ephy-history-store.c b/embed/ephy-history-store.c deleted file mode 100644 index 37ccaaf9c..000000000 --- a/embed/ephy-history-store.c +++ /dev/null @@ -1,99 +0,0 @@ -/* -*- 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-history-store.h" - -#include "ephy-history-types.h" - -#include <gtk/gtk.h> - -G_DEFINE_TYPE (EphyHistoryStore, ephy_history_store, GTK_TYPE_LIST_STORE) - -static void -ephy_history_store_class_init (EphyHistoryStoreClass *klass) -{ -} - -static void -ephy_history_store_init (EphyHistoryStore *self) -{ - GType types[EPHY_HISTORY_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; - - gtk_list_store_set_column_types (GTK_LIST_STORE (self), - EPHY_HISTORY_STORE_N_COLUMNS, - types); -} - -EphyHistoryStore * -ephy_history_store_new (void) -{ - return g_object_new (EPHY_TYPE_HISTORY_STORE, - NULL); -} - -void -ephy_history_store_add_urls (EphyHistoryStore *store, - GList *urls) -{ - EphyHistoryURL *url; - GList *iter; - - for (iter = urls; iter != NULL; iter = iter->next) { - 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, - -1); - } -} - -void -ephy_history_store_add_url (EphyHistoryStore *store, EphyHistoryURL *url) -{ - GList *urls = NULL; - urls = g_list_append (urls, url); - ephy_history_store_add_urls (store, urls); - g_list_free (urls); -} - -EphyHistoryURL * -ephy_history_store_get_url_from_path (EphyHistoryStore *store, - GtkTreePath *path) -{ - GtkTreeIter iter; - - EphyHistoryURL *url = ephy_history_url_new ("", "", 0, 0, 0); - - 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, - -1); - return url; -} diff --git a/embed/ephy-history-store.h b/embed/ephy-history-store.h deleted file mode 100644 index f5b5e702d..000000000 --- a/embed/ephy-history-store.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- 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_HISTORY_STORE_H -#define _EPHY_HISTORY_STORE_H - -#include "ephy-history-types.h" - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define EPHY_TYPE_HISTORY_STORE (ephy_history_store_get_type()) -#define EPHY_HISTORY_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EPHY_TYPE_HISTORY_STORE, EphyHistoryStore)) -#define EPHY_HISTORY_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EPHY_TYPE_HISTORY_STORE, EphyHistoryStoreClass)) -#define EPHY_IS_HISTORY_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EPHY_TYPE_HISTORY_STORE)) -#define EPHY_IS_HISTORY_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EPHY_TYPE_HISTORY_STORE)) -#define EPHY_HISTORY_STORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EPHY_TYPE_HISTORY_STORE, EphyHistoryStoreClass)) - -typedef struct _EphyHistoryStore EphyHistoryStore; -typedef struct _EphyHistoryStoreClass EphyHistoryStoreClass; -typedef struct _EphyHistoryStorePrivate EphyHistoryStorePrivate; - -typedef enum { - EPHY_HISTORY_STORE_COLUMN_TITLE = 0, - EPHY_HISTORY_STORE_COLUMN_ADDRESS, - EPHY_HISTORY_STORE_COLUMN_DATE, - EPHY_HISTORY_STORE_N_COLUMNS -} EphyHistoryStoreColumn; - -struct _EphyHistoryStore { - GtkListStore parent; -}; - -struct _EphyHistoryStoreClass { - GtkListStoreClass parent_class; -}; - -GType ephy_history_store_get_type (void) G_GNUC_CONST; -EphyHistoryStore* ephy_history_store_new (void); -void ephy_history_store_add_urls (EphyHistoryStore *store, GList *urls); -void ephy_history_store_add_url (EphyHistoryStore *store, EphyHistoryURL *url); -void ephy_history_store_add_visits (EphyHistoryStore *store, GList *visits); -EphyHistoryURL* ephy_history_store_get_url_from_path (EphyHistoryStore *store, GtkTreePath *path); - -G_END_DECLS - -#endif /* _EPHY_HISTORY_STORE_H */ diff --git a/embed/ephy-history-view.c b/embed/ephy-history-view.c deleted file mode 100644 index e23a371f7..000000000 --- a/embed/ephy-history-view.c +++ /dev/null @@ -1,182 +0,0 @@ -/* -*- 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-history-view.h" - -#include "ephy-gui.h" -#include "ephy-history-store.h" - -#include <glib/gi18n.h> -#include <gtk/gtk.h> - -G_DEFINE_TYPE (EphyHistoryView, ephy_history_view, GTK_TYPE_TREE_VIEW) - -static void -ephy_history_view_class_init (EphyHistoryViewClass *klass) -{ -} - -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 TRUE; -} - -static void -ephy_history_view_init (EphyHistoryView *self) -{ - GtkTreeViewColumn *column; - GtkTreeSelection *selection; - - 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_HISTORY_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_HISTORY_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_HISTORY_STORE_COLUMN_DATE, - NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW (self), column); - - 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); -} - -GtkWidget * -ephy_history_view_new (void) -{ - return g_object_new (EPHY_TYPE_HISTORY_VIEW, NULL); -} - -void -ephy_history_view_popup (EphyHistoryView *view, GtkWidget *menu) -{ - GdkEvent *event; - - 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); - } -} - -static void -get_selection (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gpointer *data) -{ - EphyHistoryURL *url; - - url = ephy_history_store_get_url_from_path (EPHY_HISTORY_STORE (model), path); - *data = g_list_prepend (*data, url); -} - -GList * -ephy_history_view_get_selection (EphyHistoryView *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/embed/ephy-history-view.h b/embed/ephy-history-view.h deleted file mode 100644 index d6c2d0656..000000000 --- a/embed/ephy-history-view.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- 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_HISTORY_VIEW_H -#define _EPHY_HISTORY_VIEW_H - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define EPHY_TYPE_HISTORY_VIEW ephy_history_view_get_type() - -#define EPHY_HISTORY_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EPHY_TYPE_HISTORY_VIEW, EphyHistoryView)) -#define EPHY_HISTORY_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EPHY_TYPE_HISTORY_VIEW, EphyHistoryViewClass)) -#define EPHY_IS_HISTORY_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EPHY_TYPE_HISTORY_VIEW)) -#define EPHY_IS_HISTORY_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EPHY_TYPE_HISTORY_VIEW)) -#define EPHY_HISTORY_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EPHY_TYPE_HISTORY_VIEW, EphyHistoryViewClass)) - -typedef struct _EphyHistoryView EphyHistoryView; -typedef struct _EphyHistoryViewClass EphyHistoryViewClass; -typedef struct _EphyHistoryViewPrivate EphyHistoryViewPrivate; - -struct _EphyHistoryView { - GtkTreeView parent; -}; - -struct _EphyHistoryViewClass { - GtkTreeViewClass parent_class; -}; - -GType ephy_history_view_get_type (void) G_GNUC_CONST; -GtkWidget * ephy_history_view_new (void); -void ephy_history_view_popup (EphyHistoryView *view, GtkWidget *menu); -GList * ephy_history_view_get_selection (EphyHistoryView *view); - -G_END_DECLS - -#endif /* _EPHY_HISTORY_VIEW_H */ diff --git a/embed/ephy-hosts-store.c b/embed/ephy-hosts-store.c deleted file mode 100644 index ca84f4b72..000000000 --- a/embed/ephy-hosts-store.c +++ /dev/null @@ -1,101 +0,0 @@ -/* -*- 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-store.h" - -#include <gtk/gtk.h> - -G_DEFINE_TYPE (EphyHostsStore, ephy_hosts_store, GTK_TYPE_LIST_STORE) - -static void -ephy_hosts_store_class_init (EphyHostsStoreClass *klass) -{ -} - -static void -ephy_hosts_store_init (EphyHostsStore *self) -{ - GType types[EPHY_HOSTS_STORE_N_COLUMNS]; - - types[EPHY_HOSTS_STORE_COLUMN_ID] = G_TYPE_INT; - types[EPHY_HOSTS_STORE_COLUMN_TITLE] = G_TYPE_STRING; - types[EPHY_HOSTS_STORE_COLUMN_ADDRESS] = G_TYPE_STRING; - types[EPHY_HOSTS_STORE_COLUMN_VISIT_COUNT] = G_TYPE_INT; - - gtk_list_store_set_column_types (GTK_LIST_STORE (self), - EPHY_HOSTS_STORE_N_COLUMNS, - types); -} - -EphyHostsStore * -ephy_hosts_store_new (void) -{ - return g_object_new (EPHY_TYPE_HOSTS_STORE, - NULL); -} - -void -ephy_hosts_store_add_hosts (EphyHostsStore *store, - GList *hosts) -{ - EphyHistoryHost *host; - GList *iter; - - for (iter = hosts; iter != NULL; iter = iter->next) { - host = (EphyHistoryHost *)iter->data; - gtk_list_store_insert_with_values (GTK_LIST_STORE (store), - NULL, -1, - EPHY_HOSTS_STORE_COLUMN_ID, host->id, - EPHY_HOSTS_STORE_COLUMN_TITLE, host->title, - EPHY_HOSTS_STORE_COLUMN_ADDRESS, host->url, - EPHY_HOSTS_STORE_COLUMN_VISIT_COUNT, host->visit_count, - -1); - } -} - -void -ephy_hosts_store_add_host (EphyHostsStore *store, EphyHistoryHost *host) -{ - GList *hosts = NULL; - hosts = g_list_append (hosts, host); - ephy_hosts_store_add_hosts (store, hosts); - g_list_free (hosts); -} - -EphyHistoryHost * -ephy_hosts_store_get_host_from_path (EphyHostsStore *store, - GtkTreePath *path) -{ - GtkTreeIter iter; - - EphyHistoryHost *host = ephy_history_host_new ("", "", 0, 1.0); - - gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path); - gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, - EPHY_HOSTS_STORE_COLUMN_ID, &host->id, - EPHY_HOSTS_STORE_COLUMN_TITLE, &host->title, - EPHY_HOSTS_STORE_COLUMN_ADDRESS, &host->url, - EPHY_HOSTS_STORE_COLUMN_VISIT_COUNT, &host->visit_count, - -1); - return host; -} diff --git a/embed/ephy-hosts-store.h b/embed/ephy-hosts-store.h deleted file mode 100644 index 5b61902f3..000000000 --- a/embed/ephy-hosts-store.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- 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_HOSTS_STORE_H -#define _EPHY_HOSTS_STORE_H - -#include "ephy-history-types.h" - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define EPHY_TYPE_HOSTS_STORE (ephy_hosts_store_get_type()) -#define EPHY_HOSTS_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EPHY_TYPE_HOSTS_STORE, EphyHostsStore)) -#define EPHY_HOSTS_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EPHY_TYPE_HOSTS_STORE, EphyHostsStoreClass)) -#define EPHY_IS_HOSTS_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EPHY_TYPE_HOSTS_STORE)) -#define EPHY_IS_HOSTS_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EPHY_TYPE_HOSTS_STORE)) -#define EPHY_HOSTS_STORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EPHY_TYPE_HOSTS_STORE, EphyHostsStoreClass)) - -typedef struct _EphyHostsStore EphyHostsStore; -typedef struct _EphyHostsStoreClass EphyHostsStoreClass; -typedef struct _EphyHostsStorePrivate EphyHostsStorePrivate; - -typedef enum { - EPHY_HOSTS_STORE_COLUMN_ID = 0, - EPHY_HOSTS_STORE_COLUMN_TITLE, - EPHY_HOSTS_STORE_COLUMN_ADDRESS, - EPHY_HOSTS_STORE_COLUMN_VISIT_COUNT, - EPHY_HOSTS_STORE_N_COLUMNS -} EphyHostsStoreColumn; - -struct _EphyHostsStore -{ - GtkListStore parent; -}; - -struct _EphyHostsStoreClass -{ - GtkListStoreClass parent_class; -}; - -GType ephy_hosts_store_get_type (void) G_GNUC_CONST; -EphyHostsStore* ephy_hosts_store_new (void); -void ephy_hosts_store_add_hosts (EphyHostsStore *store, GList *hosts); -void ephy_hosts_store_add_host (EphyHostsStore *store, EphyHistoryHost *host); -void ephy_hosts_store_add_visits (EphyHostsStore *store, GList *visits); -EphyHistoryHost* ephy_hosts_store_get_host_from_path (EphyHostsStore *store, GtkTreePath *path); - -G_END_DECLS - -#endif /* _EPHY_HOSTS_STORE_H */ diff --git a/embed/ephy-hosts-view.c b/embed/ephy-hosts-view.c deleted file mode 100644 index f508c8350..000000000 --- a/embed/ephy-hosts-view.c +++ /dev/null @@ -1,165 +0,0 @@ -/* -*- 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, GTK_TYPE_TREE_VIEW) -static void -ephy_hosts_view_class_init (EphyHostsViewClass *klass) -{ -} - -static gboolean -button_event_modifies_selection (GdkEventButton *event) -{ - return (event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) != 0; -} - -static gboolean -ephy_hosts_view_button_press_cb (GtkWidget *treeview, - GdkEventButton *event, - EphyHostsView *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_hosts_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_hosts_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 TRUE; -} - -static void -ephy_hosts_view_init (EphyHostsView *self) -{ - GtkTreeViewColumn *column; - GtkTreeSelection *selection; - - 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); - - 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_hosts_view_button_press_cb), - self, 0); -} - -GtkWidget * -ephy_hosts_view_new (void) -{ - return g_object_new (EPHY_TYPE_HOSTS_VIEW, NULL); -} - -void -ephy_hosts_view_popup (EphyHostsView *view, GtkWidget *menu) -{ - GdkEvent *event; - - 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); - } -} - -static void -get_selection (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gpointer *data) -{ - EphyHistoryHost *host; - - host = ephy_hosts_store_get_host_from_path (EPHY_HOSTS_STORE (model), path); - *data = g_list_prepend (*data, host); -} - -GList * -ephy_hosts_view_get_selection (EphyHostsView *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/embed/ephy-hosts-view.h b/embed/ephy-hosts-view.h deleted file mode 100644 index 534903cf5..000000000 --- a/embed/ephy-hosts-view.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- 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_HOSTS_VIEW_H -#define _EPHY_HOSTS_VIEW_H - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define EPHY_TYPE_HOSTS_VIEW (ephy_hosts_view_get_type()) -#define EPHY_HOSTS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EPHY_TYPE_HOSTS_VIEW, EphyHostsView)) -#define EPHY_HOSTS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EPHY_TYPE_HOSTS_VIEW, EphyHostsViewClass)) -#define EPHY_IS_HOSTS_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EPHY_TYPE_HOSTS_VIEW)) -#define EPHY_IS_HOSTS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EPHY_TYPE_HOSTS_VIEW)) -#define EPHY_HOSTS_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EPHY_TYPE_HOSTS_VIEW, EphyHostsViewClass)) - -typedef struct _EphyHostsView EphyHostsView; -typedef struct _EphyHostsViewClass EphyHostsViewClass; -typedef struct _EphyHostsViewPrivate EphyHostsViewPrivate; - -struct _EphyHostsView -{ - GtkTreeView parent; -}; - -struct _EphyHostsViewClass -{ - GtkTreeViewClass 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 - -#endif /* _EPHY_HOSTS_VIEW_H */ |