-
Notifications
You must be signed in to change notification settings - Fork 342
/
frontend.cpp
162 lines (138 loc) · 4.7 KB
/
frontend.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include <QCoreApplication>
#include <QKeyEvent>
#include "mythcorecontext.h"
#include "keybindings.h"
#include "mythlogging.h"
#include "mythevent.h"
#include "mythuistatetracker.h"
#include "mythmainwindow.h"
#include "tv_actions.h"
#include "frontend.h"
#define LOC QString("Frontend API: ")
QStringList Frontend::gActionList = QStringList();
QHash<QString,QStringList> Frontend::gActionDescriptions = QHash<QString,QStringList>();
DTC::FrontendStatus* Frontend::GetStatus(void)
{
DTC::FrontendStatus *status = new DTC::FrontendStatus();
MythUIStateTracker::GetFreshState(status->State());
status->Process();
return status;
}
bool Frontend::SendMessage(const QString &Message)
{
if (Message.isEmpty())
return false;
qApp->postEvent(GetMythMainWindow(),
new MythEvent(MythEvent::MythUserMessage, Message));
return true;
}
bool Frontend::SendAction(const QString &Action, const QString &Value,
uint Width, uint Height)
{
if (!IsValidAction(Action))
return false;
static const QStringList value_actions =
QStringList() << ACTION_HANDLEMEDIA << ACTION_SETVOLUME <<
ACTION_SETAUDIOSYNC << ACTION_SETBRIGHTNESS <<
ACTION_SETCONTRAST << ACTION_SETCOLOUR <<
ACTION_SETHUE << ACTION_JUMPCHAPTER <<
ACTION_SWITCHTITLE << ACTION_SWITCHANGLE <<
ACTION_SEEKABSOLUTE;
if (!Value.isEmpty() && value_actions.contains(Action))
{
MythEvent* me = new MythEvent(Action, QStringList(Value));
qApp->postEvent(GetMythMainWindow(), me);
return true;
}
if (ACTION_SCREENSHOT == Action)
{
if (!Width || !Height)
{
LOG(VB_GENERAL, LOG_ERR, LOC + "Invalid screenshot parameters.");
return false;
}
QStringList args;
args << QString::number(Width) << QString::number(Height);
MythEvent* me = new MythEvent(Action, args);
qApp->postEvent(GetMythMainWindow(), me);
return true;
}
QKeyEvent* ke = new QKeyEvent(QEvent::KeyPress, 0, Qt::NoModifier, Action);
qApp->postEvent(GetMythMainWindow(), (QEvent*)ke);
return true;
}
QStringList Frontend::GetContextList(void)
{
InitialiseActions();
return gActionDescriptions.keys();
}
DTC::FrontendActionList* Frontend::GetActionList(const QString &Context)
{
DTC::FrontendActionList *list = new DTC::FrontendActionList();
InitialiseActions();
QHashIterator<QString,QStringList> contexts(gActionDescriptions);
while (contexts.hasNext())
{
contexts.next();
if (!Context.isEmpty() && contexts.key() != Context)
continue;
// TODO can we keep the context data with QMap<QString, QStringList>?
QStringList actions = contexts.value();
foreach (QString action, actions)
{
QStringList split = action.split(",");
if (split.size() == 2)
list->ActionList().insert(split[0], split[1]);
}
}
return list;
}
bool Frontend::IsValidAction(const QString &Action)
{
InitialiseActions();
if (gActionList.contains(Action))
return true;
// TODO There must be a better way to do this
if (Action.startsWith("SELECTSUBTITLE_") ||
Action.startsWith("SELECTTTC_") ||
Action.startsWith("SELECTCC608_") ||
Action.startsWith("SELECTCC708_") ||
Action.startsWith("SELECTRAWTEXT_") ||
Action.startsWith("SELECTAUDIO_"))
{
return true;
}
LOG(VB_GENERAL, LOG_ERR, LOC + QString("Action '%1'' is invalid.")
.arg(Action));
return false;
}
void Frontend::InitialiseActions(void)
{
static bool initialised = false;
if (initialised)
return;
initialised = true;
KeyBindings *bindings = new KeyBindings(gCoreContext->GetHostName());
if (bindings)
{
QStringList contexts = bindings->GetContexts();
contexts.sort();
foreach (QString context, contexts)
{
gActionDescriptions[context] = QStringList();
QStringList ctx_actions = bindings->GetActions(context);
ctx_actions.sort();
gActionList += ctx_actions;
foreach (QString actions, ctx_actions)
{
QString desc = actions + "," +
bindings->GetActionDescription(context, actions);
gActionDescriptions[context].append(desc);
}
}
}
gActionList.removeDuplicates();
gActionList.sort();
foreach (QString actions, gActionList)
LOG(VB_GENERAL, LOG_DEBUG, LOC + QString("Action: %1").arg(actions));
}