]> git.vomp.tv Git - vompclient-marten.git/blob - vopts.cc
Possible fix for old remote & arrow keys & tab bar in options
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "vopts.h"
22
23 #include "colour.h"
24 #include "video.h"
25 #include "audio.h"
26 #include "i18n.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 //#include "vdr.h"
37 //#include "command.h"
38
39 VOpts::VOpts()
40 {
41   setTitleBarOn(1);
42   setTitleBarColour(Colour::TITLEBARBACKGROUND);
43   setTitleText(tr("Options"));
44
45   setSize(520, 360);
46   createBuffer();
47   if (Video::getInstance()->getFormat() == Video::PAL)
48     setPosition(100, 110);
49   else
50     setPosition(90, 90);
51   
52   tabbar.setPosition(6, 32);
53   tabbar.setSize(getWidth() - 12, getHeight() - 34);
54   add(&tabbar);
55   
56   Option* option;
57   WOptionPane* wop;
58   
59   //  --- edit options start here
60   
61   static const char* options1[] = {"Old", "New"};
62   static const char* options3[] = {"RGB+composite", "S-Video"};
63   static const char* options4[] = {"4:3", "16:9"};
64   static const char* options5[] = {"Chop sides", "Letterbox"};
65   static const char* options6[] = {"On", "Off", "Last state"};
66   static const char* options7[] = {"All", "FTA only"};
67   static const char* options15[] = {"Alphabetical", "Chronological"};
68
69   static const char* options13[] = {"1024", "2048", "4096", "8192", "16384", "32768", "65536"};
70   static const char* options14[] = {"No", "Yes"};
71
72   numPanes = 4;
73   panes = new Boxx*[numPanes];
74  
75   wop = new WOptionPane(); 
76   tabbar.addTab(tr("General"), wop);
77   panes[0] = wop;
78   
79   option = new Option(1, "Remote control type",      "General", "Remote type",           Option::TYPE_TEXT, 2, 0, 0, options1);
80   options.push_back(option);
81   wop->addOptionLine(option);
82   option = new Option(2, "Language",                 "General", "Language",              Option::TYPE_TEXT, I18n::NumLanguages, 0, 0, I18n::Languages);
83   options.push_back(option);
84   wop->addOptionLine(option);
85   option = new Option(3, "TV connection type",       "TV",      "Connection",            Option::TYPE_TEXT, 2, 0, 0, options3);
86   options.push_back(option);
87   wop->addOptionLine(option);
88   option = new Option(4, "TV aspect ratio",          "TV",      "Aspect",                Option::TYPE_TEXT, 2, 0, 0, options4);
89   options.push_back(option);
90   wop->addOptionLine(option);
91   option = new Option(5, "16:9 on 4:3 display mode", "TV",      "Widemode",              Option::TYPE_TEXT, 2, 0, 0, options5);
92   options.push_back(option);
93   wop->addOptionLine(option);
94   option = new Option(6, "Power state after bootup", "General", "Power After Boot",      Option::TYPE_TEXT, 3, 0, 0, options6);
95   options.push_back(option);
96   wop->addOptionLine(option);
97   option = new Option(7, "Display channels",         "General", "Channels",              Option::TYPE_TEXT, 2, 0, 0, options7);
98   options.push_back(option);
99   wop->addOptionLine(option);
100   option = new Option(15, "Recordings sort order",   "General", "Recordings Sort Order", Option::TYPE_TEXT, 2, 0, 0, options15);
101   options.push_back(option);
102   wop->addOptionLine(option);
103   
104     
105 /*  WRemoteConfig* wrc = new WRemoteConfig();
106   tabbar.addTab(tr("Remote Control"), wrc);*/
107   Remote::getInstance()->addOptionPagesToWTB(&tabbar);
108  // panes[1] = wrc;
109
110   Video::getInstance()->addOptionPagesToWTB(&tabbar);
111   Audio::getInstance()->addOptionPagesToWTB(&tabbar);
112   
113   
114   wop = new WOptionPane(); 
115   tabbar.addTab(tr("Timers"), wop);
116   panes[1] = wop;
117   
118   option = new Option(9, "Default start margin (minutes)",  "Timers", "Start margin",  Option::TYPE_INT, 20, 5, 0, NULL);
119   options.push_back(option);
120   wop->addOptionLine(option);
121   option = new Option(10, "Default end margin (minutes)",   "Timers", "End margin",    Option::TYPE_INT, 20, 5, 0, NULL);
122   options.push_back(option);
123   wop->addOptionLine(option);
124   option = new Option(11, "Default priority",               "Timers", "Priority",      Option::TYPE_INT, 100, 99, 0, NULL);
125   options.push_back(option);
126   wop->addOptionLine(option);
127   option = new Option(12, "Default lifetime",               "Timers", "Lifetime",      Option::TYPE_INT, 100, 99, 0, NULL);
128   options.push_back(option);
129   wop->addOptionLine(option);
130
131     
132   wop = new WOptionPane(); 
133   tabbar.addTab(tr("Advanced"), wop);
134   panes[2] = wop;
135   
136   option = new Option(8, "VDR-Pri 0=OK !See forums!",  "General",  "Live priority",      Option::TYPE_INT,  100, 0, 0, NULL);
137   options.push_back(option);
138   wop->addOptionLine(option);
139   option = new Option(13, "TCP receive window size",   "Advanced", "TCP receive window", Option::TYPE_TEXT, 7, 1, 0, options13);
140   options.push_back(option);
141   wop->addOptionLine(option);
142   option = new Option(14, "Use WSS (PAL only)",        "General",  "WSS",                Option::TYPE_TEXT, 2, 0, 0, options14);
143   options.push_back(option);
144   wop->addOptionLine(option);  
145 }
146
147 VOpts::~VOpts()
148 {
149  // for (int i = 0; i < numPanes; i++) delete panes[i]; //Move to TabBar, Marten
150   delete[] panes;
151
152   for(vector<Option*>::iterator j = options.begin(); j != options.end(); j++) delete *j;
153 }
154
155 int VOpts::handleCommand(int command)
156 {
157   // either is active, handle back
158   if (command == Remote::BACK)
159   {
160     doSave();
161     return 4;
162   }
163   else
164   {
165     int retval = tabbar.handleCommand(command);
166     if (retval == 1)
167     {
168       BoxStack::getInstance()->update(this);
169       return 2;
170     }
171     else if (retval == 2)
172     {
173       // command was taken and actively ignored
174       return 2;
175     }
176     else
177     {
178       return 1; // ???
179     }
180   }
181 }
182
183 void VOpts::doSave()
184 {
185   VDR* vdr = VDR::getInstance();
186
187   Remote::getInstance()->saveOptionstoServer(); //Remote
188   Video::getInstance()->saveOptionstoServer(); //Video
189   Audio::getInstance()->saveOptionstoServer(); //Remote
190
191   // Damn, and the dynamic idea was going *so* well...
192   //Whats about a check with typeid operator?
193   WOptionPane* wop;
194   wop = (WOptionPane*)panes[0];
195   wop->saveOpts();  
196   wop = (WOptionPane*)panes[1];
197   wop->saveOpts();  
198   wop = (WOptionPane*)panes[2];
199   wop->saveOpts();  
200
201
202   for (UINT i = 0; i < options.size(); i++)
203   {
204     if (options[i]->configChoice == options[i]->userSetChoice) continue; // no change
205
206     Log::getInstance()->log("Options", Log::DEBUG, "Option %i has changed", i);
207
208     // Save to vdr
209
210     if (options[i]->optionType == Option::TYPE_TEXT)
211     {
212       vdr->configSave(options[i]->configSection, options[i]->configKey, options[i]->options[options[i]->userSetChoice]);
213     }
214     else
215     {
216       char buffer[20];
217       sprintf(buffer, "%i", options[i]->userSetChoice);
218       vdr->configSave(options[i]->configSection, options[i]->configKey, buffer);
219     }
220     
221     // Set new setting
222     
223     switch(options[i]->id)
224     {
225       case 1:
226       {
227         if (options[i]->userSetChoice == 1)
228         {
229           Log::getInstance()->log("Options", Log::DEBUG, "Setting New Remote");
230           Remote::getInstance()->setRemoteType(Remote::NEWREMOTE);
231         }
232         else
233         {
234           Log::getInstance()->log("Options", Log::DEBUG, "Setting Old Remote");
235           Remote::getInstance()->setRemoteType(Remote::OLDREMOTE);
236         }
237         break;
238       }
239       case 2:
240       {
241         Message* m = new Message();
242         m->message = Message::CHANGE_LANGUAGE;
243         m->to = Command::getInstance();
244         Command::getInstance()->postMessageNoLock(m);
245         break;
246       }
247       case 3:
248       {
249         if (options[i]->userSetChoice == 1)
250         {
251           Log::getInstance()->log("Options", Log::DEBUG, "Setting S-Video");
252           Video::getInstance()->setConnection(Video::SVIDEO);
253         }
254         else
255         {
256           Log::getInstance()->log("Options", Log::DEBUG, "Setting RGB/Composite");
257           Video::getInstance()->setConnection(Video::COMPOSITERGB);
258         }
259         break;
260       }
261       case 4:
262       {
263         if (options[i]->userSetChoice == 1)
264         {
265           Log::getInstance()->log("Options", Log::DEBUG, "Setting 16:9 TV");
266           Video::getInstance()->setTVsize(Video::ASPECT16X9);
267         }
268         else
269         {
270           Log::getInstance()->log("Options", Log::DEBUG, "Setting 4:3 TV");
271           Video::getInstance()->setTVsize(Video::ASPECT4X3);
272         }
273         break;
274       }
275       case 5:
276       {
277         if (options[i]->userSetChoice == 1)
278         {
279           Log::getInstance()->log("Options", Log::DEBUG, "Setting letterbox");
280           Video::getInstance()->setMode(Video::LETTERBOX);
281         }
282         else
283         {
284           Log::getInstance()->log("Options", Log::DEBUG, "Setting chop-sides");
285           Video::getInstance()->setMode(Video::NORMAL);
286         }
287         break;
288       }
289       case 13:
290       {
291         size_t newTCPsize = 2048;
292
293         if (options[i]->userSetChoice == 0) newTCPsize = 1024;
294         else if (options[i]->userSetChoice == 1) newTCPsize = 2048;
295         else if (options[i]->userSetChoice == 2) newTCPsize = 4096;
296         else if (options[i]->userSetChoice == 3) newTCPsize = 8192;
297         else if (options[i]->userSetChoice == 4) newTCPsize = 16384;
298         else if (options[i]->userSetChoice == 5) newTCPsize = 32768;
299         else if (options[i]->userSetChoice == 6) newTCPsize = 65536;
300
301         Log::getInstance()->log("Options", Log::DEBUG, "Setting TCP window size %i", newTCPsize);
302         VDR::getInstance()->setReceiveWindow(newTCPsize);
303         break;
304       }
305     }
306   }
307 }
308
309 void VOpts::processMessage(Message* m)
310 {
311   if (m->message == Message::MOUSE_MOVE)
312   {
313     int x=(m->parameter>>16)-getScreenX();
314     int y=(m->parameter&0xFFFF)-getScreenY();
315     if (tabbar.mouseMove(x,y)) {
316         BoxStack::getInstance()->update(this);
317     }
318     
319   }
320   else if (m->message == Message::MOUSE_LBDOWN)
321   {
322     int x=(m->parameter>>16)-getScreenX();
323     int y=(m->parameter&0xFFFF)-getScreenY();
324     if (tabbar.mouseLBDOWN(x,y)) {
325         BoxStack::getInstance()->update(this);
326     } else if (x<0 || y <0 || x>(int)getWidth() || y>(int)getHeight())
327     {
328         BoxStack::getInstance()->handleCommand(Remote::BACK); //simulate cancel press
329     }
330
331     
332   }
333 }
334