• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdenetwork API Reference
  • KDE Home
  • Contact Us
 

kopete/libkopete

  • sources
  • kde-4.14
  • kdenetwork
  • kopete
  • libkopete
kopeteproperty.cpp
Go to the documentation of this file.
1 /*
2  kopeteproperty.cpp
3 
4  Kopete::Property class
5 
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>
9 
10  Kopete (c) 2004-2007 by the Kopete developers <kopete-devel@kde.org>
11 
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  *************************************************************************
20 */
21 
22 #include "kopeteproperty.h"
23 #include <kdebug.h>
24 #include "kopeteglobal.h"
25 
26 namespace Kopete
27 {
28 
29 class PropertyTmpl::Private
30 {
31 public:
32  QString key;
33  QString label;
34  QString icon;
35  PropertyOptions options;
36  unsigned int refCount;
37 };
38 
39 PropertyTmpl PropertyTmpl::null;
40 
41 
42 PropertyTmpl::PropertyTmpl()
43 {
44  d = new Private;
45  d->refCount = 1;
46  d->options = NoProperty;
47  // Don't register empty template
48 }
49 
50 PropertyTmpl::PropertyTmpl(const QString &key,
51  const QString &label, const QString &icon, PropertyOptions options)
52 {
53  PropertyTmpl other = Kopete::Global::Properties::self()->tmpl(key);
54  if(other.isNull())
55  {
56 // kDebug(14000) << "Creating new template for key = '" << key << "'";
57 
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));
65  }
66  else
67  {
68 // kDebug(14000) << "Using existing template for key = '" << key << "'";
69  d = other.d;
70  d->refCount++;
71  }
72 }
73 
74 PropertyTmpl::PropertyTmpl(const PropertyTmpl &other)
75 {
76  d = other.d;
77  d->refCount++;
78 }
79 
80 PropertyTmpl &PropertyTmpl::operator=(
81  const PropertyTmpl &other)
82 {
83  if (this == &other)
84  {
85 // kDebug(14000) << "trying to assign this to itself!";
86  return *this;
87  }
88  if( d == other.d )
89  {
90 // kDebug(14000) << "trying to assign d to itself!";
91  return *this;
92  }
93  d->refCount--;
94  if(d->refCount == 0)
95  {
96  if (!d->key.isEmpty()) // null property
97  Kopete::Global::Properties::self()->unregisterTemplate(d->key);
98  delete d;
99  }
100 
101  d = other.d;
102  d->refCount++;
103 
104  return *this;
105 }
106 
107 PropertyTmpl::~PropertyTmpl()
108 {
109  d->refCount--;
110  if(d->refCount == 0)
111  {
112  if (!d->key.isEmpty()) // null property
113  Kopete::Global::Properties::self()->unregisterTemplate(d->key);
114  delete d;
115  }
116 }
117 
118 bool PropertyTmpl::operator==(const PropertyTmpl &other) const
119 {
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);
125 }
126 
127 bool PropertyTmpl::operator!=(const PropertyTmpl &other) const
128 {
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);
134 }
135 
136 
137 const QString &PropertyTmpl::key() const
138 {
139  return d->key;
140 }
141 
142 const QString &PropertyTmpl::label() const
143 {
144  return d->label;
145 }
146 
147 const QString &PropertyTmpl::icon() const
148 {
149  return d->icon;
150 }
151 
152 PropertyTmpl::PropertyOptions PropertyTmpl::options() const
153 {
154  return d->options;
155 }
156 
157 bool PropertyTmpl::persistent() const
158 {
159  return d->options & PersistentProperty;
160 }
161 
162 bool PropertyTmpl::isRichText() const
163 {
164  return d->options & RichTextProperty;
165 }
166 
167 bool PropertyTmpl::isPrivate() const
168 {
169  return d->options & PrivateProperty;
170 }
171 
172 bool PropertyTmpl::isNull() const
173 {
174  return (!d || d->key.isNull());
175 }
176 
177 
178 // -----------------------------------------------------------------------------
179 
180 
181 Property Property::null;
182 
183 class Property::Private
184 {
185 public:
186  QVariant value;
187  PropertyTmpl propertyTemplate;
188 };
189 
190 Property::Property()
191  : d(new Private)
192 {
193 }
194 
195 Property::Property(const PropertyTmpl &tmpl,
196  const QVariant &val)
197  : d(new Private)
198 {
199  d->propertyTemplate = tmpl;
200  d->value = val;
201 }
202 
203 Property::Property(const Property& other)
204  : d(new Private)
205 {
206  d->propertyTemplate = other.d->propertyTemplate;
207  d->value = other.d->value;
208 }
209 
210 Property::~Property()
211 {
212  delete d;
213 }
214 
215 Property& Property::operator=(const Property& other)
216 {
217  if (this == &other)
218  {
219 // kDebug(14000) << "trying to assign this to itself!";
220  return *this;
221  }
222 
223  d->propertyTemplate = other.d->propertyTemplate;
224  d->value = other.d->value;
225 
226  return *this;
227 }
228 
229 const QVariant &Property::value() const
230 {
231  return d->value;
232 }
233 
234 const PropertyTmpl &Property::tmpl() const
235 {
236  return d->propertyTemplate;
237 }
238 
239 bool Property::isNull() const
240 {
241  return d->value.isNull();
242 }
243 
244 bool Property::isRichText() const
245 {
246  return d->propertyTemplate.isRichText();
247 }
248 
249 } // END namespace Kopete
Kopete::PropertyTmpl::operator!=
bool operator!=(const PropertyTmpl &other) const
Definition: kopeteproperty.cpp:127
kopeteproperty.h
Kopete::PropertyTmpl::persistent
bool persistent() const
Returns true if properties based on this template should be saved across Kopete sessions, false otherwise.
Definition: kopeteproperty.cpp:157
Kopete::PropertyTmpl::RichTextProperty
Definition: kopeteproperty.h:48
Kopete::Global::Properties::self
static Properties * self()
Singleton accessor for this class.
Definition: kopeteglobal.cpp:49
Kopete::PropertyTmpl::~PropertyTmpl
~PropertyTmpl()
Destructor.
Definition: kopeteproperty.cpp:107
Kopete::Property::isRichText
bool isRichText() const
Returns true if this property is HTML formatted.
Definition: kopeteproperty.cpp:244
Kopete::Property::~Property
~Property()
Destructor.
Definition: kopeteproperty.cpp:210
Kopete::Global::Properties::tmpl
const PropertyTmpl & tmpl(const QString &key) const
Return a template with defined by key, if no such template has been registered PropertyTmpl::null wil...
Definition: kopeteglobal.cpp:89
Kopete::PropertyTmpl
Definition: kopeteproperty.h:41
Kopete::Property::tmpl
const PropertyTmpl & tmpl() const
Getter for this properties template.
Definition: kopeteproperty.cpp:234
Kopete::PropertyTmpl::operator==
bool operator==(const PropertyTmpl &other) const
Definition: kopeteproperty.cpp:118
Kopete::PropertyTmpl::operator=
PropertyTmpl & operator=(const PropertyTmpl &other)
Definition: kopeteproperty.cpp:80
Kopete::PropertyTmpl::PersistentProperty
Definition: kopeteproperty.h:47
Kopete::PropertyTmpl::PropertyTmpl
PropertyTmpl()
Constructor only used for empty PropertyTmpl objects.
Definition: kopeteproperty.cpp:42
Kopete::Property::Property
Property()
Constructor only used for empty Property objects.
Definition: kopeteproperty.cpp:190
QString
Kopete::Property::operator=
Property & operator=(const Property &other)
Definition: kopeteproperty.cpp:215
Kopete::PropertyTmpl::isNull
bool isNull() const
Returns true if this object is an empty template.
Definition: kopeteproperty.cpp:172
Kopete::PropertyTmpl::isRichText
bool isRichText() const
Returns true if properties based on this template are HTML formatted.
Definition: kopeteproperty.cpp:162
Kopete::PropertyTmpl::isPrivate
bool isPrivate() const
Returns true if properties based on this template are invisible to the user.
Definition: kopeteproperty.cpp:167
Kopete::Property
Definition: kopeteproperty.h:150
Kopete::Property::null
static Property null
The null, i.e.
Definition: kopeteproperty.h:189
Kopete::PropertyTmpl::options
PropertyOptions options() const
Return the options for that property.
Definition: kopeteproperty.cpp:152
Kopete::PropertyTmpl::icon
const QString & icon() const
Getter for icon to show aside or instead of label()
Definition: kopeteproperty.cpp:147
Kopete::Property::value
const QVariant & value() const
Getter for this properties value.
Definition: kopeteproperty.cpp:229
Kopete::PropertyTmpl::label
const QString & label() const
Getter for i18ned label.
Definition: kopeteproperty.cpp:142
Kopete::Property::isNull
bool isNull() const
Returns true if this object is an empty Property (i.e.
Definition: kopeteproperty.cpp:239
Kopete::PropertyTmpl::PrivateProperty
Definition: kopeteproperty.h:49
Kopete::PropertyTmpl::key
const QString & key() const
Getter for the unique key.
Definition: kopeteproperty.cpp:137
Kopete::PropertyTmpl::null
static PropertyTmpl null
An empty template, check for it using isNull()
Definition: kopeteproperty.h:125
Kopete::PropertyTmpl::NoProperty
Definition: kopeteproperty.h:46
kopeteglobal.h
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:29:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kopete/libkopete

Skip menu "kopete/libkopete"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal