tazweb rev 130

Add a Kiosk mode and fullscreen button for normal use
author Christophe Lincoln <pankso@slitaz.org>
date Sat Jan 04 03:12:36 2014 +0100 (2014-01-04)
parents 0940993683ef
children 131267d07b58
files doc/tazweb.en.html src/main.c
line diff
     1.1 --- a/doc/tazweb.en.html	Sat Jan 04 02:11:10 2014 +0100
     1.2 +++ b/doc/tazweb.en.html	Sat Jan 04 03:12:36 2014 +0100
     1.3 @@ -50,6 +50,16 @@
     1.4  	with cookies!).
     1.5  </p>
     1.6  
     1.7 +<h3>Kiosk mode</h3>
     1.8 +<p>
     1.9 +	TazWeb provide a Kiosk mode useful for computer in public area. The
    1.10 +	Kiosk mode will start TazWeb in fullscreen. It will not allow users to
    1.11 +	bookmarks a page, download anything or open an URL in a new window.
    1.12 +</p>
    1.13 +<pre>
    1.14 +$ tazweb --kiosk
    1.15 +</pre>
    1.16 +
    1.17  <h3>My Home Page and bookmarks</h3>
    1.18  <p>
    1.19  	TazWeb handles a personal page located in your Freedesktop standard
    1.20 @@ -165,7 +175,7 @@
    1.21  </div>
    1.22  
    1.23  <div id="footer">
    1.24 -	Copyright (C) 2013 TazWeb contributors
    1.25 +	Copyright (C) 2014 TazWeb contributors
    1.26  </div>
    1.27  
    1.28  </body>
     2.1 --- a/src/main.c	Sat Jan 04 02:11:10 2014 +0100
     2.2 +++ b/src/main.c	Sat Jan 04 03:12:36 2014 +0100
     2.3 @@ -22,12 +22,13 @@
     2.4  
     2.5  /* Needs AppleWebKit/531.2+ to handle all sites ? */
     2.6  static gchar *useragent = "TazWeb (X11; SliTaz GNU/Linux; U; en_US)";
     2.7 -
     2.8  static GtkWidget* create_window(WebKitWebView** newwebview);
     2.9  static GtkWidget *mainwindow, *vbox, *browser, *toolbar;
    2.10  static WebKitWebView *webview;
    2.11  static WebKitWebFrame *frame;
    2.12  static gint count = 0;
    2.13 +static gboolean notoolbar;
    2.14 +static gboolean kiosk;
    2.15  const gchar* uri;
    2.16  
    2.17  /* Create an icon */
    2.18 @@ -167,17 +168,17 @@
    2.19  }
    2.20  
    2.21  /* Fullscreen and unfullscreen callback function */
    2.22 -//static void
    2.23 -//fullscreen_cb(GtkWindow* window, gpointer data)
    2.24 -//{
    2.25 -	//GdkWindowState state;
    2.26 -	//state = gdk_window_get_state(gtk_widget_get_window(GTK_WIDGET(mainwindow)));
    2.27 +static void
    2.28 +fullscreen_cb(GtkWindow* window, gpointer data)
    2.29 +{
    2.30 +	GdkWindowState state;
    2.31 +	state = gdk_window_get_state(gtk_widget_get_window(GTK_WIDGET(mainwindow)));
    2.32  
    2.33 -	//if(state & GDK_WINDOW_STATE_FULLSCREEN)
    2.34 -		//gtk_window_unfullscreen(GTK_WINDOW(mainwindow));
    2.35 -	//else
    2.36 -		//gtk_window_fullscreen(GTK_WINDOW(mainwindow));
    2.37 -//}
    2.38 +	if(state & GDK_WINDOW_STATE_FULLSCREEN)
    2.39 +		gtk_window_unfullscreen(GTK_WINDOW(mainwindow));
    2.40 +	else
    2.41 +		gtk_window_fullscreen(GTK_WINDOW(mainwindow));
    2.42 +}
    2.43  
    2.44  /* TazWeb doc callback function */
    2.45  static void
    2.46 @@ -293,15 +294,20 @@
    2.47  	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
    2.48  
    2.49  	/* Add to bookmarks */
    2.50 -	item = gtk_image_menu_item_new_with_label(_("Add a bookmark"));
    2.51 +	if (! kiosk) {
    2.52 +		item = gtk_image_menu_item_new_with_label(_("Add a bookmark"));
    2.53 +		gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
    2.54 +		gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
    2.55 +		gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
    2.56 +		g_signal_connect(item, "activate", G_CALLBACK(add_bookmark_cb), webview);
    2.57 +	}
    2.58 +
    2.59 +	/* Printing */
    2.60 +	item = gtk_image_menu_item_new_with_label(_("Print this page"));
    2.61  	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
    2.62 -	gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
    2.63 +	gtk_image_new_from_stock(GTK_STOCK_PRINT, GTK_ICON_SIZE_MENU));
    2.64  	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
    2.65 -	g_signal_connect(item, "activate", G_CALLBACK(add_bookmark_cb), webview);
    2.66 -
    2.67 -	/* Separator */
    2.68 -	item = gtk_separator_menu_item_new();
    2.69 -	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
    2.70 +	g_signal_connect(item, "activate", G_CALLBACK(print_page_cb), webview);
    2.71  
    2.72  	/* View source mode */
    2.73  	item = gtk_image_menu_item_new_with_label(_("View source mode"));
    2.74 @@ -310,13 +316,6 @@
    2.75  	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
    2.76  	g_signal_connect(item, "activate", G_CALLBACK(view_source_cb), webview);
    2.77  
    2.78 -	/* Printing */
    2.79 -	item = gtk_image_menu_item_new_with_label(_("Print this page"));
    2.80 -	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
    2.81 -	gtk_image_new_from_stock(GTK_STOCK_PRINT, GTK_ICON_SIZE_MENU));
    2.82 -	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
    2.83 -	g_signal_connect(item, "activate", G_CALLBACK(print_page_cb), webview);
    2.84 -
    2.85  	/* Separator */
    2.86  	item = gtk_separator_menu_item_new();
    2.87  	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
    2.88 @@ -328,6 +327,17 @@
    2.89  	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
    2.90  	g_signal_connect(item, "activate", G_CALLBACK(tazweb_doc_cb), webview);
    2.91  	
    2.92 +	/* Separator */
    2.93 +	item = gtk_separator_menu_item_new();
    2.94 +	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
    2.95 +	
    2.96 +	/* Quit TazWeb */
    2.97 +	item = gtk_image_menu_item_new_with_label(_("Quit TazWeb"));
    2.98 +	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
    2.99 +	gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU));
   2.100 +	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   2.101 +	g_signal_connect(item, "activate", G_CALLBACK(destroy_cb), webview);
   2.102 +	
   2.103  	gtk_widget_show_all(GTK_WIDGET(menu));
   2.104  }
   2.105  
   2.106 @@ -355,14 +365,17 @@
   2.107  			G_CALLBACK(notify_progress_cb), window);
   2.108  	g_signal_connect(webview, "notify::load-status",
   2.109  			G_CALLBACK(notify_load_status_cb), urientry);
   2.110 -	g_signal_connect(webview, "download-requested",
   2.111 -			G_CALLBACK(download_requested_cb), NULL);
   2.112 -	g_signal_connect(webview, "create-web-view",
   2.113 -			G_CALLBACK(create_web_view_cb), window);
   2.114  	g_signal_connect(webview, "web-view-ready",
   2.115  			G_CALLBACK(webview_ready_cb), window);
   2.116  	g_signal_connect(webview, "close-web-view",
   2.117  			G_CALLBACK(close_webview_cb), window);
   2.118 +	/* Impossible to open in new window or download in kiosk mode */
   2.119 +	if (! kiosk) {
   2.120 +		g_signal_connect(webview, "download-requested",
   2.121 +			G_CALLBACK(download_requested_cb), NULL);
   2.122 +		g_signal_connect(webview, "create-web-view",
   2.123 +			G_CALLBACK(create_web_view_cb), window);
   2.124 +	}
   2.125  
   2.126  	/* Connect WebKit contextual menu items */
   2.127  	g_object_connect(G_OBJECT(webview), "signal::populate-popup",
   2.128 @@ -426,15 +439,16 @@
   2.129  			G_CALLBACK(search_entry_cb), webview);
   2.130  	
   2.131  	/* The Fullscreen button */
   2.132 -	//item = gtk_tool_button_new_from_stock(GTK_STOCK_FULLSCREEN);
   2.133 -	//g_signal_connect(G_OBJECT(item), "clicked",
   2.134 -			//G_CALLBACK(fullscreen_cb), NULL);
   2.135 -	//gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
   2.136 -
   2.137 +	if (! kiosk) {
   2.138 +		item = gtk_tool_button_new_from_stock(GTK_STOCK_FULLSCREEN);
   2.139 +		g_signal_connect(G_OBJECT(item), "clicked",
   2.140 +				G_CALLBACK(fullscreen_cb), NULL);
   2.141 +		gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1);
   2.142 +	}
   2.143 +	
   2.144  	return toolbar;
   2.145  }
   2.146  
   2.147 -static gboolean notoolbar;
   2.148  /* Main window */
   2.149  static GtkWidget*
   2.150  create_window(WebKitWebView** newwebview)
   2.151 @@ -464,7 +478,7 @@
   2.152  			create_browser(window, urientry, search, webview), TRUE, TRUE, 0);
   2.153  	if (! notoolbar)
   2.154  		gtk_box_pack_start(GTK_BOX(vbox),
   2.155 -				create_toolbar(urientry, search, webview), FALSE, FALSE, 0);
   2.156 +			create_toolbar(urientry, search, webview), FALSE, FALSE, 0);
   2.157  	gtk_container_add(GTK_CONTAINER(window), vbox);
   2.158  	
   2.159  	if (newwebview)
   2.160 @@ -482,6 +496,9 @@
   2.161  		if (!strcmp(argv[1],"--notoolbar")) {
   2.162  			notoolbar++;
   2.163  		}
   2.164 +		else if (!strcmp(argv[1],"--kiosk")) {
   2.165 +			kiosk++;
   2.166 +		}
   2.167  		else if (!strcmp(argv[1],"--useragent") && argc > 2) {
   2.168  			argc--;
   2.169  			argv++;
   2.170 @@ -508,8 +525,12 @@
   2.171  		check_requested_uri();
   2.172  		
   2.173  	mainwindow = create_window(&webview);
   2.174 +	gtk_widget_show_all(mainwindow);
   2.175  	
   2.176 -	gtk_widget_show_all(mainwindow);
   2.177 +	/* Fullscreen for Kiosk mode */
   2.178 +	if (kiosk)
   2.179 +		gtk_window_fullscreen(GTK_WINDOW(mainwindow));
   2.180 +	
   2.181  	webkit_web_view_load_uri(webview, uri);
   2.182  	gtk_widget_grab_focus(GTK_WIDGET(webview));
   2.183  	gtk_main();