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
163
164
165
166
167
168
169
170
171
172
|
/*
* See the README file for copyright information and how to reach the author.
*
* This code is directly taken from VDR with some changes by me to work with this plugin
*/
#include <vdr/menu.h>
#include <vdr/config.h>
#include <vdr/interface.h>
#include "mymenucommands.h"
#if VDRVERSNUM > 10713
myMenuCommands::myMenuCommands(const char *_Title,cList<cNestedItem> *_Commands,const char *Parameters):cOsdMenu(_Title)
#else
myMenuCommands::myMenuCommands(const char *_Title,cCommands *_Commands, const char *Parameters):cOsdMenu(_Title)
#endif
{
SetHasHotkeys();
commands=_Commands;
#if VDRVERSNUM > 10713
result=NULL;
parameters=Parameters;
for(cNestedItem *Command=commands->First();Command;Command=commands->Next(Command)) {
const char *s=Command->Text();
if(Command->SubItems())
Add(new cOsdItem(hk(cString::sprintf("%s...", s))));
else if(Parse(s))
Add(new cOsdItem(hk(title)));
}
#else
parameters=Parameters?strdup(Parameters):NULL;
for(cCommand *command=commands->First();command;command=commands->Next(command))
Add(new cOsdItem(hk(command->Title())));
#endif
}
myMenuCommands::~myMenuCommands()
{
#if VDRVERSNUM > 10713
free(result);
#else
free(parameters);
#endif
}
#if VDRVERSNUM > 10713
bool myMenuCommands::Parse(const char *s)
{
const char *p=strchr(s,':');
if(p) {
int l=p-s;
if(l>0) {
char t[l+1];
stripspace(strn0cpy(t,s,l+1));
l=strlen(t);
if(l>1&&t[l-1]=='?') {
t[l-1]=0;
confirm=true;
}
else
confirm=false;
title=t;
command=skipspace(p+1);
return true;
}
}
return false;
}
#endif
#if VDRVERSNUM > 10713
eOSState myMenuCommands::Execute()
{
cNestedItem *Command=commands->Get(Current());
if(Command) {
if(Command->SubItems())
return AddSubMenu(new myMenuCommands(Title(),Command->SubItems(),parameters));
if(Parse(Command->Text())) {
if(!confirm||Interface->Confirm(cString::sprintf("%s?",*title))) {
Skins.Message(mtStatus,cString::sprintf("%s...",*title));
free(result);
result=NULL;
cString cmdbuf;
if(!isempty(parameters))
cmdbuf=cString::sprintf("%s %s",*command,*parameters);
const char *cmd=*cmdbuf?*cmdbuf:*command;
dsyslog("executing command '%s'",cmd);
cPipe p;
if(p.Open(cmd,"r")) {
int l=0;
int c;
while((c=fgetc(p))!=EOF) {
if(l%20==0)
result=(char *)realloc(result,l+21);
result[l++]=char(c);
}
if(result)
result[l]=0;
p.Close();
}
else
esyslog("ERROR: can't open pipe for command '%s'",cmd);
Skins.Message(mtStatus,NULL);
if(result)
return AddSubMenu(new cMenuText(title,result,fontFix));
return osEnd;
}
}
}
return osContinue;
}
#else
eOSState myMenuCommands::Execute()
{
cCommand *command=commands->Get(Current());
if(command)
{
char *buffer=NULL;
bool confirmed=false;
#ifdef CMDSUBMENUVERSNUM
if (command->hasChilds())
{
AddSubMenu(new myMenuCommands(command->Title(), command->getChilds(), parameters));
return osContinue;
}
#endif
if(command->Confirm())
{
if(asprintf(&buffer,"%s?",command->Title())!=-1)
{
confirmed=Interface->Confirm(buffer);
free(buffer);
}
} else {
confirmed=true;
}
if(confirmed)
{
if(asprintf(&buffer, "%s...",command->Title())!=-1)
{
Skins.Message(mtStatus,buffer);
free(buffer);
}
const char *Result=command->Execute(parameters);
Skins.Message(mtStatus,NULL);
if(Result)
return AddSubMenu(new cMenuText(command->Title(),Result,fontFix));
return osEnd;
}
}
return osContinue;
}
#endif
eOSState myMenuCommands::ProcessKey(eKeys Key)
{
eOSState state=cOsdMenu::ProcessKey(Key);
if(state==osUnknown)
{
switch(Key)
{
case kRed:
case kGreen:
case kYellow:
case kBlue: return osContinue;
case kOk: return Execute();
default: break;
}
}
return state;
}
|