]> git.vomp.tv Git - vompclient.git/blob - vopts.cc
Extended recordings menu, including artwork from tvscraper
[vompclient.git] / vopts.cc
1 /*
2     Copyright 2007 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #include "vopts.h"
22
23 #include "colour.h"
24 #include "video.h"
25 #include "osd.h"
26 #include "audio.h"
27 #include "remote.h"
28 #include "boxstack.h"
29 #include "woptionpane.h"
30 #include "wremoteconfig.h"
31 #include "log.h"
32 #include "option.h"
33 #include "vdr.h"
34 #include "command.h"
35
36 #ifdef VOMP_PLATTFORM_MVP
37 #include "mediaoptions.h"
38 #endif
39 //#include "vdr.h"
40 //#include "command.h"
41
42 VOpts::VOpts()
43 {
44   setTitleBarOn(1);
45   setTitleBarColour(DrawStyle::TITLEBARBACKGROUND);
46   setTitleText(tr("Options"));
47
48
49   setSize(520, 360);
50   createBuffer();
51   if (Video::getInstance()->getFormat() == Video::PAL)
52     setPosition(100, 110);
53   else
54     setPosition(90, 90);
55   
56   tabbar.setPosition(6, 32);
57   tabbar.setSize(getWidth() - 12, getHeight() - 34);
58   add(&tabbar);
59   
60   Option* option;
61   WOptionPane* wop;
62   
63   //  --- edit options start here
64   
65   static const char* options1[] = {"Old", "New"};
66
67   static const char* options5[] = {"Chop sides", "Letterbox"};
68   static const char* options6[] = {"On", "Off", "Last state"};
69   static const char* options7[] = {"All", "FTA only"};
70   static const char* options15[] = {"Alphabetical", "Chronological"};
71
72   static const char* options13[] = {"Auto","1024", "2048", "4096", "8192", "16384", "32768", "65536"};
73   static const char* options14[] = {"No", "Yes"};
74   static const char* options18[] = {"Off", "On"};
75 #ifdef ADVANCED_MENUES
76   static const char* options19[] = { "Advanced","Classic"};
77 #endif
78   // Get list of languages from VDR and construct options table
79   LangCode = VDR::getInstance()->getLanguageList();
80   options2 = new const char*[LangCode.size()];
81   options2keys = new const char*[LangCode.size()];
82   I18n::lang_code_list::const_iterator iter;
83   UINT LangNumber = 0;
84   for (iter = LangCode.begin(); iter != LangCode.end(); ++iter,++LangNumber)
85   {
86     options2[LangNumber] = iter->second.c_str();
87     options2keys[LangNumber] = iter->first.c_str();
88   }
89
90   numPanes = 4;
91   panes = new Boxx*[numPanes];
92
93   wop = new WOptionPane();
94   tabbar.addTab(tr("General"), wop);
95   panes[0] = wop;
96 #ifdef MVP_REMOTE_TYPES
97   option = new Option(1, "Remote control type",      "General", "Remote type",           Option::TYPE_TEXT, 2, 0, 0, options1);
98   options.push_back(option);
99   wop->addOptionLine(option);
100 #endif
101   option = new Option(2, "Language",                 "General", "LangCode",              Option::TYPE_KEYED_TEXT, LangCode.size(), 0, 0, options2, options2keys);
102   options.push_back(option);
103   wop->addOptionLine(option);
104
105   UINT suppconn = Video::getInstance()->getSupportedFormats();
106   if (suppconn) {
107           int defaultch = 0;
108           if (suppconn & Video::COMPOSITERGB) {
109                   defaultch = 0;
110                   options3.push_back("RGB+composite");
111                   options3keys.push_back("RGB+composite");
112           }
113           if (Video::SVIDEO & suppconn) {
114                   options3.push_back("S-Video");
115                   options3keys.push_back("S-Video");
116           }
117           if (Video::HDMI & suppconn) {
118                   defaultch = options3.size();
119                   options3.push_back("HDMI");
120                   options3keys.push_back("HDMI");
121           }
122           if (Video::HDMI3D & suppconn) {
123                   options3.push_back("HDMI3D");
124                   options3keys.push_back("HDMI3D");
125           }
126           option = new Option(3, "TV connection type", "TV", "Connection",
127                           Option::TYPE_KEYED_TEXT, options3.size(), defaultch, 0,
128                           &(options3[0]), &(options3keys[0]));
129
130           options.push_back(option);
131           wop->addOptionLine(option);
132   }
133
134   UINT suppformats = Video::getInstance()->supportedTVFormats();
135   if (suppformats) {
136           int defaultch = 0;
137           options16.push_back("NTSC");
138           options16keys.push_back("NTSC");
139           if (suppformats & Video::PAL) {
140                   defaultch = 1;
141                   options16.push_back("PAL");
142                   options16keys.push_back("PAL");
143           }
144           if (Video::NTSC_J & suppformats) {
145                   options16.push_back("NTSC-J");
146                   options16keys.push_back("NTSC-J");
147           }
148           if (Video::PAL_M & suppformats) {
149                   options16.push_back("PAL-M");
150                   options16keys.push_back("PAL-M");
151           }
152
153           option = new Option(16, "TV standard (needs restart)", "General", "Override Video Format",
154                           Option::TYPE_KEYED_TEXT, options16.size(), defaultch, 0,
155                           &(options16[0]), &(options16keys[0]));
156
157           options.push_back(option);
158           wop->addOptionLine(option);
159   }
160
161   UINT supptvsize=Video::getInstance()->supportedTVsize();
162   if (supptvsize) {
163           int defaultch=0;
164           options4.push_back("4:3");
165           options4keys.push_back("4:3");
166       if (Video::ASPECT16X9 & supptvsize) {
167           options4.push_back("16:9");
168           options4keys.push_back("16:9");
169 //        defaultch=1;
170       }
171       if (Video::ASPECT14X9 & supptvsize) {
172           options4.push_back("14:9");
173           options4keys.push_back("14:9");
174       }
175           option = new Option(4, "TV aspect ratio", "TV", "Aspect",
176                                 Option::TYPE_KEYED_TEXT, options4.size(), defaultch, 0,
177                                 &(options4[0]), &(options4keys[0]));
178           options.push_back(option);
179           wop->addOptionLine(option);
180   }
181
182   option = new Option(5, "16:9 on 4:3 display mode", "TV",      "Widemode",              Option::TYPE_TEXT, 2, 0, 0, options5);
183   options.push_back(option);
184   wop->addOptionLine(option);
185   option = new Option(6, "Power state after bootup", "General", "Power After Boot",      Option::TYPE_TEXT, 3, 0, 0, options6);
186   options.push_back(option);
187   wop->addOptionLine(option);
188   option = new Option(7, "Display channels",         "General", "Channels",              Option::TYPE_TEXT, 2, 0, 0, options7);
189   options.push_back(option);
190   wop->addOptionLine(option);
191   option = new Option(15, "Recordings sort order",   "General", "Recordings Sort Order", Option::TYPE_TEXT, 2, 0, 0, options15);
192   options.push_back(option);
193   wop->addOptionLine(option);
194   option = new Option(18, "Automatic VDR shutdown",  "General", "VDR shutdown",          Option::TYPE_TEXT, 2, 0, 0, options18);
195   options.push_back(option);
196   wop->addOptionLine(option);
197
198   Remote::getInstance()->addOptionsToPanes(0,&options,wop);
199   Video::getInstance()->addOptionsToPanes(0,&options,wop);
200   Audio::getInstance()->addOptionsToPanes(0,&options,wop);
201
202     
203 /*  WRemoteConfig* wrc = new WRemoteConfig();
204   tabbar.addTab(tr("Remote Control"), wrc);*/
205   Remote::getInstance()->addOptionPagesToWTB(&tabbar);
206  // panes[1] = wrc;
207
208   Video::getInstance()->addOptionPagesToWTB(&tabbar);
209   Audio::getInstance()->addOptionPagesToWTB(&tabbar);
210 #ifdef VOMP_PLATTFORM_MVP
211   MediaOptions::getInstance()->addOptionPagesToWTB(&tabbar);
212 #endif
213
214
215   wop = new WOptionPane(); 
216   tabbar.addTab(tr("Timers"), wop);
217   panes[1] = wop;
218   
219   option = new Option(9, "Default start margin (minutes)",  "Timers", "Start margin",  Option::TYPE_INT, 20, 5, 0, NULL);
220   options.push_back(option);
221   wop->addOptionLine(option);
222   option = new Option(10, "Default end margin (minutes)",   "Timers", "End margin",    Option::TYPE_INT, 20, 5, 0, NULL);
223   options.push_back(option);
224   wop->addOptionLine(option);
225   option = new Option(11, "Default priority",               "Timers", "Priority",      Option::TYPE_INT, 100, 99, 0, NULL);
226   options.push_back(option);
227   wop->addOptionLine(option);
228   option = new Option(12, "Default lifetime",               "Timers", "Lifetime",      Option::TYPE_INT, 100, 99, 0, NULL);
229   options.push_back(option);
230   wop->addOptionLine(option);
231
232   Remote::getInstance()->addOptionsToPanes(1,&options,wop);
233   Video::getInstance()->addOptionsToPanes(1,&options,wop);
234   Audio::getInstance()->addOptionsToPanes(1,&options,wop);
235
236     
237   wop = new WOptionPane(); 
238   tabbar.addTab(tr("Advanced"), wop);
239   panes[2] = wop;
240   
241   option = new Option(8, "VDR-Pri 0=OK !See forums!",  "General",  "Live priority",      Option::TYPE_INT,  199, -1, -99, NULL);
242   options.push_back(option);
243   wop->addOptionLine(option);
244   option = new Option(13, "TCP receive window size",   "Advanced", "TCP receive window", Option::TYPE_TEXT, 8, /*1*/DEFAULT_TCP_WINDOWSIZENR, 0, options13);
245   options.push_back(option);
246   wop->addOptionLine(option);
247 #ifdef PAL_WSS
248   option = new Option(14, "Use WSS (PAL only)",        "General",  "WSS",                Option::TYPE_TEXT, 2, 0, 0, options14);
249   options.push_back(option);
250   wop->addOptionLine(option);
251 #endif
252   const char * * fontnames;
253   const char * * fontnames_keys;
254   int numfonts=Osd::getInstance()->getFontNames(&fontnames,&fontnames_keys);
255   if (numfonts) {
256           option = new Option(17, "Font Name",   "Advanced", "Font Name",  Option::TYPE_KEYED_TEXT, numfonts, 1, 0, fontnames,fontnames_keys);
257           options.push_back(option);
258           wop->addOptionLine(option);
259   }
260
261 #ifdef ADVANCED_MENUES
262   option = new Option(19, "Advanced Menu", "General", "Menu type",Option::TYPE_TEXT, 2, 0, 0, options19);
263   options.push_back(option);
264   wop->addOptionLine(option);
265 #endif
266
267   Remote::getInstance()->addOptionsToPanes(2,&options,wop);
268   Video::getInstance()->addOptionsToPanes(2,&options,wop);
269   Audio::getInstance()->addOptionsToPanes(2,&options,wop);
270 }
271
272 VOpts::~VOpts()
273 {
274  // for (int i = 0; i < numPanes; i++) delete panes[i]; //Move to TabBar, Marten
275   delete[] panes;
276
277   for(vector<Option*>::iterator j = options.begin(); j != options.end(); j++) delete *j;
278   delete[] options2;
279   delete[] options2keys;
280 }
281
282 int VOpts::handleCommand(int command)
283 {
284   // either is active, handle back
285   if (command == Remote::BACK)
286   {
287     doSave();
288     return 4;
289   }
290   else
291   {
292     int retval = tabbar.handleCommand(command);
293     if (retval == 1)
294     {
295       BoxStack::getInstance()->update(this);
296       return 2;
297     }
298     else if (retval == 2)
299     {
300       // command was taken and actively ignored
301       return 2;
302     }
303     else
304     {
305       return 1; // ???
306     }
307   }
308 }
309
310 void VOpts::doSave()
311 {
312   VDR* vdr = VDR::getInstance();
313
314   Remote::getInstance()->saveOptionstoServer(); //Remote
315   Video::getInstance()->saveOptionstoServer(); //Video
316   Audio::getInstance()->saveOptionstoServer(); //Remote
317 #ifdef VOMP_PLATTFORM_MVP
318   MediaOptions::getInstance()->saveOptionstoServer(); //Media
319 #endif
320
321   // Damn, and the dynamic idea was going *so* well...
322   //Whats about a check with typeid operator?
323   WOptionPane* wop;
324   wop = (WOptionPane*)panes[0];
325   wop->saveOpts();  
326   wop = (WOptionPane*)panes[1];
327   wop->saveOpts();  
328   wop = (WOptionPane*)panes[2];
329   wop->saveOpts();  
330
331
332   for (UINT i = 0; i < options.size(); i++)
333   {
334     if (options[i]->configChoice == options[i]->userSetChoice) continue; // no change
335
336     Log::getInstance()->log("Options", Log::DEBUG, "Option %i has changed", i);
337
338     // Save to vdr
339
340     if (options[i]->optionType == Option::TYPE_TEXT)
341     {
342       vdr->configSave(options[i]->configSection, options[i]->configKey, options[i]->options[options[i]->userSetChoice]);
343     }
344     else if (options[i]->optionType == Option::TYPE_KEYED_TEXT)
345     {
346       vdr->configSave(options[i]->configSection, options[i]->configKey, options[i]->optionkeys[options[i]->userSetChoice]);
347     }
348     else
349     {
350       char buffer[20];
351       sprintf(buffer, "%i", options[i]->userSetChoice);
352       vdr->configSave(options[i]->configSection, options[i]->configKey, buffer);
353     }
354     
355     // Set new setting
356     if (options[i]->opthandler == NULL) //Ok, noone else is handling this, we are doing it
357     {
358       switch(options[i]->id)
359       {
360         case 1:
361         {
362 #ifdef MVP_REMOTE_TYPES
363           if (options[i]->userSetChoice == 1)
364           {
365             Log::getInstance()->log("Options", Log::DEBUG, "Setting New Remote");
366             Remote::getInstance()->setRemoteType(Remote::NEWREMOTE);
367           }
368           else
369           {
370             Log::getInstance()->log("Options", Log::DEBUG, "Setting Old Remote");
371             Remote::getInstance()->setRemoteType(Remote::OLDREMOTE);
372           }
373 #endif
374           break;
375         }
376         case 2:
377         {
378           Message* m = new Message();
379           m->message = Message::CHANGE_LANGUAGE;
380           m->to = Command::getInstance();
381           Command::getInstance()->postMessageNoLock(m);
382           break;
383         }
384         case 3:
385         {
386                 if (STRCASECMP(options[i]->optionkeys[options[i]->userSetChoice], "RGB+composite")==0)
387                 {
388                         Log::getInstance()->log("Options", Log::DEBUG, "Setting RGB/Composite");
389                         Video::getInstance()->setConnection(Video::COMPOSITERGB);
390                 }
391                 else  if (STRCASECMP(options[i]->optionkeys[options[i]->userSetChoice], "S-Video")==0)
392                 {
393                         Log::getInstance()->log("Options", Log::DEBUG, "Setting S-Video");
394                         Video::getInstance()->setConnection(Video::SVIDEO);
395                 }
396                 else  if (STRCASECMP(options[i]->optionkeys[options[i]->userSetChoice], "HDMI")==0)
397                 {
398                         Log::getInstance()->log("Options", Log::DEBUG, "Setting HDMI");
399                         Video::getInstance()->setConnection(Video::HDMI);
400                 }
401                 else  if (STRCASECMP(options[i]->optionkeys[options[i]->userSetChoice], "HDMI3D")==0)
402                 {
403                         Log::getInstance()->log("Options", Log::DEBUG, "Setting HDMI");
404                         Video::getInstance()->setConnection(Video::HDMI3D);
405                 }
406                 break;
407         }
408         case 4:
409         {
410           if (STRCASECMP(options[i]->optionkeys[options[i]->userSetChoice], "16:9")==0)
411           {
412             Log::getInstance()->log("Options", Log::DEBUG, "Setting 16:9 TV");
413             Video::getInstance()->setTVsize(Video::ASPECT16X9);
414           }
415           else  if (STRCASECMP(options[i]->optionkeys[options[i]->userSetChoice], "4:3")==0)
416           {
417             Log::getInstance()->log("Options", Log::DEBUG, "Setting 4:3 TV");
418             Video::getInstance()->setTVsize(Video::ASPECT4X3);
419           }
420           else  if (STRCASECMP(options[i]->optionkeys[options[i]->userSetChoice], "14:9")==0)
421           {
422                   Log::getInstance()->log("Options", Log::DEBUG, "Setting 14:9 TV");
423                   Video::getInstance()->setTVsize(Video::ASPECT14X9);
424           }
425           break;
426         }
427         case 5:
428         {
429           if (options[i]->userSetChoice == 1)
430           {
431             Log::getInstance()->log("Options", Log::DEBUG, "Setting letterbox");
432             Video::getInstance()->setMode(Video::LETTERBOX);
433           }
434           else
435           {
436             Log::getInstance()->log("Options", Log::DEBUG, "Setting chop-sides");
437             Video::getInstance()->setMode(Video::NORMAL);
438           }
439           break;
440         }
441         case 13:
442         {
443           size_t newTCPsize = 2048;
444           if (options[i]->userSetChoice == 0) newTCPsize = 0; //zero means auto
445           else if (options[i]->userSetChoice == 1) newTCPsize = 1024;
446           else if (options[i]->userSetChoice == 2) newTCPsize = 2048;
447           else if (options[i]->userSetChoice == 3) newTCPsize = 4096;
448           else if (options[i]->userSetChoice == 4) newTCPsize = 8192;
449           else if (options[i]->userSetChoice == 5) newTCPsize = 16384;
450           else if (options[i]->userSetChoice == 6) newTCPsize = 32768;
451           else if (options[i]->userSetChoice == 7) newTCPsize = 65536;
452           Log::getInstance()->log("Options", Log::DEBUG, "Setting TCP window size %i", newTCPsize);
453           VDR::getInstance()->setReceiveWindow(newTCPsize);
454           break;
455         }
456         case 17:
457         {
458           Osd::getInstance()->setFont(options[i]->optionkeys[options[i]->userSetChoice]);
459           break;
460         }
461         case 18:
462         {
463           if (options[i]->userSetChoice == 1)
464           {
465             Log::getInstance()->log("Options", Log::DEBUG, "Setting automatic vdr shutdown");
466             VDR::getInstance()->setVDRShutdown(true);
467           }
468           else
469           {
470             Log::getInstance()->log("Options", Log::DEBUG, "Setting local shutdown");
471             VDR::getInstance()->setVDRShutdown(false);
472           }
473           break;
474         }
475         case 19:
476         {
477                 if (options[i]->userSetChoice == 1)
478                 {
479                         Log::getInstance()->log("Options", Log::DEBUG, "Setting classic menu");
480                         Command::getInstance()->setAdvMenues(false);
481                 }
482                 else
483                 {
484                         Log::getInstance()->log("Options", Log::DEBUG, "Setting advanced menu");
485                         Command::getInstance()->setAdvMenues(true);
486                 }
487                 break;
488         }
489       }
490     }
491     else
492     {
493       options[i]->opthandler->handleOptionChanges(options[i]);
494     }
495   }
496 }
497
498 void VOpts::processMessage(Message* m)
499 {
500   if (m->message == Message::MOUSE_MOVE)
501   {
502     int x=(m->parameter>>16)-getScreenX();
503     int y=(m->parameter&0xFFFF)-getScreenY();
504     if (tabbar.mouseMove(x,y))
505     {
506       BoxStack::getInstance()->update(this);
507     }
508     
509   }
510   else if (m->message == Message::MOUSE_LBDOWN)
511   {
512     int x=(m->parameter>>16)-getScreenX();
513     int y=(m->parameter&0xFFFF)-getScreenY();
514     if (tabbar.mouseLBDOWN(x,y)) 
515     {
516       BoxStack::getInstance()->update(this);
517     } 
518     else if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
519     {
520       BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
521     }
522   }
523 }
524