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