]> git.vomp.tv Git - vompclient.git/blob - vopts.cc
Screenshot support for vector based osd on raspberry pi
[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   int numskins=SkinFactory::getNumberofSkins();
262    if (numskins>1) {
263           option = new Option(20, "Skin Name (needs restart)",   "Advanced", "Skin Name",  Option::TYPE_KEYED_TEXT, numskins, 0, 0,
264                                   SkinFactory::getSkinNames(),SkinFactory::getSkinNames());
265           options.push_back(option);
266           wop->addOptionLine(option);
267    }
268
269 #ifdef ADVANCED_MENUES
270   option = new Option(19, "Advanced Menu", "General", "Menu type",Option::TYPE_TEXT, 2, 0, 0, options19);
271   options.push_back(option);
272   wop->addOptionLine(option);
273 #endif
274
275   Remote::getInstance()->addOptionsToPanes(2,&options,wop);
276   Video::getInstance()->addOptionsToPanes(2,&options,wop);
277   Audio::getInstance()->addOptionsToPanes(2,&options,wop);
278 }
279
280 VOpts::~VOpts()
281 {
282  // for (int i = 0; i < numPanes; i++) delete panes[i]; //Move to TabBar, Marten
283   delete[] panes;
284
285   for(vector<Option*>::iterator j = options.begin(); j != options.end(); j++) delete *j;
286   delete[] options2;
287   delete[] options2keys;
288 }
289
290 int VOpts::handleCommand(int command)
291 {
292   // either is active, handle back
293   if (command == Remote::BACK)
294   {
295     doSave();
296     return 4;
297   }
298   else
299   {
300     int retval = tabbar.handleCommand(command);
301     if (retval == 1)
302     {
303       BoxStack::getInstance()->update(this);
304       return 2;
305     }
306     else if (retval == 2)
307     {
308       // command was taken and actively ignored
309       return 2;
310     }
311     else
312     {
313       return 1; // ???
314     }
315   }
316 }
317
318 void VOpts::doSave()
319 {
320   VDR* vdr = VDR::getInstance();
321
322   Remote::getInstance()->saveOptionstoServer(); //Remote
323   Video::getInstance()->saveOptionstoServer(); //Video
324   Audio::getInstance()->saveOptionstoServer(); //Remote
325 #ifdef VOMP_PLATTFORM_MVP
326   MediaOptions::getInstance()->saveOptionstoServer(); //Media
327 #endif
328
329   // Damn, and the dynamic idea was going *so* well...
330   //Whats about a check with typeid operator?
331   WOptionPane* wop;
332   wop = (WOptionPane*)panes[0];
333   wop->saveOpts();  
334   wop = (WOptionPane*)panes[1];
335   wop->saveOpts();  
336   wop = (WOptionPane*)panes[2];
337   wop->saveOpts();  
338
339
340   for (UINT i = 0; i < options.size(); i++)
341   {
342     if (options[i]->configChoice == options[i]->userSetChoice) continue; // no change
343
344     Log::getInstance()->log("Options", Log::DEBUG, "Option %i has changed", i);
345
346     // Save to vdr
347
348     if (options[i]->optionType == Option::TYPE_TEXT)
349     {
350       vdr->configSave(options[i]->configSection, options[i]->configKey, options[i]->options[options[i]->userSetChoice]);
351     }
352     else if (options[i]->optionType == Option::TYPE_KEYED_TEXT)
353     {
354       vdr->configSave(options[i]->configSection, options[i]->configKey, options[i]->optionkeys[options[i]->userSetChoice]);
355     }
356     else
357     {
358       char buffer[20];
359       sprintf(buffer, "%i", options[i]->userSetChoice);
360       vdr->configSave(options[i]->configSection, options[i]->configKey, buffer);
361     }
362     
363     // Set new setting
364     if (options[i]->opthandler == NULL) //Ok, noone else is handling this, we are doing it
365     {
366       switch(options[i]->id)
367       {
368         case 1:
369         {
370 #ifdef MVP_REMOTE_TYPES
371           if (options[i]->userSetChoice == 1)
372           {
373             Log::getInstance()->log("Options", Log::DEBUG, "Setting New Remote");
374             Remote::getInstance()->setRemoteType(Remote::NEWREMOTE);
375           }
376           else
377           {
378             Log::getInstance()->log("Options", Log::DEBUG, "Setting Old Remote");
379             Remote::getInstance()->setRemoteType(Remote::OLDREMOTE);
380           }
381 #endif
382           break;
383         }
384         case 2:
385         {
386           Message* m = new Message();
387           m->message = Message::CHANGE_LANGUAGE;
388           m->to = Command::getInstance();
389           Command::getInstance()->postMessageNoLock(m);
390           break;
391         }
392         case 3:
393         {
394                 if (STRCASECMP(options[i]->optionkeys[options[i]->userSetChoice], "RGB+composite")==0)
395                 {
396                         Log::getInstance()->log("Options", Log::DEBUG, "Setting RGB/Composite");
397                         Video::getInstance()->setConnection(Video::COMPOSITERGB);
398                 }
399                 else  if (STRCASECMP(options[i]->optionkeys[options[i]->userSetChoice], "S-Video")==0)
400                 {
401                         Log::getInstance()->log("Options", Log::DEBUG, "Setting S-Video");
402                         Video::getInstance()->setConnection(Video::SVIDEO);
403                 }
404                 else  if (STRCASECMP(options[i]->optionkeys[options[i]->userSetChoice], "HDMI")==0)
405                 {
406                         Log::getInstance()->log("Options", Log::DEBUG, "Setting HDMI");
407                         Video::getInstance()->setConnection(Video::HDMI);
408                 }
409                 else  if (STRCASECMP(options[i]->optionkeys[options[i]->userSetChoice], "HDMI3D")==0)
410                 {
411                         Log::getInstance()->log("Options", Log::DEBUG, "Setting HDMI");
412                         Video::getInstance()->setConnection(Video::HDMI3D);
413                 }
414                 break;
415         }
416         case 4:
417         {
418           if (STRCASECMP(options[i]->optionkeys[options[i]->userSetChoice], "16:9")==0)
419           {
420             Log::getInstance()->log("Options", Log::DEBUG, "Setting 16:9 TV");
421             Video::getInstance()->setTVsize(Video::ASPECT16X9);
422           }
423           else  if (STRCASECMP(options[i]->optionkeys[options[i]->userSetChoice], "4:3")==0)
424           {
425             Log::getInstance()->log("Options", Log::DEBUG, "Setting 4:3 TV");
426             Video::getInstance()->setTVsize(Video::ASPECT4X3);
427           }
428           else  if (STRCASECMP(options[i]->optionkeys[options[i]->userSetChoice], "14:9")==0)
429           {
430                   Log::getInstance()->log("Options", Log::DEBUG, "Setting 14:9 TV");
431                   Video::getInstance()->setTVsize(Video::ASPECT14X9);
432           }
433           break;
434         }
435         case 5:
436         {
437           if (options[i]->userSetChoice == 1)
438           {
439             Log::getInstance()->log("Options", Log::DEBUG, "Setting letterbox");
440             Video::getInstance()->setMode(Video::LETTERBOX);
441           }
442           else
443           {
444             Log::getInstance()->log("Options", Log::DEBUG, "Setting chop-sides");
445             Video::getInstance()->setMode(Video::NORMAL);
446           }
447           break;
448         }
449         case 13:
450         {
451           size_t newTCPsize = 2048;
452           if (options[i]->userSetChoice == 0) newTCPsize = 0; //zero means auto
453           else if (options[i]->userSetChoice == 1) newTCPsize = 1024;
454           else if (options[i]->userSetChoice == 2) newTCPsize = 2048;
455           else if (options[i]->userSetChoice == 3) newTCPsize = 4096;
456           else if (options[i]->userSetChoice == 4) newTCPsize = 8192;
457           else if (options[i]->userSetChoice == 5) newTCPsize = 16384;
458           else if (options[i]->userSetChoice == 6) newTCPsize = 32768;
459           else if (options[i]->userSetChoice == 7) newTCPsize = 65536;
460           Log::getInstance()->log("Options", Log::DEBUG, "Setting TCP window size %i", newTCPsize);
461           VDR::getInstance()->setReceiveWindow(newTCPsize);
462           break;
463         }
464         case 17:
465         {
466           Osd::getInstance()->setFont(options[i]->optionkeys[options[i]->userSetChoice]);
467           break;
468         }
469         case 18:
470         {
471           if (options[i]->userSetChoice == 1)
472           {
473             Log::getInstance()->log("Options", Log::DEBUG, "Setting automatic vdr shutdown");
474             VDR::getInstance()->setVDRShutdown(true);
475           }
476           else
477           {
478             Log::getInstance()->log("Options", Log::DEBUG, "Setting local shutdown");
479             VDR::getInstance()->setVDRShutdown(false);
480           }
481           break;
482         }
483         case 19:
484         {
485                 if (options[i]->userSetChoice == 1)
486                 {
487                         Log::getInstance()->log("Options", Log::DEBUG, "Setting classic menu");
488                         Command::getInstance()->setAdvMenues(false);
489                 }
490                 else
491                 {
492                         Log::getInstance()->log("Options", Log::DEBUG, "Setting advanced menu");
493                         Command::getInstance()->setAdvMenues(true);
494                 }
495                 break;
496         }
497         case 20:
498         {
499                 SkinFactory::InitSkin(options[i]->userSetChoice);
500                 Log::getInstance()->log("Options", Log::DEBUG, "Init Skin %d",options[i]->userSetChoice);
501                 break;
502         }
503       }
504     }
505     else
506     {
507       options[i]->opthandler->handleOptionChanges(options[i]);
508     }
509   }
510 }
511
512 void VOpts::processMessage(Message* m)
513 {
514   if (m->message == Message::MOUSE_MOVE)
515   {
516     int x=(m->parameter>>16)-getScreenX();
517     int y=(m->parameter&0xFFFF)-getScreenY();
518     if (tabbar.mouseMove(x,y))
519     {
520       BoxStack::getInstance()->update(this);
521     }
522     
523   }
524   else if (m->message == Message::MOUSE_LBDOWN)
525   {
526     int x=(m->parameter>>16)-getScreenX();
527     int y=(m->parameter&0xFFFF)-getScreenY();
528     if (tabbar.mouseLBDOWN(x,y)) 
529     {
530       BoxStack::getInstance()->update(this);
531     } 
532     else if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
533     {
534       BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
535     }
536   }
537 }
538