Branch 'kolab/integration/4.13.0' - korganizer/CMakeLists.txt korganizer/views
Christian Mollekopf
mollekopf at kolabsys.com
Mon Nov 17 12:27:19 CET 2014
korganizer/CMakeLists.txt | 1
korganizer/views/collectionview/collectionsearchjob.cpp | 128 ++++++++++++++++
korganizer/views/collectionview/collectionsearchjob.h | 51 ++++++
korganizer/views/collectionview/controller.cpp | 103 ------------
korganizer/views/collectionview/controller.h | 23 --
5 files changed, 184 insertions(+), 122 deletions(-)
New commits:
commit c75ba0ae5e0133da3f9635e7fb54ba4ae558765d
Author: Christian Mollekopf <chrigi_1 at fastmail.fm>
Date: Mon Nov 3 13:33:21 2014 +0100
Moved CollectionSearchJob to separate file.
diff --git a/korganizer/CMakeLists.txt b/korganizer/CMakeLists.txt
index 5c7645e..377a48f 100644
--- a/korganizer/CMakeLists.txt
+++ b/korganizer/CMakeLists.txt
@@ -175,6 +175,7 @@ set(korganizerprivate_LIB_SRCS
akonadicollectionview.cpp
views/collectionview/reparentingmodel.cpp
views/collectionview/controller.cpp
+ views/collectionview/collectionsearchjob.cpp
views/collectionview/calendardelegate.cpp
views/collectionview/quickview.cpp
calendarview.cpp
diff --git a/korganizer/views/collectionview/collectionsearchjob.cpp b/korganizer/views/collectionview/collectionsearchjob.cpp
new file mode 100644
index 0000000..6bc664b
--- /dev/null
+++ b/korganizer/views/collectionview/collectionsearchjob.cpp
@@ -0,0 +1,128 @@
+/*
+Copyright (C) 2014 Christian Mollekopf <mollekopf at kolabsys.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+As a special exception, permission is given to link this program
+with any edition of Qt, and distribute the resulting executable,
+without including the source code for Qt in the source distribution.
+*/
+#include "collectionsearchjob.h"
+
+#include <Akonadi/CollectionFetchJob>
+#include <Akonadi/CollectionFetchScope>
+#include <baloo/pim/collectionquery.h>
+
+CollectionSearchJob::CollectionSearchJob(const QString& searchString, QObject* parent)
+ : KJob(parent),
+ mSearchString(searchString)
+{
+}
+
+void CollectionSearchJob::start()
+{
+ Baloo::PIM::CollectionQuery query;
+ //We exclude the other users namespace
+ query.setNamespace(QStringList() << QLatin1String("shared") << QLatin1String(""));
+ query.pathMatches(mSearchString);
+ query.setMimetype(QStringList() << QLatin1String("text/calendar"));
+ query.setLimit(200);
+ Baloo::PIM::ResultIterator it = query.exec();
+ Akonadi::Collection::List collections;
+ while (it.next()) {
+ collections << Akonadi::Collection(it.id());
+ }
+ kDebug() << "Found collections " << collections.size();
+
+ if (collections.isEmpty()) {
+ //We didn't find anything
+ emitResult();
+ return;
+ }
+
+ Akonadi::CollectionFetchJob *fetchJob = new Akonadi::CollectionFetchJob(collections, Akonadi::CollectionFetchJob::Base, this);
+ fetchJob->fetchScope().setAncestorRetrieval(Akonadi::CollectionFetchScope::All);
+ fetchJob->fetchScope().setListFilter(Akonadi::CollectionFetchScope::NoFilter);
+ connect(fetchJob, SIGNAL(collectionsReceived(Akonadi::Collection::List)), this, SLOT(onCollectionsReceived(Akonadi::Collection::List)));
+ connect(fetchJob, SIGNAL(result(KJob*)), this, SLOT(onCollectionsFetched(KJob*)));
+}
+
+void CollectionSearchJob::onCollectionsReceived(const Akonadi::Collection::List &list)
+{
+ Q_FOREACH(const Akonadi::Collection &col, list) {
+ if (col.name().contains(mSearchString)) {
+ mMatchingCollections << col;
+ Akonadi::Collection ancestor = col.parentCollection();
+ while (ancestor.isValid() && (ancestor != Akonadi::Collection::root())) {
+ if (!mAncestors.contains(ancestor)) {
+ mAncestors << ancestor;
+ }
+ ancestor = ancestor.parentCollection();
+ }
+ }
+ }
+}
+
+void CollectionSearchJob::onCollectionsFetched(KJob *job)
+{
+ if (job->error()) {
+ kWarning() << job->errorString();
+ }
+ if (!mAncestors.isEmpty()) {
+ Akonadi::CollectionFetchJob *fetchJob = new Akonadi::CollectionFetchJob(mAncestors, Akonadi::CollectionFetchJob::Base, this);
+ fetchJob->fetchScope().setListFilter(Akonadi::CollectionFetchScope::NoFilter);
+ connect(fetchJob, SIGNAL(result(KJob*)), this, SLOT(onAncestorsFetched(KJob*)));
+ } else {
+ //We didn't find anything
+ emitResult();
+ }
+}
+
+static Akonadi::Collection replaceParent(Akonadi::Collection col, const Akonadi::Collection::List &ancestors)
+{
+ if (!col.isValid()) {
+ return col;
+ }
+ const Akonadi::Collection parent = replaceParent(col.parentCollection(), ancestors);
+ Q_FOREACH (const Akonadi::Collection &c, ancestors) {
+ if (col == c) {
+ col = c;
+ break;
+ }
+ }
+ col.setParentCollection(parent);
+ return col;
+}
+
+void CollectionSearchJob::onAncestorsFetched(KJob *job)
+{
+ if (job->error()) {
+ kWarning() << job->errorString();
+ }
+ Akonadi::CollectionFetchJob *fetchJob = static_cast<Akonadi::CollectionFetchJob*>(job);
+ Akonadi::Collection::List matchingCollections;
+ Q_FOREACH (const Akonadi::Collection &c, mMatchingCollections) {
+ //We need to replace the parents with the version that contains the name, so we can display it accordingly
+ matchingCollections << replaceParent(c, fetchJob->collections());
+ }
+ mMatchingCollections = matchingCollections;
+ emitResult();
+}
+
+Akonadi::Collection::List CollectionSearchJob::matchingCollections() const
+{
+ return mMatchingCollections;
+}
+
diff --git a/korganizer/views/collectionview/collectionsearchjob.h b/korganizer/views/collectionview/collectionsearchjob.h
new file mode 100644
index 0000000..30b0c07
--- /dev/null
+++ b/korganizer/views/collectionview/collectionsearchjob.h
@@ -0,0 +1,51 @@
+/*
+ Copyright (C) 2014 Christian Mollekopf <mollekopf at kolabsys.com>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ As a special exception, permission is given to link this program
+ with any edition of Qt, and distribute the resulting executable,
+ without including the source code for Qt in the source distribution.
+*/
+
+#ifndef KORG_COLLECTIONSEARCHJOB_H
+#define KORG_COLLECTIONSEARCHJOB_H
+
+#include <KJob>
+#include <Akonadi/Collection>
+
+class CollectionSearchJob : public KJob
+{
+ Q_OBJECT
+public:
+ explicit CollectionSearchJob(const QString &searchString, QObject* parent = 0);
+
+ virtual void start();
+
+ Akonadi::Collection::List matchingCollections() const;
+
+private Q_SLOTS:
+ void onCollectionsReceived(const Akonadi::Collection::List &);
+ void onCollectionsFetched(KJob *);
+ void onAncestorsFetched(KJob *);
+
+private:
+ QString mSearchString;
+ Akonadi::Collection::List mMatchingCollections;
+ Akonadi::Collection::List mAncestors;
+};
+
+#endif
+
diff --git a/korganizer/views/collectionview/controller.cpp b/korganizer/views/collectionview/controller.cpp
index d91497e..0500b60 100644
--- a/korganizer/views/collectionview/controller.cpp
+++ b/korganizer/views/collectionview/controller.cpp
@@ -35,6 +35,8 @@
#include <baloo/pim/collectionquery.h>
#include <akonadi/collectionidentificationattribute.h>
+#include "collectionsearchjob.h"
+
CollectionNode::CollectionNode(ReparentingModel& personModel, const Akonadi::Collection& col)
: Node(personModel),
mCollection(col),
@@ -263,107 +265,6 @@ void PersonNodeManager::checkSourceIndexRemoval(const QModelIndex &sourceIndex)
}
}
-CollectionSearchJob::CollectionSearchJob(const QString& searchString, QObject* parent)
- : KJob(parent),
- mSearchString(searchString)
-{
-}
-
-void CollectionSearchJob::start()
-{
- Baloo::PIM::CollectionQuery query;
- //We exclude the other users namespace
- query.setNamespace(QStringList() << QLatin1String("shared") << QLatin1String(""));
- query.pathMatches(mSearchString);
- query.setMimetype(QStringList() << QLatin1String("text/calendar"));
- query.setLimit(200);
- Baloo::PIM::ResultIterator it = query.exec();
- Akonadi::Collection::List collections;
- while (it.next()) {
- collections << Akonadi::Collection(it.id());
- }
- kDebug() << "Found collections " << collections.size();
-
- if (collections.isEmpty()) {
- //We didn't find anything
- emitResult();
- return;
- }
-
- Akonadi::CollectionFetchJob *fetchJob = new Akonadi::CollectionFetchJob(collections, Akonadi::CollectionFetchJob::Base, this);
- fetchJob->fetchScope().setAncestorRetrieval(Akonadi::CollectionFetchScope::All);
- fetchJob->fetchScope().setListFilter(Akonadi::CollectionFetchScope::NoFilter);
- connect(fetchJob, SIGNAL(collectionsReceived(Akonadi::Collection::List)), this, SLOT(onCollectionsReceived(Akonadi::Collection::List)));
- connect(fetchJob, SIGNAL(result(KJob*)), this, SLOT(onCollectionsFetched(KJob*)));
-}
-
-void CollectionSearchJob::onCollectionsReceived(const Akonadi::Collection::List &list)
-{
- Q_FOREACH(const Akonadi::Collection &col, list) {
- if (col.name().contains(mSearchString)) {
- mMatchingCollections << col;
- Akonadi::Collection ancestor = col.parentCollection();
- while (ancestor.isValid() && (ancestor != Akonadi::Collection::root())) {
- if (!mAncestors.contains(ancestor)) {
- mAncestors << ancestor;
- }
- ancestor = ancestor.parentCollection();
- }
- }
- }
-}
-
-void CollectionSearchJob::onCollectionsFetched(KJob *job)
-{
- if (job->error()) {
- kWarning() << job->errorString();
- }
- if (!mAncestors.isEmpty()) {
- Akonadi::CollectionFetchJob *fetchJob = new Akonadi::CollectionFetchJob(mAncestors, Akonadi::CollectionFetchJob::Base, this);
- fetchJob->fetchScope().setListFilter(Akonadi::CollectionFetchScope::NoFilter);
- connect(fetchJob, SIGNAL(result(KJob*)), this, SLOT(onAncestorsFetched(KJob*)));
- } else {
- //We didn't find anything
- emitResult();
- }
-}
-
-static Akonadi::Collection replaceParent(Akonadi::Collection col, const Akonadi::Collection::List &ancestors)
-{
- if (!col.isValid()) {
- return col;
- }
- const Akonadi::Collection parent = replaceParent(col.parentCollection(), ancestors);
- Q_FOREACH (const Akonadi::Collection &c, ancestors) {
- if (col == c) {
- col = c;
- break;
- }
- }
- col.setParentCollection(parent);
- return col;
-}
-
-void CollectionSearchJob::onAncestorsFetched(KJob *job)
-{
- if (job->error()) {
- kWarning() << job->errorString();
- }
- Akonadi::CollectionFetchJob *fetchJob = static_cast<Akonadi::CollectionFetchJob*>(job);
- Akonadi::Collection::List matchingCollections;
- Q_FOREACH (const Akonadi::Collection &c, mMatchingCollections) {
- //We need to replace the parents with the version that contains the name, so we can display it accordingly
- matchingCollections << replaceParent(c, fetchJob->collections());
- }
- mMatchingCollections = matchingCollections;
- emitResult();
-}
-
-Akonadi::Collection::List CollectionSearchJob::matchingCollections() const
-{
- return mMatchingCollections;
-}
-
PersonSearchJob::PersonSearchJob(const QString& searchString, QObject* parent)
: KJob(parent),
diff --git a/korganizer/views/collectionview/controller.h b/korganizer/views/collectionview/controller.h
index af786aa..2dc7c71 100644
--- a/korganizer/views/collectionview/controller.h
+++ b/korganizer/views/collectionview/controller.h
@@ -139,27 +139,6 @@ private:
void updateSourceIndex(const QModelIndex &sourceIndex);
};
-class CollectionSearchJob : public KJob
-{
- Q_OBJECT
-public:
- explicit CollectionSearchJob(const QString &searchString, QObject* parent = 0);
-
- virtual void start();
-
- Akonadi::Collection::List matchingCollections() const;
-
-private Q_SLOTS:
- void onCollectionsReceived(const Akonadi::Collection::List &);
- void onCollectionsFetched(KJob *);
- void onAncestorsFetched(KJob *);
-
-private:
- QString mSearchString;
- Akonadi::Collection::List mMatchingCollections;
- Akonadi::Collection::List mAncestors;
-};
-
class PersonSearchJob : public KJob
{
Q_OBJECT
@@ -194,6 +173,8 @@ private:
bool mLdapSearchDone;
};
+class CollectionSearchJob;
+
/**
* Add search results to the search model, and use the selection to add results to the person model.
*/
More information about the commits
mailing list