|
1 /* |
|
2 * Copyright (c) 2010-2011 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: This module contains the implementation of IAUpdateSettingDialog |
|
15 * class member functions. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <hbdataform.h> |
|
20 #include <hbdataformmodel.h> |
|
21 #include <centralrepository.h> |
|
22 #include <cmconnectionmethoddef.h> |
|
23 #include <cmdestination.h> |
|
24 #include <xqconversions.h> |
|
25 #include <hbaction.h> |
|
26 |
|
27 #include "iaupdatesettingdialog.h" |
|
28 #include "iaupdateprivatecrkeys.h" |
|
29 #include "iaupdate.hrh" |
|
30 |
|
31 |
|
32 const TInt KAutoUpdateOn( 0 ); |
|
33 const TInt KAutoUpdateOff( 1 ); |
|
34 const TInt KAutoUpdateOnInHomeNetwork( 2 ); |
|
35 |
|
36 /* |
|
37 Constructor. It creates a formwidget on the view. |
|
38 */ |
|
39 CIAUpdateSettingDialog::CIAUpdateSettingDialog(QGraphicsItem* parent):HbView(parent) |
|
40 { |
|
41 |
|
42 //setTitle("Software update"); |
|
43 |
|
44 mSettingsForm = new HbDataForm(this); |
|
45 |
|
46 |
|
47 // open connection manager |
|
48 TRAPD(err, mCmManager.OpenL()); |
|
49 qt_symbian_throwIfError(err); |
|
50 |
|
51 // destination field flag inititializations |
|
52 mSetByNwQuery = false; // dest set by user/by destination query |
|
53 mConnected = false; // already connected to query |
|
54 mInitialized = false; // field initialized ? |
|
55 |
|
56 // Initialize view |
|
57 initializeView(); |
|
58 |
|
59 //setWidget(mSettingsForm); |
|
60 setWidget(mSettingsForm); |
|
61 |
|
62 // Create application settings ui |
|
63 mApplSett = new CmApplSettingsUi(this); |
|
64 |
|
65 // Create a back key action and set it as the default navigation |
|
66 // action once the back key is pressed |
|
67 mBackKey = new HbAction(Hb::BackNaviAction, this); |
|
68 this->setNavigationAction(mBackKey); |
|
69 |
|
70 connect(mBackKey, SIGNAL(triggered()), this, SLOT(showPreviousView())); |
|
71 |
|
72 } |
|
73 |
|
74 /* |
|
75 Destructor |
|
76 */ |
|
77 CIAUpdateSettingDialog::~CIAUpdateSettingDialog() |
|
78 { |
|
79 // close connection manager |
|
80 mCmManager.Close(); |
|
81 } |
|
82 |
|
83 // ---------------------------------------------------------------------------- |
|
84 // CIAUpdateSettingDialog::toggleChange |
|
85 // |
|
86 // ---------------------------------------------------------------------------- |
|
87 // |
|
88 void CIAUpdateSettingDialog::toggleChange(QModelIndex startIn, QModelIndex /*endIn*/) |
|
89 { |
|
90 // HLa: this should work |
|
91 HbDataFormModelItem *itm = mModel->itemFromIndex(startIn); |
|
92 |
|
93 // Destination ? |
|
94 if ( startIn.row() == 0 ) |
|
95 { |
|
96 // no query when initializing fields |
|
97 if ( mInitialized ) |
|
98 { |
|
99 // no query if field value set by destination query |
|
100 if (!mSetByNwQuery ) |
|
101 { |
|
102 queryDestination(); |
|
103 mSetByNwQuery = true; |
|
104 } |
|
105 else |
|
106 { |
|
107 mSetByNwQuery = false; |
|
108 } |
|
109 } |
|
110 else |
|
111 { |
|
112 mInitialized = true; |
|
113 } |
|
114 |
|
115 } |
|
116 // Auto update ? |
|
117 if ( startIn.row() == 1 ) |
|
118 { |
|
119 int currentIndex = mAutoUpdateItem->contentWidgetData(QString("currentIndex")).toInt(); |
|
120 } |
|
121 } |
|
122 // ---------------------------------------------------------------------------- |
|
123 // CIAUpdateSettingDialog::queryDestination |
|
124 // |
|
125 // ---------------------------------------------------------------------------- |
|
126 // |
|
127 void CIAUpdateSettingDialog::queryDestination() |
|
128 { |
|
129 QFlags<CmApplSettingsUi::SelectionDialogItems> listItems; |
|
130 QSet<CmApplSettingsUi::BearerTypeFilter> filter; |
|
131 |
|
132 // Show only destinations |
|
133 listItems |= CmApplSettingsUi::ShowDestinations; |
|
134 // listItems |= CmApplSettingsUi::ShowConnectionMethods; |
|
135 |
|
136 mApplSett->setOptions(listItems, filter); |
|
137 mApplSett->setSelection(mSelection); |
|
138 |
|
139 // Connect finished(uint) signal and handle result via it |
|
140 if (!mConnected) |
|
141 { |
|
142 connect(mApplSett, SIGNAL(finished(uint)), this, SLOT(showResults(uint))); |
|
143 mConnected = true; |
|
144 } |
|
145 |
|
146 // Start CmApplSettingsUi |
|
147 mApplSett->open(); |
|
148 |
|
149 } |
|
150 // ---------------------------------------------------------------------------- |
|
151 // CIAUpdateSettingDialog::showResults |
|
152 // |
|
153 // ---------------------------------------------------------------------------- |
|
154 // |
|
155 void CIAUpdateSettingDialog::showResults(uint retval) |
|
156 { |
|
157 if (retval == CmApplSettingsUi::ApplSettingsErrorNone) { |
|
158 mSelection = mApplSett->selection(); |
|
159 |
|
160 uint destinationId = mSelection.id; |
|
161 |
|
162 QString idString; |
|
163 |
|
164 TRAPD( err, getDestinationNameL( destinationId, idString ) ); |
|
165 qt_symbian_throwIfError(err); |
|
166 |
|
167 // Destination changed ? |
|
168 if ( idString != mCurrentDest ) |
|
169 { |
|
170 mCurrentDest = idString; |
|
171 } |
|
172 } |
|
173 // inform toggleChange that change is not made by user |
|
174 mSetByNwQuery = true; |
|
175 mDestinationItem->setContentWidgetData(QString("text"), mCurrentDest); |
|
176 } |
|
177 |
|
178 // ---------------------------------------------------------------------------- |
|
179 // CIAUpdateSettingDialog::SaveSettingsL |
|
180 // |
|
181 // ---------------------------------------------------------------------------- |
|
182 // |
|
183 void CIAUpdateSettingDialog::saveSettingsL() |
|
184 { |
|
185 CRepository* cenrep = CRepository::NewLC( KCRUidIAUpdateSettings ); |
|
186 TInt err = cenrep->StartTransaction( CRepository::EReadWriteTransaction ); |
|
187 User::LeaveIfError( err ); |
|
188 |
|
189 cenrep->CleanupCancelTransactionPushL(); |
|
190 |
|
191 // Set destination |
|
192 TInt value = mSelection.id; |
|
193 err = cenrep->Set( KIAUpdateAccessPoint, value ) ; |
|
194 User::LeaveIfError( err ); |
|
195 |
|
196 // Set auto update check |
|
197 value = mAutoUpdateItem->contentWidgetData(QString("currentIndex")).toInt(); |
|
198 |
|
199 // Convert ist index index to setting value |
|
200 switch ( value ) |
|
201 { |
|
202 case KAutoUpdateOn: |
|
203 value = EIAUpdateSettingValueDisableWhenRoaming; |
|
204 break; |
|
205 case KAutoUpdateOff: |
|
206 value = EIAUpdateSettingValueDisable; |
|
207 break; |
|
208 case KAutoUpdateOnInHomeNetwork: |
|
209 value = EIAUpdateSettingValueEnable; |
|
210 break; |
|
211 default: |
|
212 break; |
|
213 } |
|
214 err = cenrep->Set( KIAUpdateAutoUpdateCheck, value ); |
|
215 |
|
216 User::LeaveIfError( err ); |
|
217 |
|
218 TUint32 ignore = KErrNone; |
|
219 User::LeaveIfError( cenrep->CommitTransaction( ignore ) ); |
|
220 CleanupStack::PopAndDestroy(); // CleanupCancelTransactionPushL() |
|
221 CleanupStack::PopAndDestroy( cenrep ); |
|
222 } |
|
223 |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CIAUpdateSettingDialog::initializeFieldsL |
|
227 // ----------------------------------------------------------------------------- |
|
228 // |
|
229 void CIAUpdateSettingDialog::initializeFieldsL() |
|
230 { |
|
231 CRepository* cenrep = CRepository::NewLC( KCRUidIAUpdateSettings ); |
|
232 int destId = 0; |
|
233 |
|
234 // get access point id |
|
235 User::LeaveIfError( cenrep->Get( KIAUpdateAccessPoint, destId ) ); |
|
236 |
|
237 // save id |
|
238 mSelection.id = destId; |
|
239 |
|
240 // On first time: show internet access point |
|
241 if ( mSelection.id == 0 ) |
|
242 { |
|
243 User::LeaveIfError(mSelection.id = getInternetSnapIdL()); |
|
244 } |
|
245 |
|
246 // set destination name |
|
247 TRAPD( err, getDestinationNameL( mSelection.id, mCurrentDest ) ); |
|
248 |
|
249 if ( err == KErrNotFound ) |
|
250 { |
|
251 mSelection.id = 0; |
|
252 } |
|
253 else |
|
254 { |
|
255 // nothing to do ? |
|
256 User::LeaveIfError( err ); |
|
257 } |
|
258 mDestinationItem->setContentWidgetData(QString("text"), mCurrentDest); |
|
259 |
|
260 // set auto update value |
|
261 int value = 0; |
|
262 User::LeaveIfError( cenrep->Get( KIAUpdateAutoUpdateCheck, value ) ); |
|
263 |
|
264 // map cenrep value to index |
|
265 switch ( value ) |
|
266 { |
|
267 case EIAUpdateSettingValueEnable: |
|
268 value = KAutoUpdateOn; // On |
|
269 break; |
|
270 case EIAUpdateSettingValueDisable: |
|
271 value = KAutoUpdateOff; // Off |
|
272 break; |
|
273 case EIAUpdateSettingValueDisableWhenRoaming: |
|
274 value = KAutoUpdateOnInHomeNetwork; // On in home network |
|
275 break; |
|
276 default: |
|
277 break; |
|
278 } |
|
279 |
|
280 mAutoUpdateItem->setContentWidgetData("currentIndex", value); |
|
281 |
|
282 |
|
283 CleanupStack::PopAndDestroy( cenrep ); |
|
284 |
|
285 } |
|
286 |
|
287 |
|
288 // ----------------------------------------------------------------------------- |
|
289 // CIAUpdateSettingDialog::getDestinationNameL |
|
290 // |
|
291 // ----------------------------------------------------------------------------- |
|
292 // |
|
293 void CIAUpdateSettingDialog::getDestinationNameL( uint aItemUid, QString& aItemName ) |
|
294 { |
|
295 |
|
296 if ( aItemUid == 0 ) |
|
297 { |
|
298 aItemUid = getInternetSnapIdL(); |
|
299 } |
|
300 |
|
301 RCmDestination dest = mCmManager.DestinationL( aItemUid ); |
|
302 CleanupClosePushL( dest ); |
|
303 HBufC* temp = dest.NameLC(); |
|
304 CleanupStack::Pop( temp ); |
|
305 CleanupStack::PopAndDestroy( &dest ); |
|
306 |
|
307 aItemName = XQConversions::s60DescToQString( temp->Des() ); |
|
308 |
|
309 if ( aItemName.size() == 0 ) |
|
310 { |
|
311 User::Leave(KErrNotFound); |
|
312 } |
|
313 } |
|
314 |
|
315 // ----------------------------------------------------------------------------- |
|
316 // ActionView::initializeView |
|
317 // ----------------------------------------------------------------------------- |
|
318 // |
|
319 void CIAUpdateSettingDialog::initializeView() |
|
320 { |
|
321 |
|
322 setTitle("Software update"); // txt_software_title_software_update |
|
323 mSettingsForm->setHeading("Settings"); // txt_software_subhead_settings |
|
324 |
|
325 //create a model class |
|
326 HbDataFormModel *mModel = new HbDataFormModel(); |
|
327 |
|
328 // add Destination item |
|
329 mDestinationItem = mModel->appendDataFormItem( |
|
330 HbDataFormModelItem::ToggleValueItem, QString("Network connection")); // txt_software_formlabel_access_point |
|
331 |
|
332 // add auto update item |
|
333 mAutoUpdateItem = mModel->appendDataFormItem( |
|
334 HbDataFormModelItem::ComboBoxItem, QString("Auto-check for updates")); // txt_software_setlabel_autocheck_for_updates |
|
335 |
|
336 // auto update selection values |
|
337 QStringList list; |
|
338 list.insert(0, QString("On")); // txt_software_setlabel_val_on |
|
339 list.append(QString("Off")); // txt_software_setlabel_val_off |
|
340 list.append(QString("On in home network")); // txt_software_setlabel_val_on_in_home_network |
|
341 mAutoUpdateItem->setContentWidgetData("items", list); |
|
342 |
|
343 // connect data changes for launching the access point selection dialog |
|
344 connect(mModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)), |
|
345 this, SLOT(toggleChange(QModelIndex, QModelIndex))); |
|
346 |
|
347 // connect to function called when data items are displayed |
|
348 connect(mSettingsForm, SIGNAL(activated(QModelIndex)), |
|
349 this, SLOT(activated(QModelIndex))); |
|
350 |
|
351 mSettingsForm->setModel(mModel); |
|
352 |
|
353 // set values for items |
|
354 TRAPD(err, initializeFieldsL()); |
|
355 qt_symbian_throwIfError(err); |
|
356 } |
|
357 |
|
358 // ----------------------------------------------------------------------------- |
|
359 // ActionView::getInternetSnapIdL |
|
360 // ----------------------------------------------------------------------------- |
|
361 // |
|
362 uint CIAUpdateSettingDialog::getInternetSnapIdL() |
|
363 { |
|
364 TUint internetSnapId( 0 ); |
|
365 |
|
366 RArray<TUint32> destinationIdArray; |
|
367 mCmManager.AllDestinationsL( destinationIdArray ); |
|
368 |
|
369 for ( TInt i = 0; i < destinationIdArray.Count(); i++ ) |
|
370 { |
|
371 RCmDestination destination = mCmManager.DestinationL( destinationIdArray[i] ); |
|
372 CleanupClosePushL( destination ); |
|
373 |
|
374 TUint32 metadata = destination.MetadataL( CMManager::ESnapMetadataPurpose ); |
|
375 if ( metadata == CMManager::ESnapPurposeInternet ) |
|
376 { |
|
377 internetSnapId = destinationIdArray[i]; |
|
378 // Get the destination name with destination.NameLC() if need. |
|
379 CleanupStack::PopAndDestroy( &destination ); |
|
380 break; |
|
381 } |
|
382 CleanupStack::PopAndDestroy( &destination ); |
|
383 } |
|
384 destinationIdArray.Close(); |
|
385 |
|
386 return internetSnapId; |
|
387 |
|
388 } |
|
389 |
|
390 void CIAUpdateSettingDialog::showPreviousView() |
|
391 { |
|
392 // Save settings |
|
393 TRAPD(err, saveSettingsL()); |
|
394 qt_symbian_throwIfError(err); |
|
395 |
|
396 // Switch view |
|
397 emit toMainView(); |
|
398 } |
|
399 |
|
400 void CIAUpdateSettingDialog::activated(const QModelIndex& index) |
|
401 { |
|
402 if ( this->isActiveWindow() && index.row() == 0 ) |
|
403 { |
|
404 } |
|
405 |
|
406 } |