tazweb rev 193

add: tazweb-ng.c New tazweb with tab structure and usable. Still current Tazweb functions/googies to adapt
author Christophe Lincoln <pankso@slitaz.org>
date Thu Mar 16 00:23:06 2017 +0100 (2017-03-16)
parents 9b7c0f2bdaff
children a41749316ea9
files src/tazweb-ng.c
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/tazweb-ng.c	Thu Mar 16 00:23:06 2017 +0100
     1.3 @@ -0,0 +1,597 @@
     1.4 +/*
     1.5 + * TazWeb is a radically simple web browser providing a single window
     1.6 + * with a single toolbar with buttons, an URL entry and search as well
     1.7 + * as a contextual menu, but no menu bar or tabs. Commented line code
     1.8 + * starts with // and comments are between * *
     1.9 + *
    1.10 + * NEXT GENERATION
    1.11 + *  This is TazWeb NG (2.0) with tabs and cookies support :-)
    1.12 + *
    1.13 + * Copyright (C) 2011-2017 SliTaz GNU/Linux - BSD License
    1.14 + * See AUTHORS and LICENSE for detailed information
    1.15 + *
    1.16 + */
    1.17 +
    1.18 +#include <glib.h>
    1.19 +#include <glib/gi18n.h>
    1.20 +#define GETTEXT_PACKAGE "tazweb"
    1.21 +
    1.22 +#include <stdlib.h>
    1.23 +#include <sys/queue.h>
    1.24 +#include <gtk/gtk.h>
    1.25 +#include <webkit/webkit.h>
    1.26 +#include <libsoup/soup.h> // for cookies
    1.27 +
    1.28 +#define HOME		g_get_home_dir()
    1.29 +#define CONFIG		g_strdup_printf("%s/.config/tazweb", HOME)
    1.30 +#define BMTXT		g_strdup_printf("%s/bookmarks.txt", CONFIG)
    1.31 +#define BMURL		g_strdup_printf("%s/bookmarks.html", CONFIG)
    1.32 +#define COOKIES		g_strdup_printf("%s/cookies.txt", CONFIG)
    1.33 +#define WEBHOME		"file:///usr/share/webhome/index.html"
    1.34 +#define SEARCH		"http://duckduckgo.com/?q=%s&t=slitaz"
    1.35 +
    1.36 +static gchar *useragent = "TazWeb (X11; SliTaz GNU/Linux; U; en_US) AppleWebKit/535.22+";
    1.37 +static GtkWidget *tazweb_window;
    1.38 +static GtkNotebook *notebook;
    1.39 +static gboolean notoolbar;
    1.40 +static gboolean kiosk;
    1.41 +
    1.42 +const gchar* uri;
    1.43 +
    1.44 +static SoupSession		*session;
    1.45 +static SoupCookieJar	*cookiejar;
    1.46 +
    1.47 +/* Tab structure */
    1.48 +struct tab {
    1.49 +	TAILQ_ENTRY(tab) entry;
    1.50 +	GtkWidget		*vbox;
    1.51 +	GtkWidget		*label;
    1.52 +	GtkWidget		*urientry;
    1.53 +	GtkWidget		*search_entry;
    1.54 +	GtkWidget		*toolbar;
    1.55 +	GtkWidget		*browser;
    1.56 +	GtkToolItem		*backward;
    1.57 +	GtkToolItem		*forward;
    1.58 +	GtkToolItem		*home;
    1.59 +	GtkToolItem		*bookmarks;
    1.60 +	GtkToolItem		*ttb;
    1.61 +	GtkWidget		*spinner;
    1.62 +	guint			tab_id;
    1.63 +	int				focus_wv;
    1.64 +	WebKitWebView	*webview;
    1.65 +};
    1.66 +TAILQ_HEAD(tab_list, tab);
    1.67 +struct tab_list tabs;
    1.68 +
    1.69 +/* Protocols */
    1.70 +void create_new_tab(char *, int);
    1.71 +void close_tab(struct tab *);
    1.72 +
    1.73 +/* Create an icon */
    1.74 +static GdkPixbuf*
    1.75 +create_pixbuf(const gchar* image)
    1.76 +{
    1.77 +	GdkPixbuf *pixbuf;
    1.78 +	pixbuf = gdk_pixbuf_new_from_file(image, NULL);
    1.79 +	return pixbuf;
    1.80 +}
    1.81 +
    1.82 +/* Can be: http://hg.slitaz.org or hg.slitaz.org */
    1.83 +static void
    1.84 +check_requested_uri()
    1.85 +{
    1.86 +	uri = g_strrstr(uri, "://") ? g_strdup(uri)
    1.87 +		: g_strdup_printf("http://%s", uri);
    1.88 +}
    1.89 +
    1.90 +int destroy_cb()
    1.91 +{
    1.92 +	gtk_main_quit();
    1.93 +	return (1);
    1.94 +}
    1.95 +
    1.96 +int focus()
    1.97 +{
    1.98 +	return (0);
    1.99 +}
   1.100 +
   1.101 +static void
   1.102 +uri_entry_cb(GtkWidget* entry, struct tab *ttb)
   1.103 +{
   1.104 +	uri = gtk_entry_get_text(GTK_ENTRY(entry));
   1.105 +	g_assert(uri);
   1.106 +	check_requested_uri();
   1.107 +	webkit_web_view_load_uri(ttb->webview, uri);
   1.108 +	gtk_widget_grab_focus(GTK_WIDGET(ttb->webview));
   1.109 +}
   1.110 +
   1.111 +static void
   1.112 +notify_load_status_cb(WebKitWebView* webview, GParamSpec* pspec,
   1.113 +	struct tab *ttb)
   1.114 +{
   1.115 +	GString 		*string;
   1.116 +	WebKitWebFrame 	*frame;
   1.117 +	const gchar		*uri, *title;
   1.118 +	gdouble 		progress;
   1.119 +
   1.120 +	switch (webkit_web_view_get_load_status(webview)) {
   1.121 +
   1.122 +	/* Webkit is loading */
   1.123 +	case WEBKIT_LOAD_COMMITTED:
   1.124 +		frame = webkit_web_view_get_main_frame(webview);
   1.125 +		uri = webkit_web_frame_get_uri(frame);
   1.126 +
   1.127 +		string = g_string_new("Loading");
   1.128 +		progress = webkit_web_view_get_progress(webview) * 100;
   1.129 +		if (progress < 100)
   1.130 +			g_string_append_printf(string, " (%f%%)", progress);
   1.131 +
   1.132 +		title = g_string_free(string, FALSE);
   1.133 +		gtk_label_set_text(GTK_LABEL(ttb->label), title);
   1.134 +
   1.135 +		/* Start spinner */
   1.136 +		gtk_widget_show(ttb->spinner);
   1.137 +		gtk_spinner_start(GTK_SPINNER(ttb->spinner));
   1.138 +
   1.139 +		/* Update URL entry */
   1.140 +		if (uri)
   1.141 +			gtk_entry_set_text(GTK_ENTRY(ttb->urientry), uri);
   1.142 +
   1.143 +		/* Focus */
   1.144 +		ttb->focus_wv = 1;
   1.145 +		if (gtk_notebook_get_current_page(notebook) == ttb->tab_id)
   1.146 +			gtk_widget_grab_focus(GTK_WIDGET(ttb->webview));
   1.147 +	break;
   1.148 +
   1.149 +	/* First layout with actual visible content */
   1.150 +	case WEBKIT_LOAD_FIRST_VISUALLY_NON_EMPTY_LAYOUT:
   1.151 +		title = webkit_web_view_get_title(webview);
   1.152 +		gtk_label_set_text(GTK_LABEL(ttb->label), title);
   1.153 +	break;
   1.154 +
   1.155 +	/* URL was loaded */
   1.156 +	case WEBKIT_LOAD_FINISHED:
   1.157 +		title = webkit_web_view_get_title(webview);
   1.158 +		gtk_label_set_text(GTK_LABEL(ttb->label), title);
   1.159 +		gtk_spinner_stop(GTK_SPINNER(ttb->spinner));
   1.160 +		gtk_widget_hide(ttb->spinner);
   1.161 +	break;
   1.162 +
   1.163 +		/* URL fail to load */
   1.164 +	case WEBKIT_LOAD_FAILED:
   1.165 +		gtk_label_set_text(GTK_LABEL(ttb->label), "Failed");
   1.166 +		gtk_spinner_stop(GTK_SPINNER(ttb->spinner));
   1.167 +		gtk_widget_hide(ttb->spinner);
   1.168 +	break;
   1.169 +
   1.170 +	}
   1.171 +
   1.172 +	gtk_widget_set_sensitive(GTK_WIDGET(ttb->backward),
   1.173 +		webkit_web_view_can_go_back(webview));
   1.174 +
   1.175 +	gtk_widget_set_sensitive(GTK_WIDGET(ttb->forward),
   1.176 +		webkit_web_view_can_go_forward(webview));
   1.177 +}
   1.178 +
   1.179 +/* Search entry and icon callback function */
   1.180 +static void
   1.181 +search_entry_cb(GtkWidget* search_entry, struct tab *ttb)
   1.182 +{
   1.183 +	uri = g_strdup_printf(SEARCH, gtk_entry_get_text(GTK_ENTRY(search_entry)));
   1.184 +	g_assert(uri);
   1.185 +	webkit_web_view_load_uri(ttb->webview, uri);
   1.186 +}
   1.187 +
   1.188 +static void
   1.189 +search_icon_cb(GtkWidget *search_entry, GtkEntryIconPosition pos,
   1.190 +	GdkEvent *event, struct tab *ttb)
   1.191 +{
   1.192 +	search_entry_cb(search_entry, ttb);
   1.193 +}
   1.194 +
   1.195 +/* Navigation button functions */
   1.196 +static void
   1.197 +go_back_cb(GtkWidget *widget, struct tab *ttb)
   1.198 +{
   1.199 +	webkit_web_view_go_back(ttb->webview);
   1.200 +}
   1.201 +
   1.202 +static void
   1.203 +go_forward_cb(GtkWidget *widget, struct tab *ttb)
   1.204 +{
   1.205 +	webkit_web_view_go_forward(ttb->webview);
   1.206 +}
   1.207 +
   1.208 +static void
   1.209 +go_home_cb(GtkWidget* w, struct tab *ttb)
   1.210 +{
   1.211 +	uri = WEBHOME;
   1.212 +	g_assert(uri);
   1.213 +	webkit_web_view_load_uri(ttb->webview, uri);
   1.214 +}
   1.215 +
   1.216 +static void
   1.217 +go_bookmarks_cb(GtkWidget* w, struct tab *ttb)
   1.218 +{
   1.219 +	system("/usr/lib/tazweb/helper.sh html_bookmarks");
   1.220 +	uri = g_strdup_printf("file://%s", BMURL);
   1.221 +	g_assert(uri);
   1.222 +	webkit_web_view_load_uri(ttb->webview, uri);
   1.223 +}
   1.224 +
   1.225 +/* Setup session cookies */
   1.226 +void
   1.227 +cookies_setup(void)
   1.228 +{
   1.229 +	if (cookiejar) {
   1.230 +		soup_session_remove_feature(session,
   1.231 +			(SoupSessionFeature*)cookiejar);
   1.232 +		g_object_unref(cookiejar);
   1.233 +		cookiejar = NULL;
   1.234 +	}
   1.235 +
   1.236 +	cookiejar = soup_cookie_jar_text_new(COOKIES, 0);
   1.237 +	soup_session_add_feature(session, (SoupSessionFeature*)cookiejar);
   1.238 +}
   1.239 +
   1.240 +static void
   1.241 +cookies_view_cb(GtkWidget* widget, WebKitWebView* webview)
   1.242 +{
   1.243 +	system("/usr/lib/tazweb/helper.sh html_cookies");
   1.244 +	uri = g_strdup_printf("file://%s/cookies.html", CONFIG);
   1.245 +	g_assert(uri);
   1.246 +	webkit_web_view_load_uri(webview, uri);
   1.247 +}
   1.248 +
   1.249 +static void
   1.250 +cookies_clean_cb(GtkWidget* widget, WebKitWebView* webview)
   1.251 +{
   1.252 +	system("/usr/lib/tazweb/helper.sh clean_cookies");
   1.253 +}
   1.254 +
   1.255 +/* Add items to WebKit contextual menu */
   1.256 +static void
   1.257 +populate_menu_cb(WebKitWebView *ttb, GtkMenu *menu, gpointer data)
   1.258 +{
   1.259 +	GtkWidget* item;
   1.260 +
   1.261 +	/* Separator */
   1.262 +	item = gtk_separator_menu_item_new();
   1.263 +	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   1.264 +
   1.265 +	//if (! kiosk) {
   1.266 +		///* Add a bookmark */
   1.267 +		//item = gtk_image_menu_item_new_with_label(_("Add a bookmark"));
   1.268 +		//gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
   1.269 +		//gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
   1.270 +		//gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   1.271 +		//g_signal_connect(item, "activate", G_CALLBACK(add_bookmark_cb), webview);
   1.272 +	//}
   1.273 +
   1.274 +	///* Printing */
   1.275 +	//item = gtk_image_menu_item_new_with_label(_("Print this page"));
   1.276 +	//gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
   1.277 +	//gtk_image_new_from_stock(GTK_STOCK_PRINT, GTK_ICON_SIZE_MENU));
   1.278 +	//gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   1.279 +	//g_signal_connect(item, "activate", G_CALLBACK(print_page_cb), webview);
   1.280 +
   1.281 +	///* View source mode */
   1.282 +	//item = gtk_image_menu_item_new_with_label(_("View source mode"));
   1.283 +	//gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
   1.284 +	//gtk_image_new_from_stock(GTK_STOCK_PROPERTIES, GTK_ICON_SIZE_MENU));
   1.285 +	//gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   1.286 +	//g_signal_connect(item, "activate", G_CALLBACK(view_source_cb), webview);
   1.287 +
   1.288 +	///* Separator */
   1.289 +	//item = gtk_separator_menu_item_new();
   1.290 +	//gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   1.291 +
   1.292 +	///* TazWeb documentation */
   1.293 +	//item = gtk_image_menu_item_new_with_label(_("TazWeb manual"));
   1.294 +	//gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
   1.295 +	//gtk_image_new_from_stock(GTK_STOCK_HELP, GTK_ICON_SIZE_MENU));
   1.296 +	//gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   1.297 +	//g_signal_connect(item, "activate", G_CALLBACK(tazweb_doc_cb), webview);
   1.298 +
   1.299 +	/* Quit TazWeb */
   1.300 +	item = gtk_image_menu_item_new_with_label(_("Quit TazWeb"));
   1.301 +	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
   1.302 +	gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU));
   1.303 +	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   1.304 +	g_signal_connect(item, "activate", G_CALLBACK(destroy_cb), NULL);
   1.305 +
   1.306 +	gtk_widget_show_all(GTK_WIDGET(menu));
   1.307 +}
   1.308 +
   1.309 +/* The browser */
   1.310 +GtkWidget *
   1.311 +create_browser(struct tab *ttb)
   1.312 +{
   1.313 +	GtkWidget *window;
   1.314 +	WebKitWebSettings *settings;
   1.315 +	
   1.316 +	window = gtk_scrolled_window_new(NULL, NULL);
   1.317 +	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(window),
   1.318 +		GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
   1.319 +
   1.320 +	ttb->webview = WEBKIT_WEB_VIEW(webkit_web_view_new());
   1.321 +	gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(ttb->webview));
   1.322 +	
   1.323 +	/* User agent */
   1.324 +	settings = webkit_web_view_get_settings (ttb->webview);
   1.325 +	g_object_set(G_OBJECT(settings), "user-agent", useragent, NULL);
   1.326 +
   1.327 +	g_signal_connect(ttb->webview, "notify::load-status",
   1.328 +		G_CALLBACK(notify_load_status_cb), ttb);
   1.329 +
   1.330 +	/* Connect WebKit contextual menu items */
   1.331 +	g_object_connect(G_OBJECT(ttb->webview), "signal::populate-popup",
   1.332 +		G_CALLBACK(populate_menu_cb), ttb, NULL);
   1.333 +
   1.334 +	return (window);
   1.335 +}
   1.336 +
   1.337 +/* Create a new tab callback */
   1.338 +static void
   1.339 +create_new_tab_cb()
   1.340 +{
   1.341 +	create_new_tab(WEBHOME, +1);
   1.342 +}
   1.343 +
   1.344 +/* Toolbar with URL and search entry */
   1.345 +GtkWidget *
   1.346 +create_toolbar(struct tab *ttb)
   1.347 +{
   1.348 +	GtkWidget		*toolbar = gtk_toolbar_new();
   1.349 +	GtkToolItem		*item;
   1.350 +
   1.351 +	gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar),
   1.352 +		GTK_ORIENTATION_HORIZONTAL);
   1.353 +	gtk_toolbar_set_style(GTK_TOOLBAR(toolbar),
   1.354 +		GTK_TOOLBAR_BOTH_HORIZ);
   1.355 +	
   1.356 +	/* New tab button */
   1.357 +	item = gtk_tool_button_new_from_stock(GTK_STOCK_ADD);
   1.358 +	gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
   1.359 +	g_signal_connect(G_OBJECT(item), "clicked",
   1.360 +		G_CALLBACK(create_new_tab_cb), FALSE);
   1.361 +
   1.362 +	/* The backward button */
   1.363 +	ttb->backward = gtk_tool_button_new_from_stock(GTK_STOCK_GO_BACK);
   1.364 +	gtk_widget_set_sensitive(GTK_WIDGET(ttb->backward), FALSE);
   1.365 +	gtk_toolbar_insert(GTK_TOOLBAR(toolbar), ttb->backward, -1);
   1.366 +	g_signal_connect(G_OBJECT(ttb->backward), "clicked",
   1.367 +		G_CALLBACK(go_back_cb), ttb);
   1.368 +
   1.369 +	/* The forward button */
   1.370 +	ttb->forward = gtk_tool_button_new_from_stock(GTK_STOCK_GO_FORWARD);
   1.371 +	gtk_widget_set_sensitive(GTK_WIDGET(ttb->forward), FALSE);
   1.372 +	gtk_toolbar_insert(GTK_TOOLBAR(toolbar), ttb->forward, -1);
   1.373 +	g_signal_connect(G_OBJECT(ttb->forward), "clicked",
   1.374 +		G_CALLBACK(go_forward_cb), ttb);
   1.375 +
   1.376 +	/* URL entry */
   1.377 +	item = gtk_tool_item_new();
   1.378 +	gtk_tool_item_set_expand(item, TRUE);
   1.379 +	//gtk_widget_set_size_request(urientry, 0, 20);
   1.380 +	ttb->urientry = gtk_entry_new();
   1.381 +	gtk_container_add(GTK_CONTAINER(item), ttb->urientry);
   1.382 +	gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
   1.383 +	g_signal_connect(G_OBJECT(ttb->urientry), "activate",
   1.384 +		G_CALLBACK(uri_entry_cb), ttb);
   1.385 +
   1.386 +	/* Separator --> 4-6px */
   1.387 +	item = gtk_separator_tool_item_new();
   1.388 +	gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
   1.389 +
   1.390 +	/* Search entry */
   1.391 +	item = gtk_tool_item_new();
   1.392 +	gtk_tool_item_set_expand(item, FALSE);
   1.393 +	gtk_widget_set_size_request(GTK_WIDGET(item), 200, 0);
   1.394 +	ttb->search_entry = gtk_entry_new();
   1.395 +
   1.396 +	gtk_entry_set_icon_from_stock(GTK_ENTRY(ttb->search_entry),
   1.397 +		GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_FIND);
   1.398 +	gtk_container_add(GTK_CONTAINER(item), ttb->search_entry);
   1.399 +
   1.400 +	gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
   1.401 +	g_signal_connect(GTK_ENTRY(ttb->search_entry), "icon-press",
   1.402 +		G_CALLBACK(search_icon_cb), ttb);
   1.403 +	g_signal_connect(G_OBJECT(ttb->search_entry), "activate",
   1.404 +		G_CALLBACK(search_entry_cb), ttb);
   1.405 +
   1.406 +	/* Home button */
   1.407 +	ttb->home = gtk_tool_button_new_from_stock(GTK_STOCK_HOME);
   1.408 +	gtk_toolbar_insert(GTK_TOOLBAR(toolbar), ttb->home, -1);
   1.409 +	g_signal_connect(G_OBJECT(ttb->home), "clicked",
   1.410 +		G_CALLBACK(go_home_cb), ttb);
   1.411 +
   1.412 +	/* Bookmarks button */
   1.413 +	ttb->bookmarks = gtk_tool_button_new_from_stock(GTK_STOCK_PROPERTIES);
   1.414 +	//gtk_widget_set_tooltip_text(GTK_WIDGET(item), "Bookmarks");
   1.415 +	gtk_toolbar_insert(GTK_TOOLBAR(toolbar), ttb->bookmarks, -1);
   1.416 +	g_signal_connect(G_OBJECT(ttb->bookmarks), "clicked",
   1.417 +		G_CALLBACK(go_bookmarks_cb), ttb);
   1.418 +
   1.419 +	return (toolbar);
   1.420 +}
   1.421 +
   1.422 +void
   1.423 +close_tab(struct tab *ttb)
   1.424 +{
   1.425 +	if (ttb == NULL)
   1.426 +		return;
   1.427 +
   1.428 +	TAILQ_REMOVE(&tabs, ttb, entry);
   1.429 +	if (TAILQ_EMPTY(&tabs))
   1.430 +		create_new_tab(NULL, 1);
   1.431 +
   1.432 +	webkit_web_view_stop_loading(ttb->webview);
   1.433 +	gtk_widget_destroy(ttb->vbox);
   1.434 +	g_free(ttb);
   1.435 +}
   1.436 +
   1.437 +gboolean
   1.438 +close_tab_cb(GtkWidget *event_box, GdkEventButton *event, struct tab *ttb)
   1.439 +{
   1.440 +	close_tab(ttb);
   1.441 +	return (FALSE);
   1.442 +}
   1.443 +
   1.444 +void
   1.445 +create_new_tab(char *title, int focus)
   1.446 +{
   1.447 +	struct tab	*ttb;
   1.448 +	int	load = 1;
   1.449 +	char *newuri = NULL;
   1.450 +	GtkWidget *image, *hbox, *event_box;
   1.451 +
   1.452 +	ttb = g_malloc0(sizeof *ttb);
   1.453 +	TAILQ_INSERT_TAIL(&tabs, ttb, entry);
   1.454 +
   1.455 +	if (title == NULL) {
   1.456 +		title = "Empty";
   1.457 +		load = 0;
   1.458 +	}
   1.459 +
   1.460 +	ttb->vbox = gtk_vbox_new(FALSE, 0);
   1.461 +
   1.462 +	/* Tab title, spinner & close button */
   1.463 +	hbox = gtk_hbox_new(FALSE, 0);
   1.464 +	ttb->spinner = gtk_spinner_new();
   1.465 +	ttb->label = gtk_label_new(title);
   1.466 +	image = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
   1.467 +
   1.468 +	event_box = gtk_event_box_new();
   1.469 +	gtk_container_add(GTK_CONTAINER(event_box), image);
   1.470 +
   1.471 +	gtk_widget_set_size_request(ttb->label, 160, -1);
   1.472 +	gtk_box_pack_start(GTK_BOX(hbox), ttb->spinner, FALSE, FALSE, 0);
   1.473 +	gtk_box_pack_start(GTK_BOX(hbox), ttb->label, FALSE, FALSE, 0);
   1.474 +	gtk_box_pack_start(GTK_BOX(hbox), event_box, FALSE, FALSE, 0);
   1.475 +
   1.476 +	/* Toolbar */
   1.477 +	ttb->toolbar = create_toolbar(ttb);
   1.478 +	gtk_box_pack_start(GTK_BOX(ttb->vbox), ttb->toolbar,
   1.479 +		FALSE, FALSE, 0);
   1.480 +
   1.481 +	/* Browser */
   1.482 +	ttb->browser = create_browser(ttb);
   1.483 +	gtk_box_pack_start(GTK_BOX(ttb->vbox), ttb->browser, TRUE, TRUE, 0);
   1.484 +
   1.485 +	/* Show all widgets */
   1.486 +	gtk_widget_show_all(hbox);
   1.487 +	gtk_widget_show_all(ttb->vbox);
   1.488 +	ttb->tab_id = gtk_notebook_append_page(notebook, ttb->vbox, hbox);
   1.489 +
   1.490 +	/* Reorderable notebook tabs */
   1.491 +	gtk_notebook_set_tab_reorderable(notebook, ttb->vbox, TRUE);
   1.492 +
   1.493 +	/* Close tab event */
   1.494 +	g_signal_connect(G_OBJECT(event_box), "button_press_event",
   1.495 +		G_CALLBACK(close_tab_cb), ttb);
   1.496 +
   1.497 +	if (notoolbar)
   1.498 +		gtk_widget_hide(ttb->toolbar);
   1.499 +
   1.500 +	if (focus) {
   1.501 +		gtk_notebook_set_current_page(notebook, ttb->tab_id);
   1.502 +	}
   1.503 +
   1.504 +	if (load)
   1.505 +		webkit_web_view_load_uri(ttb->webview, title);
   1.506 +	else
   1.507 +		gtk_widget_grab_focus(GTK_WIDGET(ttb->urientry));
   1.508 +
   1.509 +	if (newuri)
   1.510 +		free(newuri);
   1.511 +}
   1.512 +
   1.513 +/* Main window */
   1.514 +GtkWidget *
   1.515 +create_window(void)
   1.516 +{
   1.517 +	GtkWidget *window;
   1.518 +
   1.519 +	/* Default TazWeb window */
   1.520 +	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   1.521 +	gtk_window_set_default_size(GTK_WINDOW(window), 800, 600);
   1.522 +	gtk_window_set_icon_name(GTK_WINDOW(window), "tazweb");
   1.523 +	gtk_widget_set_name(window, "TazWeb");
   1.524 +	gtk_window_set_wmclass(GTK_WINDOW(window), "tazweb", "TazWeb");
   1.525 +	g_signal_connect(window, "destroy", G_CALLBACK(destroy_cb), NULL);
   1.526 +
   1.527 +	return (window);
   1.528 +}
   1.529 +
   1.530 +void
   1.531 +create_canvas(void)
   1.532 +{
   1.533 +	GtkWidget *vbox;
   1.534 +
   1.535 +	vbox = gtk_vbox_new(FALSE, 0);
   1.536 +	notebook = GTK_NOTEBOOK(gtk_notebook_new());
   1.537 +
   1.538 +	/* Hide tabs */
   1.539 +	if (notoolbar)
   1.540 +		gtk_notebook_set_show_tabs(GTK_NOTEBOOK(notebook), FALSE);
   1.541 +
   1.542 +	gtk_notebook_set_scrollable(notebook, TRUE);
   1.543 +	gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(notebook), TRUE, TRUE, 0);
   1.544 +
   1.545 +	tazweb_window = create_window();
   1.546 +	gtk_container_add(GTK_CONTAINER(tazweb_window), vbox);
   1.547 +	gtk_widget_show_all(tazweb_window);
   1.548 +}
   1.549 +
   1.550 +int
   1.551 +main(int argc, char *argv[])
   1.552 +{
   1.553 +	int	focus = 1;
   1.554 +
   1.555 +	while (argc > 1) {
   1.556 +		if (!strcmp(argv[1],"--notoolbar")) {
   1.557 +			notoolbar++;
   1.558 +		}
   1.559 +		else if (!strcmp(argv[1],"--kiosk")) {
   1.560 +			kiosk++;
   1.561 +		}
   1.562 +		else if (!strcmp(argv[1],"--useragent") && argc > 2) {
   1.563 +			argc--;
   1.564 +			argv++;
   1.565 +			useragent = argv[1];
   1.566 +		}
   1.567 +		else if (!strcmp(argv[1],"--help")) {
   1.568 +			printf ("Usage: tazweb [--notoolbar|--kiosk|--useragent] [ua]\n");
   1.569 +			printf ("Bookmarks: %s\n", BMTXT);
   1.570 +			return 0;
   1.571 +		}
   1.572 +		else break;
   1.573 +		argc--;
   1.574 +		argv++;
   1.575 +	}
   1.576 +
   1.577 +	argc -= optind;
   1.578 +	argv += optind;
   1.579 +
   1.580 +	/* FreeBSD sytle! */
   1.581 +	TAILQ_INIT(&tabs);
   1.582 +
   1.583 +	/* Initialize GTK */
   1.584 +	gtk_init(&argc, &argv);
   1.585 +	create_canvas();
   1.586 +
   1.587 +	/* Open all urls in a new tab */
   1.588 +	while (argc) {
   1.589 +		create_new_tab(argv[0], FALSE);
   1.590 +		focus = 0;
   1.591 +		argc--;
   1.592 +		argv++;
   1.593 +	}
   1.594 +	if (focus == 1)
   1.595 +		create_new_tab(WEBHOME, 1);
   1.596 +
   1.597 +	gtk_main();
   1.598 +
   1.599 +	return (0);
   1.600 +}