20 #include "collectionpathresolver_p.h"
22 #include "collectionfetchjob.h"
25 #include <klocalizedstring.h>
27 #include <QtCore/QStringList>
29 using namespace Akonadi;
33 class Akonadi::CollectionPathResolverPrivate :
public JobPrivate
41 void jobResult( KJob* );
43 QStringList splitPath(
const QString &path )
45 if ( path.isEmpty() ) {
51 const int pathSize( path.size() );
52 for (
int i = 0; i < pathSize; ++i ) {
53 if ( path[i] == QLatin1Char(
'/' ) ) {
54 QString pathElement = path.mid( begin, i - begin );
55 pathElement = pathElement.replace( QLatin1String(
"\\/" ), QLatin1String(
"/" ) );
56 rv.append( pathElement );
59 if ( i < path.size() - 2 && path[i] == QLatin1Char(
'\\' ) && path[i + 1] == QLatin1Char(
'/' ) ) {
63 QString pathElement = path.mid( begin );
64 pathElement = pathElement.replace( QLatin1String(
"\\/" ), QLatin1String(
"/" ) );
65 rv.append( pathElement );
74 QStringList mPathParts;
78 void CollectionPathResolverPrivate::jobResult(KJob *job )
89 if ( cols.isEmpty() ) {
91 q->setErrorText( i18n(
"No such collection." ) );
97 const QString currentPart = mPathParts.takeFirst();
100 if ( c.
name() == currentPart ) {
108 q->setErrorText( i18n(
"No such collection." ) );
112 if ( mPathParts.isEmpty() ) {
113 mColId = mCurrentNode.
id();
121 mPathParts.prepend( col.
name() );
128 q->connect( nextJob, SIGNAL(result(KJob*)), q, SLOT(jobResult(KJob*)) );
132 :
Job( new CollectionPathResolverPrivate( this ), parent )
138 if ( d->mPath.startsWith( pathDelimiter() ) ) {
139 d->mPath = d->mPath.right( d->mPath.length() - pathDelimiter().length() );
141 if ( d->mPath.endsWith( pathDelimiter() ) ) {
142 d->mPath = d->mPath.left( d->mPath.length() - pathDelimiter().length() );
145 d->mPathParts = d->splitPath( d->mPath );
150 :
Job( new CollectionPathResolverPrivate( this ), parent )
154 d->mPathToId =
false;
155 d->mColId = collection.
id();
156 d->mCurrentNode = collection;
174 if ( d->mPathToId ) {
182 return QLatin1String(
"/" );
190 if ( d->mPathToId ) {
191 if ( d->mPath.isEmpty() ) {
198 if ( d->mColId == 0 ) {
205 connect( job, SIGNAL(result(KJob*)), SLOT(jobResult(KJob*)) );
210 #include "moc_collectionpathresolver_p.cpp"
CollectionPathResolver(const QString &path, QObject *parent=0)
Creates a new collection path resolver to convert a path into a id.
Collection::List collections() const
Returns the list of fetched collection.
Collection::Id collection() const
Returns the collection id.
QString name() const
Returns the i18n'ed name of the collection.
Only list direct sub-collections of the base collection.
Represents a collection of PIM items.
Job that fetches collections from the Akonadi storage.
qint64 Id
Describes the unique id type.
Base class for all actions in the Akonadi storage.
~CollectionPathResolver()
Destroys the collection path resolver.
Only fetch the base collection.
Collection parentCollection() const
Returns the parent collection of this object.
QString path() const
Returns the collection path.
static Collection root()
Returns the root collection.
Id id() const
Returns the unique identifier of the entity.
static QString pathDelimiter()
Returns the path delimiter for collections.
QList< Collection > List
Describes a list of collections.
void doStart()
This method must be reimplemented in the concrete jobs.