From 3e18b780ac3076d36016e7002f5f4290339f72e6 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Mon, 26 Jan 2009 03:41:12 +0100 Subject: [PATCH] Implement katze_item_copy and a virtual method for subclasses --- katze/katze-item.c | 36 ++++++++++++++++++++++++++++++++++++ katze/katze-item.h | 6 ++++++ 2 files changed, 42 insertions(+) diff --git a/katze/katze-item.c b/katze/katze-item.c index 3423cfe5..006adc4b 100644 --- a/katze/katze-item.c +++ b/katze/katze-item.c @@ -138,6 +138,8 @@ katze_item_class_init (KatzeItemClass* class) "The parent of the item", G_TYPE_OBJECT, flags)); + + class->copy = NULL; } @@ -492,3 +494,37 @@ katze_item_set_parent (KatzeItem* item, katze_object_assign (item->parent, parent); g_object_notify (G_OBJECT (item), "parent"); } + +/** + * katze_item_copy: + * @item: a #KatzeItem + * + * Creates an exact copy of @item. + * + * Note that subclass specific features will only + * be preserved if the class implements it. + * + * Return value: a new #KatzeItem + * + * Since: 0.1.3 + **/ +KatzeItem* +katze_item_copy (KatzeItem* item) +{ + KatzeItem* copy; + KatzeItemClass* class; + + g_return_val_if_fail (KATZE_IS_ITEM (item), NULL); + + copy = g_object_new (G_OBJECT_TYPE (item), + "name", item->name, + "text", item->text, + "uri", item->uri, + "icon", item->icon, + "token", item->token, + "added", item->added, + "parent", item->parent, + NULL); + class = KATZE_ITEM_GET_CLASS (item); + return class->copy ? class->copy (copy) : copy; +} diff --git a/katze/katze-item.h b/katze/katze-item.h index add88de1..8e40110a 100644 --- a/katze/katze-item.h +++ b/katze/katze-item.h @@ -49,6 +49,9 @@ struct _KatzeItem struct _KatzeItemClass { GObjectClass parent_class; + + gpointer + (*copy) (KatzeItem* item); }; GType @@ -106,6 +109,9 @@ void katze_item_set_parent (KatzeItem* item, gpointer parent); +KatzeItem* +katze_item_copy (KatzeItem* item); + G_END_DECLS #endif /* __MIDORI_WEB_ITEM_H__ */ -- 2.39.5