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
23#include <KAboutData>
24
25int main(int argc, char** argv)
26{
27 lowerIOPriority();
28 lowerSchedulingPriority();
29 lowerPriority();
30
31 QCoreApplication app(argc, argv);
32
33 Baloo::FileIndexerConfig indexerConfig;
34 if (!indexerConfig.indexingEnabled()) {
35 std::cout << "Baloo File Indexing has been disabled" << std::endl;
36 return 0;
37 }
38
39 if (!QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.baloo"))) {
40 qWarning() << "Failed to register via dbus. Another instance is running";
41 return 1;
42 }
43
44 KAboutData aboutData(QStringLiteral("baloo_file"), QString(), QLatin1String(PROJECT_VERSION));
46
47 // Crash Handling
50
51 const QString path = Baloo::fileIndexDbPath();
52
53 Baloo::Migrator migrator(path, &indexerConfig);
54 if (migrator.migrationRequired()) {
55 migrator.migrate();
56 }
57
58 bool firstRun = !QFile::exists(path + QStringLiteral("/index"));
59
60 Baloo::Database *db = Baloo::globalDatabaseInstance();
61
62 /**
63 * try to open, if that fails, try to unlink the index db and retry
64 */
65 if (!db->open(Baloo::Database::CreateDatabase)) {
66 // delete old stuff, set to initial run!
67 qWarning() << "Failed to create database, removing corrupted database.";
68 QFile::remove(path + QStringLiteral("/index"));
69 QFile::remove(path + QStringLiteral("/index-lock"));
70 firstRun = true;
71
72 // try to create now after cleanup, if still no works => fail
73 if (!db->open(Baloo::Database::CreateDatabase)) {
74 qWarning() << "Failed to create database after deleting corrupted one.";
75 return 1;
76 }
77 }
78
79 Baloo::MainHub hub(db, &indexerConfig, firstRun);
80 return app.exec();
81}
Active config class which emits signals if the config was changed, for example if the KCM saved the c...
static void setApplicationData(const KAboutData &aboutData)
KCRASH_EXPORT void setFlags(KCrash::CrashFlags flags)
KCRASH_EXPORT void initialize()
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 Oct 25 2024 11:52:07 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.