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

akonadi

  • akonadi
tagfetchjob.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 "tagfetchjob.h"
21#include "job_p.h"
22#include "tag.h"
23#include "protocolhelper_p.h"
24#include "tagfetchscope.h"
25#include <QTimer>
26#include <QFile>
27#include <akonadi/attributefactory.h>
28
29using namespace Akonadi;
30
31class Akonadi::TagFetchJobPrivate : public JobPrivate
32{
33public:
34 TagFetchJobPrivate(TagFetchJob *parent)
35 : JobPrivate(parent)
36 , mEmitTimer(0)
37 {
38 }
39
40 void init()
41 {
42 Q_Q(TagFetchJob);
43 mEmitTimer = new QTimer(q);
44 mEmitTimer->setSingleShot(true);
45 mEmitTimer->setInterval(100);
46 q->connect(mEmitTimer, SIGNAL(timeout()), q, SLOT(timeout()));
47 }
48
49 void aboutToFinish()
50 {
51 timeout();
52 }
53
54 void timeout()
55 {
56 Q_Q(TagFetchJob);
57 mEmitTimer->stop(); // in case we are called by result()
58 if (!mPendingTags.isEmpty()) {
59 if (!q->error()) {
60 emit q->tagsReceived(mPendingTags);
61 }
62 mPendingTags.clear();
63 }
64 }
65
66 Q_DECLARE_PUBLIC(TagFetchJob)
67
68 Tag::List mRequestedTags;
69 Tag::List mResultTags;
70 Tag::List mPendingTags; // items pending for emitting itemsReceived()
71 QTimer *mEmitTimer;
72 TagFetchScope mFetchScope;
73};
74
75TagFetchJob::TagFetchJob(QObject *parent)
76 : Job(new TagFetchJobPrivate(this), parent)
77{
78 Q_D(TagFetchJob);
79 d->init();
80}
81
82TagFetchJob::TagFetchJob(const Tag &tag, QObject *parent)
83 : Job(new TagFetchJobPrivate(this), parent)
84{
85 Q_D(TagFetchJob);
86 d->init();
87 d->mRequestedTags << tag;
88}
89
90TagFetchJob::TagFetchJob(const Tag::List &tags, QObject *parent)
91 : Job(new TagFetchJobPrivate(this), parent)
92{
93 Q_D(TagFetchJob);
94 d->init();
95 d->mRequestedTags = tags;
96}
97
98TagFetchJob::TagFetchJob(const QList<Tag::Id> &ids, QObject *parent)
99 : Job(new TagFetchJobPrivate(this), parent)
100{
101 Q_D(TagFetchJob);
102 d->init();
103 Q_FOREACH (Tag::Id id, ids) {
104 d->mRequestedTags << Tag(id);
105 }
106}
107
108void TagFetchJob::setFetchScope(const TagFetchScope &fetchScope)
109{
110 Q_D(TagFetchJob);
111 d->mFetchScope = fetchScope;
112}
113
114TagFetchScope &TagFetchJob::fetchScope()
115{
116 Q_D(TagFetchJob);
117 return d->mFetchScope;
118}
119
120void TagFetchJob::doStart()
121{
122 Q_D(TagFetchJob);
123
124 QByteArray command = d->newTag();
125 if (d->mRequestedTags.isEmpty()) {
126 command += " UID TAGFETCH 1:*";
127 } else {
128 try {
129 command += ProtocolHelper::tagSetToByteArray(d->mRequestedTags, "TAGFETCH");
130 } catch (const Exception &e) {
131 setError(Job::Unknown);
132 setErrorText(QString::fromUtf8(e.what()));
133 emitResult();
134 return;
135 }
136 }
137 command += " " + ProtocolHelper::tagFetchScopeToByteArray(d->mFetchScope) + "\n";
138
139 d->writeData(command);
140}
141
142void TagFetchJob::doHandleResponse(const QByteArray &tag, const QByteArray &data)
143{
144 Q_D(TagFetchJob);
145
146 if (tag == "*") {
147 int begin = data.indexOf("TAGFETCH");
148 if (begin >= 0) {
149 // split fetch response into key/value pairs
150 QList<QByteArray> fetchResponse;
151 ImapParser::parseParenthesizedList(data, fetchResponse, begin + 8);
152
153 Tag tag;
154 ProtocolHelper::parseTagFetchResult(fetchResponse, tag);
155
156 if (tag.isValid()) {
157 d->mResultTags.append(tag);
158 d->mPendingTags.append(tag);
159 if (!d->mEmitTimer->isActive()) {
160 d->mEmitTimer->start();
161 }
162 }
163 return;
164 }
165 }
166 kDebug() << "Unhandled response: " << tag << data;
167}
168
169Tag::List TagFetchJob::tags() const
170{
171 Q_D(const TagFetchJob);
172 return d->mResultTags;
173}
174
175#include "moc_tagfetchjob.cpp"
Akonadi::Exception
Base class for exceptions used by the Akonadi library.
Definition exception.h:36
Akonadi::Exception::what
const char * what() const
Returns the error message associated with this exception.
Definition exception.cpp:94
Akonadi::JobPrivate
Definition job_p.h:32
Akonadi::Job
Base class for all actions in the Akonadi storage.
Definition job.h:87
Akonadi::Job::Unknown
@ Unknown
Unknown error.
Definition job.h:108
Akonadi::ProtocolHelper::tagFetchScopeToByteArray
static QByteArray tagFetchScopeToByteArray(const TagFetchScope &fetchScope)
Converts a given TagFetchScope object into a protocol representation.
Definition protocolhelper.cpp:468
Akonadi::TagFetchJob
Job that fetches tags from the Akonadi storage.
Definition tagfetchjob.h:42
Akonadi::TagFetchJob::tags
Tag::List tags() const
Returns the fetched tags after the job has been completed.
Definition tagfetchjob.cpp:169
Akonadi::TagFetchJob::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 tagfetchjob.cpp:142
Akonadi::TagFetchJob::fetchScope
TagFetchScope & fetchScope()
Returns the tag fetch scope.
Definition tagfetchjob.cpp:114
Akonadi::TagFetchJob::setFetchScope
void setFetchScope(const TagFetchScope &fetchScope)
Sets the tag fetch scope.
Definition tagfetchjob.cpp:108
Akonadi::TagFetchJob::TagFetchJob
TagFetchJob(QObject *parent=0)
Constructs a new tag fetch job that retrieves all tags stored in Akonadi.
Definition tagfetchjob.cpp:75
Akonadi::TagFetchJob::doStart
virtual void doStart()
This method must be reimplemented in the concrete jobs.
Definition tagfetchjob.cpp:120
Akonadi::TagFetchScope
Specifies which parts of a tag should be fetched from the Akonadi storage.
Definition tagfetchscope.h:34
Akonadi::Tag
An Akonadi Tag.
Definition tag.h:44
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