• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

akonadi

subscriptionjob.cpp

00001 /*
00002     Copyright (c) 2007 Volker Krause <vkrause@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 #include "subscriptionjob_p.h"
00021 
00022 #include "job_p.h"
00023 
00024 using namespace Akonadi;
00025 
00026 class Akonadi::SubscriptionJobPrivate : public JobPrivate
00027 {
00028   public:
00029     SubscriptionJobPrivate( SubscriptionJob *parent )
00030       : JobPrivate( parent )
00031     {
00032     }
00033 
00034     void sendCommand( const QByteArray &cmd, const Collection::List &list )
00035     {
00036       mTag = newTag();
00037       QByteArray line = mTag + ' ' + cmd;
00038       foreach ( const Collection &col, list )
00039         line += ' ' + QByteArray::number( col.id() );
00040       line += '\n';
00041       writeData( line );
00042       newTag(); // prevent automatic response handling
00043     }
00044 
00045     void sendNextCommand()
00046     {
00047       Q_Q( SubscriptionJob );
00048 
00049       QByteArray cmd;
00050       if ( !mSub.isEmpty() ) {
00051         sendCommand( "SUBSCRIBE", mSub );
00052         mSub.clear();
00053       } else if ( !mUnsub.isEmpty() ) {
00054         sendCommand( "UNSUBSCRIBE", mUnsub );
00055         mUnsub.clear();
00056       } else {
00057         q->emitResult();
00058       }
00059     }
00060 
00061     Q_DECLARE_PUBLIC( SubscriptionJob )
00062 
00063     QByteArray mTag;
00064     Collection::List mSub, mUnsub;
00065 };
00066 
00067 SubscriptionJob::SubscriptionJob(QObject * parent)
00068   : Job( new SubscriptionJobPrivate( this ), parent )
00069 {
00070 }
00071 
00072 SubscriptionJob::~SubscriptionJob()
00073 {
00074 }
00075 
00076 void SubscriptionJob::subscribe(const Collection::List & list)
00077 {
00078   Q_D( SubscriptionJob );
00079 
00080   d->mSub = list;
00081 }
00082 
00083 void SubscriptionJob::unsubscribe(const Collection::List & list)
00084 {
00085   Q_D( SubscriptionJob );
00086 
00087   d->mUnsub = list;
00088 }
00089 
00090 void SubscriptionJob::doStart()
00091 {
00092   Q_D( SubscriptionJob );
00093 
00094   d->sendNextCommand();
00095 }
00096 
00097 void SubscriptionJob::doHandleResponse(const QByteArray &_tag, const QByteArray & data)
00098 {
00099   Q_D( SubscriptionJob );
00100 
00101   if ( _tag == d->mTag ) {
00102     if ( data.startsWith( "OK" ) ) { //krazy:exclude=strings
00103       d->sendNextCommand();
00104     } else {
00105       setError( Unknown );
00106       setErrorText( QString::fromUtf8( data ) );
00107       emitResult();
00108     }
00109     return;
00110   }
00111 }
00112 
00113 #include "subscriptionjob_p.moc"

akonadi

Skip menu "akonadi"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.6.2-20100208
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal