diff --git a/akonadi/cachepolicy.cpp b/akonadi/cachepolicy.cpp index c96657cbf..e4995d0d8 100644 --- a/akonadi/cachepolicy.cpp +++ b/akonadi/cachepolicy.cpp @@ -1,136 +1,146 @@ /* Copyright (c) 2008 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "cachepolicy.h" #include "collection.h" using namespace Akonadi; /** * @internal */ class CachePolicy::Private : public QSharedData { public: Private() : QSharedData(), inherit( true ), timeout( -1 ), interval( -1 ), syncOnDemand( false ) {} Private( const Private &other ) : QSharedData( other ) { inherit = other.inherit; localParts = other.localParts; timeout = other.timeout; interval = other.interval; syncOnDemand = other.syncOnDemand; } bool inherit; QStringList localParts; int timeout; int interval; bool syncOnDemand; }; CachePolicy::CachePolicy() : d( new Private ) { } CachePolicy::CachePolicy(const CachePolicy & other) : d( other.d ) { } CachePolicy::~ CachePolicy() { } CachePolicy & CachePolicy::operator =(const CachePolicy & other) { d = other.d; return *this; } bool Akonadi::CachePolicy::operator ==(const CachePolicy & other) const { if ( !d->inherit && !other.d->inherit ) { return d->localParts == other.d->localParts && d->timeout == other.d->timeout && d->interval == other.d->interval && d->syncOnDemand == other.d->syncOnDemand; } return d->inherit == other.d->inherit; } bool CachePolicy::inheritFromParent() const { return d->inherit; } void CachePolicy::setInheritFromParent(bool inherit) { d->inherit = inherit; } QStringList CachePolicy::localParts() const { return d->localParts; } void CachePolicy::setLocalParts(const QStringList & parts) { d->localParts = parts; } int CachePolicy::cacheTimeout() const { return d->timeout; } void CachePolicy::setCacheTimeout(int timeout) { d->timeout = timeout; } int CachePolicy::intervalCheckTime() const { return d->interval; } void CachePolicy::setIntervalCheckTime(int time) { d->interval = time; } bool CachePolicy::syncOnDemand() const { return d->syncOnDemand; } void CachePolicy::setSyncOnDemand(bool enable) { d->syncOnDemand = enable; } + +QDebug operator<<( QDebug d, const CachePolicy& c ) +{ + return d << "CachePolicy: " << endl + << " inherit:" << c.inheritFromParent() << endl + << " interval:" << c.intervalCheckTime() << endl + << " timeout:" << c.cacheTimeout() << endl + << " sync on demand:" << c.syncOnDemand() << endl + << " local parts:" << c.localParts(); +} diff --git a/akonadi/cachepolicy.h b/akonadi/cachepolicy.h index 3ed3e7ab9..f93480e0d 100644 --- a/akonadi/cachepolicy.h +++ b/akonadi/cachepolicy.h @@ -1,153 +1,158 @@ /* Copyright (c) 2008 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef AKONADI_CACHEPOLICY_H #define AKONADI_CACHEPOLICY_H #include "akonadi_export.h" #include #include namespace Akonadi { /** * @short Represents the caching policy for a collection. * * There is one cache policy per collection, it can either define to * inherit all properties of the policy of the parent collection (the default) * or specify the following values: * * - The item parts that should be permanently kept locally and are downloaded * during a collection sync (eg. full mail vs. just the headers). * - A time up to which non-permantly cached item parts have to be kept at * least (0 - infinity). * - Whether or not a collection sync is triggered on demand, ie. as soon * as it is accessed by a client. * - An optional time interval for regular collection sync (aka interval * mail check). * * @code * * Akonadi::CachePolicy policy; * policy.setCacheTimeout( 30 ); * policy.setIntervalCheckTime( 20 ); * * Akonadi::Collection collection = ... * collection.setCachePolicy( policy ); * * @endcode * * @todo Do we also need a size limit for the cache as well? * @todo on a POP3 account, is should not be possible to change locally cached parts, find a solution for that * * @author Volker Krause */ class AKONADI_EXPORT CachePolicy { public: /** * Creates an empty cache policy. */ CachePolicy(); /** * Creates a cache policy from an @p other cache policy. */ CachePolicy( const CachePolicy &other ); /** * Destroys the cache policy. */ ~CachePolicy(); /** * Returns whether it inherits cache policy from parent collection. */ bool inheritFromParent() const; /** * Sets whether the cache policy should be inherited from the parent collection. */ void setInheritFromParent( bool inherit ); /** * Returns the parts to permanently cache locally. */ QStringList localParts() const; /** * Specifies the parts to permanently cache locally. */ void setLocalParts( const QStringList &parts ); /** * Returns the cache timeout for non-permanently cached parts in minutes, * -1 means indefinitely. */ int cacheTimeout() const; /** * Sets cache timeout for non-permanently cached parts. * @param timeout Timeout in minutes, -1 for indefinitely. */ void setCacheTimeout( int timeout ); /** * Returns the interval check time in minutes, -1 for never. */ int intervalCheckTime() const; /** * Sets interval check time. * @param time Check time interval in minutes, -1 for never. */ void setIntervalCheckTime( int time ); /** * Returns whether the collection shall be synced automatically when necessary. */ bool syncOnDemand() const; /** * Sets whether the collection shall be synced automatically when necessary. * @param enable If @c true the collection is synced. */ void setSyncOnDemand( bool enable ); /** * @internal. */ CachePolicy& operator=( const CachePolicy &other ); /** * @internal */ bool operator==( const CachePolicy &other ) const; private: //@cond PRIVATE class Private; QSharedDataPointer d; //@endcond }; } +/** + * Allows to output a cache policy for debugging purposes. + */ +AKONADI_EXPORT QDebug operator<<( QDebug, const Akonadi::CachePolicy& ); + #endif diff --git a/akonadi/collection.cpp b/akonadi/collection.cpp index 9ffef9665..b907e3e39 100644 --- a/akonadi/collection.cpp +++ b/akonadi/collection.cpp @@ -1,221 +1,237 @@ /* Copyright (c) 2006 - 2007 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "collection.h" #include "collection_p.h" #include "attributefactory.h" #include "cachepolicy.h" #include "collectionrightsattribute_p.h" #include "collectionstatistics.h" #include "entity_p.h" #include #include #include #include #include #include using namespace Akonadi; class CollectionRoot : public Collection { public: CollectionRoot() : Collection( 0 ) { QStringList types; types << Collection::mimeType(); setContentMimeTypes( types ); // The root collection is read-only for the users Collection::Rights rights; rights |= Collection::ReadOnly; setRights( rights ); } }; K_GLOBAL_STATIC( CollectionRoot, s_root ) Collection::Collection() : Entity( new CollectionPrivate ) { Q_D( Collection ); static int lastId = -1; d->mId = lastId--; } Collection::Collection( Id id ) : Entity( new CollectionPrivate( id ) ) { } Collection::Collection(const Collection & other) : Entity( other ) { } Collection::~Collection() { } QString Collection::name( ) const { return d_func()->name; } void Collection::setName( const QString & name ) { Q_D( Collection ); d->name = name; } Collection::Rights Collection::rights() const { CollectionRightsAttribute *attr = attribute(); if ( attr ) return attr->rights(); else return AllRights; } void Collection::setRights( Rights rights ) { CollectionRightsAttribute *attr = attribute( AddIfMissing ); attr->setRights( rights ); } QStringList Collection::contentMimeTypes() const { return d_func()->contentTypes; } void Collection::setContentMimeTypes( const QStringList & types ) { Q_D( Collection ); d->contentTypes = types; d->contentTypesChanged = true; } Collection::Id Collection::parent() const { return d_func()->parentId; } void Collection::setParent( Id parent ) { Q_D( Collection ); d->parentId = parent; } void Collection::setParent(const Collection & collection) { Q_D( Collection ); d->parentId = collection.id(); d->parentRemoteId = collection.remoteId(); } QString Collection::parentRemoteId() const { return d_func()->parentRemoteId; } void Collection::setParentRemoteId(const QString & remoteParent) { Q_D( Collection ); d->parentRemoteId = remoteParent; } KUrl Collection::url() const { KUrl url; url.setProtocol( QString::fromLatin1("akonadi") ); url.addQueryItem( QLatin1String("collection"), QString::number( id() ) ); return url; } Collection Collection::fromUrl( const KUrl &url ) { if ( url.protocol() != QLatin1String( "akonadi" ) ) return Collection(); const QString colStr = url.queryItem( QLatin1String( "collection" ) ); bool ok = false; Collection::Id colId = colStr.toLongLong( &ok ); if ( !ok ) return Collection(); if ( colId == 0 ) return Collection::root(); return Collection( colId ); } Collection Collection::root() { return *s_root; } QString Collection::mimeType( ) { return QString::fromLatin1("inode/directory"); } QString Collection::resource() const { return d_func()->resource; } void Collection::setResource(const QString & resource) { Q_D( Collection ); d->resource = resource; } uint qHash( const Akonadi::Collection &collection ) { return qHash( collection.id() ); } +QDebug operator <<( QDebug d, const Akonadi::Collection &collection ) +{ + return d << "Collection ID:" << collection.id() + << " remote ID:" << collection.remoteId() << endl + << " name:" << collection.name() << endl + << " url:" << collection.url() << endl + << " parent ID:" << collection.parent() + << " parent remote ID: " << collection.parentRemoteId() << endl + << " resource:" << collection.resource() << endl + << " mime type:" << collection.mimeType() << endl + << " rights:" << collection.rights() << endl + << " contents mime type:" << collection.contentMimeTypes() << endl + << " " << collection.cachePolicy() << endl + << " " << collection.statistics(); +} + CollectionStatistics Collection::statistics() const { return d_func()->statistics; } void Collection::setStatistics(const CollectionStatistics & statistics) { Q_D( Collection ); d->statistics = statistics; } CachePolicy Collection::cachePolicy() const { return d_func()->cachePolicy; } void Collection::setCachePolicy(const CachePolicy & cachePolicy) { Q_D( Collection ); d->cachePolicy = cachePolicy; d->cachePolicyChanged = true; } AKONADI_DEFINE_PRIVATE( Akonadi::Collection ) diff --git a/akonadi/collection.h b/akonadi/collection.h index 211dccbce..7d5bb71fa 100644 --- a/akonadi/collection.h +++ b/akonadi/collection.h @@ -1,234 +1,238 @@ /* Copyright (c) 2006 - 2007 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef AKONADI_COLLECTION_H #define AKONADI_COLLECTION_H #include "akonadi_export.h" #include #include #include class KUrl; namespace Akonadi { class CachePolicy; class CollectionPrivate; class CollectionStatistics; /** * @short Represents a collection of PIM items. * * This class represents a collection of PIM items, such as a folder on a mail- or * groupware-server. * * Collections are hierarchical, i.e., they may have a parent collection. * * @code * * using namespace Akonadi; * * // fetching all collections recursive, starting at the root collection * CollectionFetchJob *job = new CollectionFetchJob( Collection::root(), CollectionFetchJob::Recursive ); * if ( job->exec() ) { * Collection::List collections = job->collections(); * foreach( const Collection &collection, collections ) { * qDebug() << "Name:" << collection.name(); * } * } * * @endcode * * @author Volker Krause * * @see \ref akonadi_concepts_collections "Akonadi Collection Concept" */ class AKONADI_EXPORT Collection : public Entity { public: /** * Describes a list of collections. */ typedef QList List; /** * Describes rights of a collection. */ enum Right { ReadOnly = 0x0, ///< Can only read items or subcollection of this collection CanChangeItem = 0x1, ///< Can change items in this collection CanCreateItem = 0x2, ///< Can create new items in this collection CanDeleteItem = 0x4, ///< Can delete items in this collection CanChangeCollection = 0x8, ///< Can change subcollections in this collection CanCreateCollection = 0x10, ///< Can create new subcollections in this collection CanDeleteCollection = 0x20, ///< Can delete subcollections in this collection AllRights = (CanChangeItem | CanCreateItem | CanDeleteItem | CanChangeCollection | CanCreateCollection | CanDeleteCollection) ///< Has all rights on this collection }; Q_DECLARE_FLAGS(Rights, Right) /** * Creates an invalid collection. */ Collection(); /** * Create a new collection. * * @param id The unique identifier of the collection. */ explicit Collection( Id id ); /** * Destroys the collection. */ ~Collection(); /** * Creates a collection from an @p other collection. */ Collection( const Collection &other ); /** * Creates a collection from the given @p url. */ static Collection fromUrl( const KUrl &url ); /** * Returns the i18n'ed name of the collection. */ QString name() const; /** * Sets the i18n'ed name of the collection. * * @param name The new collection name. */ void setName( const QString &name ); /** * Returns the rights the user has on the collection. */ Rights rights() const; /** * Sets the @p rights the user has on the collection. */ void setRights( Rights rights ); /** * Returns a list of possible content mimetypes, * e.g. message/rfc822, x-akonadi/collection for a mail folder that * supports sub-folders. */ QStringList contentMimeTypes() const; /** * Sets the list of possible content mime @p types. */ void setContentMimeTypes( const QStringList &types ); /** * Returns the identifier of the parent collection. */ Id parent() const; /** * Sets the identifier of the @p parent collection. */ void setParent( Id parent ); /** * Sets the parent @p collection. */ void setParent( const Collection &collection ); /** * Returns the parent remote identifier. * @note This usually returns nothing for collections retrieved from the backend. */ QString parentRemoteId() const; /** * Sets the parent's remote @p identifier. */ void setParentRemoteId( const QString &identifier ); /** * Returns the root collection. */ static Collection root(); /** * Returns the mimetype used for collections. */ static QString mimeType(); /** * Returns the identifier of the resource owning the collection. */ QString resource() const; /** * Sets the @p identifier of the resource owning the collection. */ void setResource( const QString &identifier ); /** * Returns the cache policy of the collection. */ CachePolicy cachePolicy() const; /** * Sets the cache @p policy of the collection. */ void setCachePolicy( const CachePolicy &policy ); /** * Returns the collection statistics of the collection. */ CollectionStatistics statistics() const; /** * Sets the collection @p statistics for the collection. */ void setStatistics( const CollectionStatistics &statistics ); /** * Returns the collection url */ KUrl url() const; private: AKONADI_DECLARE_PRIVATE( Collection ) friend class CollectionFetchJob; friend class CollectionModifyJob; }; } AKONADI_EXPORT uint qHash( const Akonadi::Collection &collection ); +/** + * Allows to output a collection for debugging purposes. + */ +AKONADI_EXPORT QDebug operator<<( QDebug d, const Akonadi::Collection &collection ); Q_DECLARE_METATYPE(Akonadi::Collection) Q_DECLARE_METATYPE(Akonadi::Collection::List) #endif diff --git a/akonadi/collectionstatistics.cpp b/akonadi/collectionstatistics.cpp index d394482f6..f36e45170 100644 --- a/akonadi/collectionstatistics.cpp +++ b/akonadi/collectionstatistics.cpp @@ -1,101 +1,110 @@ /* Copyright (c) 2006 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "collectionstatistics.h" #include +#include using namespace Akonadi; /** * @internal */ class CollectionStatistics::Private : public QSharedData { public: Private() : QSharedData(), count( -1 ), unreadCount( -1 ), size( -1 ) {} Private( const Private &other ) : QSharedData( other ) { count = other.count; unreadCount = other.count; size = other.size; } qint64 count; qint64 unreadCount; qint64 size; }; CollectionStatistics::CollectionStatistics() : d( new Private ) { } CollectionStatistics::CollectionStatistics(const CollectionStatistics &other) : d( other.d ) { } CollectionStatistics::~CollectionStatistics() { } qint64 CollectionStatistics::count( ) const { return d->count; } void CollectionStatistics::setCount( qint64 count ) { d->count = count; } qint64 CollectionStatistics::unreadCount( ) const { return d->unreadCount; } void CollectionStatistics::setUnreadCount( qint64 count ) { d->unreadCount = count; } qint64 CollectionStatistics::size( ) const { return d->size; } void CollectionStatistics::setSize( qint64 size ) { d->size = size; } CollectionStatistics& CollectionStatistics::operator =(const CollectionStatistics & other) { d = other.d; return *this; } + +QDebug operator<<( QDebug d, const CollectionStatistics& s ) +{ + return d << "CollectionStatistics:" << endl + << " count:" << s.count() << endl + << " unread count:" << s.unreadCount() << endl + << " size:" << s.size(); +} diff --git a/akonadi/collectionstatistics.h b/akonadi/collectionstatistics.h index a57742556..5d23d9071 100644 --- a/akonadi/collectionstatistics.h +++ b/akonadi/collectionstatistics.h @@ -1,143 +1,148 @@ /* Copyright (c) 2006 Volker Krause This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef AKONADI_COLLECTIONSTATISTICS_H #define AKONADI_COLLECTIONSTATISTICS_H #include "akonadi_export.h" #include #include namespace Akonadi { /** * @short Provides statistics information of a Collection. * * This class contains information such as total number of items, * number of new and unread items, etc. * * These information might be expensive to obtain and are thus * not included when fetching collection with a CollectionFetchJob. * They can be retrieved spearately using CollectionStatisticsJob. * * Example: * * @code * * Akonadi::Collection collection = ... * * Akonadi::CollectionStatisticsJob *job = new Akonadi::CollectionStatisticsJob( collection ); * if ( job->exec() ) { * Akonadi::CollectionStatistics statistics = job->statistics(); * qDebug() << "Unread items:" << statistics.unreadCount(); * } * * @endcode * * This class is implicitely shared. * * @author Volker Krause */ class AKONADI_EXPORT CollectionStatistics { public: /** * Creates a new collection statistics object. */ CollectionStatistics(); /** * Creates a collection statistics object from an @p other one. */ CollectionStatistics( const CollectionStatistics &other ); /** * Destroys the collection statistics object. */ ~CollectionStatistics(); /** * Returns the number of items in this collection or @c -1 if * this information is not available. * * @see setCount() * @see unreadCount() */ qint64 count() const; /** * Sets the number of items in this collection. * * @param count The number of items. * @see count() */ void setCount( qint64 count ); /** * Returns the number of unread items in this collection or @c -1 if * this information is not available. * * @see setUnreadCount() * @see count() */ qint64 unreadCount() const; /** * Sets the number of unread items in this collection. * * @param count The number of unread messages. * @see unreadCount() */ void setUnreadCount( qint64 count ); /** * Returns the total size of the items in this collection or @c -1 if * this information is not available. * * @see setSize() * @since 4.3 */ qint64 size() const; /** * Sets the total size of the items in this collection. * * @param size The total size of the items * @see size() * @since 4.3 */ void setSize( qint64 size ); /** * Assigns @p other to this statistics object and returns a reference to this one. */ CollectionStatistics& operator=( const CollectionStatistics &other ); private: //@cond PRIVATE class Private; QSharedDataPointer d; //@endcond }; } +/** + * Allows to output the collection statistics for debugging purposes. + */ +AKONADI_EXPORT QDebug operator<<( QDebug d, const Akonadi::CollectionStatistics& ); + Q_DECLARE_METATYPE( Akonadi::CollectionStatistics ) #endif