tazweb rev 185

Add src/snippets.c for unused but usable code :-)
author Christophe Lincoln <pankso@slitaz.org>
date Tue Mar 14 13:01:10 2017 +0100 (2017-03-14)
parents 639b611287cb
children f71f2a7adfbf
files src/snippets.c
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/snippets.c	Tue Mar 14 13:01:10 2017 +0100
     1.3 @@ -0,0 +1,110 @@
     1.4 +/*
     1.5 + * TazWeb code snippets: small region of re-usable source code
     1.6 + * 
     1.7 + * This file is used for ideas, proposal and to keep removed code under
     1.8 + * the hand.
     1.9 + *
    1.10 + * Copyright (C) 2011-2017 SliTaz GNU/Linux - BSD License
    1.11 + * See AUTHORS and LICENSE for detailed information
    1.12 + *
    1.13 + */
    1.14 +
    1.15 +/* Cmdline parsing with getopt to handle -p -s */
    1.16 +while ((c = getopt(argc, argv, "psk:u")) != -1) {
    1.17 +	switch (c) {
    1.18 +		case 'p':
    1.19 +			notoolbar++;
    1.20 +			break;
    1.21 +		
    1.22 +		case 's':
    1.23 +			nocookies++;
    1.24 +			break;
    1.25 +		
    1.26 +		case 'k':
    1.27 +			kiosk++;
    1.28 +			break;
    1.29 +		
    1.30 +		case 'u':
    1.31 +			useragent = optarg;
    1.32 +			break;
    1.33 +		
    1.34 +		default:
    1.35 +			help();
    1.36 +	}
    1.37 +}
    1.38 +
    1.39 +/* 
    1.40 + * 
    1.41 + * Callback
    1.42 + * 
    1.43 + * 
    1.44 + **********************************************************************/
    1.45 +
    1.46 +/* Zoom out and in callback function
    1.47 + * 
    1.48 + * Not sure zooming is usefull in menu, but with GDK keybinding or
    1.49 + * mouse Ctrl+scroll it would be nice!
    1.50 + * 
    1.51 + */
    1.52 +
    1.53 +static void
    1.54 +zoom_out_cb(GtkWidget *widget, WebKitWebView* webview)
    1.55 +{
    1.56 +	webkit_web_view_zoom_out(webview);
    1.57 +}
    1.58 +
    1.59 +static void
    1.60 +zoom_in_cb(GtkWidget *widget, WebKitWebView* webview)
    1.61 +{
    1.62 +	webkit_web_view_zoom_in(webview);
    1.63 +}
    1.64 +
    1.65 +/* Fullscreen and unfullscreen callback function 
    1.66 + * 
    1.67 + * Buggy: first window is going fullscreen
    1.68 + * 
    1.69 + */
    1.70 +
    1.71 +static void
    1.72 +fullscreen_cb(GtkWidget* window, gpointer data)
    1.73 +{
    1.74 +	GdkWindowState state;
    1.75 +	state = gdk_window_get_state(gtk_widget_get_window(GTK_WIDGET(mainwindow)));
    1.76 +
    1.77 +	if(state & GDK_WINDOW_STATE_FULLSCREEN)
    1.78 +		gtk_window_unfullscreen(GTK_WINDOW(mainwindow));
    1.79 +	else
    1.80 +		gtk_window_fullscreen(GTK_WINDOW(mainwindow));
    1.81 +}
    1.82 +
    1.83 +/* Add items to WebKit contextual menu */
    1.84 +static void
    1.85 +populate_menu_cb(WebKitWebView *webview, GtkMenu *menu, gpointer data)
    1.86 +{
    1.87 +	
    1.88 +	/* Zoom in */
    1.89 +	item = gtk_image_menu_item_new_with_label(_("Zoom in"));
    1.90 +	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
    1.91 +	gtk_image_new_from_stock(GTK_STOCK_ZOOM_IN, GTK_ICON_SIZE_MENU));
    1.92 +	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
    1.93 +	g_signal_connect(item, "activate", G_CALLBACK(zoom_in_cb), webview);
    1.94 +
    1.95 +	/* Zoom out */
    1.96 +	item = gtk_image_menu_item_new_with_label(_("Zoom out"));
    1.97 +	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
    1.98 +	gtk_image_new_from_stock(GTK_STOCK_ZOOM_OUT, GTK_ICON_SIZE_MENU));
    1.99 +	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   1.100 +	g_signal_connect(item, "activate", G_CALLBACK(zoom_out_cb), webview);
   1.101 +	
   1.102 +	/* Fullscreen */
   1.103 +	item = gtk_image_menu_item_new_with_label(_("Fullscreen mode"));
   1.104 +	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
   1.105 +	gtk_image_new_from_stock(GTK_STOCK_FULLSCREEN, GTK_ICON_SIZE_MENU));
   1.106 +	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   1.107 +	g_signal_connect(item, "activate", G_CALLBACK(fullscreen_cb), webview);
   1.108 +
   1.109 +	/* Separator */
   1.110 +	item = gtk_separator_menu_item_new();
   1.111 +	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
   1.112 +
   1.113 +}