Rely on sqlite for completion, otherwise disable it entirely

This commit is contained in:
Christian Dywan 2010-01-25 01:19:03 +01:00
parent 726c7c34e0
commit 65c56f26a8
2 changed files with 5 additions and 72 deletions

View file

@ -121,13 +121,6 @@ static void
midori_location_action_disconnect_proxy (GtkAction* action, midori_location_action_disconnect_proxy (GtkAction* action,
GtkWidget* proxy); GtkWidget* proxy);
#if !HAVE_SQLITE
static gboolean
midori_location_action_filter_match_cb (GtkTreeModel* model,
GtkTreeIter* iter,
gpointer data);
#endif
static void static void
midori_location_entry_render_text_cb (GtkCellLayout* layout, midori_location_entry_render_text_cb (GtkCellLayout* layout,
GtkCellRenderer* renderer, GtkCellRenderer* renderer,
@ -281,6 +274,7 @@ midori_location_action_create_model (void)
return model; return model;
} }
#if HAVE_SQLITE
static void static void
midori_location_action_popup_position (GtkWidget* popup, midori_location_action_popup_position (GtkWidget* popup,
GtkWidget* widget) GtkWidget* widget)
@ -342,13 +336,11 @@ midori_location_action_popup_timeout_cb (gpointer data)
MidoriLocationAction* action = data; MidoriLocationAction* action = data;
static GtkTreeModel* model = NULL; static GtkTreeModel* model = NULL;
GtkTreeViewColumn* column; GtkTreeViewColumn* column;
#if HAVE_SQLITE
GtkListStore* store; GtkListStore* store;
sqlite3* db; sqlite3* db;
gchar* query; gchar* query;
gint result; gint result;
sqlite3_stmt* statement; sqlite3_stmt* statement;
#endif
gint matches, height, screen_height; gint matches, height, screen_height;
if (!gtk_widget_has_focus (action->entry) || !action->history) if (!gtk_widget_has_focus (action->entry) || !action->history)
@ -357,11 +349,7 @@ midori_location_action_popup_timeout_cb (gpointer data)
if (!*action->key) if (!*action->key)
{ {
const gchar* uri = gtk_entry_get_text (GTK_ENTRY (action->entry)); const gchar* uri = gtk_entry_get_text (GTK_ENTRY (action->entry));
#if HAVE_SQLITE
katze_assign (action->key, g_strdup (uri)); katze_assign (action->key, g_strdup (uri));
#else
katze_assign (action->key, katze_collfold (uri));
#endif
} }
if (!*action->key) if (!*action->key)
@ -370,7 +358,6 @@ midori_location_action_popup_timeout_cb (gpointer data)
return FALSE; return FALSE;
} }
#if HAVE_SQLITE
db = g_object_get_data (G_OBJECT (action->history), "db"); db = g_object_get_data (G_OBJECT (action->history), "db");
/* FIXME: Consider keeping the prepared statement with '...LIKE ?...' /* FIXME: Consider keeping the prepared statement with '...LIKE ?...'
and prepending/ appending % to the key. */ and prepending/ appending % to the key. */
@ -396,7 +383,6 @@ midori_location_action_popup_timeout_cb (gpointer data)
midori_location_action_popdown_completion (action); midori_location_action_popdown_completion (action);
return FALSE; return FALSE;
} }
#endif
if (G_UNLIKELY (!action->popup)) if (G_UNLIKELY (!action->popup))
{ {
@ -405,13 +391,7 @@ midori_location_action_popup_timeout_cb (gpointer data)
GtkWidget* treeview; GtkWidget* treeview;
GtkCellRenderer* renderer; GtkCellRenderer* renderer;
#if HAVE_SQLITE
model = midori_location_action_create_model (); model = midori_location_action_create_model ();
#else
model = gtk_tree_model_filter_new (action->model, NULL);
gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (model),
midori_location_action_filter_match_cb, action, NULL);
#endif
action->completion_model = model; action->completion_model = model;
popup = gtk_window_new (GTK_WINDOW_POPUP); popup = gtk_window_new (GTK_WINDOW_POPUP);
@ -449,7 +429,6 @@ midori_location_action_popup_timeout_cb (gpointer data)
G_CALLBACK (gtk_widget_destroyed), &action->popup); G_CALLBACK (gtk_widget_destroyed), &action->popup);
} }
#if HAVE_SQLITE
store = GTK_LIST_STORE (model); store = GTK_LIST_STORE (model);
gtk_list_store_clear (store); gtk_list_store_clear (store);
@ -468,10 +447,6 @@ midori_location_action_popup_timeout_cb (gpointer data)
result = sqlite3_step (statement); result = sqlite3_step (statement);
} }
while (result == SQLITE_ROW); while (result == SQLITE_ROW);
#else
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model));
matches = gtk_tree_model_iter_n_children (model, NULL);
#endif
/* TODO: Suggest _("Search with %s") or opening hostname as actions */ /* TODO: Suggest _("Search with %s") or opening hostname as actions */
if (!GTK_WIDGET_VISIBLE (action->popup)) if (!GTK_WIDGET_VISIBLE (action->popup))
@ -495,6 +470,7 @@ midori_location_action_popup_timeout_cb (gpointer data)
return FALSE; return FALSE;
} }
#endif
static void static void
midori_location_action_popup_completion (MidoriLocationAction* action, midori_location_action_popup_completion (MidoriLocationAction* action,
@ -507,9 +483,11 @@ midori_location_action_popup_completion (MidoriLocationAction* action,
action->entry = entry; action->entry = entry;
g_signal_connect (entry, "destroy", g_signal_connect (entry, "destroy",
G_CALLBACK (gtk_widget_destroyed), &action->entry); G_CALLBACK (gtk_widget_destroyed), &action->entry);
#if HAVE_SQLITE
action->completion_timeout = g_timeout_add (COMPLETION_DELAY, action->completion_timeout = g_timeout_add (COMPLETION_DELAY,
midori_location_action_popup_timeout_cb, action); midori_location_action_popup_timeout_cb, action);
/* TODO: Inline completion */ /* TODO: Inline completion */
#endif
} }
static void static void
@ -1044,15 +1022,8 @@ midori_location_action_preedit_changed_cb (GtkWidget* widget,
GtkAction* action) GtkAction* action)
{ {
MidoriLocationAction* location_action = MIDORI_LOCATION_ACTION (action); MidoriLocationAction* location_action = MIDORI_LOCATION_ACTION (action);
#if HAVE_SQLITE
midori_location_action_popup_completion (location_action, midori_location_action_popup_completion (location_action,
GTK_WIDGET (widget), preedit); GTK_WIDGET (widget), preedit);
#else
gchar* key = katze_collfold (preedit);
midori_location_action_popup_completion (location_action,
GTK_WIDGET (widget), key);
g_free (key);
#endif
} }
#endif #endif
@ -1210,44 +1181,6 @@ midori_location_entry_render_text_cb (GtkCellLayout* layout,
g_free (desc); g_free (desc);
} }
#if !HAVE_SQLITE
static gboolean
midori_location_action_match (GtkTreeModel* model,
const gchar* key,
GtkTreeIter* iter,
gpointer data)
{
gchar* uri;
gchar* title;
gboolean match;
gtk_tree_model_get (model, iter, URI_COL, &uri, TITLE_COL, &title, -1);
match = FALSE;
if (G_LIKELY (uri))
{
match = katze_utf8_stristr (uri, key);
g_free (uri);
if (!match && G_LIKELY (title))
match = katze_utf8_stristr (title, key);
}
g_free (title);
return match;
}
static gboolean
midori_location_action_filter_match_cb (GtkTreeModel* model,
GtkTreeIter* iter,
gpointer data)
{
MidoriLocationAction* action = data;
return midori_location_action_match (model, action->key, iter, data);
}
#endif
/** /**
* midori_location_action_iter_lookup: * midori_location_action_iter_lookup:
* @location_action: a #MidoriLocationAction * @location_action: a #MidoriLocationAction

View file

@ -306,7 +306,7 @@ def configure (conf):
print ''' print '''
Localization: %(nls)s (intltool) Localization: %(nls)s (intltool)
Icon optimizations: %(icons)s (rsvg-convert) Icon optimizations: %(icons)s (rsvg-convert)
Persistent history: %(sqlite)s (sqlite3) History: %(sqlite)s (sqlite3)
Notifications: %(libnotify)s (libnotify) Notifications: %(libnotify)s (libnotify)
IDN support: %(idn)s (libidn or libsoup 2.27.90) IDN support: %(idn)s (libidn or libsoup 2.27.90)