From 04d3ae65068ba209c6c3bdc2a283351e4e94c5af Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Tue, 24 Jun 2008 21:54:01 +0200 Subject: [PATCH] Make WebList more flexible so it can replace Trash --- midori/Makefile.am | 1 - midori/main.c | 6 +- midori/main.h | 1 - midori/midori-app.c | 10 +- midori/midori-app.h | 15 +- midori/midori-browser.c | 22 +-- midori/midori-trash.c | 328 ---------------------------------------- midori/midori-trash.h | 85 ----------- midori/midori-weblist.c | 100 +++++++++--- midori/midori-weblist.h | 20 ++- po/POTFILES.in | 1 - 11 files changed, 116 insertions(+), 473 deletions(-) delete mode 100644 midori/midori-trash.c delete mode 100644 midori/midori-trash.h diff --git a/midori/Makefile.am b/midori/Makefile.am index fe0c9e5a..91fa7b89 100644 --- a/midori/Makefile.am +++ b/midori/Makefile.am @@ -25,7 +25,6 @@ midori_SOURCES = \ midori-panel.c midori-panel.h \ midori-addons.c midori-addons.h \ midori-console.c midori-console.h \ - midori-trash.c midori-trash.h \ midori-webview.c midori-webview.h \ midori-websettings.c midori-websettings.h \ midori-preferences.c midori-preferences.h \ diff --git a/midori/main.c b/midori/main.c index ee78f140..4bd1f460 100644 --- a/midori/main.c +++ b/midori/main.c @@ -15,7 +15,6 @@ #include "midori-app.h" #include "midori-websettings.h" -#include "midori-trash.h" #include "midori-browser.h" #include "midori-weblist.h" #include "gjs.h" @@ -509,13 +508,14 @@ main (int argc, stock_items_init (); - MidoriTrash* trash = midori_trash_new (10); + // FIXME: Implement 10 item limit for trash + MidoriWebList* trash = midori_web_list_new (); guint n = katze_xbel_folder_get_n_items (xbel_trash); guint i; for (i = 0; i < n; i++) { KatzeXbelItem* item = katze_xbel_folder_get_nth_item (xbel_trash, i); - midori_trash_prepend_xbel_item (trash, item); + midori_web_list_add_item (trash, item); } MidoriApp* app = g_object_new (MIDORI_TYPE_APP, diff --git a/midori/main.h b/midori/main.h index 829c76d9..f9fcf4df 100644 --- a/midori/main.h +++ b/midori/main.h @@ -16,7 +16,6 @@ #include #include - #include /* FIXME: Remove these globals */ diff --git a/midori/midori-app.c b/midori/midori-app.c index 6cab3403..fab0b780 100644 --- a/midori/midori-app.c +++ b/midori/midori-app.c @@ -25,7 +25,7 @@ struct _MidoriApp GtkAccelGroup* accel_group; MidoriWebSettings* settings; - MidoriTrash* trash; + MidoriWebList* trash; MidoriWebList* search_engines; }; @@ -122,7 +122,7 @@ midori_app_class_init (MidoriAppClass* class) "trash", _("Trash"), _("The trash, collecting recently closed tabs and windows"), - MIDORI_TYPE_TRASH, + MIDORI_TYPE_WEB_LIST, G_PARAM_READWRITE)); g_object_class_install_property (gobject_class, @@ -175,7 +175,7 @@ midori_app_init (MidoriApp* app) app->accel_group = gtk_accel_group_new (); app->settings = midori_web_settings_new (); - app->trash = midori_trash_new (10); + app->trash = midori_web_list_new (); app->search_engines = midori_web_list_new (); } @@ -387,11 +387,11 @@ midori_app_set_settings (MidoriApp* app, * midori_app_get_trash: * @app: a #MidoriApp * - * Retrieves the #MidoriTrash of the app. + * Retrieves the trash of the app. * * Return value: the assigned #MidoriTrash **/ -MidoriTrash* +MidoriWebList* midori_app_get_trash (MidoriApp* app) { g_return_val_if_fail (MIDORI_IS_APP (app), NULL); diff --git a/midori/midori-app.h b/midori/midori-app.h index 8de03fe0..9372d7e5 100644 --- a/midori/midori-app.h +++ b/midori/midori-app.h @@ -16,7 +16,7 @@ #include "midori-browser.h" #include "midori-websettings.h" -#include "midori-trash.h" +#include "midori-weblist.h" G_BEGIN_DECLS @@ -34,7 +34,6 @@ G_BEGIN_DECLS (G_TYPE_INSTANCE_GET_CLASS ((obj), MIDORI_TYPE_APP, MidoriAppClass)) typedef struct _MidoriApp MidoriApp; -typedef struct _MidoriAppPrivate MidoriAppPrivate; typedef struct _MidoriAppClass MidoriAppClass; struct _MidoriAppClass @@ -56,21 +55,21 @@ MidoriApp* midori_app_new (void); void -midori_app_add_browser (MidoriApp* app, - MidoriBrowser* browser); +midori_app_add_browser (MidoriApp* app, + MidoriBrowser* browser); MidoriWebSettings* -midori_app_get_settings (MidoriApp* app); +midori_app_get_settings (MidoriApp* app); void midori_app_set_settings (MidoriApp* app, MidoriWebSettings* settings); -MidoriTrash* -midori_app_get_trash (MidoriApp* app); +MidoriWebList* +midori_app_get_trash (MidoriApp* app); void -midori_app_quit (MidoriApp* app); +midori_app_quit (MidoriApp* app); G_END_DECLS diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 29e9ea78..a0e09573 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -20,7 +20,6 @@ #include "midori-panel.h" #include "midori-addons.h" #include "midori-console.h" -#include "midori-trash.h" #include "midori-searchentry.h" #include @@ -70,7 +69,7 @@ struct _MidoriBrowser MidoriWebSettings* settings; KatzeXbelItem* proxy_xbel_folder; - MidoriTrash* trash; + MidoriWebList* trash; MidoriWebList* search_engines; }; @@ -157,7 +156,7 @@ _midori_browser_update_actions (MidoriBrowser* browser) if (browser->trash) { - gboolean trash_empty = midori_trash_is_empty (browser->trash); + gboolean trash_empty = midori_web_list_is_empty (browser->trash); _action_set_sensitive (browser, "UndoTabClose", !trash_empty); _action_set_sensitive (browser, "Trash", !trash_empty); } @@ -620,7 +619,7 @@ midori_web_view_close_cb (GtkWidget* web_view, MIDORI_WEB_VIEW (web_view)); const gchar* uri = katze_xbel_bookmark_get_href (xbel_item); if (browser->trash && uri && *uri) - midori_trash_prepend_xbel_item (browser->trash, xbel_item); + midori_web_list_add_item (browser->trash, xbel_item); katze_xbel_folder_remove_item (browser->proxy_xbel_folder, xbel_item); katze_xbel_item_unref (xbel_item); } @@ -1087,7 +1086,7 @@ midori_browser_class_init (MidoriBrowserClass* class) "trash", _("Trash"), _("The trash, collecting recently closed tabs and windows"), - MIDORI_TYPE_TRASH, + MIDORI_TYPE_WEB_LIST, G_PARAM_READWRITE)); /** @@ -1414,12 +1413,12 @@ midori_browser_menu_trash_activate_cb (GtkWidget* widget, MidoriBrowser* browser) { GtkWidget* menu = gtk_menu_new (); - guint n = midori_trash_get_n_items (browser->trash); + guint n = midori_web_list_get_length (browser->trash); GtkWidget* menuitem; guint i; for (i = 0; i < n; i++) { - KatzeXbelItem* item = midori_trash_get_nth_xbel_item (browser->trash, i); + KatzeXbelItem* item = midori_web_list_get_nth_item (browser->trash, i); const gchar* title = katze_xbel_item_get_title (item); const gchar* uri = katze_xbel_bookmark_get_href (item); menuitem = gtk_image_menu_item_new_with_label (title ? title : uri); @@ -2214,10 +2213,11 @@ _action_undo_tab_close_activate (GtkAction* action, MidoriBrowser* browser) { /* Reopen the most recent trash item */ - KatzeXbelItem* item = midori_trash_get_nth_xbel_item (browser->trash, 0); + guint length = midori_web_list_get_length (browser->trash); + KatzeXbelItem* item = midori_web_list_get_nth_item (browser->trash, length); gint n = midori_browser_add_xbel_item (browser, item); midori_browser_set_current_page (browser, n); - midori_trash_remove_nth_item (browser->trash, 0); + midori_web_list_remove_item (browser->trash, item); _midori_browser_update_actions (browser); } @@ -2225,12 +2225,12 @@ static void _action_trash_empty_activate (GtkAction* action, MidoriBrowser* browser) { - midori_trash_empty (browser->trash); + midori_web_list_clear (browser->trash); _midori_browser_update_actions (browser); } static void -_action_bookmark_delete_activate (GtkAction* action, +_action_bookmark_delete_activate (GtkAction* action, MidoriBrowser* browser) { GtkTreeView* treeview = GTK_TREE_VIEW (browser->panel_bookmarks); diff --git a/midori/midori-trash.c b/midori/midori-trash.c deleted file mode 100644 index b546e121..00000000 --- a/midori/midori-trash.c +++ /dev/null @@ -1,328 +0,0 @@ -/* - Copyright (C) 2008 Christian Dywan - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - See the file COPYING for the full license text. -*/ - -#include "midori-trash.h" - -#include "sokoke.h" -#include - -G_DEFINE_TYPE (MidoriTrash, midori_trash, G_TYPE_OBJECT) - -struct _MidoriTrashPrivate -{ - guint limit; - KatzeXbelItem* xbel_folder; -}; - -#define MIDORI_TRASH_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ - MIDORI_TYPE_TRASH, MidoriTrashPrivate)) - -enum -{ - PROP_0, - - PROP_LIMIT -}; - -enum { - INSERTED, - REMOVED, - - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL]; - -static void -midori_trash_finalize (GObject* object); - -static void -midori_trash_set_property (GObject* object, - guint prop_id, - const GValue* value, - GParamSpec* pspec); - -static void -midori_trash_get_property (GObject* object, - guint prop_id, - GValue* value, - GParamSpec* pspec); - -static void -midori_trash_class_init (MidoriTrashClass* class) -{ - signals[INSERTED] = g_signal_new ( - "inserted", - G_TYPE_FROM_CLASS (class), - (GSignalFlags)(G_SIGNAL_RUN_LAST), - G_STRUCT_OFFSET (MidoriTrashClass, inserted), - 0, - NULL, - g_cclosure_marshal_VOID__UINT, - G_TYPE_NONE, 1, - G_TYPE_UINT); - - signals[REMOVED] = g_signal_new ( - "removed", - G_TYPE_FROM_CLASS (class), - (GSignalFlags)(G_SIGNAL_RUN_LAST), - G_STRUCT_OFFSET (MidoriTrashClass, removed), - 0, - NULL, - g_cclosure_marshal_VOID__UINT, - G_TYPE_NONE, 1, - G_TYPE_UINT); - - GObjectClass* gobject_class = G_OBJECT_CLASS (class); - gobject_class->finalize = midori_trash_finalize; - gobject_class->set_property = midori_trash_set_property; - gobject_class->get_property = midori_trash_get_property; - - GParamFlags flags = G_PARAM_READWRITE | G_PARAM_CONSTRUCT; - - g_object_class_install_property (gobject_class, - PROP_LIMIT, - g_param_spec_uint ( - "limit", - _("Limit"), - _("The maximum number of items"), - 0, G_MAXUINT, 10, - flags)); - - g_type_class_add_private (class, sizeof (MidoriTrashPrivate)); -} - - - -static void -midori_trash_init (MidoriTrash* trash) -{ - trash->priv = MIDORI_TRASH_GET_PRIVATE (trash); - - MidoriTrashPrivate* priv = trash->priv; - - priv->xbel_folder = katze_xbel_folder_new (); -} - -static void -midori_trash_finalize (GObject* object) -{ - MidoriTrash* trash = MIDORI_TRASH (object); - MidoriTrashPrivate* priv = trash->priv; - - katze_xbel_item_unref (priv->xbel_folder); - - G_OBJECT_CLASS (midori_trash_parent_class)->finalize (object); -} - -static void -midori_trash_set_property (GObject* object, - guint prop_id, - const GValue* value, - GParamSpec* pspec) -{ - MidoriTrash* trash = MIDORI_TRASH (object); - MidoriTrashPrivate* priv = trash->priv; - - switch (prop_id) - { - case PROP_LIMIT: - priv->limit = g_value_get_uint (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -midori_trash_get_property (GObject* object, - guint prop_id, - GValue* value, - GParamSpec* pspec) -{ - MidoriTrash* trash = MIDORI_TRASH (object); - MidoriTrashPrivate* priv = trash->priv; - - switch (prop_id) - { - case PROP_LIMIT: - g_value_set_uint (value, priv->limit); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -/** - * midori_trash_new: - * @limit: the maximum number of items - * - * Creates a new #MidoriTrash that can contain a specified number of items, - * meaning that each additional item will replace the oldest existing item. - * - * The value 0 for @limit actually means that there is no limit. - * - * You will typically want to assign this to a #MidoriBrowser. - * - * Return value: a new #MidoriTrash - **/ -MidoriTrash* -midori_trash_new (guint limit) -{ - MidoriTrash* trash = g_object_new (MIDORI_TYPE_TRASH, - "limit", limit, - NULL); - - return trash; -} - -/** - * midori_trash_is_empty: - * @trash: a #MidoriTrash - * - * Determines whether the @trash contains no items. - * - * Return value: %TRUE if there are no items, %FALSE otherwise - **/ -gboolean -midori_trash_is_empty (MidoriTrash* trash) -{ - g_return_val_if_fail (MIDORI_IS_TRASH (trash), FALSE); - - MidoriTrashPrivate* priv = trash->priv; - - return katze_xbel_folder_is_empty (priv->xbel_folder); -} - -/** - * midori_trash_get_n_items: - * @trash: a #MidoriTrash - * - * Determines the number of items in @trash. - * - * Return value: the current number of items - **/ -guint -midori_trash_get_n_items (MidoriTrash* trash) -{ - g_return_val_if_fail (MIDORI_IS_TRASH (trash), 0); - - MidoriTrashPrivate* priv = trash->priv; - - return katze_xbel_folder_get_n_items (priv->xbel_folder); -} - -/** - * midori_trash_get_nth_xbel_item: - * @trash: a #MidoriTrash - * @n: the index of an item - * - * Retrieve an item contained in @trash by its index. - * - * Note that you mustn't unref this item. - * - * Return value: the index at the given index or %NULL - **/ -KatzeXbelItem* -midori_trash_get_nth_xbel_item (MidoriTrash* trash, - guint n) -{ - g_return_val_if_fail (MIDORI_IS_TRASH (trash), 0); - - MidoriTrashPrivate* priv = trash->priv; - - return katze_xbel_folder_get_nth_item (priv->xbel_folder, n); -} - -/** - * midori_trash_prepend_xbel_item: - * @trash: a #MidoriTrash - * @xbel_item: a #KatzeXbelItem - * - * Prepends a #KatzeXbelItem to @trash. - * - * The item is copied. If there is a limit set, the oldest item is - * removed automatically. - * - * Return value: %TRUE if there are no items, %FALSE otherwise - **/ -void -midori_trash_prepend_xbel_item (MidoriTrash* trash, - KatzeXbelItem* xbel_item) -{ - g_return_if_fail (MIDORI_IS_TRASH (trash)); - - MidoriTrashPrivate* priv = trash->priv; - - KatzeXbelItem* copy = katze_xbel_item_copy (xbel_item); - katze_xbel_folder_prepend_item (priv->xbel_folder, copy); - g_signal_emit (trash, signals[INSERTED], 0, 0); - guint n = katze_xbel_folder_get_n_items (priv->xbel_folder); - if (n > 10) - { - KatzeXbelItem* item = katze_xbel_folder_get_nth_item (priv->xbel_folder, - n - 1); - g_signal_emit (trash, signals[REMOVED], 0, n - 1); - katze_xbel_item_unref (item); - } -} - -/** - * midori_trash_remove_nth_item: - * @trash: a #MidoriTrash - * @n: the index of an item - * - * Removes the item at the specified position from @trash. - * - * Nothing happens if the function fails. - **/ -void -midori_trash_remove_nth_item (MidoriTrash* trash, - guint n) -{ - g_return_if_fail (MIDORI_IS_TRASH (trash)); - - MidoriTrashPrivate* priv = trash->priv; - - KatzeXbelItem* item = katze_xbel_folder_get_nth_item (priv->xbel_folder, n); - if (!n) - return; - katze_xbel_folder_remove_item (priv->xbel_folder, item); - g_signal_emit (trash, signals[REMOVED], 0, n); - katze_xbel_item_unref (item); -} - -/** - * midori_trash_empty: - * @trash: a #MidoriTrash - * - * Deletes all items currently contained in @trash. - **/ -void -midori_trash_empty (MidoriTrash* trash) -{ - g_return_if_fail (MIDORI_IS_TRASH (trash)); - - MidoriTrashPrivate* priv = trash->priv; - - guint n = katze_xbel_folder_get_n_items (priv->xbel_folder); - guint i; - for (i = 0; i < n; i++) - { - KatzeXbelItem* item = katze_xbel_folder_get_nth_item (priv->xbel_folder, - i); - g_signal_emit (trash, signals[REMOVED], 0, i); - katze_xbel_item_unref (item); - } -} diff --git a/midori/midori-trash.h b/midori/midori-trash.h deleted file mode 100644 index bc711792..00000000 --- a/midori/midori-trash.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - Copyright (C) 2008 Christian Dywan - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - See the file COPYING for the full license text. -*/ - -#ifndef __MIDORI_TRASH_H__ -#define __MIDORI_TRASH_H__ - -#include - -G_BEGIN_DECLS - -#define MIDORI_TYPE_TRASH \ - (midori_trash_get_type ()) -#define MIDORI_TRASH(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), MIDORI_TYPE_TRASH, MidoriTrash)) -#define MIDORI_TRASH_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), MIDORI_TYPE_TRASH, MidoriTrashClass)) -#define MIDORI_IS_TRASH(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MIDORI_TYPE_TRASH)) -#define MIDORI_IS_TRASH_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), MIDORI_TYPE_TRASH)) -#define MIDORI_TRASH_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), MIDORI_TYPE_TRASH, MidoriTrashClass)) - -typedef struct _MidoriTrash MidoriTrash; -typedef struct _MidoriTrashPrivate MidoriTrashPrivate; -typedef struct _MidoriTrashClass MidoriTrashClass; - -struct _MidoriTrash -{ - GObject parent_instance; - - MidoriTrashPrivate* priv; -}; - -struct _MidoriTrashClass -{ - GObjectClass parent_class; - - /* Signals */ - void - (*inserted) (MidoriTrash* trash, - guint n); - void - (*removed) (MidoriTrash* trash, - guint n); -}; - -GType -midori_trash_get_type (void); - -MidoriTrash* -midori_trash_new (guint limit); - -gboolean -midori_trash_is_empty (MidoriTrash* trash); - -guint -midori_trash_get_n_items (MidoriTrash* trash); - -KatzeXbelItem* -midori_trash_get_nth_xbel_item (MidoriTrash* trash, - guint n); - -void -midori_trash_prepend_xbel_item (MidoriTrash* trash, - KatzeXbelItem* xbel_item); - -void -midori_trash_remove_nth_item (MidoriTrash* trash, - guint n); - -void -midori_trash_empty (MidoriTrash* trash); - -G_END_DECLS - -#endif /* __MIDORI_TRASH_H__ */ diff --git a/midori/midori-weblist.c b/midori/midori-weblist.c index daf2c3b1..fb301819 100644 --- a/midori/midori-weblist.c +++ b/midori/midori-weblist.c @@ -14,6 +14,15 @@ #include #include +/** + * SECTION:midori-weblist + * @short_description: A versatile object container + * @see_also: #MidoriWebItem + * + * #MidoriWebList is a versatile container for objects with + * explicit support for #MidoriWebList and #MidoriWebItem children. + */ + struct _MidoriWebList { GObject parent_instance; @@ -37,18 +46,17 @@ midori_web_list_finalize (GObject* object); static void _midori_web_list_add_item (MidoriWebList* web_list, - MidoriWebItem* web_item) + GObject* item) { - g_object_ref (web_item); - web_list->items = g_list_append (web_list->items, web_item); + web_list->items = g_list_append (web_list->items, item); } static void _midori_web_list_remove_item (MidoriWebList* web_list, - MidoriWebItem* web_item) + GObject* item) { - web_list->items = g_list_remove (web_list->items, web_item); - g_object_unref (web_item); + web_list->items = g_list_remove (web_list->items, item); + g_object_unref (item); } static void @@ -63,7 +71,7 @@ midori_web_list_class_init (MidoriWebListClass* class) NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, - MIDORI_TYPE_WEB_ITEM); + G_TYPE_OBJECT); signals[REMOVE_ITEM] = g_signal_new ( "remove-item", @@ -74,7 +82,7 @@ midori_web_list_class_init (MidoriWebListClass* class) NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, - MIDORI_TYPE_WEB_ITEM); + G_TYPE_OBJECT); class->add_item = _midori_web_list_add_item; class->remove_item = _midori_web_list_remove_item; @@ -94,7 +102,7 @@ midori_web_list_finalize (GObject* object) { MidoriWebList* web_list = MIDORI_WEB_LIST (object); - g_list_foreach (web_list->items, (GFunc)g_object_unref, NULL); + midori_web_list_clear (web_list); g_list_free (web_list->items); G_OBJECT_CLASS (midori_web_list_parent_class)->finalize (object); @@ -119,29 +127,33 @@ midori_web_list_new (void) /** * midori_web_list_add_item: * @web_list: a #MidoriWebList - * @web_item: a #MidoriWebItem + * @item: a #GObject * * Adds an item to the list. **/ void midori_web_list_add_item (MidoriWebList* web_list, - MidoriWebItem* web_item) + gpointer item) { - g_signal_emit (web_list, signals[ADD_ITEM], 0, web_item); + g_return_if_fail (G_IS_OBJECT (item)); + + g_signal_emit (web_list, signals[ADD_ITEM], 0, item); } /** * midori_web_list_add_item: * @web_list: a #MidoriWebList - * @web_item: a #MidoriWebItem + * @item: a #GObject * * Removes an item from the list. **/ void midori_web_list_remove_item (MidoriWebList* web_list, - MidoriWebItem* web_item) + gpointer item) { - g_signal_emit (web_list, signals[REMOVE_ITEM], 0, web_item); + g_return_if_fail (G_IS_OBJECT (item)); + + g_signal_emit (web_list, signals[REMOVE_ITEM], 0, item); } /** @@ -153,15 +165,31 @@ midori_web_list_remove_item (MidoriWebList* web_list, * * Return value: an item, or %NULL **/ -MidoriWebItem* +gpointer midori_web_list_get_nth_item (MidoriWebList* web_list, guint n) { - g_return_val_if_fail (MIDORI_IS_WEB_LIST (web_list), 0); + g_return_val_if_fail (MIDORI_IS_WEB_LIST (web_list), NULL); return g_list_nth_data (web_list->items, n); } +/** + * midori_web_list_is_empty: + * @web_list: a #MidoriWebList + * + * Determines if @web_list is empty. + * + * Return value: an item, or %NULL + **/ +gboolean +midori_web_list_is_empty (MidoriWebList* web_list) +{ + g_return_val_if_fail (MIDORI_IS_WEB_LIST (web_list), TRUE); + + return !g_list_nth_data (web_list->items, 0); +} + /** * midori_web_list_get_item_position: * @web_list: a #MidoriWebList @@ -173,12 +201,12 @@ midori_web_list_get_nth_item (MidoriWebList* web_list, **/ gint midori_web_list_get_item_index (MidoriWebList* web_list, - MidoriWebItem* web_item) + gpointer 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); + g_return_val_if_fail (G_IS_OBJECT (item), -1); - return g_list_index (web_list->items, web_item); + return g_list_index (web_list->items, item); } /** @@ -188,15 +216,18 @@ midori_web_list_get_item_index (MidoriWebList* web_list, * * Looks up an item in the list which has the specified token. * + * Supported is #MidoriWebItem. + * * Note that @token is by definition unique to one item. * * Return value: an item, or %NULL **/ -MidoriWebItem* +gpointer midori_web_list_find_token (MidoriWebList* web_list, const gchar* token) { guint n, i; + GObject* item; MidoriWebItem* web_item; g_return_val_if_fail (MIDORI_IS_WEB_LIST (web_list), NULL); @@ -204,9 +235,12 @@ midori_web_list_find_token (MidoriWebList* web_list, n = g_list_length (web_list->items); for (i = 0; i < n; i++) { - web_item = (MidoriWebItem*)g_list_nth_data (web_list->items, i); + item = (GObject*)g_list_nth_data (web_list->items, i); + if (!MIDORI_IS_WEB_ITEM (item)) + continue; + web_item = (MidoriWebItem*)item; if (!strcmp (midori_web_item_get_token (web_item), token)) - return web_item; + return item; } return NULL; } @@ -226,3 +260,23 @@ midori_web_list_get_length (MidoriWebList* web_list) return g_list_length (web_list->items); } + +/** + * midori_web_list_clear: + * @web_list: a #MidoriWebList + * + * Deletes all items currently contained in @web_list. + **/ +void +midori_web_list_clear (MidoriWebList* web_list) +{ + g_return_if_fail (MIDORI_IS_WEB_LIST (web_list)); + + guint n = g_list_length (web_list->items); + guint i; + for (i = 0; i < n; i++) + { + GObject* item = g_list_nth_data (web_list->items, i); + midori_web_list_remove_item (web_list, item); + } +} diff --git a/midori/midori-weblist.h b/midori/midori-weblist.h index 64f9866c..e051cbc5 100644 --- a/midori/midori-weblist.h +++ b/midori/midori-weblist.h @@ -39,10 +39,10 @@ struct _MidoriWebListClass /* Signals */ void (*add_item) (MidoriWebList* web_list, - MidoriWebItem* web_item); + GObject* item); void (*remove_item) (MidoriWebList* web_list, - MidoriWebItem* web_item); + GObject* item); }; GType @@ -53,27 +53,33 @@ midori_web_list_new (void); void midori_web_list_add_item (MidoriWebList* web_list, - MidoriWebItem* web_item); + gpointer item); void midori_web_list_remove_item (MidoriWebList* web_list, - MidoriWebItem* web_item); + gpointer item); -MidoriWebItem* +gpointer midori_web_list_get_nth_item (MidoriWebList* web_list, guint n); +gboolean +midori_web_list_is_empty (MidoriWebList* web_list); + gint midori_web_list_get_item_index (MidoriWebList* web_list, - MidoriWebItem* web_item); + gpointer item); -MidoriWebItem* +gpointer midori_web_list_find_token (MidoriWebList* web_list, const gchar* token); guint midori_web_list_get_length (MidoriWebList* web_list); +void +midori_web_list_clear (MidoriWebList* web_list); + G_END_DECLS #endif /* __MIDORI_WEB_LIST_H__ */ diff --git a/po/POTFILES.in b/po/POTFILES.in index bb0358a2..df1c867e 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -7,7 +7,6 @@ midori/midori-addons.c midori/midori-console.c midori/midori-browser.c midori/midori-panel.c -midori/midori-trash.c midori/midori-websettings.c midori/midori-webview.c midori/midori-preferences.c