Changeset View
Changeset View
Standalone View
Standalone View
Modules/about-distro/src/PlasmaEntry.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (C) 2012-2020 Harald Sitter <sitter@kde.org> | ||||
3 | | ||||
4 | This program is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU General Public License as | ||||
6 | published by the Free Software Foundation; either version 2 of | ||||
7 | the License or (at your option) version 3 or any later version | ||||
8 | accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | defined in Section 14 of version 3 of the license. | ||||
11 | | ||||
12 | This program is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | GNU General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU General Public License | ||||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "PlasmaEntry.h" | ||||
22 | | ||||
23 | #include <QStandardPaths> | ||||
24 | #include <KConfigGroup> | ||||
25 | #include <KDesktopFile> | ||||
26 | | ||||
27 | PlasmaEntry::PlasmaEntry() | ||||
28 | : Entry(ki18n("KDE Plasma Version:"), plasmaVersion()) | ||||
29 | { | ||||
30 | // Since Plasma version detection isn't based on a library query it can fail | ||||
31 | // in weird cases; instead of admitting defeat we simply hide everything :P | ||||
32 | if (value.isEmpty()) { | ||||
33 | return; | ||||
34 | } | ||||
35 | } | ||||
36 | | ||||
37 | QString PlasmaEntry::plasmaVersion() | ||||
38 | { | ||||
39 | const QStringList &filePaths = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, | ||||
40 | QStringLiteral("xsessions/plasma.desktop")); | ||||
41 | | ||||
42 | if (filePaths.length() < 1) { | ||||
43 | return QString(); | ||||
44 | } | ||||
45 | | ||||
46 | // Despite the fact that there can be multiple desktop files we simply take | ||||
47 | // the first one as users usually don't have xsessions/ in their $HOME | ||||
48 | // data location, so the first match should (usually) be the only one and | ||||
49 | // reflect the plasma session run. | ||||
50 | KDesktopFile desktopFile(filePaths.first()); | ||||
51 | return desktopFile.desktopGroup().readEntry("X-KDE-PluginInfo-Version", QString()); | ||||
52 | } |