summaryrefslogtreecommitdiffstats
path: root/src/toolbars/navigation-toolbar.c
blob: 6a5e772e6d1fb8815845e83bd9781ad485394561 (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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*
 * Navigation toolbar
 *
 * Copyright (C) 2017  Patrick McDermott
 *
 * This file is part of Marquee.
 *
 * Marquee 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 3 of the License, or
 * (at your option) any later version.
 *
 * Marquee 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 Marquee.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "navigation-toolbar.h"

#include <glib.h>
#include <gtk/gtk.h>
#include <webkit2/webkit2.h>

#include "../config/config.h"
#include "../i18n.h"
#include "../tab-page.h"
#include "../web-view.h"
#include "find-toolbar.h"
#include "navigation/back-forward-button-box.h"
#include "navigation/bookmarks-button-box.h"
#include "navigation/downloads-button.h"
#include "navigation/history-button.h"
#include "navigation/home-button.h"
#include "navigation/main-menu.h"
#include "navigation/stop-reload-button.h"
#include "navigation/uri-entry.h"

struct _MqNavigationToolbar {
	GtkToolbar     parent_instance;
	MqConfig      *config;
	MqTabPage     *tab_page;
	MqFindToolbar *find_toolbar;
	MqWebView     *web_view;
	gchar         *uri;
	GtkToolItem   *uri_entry;
};

enum {
	PROP_CONFIG = 1,
	PROP_TAB_PAGE,
	PROP_FIND_TOOLBAR,
	PROP_WEB_VIEW,
	PROP_URI,
	N_PROPERTIES
};

static GParamSpec *obj_properties[N_PROPERTIES] = {NULL,};

struct _MqNavigationToolbarClass {
	GtkToolbarClass parent_class;
};

G_DEFINE_TYPE(MqNavigationToolbar, mq_navigation_toolbar, GTK_TYPE_TOOLBAR)

static void
constructed(GObject *object)
{
	MqNavigationToolbar *navigation_toolbar;
	GtkToolItem         *back_forward_button_box;
	GtkToolItem         *bookmarks_button_box;
	GtkToolItem         *stop_reload_button;
	GtkToolItem         *home_button;
	GtkToolItem         *history_button;
	GtkToolItem         *downloads_button;
	GtkToolItem         *menu_button;

	if (G_OBJECT_CLASS(mq_navigation_toolbar_parent_class)->constructed) {
		G_OBJECT_CLASS(mq_navigation_toolbar_parent_class)->constructed(
			object);
	}

	navigation_toolbar = MQ_NAVIGATION_TOOLBAR(object);

	/* Back/forward button box */
	back_forward_button_box = mq_back_forward_button_box_new(
		navigation_toolbar->web_view);

	/* Stop/reload button */
	stop_reload_button = mq_stop_reload_button_new(
		navigation_toolbar->web_view);

	/* URI entry */
	navigation_toolbar->uri_entry = mq_uri_entry_new(
		navigation_toolbar->web_view, navigation_toolbar->uri);

	/* Bookmarks button box */
	bookmarks_button_box = mq_bookmarks_button_box_new();

	/* Home button */
	home_button = mq_home_button_new(navigation_toolbar->config,
		navigation_toolbar->web_view);

	/* History button */
	history_button = mq_history_button_new();

	/* Downloads button */
	downloads_button = mq_downloads_button_new();

	/* Menu button */
	menu_button = mq_main_menu_new(navigation_toolbar->tab_page,
		navigation_toolbar->find_toolbar, navigation_toolbar->web_view);

	/* Navigation toolbar */
	gtk_toolbar_insert(GTK_TOOLBAR(navigation_toolbar),
		back_forward_button_box, -1);
	gtk_toolbar_insert(GTK_TOOLBAR(navigation_toolbar),
		stop_reload_button, -1);
	gtk_toolbar_insert(GTK_TOOLBAR(navigation_toolbar),
		navigation_toolbar->uri_entry, -1);
	gtk_toolbar_insert(GTK_TOOLBAR(navigation_toolbar),
		bookmarks_button_box, -1);
	gtk_toolbar_insert(GTK_TOOLBAR(navigation_toolbar), home_button, -1);
	gtk_toolbar_insert(GTK_TOOLBAR(navigation_toolbar), history_button, -1);
	gtk_toolbar_insert(GTK_TOOLBAR(navigation_toolbar),
		downloads_button, -1);
	gtk_toolbar_insert(GTK_TOOLBAR(navigation_toolbar), menu_button, -1);

	gtk_widget_set_hexpand(GTK_WIDGET(navigation_toolbar), TRUE);
}

static void
finalize(GObject *object)
{
	MqNavigationToolbar *navigation_toolbar;

	navigation_toolbar = MQ_NAVIGATION_TOOLBAR(object);

	if (navigation_toolbar->uri) {
		g_free(navigation_toolbar->uri);
	}

	G_OBJECT_CLASS(mq_navigation_toolbar_parent_class)->finalize(object);
}

static void
get_property(GObject *object, guint property_id, GValue *value,
	GParamSpec *param_spec)
{
	MqNavigationToolbar *navigation_toolbar;

	navigation_toolbar = MQ_NAVIGATION_TOOLBAR(object);

	switch (property_id) {
		case PROP_CONFIG:
			g_value_set_pointer(value, navigation_toolbar->config);
			break;
		case PROP_TAB_PAGE:
			g_value_set_object(value, navigation_toolbar->tab_page);
			break;
		case PROP_FIND_TOOLBAR:
			g_value_set_object(value,
				navigation_toolbar->find_toolbar);
			break;
		case PROP_WEB_VIEW:
			g_value_set_object(value, navigation_toolbar->web_view);
			break;
		case PROP_URI:
			g_value_set_string(value, navigation_toolbar->uri);
			break;
		default:
			G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id,
				param_spec);
			break;
	}
}

static void
set_property(GObject *object, guint property_id, const GValue *value,
	GParamSpec *param_spec)
{
	MqNavigationToolbar *navigation_toolbar;

	navigation_toolbar = MQ_NAVIGATION_TOOLBAR(object);

	switch (property_id) {
		case PROP_CONFIG:
			navigation_toolbar->config = g_value_get_pointer(value);
			break;
		case PROP_TAB_PAGE:
			navigation_toolbar->tab_page =
				g_value_get_object(value);
			break;
		case PROP_FIND_TOOLBAR:
			navigation_toolbar->find_toolbar =
				g_value_get_object(value);
			break;
		case PROP_WEB_VIEW:
			navigation_toolbar->web_view =
				g_value_get_object(value);
			break;
		case PROP_URI:
			navigation_toolbar->uri = g_strdup(g_value_get_string(
					value));
			break;
		default:
			G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id,
				param_spec);
			break;
	}
}

static void
mq_navigation_toolbar_class_init(MqNavigationToolbarClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS(klass);

	object_class->constructed  = constructed;
	object_class->finalize     = finalize;
	object_class->get_property = get_property;
	object_class->set_property = set_property;

	obj_properties[PROP_CONFIG] = g_param_spec_pointer(
		"config",
		P_("MqConfig"),
		P_("The application's MqConfig instance"),
		G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
		G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB);
	obj_properties[PROP_TAB_PAGE] = g_param_spec_object(
		"tab-page",
		P_("MqTabPage"),
		P_("The ancestral MqTabPage instance"),
		MQ_TYPE_TAB_PAGE,
		G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
		G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB);
	obj_properties[PROP_FIND_TOOLBAR] = g_param_spec_object(
		"find-toolbar",
		P_("MqFindToolbar"),
		P_("The associated MqFindToolbar instance"),
		MQ_TYPE_FIND_TOOLBAR,
		G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
		G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB);
	obj_properties[PROP_WEB_VIEW] = g_param_spec_object(
		"web-view",
		P_("MqWebView"),
		P_("The associated MqWebView instance"),
		MQ_TYPE_WEB_VIEW,
		G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
		G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB);
	obj_properties[PROP_URI] = g_param_spec_string(
		"uri",
		P_("URI"),
		P_("The URI to load"),
		"",
		G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
		G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB);
	g_object_class_install_properties(object_class, N_PROPERTIES,
		obj_properties);
}

static void
mq_navigation_toolbar_init(
	MqNavigationToolbar G_GNUC_UNUSED *navigation_toolbar)
{
}

GtkWidget *
mq_navigation_toolbar_new(MqConfig *config, MqTabPage *tab_page,
	MqFindToolbar *find_toolbar, MqWebView *web_view, const gchar *uri)
{
	return g_object_new(MQ_TYPE_NAVIGATION_TOOLBAR,
		"config", config,
		"tab-page", tab_page,
		"find-toolbar", find_toolbar,
		"web-view", web_view,
		"uri", uri,
		NULL);
}

void
mq_navigation_toolbar_focus_uri_entry(MqNavigationToolbar *navigation_toolbar)
{
	mq_uri_entry_grab_focus(MQ_URI_ENTRY(navigation_toolbar->uri_entry));
}