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