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