Akonadi

entitydisplayattribute.cpp
1/*
2 SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "entitydisplayattribute.h"
8
9#include "private/imapparser_p.h"
10
11using namespace Akonadi;
12
13class Akonadi::EntityDisplayAttributePrivate
14{
15public:
16 QString name;
17 QString icon;
18 QString activeIcon;
19 QColor backgroundColor;
20};
21
23 : d(new EntityDisplayAttributePrivate())
24{
25}
26
28
30{
31 return d->name;
32}
33
35{
36 d->name = name;
37}
38
40{
41 return QIcon::fromTheme(d->icon);
42}
43
45{
46 return d->icon;
47}
48
50{
51 d->icon = icon;
52}
53
55{
56 static const QByteArray sType("ENTITYDISPLAY");
57 return sType;
58}
59
61{
62 auto attr = new EntityDisplayAttribute();
63 attr->d->name = d->name;
64 attr->d->icon = d->icon;
65 attr->d->activeIcon = d->activeIcon;
66 attr->d->backgroundColor = d->backgroundColor;
67 return attr;
68}
69
71{
73 l.reserve(4);
74 l << ImapParser::quote(d->name.toUtf8());
75 l << ImapParser::quote(d->icon.toUtf8());
76 l << ImapParser::quote(d->activeIcon.toUtf8());
77 QList<QByteArray> components;
78 if (d->backgroundColor.isValid()) {
79 components = QList<QByteArray>() << QByteArray::number(d->backgroundColor.red()) << QByteArray::number(d->backgroundColor.green())
80 << QByteArray::number(d->backgroundColor.blue()) << QByteArray::number(d->backgroundColor.alpha());
81 }
82 l << '(' + ImapParser::join(components, " ") + ')';
83 return '(' + ImapParser::join(l, " ") + ')';
84}
85
87{
89 ImapParser::parseParenthesizedList(data, l);
90 int size = l.size();
91 Q_ASSERT(size >= 2);
92 d->name = QString::fromUtf8(l[0]);
93 d->icon = QString::fromUtf8(l[1]);
94 if (size >= 3) {
95 d->activeIcon = QString::fromUtf8(l[2]);
96 }
97 if (size >= 4) {
98 if (!l[3].isEmpty()) {
99 QList<QByteArray> componentData;
100 ImapParser::parseParenthesizedList(l[3], componentData);
101 if (componentData.size() != 4) {
102 return;
103 }
104 QList<int> components;
105 components.reserve(4);
106
107 bool ok;
108 for (int i = 0; i <= 3; ++i) {
109 components << componentData.at(i).toInt(&ok);
110 if (!ok) {
111 return;
112 }
113 }
114 d->backgroundColor = QColor(components.at(0), components.at(1), components.at(2), components.at(3));
115 }
116 }
117}
118
120{
121 d->activeIcon = name;
122}
123
125{
126 return QIcon::fromTheme(d->activeIcon);
127}
128
130{
131 return d->activeIcon;
132}
133
135{
136 return d->backgroundColor;
137}
138
140{
141 d->backgroundColor = color;
142}
Attribute that stores the properties that are used to display an entity.
void setIconName(const QString &name)
Sets the icon name for the default icon.
QIcon activeIcon() const
Returns the icon that should be used for this collection or item when active.
void setBackgroundColor(const QColor &color)
Sets the backgroundColor to color.
void setActiveIconName(const QString &name)
Sets the icon name for the active icon.
~EntityDisplayAttribute() override
Destroys the entity display attribute.
QIcon icon() const
Returns the icon that should be used for this collection or item.
QByteArray type() const override
Returns the type of the attribute.
EntityDisplayAttribute()
Creates a new entity display attribute.
QByteArray serialized() const override
Returns a QByteArray representation of the attribute which will be storaged.
QColor backgroundColor() const
Returns the backgroundColor or an invalid color if none is set.
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.
QString activeIconName() const
Returns the icon name of an active item.
void deserialize(const QByteArray &data) override
Sets the data of this attribute, using the same encoding as returned by toByteArray().
EntityDisplayAttribute * clone() const override
Creates a copy of this attribute.
QString iconName() const
Returns the icon name of the icon returned by icon().
Helper integration between Akonadi and Qt.
QByteArray number(double n, char format, int precision)
QIcon fromTheme(const QString &name)
const_reference at(qsizetype i) const const
void reserve(qsizetype size)
qsizetype size() const const
QString fromUtf8(QByteArrayView str)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 27 2024 11:48:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.