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 )
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"