|
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 #include "cpcommunicationgroupitemdata.h" |
|
18 #include <QStringList> |
|
19 #include <QtAlgorithms> |
|
20 #include <CoreApplicationUIsSDKCRKeys.h> |
|
21 #include <xqsettingsmanager.h> |
|
22 #include <cpitemdatahelper.h> |
|
23 |
|
24 CpCommunicationGroupItemData::CpCommunicationGroupItemData(const QString &configFile, |
|
25 const HbDataFormModelItem *parent): |
|
26 CpCategorySettingFormItemData(configFile,parent), |
|
27 mAirplaneModeItem(0), |
|
28 mSettingManager(new XQSettingsManager()) |
|
29 { |
|
30 |
|
31 } |
|
32 |
|
33 CpCommunicationGroupItemData::CpCommunicationGroupItemData(HbDataFormModelItem::DataItemType type, |
|
34 const QString &label, |
|
35 const QString &configFile, |
|
36 const HbDataFormModelItem *parent): |
|
37 CpCategorySettingFormItemData(type, label, configFile, parent), |
|
38 mAirplaneModeItem(0), |
|
39 mSettingManager(new XQSettingsManager()) |
|
40 { |
|
41 |
|
42 } |
|
43 |
|
44 CpCommunicationGroupItemData::~CpCommunicationGroupItemData() |
|
45 { |
|
46 delete mSettingManager; |
|
47 } |
|
48 |
|
49 void CpCommunicationGroupItemData::beforeLoadingConfigPlugins(CpItemDataHelper &itemDataHelper) |
|
50 { |
|
51 mAirplaneModeItem = new HbDataFormModelItem(HbDataFormModelItem::ToggleValueItem); |
|
52 mAirplaneModeItem->setContentWidgetData("text", hbTrId("txt_cp_button_offline")); |
|
53 mAirplaneModeItem->setContentWidgetData("additionalText", hbTrId("txt_cp_button_offline")); |
|
54 mAirplaneModeItem->setDescription(hbTrId("txt_cp_info_in_offline_mode_all_wireless_communica")); |
|
55 mAirplaneModeItem->setContentWidgetData("objectName", "airplaneModeToggle"); |
|
56 mAirplaneModeItem->setContentWidgetData("checkable", true); |
|
57 itemDataHelper.addConnection(mAirplaneModeItem, |
|
58 SIGNAL(toggled(bool)), |
|
59 this, |
|
60 SLOT(toggleAirplaneMode(bool))); |
|
61 |
|
62 XQCentralRepositorySettingsKey key(KCRUidCoreApplicationUIs.iUid,KCoreAppUIsNetworkConnectionAllowed); |
|
63 QVariant airplaneMode = mSettingManager->readItemValue(key,XQSettingsManager::TypeInt); |
|
64 settingValueChanged(key,airplaneMode); |
|
65 |
|
66 mSettingManager->startMonitoring(key,XQSettingsManager::TypeInt); |
|
67 connect(mSettingManager, SIGNAL(valueChanged (XQSettingsKey, QVariant)), |
|
68 this, SLOT(settingValueChanged(XQSettingsKey, QVariant))); |
|
69 |
|
70 this->appendChild(mAirplaneModeItem); |
|
71 |
|
72 } |
|
73 |
|
74 void CpCommunicationGroupItemData::toggleAirplaneMode(bool toggled) |
|
75 { |
|
76 XQCentralRepositorySettingsKey key(KCRUidCoreApplicationUIs.iUid,KCoreAppUIsNetworkConnectionAllowed); |
|
77 //toggled = true means ECoreAppUIsNetworkConnectionNotAllowed |
|
78 //toggled = false means ECoreAppUIsNetworkConnectionAllowed |
|
79 QVariant airplaneMode(static_cast<int>(!toggled)); |
|
80 mSettingManager->writeItemValue(key, airplaneMode); |
|
81 } |
|
82 |
|
83 void CpCommunicationGroupItemData::settingValueChanged(const XQSettingsKey &key, const QVariant &value) |
|
84 { |
|
85 if (mAirplaneModeItem |
|
86 && key.uid() == KCRUidCoreApplicationUIs.iUid |
|
87 && key.key() == KCoreAppUIsNetworkConnectionAllowed |
|
88 && value.isValid()) { |
|
89 //value.toBool() returns |
|
90 //true(1) if value equals ECoreAppUIsNetworkConnectionAllowed, that means offline mode off. |
|
91 //false(0) if value equals ECoreAppUIsNetworkConnectionNotAllowed, that means offline mode on. |
|
92 mAirplaneModeItem->setContentWidgetData("checked", !value.toBool()); |
|
93 } |
|
94 } |
|
95 |
|
96 //End of File |