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

akonadi

collectioncreatejob.cpp

00001 /*
00002     Copyright (c) 2006 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 "collectioncreatejob.h"
00021 #include "imapparser_p.h"
00022 #include "protocolhelper_p.h"
00023 
00024 #include "job_p.h"
00025 
00026 #include <kdebug.h>
00027 #include <KLocale>
00028 using namespace Akonadi;
00029 
00030 class Akonadi::CollectionCreateJobPrivate : public JobPrivate
00031 {
00032   public:
00033     CollectionCreateJobPrivate( CollectionCreateJob *parent )
00034       : JobPrivate( parent )
00035     {
00036     }
00037 
00038     Collection mCollection;
00039 };
00040 
00041 CollectionCreateJob::CollectionCreateJob( const Collection &collection, QObject * parent )
00042   : Job( new CollectionCreateJobPrivate( this ), parent )
00043 {
00044   Q_D( CollectionCreateJob );
00045 
00046   d->mCollection = collection;
00047 }
00048 
00049 CollectionCreateJob::~CollectionCreateJob( )
00050 {
00051 }
00052 
00053 void CollectionCreateJob::doStart( )
00054 {
00055   Q_D( CollectionCreateJob );
00056   if ( d->mCollection.parentCollection().id() < 0 && d->mCollection.parentCollection().remoteId().isEmpty() ) {
00057     setError( Unknown );
00058     setErrorText( i18n("Invalid parent") );
00059     emitResult();
00060     return;
00061   }
00062 
00063   QByteArray command = d->newTag();
00064   if ( d->mCollection.parentCollection().id() < 0 )
00065     command += " RID";
00066   command += " CREATE \"" + d->mCollection.name().toUtf8() + "\" ";
00067   if ( d->mCollection.parentCollection().id() >= 0 )
00068     command += QByteArray::number( d->mCollection.parentCollection().id() );
00069   else
00070     command += ImapParser::quote( d->mCollection.parentCollection().remoteId().toUtf8() );
00071   command += " (";
00072   if ( !d->mCollection.contentMimeTypes().isEmpty() )
00073   {
00074     QList<QByteArray> cList;
00075     foreach( const QString &s, d->mCollection.contentMimeTypes() ) cList << s.toLatin1();
00076     command += "MIMETYPE (" + ImapParser::join( cList, QByteArray(" ") ) + ')';
00077   }
00078   command += " REMOTEID \"" + d->mCollection.remoteId().toUtf8() + '"';
00079   foreach ( Attribute* attr, d->mCollection.attributes() )
00080     command += ' ' + attr->type() + ' ' + ImapParser::quote( attr->serialized() );
00081   command += ' ' + ProtocolHelper::cachePolicyToByteArray( d->mCollection.cachePolicy() );
00082   command += ")\n";
00083   d->writeData( command );
00084   emitWriteFinished();
00085 }
00086 
00087 Collection CollectionCreateJob::collection() const
00088 {
00089   Q_D( const CollectionCreateJob );
00090 
00091   return d->mCollection;
00092 }
00093 
00094 void CollectionCreateJob::doHandleResponse(const QByteArray & tag, const QByteArray & data)
00095 {
00096   Q_D( CollectionCreateJob );
00097 
00098   if ( tag == "*" ) {
00099     Collection col;
00100     ProtocolHelper::parseCollection( data, col );
00101     if ( !col.isValid() )
00102       return;
00103 
00104     col.setParentCollection( d->mCollection.parentCollection() );
00105     col.setName( d->mCollection.name() );
00106     col.setRemoteId( d->mCollection.remoteId() );
00107     d->mCollection = col;
00108   } else {
00109     Job::doHandleResponse( tag, data );
00110   }
00111 }
00112 
00113 #include "collectioncreatejob.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.1
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