trunk 20080912
[gitenigma.git] / src / enigma_mainmenu.cpp
blob6494c56adab49223038c78c1f61ad5b70e1a4e17
1 #include <enigma.h>
2 #include <enigma_main.h>
3 #include <enigma_mainmenu.h>
4 #include <enigma_setup.h>
5 #include <enigma_plugins.h>
6 #include <enigma_info.h>
7 #include <enigma_vcr.h>
8 #include <enigma_lcd.h>
9 #include <timer.h>
11 #include <lib/gui/eskin.h>
12 #include <lib/driver/eavswitch.h>
13 #include <lib/gui/elabel.h>
14 #include <lib/dvb/epgcache.h>
15 #include <lib/dvb/decoder.h>
16 #include <lib/base/i18n.h>
17 #include <lib/gui/guiactions.h>
18 #include <lib/system/init_num.h>
19 #include <lib/system/info.h>
21 struct enigmaMainmenuActions
23 eActionMap map;
24 eAction close, prev, next;
25 enigmaMainmenuActions():
26 map("mainmenu", _("enigma mainmenu")),
27 close(map, "close", _("close the mainmenu"), eAction::prioDialog),
28 prev(map, "prev", _("select previous entry"), eAction::prioDialog),
29 next(map, "next", _("select next entry"), eAction::prioDialog)
34 eAutoInitP0<enigmaMainmenuActions> i_mainmenuActions(eAutoInitNumbers::actions, "enigma mainmenu actions");
37 void eMainMenu::setActive(int i)
39 int count = MENU_ENTRIES;
40 if (!eSystemInfo::getInstance()->hasScartSwitch())
41 --count;
42 for (int a=0; a<7; a++)
44 int c=(i+a+count-3)%count;
45 if (a != 3)
46 label[a]->setPixmap(pixmaps[c][0]); // unselected
47 else
48 label[a]->setPixmap(pixmaps[c][1]); // selected
51 switch (i)
53 case 0:
54 description->setText(eString("(1) ") + eString(_("TV mode")));
55 break;
56 case 1:
57 description->setText(eString("(2) ") + eString(_("Radio mode")));
58 break;
59 #ifndef DISABLE_FILE
60 case 2:
61 description->setText(eString("(3) ") + eString(_("File mode")));
62 break;
63 case 3:
64 description->setText(eString("(4) ") + eString(_("Information")));
65 break;
66 case 4:
67 description->setText(eString("(5) ") + eString(_("Shutdown")));
68 break;
69 case 5:
70 description->setText(eString("(6) ") + eString(_("Setup")));
71 break;
72 case 6:
73 description->setText(eString("(7) ") + eString(_("Games")));
74 break;
75 case 7:
76 description->setText(eString("(8) ") + eString(_("Timer")));
77 break;
78 case 8:
79 description->setText(eString("(9) ") + eString(_("VCR")));
80 break;
81 #else
82 case 2:
83 description->setText(eString("(3) ") + eString(_("Information")));
84 break;
85 case 3:
86 description->setText(eString("(4) ") + eString(_("Setup")));
87 break;
88 case 4:
89 description->setText(eString("(5) ") + eString(_("Timer")));
90 break;
91 case 5:
92 description->setText(eString("(6) ") + eString(_("VCR")));
93 break;
94 #endif
96 #ifndef DISABLE_LCD
97 if (LCDTitle)
98 LCDTitle->setText(_("Mainmenu"));
99 if (LCDElement)
100 LCDElement->setText( description->getText() );
101 #endif
104 eMainMenu::eMainMenu()
105 : eWidget(0, 1),
106 wnd(_("Mainmenu"),
107 #ifndef DISABLE_FILE
108 eSystemInfo::getInstance()->hasScartSwitch()?11:10,
109 #else
110 eSystemInfo::getInstance()->hasScartSwitch()?8:7,
111 #endif
112 350),
113 wndShowTimer(eApp)
115 simpleMainmenu=0;
116 eConfig::getInstance()->getKey("/ezap/osd/simpleMainMenu", simpleMainmenu);
118 if ( !simpleMainmenu )
120 addActionMap(&i_mainmenuActions->map);
121 addActionMap(&i_cursorActions->map);
122 addActionMap(&i_shortcutActions->map);
123 eLabel *background=new eLabel(this);
124 background->setName("background");
126 label[0]=new eLabel(this);
127 label[0]->setName("l3");
128 label[1]=new eLabel(this);
129 label[1]->setName("l2");
130 label[2]=new eLabel(this);
131 label[2]->setName("l1");
132 label[3]=new eLabel(this);
133 label[3]->setName("m");
134 label[4]=new eLabel(this);
135 label[4]->setName("r1");
136 label[5]=new eLabel(this);
137 label[5]->setName("r2");
138 label[6]=new eLabel(this);
139 label[6]->setName("r3");
141 description=new eLabel(this);
142 description->setName("description");
144 if (eSkin::getActive()->build(this, "eZapMainMenu"))
145 eFatal("unable to load main menu");
147 char *pixmap_name[]={
148 "tv",
149 "radio",
150 #ifndef DISABLE_FILE
151 "file",
152 #endif
153 "info",
154 #ifndef DISABLE_FILE
155 "shutdown",
156 #endif
157 "setup",
158 #ifndef DISABLE_FILE
159 "games",
160 #endif
161 "timer",
162 "scart"
165 int count = MENU_ENTRIES;
166 if (!eSystemInfo::getInstance()->hasScartSwitch())
167 --count;
168 for (int i=0; i<count; i++)
170 pixmaps[i][0]=eSkin::getActive()->queryImage(eString("mainmenu.") + eString(pixmap_name[i]) );
171 pixmaps[i][1]=eSkin::getActive()->queryImage(eString("mainmenu.") + eString(pixmap_name[i]) + ".sel" );
172 if (!pixmaps[i][0])
173 eFatal("error, mainmenu bug, mainmenu.%s not defined", pixmap_name[i]);
174 if (!pixmaps[i][1])
175 eFatal("error, mainmenu bug, mainmenu.%s.sel not defined", pixmap_name[i]);
176 pixmaps[i][0]->uncompressdata();
177 pixmaps[i][1]->uncompressdata();
180 setActive(active=eZapMain::getInstance()->getMode());
182 else
184 CONNECT(wndShowTimer.timeout, eMainMenu::showWindow);
185 wnd.cmove(ePoint(180, 115));
186 int entry=0;
187 int count = MENU_ENTRIES;
188 for (int i=0; i<count; i++)
190 pixmaps[i][0]=NULL;
191 pixmaps[i][1]=NULL;
193 CONNECT((new eListBoxEntryMenu(wnd.getList(), _("TV mode"), eString().sprintf("(%d) %s", ++entry, _("TV mode")) ))->selected, eMainMenu::sel_tv);
194 CONNECT((new eListBoxEntryMenu(wnd.getList(), _("Radio mode"), eString().sprintf("(%d) %s", ++entry, _("Radio mode")) ))->selected, eMainMenu::sel_radio);
195 #ifndef DISABLE_FILE
196 CONNECT((new eListBoxEntryMenu(wnd.getList(), _("File mode"), eString().sprintf("(%d) %s", ++entry, _("File mode")) ))->selected, eMainMenu::sel_file);
197 if ( eSystemInfo::getInstance()->hasScartSwitch() )
198 CONNECT((new eListBoxEntryMenu(wnd.getList(), _("VCR"), eString().sprintf("(%d) %s", ++entry, _("VCR")) ))->selected, eMainMenu::sel_vcr);
199 new eListBoxEntryMenuSeparator(wnd.getList(), eSkin::getActive()->queryImage("listbox.separator"), 0, true );
200 CONNECT((new eListBoxEntryMenu(wnd.getList(), _("Timer"), eString().sprintf("(%d) %s", ++entry, _("Timer")) ))->selected, eMainMenu::sel_timer);
201 CONNECT((new eListBoxEntryMenu(wnd.getList(), _("Setup"), eString().sprintf("(%d) %s", ++entry, _("Setup")) ))->selected, eMainMenu::sel_setup);
202 CONNECT((new eListBoxEntryMenu(wnd.getList(), _("Games"), eString().sprintf("(%d) %s", ++entry, _("Games")) ))->selected, eMainMenu::sel_plugins);
203 CONNECT((new eListBoxEntryMenu(wnd.getList(), _("Information"), eString().sprintf("(%d) %s", ++entry, _("Information")) ))->selected, eMainMenu::sel_info);
204 new eListBoxEntryMenuSeparator(wnd.getList(), eSkin::getActive()->queryImage("listbox.separator"), 0, true );
205 CONNECT((new eListBoxEntryMenu(wnd.getList(), _("Shutdown"), eString().sprintf("(%d) %s", ++entry, _("Shutdown")) ))->selected, eMainMenu::sel_quit);
206 #else
207 if ( eSystemInfo::getInstance()->hasScartSwitch() )
208 CONNECT((new eListBoxEntryMenu(wnd.getList(), _("VCR"), eString().sprintf("(%d) %s", ++entry, _("VCR")) ))->selected, eMainMenu::sel_vcr);
209 new eListBoxEntryMenuSeparator(wnd.getList(), eSkin::getActive()->queryImage("listbox.separator"), 0, true );
210 CONNECT((new eListBoxEntryMenu(wnd.getList(), _("Timer"), eString().sprintf("(%d) %s", ++entry, _("Timer")) ))->selected, eMainMenu::sel_timer);
211 CONNECT((new eListBoxEntryMenu(wnd.getList(), _("Setup"), eString().sprintf("(%d) %s", ++entry, _("Setup")) ))->selected, eMainMenu::sel_setup);
212 new eListBoxEntryMenuSeparator(wnd.getList(), eSkin::getActive()->queryImage("listbox.separator"), 0, true );
213 CONNECT((new eListBoxEntryMenu(wnd.getList(), _("Information"), eString().sprintf("(%d) %s", ++entry, _("Information")) ))->selected, eMainMenu::sel_info);
214 #endif
216 setHelpID(10);
218 eMainMenu::~eMainMenu()
220 simpleMainmenu=0;
221 eConfig::getInstance()->getKey("/ezap/osd/simpleMainMenu", simpleMainmenu);
223 if ( !simpleMainmenu )
225 int count = MENU_ENTRIES;
226 if (!eSystemInfo::getInstance()->hasScartSwitch())
227 --count;
228 for (int i=0; i<count; i++)
230 if (pixmaps[i][0])
231 pixmaps[i][0]->compressdata();
232 if (pixmaps[i][1])
233 pixmaps[i][1]->compressdata();
237 #ifndef DISABLE_LCD
238 void eMainMenu::setLCD( eWidget *LCDTitle, eWidget *LCDElement )
240 eWidget::setLCD(LCDTitle, LCDElement);
241 wnd.setLCD(LCDTitle,LCDElement);
243 #endif
245 void eMainMenu::sel_tv()
247 eZapMain::getInstance()->setMode(eZapMain::modeTV, 1);
248 if (!simpleMainmenu)
249 close(0);
250 else
251 wnd.close(0);
254 void eMainMenu::sel_radio()
256 eZapMain::getInstance()->setMode(eZapMain::modeRadio, 1);
257 if (!simpleMainmenu)
258 close(0);
259 else
260 wnd.close(0);
263 #ifndef DISABLE_FILE
264 void eMainMenu::sel_file()
266 eZapMain::getInstance()->setMode(eZapMain::modeFile, 1);
267 if (!simpleMainmenu)
268 close(0);
269 else
270 wnd.close(0);
272 #endif
274 void eMainMenu::sel_vcr()
276 hide();
277 eZapMain::getInstance()->toggleScart(1);
278 show();
281 void eMainMenu::sel_info()
283 eZapInfo info;
284 #ifndef DISABLE_LCD
285 info.setLCD(LCDTitle, LCDElement);
286 #endif
287 hide();
288 info.show();
289 info.exec();
290 info.hide();
291 show();
294 extern bool checkPin( int, const char* );
296 void eMainMenu::sel_setup()
298 int setuppin=0;
299 eConfig::getInstance()->getKey("/elitedvb/pins/setuplock", setuppin);
301 if ( checkPin( setuppin, _("setup") ) )
303 hide();
304 int i=0;
307 eZapSetup setup;
308 #ifndef DISABLE_LCD
309 setup.setLCD(LCDTitle, LCDElement);
310 #endif
311 setup.show();
312 i=setup.exec();
313 setup.hide();
315 while(i==-1); // to redisplay Setup after language change
316 if ( !simpleMainmenu )
317 setActive(active); // --"--
318 show();
322 void eMainMenu::sel_plugins()
324 #ifndef DISABLE_LCD
325 eZapPlugins plugins(eZapPlugins::GamePlugin, LCDTitle, LCDElement);
326 #else
327 eZapPlugins plugins(eZapPlugins::GamePlugin);
328 #endif
329 hide();
330 plugins.exec();
331 show();
334 void eMainMenu::sel_timer()
336 hide();
337 eTimerListView setup;
338 #ifndef DISABLE_LCD
339 setup.setLCD(LCDTitle, LCDElement);
340 #endif
341 setup.show();
342 setup.exec();
343 setup.hide();
344 show();
347 void eMainMenu::sel_quit()
349 if (!simpleMainmenu)
350 close(1);
351 else
352 wnd.close(1);
355 int eMainMenu::eventHandler(const eWidgetEvent &event)
357 int num=-1;
358 if ( !simpleMainmenu )
360 switch (event.type)
362 case eWidgetEvent::willShow:
363 #ifndef DISABLE_LCD
364 if (LCDTitle)
365 LCDTitle->setText(_("Mainmenu"));
366 if (LCDElement)
367 LCDElement->setText( description->getText() );
368 #endif
369 break;
370 case eWidgetEvent::evtAction:
372 int count = MENU_ENTRIES;
373 if (!eSystemInfo::getInstance()->hasScartSwitch())
374 --count;
375 if (event.action == &i_mainmenuActions->close)
376 close(0);
377 else if (event.action == &i_mainmenuActions->prev)
379 active+=count-1;
380 active%=count;
381 setActive(active);
383 else if (event.action == &i_mainmenuActions->next)
385 active++;
386 active%=count;
387 setActive(active);
389 else if (event.action == &i_cursorActions->ok)
390 selected(active);
391 else if (event.action == &i_cursorActions->cancel)
392 close(0);
393 else if (event.action == &i_shortcutActions->number0)
394 num=9;
395 else if (event.action == &i_shortcutActions->number1)
396 num=0;
397 else if (event.action == &i_shortcutActions->number2)
398 num=1;
399 else if (event.action == &i_shortcutActions->number3)
400 num=2;
401 else if (event.action == &i_shortcutActions->number4)
402 num=3;
403 else if (event.action == &i_shortcutActions->number5)
404 num=4;
405 else if (event.action == &i_shortcutActions->number6)
406 num=5;
407 else if (event.action == &i_shortcutActions->number7)
408 num=6;
409 else if (event.action == &i_shortcutActions->number8)
410 num=7;
411 else if (event.action == &i_shortcutActions->number9)
412 num=8;
413 else
414 break;
415 if (num != -1)
417 if (num < count)
419 setActive(active=num);
420 selected(num);
423 return 1;
425 default:
426 break;
429 else
431 switch (event.type)
433 case eWidgetEvent::willShow:
434 wnd.show();
435 break;
436 case eWidgetEvent::willHide:
437 wnd.hide();
438 break;
439 case eWidgetEvent::execBegin:
440 wndShowTimer.start(0,true);
441 return 1;
442 default:
443 break;
446 return eWidget::eventHandler(event);
449 void eMainMenu::selected(int i)
451 switch (active)
453 case 0:
454 sel_tv();
455 break;
456 case 1:
457 sel_radio();
458 break;
459 #ifndef DISABLE_FILE
460 case 2:
461 sel_file();
462 break;
463 case 3:
464 sel_info();
465 break;
466 case 4:
467 sel_quit();
468 break;
469 case 5:
470 sel_setup();
471 break;
472 case 6:
473 sel_plugins();
474 break;
475 case 7:
476 sel_timer();
477 break;
478 case 8:
479 sel_vcr();
480 break;
481 #else
482 case 2:
483 sel_info();
484 break;
485 case 3:
486 sel_setup();
487 break;
488 case 4:
489 sel_timer();
490 break;
491 case 5:
492 sel_vcr();
493 break;
494 #endif
498 void eMainMenu::showWindow()
500 close(wnd.exec());
503 void eMainMenu::eraseBackground(gPainter *, const eRect &where)