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