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"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:49:16 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Apr 30 2012 21:49:16 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.