gboolean show_statusbar;
gboolean progress_in_location;
gboolean remember_last_visited_pages;
+ gchar* location_entry_search;
gchar* news_aggregator;
};
gboolean new_tab,
MidoriBrowser* browser)
{
- gchar* location_entry_search;
gchar* new_uri;
gint n;
- g_object_get (browser->settings, "location-entry-search",
- &location_entry_search, NULL);
new_uri = sokoke_magic_uri (uri, browser->search_engines);
- if (!new_uri && strstr (location_entry_search, "%s"))
- new_uri = g_strdup_printf (location_entry_search, uri);
+ if (!new_uri && strstr (browser->location_entry_search, "%s"))
+ new_uri = g_strdup_printf (browser->location_entry_search, uri);
else if (!new_uri)
- new_uri = g_strdup (location_entry_search);
- g_free (location_entry_search);
+ new_uri = g_strconcat (browser->location_entry_search, uri, NULL);
+
if (new_tab)
{
n = midori_browser_add_uri (browser, new_uri);
guint last_web_search;
KatzeItem* item;
const gchar* url;
- gchar* location_entry_search;
gchar* search;
g_object_get (browser->settings, "last-web-search", &last_web_search, NULL);
item = katze_array_get_nth_item (browser->search_engines, last_web_search);
if (item)
- {
- location_entry_search = NULL;
url = katze_item_get_uri (item);
- }
else /* The location entry search is our fallback */
- {
- g_object_get (browser->settings, "location-entry-search",
- &location_entry_search, NULL);
- url = location_entry_search;
- }
+ url = browser->location_entry_search;
+
if (strstr (url, "%s"))
search = g_strdup_printf (url, keywords);
else
midori_browser_set_current_uri (browser, search);
g_free (search);
- g_free (location_entry_search);
}
static void
g_object_set (browser->settings, "last-web-search", idx, NULL);
}
+static void
+_action_search_notify_default_item (GtkAction* action,
+ GParamSpec* pspec,
+ MidoriBrowser* browser)
+{
+ MidoriSearchAction* search_action;
+ KatzeItem* item;
+
+ search_action = MIDORI_SEARCH_ACTION (action);
+ item = midori_search_action_get_default_item (search_action);
+ if (item)
+ g_object_set (browser->settings, "location-entry-search",
+ katze_item_get_uri (item), NULL);
+}
+
static void
_action_search_focus_out (GtkAction* action,
MidoriBrowser* browser)
_action_search_focus_out, browser,
"signal::notify::current-item",
_action_search_notify_current_item, browser,
+ "signal::notify::default-item",
+ _action_search_notify_default_item, browser,
NULL);
gtk_action_group_add_action_with_accel (browser->action_group,
action, "<Ctrl>K");
"toolbar-style", &toolbar_style,
"toolbar-items", &toolbar_items,
"last-web-search", &last_web_search,
+ "location-entry-search", &browser->location_entry_search,
"close-buttons-on-tabs", &close_buttons_on_tabs,
"progress-in-location", &browser->progress_in_location,
"remember-last-visited-pages", &browser->remember_last_visited_pages,
if (browser->search_engines)
{
+ guint i;
+
item = katze_array_get_nth_item (browser->search_engines,
last_web_search);
if (item)
midori_search_action_set_current_item (MIDORI_SEARCH_ACTION (
_action_by_name (browser, "Search")), item);
+
+ i = 0;
+ while ((item = katze_array_get_nth_item (browser->search_engines, i++)))
+ if (!g_strcmp0 (katze_item_get_uri (item), browser->location_entry_search))
+ {
+ midori_search_action_set_default_item (MIDORI_SEARCH_ACTION (
+ _action_by_name (browser, "Search")), item);
+ break;
+ }
}
midori_panel_set_compact (MIDORI_PANEL (browser->panel), compact_sidepanel);
browser->show_statusbar = g_value_get_boolean (&value);
else if (name == g_intern_string ("progress-in-location"))
browser->progress_in_location = g_value_get_boolean (&value);
+ else if (name == g_intern_string ("location-entry-search"))
+ {
+ katze_assign (browser->location_entry_search, g_value_dup_string (&value));
+ }
else if (name == g_intern_string ("remember-last-visited-pages"))
browser->remember_last_visited_pages = g_value_get_boolean (&value);
else if (name == g_intern_string ("news-aggregator"))
/* FIXME: Connect to updates */
if (browser->settings)
{
+ guint i;
+
g_object_get (browser->settings, "last-web-search",
&last_web_search, NULL);
item = katze_array_get_nth_item (browser->search_engines,
last_web_search);
midori_search_action_set_current_item (MIDORI_SEARCH_ACTION (
_action_by_name (browser, "Search")), item);
+
+ i = 0;
+ while ((item = katze_array_get_nth_item (browser->search_engines, i++)))
+ if (!g_strcmp0 (katze_item_get_uri (item), browser->location_entry_search))
+ {
+ midori_search_action_set_default_item (MIDORI_SEARCH_ACTION (
+ _action_by_name (browser, "Search")), item);
+ break;
+ }
}
break;
case PROP_HISTORY:
KatzeArray* search_engines;
KatzeItem* current_item;
+ KatzeItem* default_item;
gchar* text;
KatzeNet* net;
GtkWidget* treeview;
GtkWidget* edit_button;
GtkWidget* remove_button;
+ GtkWidget* default_button;
};
struct _MidoriSearchActionClass
PROP_SEARCH_ENGINES,
PROP_CURRENT_ITEM,
+ PROP_DEFAULT_ITEM,
PROP_TEXT,
PROP_DIALOG
};
KATZE_TYPE_ITEM,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ /**
+ * MidoriSearchAction:default-item:
+ *
+ * The default search engine.
+ *
+ * Since: 0.1.6
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_DEFAULT_ITEM,
+ g_param_spec_object (
+ "default-item",
+ "Default Item",
+ "The default search engine",
+ KATZE_TYPE_ITEM,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
g_object_class_install_property (gobject_class,
PROP_TEXT,
g_param_spec_string (
{
search_action->search_engines = NULL;
search_action->current_item = NULL;
+ search_action->default_item = NULL;
search_action->text = NULL;
search_action->net = katze_net_new ();
search_action->treeview = NULL;
search_action->edit_button = NULL;
search_action->remove_button = NULL;
+ search_action->default_button = NULL;
}
static void
midori_search_action_set_current_item (search_action,
g_value_get_object (value));
break;
+ case PROP_DEFAULT_ITEM:
+ midori_search_action_set_default_item (search_action,
+ g_value_get_object (value));
+ break;
case PROP_TEXT:
midori_search_action_set_text (search_action,
g_value_get_string (value));
case PROP_CURRENT_ITEM:
g_value_set_object (value, search_action->current_item);
break;
+ case PROP_DEFAULT_ITEM:
+ g_value_set_object (value, search_action->default_item);
+ break;
case PROP_TEXT:
g_value_set_string (value, search_action->text);
break;
while ((proxies = g_slist_next (proxies)));
}
+/**
+ * midori_search_action_get_default_item:
+ * @search_action: a #MidoriSearchAction
+ *
+ * Retrieves the default search engine.
+ *
+ * Since 0.1.6
+ *
+ * Return value: a #KatzeItem
+ **/
+KatzeItem*
+midori_search_action_get_default_item (MidoriSearchAction* search_action)
+{
+ g_return_val_if_fail (MIDORI_IS_SEARCH_ACTION (search_action), NULL);
+
+ return search_action->default_item;
+}
+
+/**
+ * midori_search_action_set_default_item:
+ * @search_action: a #MidoriSearchAction
+ * @item: a #KatzeItem
+ *
+ * Sets the default search engine.
+ *
+ * Since 0.1.6
+ **/
+void
+midori_search_action_set_default_item (MidoriSearchAction* search_action,
+ KatzeItem* item)
+{
+ g_return_if_fail (MIDORI_IS_SEARCH_ACTION (search_action));
+ g_return_if_fail (!item || KATZE_IS_ITEM (item));
+
+ if (item)
+ g_object_ref (item);
+ katze_object_assign (search_action->default_item, item);
+ g_object_notify (G_OBJECT (search_action), "default-item");
+}
+
+static void
+midori_search_action_dialog_render_tick_cb (GtkTreeViewColumn* column,
+ GtkCellRenderer* renderer,
+ GtkTreeModel* model,
+ GtkTreeIter* iter,
+ GtkWidget* treeview)
+{
+ KatzeItem* item;
+ MidoriSearchAction* search_action;
+ gint width;
+
+ gtk_tree_model_get (model, iter, 0, &item, -1);
+
+ search_action = g_object_get_data (G_OBJECT (treeview), "search-action");
+ gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, NULL);
+ g_object_set (renderer, "stock-id",
+ search_action->default_item == item ? GTK_STOCK_YES : NULL,
+ "width", width + 4, NULL);
+ g_object_unref (item);
+}
+
static void
midori_search_action_dialog_render_icon_cb (GtkTreeViewColumn* column,
GtkCellRenderer* renderer,
icon = midori_search_action_get_icon (search_action->net, item, treeview);
g_object_set (renderer, "pixbuf", icon, "yalign", 0.25, NULL);
g_object_unref (icon);
+ g_object_unref (item);
}
static void
markup = g_markup_printf_escaped ("<b>%s</b>\n%s", name, text ? text : "");
g_object_set (renderer, "markup", markup, NULL);
g_free (markup);
+ g_object_unref (item);
}
static void
markup = g_markup_printf_escaped ("<b>%s</b>", token ? token : "");
g_object_set (renderer, "markup", markup, "yalign", 0.0, NULL);
g_free (markup);
+ g_object_unref (item);
}
static void
}
}
+static void
+midori_search_action_dialog_default_cb (GtkWidget* widget,
+ MidoriSearchAction* search_action)
+{
+ KatzeArray* search_engines;
+ GtkWidget* treeview;
+ GtkTreeSelection* selection;
+ GtkTreeModel* liststore;
+ GtkTreeIter iter;
+ KatzeItem* item;
+
+ search_engines = search_action->search_engines;
+ treeview = search_action->treeview;
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
+ if (gtk_tree_selection_get_selected (selection, &liststore, &iter))
+ {
+ gtk_tree_model_get (liststore, &iter, 0, &item, -1);
+ midori_search_action_set_default_item (search_action, item);
+ g_object_unref (item);
+ gtk_widget_queue_draw (treeview);
+ }
+}
+
static void
midori_search_action_treeview_selection_cb (GtkTreeSelection* selection,
MidoriSearchAction* search_action)
gtk_widget_set_sensitive (search_action->edit_button, selected);
gtk_widget_set_sensitive (search_action->remove_button, selected);
+ gtk_widget_set_sensitive (search_action->default_button, selected);
}
static void
KatzeItem* item;
GtkWidget* vbox;
GtkWidget* button;
+ GtkWidget* image;
g_return_val_if_fail (MIDORI_IS_SEARCH_ACTION (search_action), NULL);
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog),
GTK_RESPONSE_HELP, FALSE);
sokoke_widget_get_text_size (dialog, "M", &width, &height);
- gtk_window_set_default_size (GTK_WINDOW (dialog), width * 42, -1);
+ gtk_window_set_default_size (GTK_WINDOW (dialog), width * 52, -1);
g_signal_connect (dialog, "response",
G_CALLBACK (gtk_widget_destroy), dialog);
/* TODO: Do we want tooltips for explainations or can we omit that?
"changed", G_CALLBACK (midori_search_action_treeview_selection_cb),
search_action);
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
+ g_object_set_data (G_OBJECT (treeview), "search-action", search_action);
column = gtk_tree_view_column_new ();
renderer_pixbuf = gtk_cell_renderer_pixbuf_new ();
gtk_tree_view_column_pack_start (column, renderer_pixbuf, FALSE);
- g_object_set_data (G_OBJECT (treeview), "search-action", search_action);
+ gtk_tree_view_column_set_cell_data_func (column, renderer_pixbuf,
+ (GtkTreeCellDataFunc)midori_search_action_dialog_render_tick_cb,
+ treeview, NULL);
+ renderer_pixbuf = gtk_cell_renderer_pixbuf_new ();
+ gtk_tree_view_column_pack_start (column, renderer_pixbuf, FALSE);
gtk_tree_view_column_set_cell_data_func (column, renderer_pixbuf,
(GtkTreeCellDataFunc)midori_search_action_dialog_render_icon_cb,
treeview, NULL);
if (!i)
gtk_widget_set_sensitive (button, FALSE);
button = gtk_label_new (""); /* This is an invisible separator */
+ gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 8);
+ button = gtk_button_new_with_mnemonic ("Use as _default");
+ image = gtk_image_new_from_stock (GTK_STOCK_YES, GTK_ICON_SIZE_BUTTON);
+ gtk_button_set_image (GTK_BUTTON (button), image);
+ search_action->default_button = button;
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (midori_search_action_dialog_default_cb), search_action);
+ gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+ if (!i)
+ gtk_widget_set_sensitive (button, FALSE);
+ button = gtk_label_new (""); /* This is an invisible separator */
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 12);
button = gtk_button_new_from_stock (GTK_STOCK_GO_DOWN);
gtk_widget_set_sensitive (button, FALSE);