• 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
tagmodifyjob.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 "tagmodifyjob.h"
21 #include "job_p.h"
22 #include "tag.h"
23 #include "protocolhelper_p.h"
24 #include "changemediator_p.h"
25 
26 using namespace Akonadi;
27 
28 struct Akonadi::TagModifyJobPrivate : public JobPrivate
29 {
30  TagModifyJobPrivate(TagModifyJob *parent)
31  : JobPrivate(parent)
32  {
33  }
34 
35  Tag mTag;
36 };
37 
38 TagModifyJob::TagModifyJob(const Akonadi::Tag &tag, QObject *parent)
39  : Job(new TagModifyJobPrivate(this), parent)
40 {
41  Q_D(TagModifyJob);
42  d->mTag = tag;
43 }
44 
45 void TagModifyJob::doStart()
46 {
47  Q_D(TagModifyJob);
48 
49  QList<QByteArray> list;
50  if (!d->mTag.remoteId().isEmpty()) {
51  list << "REMOTEID";
52  list << ImapParser::quote(d->mTag.remoteId());
53  }
54  if (!d->mTag.type().isEmpty()) {
55  list << "MIMETYPE";
56  list << ImapParser::quote(d->mTag.type());
57  }
58  if (d->mTag.parent().isValid() && !d->mTag.isImmutable()) {
59  list << "PARENT";
60  list << QString::number(d->mTag.parent().id()).toLatin1();
61  }
62 
63  QByteArray command = d->newTag();
64  try {
65  command += ProtocolHelper::tagSetToByteArray(Tag::List() << d->mTag, "TAGSTORE");
66  } catch (const std::exception &e) {
67  setError(Unknown);
68  setErrorText(QString::fromUtf8(e.what()));
69  emitResult();
70  return;
71  }
72  command += " (";
73  command += ImapParser::join(list, " ");
74  command += " ";
75 
76  if (!d->mTag.attributes().isEmpty()) {
77  command += ProtocolHelper::attributesToByteArray(d->mTag, false);
78  }
79  if (!d->mTag.removedAttributes().isEmpty()) {
80  QList<QByteArray> l;
81  Q_FOREACH (const QByteArray &attr, d->mTag.removedAttributes()) {
82  l << '-' + attr;
83  }
84  command += ImapParser::join(l, " ");
85  }
86 
87  command += ")";
88 
89  d->writeData(command);
90 }
91 
92 void TagModifyJob::doHandleResponse(const QByteArray &tag, const QByteArray &data)
93 {
94  Q_D(TagModifyJob);
95  Q_UNUSED(tag);
96 
97  if (data.startsWith("OK")) { //krazy:exclude=strings
98  ChangeMediator::invalidateTag(d->mTag);
99  emitResult();
100  }
101 }
QByteArray
Akonadi::TagModifyJob::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: tagmodifyjob.cpp:92
Akonadi::Job::Unknown
Unknown error.
Definition: job.h:108
QByteArray::startsWith
bool startsWith(const QByteArray &ba) const
Akonadi::ProtocolHelper::attributesToByteArray
static QByteArray attributesToByteArray(const Entity &entity, bool ns=false)
Convert attributes to their protocol representation.
Definition: protocolhelper.cpp:232
Akonadi::TagModifyJob::TagModifyJob
TagModifyJob(const Tag &tag, QObject *parent=0)
Creates a new tag modify job.
Definition: tagmodifyjob.cpp:38
Akonadi::Job
Base class for all actions in the Akonadi storage.
Definition: job.h:86
QString::number
QString number(int n, int base)
QString::fromUtf8
QString fromUtf8(const char *str, int size)
QObject
QList< QByteArray >
Akonadi::TagModifyJob::doStart
virtual void doStart()
This method must be reimplemented in the concrete jobs.
Definition: tagmodifyjob.cpp:45
Akonadi::TagModifyJob
Job that modifies a tag in the Akonadi storage.
Definition: tagmodifyjob.h:34
Akonadi::JobPrivate
Definition: job_p.h:31
Akonadi::Tag
An Akonadi Tag.
Definition: tag.h:43
Akonadi::TagModifyJob::tag
Tag tag() const
Returns the modified tag.
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