Commit 436061cc authored by Laurent Montel's avatar Laurent Montel 😁

Add collectionindexstatusjob

parent 22605e77
......@@ -21,7 +21,7 @@ include(ECMQtDeclareLoggingCategory)
include(ECMAddTests)
include(ECMInstallIcons)
set(PIM_VERSION "5.2.41")
set(PIM_VERSION "5.2.42")
set(PIMCOMMON_LIB_VERSION ${PIM_VERSION})
set(KDEPIMLIBS_LIB_VERSION "5.2.40")
......
......@@ -118,6 +118,7 @@ set(libpimcommon_folderdialog_SRCS
set(libpimcommon_job_SRCS
job/fetchrecursivecollectionsjob.cpp
job/collectionindexstatusjob.cpp
)
set(libpimcommon_acl_SRCS
......@@ -332,6 +333,7 @@ ecm_generate_headers(PimCommon_CamelCasegenericgrantlee_HEADERS
ecm_generate_headers(PimCommon_CamelCasejob_HEADERS
HEADER_NAMES
FetchRecursiveCollectionsJob
CollectionIndexStatusJob
REQUIRED_HEADERS PimCommon_job_HEADERS
PREFIX PimCommon
RELATIVE job
......
/*
* Copyright (c) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
*
* 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.
*
*/
#include "collectionindexstatusjob.h"
#include "pimcommon_debug.h"
#include <QDBusInterface>
#include <QDBusPendingCallWatcher>
#include <QDBusPendingReply>
#include <AkonadiCore/ServerManager>
using namespace PimCommon;
QString PimCommon::indexerServiceName()
{
QLatin1String basename("org.freedesktop.Akonadi.Agent.akonadi_indexing_agent");
if (Akonadi::ServerManager::hasInstanceIdentifier()) {
return basename + QLatin1Char('.') + Akonadi::ServerManager::instanceIdentifier();
} else {
return basename;
}
}
CollectionIndexStatusJob::CollectionIndexStatusJob(const Akonadi::Collection::List &collections, QObject* parent)
: KJob(parent)
, mCollections(collections)
{
}
CollectionIndexStatusJob::~CollectionIndexStatusJob()
{
}
QMap<qint64, qint64> CollectionIndexStatusJob::resultStats() const
{
return mResult;
}
void CollectionIndexStatusJob::start()
{
QDBusInterface indexer(indexerServiceName(), QLatin1String("/"),
QStringLiteral("org.freedesktop.Akonadi.Indexer"),
QDBusConnection::sessionBus(), this);
Q_FOREACH (const Akonadi::Collection &col, mCollections) {
QDBusPendingCall call = indexer.asyncCall(QLatin1String("indexedItems"), col.id());
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
watcher->setProperty("collectionId", col.id());
connect(watcher, &QDBusPendingCallWatcher::finished, this, &CollectionIndexStatusJob::replyReceived);
mWatchers.push_back(watcher);
}
if (mWatchers.isEmpty()) {
emitResult();
}
}
void CollectionIndexStatusJob::replyReceived(QDBusPendingCallWatcher *watcher)
{
Q_ASSERT(mWatchers.contains(watcher));
QDBusPendingReply<qint64> reply = *watcher;
if (reply.isError()) {
qCWarning(PIMCOMMON_LOG) << "DBus error:" << reply.error().message();
} else {
mResult.insert(watcher->property("collectionId").toLongLong(), reply.argumentAt<0>());
}
watcher->deleteLater();
mWatchers.removeOne(watcher);
if (mWatchers.isEmpty()) {
emitResult();
}
}
/*
* Copyright (c) 2016 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
*
* 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.
*
*/
#ifndef INDEXERUTILS_H
#define INDEXERUTILS_H
#include <KJob>
#include "pimcommon_export.h"
#include <AkonadiCore/Collection>
class QDBusPendingCallWatcher;
namespace PimCommon
{
PIMCOMMON_EXPORT QString indexerServiceName();
class PIMCOMMON_EXPORT CollectionIndexStatusJob : public KJob
{
Q_OBJECT
public:
explicit CollectionIndexStatusJob(const Akonadi::Collection::List &collections, QObject *parent = Q_NULLPTR);
~CollectionIndexStatusJob();
void start() Q_DECL_OVERRIDE;
QMap<qint64, qint64> resultStats() const;
private Q_SLOTS:
void replyReceived(QDBusPendingCallWatcher *watcher);
private:
QList<QDBusPendingCallWatcher*> mWatchers;
Akonadi::Collection::List mCollections;
QMap<qint64 /* collectionId */, qint64 /* indexed cnt */> mResult;
};
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment