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

akonadi

  • sources
  • kde-4.12
  • 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  line += '\n';
41  writeData( line );
42  newTag(); // prevent automatic response handling
43  }
44 
45  void sendNextCommand()
46  {
47  Q_Q( SubscriptionJob );
48 
49  QByteArray cmd;
50  if ( !mSub.isEmpty() ) {
51  sendCommand( "SUBSCRIBE", mSub );
52  mSub.clear();
53  } else if ( !mUnsub.isEmpty() ) {
54  sendCommand( "UNSUBSCRIBE", mUnsub );
55  mUnsub.clear();
56  } else {
57  q->emitResult();
58  }
59  }
60 
61  Q_DECLARE_PUBLIC( SubscriptionJob )
62 
63  QByteArray mTag;
64  Collection::List mSub, mUnsub;
65 };
66 
67 SubscriptionJob::SubscriptionJob(QObject * parent)
68  : Job( new SubscriptionJobPrivate( this ), parent )
69 {
70 }
71 
72 SubscriptionJob::~SubscriptionJob()
73 {
74 }
75 
76 void SubscriptionJob::subscribe(const Collection::List & list)
77 {
78  Q_D( SubscriptionJob );
79 
80  d->mSub = list;
81 }
82 
83 void SubscriptionJob::unsubscribe(const Collection::List & list)
84 {
85  Q_D( SubscriptionJob );
86 
87  d->mUnsub = list;
88 }
89 
90 void SubscriptionJob::doStart()
91 {
92  Q_D( SubscriptionJob );
93 
94  d->sendNextCommand();
95 }
96 
97 void SubscriptionJob::doHandleResponse(const QByteArray &_tag, const QByteArray & data)
98 {
99  Q_D( SubscriptionJob );
100 
101  if ( _tag == d->mTag ) {
102  if ( data.startsWith( "OK" ) ) { //krazy:exclude=strings
103  d->sendNextCommand();
104  } else {
105  setError( Unknown );
106  setErrorText( QString::fromUtf8( data ) );
107  emitResult();
108  }
109  return;
110  }
111 }
112 
113 #include "moc_subscriptionjob_p.cpp"
Akonadi::SubscriptionJob::subscribe
void subscribe(const Collection::List &collections)
Subscribes to the given list of collections.
Definition: subscriptionjob.cpp:76
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:97
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::Job
Base class for all actions in the Akonadi storage.
Definition: job.h:86
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:83
Akonadi::Collection::List
QList< Collection > List
Describes a list of collections.
Definition: collection.h:81
Akonadi::SubscriptionJob::~SubscriptionJob
~SubscriptionJob()
Destroys the subscription job.
Definition: subscriptionjob.cpp:72
Akonadi::SubscriptionJob::doStart
void doStart()
This method must be reimplemented in the concrete jobs.
Definition: subscriptionjob.cpp:90
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:28 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
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

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