-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexport.cpp
79 lines (70 loc) · 3.28 KB
/
export.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "export.h"
#include <KConfigGroup>
#include <QRegularExpression>
#include <algorithm>
namespace JetbrainsAPI
{
QList<JetbrainsApplication *> fetchApplications(const KConfigGroup &config, bool filterEmpty, bool fileWatchers)
{
QList<JetbrainsApplication *> appList;
QList<JetbrainsApplication *> automaticAppList;
const QMap<QString, QString> mappingMap = config.isValid() ? config.group(Config::customMappingGroup).entryMap() : QMap<QString, QString>();
const auto desktopPaths = JetbrainsApplication::getInstalledApplicationPaths(config.isValid() ? config.group(Config::customMappingGroup) : config);
std::map<QString, QString> specialEditions;
// This should extract "pycharm" from "jetbrains-pycharm-ce.desktop"
static const QRegularExpression baseNameExpr(QStringLiteral("jetbrains-([a-z]+)(-[a-z])?+"));
for (const QString &path : desktopPaths) {
const QRegularExpressionMatch regexMatch = baseNameExpr.match(path);
if (regexMatch.hasMatch()) {
Q_ASSERT(regexMatch.capturedTexts().length() >= 2);
specialEditions.insert(std::pair<QString, QString>(QFileInfo(path).baseName(), regexMatch.capturedTexts().at(1)));
}
}
// Split manually configured and automatically found apps
for (const QString &path : desktopPaths) {
// Desktop file is manually specified
if (mappingMap.contains(path)) {
auto customMappedApp = new JetbrainsApplication(path, fileWatchers);
if (QFileInfo::exists(mappingMap.value(path))) {
customMappedApp->parseXMLFile(mappingMap.value(path));
// Add path for filewatcher
customMappedApp->addPath(mappingMap.value(path));
if (!filterEmpty || !customMappedApp->recentlyUsed.isEmpty()) {
appList.append(customMappedApp);
}
}
} else {
const QString baseName = QFileInfo(path).baseName();
bool shouldNotTrimEdition = std::any_of(specialEditions.begin(), specialEditions.end(), [baseName](const std::pair<QString, QString> &value) {
return baseName.contains(value.second) && baseName != value.first;
});
automaticAppList.append(new JetbrainsApplication(path, fileWatchers, shouldNotTrimEdition));
}
}
// Find automatically config directory, read config file and filter apps
SettingsDirectory::findCorrespondingDirectories(SettingsDirectory::getSettingsDirectories(), automaticAppList);
JetbrainsApplication::parseXMLFiles(automaticAppList);
if (filterEmpty) {
automaticAppList = JetbrainsApplication::filterApps(automaticAppList);
}
appList.append(automaticAppList);
return appList;
}
QList<JetbrainsApplication *> fetchRawApplications(const KConfigGroup &config)
{
QList<JetbrainsApplication *> appList;
KConfigGroup grp;
if (config.isValid()) {
grp = config.group(Config::customMappingGroup);
}
const auto desktopPaths = JetbrainsApplication::getInstalledApplicationPaths(grp);
for (const auto &p : desktopPaths.toStdMap()) {
appList.append(new JetbrainsApplication(p.second, false));
}
return appList;
}
QList<JetbrainsApplication *> fetchRawApplications()
{
return fetchRawApplications(KConfigGroup());
}
}