tazweb rev 92

Add bookmarks function with menu item 'Add a bookmark'
author Christophe Lincoln <pankso@slitaz.org>
date Thu Apr 28 00:18:06 2011 +0200 (2011-04-28)
parents 9f32338b3ff3
children 238cbb117fa0
files data/home.html src/main.c
line diff
     1.1 --- a/data/home.html	Wed Apr 27 18:04:23 2011 +0200
     1.2 +++ b/data/home.html	Thu Apr 28 00:18:06 2011 +0200
     1.3 @@ -11,22 +11,14 @@
     1.4  	<h1>My Web Home</h1>
     1.5  </div>
     1.6  
     1.7 -<!-- Start content -->
     1.8 +<!-- start:content -->
     1.9  <div id="content">
    1.10  
    1.11  <!--
    1.12  	Welcome to your personal and custom TazWeb page: a pure xHTML 5 file
    1.13 -	with some CSS for the design, you can customize it as you want. To add
    1.14 -	a section title you can use <h2></h2> elements and <div></div> to
    1.15 -	organize content.
    1.16 -
    1.17 -	Here is an example of a bookmark entry, copy and paste it somewhere
    1.18 -	between an <ul></ul> element to add an entry in the list.
    1.19 -	
    1.20 -	<li>
    1.21 -		<a href="URL">NAME</a>
    1.22 -		: DESCRIPTION
    1.23 -	</li>
    1.24 +	with some CSS for the design, you can customize it as you want. All
    1.25 +	the page style is in the file: style.css. To add a section title you
    1.26 +	can use <h2></h2> elements and <div></div> to organize content.
    1.27  -->
    1.28  
    1.29  <div id="cloud">
    1.30 @@ -41,27 +33,21 @@
    1.31  	<a class="tag8" href="http://tazpanel:82/">TazPanel</a>
    1.32  </div>
    1.33  
    1.34 -<!-- A nice bookmarks list (Uncomment img to have favicons) -->
    1.35 -<div id="bookmarks">
    1.36 -	<h2>Bookmarks</h2>
    1.37 -	<ul>
    1.38 -		<li>
    1.39 -			<!-- <img src="http://www.slitaz.org/favicon.ico" /> -->
    1.40 -			<a href="http://bugs.slitaz.org/">bugs.slitaz.org</a>
    1.41 -			: SliTaz Bug tracker
    1.42 -		</li>
    1.43 -		<li>
    1.44 -			<!-- <img src="http://www.gnu.org/favicon.ico" /> -->
    1.45 -			<a href="http://www.gnu.org/">www.gnu.org</a>
    1.46 -			: The GNU Website
    1.47 -		</li>
    1.48 -		<li>
    1.49 -			<!-- <img src="http://is.gd/isgd_favicon.ico" /> -->
    1.50 -			<a href="http://is.gd/">is.gd</a>
    1.51 -			: URL shortener
    1.52 -		</li>
    1.53 -	</ul>
    1.54 -</div>
    1.55 +<!--
    1.56 +	The bookmarks list must finish with end:bookmarks markup since it
    1.57 +	is used by TazWeb to add a new item via the right click menu. Tip:
    1.58 +	you can add a favicon image with a bookmark URL by adding this code
    1.59 +	between <li> and <a : <img src="http://www.gnu.org/favicon.ico" />
    1.60 +-->
    1.61 +
    1.62 +<h2>Bookmarks</h2>
    1.63 +<ul>
    1.64 +	<!-- start:bookmarks -->
    1.65 +	<li><a href="http://bugs.slitaz.org/">SliTaz Bug tracker</a></li>
    1.66 +	<li><a href="http://www.gnu.org/">The GNU Website</a></li>
    1.67 +	<li><a href="http://is.gd/">is.gd URL shortener</a></li>
    1.68 +	<!-- end:bookmarks -->
    1.69 +</ul>
    1.70  
    1.71  <!-- End content -->
    1.72  </div>
     2.1 --- a/src/main.c	Wed Apr 27 18:04:23 2011 +0200
     2.2 +++ b/src/main.c	Thu Apr 28 00:18:06 2011 +0200
     2.3 @@ -189,10 +189,9 @@
     2.4  download_requested_cb(WebKitWebView *webview, WebKitDownload *download,
     2.5  		gpointer user_data)
     2.6  {
     2.7 +	const gchar* buffer;
     2.8  	uri = webkit_download_get_uri(download);
     2.9 -	const gchar* buffer;
    2.10 -	asprintf(&buffer,
    2.11 -			"xterm -T 'Download' -geom 72x10+0-24 -e \
    2.12 +	asprintf(&buffer, "xterm -T 'Download' -geom 72x10+0-24 -e \
    2.13  				'cd $HOME/Downloads && wget -c %s; sleep 2' &", uri);
    2.14  	system(buffer);
    2.15  }
    2.16 @@ -243,6 +242,23 @@
    2.17  	return TRUE;
    2.18  }
    2.19  
    2.20 +/* Add a bookmark to home.html */
    2.21 +void
    2.22 +add_bookmark_cb(GtkWidget *widget, gpointer data)
    2.23 +{
    2.24 +	const gchar* title;
    2.25 +	const gchar* buffer;
    2.26 +	
    2.27 +	title = webkit_web_view_get_title(WEBKIT_WEB_VIEW (webview));
    2.28 +	uri = webkit_web_view_get_uri(WEBKIT_WEB_VIEW (webview));
    2.29 +	
    2.30 +	asprintf(&buffer, "sed -i \
    2.31 +			-e '/<!-- end:bookmarks -->/ i <li><a href=\"%s\">%s</a></li>' \
    2.32 +			-e s'/^<li>/	<li>/' $HOME/.config/tazweb/home.html &",
    2.33 +			uri, title);
    2.34 +	system(buffer);
    2.35 +}
    2.36 +
    2.37  /* Add items to WebKit contextual menu */
    2.38  static void
    2.39  populate_menu_cb(WebKitWebView *webview, GtkMenu *menu, gpointer data)
    2.40 @@ -271,15 +287,26 @@
    2.41  	item = gtk_separator_menu_item_new();
    2.42  	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
    2.43  
    2.44 +	/* Add to bookmarks */
    2.45 +	item = gtk_image_menu_item_new_with_label("Add a bookmark");
    2.46 +	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
    2.47 +	gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
    2.48 +	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
    2.49 +	g_signal_connect(item, "activate", G_CALLBACK(add_bookmark_cb), webview);
    2.50 +
    2.51 +	/* Separator */
    2.52 +	item = gtk_separator_menu_item_new();
    2.53 +	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
    2.54 +
    2.55  	/* View source mode */
    2.56 -	item = gtk_image_menu_item_new_with_label("View source");
    2.57 +	item = gtk_image_menu_item_new_with_label("View source mode");
    2.58  	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
    2.59  	gtk_image_new_from_stock(GTK_STOCK_PROPERTIES, GTK_ICON_SIZE_MENU));
    2.60  	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
    2.61  	g_signal_connect(item, "activate", G_CALLBACK(view_source_cb), webview);
    2.62  
    2.63  	/* Printing */
    2.64 -	item = gtk_image_menu_item_new_with_label("Print page");
    2.65 +	item = gtk_image_menu_item_new_with_label("Print this page");
    2.66  	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
    2.67  	gtk_image_new_from_stock(GTK_STOCK_PRINT, GTK_ICON_SIZE_MENU));
    2.68  	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
    2.69 @@ -292,7 +319,7 @@
    2.70  	/* TazWeb documentation */
    2.71  	item = gtk_image_menu_item_new_with_label("TazWeb manual");
    2.72  	gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
    2.73 -	gtk_image_new_from_stock(GTK_STOCK_INFO, GTK_ICON_SIZE_MENU));
    2.74 +	gtk_image_new_from_stock(GTK_STOCK_HELP, GTK_ICON_SIZE_MENU));
    2.75  	gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
    2.76  	g_signal_connect(item, "activate", G_CALLBACK(tazweb_doc_cb), webview);
    2.77