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

source code of baloo/src/file/mainhub.cpp