21#include <akonadi/tagattribute.h>
27struct Akonadi::Tag::Private {
38 QScopedPointer<Tag> parent;
56Tag::Tag(
const QString &name)
60 d->gid = name.toUtf8();
65Tag::Tag(
const Tag &other)
76Tag &Tag::operator=(
const Tag &other)
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));
85 AttributeEntity::operator=(other);
91 return operator=(*
static_cast<const Tag *
>(&other));
94bool Tag::operator==(
const Tag &other)
const
96 if (isValid() && other.isValid()) {
97 return d->id == other.d->id;
99 return d->gid == other.d->gid;
102Tag Tag::fromUrl(
const KUrl &url)
104 if (
url.protocol() != QLatin1String(
"akonadi")) {
108 const QString tagStr =
url.queryItem(QLatin1String(
"tag"));
110 Tag::Id itemId = tagStr.toLongLong(&ok);
121 url.setProtocol(QString::fromLatin1(
"akonadi"));
122 url.addQueryItem(QLatin1String(
"tag"), QString::number(
id()));
136void Tag::setGid(
const QByteArray &gid)
const
141QByteArray Tag::gid()
const
146void Tag::setRemoteId(
const QByteArray &remoteId)
const
148 d->remoteId = remoteId;
151QByteArray Tag::remoteId()
const
156void Tag::setName(
const QString &name)
158 if (!name.isEmpty()) {
164QString Tag::name()
const
166 const TagAttribute *
const attr = attribute<TagAttribute>();
167 const QString displayName = attr ? attr->
displayName() : QString();
168 return !displayName.isEmpty() ? displayName : QString::fromUtf8(d->gid);
171void Tag::setParent(
const Tag &parent)
173 if (parent.isValid()) {
174 d->parent.reset(
new Tag(parent));
178Tag Tag::parent()
const
186void Tag::setType(
const QByteArray &type)
const
191QByteArray Tag::type()
const
196bool Tag::isValid()
const
203 return (d->type.isEmpty() || d->type ==
PLAIN);
206uint qHash(
const Tag &tag)
208 return qHash(tag.id());
211QDebug &operator<<(QDebug &debug,
const Tag &tag)
213 debug <<
"Akonadi::Tag( ID " << tag.id() <<
", GID " << tag.gid() <<
", parent" << tag.parent().id() <<
")";
Parent class for entities that can have attributes.
@ AddIfMissing
Creates the attribute if it is missing.
Attribute that stores the properties that are used to display a tag.
QString displayName() const
Returns the name that should be used for display.
void setDisplayName(const QString &name)
Sets the name that should be used for display.
Id id() const
Returns the unique identifier of the tag.
bool isImmutable() const
Returns true if the tag is immutable (cannot be modified after creation).
KUrl url() const
Returns the url of the tag.
static const char * PLAIN
The PLAIN type has the following properties:
void setId(Id identifier)
Sets the unique identifier of the tag.
FreeBusyManager::Singleton.