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

akonadi

  • sources
  • kde-4.14
  • kdepimlibs
  • akonadi
tag.cpp
1 /*
2  Copyright (c) 2014 Christian Mollekopf <mollekopf@kolabsys.com>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "tag.h"
21 #include <akonadi/tagattribute.h>
22 
23 using namespace Akonadi;
24 
25 const char *Akonadi::Tag::PLAIN = "PLAIN";
26 
27 struct Akonadi::Tag::Private {
28  Private()
29  : id(-1)
30  {}
31 
32  ~Private()
33  {}
34 
35  Id id;
36  QByteArray gid;
37  QByteArray remoteId;
38  QScopedPointer<Tag> parent;
39  QByteArray type;
40 };
41 
42 Tag::Tag()
43  : AttributeEntity()
44  , d(new Private)
45 {
46 
47 }
48 
49 Tag::Tag(Tag::Id id)
50  : AttributeEntity()
51  , d(new Private)
52 {
53  d->id = id;
54 }
55 
56 Tag::Tag(const QString &name)
57  : AttributeEntity()
58  , d(new Private)
59 {
60  d->gid = name.toUtf8();
61  setName(name);
62  d->type = PLAIN;
63 }
64 
65 Tag::Tag(const Tag &other)
66  : AttributeEntity()
67  , d(new Private)
68 {
69  operator=(other);
70 }
71 
72 Tag::~Tag()
73 {
74 }
75 
76 Tag &Tag::operator=(const Tag &other)
77 {
78  d->id = other.d->id;
79  d->gid = other.d->gid;
80  d->remoteId = other.d->remoteId;
81  d->type = other.d->type;
82  if (other.d->parent) {
83  d->parent.reset(new Tag(*other.d->parent));
84  }
85  AttributeEntity::operator=(other);
86  return *this;
87 }
88 
89 AttributeEntity &Tag::operator=(const AttributeEntity &other)
90 {
91  return operator=(*static_cast<const Tag *>(&other));
92 }
93 
94 bool Tag::operator==(const Tag &other) const
95 {
96  if (isValid() && other.isValid()) {
97  return d->id == other.d->id;
98  }
99  return d->gid == other.d->gid;
100 }
101 
102 Tag Tag::fromUrl(const KUrl &url)
103 {
104  if (url.protocol() != QLatin1String("akonadi")) {
105  return Tag();
106  }
107 
108  const QString tagStr = url.queryItem(QLatin1String("tag"));
109  bool ok = false;
110  Tag::Id itemId = tagStr.toLongLong(&ok);
111  if (!ok) {
112  return Tag();
113  }
114 
115  return Tag(itemId);
116 }
117 
118 KUrl Tag::url() const
119 {
120  KUrl url;
121  url.setProtocol(QString::fromLatin1("akonadi"));
122  url.addQueryItem(QLatin1String("tag"), QString::number(id()));
123  return url;
124 }
125 
126 void Tag::setId(Tag::Id identifier)
127 {
128  d->id = identifier;
129 }
130 
131 Tag::Id Tag::id() const
132 {
133  return d->id;
134 }
135 
136 void Tag::setGid(const QByteArray &gid) const
137 {
138  d->gid = gid;
139 }
140 
141 QByteArray Tag::gid() const
142 {
143  return d->gid;
144 }
145 
146 void Tag::setRemoteId(const QByteArray &remoteId) const
147 {
148  d->remoteId = remoteId;
149 }
150 
151 QByteArray Tag::remoteId() const
152 {
153  return d->remoteId;
154 }
155 
156 void Tag::setName(const QString &name)
157 {
158  if (!name.isEmpty()) {
159  TagAttribute *const attr = attribute<TagAttribute>(AttributeEntity::AddIfMissing);
160  attr->setDisplayName(name);
161  }
162 }
163 
164 QString Tag::name() const
165 {
166  const TagAttribute *const attr = attribute<TagAttribute>();
167  const QString displayName = attr ? attr->displayName() : QString();
168  return !displayName.isEmpty() ? displayName : QString::fromUtf8(d->gid);
169 }
170 
171 void Tag::setParent(const Tag &parent)
172 {
173  if (parent.isValid()) {
174  d->parent.reset(new Tag(parent));
175  }
176 }
177 
178 Tag Tag::parent() const
179 {
180  if (!d->parent) {
181  return Tag();
182  }
183  return *d->parent;
184 }
185 
186 void Tag::setType(const QByteArray &type) const
187 {
188  d->type = type;
189 }
190 
191 QByteArray Tag::type() const
192 {
193  return d->type;
194 }
195 
196 bool Tag::isValid() const
197 {
198  return d->id >= 0;
199 }
200 
201 bool Tag::isImmutable() const
202 {
203  return (d->type.isEmpty() || d->type == PLAIN);
204 }
205 
206 uint qHash(const Tag &tag)
207 {
208  return qHash(tag.id());
209 }
210 
211 QDebug &operator<<(QDebug &debug, const Tag &tag)
212 {
213  debug << "Akonadi::Tag( ID " << tag.id() << ", GID " << tag.gid() << ", parent" << tag.parent().id() << ")";
214  return debug;
215 }
Akonadi::Tag::setId
void setId(Id identifier)
Sets the unique identifier of the tag.
Definition: tag.cpp:126
QByteArray
Akonadi::Tag::id
Id id() const
Returns the unique identifier of the tag.
Definition: tag.cpp:131
Akonadi::TagAttribute::setDisplayName
void setDisplayName(const QString &name)
Sets the name that should be used for display.
Definition: tagattribute.cpp:61
Akonadi::AttributeEntity
Parent class for entities that can have attributes.
Definition: attributeentity.h:40
Akonadi::Tag::PLAIN
static const char * PLAIN
The PLAIN type has the following properties:
Definition: tag.h:57
QString::number
QString number(int n, int base)
QString::fromUtf8
QString fromUtf8(const char *str, int size)
Akonadi::Tag::isImmutable
bool isImmutable() const
Returns true if the tag is immutable (cannot be modified after creation).
Definition: tag.cpp:201
QScopedPointer
QString::isEmpty
bool isEmpty() const
Akonadi::AttributeEntity::AddIfMissing
Creates the attribute if it is missing.
Definition: attributeentity.h:92
QString
Akonadi::TagAttribute::displayName
QString displayName() const
Returns the name that should be used for display.
Definition: tagattribute.cpp:56
Akonadi::TagAttribute
Attribute that stores the properties that are used to display a tag.
Definition: tagattribute.h:38
QDebug
QLatin1String
Akonadi::Tag
An Akonadi Tag.
Definition: tag.h:43
Akonadi::Tag::url
KUrl url() const
Returns the url of the tag.
Definition: tag.cpp:118
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QString::toLongLong
qlonglong toLongLong(bool *ok, int base) const
QString::toUtf8
QByteArray toUtf8() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:03 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

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