Changeset View
Changeset View
Standalone View
Standalone View
src/baloo/baloodetector.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2016-2019 Matthieu Gallien <matthieu_gallien@yahoo.fr> | ||||
3 | * | ||||
4 | * This program is free software: you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU Lesser General Public | ||||
6 | * License as published by the Free Software Foundation; either | ||||
7 | * version 3 of the License, or (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | * Lesser General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Lesser General Public License | ||||
15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||||
16 | */ | ||||
17 | | ||||
18 | #include "baloodetector.h" | ||||
19 | | ||||
20 | #include "baloo/baloocommon.h" | ||||
21 | | ||||
22 | #include <Baloo/IndexerConfig> | ||||
23 | | ||||
24 | #include <QDBusConnection> | ||||
25 | #include <QDBusConnectionInterface> | ||||
26 | | ||||
27 | BalooDetector::BalooDetector(QObject *parent) : QObject(parent) | ||||
28 | { | ||||
29 | connect(&mBalooWatcher, &QDBusServiceWatcher::serviceRegistered, | ||||
30 | this, &BalooDetector::serviceRegistered); | ||||
31 | connect(&mBalooWatcher, &QDBusServiceWatcher::serviceUnregistered, | ||||
32 | this, &BalooDetector::serviceUnregistered); | ||||
33 | } | ||||
34 | | ||||
35 | bool BalooDetector::balooAvailability() const | ||||
36 | { | ||||
37 | return mBalooAvailability; | ||||
38 | } | ||||
39 | | ||||
40 | void BalooDetector::checkBalooAvailability() | ||||
41 | { | ||||
42 | bool problemDetected = false; | ||||
43 | | ||||
44 | problemDetected = problemDetected || checkBalooConfiguration(); | ||||
45 | | ||||
46 | mBalooWatcher.setWatchedServices({QStringLiteral("org.kde.baloo")}); | ||||
47 | | ||||
48 | problemDetected = problemDetected || checkBalooServiceIsRunning(); | ||||
49 | | ||||
50 | signalBalooAvailability(problemDetected); | ||||
51 | } | ||||
52 | | ||||
53 | void BalooDetector::serviceRegistered(const QString &service) | ||||
54 | { | ||||
55 | Q_UNUSED(service); | ||||
56 | | ||||
57 | bool problemDetected = false; | ||||
58 | | ||||
59 | problemDetected = problemDetected || checkBalooConfiguration(); | ||||
60 | problemDetected = problemDetected || checkBalooServiceIsRunning(); | ||||
61 | | ||||
62 | signalBalooAvailability(problemDetected); | ||||
63 | } | ||||
64 | | ||||
65 | void BalooDetector::serviceUnregistered(const QString &service) | ||||
66 | { | ||||
67 | Q_UNUSED(service); | ||||
68 | | ||||
69 | if (mBalooAvailability) { | ||||
70 | qCInfo(orgKdeElisaBaloo) << "Baloo service is no longer detected and seems not be running. Disabling Elisa support for using Baloo indexer."; | ||||
71 | | ||||
72 | mBalooAvailability = false; | ||||
73 | Q_EMIT balooAvailabilityChanged(); | ||||
74 | } | ||||
75 | } | ||||
76 | | ||||
77 | bool BalooDetector::checkBalooConfiguration() | ||||
78 | { | ||||
79 | Baloo::IndexerConfig balooConfiguration; | ||||
80 | | ||||
81 | auto problemDetected = !balooConfiguration.fileIndexingEnabled(); | ||||
82 | | ||||
83 | if (problemDetected) { | ||||
84 | qCInfo(orgKdeElisaBaloo) << "Baloo indexer has been configured to be deactivated. Disabling Elisa support for using Baloo indexer."; | ||||
85 | } | ||||
86 | | ||||
87 | return problemDetected; | ||||
88 | } | ||||
89 | | ||||
90 | bool BalooDetector::checkBalooServiceIsRunning() | ||||
91 | { | ||||
92 | auto problemDetected = !QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.baloo")); | ||||
93 | | ||||
94 | if (problemDetected) { | ||||
95 | qCInfo(orgKdeElisaBaloo) << "Baloo service is not detected and seems not be running. Disabling Elisa support for using Baloo indexer."; | ||||
96 | } | ||||
97 | | ||||
98 | return problemDetected; | ||||
99 | } | ||||
100 | | ||||
101 | void BalooDetector::signalBalooAvailability(bool isAvailable) | ||||
102 | { | ||||
103 | if (!isAvailable) { | ||||
104 | if (!mBalooAvailability) { | ||||
105 | mBalooAvailability = true; | ||||
106 | Q_EMIT balooAvailabilityChanged(); | ||||
107 | } | ||||
108 | } else { | ||||
109 | if (mBalooAvailability) { | ||||
110 | mBalooAvailability = false; | ||||
111 | Q_EMIT balooAvailabilityChanged(); | ||||
112 | } | ||||
113 | } | ||||
114 | } | ||||
115 | | ||||
116 | | ||||
117 | #include "moc_baloodetector.cpp" |