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
|
#include "menu.h"
#include "dynamicdevice.h"
class cDynamiteMenuDevicelist : public cOsdMenu
{
public:
cVector<int> deviceIds;
cStringList devicePaths;
cDynamiteMenuDevicelist(const char *Title)
:cOsdMenu(Title)
{
cDynamicDevice *d;
const char *cp;
char *p;
for (int i = 0; i < cDynamicDevice::NumDynamicDevices(); i++) {
d = cDynamicDevice::GetDynamicDevice(i);
if (d == NULL)
continue;
cp = d->GetDevPath();
if ((cp == NULL) || (strlen(cp) == 0))
continue;
p = strdup(cp);
if (p == NULL)
continue;
deviceIds.Append(i);
devicePaths.Append(p);
cString text = cString::sprintf("%d%s %s", i + 1, (d->IsDetachable() ? " " : "*"), p);
Add(new cOsdItem(*text));
}
}
};
enum eMenuAction { maList,
maScan,
maDetach,
maLock,
maUnlock,
maSetIdle
};
class cDynamiteMenuItem : public cOsdItem
{
public:
eMenuAction action;
bool showList;
cDynamiteMenuItem(eMenuAction Action, const char *Text, bool ShowList = true)
:cOsdItem(Text)
,action(Action)
,showList(ShowList)
{
}
virtual eOSState Action(int DevId, const char *DevPath)
{
switch (action) {
case maScan:
isyslog("dynamite: menu action: scan for dvb devices");
cDynamicDevice::AttachDevicePattern("/dev/dvb/adapter*/frontend*");
return osEnd;
case maDetach:
isyslog("dynamite: menu action: detach device %s", DevPath);
cDynamicDeviceProbe::QueueDynamicDeviceCommand(ddpcDetach, DevPath);
return osEnd;
case maLock:
case maUnlock:
isyslog("dynamite: menu action: %slock device %s", (action == maUnlock ? "un" : ""), DevPath);
cDynamicDevice::SetLockDevice(DevPath, action == maLock);
break;
case maSetIdle:
isyslog("dynamite: menu action: set idle mode on device %s", DevPath);
cDynamicDevice::SetIdle(DevPath, true);
break;
default:
return osUnknown;
}
return osUnknown;
}
};
cDynamiteMainMenu::cDynamiteMainMenu(void)
{
Add(new cDynamiteMenuItem(maList, tr("list attached devices")));
Add(new cDynamiteMenuItem(maScan, tr("scan for new DVB devices"), false));
Add(new cDynamiteMenuItem(maDetach, tr("detach device")));
Add(new cDynamiteMenuItem(maLock, tr("disable detach of device")));
Add(new cDynamiteMenuItem(maUnlock, tr("enable detach of device")));
Add(new cDynamiteMenuItem(maSetIdle, tr("switch device to idle")));
}
cDynamiteMainMenu::~cDynamiteMainMenu(void)
{
}
void cDynamiteMainMenu::Store(void)
{
}
eOSState cDynamiteMainMenu::ProcessKey(eKeys Key)
{
cDynamiteMenuItem *item = dynamic_cast<cDynamiteMenuItem*>(Get(Current()));
if (item == NULL)
return cOsdMenu::ProcessKey(Key);
eOSState state = osUnknown;
switch (Key) {
case kOk:
{
if (HasSubMenu()) {
cDynamiteMenuDevicelist *dl = dynamic_cast<cDynamiteMenuDevicelist*>(SubMenu());
if (dl != NULL) {
int i = dl->Current();
if ((i >= 0) && (i < dl->deviceIds.Size()))
state = item->Action(dl->deviceIds[i], dl->devicePaths[i]);
}
CloseSubMenu();
}
else {
if (item->showList)
state = AddSubMenu(new cDynamiteMenuDevicelist(item->Text()));
else
state = item->Action(-1, NULL);
}
break;
}
default:
{
state = cOsdMenu::ProcessKey(Key);
break;
}
}
return state;
}
|