• 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
subscriptionjob.cpp
1 /*
2  Copyright (c) 2007 Volker Krause <vkrause@kde.org>
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 "subscriptionjob_p.h"
21 
22 #include "job_p.h"
23 
24 using namespace Akonadi;
25 
26 class Akonadi::SubscriptionJobPrivate : public JobPrivate
27 {
28 public:
29  SubscriptionJobPrivate(SubscriptionJob *parent)
30  : JobPrivate(parent)
31  {
32  }
33 
34  void sendCommand(const QByteArray &cmd, const Collection::List &list)
35  {
36  mTag = newTag();
37  QByteArray line = mTag + ' ' + cmd;
38  foreach (const Collection &col, list) {
39  line += ' ' + QByteArray::number(col.id());
40  }
41  line += '\n';
42  writeData(line);
43  newTag(); // prevent automatic response handling
44  }
45 
46  void sendNextCommand()
47  {
48  Q_Q(SubscriptionJob);
49 
50  QByteArray cmd;
51  if (!mSub.isEmpty()) {
52  sendCommand("SUBSCRIBE", mSub);
53  mSub.clear();
54  } else if (!mUnsub.isEmpty()) {
55  sendCommand("UNSUBSCRIBE", mUnsub);
56  mUnsub.clear();
57  } else {
58  q->emitResult();
59  }
60  }
61 
62  Q_DECLARE_PUBLIC(SubscriptionJob)
63 
64  QByteArray mTag;
65  Collection::List mSub, mUnsub;
66 };
67 
68 SubscriptionJob::SubscriptionJob(QObject *parent)
69  : Job(new SubscriptionJobPrivate(this), parent)
70 {
71 }
72 
73 SubscriptionJob::~SubscriptionJob()
74 {
75 }
76 
77 void SubscriptionJob::subscribe(const Collection::List &list)
78 {
79  Q_D(SubscriptionJob);
80 
81  d->mSub = list;
82 }
83 
84 void SubscriptionJob::unsubscribe(const Collection::List &list)
85 {
86  Q_D(SubscriptionJob);
87 
88  d->mUnsub = list;
89 }
90 
91 void SubscriptionJob::doStart()
92 {
93  Q_D(SubscriptionJob);
94 
95  d->sendNextCommand();
96 }
97 
98 void SubscriptionJob::doHandleResponse(const QByteArray &_tag, const QByteArray &data)
99 {
100  Q_D(SubscriptionJob);
101 
102  if (_tag == d->mTag) {
103  if (data.startsWith("OK")) { //krazy:exclude=strings
104  d->sendNextCommand();
105  } else {
106  setError(Unknown);
107  setErrorText(QString::fromUtf8(data));
108  emitResult();
109  }
110  return;
111  }
112 }
113 
114 #include "moc_subscriptionjob_p.cpp"
Akonadi::SubscriptionJob::subscribe
void subscribe(const Collection::List &collections)
Subscribes to the given list of collections.
Definition: subscriptionjob.cpp:77
Akonadi::SubscriptionJob::doHandleResponse
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: subscriptionjob.cpp:98
QByteArray
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
QByteArray::startsWith
bool startsWith(const QByteArray &ba) const
Akonadi::Job
Base class for all actions in the Akonadi storage.
Definition: job.h:86
QString::fromUtf8
QString fromUtf8(const char *str, int size)
QObject
QByteArray::number
QByteArray number(int n, int base)
QList
Akonadi::Entity::id
Id id() const
Returns the unique identifier of the entity.
Definition: entity.cpp:72
Akonadi::JobPrivate::newTag
QByteArray newTag()
Returns a new unique command tag for communication with the backend.
Akonadi::SubscriptionJob
Job to manipulate the local subscription state of a set of collections.
Definition: subscriptionjob_p.h:35
Akonadi::JobPrivate::writeData
void writeData(const QByteArray &data)
Sends raw data to the backend.
Akonadi::JobPrivate
Definition: job_p.h:31
Akonadi::SubscriptionJob::unsubscribe
void unsubscribe(const Collection::List &collections)
Unsubscribes from the given list of collections.
Definition: subscriptionjob.cpp:84
Akonadi::SubscriptionJob::~SubscriptionJob
~SubscriptionJob()
Destroys the subscription job.
Definition: subscriptionjob.cpp:73
Akonadi::SubscriptionJob::doStart
void doStart()
This method must be reimplemented in the concrete jobs.
Definition: subscriptionjob.cpp:91
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