]> spindle.queued.net Git - midori/commitdiff
Implement katze_item_copy and a virtual method for subclasses
authorChristian Dywan <christian@twotoasts.de>
Mon, 26 Jan 2009 02:41:12 +0000 (03:41 +0100)
committerChristian Dywan <christian@twotoasts.de>
Mon, 26 Jan 2009 02:41:12 +0000 (03:41 +0100)
katze/katze-item.c
katze/katze-item.h

index 3423cfe532cd6c7e1d23c6b1f29d55501b014e55..006adc4bf46bb2cc52661466a494c6e69dae54eb 100644 (file)
@@ -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;
+}
index add88de163a621fbdc16581ee2f9e6e1ab51dceb..8e40110a05d862a53b29eccb6062eab7035f68ee 100644 (file)
@@ -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__ */