Akonadi

entitydisplayattribute.cpp
1 /*
2  Copyright (c) 2008 Volker Krause <[email protected]>
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 "entitydisplayattribute.h"
21 
22 #include "private/imapparser_p.h"
23 
24 #include <QIcon>
25 
26 using namespace Akonadi;
27 
28 class Q_DECL_HIDDEN EntityDisplayAttribute::Private
29 {
30 public:
31  Private()
32  {
33  }
34  QString name;
35  QString icon;
36  QString activeIcon;
37  QColor backgroundColor;
38 };
39 
41  : d(new Private)
42 {
43 }
44 
46 {
47  delete d;
48 }
49 
51 {
52  return d->name;
53 }
54 
56 {
57  d->name = name;
58 }
59 
61 {
62  return QIcon::fromTheme(d->icon);
63 }
64 
66 {
67  return d->icon;
68 }
69 
71 {
72  d->icon = icon;
73 }
74 
76 {
77  static const QByteArray sType("ENTITYDISPLAY");
78  return sType;
79 }
80 
82 {
84  attr->d->name = d->name;
85  attr->d->icon = d->icon;
86  attr->d->activeIcon = d->activeIcon;
87  attr->d->backgroundColor = d->backgroundColor;
88  return attr;
89 }
90 
92 {
94  l.reserve(4);
95  l << ImapParser::quote(d->name.toUtf8());
96  l << ImapParser::quote(d->icon.toUtf8());
97  l << ImapParser::quote(d->activeIcon.toUtf8());
98  QList<QByteArray> components;
99  if (d->backgroundColor.isValid()) {
100  components = QList<QByteArray>() << QByteArray::number(d->backgroundColor.red())
101  << QByteArray::number(d->backgroundColor.green())
102  << QByteArray::number(d->backgroundColor.blue())
103  << QByteArray::number(d->backgroundColor.alpha());
104  }
105  l << '(' + ImapParser::join(components, " ") + ')';
106  return '(' + ImapParser::join(l, " ") + ')';
107 }
108 
110 {
112  ImapParser::parseParenthesizedList(data, l);
113  int size = l.size();
114  Q_ASSERT(size >= 2);
115  d->name = QString::fromUtf8(l[0]);
116  d->icon = QString::fromUtf8(l[1]);
117  if (size >= 3) {
118  d->activeIcon = QString::fromUtf8(l[2]);
119  }
120  if (size >= 4) {
121  if (!l[3].isEmpty()) {
122  QList<QByteArray> componentData;
123  ImapParser::parseParenthesizedList(l[3], componentData);
124  if (componentData.size() != 4) {
125  return;
126  }
127  QVector<int> components;
128  components.reserve(4);
129 
130  bool ok;
131  for (int i = 0; i <= 3; ++i) {
132  components << componentData.at(i).toInt(&ok);
133  if (!ok) {
134  return;
135  }
136  }
137  d->backgroundColor = QColor(components.at(0), components.at(1), components.at(2), components.at(3));
138  }
139  }
140 }
141 
143 {
144  d->activeIcon = name;
145 }
146 
148 {
149  return QIcon::fromTheme(d->activeIcon);
150 }
151 
153 {
154  return d->activeIcon;
155 }
156 
158 {
159  return d->backgroundColor;
160 }
161 
163 {
164  d->backgroundColor = color;
165 }
QString activeIconName() const
Returns the icon name of an active item.
QString name(const QVariant &location)
QString iconName() const
Returns the icon name of the icon returned by icon().
QByteArray type() const override
Returns the type of the attribute.
void reserve(int alloc)
QString displayName() const
Returns the name that should be used for display.
const T & at(int i) const const
void deserialize(const QByteArray &data) override
Sets the data of this attribute, using the same encoding as returned by toByteArray().
int size() const const
void setActiveIconName(const QString &name)
Sets the icon name for the active icon.
QString fromUtf8(const char *str, int size)
void setIconName(const QString &name)
Sets the icon name for the default icon.
QByteArray number(int n, int base)
void setBackgroundColor(const QColor &color)
Sets the backgroundColor to color.
EntityDisplayAttribute * clone() const override
Creates a copy of this attribute.
void setDisplayName(const QString &name)
Sets the name that should be used for display.
QByteArray serialized() const override
Returns a QByteArray representation of the attribute which will be storaged.
void reserve(int size)
const T & at(int i) const const
QColor backgroundColor() const
Returns the backgroundColor or an invalid color if none is set.
EntityDisplayAttribute()
Creates a new entity display attribute.
Definition: item.h:44
Helper integration between Akonadi and Qt.
QIcon icon() const
Returns the icon that should be used for this collection or item.
QIcon fromTheme(const QString &name)
~EntityDisplayAttribute() override
Destroys the entity display attribute.
Attribute that stores the properties that are used to display an entity.
QIcon activeIcon() const
Returns the icon that should be used for this collection or item when active.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Jun 4 2020 23:08:41 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.