[Xfce4-commits] <midori:master> Store searches and completion search in the location

Christian Dywan noreply at xfce.org
Thu Feb 25 00:44:01 CET 2010


Updating branch refs/heads/master
         to de89bcd2dca283e0e93b0d5fe1ce6d881c7b42cc (commit)
       from 705d2b7627826c6f6c7ac0f6aab242b5963df2fe (commit)

commit de89bcd2dca283e0e93b0d5fe1ce6d881c7b42cc
Author: Christian Dywan <christian at twotoasts.de>
Date:   Mon Feb 22 23:49:27 2010 +0100

    Store searches and completion search in the location

 midori/main.c                  |   12 +++++++--
 midori/midori-browser.c        |   28 ++++++++++++++++++++++
 midori/midori-locationaction.c |   51 +++++++++++++++++++++++++++------------
 3 files changed, 72 insertions(+), 19 deletions(-)

diff --git a/midori/main.c b/midori/main.c
index eed1713..70eb1b0 100644
--- a/midori/main.c
+++ b/midori/main.c
@@ -368,9 +368,15 @@ midori_history_initialize (KatzeArray*  array,
     }
 
     if (sqlite3_exec (db,
-                  "CREATE TABLE IF NOT EXISTS "
-                  "history(uri text, title text, date integer, day integer)",
-                  NULL, NULL, errmsg) != SQLITE_OK)
+                      "CREATE TABLE IF NOT EXISTS "
+                      "history (uri text, title text, date integer, day integer);"
+                      "CREATE TABLE IF NOT EXISTS "
+                      "search (keywords text, uri text, day integer);"
+                      "CREATE TEMP VIEW history_view AS SELECT "
+                      "1 AS type, uri, title FROM history;"
+                      "CREATE TEMP VIEW search_view AS SELECT "
+                      "2 AS type, uri, keywords AS title FROM search;",
+                      NULL, NULL, errmsg) != SQLITE_OK)
         return NULL;
 
     sqlite3_prepare_v2 (db, "SELECT day FROM history LIMIT 1", -1, &stmt, NULL);
diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index f5906e2..f5c41d6 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -3853,6 +3853,12 @@ _action_location_submit_uri (GtkAction*     action,
         gchar** parts;
         gchar* keywords = NULL;
         const gchar* search_uri = NULL;
+        #if HAVE_SQLITE
+        time_t now;
+        gint64 day;
+        sqlite3* db;
+        static sqlite3_stmt* statement = NULL;
+        #endif
 
         /* Do we have a keyword and a string? */
         parts = g_strsplit (stripped_uri, " ", 2);
@@ -3876,6 +3882,28 @@ _action_location_submit_uri (GtkAction*     action,
         }
         new_uri = sokoke_search_uri (search_uri, keywords);
 
+        #if HAVE_SQLITE
+        now = time (NULL);
+        day = sokoke_time_t_to_julian (&now);
+
+        db = g_object_get_data (G_OBJECT (browser->history), "db");
+        if (!statement)
+        {
+            const gchar* sqlcmd;
+            sqlcmd = "INSERT INTO search (keywords, uri, day) VALUES (?,?,?)";
+            sqlite3_prepare_v2 (db, sqlcmd, strlen (sqlcmd) + 1, &statement, NULL);
+        }
+        sqlite3_bind_text (statement, 1, keywords, -1, 0);
+        sqlite3_bind_text (statement, 2, search_uri, -1, 0);
+        sqlite3_bind_int64 (statement, 3, day);
+
+        if (sqlite3_step (statement) != SQLITE_DONE)
+            g_printerr (_("Failed to insert new history item: %s\n"),
+                        sqlite3_errmsg (db));
+        sqlite3_reset (statement);
+        sqlite3_clear_bindings (statement);
+        #endif
+
         g_free (keywords);
     }
     else
diff --git a/midori/midori-locationaction.c b/midori/midori-locationaction.c
index 1ab63c7..b10a9fc 100644
--- a/midori/midori-locationaction.c
+++ b/midori/midori-locationaction.c
@@ -87,6 +87,7 @@ enum
     VISIBLE_COL,
     YALIGN_COL,
     BACKGROUND_COL,
+    STYLE_COL,
     N_COLS
 };
 
@@ -268,7 +269,8 @@ midori_location_action_create_model (void)
 {
     GtkTreeModel* model = (GtkTreeModel*) gtk_list_store_new (N_COLS,
         GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING,
-        G_TYPE_INT, G_TYPE_BOOLEAN, G_TYPE_FLOAT, GDK_TYPE_COLOR);
+        G_TYPE_INT, G_TYPE_BOOLEAN, G_TYPE_FLOAT,
+        GDK_TYPE_COLOR, G_TYPE_BOOLEAN);
     return model;
 }
 
@@ -341,6 +343,7 @@ midori_location_action_popup_timeout_cb (gpointer data)
     static sqlite3_stmt* stmt;
     const gchar* sqlcmd;
     gint matches, searches, height, screen_height, sep;
+    GtkStyle* style;
 
     if (!gtk_widget_has_focus (action->entry) || !action->history)
         return FALSE;
@@ -355,13 +358,16 @@ midori_location_action_popup_timeout_cb (gpointer data)
     {
         sqlite3* db;
         db = g_object_get_data (G_OBJECT (action->history), "db");
-        sqlcmd = "SELECT uri, title FROM history WHERE uri LIKE ? OR title LIKE ?"
-                 " GROUP BY uri ORDER BY count() DESC LIMIT ?";
-        sqlite3_prepare_v2 (db, sqlcmd, -1, &stmt, NULL);
+        sqlcmd = "SELECT type, uri, title, count() AS ct FROM history_view "
+                 "WHERE uri LIKE ?1 OR title LIKE ?1 GROUP BY uri "
+                 "UNION ALL "
+                 "SELECT type, uri, title, count() AS ct FROM search_view "
+                 "WHERE title LIKE ?1 GROUP BY uri "
+                 "ORDER BY ct DESC LIMIT ?2";
+        sqlite3_prepare_v2 (db, sqlcmd, strlen (sqlcmd) + 1, &stmt, NULL);
     }
     sqlite3_bind_text (stmt, 1, g_strdup_printf ("%%%s%%", action->key), -1, g_free);
-    sqlite3_bind_text (stmt, 2, g_strdup_printf ("%%%s%%", action->key), -1, g_free);
-    sqlite3_bind_int64 (stmt, 3, MAX_ITEMS);
+    sqlite3_bind_int64 (stmt, 2, MAX_ITEMS);
 
     result = sqlite3_step (stmt);
     if (result != SQLITE_ROW && !action->search_engines)
@@ -429,16 +435,30 @@ midori_location_action_popup_timeout_cb (gpointer data)
     gtk_list_store_clear (store);
 
     matches = searches = 0;
+    style = gtk_widget_get_style (action->treeview);
     while (result == SQLITE_ROW)
     {
-        const unsigned char* uri = sqlite3_column_text (stmt, 0);
-        const unsigned char* title = sqlite3_column_text (stmt, 1);
+        sqlite3_int64 type = sqlite3_column_int64 (stmt, 0);
+        const unsigned char* uri = sqlite3_column_text (stmt, 1);
+        const unsigned char* title = sqlite3_column_text (stmt, 2);
         GdkPixbuf* icon = katze_load_cached_icon ((gchar*)uri, NULL);
         if (!icon)
             icon = action->default_icon;
-        gtk_list_store_insert_with_values (store, NULL, matches,
-            URI_COL, uri, TITLE_COL, title, YALIGN_COL, 0.25,
-            FAVICON_COL, icon, -1);
+        if (type == 1 /* history_view */)
+            gtk_list_store_insert_with_values (store, NULL, matches,
+                URI_COL, uri, TITLE_COL, title, YALIGN_COL, 0.25,
+                FAVICON_COL, icon, -1);
+        else if (type == 2 /* search_view */)
+        {
+            gchar* search_uri = sokoke_search_uri ((gchar*)uri, (gchar*)title);
+            gchar* search_title = g_strdup_printf (_("Search for %s"), title);
+            gtk_list_store_insert_with_values (store, NULL, matches,
+                URI_COL, search_uri, TITLE_COL, search_title, YALIGN_COL, 0.25,
+                STYLE_COL, 1, FAVICON_COL, icon, -1);
+            g_free (search_uri);
+            g_free (search_title);
+        }
+
         matches++;
         result = sqlite3_step (stmt);
     }
@@ -453,15 +473,13 @@ midori_location_action_popup_timeout_cb (gpointer data)
         {
             gchar* uri;
             gchar* title;
-            GtkStyle* style;
 
             uri = sokoke_search_uri (katze_item_get_uri (item), action->key);
             title = g_strdup_printf (_("Search with %s"), katze_item_get_name (item));
-            style = gtk_widget_get_style (action->treeview);
             gtk_list_store_insert_with_values (store, NULL, matches + i,
                 URI_COL, uri, TITLE_COL, title, YALIGN_COL, 0.25,
                 BACKGROUND_COL, style ? &style->bg[GTK_STATE_NORMAL] : NULL,
-                FAVICON_COL, NULL, -1);
+                STYLE_COL, 1, FAVICON_COL, NULL, -1);
             g_free (uri);
             g_free (title);
             i++;
@@ -1018,6 +1036,7 @@ midori_location_entry_render_text_cb (GtkCellLayout*   layout,
     gchar* uri;
     gchar* title;
     GdkColor* background;
+    gboolean style;
     gchar* desc;
     gchar* desc_uri;
     gchar* desc_title;
@@ -1030,9 +1049,9 @@ midori_location_entry_render_text_cb (GtkCellLayout*   layout,
     size_t len;
 
     gtk_tree_model_get (model, iter, URI_COL, &uri, TITLE_COL, &title,
-        BACKGROUND_COL, &background, -1);
+        BACKGROUND_COL, &background, STYLE_COL, &style, -1);
 
-    if (background != NULL) /* A search engine action */
+    if (style) /* A search engine action */
     {
         g_object_set (renderer, "text", title,
             "ellipsize-set", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL);



More information about the Xfce4-commits mailing list