Fix the search in the custom homepage and optimize the saving
This commit is contained in:
parent
5916815daf
commit
2e250b66e8
3 changed files with 52 additions and 30 deletions
|
@ -3,14 +3,7 @@
|
||||||
Copyright (C) 2009 Jean-François Guchens <zcx000@gmail.com>
|
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.
|
This file is licensed under the terms of the expat license, see the file EXPAT.
|
||||||
-->
|
-->
|
||||||
|
<div id="content">
|
||||||
<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">
|
<div class="shortcut top" id="s1">
|
||||||
<a href="#" onclick="javascript:return getAction('s1');">
|
<a href="#" onclick="javascript:return getAction('s1');">
|
||||||
<h1>1</h1><h4><span/></h4>
|
<h1>1</h1><h4><span/></h4>
|
||||||
|
@ -65,7 +58,8 @@
|
||||||
</a>
|
</a>
|
||||||
<p> </p>
|
<p> </p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div> <!-- #wrap -->
|
||||||
<div class="clear"></div>
|
<div class="clear"></div>
|
||||||
|
</div> <!-- #content -->
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -200,6 +200,8 @@
|
||||||
if (!name) return;
|
if (!name) return;
|
||||||
|
|
||||||
$(id).getLast ().set ('html', name);
|
$(id).getLast ().set ('html', name);
|
||||||
|
|
||||||
|
console.log ("speeddial-save");
|
||||||
}
|
}
|
||||||
|
|
||||||
var clearShortcut = function (id)
|
var clearShortcut = function (id)
|
||||||
|
@ -226,6 +228,29 @@
|
||||||
console.log ("speeddial-save");
|
console.log ("speeddial-save");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var speeddialSearch = function ()
|
||||||
|
{
|
||||||
|
var reg = new RegExp("%s", "g");
|
||||||
|
var search_url = $('search_bar').getProperty ('action');
|
||||||
|
var search_content = $('search_bar').getFirst ().get ('value');
|
||||||
|
window.location.href = search_url.replace (reg, encodeURIComponent (search_content));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var getSpeeddialContent = function()
|
||||||
|
{
|
||||||
|
var content = $('content').get ('html');
|
||||||
|
return '<div id="content">' + content + '</div></div></body></html>';
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="wrap">
|
||||||
|
<form id="search_bar" name="search_bar" action="{search_uri}"
|
||||||
|
method="get" onsubmit="javascript:return speeddialSearch();">
|
||||||
|
<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>
|
||||||
|
|
||||||
|
|
|
@ -1014,13 +1014,13 @@ midori_web_view_menu_action_add_speeddial_cb (GtkWidget* widget,
|
||||||
gchar* file_content;
|
gchar* file_content;
|
||||||
gchar* encoded;
|
gchar* encoded;
|
||||||
gchar* speeddial_body;
|
gchar* speeddial_body;
|
||||||
gchar* t_body_fname;
|
gchar* body_fname;
|
||||||
gsize sz;
|
gsize sz;
|
||||||
|
|
||||||
t_body_fname = g_strdup_printf ("%s%s", g_get_user_config_dir (),
|
body_fname = g_strconcat (g_get_user_config_dir (),
|
||||||
"/midori/speeddial-body.html");
|
"/midori/speeddial-body.html", NULL);
|
||||||
|
|
||||||
g_file_get_contents (t_body_fname, &speeddial_body, NULL, NULL);
|
g_file_get_contents (body_fname, &speeddial_body, NULL, NULL);
|
||||||
|
|
||||||
img = gdk_pixbuf_new_from_file_at_scale (filename, 160, 107, FALSE, 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);
|
gdk_pixbuf_save_to_buffer (img, &file_content, &sz, "png", NULL, NULL);
|
||||||
|
@ -1046,13 +1046,13 @@ midori_web_view_menu_action_add_speeddial_cb (GtkWidget* widget,
|
||||||
replace = g_regex_replace (regex, speeddial_body, -1,
|
replace = g_regex_replace (regex, speeddial_body, -1,
|
||||||
1, replace_by, 0, NULL);
|
1, replace_by, 0, NULL);
|
||||||
|
|
||||||
g_file_set_contents (t_body_fname, replace, -1, NULL);
|
g_file_set_contents (body_fname, replace, -1, NULL);
|
||||||
|
|
||||||
g_object_unref (img);
|
g_object_unref (img);
|
||||||
g_regex_unref (regex);
|
g_regex_unref (regex);
|
||||||
g_free (encoded);
|
g_free (encoded);
|
||||||
g_free (file_content);
|
g_free (file_content);
|
||||||
g_free (t_body_fname);
|
g_free (body_fname);
|
||||||
g_free (speeddial_body);
|
g_free (speeddial_body);
|
||||||
g_free (replace_by);
|
g_free (replace_by);
|
||||||
g_free (replace_from);
|
g_free (replace_from);
|
||||||
|
@ -2028,7 +2028,7 @@ midori_view_set_uri (MidoriView* view,
|
||||||
gchar* speeddial_head;
|
gchar* speeddial_head;
|
||||||
gchar* speeddial_body;
|
gchar* speeddial_body;
|
||||||
gchar* speeddial_html;
|
gchar* speeddial_html;
|
||||||
gchar* t_body_fname;
|
gchar* body_fname;
|
||||||
gchar* location_entry_search;
|
gchar* location_entry_search;
|
||||||
|
|
||||||
katze_assign (view->uri, g_strdup (""));
|
katze_assign (view->uri, g_strdup (""));
|
||||||
|
@ -2039,32 +2039,34 @@ midori_view_set_uri (MidoriView* view,
|
||||||
res_server = sokoke_get_res_server ();
|
res_server = sokoke_get_res_server ();
|
||||||
port = soup_server_get_port (res_server);
|
port = soup_server_get_port (res_server);
|
||||||
res_root = g_strdup_printf ("http://localhost:%d/res", port);
|
res_root = g_strdup_printf ("http://localhost:%d/res", port);
|
||||||
t_body_fname = g_strconcat (g_get_user_config_dir (),
|
body_fname = g_strconcat (g_get_user_config_dir (),
|
||||||
"/midori/speeddial-body.html", NULL);
|
"/midori/speeddial-body.html", NULL);
|
||||||
|
|
||||||
if (!g_file_test (t_body_fname, G_FILE_TEST_EXISTS))
|
if (!g_file_test (body_fname, G_FILE_TEST_EXISTS))
|
||||||
{
|
{
|
||||||
g_file_get_contents (DATADIR "/midori/res/speeddial-body.html",
|
g_file_get_contents (DATADIR "/midori/res/speeddial-body.html",
|
||||||
&speeddial_body, NULL, NULL );
|
&speeddial_body, NULL, NULL );
|
||||||
g_file_set_contents (t_body_fname, speeddial_body, -1, NULL );
|
g_file_set_contents (body_fname, speeddial_body, -1, NULL );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
g_file_get_contents (t_body_fname, &speeddial_body, NULL, NULL);
|
g_file_get_contents (body_fname, &speeddial_body, NULL, NULL);
|
||||||
|
|
||||||
speeddial_html = g_strconcat (speeddial_head, speeddial_body, NULL);
|
speeddial_html = g_strconcat (speeddial_head, speeddial_body, NULL);
|
||||||
|
|
||||||
g_object_get (view->settings, "location-entry-search",
|
g_object_get (view->settings, "location-entry-search",
|
||||||
&location_entry_search, NULL);
|
&location_entry_search, NULL);
|
||||||
|
|
||||||
data = sokoke_replace_variables (speeddial_html,
|
data = sokoke_replace_variables (speeddial_html,
|
||||||
"{res}", res_root,
|
"{res}", res_root,
|
||||||
"{title}", _("Blank page"),
|
"{title}", _("Blank page"),
|
||||||
"{search_uri}", &location_entry_search,
|
"{search_uri}", location_entry_search,
|
||||||
"{search_title}", _("Search"),
|
"{search_title}", _("Search"),
|
||||||
"{search}", _("Search"),
|
"{search}", _("Search"),
|
||||||
"{click_to_add}", _("Click to add a shortcut"),
|
"{click_to_add}", _("Click to add a shortcut"),
|
||||||
"{enter_shortcut_address}", _("Enter shortcut address"),
|
"{enter_shortcut_address}", _("Enter shortcut address"),
|
||||||
"{enter_shortcut_name}", _("Enter shortcut name"),
|
"{enter_shortcut_name}", _("Enter shortcut name"),
|
||||||
"{are_you_sure}", _("Are you sure you want to delete this shortcut?"), NULL);
|
"{are_you_sure}", _("Are you sure you want to delete this shortcut?"), NULL);
|
||||||
g_free (location_entry_search);
|
|
||||||
|
|
||||||
#if WEBKIT_CHECK_VERSION (1, 1, 6)
|
#if WEBKIT_CHECK_VERSION (1, 1, 6)
|
||||||
webkit_web_frame_load_alternate_string (
|
webkit_web_frame_load_alternate_string (
|
||||||
|
@ -2080,7 +2082,8 @@ midori_view_set_uri (MidoriView* view,
|
||||||
g_free (speeddial_html);
|
g_free (speeddial_html);
|
||||||
g_free (speeddial_head);
|
g_free (speeddial_head);
|
||||||
g_free (speeddial_body);
|
g_free (speeddial_body);
|
||||||
g_free (t_body_fname);
|
g_free (body_fname);
|
||||||
|
g_free (location_entry_search);
|
||||||
}
|
}
|
||||||
/* This is not prefectly elegant, but creating an
|
/* This is not prefectly elegant, but creating an
|
||||||
error page inline is the simplest solution. */
|
error page inline is the simplest solution. */
|
||||||
|
@ -3101,7 +3104,7 @@ midori_view_speeddial_save (GtkWidget* web_view)
|
||||||
{
|
{
|
||||||
JSContextRef js_context = webkit_web_frame_get_global_context (
|
JSContextRef js_context = webkit_web_frame_get_global_context (
|
||||||
webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view)));
|
webkit_web_view_get_main_frame (WEBKIT_WEB_VIEW (web_view)));
|
||||||
gchar* newdom = sokoke_js_script_eval (js_context,"document.body.innerHTML", NULL);
|
gchar* newdom = sokoke_js_script_eval (js_context,"getSpeeddialContent()", NULL);
|
||||||
gchar* fname = g_strconcat (g_get_user_config_dir (), "/midori/speeddial-body.html", NULL);
|
gchar* fname = g_strconcat (g_get_user_config_dir (), "/midori/speeddial-body.html", NULL);
|
||||||
g_file_set_contents (fname, newdom, -1, NULL);
|
g_file_set_contents (fname, newdom, -1, NULL);
|
||||||
g_free (fname);
|
g_free (fname);
|
||||||
|
|
Loading…
Reference in a new issue