diff --git a/katze/katze-item.c b/katze/katze-item.c index 3cc437f1..787995d8 100644 --- a/katze/katze-item.c +++ b/katze/katze-item.c @@ -35,8 +35,7 @@ enum PROP_URI, PROP_ICON, PROP_TOKEN, - PROP_ADDED, - PROP_VISITS + PROP_ADDED }; static void @@ -123,17 +122,6 @@ katze_item_class_init (KatzeItemClass* class) 0, flags)); - g_object_class_install_property (gobject_class, - PROP_VISITS, - g_param_spec_int ( - "visits", - "Visits", - "The number of visits of the item", - G_MININT, - G_MAXINT, - 0, - flags)); - } @@ -186,9 +174,6 @@ katze_item_set_property (GObject* object, case PROP_ADDED: item->added = g_value_get_int64 (value); break; - case PROP_VISITS: - item->visits = g_value_get_int (value); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -223,9 +208,6 @@ katze_item_get_property (GObject* object, case PROP_ADDED: g_value_set_int64 (value, item->added); break; - case PROP_VISITS: - g_value_set_int (value, item->visits); - break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -445,39 +427,6 @@ katze_item_set_added (KatzeItem* item, g_object_notify (G_OBJECT (item), "added"); } -/** - * katze_item_get_visits: - * @item: a #KatzeItem - * - * Retrieves the number of visits of @item. - * - * Return value: the number of visits - **/ -gint -katze_item_get_visits (KatzeItem* item) -{ - g_return_val_if_fail (KATZE_IS_ITEM (item), -1); - - return item->visits; -} - -/** - * katze_item_set_visits: - * @item: a #KatzeItem - * @visits: an integer - * - * Sets the number of visits of @item. - **/ -void -katze_item_set_visits (KatzeItem* item, - gint visits) -{ - g_return_if_fail (KATZE_IS_ITEM (item)); - - item->visits = visits; - g_object_notify (G_OBJECT (item), "visits"); -} - /** * katze_item_get_parent: * @item: a #KatzeItem diff --git a/katze/katze-item.h b/katze/katze-item.h index 6aceb449..add88de1 100644 --- a/katze/katze-item.h +++ b/katze/katze-item.h @@ -42,7 +42,6 @@ struct _KatzeItem gchar* icon; gchar* token; gint64 added; - gint visits; KatzeItem* parent; }; @@ -100,13 +99,6 @@ void katze_item_set_added (KatzeItem* item, gint64 added); -gint -katze_item_get_visits (KatzeItem* item); - -void -katze_item_set_visits (KatzeItem* item, - gint visits); - gpointer katze_item_get_parent (KatzeItem* item); diff --git a/midori/main.c b/midori/main.c index d5735b98..550e5722 100644 --- a/midori/main.c +++ b/midori/main.c @@ -668,11 +668,10 @@ midori_history_remove_item_cb (KatzeArray* history, sqlcmd = g_strdup_printf ( "DELETE FROM history WHERE uri = '%s' AND" - " title = '%s' AND date = %" G_GINT64_FORMAT " AND visits = %d", + " title = '%s' AND date = %" G_GINT64_FORMAT, katze_item_get_uri (item), katze_item_get_name (item), - katze_item_get_added (item), - katze_item_get_visits (item)); + katze_item_get_added (item)); success = db_exec (db, sqlcmd, &error); if (!success) { @@ -739,11 +738,10 @@ midori_history_add_item_cb (KatzeArray* array, } } sqlcmd = g_strdup_printf ("INSERT INTO history VALUES" - "('%s', '%s', %" G_GUINT64_FORMAT ", %d)", + "('%s', '%s', %" G_GUINT64_FORMAT ", -1)", katze_item_get_uri (item), katze_item_get_name (item), - katze_item_get_added (item), - katze_item_get_visits (item)); + katze_item_get_added (item)); success = db_exec (db, sqlcmd, &error); g_free (sqlcmd); if (!success) @@ -766,7 +764,7 @@ midori_history_add_items (void* data, gint64 date; time_t newdate; gint i, j, n; - gint ncols = 4; + gint ncols = 3; g_return_val_if_fail (KATZE_IS_ARRAY (array), 1); @@ -779,15 +777,13 @@ midori_history_add_items (void* data, { if (colname[i] && !g_ascii_strcasecmp (colname[i], "uri") && colname[i + 1] && !g_ascii_strcasecmp (colname[i + 1], "title") && - colname[i + 2] && !g_ascii_strcasecmp (colname[i + 2], "date") && - colname[i + 3] && !g_ascii_strcasecmp (colname[i + 3], "visits")) + colname[i + 2] && !g_ascii_strcasecmp (colname[i + 2], "date")) { item = katze_item_new (); katze_item_set_uri (item, argv[i]); katze_item_set_name (item, argv[i + 1]); date = g_ascii_strtoull (argv[i + 2], NULL, 10); katze_item_set_added (item, date); - katze_item_set_visits (item, atoi (argv[i + 3])); n = katze_array_get_length (array); for (j = 0; j < n; j++) @@ -829,7 +825,7 @@ midori_history_initialize (KatzeArray* array, return NULL; if (!db_exec_callback (db, - "SELECT uri, title, date, visits FROM history " + "SELECT uri, title, date FROM history " "ORDER BY date ASC", midori_history_add_items, array, diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 492f930e..1b5eb90a 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -454,7 +454,6 @@ midori_view_notify_title_cb (GtkWidget* view, item = katze_item_new (); katze_item_set_uri (item, uri); katze_item_set_name (item, title); - katze_item_set_visits (item, -1); midori_browser_new_history_item (browser, item); } @@ -2491,15 +2490,19 @@ midori_panel_history_key_release_event_cb (GtkWidget* widget, GtkTreeModel* model; GtkTreeIter iter; KatzeItem* item; + GtkAction* location_action; - if (event->keyval == GDK_Delete) + if (event->keyval != GDK_Delete) + return FALSE; + + treeview = GTK_TREE_VIEW (widget); + if (sokoke_tree_view_get_selected_iter (treeview, &model, &iter)) { - treeview = GTK_TREE_VIEW (widget); - if (sokoke_tree_view_get_selected_iter (treeview, &model, &iter)) - { - gtk_tree_model_get (model, &iter, 0, &item, -1); - midori_browser_model_remove_item (model, item, &iter); - } + location_action = _action_by_name (browser, "Location"); + gtk_tree_model_get (model, &iter, 0, &item, -1); + midori_browser_model_remove_item (model, item, &iter); + midori_location_action_delete_item_from_uri ( + MIDORI_LOCATION_ACTION (location_action), katze_item_get_uri (item)); } return FALSE; @@ -2913,12 +2916,16 @@ _action_history_delete_activate (GtkAction* action, GtkTreeModel* model; GtkTreeIter iter; KatzeItem* item; + GtkAction* location_action; treeview = GTK_TREE_VIEW (browser->panel_history); if (sokoke_tree_view_get_selected_iter (treeview, &model, &iter)) { + location_action = _action_by_name (browser, "Location"); gtk_tree_model_get (model, &iter, 0, &item, -1); midori_browser_model_remove_item (model, item, &iter); + midori_location_action_delete_item_from_uri ( + MIDORI_LOCATION_ACTION (location_action), katze_item_get_uri (item)); } } @@ -2930,6 +2937,7 @@ _action_history_clear_activate (GtkAction* action, GtkTreeView* tree_view; GtkTreeStore* store; KatzeItem* item; + GtkAction* location_action; gint i, n; gint result; @@ -2945,6 +2953,7 @@ _action_history_clear_activate (GtkAction* action, if (result != GTK_RESPONSE_YES) return; + location_action = _action_by_name (browser, "Location"); tree_view = GTK_TREE_VIEW (browser->panel_history); store = GTK_TREE_STORE (gtk_tree_view_get_model (tree_view)); gtk_tree_store_clear (store); @@ -2956,6 +2965,7 @@ _action_history_clear_activate (GtkAction* action, katze_array_clear (KATZE_ARRAY (item)); } katze_array_clear (browser->history); + midori_location_action_clear (MIDORI_LOCATION_ACTION (location_action)); } static void diff --git a/midori/midori-locationaction.c b/midori/midori-locationaction.c index 9145d276..90d1ae46 100644 --- a/midori/midori-locationaction.c +++ b/midori/midori-locationaction.c @@ -456,7 +456,6 @@ midori_location_action_add_uri (MidoriLocationAction* location_action, g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action)); g_return_if_fail (uri != NULL); - katze_assign (location_action->uri, g_strdup (uri)); proxies = gtk_action_get_proxies (GTK_ACTION (location_action)); @@ -660,3 +659,54 @@ midori_location_action_set_secondary_icon (MidoriLocationAction* location_action } while ((proxies = g_slist_next (proxies))); } + +void +midori_location_action_delete_item_from_uri (MidoriLocationAction* location_action, + const gchar* uri) +{ + GSList* proxies; + GtkWidget* alignment; + GtkWidget* entry; + + g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action)); + g_return_if_fail (uri != NULL); + + proxies = gtk_action_get_proxies (GTK_ACTION (location_action)); + if (!proxies) + return; + + do + if (GTK_IS_TOOL_ITEM (proxies->data)) + { + alignment = gtk_bin_get_child (GTK_BIN (proxies->data)); + entry = gtk_bin_get_child (GTK_BIN (alignment)); + + midori_location_entry_delete_item_from_uri + (MIDORI_LOCATION_ENTRY (entry), uri); + } + while ((proxies = g_slist_next (proxies))); +} + +void +midori_location_action_clear (MidoriLocationAction* location_action) +{ + GSList* proxies; + GtkWidget* alignment; + GtkWidget* entry; + + g_return_if_fail (MIDORI_IS_LOCATION_ACTION (location_action)); + + proxies = gtk_action_get_proxies (GTK_ACTION (location_action)); + if (!proxies) + return; + + do + if (GTK_IS_TOOL_ITEM (proxies->data)) + { + alignment = gtk_bin_get_child (GTK_BIN (proxies->data)); + entry = gtk_bin_get_child (GTK_BIN (alignment)); + + midori_location_entry_clear (MIDORI_LOCATION_ENTRY (entry)); + } + while ((proxies = g_slist_next (proxies))); +} diff --git a/midori/midori-locationaction.h b/midori/midori-locationaction.h index ba6da7bb..5a8f53de 100644 --- a/midori/midori-locationaction.h +++ b/midori/midori-locationaction.h @@ -35,44 +35,51 @@ typedef struct _MidoriLocationAction MidoriLocationAction; typedef struct _MidoriLocationActionClass MidoriLocationActionClass; GType -midori_location_action_get_type (void); +midori_location_action_get_type (void); const gchar* -midori_location_action_get_uri (MidoriLocationAction* action); +midori_location_action_get_uri (MidoriLocationAction* action); void -midori_location_action_set_uri (MidoriLocationAction* location_action, - const gchar* uri); +midori_location_action_set_uri (MidoriLocationAction* location_action, + const gchar* uri); void -midori_location_action_add_uri (MidoriLocationAction* location_action, - const gchar* uri); +midori_location_action_add_uri (MidoriLocationAction* location_action, + const gchar* uri); void -midori_location_action_add_item (MidoriLocationAction* location_action, - const gchar* uri, - GdkPixbuf* icon, - const gchar* title); +midori_location_action_add_item (MidoriLocationAction* location_action, + const gchar* uri, + GdkPixbuf* icon, + const gchar* title); void -midori_location_action_set_icon_for_uri (MidoriLocationAction* location_action, - GdkPixbuf* icon, - const gchar* text); +midori_location_action_set_icon_for_uri (MidoriLocationAction* location_action, + GdkPixbuf* icon, + const gchar* text); void -midori_location_action_set_title_for_uri (MidoriLocationAction* location_action, - const gchar* title, - const gchar* text); +midori_location_action_set_title_for_uri (MidoriLocationAction* location_action, + const gchar* title, + const gchar* text); gdouble -midori_location_action_get_progress (MidoriLocationAction* location_action); +midori_location_action_get_progress (MidoriLocationAction* location_action); void -midori_location_action_set_progress (MidoriLocationAction* location_action, - gdouble progress); +midori_location_action_set_progress (MidoriLocationAction* location_action, + gdouble progress); void -midori_location_action_set_secondary_icon (MidoriLocationAction* location_action, - const gchar* stock_id); +midori_location_action_set_secondary_icon (MidoriLocationAction* location_action, + const gchar* stock_id); + +void +midori_location_action_delete_item_from_uri (MidoriLocationAction* location_action, + const gchar* uri); + +void +midori_location_action_clear (MidoriLocationAction* location_action); G_END_DECLS diff --git a/midori/midori-locationentry.c b/midori/midori-locationentry.c index 7add46bd..6170c8dd 100644 --- a/midori/midori-locationentry.c +++ b/midori/midori-locationentry.c @@ -18,6 +18,7 @@ #define DEFAULT_ICON GTK_STOCK_FILE #define MAX_ITEMS 25 +/* #define ORDER_BY_VISITS 1 */ struct _MidoriLocationEntry { @@ -31,13 +32,15 @@ struct _MidoriLocationEntryClass GtkComboBoxEntryClass parent_class; }; -G_DEFINE_TYPE (MidoriLocationEntry, midori_location_entry, GTK_TYPE_COMBO_BOX_ENTRY) +G_DEFINE_TYPE (MidoriLocationEntry, + midori_location_entry, GTK_TYPE_COMBO_BOX_ENTRY) enum { FAVICON_COL, URI_COL, TITLE_COL, + VISITS_COL, VISIBLE_COL, N_COLS }; @@ -74,18 +77,78 @@ midori_location_entry_class_init (MidoriLocationEntryClass* class) } static GtkTreeModel* -midori_location_entry_get_model (MidoriLocationEntry* location_entry) +midori_location_entry_get_filter_model (MidoriLocationEntry* location_entry) +{ + return gtk_combo_box_get_model (GTK_COMBO_BOX (location_entry)); +} + +static GtkTreeModel* +midori_location_entry_get_sort_model (MidoriLocationEntry* location_entry) { GtkTreeModel* model; GtkTreeModelFilter* filter_model; - model = gtk_combo_box_get_model (GTK_COMBO_BOX (location_entry)); + model = midori_location_entry_get_filter_model (location_entry); filter_model = GTK_TREE_MODEL_FILTER (model); g_assert (filter_model); return gtk_tree_model_filter_get_model (filter_model); } +static GtkTreeModel* +midori_location_entry_get_model (MidoriLocationEntry* location_entry) +{ + + GtkTreeModel* model; +#ifdef ORDER_BY_VISITS + GtkTreeModelSort* sort_model; +#endif + + model = midori_location_entry_get_sort_model (location_entry); + +#ifdef ORDER_BY_VISITS + sort_model = GTK_TREE_MODEL_SORT (model); + g_assert (sort_model); + + return gtk_tree_model_sort_get_model (sort_model); +#else + return GTK_IS_TREE_MODEL (model) ? model : NULL; +#endif + +} + +static gboolean +midori_location_entry_child_iter_to_iter (MidoriLocationEntry* location_entry, + GtkTreeIter* iter, + GtkTreeIter* child_iter) +{ + GtkTreeModel* filter_model; +#ifdef ORDER_BY_VISITS + GtkTreeModel* sort_model; + GtkTreeIter sort_iter; +#endif + GtkTreeIter* temp_iter; + + temp_iter = child_iter; + + filter_model = midori_location_entry_get_filter_model (location_entry); + +#ifdef ORDER_BY_VISITS + sort_model = midori_location_entry_get_sort_model (location_entry); + + g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (filter_model) && + GTK_IS_TREE_MODEL_SORT (sort_model), FALSE); + + gtk_tree_model_sort_convert_child_iter_to_iter + (GTK_TREE_MODEL_SORT (sort_model), &sort_iter, child_iter); + + temp_iter = &sort_iter; +#endif + + return gtk_tree_model_filter_convert_child_iter_to_iter + (GTK_TREE_MODEL_FILTER (filter_model), iter, temp_iter); +} + #define HAVE_ENTRY_PROGRESS 1 #ifdef HAVE_ENTRY_PROGRESS @@ -565,7 +628,7 @@ midori_location_entry_completion_init (MidoriLocationEntry* location_entry) completion = gtk_entry_completion_new (); gtk_entry_completion_set_model (GTK_ENTRY_COMPLETION (completion), - midori_location_entry_get_model (location_entry)); + midori_location_entry_get_sort_model (location_entry)); gtk_entry_completion_set_text_column (GTK_ENTRY_COMPLETION (completion), URI_COL); gtk_cell_layout_clear (GTK_CELL_LAYOUT (completion)); @@ -597,6 +660,9 @@ midori_location_entry_init (MidoriLocationEntry* location_entry) GtkListStore* store; GtkCellRenderer* renderer; GtkTreeModel* filter_model; +#ifdef ORDER_BY_VISITS + GtkTreeModel* sort_model; +#endif /* we want the widget to have appears-as-list applied */ gtk_rc_parse_string ("style \"midori-location-entry-style\" {\n" @@ -620,8 +686,18 @@ midori_location_entry_init (MidoriLocationEntry* location_entry) gtk_container_add (GTK_CONTAINER (location_entry), entry); store = gtk_list_store_new (N_COLS, - GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN); + GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, + G_TYPE_INT, G_TYPE_BOOLEAN); + +#ifdef ORDER_BY_VISITS + sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (store)); + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model), + VISITS_COL, GTK_SORT_DESCENDING); + filter_model = gtk_tree_model_filter_new (GTK_TREE_MODEL (sort_model), NULL); +#else filter_model = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL); +#endif + gtk_tree_model_filter_set_visible_column ( GTK_TREE_MODEL_FILTER (filter_model), VISIBLE_COL); g_object_set (location_entry, "model", filter_model, NULL); @@ -687,7 +763,8 @@ midori_location_entry_changed (GtkComboBox* combo_box, { pixbuf = NULL; - model = gtk_combo_box_get_model (combo_box); + model = midori_location_entry_get_filter_model + (MIDORI_LOCATION_ENTRY (combo_box)); gtk_tree_model_get (model, &iter, FAVICON_COL, &pixbuf, -1); gtk_icon_entry_set_icon_from_pixbuf (GTK_ICON_ENTRY (entry), @@ -736,22 +813,19 @@ midori_location_entry_set_active_iter (MidoriLocationEntry* location_entry, GdkPixbuf* pixbuf; GtkTreeModel* model; GtkWidget* entry; - GtkTreeModel* filter_model; - GtkTreeIter filter_iter; + GtkTreeIter parent_iter; entry = gtk_bin_get_child (GTK_BIN (location_entry)); - model = midori_location_entry_get_model (location_entry); - filter_model = gtk_combo_box_get_model (GTK_COMBO_BOX (location_entry)); /* The filter iter must be set, not the child iter, * but the row must first be set as visible to * convert to a filter iter without error. */ gtk_list_store_set (GTK_LIST_STORE (model), iter, VISIBLE_COL, TRUE, -1); - gtk_tree_model_filter_convert_child_iter_to_iter ( - GTK_TREE_MODEL_FILTER (filter_model), &filter_iter, iter); - gtk_combo_box_set_active_iter (GTK_COMBO_BOX (location_entry), &filter_iter); + if (midori_location_entry_child_iter_to_iter ( + location_entry, &parent_iter, iter)) + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (location_entry), &parent_iter); /* When setting the active iter (when adding or setting an item) * the favicon may have changed, so we must update the entry favicon. @@ -777,7 +851,7 @@ midori_location_entry_set_active_iter (MidoriLocationEntry* location_entry, GtkWidget* midori_location_entry_new (void) { - return (g_object_new (MIDORI_TYPE_LOCATION_ENTRY, NULL)); + return g_object_new (MIDORI_TYPE_LOCATION_ENTRY, NULL); } /** @@ -878,13 +952,13 @@ midori_location_entry_set_text (MidoriLocationEntry* location_entry, } /** - * midori_location_entry_clear: + * midori_location_entry_reset: * @location_entry: a #MidoriLocationEntry * * Clears the entry text and resets the entry favicon. **/ void -midori_location_entry_clear (MidoriLocationEntry* location_entry) +midori_location_entry_reset (MidoriLocationEntry* location_entry) { GtkWidget* entry; @@ -898,6 +972,23 @@ midori_location_entry_clear (MidoriLocationEntry* location_entry) GTK_ICON_ENTRY_PRIMARY, DEFAULT_ICON); } +/** + * midori_location_entry_clear: + * @location_entry: a #MidoriLocationEntry + * + * Removes all items from @location_entry + **/ +void +midori_location_entry_clear (MidoriLocationEntry* location_entry) +{ + GtkTreeModel* model; + + g_return_if_fail (MIDORI_IS_LOCATION_ENTRY (location_entry)); + + model = midori_location_entry_get_model (location_entry); + gtk_list_store_clear (GTK_LIST_STORE (model)); +} + /** * midori_location_entry_set_item_from_uri: * @location_entry: a #MidoriLocationEntry @@ -917,7 +1008,7 @@ midori_location_entry_set_item_from_uri (MidoriLocationEntry* location_entry, if (midori_location_entry_item_iter (location_entry, uri, &iter)) midori_location_entry_set_active_iter (location_entry, &iter); else - midori_location_entry_clear (location_entry); + midori_location_entry_reset (location_entry); } @@ -939,22 +1030,23 @@ midori_location_entry_prepend_item (MidoriLocationEntry* location_entry, GtkTreeIter iter; GtkTreeIter index; gint n; + gint visits = 0; g_return_if_fail (MIDORI_IS_LOCATION_ENTRY (location_entry)); g_return_if_fail (item->uri != NULL); - filter_model = gtk_combo_box_get_model (GTK_COMBO_BOX (location_entry)); + filter_model = midori_location_entry_get_filter_model (location_entry); model = midori_location_entry_get_model (location_entry); - if (!midori_location_entry_item_iter (location_entry, item->uri, &iter)) - { - gtk_list_store_prepend (GTK_LIST_STORE (model), &iter); - } - else + if (midori_location_entry_item_iter (location_entry, item->uri, &iter)) { gtk_tree_model_get_iter_first (model, &index); + gtk_tree_model_get (model, &iter, VISITS_COL, &visits, -1); gtk_list_store_move_before (GTK_LIST_STORE (model), &iter, &index); } + else + gtk_list_store_prepend (GTK_LIST_STORE (model), &iter); + n = gtk_tree_model_iter_n_children (filter_model, NULL); if (n > MAX_ITEMS) { @@ -962,7 +1054,11 @@ midori_location_entry_prepend_item (MidoriLocationEntry* location_entry, gtk_list_store_set (GTK_LIST_STORE (model), &index, VISIBLE_COL, FALSE, -1); } - gtk_list_store_set (GTK_LIST_STORE (model), &iter, VISIBLE_COL, TRUE, -1); + + /* Only increment the visits when we add the uri */ + if (!item->title && !item->favicon) + gtk_list_store_set (GTK_LIST_STORE (model), &iter, VISITS_COL, ++visits, + VISIBLE_COL, TRUE, -1); midori_location_entry_set_item (location_entry, &iter, item); } @@ -981,6 +1077,7 @@ midori_location_entry_append_item (MidoriLocationEntry* location_entry, GtkTreeModel* model; GtkTreeIter iter; gint n; + gint visits = 0; g_return_if_fail (MIDORI_IS_LOCATION_ENTRY (location_entry)); g_return_if_fail (item->uri != NULL); @@ -989,12 +1086,46 @@ midori_location_entry_append_item (MidoriLocationEntry* location_entry, if (!midori_location_entry_item_iter (location_entry, item->uri, &iter)) { - gtk_list_store_append (GTK_LIST_STORE (model), &iter); + gtk_list_store_append (GTK_LIST_STORE (model), &iter); - n = gtk_tree_model_iter_n_children (model, NULL); - gtk_list_store_set (GTK_LIST_STORE (model), &iter, VISIBLE_COL, - (n <= MAX_ITEMS), -1); + n = gtk_tree_model_iter_n_children (model, NULL); + gtk_list_store_set (GTK_LIST_STORE (model), &iter, VISIBLE_COL, + (n <= MAX_ITEMS), -1); } + else + gtk_tree_model_get (model, &iter, VISITS_COL, &visits, -1); + + gtk_list_store_set (GTK_LIST_STORE (model), &iter, VISITS_COL, ++visits, -1); midori_location_entry_set_item (location_entry, &iter, item); } +/** + * midori_location_entry_set_item_from_uri: + * @location_entry: a #MidoriLocationEntry + * @uri: a string + * + * Finds the item from the list matching @uri + * and removes it if it is the last instance. + **/ +void +midori_location_entry_delete_item_from_uri (MidoriLocationEntry* location_entry, + const gchar* uri) +{ + GtkTreeModel* model; + GtkTreeIter iter; + gint visits = 0; + + g_return_if_fail (MIDORI_IS_LOCATION_ENTRY (location_entry)); + + model = midori_location_entry_get_model (location_entry); + if (midori_location_entry_item_iter (location_entry, uri, &iter)) + { + gtk_tree_model_get (model, &iter, VISITS_COL, &visits, -1); + if (visits > 1) + gtk_list_store_set (GTK_LIST_STORE (model), + &iter, VISITS_COL, --visits, -1); + else + gtk_list_store_remove (GTK_LIST_STORE (model), &iter); + } +} + diff --git a/midori/midori-locationentry.h b/midori/midori-locationentry.h index cc47b9da..6be5ed69 100644 --- a/midori/midori-locationentry.h +++ b/midori/midori-locationentry.h @@ -35,44 +35,51 @@ struct _MidoriLocationEntryItem }; GType -midori_location_entry_get_type (void); +midori_location_entry_get_type (void); GtkWidget* -midori_location_entry_new (void); +midori_location_entry_new (void); gboolean -midori_location_entry_item_iter (MidoriLocationEntry* location_entry, - const gchar* uri, - GtkTreeIter* iter); +midori_location_entry_item_iter (MidoriLocationEntry* location_entry, + const gchar* uri, + GtkTreeIter* iter); const gchar* -midori_location_entry_get_text (MidoriLocationEntry* location_entry); +midori_location_entry_get_text (MidoriLocationEntry* location_entry); void -midori_location_entry_set_text (MidoriLocationEntry* location_entry, - const gchar* text); +midori_location_entry_set_text (MidoriLocationEntry* location_entry, + const gchar* text); void -midori_location_entry_clear (MidoriLocationEntry* location_entry); +midori_location_entry_reset (MidoriLocationEntry* location_entry); void -midori_location_entry_set_item_from_uri (MidoriLocationEntry* location_entry, - const gchar* uri); +midori_location_entry_clear (MidoriLocationEntry* location_entry); void -midori_location_entry_prepend_item (MidoriLocationEntry* location_entry, - MidoriLocationEntryItem* item); +midori_location_entry_set_item_from_uri (MidoriLocationEntry* location_entry, + const gchar* uri); void -midori_location_entry_append_item (MidoriLocationEntry* location_entry, - MidoriLocationEntryItem* item); +midori_location_entry_prepend_item (MidoriLocationEntry* location_entry, + MidoriLocationEntryItem* item); + +void +midori_location_entry_append_item (MidoriLocationEntry* location_entry, + MidoriLocationEntryItem* item); + +void +midori_location_entry_delete_item_from_uri (MidoriLocationEntry* location_entry, + const gchar* uri); gdouble -midori_location_entry_get_progress (MidoriLocationEntry* location_entry); +midori_location_entry_get_progress (MidoriLocationEntry* location_entry); void -midori_location_entry_set_progress (MidoriLocationEntry* location_entry, - gdouble progress); +midori_location_entry_set_progress (MidoriLocationEntry* location_entry, + gdouble progress); G_END_DECLS