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