2
Copyright (C) 2009-2012 Alexander Butenko <a.butenka@gmail.com>
3
Copyright (C) 2009-2012 Christian Dywan <christian@twotoasts.de>
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) any later version.
10
#include "formhistory-frontend.h"
11
#ifdef FORMHISTORY_USE_JS
14
formhistory_private_new ()
16
FormHistoryPriv* priv = g_slice_new (FormHistoryPriv);
21
formhistory_construct_popup_gui (FormHistoryPriv* priv)
28
file = midori_app_find_res_filename ("autosuggestcontrol.js");
29
if (!g_file_get_contents (file, &autosuggest, NULL, NULL))
34
g_strchomp (autosuggest);
36
katze_assign (file, midori_app_find_res_filename ("autosuggestcontrol.css"));
37
if (!g_file_get_contents (file, &style, NULL, NULL))
53
priv->jsforms = g_strdup_printf (
55
"window.addEventListener ('DOMContentLoaded',"
57
" if (document.getElementById('formhistory'))"
59
" if (!initSuggestions ())"
61
" var mystyle = document.createElement('style');"
62
" mystyle.setAttribute('type', 'text/css');"
63
" mystyle.setAttribute('id', 'formhistory');"
64
" mystyle.appendChild(document.createTextNode('%s'));"
65
" var head = document.getElementsByTagName('head')[0];"
66
" if (head) head.appendChild(mystyle);"
70
g_strstrip (priv->jsforms);
77
formhistory_setup_suggestions (WebKitWebView* web_view,
78
JSContextRef js_context,
79
MidoriExtension* extension)
82
FormHistoryPriv* priv;
83
static sqlite3_stmt* stmt;
85
const unsigned char* key;
86
const unsigned char* value;
90
priv = g_object_get_data (G_OBJECT (extension), "priv");
96
sqlcmd = "SELECT DISTINCT group_concat(value,'\",\"'), field FROM forms \
97
GROUP BY field ORDER BY field";
98
sqlite3_prepare_v2 (priv->db, sqlcmd, strlen (sqlcmd) + 1, &stmt, NULL);
100
result = sqlite3_step (stmt);
101
if (result != SQLITE_ROW)
103
if (result == SQLITE_ERROR)
104
g_print (_("Failed to select suggestions\n"));
105
sqlite3_reset (stmt);
108
suggestions = g_string_new (
109
"function FormSuggestions(eid) { "
110
"arr = new Array();");
112
while (result == SQLITE_ROW)
115
value = sqlite3_column_text (stmt, 0);
116
key = sqlite3_column_text (stmt, 1);
119
g_string_append_printf (suggestions, " arr[\"%s\"] = [\"%s\"]; ",
120
(gchar*)key, (gchar*)value);
122
result = sqlite3_step (stmt);
124
g_string_append (suggestions, "this.suggestions = arr[eid]; }");
125
g_string_append (suggestions, priv->jsforms);
126
sokoke_js_script_eval (js_context, suggestions->str, NULL);
127
g_string_free (suggestions, TRUE);
131
formhistory_private_destroy (FormHistoryPriv *priv)
135
sqlite3_close (priv->db);
138
katze_assign (priv->jsforms, NULL);
139
g_slice_free (FormHistoryPriv, priv);