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