• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • 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
26using namespace Akonadi;
27
28EntityAnnotationsAttribute::EntityAnnotationsAttribute()
29{
30}
31
32EntityAnnotationsAttribute::EntityAnnotationsAttribute(const QMap<QByteArray, QByteArray> &annotations)
33 : mAnnotations(annotations)
34{
35}
36
37void EntityAnnotationsAttribute::setAnnotations(const QMap<QByteArray, QByteArray> &annotations)
38{
39 mAnnotations = annotations;
40}
41
42QMap<QByteArray, QByteArray> EntityAnnotationsAttribute::annotations() const
43{
44 return mAnnotations;
45}
46
47void EntityAnnotationsAttribute::insert(const QByteArray &key, const QString &value)
48{
49 mAnnotations.insert(key, value.toUtf8());
50}
51
52QString EntityAnnotationsAttribute::value(const QByteArray &key)
53{
54 return QString::fromUtf8(mAnnotations.value(key).data());
55}
56
57bool EntityAnnotationsAttribute::contains(const QByteArray &key) const
58{
59 return mAnnotations.contains(key);
60}
61
62QByteArray EntityAnnotationsAttribute::type() const
63{
64 static const QByteArray sType( "entityannotations" );
65 return sType;
66}
67
68Akonadi::Attribute *EntityAnnotationsAttribute::clone() const
69{
70 return new EntityAnnotationsAttribute(mAnnotations);
71}
72
73QByteArray 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
88void 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}
Akonadi::Attribute
Provides interface for custom attributes for Entity.
Definition attribute.h:139
Akonadi::EntityAnnotationsAttribute
An attribute for annotations.
Definition entityannotationsattribute.h:45
Akonadi::EntityAnnotationsAttribute::type
QByteArray type() const
Returns the type of the attribute.
Definition entityannotationsattribute.cpp:62
Akonadi::EntityAnnotationsAttribute::serialized
QByteArray serialized() const
Returns a QByteArray representation of the attribute which will be storaged.
Definition entityannotationsattribute.cpp:73
Akonadi::EntityAnnotationsAttribute::clone
Attribute * clone() const
Creates a copy of this attribute.
Definition entityannotationsattribute.cpp:68
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
Akonadi
FreeBusyManager::Singleton.
Definition actionstatemanager_p.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 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
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 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
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