# HG changeset patch # User Christophe Lincoln # Date 1396716702 -7200 # Node ID b499c4de56347f1b2d1324be58fe173e7039e0f9 # Parent b3a109d2818ff662258272f156d94f6d2d4ef572 Add real bookmark support :-) diff -r b3a109d2818f -r b499c4de5634 Makefile --- a/Makefile Sat Apr 05 09:13:43 2014 +0200 +++ b/Makefile Sat Apr 05 18:51:42 2014 +0200 @@ -40,23 +40,20 @@ msgfmt -o po/mo/$$l/LC_MESSAGES/$(PACKAGE).mo po/$$l.po; \ done; - install: mkdir -p \ $(DESTDIR)$(DOCDIR)/$(PACKAGE) \ $(DESTDIR)$(PREFIX)/bin \ + $(DESTDIR)$(PREFIX)/var/www/cgi-bin \ $(DESTDIR)$(PREFIX)/share/tazweb \ $(DESTDIR)$(PREFIX)/share/pixmaps \ $(DESTDIR)$(PREFIX)/share/applications install -m 0755 $(PACKAGE) $(DESTDIR)$(PREFIX)/bin cp -d doc/* $(DESTDIR)$(DOCDIR)/$(PACKAGE) - install -m 0644 data/tazweb.png \ - $(DESTDIR)$(PREFIX)/share/pixmaps - install -m 0644 data/tazweb.desktop \ - $(DESTDIR)$(PREFIX)/share/applications - cp -a data/*.html $(DESTDIR)$(PREFIX)/share/tazweb - install -m 0644 data/style.css \ - $(DESTDIR)$(PREFIX)/share/tazweb + install -m 0644 data/tazweb.png $(DESTDIR)$(PREFIX)/share/pixmaps + install -m 0644 data/tazweb.desktop $(DESTDIR)$(PREFIX)/share/applications + install -m 0644 data/bookmarks.txt $(DESTDIR)$(PREFIX)/share/tazweb + install -m 0755 data/bookmarks.cgi $(DESTDIR)$(PREFIX)/var/www/cgi-bin mkdir -p $(DESTDIR)$(PREFIX)/share/locale cp -a po/mo/* $(DESTDIR)$(PREFIX)/share/locale diff -r b3a109d2818f -r b499c4de5634 README --- a/README Sat Apr 05 09:13:43 2014 +0200 +++ b/README Sat Apr 05 18:51:42 2014 +0200 @@ -52,6 +52,7 @@ Coding notes ------------ + * To get the filename of a WebKitDownload: file = webkit_download_get_suggested_filename (download); diff -r b3a109d2818f -r b499c4de5634 data/bookmarks.cgi --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/bookmarks.cgi Sat Apr 05 18:51:42 2014 +0200 @@ -0,0 +1,95 @@ +#!/bin/sh +# +# TazWeb Bookmarks CGI handler +# Copyright (C) 2014 SliTaz GNU/Linux - BSD License +# +. /usr/lib/slitaz/httphelper.sh + +script="$SCRIPT_NAME" +home="$(GET home)" +user="$(basename $home)" +config="/home/$user/.config/tazweb" +bookmarks="$config/bookmarks.txt" + +# Security check +if [ "$REMOTE_ADDR" != "127.0.0.1" ]; then + echo "Security exit" && exit 1 +fi + +# HTML 5 header with built-in minimal CSS +html_header() { + cat << EOT + + + + + TazWeb - Bookmarks + + + +
+ +EOT +} + +# HTML 5 footer +html_footer() { + cat << EOT + +
+ + + + + +EOT +} + +# Handle GET actions: continue or exit + +case " $(GET) " in + *\ raw\ *) + # View bookmarks file + header + html_header + echo "

TazWeb: bookmarks.txt

" + echo "
" 
+		cat ${bookmarks}
+		echo "
" + html_footer && exit 0 ;; + *\ rm\ *) + # Remove a bookmark item and contine + url=$(GET rm) + [ "$url" ] || continue + sed -i s"#.*${url}.*##" ${bookmarks} + sed -i "/^$/"d ${bookmarks} ;; +esac + +# Show all bookmarks +header +html_header +echo '

TazWeb Bookmarks

' +echo '' +html_footer + +exit 0 diff -r b3a109d2818f -r b499c4de5634 data/bookmarks.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/bookmarks.txt Sat Apr 05 18:51:42 2014 +0200 @@ -0,0 +1,5 @@ +SliTaz Website|http://www.slitaz.org| +SliTaz ARM|http://arm.slitaz.org| +Wikipedia|http://wikipedia.org/| +Twitter|http://twitter.com| +Google search|http://www.google.com/| diff -r b3a109d2818f -r b499c4de5634 data/home.en.html --- a/data/home.en.html Sat Apr 05 09:13:43 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ - - - - My Web Home - - - - - - - - -
- - - - - - - -

Bookmarks

- - - -
- - - diff -r b3a109d2818f -r b499c4de5634 data/home.fr.html --- a/data/home.fr.html Sat Apr 05 09:13:43 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ - - - - My Web Home - - - - - - - - -
- - - - - - - -

Bookmarks

- - - -
- - - diff -r b3a109d2818f -r b499c4de5634 data/home.html --- a/data/home.html Sat Apr 05 09:13:43 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -home.en.html \ No newline at end of file diff -r b3a109d2818f -r b499c4de5634 data/home.pt.html --- a/data/home.pt.html Sat Apr 05 09:13:43 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ - - - - Página inicial do TazWeb - - - - - - - - -
- - - - - - - -

Favoritos

- - - -
- - - diff -r b3a109d2818f -r b499c4de5634 data/home.ru.html --- a/data/home.ru.html Sat Apr 05 09:13:43 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ - - - - - Моя веб-страница - - - - - - - -
- - - - - - - -

Закладки

- - - -
- - - diff -r b3a109d2818f -r b499c4de5634 data/style.css --- a/data/style.css Sat Apr 05 09:13:43 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -/* CSS style for TazWeb page */ - -body { - font: 88% sans-serif, vernada, arial; - margin: 0; -} - -h1 { margin: 0; padding: 8px; - color: #fff; font-size: 20px; font-style: italic; } -h2 { color: #444; } -h3 { color: #666; font-size: 140%; } -ul { list-style-type: square; line-height: 140%; } -img { vertical-align: middle; } -a { color: #215090; } -a:hover { text-decoration: none; color: blue; } - -#header { - background: #351a0a; - height: 40px; - border-bottom: 8px solid #d66018; -} - -#content { - margin: 80px; -} - -#cloud { - padding: 10px; - margin: 0 0 40px; - line-height: 3em; - text-align: center; - background: #f8f8f8; - border: 1px solid #ddd; - border-radius: 8px; -} - -#cloud a { padding: 0 6px; color: #444444; } -#cloud a.tag1 { font-size: 0.6em; font-weight: 100; } -#cloud a.tag2 { font-size: 0.8em; font-weight: 200; } -#cloud a.tag3 { font-size: 1.0em; font-weight: 300; } -#cloud a.tag4 { font-size: 1.2em; font-weight: 400; } -#cloud a.tag5 { font-size: 1.4em; font-weight: 500; } -#cloud a.tag6 { font-size: 1.6em; font-weight: 600; } -#cloud a.tag7 { font-size: 1.8em; font-weight: 700; } -#cloud a.tag8 { font-size: 2.0em; font-weight: 800; } - diff -r b3a109d2818f -r b499c4de5634 doc/tazweb.en.html --- a/doc/tazweb.en.html Sat Apr 05 09:13:43 2014 +0200 +++ b/doc/tazweb.en.html Sat Apr 05 18:51:42 2014 +0200 @@ -60,39 +60,29 @@ $ tazweb --kiosk -

My Home Page and bookmarks

+

Home Page and bookmarks

- TazWeb handles a personal page located in your Freedesktop standard - configuration directory, the path is: $HOME/.config/tazweb/home.html. - It lets you have a custom page with bookmarks and other content. The - CSS style is defined in $HOME/.config/tazweb/style.css. + TazWeb handles a home page located in your a system wide standard + configuration directory, the path is: /usr/share/webhome

- The file is a simple xHTML 5 document with, by default, a list of - links and a box. You can edit this file with you favorite editor - and add content such as bookmarks entries or change the look and - feel as you want. At first start TazWeb will create and copy your - personal page and style to your config directory. -

-

- To add some life to your pages you can use your own Javascript - widgets or some from a third party website such as the famous - - Twitter Widget as seen on the SliTaz main website. + The bookmark.txt file is a simple text document with, by default, a + list of links. You can edit this file with you favorite editor + and add bookmarks entries or use Tazweb right click menu. At first + start TazWeb will create and copy your personal bookmarks file to + your config directory.

Bookmarks can be handled by TazWeb and you can easily add a bookmark to - your home page with the right click menu item: "Add a bookmark". To function - TazWeb uses markup in your home.html document; this markup should not - be removed if you want bookmarking to work since each new item will be - added just before the line: <!-- end:bookmarks --> + your home page with the right click menu item: "Add a bookmark". + Tazweb let you also manage your bookmarks via a nifty CGI web interface.

- Note: You will find the default home.html in: /usr/share/tazweb and + Note: You will find the default bookmarks.txt in: /usr/share/tazweb and can get an original copy with the following command in a terminal:

-$ cp -r /usr/share/tazweb $HOME/.config/tazweb
+$ cp -f /usr/share/tazweb/bookmarks.html $HOME/.config/tazweb
 

Start page and url in argument

diff -r b3a109d2818f -r b499c4de5634 src/main.c --- a/src/main.c Sat Apr 05 09:13:43 2014 +0200 +++ b/src/main.c Sat Apr 05 18:51:42 2014 +0200 @@ -16,9 +16,12 @@ #include #include -#define CONFIG g_strdup_printf("%s/.config/tazweb", g_get_home_dir()) -#define START "file:///usr/share/webhome/index.html" -#define SEARCH "http://duckduckgo.com/?q=%s&t=slitaz" +#define HOME g_get_home_dir() +#define CONFIG g_strdup_printf("%s/.config/tazweb", HOME) +#define BMTXT g_strdup_printf("%s/bookmarks.txt", CONFIG) +#define BMURL "http://localhost/cgi-bin/bookmarks.cgi" +#define WEBHOME "file:///usr/share/webhome/index.html" +#define SEARCH "http://duckduckgo.com/?q=%s&t=slitaz" /* Needs AppleWebKit/531.2+ to handle all sites ? */ static gchar *useragent = "TazWeb (X11; SliTaz GNU/Linux; U; en_US)"; @@ -28,6 +31,7 @@ static WebKitWebFrame *frame; static gint count = 0; static gboolean notoolbar; +static gboolean noquit; static gboolean kiosk; const gchar* uri; @@ -146,11 +150,19 @@ search_web(search, webview); } -/* Navigation button function */ +/* Navigation button function: */ +static void +go_bookmarks_cb(GtkWidget* widget, WebKitWebView* webview) +{ + uri = g_strdup_printf("%s?home=%s", BMURL, HOME); + g_assert(uri); + webkit_web_view_load_uri(webview, uri); +} + static void go_home_cb(GtkWidget* widget, WebKitWebView* webview) { - uri = g_strdup_printf("file://%s/home.html", CONFIG); + uri = WEBHOME; g_assert(uri); webkit_web_view_load_uri(webview, uri); } @@ -168,17 +180,17 @@ } /* Fullscreen and unfullscreen callback function */ -static void -fullscreen_cb(GtkWindow* window, gpointer data) -{ - GdkWindowState state; - state = gdk_window_get_state(gtk_widget_get_window(GTK_WIDGET(mainwindow))); +//static void +//fullscreen_cb(GtkWindow* window, gpointer data) +//{ + //GdkWindowState state; + //state = gdk_window_get_state(gtk_widget_get_window(GTK_WIDGET(mainwindow))); - if(state & GDK_WINDOW_STATE_FULLSCREEN) - gtk_window_unfullscreen(GTK_WINDOW(mainwindow)); - else - gtk_window_fullscreen(GTK_WINDOW(mainwindow)); -} + //if(state & GDK_WINDOW_STATE_FULLSCREEN) + //gtk_window_unfullscreen(GTK_WINDOW(mainwindow)); + //else + //gtk_window_fullscreen(GTK_WINDOW(mainwindow)); +//} /* TazWeb doc callback function */ static void @@ -249,8 +261,7 @@ } /* Add a bookmark to home.html */ -void -add_bookmark_cb(GtkWidget *widget, gpointer data) +void add_bookmark_cb(GtkWidget *widget, gpointer data) { const gchar* title; const gchar* buffer; @@ -258,10 +269,7 @@ title = webkit_web_view_get_title(WEBKIT_WEB_VIEW (webview)); uri = webkit_web_view_get_uri(WEBKIT_WEB_VIEW (webview)); - asprintf(&buffer, "sed -i \ - -e '// i
  • %s
  • ' \ - -e s'/^
  • /
  • /' $HOME/.config/tazweb/home.html &", - uri, title); + asprintf(&buffer, "echo '%s|%s' >> %s", title, uri, BMTXT); system(buffer); } @@ -293,8 +301,8 @@ item = gtk_separator_menu_item_new(); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); - /* Add to bookmarks */ if (! kiosk) { + /* Add a bookmark */ item = gtk_image_menu_item_new_with_label(_("Add a bookmark")); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU)); @@ -327,10 +335,6 @@ gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); g_signal_connect(item, "activate", G_CALLBACK(tazweb_doc_cb), webview); - /* Separator */ - item = gtk_separator_menu_item_new(); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); - /* Quit TazWeb */ item = gtk_image_menu_item_new_with_label(_("Quit TazWeb")); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), @@ -369,6 +373,7 @@ G_CALLBACK(webview_ready_cb), window); g_signal_connect(webview, "close-web-view", G_CALLBACK(close_webview_cb), window); + /* Impossible to open in new window or download in kiosk mode */ if (! kiosk) { g_signal_connect(webview, "download-requested", @@ -428,7 +433,7 @@ /* Search entry */ item = gtk_tool_item_new(); - gtk_widget_set_size_request(search, 150, 20); + gtk_widget_set_size_request(search, 160, 20); gtk_container_add(GTK_CONTAINER(item), search); gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1); gtk_entry_set_icon_from_stock(GTK_ENTRY(search), @@ -438,14 +443,12 @@ g_signal_connect(G_OBJECT(search), "activate", G_CALLBACK(search_entry_cb), webview); - /* The Fullscreen button */ - if (! kiosk) { - item = gtk_tool_button_new_from_stock(GTK_STOCK_FULLSCREEN); - g_signal_connect(G_OBJECT(item), "clicked", - G_CALLBACK(fullscreen_cb), NULL); - gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1); - } - + /* Bookmark button */ + item = gtk_tool_button_new_from_stock(GTK_STOCK_SAVE); + g_signal_connect(G_OBJECT(item), "clicked", + G_CALLBACK(go_bookmarks_cb), webview); + gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, -1); + return toolbar; } @@ -492,7 +495,7 @@ main(int argc, char* argv[]) { textdomain (GETTEXT_PACKAGE); - + while (argc > 1) { if (!strcmp(argv[1],"--notoolbar")) { notoolbar++; @@ -505,23 +508,29 @@ argv++; useragent = argv[1]; } + else if (!strcmp(argv[1],"--help")) { + printf ("Usage: tazweb [--notoolbar|--kiosk|--useragent] [ua]\n"); + printf ("Bookmarks: %s\n", BMTXT); + return 0; + } else break; argc--; argv++; } + gtk_init(NULL, NULL); if (!g_thread_supported()) g_thread_init(NULL); - + /* Get a default home.html if missing */ if (! g_file_test(CONFIG, G_FILE_TEST_EXISTS)) { - system("mkdir -p $HOME/.config/tazweb"); - system("cp /usr/share/tazweb/home.html $HOME/.config/tazweb"); - system("cp /usr/share/tazweb/style.css $HOME/.config/tazweb"); - } + system("install -m 0777 $HOME/.config/tazweb"); + system("install -m 0666 /usr/share/tazweb/bookmarks.txt \ + $HOME/.config/tazweb"); + } /* Load the start page file or the url in argument */ - uri =(char*)(argc > 1 ? argv[1] : START); + uri =(char*)(argc > 1 ? argv[1] : WEBHOME); if (argv[1]) check_requested_uri();