-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.cpp
62 lines (48 loc) · 1.41 KB
/
actions.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
#include "actions.h"
#include <QDebug>
#include "stations.h"
#include "commands.h"
Actions::Actions()
{
}
QString Actions::loadActions()
{
Utils::ErrorOrValue errorOrvalue = Utils::readJsonToVariant("configuration/stations.json");
m_keyToAction.clear();
if (!errorOrvalue.error.isEmpty())
{
return errorOrvalue.error;
}
QMap<QString, QVariant> actions = errorOrvalue.value.toMap();
for (const QString& key : actions.keys())
{
QMap<QString, QVariant> action = actions.value(key).toMap();
if (action.contains("stream") && action.contains("name"))
{
Stations::Station station;
station.name = action.value("name").toString();
station.stream = action.value("stream").toString();
m_keyToAction.insert(key, QVariant::fromValue(station));
}
else if (action.contains("command"))
{
Commands::Command commandName = Commands::fromString(action.value("command").toString());
QVariant variant;
variant.setValue(commandName);
m_keyToAction.insert(key, variant);
}
else
{
qDebug() << "Warning ignored:" << action;
}
}
return QString();
}
QVariant Actions::action(const QString& key) const
{
return m_keyToAction.value(key);
}
QSet<QString> Actions::numbers() const
{
return m_keyToAction.keys().toSet();
}