summaryrefslogtreecommitdiff
path: root/gtk/gtk_history.c
blob: 349643e56a8a9c6032382be4c717769bd692180c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
 * Copyright 2006 Rob Kendrick <rjek@rjek.com>
 *
 * This file is part of NetSurf, http://www.netsurf-browser.org/
 *
 * NetSurf 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; version 2 of the License.
 *
 * NetSurf 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, see <http://www.gnu.org/licenses/>.
 */

#include <gtk/gtk.h>
#include <glade/glade.h>
#include "utils/log.h"
#include "content/urldb.h"
#include "gtk/gtk_history.h"
#include "gtk/gtk_gui.h"
#include "gtk/gtk_window.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;
	GtkTreeModel *model = GTK_TREE_MODEL(history_tree);
	if (gtk_tree_selection_get_selected(treesel, &model, &iter))
	{
		gchar *b;
		gint i;
		char buf[20];

		gtk_tree_model_get(model, &iter, COL_ADDRESS, &b, -1);
		gtk_label_set_text(GTK_LABEL(glade_xml_get_widget(gladeWindows,
						"labelHistoryAddress")), b);

		gtk_tree_model_get(model, &iter, COL_LASTVISIT, &b, -1);
		gtk_label_set_text(GTK_LABEL(glade_xml_get_widget(gladeWindows,
						"labelHistoryLastVisit")), b);

		gtk_tree_model_get(model, &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);

}