20 #include "collectionpathresolver_p.h"
22 #include "collectionfetchjob.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 )
50 const int pathSize( path.size() );
51 for (
int i = 0; i < pathSize; ++i ) {
52 if ( path[i] == QLatin1Char(
'/') ) {
53 QString pathElement = path.mid( begin, i - begin );
54 pathElement = pathElement.replace( QLatin1String(
"\\/" ), QLatin1String(
"/" ) );
55 rv.append( pathElement );
58 if ( i < path.size() - 2 && path[i] == QLatin1Char(
'\\') && path[i + 1] == QLatin1Char(
'/') )
61 QString pathElement = path.mid( begin );
62 pathElement = pathElement.replace( QLatin1String(
"\\/" ), QLatin1String(
"/" ) );
63 rv.append( pathElement );
72 QStringList mPathParts;
76 void CollectionPathResolverPrivate::jobResult(KJob *job )
86 if ( cols.isEmpty() ) {
88 q->setErrorText( i18n(
"No such collection." ) );
94 const QString currentPart = mPathParts.takeFirst();
97 if ( c.
name() == currentPart ) {
105 q->setErrorText( i18n(
"No such collection." ) );
109 if ( mPathParts.isEmpty() ) {
110 mColId = mCurrentNode.
id();
118 mPathParts.prepend( col.
name() );
125 q->connect( nextJob, SIGNAL(result(KJob*)), q, SLOT(jobResult(KJob*)) );
129 :
Job( new CollectionPathResolverPrivate( this ), parent )
135 if ( d->mPath.startsWith( pathDelimiter() ) )
136 d->mPath = d->mPath.right( d->mPath.length() - pathDelimiter().length() );
137 if ( d->mPath.endsWith( pathDelimiter() ) )
138 d->mPath = d->mPath.left( d->mPath.length() - pathDelimiter().length() );
140 d->mPathParts = d->splitPath( d->mPath );
145 :
Job( new CollectionPathResolverPrivate( this ), parent )
149 d->mPathToId =
false;
150 d->mColId = collection.
id();
151 d->mCurrentNode = collection;
176 return QLatin1String(
"/" );
184 if ( d->mPathToId ) {
185 if ( d->mPath.isEmpty() ) {
192 if ( d->mColId == 0 ) {
199 connect( job, SIGNAL(result(KJob*)), SLOT(jobResult(KJob*)) );
204 #include "collectionpathresolver_p.moc"