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

akonadi

item.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 "item.h"
00021 #include "item_p.h"
00022 #include "itemserializer_p.h"
00023 #include "protocol_p.h"
00024 
00025 #include <kurl.h>
00026 
00027 #include <QtCore/QStringList>
00028 
00029 using namespace Akonadi;
00030 
00031 // Change to something != RFC822 as soon as the server supports it
00032 const char* Item::FullPayload = "RFC822";
00033 
00034 Item::Item()
00035   : Entity( new ItemPrivate )
00036 {
00037 }
00038 
00039 Item::Item( Id id )
00040   : Entity( new ItemPrivate( id ) )
00041 {
00042 }
00043 
00044 Item::Item( const QString & mimeType )
00045   : Entity( new ItemPrivate )
00046 {
00047   d_func()->mMimeType = mimeType;
00048 }
00049 
00050 Item::Item( const Item &other )
00051   : Entity( other )
00052 {
00053 }
00054 
00055 Item::~Item()
00056 {
00057 }
00058 
00059 Item::Flags Item::flags() const
00060 {
00061   return d_func()->mFlags;
00062 }
00063 
00064 void Item::setFlag( const QByteArray & name )
00065 {
00066   Q_D( Item );
00067   d->mFlags.insert( name );
00068   if ( !d->mFlagsOverwritten ) {
00069     if ( d->mDeletedFlags.contains( name ) )
00070       d->mDeletedFlags.remove( name );
00071     else
00072       d->mAddedFlags.insert( name );
00073   }
00074 }
00075 
00076 void Item::clearFlag( const QByteArray & name )
00077 {
00078   Q_D( Item );
00079   d->mFlags.remove( name );
00080   if ( !d->mFlagsOverwritten ) {
00081     if ( d->mAddedFlags.contains( name ) )
00082       d->mAddedFlags.remove( name );
00083     else
00084       d->mDeletedFlags.insert( name );
00085   }
00086 }
00087 
00088 void Item::setFlags( const Flags &flags )
00089 {
00090   Q_D( Item );
00091   d->mFlags = flags;
00092   d->mFlagsOverwritten = true;
00093 }
00094 
00095 void Item::clearFlags()
00096 {
00097   Q_D( Item );
00098   d->mFlags.clear();
00099   d->mFlagsOverwritten = true;
00100 }
00101 
00102 QDateTime Item::modificationTime() const
00103 {
00104   return d_func()->mModificationTime;
00105 }
00106 
00107 void Item::setModificationTime( const QDateTime &datetime )
00108 {
00109   d_func()->mModificationTime = datetime;
00110 }
00111 
00112 bool Item::hasFlag( const QByteArray & name ) const
00113 {
00114   return d_func()->mFlags.contains( name );
00115 }
00116 
00117 QSet<QByteArray> Item::loadedPayloadParts() const
00118 {
00119   return ItemSerializer::parts( *this );
00120 }
00121 
00122 QByteArray Item::payloadData() const
00123 {
00124   int version = 0;
00125   QByteArray data;
00126   ItemSerializer::serialize( *this, FullPayload, data, version );
00127   return data;
00128 }
00129 
00130 void Item::setPayloadFromData( const QByteArray &data )
00131 {
00132   ItemSerializer::deserialize( *this, FullPayload, data, 0, false );
00133 }
00134 
00135 int Item::revision() const
00136 {
00137   return d_func()->mRevision;
00138 }
00139 
00140 void Item::setRevision( int rev )
00141 {
00142   d_func()->mRevision = rev;
00143 }
00144 
00145 Entity::Id Item::storageCollectionId() const
00146 {
00147   return d_func()->mCollectionId;
00148 }
00149 
00150 void Item::setStorageCollectionId( Entity::Id collectionId )
00151 {
00152   d_func()->mCollectionId = collectionId;
00153 }
00154 
00155 QString Item::mimeType() const
00156 {
00157   return d_func()->mMimeType;
00158 }
00159 
00160 void Item::setSize( qint64 size )
00161 {
00162   Q_D( Item );
00163   d->mSize = size;
00164   d->mSizeChanged = true;
00165 }
00166 
00167 qint64 Item::size() const
00168 {
00169   return d_func()->mSize;
00170 }
00171 
00172 void Item::setMimeType( const QString & mimeType )
00173 {
00174   d_func()->mMimeType = mimeType;
00175 }
00176 
00177 bool Item::hasPayload() const
00178 {
00179   return d_func()->mPayload != 0;
00180 }
00181 
00182 KUrl Item::url( UrlType type ) const
00183 {
00184   KUrl url;
00185   url.setProtocol( QString::fromLatin1("akonadi") );
00186   url.addQueryItem( QLatin1String( "item" ), QString::number( id() ) );
00187 
00188   if ( type == UrlWithMimeType )
00189     url.addQueryItem( QLatin1String( "type" ), mimeType() );
00190 
00191   return url;
00192 }
00193 
00194 Item Item::fromUrl( const KUrl &url )
00195 {
00196   if ( url.protocol() != QLatin1String( "akonadi" ) )
00197     return Item();
00198 
00199   const QString itemStr = url.queryItem( QLatin1String( "item" ) );
00200   bool ok = false;
00201   Item::Id itemId = itemStr.toLongLong( &ok );
00202   if ( !ok )
00203     return Item();
00204 
00205   return Item( itemId );
00206 }
00207 
00208 PayloadBase* Item::payloadBase() const
00209 {
00210   return d_func()->mPayload;
00211 }
00212 
00213 void Item::setPayloadBase( PayloadBase* p )
00214 {
00215   Q_D( Item );
00216   delete d->mPayload;
00217   d->mPayload = p;
00218 }
00219 
00220 QSet<QByteArray> Item::availablePayloadParts() const
00221 {
00222   return ItemSerializer::availableParts( *this );
00223 }
00224 
00225 void Item::apply( const Item &other )
00226 {
00227   Q_ASSERT( mimeType() == other.mimeType() && id() == other.id() );
00228   setRemoteId( other.remoteId() );
00229   setRevision( other.revision() );
00230   setFlags( other.flags() );
00231   setModificationTime( other.modificationTime() );
00232   setSize( other.size() );
00233   setParentCollection( other.parentCollection() );
00234   setStorageCollectionId( other.storageCollectionId() );
00235   setRemoteId( other.remoteId() );
00236 
00237   foreach( Attribute *attribute, other.attributes() )
00238     addAttribute( attribute->clone() );
00239 
00240   ItemSerializer::apply( *this, other );
00241 }
00242 
00243 AKONADI_DEFINE_PRIVATE( Item )

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