Implement katze_item_copy and a virtual method for subclasses

This commit is contained in:
Christian Dywan 2009-01-26 03:41:12 +01:00
parent 2323c57d7e
commit 3e18b780ac
2 changed files with 42 additions and 0 deletions

View file

@ -138,6 +138,8 @@ katze_item_class_init (KatzeItemClass* class)
"The parent of the item", "The parent of the item",
G_TYPE_OBJECT, G_TYPE_OBJECT,
flags)); flags));
class->copy = NULL;
} }
@ -492,3 +494,37 @@ katze_item_set_parent (KatzeItem* item,
katze_object_assign (item->parent, parent); katze_object_assign (item->parent, parent);
g_object_notify (G_OBJECT (item), "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;
}

View file

@ -49,6 +49,9 @@ struct _KatzeItem
struct _KatzeItemClass struct _KatzeItemClass
{ {
GObjectClass parent_class; GObjectClass parent_class;
gpointer
(*copy) (KatzeItem* item);
}; };
GType GType
@ -106,6 +109,9 @@ void
katze_item_set_parent (KatzeItem* item, katze_item_set_parent (KatzeItem* item,
gpointer parent); gpointer parent);
KatzeItem*
katze_item_copy (KatzeItem* item);
G_END_DECLS G_END_DECLS
#endif /* __MIDORI_WEB_ITEM_H__ */ #endif /* __MIDORI_WEB_ITEM_H__ */