51
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 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 "cppsmview.h"
|
|
18 |
#include <hbdataform.h>
|
|
19 |
#include <qstringlist>
|
|
20 |
#include <QDebug>
|
|
21 |
#include <hbdataformmodel.h>
|
|
22 |
#include <cpsettingformitemdata.h>
|
|
23 |
#include <hbmessagebox.h>
|
|
24 |
#include <hblineedit.h>
|
|
25 |
#include <hwrmpowerstatesdkpskeys.h>
|
|
26 |
#include <hwrmdomainpskeys.h>
|
|
27 |
#include <e32property.h>
|
|
28 |
#include <psmclient.h>
|
|
29 |
#include <psmsettings.h>
|
|
30 |
#include <hwrmpowerstatesdkpskeys.h>
|
|
31 |
#include <centralrepository.h>
|
|
32 |
#include <settingsinternalcrkeys.h>
|
|
33 |
#include <hbcheckbox.h>
|
|
34 |
#include <e32debug.h>
|
|
35 |
|
|
36 |
CpPsmView::CpPsmView(QGraphicsItem *parent) :
|
|
37 |
CpBaseSettingView(0,parent),iCheckBoxItem(0),iTrans(new HbTranslator("powermanagement"))
|
|
38 |
{
|
|
39 |
RDebug::Print( _L("CpPsmView::CpPsmView:Begin") );
|
|
40 |
iForm = new HbDataForm();
|
|
41 |
iModel = new HbDataFormModel();
|
|
42 |
iForm->setHeading(hbTrId("txt_power_management_subhead_power_management"));
|
|
43 |
//our view has 3 items first one being toggle button for enabling and disabling PSM
|
|
44 |
iPowerSaveMode = iModel->appendDataFormItem(HbDataFormModelItem::ToggleValueItem,
|
|
45 |
hbTrId("txt_power_list_power_save_mode"));
|
|
46 |
iPsmClient = CPsmClient::NewL( *this );
|
|
47 |
iPsmClient->RequestPowerSaveModeNotification();
|
|
48 |
TInt mode;
|
|
49 |
TInt err = iPsmClient->PsmSettings().GetCurrentMode( mode );
|
|
50 |
//setting of toggle value to on or off depends on the current mode
|
|
51 |
if( mode == EPsmsrvModePowerSave )
|
|
52 |
{
|
|
53 |
iPowerSaveMode->setContentWidgetData(QString("text"), hbTrId("txt_power_setlabel_val_off"));
|
|
54 |
}
|
|
55 |
else
|
|
56 |
{
|
|
57 |
iPowerSaveMode->setContentWidgetData(QString("text"), hbTrId("txt_power_setlabel_val_on"));
|
|
58 |
}
|
|
59 |
|
|
60 |
iForm->addConnection(iPowerSaveMode,SIGNAL(clicked()), this,SLOT(toggleChange()));
|
|
61 |
|
|
62 |
RDebug::Print( _L("CpPsmView::toggle button added") );
|
|
63 |
//this is the second item which is a text item which is readonly and describes what PSM does
|
|
64 |
HbDataFormModelItem *dataItem2 = iModel->appendDataFormItem(HbDataFormModelItem::TextItem);
|
|
65 |
//setting the maxrows property of hblineedit
|
|
66 |
dataItem2->setContentWidgetData("maxRows",11);
|
|
67 |
//setting the text property of hblineedit
|
|
68 |
dataItem2->setContentWidgetData("text",hbTrId("txt_power_list_activating_power_save_mode_will_con"));
|
|
69 |
dataItem2->setContentWidgetData("readOnly" , true);
|
|
70 |
RDebug::Print( _L("CpPsmView::text item added") );
|
|
71 |
|
|
72 |
//now the third item which is checkbox item for enabling psm automatically when low power
|
|
73 |
iCheckBoxItem = iModel->appendDataFormItem(
|
|
74 |
HbDataFormModelItem::CheckBoxItem);
|
|
75 |
//setting the text property of check box.
|
|
76 |
iCheckBoxItem->setContentWidgetData("text",hbTrId("txt_power_list_activate_power_save_mode_automatica"));
|
|
77 |
RDebug::Print( _L("CpPsmView::check box added") );
|
|
78 |
|
|
79 |
CRepository* repository( NULL );
|
|
80 |
TRAPD(err1,repository =CRepository::NewL(KCRUidDeviceManagementSettings));
|
|
81 |
TInt value;
|
|
82 |
err1 = repository->Get( KSettingsPowerSavingQuery, value );
|
|
83 |
|
|
84 |
if ( err1 == KErrNone )
|
|
85 |
{
|
|
86 |
//checkbox state is initialised based on cenrep key and default value of the key is 1 (meaning unchecked)
|
|
87 |
if(value==0)
|
|
88 |
{
|
|
89 |
RDebug::Print( _L("CpPsmView::checkbox state is checked ") );
|
|
90 |
iCheckBoxItem->setContentWidgetData("checkState",2);
|
|
91 |
}
|
|
92 |
}
|
|
93 |
delete repository;
|
|
94 |
iForm->addConnection(iCheckBoxItem,SIGNAL(stateChanged(int)),this,SLOT(checkBoxStateChanged(int)));
|
|
95 |
|
|
96 |
|
|
97 |
err = iPsmClient->PsmSettings().GetCurrentMode( mode );
|
|
98 |
|
|
99 |
if ( err == KErrNone && mode == EPsmsrvModePowerSave )
|
|
100 |
{
|
|
101 |
//if device is in powersavemode then disable the checkbox
|
|
102 |
RDebug::Print( _L("CpPsmView::checkbox disabled ") );
|
|
103 |
iCheckBoxItem->setEnabled(0);
|
|
104 |
}
|
|
105 |
|
|
106 |
iForm->setModel(iModel);
|
|
107 |
setWidget(iForm);
|
|
108 |
RDebug::Print( _L("CpPsmView::end "));
|
|
109 |
}
|
|
110 |
|
|
111 |
CpPsmView::~CpPsmView()
|
|
112 |
{
|
|
113 |
RDebug::Print( _L("CpPsmView::destructor begin ") );
|
|
114 |
delete iTrans;
|
|
115 |
delete iPsmClient;
|
|
116 |
RDebug::Print( _L("CpPsmView::destructor end ") );
|
|
117 |
}
|
|
118 |
|
|
119 |
|
|
120 |
void CpPsmView::checkBoxStateChanged(int state)
|
|
121 |
{
|
|
122 |
// store your changes
|
|
123 |
//state=1 means ->"checked" else it is "un-checked"
|
|
124 |
RDebug::Print( _L("CpPsmView::checkBoxStateChanged begin ") );
|
|
125 |
CRepository* repository( NULL );
|
|
126 |
|
|
127 |
TRAPD( err, repository = CRepository::NewL( KCRUidDeviceManagementSettings ) );
|
|
128 |
|
|
129 |
if ( err == KErrNone )
|
|
130 |
{
|
|
131 |
TInt value( 0 );
|
|
132 |
//default value of the key is 1 meaning unchecked,so if the checkbox is checked then state=1 so key is set to 0
|
|
133 |
if(state)
|
|
134 |
{
|
|
135 |
err = repository->Set( KSettingsPowerSavingQuery, value );
|
|
136 |
RDebug::Print( _L("CpPsmView::checkBoxStateChanged checked ") );
|
|
137 |
}
|
|
138 |
else
|
|
139 |
{
|
|
140 |
err = repository->Set( KSettingsPowerSavingQuery, 1 );
|
|
141 |
RDebug::Print( _L("CpPsmView::checkBoxStateChanged unchecked ") );
|
|
142 |
}
|
|
143 |
}
|
|
144 |
|
|
145 |
delete repository;
|
|
146 |
RDebug::Print( _L("CpPsmView::checkBoxStateChanged end ") );
|
|
147 |
|
|
148 |
}
|
|
149 |
|
|
150 |
void CpPsmView::toggleChange()
|
|
151 |
{
|
|
152 |
// iPsmClient = CPsmClient::NewL( *this );
|
|
153 |
RDebug::Print( _L("CpPsmView::toggleChange begin ") );
|
|
154 |
TInt mode;
|
|
155 |
TInt err = iPsmClient->PsmSettings().GetCurrentMode( mode );
|
|
156 |
|
|
157 |
if ( err == KErrNone )
|
|
158 |
{
|
|
159 |
if( mode == EPsmsrvModeNormal || mode == EPsmsrvPartialMode )
|
|
160 |
{
|
|
161 |
iPsmClient->CancelPowerSaveModeNotificationRequest();
|
|
162 |
iPsmClient->ChangePowerSaveMode( EPsmsrvModePowerSave );
|
|
163 |
// powerSaveMode->setContentWidgetData(QString("additionalText"), QString("off"));
|
|
164 |
RDebug::Print( _L("CpPsmView::toggleChange psm on ") );
|
|
165 |
}
|
|
166 |
else
|
|
167 |
{
|
|
168 |
iPsmClient->CancelPowerSaveModeNotificationRequest();
|
|
169 |
iPsmClient->ChangePowerSaveMode( EPsmsrvModeNormal );
|
|
170 |
// powerSaveMode->setContentWidgetData(QString("text"), QString("on"));
|
|
171 |
RDebug::Print( _L("CpPsmView::toggleChange psm off ") );
|
|
172 |
}
|
|
173 |
}
|
|
174 |
RDebug::Print( _L("CpPsmView::toggleChange end ") );
|
|
175 |
}
|
|
176 |
|
|
177 |
|
|
178 |
void CpPsmView::PowerSaveModeChanged( const TPsmsrvMode aMode )
|
|
179 |
{
|
|
180 |
RDebug::Print( _L("CpPsmView::PowerSaveModeChanged begin ") );
|
|
181 |
iPsmClient->RequestPowerSaveModeNotification();
|
|
182 |
if( aMode == EPsmsrvModePowerSave )
|
|
183 |
{
|
|
184 |
//device in psm mode so disable checkbox and set the value of toggle button to off
|
|
185 |
iCheckBoxItem->setEnabled(0);
|
|
186 |
iPowerSaveMode->setContentWidgetData(QString("text"), hbTrId("txt_power_setlabel_val_off"));
|
|
187 |
RDebug::Print( _L("CpPsmView::PowerSaveModeChanged powersavemode enabled ") );
|
|
188 |
}
|
|
189 |
else
|
|
190 |
{
|
|
191 |
//device is in normal mode so enable checkbox and set the value of toggle button to on
|
|
192 |
iCheckBoxItem->setEnabled(1);
|
|
193 |
iPowerSaveMode->setContentWidgetData(QString("text"), hbTrId("txt_power_setlabel_val_on"));
|
|
194 |
RDebug::Print( _L("CpPsmView::PowerSaveModeChanged powersavemode disabled ") );
|
|
195 |
}
|
|
196 |
RDebug::Print( _L("CpPsmView::PowerSaveModeChanged end ") );
|
|
197 |
}
|
|
198 |
|
|
199 |
|
|
200 |
void CpPsmView::PowerSaveModeChangeError( const TInt aError )
|
|
201 |
{
|
|
202 |
RDebug::Print( _L("CpPsmView::PowerSaveModeChangeError ") );
|
|
203 |
}
|
|
204 |
|