diff --git a/src/pim/agent/agent.cpp b/src/pim/agent/agent.cpp index c0a268c7..3ab76d9c 100644 --- a/src/pim/agent/agent.cpp +++ b/src/pim/agent/agent.cpp @@ -1,257 +1,258 @@ /* * This file is part of the KDE Baloo Project * Copyright (C) 2013 Vishesh Handa * Copyright (C) 2014 Christian Mollekopf * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . * */ #include "agent.h" #include "contactindexer.h" #include "emailindexer.h" #include "akonotesindexer.h" #include "calendarindexer.h" #include "balooindexeradaptor.h" #include "collectionupdatejob.h" #include "src/file/priority.h" #include #include #include #include #include #include #include #include #include #include #include #define INDEXING_AGENT_VERSION 4 BalooIndexingAgent::BalooIndexingAgent(const QString& id) : AgentBase(id), m_scheduler(m_index, QSharedPointer(new JobFactory)) { lowerIOPriority(); lowerSchedulingPriority(); lowerPriority(); KConfig config("baloorc"); KConfigGroup group = config.group("Akonadi"); const int agentIndexingVersion = group.readEntry("agentIndexingVersion", 0); if (agentIndexingVersionsetAllMonitored(true); changeRecorder()->itemFetchScope().setCacheOnly(true); changeRecorder()->itemFetchScope().setAncestorRetrieval(Akonadi::ItemFetchScope::Parent); changeRecorder()->itemFetchScope().setFetchRemoteIdentification(false); changeRecorder()->itemFetchScope().setFetchModificationTime(false); changeRecorder()->collectionFetchScope().setAncestorRetrieval(Akonadi::CollectionFetchScope::All); changeRecorder()->collectionFetchScope().ancestorFetchScope().fetchAttribute(); changeRecorder()->collectionFetchScope().setListFilter(Akonadi::CollectionFetchScope::Index); changeRecorder()->setChangeRecordingEnabled(false); changeRecorder()->fetchCollection(true); + changeRecorder()->setExclusive(true); new BalooIndexerAdaptor(this); // Cleanup agentsrc after migration to 4.13 Akonadi::AgentManager* agentManager = Akonadi::AgentManager::self(); const Akonadi::AgentInstance::List allAgents = agentManager->instances(); const QStringList oldFeeders = QStringList() << "akonadi_nepomuk_feeder"; // Cannot use agentManager->instance(oldInstanceName) here, it wouldn't find broken instances. Q_FOREACH( const Akonadi::AgentInstance& inst, allAgents ) { if ( oldFeeders.contains( inst.identifier() ) ) { kDebug() << "Removing old nepomuk feeder" << inst.identifier(); agentManager->removeInstance( inst ); } } } BalooIndexingAgent::~BalooIndexingAgent() { } void BalooIndexingAgent::reindexAll() { kDebug() << "Reindexing everything"; m_scheduler.abort(); m_index.removeDatabase(); m_index.createIndexers(); QTimer::singleShot(0, &m_scheduler, SLOT(scheduleCompleteSync())); } void BalooIndexingAgent::reindexCollection(const qlonglong id) { kDebug() << "Reindexing collection " << id; m_scheduler.scheduleCollection(Akonadi::Collection(id), true); } qlonglong BalooIndexingAgent::indexedItems(const qlonglong id) { return m_index.indexedItems(id); } void BalooIndexingAgent::itemAdded(const Akonadi::Item& item, const Akonadi::Collection& collection) { Q_UNUSED(collection); m_scheduler.addItem(item); } void BalooIndexingAgent::itemChanged(const Akonadi::Item& item, const QSet& partIdentifiers) { // We don't index certain parts so we don't care when they change QSet pi = partIdentifiers; QMutableSetIterator it(pi); while (it.hasNext()) { it.next(); if (!it.value().startsWith("PLD:")) it.remove(); } if (pi.isEmpty()) { return; } m_scheduler.addItem(item); } void BalooIndexingAgent::itemsFlagsChanged(const Akonadi::Item::List& items, const QSet& addedFlags, const QSet& removedFlags) { // Akonadi always sends batch of items of the same type m_index.updateFlags(items, addedFlags, removedFlags); m_index.scheduleCommit(); } void BalooIndexingAgent::itemsRemoved(const Akonadi::Item::List& items) { m_index.remove(items); m_index.scheduleCommit(); } void BalooIndexingAgent::itemsMoved(const Akonadi::Item::List& items, const Akonadi::Collection& sourceCollection, const Akonadi::Collection& destinationCollection) { m_index.move(items, sourceCollection, destinationCollection); m_index.scheduleCommit(); } void BalooIndexingAgent::collectionAdded(const Akonadi::Collection& collection, const Akonadi::Collection& parent) { m_index.index(collection); m_index.scheduleCommit(); } void BalooIndexingAgent::collectionChanged(const Akonadi::Collection& collection, const QSet& changedAttributes) { QSet changes = changedAttributes; changes.remove("collectionquota"); changes.remove("timestamp"); changes.remove("imapquota"); if (changes.isEmpty()) { return; } if (changes.contains("ENTITYDISPLAY")) { //If the name changed we have to reindex all subcollections CollectionUpdateJob *job = new CollectionUpdateJob(m_index, collection, this); job->start(); } else { m_index.index(collection); m_index.scheduleCommit(); } } void BalooIndexingAgent::collectionRemoved(const Akonadi::Collection& collection) { m_index.remove(collection); m_index.scheduleCommit(); } void BalooIndexingAgent::collectionMoved(const Akonadi::Collection &collection, const Akonadi::Collection &collectionSource, const Akonadi::Collection &collectionDestination) { m_index.remove(collection); CollectionUpdateJob *job = new CollectionUpdateJob(m_index, collection, this); job->start(); } void BalooIndexingAgent::cleanup() { // Remove all the databases Akonadi::AgentBase::cleanup(); } void BalooIndexingAgent::onAbortRequested() { KConfig config(QLatin1String("baloorc")); KConfigGroup group = config.group("Akonadi"); group.writeEntry("aborted", true); group.sync(); m_scheduler.abort(); } void BalooIndexingAgent::onOnlineChanged(bool online) { // Ignore everything when offline changeRecorder()->setAllMonitored(online); // Index items that might have changed while we were offline if (online) { //We only reindex if this is not a regular start KConfig config(QLatin1String("baloorc")); KConfigGroup group = config.group("Akonadi"); const bool aborted = group.readEntry("aborted", false); if (aborted) { group.writeEntry("aborted", false); group.sync(); m_scheduler.scheduleCompleteSync(); } } else { // Abort ongoing indexing when switched to offline onAbortRequested(); } } AKONADI_AGENT_MAIN(BalooIndexingAgent)