Added qmafw-gst-subtitles-renderer-0.0.55 for Meego Harmattan 1.2
[mafwsubrenderer] / qmafw-gst-subtitles-renderer / src / MafwGstRendererDolby.cpp
1 /*
2  * This file is part of QMAFW
3  *
4  * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights
5  * reserved.
6  *
7  * Contact: Visa Smolander <visa.smolander@nokia.com>
8  *
9  * This software, including documentation, is protected by copyright controlled
10  * by Nokia Corporation. All rights are reserved. Copying, including
11  * reproducing, storing, adapting or translating, any or all of this material
12  * requires the prior written consent of Nokia Corporation. This material also
13  * contains confidential information which may not be disclosed to others
14  * without the prior written consent of Nokia.
15  *
16  */
17
18 #include "MafwGstRendererDolby.h"
19
20 #include <QDebug>
21
22 const int DEFAULT_COLOR = 2;
23 const int DEFAULT_ROOM_SIZE = 2;
24 const int MAX_VALUE = 4;
25
26 enum MafwDolbyStates
27 {
28     MafwDolbyOff,
29     MafwDolbyOn,
30     MafwDolbyAuto
31 };
32
33 MafwGstRendererDolby::MafwGstRendererDolby( QObject* parent ):
34         QObject(parent),
35         m_dolbyConfMusic(0),
36         m_dolbyConfMusicRoom(0),
37         m_dolbyConfMusicColor(0),
38         m_dolbyConfVideo(0),
39         m_dolbyConfVideoRoom(0),
40         m_dolbyConfVideoColor(0)
41 {
42     qDebug() << __PRETTY_FUNCTION__;
43     m_currentMusicDolbyState = MafwDolbyOff;
44     m_currentMusicDolbyRoom = DEFAULT_ROOM_SIZE;
45     m_currentMusicDolbyColor = DEFAULT_COLOR;
46     m_currentVideoDolbyState = MafwDolbyOff;
47     m_currentVideoDolbyRoom = DEFAULT_ROOM_SIZE;
48     m_currentVideoDolbyColor = DEFAULT_COLOR;
49 }
50
51 void MafwGstRendererDolby::initialize()
52 {
53     if (!m_dolbyConfMusic)
54     {
55         m_dolbyConfMusic = new GConfItem("/apps/Multimedia/music/dolbyConf", this);
56     }
57     if (!m_dolbyConfMusicRoom)
58     {
59         m_dolbyConfMusicRoom = new GConfItem("/apps/Multimedia/music/dolbyConfRoom", this);
60     }
61     if (!m_dolbyConfMusicColor)
62     {
63         m_dolbyConfMusicColor = new GConfItem("/apps/Multimedia/music/dolbyConfColor", this);
64     }
65     if (!m_dolbyConfVideo)
66     {
67         m_dolbyConfVideo = new GConfItem("/apps/Multimedia/video/dolbyConf", this);
68     }
69     if (!m_dolbyConfVideoRoom)
70     {
71         m_dolbyConfVideoRoom = new GConfItem("/apps/Multimedia/video/dolbyConfRoom", this);
72     }
73     if (!m_dolbyConfVideoColor)
74     {
75         m_dolbyConfVideoColor = new GConfItem("/apps/Multimedia/video/dolbyConfColor", this);
76     }
77     if (!m_dolbyConfMusic->value().toString().isEmpty())
78     {
79         valueMusicChanged();
80         connect(m_dolbyConfMusic, SIGNAL(valueChanged()), this, SLOT(valueMusicChanged()));
81         connect(m_dolbyConfMusicRoom, SIGNAL(valueChanged()), this, SLOT(valueMusicChanged()));
82         connect(m_dolbyConfMusicColor, SIGNAL(valueChanged()), this, SLOT(valueMusicChanged()));
83     }
84     if (!m_dolbyConfVideo->value().toString().isEmpty())
85     {
86         valueVideoChanged();
87         connect(m_dolbyConfVideo, SIGNAL(valueChanged()), this, SLOT(valueVideoChanged()));
88         connect(m_dolbyConfVideoRoom, SIGNAL(valueChanged()), this, SLOT(valueVideoChanged()));
89         connect(m_dolbyConfVideoColor, SIGNAL(valueChanged()), this, SLOT(valueVideoChanged()));
90     }
91 }
92
93 MafwGstRendererDolby::~MafwGstRendererDolby()
94 {
95     qDebug() << __PRETTY_FUNCTION__;
96 }
97
98 bool MafwGstRendererDolby::setMusicDolbyState (uint value)
99 {
100     qDebug() << __PRETTY_FUNCTION__ << value;
101     if ( value <= MafwDolbyAuto)
102     {
103         m_currentMusicDolbyState = value;
104         m_dolbyConfMusic->set(m_currentMusicDolbyState);
105         return true;
106     }
107     else
108     {
109         m_currentMusicDolbyState = MafwDolbyOff;
110         m_dolbyConfMusic->set(m_currentMusicDolbyState);
111         return false;
112     }
113 }
114
115 bool MafwGstRendererDolby::setMusicDolbyRoom (int value)
116 {
117     qDebug() << __PRETTY_FUNCTION__ << value;
118     if ( value < 0)
119     {
120         m_currentMusicDolbyRoom = 0;
121         m_dolbyConfMusicRoom->set(m_currentMusicDolbyRoom);
122     }
123     else if ( value > MAX_VALUE)
124     {
125         m_currentMusicDolbyRoom = MAX_VALUE;
126         m_dolbyConfMusicRoom->set(m_currentMusicDolbyRoom);
127     }
128     else
129     {
130         m_currentMusicDolbyRoom = value;
131         m_dolbyConfMusicRoom->set(m_currentMusicDolbyRoom);
132     }
133     return true;
134 }
135
136 bool MafwGstRendererDolby::setMusicDolbyColor (int value)
137 {
138     qDebug() << __PRETTY_FUNCTION__ << value;
139     if ( value < 0)
140     {
141         m_currentMusicDolbyColor = 0;
142         m_dolbyConfMusicColor->set(m_currentMusicDolbyColor);
143     }
144     else if ( value > MAX_VALUE)
145     {
146         m_currentMusicDolbyColor = MAX_VALUE;
147         m_dolbyConfMusicColor->set(m_currentMusicDolbyColor);
148     }
149     else
150     {
151         m_currentMusicDolbyColor = value;
152         m_dolbyConfMusicColor->set(m_currentMusicDolbyColor);
153     }
154     return true;
155 }
156
157 bool MafwGstRendererDolby::setVideoDolbyState (uint value)
158 {
159     qDebug() << __PRETTY_FUNCTION__ << value;
160     if ( value <= MafwDolbyAuto)
161     {
162         m_currentVideoDolbyState = value;
163         m_dolbyConfVideo->set(int(m_currentVideoDolbyState));
164         return true;
165     }
166     else
167     {
168         m_currentVideoDolbyState = MafwDolbyOff;
169         m_dolbyConfVideo->set(int(m_currentVideoDolbyState));
170         return false;
171     }
172 }
173
174 bool MafwGstRendererDolby::setVideoDolbyRoom (int value)
175 {
176     qDebug() << __PRETTY_FUNCTION__ << value;
177     if ( value < 0)
178     {
179         m_currentVideoDolbyRoom = 0;
180         m_dolbyConfVideoRoom->set(m_currentVideoDolbyRoom);
181     }
182     else if ( value > MAX_VALUE)
183     {
184         m_currentVideoDolbyRoom = MAX_VALUE;
185         m_dolbyConfVideoRoom->set(m_currentVideoDolbyRoom);
186     }
187     else
188     {
189         m_currentVideoDolbyRoom = value;
190         m_dolbyConfVideoRoom->set(m_currentVideoDolbyRoom);
191     }
192     return true;
193 }
194
195 bool MafwGstRendererDolby::setVideoDolbyColor (int value)
196 {
197     qDebug() << __PRETTY_FUNCTION__ << value;
198     if ( value < 0)
199     {
200         m_currentVideoDolbyColor = 0;
201         m_dolbyConfVideoColor->set(m_currentVideoDolbyColor);
202     }
203     else if ( value > MAX_VALUE)
204     {
205         m_currentVideoDolbyColor = MAX_VALUE;
206         m_dolbyConfVideoColor->set(m_currentVideoDolbyColor);
207     }
208     else
209     {
210         m_currentVideoDolbyColor = value;
211         m_dolbyConfVideoColor->set(m_currentVideoDolbyColor);
212     }
213     return true;
214 }
215
216 void MafwGstRendererDolby::valueMusicChanged()
217 {
218     m_currentMusicDolbyState = m_dolbyConfMusic->value().toUInt();
219     if (!(m_currentMusicDolbyState <= MafwDolbyAuto))
220     {
221         m_currentMusicDolbyState = MafwDolbyOff;
222         m_currentMusicDolbyRoom = m_dolbyConfMusicRoom->value().toInt();
223         if (m_currentMusicDolbyRoom < 0)
224         {
225             m_currentMusicDolbyRoom = 0;
226         }
227         if (m_currentMusicDolbyRoom > MAX_VALUE)
228         {
229             m_currentMusicDolbyRoom = MAX_VALUE;
230         }
231         m_currentMusicDolbyColor = m_dolbyConfMusicColor->value().toInt();
232         if (m_currentMusicDolbyColor < 0)
233         {
234             m_currentMusicDolbyColor = 0;
235         }
236         if (m_currentMusicDolbyColor > MAX_VALUE)
237         {
238             m_currentMusicDolbyColor = MAX_VALUE;
239         }
240     }
241     qDebug() << __PRETTY_FUNCTION__ << "state" << m_currentMusicDolbyState;
242     qDebug() << __PRETTY_FUNCTION__ << "room" << m_currentMusicDolbyRoom;
243     qDebug() << __PRETTY_FUNCTION__ << "color" << m_currentMusicDolbyColor;
244    Q_EMIT mafwDHMMusicPropertyChanged();
245 }
246
247 void MafwGstRendererDolby::valueVideoChanged()
248 {
249     m_currentVideoDolbyState = m_dolbyConfVideo->value().toUInt();
250     if (!(m_currentVideoDolbyState <= MafwDolbyAuto))
251     {
252         m_currentVideoDolbyState = MafwDolbyOff;
253         m_currentVideoDolbyRoom = m_dolbyConfVideoRoom->value().toInt();
254         if (m_currentVideoDolbyRoom < 0)
255         {
256             m_currentVideoDolbyRoom = 0;
257         }
258         if (m_currentVideoDolbyRoom > MAX_VALUE)
259         {
260             m_currentVideoDolbyRoom = MAX_VALUE;
261         }
262         m_currentVideoDolbyColor = m_dolbyConfVideoColor->value().toInt();
263         if (m_currentVideoDolbyColor < 0)
264         {
265             m_currentVideoDolbyColor = 0;
266         }
267         if (m_currentVideoDolbyColor > MAX_VALUE)
268         {
269             m_currentVideoDolbyColor = MAX_VALUE;
270         }
271     }
272     qDebug() << __PRETTY_FUNCTION__ << "state" << m_currentVideoDolbyState;
273     qDebug() << __PRETTY_FUNCTION__ << "room" << m_currentVideoDolbyRoom;
274     qDebug() << __PRETTY_FUNCTION__ << "color" << m_currentVideoDolbyColor;
275    Q_EMIT mafwDHMVideoPropertyChanged();
276 }
277
278 uint MafwGstRendererDolby::getMusicDolbyState ()
279 {
280     qDebug() << __PRETTY_FUNCTION__ << m_currentMusicDolbyState;
281     return m_currentMusicDolbyState;
282 }
283
284 int MafwGstRendererDolby::getMusicDolbyRoom ()
285 {
286     qDebug() << __PRETTY_FUNCTION__ << m_currentMusicDolbyRoom;
287     return m_currentMusicDolbyRoom;
288 }
289
290 int MafwGstRendererDolby::getMusicDolbyColor ()
291 {
292     qDebug() << __PRETTY_FUNCTION__ << m_currentMusicDolbyColor;
293     return m_currentMusicDolbyColor;
294 }
295
296 uint MafwGstRendererDolby::getVideoDolbyState ()
297 {
298     qDebug() << __PRETTY_FUNCTION__ << m_currentVideoDolbyState;
299     return m_currentVideoDolbyState;
300 }
301
302 int MafwGstRendererDolby::getVideoDolbyRoom ()
303 {
304     qDebug() << __PRETTY_FUNCTION__ << m_currentVideoDolbyRoom;
305     return m_currentVideoDolbyRoom;
306 }
307
308 int MafwGstRendererDolby::getVideoDolbyColor ()
309 {
310     qDebug() << __PRETTY_FUNCTION__ << m_currentVideoDolbyColor;
311     return m_currentVideoDolbyColor;
312 }