Baloo

file/main.cpp
1/*
2 This file is part of the KDE Baloo Project
3 SPDX-FileCopyrightText: 2013-2015 Vishesh Handa <vhanda@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6*/
7
8#include <KCrash>
9
10#include <iostream>
11
12#include "global.h"
13#include "database.h"
14#include "fileindexerconfig.h"
15#include "priority.h"
16#include "migrator.h"
17#include "mainhub.h"
18
19#include <QDBusConnection>
20#include <QCoreApplication>
21#include <QFile>
22
23int main(int argc, char** argv)
24{
25 lowerIOPriority();
26 lowerSchedulingPriority();
27 lowerPriority();
28
29 QCoreApplication app(argc, argv);
30
31 Baloo::FileIndexerConfig indexerConfig;
32 if (!indexerConfig.indexingEnabled()) {
33 std::cout << "Baloo File Indexing has been disabled" << std::endl;
34 return 0;
35 }
36
37 if (!QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.baloo"))) {
38 qWarning() << "Failed to register via dbus. Another instance is running";
39 return 1;
40 }
41
42 // Crash Handling
44
45 const QString path = Baloo::fileIndexDbPath();
46
47 Baloo::Migrator migrator(path, &indexerConfig);
48 if (migrator.migrationRequired()) {
49 migrator.migrate();
50 }
51
52 bool firstRun = !QFile::exists(path + QStringLiteral("/index"));
53
54 Baloo::Database *db = Baloo::globalDatabaseInstance();
55
56 /**
57 * try to open, if that fails, try to unlink the index db and retry
58 */
59 if (!db->open(Baloo::Database::CreateDatabase)) {
60 // delete old stuff, set to initial run!
61 qWarning() << "Failed to create database, removing corrupted database.";
62 QFile::remove(path + QStringLiteral("/index"));
63 QFile::remove(path + QStringLiteral("/index-lock"));
64 firstRun = true;
65
66 // try to create now after cleanup, if still no works => fail
67 if (!db->open(Baloo::Database::CreateDatabase)) {
68 qWarning() << "Failed to create database after deleting corrupted one.";
69 return 1;
70 }
71 }
72
73 Baloo::MainHub hub(db, &indexerConfig, firstRun);
74 return app.exec();
75}
Active config class which emits signals if the config was changed, for example if the KCM saved the c...
KCRASH_EXPORT void setFlags(KCrash::CrashFlags flags)
QString path(const QString &relativePath)
QDBusConnection sessionBus()
bool exists() const const
bool remove()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 12 2024 12:03:48 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.