Finish missing web search functionality
This commit is contained in:
parent
f628b7dc5f
commit
38c48dd9f6
6 changed files with 155 additions and 18 deletions
|
@ -3391,6 +3391,8 @@ midori_browser_set_property (GObject* object,
|
||||||
{
|
{
|
||||||
MidoriBrowser* browser = MIDORI_BROWSER (object);
|
MidoriBrowser* browser = MIDORI_BROWSER (object);
|
||||||
MidoriBrowserPrivate* priv = browser->priv;
|
MidoriBrowserPrivate* priv = browser->priv;
|
||||||
|
guint last_web_search;
|
||||||
|
MidoriWebItem* web_item;
|
||||||
|
|
||||||
switch (prop_id)
|
switch (prop_id)
|
||||||
{
|
{
|
||||||
|
@ -3430,7 +3432,14 @@ midori_browser_set_property (GObject* object,
|
||||||
g_object_set (priv->search, "search-engines",
|
g_object_set (priv->search, "search-engines",
|
||||||
priv->search_engines, NULL);
|
priv->search_engines, NULL);
|
||||||
/* FIXME: Connect to updates */
|
/* FIXME: Connect to updates */
|
||||||
_midori_browser_update_actions (browser);
|
if (priv->settings)
|
||||||
|
{
|
||||||
|
g_object_get (priv->settings, "last-web-search",
|
||||||
|
&last_web_search, NULL);
|
||||||
|
web_item = midori_web_list_get_nth_item (priv->search_engines,
|
||||||
|
last_web_search);
|
||||||
|
g_object_set (priv->search, "current-item", web_item, NULL);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
|
|
@ -159,8 +159,23 @@ midori_search_entry_icon_released_cb (GtkWidget* widget,
|
||||||
NULL, SOKOKE_MENU_POSITION_LEFT);
|
NULL, SOKOKE_MENU_POSITION_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_midori_search_entry_move_index (MidoriSearchEntry* search_entry,
|
||||||
|
guint n)
|
||||||
|
{
|
||||||
|
gint i;
|
||||||
|
MidoriWebItem* web_item;
|
||||||
|
|
||||||
|
i = midori_web_list_get_item_index (search_entry->search_engines,
|
||||||
|
search_entry->current_item);
|
||||||
|
web_item = midori_web_list_get_nth_item (search_entry->search_engines,
|
||||||
|
i + n);
|
||||||
|
if (web_item)
|
||||||
|
midori_search_entry_set_current_item (search_entry, web_item);
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
midori_search_entry_key_press_event_cb (GtkWidget* widget,
|
midori_search_entry_key_press_event_cb (MidoriSearchEntry* search_entry,
|
||||||
GdkEventKey* event)
|
GdkEventKey* event)
|
||||||
{
|
{
|
||||||
GdkModifierType state;
|
GdkModifierType state;
|
||||||
|
@ -172,26 +187,59 @@ midori_search_entry_key_press_event_cb (GtkWidget* widget,
|
||||||
switch (event->keyval)
|
switch (event->keyval)
|
||||||
{
|
{
|
||||||
case GDK_Up:
|
case GDK_Up:
|
||||||
/* update_searchEngine(config->searchEngine - 1, browser); */
|
_midori_search_entry_move_index (search_entry, - 1);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
case GDK_Down:
|
case GDK_Down:
|
||||||
/* update_searchEngine(config->searchEngine + 1, browser); */
|
_midori_search_entry_move_index (search_entry, + 1);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
midori_search_entry_scroll_event_cb (GtkWidget* widget,
|
midori_search_entry_scroll_event_cb (MidoriSearchEntry* search_entry,
|
||||||
GdkEventScroll* event)
|
GdkEventScroll* event)
|
||||||
{
|
{
|
||||||
if (event->direction == GDK_SCROLL_DOWN)
|
if (event->direction == GDK_SCROLL_DOWN)
|
||||||
; /* update_searchEngine(config->searchEngine + 1, browser); */
|
_midori_search_entry_move_index (search_entry, + 1);
|
||||||
else if (event->direction == GDK_SCROLL_UP)
|
else if (event->direction == GDK_SCROLL_UP)
|
||||||
; /* update_searchEngine(config->searchEngine - 1, browser); */
|
_midori_search_entry_move_index (search_entry, - 1);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
midori_search_entry_engines_add_item_cb (MidoriWebList* web_list,
|
||||||
|
MidoriWebItem* item,
|
||||||
|
MidoriSearchEntry* search_entry)
|
||||||
|
{
|
||||||
|
if (!search_entry->current_item)
|
||||||
|
midori_search_entry_set_current_item (search_entry, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
midori_search_entry_engines_remove_item_cb (MidoriWebList* web_list,
|
||||||
|
MidoriWebItem* item,
|
||||||
|
MidoriSearchEntry* search_entry)
|
||||||
|
{
|
||||||
|
MidoriWebItem* web_item;
|
||||||
|
|
||||||
|
if (search_entry->current_item == item)
|
||||||
|
{
|
||||||
|
web_item = midori_web_list_get_nth_item (web_list, 0);
|
||||||
|
if (web_item)
|
||||||
|
midori_search_entry_set_current_item (search_entry, web_item);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sexy_icon_entry_set_icon (SEXY_ICON_ENTRY (search_entry),
|
||||||
|
SEXY_ICON_ENTRY_PRIMARY, NULL);
|
||||||
|
sokoke_entry_set_default_text (GTK_ENTRY (search_entry), "");
|
||||||
|
|
||||||
|
katze_object_assign (search_entry->current_item, NULL);
|
||||||
|
g_object_notify (G_OBJECT (search_entry), "current-item");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
midori_search_entry_init (MidoriSearchEntry* search_entry)
|
midori_search_entry_init (MidoriSearchEntry* search_entry)
|
||||||
{
|
{
|
||||||
|
@ -210,6 +258,13 @@ midori_search_entry_init (MidoriSearchEntry* search_entry)
|
||||||
"signal::scroll-event",
|
"signal::scroll-event",
|
||||||
midori_search_entry_scroll_event_cb, NULL,
|
midori_search_entry_scroll_event_cb, NULL,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
g_object_connect (search_entry->search_engines,
|
||||||
|
"signal-after::add-item",
|
||||||
|
midori_search_entry_engines_add_item_cb, search_entry,
|
||||||
|
"signal-after::remove-item",
|
||||||
|
midori_search_entry_engines_remove_item_cb, search_entry,
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -218,6 +273,7 @@ midori_search_entry_finalize (GObject* object)
|
||||||
MidoriSearchEntry* search_entry = MIDORI_SEARCH_ENTRY (object);
|
MidoriSearchEntry* search_entry = MIDORI_SEARCH_ENTRY (object);
|
||||||
|
|
||||||
g_object_unref (search_entry->search_engines);
|
g_object_unref (search_entry->search_engines);
|
||||||
|
g_object_unref (search_entry->current_item);
|
||||||
|
|
||||||
G_OBJECT_CLASS (midori_search_entry_parent_class)->finalize (object);
|
G_OBJECT_CLASS (midori_search_entry_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
@ -233,10 +289,12 @@ midori_search_entry_set_property (GObject* object,
|
||||||
switch (prop_id)
|
switch (prop_id)
|
||||||
{
|
{
|
||||||
case PROP_SEARCH_ENGINES:
|
case PROP_SEARCH_ENGINES:
|
||||||
search_entry->search_engines = g_value_get_object (value);
|
midori_search_entry_set_search_engines (search_entry,
|
||||||
|
g_value_get_object (value));
|
||||||
break;
|
break;
|
||||||
case PROP_CURRENT_ITEM:
|
case PROP_CURRENT_ITEM:
|
||||||
search_entry->current_item = g_value_get_object (value);
|
midori_search_entry_set_current_item (search_entry,
|
||||||
|
g_value_get_object (value));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
@ -316,6 +374,13 @@ midori_search_entry_set_search_engines (MidoriSearchEntry* search_entry,
|
||||||
g_object_ref (search_engines);
|
g_object_ref (search_engines);
|
||||||
katze_object_assign (search_entry->search_engines, search_engines);
|
katze_object_assign (search_entry->search_engines, search_engines);
|
||||||
g_object_notify (G_OBJECT (search_entry), "search-engines");
|
g_object_notify (G_OBJECT (search_entry), "search-engines");
|
||||||
|
|
||||||
|
g_object_connect (search_engines,
|
||||||
|
"signal-after::add-item",
|
||||||
|
midori_search_entry_engines_add_item_cb, search_entry,
|
||||||
|
"signal-after::remove-item",
|
||||||
|
midori_search_entry_engines_remove_item_cb, search_entry,
|
||||||
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -345,7 +410,9 @@ midori_search_entry_set_current_item (MidoriSearchEntry* search_entry,
|
||||||
g_object_unref (pixbuf);
|
g_object_unref (pixbuf);
|
||||||
sokoke_entry_set_default_text (GTK_ENTRY (search_entry),
|
sokoke_entry_set_default_text (GTK_ENTRY (search_entry),
|
||||||
midori_web_item_get_name (web_item));
|
midori_web_item_get_name (web_item));
|
||||||
search_entry->current_item = web_item;
|
|
||||||
|
g_object_ref (web_item);
|
||||||
|
katze_object_assign (search_entry->current_item, web_item);
|
||||||
g_object_notify (G_OBJECT (search_entry), "current-item");
|
g_object_notify (G_OBJECT (search_entry), "current-item");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -608,6 +675,20 @@ midori_search_entry_dialog_remove_cb (GtkWidget* widget,
|
||||||
/* FIXME: we want to allow undo of some kind */
|
/* FIXME: we want to allow undo of some kind */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
midori_search_entry_treeview_selection_cb (GtkWidget* treeview,
|
||||||
|
MidoriSearchEntry* search_entry)
|
||||||
|
{
|
||||||
|
GtkTreeSelection* selection;
|
||||||
|
gboolean selected;
|
||||||
|
|
||||||
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (search_entry->treeview));
|
||||||
|
selected = gtk_tree_selection_get_selected (selection, NULL, NULL);
|
||||||
|
|
||||||
|
gtk_widget_set_sensitive (search_entry->edit_button, selected);
|
||||||
|
gtk_widget_set_sensitive (search_entry->remove_button, selected);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* midori_search_entry_get_dialog:
|
* midori_search_entry_get_dialog:
|
||||||
* @search_entry: a #MidoriSearchEntry
|
* @search_entry: a #MidoriSearchEntry
|
||||||
|
@ -670,6 +751,11 @@ midori_search_entry_get_dialog (MidoriSearchEntry* search_entry)
|
||||||
TRUE, TRUE, 12);
|
TRUE, TRUE, 12);
|
||||||
liststore = gtk_list_store_new (1, MIDORI_TYPE_WEB_ITEM);
|
liststore = gtk_list_store_new (1, MIDORI_TYPE_WEB_ITEM);
|
||||||
treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (liststore));
|
treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (liststore));
|
||||||
|
/*g_signal_connect (treeview, "cursor-changed",
|
||||||
|
G_CALLBACK (midori_search_entry_treeview_selection_cb), search_entry);*/
|
||||||
|
g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)),
|
||||||
|
"changed", G_CALLBACK (midori_search_entry_treeview_selection_cb),
|
||||||
|
search_entry);
|
||||||
search_entry->treeview = treeview;
|
search_entry->treeview = treeview;
|
||||||
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
|
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
|
||||||
column = gtk_tree_view_column_new ();
|
column = gtk_tree_view_column_new ();
|
||||||
|
|
|
@ -46,6 +46,13 @@ midori_search_entry_get_type (void);
|
||||||
GtkWidget*
|
GtkWidget*
|
||||||
midori_search_entry_new (void);
|
midori_search_entry_new (void);
|
||||||
|
|
||||||
|
MidoriWebList*
|
||||||
|
midori_search_entry_get_search_engines (MidoriSearchEntry* search_entry);
|
||||||
|
|
||||||
|
void
|
||||||
|
midori_search_entry_set_search_engines (MidoriSearchEntry* search_entry,
|
||||||
|
MidoriWebList* name);
|
||||||
|
|
||||||
MidoriWebItem*
|
MidoriWebItem*
|
||||||
midori_search_entry_get_current_item (MidoriSearchEntry* search_entry);
|
midori_search_entry_get_current_item (MidoriSearchEntry* search_entry);
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@ _midori_web_list_remove_item (MidoriWebList* web_list,
|
||||||
MidoriWebItem* web_item)
|
MidoriWebItem* web_item)
|
||||||
{
|
{
|
||||||
web_list->items = g_list_remove (web_list->items, web_item);
|
web_list->items = g_list_remove (web_list->items, web_item);
|
||||||
|
g_object_unref (web_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -148,7 +149,7 @@ midori_web_list_remove_item (MidoriWebList* web_list,
|
||||||
* @web_list: a #MidoriWebList
|
* @web_list: a #MidoriWebList
|
||||||
* @n: an index in the list
|
* @n: an index in the list
|
||||||
*
|
*
|
||||||
* Retrieves the item in @web_list at the index @n.
|
* Retrieves the item in @web_list at the position @n.
|
||||||
*
|
*
|
||||||
* Return value: an item, or %NULL
|
* Return value: an item, or %NULL
|
||||||
**/
|
**/
|
||||||
|
@ -161,6 +162,25 @@ midori_web_list_get_nth_item (MidoriWebList* web_list,
|
||||||
return g_list_nth_data (web_list->items, n);
|
return g_list_nth_data (web_list->items, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* midori_web_list_get_item_position:
|
||||||
|
* @web_list: a #MidoriWebList
|
||||||
|
* @item: an item in the list
|
||||||
|
*
|
||||||
|
* Retrieves the index of the item in @web_list.
|
||||||
|
*
|
||||||
|
* Return value: an item, or -1
|
||||||
|
**/
|
||||||
|
gint
|
||||||
|
midori_web_list_get_item_index (MidoriWebList* web_list,
|
||||||
|
MidoriWebItem* web_item)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (MIDORI_IS_WEB_LIST (web_list), -1);
|
||||||
|
g_return_val_if_fail (MIDORI_IS_WEB_ITEM (web_item), -1);
|
||||||
|
|
||||||
|
return g_list_index (web_list->items, web_item);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* midori_web_list_find_token:
|
* midori_web_list_find_token:
|
||||||
* @web_list: a #MidoriWebList
|
* @web_list: a #MidoriWebList
|
||||||
|
|
|
@ -63,6 +63,10 @@ MidoriWebItem*
|
||||||
midori_web_list_get_nth_item (MidoriWebList* web_list,
|
midori_web_list_get_nth_item (MidoriWebList* web_list,
|
||||||
guint n);
|
guint n);
|
||||||
|
|
||||||
|
gint
|
||||||
|
midori_web_list_get_item_index (MidoriWebList* web_list,
|
||||||
|
MidoriWebItem* web_item);
|
||||||
|
|
||||||
MidoriWebItem*
|
MidoriWebItem*
|
||||||
midori_web_list_find_token (MidoriWebList* web_list,
|
midori_web_list_find_token (MidoriWebList* web_list,
|
||||||
const gchar* token);
|
const gchar* token);
|
||||||
|
|
|
@ -340,9 +340,9 @@ sokoke_on_entry_focus_in_event (GtkEntry* entry,
|
||||||
GdkEventFocus* event,
|
GdkEventFocus* event,
|
||||||
gpointer userdata)
|
gpointer userdata)
|
||||||
{
|
{
|
||||||
gint default_text = GPOINTER_TO_INT (
|
gint has_default = GPOINTER_TO_INT (
|
||||||
g_object_get_data (G_OBJECT (entry), "sokoke_has_default"));
|
g_object_get_data (G_OBJECT (entry), "sokoke_has_default"));
|
||||||
if (default_text)
|
if (has_default)
|
||||||
{
|
{
|
||||||
gtk_entry_set_text (entry, "");
|
gtk_entry_set_text (entry, "");
|
||||||
g_object_set_data (G_OBJECT(entry), "sokoke_has_default",
|
g_object_set_data (G_OBJECT(entry), "sokoke_has_default",
|
||||||
|
@ -361,9 +361,9 @@ sokoke_on_entry_focus_out_event (GtkEntry* entry,
|
||||||
const gchar* text = gtk_entry_get_text (entry);
|
const gchar* text = gtk_entry_get_text (entry);
|
||||||
if (text && !*text)
|
if (text && !*text)
|
||||||
{
|
{
|
||||||
const gchar* defaultText = (const gchar*)g_object_get_data (
|
const gchar* default_text = (const gchar*)g_object_get_data (
|
||||||
G_OBJECT (entry), "sokoke_default_text");
|
G_OBJECT (entry), "sokoke_default_text");
|
||||||
gtk_entry_set_text (entry, defaultText);
|
gtk_entry_set_text (entry, default_text);
|
||||||
g_object_set_data (G_OBJECT(entry),
|
g_object_set_data (G_OBJECT(entry),
|
||||||
"sokoke_has_default", GINT_TO_POINTER (1));
|
"sokoke_has_default", GINT_TO_POINTER (1));
|
||||||
sokoke_widget_set_pango_font_style (GTK_WIDGET (entry),
|
sokoke_widget_set_pango_font_style (GTK_WIDGET (entry),
|
||||||
|
@ -387,6 +387,17 @@ sokoke_entry_set_default_text (GtkEntry* entry,
|
||||||
PANGO_STYLE_ITALIC);
|
PANGO_STYLE_ITALIC);
|
||||||
gtk_entry_set_text (entry, default_text);
|
gtk_entry_set_text (entry, default_text);
|
||||||
}
|
}
|
||||||
|
else if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET (entry)))
|
||||||
|
{
|
||||||
|
gint has_default = GPOINTER_TO_INT (
|
||||||
|
g_object_get_data (G_OBJECT (entry), "sokoke_has_default"));
|
||||||
|
if (has_default)
|
||||||
|
{
|
||||||
|
gtk_entry_set_text (entry, default_text);
|
||||||
|
sokoke_widget_set_pango_font_style (GTK_WIDGET (entry),
|
||||||
|
PANGO_STYLE_ITALIC);
|
||||||
|
}
|
||||||
|
}
|
||||||
g_object_set_data (G_OBJECT (entry), "sokoke_default_text",
|
g_object_set_data (G_OBJECT (entry), "sokoke_default_text",
|
||||||
(gpointer)default_text);
|
(gpointer)default_text);
|
||||||
g_signal_connect (entry, "focus-in-event",
|
g_signal_connect (entry, "focus-in-event",
|
||||||
|
|
Loading…
Reference in a new issue