Remove "endl;" not necessary now
[kdenetwork.git] / kopete / libkopete / kopeteproperty.cpp
blob48c6b6dbf137b4a222815e886f828466dccbb43f
1 /*
2 kopeteproperty.cpp
4 Kopete::Property class
6 Copyright (c) 2007 by Gustavo Pichorim Boiko <gustavo.boiko@kdemail.net>
7 Copyright (c) 2004 by Stefan Gehn <metz AT gehn.net>
8 Copyright (c) 2006 by Michaƫl Larouche <larouche@kde.org>
10 Kopete (c) 2004-2007 by the Kopete developers <kopete-devel@kde.org>
12 *************************************************************************
13 * *
14 * This library is free software; you can redistribute it and/or *
15 * modify it under the terms of the GNU Lesser General Public *
16 * License as published by the Free Software Foundation; either *
17 * version 2 of the License, or (at your option) any later version. *
18 * *
19 *************************************************************************
22 #include "kopeteproperty.h"
23 #include <kdebug.h>
24 #include "kopeteglobal.h"
26 namespace Kopete
29 class PropertyTmpl::Private
31 public:
32 QString key;
33 QString label;
34 QString icon;
35 PropertyOptions options;
36 unsigned int refCount;
39 PropertyTmpl PropertyTmpl::null;
42 PropertyTmpl::PropertyTmpl()
44 d = new Private;
45 d->refCount = 1;
46 d->options = NoProperty;
47 // Don't register empty template
50 PropertyTmpl::PropertyTmpl(const QString &key,
51 const QString &label, const QString &icon, PropertyOptions options)
53 PropertyTmpl other = Kopete::Global::Properties::self()->tmpl(key);
54 if(other.isNull())
56 // kDebug(14000) << "Creating new template for key = '" << key << "'";
58 d = new Private;
59 d->refCount = 1;
60 d->key = key;
61 d->label = label;
62 d->icon = icon;
63 d->options = options;
64 Kopete::Global::Properties::self()->registerTemplate(key, (*this));
66 else
68 // kDebug(14000) << "Using existing template for key = '" << key << "'";
69 d = other.d;
70 d->refCount++;
74 PropertyTmpl::PropertyTmpl(const PropertyTmpl &other)
76 d = other.d;
77 d->refCount++;
80 PropertyTmpl &PropertyTmpl::operator=(
81 const PropertyTmpl &other)
83 if (this == &other)
85 // kDebug(14000) << "trying to assign this to itself!";
86 return *this;
88 if( d == other.d )
90 // kDebug(14000) << "trying to assign d to itself!";
91 return *this;
93 d->refCount--;
94 if(d->refCount == 0)
96 if (!d->key.isEmpty()) // null property
97 Kopete::Global::Properties::self()->unregisterTemplate(d->key);
98 delete d;
101 d = other.d;
102 d->refCount++;
104 return *this;
107 PropertyTmpl::~PropertyTmpl()
109 d->refCount--;
110 if(d->refCount == 0)
112 if (!d->key.isEmpty()) // null property
113 Kopete::Global::Properties::self()->unregisterTemplate(d->key);
114 delete d;
118 bool PropertyTmpl::operator==(const PropertyTmpl &other) const
120 return (d && other.d &&
121 d->key == other.d->key &&
122 d->label == other.d->label &&
123 d->icon == other.d->key &&
124 d->options == other.d->options);
127 bool PropertyTmpl::operator!=(const PropertyTmpl &other) const
129 return (!d || !other.d ||
130 d->key != other.d->key ||
131 d->label != other.d->label ||
132 d->icon != other.d->key ||
133 d->options != other.d->options);
137 const QString &PropertyTmpl::key() const
139 return d->key;
142 const QString &PropertyTmpl::label() const
144 return d->label;
147 const QString &PropertyTmpl::icon() const
149 return d->icon;
152 PropertyTmpl::PropertyOptions PropertyTmpl::options() const
154 return d->options;
157 bool PropertyTmpl::persistent() const
159 return d->options & PersistentProperty;
162 bool PropertyTmpl::isRichText() const
164 return d->options & RichTextProperty;
167 bool PropertyTmpl::isPrivate() const
169 return d->options & PrivateProperty;
172 bool PropertyTmpl::isNull() const
174 return (!d || d->key.isNull());
178 // -----------------------------------------------------------------------------
181 Property Property::null;
183 class Property::Private
185 public:
186 QVariant value;
187 PropertyTmpl propertyTemplate;
190 Property::Property()
191 : d(new Private)
195 Property::Property(const PropertyTmpl &tmpl,
196 const QVariant &val)
197 : d(new Private)
199 d->propertyTemplate = tmpl;
200 d->value = val;
203 Property::Property(const Property& other)
204 : d(new Private)
206 d->propertyTemplate = other.d->propertyTemplate;
207 d->value = other.d->value;
210 Property::~Property()
212 delete d;
215 Property& Property::operator=(const Property& other)
217 if (this == &other)
219 // kDebug(14000) << "trying to assign this to itself!";
220 return *this;
223 d->propertyTemplate = other.d->propertyTemplate;
224 d->value = other.d->value;
226 return *this;
229 const QVariant &Property::value() const
231 return d->value;
234 const PropertyTmpl &Property::tmpl() const
236 return d->propertyTemplate;
239 bool Property::isNull() const
241 return d->value.isNull();
244 bool Property::isRichText() const
246 return d->propertyTemplate.isRichText();
249 } // END namespace Kopete