Implement katze_item_copy and a virtual method for subclasses
This commit is contained in:
parent
2323c57d7e
commit
3e18b780ac
2 changed files with 42 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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__ */
|
||||
|
|
Loading…
Reference in a new issue