Popdown completion if key is empty or there are no matches

This commit is contained in:
Christian Dywan 2010-01-24 23:53:18 +01:00
parent af7d9428e7
commit 726c7c34e0

View file

@ -351,7 +351,7 @@ midori_location_action_popup_timeout_cb (gpointer data)
#endif #endif
gint matches, height, screen_height; gint matches, height, screen_height;
if (!gtk_widget_has_focus (action->entry)) if (!gtk_widget_has_focus (action->entry) || !action->history)
return FALSE; return FALSE;
if (!*action->key) if (!*action->key)
@ -364,8 +364,39 @@ midori_location_action_popup_timeout_cb (gpointer data)
#endif #endif
} }
if (!(action->key && *action->key)) if (!*action->key)
{
midori_location_action_popdown_completion (action);
return FALSE; return FALSE;
}
#if HAVE_SQLITE
db = g_object_get_data (G_OBJECT (action->history), "db");
/* FIXME: Consider keeping the prepared statement with '...LIKE ?...'
and prepending/ appending % to the key. */
query = sqlite3_mprintf ("SELECT uri, title FROM history WHERE "
"uri LIKE '%%%q%%' OR title LIKE '%%%q%%'"
"GROUP BY uri ORDER BY count() DESC LIMIT %d",
action->key, action->key, MAX_ITEMS);
result = sqlite3_prepare_v2 (db, query, -1, &statement, NULL);
sqlite3_free (query);
if (result != SQLITE_OK)
{
g_print (_("Failed to execute database statement: %s\n"),
sqlite3_errmsg (db));
midori_location_action_popdown_completion (action);
return FALSE;
}
result = sqlite3_step (statement);
if (result != SQLITE_ROW)
{
sqlite3_finalize (statement);
midori_location_action_popdown_completion (action);
return FALSE;
}
#endif
if (G_UNLIKELY (!action->popup)) if (G_UNLIKELY (!action->popup))
{ {
@ -422,19 +453,8 @@ midori_location_action_popup_timeout_cb (gpointer data)
store = GTK_LIST_STORE (model); store = GTK_LIST_STORE (model);
gtk_list_store_clear (store); gtk_list_store_clear (store);
db = g_object_get_data (G_OBJECT (action->history), "db");
/* FIXME: Consider keeping the prepared statement with '...LIKE ?...'
and prepending/ appending % to the key. */
query = sqlite3_mprintf ("SELECT uri, title FROM history WHERE "
"uri LIKE '%%%q%%' OR title LIKE '%%%q%%'"
"GROUP BY uri ORDER BY count() DESC LIMIT %d",
action->key, action->key, MAX_ITEMS);
result = sqlite3_prepare_v2 (db, query, -1, &statement, NULL);
sqlite3_free (query);
matches = 0; matches = 0;
if (result == SQLITE_OK) do
{
while ((result = sqlite3_step (statement)) == SQLITE_ROW)
{ {
const unsigned char* uri = sqlite3_column_text (statement, 0); const unsigned char* uri = sqlite3_column_text (statement, 0);
const unsigned char* title = sqlite3_column_text (statement, 1); const unsigned char* title = sqlite3_column_text (statement, 1);
@ -445,15 +465,9 @@ midori_location_action_popup_timeout_cb (gpointer data)
URI_COL, uri, TITLE_COL, title, YALIGN_COL, 0.25, URI_COL, uri, TITLE_COL, title, YALIGN_COL, 0.25,
FAVICON_COL, icon, -1); FAVICON_COL, icon, -1);
matches++; matches++;
result = sqlite3_step (statement);
} }
if (result != SQLITE_DONE) while (result == SQLITE_ROW);
g_print (_("Failed to execute database statement: %s\n"),
sqlite3_errmsg (db));
sqlite3_finalize (statement);
}
else
g_print (_("Failed to execute database statement: %s\n"),
sqlite3_errmsg (db));
#else #else
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model)); gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model));
matches = gtk_tree_model_iter_n_children (model, NULL); matches = gtk_tree_model_iter_n_children (model, NULL);