xref: /haiku/src/apps/icon-o-matic/document/IconObject.cpp (revision 445d4fd926c569e7b9ae28017da86280aaecbae2)
1 /*
2  * Copyright 2006, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stephan Aßmus <superstippi@gmx.de>
7  */
8 
9 #include "IconObject.h"
10 
11 #include <Message.h>
12 
13 #include "CommonPropertyIDs.h"
14 #include "Property.h"
15 #include "PropertyObject.h"
16 
17 // constructor
18 IconObject::IconObject(const char* name)
19 	: Observable(),
20 	  BReferenceable(),
21 	  Selectable(),
22 
23 	  fName(name)
24 {
25 }
26 
27 // copy constructor
28 IconObject::IconObject(const IconObject& other)
29 	: Observable(),
30 	  BReferenceable(),
31 	  Selectable(),
32 
33 	  fName(other.fName)
34 {
35 }
36 
37 // archive constructor
38 IconObject::IconObject(BMessage* archive)
39 	: Observable(),
40 	  BReferenceable(),
41 	  Selectable(),
42 
43 	  fName()
44 {
45 	// NOTE: uses IconObject version, not overridden
46 	Unarchive(archive);
47 }
48 
49 // destructor
50 IconObject::~IconObject()
51 {
52 }
53 
54 // SelectedChanged
55 void
56 IconObject::SelectedChanged()
57 {
58 	// simply pass on the event for now
59 //	Notify();
60 }
61 
62 // #pragma mark -
63 
64 // Unarchive
65 status_t
66 IconObject::Unarchive(BMessage* archive)
67 {
68 	if (!archive)
69 		return B_BAD_VALUE;
70 
71 	const char* name;
72 	status_t ret = archive->FindString("name", &name);
73 
74 	if (ret == B_OK)
75 		fName = name;
76 
77 	return ret;
78 }
79 
80 // Archive
81 status_t
82 IconObject::Archive(BMessage* into, bool deep) const
83 {
84 	if (!into)
85 		return B_BAD_VALUE;
86 
87 	return into->AddString("name", fName.String());
88 }
89 
90 // MakePropertyObject
91 PropertyObject*
92 IconObject::MakePropertyObject() const
93 {
94 	PropertyObject* object = new PropertyObject();
95 
96 	object->AddProperty(new StringProperty(PROPERTY_NAME, fName.String()));
97 
98 	return object;
99 }
100 
101 // SetToPropertyObject
102 bool
103 IconObject::SetToPropertyObject(const PropertyObject* object)
104 {
105 	AutoNotificationSuspender _(this);
106 
107 	BString name;
108 	if (object->GetValue(PROPERTY_NAME, name))
109 		SetName(name.String());
110 
111 	return HasPendingNotifications();
112 }
113 
114 // SetName
115 void
116 IconObject::SetName(const char* name)
117 {
118 	if (fName == name)
119 		return;
120 
121 	fName = name;
122 	Notify();
123 }
124