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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
#include <libxml++/libxml++.h>
#include <vdr/plugin.h>
#include "menunode.h"
#include "vdrmenuitem.h"
#include "submenuitem.h"
#include "pluginmenuitem.h"
#include "xmlmenu.h"
#include <iostream>
using namespace xmlpp;
using namespace std;
void XmlMenu::loadXmlMenu()
{
// TODO: show how vdr handels the path vars (developer doc)
// and change code for dynamic path vars
const char *File = "/var/lib/vdr/plugins/vdr-menu.xml";
try
{
DomParser parser;
//TODO: patch the xmlfile with the xsd definition for validate the schema
//parser.set_validate();
parser.set_substitute_entities(); //We just want the text to be resolved/unescaped automatically.
parser.parse_file(File);
if(parser)
{
//Walk the tree:
MenuCount=0;
const Node* pNode = parser.get_document()->get_root_node(); //deleted by DomParser.
parseNode(pNode,0,0,0);
}
}
catch(const std::exception& ex)
{
//TODO: print output to syslog (isyslog or dsyslog?)
cout << "Exception caught: " << ex.what() << endl;
//TODO: display message on osd
}
}
void XmlMenu::parseNode(const Node* a_node, unsigned int Parent, unsigned int ItemIndex, unsigned int MenuIndex)
{
const ContentNode* nodeContent = dynamic_cast<const ContentNode*>(a_node);
const TextNode* nodeText = dynamic_cast<const TextNode*>(a_node);
const CommentNode* nodeComment = dynamic_cast<const CommentNode*>(a_node);
/****
MenuNode* subMenu1 =_rootMenuNode.AddChild(new SubMenuItem("Custom menu 1"));
subMenu1->AddChild(new VdrMenuItem(tr("Schedule"), osSchedule));
subMenu1->AddChild(new VdrMenuItem(tr("Channels"), osChannels));
MenuNode* subMenu1_1 = subMenu1->AddChild(new SubMenuItem("Custom menu 1.1"));
subMenu1_1->AddChild(new VdrMenuItem(tr("Timers"), osTimers));
subMenu1_1->AddChild(new VdrMenuItem(tr("Recordings"), osRecordings));
MenuNode* subMenu2 =_rootMenuNode.AddChild(new SubMenuItem("Custom menu 2"));
subMenu2->AddChild(new PluginMenuItem(item, i));
****/
Glib::ustring nodename = a_node->get_name();
if(!nodeText && !nodeComment && !nodename.empty()) //Let's not say "name: text".
{
/*
for(unsigned int i=0;i<=Parent;i++)
{
printf(" ");
}*/
if (nodename == "menus")
{
//cout << Parent << "-" << MainMenuIndex << "-" << myMenuNr << "-ROOT" << endl;
isyslog("ROOT Node passed");
}
else if (nodename == "system")
{
if (const Element* nodeElement = dynamic_cast<const Element*>(a_node))
{
const Element::AttributeList& attributes = nodeElement->get_attributes();
for(xmlpp::Element::AttributeList::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter)
{
const Attribute* attribute = *iter;
//cout << Parent << "-" << MainMenuIndex << "-" << myMenuNr << "-SystemItem=" << attribute->get_value() << endl;
isyslog("%d-%d-%d-SystemItem=%s",Parent,ItemIndex,MenuIndex,attribute->get_value().data());
eOSState ItemeOSState = geteOSState(attribute->get_value());
if ((ItemeOSState == osCommands && Commands.Count()) || ItemeOSState != osCommands)
{
if(MenuIndex > 0)
{
isyslog(" - add to _subMenu[%d]",MenuIndex);
_subMenu[MenuIndex]->AddChild(new VdrMenuItem(tr(attribute->get_value().data()), geteOSState(attribute->get_value())));
}
else
{
isyslog(" - add to _rootMenuNode");
_rootMenuNode.AddChild(new VdrMenuItem(tr(attribute->get_value().data()), geteOSState(attribute->get_value())));
}
}
}
}
}
else if (nodename == "menu")
{
if (const Element* nodeElement = dynamic_cast<const Element*>(a_node))
{
const Element::AttributeList& attributes = nodeElement->get_attributes();
for(xmlpp::Element::AttributeList::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter)
{
const Attribute* attribute = *iter;
//cout << Parent << "-" << MainMenuIndex << "-" << myMenuNr << "-MenuItem=" << attribute->get_value() << endl;
isyslog("%d-%d-%d-MenuItem=%s",Parent,ItemIndex,MenuIndex,attribute->get_value().data());
if(MenuIndex > 0)
{
isyslog(" - add to _subMenu[%d]",MenuIndex);
_subMenu[MenuIndex+1] = _subMenu[MenuIndex]->AddChild(new SubMenuItem(attribute->get_value().data()));
}
else
{
isyslog(" - add to _rootMenuNode");
_subMenu[MenuIndex+1] = _rootMenuNode.AddChild(new SubMenuItem(attribute->get_value().data()));
}
MenuCount++;
}
}
}
else if (nodename == "plugin")
{
if (const Element* nodeElement = dynamic_cast<const Element*>(a_node))
{
const Element::AttributeList& attributes = nodeElement->get_attributes();
for(xmlpp::Element::AttributeList::const_iterator iter = attributes.begin(); iter != attributes.end(); ++iter)
{
const Attribute* attribute = *iter;
//cout << Parent << "-" << MainMenuIndex << "-" << myMenuNr << "-PluginItem=" << attribute->get_value() << endl;
isyslog("%d-%d-%d-PluginItem=%s",Parent,ItemIndex,MenuIndex,attribute->get_value().data());
PluginItemAndIndex *myPlugin = getPlugin(attribute->get_value());
if (myPlugin->index >= 0)
{
if(MenuIndex > 0)
{
isyslog(" - add to _subMenu[%d]",MenuIndex);
_subMenu[MenuIndex]->AddChild(new PluginMenuItem(myPlugin->item, myPlugin->index));
}
else
{
isyslog(" - add to _rootMenuNode");
_rootMenuNode.AddChild(new PluginMenuItem(myPlugin->item, myPlugin->index));
}
}
}
}
}
}
if(!nodeContent)
{
int ItemIndex=0;
int myMenuIndex=MenuCount;
//Recurse through child nodes:
Node::NodeList list = a_node->get_children();
for(Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
{
const Node* b_node = dynamic_cast<const Node*>(*iter);
const ContentNode* tmpnodeContent = dynamic_cast<const ContentNode*>(b_node);
const TextNode* tmpnodeText = dynamic_cast<const TextNode*>(b_node);
const CommentNode* tmpnodeComment = dynamic_cast<const CommentNode*>(b_node);
Glib::ustring subNodename = b_node->get_name();
if(!tmpnodeText && !tmpnodeComment && !subNodename.empty() && !nodeContent)
{
parseNode(*iter, Parent+1, ItemIndex, myMenuIndex); //recursive
ItemIndex++;
}
}
}
}
/*
enum eOSState { osUnknown,
osContinue,
osSchedule,
osChannels,
osTimers,
osRecordings,
osPlugin,
osSetup,
osCommands,
osPause,
osRecord,
osReplay,
osStopRecord,
osStopReplay,
osCancelEdit,
osSwitchDvb,
osBack,
osEnd,
os_User, // the following values can be used locally
osUser1,
osUser2,
osUser3,
osUser4,
osUser5,
osUser6,
osUser7,
osUser8,
osUser9,
osUser10,
};
*/
eOSState XmlMenu::geteOSState(const Glib::ustring& name)
{
if(name == "Continue")
{
return osContinue;
}
else if (name == "Schedule")
{
return osSchedule;
}
else if (name == "Channels")
{
return osChannels;
}
else if (name == "Timers")
{
return osTimers;
}
else if (name == "Recordings")
{
return osRecordings;
}
else if (name == "Plugin")
{
return osPlugin;
}
else if (name == "Setup")
{
return osSetup;
}
else if (name == "Pause")
{
return osPause;
}
else if (name == "Record")
{
return osRecord;
}
else if (name == "Replay")
{
return osReplay;
}
else if (name == "CancelEdit")
{
return osCancelEdit;
}
else if (name == "SwitchDvb")
{
return osSwitchDvb;
}
else if (name == "Back")
{
return osBack;
}
else if (name == "End")
{
return osEnd;
}
else if (name == "User")
{
return os_User;
}
else if (name == "Commands")
{
return osCommands;
}
else
return osContinue;
}
PluginItemAndIndex* XmlMenu::getPlugin(const Glib::ustring& name)
{
PluginItemAndIndex* returnVar;
returnVar->index = -1;
int i=0;
while (cPlugin *p = cPluginManager::GetPlugin(i))
{
if (const char *item = p->MainMenuEntry())
{
if (name == (const Glib::ustring) p->Name())
{
returnVar->item = item;
returnVar->index = i;
break;
}
}
i++;
}
return returnVar;
}
|