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

akonadi

  • akonadi
collectioncreatejob.cpp
1 /*
2  Copyright (c) 2006 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 "collectioncreatejob.h"
21 #include "imapparser_p.h"
22 #include "protocolhelper_p.h"
23 
24 #include "job_p.h"
25 
26 #include <kdebug.h>
27 #include <KLocale>
28 using namespace Akonadi;
29 
30 class Akonadi::CollectionCreateJobPrivate : public JobPrivate
31 {
32  public:
33  CollectionCreateJobPrivate( CollectionCreateJob *parent )
34  : JobPrivate( parent )
35  {
36  }
37 
38  Collection mCollection;
39 };
40 
41 CollectionCreateJob::CollectionCreateJob( const Collection &collection, QObject * parent )
42  : Job( new CollectionCreateJobPrivate( this ), parent )
43 {
44  Q_D( CollectionCreateJob );
45 
46  d->mCollection = collection;
47 }
48 
49 CollectionCreateJob::~CollectionCreateJob( )
50 {
51 }
52 
53 void CollectionCreateJob::doStart( )
54 {
55  Q_D( CollectionCreateJob );
56  if ( d->mCollection.parentCollection().id() < 0 && d->mCollection.parentCollection().remoteId().isEmpty() ) {
57  setError( Unknown );
58  setErrorText( i18n( "Invalid parent" ) );
59  emitResult();
60  return;
61  }
62 
63  QByteArray command = d->newTag();
64  if ( d->mCollection.parentCollection().id() < 0 )
65  command += " RID";
66  command += " CREATE " + ImapParser::quote( d->mCollection.name().toUtf8() ) + ' ';
67  if ( d->mCollection.parentCollection().id() >= 0 )
68  command += QByteArray::number( d->mCollection.parentCollection().id() );
69  else
70  command += ImapParser::quote( d->mCollection.parentCollection().remoteId().toUtf8() );
71  command += " (";
72  if ( !d->mCollection.contentMimeTypes().isEmpty() )
73  {
74  QList<QByteArray> cList;
75  foreach ( const QString &s, d->mCollection.contentMimeTypes() ) cList << s.toLatin1();
76  command += "MIMETYPE (" + ImapParser::join( cList, QByteArray(" ") ) + ')';
77  }
78  command += " REMOTEID " + ImapParser::quote( d->mCollection.remoteId().toUtf8() );
79  command += " REMOTEREVISION " + ImapParser::quote( d->mCollection.remoteRevision().toUtf8() );
80  foreach ( Attribute* attr, d->mCollection.attributes() )
81  command += ' ' + attr->type() + ' ' + ImapParser::quote( attr->serialized() );
82  command += ' ' + ProtocolHelper::cachePolicyToByteArray( d->mCollection.cachePolicy() );
83  command += ")\n";
84  d->writeData( command );
85  emitWriteFinished();
86 }
87 
88 Collection CollectionCreateJob::collection() const
89 {
90  Q_D( const CollectionCreateJob );
91 
92  return d->mCollection;
93 }
94 
95 void CollectionCreateJob::doHandleResponse(const QByteArray & tag, const QByteArray & data)
96 {
97  Q_D( CollectionCreateJob );
98 
99  if ( tag == "*" ) {
100  Collection col;
101  ProtocolHelper::parseCollection( data, col );
102  if ( !col.isValid() )
103  return;
104 
105  col.setParentCollection( d->mCollection.parentCollection() );
106  col.setName( d->mCollection.name() );
107  col.setRemoteId( d->mCollection.remoteId() );
108  col.setRemoteRevision( d->mCollection.remoteRevision() );
109  d->mCollection = col;
110  } else {
111  Job::doHandleResponse( tag, data );
112  }
113 }
114 
115 #include "collectioncreatejob.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Tue Dec 11 2012 12:14:30 by doxygen 1.8.1.2 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-4.9.4 API Reference

Skip menu "kdepimlibs-4.9.4 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
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