Very simple global history implementation for nsgtk, misc fixes

svn path=/trunk/netsurf/; revision=2867
This commit is contained in:
Rob Kendrick 2006-08-18 11:44:24 +00:00
parent a1292c7935
commit 43bb5b652d
6 changed files with 487 additions and 6 deletions

View File

@ -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)
{

149
gtk/gtk_history.c Normal file
View File

@ -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 <rjek@rjek.com>
*/
#include <gtk/gtk.h>
#include <glade/glade.h>
#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);
}

20
gtk/gtk_history.h Normal file
View File

@ -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 <rjek@rjek.com>
*/
#ifndef __NSGTK_HISTORY_H__
#define __NSGTK_HISTORY_H__
#include <gtk/gtk.h>
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__ */

View File

@ -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;

View File

@ -707,9 +707,8 @@
</child>
<child>
<widget class="GtkMenuItem" id="global_history1">
<widget class="GtkMenuItem" id="global_history">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="tooltip" translatable="yes">Show the history tree for all windows.</property>
<property name="label" translatable="yes">_Global history...</property>
<property name="use_underline">True</property>
@ -4374,4 +4373,304 @@ Fantasy</property>
</child>
</widget>
<widget class="GtkWindow" id="wndHistory">
<property name="width_request">400</property>
<property name="height_request">500</property>
<property name="title" translatable="yes">NetSurf Global History</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_CENTER</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_UTILITY</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<signal name="delete_event" handler="gtk_widget_hide" last_modification_time="Fri, 18 Aug 2006 10:17:39 GMT"/>
<child>
<widget class="GtkVBox" id="vbox28">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="shadow_type">GTK_SHADOW_IN</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTreeView" id="treeHistory">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="headers_visible">False</property>
<property name="rules_hint">True</property>
<property name="reorderable">False</property>
<property name="enable_search">True</property>
<property name="fixed_height_mode">False</property>
<property name="hover_selection">False</property>
<property name="hover_expand">False</property>
<signal name="row_activated" handler="nsgtk_history_row_activated" last_modification_time="Fri, 18 Aug 2006 11:33:42 GMT"/>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkExpander" id="expander1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="expanded">True</property>
<property name="spacing">0</property>
<child>
<widget class="GtkHBox" id="hbox25">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkImage" id="image400">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0</property>
<property name="xpad">5</property>
<property name="ypad">5</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkTable" id="table11">
<property name="border_width">2</property>
<property name="visible">True</property>
<property name="n_rows">3</property>
<property name="n_columns">2</property>
<property name="homogeneous">False</property>
<property name="row_spacing">0</property>
<property name="column_spacing">4</property>
<child>
<widget class="GtkLabel" id="label117">
<property name="visible">True</property>
<property name="label" translatable="yes">Address</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">1</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label118">
<property name="visible">True</property>
<property name="label" translatable="yes">Last visited</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">1</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label119">
<property name="visible">True</property>
<property name="label" translatable="yes">Number of visits</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">1</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="labelHistoryVisits">
<property name="visible">True</property>
<property name="label" translatable="yes">2</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_END</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="labelHistoryLastVisit">
<property name="visible">True</property>
<property name="label" translatable="yes">Fri Aug 09 00:00:00 2006</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_END</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="labelHistoryAddress">
<property name="visible">True</property>
<property name="label" translatable="yes">http://netsurf.sf.net/</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_MIDDLE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
<child>
<widget class="GtkLabel" id="label116">
<property name="visible">True</property>
<property name="label" translatable="yes">Details</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="type">label_item</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>

View File

@ -69,7 +69,8 @@ OBJECTS_GTK += browser.o history_core.o netsurf.o selection.o textinput.o \
OBJECTS_GTK += font_pango.o gtk_bitmap.o gtk_gui.o \
gtk_schedule.o gtk_thumbnail.o gtk_options.o \
gtk_plotters.o gtk_treeview.o gtk_window.o \
gtk_completion.o gtk_login.o gtk_throbber.o # gtk/
gtk_completion.o gtk_login.o gtk_throbber.o \
gtk_history.o # gtk/
OBJDIR_RISCOS = arm-riscos-aof
@ -122,7 +123,7 @@ CFLAGS_NCOS = $(CFLAGS_RISCOS) -Dncos
CFLAGS_DEBUG = -std=c9x -D_BSD_SOURCE -DDEBUG_BUILD $(WARNFLAGS) -I.. \
$(PLATFORM_CFLAGS_DEBUG) -g
CFLAGS_GTK = -Dnsgtk -std=c9x -D_BSD_SOURCE -D_POSIX_C_SOURCE -Dgtk \
$(WARNFLAGS) -I.. -g -O2 -Wformat=2 \
$(WARNFLAGS) -I.. -g -O0 -Wformat=2 \
`pkg-config --cflags libglade-2.0 gtk+-2.0` `xml2-config --cflags`
# Stop GCC under Cygwin throwing a fit