| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.1-or-later |
| 5 | */ |
| 6 | |
| 7 | #include "mainhub.h" |
| 8 | #include "fileindexerconfig.h" |
| 9 | |
| 10 | #include <QDBusConnection> |
| 11 | #include <QCoreApplication> |
| 12 | #include <QTimer> |
| 13 | |
| 14 | using namespace Baloo; |
| 15 | |
| 16 | MainHub::MainHub(Database *db, FileIndexerConfig *config, bool firstRun) |
| 17 | : m_config(config) |
| 18 | , m_fileWatcher(db, config, this) |
| 19 | , m_fileIndexScheduler(db, config, firstRun, this) |
| 20 | { |
| 21 | Q_ASSERT(db); |
| 22 | Q_ASSERT(config); |
| 23 | |
| 24 | connect(sender: &m_fileWatcher, signal: &FileWatch::indexNewFile, context: &m_fileIndexScheduler, slot: &FileIndexScheduler::indexNewFile); |
| 25 | connect(sender: &m_fileWatcher, signal: &FileWatch::indexModifiedFile, context: &m_fileIndexScheduler, slot: &FileIndexScheduler::indexModifiedFile); |
| 26 | connect(sender: &m_fileWatcher, signal: &FileWatch::indexXAttr, context: &m_fileIndexScheduler, slot: &FileIndexScheduler::indexXAttrFile); |
| 27 | connect(sender: &m_fileWatcher, signal: &FileWatch::fileRemoved, context: &m_fileIndexScheduler, slot: &FileIndexScheduler::handleFileRemoved); |
| 28 | |
| 29 | connect(sender: &m_fileWatcher, signal: &FileWatch::installedWatches, context: &m_fileIndexScheduler, slot: &FileIndexScheduler::scheduleIndexing); |
| 30 | |
| 31 | QDBusConnection bus = QDBusConnection::sessionBus(); |
| 32 | bus.registerObject(QStringLiteral("/" ), object: this, options: QDBusConnection::ExportAllSlots | |
| 33 | QDBusConnection::ExportScriptableSignals | QDBusConnection::ExportAdaptors); |
| 34 | |
| 35 | if (firstRun) { |
| 36 | QTimer::singleShot(interval: 5000, receiver: this, slot: [this] { |
| 37 | m_fileIndexScheduler.startupFinished(); |
| 38 | }); |
| 39 | } else { |
| 40 | // Delay these checks so we don't end up consuming excessive resources on login |
| 41 | QTimer::singleShot(interval: 5000, receiver: this, slot: [this] { |
| 42 | m_fileIndexScheduler.checkUnindexedFiles(); |
| 43 | m_fileIndexScheduler.checkStaleIndexEntries(); |
| 44 | m_fileIndexScheduler.startupFinished(); |
| 45 | }); |
| 46 | } |
| 47 | QTimer::singleShot(interval: 0, receiver: &m_fileWatcher, slot: &FileWatch::updateIndexedFoldersWatches); |
| 48 | } |
| 49 | |
| 50 | void MainHub::quit() const |
| 51 | { |
| 52 | QCoreApplication::instance()->quit(); |
| 53 | } |
| 54 | |
| 55 | void MainHub::updateConfig() |
| 56 | { |
| 57 | m_config->forceConfigUpdate(); |
| 58 | m_fileWatcher.updateIndexedFoldersWatches(); |
| 59 | m_fileIndexScheduler.updateConfig(); |
| 60 | } |
| 61 | |
| 62 | #include "moc_mainhub.cpp" |
| 63 | |