From 43bb5b652d0a5c2efda484195a3ef55f17b9cc8b Mon Sep 17 00:00:00 2001 From: Rob Kendrick Date: Fri, 18 Aug 2006 11:44:24 +0000 Subject: Very simple global history implementation for nsgtk, misc fixes svn path=/trunk/netsurf/; revision=2867 --- gtk/gtk_gui.c | 5 +- gtk/gtk_history.c | 149 +++++++++++++++++++++++++++ gtk/gtk_history.h | 20 ++++ gtk/gtk_window.c | 11 ++ gtk/netsurf.glade | 303 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 484 insertions(+), 4 deletions(-) create mode 100644 gtk/gtk_history.c create mode 100644 gtk/gtk_history.h (limited to 'gtk') diff --git a/gtk/gtk_gui.c b/gtk/gtk_gui.c index 1abdba87f..eb756b8fb 100644 --- a/gtk/gtk_gui.c +++ b/gtk/gtk_gui.c @@ -31,6 +31,7 @@ #include "netsurf/gtk/gtk_completion.h" #include "netsurf/gtk/options.h" #include "netsurf/gtk/gtk_throbber.h" +#include "netsurf/gtk/gtk_history.h" #include "netsurf/render/box.h" #include "netsurf/render/form.h" #include "netsurf/render/html.h" @@ -157,6 +158,8 @@ void gui_init(int argc, char** argv) urldb_load(option_url_file); urldb_load_cookies(option_cookie_file); + + nsgtk_history_init(); } @@ -309,8 +312,6 @@ void hotlist_visited(struct content *content) void gui_cert_verify(struct browser_window *bw, struct content *c, const struct ssl_cert_info *certs, unsigned long num) {} -void global_history_add(const char *url) {} - utf8_convert_ret utf8_to_local_encoding(const char *string, size_t len, char **result) { diff --git a/gtk/gtk_history.c b/gtk/gtk_history.c new file mode 100644 index 000000000..a93192408 --- /dev/null +++ b/gtk/gtk_history.c @@ -0,0 +1,149 @@ +/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2006 Rob Kendrick + */ + +#include +#include +#include "netsurf/utils/log.h" +#include "netsurf/content/urldb.h" +#include "netsurf/gtk/gtk_history.h" +#include "netsurf/gtk/gtk_gui.h" + +enum +{ + COL_TITLE = 0, + COL_ADDRESS, + COL_LASTVISIT, + COL_TOTALVISITS, + COL_THUMBNAIL, + COL_NCOLS +}; + +GtkWindow *wndHistory; +static GtkTreeView *treeview; +static GtkTreeStore *history_tree; +static GtkTreeSelection *selection; + +static bool nsgtk_history_add_internal(const char *, const struct url_data *); +static void nsgtk_history_selection_changed(GtkTreeSelection *, gpointer); + +void nsgtk_history_init(void) +{ + GtkCellRenderer *renderer; + + wndHistory = GTK_WINDOW(glade_xml_get_widget(gladeWindows, + "wndHistory")); + treeview = GTK_TREE_VIEW(glade_xml_get_widget(gladeWindows, + "treeHistory")); + history_tree = gtk_tree_store_new(COL_NCOLS, + G_TYPE_STRING, /* title */ + G_TYPE_STRING, /* address */ + G_TYPE_STRING, /* last visit */ + G_TYPE_INT, /* nr. visits */ + GDK_TYPE_PIXBUF); /* thumbnail */ + + selection = gtk_tree_view_get_selection(treeview); + gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); + g_signal_connect(G_OBJECT(selection), "changed", + G_CALLBACK(nsgtk_history_selection_changed), NULL); + + renderer = gtk_cell_renderer_text_new(); + gtk_tree_view_insert_column_with_attributes(treeview, -1, "Title", + renderer, + "text", + COL_TITLE, + NULL); + + gtk_tree_view_set_model(treeview, GTK_TREE_MODEL(history_tree)); + + nsgtk_history_update(); +} + +void nsgtk_history_update(void) +{ + gtk_tree_store_clear(history_tree); + urldb_iterate_entries(nsgtk_history_add_internal); +} + +bool nsgtk_history_add_internal(const char *url, const struct url_data *data) +{ + GtkTreeIter iter; + + if (data->visits > 0) + { + gtk_tree_store_append(history_tree, &iter, NULL); + gtk_tree_store_set(history_tree, &iter, + COL_TITLE, data->title, + COL_ADDRESS, url, + COL_LASTVISIT, "Unknown", + COL_TOTALVISITS, data->visits, + -1); + } + + return true; +} + +void nsgtk_history_selection_changed(GtkTreeSelection *treesel, gpointer g) +{ + GtkTreeIter iter; + + if (gtk_tree_selection_get_selected(treesel, &history_tree, &iter)) + { + gchar *b; + gint i; + char buf[20]; + + gtk_tree_model_get(history_tree, &iter, COL_ADDRESS, &b, -1); + gtk_label_set_text(GTK_LABEL(glade_xml_get_widget(gladeWindows, + "labelHistoryAddress")), b); + + gtk_tree_model_get(history_tree, &iter, COL_LASTVISIT, &b, -1); + gtk_label_set_text(GTK_LABEL(glade_xml_get_widget(gladeWindows, + "labelHistoryLastVisit")), b); + + gtk_tree_model_get(history_tree, &iter, COL_TOTALVISITS, + &i, -1); + snprintf(buf, 20, "%d", i); + gtk_label_set_text(GTK_LABEL(glade_xml_get_widget(gladeWindows, + "labelHistoryVisits")), buf); + + + + } + else + { + + } +} + +void nsgtk_history_row_activated(GtkTreeView *tv, GtkTreePath *path, + GtkTreeViewColumn *column, gpointer g) +{ + GtkTreeModel *model; + GtkTreeIter iter; + + model = gtk_tree_view_get_model(tv); + if (gtk_tree_model_get_iter(model, &iter, path)) + { + gchar *b; + + gtk_tree_model_get(model, &iter, COL_ADDRESS, &b, -1); + + browser_window_create((const char *)b, NULL, NULL, true); + } +} + +void global_history_add(const char *url) +{ + const struct url_data *data; + + data = urldb_get_url_data(url); + if (!data) + return; + + nsgtk_history_add_internal(url, data); + +} diff --git a/gtk/gtk_history.h b/gtk/gtk_history.h new file mode 100644 index 000000000..230279b0b --- /dev/null +++ b/gtk/gtk_history.h @@ -0,0 +1,20 @@ +/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2006 Rob Kendrick + */ + +#ifndef __NSGTK_HISTORY_H__ +#define __NSGTK_HISTORY_H__ + +#include + +extern GtkWindow *wndHistory; + +void nsgtk_history_init(void); +void nsgtk_history_update(void); +void nsgtk_history_row_activated(GtkTreeView *, GtkTreePath *, + GtkTreeViewColumn *, gpointer); + +#endif /* __NSGTK_HISTORY_H__ */ diff --git a/gtk/gtk_window.c b/gtk/gtk_window.c index 6fe604c38..183497bd7 100644 --- a/gtk/gtk_window.c +++ b/gtk/gtk_window.c @@ -27,6 +27,7 @@ #include "netsurf/gtk/gtk_options.h" #include "netsurf/gtk/gtk_completion.h" #include "netsurf/gtk/gtk_throbber.h" +#include "netsurf/gtk/gtk_history.h" #include "netsurf/render/box.h" #include "netsurf/render/font.h" #include "netsurf/render/form.h" @@ -151,6 +152,7 @@ MENUPROTO(back); MENUPROTO(forward); MENUPROTO(home); MENUPROTO(local_history); +MENUPROTO(global_history); /* help menu */ MENUPROTO(about); @@ -179,6 +181,7 @@ static struct menu_events menu_events[] = { MENUEVENT(forward), MENUEVENT(home), MENUEVENT(local_history), + MENUEVENT(global_history), /* help menu */ MENUEVENT(about), @@ -609,6 +612,14 @@ MENUHANDLER(local_history) return TRUE; } +MENUHANDLER(global_history) +{ + gtk_widget_show(GTK_WIDGET(wndHistory)); + gdk_window_raise(GDK_WINDOW(wndHistory)); + + return TRUE; +} + MENUHANDLER(about) { return TRUE; diff --git a/gtk/netsurf.glade b/gtk/netsurf.glade index 9509cbfc0..ae414d478 100644 --- a/gtk/netsurf.glade +++ b/gtk/netsurf.glade @@ -707,9 +707,8 @@ - + True - False Show the history tree for all windows. _Global history... True @@ -4374,4 +4373,304 @@ Fantasy + + 400 + 500 + NetSurf Global History + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_CENTER + False + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_UTILITY + GDK_GRAVITY_NORTH_WEST + True + False + + + + + True + False + 0 + + + + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + False + True + False + True + False + False + False + + + + + + 0 + True + True + + + + + + True + True + True + 0 + + + + True + False + 0 + + + + True + 0.5 + 0 + 5 + 5 + + + 0 + False + True + + + + + + 2 + True + 3 + 2 + False + 0 + 4 + + + + True + Address + False + False + GTK_JUSTIFY_LEFT + False + False + 1 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + Last visited + False + False + GTK_JUSTIFY_LEFT + False + False + 1 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + Number of visits + False + False + GTK_JUSTIFY_LEFT + False + False + 1 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 2 + 3 + fill + + + + + + + True + 2 + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_END + -1 + False + 0 + + + 1 + 2 + 2 + 3 + + + + + + + True + Fri Aug 09 00:00:00 2006 + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_END + -1 + False + 0 + + + 1 + 2 + 1 + 2 + + + + + + + True + http://netsurf.sf.net/ + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_MIDDLE + -1 + False + 0 + + + 1 + 2 + 0 + 1 + + + + + + 0 + True + True + + + + + + + + True + Details + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + label_item + + + + + 0 + False + True + + + + + + -- cgit v1.2.3