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