20 #include "collection.h"
21 #include "collection_p.h"
23 #include "attributefactory.h"
24 #include "cachepolicy.h"
25 #include "collectionrightsattribute_p.h"
26 #include "collectionstatistics.h"
29 #include <QtCore/QDebug>
30 #include <QtCore/QHash>
31 #include <QtCore/QString>
32 #include <QtCore/QStringList>
37 using namespace Akonadi;
39 class CollectionRoot :
public Collection
46 types << Collection::mimeType();
47 setContentMimeTypes( types );
50 Collection::Rights rights;
51 rights |= Collection::ReadOnly;
56 K_GLOBAL_STATIC( CollectionRoot, s_root )
62 static int lastId = -1;
66 Collection::Collection(
Id id ) :
76 Collection::~Collection()
80 QString Collection::name( )
const
82 return d_func()->name;
85 void Collection::setName(
const QString & name )
91 Collection::Rights Collection::rights()
const
100 void Collection::setRights( Rights rights )
106 QStringList Collection::contentMimeTypes()
const
108 return d_func()->contentTypes;
111 void Collection::setContentMimeTypes(
const QStringList & types )
114 if ( d->contentTypes != types ) {
115 d->contentTypes = types;
116 d->contentTypesChanged =
true;
122 return parentCollection().id();
125 void Collection::setParent(
Id parent )
127 parentCollection().setId( parent );
132 setParentCollection( collection );
135 QString Collection::parentRemoteId()
const
137 return parentCollection().remoteId();
140 void Collection::setParentRemoteId(
const QString & remoteParent)
142 parentCollection().setRemoteId( remoteParent );
145 KUrl Collection::url()
const
147 return url( UrlShort );
150 KUrl Collection::url( UrlType type )
const
153 url.setProtocol( QString::fromLatin1(
"akonadi" ) );
154 url.addQueryItem( QLatin1String(
"collection" ), QString::number(
id() ) );
156 if ( type == UrlWithName )
157 url.addQueryItem( QLatin1String(
"name" ), name() );
164 if ( url.protocol() != QLatin1String(
"akonadi" ) )
167 const QString colStr = url.queryItem( QLatin1String(
"collection" ) );
174 return Collection::root();
184 QString Collection::mimeType( )
186 return QString::fromLatin1(
"inode/directory" );
189 QString Collection::resource()
const
191 return d_func()->resource;
194 void Collection::setResource(
const QString & resource)
197 d->resource = resource;
200 uint qHash(
const Akonadi::Collection &collection )
202 return qHash( collection.id() );
205 QDebug operator <<( QDebug d,
const Akonadi::Collection &collection )
207 return d <<
"Collection ID:" << collection.id()
208 <<
" remote ID:" << collection.remoteId() << endl
209 <<
" name:" << collection.name() << endl
210 <<
" url:" << collection.url() << endl
211 <<
" parent:" << collection.parentCollection().id() << collection.parentCollection().remoteId() << endl
212 <<
" resource:" << collection.resource() << endl
213 <<
" rights:" << collection.rights() << endl
214 <<
" contents mime type:" << collection.contentMimeTypes() << endl
215 <<
" " << collection.cachePolicy() << endl
216 <<
" " << collection.statistics();
221 return d_func()->statistics;
227 d->statistics = statistics;
232 return d_func()->cachePolicy;
238 d->cachePolicy = cachePolicy;
239 d->cachePolicyChanged =
true;
242 bool Collection::isVirtual()
const
245 return ( (resource() == QLatin1String(
"akonadi_search_resource" ) || resource() == QLatin1String(
"akonadi_nepomuktag_resource" ) ) );
248 AKONADI_DEFINE_PRIVATE( Akonadi::Collection )