• 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
tagattribute.cpp
1 /*
2  Copyright (c) 2008 Volker Krause <vkrause@kde.org>
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 "tagattribute.h"
21 
22 #include "imapparser_p.h"
23 
24 #include <KIcon>
25 
26 using namespace Akonadi;
27 
28 class TagAttribute::Private
29 {
30 public:
31  Private()
32  : inToolbar(false)
33  , priority(-1)
34  {}
35 
36  QString name;
37  QString icon;
38  QColor backgroundColor;
39  QColor textColor;
40  QString font;
41  bool inToolbar;
42  QString shortcut;
43  int priority;
44 };
45 
46 TagAttribute::TagAttribute()
47  : d(new Private)
48 {
49 }
50 
51 TagAttribute::~TagAttribute()
52 {
53  delete d;
54 }
55 
56 QString TagAttribute::displayName() const
57 {
58  return d->name;
59 }
60 
61 void TagAttribute::setDisplayName(const QString &name)
62 {
63  d->name = name;
64 }
65 
66 QString TagAttribute::iconName() const
67 {
68  return d->icon;
69 }
70 
71 void TagAttribute::setIconName(const QString &icon)
72 {
73  d->icon = icon;
74 }
75 
76 QByteArray Akonadi::TagAttribute::type() const
77 {
78  static const QByteArray sType( "TAG" );
79  return sType;
80 }
81 
82 TagAttribute *TagAttribute::clone() const
83 {
84  TagAttribute *attr = new TagAttribute();
85  attr->d->name = d->name;
86  attr->d->icon = d->icon;
87  attr->d->backgroundColor = d->backgroundColor;
88  attr->d->textColor = d->textColor;
89  attr->d->font = d->font;
90  attr->d->inToolbar = d->inToolbar;
91  attr->d->shortcut = d->shortcut;
92  attr->d->priority = d->priority;
93  return attr;
94 }
95 
96 QByteArray TagAttribute::serialized() const
97 {
98  QList<QByteArray> l;
99  l << ImapParser::quote(d->name.toUtf8());
100  l << ImapParser::quote(d->icon.toUtf8());
101  l << ImapParser::quote(d->font.toUtf8());
102  l << ImapParser::quote(d->shortcut.toUtf8());
103  l << ImapParser::quote(QString::number(d->inToolbar).toUtf8());
104  {
105  QList<QByteArray> components;
106  if (d->backgroundColor.isValid()) {
107  components = QList<QByteArray>() << QByteArray::number(d->backgroundColor.red())
108  << QByteArray::number(d->backgroundColor.green())
109  << QByteArray::number(d->backgroundColor.blue())
110  << QByteArray::number(d->backgroundColor.alpha());
111  }
112  l << '(' + ImapParser::join(components, " ") + ')';
113  }
114  {
115  QList<QByteArray> components;
116  if (d->textColor.isValid()) {
117  components = QList<QByteArray>() << QByteArray::number(d->textColor.red())
118  << QByteArray::number(d->textColor.green())
119  << QByteArray::number(d->textColor.blue())
120  << QByteArray::number(d->textColor.alpha());
121  }
122  l << '(' + ImapParser::join(components, " ") + ')';
123  }
124  l << ImapParser::quote(QString::number(d->priority).toUtf8());
125  return '(' + ImapParser::join(l, " ") + ')';
126 }
127 
128 static QColor parseColor(const QByteArray &data)
129 {
130  QList<QByteArray> componentData;
131  ImapParser::parseParenthesizedList(data, componentData);
132  if (componentData.size() != 4) {
133  return QColor();
134  }
135  QList<int> components;
136  bool ok;
137  for (int i = 0; i <= 3; ++i) {
138  components << componentData.at(i).toInt(&ok);
139  if (!ok) {
140  return QColor();
141  }
142  }
143  return QColor(components.at(0), components.at(1), components.at(2), components.at(3));
144 }
145 
146 void TagAttribute::deserialize(const QByteArray &data)
147 {
148  QList<QByteArray> l;
149  ImapParser::parseParenthesizedList(data, l);
150  int size = l.size();
151  Q_ASSERT(size >= 7);
152  d->name = QString::fromUtf8(l[0]);
153  d->icon = QString::fromUtf8(l[1]);
154  d->font = QString::fromUtf8(l[2]);
155  d->shortcut = QString::fromUtf8(l[3]);
156  d->inToolbar = QString::fromUtf8(l[4]).toInt();
157  if (!l[5].isEmpty()) {
158  d->backgroundColor = parseColor(l[5]);
159  }
160  if (!l[6].isEmpty()) {
161  d->textColor = parseColor(l[6]);
162  }
163  if (l.size() >= 8) {
164  d->priority = QString::fromUtf8(l[7]).toInt();
165  }
166 }
167 
168 QColor TagAttribute::backgroundColor() const
169 {
170  return d->backgroundColor;
171 }
172 
173 void TagAttribute::setBackgroundColor(const QColor &color)
174 {
175  d->backgroundColor = color;
176 }
177 
178 void TagAttribute::setTextColor(const QColor &color)
179 {
180  d->textColor = color;
181 }
182 
183 QColor TagAttribute::textColor() const
184 {
185  return d->textColor;
186 }
187 
188 void TagAttribute::setFont(const QString &font)
189 {
190  d->font = font;
191 }
192 
193 QString TagAttribute::font() const
194 {
195  return d->font;
196 }
197 
198 void TagAttribute::setInToolbar(bool inToolbar)
199 {
200  d->inToolbar = inToolbar;
201 }
202 
203 bool TagAttribute::inToolbar() const
204 {
205  return d->inToolbar;
206 }
207 
208 void TagAttribute::setShortcut(const QString &shortcut)
209 {
210  d->shortcut = shortcut;
211 }
212 
213 QString TagAttribute::shortcut() const
214 {
215  return d->shortcut;
216 }
217 
218 void TagAttribute::setPriority(int priority)
219 {
220  d->priority = priority;
221 }
222 
223 int TagAttribute::priority() const
224 {
225  return d->priority;
226 }
Akonadi::TagAttribute::type
QByteArray type() const
Returns the type of the attribute.
Definition: tagattribute.cpp:76
QByteArray
Akonadi::TagAttribute::setPriority
void setPriority(int priority)
Sets the priority of the tag.
Definition: tagattribute.cpp:218
QList::at
const T & at(int i) const
Akonadi::TagAttribute::serialized
QByteArray serialized() const
Returns a QByteArray representation of the attribute which will be storaged.
Definition: tagattribute.cpp:96
Akonadi::TagAttribute::setDisplayName
void setDisplayName(const QString &name)
Sets the name that should be used for display.
Definition: tagattribute.cpp:61
QList::size
int size() const
QString::number
QString number(int n, int base)
QString::fromUtf8
QString fromUtf8(const char *str, int size)
QString::toInt
int toInt(bool *ok, int base) const
Akonadi::TagAttribute::priority
int priority() const
Returns the priority of the tag.
Definition: tagattribute.cpp:223
QByteArray::number
QByteArray number(int n, int base)
Akonadi::TagAttribute::iconName
QString iconName() const
Returns the icon name of the icon returned by icon().
Definition: tagattribute.cpp:66
QString
QList< QByteArray >
QColor
Akonadi::TagAttribute::deserialize
void deserialize(const QByteArray &data)
Sets the data of this attribute, using the same encoding as returned by toByteArray().
Definition: tagattribute.cpp:146
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
Akonadi::TagAttribute::setIconName
void setIconName(const QString &name)
Sets the icon name for the default icon.
Definition: tagattribute.cpp:71
Akonadi::TagAttribute::clone
TagAttribute * clone() const
Creates a copy of this attribute.
Definition: tagattribute.cpp:82
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