diff --git a/src/file/filecontentindexer.cpp b/src/file/filecontentindexer.cpp index 6f09d645..17b13ad4 100644 --- a/src/file/filecontentindexer.cpp +++ b/src/file/filecontentindexer.cpp @@ -1,145 +1,145 @@ /* * Copyright (C) 2015 Vishesh Handa * * 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) any later version. * * 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #include "filecontentindexer.h" #include "filecontentindexerprovider.h" #include "extractorprocess.h" #include #include #include using namespace Baloo; FileContentIndexer::FileContentIndexer(FileIndexerConfig* config, FileContentIndexerProvider* provider, QObject* parent) : QObject(parent) , m_config(config) , m_batchSize(config->maxUncomittedFiles()) , m_provider(provider) , m_stop(0) { Q_ASSERT(provider); QDBusConnection bus = QDBusConnection::sessionBus(); m_monitorWatcher.setConnection(bus); m_monitorWatcher.setWatchMode(QDBusServiceWatcher::WatchForUnregistration); connect(&m_monitorWatcher, &QDBusServiceWatcher::serviceUnregistered, this, &FileContentIndexer::monitorClosed); bus.registerObject(QStringLiteral("/fileindexer"), this, QDBusConnection::ExportScriptableContents); } void FileContentIndexer::run() { ExtractorProcess process; connect(&process, &ExtractorProcess::startedIndexingFile, this, &FileContentIndexer::slotStartedIndexingFile); connect(&process, &ExtractorProcess::finishedIndexingFile, this, &FileContentIndexer::slotFinishedIndexingFile); -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) m_stop.store(false); #else m_stop.storeRelaxed(false); #endif auto batchSize = m_batchSize; -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) while (m_provider->size() && !m_stop.load()) { #else while (m_provider->size() && !m_stop.loadRelaxed()) { #endif // // WARNING: This will go mad, if the Extractor does not commit after N=m_batchSize files // cause then we will keep fetching the same N files again and again. // QElapsedTimer timer; timer.start(); QVector idList = m_provider->fetch(batchSize); -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) if (idList.isEmpty() || m_stop.load()) { #else if (idList.isEmpty() || m_stop.loadRelaxed()) { #endif break; } QEventLoop loop; connect(&process, &ExtractorProcess::done, &loop, &QEventLoop::quit); bool hadErrors = false; connect(&process, &ExtractorProcess::failed, &loop, [&hadErrors, &loop]() { hadErrors = true; loop.quit(); }); process.index(idList); loop.exec(); // QDbus requires us to be in object creation thread (thread affinity) // This signal is not even exported, and yet QDbus complains. QDbus bug? QMetaObject::invokeMethod(this, "newBatchTime", Qt::QueuedConnection, Q_ARG(uint, timer.elapsed())); -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) if (hadErrors && !m_stop.load()) { #else if (hadErrors && !m_stop.loadRelaxed()) { #endif if (idList.size() == 1) { auto failedId = idList.first(); m_provider->markFailed(failedId); batchSize = m_batchSize; } else { batchSize = idList.size() / 2; } process.start(); } } QMetaObject::invokeMethod(this, "done", Qt::QueuedConnection); } void FileContentIndexer::slotStartedIndexingFile(const QString& filePath) { m_currentFile = filePath; if (!m_registeredMonitors.isEmpty()) { Q_EMIT startedIndexingFile(filePath); } } void FileContentIndexer::slotFinishedIndexingFile(const QString& filePath) { Q_UNUSED(filePath); if (!m_registeredMonitors.isEmpty()) { Q_EMIT finishedIndexingFile(filePath); } m_currentFile = QString(); } void FileContentIndexer::registerMonitor(const QDBusMessage& message) { if (!m_registeredMonitors.contains(message.service())) { m_registeredMonitors << message.service(); m_monitorWatcher.addWatchedService(message.service()); } } void FileContentIndexer::unregisterMonitor(const QDBusMessage& message) { m_registeredMonitors.removeAll(message.service()); m_monitorWatcher.removeWatchedService(message.service()); } void FileContentIndexer::monitorClosed(const QString& service) { m_registeredMonitors.removeAll(service); m_monitorWatcher.removeWatchedService(service); } diff --git a/src/file/filecontentindexer.h b/src/file/filecontentindexer.h index dfe2c585..011f45b5 100644 --- a/src/file/filecontentindexer.h +++ b/src/file/filecontentindexer.h @@ -1,88 +1,88 @@ /* * Copyright (C) 2015 Vishesh Handa * * 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) any later version. * * 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ #ifndef BALOO_FILECONTENTINDEXER_H #define BALOO_FILECONTENTINDEXER_H #include #include #include #include #include #include #include "fileindexerconfig.h" namespace Baloo { class FileContentIndexerProvider; class FileContentIndexer : public QObject, public QRunnable { Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.baloo.fileindexer") Q_PROPERTY(QString currentFile READ currentFile NOTIFY startedIndexingFile) public: FileContentIndexer(FileIndexerConfig* config, FileContentIndexerProvider* provider, QObject* parent = nullptr); QString currentFile() { return m_currentFile; } void run() override; void quit() { -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) m_stop.store(true); #else m_stop.storeRelaxed(true); #endif } public Q_SLOTS: Q_SCRIPTABLE void registerMonitor(const QDBusMessage& message); Q_SCRIPTABLE void unregisterMonitor(const QDBusMessage& message); Q_SIGNALS: Q_SCRIPTABLE void startedIndexingFile(const QString& filePath); Q_SCRIPTABLE void finishedIndexingFile(const QString& filePath); void done(); void newBatchTime(uint time); private Q_SLOTS: void monitorClosed(const QString& service); void slotStartedIndexingFile(const QString& filePath); void slotFinishedIndexingFile(const QString& filePath); private: FileIndexerConfig *m_config; uint m_batchSize; FileContentIndexerProvider* m_provider; QAtomicInt m_stop; QString m_currentFile; QStringList m_registeredMonitors; QDBusServiceWatcher m_monitorWatcher; }; } #endif // BALOO_FILECONTENTINDEXER_H diff --git a/src/lib/queryrunnable.cpp b/src/lib/queryrunnable.cpp index 7b1dfe58..e8fa4945 100644 --- a/src/lib/queryrunnable.cpp +++ b/src/lib/queryrunnable.cpp @@ -1,74 +1,74 @@ /* * This file is part of the KDE Baloo Project * Copyright (C) 2013 Vishesh Handa * * 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 "queryrunnable.h" #include using namespace Baloo; class QueryRunnable::Private { public: Query m_query; QAtomicInt m_stop; bool stopRequested() const { -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) return m_stop.load(); #else return m_stop.loadRelaxed(); #endif } }; QueryRunnable::QueryRunnable(const Query& query, QObject* parent) : QObject(parent) , d(new Private) { d->m_query = query; d->m_stop = false; } QueryRunnable::~QueryRunnable() { delete d; } void QueryRunnable::stop() { -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) d->m_stop.store(true); #else d->m_stop.storeRelaxed(true); #endif } void QueryRunnable::run() { ResultIterator it = d->m_query.exec(); while (!d->stopRequested() && it.next()) { Q_EMIT queryResult(this, it.filePath()); } Q_EMIT finished(this); }