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