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
42 void init(
const QString &path,
const Collection &rootCollection)
48 if (mPath.startsWith(q->pathDelimiter())) {
49 mPath = mPath.right(mPath.length() - q->pathDelimiter().length());
51 if (mPath.endsWith(q->pathDelimiter())) {
52 mPath = mPath.left(mPath.length() - q->pathDelimiter().length());
55 mPathParts = splitPath(mPath);
56 mCurrentNode = rootCollection;
59 void jobResult(KJob *);
61 QStringList splitPath(
const QString &path)
69 const int pathSize(path.size());
70 for (
int i = 0; i < pathSize; ++i) {
71 if (path[i] == QLatin1Char(
'/')) {
72 QString pathElement = path.mid(begin, i - begin);
73 pathElement = pathElement.replace(QLatin1String(
"\\/"), QLatin1String(
"/"));
74 rv.append(pathElement);
77 if (i < path.size() - 2 && path[i] == QLatin1Char(
'\\') && path[i + 1] == QLatin1Char(
'/')) {
81 QString pathElement = path.mid(begin);
82 pathElement = pathElement.replace(QLatin1String(
"\\/"), QLatin1String(
"/"));
83 rv.append(pathElement);
92 QStringList mPathParts;
96 void CollectionPathResolverPrivate::jobResult(KJob *job)
107 if (cols.isEmpty()) {
110 q->setErrorText(i18n(
"No such collection."));
116 const QString currentPart = mPathParts.takeFirst();
119 if (c.
name() == currentPart) {
126 kWarning() <<
"No such collection" << currentPart <<
"with parent" << mCurrentNode.
id();
129 q->setErrorText(i18n(
"No such collection."));
133 if (mPathParts.isEmpty()) {
134 mColId = mCurrentNode.
id();
142 mPathParts.prepend(col.
name());
149 q->connect(nextJob, SIGNAL(result(KJob*)), q, SLOT(jobResult(KJob*)));
153 :
Job(new CollectionPathResolverPrivate(this), parent)
160 :
Job(new CollectionPathResolverPrivate(this), parent)
163 d->init(path, parentCollection);
167 :
Job(new CollectionPathResolverPrivate(this), parent)
171 d->mPathToId =
false;
172 d->mColId = collection.
id();
173 d->mCurrentNode = collection;
199 return QLatin1String(
"/");
208 if (d->mPath.isEmpty()) {
215 if (d->mColId == 0) {
222 connect(job, SIGNAL(result(KJob*)), SLOT(jobResult(KJob*)));
227 #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.