From: Christian Dywan Date: Thu, 28 Jan 2010 21:19:00 +0000 (+0100) Subject: Re-implement search engines in the completion X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b947e5d662d64dc73fc3ad0c031cb0d312ad627a;p=midori Re-implement search engines in the completion --- diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 44e94c70..27f9b2ee 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -6640,7 +6640,12 @@ midori_browser_settings_notify (MidoriWebSettings* web_settings, g_value_get_string (&value) && *g_value_get_string (&value)); else if (name == g_intern_string ("search-engines-in-completion")) { - /* Do nothing */ + if (g_value_get_boolean (&value)) + midori_location_action_set_search_engines (MIDORI_LOCATION_ACTION ( + _action_by_name (browser, "Location")), browser->search_engines); + else + midori_location_action_set_search_engines (MIDORI_LOCATION_ACTION ( + _action_by_name (browser, "Location")), NULL); } else if (name == g_intern_string ("location-entry-search")) { @@ -6854,6 +6859,13 @@ midori_browser_set_property (GObject* object, /* FIXME: Disconnect handlers */ katze_object_assign (browser->search_engines, g_value_dup_object (value)); + if (katze_object_get_boolean (browser->settings, + "search-engines-in-completion")) + midori_location_action_set_search_engines (MIDORI_LOCATION_ACTION ( + _action_by_name (browser, "Location")), browser->search_engines); + else + midori_location_action_set_search_engines (MIDORI_LOCATION_ACTION ( + _action_by_name (browser, "Location")), NULL); midori_search_action_set_search_engines (MIDORI_SEARCH_ACTION ( _action_by_name (browser, "Search")), browser->search_engines); /* FIXME: Connect to updates */ diff --git a/midori/midori-locationaction.c b/midori/midori-locationaction.c index 5098794d..a0593643 100644 --- a/midori/midori-locationaction.c +++ b/midori/midori-locationaction.c @@ -34,6 +34,7 @@ struct _MidoriLocationAction gchar* text; gchar* uri; + KatzeArray* search_engines; gdouble progress; gchar* secondary_icon; @@ -373,7 +374,7 @@ midori_location_action_popup_timeout_cb (gpointer data) } result = sqlite3_step (statement); - if (result != SQLITE_ROW) + if (result != SQLITE_ROW && !action->search_engines) { sqlite3_finalize (statement); midori_location_action_popdown_completion (action); @@ -432,7 +433,7 @@ midori_location_action_popup_timeout_cb (gpointer data) gtk_list_store_clear (store); matches = 0; - do + while (result == SQLITE_ROW) { const unsigned char* uri = sqlite3_column_text (statement, 0); const unsigned char* title = sqlite3_column_text (statement, 1); @@ -445,8 +446,27 @@ midori_location_action_popup_timeout_cb (gpointer data) matches++; result = sqlite3_step (statement); } - while (result == SQLITE_ROW); - /* TODO: Suggest _("Search with %s") or opening hostname as actions */ + + if (action->search_engines) + { + gint i = 0; + KatzeItem* item; + while ((item = katze_array_get_nth_item (action->search_engines, i))) + { + gchar* uri; + gchar* title; + + uri = sokoke_search_uri (katze_item_get_uri (item), action->key); + title = g_strdup_printf (_("Search with %s"), katze_item_get_name (item)); + gtk_list_store_insert_with_values (store, NULL, matches, + URI_COL, uri, TITLE_COL, title, YALIGN_COL, 0.25, + FAVICON_COL, NULL, -1); + g_free (uri); + g_free (title); + i++; + } + matches += i; + } if (!GTK_WIDGET_VISIBLE (action->popup)) { @@ -547,6 +567,7 @@ static void midori_location_action_init (MidoriLocationAction* location_action) { location_action->text = location_action->uri = NULL; + location_action->search_engines = NULL; location_action->progress = 0.0; location_action->secondary_icon = NULL; location_action->default_icon = NULL; @@ -565,6 +586,7 @@ midori_location_action_finalize (GObject* object) katze_assign (location_action->text, NULL); katze_assign (location_action->uri, NULL); + katze_assign (location_action->search_engines, NULL); katze_assign (location_action->key, NULL); if (location_action->popup) @@ -1455,15 +1477,21 @@ midori_location_action_set_title_for_uri (MidoriLocationAction* location_action, * @location_action: a #MidoriLocationAction * @search_engines: a #KatzeArray * - * This function is obsolete and has no effect. + * Assigns the specified search engines to the location action. + * Search engines will appear as actions in the completion. * - * Deprecated: 0.2.3 + * Since: 0.1.6 **/ void midori_location_action_set_search_engines (MidoriLocationAction* location_action, KatzeArray* search_engines) { - /* Do nothing */ + g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action)); + + if (search_engines) + g_object_ref (search_engines); + + katze_object_assign (location_action->search_engines, search_engines); } gdouble diff --git a/midori/midori-preferences.c b/midori/midori-preferences.c index df123498..fe71743e 100644 --- a/midori/midori-preferences.c +++ b/midori/midori-preferences.c @@ -435,6 +435,8 @@ midori_preferences_set_settings (MidoriPreferences* preferences, SPANNED_ADD (button); button = katze_property_proxy (settings, "progress-in-location", NULL); INDENTED_ADD (button); + button = katze_property_proxy (settings, "search-engines-in-completion", NULL); + SPANNED_ADD (button); #endif FRAME_NEW (_("Browsing")); label = katze_property_label (settings, "open-new-pages-in"); diff --git a/midori/midori-websettings.c b/midori/midori-websettings.c index 4305a413..10e40e89 100644 --- a/midori/midori-websettings.c +++ b/midori/midori-websettings.c @@ -512,7 +512,7 @@ midori_web_settings_class_init (MidoriWebSettingsClass* class) * * Whether to show search engines in the location completion. * - * Deprecated: 0.2.3: This setting is obsolete. + * Since: 0.1.6 */ g_object_class_install_property (gobject_class, PROP_SEARCH_ENGINES_IN_COMPLETION,