|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0"" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "mpxvideo_debug.h" |
|
19 #include "videosettingsgroup.h" |
|
20 #include "videosettingsaccesspointentry.h" |
|
21 #include <cpsettingformitemdata.h> |
|
22 #include <cpitemdatahelper.h> |
|
23 #include <hbdataformmodel.h> |
|
24 #include <hblineedit.h> |
|
25 #include <hbinputeditorinterface.h> |
|
26 #include <hbdataformviewitem.h> |
|
27 #include <hbinputstandardfilters.h> |
|
28 #include <hbvalidator.h> |
|
29 #include <hbpushbutton.h> |
|
30 #include <mpsettingsmodel.h> |
|
31 #include <MPSettEngPluginImplementationUIDs.hrh> |
|
32 #include <xqconversions.h> |
|
33 #include <qapplication.h> |
|
34 #include <qtranslator.h> |
|
35 #include <hbapplication.h> |
|
36 |
|
37 // --------------------------------------------------------------------------- |
|
38 // Constructor |
|
39 // --------------------------------------------------------------------------- |
|
40 // |
|
41 VideoSettingsGroup::VideoSettingsGroup(CpItemDataHelper &itemDataHelper) : |
|
42 CpSettingFormItemData(HbDataFormModelItem::GroupItem, QString()), |
|
43 mItemDataHelper(itemDataHelper), |
|
44 mSettingsModel(0), |
|
45 mAccessPointItem(0), |
|
46 mLowestUDPPortItem(0), |
|
47 mHighestUDPPortItem(0), |
|
48 mUseProxyItem(0), |
|
49 mProxyServerItem(0), |
|
50 mProxyPortItem(0) |
|
51 { |
|
52 MPX_ENTER_EXIT(_L("VideoSettingsGroup::VideoSettingsGroup()")); |
|
53 |
|
54 // Load the translation file. |
|
55 QString lang = QLocale::system().name(); |
|
56 QTranslator translator; |
|
57 bool loaded(false); |
|
58 |
|
59 loaded = translator.load( "videos_" + lang, QString("c:/resource/qt/translations") ); |
|
60 |
|
61 if (!loaded) |
|
62 { |
|
63 translator.load("videos_" + lang, QString("z:/resource/qt/translations") ); |
|
64 } |
|
65 |
|
66 // Install the translator |
|
67 HbApplication* app = qobject_cast<HbApplication*>(qApp); |
|
68 if(app) |
|
69 { |
|
70 app->installTranslator(&translator); |
|
71 } |
|
72 |
|
73 this->setLabel(hbTrId("txt_videos_subhead_video_streaming_settings")); |
|
74 |
|
75 TRAPD(err, InitSettingsModelL()); |
|
76 if(err != KErrNone) |
|
77 { |
|
78 delete mSettingsModel; |
|
79 mSettingsModel = 0; |
|
80 return; |
|
81 } |
|
82 |
|
83 itemDataHelper.connectToForm(SIGNAL(itemShown(const QModelIndex)), this, SLOT(itemShown(const QModelIndex))); |
|
84 |
|
85 // Access point in use |
|
86 mAccessPointItem = new VideoSettingsAccessPointEntry(itemDataHelper, |
|
87 hbTrId("txt_videos_dblist_access_point"), this); |
|
88 this->appendChild(mAccessPointItem); |
|
89 |
|
90 // Lowest UDP port |
|
91 mLowestUDPPortItem = new CpSettingFormItemData(HbDataFormModelItem::TextItem, |
|
92 hbTrId("txt_videos_dblist_min_udp_port")); |
|
93 mLowestUDPPortItem->setContentWidgetData(QString("maxRows"), 1); |
|
94 mItemDataHelper.addConnection(mLowestUDPPortItem, SIGNAL(editingFinished()), |
|
95 this, SLOT(lowestUdpPortEditingFinished())); |
|
96 this->appendChild(mLowestUDPPortItem); |
|
97 |
|
98 // Highest UDP port |
|
99 mHighestUDPPortItem = new CpSettingFormItemData(HbDataFormModelItem::TextItem, |
|
100 hbTrId("txt_videos_dblist_max_udp_port")); |
|
101 mHighestUDPPortItem->setContentWidgetData(QString("maxRows"), 1); |
|
102 mItemDataHelper.addConnection(mHighestUDPPortItem, SIGNAL(editingFinished()), |
|
103 this, SLOT(highestUdpPortEditingFinished())); |
|
104 this->appendChild(mHighestUDPPortItem); |
|
105 |
|
106 // Use proxy |
|
107 mUseProxyItem = new CpSettingFormItemData(HbDataFormModelItem::CheckBoxItem, QString()); |
|
108 mUseProxyItem->setContentWidgetData(QString("text"), hbTrId("txt_videos_formlabel_proxy_in_use")); |
|
109 this->appendChild(mUseProxyItem); |
|
110 |
|
111 // Proxy server address |
|
112 mProxyServerItem = new CpSettingFormItemData(HbDataFormModelItem::TextItem, |
|
113 hbTrId("txt_videos_dblist_proxy_host_name")); |
|
114 mProxyServerItem->setContentWidgetData(QString("maxRows"), 1); |
|
115 mProxyServerItem->setContentWidgetData(QString("placeholderText"), hbTrId("txt_videos_dblist_none")); |
|
116 mItemDataHelper.addConnection(mProxyServerItem, SIGNAL(editingFinished()), |
|
117 this, SLOT(proxyServerEditingFinished())); |
|
118 this->appendChild(mProxyServerItem); |
|
119 |
|
120 // Proxy port number |
|
121 mProxyPortItem = new CpSettingFormItemData(HbDataFormModelItem::TextItem, |
|
122 hbTrId("txt_videos_dblist_proxy_port")); |
|
123 mProxyPortItem->setContentWidgetData(QString("maxRows"), 1); |
|
124 mItemDataHelper.addConnection(mProxyPortItem, SIGNAL(editingFinished()), |
|
125 this, SLOT(proxyPortEditingFinished())); |
|
126 this->appendChild(mProxyPortItem); |
|
127 |
|
128 loadSettings(); |
|
129 } |
|
130 |
|
131 // --------------------------------------------------------------------------- |
|
132 // Destructor |
|
133 // --------------------------------------------------------------------------- |
|
134 // |
|
135 VideoSettingsGroup::~VideoSettingsGroup() |
|
136 { |
|
137 MPX_ENTER_EXIT(_L("VideoSettingsGroup::~VideoSettingsGroup()")); |
|
138 |
|
139 TRAP_IGNORE( mSettingsModel->StoreSettingsL() ); |
|
140 |
|
141 delete mSettingsModel; |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------------------------- |
|
145 // getAccessPointId |
|
146 // --------------------------------------------------------------------------- |
|
147 // |
|
148 uint VideoSettingsGroup::getAccessPointId() |
|
149 { |
|
150 MPX_ENTER_EXIT(_L("VideoSettingsGroup::getAccessPointId()")); |
|
151 |
|
152 TUint32 defaultAp(0); |
|
153 mSettingsModel->GetDefaultAp(defaultAp); |
|
154 |
|
155 MPX_DEBUG(_L("Returned access point id = %i"), defaultAp); |
|
156 |
|
157 return defaultAp; |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // setAccessPointId |
|
162 // --------------------------------------------------------------------------- |
|
163 // |
|
164 void VideoSettingsGroup::setAccessPointId(const uint& defaultAp) |
|
165 { |
|
166 MPX_ENTER_EXIT(_L("VideoSettingsGroup::setAccessPointId()"), |
|
167 _L("defaultAp = %i"), defaultAp); |
|
168 |
|
169 mSettingsModel->SetDefaultAp(defaultAp); |
|
170 } |
|
171 |
|
172 // --------------------------------------------------------------------------- |
|
173 // lowestUdpPortValueChanged |
|
174 // --------------------------------------------------------------------------- |
|
175 // |
|
176 void VideoSettingsGroup::lowestUdpPortEditingFinished() |
|
177 { |
|
178 MPX_ENTER_EXIT(_L("VideoSettingsGroup::lowestUdpPortValueChanged()")); |
|
179 |
|
180 int minPort = mLowestUDPPortItem->contentWidgetData(QString("text")).toString().toInt(); |
|
181 int maxPort = mHighestUDPPortItem->contentWidgetData(QString("text")).toString().toInt(); |
|
182 |
|
183 MPX_DEBUG(_L("minudp = %i, maxudp = %i"), minPort, maxPort); |
|
184 |
|
185 if(minPort > maxPort) |
|
186 { |
|
187 minPort = maxPort; |
|
188 mLowestUDPPortItem->setContentWidgetData(QString("text"), QString::number(minPort)); |
|
189 } |
|
190 |
|
191 mSettingsModel->SetMinUDPPort(minPort); |
|
192 } |
|
193 |
|
194 // --------------------------------------------------------------------------- |
|
195 // highestUdpPortValueChanged |
|
196 // --------------------------------------------------------------------------- |
|
197 // |
|
198 void VideoSettingsGroup::highestUdpPortEditingFinished() |
|
199 { |
|
200 MPX_ENTER_EXIT(_L("VideoSettingsGroup::highestUdpPortValueChanged()")); |
|
201 |
|
202 int maxPort = mHighestUDPPortItem->contentWidgetData(QString("text")).toString().toInt(); |
|
203 int minPort = mLowestUDPPortItem->contentWidgetData(QString("text")).toString().toInt(); |
|
204 |
|
205 MPX_DEBUG(_L("minudp = %i, maxudp = %i"), minPort, maxPort); |
|
206 |
|
207 if(maxPort < minPort) |
|
208 { |
|
209 maxPort = minPort; |
|
210 mHighestUDPPortItem->setContentWidgetData(QString("text"), QString::number(maxPort)); |
|
211 } |
|
212 |
|
213 mSettingsModel->SetMaxUDPPort(maxPort); |
|
214 } |
|
215 |
|
216 // --------------------------------------------------------------------------- |
|
217 // useProxyToggled |
|
218 // --------------------------------------------------------------------------- |
|
219 // |
|
220 void VideoSettingsGroup::useProxyToggled(int state) |
|
221 { |
|
222 MPX_ENTER_EXIT(_L("VideoSettingsGroup::useProxyToggled()"), |
|
223 _L("state = %i"), state); |
|
224 |
|
225 mProxyServerItem->setEnabled(state == Qt::Checked); |
|
226 mProxyPortItem->setEnabled(state == Qt::Checked); |
|
227 |
|
228 mSettingsModel->SetProxyMode(state == Qt::Checked ? 1 : 0); |
|
229 } |
|
230 |
|
231 // --------------------------------------------------------------------------- |
|
232 // proxyServerValueChanged |
|
233 // --------------------------------------------------------------------------- |
|
234 // |
|
235 void VideoSettingsGroup::proxyServerEditingFinished() |
|
236 { |
|
237 MPX_ENTER_EXIT(_L("VideoSettingsGroup::proxyServerValueChanged()")); |
|
238 |
|
239 QString text = mProxyServerItem->contentWidgetData(QString("text")).toString(); |
|
240 |
|
241 MPX_DEBUG(_L("new proxy server = '%s'"), text.data()); |
|
242 |
|
243 HBufC* proxyServer = XQConversions::qStringToS60Desc(text); |
|
244 TRAP_IGNORE( mSettingsModel->SetProxyHostNameL(*proxyServer) ); |
|
245 delete proxyServer; |
|
246 } |
|
247 |
|
248 // --------------------------------------------------------------------------- |
|
249 // proxyPortValueChanged |
|
250 // --------------------------------------------------------------------------- |
|
251 // |
|
252 void VideoSettingsGroup::proxyPortEditingFinished() |
|
253 { |
|
254 MPX_ENTER_EXIT(_L("VideoSettingsGroup::proxyPortValueChanged()")); |
|
255 |
|
256 int proxyPort = mProxyPortItem->contentWidgetData(QString("text")).toString().toInt(); |
|
257 |
|
258 MPX_DEBUG(_L("new proxy port = %i"), proxyPort); |
|
259 |
|
260 mSettingsModel->SetProxyPort(proxyPort); |
|
261 } |
|
262 |
|
263 // --------------------------------------------------------------------------- |
|
264 // itemShown |
|
265 // --------------------------------------------------------------------------- |
|
266 // |
|
267 void VideoSettingsGroup::itemShown(const QModelIndex& index) |
|
268 { |
|
269 MPX_ENTER_EXIT(_L("VideoSettingsGroup::itemShown()"), |
|
270 _L("index row = %i"), index.row()); |
|
271 |
|
272 HbDataFormModelItem* modelItem = mItemDataHelper.modelItemFromModelIndex(index); |
|
273 |
|
274 if(modelItem == mLowestUDPPortItem || |
|
275 modelItem == mHighestUDPPortItem || |
|
276 modelItem == mProxyPortItem ) |
|
277 { |
|
278 HbLineEdit *editor = static_cast<HbLineEdit *>(mItemDataHelper.widgetFromModelIndex(index)); |
|
279 |
|
280 HbEditorInterface editorIf(editor); |
|
281 editorIf.setFilter(HbDigitsOnlyFilter::instance()); |
|
282 |
|
283 HbValidator *validator = new HbValidator(this); |
|
284 int lowestAllowedPort = modelItem == mProxyPortItem ? 1 : 1024; |
|
285 validator->addField(new QIntValidator(lowestAllowedPort, 65535, validator), modelItem->contentWidgetData(QString("text")).toString()); |
|
286 editor->setValidator(validator); |
|
287 } |
|
288 |
|
289 if(modelItem == mProxyServerItem) |
|
290 { |
|
291 mItemDataHelper.addConnection(mUseProxyItem, SIGNAL(stateChanged(int)), this, SLOT(useProxyToggled(int))); |
|
292 HbEditorInterface editor(mItemDataHelper.widgetFromModelIndex(index)); |
|
293 editor.setFilter(HbUrlFilter::instance()); |
|
294 } |
|
295 } |
|
296 |
|
297 // --------------------------------------------------------------------------- |
|
298 // InitSettingsModelL |
|
299 // --------------------------------------------------------------------------- |
|
300 // |
|
301 void VideoSettingsGroup::InitSettingsModelL() |
|
302 { |
|
303 MPX_ENTER_EXIT(_L("VideoSettingsGroup::InitSettingsModelL()")); |
|
304 |
|
305 TUid settingsUid = {KMPSettEngImplUidROP}; |
|
306 mSettingsModel = CMPSettingsModel::NewL(settingsUid); |
|
307 mSettingsModel->LoadSettingsL(EConfigUser); |
|
308 } |
|
309 |
|
310 // --------------------------------------------------------------------------- |
|
311 // loadSettings |
|
312 // --------------------------------------------------------------------------- |
|
313 // |
|
314 void VideoSettingsGroup::loadSettings() |
|
315 { |
|
316 MPX_ENTER_EXIT(_L("VideoSettingsGroup::loadSettings()")); |
|
317 |
|
318 int lowestUdpPort(0); |
|
319 mSettingsModel->GetMinUDPPort(lowestUdpPort); |
|
320 mLowestUDPPortItem->setContentWidgetData(QString("text"), QString::number(lowestUdpPort)); |
|
321 |
|
322 int highestUdpPort(0); |
|
323 mSettingsModel->GetMaxUDPPort(highestUdpPort); |
|
324 mHighestUDPPortItem->setContentWidgetData(QString("text"), QString::number(highestUdpPort)); |
|
325 |
|
326 int proxyMode(0); |
|
327 mSettingsModel->GetProxyMode(proxyMode); |
|
328 mUseProxyItem->setContentWidgetData(QString("checked"), proxyMode == 1); |
|
329 useProxyToggled(proxyMode == 1 ? Qt::Checked : Qt::Unchecked); |
|
330 |
|
331 TBuf<2048> proxyServerBuf; |
|
332 mSettingsModel->GetProxyHostName(proxyServerBuf); |
|
333 QString proxyServer = XQConversions::s60DescToQString(proxyServerBuf); |
|
334 mProxyServerItem->setContentWidgetData(QString("text"), proxyServer); |
|
335 |
|
336 int proxyPort; |
|
337 mSettingsModel->GetProxyPort(proxyPort); |
|
338 mProxyPortItem->setContentWidgetData(QString("text"), QString::number(proxyPort)); |
|
339 |
|
340 mAccessPointItem->setIapId(getAccessPointId()); |
|
341 } |