diff --git a/autotests/unit/file/filewatchtest.cpp b/autotests/unit/file/filewatchtest.cpp --- a/autotests/unit/file/filewatchtest.cpp +++ b/autotests/unit/file/filewatchtest.cpp @@ -43,7 +43,7 @@ m_tempDir = new QTemporaryDir(); m_db = new Database(m_tempDir->path()); m_db->open(Database::CreateDatabase); - m_dbusInterface = new MainHub(m_db, &m_config); + m_dbusInterface = new MainHub(m_db, &m_config, false); } void testFileCreation(); diff --git a/src/file/fileindexerconfig.h b/src/file/fileindexerconfig.h --- a/src/file/fileindexerconfig.h +++ b/src/file/fileindexerconfig.h @@ -69,12 +69,6 @@ bool onlyBasicIndexing() const; - /** - * \return \c true if the service is run for the first time - * (or after manually setting "first run=true" in the config). - */ - bool isInitialRun() const; - /** * Check if \p folder can be searched. * \p folder can be searched if itself or one of its descendants is indexed. @@ -166,12 +160,6 @@ */ void forceConfigUpdate(); - /** - * Should be called once the initial indexing is done, ie. all folders - * have been indexed. - */ - void setInitialRun(bool isInitialRun); - private: void buildFolderCache(); diff --git a/src/file/fileindexerconfig.cpp b/src/file/fileindexerconfig.cpp --- a/src/file/fileindexerconfig.cpp +++ b/src/file/fileindexerconfig.cpp @@ -26,7 +26,6 @@ #include #include -#include #include "baloosettings.h" namespace @@ -142,13 +141,6 @@ return m_onlyBasicIndexing; } -bool FileIndexerConfig::isInitialRun() const -{ - KConfig config(QStringLiteral("baloofilerc")); - return config.group("General").readEntry("first run", true); -} - - bool FileIndexerConfig::canBeSearched(const QString& folder) const { QFileInfo fi(folder); @@ -370,14 +362,6 @@ m_onlyBasicIndexing = m_settings->onlyBasicIndexing(); } -void FileIndexerConfig::setInitialRun(bool isInitialRun) -{ - // Don't use kcfg, it will break KCM default state - KConfig config(QStringLiteral("baloofilerc")); - config.group("General").writeEntry("first run", isInitialRun); - config.sync(); -} - int FileIndexerConfig::databaseVersion() const { return m_settings->dbVersion(); diff --git a/src/file/fileindexscheduler.h b/src/file/fileindexscheduler.h --- a/src/file/fileindexscheduler.h +++ b/src/file/fileindexscheduler.h @@ -43,7 +43,7 @@ Q_PROPERTY(int state READ state NOTIFY stateChanged) public: - FileIndexScheduler(Database* db, FileIndexerConfig* config, QObject* parent = nullptr); + FileIndexScheduler(Database* db, FileIndexerConfig* config, bool firstRun, QObject* parent = nullptr); ~FileIndexScheduler() override; int state() const { return m_indexerState; } @@ -89,6 +89,7 @@ void scheduleIndexing(); void scheduleCheckUnindexedFiles(); void scheduleCheckStaleIndexEntries(); + void startupFinished(); Q_SCRIPTABLE void suspend() { setSuspend(true); } Q_SCRIPTABLE void resume() { setSuspend(false); } @@ -105,6 +106,7 @@ bool isIndexerIdle() { return m_isGoingIdle || (m_indexerState == Suspended) || + (m_indexerState == Startup) || (m_indexerState == Idle) || (m_indexerState == LowPowerIdle); } @@ -130,6 +132,8 @@ bool m_checkStaleIndexEntries; bool m_isGoingIdle; bool m_isSuspended; + bool m_isFirstRun; + bool m_inStartup; }; } diff --git a/src/file/fileindexscheduler.cpp b/src/file/fileindexscheduler.cpp --- a/src/file/fileindexscheduler.cpp +++ b/src/file/fileindexscheduler.cpp @@ -37,18 +37,20 @@ using namespace Baloo; -FileIndexScheduler::FileIndexScheduler(Database* db, FileIndexerConfig* config, QObject* parent) +FileIndexScheduler::FileIndexScheduler(Database* db, FileIndexerConfig* config, bool firstRun, QObject* parent) : QObject(parent) , m_db(db) , m_config(config) , m_provider(db) , m_contentIndexer(nullptr) - , m_indexerState(Idle) + , m_indexerState(Startup) , m_timeEstimator(config, this) , m_checkUnindexedFiles(false) , m_checkStaleIndexEntries(false) , m_isGoingIdle(false) , m_isSuspended(false) + , m_isFirstRun(firstRun) + , m_inStartup(true) { Q_ASSERT(db); Q_ASSERT(config); @@ -79,6 +81,11 @@ m_threadPool.waitForDone(0); // wait 0 msecs } +void FileIndexScheduler::startupFinished() { + m_inStartup = false; + QTimer::singleShot(0, this, &FileIndexScheduler::scheduleIndexing); +} + void FileIndexScheduler::scheduleIndexing() { if (!isIndexerIdle()) { @@ -94,7 +101,12 @@ return; } - if (m_config->isInitialRun()) { + if (m_isFirstRun) { + if (m_inStartup) { + return; + } + + m_isFirstRun = false; auto runnable = new FirstRunIndexer(m_db, m_config, m_config->includeFolders()); connect(runnable, &FirstRunIndexer::done, this, &FileIndexScheduler::runnerFinished); @@ -146,6 +158,14 @@ return; } + if (m_inStartup) { + if (m_indexerState != Startup) { + m_indexerState = Startup; + Q_EMIT stateChanged(m_indexerState); + } + return; + } + // This has to be above content indexing, because there can be files that // should not be indexed in the DB (i.e. if config was changed) if (m_checkStaleIndexEntries) { diff --git a/src/file/firstrunindexer.cpp b/src/file/firstrunindexer.cpp --- a/src/file/firstrunindexer.cpp +++ b/src/file/firstrunindexer.cpp @@ -41,12 +41,6 @@ void FirstRunIndexer::run() { - Q_ASSERT(m_config->isInitialRun()); - { - Transaction tr(m_db, Transaction::ReadOnly); - Q_ASSERT_X(tr.size() == 0, "FirstRunIndexer", "The database is not empty on first run"); - } - QMimeDatabase mimeDb; BasicIndexingJob::IndexingLevel level = m_config->onlyBasicIndexing() ? BasicIndexingJob::NoLevel : BasicIndexingJob::MarkForContentIndexing; @@ -87,7 +81,5 @@ tr.commit(); } - m_config->setInitialRun(false); - Q_EMIT done(); } diff --git a/src/file/indexerstate.h b/src/file/indexerstate.h --- a/src/file/indexerstate.h +++ b/src/file/indexerstate.h @@ -38,6 +38,7 @@ StaleIndexEntriesClean, LowPowerIdle, Unavailable, + Startup, }; inline QString stateString(IndexerState state) @@ -77,6 +78,9 @@ case Unavailable: status = i18n("Not Running"); break; + case Startup: + status = i18n("Starting"); + break; } return status; } diff --git a/src/file/main.cpp b/src/file/main.cpp --- a/src/file/main.cpp +++ b/src/file/main.cpp @@ -72,9 +72,7 @@ migrator.migrate(); } - if (!QFile::exists(path + "/index")) { - indexerConfig.setInitialRun(true); - } + bool firstRun = !QFile::exists(path + "/index"); // HACK: Until we start using lmdb with robust mutex support. We're just going to remove // the lock manually in the baloo_file process. @@ -90,15 +88,15 @@ qWarning() << "Failed to create database, removing corrupted database."; QFile::remove(path + "/index"); QFile::remove(path + "/index-lock"); - indexerConfig.setInitialRun(true); + firstRun = true; // try to create now after cleanup, if still no works => fail if (!db->open(Baloo::Database::CreateDatabase)) { qWarning() << "Failed to create database after deleting corrupted one."; return 1; } } - Baloo::MainHub hub(db, &indexerConfig); + Baloo::MainHub hub(db, &indexerConfig, firstRun); return app.exec(); } diff --git a/src/file/mainhub.h b/src/file/mainhub.h --- a/src/file/mainhub.h +++ b/src/file/mainhub.h @@ -36,7 +36,7 @@ Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.baloo.main") public: - MainHub(Database* db, FileIndexerConfig* config); + MainHub(Database* db, FileIndexerConfig* config, bool firstRun); public Q_SLOTS: Q_SCRIPTABLE void quit() const; diff --git a/src/file/mainhub.cpp b/src/file/mainhub.cpp --- a/src/file/mainhub.cpp +++ b/src/file/mainhub.cpp @@ -27,11 +27,11 @@ using namespace Baloo; -MainHub::MainHub(Database* db, FileIndexerConfig* config) +MainHub::MainHub(Database* db, FileIndexerConfig* config, bool firstRun) : m_db(db) , m_config(config) , m_fileWatcher(db, config, this) - , m_fileIndexScheduler(db, config, this) + , m_fileIndexScheduler(db, config, firstRun, this) { Q_ASSERT(db); Q_ASSERT(config); @@ -50,11 +50,16 @@ bus.registerObject(QStringLiteral("/"), this, QDBusConnection::ExportAllSlots | QDBusConnection::ExportScriptableSignals | QDBusConnection::ExportAdaptors); - if (!m_config->isInitialRun()) { + if (firstRun) { + QTimer::singleShot(5000, this, [this] { + m_fileIndexScheduler.startupFinished(); + }); + } else { // Delay these checks so we don't end up consuming excessive resources on login QTimer::singleShot(5000, this, [this] { m_fileIndexScheduler.checkUnindexedFiles(); m_fileIndexScheduler.checkStaleIndexEntries(); + m_fileIndexScheduler.startupFinished(); }); } QTimer::singleShot(0, &m_fileWatcher, &FileWatch::watchIndexedFolders); diff --git a/src/file/migrator.cpp b/src/file/migrator.cpp --- a/src/file/migrator.cpp +++ b/src/file/migrator.cpp @@ -60,5 +60,4 @@ } m_config->setDatabaseVersion(s_dbVersion); - m_config->setInitialRun(true); } diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -68,7 +68,7 @@ GROUP_BASE_NAME KF VERSION ${KF5_VERSION} DEPRECATED_BASE_VERSION 0 - DEPRECATION_VERSIONS 5.55 + DEPRECATION_VERSIONS 5.55 5.69 EXCLUDE_DEPRECATED_BEFORE_AND_AT ${EXCLUDE_DEPRECATED_BEFORE_AND_AT} ) diff --git a/src/lib/indexerconfig.h b/src/lib/indexerconfig.h --- a/src/lib/indexerconfig.h +++ b/src/lib/indexerconfig.h @@ -87,12 +87,21 @@ void setExcludeFilters(const QStringList& excludeFilters); void setExcludeMimetypes(const QStringList& excludeMimetypes); +#if BALOO_CORE_BUILD_DEPRECATED_SINCE(5, 69) /** - * \return \c true if the service is run for the first time - * (or after manually setting "first run=true" in the config). + * @deprecated Since 5.69. Do not use this function, firstRun is no longer + * exposed in the config, as it is an internal baloo state. + * \return \c false */ + BALOO_CORE_DEPRECATED_VERSION(5, 69, "Do not use. firstRun is a baloo internal state") bool firstRun() const; + /** + * @deprecated Since 5.69. Do not use this function. Since 5.69, calling + * it no longer has any effect. + */ + BALOO_CORE_DEPRECATED_VERSION(5, 69, "Do not use. firstRun is a baloo internal state") void setFirstRun(bool firstRun) const; +#endif bool indexHidden() const; void setIndexHidden(bool value) const; diff --git a/src/lib/indexerconfig.cpp b/src/lib/indexerconfig.cpp --- a/src/lib/indexerconfig.cpp +++ b/src/lib/indexerconfig.cpp @@ -109,15 +109,16 @@ d->m_settings.setExcludedMimetypes(excludeMimetypes); } +#if BALOO_CORE_BUILD_DEPRECATED_SINCE(5, 69) bool IndexerConfig::firstRun() const { - return d->m_config.isInitialRun(); + return false; } -void IndexerConfig::setFirstRun(bool firstRun) const +void IndexerConfig::setFirstRun(bool) const { - d->m_config.setInitialRun(firstRun); } +#endif bool IndexerConfig::indexHidden() const {