-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplications.cpp
49 lines (41 loc) · 1.16 KB
/
applications.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
#include "applications.h"
Applications::Applications()
{
}
void Applications::loadFromJson(QString &path)
{
settingsPath = path;
QFile file(path);
if (!file.open(QIODevice::ReadOnly))
{
qDebug() << file.errorString();
}
QTextStream input(&file);
QJsonObject jsonObject = QJsonDocument::fromJson(input.readAll().toUtf8()).object();
QJsonArray jsonArray = jsonObject.value("apps").toArray();
foreach (const QJsonValue &v, jsonArray)
{
appList << v.toObject().value("name").toString();
appHashTable.insert(v.toObject().value("name").toString(), v.toObject().value("path").toString());
}
}
bool Applications::contains(QString name)
{
return appHashTable.contains(name);
}
bool Applications::getPathByName(QString &path, QString name)
{
if (!this->contains(name))
return false;
path = appHashTable.value(name);
return true;
}
bool Applications::launch(QString name)
{
if (!this->contains(name))
return false;
QString exePath = appHashTable.value(name);
qDebug() << "Launching " + name + " - " + exePath;
QProcess::startDetached(exePath, QStringList());
return true;
}