]> git.vomp.tv Git - vompclient-marten.git/blob - mediaoptions.cc
Fix bug in demuxer widescreen signaling
[vompclient-marten.git] / mediaoptions.cc
1 /*
2     Copyright 2004-2005 Chris Tallon, Andreas Vogel
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
22 #include "mediaoptions.h"
23 #include "woptionpane.h"
24 #include "wtabbar.h"
25 #include "option.h"
26 #include "vdr.h"
27 #include "i18n.h"
28 #include <time.h>
29
30
31 MediaOptions * MediaOptions::instance=NULL;
32
33 static const char * option1[]={"clip","letter","clipfactor"};
34 static const char * option2[]={"count","audio","picture","none"};
35
36 static const char * msection="Media";
37
38 MediaOptions::MediaOptions()
39 {
40   myOptions.push_back( new Option(1,"Slide Show Interval",msection,"SlideShowInterval",Option::TYPE_INT,20,5,1,NULL));
41   myOptions.push_back( new Option(2,"Picture Mode",msection,"PictureMode",Option::TYPE_TEXT,3,0,0,option1));
42   myOptions.push_back( new Option(3,"max. Scale Factor",msection,"ScaleFactor",Option::TYPE_INT,5,0,1,NULL));
43   myOptions.push_back( new Option(4,"Picture Size %(10...150)",msection,"PictureSize",Option::TYPE_INT,150,90,10,NULL));
44   myOptions.push_back( new Option(5,"Factor Red",msection,"FactorRed",Option::TYPE_INT,180,100,20,NULL));
45   myOptions.push_back( new Option(6,"Factor Green",msection,"FactorGreen",Option::TYPE_INT,180,100,20,NULL));
46   myOptions.push_back( new Option(7,"Factor Blue",msection,"FactorBlue",Option::TYPE_INT,180,100,20,NULL));
47   myOptions.push_back( new Option(8,"DirectoryPlayMode",msection,"DirectoryPlayMode",Option::TYPE_TEXT,4,0,0,option2));
48   //strange: Option ctor only sets configChoice - maybe this should set both...
49   for(vector<Option*>::iterator j = myOptions.begin(); j != myOptions.end(); j++) {
50     (*j)->userSetChoice=(*j)->configChoice;
51   }
52   Log::getInstance()->log("MediaOptions",Log::DEBUG,"ctor %d options",myOptions.size());
53   pane=NULL;
54 }
55
56 MediaOptions::~MediaOptions()
57 {
58   for(vector<Option*>::iterator j = myOptions.begin(); j != myOptions.end(); j++) delete *j;
59
60 }
61
62 bool MediaOptions::loadOptionsfromServer(VDR* vdr)
63 {
64     return true;
65 }
66
67 bool MediaOptions::saveOptionstoServer()
68 {
69   pane->saveOpts();
70   return externSaveOptionstoServer();
71 }
72 bool MediaOptions::externSaveOptionstoServer()
73 {
74   bool rt=true;
75   Log::getInstance()->log("MediaOptions", Log::DEBUG, "save for %i options", myOptions.size());
76   for (UINT i = 0; i < myOptions.size(); i++)
77   {
78      if (! saveOption(myOptions[i])) rt=false;
79
80   }
81  
82   return rt;
83 }
84 bool MediaOptions::saveOption(Option *o)
85 {
86   if (o->configChoice == o->userSetChoice) return true; // no change
87
88   Log::getInstance()->log("MediaOptions", Log::DEBUG, "Option %s has changed", o->configKey);
89   //now we have saved
90   o->configChoice=o->userSetChoice;
91
92   // Save to vdr
93
94   if (o->optionType == Option::TYPE_TEXT)
95   {
96     VDR::getInstance()->configSave(o->configSection, o->configKey, o->options[o->userSetChoice]);
97   }
98   else
99   {
100     char buffer[20];
101     sprintf(buffer, "%i", o->userSetChoice);
102     VDR::getInstance()->configSave(o->configSection, o->configKey, buffer);
103   }
104   return true;
105 }
106
107
108 bool MediaOptions::addOptionPagesToWTB(WTabBar *wtb)
109 {
110   pane=new WOptionPane();
111   for(vector<Option*>::iterator j = myOptions.begin(); j != myOptions.end(); j++) {
112     pane->addOptionLine(*j);
113   }
114   //we have to be carefull here
115   //the pane will get deleted when the tabbar is deleted
116   //but the options will not be deleted
117   wtb->addTab(tr("Media"),pane);
118   return true;
119 }
120
121 MediaOptions * MediaOptions::getInstance() {
122   if (! instance) {
123     instance=new MediaOptions();
124   }
125   return instance;
126 }
127
128 Option * MediaOptions::findOption(const char * name){
129   for(vector<Option*>::iterator j = myOptions.begin(); j != myOptions.end(); j++) {
130     if (strcmp((*j)->configKey,name) == 0) {
131       return *j;
132     }
133   }
134   return NULL;
135 }
136
137 const char * MediaOptions::getStringOption(const char * name) {
138   const char * rt=NULL;
139   Option *o=findOption(name);
140   if (!o) return NULL;
141   if (! o->optionType == Option::TYPE_TEXT) return NULL;
142   rt=o->options[o->userSetChoice];
143   Log::getInstance()->log("MediaOptions",Log::DEBUG,"option value for %s is %s",name,rt);
144   return rt;
145 }
146 int MediaOptions::getIntOption(const char * name) {
147   Option *o=findOption(name);
148   if (!o) return -1;
149   if (! o->optionType == Option::TYPE_INT) return -1;
150   int rt=o->userSetChoice;
151   Log::getInstance()->log("MediaOptions",Log::DEBUG,"option value for %s is %d",name,rt);
152   return rt;
153 }
154 bool MediaOptions::setIntOption(const char * name, UINT value) {
155   Option *o=findOption(name);
156   if (!o) return false;
157   if (! o->optionType == Option::TYPE_INT) return false;
158   o->userSetChoice=value;
159   Log::getInstance()->log("MediaOptions",Log::DEBUG,"option value for %s set to %d",name,value);
160   return saveOption(o);
161 }
162 bool MediaOptions::setStringOption(const char * name, const char * value) {
163   Option *o=findOption(name);
164   if (!o) return false;
165   if (! o->optionType == Option::TYPE_TEXT) return false;
166   bool rt=false;
167   for (UINT i = 0; i < o->numChoices; i++) {
168     if (!STRCASECMP(value, o->options[i]))
169     {
170       o->configChoice = i;
171       rt=true;
172       break;
173     }
174   }  
175   if (rt) Log::getInstance()->log("MediaOptions",Log::DEBUG,"option value for %s set to %d",name,value);
176   return saveOption(o);
177 }
178