• 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
entityannotationsattribute.cpp
1 /*
2  * Copyright (C) 2008 Omat Holding B.V. <info@omat.nl>
3  * Copyright (C) 2014 Christian Mollekopf <mollekopf@kolabsys.com>
4  *
5  * This library is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Library General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13  * License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to the
17  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  * 02110-1301, USA.
19  */
20 
21 #include "entityannotationsattribute.h"
22 
23 #include <QByteArray>
24 #include <QString>
25 
26 using namespace Akonadi;
27 
28 EntityAnnotationsAttribute::EntityAnnotationsAttribute()
29 {
30 }
31 
32 EntityAnnotationsAttribute::EntityAnnotationsAttribute(const QMap<QByteArray, QByteArray> &annotations)
33  : mAnnotations(annotations)
34 {
35 }
36 
37 void EntityAnnotationsAttribute::setAnnotations(const QMap<QByteArray, QByteArray> &annotations)
38 {
39  mAnnotations = annotations;
40 }
41 
42 QMap<QByteArray, QByteArray> EntityAnnotationsAttribute::annotations() const
43 {
44  return mAnnotations;
45 }
46 
47 void EntityAnnotationsAttribute::insert(const QByteArray &key, const QString &value)
48 {
49  mAnnotations.insert(key, value.toUtf8());
50 }
51 
52 QString EntityAnnotationsAttribute::value(const QByteArray &key)
53 {
54  return QString::fromUtf8(mAnnotations.value(key).data());
55 }
56 
57 bool EntityAnnotationsAttribute::contains(const QByteArray &key) const
58 {
59  return mAnnotations.contains(key);
60 }
61 
62 QByteArray EntityAnnotationsAttribute::type() const
63 {
64  static const QByteArray sType( "entityannotations" );
65  return sType;
66 }
67 
68 Akonadi::Attribute *EntityAnnotationsAttribute::clone() const
69 {
70  return new EntityAnnotationsAttribute(mAnnotations);
71 }
72 
73 QByteArray EntityAnnotationsAttribute::serialized() const
74 {
75  QByteArray result = "";
76 
77  Q_FOREACH (const QByteArray &key, mAnnotations.keys()) {
78  result += key;
79  result += ' ';
80  result += mAnnotations[key];
81  result += " % "; // We use this separator as '%' is not allowed in keys or values
82  }
83  result.chop(3);
84 
85  return result;
86 }
87 
88 void EntityAnnotationsAttribute::deserialize(const QByteArray &data)
89 {
90  mAnnotations.clear();
91  const QList<QByteArray> lines = data.split('%');
92 
93  for (int i = 0; i < lines.size(); ++i) {
94  QByteArray line = lines[i];
95  if (i != 0 && line.startsWith(' ')) {
96  line = line.mid(1);
97  }
98  if (i != lines.size() - 1 && line.endsWith(' ')) {
99  line.chop(1);
100  }
101  if (line.trimmed().isEmpty()) {
102  continue;
103  }
104  int wsIndex = line.indexOf(' ');
105  if (wsIndex > 0) {
106  const QByteArray key = line.mid(0, wsIndex);
107  const QByteArray value = line.mid(wsIndex + 1);
108  mAnnotations[key] = value;
109  } else {
110  mAnnotations.insert(line, QByteArray());
111  }
112  }
113 }
QMap::contains
bool contains(const Key &key) const
QByteArray::split
QList< QByteArray > split(char sep) const
QByteArray::trimmed
QByteArray trimmed() const
QByteArray
QMap< QByteArray, QByteArray >
QByteArray::chop
void chop(int n)
QByteArray::isEmpty
bool isEmpty() const
QByteArray::startsWith
bool startsWith(const QByteArray &ba) const
Akonadi::Attribute
Provides interface for custom attributes for Entity.
Definition: attribute.h:138
QMap::clear
void clear()
QList::size
int size() const
QMap::keys
QList< Key > keys() const
QByteArray::indexOf
int indexOf(char ch, int from) const
QString::fromUtf8
QString fromUtf8(const char *str, int size)
Akonadi::EntityAnnotationsAttribute::clone
Attribute * clone() const
Creates a copy of this attribute.
Definition: entityannotationsattribute.cpp:68
Akonadi::EntityAnnotationsAttribute::serialized
QByteArray serialized() const
Returns a QByteArray representation of the attribute which will be storaged.
Definition: entityannotationsattribute.cpp:73
Akonadi::EntityAnnotationsAttribute::deserialize
void deserialize(const QByteArray &data)
Sets the data of this attribute, using the same encoding as returned by toByteArray().
Definition: entityannotationsattribute.cpp:88
QString
QList< QByteArray >
QByteArray::mid
QByteArray mid(int pos, int len) const
Akonadi::EntityAnnotationsAttribute
An attribute for annotations.
Definition: entityannotationsattribute.h:44
QMap::insert
iterator insert(const Key &key, const T &value)
QByteArray::endsWith
bool endsWith(const QByteArray &ba) const
Akonadi::EntityAnnotationsAttribute::type
QByteArray type() const
Returns the type of the attribute.
Definition: entityannotationsattribute.cpp:62
QMap::value
const T value(const Key &key) const
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