summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2016-06-16 23:18:49 +0200
committerMontel Laurent <[email protected]>2016-06-16 23:19:36 +0200
commit3feced60911c7c23b3b11901e7e96fca5049406c (patch)
tree5b4f253113bf0b61e678989ceefd7a7681b1eaad
parent993ecffe49d49fa8a658813d89db51bfdf835bca (diff)
We don't want to check all the time. Reveify check each 7 days
-rw-r--r--kmail/src/search/checkindexingjob.cpp14
-rw-r--r--kmail/src/search/checkindexingjob.h4
-rw-r--r--kmail/src/search/checkindexingmanager.cpp43
-rw-r--r--kmail/src/search/checkindexingmanager.h3
4 files changed, 44 insertions, 20 deletions
diff --git a/kmail/src/search/checkindexingjob.cpp b/kmail/src/search/checkindexingjob.cpp
index b2086eb..e80cdef 100644
--- a/kmail/src/search/checkindexingjob.cpp
+++ b/kmail/src/search/checkindexingjob.cpp
@@ -40,10 +40,10 @@ CheckIndexingJob::~CheckIndexingJob()
}
-void CheckIndexingJob::askForNextCheck()
+void CheckIndexingJob::askForNextCheck(quint64 id)
{
deleteLater();
- Q_EMIT finished();
+ Q_EMIT finished(id);
}
void CheckIndexingJob::setCollection(const Akonadi::Collection &col)
@@ -60,7 +60,7 @@ void CheckIndexingJob::start()
connect(fetch, &KJob::result, this, &CheckIndexingJob::slotCollectionPropertiesFinished);
} else {
qCWarning(KMAIL_LOG) << "Collection was not valid";
- askForNextCheck();
+ askForNextCheck(-1);
}
}
@@ -70,7 +70,7 @@ void CheckIndexingJob::slotCollectionPropertiesFinished(KJob *job)
Q_ASSERT(fetch);
if (fetch->collections().isEmpty()) {
qCWarning(KMAIL_LOG) << "No collection fetched";
- askForNextCheck();
+ askForNextCheck(-1);
return;
}
@@ -84,7 +84,7 @@ void CheckIndexingJob::indexerStatsFetchFinished(KJob* job)
{
if (job->error()) {
qCWarning(KMAIL_LOG) << "CheckIndexingJob::indexerStatsFetchFinished error :" << job->errorString();
- askForNextCheck();
+ askForNextCheck(-1);
return;
}
@@ -92,11 +92,11 @@ void CheckIndexingJob::indexerStatsFetchFinished(KJob* job)
//qDebug()<<" stats "<< stats;
qCDebug(KMAIL_LOG) << " mCollection.statistics().count() "<< mCollection.statistics().count() << "stats.value(mCollection.id())" << stats.value(mCollection.id());
if (mCollection.statistics().count() != stats.value(mCollection.id())) {
- QDBusInterface interfaceBalooIndexer(QStringLiteral("org.freedesktop.Akonadi.Agent.akonadi_indexing_agent"), QStringLiteral("/"), QStringLiteral("org.freedesktop.Akonadi.Indexer"));
+ QDBusInterface interfaceBalooIndexer(PimCommon::indexerServiceName(), QStringLiteral("/"), QStringLiteral("org.freedesktop.Akonadi.Indexer"));
if (interfaceBalooIndexer.isValid()) {
qCDebug(KMAIL_LOG) << "Reindex collection :"<< mCollection.id() << "name :"<< mCollection.name();
interfaceBalooIndexer.call(QStringLiteral("reindexCollection"), (qlonglong)mCollection.id());
}
}
- askForNextCheck();
+ askForNextCheck(mCollection.id());
}
diff --git a/kmail/src/search/checkindexingjob.h b/kmail/src/search/checkindexingjob.h
index a79811b..57a735d 100644
--- a/kmail/src/search/checkindexingjob.h
+++ b/kmail/src/search/checkindexingjob.h
@@ -35,13 +35,13 @@ public:
void start();
Q_SIGNALS:
- void finished();
+ void finished(Akonadi::Collection::Id id);
private Q_SLOTS:
void slotCollectionPropertiesFinished(KJob *job);
void indexerStatsFetchFinished(KJob *job);
private:
- void askForNextCheck();
+ void askForNextCheck(quint64 id);
Akonadi::Collection mCollection;
};
diff --git a/kmail/src/search/checkindexingmanager.cpp b/kmail/src/search/checkindexingmanager.cpp
index 0b22428..0e710fc 100644
--- a/kmail/src/search/checkindexingmanager.cpp
+++ b/kmail/src/search/checkindexingmanager.cpp
@@ -23,6 +23,8 @@
#include "checkindexingjob.h"
#include <AkonadiCore/EntityTreeModel>
#include <AkonadiCore/CachePolicy>
+#include <KSharedConfig>
+#include <KConfigGroup>
#include <MailCommon/MailUtil>
#include <PimCommon/PimUtil>
#include <QTimer>
@@ -41,7 +43,9 @@ CheckIndexingManager::CheckIndexingManager(QObject *parent)
CheckIndexingManager::~CheckIndexingManager()
{
-
+ const KSharedConfig::Ptr cfg = KSharedConfig::openConfig(QStringLiteral("kmailsearchindexingrc"));
+ KConfigGroup grp = cfg->group(QStringLiteral("General"));
+ grp.writeEntry(QStringLiteral("collectionsIndexed"), mCollectionsIndexed);
}
void CheckIndexingManager::start(QAbstractItemModel *collectionModel)
@@ -49,12 +53,20 @@ void CheckIndexingManager::start(QAbstractItemModel *collectionModel)
if(mIsReady) {
mIndex = 0;
mListCollection.clear();
- if (collectionModel) {
- initializeCollectionList(collectionModel);
- if (!mListCollection.isEmpty()) {
- qCDebug(KMAIL_LOG) << "Number of collection to check " << mListCollection.count();
- mIsReady = false;
- mTimer->start();
+ const KSharedConfig::Ptr cfg = KSharedConfig::openConfig(QStringLiteral("kmailsearchindexingrc"));
+ KConfigGroup grp = cfg->group(QStringLiteral("General"));
+ const QDateTime lastDateTime = grp.readEntry(QStringLiteral("lastCheck"), QDateTime());
+ //Check each 7 days
+ QDateTime today = QDateTime::currentDateTime();
+ if (lastDateTime.isValid() || today > lastDateTime.addDays(7)) {
+ mCollectionsIndexed = grp.readEntry(QStringLiteral("collectionsIndexed"), QList<qint64>());
+ if (collectionModel) {
+ initializeCollectionList(collectionModel);
+ if (!mListCollection.isEmpty()) {
+ qCDebug(KMAIL_LOG) << "Number of collection to check " << mListCollection.count();
+ mIsReady = false;
+ mTimer->start();
+ }
}
}
}
@@ -64,7 +76,7 @@ void CheckIndexingManager::createJob()
{
CheckIndexingJob *job = new CheckIndexingJob(this);
job->setCollection(mListCollection.at(mIndex));
- connect(job, &CheckIndexingJob::finished, this, &CheckIndexingManager::slotRestartTimer);
+ connect(job, &CheckIndexingJob::finished, this, &CheckIndexingManager::indexingFinished);
job->start();
}
@@ -75,8 +87,13 @@ void CheckIndexingManager::checkNextCollection()
}
}
-void CheckIndexingManager::slotRestartTimer()
+void CheckIndexingManager::indexingFinished(qint64 index)
{
+ if (index != -1) {
+ if (!mCollectionsIndexed.contains(index)) {
+ mCollectionsIndexed.append(index);
+ }
+ }
mIndex++;
if (mIndex < mListCollection.count()) {
mTimer->start();
@@ -84,6 +101,10 @@ void CheckIndexingManager::slotRestartTimer()
mIsReady = true;
mIndex = 0;
mListCollection.clear();
+ const KSharedConfig::Ptr cfg = KSharedConfig::openConfig(QStringLiteral("kmailsearchindexingrc"));
+ KConfigGroup grp = cfg->group(QStringLiteral("General"));
+ grp.writeEntry(QStringLiteral("lastCheck"), QDateTime::currentDateTime());
+ grp.deleteEntry(QStringLiteral("collectionsIndexed"));
}
}
@@ -111,7 +132,9 @@ void CheckIndexingManager::initializeCollectionList(QAbstractItemModel *model, c
if (PimCommon::Util::isImapResource(collection.resource()) && !collection.cachePolicy().localParts().contains(QLatin1String("RFC822"))) {
continue;
}
- mListCollection.append(collection);
+ if (!mCollectionsIndexed.contains(collection.id())) {
+ mListCollection.append(collection);
+ }
if (model->rowCount(index) > 0) {
initializeCollectionList(model, index);
}
diff --git a/kmail/src/search/checkindexingmanager.h b/kmail/src/search/checkindexingmanager.h
index 3773391..45aaf9e 100644
--- a/kmail/src/search/checkindexingmanager.h
+++ b/kmail/src/search/checkindexingmanager.h
@@ -38,13 +38,14 @@ public:
private Q_SLOTS:
void checkNextCollection();
- void slotRestartTimer();
+ void indexingFinished(qint64 index);
private:
void initializeCollectionList(QAbstractItemModel *model, const QModelIndex &parentIndex = QModelIndex());
void createJob();
Akonadi::Collection::List mListCollection;
QTimer *mTimer;
+ QList<qint64> mCollectionsIndexed;
int mIndex;
bool mIsReady;
};