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

akonadi

  • 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
23using namespace Akonadi;
24
25const char *Akonadi::Tag::PLAIN = "PLAIN";
26
27struct 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
42Tag::Tag()
43 : AttributeEntity()
44 , d(new Private)
45{
46
47}
48
49Tag::Tag(Tag::Id id)
50 : AttributeEntity()
51 , d(new Private)
52{
53 d->id = id;
54}
55
56Tag::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
65Tag::Tag(const Tag &other)
66 : AttributeEntity()
67 , d(new Private)
68{
69 operator=(other);
70}
71
72Tag::~Tag()
73{
74}
75
76Tag &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
89AttributeEntity &Tag::operator=(const AttributeEntity &other)
90{
91 return operator=(*static_cast<const Tag *>(&other));
92}
93
94bool 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
102Tag 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
118KUrl 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
126void Tag::setId(Tag::Id identifier)
127{
128 d->id = identifier;
129}
130
131Tag::Id Tag::id() const
132{
133 return d->id;
134}
135
136void Tag::setGid(const QByteArray &gid) const
137{
138 d->gid = gid;
139}
140
141QByteArray Tag::gid() const
142{
143 return d->gid;
144}
145
146void Tag::setRemoteId(const QByteArray &remoteId) const
147{
148 d->remoteId = remoteId;
149}
150
151QByteArray Tag::remoteId() const
152{
153 return d->remoteId;
154}
155
156void 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
164QString 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
171void Tag::setParent(const Tag &parent)
172{
173 if (parent.isValid()) {
174 d->parent.reset(new Tag(parent));
175 }
176}
177
178Tag Tag::parent() const
179{
180 if (!d->parent) {
181 return Tag();
182 }
183 return *d->parent;
184}
185
186void Tag::setType(const QByteArray &type) const
187{
188 d->type = type;
189}
190
191QByteArray Tag::type() const
192{
193 return d->type;
194}
195
196bool Tag::isValid() const
197{
198 return d->id >= 0;
199}
200
201bool Tag::isImmutable() const
202{
203 return (d->type.isEmpty() || d->type == PLAIN);
204}
205
206uint qHash(const Tag &tag)
207{
208 return qHash(tag.id());
209}
210
211QDebug &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::AttributeEntity
Parent class for entities that can have attributes.
Definition: attributeentity.h:40
Akonadi::AttributeEntity::AddIfMissing
@ AddIfMissing
Creates the attribute if it is missing.
Definition: attributeentity.h:92
Akonadi::TagAttribute
Attribute that stores the properties that are used to display a tag.
Definition: tagattribute.h:39
Akonadi::TagAttribute::displayName
QString displayName() const
Returns the name that should be used for display.
Definition: tagattribute.cpp:56
Akonadi::TagAttribute::setDisplayName
void setDisplayName(const QString &name)
Sets the name that should be used for display.
Definition: tagattribute.cpp:61
Akonadi::Tag
An Akonadi Tag.
Definition: tag.h:44
Akonadi::Tag::id
Id id() const
Returns the unique identifier of the tag.
Definition: tag.cpp:131
Akonadi::Tag::isImmutable
bool isImmutable() const
Returns true if the tag is immutable (cannot be modified after creation).
Definition: tag.cpp:201
Akonadi::Tag::url
KUrl url() const
Returns the url of the tag.
Definition: tag.cpp:118
Akonadi::Tag::PLAIN
static const char * PLAIN
The PLAIN type has the following properties:
Definition: tag.h:57
Akonadi::Tag::setId
void setId(Id identifier)
Sets the unique identifier of the tag.
Definition: tag.cpp:126
Akonadi
FreeBusyManager::Singleton.
Definition: actionstatemanager_p.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 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-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 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
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