File indexing completed on 2024-04-21 03:51:45
0001 /* 0002 SPDX-FileCopyrightText: 2015 Vishesh Handa <vhanda@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #include "mainhub.h" 0008 #include "fileindexerconfig.h" 0009 0010 #include <QDBusConnection> 0011 #include <QCoreApplication> 0012 #include <QTimer> 0013 0014 using namespace Baloo; 0015 0016 MainHub::MainHub(Database* db, FileIndexerConfig* config, bool firstRun) 0017 : m_db(db) 0018 , m_config(config) 0019 , m_fileWatcher(db, config, this) 0020 , m_fileIndexScheduler(db, config, firstRun, this) 0021 { 0022 Q_ASSERT(db); 0023 Q_ASSERT(config); 0024 0025 connect(&m_fileWatcher, &FileWatch::indexNewFile, &m_fileIndexScheduler, &FileIndexScheduler::indexNewFile); 0026 connect(&m_fileWatcher, &FileWatch::indexModifiedFile, &m_fileIndexScheduler, &FileIndexScheduler::indexModifiedFile); 0027 connect(&m_fileWatcher, &FileWatch::indexXAttr, &m_fileIndexScheduler, &FileIndexScheduler::indexXAttrFile); 0028 connect(&m_fileWatcher, &FileWatch::fileRemoved, &m_fileIndexScheduler, &FileIndexScheduler::handleFileRemoved); 0029 0030 connect(&m_fileWatcher, &FileWatch::installedWatches, &m_fileIndexScheduler, &FileIndexScheduler::scheduleIndexing); 0031 0032 QDBusConnection bus = QDBusConnection::sessionBus(); 0033 bus.registerObject(QStringLiteral("/"), this, QDBusConnection::ExportAllSlots | 0034 QDBusConnection::ExportScriptableSignals | QDBusConnection::ExportAdaptors); 0035 0036 if (firstRun) { 0037 QTimer::singleShot(5000, this, [this] { 0038 m_fileIndexScheduler.startupFinished(); 0039 }); 0040 } else { 0041 // Delay these checks so we don't end up consuming excessive resources on login 0042 QTimer::singleShot(5000, this, [this] { 0043 m_fileIndexScheduler.checkUnindexedFiles(); 0044 m_fileIndexScheduler.checkStaleIndexEntries(); 0045 m_fileIndexScheduler.startupFinished(); 0046 }); 0047 } 0048 QTimer::singleShot(0, &m_fileWatcher, &FileWatch::updateIndexedFoldersWatches); 0049 } 0050 0051 void MainHub::quit() const 0052 { 0053 QCoreApplication::instance()->quit(); 0054 } 0055 0056 void MainHub::updateConfig() 0057 { 0058 m_config->forceConfigUpdate(); 0059 m_fileWatcher.updateIndexedFoldersWatches(); 0060 m_fileIndexScheduler.updateConfig(); 0061 } 0062 0063 #include "moc_mainhub.cpp"