rev |
line source |
pankso@193
|
1 /*
|
pankso@193
|
2 * TazWeb is a radically simple web browser providing a single window
|
paul@196
|
3 * with a single toolbar with buttons, a URL entry and search as well
|
pankso@193
|
4 * as a contextual menu, but no menu bar or tabs. Commented line code
|
pankso@201
|
5 * starts with // and comments are between * *. IDE: Geany
|
pankso@193
|
6 *
|
pankso@193
|
7 * NEXT GENERATION
|
pankso@193
|
8 * This is TazWeb NG (2.0) with tabs and cookies support :-)
|
pankso@193
|
9 *
|
pankso@193
|
10 * Copyright (C) 2011-2017 SliTaz GNU/Linux - BSD License
|
pankso@193
|
11 * See AUTHORS and LICENSE for detailed information
|
pankso@193
|
12 *
|
pankso@193
|
13 */
|
pankso@193
|
14
|
pankso@199
|
15 #include <stdlib.h>
|
pankso@199
|
16 #include <sys/queue.h>
|
pankso@199
|
17 #include <getopt.h>
|
pankso@193
|
18 #include <glib.h>
|
pankso@193
|
19 #include <glib/gi18n.h>
|
pankso@193
|
20
|
pankso@193
|
21 #include <gtk/gtk.h>
|
pankso@193
|
22 #include <webkit/webkit.h>
|
pankso@199
|
23 #include <libsoup/soup.h>
|
pankso@193
|
24
|
pankso@201
|
25 #define VERSION "2.0"
|
pankso@200
|
26 #define GETTEXT_PACKAGE "tazweb"
|
pankso@200
|
27 #define WEBHOME "file:///usr/share/webhome/index.html"
|
pankso@200
|
28 #define SEARCH "http://duckduckgo.com/?q=%s&t=slitaz"
|
pankso@199
|
29 #define HOME g_get_home_dir()
|
pankso@199
|
30 #define CONFIG g_strdup_printf("%s/.config/tazweb", HOME)
|
pankso@199
|
31 #define BOOKMARKS g_strdup_printf("%s/bookmarks.txt", CONFIG)
|
pankso@199
|
32 #define COOKIES g_strdup_printf("%s/cookies.txt", CONFIG)
|
pankso@199
|
33 #define DOWNLOADS g_strdup_printf("%s/Downloads", HOME)
|
pankso@200
|
34
|
pankso@200
|
35 /* User agent string */
|
pankso@200
|
36 #define UA_TAZWEB g_strdup_printf("TazWeb/%s (X11; SliTaz GNU/Linux)", VERSION)
|
pankso@200
|
37 #define UA_COMPAT "Mozilla/5.0 AppleWebKit/535.22+"
|
pankso@200
|
38 #define UA g_strdup_printf("%s %s", UA_TAZWEB, UA_COMPAT)
|
pankso@193
|
39
|
pankso@199
|
40 int width = 800;
|
pankso@199
|
41 int height = 600;
|
pankso@199
|
42 int private = 0;
|
pankso@193
|
43
|
pankso@200
|
44 static gchar *useragent;
|
pankso@199
|
45 static gboolean notoolbar;
|
pankso@199
|
46 static gboolean nomenu;
|
pankso@199
|
47 static gboolean kiosk;
|
pankso@193
|
48
|
pankso@199
|
49 static GtkWidget *tazweb_window;
|
pankso@199
|
50 static GtkNotebook *notebook;
|
pankso@193
|
51 static SoupSession *session;
|
pankso@193
|
52 static SoupCookieJar *cookiejar;
|
pankso@199
|
53 const gchar* uri;
|
pankso@193
|
54
|
pankso@193
|
55 /* Tab structure */
|
pankso@193
|
56 struct tab {
|
pankso@193
|
57 TAILQ_ENTRY(tab) entry;
|
pankso@193
|
58 GtkWidget *vbox;
|
pankso@193
|
59 GtkWidget *label;
|
pankso@193
|
60 GtkWidget *urientry;
|
pankso@193
|
61 GtkWidget *search_entry;
|
pankso@193
|
62 GtkWidget *toolbar;
|
pankso@193
|
63 GtkWidget *browser;
|
pankso@193
|
64 GtkToolItem *backward;
|
pankso@193
|
65 GtkToolItem *forward;
|
pankso@193
|
66 GtkToolItem *home;
|
pankso@193
|
67 GtkToolItem *bookmarks;
|
pankso@193
|
68 GtkToolItem *ttb;
|
pankso@193
|
69 GtkWidget *spinner;
|
pankso@193
|
70 guint tab_id;
|
pankso@193
|
71 int focus_wv;
|
pankso@193
|
72 WebKitWebView *webview;
|
pankso@193
|
73 };
|
pankso@193
|
74 TAILQ_HEAD(tab_list, tab);
|
pankso@193
|
75 struct tab_list tabs;
|
pankso@193
|
76
|
pankso@193
|
77 /* Protocols */
|
pankso@193
|
78 void create_new_tab(char *, int);
|
pankso@193
|
79 void close_tab(struct tab *);
|
pankso@193
|
80
|
pankso@193
|
81 /* Create an icon */
|
pankso@193
|
82 static GdkPixbuf*
|
pankso@193
|
83 create_pixbuf(const gchar* image)
|
pankso@193
|
84 {
|
pankso@193
|
85 GdkPixbuf *pixbuf;
|
pankso@193
|
86 pixbuf = gdk_pixbuf_new_from_file(image, NULL);
|
pankso@193
|
87 return pixbuf;
|
pankso@193
|
88 }
|
pankso@193
|
89
|
pankso@193
|
90 /* Can be: http://hg.slitaz.org or hg.slitaz.org */
|
pankso@193
|
91 static void
|
pankso@193
|
92 check_requested_uri()
|
pankso@193
|
93 {
|
pankso@193
|
94 uri = g_strrstr(uri, "://") ? g_strdup(uri)
|
pankso@193
|
95 : g_strdup_printf("http://%s", uri);
|
pankso@193
|
96 }
|
pankso@193
|
97
|
pankso@193
|
98 int destroy_cb()
|
pankso@193
|
99 {
|
pankso@193
|
100 gtk_main_quit();
|
pankso@193
|
101 return (1);
|
pankso@193
|
102 }
|
pankso@193
|
103
|
pankso@193
|
104 int focus()
|
pankso@193
|
105 {
|
pankso@193
|
106 return (0);
|
pankso@193
|
107 }
|
pankso@193
|
108
|
pankso@193
|
109 static void
|
pankso@193
|
110 uri_entry_cb(GtkWidget* entry, struct tab *ttb)
|
pankso@193
|
111 {
|
pankso@193
|
112 uri = gtk_entry_get_text(GTK_ENTRY(entry));
|
pankso@193
|
113 g_assert(uri);
|
pankso@193
|
114 check_requested_uri();
|
pankso@193
|
115 webkit_web_view_load_uri(ttb->webview, uri);
|
pankso@193
|
116 gtk_widget_grab_focus(GTK_WIDGET(ttb->webview));
|
pankso@193
|
117 }
|
pankso@193
|
118
|
pankso@193
|
119 static void
|
pankso@193
|
120 notify_load_status_cb(WebKitWebView* webview, GParamSpec* pspec,
|
pankso@193
|
121 struct tab *ttb)
|
pankso@193
|
122 {
|
pankso@193
|
123 GString *string;
|
pankso@193
|
124 WebKitWebFrame *frame;
|
pankso@193
|
125 const gchar *uri, *title;
|
pankso@193
|
126 gdouble progress;
|
pankso@193
|
127
|
pankso@193
|
128 switch (webkit_web_view_get_load_status(webview)) {
|
pankso@193
|
129
|
pankso@193
|
130 /* Webkit is loading */
|
pankso@193
|
131 case WEBKIT_LOAD_COMMITTED:
|
pankso@193
|
132 frame = webkit_web_view_get_main_frame(webview);
|
pankso@193
|
133 uri = webkit_web_frame_get_uri(frame);
|
pankso@193
|
134
|
pankso@193
|
135 string = g_string_new("Loading");
|
pankso@193
|
136 progress = webkit_web_view_get_progress(webview) * 100;
|
pankso@193
|
137 if (progress < 100)
|
pankso@193
|
138 g_string_append_printf(string, " (%f%%)", progress);
|
pankso@193
|
139
|
pankso@193
|
140 title = g_string_free(string, FALSE);
|
pankso@193
|
141 gtk_label_set_text(GTK_LABEL(ttb->label), title);
|
pankso@193
|
142
|
pankso@193
|
143 /* Start spinner */
|
pankso@193
|
144 gtk_widget_show(ttb->spinner);
|
pankso@193
|
145 gtk_spinner_start(GTK_SPINNER(ttb->spinner));
|
pankso@193
|
146
|
pankso@193
|
147 /* Update URL entry */
|
pankso@193
|
148 if (uri)
|
pankso@193
|
149 gtk_entry_set_text(GTK_ENTRY(ttb->urientry), uri);
|
pankso@193
|
150
|
pankso@193
|
151 /* Focus */
|
pankso@193
|
152 ttb->focus_wv = 1;
|
pankso@193
|
153 if (gtk_notebook_get_current_page(notebook) == ttb->tab_id)
|
pankso@193
|
154 gtk_widget_grab_focus(GTK_WIDGET(ttb->webview));
|
pankso@193
|
155 break;
|
pankso@193
|
156
|
pankso@193
|
157 /* First layout with actual visible content */
|
pankso@193
|
158 case WEBKIT_LOAD_FIRST_VISUALLY_NON_EMPTY_LAYOUT:
|
pankso@193
|
159 title = webkit_web_view_get_title(webview);
|
pankso@193
|
160 gtk_label_set_text(GTK_LABEL(ttb->label), title);
|
pankso@193
|
161 break;
|
pankso@193
|
162
|
pankso@193
|
163 /* URL was loaded */
|
pankso@193
|
164 case WEBKIT_LOAD_FINISHED:
|
pankso@193
|
165 title = webkit_web_view_get_title(webview);
|
pankso@193
|
166 gtk_label_set_text(GTK_LABEL(ttb->label), title);
|
pankso@193
|
167 gtk_spinner_stop(GTK_SPINNER(ttb->spinner));
|
pankso@193
|
168 gtk_widget_hide(ttb->spinner);
|
pankso@193
|
169 break;
|
pankso@193
|
170
|
pankso@193
|
171 /* URL fail to load */
|
pankso@193
|
172 case WEBKIT_LOAD_FAILED:
|
pankso@193
|
173 gtk_label_set_text(GTK_LABEL(ttb->label), "Failed");
|
pankso@193
|
174 gtk_spinner_stop(GTK_SPINNER(ttb->spinner));
|
pankso@193
|
175 gtk_widget_hide(ttb->spinner);
|
pankso@193
|
176 break;
|
pankso@193
|
177
|
pankso@193
|
178 }
|
pankso@193
|
179
|
pankso@193
|
180 gtk_widget_set_sensitive(GTK_WIDGET(ttb->backward),
|
pankso@193
|
181 webkit_web_view_can_go_back(webview));
|
pankso@193
|
182
|
pankso@193
|
183 gtk_widget_set_sensitive(GTK_WIDGET(ttb->forward),
|
pankso@193
|
184 webkit_web_view_can_go_forward(webview));
|
pankso@193
|
185 }
|
pankso@193
|
186
|
pankso@193
|
187 /* Search entry and icon callback function */
|
pankso@193
|
188 static void
|
pankso@193
|
189 search_entry_cb(GtkWidget* search_entry, struct tab *ttb)
|
pankso@193
|
190 {
|
pankso@193
|
191 uri = g_strdup_printf(SEARCH, gtk_entry_get_text(GTK_ENTRY(search_entry)));
|
pankso@193
|
192 g_assert(uri);
|
pankso@193
|
193 webkit_web_view_load_uri(ttb->webview, uri);
|
pankso@193
|
194 }
|
pankso@193
|
195
|
pankso@193
|
196 static void
|
pankso@193
|
197 search_icon_cb(GtkWidget *search_entry, GtkEntryIconPosition pos,
|
pankso@193
|
198 GdkEvent *event, struct tab *ttb)
|
pankso@193
|
199 {
|
pankso@193
|
200 search_entry_cb(search_entry, ttb);
|
pankso@193
|
201 }
|
pankso@193
|
202
|
pankso@202
|
203 /*
|
pankso@202
|
204 *
|
pankso@202
|
205 * Navigation functions
|
pankso@202
|
206 *
|
pankso@202
|
207 */
|
pankso@202
|
208
|
pankso@193
|
209 static void
|
pankso@202
|
210 bookmarks_edit_cb()
|
pankso@193
|
211 {
|
pankso@202
|
212 system("/usr/lib/tazweb/helper.sh bookmarks_handler &");
|
pankso@193
|
213 }
|
pankso@193
|
214
|
pankso@193
|
215 static void
|
pankso@202
|
216 go_bookmarks_cb(GtkWidget* w, struct tab *ttb)
|
pankso@193
|
217 {
|
pankso@202
|
218 system("/usr/lib/tazweb/helper.sh html_bookmarks");
|
pankso@202
|
219 uri = g_strdup_printf("file://%s/bookmarks.html", CONFIG);
|
pankso@202
|
220 g_assert(uri);
|
pankso@202
|
221 webkit_web_view_load_uri(ttb->webview, uri);
|
pankso@193
|
222 }
|
pankso@193
|
223
|
pankso@193
|
224 static void
|
pankso@193
|
225 go_home_cb(GtkWidget* w, struct tab *ttb)
|
pankso@193
|
226 {
|
pankso@193
|
227 uri = WEBHOME;
|
pankso@193
|
228 g_assert(uri);
|
pankso@193
|
229 webkit_web_view_load_uri(ttb->webview, uri);
|
pankso@193
|
230 }
|
pankso@193
|
231
|
pankso@193
|
232 static void
|
pankso@202
|
233 go_back_cb(GtkWidget *widget, struct tab *ttb)
|
pankso@193
|
234 {
|
pankso@202
|
235 webkit_web_view_go_back(ttb->webview);
|
pankso@202
|
236 }
|
pankso@202
|
237
|
pankso@202
|
238 static void
|
pankso@202
|
239 go_forward_cb(GtkWidget *widget, struct tab *ttb)
|
pankso@202
|
240 {
|
pankso@202
|
241 webkit_web_view_go_forward(ttb->webview);
|
pankso@193
|
242 }
|
pankso@193
|
243
|
pankso@193
|
244 /* Setup session cookies */
|
pankso@193
|
245 void
|
pankso@193
|
246 cookies_setup(void)
|
pankso@193
|
247 {
|
pankso@193
|
248 if (cookiejar) {
|
pankso@193
|
249 soup_session_remove_feature(session,
|
pankso@193
|
250 (SoupSessionFeature*)cookiejar);
|
pankso@193
|
251 g_object_unref(cookiejar);
|
pankso@193
|
252 cookiejar = NULL;
|
pankso@193
|
253 }
|
pankso@193
|
254
|
pankso@193
|
255 cookiejar = soup_cookie_jar_text_new(COOKIES, 0);
|
pankso@193
|
256 soup_session_add_feature(session, (SoupSessionFeature*)cookiejar);
|
pankso@193
|
257 }
|
pankso@193
|
258
|
pankso@193
|
259 static void
|
pankso@193
|
260 cookies_view_cb(GtkWidget* widget, WebKitWebView* webview)
|
pankso@193
|
261 {
|
pankso@193
|
262 system("/usr/lib/tazweb/helper.sh html_cookies");
|
pankso@193
|
263 uri = g_strdup_printf("file://%s/cookies.html", CONFIG);
|
pankso@193
|
264 g_assert(uri);
|
pankso@193
|
265 webkit_web_view_load_uri(webview, uri);
|
pankso@193
|
266 }
|
pankso@193
|
267
|
pankso@193
|
268 static void
|
pankso@202
|
269 cookies_clean_cb()
|
pankso@193
|
270 {
|
pankso@193
|
271 system("/usr/lib/tazweb/helper.sh clean_cookies");
|
pankso@193
|
272 }
|
pankso@193
|
273
|
pankso@193
|
274 /* Add items to WebKit contextual menu */
|
pankso@193
|
275 static void
|
pankso@193
|
276 populate_menu_cb(WebKitWebView *ttb, GtkMenu *menu, gpointer data)
|
pankso@193
|
277 {
|
pankso@193
|
278 GtkWidget* item;
|
pankso@193
|
279
|
pankso@193
|
280 /* Separator */
|
pankso@193
|
281 item = gtk_separator_menu_item_new();
|
pankso@193
|
282 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
|
pankso@203
|
283
|
pankso@203
|
284 /* Bookmark */
|
pankso@203
|
285 //item = gtk_image_menu_item_new_with_label(_("Bookmarks"));
|
pankso@203
|
286 //gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
|
pankso@203
|
287 //gtk_image_new_from_stock(GTK_STOCK_PROPERTIES, GTK_ICON_SIZE_MENU));
|
pankso@203
|
288 //gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
|
pankso@203
|
289 //g_signal_connect(item, "activate", G_CALLBACK(go_bookmarks_cb), webview);
|
pankso@193
|
290
|
pankso@202
|
291 if (! kiosk) {
|
pankso@193
|
292 ///* Add a bookmark */
|
pankso@193
|
293 //item = gtk_image_menu_item_new_with_label(_("Add a bookmark"));
|
pankso@193
|
294 //gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
|
pankso@193
|
295 //gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
|
pankso@193
|
296 //gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
|
pankso@193
|
297 //g_signal_connect(item, "activate", G_CALLBACK(add_bookmark_cb), webview);
|
pankso@202
|
298
|
pankso@202
|
299 /* Edit bookmarks */
|
pankso@202
|
300 item = gtk_image_menu_item_new_with_label(_("Edit bookmarks"));
|
pankso@202
|
301 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
|
pankso@202
|
302 gtk_image_new_from_stock(GTK_STOCK_EDIT, GTK_ICON_SIZE_MENU));
|
pankso@202
|
303 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
|
pankso@202
|
304 g_signal_connect(item, "activate", G_CALLBACK(bookmarks_edit_cb), NULL);
|
pankso@202
|
305
|
pankso@202
|
306 /* Separator */
|
pankso@202
|
307 item = gtk_separator_menu_item_new();
|
pankso@202
|
308 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
|
pankso@202
|
309 }
|
pankso@193
|
310
|
pankso@193
|
311 ///* Printing */
|
pankso@193
|
312 //item = gtk_image_menu_item_new_with_label(_("Print this page"));
|
pankso@193
|
313 //gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
|
pankso@193
|
314 //gtk_image_new_from_stock(GTK_STOCK_PRINT, GTK_ICON_SIZE_MENU));
|
pankso@193
|
315 //gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
|
pankso@193
|
316 //g_signal_connect(item, "activate", G_CALLBACK(print_page_cb), webview);
|
pankso@193
|
317
|
pankso@193
|
318 ///* View source mode */
|
pankso@193
|
319 //item = gtk_image_menu_item_new_with_label(_("View source mode"));
|
pankso@193
|
320 //gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
|
pankso@193
|
321 //gtk_image_new_from_stock(GTK_STOCK_PROPERTIES, GTK_ICON_SIZE_MENU));
|
pankso@193
|
322 //gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
|
pankso@193
|
323 //g_signal_connect(item, "activate", G_CALLBACK(view_source_cb), webview);
|
pankso@193
|
324
|
pankso@193
|
325 ///* Separator */
|
pankso@193
|
326 //item = gtk_separator_menu_item_new();
|
pankso@193
|
327 //gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
|
pankso@193
|
328
|
pankso@193
|
329 ///* TazWeb documentation */
|
pankso@193
|
330 //item = gtk_image_menu_item_new_with_label(_("TazWeb manual"));
|
pankso@193
|
331 //gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
|
pankso@193
|
332 //gtk_image_new_from_stock(GTK_STOCK_HELP, GTK_ICON_SIZE_MENU));
|
pankso@193
|
333 //gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
|
pankso@193
|
334 //g_signal_connect(item, "activate", G_CALLBACK(tazweb_doc_cb), webview);
|
pankso@202
|
335
|
pankso@202
|
336 /* Cookies */
|
pankso@202
|
337 if (! private) {
|
pankso@202
|
338 //item = gtk_image_menu_item_new_with_label(_("View cookies"));
|
pankso@202
|
339 //gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
|
pankso@202
|
340 //gtk_image_new_from_stock(GTK_STOCK_HELP, GTK_ICON_SIZE_MENU));
|
pankso@202
|
341 //gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
|
pankso@202
|
342 //g_signal_connect(item, "activate", G_CALLBACK(cookies_view_cb), webview);
|
pankso@202
|
343
|
pankso@202
|
344 item = gtk_image_menu_item_new_with_label(_("Clean all cookies"));
|
pankso@202
|
345 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
|
pankso@202
|
346 gtk_image_new_from_stock(GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU));
|
pankso@202
|
347 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
|
pankso@202
|
348 g_signal_connect(item, "activate", G_CALLBACK(cookies_clean_cb), NULL);
|
pankso@202
|
349
|
pankso@202
|
350 /* Separator */
|
pankso@202
|
351 item = gtk_separator_menu_item_new();
|
pankso@202
|
352 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
|
pankso@202
|
353 }
|
pankso@193
|
354
|
pankso@193
|
355 /* Quit TazWeb */
|
pankso@193
|
356 item = gtk_image_menu_item_new_with_label(_("Quit TazWeb"));
|
pankso@193
|
357 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
|
pankso@193
|
358 gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU));
|
pankso@193
|
359 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
|
pankso@193
|
360 g_signal_connect(item, "activate", G_CALLBACK(destroy_cb), NULL);
|
pankso@193
|
361
|
pankso@193
|
362 gtk_widget_show_all(GTK_WIDGET(menu));
|
pankso@193
|
363 }
|
pankso@193
|
364
|
pankso@199
|
365 /* Create a new tab callback */
|
pankso@199
|
366 static void
|
pankso@199
|
367 create_new_tab_cb()
|
pankso@199
|
368 {
|
pankso@199
|
369 create_new_tab(WEBHOME, +1);
|
pankso@199
|
370 }
|
pankso@199
|
371
|
pankso@193
|
372 /* The browser */
|
pankso@193
|
373 GtkWidget *
|
pankso@193
|
374 create_browser(struct tab *ttb)
|
pankso@193
|
375 {
|
pankso@193
|
376 GtkWidget *window;
|
pankso@193
|
377 WebKitWebSettings *settings;
|
pankso@193
|
378
|
pankso@193
|
379 window = gtk_scrolled_window_new(NULL, NULL);
|
pankso@193
|
380 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(window),
|
pankso@193
|
381 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
pankso@193
|
382
|
pankso@193
|
383 ttb->webview = WEBKIT_WEB_VIEW(webkit_web_view_new());
|
pankso@193
|
384 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(ttb->webview));
|
pankso@193
|
385
|
pankso@199
|
386 /* Webkit settings */
|
pankso@193
|
387 settings = webkit_web_view_get_settings (ttb->webview);
|
pankso@200
|
388 if (! useragent)
|
pankso@200
|
389 useragent = g_strdup_printf("%s", UA);
|
pankso@193
|
390 g_object_set(G_OBJECT(settings), "user-agent", useragent, NULL);
|
pankso@199
|
391
|
pankso@199
|
392 if (private)
|
pankso@199
|
393 g_object_set(G_OBJECT(settings), "enable-private-browsing", TRUE);
|
pankso@193
|
394
|
pankso@199
|
395 /* Connect Webkit events */
|
pankso@193
|
396 g_signal_connect(ttb->webview, "notify::load-status",
|
pankso@193
|
397 G_CALLBACK(notify_load_status_cb), ttb);
|
pankso@199
|
398
|
pankso@203
|
399
|
pankso@203
|
400 // BUGGY We want to be able to open link in new tab from contectual menu
|
pankso@199
|
401 ////////////////////////////////////////////////////////////////////
|
pankso@199
|
402 //g_signal_connect(ttb->webview, "create-web-view",
|
pankso@203
|
403 // G_CALLBACK(create_new_tab), NULL);
|
pankso@199
|
404
|
pankso@193
|
405
|
pankso@193
|
406 /* Connect WebKit contextual menu items */
|
pankso@193
|
407 g_object_connect(G_OBJECT(ttb->webview), "signal::populate-popup",
|
pankso@193
|
408 G_CALLBACK(populate_menu_cb), ttb, NULL);
|
pankso@193
|
409
|
pankso@193
|
410 return (window);
|
pankso@193
|
411 }
|
pankso@193
|
412
|
pankso@193
|
413 /* Toolbar with URL and search entry */
|
pankso@193
|
414 GtkWidget *
|
pankso@193
|
415 create_toolbar(struct tab *ttb)
|
pankso@193
|
416 {
|
pankso@193
|
417 GtkWidget *toolbar = gtk_toolbar_new();
|
pankso@193
|
418 GtkToolItem *item;
|
pankso@193
|
419
|
pankso@193
|
420 gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar),
|
pankso@193
|
421 GTK_ORIENTATION_HORIZONTAL);
|
pankso@193
|
422 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar),
|
pankso@193
|
423 GTK_TOOLBAR_BOTH_HORIZ);
|
pankso@193
|
424
|
pankso@193
|
425 /* New tab button */
|
pankso@193
|
426 item = gtk_tool_button_new_from_stock(GTK_STOCK_ADD);
|
pankso@193
|
427 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
|
pankso@193
|
428 g_signal_connect(G_OBJECT(item), "clicked",
|
pankso@193
|
429 G_CALLBACK(create_new_tab_cb), FALSE);
|
pankso@193
|
430
|
pankso@193
|
431 /* The backward button */
|
pankso@193
|
432 ttb->backward = gtk_tool_button_new_from_stock(GTK_STOCK_GO_BACK);
|
pankso@193
|
433 gtk_widget_set_sensitive(GTK_WIDGET(ttb->backward), FALSE);
|
pankso@193
|
434 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), ttb->backward, -1);
|
pankso@193
|
435 g_signal_connect(G_OBJECT(ttb->backward), "clicked",
|
pankso@193
|
436 G_CALLBACK(go_back_cb), ttb);
|
pankso@193
|
437
|
pankso@193
|
438 /* The forward button */
|
pankso@193
|
439 ttb->forward = gtk_tool_button_new_from_stock(GTK_STOCK_GO_FORWARD);
|
pankso@193
|
440 gtk_widget_set_sensitive(GTK_WIDGET(ttb->forward), FALSE);
|
pankso@193
|
441 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), ttb->forward, -1);
|
pankso@193
|
442 g_signal_connect(G_OBJECT(ttb->forward), "clicked",
|
pankso@193
|
443 G_CALLBACK(go_forward_cb), ttb);
|
pankso@193
|
444
|
pankso@193
|
445 /* URL entry */
|
pankso@193
|
446 item = gtk_tool_item_new();
|
pankso@193
|
447 gtk_tool_item_set_expand(item, TRUE);
|
pankso@193
|
448 //gtk_widget_set_size_request(urientry, 0, 20);
|
pankso@193
|
449 ttb->urientry = gtk_entry_new();
|
pankso@193
|
450 gtk_container_add(GTK_CONTAINER(item), ttb->urientry);
|
pankso@193
|
451 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
|
pankso@193
|
452 g_signal_connect(G_OBJECT(ttb->urientry), "activate",
|
pankso@193
|
453 G_CALLBACK(uri_entry_cb), ttb);
|
pankso@193
|
454
|
pankso@193
|
455 /* Separator --> 4-6px */
|
pankso@193
|
456 item = gtk_separator_tool_item_new();
|
pankso@193
|
457 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
|
pankso@193
|
458
|
pankso@193
|
459 /* Search entry */
|
pankso@193
|
460 item = gtk_tool_item_new();
|
pankso@193
|
461 gtk_tool_item_set_expand(item, FALSE);
|
pankso@193
|
462 gtk_widget_set_size_request(GTK_WIDGET(item), 200, 0);
|
pankso@193
|
463 ttb->search_entry = gtk_entry_new();
|
pankso@193
|
464
|
pankso@193
|
465 gtk_entry_set_icon_from_stock(GTK_ENTRY(ttb->search_entry),
|
pankso@193
|
466 GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_FIND);
|
pankso@193
|
467 gtk_container_add(GTK_CONTAINER(item), ttb->search_entry);
|
pankso@193
|
468
|
pankso@193
|
469 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
|
pankso@193
|
470 g_signal_connect(GTK_ENTRY(ttb->search_entry), "icon-press",
|
pankso@193
|
471 G_CALLBACK(search_icon_cb), ttb);
|
pankso@193
|
472 g_signal_connect(G_OBJECT(ttb->search_entry), "activate",
|
pankso@193
|
473 G_CALLBACK(search_entry_cb), ttb);
|
pankso@193
|
474
|
pankso@193
|
475 /* Home button */
|
pankso@193
|
476 ttb->home = gtk_tool_button_new_from_stock(GTK_STOCK_HOME);
|
pankso@193
|
477 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), ttb->home, -1);
|
pankso@193
|
478 g_signal_connect(G_OBJECT(ttb->home), "clicked",
|
pankso@193
|
479 G_CALLBACK(go_home_cb), ttb);
|
pankso@193
|
480
|
pankso@193
|
481 /* Bookmarks button */
|
pankso@193
|
482 ttb->bookmarks = gtk_tool_button_new_from_stock(GTK_STOCK_PROPERTIES);
|
pankso@197
|
483 gtk_widget_set_tooltip_text(GTK_WIDGET(item), "Bookmarks");
|
pankso@193
|
484 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), ttb->bookmarks, -1);
|
pankso@193
|
485 g_signal_connect(G_OBJECT(ttb->bookmarks), "clicked",
|
pankso@193
|
486 G_CALLBACK(go_bookmarks_cb), ttb);
|
pankso@193
|
487
|
pankso@193
|
488 return (toolbar);
|
pankso@193
|
489 }
|
pankso@193
|
490
|
pankso@193
|
491 void
|
pankso@193
|
492 close_tab(struct tab *ttb)
|
pankso@193
|
493 {
|
pankso@193
|
494 if (ttb == NULL)
|
pankso@193
|
495 return;
|
pankso@193
|
496
|
pankso@193
|
497 TAILQ_REMOVE(&tabs, ttb, entry);
|
pankso@193
|
498 if (TAILQ_EMPTY(&tabs))
|
pankso@193
|
499 create_new_tab(NULL, 1);
|
pankso@193
|
500
|
pankso@193
|
501 webkit_web_view_stop_loading(ttb->webview);
|
pankso@193
|
502 gtk_widget_destroy(ttb->vbox);
|
pankso@193
|
503 g_free(ttb);
|
pankso@193
|
504 }
|
pankso@193
|
505
|
pankso@193
|
506 gboolean
|
pankso@193
|
507 close_tab_cb(GtkWidget *event_box, GdkEventButton *event, struct tab *ttb)
|
pankso@193
|
508 {
|
pankso@193
|
509 close_tab(ttb);
|
pankso@193
|
510 return (FALSE);
|
pankso@193
|
511 }
|
pankso@193
|
512
|
pankso@193
|
513 void
|
pankso@193
|
514 create_new_tab(char *title, int focus)
|
pankso@193
|
515 {
|
pankso@193
|
516 struct tab *ttb;
|
pankso@193
|
517 int load = 1;
|
pankso@193
|
518 char *newuri = NULL;
|
pankso@193
|
519 GtkWidget *image, *hbox, *event_box;
|
pankso@193
|
520
|
pankso@193
|
521 ttb = g_malloc0(sizeof *ttb);
|
pankso@193
|
522 TAILQ_INSERT_TAIL(&tabs, ttb, entry);
|
pankso@193
|
523
|
pankso@193
|
524 if (title == NULL) {
|
pankso@193
|
525 title = "Empty";
|
pankso@193
|
526 load = 0;
|
pankso@193
|
527 }
|
pankso@193
|
528
|
pankso@193
|
529 ttb->vbox = gtk_vbox_new(FALSE, 0);
|
pankso@193
|
530
|
pankso@193
|
531 /* Tab title, spinner & close button */
|
pankso@193
|
532 hbox = gtk_hbox_new(FALSE, 0);
|
pankso@193
|
533 ttb->spinner = gtk_spinner_new();
|
pankso@193
|
534 ttb->label = gtk_label_new(title);
|
pankso@193
|
535 image = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
|
pankso@193
|
536
|
pankso@193
|
537 event_box = gtk_event_box_new();
|
pankso@193
|
538 gtk_container_add(GTK_CONTAINER(event_box), image);
|
pankso@193
|
539
|
pankso@193
|
540 gtk_widget_set_size_request(ttb->label, 160, -1);
|
pankso@193
|
541 gtk_box_pack_start(GTK_BOX(hbox), ttb->spinner, FALSE, FALSE, 0);
|
pankso@193
|
542 gtk_box_pack_start(GTK_BOX(hbox), ttb->label, FALSE, FALSE, 0);
|
pankso@193
|
543 gtk_box_pack_start(GTK_BOX(hbox), event_box, FALSE, FALSE, 0);
|
pankso@193
|
544
|
pankso@193
|
545 /* Toolbar */
|
pankso@193
|
546 ttb->toolbar = create_toolbar(ttb);
|
pankso@193
|
547 gtk_box_pack_start(GTK_BOX(ttb->vbox), ttb->toolbar,
|
pankso@193
|
548 FALSE, FALSE, 0);
|
pankso@193
|
549
|
pankso@193
|
550 /* Browser */
|
pankso@193
|
551 ttb->browser = create_browser(ttb);
|
pankso@193
|
552 gtk_box_pack_start(GTK_BOX(ttb->vbox), ttb->browser, TRUE, TRUE, 0);
|
pankso@193
|
553
|
pankso@193
|
554 /* Show all widgets */
|
pankso@193
|
555 gtk_widget_show_all(hbox);
|
pankso@193
|
556 gtk_widget_show_all(ttb->vbox);
|
pankso@193
|
557 ttb->tab_id = gtk_notebook_append_page(notebook, ttb->vbox, hbox);
|
pankso@193
|
558
|
pankso@193
|
559 /* Reorderable notebook tabs */
|
pankso@193
|
560 gtk_notebook_set_tab_reorderable(notebook, ttb->vbox, TRUE);
|
pankso@193
|
561
|
pankso@193
|
562 /* Close tab event */
|
pankso@193
|
563 g_signal_connect(G_OBJECT(event_box), "button_press_event",
|
pankso@193
|
564 G_CALLBACK(close_tab_cb), ttb);
|
pankso@193
|
565
|
pankso@193
|
566 if (notoolbar)
|
pankso@193
|
567 gtk_widget_hide(ttb->toolbar);
|
pankso@193
|
568
|
pankso@193
|
569 if (focus) {
|
pankso@193
|
570 gtk_notebook_set_current_page(notebook, ttb->tab_id);
|
pankso@193
|
571 }
|
pankso@193
|
572
|
pankso@193
|
573 if (load)
|
pankso@193
|
574 webkit_web_view_load_uri(ttb->webview, title);
|
pankso@193
|
575 else
|
pankso@193
|
576 gtk_widget_grab_focus(GTK_WIDGET(ttb->urientry));
|
pankso@193
|
577
|
pankso@193
|
578 if (newuri)
|
pankso@193
|
579 free(newuri);
|
pankso@193
|
580 }
|
pankso@193
|
581
|
pankso@193
|
582 /* Main window */
|
pankso@193
|
583 GtkWidget *
|
pankso@193
|
584 create_window(void)
|
pankso@193
|
585 {
|
pankso@193
|
586 GtkWidget *window;
|
pankso@193
|
587
|
pankso@193
|
588 /* Default TazWeb window */
|
pankso@193
|
589 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
pankso@199
|
590 gtk_window_set_default_size(GTK_WINDOW(window), width, height);
|
pankso@193
|
591 gtk_window_set_icon_name(GTK_WINDOW(window), "tazweb");
|
pankso@193
|
592 gtk_widget_set_name(window, "TazWeb");
|
pankso@193
|
593 gtk_window_set_wmclass(GTK_WINDOW(window), "tazweb", "TazWeb");
|
pankso@193
|
594 g_signal_connect(window, "destroy", G_CALLBACK(destroy_cb), NULL);
|
pankso@193
|
595
|
pankso@193
|
596 return (window);
|
pankso@193
|
597 }
|
pankso@193
|
598
|
pankso@193
|
599 void
|
pankso@193
|
600 create_canvas(void)
|
pankso@193
|
601 {
|
pankso@193
|
602 GtkWidget *vbox;
|
pankso@193
|
603
|
pankso@193
|
604 vbox = gtk_vbox_new(FALSE, 0);
|
pankso@193
|
605 notebook = GTK_NOTEBOOK(gtk_notebook_new());
|
pankso@193
|
606
|
pankso@193
|
607 /* Hide tabs */
|
pankso@193
|
608 if (notoolbar)
|
pankso@193
|
609 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE);
|
pankso@193
|
610
|
pankso@193
|
611 gtk_notebook_set_scrollable(notebook, TRUE);
|
pankso@193
|
612 gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(notebook), TRUE, TRUE, 0);
|
pankso@193
|
613
|
pankso@193
|
614 tazweb_window = create_window();
|
pankso@193
|
615 gtk_container_add(GTK_CONTAINER(tazweb_window), vbox);
|
pankso@193
|
616 gtk_widget_show_all(tazweb_window);
|
pankso@199
|
617
|
pankso@199
|
618 /* Handle cookies */
|
pankso@199
|
619 if (! private) {
|
pankso@199
|
620 session = webkit_get_default_session();
|
pankso@199
|
621 snprintf(COOKIES, sizeof COOKIES, "%s", COOKIES);
|
pankso@199
|
622 cookies_setup();
|
pankso@199
|
623 }
|
pankso@199
|
624
|
pankso@199
|
625 /* Fullscreen for Kiosk mode */
|
pankso@199
|
626 if (kiosk)
|
pankso@199
|
627 gtk_window_fullscreen(GTK_WINDOW(tazweb_window));
|
pankso@199
|
628 }
|
pankso@199
|
629
|
pankso@199
|
630 /* Cmdline Help & usage */
|
pankso@199
|
631 void
|
pankso@199
|
632 help(void)
|
pankso@199
|
633 {
|
pankso@199
|
634 printf("\nTazWeb - Light and fast web browser using Webkit engine\n\n\
|
pankso@199
|
635 Usage: tazweb [--options] [value] url\n\
|
pankso@199
|
636 \n\
|
pankso@199
|
637 Options:\n\
|
pankso@199
|
638 -h --help Print TazWeb command line help\n\
|
pankso@199
|
639 -p --private Disable on-disk cache, cookies, history\n\
|
pankso@199
|
640 -u --useragent [ua] Configure the user agent string\n\
|
pankso@199
|
641 -k --kiosk Fullscreen, no bookmarks and download support\n\
|
pankso@199
|
642 -r --raw Raw webkit window without toolbar and menu\n\
|
pankso@199
|
643 -s --small Small Tazweb window for tiny web applications\n\
|
pankso@199
|
644 --notoolbar Disable the top toolbar\n\
|
pankso@199
|
645 --nomenu Disable TazWeb contextual menu\n\n");
|
pankso@199
|
646
|
pankso@199
|
647 return;
|
pankso@193
|
648 }
|
pankso@193
|
649
|
pankso@193
|
650 int
|
pankso@193
|
651 main(int argc, char *argv[])
|
pankso@193
|
652 {
|
pankso@199
|
653 //textdomain (GETTEXT_PACKAGE);
|
pankso@193
|
654 int focus = 1;
|
pankso@199
|
655 int c;
|
pankso@193
|
656
|
pankso@199
|
657 /* Cmdline parsing with getopt_long to handle --option or -o */
|
pankso@199
|
658 while (1) {
|
pankso@199
|
659 static struct option long_options[] =
|
pankso@199
|
660 {
|
pankso@199
|
661 /* Set flag */
|
pankso@199
|
662 { "notoolbar", no_argument, ¬oolbar, 1 },
|
pankso@199
|
663 { "nomenu", no_argument, &nomenu, 1 },
|
pankso@199
|
664 /* No flag */
|
pankso@199
|
665 { "help", no_argument, 0, 'h' },
|
pankso@199
|
666 { "private", no_argument, 0, 'p' },
|
pankso@199
|
667 { "useragent", required_argument, 0, 'u' },
|
pankso@199
|
668 { "kiosk", no_argument, 0, 'k' },
|
pankso@199
|
669 { "raw", no_argument, 0, 'r' },
|
pankso@199
|
670 { "small", no_argument, 0, 's' },
|
pankso@199
|
671 { 0, 0, 0, 0}
|
pankso@199
|
672 };
|
pankso@199
|
673
|
pankso@199
|
674 int index = 0;
|
pankso@199
|
675 c = getopt_long (argc, argv, "hpu:krs", long_options, &index);
|
pankso@199
|
676
|
pankso@199
|
677 /* Detect the end of the options */
|
pankso@199
|
678 if (c == -1)
|
pankso@199
|
679 break;
|
pankso@199
|
680
|
pankso@199
|
681 switch (c) {
|
pankso@199
|
682 case 0:
|
pankso@199
|
683 /* Options with flag */
|
pankso@199
|
684 break;
|
pankso@199
|
685
|
pankso@199
|
686 case 'h':
|
pankso@199
|
687 help();
|
pankso@199
|
688 return 0;
|
pankso@199
|
689
|
pankso@199
|
690 case 'p':
|
pankso@199
|
691 private++;
|
pankso@199
|
692 break;
|
pankso@199
|
693
|
pankso@199
|
694 case 'u':
|
pankso@199
|
695 useragent = optarg;
|
pankso@199
|
696 break;
|
pankso@199
|
697
|
pankso@199
|
698 case 'k':
|
pankso@199
|
699 kiosk++;
|
pankso@199
|
700 break;
|
pankso@199
|
701
|
pankso@199
|
702 case 'r':
|
pankso@199
|
703 notoolbar++;
|
pankso@199
|
704 nomenu++;
|
pankso@199
|
705 break;
|
pankso@199
|
706
|
pankso@199
|
707 case 's':
|
pankso@199
|
708 width = 640;
|
pankso@199
|
709 height = 480;
|
pankso@199
|
710 break;
|
pankso@199
|
711
|
pankso@199
|
712 default:
|
pankso@199
|
713 help();
|
pankso@199
|
714 return 0;
|
pankso@193
|
715 }
|
pankso@193
|
716 }
|
pankso@193
|
717
|
pankso@193
|
718 argc -= optind;
|
pankso@193
|
719 argv += optind;
|
pankso@193
|
720
|
paul@196
|
721 /* FreeBSD style! */
|
pankso@193
|
722 TAILQ_INIT(&tabs);
|
pankso@193
|
723
|
pankso@193
|
724 /* Initialize GTK */
|
pankso@193
|
725 gtk_init(&argc, &argv);
|
pankso@193
|
726 create_canvas();
|
pankso@193
|
727
|
pankso@193
|
728 /* Open all urls in a new tab */
|
pankso@193
|
729 while (argc) {
|
pankso@193
|
730 create_new_tab(argv[0], FALSE);
|
pankso@193
|
731 focus = 0;
|
pankso@193
|
732 argc--;
|
pankso@193
|
733 argv++;
|
pankso@193
|
734 }
|
pankso@193
|
735 if (focus == 1)
|
pankso@193
|
736 create_new_tab(WEBHOME, 1);
|
pankso@193
|
737
|
pankso@193
|
738 gtk_main();
|
pankso@193
|
739
|
pankso@193
|
740 return (0);
|
pankso@193
|
741 }
|