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

akonadi

  • 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.remoteId().isEmpty()) {
77  list << "RID";
78  list << ImapParser::quote(d->mTag.remoteId());
79  }
80  if (d->mTag.parent().isValid()) {
81  list << "PARENT";
82  list << QString::number(d->mTag.parent().id()).toLatin1();
83  }
84  command += ImapParser::join(list, " ");
85  command += " "; // list of parts
86  const QByteArray attrs = ProtocolHelper::attributesToByteArray(d->mTag, false);
87  if (!attrs.isEmpty()) {
88  command += attrs;
89  }
90  command += ")";
91 
92  d->writeData( command );
93 }
94 
95 void TagCreateJob::doHandleResponse(const QByteArray &tag, const QByteArray &data)
96 {
97  Q_D(TagCreateJob);
98 
99  if ( tag == "*" ) {
100  int begin = data.indexOf("TAGFETCH");
101  if ( begin >= 0 ) {
102  // split fetch response into key/value pairs
103  QList<QByteArray> fetchResponse;
104  ImapParser::parseParenthesizedList(data, fetchResponse, begin + 8);
105  if (!d->mMerge) {
106  //If merge is enabled there is the possibility that existing attributes etc are not valid anymore
107  d->mResultTag = d->mTag;
108  }
109  ProtocolHelper::parseTagFetchResult(fetchResponse, d->mResultTag);
110  }
111  }
112 }
113 
114 Tag TagCreateJob::tag() const
115 {
116  Q_D(const TagCreateJob);
117  return d->mResultTag;
118 }
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:114
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:95
Akonadi::Job::Unknown
Unknown error.
Definition: job.h:109
Akonadi::ProtocolHelper::attributesToByteArray
static QByteArray attributesToByteArray(const Entity &entity, bool ns=false)
Convert attributes to their protocol representation.
Definition: protocolhelper.cpp:206
Akonadi::Job
Base class for all actions in the Akonadi storage.
Definition: job.h:86
Akonadi::TagCreateJob::doStart
virtual void doStart()
This method must be reimplemented in the concrete jobs.
Definition: tagcreatejob.cpp:54
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:44
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Mon Jul 21 2014 08:03:56 by doxygen 1.8.6 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-4.13.3 API Reference

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