Improve location favicon updating
This commit is contained in:
parent
b85bd2d3ef
commit
6a32c93138
1 changed files with 58 additions and 33 deletions
|
@ -188,6 +188,33 @@ midori_location_entry_set_item (GtkTreeModel* model,
|
||||||
g_free (desc);
|
g_free (desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
midori_location_entry_set_active_iter (MidoriLocationEntry* location_entry,
|
||||||
|
GtkTreeIter* iter)
|
||||||
|
{
|
||||||
|
GdkPixbuf* pixbuf;
|
||||||
|
GtkTreeModel* model;
|
||||||
|
GtkWidget* entry;
|
||||||
|
|
||||||
|
entry = gtk_bin_get_child (GTK_BIN (location_entry));
|
||||||
|
|
||||||
|
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (location_entry), iter);
|
||||||
|
|
||||||
|
/* When setting the active iter (when adding or setting an item)
|
||||||
|
* The favicon may have change, so we must update the entry favicon.
|
||||||
|
*/
|
||||||
|
if (entry)
|
||||||
|
{
|
||||||
|
model = gtk_combo_box_get_model (GTK_COMBO_BOX (location_entry));
|
||||||
|
gtk_tree_model_get (model, iter, FAVICON_COL, &pixbuf, -1);
|
||||||
|
|
||||||
|
gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (entry),
|
||||||
|
GTK_ICON_ENTRY_PRIMARY, pixbuf);
|
||||||
|
|
||||||
|
g_object_unref (pixbuf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* midori_location_entry_new:
|
* midori_location_entry_new:
|
||||||
*
|
*
|
||||||
|
@ -202,56 +229,51 @@ midori_location_entry_new (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* midori_location_entry_item_index:
|
* midori_location_entry_item_iter:
|
||||||
* @location_entry: a #MidoriLocationEntry
|
* @location_entry: a #MidoriLocationEntry
|
||||||
* @uri: a string
|
* @uri: a string
|
||||||
|
* @iter: a GtkTreeIter
|
||||||
*
|
*
|
||||||
* Gets the index of the item matching @uri.
|
* Retrieves the iter of the item matching @uri.
|
||||||
*
|
*
|
||||||
* Return value: an integer
|
* Return value: %TRUE if @uri was found, %FALSE otherwise
|
||||||
**/
|
**/
|
||||||
gint
|
gboolean
|
||||||
midori_location_entry_item_index (MidoriLocationEntry* location_entry,
|
midori_location_entry_item_iter (MidoriLocationEntry* location_entry,
|
||||||
const gchar* uri)
|
const gchar* uri,
|
||||||
|
GtkTreeIter* iter)
|
||||||
{
|
{
|
||||||
GtkTreeModel* model;
|
GtkTreeModel* model;
|
||||||
GtkTreeIter iter;
|
|
||||||
gint index;
|
|
||||||
gchar* tmpuri;
|
gchar* tmpuri;
|
||||||
gint tmpindex;
|
gboolean found;
|
||||||
|
|
||||||
g_return_val_if_fail (MIDORI_IS_LOCATION_ENTRY (location_entry), -1);
|
g_return_val_if_fail (MIDORI_IS_LOCATION_ENTRY (location_entry), FALSE);
|
||||||
g_return_val_if_fail (uri != NULL, -1);
|
g_return_val_if_fail (uri != NULL, FALSE);
|
||||||
|
|
||||||
|
found = FALSE;
|
||||||
model = gtk_combo_box_get_model (GTK_COMBO_BOX (location_entry));
|
model = gtk_combo_box_get_model (GTK_COMBO_BOX (location_entry));
|
||||||
|
if (gtk_tree_model_get_iter_first (model, iter))
|
||||||
index = -1;
|
|
||||||
if (gtk_tree_model_get_iter_first (model, &iter))
|
|
||||||
{
|
{
|
||||||
tmpuri = NULL;
|
tmpuri = NULL;
|
||||||
tmpindex = 0;
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
gtk_tree_model_get (model, &iter, URI_COL, &tmpuri, -1);
|
gtk_tree_model_get (model, iter, URI_COL, &tmpuri, -1);
|
||||||
if (g_ascii_strcasecmp (uri, tmpuri) == 0)
|
found = !g_ascii_strcasecmp (uri, tmpuri);
|
||||||
{
|
|
||||||
g_free (tmpuri);
|
|
||||||
index = tmpindex;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
g_free (tmpuri);
|
g_free (tmpuri);
|
||||||
tmpindex++;
|
|
||||||
|
if (found)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
while (gtk_tree_model_iter_next (model, &iter));
|
while (gtk_tree_model_iter_next (model, iter));
|
||||||
}
|
}
|
||||||
return index;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* midori_location_entry_get_text:
|
* midori_location_entry_get_text:
|
||||||
* @location_entry: a #MidoriLocationEntry
|
* @location_entry: a #MidoriLocationEntry
|
||||||
*
|
*
|
||||||
* Gets the entry text.
|
* Retrieves the text of the embedded entry.
|
||||||
*
|
*
|
||||||
* Return value: a string
|
* Return value: a string
|
||||||
**/
|
**/
|
||||||
|
@ -322,16 +344,19 @@ void
|
||||||
midori_location_entry_set_item_from_uri (MidoriLocationEntry* location_entry,
|
midori_location_entry_set_item_from_uri (MidoriLocationEntry* location_entry,
|
||||||
const gchar* uri)
|
const gchar* uri)
|
||||||
{
|
{
|
||||||
gint index;
|
gboolean found;
|
||||||
|
GtkTreeIter iter;
|
||||||
|
|
||||||
g_return_if_fail (MIDORI_IS_LOCATION_ENTRY (location_entry));
|
g_return_if_fail (MIDORI_IS_LOCATION_ENTRY (location_entry));
|
||||||
|
|
||||||
index = midori_location_entry_item_index (
|
found = midori_location_entry_item_iter (MIDORI_LOCATION_ENTRY (location_entry),
|
||||||
MIDORI_LOCATION_ENTRY (location_entry), uri);
|
uri,
|
||||||
gtk_combo_box_set_active (GTK_COMBO_BOX (location_entry), index);
|
&iter);
|
||||||
|
if(found)
|
||||||
if(index == -1)
|
midori_location_entry_set_active_iter (location_entry, &iter);
|
||||||
|
else
|
||||||
midori_location_entry_clear (location_entry);
|
midori_location_entry_clear (location_entry);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -377,6 +402,6 @@ midori_location_entry_add_item (MidoriLocationEntry* location_entry,
|
||||||
gtk_list_store_prepend (GTK_LIST_STORE (model), &iter);
|
gtk_list_store_prepend (GTK_LIST_STORE (model), &iter);
|
||||||
|
|
||||||
midori_location_entry_set_item (model, &iter, item);
|
midori_location_entry_set_item (model, &iter, item);
|
||||||
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (location_entry), &iter);
|
midori_location_entry_set_active_iter (location_entry, &iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue