]> git.vomp.tv Git - vompclient-marten.git/blob - vopts.cc
dvbsubtitles fixup part 2
[vompclient-marten.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   // Get list of languages from VDR and construct options table
75   LangCode = VDR::getInstance()->getLanguageList();
76   options2 = new const char*[LangCode.size()];
77   options2keys = new const char*[LangCode.size()];
78   I18n::lang_code_list::const_iterator iter;
79   UINT LangNumber = 0;
80   for (iter = LangCode.begin(); iter != LangCode.end(); ++iter,++LangNumber)
81   {
82     options2[LangNumber] = iter->second.c_str();
83     options2keys[LangNumber] = iter->first.c_str();
84   }
85
86   numPanes = 4;
87   panes = new Boxx*[numPanes];
88
89   wop = new WOptionPane();
90   tabbar.addTab(tr("General"), wop);
91   panes[0] = wop;
92 #ifdef MVP_REMOTE_TYPES
93   option = new Option(1, "Remote control type",      "General", "Remote type",           Option::TYPE_TEXT, 2, 0, 0, options1);
94   options.push_back(option);
95   wop->addOptionLine(option);
96 #endif
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
102   UINT suppconn = Video::getInstance()->getSupportedFormats();
103   if (suppconn) {
104           int 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           int 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           int 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
192   Remote::getInstance()->addOptionsToPanes(0,&options,wop);
193   Video::getInstance()->addOptionsToPanes(0,&options,wop);
194   Audio::getInstance()->addOptionsToPanes(0,&options,wop);
195
196     
197 /*  WRemoteConfig* wrc = new WRemoteConfig();
198   tabbar.addTab(tr("Remote Control"), wrc);*/
199   Remote::getInstance()->addOptionPagesToWTB(&tabbar);
200  // panes[1] = wrc;
201
202   Video::getInstance()->addOptionPagesToWTB(&tabbar);
203   Audio::getInstance()->addOptionPagesToWTB(&tabbar);
204 #ifdef VOMP_PLATTFORM_MVP
205   MediaOptions::getInstance()->addOptionPagesToWTB(&tabbar);
206 #endif
207
208
209   wop = new WOptionPane(); 
210   tabbar.addTab(tr("Timers"), wop);
211   panes[1] = wop;
212   
213   option = new Option(9, "Default start margin (minutes)",  "Timers", "Start margin",  Option::TYPE_INT, 20, 5, 0, NULL);
214   options.push_back(option);
215   wop->addOptionLine(option);
216   option = new Option(10, "Default end margin (minutes)",   "Timers", "End margin",    Option::TYPE_INT, 20, 5, 0, NULL);
217   options.push_back(option);
218   wop->addOptionLine(option);
219   option = new Option(11, "Default priority",               "Timers", "Priority",      Option::TYPE_INT, 100, 99, 0, NULL);
220   options.push_back(option);
221   wop->addOptionLine(option);
222   option = new Option(12, "Default lifetime",               "Timers", "Lifetime",      Option::TYPE_INT, 100, 99, 0, NULL);
223   options.push_back(option);
224   wop->addOptionLine(option);
225
226   Remote::getInstance()->addOptionsToPanes(1,&options,wop);
227   Video::getInstance()->addOptionsToPanes(1,&options,wop);
228   Audio::getInstance()->addOptionsToPanes(1,&options,wop);
229
230     
231   wop = new WOptionPane(); 
232   tabbar.addTab(tr("Advanced"), wop);
233   panes[2] = wop;
234   
235   option = new Option(8, "VDR-Pri 0=OK !See forums!",  "General",  "Live priority",      Option::TYPE_INT,  199, -1, -99, NULL);
236   options.push_back(option);
237   wop->addOptionLine(option);
238   option = new Option(13, "TCP receive window size",   "Advanced", "TCP receive window", Option::TYPE_TEXT, 8, /*1*/DEFAULT_TCP_WINDOWSIZENR, 0, options13);
239   options.push_back(option);
240   wop->addOptionLine(option);
241 #ifdef PAL_WSS
242   option = new Option(14, "Use WSS (PAL only)",        "General",  "WSS",                Option::TYPE_TEXT, 2, 0, 0, options14);
243   options.push_back(option);
244   wop->addOptionLine(option);
245 #endif
246   const char * * fontnames;
247   const char * * fontnames_keys;
248   int numfonts=Osd::getInstance()->getFontNames(&fontnames,&fontnames_keys);
249   if (numfonts) {
250           option = new Option(17, "Font Name",   "Advanced", "Font Name",  Option::TYPE_KEYED_TEXT, numfonts, 1, 0, fontnames,fontnames_keys);
251           options.push_back(option);
252           wop->addOptionLine(option);
253   }
254
255   Remote::getInstance()->addOptionsToPanes(2,&options,wop);
256   Video::getInstance()->addOptionsToPanes(2,&options,wop);
257   Audio::getInstance()->addOptionsToPanes(2,&options,wop);
258 }
259
260 VOpts::~VOpts()
261 {
262  // for (int i = 0; i < numPanes; i++) delete panes[i]; //Move to TabBar, Marten
263   delete[] panes;
264
265   for(vector<Option*>::iterator j = options.begin(); j != options.end(); j++) delete *j;
266   delete[] options2;
267   delete[] options2keys;
268 }
269
270 int VOpts::handleCommand(int command)
271 {
272   // either is active, handle back
273   if (command == Remote::BACK)
274   {
275     doSave();
276     return 4;
277   }
278   else
279   {
280     int retval = tabbar.handleCommand(command);
281     if (retval == 1)
282     {
283       BoxStack::getInstance()->update(this);
284       return 2;
285     }
286     else if (retval == 2)
287     {
288       // command was taken and actively ignored
289       return 2;
290     }
291     else
292     {
293       return 1; // ???
294     }
295   }
296 }
297
298 void VOpts::doSave()
299 {
300   VDR* vdr = VDR::getInstance();
301
302   Remote::getInstance()->saveOptionstoServer(); //Remote
303   Video::getInstance()->saveOptionstoServer(); //Video
304   Audio::getInstance()->saveOptionstoServer(); //Remote
305 #ifdef VOMP_PLATTFORM_MVP
306   MediaOptions::getInstance()->saveOptionstoServer(); //Media
307 #endif
308
309   // Damn, and the dynamic idea was going *so* well...
310   //Whats about a check with typeid operator?
311   WOptionPane* wop;
312   wop = (WOptionPane*)panes[0];
313   wop->saveOpts();  
314   wop = (WOptionPane*)panes[1];
315   wop->saveOpts();  
316   wop = (WOptionPane*)panes[2];
317   wop->saveOpts();  
318
319
320   for (UINT i = 0; i < options.size(); i++)
321   {
322     if (options[i]->configChoice == options[i]->userSetChoice) continue; // no change
323
324     Log::getInstance()->log("Options", Log::DEBUG, "Option %i has changed", i);
325
326     // Save to vdr
327
328     if (options[i]->optionType == Option::TYPE_TEXT)
329     {
330       vdr->configSave(options[i]->configSection, options[i]->configKey, options[i]->options[options[i]->userSetChoice]);
331     }
332     else if (options[i]->optionType == Option::TYPE_KEYED_TEXT)
333     {
334       vdr->configSave(options[i]->configSection, options[i]->configKey, options[i]->optionkeys[options[i]->userSetChoice]);
335     }
336     else
337     {
338       char buffer[20];
339       sprintf(buffer, "%i", options[i]->userSetChoice);
340       vdr->configSave(options[i]->configSection, options[i]->configKey, buffer);
341     }
342     
343     // Set new setting
344     if (options[i]->opthandler == NULL) //Ok, noone else is handling this, we are doing it
345     {
346       switch(options[i]->id)
347       {
348         case 1:
349         {
350 #ifdef MVP_REMOTE_TYPES
351           if (options[i]->userSetChoice == 1)
352           {
353             Log::getInstance()->log("Options", Log::DEBUG, "Setting New Remote");
354             Remote::getInstance()->setRemoteType(Remote::NEWREMOTE);
355           }
356           else
357           {
358             Log::getInstance()->log("Options", Log::DEBUG, "Setting Old Remote");
359             Remote::getInstance()->setRemoteType(Remote::OLDREMOTE);
360           }
361 #endif
362           break;
363         }
364         case 2:
365         {
366           Message* m = new Message();
367           m->message = Message::CHANGE_LANGUAGE;
368           m->to = Command::getInstance();
369           Command::getInstance()->postMessageNoLock(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                 Osd::getInstance()->setFont(options[i]->optionkeys[options[i]->userSetChoice]);
446         } break;
447       }
448     }
449     else
450     {
451       options[i]->opthandler->handleOptionChanges(options[i]);
452     }
453   }
454 }
455
456 void VOpts::processMessage(Message* m)
457 {
458   if (m->message == Message::MOUSE_MOVE)
459   {
460     int x=(m->parameter>>16)-getScreenX();
461     int y=(m->parameter&0xFFFF)-getScreenY();
462     if (tabbar.mouseMove(x,y))
463     {
464       BoxStack::getInstance()->update(this);
465     }
466     
467   }
468   else if (m->message == Message::MOUSE_LBDOWN)
469   {
470     int x=(m->parameter>>16)-getScreenX();
471     int y=(m->parameter&0xFFFF)-getScreenY();
472     if (tabbar.mouseLBDOWN(x,y)) 
473     {
474       BoxStack::getInstance()->update(this);
475     } 
476     else if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
477     {
478       BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
479     }
480   }
481 }
482