Popdown completion if key is empty or there are no matches
This commit is contained in:
parent
af7d9428e7
commit
726c7c34e0
1 changed files with 45 additions and 31 deletions
|
@ -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,38 +453,21 @@ 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* title = sqlite3_column_text (statement, 1);
|
||||||
const unsigned char* uri = sqlite3_column_text (statement, 0);
|
GdkPixbuf* icon = katze_load_cached_icon ((gchar*)uri, NULL);
|
||||||
const unsigned char* title = sqlite3_column_text (statement, 1);
|
if (!icon)
|
||||||
GdkPixbuf* icon = katze_load_cached_icon ((gchar*)uri, NULL);
|
icon = action->default_icon;
|
||||||
if (!icon)
|
gtk_list_store_insert_with_values (store, NULL, matches,
|
||||||
icon = action->default_icon;
|
URI_COL, uri, TITLE_COL, title, YALIGN_COL, 0.25,
|
||||||
gtk_list_store_insert_with_values (store, NULL, matches,
|
FAVICON_COL, icon, -1);
|
||||||
URI_COL, uri, TITLE_COL, title, YALIGN_COL, 0.25,
|
matches++;
|
||||||
FAVICON_COL, icon, -1);
|
result = sqlite3_step (statement);
|
||||||
matches++;
|
|
||||||
}
|
|
||||||
if (result != SQLITE_DONE)
|
|
||||||
g_print (_("Failed to execute database statement: %s\n"),
|
|
||||||
sqlite3_errmsg (db));
|
|
||||||
sqlite3_finalize (statement);
|
|
||||||
}
|
}
|
||||||
else
|
while (result == SQLITE_ROW);
|
||||||
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);
|
||||||
|
|
Loading…
Reference in a new issue