• 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
tagcreatejob.cpp
1 /*
2  Copyright (c) 2014 Christian Mollekopf <mollekopf@kolabsys.com>
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 "tagcreatejob.h"
21 #include "job_p.h"
22 #include "tag.h"
23 #include "protocolhelper_p.h"
24 #include <KLocalizedString>
25 
26 using namespace Akonadi;
27 
28 struct Akonadi::TagCreateJobPrivate : public JobPrivate
29 {
30  TagCreateJobPrivate(TagCreateJob *parent)
31  : JobPrivate(parent)
32  , mMerge(false)
33  {
34  }
35 
36  Tag mTag;
37  Tag mResultTag;
38  bool mMerge;
39 };
40 
41 TagCreateJob::TagCreateJob(const Akonadi::Tag &tag, QObject *parent)
42  : Job(new TagCreateJobPrivate(this), parent)
43 {
44  Q_D(TagCreateJob);
45  d->mTag = tag;
46 }
47 
48 void TagCreateJob::setMergeIfExisting(bool merge)
49 {
50  Q_D(TagCreateJob);
51  d->mMerge = merge;
52 }
53 
54 void TagCreateJob::doStart()
55 {
56  Q_D(TagCreateJob);
57 
58  if (d->mTag.gid().isEmpty()) {
59  kWarning() << "The gid of a new tag must not be empty";
60  setError(Job::Unknown);
61  setErrorText(i18n("Failed to create tag."));
62  emitResult();
63  return;
64  }
65 
66  QByteArray command = d->newTag() + " TAGAPPEND (";
67 
68  QList<QByteArray> list;
69  list << "GID";
70  list << ImapParser::quote(d->mTag.gid());
71 
72  if (d->mMerge) {
73  list << "MERGE";
74  }
75 
76  if (!d->mTag.type().isEmpty()) {
77  list << "MIMETYPE";
78  list << ImapParser::quote(d->mTag.type());
79  }
80  if (!d->mTag.remoteId().isEmpty()) {
81  list << "REMOTEID";
82  list << ImapParser::quote(d->mTag.remoteId());
83  }
84  if (d->mTag.parent().isValid()) {
85  list << "PARENT";
86  list << QString::number(d->mTag.parent().id()).toLatin1();
87  }
88  command += ImapParser::join(list, " ");
89  command += " "; // list of parts
90  const QByteArray attrs = ProtocolHelper::attributesToByteArray(d->mTag, false);
91  if (!attrs.isEmpty()) {
92  command += attrs;
93  }
94  command += ")";
95 
96  d->writeData(command);
97 }
98 
99 void TagCreateJob::doHandleResponse(const QByteArray &tag, const QByteArray &data)
100 {
101  Q_D(TagCreateJob);
102 
103  if (tag == "*") {
104  int begin = data.indexOf("TAGFETCH");
105  if (begin >= 0) {
106  // split fetch response into key/value pairs
107  QList<QByteArray> fetchResponse;
108  ImapParser::parseParenthesizedList(data, fetchResponse, begin + 8);
109  if (!d->mMerge) {
110  //If merge is enabled there is the possibility that existing attributes etc are not valid anymore
111  d->mResultTag = d->mTag;
112  }
113  ProtocolHelper::parseTagFetchResult(fetchResponse, d->mResultTag);
114  }
115  }
116 }
117 
118 Tag TagCreateJob::tag() const
119 {
120  Q_D(const TagCreateJob);
121  return d->mResultTag;
122 }
Akonadi::TagCreateJob::tag
Tag tag() const
Returns the created tag with the new unique id, or an invalid tag if the job failed.
Definition: tagcreatejob.cpp:118
Akonadi::TagCreateJob::doHandleResponse
virtual void doHandleResponse(const QByteArray &tag, const QByteArray &data)
This method should be reimplemented in the concrete jobs in case you want to handle incoming data...
Definition: tagcreatejob.cpp:99
QByteArray
Akonadi::Job::Unknown
Unknown error.
Definition: job.h:108
QByteArray::isEmpty
bool isEmpty() const
Akonadi::ProtocolHelper::attributesToByteArray
static QByteArray attributesToByteArray(const Entity &entity, bool ns=false)
Convert attributes to their protocol representation.
Definition: protocolhelper.cpp:232
Akonadi::Job
Base class for all actions in the Akonadi storage.
Definition: job.h:86
QByteArray::indexOf
int indexOf(char ch, int from) const
QString::number
QString number(int n, int base)
QObject
Akonadi::TagCreateJob::doStart
virtual void doStart()
This method must be reimplemented in the concrete jobs.
Definition: tagcreatejob.cpp:54
QList< QByteArray >
Akonadi::TagCreateJob::TagCreateJob
TagCreateJob(const Tag &tag, QObject *parent=0)
Creates a new tag create job.
Definition: tagcreatejob.cpp:41
Akonadi::TagCreateJob::setMergeIfExisting
void setMergeIfExisting(bool merge)
Merges the tag by GID if it is already existing, and returns the merged version.
Definition: tagcreatejob.cpp:48
Akonadi::TagCreateJob
Job that creates a new tag in the Akonadi storage.
Definition: tagcreatejob.h:34
Akonadi::JobPrivate
Definition: job_p.h:31
Akonadi::Tag
An Akonadi Tag.
Definition: tag.h:43
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