tazweb rev 177

Rename source files, improve Makefile
author Christophe Lincoln <pankso@slitaz.org>
date Sun Mar 12 17:56:20 2017 +0100 (2017-03-12)
parents f6f730c0635d
children 02eed5624373
files .hgignore Makefile src/main.c src/main.cpp src/tazweb-qt.cpp src/tazweb-qt.pro src/tazweb.c src/tazweb.pro tazweb-helper
line diff
     1.1 --- a/.hgignore	Fri Mar 10 11:53:18 2017 +0100
     1.2 +++ b/.hgignore	Sun Mar 12 17:56:20 2017 +0100
     1.3 @@ -1,2 +1,4 @@
     1.4  tazweb$
     1.5 +tazweb-ng$
     1.6 +tazweb-qt$
     1.7  po/mo
     2.1 --- a/Makefile	Fri Mar 10 11:53:18 2017 +0100
     2.2 +++ b/Makefile	Sun Mar 12 17:56:20 2017 +0100
     2.3 @@ -11,10 +11,16 @@
     2.4  CC?=gcc
     2.5  
     2.6  all:
     2.7 -	$(CC) src/main.c -o $(PACKAGE) $(CFLAGS) \
     2.8 +	$(CC) src/tazweb.c -o $(PACKAGE) $(CFLAGS) \
     2.9  		`pkg-config --cflags --libs gtk+-2.0 webkit-1.0`
    2.10  	@du -sh $(PACKAGE)
    2.11  
    2.12 +# Next generation
    2.13 +ng:
    2.14 +	$(CC) src/tazweb-ng.c -o $(PACKAGE)-ng $(CFLAGS) \
    2.15 +		`pkg-config --cflags --libs gtk+-2.0 webkit-1.0`
    2.16 +	@du -sh $(PACKAGE)-ng
    2.17 +	
    2.18  qt:
    2.19  	cd src && qmake && make
    2.20  	@du -sh src/$(PACKAGE)-qt
    2.21 @@ -65,4 +71,4 @@
    2.22  	rm -f src/Makefile src/*.o src/tazweb-qt
    2.23  
    2.24  help:
    2.25 -	@echo "make [ pot | msgmerge | msgfmt | install | clean ]"
    2.26 +	@echo "make [ ng | qt | pot | msgmerge | msgfmt | install | clean ]"
     3.1 --- a/src/main.c	Fri Mar 10 11:53:18 2017 +0100
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,549 +0,0 @@
     3.4 -/*
     3.5 - * TazWeb is a radically simple web browser providing a single window
     3.6 - * with a single toolbar with buttons, an URL entry and search as well
     3.7 - * as a contextual menu, but no menu bar or tabs. Commented line code
     3.8 - * starts with // and comments are between * *
     3.9 - *
    3.10 - * Copyright (C) 2011-2014 SliTaz GNU/Linux - BSD License
    3.11 - * See AUTHORS and LICENSE for detailed information
    3.12 - * 
    3.13 - */
    3.14 -
    3.15 -#include <glib.h>
    3.16 -#include <glib/gi18n.h>
    3.17 -#define GETTEXT_PACKAGE "tazweb"
    3.18 -
    3.19 -#include <gtk/gtk.h>
    3.20 -#include <webkit/webkit.h>
    3.21 -
    3.22 -#define HOME       g_get_home_dir()
    3.23 -#define CONFIG     g_strdup_printf("%s/.config/tazweb", HOME)
    3.24 -#define BMTXT      g_strdup_printf("%s/bookmarks.txt", CONFIG)
    3.25 -#define BMURL      g_strdup_printf("%s/bookmarks.html", CONFIG)
    3.26 -#define WEBHOME    "file:///usr/share/webhome/index.html"
    3.27 -#define SEARCH     "http://duckduckgo.com/?q=%s&t=slitaz"
    3.28 -
    3.29 -/* Needs AppleWebKit/531.2+ to handle all sites ? */
    3.30 -static gchar *useragent = "TazWeb (X11; SliTaz GNU/Linux; U; en_US)";
    3.31 -static GtkWidget* create_window(WebKitWebView** newwebview);
    3.32 -static GtkWidget *mainwindow, *vbox, *browser, *toolbar;
    3.33 -static WebKitWebView *webview;
    3.34 -static WebKitWebFrame *frame;
    3.35 -static gint count = 0;
    3.36 -static gboolean notoolbar;
    3.37 -static gboolean noquit;
    3.38 -static gboolean kiosk;
    3.39 -const gchar* uri;
    3.40 -
    3.41 -/* Create an icon */
    3.42 -static GdkPixbuf*
    3.43 -create_pixbuf(const gchar* image)
    3.44 -{
    3.45 -	GdkPixbuf *pixbuf;
    3.46 -	pixbuf = gdk_pixbuf_new_from_file(image, NULL);
    3.47 -	return pixbuf;
    3.48 -}
    3.49 -
    3.50 -/* Can be: http://hg.slitaz.org or hg.slitaz.org */
    3.51 -static void
    3.52 -check_requested_uri()
    3.53 -{
    3.54 -	uri = g_strrstr(uri, "://") ? g_strdup(uri)
    3.55 -		: g_strdup_printf("http://%s", uri);
    3.56 -}
    3.57 -
    3.58 -/* Update title */
    3.59 -static void
    3.60 -update_title(GtkWindow* window, WebKitWebView* webview)
    3.61 -{
    3.62 -	GString *string;
    3.63 -	gdouble progress;
    3.64 -	gchar *title;
    3.65 -	
    3.66 -	string = g_string_new(webkit_web_view_get_title(webview));
    3.67 -	progress = webkit_web_view_get_progress(webview) * 100;
    3.68 -	if (progress < 100)
    3.69 -		g_string_append_printf(string, " [ %f%% ] ", progress);
    3.70 -	
    3.71 -	title = g_string_free(string, FALSE);
    3.72 -	gtk_window_set_title(window, title);
    3.73 -	g_free(title);
    3.74 -}
    3.75 -
    3.76 -/* Get the page title */
    3.77 -static void
    3.78 -notify_title_cb(WebKitWebView* webview, GParamSpec* pspec, GtkWidget* window)
    3.79 -{
    3.80 -	update_title(GTK_WINDOW(window), webview);
    3.81 -}
    3.82 -
    3.83 -/* Request progress in window title */
    3.84 -static void
    3.85 -notify_progress_cb(WebKitWebView* webview, GParamSpec* pspec, GtkWidget* window)
    3.86 -{
    3.87 -	update_title(GTK_WINDOW(window), webview);
    3.88 -}
    3.89 -
    3.90 -/* Notify url entry */
    3.91 -static void
    3.92 -notify_load_status_cb(WebKitWebView* webview, GParamSpec* pspec, GtkWidget* urientry)
    3.93 -{
    3.94 -	if (webkit_web_view_get_load_status(webview) == WEBKIT_LOAD_COMMITTED) {
    3.95 -		frame = webkit_web_view_get_main_frame(webview);
    3.96 -		uri = webkit_web_frame_get_uri(frame);
    3.97 -		if (uri)
    3.98 -			gtk_entry_set_text(GTK_ENTRY(urientry), uri);
    3.99 -	}
   3.100 -}
   3.101 -
   3.102 -/* Destroy the window */
   3.103 -static void
   3.104 -destroy_cb(GtkWidget* widget, GtkWindow* window)
   3.105 -{
   3.106 -	if (g_atomic_int_dec_and_test(&count))
   3.107 -		gtk_main_quit();
   3.108 -}
   3.109 -
   3.110 -/* Show page source */
   3.111 -static void
   3.112 -view_source_cb(GtkWidget* widget, WebKitWebView* webview)
   3.113 -{
   3.114 -	gboolean source;
   3.115 -	
   3.116 -	frame = webkit_web_view_get_main_frame(webview);
   3.117 -	uri = webkit_web_frame_get_uri(frame);
   3.118 -	source = webkit_web_view_get_view_source_mode(webview);
   3.119 -	
   3.120 -	webkit_web_view_set_view_source_mode(webview, !source);
   3.121 -	webkit_web_view_reload(webview);
   3.122 -}
   3.123 -
   3.124 -/* URL entry callback function */
   3.125 -static void
   3.126 -uri_entry_cb(GtkWidget* urientry, WebKitWebView* webview)
   3.127 -{
   3.128 -	uri = gtk_entry_get_text(GTK_ENTRY(urientry));
   3.129 -	g_assert(uri);
   3.130 -	check_requested_uri();
   3.131 -	webkit_web_view_load_uri(webview, uri);
   3.132 -}
   3.133 -
   3.134 -/* Search entry and icon callback function */
   3.135 -static void
   3.136 -search_web(GtkWidget* search, WebKitWebView* webview)
   3.137 -{
   3.138 -	uri = g_strdup_printf(SEARCH, gtk_entry_get_text(GTK_ENTRY(search)));
   3.139 -	g_assert(uri);
   3.140 -	webkit_web_view_load_uri(webview, uri);
   3.141 -}
   3.142 -
   3.143 -static void
   3.144 -search_entry_cb(GtkWidget* search, WebKitWebView* webview)
   3.145 -{
   3.146 -	search_web(search, webview);
   3.147 -}
   3.148 -
   3.149 -static void
   3.150 -search_icon_press_cb(GtkWidget *search, GtkEntryIconPosition pos,
   3.151 -		GdkEvent *event, WebKitWebView* webview)
   3.152 -{
   3.153 -    search_web(search, webview);
   3.154 -}
   3.155 -
   3.156 -/* Navigation button function: */
   3.157 -static void
   3.158 -go_bookmarks_cb(GtkWidget* widget, WebKitWebView* webview)
   3.159 -{
   3.160 -	system("tazweb-helper html_bookmarks");
   3.161 -	uri = g_strdup_printf("file://%s", BMURL);
   3.162 -	g_assert(uri);
   3.163 -	webkit_web_view_load_uri(webview, uri);
   3.164 -}
   3.165 -
   3.166 -static void
   3.167 -go_home_cb(GtkWidget* widget, WebKitWebView* webview)
   3.168 -{
   3.169 -	uri = WEBHOME;
   3.170 -	g_assert(uri);
   3.171 -	webkit_web_view_load_uri(webview, uri);
   3.172 -}
   3.173 -
   3.174 -static void
   3.175 -go_back_cb(GtkWidget* widget, WebKitWebView* webview)
   3.176 -{
   3.177 -    webkit_web_view_go_back(webview);
   3.178 -}
   3.179 -
   3.180 -static void
   3.181 -go_forward_cb(GtkWidget* widget, WebKitWebView* webview)
   3.182 -{
   3.183 -    webkit_web_view_go_forward(webview);
   3.184 -}
   3.185 -
   3.186 -/* Fullscreen and unfullscreen callback function */
   3.187 -//static void
   3.188 -//fullscreen_cb(GtkWindow* window, gpointer data)
   3.189 -//{
   3.190 -	//GdkWindowState state;
   3.191 -	//state = gdk_window_get_state(gtk_widget_get_window(GTK_WIDGET(mainwindow)));
   3.192 -
   3.193 -	//if(state & GDK_WINDOW_STATE_FULLSCREEN)
   3.194 -		//gtk_window_unfullscreen(GTK_WINDOW(mainwindow));
   3.195 -	//else
   3.196 -		//gtk_window_fullscreen(GTK_WINDOW(mainwindow));
   3.197 -//}
   3.198 -
   3.199 -/* TazWeb doc callback function */
   3.200 -static void
   3.201 -tazweb_doc_cb(GtkWidget* widget, WebKitWebView *webview)
   3.202 -{
   3.203 -	uri = ("file:///usr/share/doc/tazweb/tazweb.html");
   3.204 -	g_assert(uri);
   3.205 -	webkit_web_view_load_uri(webview, uri);
   3.206 -}
   3.207 -
   3.208 -/* Download function */
   3.209 -static gboolean
   3.210 -download_requested_cb(WebKitWebView *webview, WebKitDownload *download,
   3.211 -		gpointer user_data)
   3.212 -{
   3.213 -	const gchar* buffer;
   3.214 -	uri = webkit_download_get_uri(download);
   3.215 -	asprintf(&buffer, "xterm -T 'Download' -geom 72x10+0-24 -e \
   3.216 -				'mkdir -p $HOME/Downloads && cd $HOME/Downloads && \
   3.217 -				wget -c %s; sleep 2' &", uri);
   3.218 -	system(buffer);
   3.219 -}
   3.220 -
   3.221 -/* Zoom out and in callback function */
   3.222 -static void
   3.223 -zoom_out_cb(GtkWidget *widget, WebKitWebView* webview)
   3.224 -{
   3.225 -	webkit_web_view_zoom_out(webview);
   3.226 -}
   3.227 -
   3.228 -static void
   3.229 -zoom_in_cb(GtkWidget *widget, WebKitWebView* webview)
   3.230 -{
   3.231 -	webkit_web_view_zoom_in(webview);
   3.232 -}
   3.233 -
   3.234 -/* Printing callback function */
   3.235 -static void
   3.236 -print_page_cb (GtkWidget *widget, gpointer data)
   3.237 -{
   3.238 -    webkit_web_frame_print (webkit_web_view_get_main_frame (
   3.239 -        WEBKIT_WEB_VIEW (webview)));
   3.240 -}
   3.241 -
   3.242 -/* New webview callbacks */
   3.243 -static WebKitWebView*
   3.244 -create_web_view_cb(WebKitWebView* webview, WebKitWebFrame* web_frame,
   3.245 -		GtkWidget* window)
   3.246 -{
   3.247 -	WebKitWebView *newview;
   3.248 -	create_window(&newview);
   3.249 -	return newview;
   3.250 -}
   3.251 -
   3.252 -static gboolean
   3.253 -webview_ready_cb(WebKitWebView* webview, GtkWidget* window)
   3.254 -{
   3.255 -	gtk_widget_grab_focus(GTK_WIDGET(webview));
   3.256 -	gtk_widget_show_all(window);
   3.257 -	return FALSE;
   3.258 -}
   3.259 -
   3.260 -static gboolean
   3.261 -close_webview_cb(WebKitWebView* webview, GtkWidget* window)
   3.262 -{
   3.263 -	gtk_widget_destroy(window);
   3.264 -	return TRUE;
   3.265 -}
   3.266 -
   3.267 -/* Add a bookmark */
   3.268 -void add_bookmark_cb(GtkWidget *widget, gpointer data)
   3.269 -{
   3.270 -	const gchar* title;
   3.271 -	const gchar* buffer;
   3.272 -	
   3.273 -	title = webkit_web_view_get_title(WEBKIT_WEB_VIEW (webview));
   3.274 -	uri = webkit_web_view_get_uri(WEBKIT_WEB_VIEW (webview));
   3.275 -	
   3.276 -	asprintf(&buffer, "echo '%s|%s' >> %s", title, uri, BMTXT);
   3.277 -	system(buffer);
   3.278 -}
   3.279 -
   3.280 -/* Add items to WebKit contextual menu */
   3.281 -static void
   3.282 -populate_menu_cb(WebKitWebView *webview, GtkMenu *menu, gpointer data)
   3.283 -{
   3.284 -	GtkWidget* item;
   3.285 -	
   3.286 -	/* Separator */
   3.287 -	item = gtk_separator_menu_item_new();
   3.288 -	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   3.289 -
   3.290 -	/* Zoom in */
   3.291 -	item = gtk_image_menu_item_new_with_label(_("Zoom in"));
   3.292 -	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
   3.293 -	gtk_image_new_from_stock(GTK_STOCK_ZOOM_IN, GTK_ICON_SIZE_MENU));
   3.294 -	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   3.295 -	g_signal_connect(item, "activate", G_CALLBACK(zoom_in_cb), webview);
   3.296 -	
   3.297 -	/* Zoom out */
   3.298 -	item = gtk_image_menu_item_new_with_label(_("Zoom out"));
   3.299 -	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
   3.300 -	gtk_image_new_from_stock(GTK_STOCK_ZOOM_OUT, GTK_ICON_SIZE_MENU));
   3.301 -	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   3.302 -	g_signal_connect(item, "activate", G_CALLBACK(zoom_out_cb), webview);
   3.303 -
   3.304 -	/* Separator */
   3.305 -	item = gtk_separator_menu_item_new();
   3.306 -	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   3.307 -
   3.308 -	if (! kiosk) {
   3.309 -		/* Add a bookmark */
   3.310 -		item = gtk_image_menu_item_new_with_label(_("Add a bookmark"));
   3.311 -		gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
   3.312 -		gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
   3.313 -		gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   3.314 -		g_signal_connect(item, "activate", G_CALLBACK(add_bookmark_cb), webview);
   3.315 -	}
   3.316 -
   3.317 -	/* Printing */
   3.318 -	item = gtk_image_menu_item_new_with_label(_("Print this page"));
   3.319 -	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
   3.320 -	gtk_image_new_from_stock(GTK_STOCK_PRINT, GTK_ICON_SIZE_MENU));
   3.321 -	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   3.322 -	g_signal_connect(item, "activate", G_CALLBACK(print_page_cb), webview);
   3.323 -
   3.324 -	/* View source mode */
   3.325 -	item = gtk_image_menu_item_new_with_label(_("View source mode"));
   3.326 -	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
   3.327 -	gtk_image_new_from_stock(GTK_STOCK_PROPERTIES, GTK_ICON_SIZE_MENU));
   3.328 -	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   3.329 -	g_signal_connect(item, "activate", G_CALLBACK(view_source_cb), webview);
   3.330 -
   3.331 -	/* Separator */
   3.332 -	item = gtk_separator_menu_item_new();
   3.333 -	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   3.334 -
   3.335 -	/* TazWeb documentation */
   3.336 -	item = gtk_image_menu_item_new_with_label(_("TazWeb manual"));
   3.337 -	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
   3.338 -	gtk_image_new_from_stock(GTK_STOCK_HELP, GTK_ICON_SIZE_MENU));
   3.339 -	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   3.340 -	g_signal_connect(item, "activate", G_CALLBACK(tazweb_doc_cb), webview);
   3.341 -	
   3.342 -	/* Quit TazWeb */
   3.343 -	item = gtk_image_menu_item_new_with_label(_("Quit TazWeb"));
   3.344 -	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
   3.345 -	gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU));
   3.346 -	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   3.347 -	g_signal_connect(item, "activate", G_CALLBACK(destroy_cb), webview);
   3.348 -	
   3.349 -	gtk_widget_show_all(GTK_WIDGET(menu));
   3.350 -}
   3.351 -
   3.352 -/* Scrolled window for the webview */
   3.353 -static GtkWidget*
   3.354 -create_browser(GtkWidget* window, GtkWidget* urientry, GtkWidget* search,
   3.355 -		WebKitWebView* webview)
   3.356 -{
   3.357 -	WebKitWebSettings *settings;
   3.358 -	
   3.359 -	browser = gtk_scrolled_window_new(NULL, NULL);
   3.360 -	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(browser),
   3.361 -			GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
   3.362 -
   3.363 -	gtk_container_add(GTK_CONTAINER(browser), GTK_WIDGET(webview));
   3.364 -
   3.365 -	/* User agent */
   3.366 -	settings = webkit_web_view_get_settings (webview);
   3.367 -	g_object_set(G_OBJECT(settings), "user-agent", useragent, NULL);
   3.368 -
   3.369 -	/* Connect WebKit events */
   3.370 -	g_signal_connect(webview, "notify::title",
   3.371 -			G_CALLBACK(notify_title_cb), window);
   3.372 -	g_signal_connect(webview, "notify::progress",
   3.373 -			G_CALLBACK(notify_progress_cb), window);
   3.374 -	g_signal_connect(webview, "notify::load-status",
   3.375 -			G_CALLBACK(notify_load_status_cb), urientry);
   3.376 -	g_signal_connect(webview, "web-view-ready",
   3.377 -			G_CALLBACK(webview_ready_cb), window);
   3.378 -	g_signal_connect(webview, "close-web-view",
   3.379 -			G_CALLBACK(close_webview_cb), window);
   3.380 -	
   3.381 -	/* Impossible to open in new window or download in kiosk mode */
   3.382 -	if (! kiosk) {
   3.383 -		g_signal_connect(webview, "download-requested",
   3.384 -			G_CALLBACK(download_requested_cb), NULL);
   3.385 -		g_signal_connect(webview, "create-web-view",
   3.386 -			G_CALLBACK(create_web_view_cb), window);
   3.387 -	}
   3.388 -
   3.389 -	/* Connect WebKit contextual menu items */
   3.390 -	g_object_connect(G_OBJECT(webview), "signal::populate-popup",
   3.391 -		G_CALLBACK(populate_menu_cb), webview, NULL);
   3.392 -
   3.393 -	return browser;
   3.394 -}
   3.395 -
   3.396 -static GtkWidget*
   3.397 -create_toolbar(GtkWidget* urientry, GtkWidget* search, WebKitWebView* webview)
   3.398 -{
   3.399 -	GtkToolItem* item;
   3.400 -	
   3.401 -	toolbar = gtk_toolbar_new();
   3.402 -	gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar),
   3.403 -			GTK_ORIENTATION_HORIZONTAL);
   3.404 -	gtk_toolbar_set_style(GTK_TOOLBAR(toolbar),
   3.405 -			GTK_TOOLBAR_BOTH_HORIZ);
   3.406 -
   3.407 -	/* The back button */
   3.408 -    item = gtk_tool_button_new_from_stock(GTK_STOCK_GO_BACK);
   3.409 -    g_signal_connect(G_OBJECT(item), "clicked",
   3.410 -			G_CALLBACK(go_back_cb), webview);
   3.411 -    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
   3.412 -
   3.413 -    /* The forward button */
   3.414 -    item = gtk_tool_button_new_from_stock(GTK_STOCK_GO_FORWARD);
   3.415 -    g_signal_connect(G_OBJECT(item), "clicked",
   3.416 -			G_CALLBACK(go_forward_cb), webview);
   3.417 -    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
   3.418 -
   3.419 -    /* Home button */
   3.420 -	item = gtk_tool_button_new_from_stock(GTK_STOCK_HOME);
   3.421 -	g_signal_connect(G_OBJECT(item), "clicked",
   3.422 -			G_CALLBACK(go_home_cb), webview);
   3.423 -	gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
   3.424 -
   3.425 -	/* URL entry */
   3.426 -	item = gtk_tool_item_new();
   3.427 -	gtk_tool_item_set_expand(item, TRUE);
   3.428 -	gtk_widget_set_size_request(urientry, 0, 20);
   3.429 -	gtk_container_add(GTK_CONTAINER(item), urientry);
   3.430 -	gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
   3.431 -	g_signal_connect(G_OBJECT(urientry), "activate",
   3.432 -			G_CALLBACK(uri_entry_cb), webview);
   3.433 -	
   3.434 -	/* Separator */
   3.435 -	item = gtk_separator_tool_item_new();
   3.436 -	gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1); 
   3.437 -	
   3.438 -	/* Search entry */
   3.439 -	item = gtk_tool_item_new();
   3.440 -	gtk_widget_set_size_request(search, 160, 20);
   3.441 -	gtk_container_add(GTK_CONTAINER(item), search);
   3.442 -	gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
   3.443 -	gtk_entry_set_icon_from_stock(GTK_ENTRY(search),
   3.444 -			GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_FIND);
   3.445 -	g_signal_connect(GTK_ENTRY(search), "icon-press",
   3.446 -			G_CALLBACK(search_icon_press_cb), webview);
   3.447 -	g_signal_connect(G_OBJECT(search), "activate",
   3.448 -			G_CALLBACK(search_entry_cb), webview);
   3.449 -	
   3.450 -	/* Bookmark button */
   3.451 -	item = gtk_tool_button_new_from_stock(GTK_STOCK_PROPERTIES);
   3.452 -	g_signal_connect(G_OBJECT(item), "clicked",
   3.453 -			G_CALLBACK(go_bookmarks_cb), webview);
   3.454 -	gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
   3.455 -
   3.456 -	return toolbar;
   3.457 -}
   3.458 -
   3.459 -/* Main window */
   3.460 -static GtkWidget*
   3.461 -create_window(WebKitWebView** newwebview)
   3.462 -{
   3.463 -	GtkWidget *window;
   3.464 -	GtkWidget *urientry;
   3.465 -	GtkWidget *search;
   3.466 -	
   3.467 -	g_atomic_int_inc(&count);
   3.468 -
   3.469 -	/* Default TazWeb window */
   3.470 -	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   3.471 -	gtk_window_set_default_size(GTK_WINDOW(window), 800, 600);
   3.472 -	gtk_window_set_icon_name(GTK_WINDOW(window), "tazweb");
   3.473 -	gtk_widget_set_name(window, "TazWeb");
   3.474 -	gtk_window_set_wmclass(GTK_WINDOW(window), "tazweb", "TazWeb");
   3.475 -	g_signal_connect(window, "destroy", G_CALLBACK(destroy_cb), NULL);
   3.476 -
   3.477 -	/* Webview and widgets */
   3.478 -	webview = WEBKIT_WEB_VIEW(webkit_web_view_new());
   3.479 -	urientry = gtk_entry_new();
   3.480 -	search = gtk_entry_new();
   3.481 -	vbox = gtk_vbox_new(FALSE, 0);
   3.482 -	
   3.483 -	/* Pack box and container */
   3.484 -	if (! notoolbar)
   3.485 -		gtk_box_pack_start(GTK_BOX(vbox),
   3.486 -			create_toolbar(urientry, search, webview), FALSE, FALSE, 0);
   3.487 -	gtk_box_pack_start(GTK_BOX(vbox),
   3.488 -			create_browser(window, urientry, search, webview), TRUE, TRUE, 0);
   3.489 -	
   3.490 -	gtk_container_add(GTK_CONTAINER(window), vbox);
   3.491 -	
   3.492 -	if (newwebview)
   3.493 -		*newwebview = webview;
   3.494 -	
   3.495 -	return window;	
   3.496 -}
   3.497 -
   3.498 -int
   3.499 -main(int argc, char* argv[])
   3.500 -{
   3.501 -	textdomain (GETTEXT_PACKAGE);
   3.502 -	
   3.503 -	while (argc > 1) {
   3.504 -		if (!strcmp(argv[1],"--notoolbar")) {
   3.505 -			notoolbar++;
   3.506 -		}
   3.507 -		else if (!strcmp(argv[1],"--kiosk")) {
   3.508 -			kiosk++;
   3.509 -		}
   3.510 -		else if (!strcmp(argv[1],"--useragent") && argc > 2) {
   3.511 -			argc--;
   3.512 -			argv++;
   3.513 -			useragent = argv[1];
   3.514 -		}
   3.515 -		else if (!strcmp(argv[1],"--help")) {
   3.516 -			printf ("Usage: tazweb [--notoolbar|--kiosk|--useragent] [ua]\n");
   3.517 -			printf ("Bookmarks: %s\n", BMTXT);
   3.518 -			return 0;
   3.519 -		}
   3.520 -		else break;
   3.521 -		argc--;
   3.522 -		argv++;
   3.523 -	}
   3.524 -	
   3.525 -	/* Initialize GTK */
   3.526 -	gtk_init(NULL, NULL);
   3.527 -	
   3.528 -	/* Get a default bookmarks.txt if missing */
   3.529 -	if (! g_file_test(BMTXT, G_FILE_TEST_EXISTS)) {
   3.530 -		system("install -m 0700 -d $HOME/.config/tazweb");
   3.531 -		system("install -m 0600 /usr/share/tazweb/bookmarks.txt \
   3.532 -			$HOME/.config/tazweb/bookmarks.txt");
   3.533 -	} 
   3.534 -
   3.535 -	/* Load the start page file or the url in argument */
   3.536 -	uri =(char*)(argc > 1 ? argv[1] : WEBHOME);
   3.537 -	if (argv[1])
   3.538 -		check_requested_uri();
   3.539 -		
   3.540 -	mainwindow = create_window(&webview);
   3.541 -	gtk_widget_show_all(mainwindow);
   3.542 -	
   3.543 -	/* Fullscreen for Kiosk mode */
   3.544 -	if (kiosk)
   3.545 -		gtk_window_fullscreen(GTK_WINDOW(mainwindow));
   3.546 -	
   3.547 -	webkit_web_view_load_uri(webview, uri);
   3.548 -	gtk_widget_grab_focus(GTK_WIDGET(webview));
   3.549 -	gtk_main();
   3.550 -	
   3.551 -	return 0;
   3.552 -}
     4.1 --- a/src/main.cpp	Fri Mar 10 11:53:18 2017 +0100
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,53 +0,0 @@
     4.4 -/*
     4.5 - * TazWeb-Qt is a radically simple web browser providing a single window.
     4.6 - * Commented line code starts with // and comments are between * *
     4.7 - *
     4.8 - * Copyright (C) 2011-2014 SliTaz GNU/Linux - BSD License
     4.9 - * See AUTHORS and LICENSE for detailed information
    4.10 - * 
    4.11 - */
    4.12 -#include <QtGui>
    4.13 -#include <QtWebKit>
    4.14 -
    4.15 -int main(int argc, char** argv)
    4.16 -{
    4.17 -	QApplication app(argc, argv);
    4.18 -	QApplication::setWindowIcon(QIcon::fromTheme("tazweb"));
    4.19 -	QFile file(QDir::homePath() + "/.config/slitaz/subox.conf");
    4.20 -	QString msg, line;
    4.21 -	QString msg2("\n ENTER/ok -> tazpanel, ESC/cancel -> bookmarks/webhome");
    4.22 -	QUrl url;
    4.23 -	if (argc > 1) { url = QUrl::fromUserInput(argv[1]); }
    4.24 -	else {
    4.25 -		if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
    4.26 -			msg = "Using subox pass... Load successfully" + msg2;
    4.27 -			QTextStream in(&file);
    4.28 -			while (!in.atEnd()) { line = in.readLine(); }
    4.29 -			file.close(); }
    4.30 -		else {	msg = file.fileName() + " not found.\nroot password requested:" + msg2;
    4.31 -			line = "root"; }
    4.32 -		bool ok;
    4.33 -		QString text = QInputDialog::getText(0, "TazWeb-Qt: TazPanel authentication",
    4.34 -			msg, QLineEdit::Password, line, &ok);
    4.35 -		if (ok && !text.isEmpty()) {
    4.36 -			QApplication::setWindowIcon(QIcon::fromTheme("tazpanel"));
    4.37 -			url = QUrl("http://root:" + text + "@tazpanel:82"); }
    4.38 -		else {
    4.39 -			if (QFile::exists(QDir::homePath() + "/.config/tazweb/bookmarks.txt"))
    4.40 -			url = QUrl("http://localhost/cgi-bin/bookmarks.cgi?home=" + QDir::homePath());
    4.41 -			else
    4.42 -			url = QUrl("file:///usr/share/webhome/index.html"); }
    4.43 -	}
    4.44 -	QWebView view;
    4.45 -/*
    4.46 -	view.show();
    4.47 -	//view.setUrl(QUrl("file:///usr/share/webhome/index.html"));
    4.48 -	view.load(QUrl("file:///usr/share/webhome/index.html"));
    4.49 -*/	
    4.50 -	//view.settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
    4.51 -	//view.settings()->setAttribute(QWebSettings::ZoomTextOnly, true);
    4.52 -	//view.setTextSizeMultiplier(1);
    4.53 -	view.showMaximized();
    4.54 -	view.load(url);
    4.55 -	return app.exec();
    4.56 -}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/tazweb-qt.cpp	Sun Mar 12 17:56:20 2017 +0100
     5.3 @@ -0,0 +1,53 @@
     5.4 +/*
     5.5 + * TazWeb-Qt is a radically simple web browser providing a single window.
     5.6 + * Commented line code starts with // and comments are between * *
     5.7 + *
     5.8 + * Copyright (C) 2011-2014 SliTaz GNU/Linux - BSD License
     5.9 + * See AUTHORS and LICENSE for detailed information
    5.10 + * 
    5.11 + */
    5.12 +#include <QtGui>
    5.13 +#include <QtWebKit>
    5.14 +
    5.15 +int main(int argc, char** argv)
    5.16 +{
    5.17 +	QApplication app(argc, argv);
    5.18 +	QApplication::setWindowIcon(QIcon::fromTheme("tazweb"));
    5.19 +	QFile file(QDir::homePath() + "/.config/slitaz/subox.conf");
    5.20 +	QString msg, line;
    5.21 +	QString msg2("\n ENTER/ok -> tazpanel, ESC/cancel -> bookmarks/webhome");
    5.22 +	QUrl url;
    5.23 +	if (argc > 1) { url = QUrl::fromUserInput(argv[1]); }
    5.24 +	else {
    5.25 +		if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
    5.26 +			msg = "Using subox pass... Load successfully" + msg2;
    5.27 +			QTextStream in(&file);
    5.28 +			while (!in.atEnd()) { line = in.readLine(); }
    5.29 +			file.close(); }
    5.30 +		else {	msg = file.fileName() + " not found.\nroot password requested:" + msg2;
    5.31 +			line = "root"; }
    5.32 +		bool ok;
    5.33 +		QString text = QInputDialog::getText(0, "TazWeb-Qt: TazPanel authentication",
    5.34 +			msg, QLineEdit::Password, line, &ok);
    5.35 +		if (ok && !text.isEmpty()) {
    5.36 +			QApplication::setWindowIcon(QIcon::fromTheme("tazpanel"));
    5.37 +			url = QUrl("http://root:" + text + "@tazpanel:82"); }
    5.38 +		else {
    5.39 +			if (QFile::exists(QDir::homePath() + "/.config/tazweb/bookmarks.txt"))
    5.40 +			url = QUrl("http://localhost/cgi-bin/bookmarks.cgi?home=" + QDir::homePath());
    5.41 +			else
    5.42 +			url = QUrl("file:///usr/share/webhome/index.html"); }
    5.43 +	}
    5.44 +	QWebView view;
    5.45 +/*
    5.46 +	view.show();
    5.47 +	//view.setUrl(QUrl("file:///usr/share/webhome/index.html"));
    5.48 +	view.load(QUrl("file:///usr/share/webhome/index.html"));
    5.49 +*/	
    5.50 +	//view.settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
    5.51 +	//view.settings()->setAttribute(QWebSettings::ZoomTextOnly, true);
    5.52 +	//view.setTextSizeMultiplier(1);
    5.53 +	view.showMaximized();
    5.54 +	view.load(url);
    5.55 +	return app.exec();
    5.56 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/tazweb-qt.pro	Sun Mar 12 17:56:20 2017 +0100
     6.3 @@ -0,0 +1,4 @@
     6.4 +
     6.5 +TARGET = tazweb-qt
     6.6 +QT += webkit
     6.7 +SOURCES = tazweb-qt.cpp
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/tazweb.c	Sun Mar 12 17:56:20 2017 +0100
     7.3 @@ -0,0 +1,549 @@
     7.4 +/*
     7.5 + * TazWeb is a radically simple web browser providing a single window
     7.6 + * with a single toolbar with buttons, an URL entry and search as well
     7.7 + * as a contextual menu, but no menu bar or tabs. Commented line code
     7.8 + * starts with // and comments are between * *
     7.9 + *
    7.10 + * Copyright (C) 2011-2014 SliTaz GNU/Linux - BSD License
    7.11 + * See AUTHORS and LICENSE for detailed information
    7.12 + * 
    7.13 + */
    7.14 +
    7.15 +#include <glib.h>
    7.16 +#include <glib/gi18n.h>
    7.17 +#define GETTEXT_PACKAGE "tazweb"
    7.18 +
    7.19 +#include <gtk/gtk.h>
    7.20 +#include <webkit/webkit.h>
    7.21 +//#include <libsoup/soup.h> // for cookies ?
    7.22 +
    7.23 +#define HOME		g_get_home_dir()
    7.24 +#define CONFIG		g_strdup_printf("%s/.config/tazweb", HOME)
    7.25 +#define BMTXT		g_strdup_printf("%s/bookmarks.txt", CONFIG)
    7.26 +#define BMURL		g_strdup_printf("%s/bookmarks.html", CONFIG)
    7.27 +#define WEBHOME		"file:///usr/share/webhome/index.html"
    7.28 +#define SEARCH		"http://duckduckgo.com/?q=%s&t=slitaz"
    7.29 +
    7.30 +static gchar *useragent = "TazWeb (X11; SliTaz GNU/Linux; U; en_US)";
    7.31 +static GtkWidget* create_window(WebKitWebView** newwebview);
    7.32 +static GtkWidget *mainwindow, *vbox, *browser, *toolbar;
    7.33 +static WebKitWebView *webview;
    7.34 +static WebKitWebFrame *frame;
    7.35 +static gint count = 0;
    7.36 +static gboolean notoolbar;
    7.37 +static gboolean noquit;
    7.38 +static gboolean kiosk;
    7.39 +const gchar* uri;
    7.40 +
    7.41 +/* Create an icon */
    7.42 +static GdkPixbuf*
    7.43 +create_pixbuf(const gchar* image)
    7.44 +{
    7.45 +	GdkPixbuf *pixbuf;
    7.46 +	pixbuf = gdk_pixbuf_new_from_file(image, NULL);
    7.47 +	return pixbuf;
    7.48 +}
    7.49 +
    7.50 +/* Can be: http://hg.slitaz.org or hg.slitaz.org */
    7.51 +static void
    7.52 +check_requested_uri()
    7.53 +{
    7.54 +	uri = g_strrstr(uri, "://") ? g_strdup(uri)
    7.55 +		: g_strdup_printf("http://%s", uri);
    7.56 +}
    7.57 +
    7.58 +/* Update title */
    7.59 +static void
    7.60 +update_title(GtkWindow* window, WebKitWebView* webview)
    7.61 +{
    7.62 +	GString *string;
    7.63 +	gdouble progress;
    7.64 +	gchar *title;
    7.65 +	
    7.66 +	string = g_string_new(webkit_web_view_get_title(webview));
    7.67 +	progress = webkit_web_view_get_progress(webview) * 100;
    7.68 +	if (progress < 100)
    7.69 +		g_string_append_printf(string, " [ %f%% ] ", progress);
    7.70 +	
    7.71 +	title = g_string_free(string, FALSE);
    7.72 +	gtk_window_set_title(window, title);
    7.73 +	g_free(title);
    7.74 +}
    7.75 +
    7.76 +/* Get the page title */
    7.77 +static void
    7.78 +notify_title_cb(WebKitWebView* webview, GParamSpec* pspec, GtkWidget* window)
    7.79 +{
    7.80 +	update_title(GTK_WINDOW(window), webview);
    7.81 +}
    7.82 +
    7.83 +/* Request progress in window title */
    7.84 +static void
    7.85 +notify_progress_cb(WebKitWebView* webview, GParamSpec* pspec, GtkWidget* window)
    7.86 +{
    7.87 +	update_title(GTK_WINDOW(window), webview);
    7.88 +}
    7.89 +
    7.90 +/* Notify url entry */
    7.91 +static void
    7.92 +notify_load_status_cb(WebKitWebView* webview, GParamSpec* pspec, GtkWidget* urientry)
    7.93 +{
    7.94 +	if (webkit_web_view_get_load_status(webview) == WEBKIT_LOAD_COMMITTED) {
    7.95 +		frame = webkit_web_view_get_main_frame(webview);
    7.96 +		uri = webkit_web_frame_get_uri(frame);
    7.97 +		if (uri)
    7.98 +			gtk_entry_set_text(GTK_ENTRY(urientry), uri);
    7.99 +	}
   7.100 +}
   7.101 +
   7.102 +/* Destroy the window */
   7.103 +static void
   7.104 +destroy_cb(GtkWidget* widget, GtkWindow* window)
   7.105 +{
   7.106 +	if (g_atomic_int_dec_and_test(&count))
   7.107 +		gtk_main_quit();
   7.108 +}
   7.109 +
   7.110 +/* Show page source */
   7.111 +static void
   7.112 +view_source_cb(GtkWidget* widget, WebKitWebView* webview)
   7.113 +{
   7.114 +	gboolean source;
   7.115 +	
   7.116 +	frame = webkit_web_view_get_main_frame(webview);
   7.117 +	uri = webkit_web_frame_get_uri(frame);
   7.118 +	source = webkit_web_view_get_view_source_mode(webview);
   7.119 +	
   7.120 +	webkit_web_view_set_view_source_mode(webview, !source);
   7.121 +	webkit_web_view_reload(webview);
   7.122 +}
   7.123 +
   7.124 +/* URL entry callback function */
   7.125 +static void
   7.126 +uri_entry_cb(GtkWidget* urientry, WebKitWebView* webview)
   7.127 +{
   7.128 +	uri = gtk_entry_get_text(GTK_ENTRY(urientry));
   7.129 +	g_assert(uri);
   7.130 +	check_requested_uri();
   7.131 +	webkit_web_view_load_uri(webview, uri);
   7.132 +}
   7.133 +
   7.134 +/* Search entry and icon callback function */
   7.135 +static void
   7.136 +search_web(GtkWidget* search, WebKitWebView* webview)
   7.137 +{
   7.138 +	uri = g_strdup_printf(SEARCH, gtk_entry_get_text(GTK_ENTRY(search)));
   7.139 +	g_assert(uri);
   7.140 +	webkit_web_view_load_uri(webview, uri);
   7.141 +}
   7.142 +
   7.143 +static void
   7.144 +search_entry_cb(GtkWidget* search, WebKitWebView* webview)
   7.145 +{
   7.146 +	search_web(search, webview);
   7.147 +}
   7.148 +
   7.149 +static void
   7.150 +search_icon_press_cb(GtkWidget *search, GtkEntryIconPosition pos,
   7.151 +		GdkEvent *event, WebKitWebView* webview)
   7.152 +{
   7.153 +    search_web(search, webview);
   7.154 +}
   7.155 +
   7.156 +/* Navigation button function: */
   7.157 +static void
   7.158 +go_bookmarks_cb(GtkWidget* widget, WebKitWebView* webview)
   7.159 +{
   7.160 +	system("tazweb-helper html_bookmarks");
   7.161 +	uri = g_strdup_printf("file://%s", BMURL);
   7.162 +	g_assert(uri);
   7.163 +	webkit_web_view_load_uri(webview, uri);
   7.164 +}
   7.165 +
   7.166 +static void
   7.167 +go_home_cb(GtkWidget* widget, WebKitWebView* webview)
   7.168 +{
   7.169 +	uri = WEBHOME;
   7.170 +	g_assert(uri);
   7.171 +	webkit_web_view_load_uri(webview, uri);
   7.172 +}
   7.173 +
   7.174 +static void
   7.175 +go_back_cb(GtkWidget* widget, WebKitWebView* webview)
   7.176 +{
   7.177 +    webkit_web_view_go_back(webview);
   7.178 +}
   7.179 +
   7.180 +static void
   7.181 +go_forward_cb(GtkWidget* widget, WebKitWebView* webview)
   7.182 +{
   7.183 +    webkit_web_view_go_forward(webview);
   7.184 +}
   7.185 +
   7.186 +/* Fullscreen and unfullscreen callback function */
   7.187 +//static void
   7.188 +//fullscreen_cb(GtkWindow* window, gpointer data)
   7.189 +//{
   7.190 +	//GdkWindowState state;
   7.191 +	//state = gdk_window_get_state(gtk_widget_get_window(GTK_WIDGET(mainwindow)));
   7.192 +
   7.193 +	//if(state & GDK_WINDOW_STATE_FULLSCREEN)
   7.194 +		//gtk_window_unfullscreen(GTK_WINDOW(mainwindow));
   7.195 +	//else
   7.196 +		//gtk_window_fullscreen(GTK_WINDOW(mainwindow));
   7.197 +//}
   7.198 +
   7.199 +/* TazWeb doc callback function */
   7.200 +static void
   7.201 +tazweb_doc_cb(GtkWidget* widget, WebKitWebView *webview)
   7.202 +{
   7.203 +	uri = ("file:///usr/share/doc/tazweb/tazweb.html");
   7.204 +	g_assert(uri);
   7.205 +	webkit_web_view_load_uri(webview, uri);
   7.206 +}
   7.207 +
   7.208 +/* Download function */
   7.209 +static gboolean
   7.210 +download_requested_cb(WebKitWebView *webview, WebKitDownload *download,
   7.211 +		gpointer user_data)
   7.212 +{
   7.213 +	const gchar* buffer;
   7.214 +	uri = webkit_download_get_uri(download);
   7.215 +	asprintf(&buffer, "xterm -T 'Download' -geom 72x10+0-24 -e \
   7.216 +				'mkdir -p $HOME/Downloads && cd $HOME/Downloads && \
   7.217 +				wget -c %s; sleep 2' &", uri);
   7.218 +	system(buffer);
   7.219 +}
   7.220 +
   7.221 +/* Zoom out and in callback function */
   7.222 +static void
   7.223 +zoom_out_cb(GtkWidget *widget, WebKitWebView* webview)
   7.224 +{
   7.225 +	webkit_web_view_zoom_out(webview);
   7.226 +}
   7.227 +
   7.228 +static void
   7.229 +zoom_in_cb(GtkWidget *widget, WebKitWebView* webview)
   7.230 +{
   7.231 +	webkit_web_view_zoom_in(webview);
   7.232 +}
   7.233 +
   7.234 +/* Printing callback function */
   7.235 +static void
   7.236 +print_page_cb (GtkWidget *widget, gpointer data)
   7.237 +{
   7.238 +    webkit_web_frame_print (webkit_web_view_get_main_frame (
   7.239 +        WEBKIT_WEB_VIEW (webview)));
   7.240 +}
   7.241 +
   7.242 +/* New webview callbacks */
   7.243 +static WebKitWebView*
   7.244 +create_web_view_cb(WebKitWebView* webview, WebKitWebFrame* web_frame,
   7.245 +		GtkWidget* window)
   7.246 +{
   7.247 +	WebKitWebView *newview;
   7.248 +	create_window(&newview);
   7.249 +	return newview;
   7.250 +}
   7.251 +
   7.252 +static gboolean
   7.253 +webview_ready_cb(WebKitWebView* webview, GtkWidget* window)
   7.254 +{
   7.255 +	gtk_widget_grab_focus(GTK_WIDGET(webview));
   7.256 +	gtk_widget_show_all(window);
   7.257 +	return FALSE;
   7.258 +}
   7.259 +
   7.260 +static gboolean
   7.261 +close_webview_cb(WebKitWebView* webview, GtkWidget* window)
   7.262 +{
   7.263 +	gtk_widget_destroy(window);
   7.264 +	return TRUE;
   7.265 +}
   7.266 +
   7.267 +/* Add a bookmark */
   7.268 +void add_bookmark_cb(GtkWidget *widget, gpointer data)
   7.269 +{
   7.270 +	const gchar* title;
   7.271 +	const gchar* buffer;
   7.272 +	
   7.273 +	title = webkit_web_view_get_title(WEBKIT_WEB_VIEW (webview));
   7.274 +	uri = webkit_web_view_get_uri(WEBKIT_WEB_VIEW (webview));
   7.275 +	
   7.276 +	asprintf(&buffer, "echo '%s|%s' >> %s", title, uri, BMTXT);
   7.277 +	system(buffer);
   7.278 +}
   7.279 +
   7.280 +/* Add items to WebKit contextual menu */
   7.281 +static void
   7.282 +populate_menu_cb(WebKitWebView *webview, GtkMenu *menu, gpointer data)
   7.283 +{
   7.284 +	GtkWidget* item;
   7.285 +	
   7.286 +	/* Separator */
   7.287 +	item = gtk_separator_menu_item_new();
   7.288 +	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   7.289 +
   7.290 +	/* Zoom in */
   7.291 +	item = gtk_image_menu_item_new_with_label(_("Zoom in"));
   7.292 +	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
   7.293 +	gtk_image_new_from_stock(GTK_STOCK_ZOOM_IN, GTK_ICON_SIZE_MENU));
   7.294 +	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   7.295 +	g_signal_connect(item, "activate", G_CALLBACK(zoom_in_cb), webview);
   7.296 +	
   7.297 +	/* Zoom out */
   7.298 +	item = gtk_image_menu_item_new_with_label(_("Zoom out"));
   7.299 +	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
   7.300 +	gtk_image_new_from_stock(GTK_STOCK_ZOOM_OUT, GTK_ICON_SIZE_MENU));
   7.301 +	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   7.302 +	g_signal_connect(item, "activate", G_CALLBACK(zoom_out_cb), webview);
   7.303 +
   7.304 +	/* Separator */
   7.305 +	item = gtk_separator_menu_item_new();
   7.306 +	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   7.307 +
   7.308 +	if (! kiosk) {
   7.309 +		/* Add a bookmark */
   7.310 +		item = gtk_image_menu_item_new_with_label(_("Add a bookmark"));
   7.311 +		gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
   7.312 +		gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
   7.313 +		gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   7.314 +		g_signal_connect(item, "activate", G_CALLBACK(add_bookmark_cb), webview);
   7.315 +	}
   7.316 +
   7.317 +	/* Printing */
   7.318 +	item = gtk_image_menu_item_new_with_label(_("Print this page"));
   7.319 +	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
   7.320 +	gtk_image_new_from_stock(GTK_STOCK_PRINT, GTK_ICON_SIZE_MENU));
   7.321 +	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   7.322 +	g_signal_connect(item, "activate", G_CALLBACK(print_page_cb), webview);
   7.323 +
   7.324 +	/* View source mode */
   7.325 +	item = gtk_image_menu_item_new_with_label(_("View source mode"));
   7.326 +	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
   7.327 +	gtk_image_new_from_stock(GTK_STOCK_PROPERTIES, GTK_ICON_SIZE_MENU));
   7.328 +	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   7.329 +	g_signal_connect(item, "activate", G_CALLBACK(view_source_cb), webview);
   7.330 +
   7.331 +	/* Separator */
   7.332 +	item = gtk_separator_menu_item_new();
   7.333 +	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   7.334 +
   7.335 +	/* TazWeb documentation */
   7.336 +	item = gtk_image_menu_item_new_with_label(_("TazWeb manual"));
   7.337 +	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
   7.338 +	gtk_image_new_from_stock(GTK_STOCK_HELP, GTK_ICON_SIZE_MENU));
   7.339 +	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   7.340 +	g_signal_connect(item, "activate", G_CALLBACK(tazweb_doc_cb), webview);
   7.341 +	
   7.342 +	/* Quit TazWeb */
   7.343 +	item = gtk_image_menu_item_new_with_label(_("Quit TazWeb"));
   7.344 +	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
   7.345 +	gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU));
   7.346 +	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   7.347 +	g_signal_connect(item, "activate", G_CALLBACK(destroy_cb), webview);
   7.348 +	
   7.349 +	gtk_widget_show_all(GTK_WIDGET(menu));
   7.350 +}
   7.351 +
   7.352 +/* Scrolled window for the webview */
   7.353 +static GtkWidget*
   7.354 +create_browser(GtkWidget* window, GtkWidget* urientry, GtkWidget* search,
   7.355 +		WebKitWebView* webview)
   7.356 +{
   7.357 +	WebKitWebSettings *settings;
   7.358 +	
   7.359 +	browser = gtk_scrolled_window_new(NULL, NULL);
   7.360 +	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(browser),
   7.361 +			GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
   7.362 +
   7.363 +	gtk_container_add(GTK_CONTAINER(browser), GTK_WIDGET(webview));
   7.364 +
   7.365 +	/* User agent */
   7.366 +	settings = webkit_web_view_get_settings (webview);
   7.367 +	g_object_set(G_OBJECT(settings), "user-agent", useragent, NULL);
   7.368 +
   7.369 +	/* Connect WebKit events */
   7.370 +	g_signal_connect(webview, "notify::title",
   7.371 +			G_CALLBACK(notify_title_cb), window);
   7.372 +	g_signal_connect(webview, "notify::progress",
   7.373 +			G_CALLBACK(notify_progress_cb), window);
   7.374 +	g_signal_connect(webview, "notify::load-status",
   7.375 +			G_CALLBACK(notify_load_status_cb), urientry);
   7.376 +	g_signal_connect(webview, "web-view-ready",
   7.377 +			G_CALLBACK(webview_ready_cb), window);
   7.378 +	g_signal_connect(webview, "close-web-view",
   7.379 +			G_CALLBACK(close_webview_cb), window);
   7.380 +	
   7.381 +	/* Impossible to open in new window or download in kiosk mode */
   7.382 +	if (! kiosk) {
   7.383 +		g_signal_connect(webview, "download-requested",
   7.384 +			G_CALLBACK(download_requested_cb), NULL);
   7.385 +		g_signal_connect(webview, "create-web-view",
   7.386 +			G_CALLBACK(create_web_view_cb), window);
   7.387 +	}
   7.388 +
   7.389 +	/* Connect WebKit contextual menu items */
   7.390 +	g_object_connect(G_OBJECT(webview), "signal::populate-popup",
   7.391 +		G_CALLBACK(populate_menu_cb), webview, NULL);
   7.392 +
   7.393 +	return browser;
   7.394 +}
   7.395 +
   7.396 +static GtkWidget*
   7.397 +create_toolbar(GtkWidget* urientry, GtkWidget* search, WebKitWebView* webview)
   7.398 +{
   7.399 +	GtkToolItem* item;
   7.400 +	
   7.401 +	toolbar = gtk_toolbar_new();
   7.402 +	gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar),
   7.403 +			GTK_ORIENTATION_HORIZONTAL);
   7.404 +	gtk_toolbar_set_style(GTK_TOOLBAR(toolbar),
   7.405 +			GTK_TOOLBAR_BOTH_HORIZ);
   7.406 +
   7.407 +	/* The back button */
   7.408 +    item = gtk_tool_button_new_from_stock(GTK_STOCK_GO_BACK);
   7.409 +    g_signal_connect(G_OBJECT(item), "clicked",
   7.410 +			G_CALLBACK(go_back_cb), webview);
   7.411 +    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
   7.412 +
   7.413 +    /* The forward button */
   7.414 +    item = gtk_tool_button_new_from_stock(GTK_STOCK_GO_FORWARD);
   7.415 +    g_signal_connect(G_OBJECT(item), "clicked",
   7.416 +			G_CALLBACK(go_forward_cb), webview);
   7.417 +    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
   7.418 +
   7.419 +    /* Home button */
   7.420 +	item = gtk_tool_button_new_from_stock(GTK_STOCK_HOME);
   7.421 +	g_signal_connect(G_OBJECT(item), "clicked",
   7.422 +			G_CALLBACK(go_home_cb), webview);
   7.423 +	gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
   7.424 +
   7.425 +	/* URL entry */
   7.426 +	item = gtk_tool_item_new();
   7.427 +	gtk_tool_item_set_expand(item, TRUE);
   7.428 +	gtk_widget_set_size_request(urientry, 0, 20);
   7.429 +	gtk_container_add(GTK_CONTAINER(item), urientry);
   7.430 +	gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
   7.431 +	g_signal_connect(G_OBJECT(urientry), "activate",
   7.432 +			G_CALLBACK(uri_entry_cb), webview);
   7.433 +	
   7.434 +	/* Separator */
   7.435 +	item = gtk_separator_tool_item_new();
   7.436 +	gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1); 
   7.437 +	
   7.438 +	/* Search entry */
   7.439 +	item = gtk_tool_item_new();
   7.440 +	gtk_widget_set_size_request(search, 160, 20);
   7.441 +	gtk_container_add(GTK_CONTAINER(item), search);
   7.442 +	gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
   7.443 +	gtk_entry_set_icon_from_stock(GTK_ENTRY(search),
   7.444 +			GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_FIND);
   7.445 +	g_signal_connect(GTK_ENTRY(search), "icon-press",
   7.446 +			G_CALLBACK(search_icon_press_cb), webview);
   7.447 +	g_signal_connect(G_OBJECT(search), "activate",
   7.448 +			G_CALLBACK(search_entry_cb), webview);
   7.449 +	
   7.450 +	/* Bookmark button */
   7.451 +	item = gtk_tool_button_new_from_stock(GTK_STOCK_PROPERTIES);
   7.452 +	g_signal_connect(G_OBJECT(item), "clicked",
   7.453 +			G_CALLBACK(go_bookmarks_cb), webview);
   7.454 +	gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
   7.455 +
   7.456 +	return toolbar;
   7.457 +}
   7.458 +
   7.459 +/* Main window */
   7.460 +static GtkWidget*
   7.461 +create_window(WebKitWebView** newwebview)
   7.462 +{
   7.463 +	GtkWidget *window;
   7.464 +	GtkWidget *urientry;
   7.465 +	GtkWidget *search;
   7.466 +	
   7.467 +	g_atomic_int_inc(&count);
   7.468 +
   7.469 +	/* Default TazWeb window */
   7.470 +	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   7.471 +	gtk_window_set_default_size(GTK_WINDOW(window), 800, 600);
   7.472 +	gtk_window_set_icon_name(GTK_WINDOW(window), "tazweb");
   7.473 +	gtk_widget_set_name(window, "TazWeb");
   7.474 +	gtk_window_set_wmclass(GTK_WINDOW(window), "tazweb", "TazWeb");
   7.475 +	g_signal_connect(window, "destroy", G_CALLBACK(destroy_cb), NULL);
   7.476 +
   7.477 +	/* Webview and widgets */
   7.478 +	webview = WEBKIT_WEB_VIEW(webkit_web_view_new());
   7.479 +	urientry = gtk_entry_new();
   7.480 +	search = gtk_entry_new();
   7.481 +	vbox = gtk_vbox_new(FALSE, 0);
   7.482 +	
   7.483 +	/* Pack box and container */
   7.484 +	if (! notoolbar)
   7.485 +		gtk_box_pack_start(GTK_BOX(vbox),
   7.486 +			create_toolbar(urientry, search, webview), FALSE, FALSE, 0);
   7.487 +	gtk_box_pack_start(GTK_BOX(vbox),
   7.488 +			create_browser(window, urientry, search, webview), TRUE, TRUE, 0);
   7.489 +	
   7.490 +	gtk_container_add(GTK_CONTAINER(window), vbox);
   7.491 +	
   7.492 +	if (newwebview)
   7.493 +		*newwebview = webview;
   7.494 +	
   7.495 +	return window;	
   7.496 +}
   7.497 +
   7.498 +int
   7.499 +main(int argc, char* argv[])
   7.500 +{
   7.501 +	textdomain (GETTEXT_PACKAGE);
   7.502 +	
   7.503 +	while (argc > 1) {
   7.504 +		if (!strcmp(argv[1],"--notoolbar")) {
   7.505 +			notoolbar++;
   7.506 +		}
   7.507 +		else if (!strcmp(argv[1],"--kiosk")) {
   7.508 +			kiosk++;
   7.509 +		}
   7.510 +		else if (!strcmp(argv[1],"--useragent") && argc > 2) {
   7.511 +			argc--;
   7.512 +			argv++;
   7.513 +			useragent = argv[1];
   7.514 +		}
   7.515 +		else if (!strcmp(argv[1],"--help")) {
   7.516 +			printf ("Usage: tazweb [--notoolbar|--kiosk|--useragent] [ua]\n");
   7.517 +			printf ("Bookmarks: %s\n", BMTXT);
   7.518 +			return 0;
   7.519 +		}
   7.520 +		else break;
   7.521 +		argc--;
   7.522 +		argv++;
   7.523 +	}
   7.524 +	
   7.525 +	/* Initialize GTK */
   7.526 +	gtk_init(NULL, NULL);
   7.527 +	
   7.528 +	/* Get a default bookmarks.txt if missing */
   7.529 +	if (! g_file_test(BMTXT, G_FILE_TEST_EXISTS)) {
   7.530 +		system("install -m 0700 -d $HOME/.config/tazweb");
   7.531 +		system("install -m 0600 /usr/share/tazweb/bookmarks.txt \
   7.532 +			$HOME/.config/tazweb/bookmarks.txt");
   7.533 +	} 
   7.534 +
   7.535 +	/* Load the start page file or the url in argument */
   7.536 +	uri =(char*)(argc > 1 ? argv[1] : WEBHOME);
   7.537 +	if (argv[1])
   7.538 +		check_requested_uri();
   7.539 +		
   7.540 +	mainwindow = create_window(&webview);
   7.541 +	gtk_widget_show_all(mainwindow);
   7.542 +	
   7.543 +	/* Fullscreen for Kiosk mode */
   7.544 +	if (kiosk)
   7.545 +		gtk_window_fullscreen(GTK_WINDOW(mainwindow));
   7.546 +	
   7.547 +	webkit_web_view_load_uri(webview, uri);
   7.548 +	gtk_widget_grab_focus(GTK_WIDGET(webview));
   7.549 +	gtk_main();
   7.550 +	
   7.551 +	return 0;
   7.552 +}
     8.1 --- a/src/tazweb.pro	Fri Mar 10 11:53:18 2017 +0100
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,4 +0,0 @@
     8.4 -
     8.5 -TARGET = tazweb-qt
     8.6 -QT += webkit
     8.7 -SOURCES = main.cpp
     9.1 --- a/tazweb-helper	Fri Mar 10 11:53:18 2017 +0100
     9.2 +++ b/tazweb-helper	Sun Mar 12 17:56:20 2017 +0100
     9.3 @@ -1,6 +1,6 @@
     9.4  #!/bin/sh
     9.5  #
     9.6 -# TazWeb Helper - Handle bookmarks (no libtaz, usable on any Linux distro)
     9.7 +# TazWeb Helper - Handle bookmarks (No libtaz.sh: usable on any Linux distro)
     9.8  #
     9.9  
    9.10  tazweb="$(pwd)/tazweb"
    9.11 @@ -14,7 +14,8 @@
    9.12  $(gettext "Usage:") $(basename $0) [bookmarks] --option
    9.13  
    9.14  $(gettext "Options:")
    9.15 -  --raw       Show raw bookmarks.txt
    9.16 +  --raw       Show raw bookmarks.txt in textmode
    9.17 +  --html      Show html bookmarks in TazWeb
    9.18  
    9.19  EOT
    9.20  }
    9.21 @@ -33,7 +34,6 @@
    9.22  		ul a { text-decoration: none; } ul a:hover { text-decoration: underline; }
    9.23  		li { list-style-type: none; color: #666; line-height: 1.4em; padding: 0; }
    9.24  		footer { font-size: 80%; border-top: 1px solid #888; padding: 5px 0; }
    9.25 -		textarea { width: 100%; height: 240px; font-size: 98%; }
    9.26  	</style>
    9.27  </head>
    9.28  <body>
    9.29 @@ -69,7 +69,7 @@
    9.30  	unset IFS
    9.31  	html_footer  >> ${bm_html}
    9.32  	# Security fix from old cgi-bin bookmarks.cgi
    9.33 -	chmod 0600 ${USER}.${USER} ${bm_txt}
    9.34 +	chown ${USER}.${USER} ${bm_txt}; chmod 0600 ${bm_txt}
    9.35  }
    9.36  
    9.37  #
    9.38 @@ -79,8 +79,9 @@
    9.39  	
    9.40  	-b|bookmarks)
    9.41  		if [ "$raw" ]; then
    9.42 -			${tazweb} file:///${config}/bookmarks.txt &
    9.43 -		else
    9.44 +			cat ${config}/bookmarks.txt
    9.45 +		fi
    9.46 +		if [ "$html" ]; then
    9.47  			html_bookmarks
    9.48  			${tazweb} file:///${config}/bookmarks.html &
    9.49  		fi ;;