]> spindle.queued.net Git - midori/commitdiff
Allow adding speed dial shortcuts from the context menu
authorJean-François Guchens <zcx000@gmail.com>
Sat, 9 May 2009 14:41:01 +0000 (16:41 +0200)
committerChristian Dywan <christian@twotoasts.de>
Sat, 9 May 2009 14:41:01 +0000 (16:41 +0200)
data/speeddial-body.html [new file with mode: 0644]
data/speeddial-head.html [new file with mode: 0644]
data/tandoori-body.html [deleted file]
data/tandoori-head.html [deleted file]
midori/midori-view.c
wscript

diff --git a/data/speeddial-body.html b/data/speeddial-body.html
new file mode 100644 (file)
index 0000000..1ae3f1e
--- /dev/null
@@ -0,0 +1,71 @@
+<!--
+ Speed Dial head template for Midori.
+ Copyright (C) 2009 Jean-François Guchens <zcx000@gmail.com>
+ This file is licensed under the terms of the expat license, see the file EXPAT.
+-->
+
+<body>
+    <div id="wrap">
+        <form id="search_bar" name="search_bar" action="{search_uri}" method="get">
+            <input type="text" name="q" value="{search_title}" onfocus="javascript:this.value='';"
+                onblur="javascript:if(this.value=='') this.value='{search_title}';" />
+            <button>{search}</button>
+        </form>
+    <div class="shortcut top" id="s1">
+        <a href="#" onclick="javascript:return getAction('s1');">
+            <h1>1</h1><h4><span/></h4>
+        </a>
+        <p> </p>
+    </div>
+    <div class="shortcut top" id="s2">
+        <a href="#" onclick="javascript:return getAction('s2');">
+            <h1>2</h1><h4><span/></h4>
+        </a>
+        <p> </p>
+    </div>
+    <div class="shortcut top right" id="s3">
+        <a href="#" onclick="javascript:return getAction('s3');">
+            <h1>3</h1><h4><span/></h4>
+        </a>
+        <p> </p>
+    </div>
+    <div class="shortcut" id="s4">
+        <a href="#" onclick="javascript:return getAction('s4');">
+            <h1>4</h1><h4><span/></h4>
+        </a>
+        <p> </p>
+    </div>
+    <div class="shortcut" id="s5">
+        <a href="#" onclick="javascript:return getAction('s5');">
+            <h1>5</h1><h4><span/></h4>
+        </a>
+        <p> </p>
+    </div>
+    <div class="shortcut right" id="s6">
+        <a href="#" onclick="javascript:return getAction('s6');">
+            <h1>6</h1><h4><span/></h4>
+        </a>
+        <p> </p>
+    </div>
+    <div class="shortcut" id="s7">
+        <a href="#" onclick="javascript:return getAction('s7');">
+            <h1>7</h1><h4><span/></h4>
+        </a>
+        <p> </p>
+    </div>
+    <div class="shortcut" id="s8">
+        <a href="#" onclick="javascript:return getAction('s8');">
+            <h1>8</h1><h4><span/></h4>
+        </a>
+        <p> </p>
+    </div>
+        <div class="shortcut right" id="s9">
+            <a href="#" onclick="javascript:return getAction('s9');">
+                <h1>9</h1><h4><span/></h4>
+            </a>
+            <p> </p>
+        </div>
+    </div>
+    <div class="clear"></div>
+</body>
+</html>
diff --git a/data/speeddial-head.html b/data/speeddial-head.html
new file mode 100644 (file)
index 0000000..22f3924
--- /dev/null
@@ -0,0 +1,231 @@
+<!--
+ Speed Dial head template for Midori.
+ Copyright (C) 2009 Jean-François Guchens <zcx000@gmail.com>
+ This file is licensed under the terms of the expat license, see the file EXPAT.
+-->
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+  <head>
+    <title>{title}</title>
+    <script type="text/javascript" src="{res}/mootools.js"></script>
+
+    <style>
+    body {
+        text-align: center;
+        background-color: #fefefe;
+        font-family: sans-serif;
+    }
+
+    #wrap {
+        width: 660px;
+        height: 570px;
+        margin: 0px auto;
+        text-align: center;
+    }
+
+    div.shortcut {
+        float: left;
+        border: 1px solid #ccc;
+        position: relative;
+        width: 200px;
+        height: 150px;
+        margin: 25px 25px 0px 0px;
+        background-color: #fff;
+        -webkit-border-radius: 10px;
+    }
+
+    div.right {
+        margin-right: 0px;
+        margin-left: 0px;
+    }
+
+    div.top {
+        margin-top: 0px;
+    }
+
+    h1 {
+        font-size: 50px;
+        font-weight: bold;
+        margin: 0px;
+        height: 30px;
+        padding: 10px 0px 0px 0px;
+        display: block;
+    }
+
+    h4 {
+        font-size: 11px;
+        font-weight: bold
+        margin: 10px 0px 0px 0px;
+        padding: 10px 5px 0px;
+        display: block;
+    }
+
+    h4 span:before {
+        content: "{click_to_add}";
+        font-size: 11px;
+    }
+
+    h4 span {
+        font-size: 11px;
+    }
+
+    div.shortcut a {
+        border: 1px solid #ccc;
+        display: block;
+        width: 160px;
+        height: 107px;
+        margin: 15px auto 0px;
+        background-color: #fafafa;
+        color: #aaa;
+        text-decoration: none;
+    }
+
+    .waiter img {
+        margin-top: 38px;
+    }
+
+    div.shortcut a:hover {
+        border: 1px solid #999;
+    }
+
+    div.shortcut p {
+        font-size: 12px;
+        margin: 0px;
+        padding: 5px 0px 0px;
+        color: #222;
+    }
+
+    #search_bar {
+        margin: 20px 0px 20px;
+    }
+
+    div.clear {
+        clear: both;
+    }
+
+    input[type=text] {
+        color: #ddd;
+    }
+
+    input[type=text]:active, input[type=text]:focus {
+        color: #222;
+    }
+
+    div.activated {
+        background-color: #f5f5f5;
+    }
+
+    .cross {
+        -webkit-border-radius: 7px;
+        background-color: #ddd;
+        height: 15px;
+        width: 15px;
+        font-size: 11px;
+        font-weight: bolder;
+        font-family: sans-serif;
+        margin-bottom: -17px;
+        margin-left: 183px;
+        margin-top: 2px;
+        text-align: center;
+        color: #fff;
+        cursor: pointer;
+        z-index: -4;
+    }
+
+    .cross:hover {
+        background-color: #ff7575;
+    }
+
+    .activated p {
+        cursor: text;
+    }
+    </style>
+
+    <script type="text/javascript">
+    var getAction = function (id)
+    {
+
+        var a = $(id).getFirst ();
+        if (a.getProperty ('href') != "#" )
+            return true;
+
+        var url = prompt ("{enter_shortcut_address}", "http://");
+        if (!url) return false;
+
+        var name = prompt ("{enter_shortcut_name}", "");
+        if (!name) name = "";
+
+        a.setProperty('href', url);
+        a.getNext().set('text', name);
+
+        a.empty();
+        var im = new Element('img', { src: '{stock}/throbber.gif' });
+
+        a.addClass ('waiter');
+        a.grab (im);
+
+        getThumbnail (id, url);
+        return false;
+    }
+
+    var getThumbnail = function (id, url)
+    {
+        console.log ("speeddial-get-thumbnail " + id + " " + url);
+        return false;
+    }
+
+    var setThumbnail = function (id, data, href)
+    {
+        var a = $(id).getFirst ();
+        var im = new Element ('img', { src: 'data:image/png;base64,' + data });
+
+        a.empty ().removeClass ('waiter').grab (im);
+        a.setProperty ('href', href);
+
+        var cross = new Element ('div', { 'html': 'x' });
+        cross.setProperty ('onclick', 'clearShortcut("' + id + '");');
+        cross.addClass ('cross');
+        cross.inject ($(id), 'top');
+
+        $(id).addClass ('activated');
+
+        var p = a.getNext();
+        p.setProperty('onclick', 'javascript:rename_shortcut("' + id + '");');
+    }
+
+    var rename_shortcut = function (id)
+    {
+        var name = prompt ("{enter_shortcut_name}", "");
+        if (!name) return;
+
+        $(id).getLast ().set ('html', name);
+    }
+
+    var clearShortcut = function (id)
+    {
+        if(!confirm("{are_you_sure}"))
+            return;
+
+        var num = id.charAt (1);
+        var sc = $(id);
+        var cross = sc.getFirst ();
+        var a = cross.getNext ();
+        var p = a.getNext ();
+
+        cross.dispose ();
+        sc.removeClass ('activated');
+        a.empty ();
+
+        cross.dispose ();
+        sc.removeClass ('activated');
+        a.empty ().set ('html', '<h1>' + num + '</h1><h4><span/></h4>');
+        a.setProperty ('href', '#');
+        p.empty ().removeProperty ('onclick');
+
+        console.log ("speeddial-save");
+    }
+
+    </script>
+</head>
+
diff --git a/data/tandoori-body.html b/data/tandoori-body.html
deleted file mode 100644 (file)
index a99f3da..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-<!--
- Speed Dial head template for Midori.
- Copyright (C) 2009 Jean-François Guchens <zcx000@gmail.com>
- This file is licensed under the terms of the expat license, see the file EXPAT.
--->
-
-<body>
-    <div id="wrap">
-        <form id="search_bar" name="search_bar" action="{search_uri}" method="get">
-            <input type="text" name="q" value="{search_title}" onfocus="javascript:this.value='';"
-                onblur="javascript:if(this.value=='') this.value='{search_title}';" />
-            <button>{search}</button>
-        </form>
-    <div class="shortcut top" id="s1">
-        <a href="#" onclick="javascript:return getAction('s1');">
-            <h1>1</h1><h4><span/></h4>
-        </a>
-        <p> </p>
-    </div>
-    <div class="shortcut top" id="s2">
-        <a href="#" onclick="javascript:return getAction('s2');">
-            <h1>2</h1><h4><span/></h4>
-        </a>
-        <p> </p>
-    </div>
-    <div class="shortcut top right" id="s3">
-        <a href="#" onclick="javascript:return getAction('s3');">
-            <h1>3</h1><h4><span/></h4>
-        </a>
-        <p> </p>
-    </div>
-    <div class="shortcut" id="s4">
-        <a href="#" onclick="javascript:return getAction('s4');">
-            <h1>4</h1><h4><span/></h4>
-        </a>
-        <p> </p>
-    </div>
-    <div class="shortcut" id="s5">
-        <a href="#" onclick="javascript:return getAction('s5');">
-            <h1>5</h1><h4><span/></h4>
-        </a>
-        <p> </p>
-    </div>
-    <div class="shortcut right" id="s6">
-        <a href="#" onclick="javascript:return getAction('s6');">
-            <h1>6</h1><h4><span/></h4>
-        </a>
-        <p> </p>
-    </div>
-    <div class="shortcut" id="s7">
-        <a href="#" onclick="javascript:return getAction('s7');">
-            <h1>7</h1><h4><span/></h4>
-        </a>
-        <p> </p>
-    </div>
-    <div class="shortcut" id="s8">
-        <a href="#" onclick="javascript:return getAction('s8');">
-            <h1>8</h1><h4><span/></h4>
-        </a>
-        <p> </p>
-    </div>
-        <div class="shortcut right" id="s9">
-            <a href="#" onclick="javascript:return getAction('s9');">
-                <h1>9</h1><h4><span/></h4>
-            </a>
-            <p> </p>
-        </div>
-    </div>
-    <div class="clear" />
-</body>
-</html>
diff --git a/data/tandoori-head.html b/data/tandoori-head.html
deleted file mode 100644 (file)
index e1051b7..0000000
+++ /dev/null
@@ -1,216 +0,0 @@
-<!--
- Speed Dial head template for Midori.
- Copyright (C) 2009 Jean-François Guchens <zcx000@gmail.com>
- This file is licensed under the terms of the expat license, see the file EXPAT.
--->
-
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-  <head>
-    <title>{title}</title>
-    <script type="text/javascript" src="{res}/mootools.js"></script>
-    <style>
-    body {
-        text-align: center;
-        background-color: #fefefe;
-        font-family: sans-serif;
-    }
-
-    #wrap {
-        width: 660px;
-        height: 570px;
-        margin: 0px auto;
-        text-align: center;
-    }
-
-    div.shortcut {
-        float: left;
-        border: 1px solid #ccc;
-        position: relative;
-        width: 200px;
-        height: 150px;
-        margin: 25px 25px 0px 0px;
-        background-color: #fff;
-        -webkit-border-radius: 10px;
-    }
-
-    div.right {
-        margin-right: 0px;
-        margin-left: 0px;
-    }
-
-    div.top {
-        margin-top: 0px;
-    }
-
-    h1 {
-        font-size: 50px;
-        font-weight: bold;
-        margin: 0px;
-        height: 30px;
-        padding: 10px 0px 0px 0px;
-        display: block;
-    }
-
-    h4 {
-        font-size: 11px;
-        font-weight: bold
-        margin: 10px 0px 0px 0px;
-        padding: 10px 5px 0px;
-        display: block;
-    }
-
-    h4 span:before {
-        content: "{click_to_add}";
-        font-size: 11px;
-    }
-
-    h4 span {
-        font-size: 11px;
-    }
-
-
-    div.shortcut a {
-        border: 1px solid #ccc;
-        display: block;
-        width: 160px;
-        height: 107px;
-        margin: 15px auto 0px;
-        background-color: #fafafa;
-        color: #aaa;
-        text-decoration: none;
-    }
-
-    .waiter img {
-        margin-top: 38px;
-    }
-
-    div.shortcut a:hover {
-        border: 1px solid #999;
-    }
-
-    div.shortcut p {
-        font-size: 12px;
-        margin: 0px;
-        padding: 5px 0px 0px;
-        color: #222;
-    }
-
-    #search_bar {
-        margin: 20px 0px 20px;
-    }
-
-    div.clear {
-        clear: both;
-    }
-
-    input[type=text] {
-        color: #ddd;
-    }
-
-    input[type=text]:active, input[type=text]:focus {
-        color: #222;
-    }
-
-    div.activated {
-        background-color: #f5f5f5;
-    }
-
-    .cross {
-        -webkit-border-radius: 7px;
-        background-color: #ddd;
-        height: 15px;
-        width: 15px;
-        font-size: 11px;
-        font-weight: bolder;
-        font-family: sans-serif;
-        margin-bottom: -17px;
-        margin-left: 183px;
-        margin-top: 2px;
-        text-align: center;
-        color: #fff;
-        cursor: pointer;
-        z-index: -4;
-    }
-
-    .cross:hover {
-        background-color: #ff7575;
-    }
-    </style>
-
-    <script type="text/javascript">
-    var getAction = function (id)
-    {
-
-        var a = $(id).getFirst ();
-        if (a.getProperty ('href') != "#" )
-            return true;
-
-        var url = prompt ("{enter_shortcut_address}", "http://");
-        if (!url) return false;
-
-        var name = prompt ("{enter_shortcut_name}", "");
-        if (!name) name = "";
-
-        a.setProperty('href', url);
-        a.getNext().set('text', name);
-
-        a.empty();
-        var im = new Element('img', { src: '{stock}/throbber.gif' });
-
-        a.addClass ('waiter');
-        a.grab (im);
-
-        getThumbnail (id, url);
-        return false;
-    }
-
-    var getThumbnail = function (id, url)
-    {
-        console.log ("tandoori-get-thumbnail "+ id +" "+ url);
-        return false;
-    }
-
-    var setThumbnail = function (id, data, href)
-    {
-        var a = $(id).getFirst ();
-        var im = new Element ('img', { src: 'data:image/png;base64,' + data });
-
-        a.empty ().removeClass ('waiter').grab (im);
-        a.setProperty ('href', href);
-
-        var cross = new Element ('div', { 'html': 'x' });
-            cross.setProperty ('onclick', 'clearShortcut("' + id + '");');
-            cross.addClass ('cross');
-            cross.inject ($(id), 'top');
-            $(id).addClass ('activated');
-    }
-
-
-    var clearShortcut = function (id)
-    {
-        if(!confirm("{are_you_sure}"))
-            return;
-
-        var num = id.charAt (1);
-        var sc = $(id);
-        var cross = sc.getFirst ();
-        var a = cross.getNext ();
-        var p = a.getNext ();
-
-        cross.dispose ();
-        sc.removeClass ('activated');
-        a.empty ();
-
-        cross.dispose ();
-        sc.removeClass ('activated');
-        a.empty ().set ('html', '<h1>' + num + '</h1><h4><span/></h4>');
-        a.setProperty ('href', '#');
-        p.empty ();
-
-        console.log ("tandoori-save");
-    }
-
-    </script>
-</head>
-
index 9649a45579f6f2ee557c0e9c275237d7ee947b9e..b4a9f3f17b2def21cee013b5102254a16d4bafee 100644 (file)
@@ -179,14 +179,15 @@ midori_view_settings_notify_cb (MidoriWebSettings* settings,
                                 MidoriView*        view);
 
 static void
-midori_view_tandoori_get_thumb (GtkWidget*   web_view,
-                                const gchar* message,
-                                MidoriView*  view);
-
+midori_view_speeddial_get_thumb (GtkWidget*   web_view,
+                                 const gchar* message,
+                                 MidoriView*  view);
 
 static void
-midori_view_tandoori_save (GtkWidget* web_view);
+midori_view_speeddial_save (GtkWidget* web_view);
 
+static gchar*
+midori_view_speeddial_get_next_free_slot (void);
 
 static void
 midori_view_class_init (MidoriViewClass* class)
@@ -969,6 +970,99 @@ midori_web_view_menu_new_tab_activate_cb (GtkWidget*  widget,
         view->open_tabs_in_the_background);
 }
 
+static void
+midori_web_view_menu_action_add_speeddial_cb (GtkWidget*  widget,
+                                              MidoriView* view)
+{
+    gchar* folder;
+    gchar* thumb;
+    gchar* filename;
+    gchar* replace_from;
+    gchar* replace_by;
+    /*gchar* uri = g_strdup (webkit_web_frame_get_uri (
+        webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (view->web_view))));
+    gchar* title = g_strdup (webkit_web_frame_get_title (
+                            webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (view->web_view))));*/
+    gchar* uri = g_strdup (view->uri);
+    gchar* title = g_strdup (view->title);
+    gchar* slot_id = midori_view_speeddial_get_next_free_slot ();
+
+    if (slot_id == NULL)
+    {
+        g_free (uri);
+        g_free (title);
+        return;
+    }
+
+    if (strlen (title) > 15)
+    {
+        gchar* stripped = g_strndup (title, 15 * sizeof (gchar));
+        g_free (title);
+        title = g_strdup_printf ("%s...", stripped);
+        g_free  (stripped);
+    }
+
+    folder = g_build_filename (g_get_user_cache_dir (), PACKAGE_NAME, "thumbs", NULL);
+    thumb = g_compute_checksum_for_string (G_CHECKSUM_MD5, uri, -1);
+    filename = g_build_filename (folder, thumb, NULL);
+
+    if (g_file_test (filename, G_FILE_TEST_EXISTS))
+    {
+        GdkPixbuf* img;
+        GRegex* regex;
+        gchar* replace;
+        gchar* file_content;
+        gchar* encoded;
+        gchar* speeddial_body;
+        gchar* t_body_fname;
+        gsize sz;
+
+        t_body_fname = g_strdup_printf ("%s%s", g_get_user_config_dir (),
+                                        "/midori/speeddial-body.html");
+
+        g_file_get_contents (t_body_fname, &speeddial_body, NULL, NULL);
+
+        img = gdk_pixbuf_new_from_file_at_scale (filename, 160, 107, FALSE, NULL);
+        gdk_pixbuf_save_to_buffer (img, &file_content, &sz, "png", NULL, NULL);
+        encoded = g_base64_encode ((guchar *)file_content, sz);
+
+        replace_from = g_strdup_printf (
+            "<div class=\"(.+)\" id=\"%s\">[ \r\n\t]*"\
+            "<a href=\"#\" onclick=\""\
+            "javascript:return getAction\\('%s'\\);\".*>[ \r\n\t]*<h1>"\
+            "%s</h1><h4>.+</h4>[ \r\n\t]*</a>[ \r\n\t]*<p>[ ]*</p>[ \r\t\n]*</div>",
+                slot_id, slot_id, (slot_id+1));
+
+        replace_by = g_strdup_printf (
+            "<div class=\"\\1 activated\" id=\"%s\">"\
+            "<div onclick=\"clearShortcut"\
+            "('%s');\" class=\"cross\">x</div><a href=\"%s\" onclick="\
+            "\"javascript:return getAction('%s');\"><img src="\
+            "\"data:image/png;base64,%s\" /></a><p onclick="\
+            "\"javascript:rename_shortcut('%s');\">%s</p></div>",
+                slot_id, slot_id, uri, slot_id, encoded, slot_id, title);
+
+        regex = g_regex_new (replace_from, G_REGEX_MULTILINE, 0, NULL);
+        replace = g_regex_replace (regex, speeddial_body, -1,
+                                   1, replace_by, 0, NULL);
+
+        g_file_set_contents (t_body_fname, replace, -1, NULL);
+
+        g_object_unref (img);
+        g_regex_unref (regex);
+        g_free (encoded);
+        g_free (file_content);
+        g_free (t_body_fname);
+        g_free (speeddial_body);
+        g_free (replace_by);
+        g_free (replace_from);
+        g_free (replace);
+    }
+
+    g_free (thumb);
+    g_free (filename);
+}
+
 static void
 midori_web_view_menu_new_window_activate_cb (GtkWidget*  widget,
                                              MidoriView* view)
@@ -1212,15 +1306,26 @@ webkit_web_view_populate_popup_cb (WebKitWebView* web_view,
             G_CALLBACK (midori_web_view_menu_action_activate_cb), view);
         /* FIXME: Make this sensitive only when there is a tab to undo */
         gtk_widget_show (menuitem);
+
         menuitem = gtk_separator_menu_item_new ();
         gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
         gtk_widget_show (menuitem);
+
         menuitem = gtk_image_menu_item_new_from_stock (STOCK_BOOKMARK_ADD, NULL);
         gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
         g_object_set_data (G_OBJECT (menuitem), "action", "BookmarkAdd");
         g_signal_connect (menuitem, "activate",
             G_CALLBACK (midori_web_view_menu_action_activate_cb), view);
         gtk_widget_show (menuitem);
+
+        /* FIXME: This should be a proper action in the browser */
+        menuitem = gtk_image_menu_item_new_with_mnemonic (_("Add to customized homepage"));
+        gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
+        g_object_set_data (G_OBJECT (menuitem), "action", "AddSpeeddial");
+        g_signal_connect (menuitem, "activate",
+            G_CALLBACK (midori_web_view_menu_action_add_speeddial_cb), view);
+        gtk_widget_show (menuitem);
+
         menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
         gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
         g_object_set_data (G_OBJECT (menuitem), "action", "SaveAs");
@@ -1231,6 +1336,7 @@ webkit_web_view_populate_popup_cb (WebKitWebView* web_view,
            saving either. If that changes, we need to think of something. */
         if (!midori_view_can_view_source (view))
             gtk_widget_set_sensitive (menuitem, FALSE);
+
         menuitem = gtk_image_menu_item_new_with_mnemonic (_("View _Source"));
         gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
         g_object_set_data (G_OBJECT (menuitem), "action", "SourceView");
@@ -1239,6 +1345,7 @@ webkit_web_view_populate_popup_cb (WebKitWebView* web_view,
         gtk_widget_show (menuitem);
         if (!midori_view_can_view_source (view))
             gtk_widget_set_sensitive (menuitem, FALSE);
+
         menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_PRINT, NULL);
         gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
         g_object_set_data (G_OBJECT (menuitem), "action", "Print");
@@ -1425,10 +1532,10 @@ webkit_web_view_console_message_cb (GtkWidget*   web_view,
                                     const gchar* source_id,
                                     MidoriView*  view)
 {
-    if (!strncmp (message, "tandoori-get-thumbnail", 22))
-        midori_view_tandoori_get_thumb (web_view, message, view);
-    else if (!strncmp (message, "tandoori-save", 13))
-        midori_view_tandoori_save (web_view);
+    if (!strncmp (message, "speeddial-get-thumbnail", 22))
+        midori_view_speeddial_get_thumb (web_view, message, view);
+    else if (!strncmp (message, "speeddial-save", 13))
+        midori_view_speeddial_save (web_view);
     else
         g_signal_emit (view, signals[CONSOLE_MESSAGE], 0, message, line, source_id);
     return TRUE;
@@ -1918,36 +2025,36 @@ midori_view_set_uri (MidoriView*  view,
             SoupServer* res_server;
             guint port;
             gchar* res_root;
-            gchar* tandoori_head;
-            gchar* tandoori_body;
-            gchar* tandoori_html;
+            gchar* speeddial_head;
+            gchar* speeddial_body;
+            gchar* speeddial_html;
             gchar* t_body_fname;
             gchar* location_entry_search;
 
             katze_assign (view->uri, g_strdup (""));
 
-            g_file_get_contents (DATADIR "/midori/res/tandoori-head.html",
-                                 &tandoori_head, NULL, NULL);
+            g_file_get_contents (DATADIR "/midori/res/speeddial-head.html",
+                                 &speeddial_head, NULL, NULL);
 
             res_server = sokoke_get_res_server ();
             port = soup_server_get_port (res_server);
             res_root = g_strdup_printf ("http://localhost:%d/res", port);
             t_body_fname = g_strconcat (g_get_user_config_dir (),
-                                        "/midori/tandoori-body.html", NULL);
+                                        "/midori/speeddial-body.html", NULL);
 
             if (!g_file_test (t_body_fname, G_FILE_TEST_EXISTS))
             {
-                g_file_get_contents (DATADIR "/midori/res/tandoori-body.html",
-                                     &tandoori_body, NULL, NULL );
-                g_file_set_contents (t_body_fname, tandoori_body, -1, NULL );
+                g_file_get_contents (DATADIR "/midori/res/speeddial-body.html",
+                                     &speeddial_body, NULL, NULL );
+                g_file_set_contents (t_body_fname, speeddial_body, -1, NULL );
             }
             else
-                g_file_get_contents (t_body_fname, &tandoori_body, NULL, NULL);
+                g_file_get_contents (t_body_fname, &speeddial_body, NULL, NULL);
 
-            tandoori_html = g_strconcat (tandoori_head, tandoori_body, NULL);
+            speeddial_html = g_strconcat (speeddial_head, speeddial_body, NULL);
             g_object_get (view->settings, "location-entry-search",
                           &location_entry_search, NULL);
-            data = sokoke_replace_variables (tandoori_html,
+            data = sokoke_replace_variables (speeddial_html,
                 "{res}", res_root,
                 "{title}", _("Blank page"),
                 "{search_uri}", &location_entry_search,
@@ -1970,9 +2077,9 @@ midori_view_set_uri (MidoriView*  view,
 
             g_free (res_root);
             g_free (data);
-            g_free (tandoori_html);
-            g_free (tandoori_head);
-            g_free (tandoori_body);
+            g_free (speeddial_html);
+            g_free (speeddial_head);
+            g_free (speeddial_body);
             g_free (t_body_fname);
         }
         /* This is not prefectly elegant, but creating an
@@ -2858,9 +2965,17 @@ midori_view_execute_script (MidoriView*  view,
     return TRUE;
 }
 
+
+/**
+ * midori_view_speeddial_inject_thumb
+ * @view: a #MidoriView
+ * @filename: filename of the thumbnail
+ * @dom_id: Id of the shortcut on speeddial page in wich to inject content
+ * @url: url of the shortcut
+ */
 static void
-midori_view_tandoori_inject_thumb (MidoriView* view,
-                                   gchar*      filename,
+midori_view_speeddial_inject_thumb (MidoriView* view,
+                                   gchar*     filename,
                                    gchar*     dom_id,
                                    gchar*     url)
 {
@@ -2877,13 +2992,13 @@ midori_view_tandoori_inject_thumb (MidoriView* view,
     gdk_pixbuf_save_to_buffer (img, &file_content, &sz, "png", NULL, NULL);
     encoded = g_base64_encode ( (guchar *)file_content, sz );
 
-    /** Call Javascript function to replace shortcut content **/
+    /* Call Javascript function to replace shortcut's content */
     js = g_strdup_printf ("setThumbnail('%s','%s','%s');", dom_id, encoded, url);
     webkit_web_view_execute_script (WEBKIT_WEB_VIEW (view->web_view), js);
     free (js);
     g_object_unref (img);
 
-    midori_view_tandoori_save (view->web_view);
+    midori_view_speeddial_save (view->web_view);
 
     g_free (url);
     g_free (dom_id);
@@ -2891,16 +3006,21 @@ midori_view_tandoori_inject_thumb (MidoriView* view,
     g_free (file_content);
 }
 
+
 /**
- * midori_view_tandoori_save
+ * midori_view_speeddial_save
  * @web_view: a #WebkitView
  * @message: Console log data
  *
- * Load a thumbnail, and sets the DOM
+ * Load a thumbnail, and set the DOM
+ *
+ * message[0] == console message call
+ * message[1] == shortcut id in the DOM
+ * message[2] == shortcut uri
  *
  **/
 static void
-midori_view_tandoori_get_thumb (GtkWidget*   web_view,
+midori_view_speeddial_get_thumb (GtkWidget*   web_view,
                                 const gchar* message,
                                 MidoriView*  view)
 {
@@ -2909,35 +3029,75 @@ midori_view_tandoori_get_thumb (GtkWidget*   web_view,
     gchar* filename;
     gchar** t_data = g_strsplit (message," ", 4);
 
-    /* t_data[1] = div id and t_data[2] = shortcut's url */
     if (t_data[1] == NULL || t_data[2] == NULL )
         return;
 
-    folder = g_build_filename (g_get_user_cache_dir (), PACKAGE_NAME, "thumbs", NULL);
+    folder = g_build_filename (g_get_user_cache_dir (), PACKAGE_NAME,
+                               "thumbs", NULL);
     thumb = g_compute_checksum_for_string (G_CHECKSUM_MD5, t_data[2], -1);
     filename = g_build_filename (folder, thumb, NULL);
     g_free (thumb);
 
-    midori_view_tandoori_inject_thumb (view, filename,
+    midori_view_speeddial_inject_thumb (view, filename,
         g_strdup (t_data[1]), g_strdup (t_data[2]));
     g_strfreev (t_data);
 }
 
+
+/**
+ * midori_view_speeddial_get_next_free_slot
+ *
+ * Returns: Id of the next shortcut slot on the speeddial page
+ */
+static gchar*
+midori_view_speeddial_get_next_free_slot (void)
+{
+    gchar* speeddial_body;
+    gchar* body_fname;
+    gchar* slot_id = NULL;
+    gchar* p = NULL;
+
+    body_fname = g_strdup_printf ("%s%s", g_get_user_config_dir (),
+                                  "/midori/speeddial-body.html");
+    if (!g_file_test (body_fname, G_FILE_TEST_EXISTS))
+    {
+        g_file_get_contents (DATADIR "/midori/res/speeddial-body.html",
+                             &speeddial_body, NULL, NULL);
+        g_file_set_contents (body_fname, speeddial_body, -1, NULL);
+    }
+    else
+        g_file_get_contents (body_fname, &speeddial_body, NULL, NULL);
+
+    p = g_strstr_len (speeddial_body, -1, "<h1>");
+
+    if (p != NULL)
+    {
+        p = g_strndup ((p+4), 1);
+        slot_id = g_strdup_printf ("s%s", p);
+        g_free (p);
+    }
+
+    g_free (body_fname);
+    g_free (speeddial_body);
+
+    return slot_id;
+}
+
 /**
- * midori_view_tandoori_save
+ * midori_view_speeddial_save
  * @web_view: a #WebkitView
  *
- * Save tandoori DOM structure to body template
+ * Save speeddial DOM structure to body template
  *
  **/
 static void
-midori_view_tandoori_save (GtkWidget*    web_view)
+midori_view_speeddial_save (GtkWidget*    web_view)
 {
     JSContextRef js_context = webkit_web_frame_get_global_context (
         webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view)));
     gchar* newdom = sokoke_js_script_eval (js_context,"document.body.innerHTML", NULL);
-    gchar* fname = g_strconcat (g_get_user_config_dir (), "/midori/tandoori-body.html", NULL);
-    g_file_set_contents ( fname, newdom, -1, NULL );
+    gchar* fname = g_strconcat (g_get_user_config_dir (), "/midori/speeddial-body.html", NULL);
+    g_file_set_contents (fname, newdom, -1, NULL);
     g_free (fname);
     g_free (newdom);
 }
diff --git a/wscript b/wscript
index c05f05060cd90915280d0625592ab921ea52846e..4fcb61c90aa7d85d48e3f1edfe2d0dcecdb6819c 100644 (file)
--- a/wscript
+++ b/wscript
@@ -339,8 +339,8 @@ def build (bld):
         else:
             Utils.pprint ('BLUE', "logo-shade could not be rasterized.")
     bld.install_files ('${DATADIR}/' + APPNAME + '/res', 'data/error.html')
-    bld.install_files ('${DATADIR}/' + APPNAME + '/res', 'data/tandoori-head.html')
-    bld.install_files ('${DATADIR}/' + APPNAME + '/res', 'data/tandoori-body.html')
+    bld.install_files ('${DATADIR}/' + APPNAME + '/res', 'data/speeddial-head.html')
+    bld.install_files ('${DATADIR}/' + APPNAME + '/res', 'data/speeddial-body.html')
     bld.install_files ('${DATADIR}/' + APPNAME + '/res', 'data/mootools.js')
 
     if Options.commands['check']: