Use foreach with copied list for importing bookmarks

The new macro KATZE_ARRAY_FOREACH_ITEM_L is added, taking a
list that must be freed afterwards. It copies the list to
not enter infinite recursion if items are removed or appended.
This commit is contained in:
Christian Dywan 2010-12-05 23:34:17 +01:00
parent 566985bb8b
commit b604b177bb
2 changed files with 28 additions and 1 deletions

View file

@ -84,6 +84,15 @@ GList*
katze_array_peek_items (KatzeArray* array);
extern GList* kalistglobal;
/* KATZE_ARRAY_FOREACH_ITEM:
* @item: a #KatzeItem variable
* @array: a #KatzeArray to loop through
*
* Loops through all items of the array. The macro can
* be used like a for() loop.
* If the array is modified during the loop, you must
* use KATZE_ARRAY_FOREACH_ITEM_L instead.
* */
#define KATZE_ARRAY_FOREACH_ITEM(kaitem, kaarray) \
for (kalistglobal = katze_array_peek_items (kaarray), \
kaitem = kalistglobal ? kalistglobal->data : NULL; \
@ -91,6 +100,22 @@ extern GList* kalistglobal;
kalistglobal = g_list_next (kalistglobal), \
kaitem = kalistglobal ? kalistglobal->data : NULL)
/* KATZE_ARRAY_FOREACH_ITEM_L:
* @item: a #KatzeItem variable
* @array: a #KatzeArray to loop through
* @list: a #GList variable
*
* Loops through all items of the array. The list must be freed.
*
* Since: 0.3.0
* */
#define KATZE_ARRAY_FOREACH_ITEM_L(kaitem, kaarray, kalist) \
for (kalist = katze_array_get_items (kaarray), \
kaitem = kalist ? kalist->data : NULL; \
kalist != NULL; \
kalist = g_list_next (kalist), \
kaitem = kalist ? kalist->data : NULL)
void
katze_array_clear (KatzeArray* array);

View file

@ -155,15 +155,17 @@ midori_bookmarks_import_array_db (sqlite3* db,
KatzeArray* array,
const gchar* folder)
{
GList* list;
KatzeItem* item;
KATZE_ARRAY_FOREACH_ITEM (item, array)
KATZE_ARRAY_FOREACH_ITEM_L (item, array, list)
{
if (KATZE_IS_ARRAY (item))
midori_bookmarks_import_array_db (db, KATZE_ARRAY (item), folder);
katze_item_set_meta_string (item, "folder", folder);
katze_array_add_item (array, item);
}
g_list_free (list);
}
static KatzeArray*