0
|
1 |
/*------------------------------------------------------------------
|
|
2 |
-
|
|
3 |
* Software Name : UserEmulator
|
|
4 |
* Version : v4.2.1309
|
|
5 |
*
|
|
6 |
* Copyright (c) 2009 France Telecom. All rights reserved.
|
|
7 |
* This software is distributed under the License
|
|
8 |
* "Eclipse Public License - v 1.0" the text of which is available
|
|
9 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
10 |
*
|
|
11 |
* Initial Contributors:
|
|
12 |
* France Telecom
|
|
13 |
*
|
|
14 |
* Contributors:
|
|
15 |
*------------------------------------------------------------------
|
|
16 |
-
|
|
17 |
* File Name: SettingsDialog.cpp
|
|
18 |
*
|
|
19 |
* Created: 13/08/2009
|
|
20 |
* Author(s): Marcell Kiss, Reshma Sandeep Das
|
|
21 |
*
|
|
22 |
* Description:
|
|
23 |
* This class is used for handling settings dialog
|
|
24 |
*------------------------------------------------------------------
|
|
25 |
-
|
|
26 |
*
|
|
27 |
*/
|
|
28 |
|
|
29 |
//System Includes
|
|
30 |
#include <stringloader.h>
|
|
31 |
#include <eikfrlbd.h>
|
|
32 |
#include <aknquerydialog.h>
|
|
33 |
#include <bautils.h> // BaflUtils
|
|
34 |
#include <aknnotewrappers.h>
|
|
35 |
|
|
36 |
//User Includes
|
|
37 |
#include <UserEmulator_0x2001C3AF.rsg>
|
|
38 |
#include "SettingsDialog.h"
|
|
39 |
#include "Settings.h"
|
|
40 |
#include "UserEmulator.hrh"
|
|
41 |
#include "UserEmulatorAppUi.h"
|
|
42 |
|
|
43 |
//Constants
|
|
44 |
_LIT(KAPPIDSTATUS,"App ID is empty");
|
|
45 |
_LIT(KINVALIDDRIVEEXT,"Invalid Drive/Path/Extension..Changing to default path");
|
|
46 |
|
|
47 |
// -----------------------------------------------------------------------------
|
|
48 |
// CSettingsDialog::CSettingsDialog
|
|
49 |
// Constructor
|
|
50 |
// -----------------------------------------------------------------------------
|
|
51 |
//
|
|
52 |
CSettingsDialog::CSettingsDialog(CSettings& aSettings) : iSettings(aSettings)
|
|
53 |
{
|
|
54 |
iPrevLogPath.Copy(iSettings.iLogPath);
|
|
55 |
}
|
|
56 |
|
|
57 |
// -----------------------------------------------------------------------------
|
|
58 |
// CSettingsDialog::PostLayoutDynInitL
|
|
59 |
// Initializes the dialog's controls after the dialog has been sized but before
|
|
60 |
// it has been activated
|
|
61 |
// -----------------------------------------------------------------------------
|
|
62 |
//
|
|
63 |
void CSettingsDialog::PostLayoutDynInitL()
|
|
64 |
{
|
|
65 |
TRect mainPaneRect;
|
|
66 |
AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,mainPaneRect);
|
|
67 |
iSettingsList->SetRect(mainPaneRect);
|
|
68 |
}
|
|
69 |
// -----------------------------------------------------------------------------
|
|
70 |
// CSettingsDialog::~CSettingsDialog
|
|
71 |
// Destructor
|
|
72 |
// -----------------------------------------------------------------------------
|
|
73 |
//
|
|
74 |
CSettingsDialog::~CSettingsDialog()
|
|
75 |
{
|
|
76 |
delete iSettingsList;
|
|
77 |
iSettingsList=NULL;
|
|
78 |
}
|
|
79 |
// -----------------------------------------------------------------------------
|
|
80 |
// CSettingsDialog::PreLayoutDynInitL
|
|
81 |
// Initializes the dialog's controls before the dialog is sized and layed out.
|
|
82 |
// -----------------------------------------------------------------------------
|
|
83 |
//
|
|
84 |
void CSettingsDialog::PreLayoutDynInitL()
|
|
85 |
{
|
|
86 |
iSettingsList = new (ELeave) CAknSettingItemList;
|
|
87 |
iSettingsList->SetMopParent(this);
|
|
88 |
iSettingsList->ConstructFromResourceL(R_SETTING_ITEM_LIST);
|
|
89 |
|
|
90 |
TBool isNumberedStyle = iSettingsList->IsNumberedStyle();
|
|
91 |
CArrayPtr<CGulIcon>* icons = iSettingsList->ListBox()->ItemDrawer()->FormattedCellData()->IconArray();
|
|
92 |
|
|
93 |
TInt id = 0;
|
|
94 |
HBufC* label;
|
|
95 |
|
|
96 |
//Scripts Settings Path
|
|
97 |
CAknSettingItem* settingItem = new (ELeave) CAknTextSettingItem(id++, iSettings.iScriptsPath);
|
|
98 |
CleanupStack::PushL(settingItem);
|
|
99 |
label = StringLoader::LoadLC(R_SETTING_PATH_SELECTOR);
|
|
100 |
settingItem->SetEmptyItemTextL(KEmptyItemText);
|
|
101 |
settingItem->ConstructL(isNumberedStyle, 0, *label, icons, R_TEXT_SETTING_PAGE, -1, 0, R_NAME_EDWIN);
|
|
102 |
iSettingsList->SettingItemArray()->AppendL(settingItem);
|
|
103 |
CleanupStack::PopAndDestroy(label);
|
|
104 |
CleanupStack::Pop(settingItem);
|
|
105 |
|
|
106 |
//Log Status (ON/OFF)
|
|
107 |
CAknSettingItem* logStatusItem = new(ELeave) CAknBinaryPopupSettingItem(id++, iSettings.iLogStatus);
|
|
108 |
CleanupStack::PushL(logStatusItem);
|
|
109 |
label = StringLoader::LoadLC(R_SETTING_LOG_STATUS);
|
|
110 |
logStatusItem->ConstructL(isNumberedStyle, 0, *label, icons, R_BINARY_SETTING_PAGE, -1, 0, R_BINARY_TEXTS);
|
|
111 |
iSettingsList->SettingItemArray()->AppendL(logStatusItem);
|
|
112 |
CleanupStack::PopAndDestroy(label);
|
|
113 |
CleanupStack::Pop(logStatusItem);
|
|
114 |
|
|
115 |
//Log Settings Path
|
|
116 |
CAknSettingItem* logSettingItem = new (ELeave) CAknTextSettingItem(id++, iSettings.iLogPath);
|
|
117 |
CleanupStack::PushL(logSettingItem);
|
|
118 |
label = StringLoader::LoadLC(R_SETTING_LOG_SELECTOR);
|
|
119 |
logSettingItem->SetEmptyItemTextL(KEmptyItemText);
|
|
120 |
logSettingItem->ConstructL(isNumberedStyle, 0, *label, icons, R_TEXT_SETTING_PAGE, -1, 0, R_NAME_EDWIN);
|
|
121 |
iSettingsList->SettingItemArray()->AppendL(logSettingItem);
|
|
122 |
CleanupStack::PopAndDestroy(label);
|
|
123 |
CleanupStack::Pop(logSettingItem);
|
|
124 |
|
|
125 |
//Random test app Status (ON/OFF)
|
|
126 |
CAknSettingItem* RandomTestAppItem = new(ELeave) CAknBinaryPopupSettingItem(id++, iSettings.iRandomTestAppIdStatus);
|
|
127 |
CleanupStack::PushL(RandomTestAppItem);
|
|
128 |
label = StringLoader::LoadLC(R_SETTING_RANDOMTEST_STATUS);
|
|
129 |
RandomTestAppItem->ConstructL(isNumberedStyle, 0, *label, icons, R_BINARY_SETTING_PAGE, -1, 0, R_BINARY_TEXTS);
|
|
130 |
iSettingsList->SettingItemArray()->AppendL(RandomTestAppItem);
|
|
131 |
CleanupStack::PopAndDestroy(label);
|
|
132 |
CleanupStack::Pop(RandomTestAppItem);
|
|
133 |
|
|
134 |
//Random test app Id
|
|
135 |
CAknSettingItem* itemAppID = new (ELeave) CAknTextSettingItem(id++, iSettings.iRandomTestAppID );
|
|
136 |
CleanupStack::PushL(itemAppID);
|
|
137 |
label = StringLoader::LoadLC(R_SETTING_RANDOMTEST);
|
|
138 |
itemAppID->SetEmptyItemTextL(KEMPTYTEXT);
|
|
139 |
itemAppID->ConstructL(isNumberedStyle, 0, *label, icons, R_APPID_SETTING_PAGE, -1, 0, R_NAME_EDWIN);
|
|
140 |
iSettingsList->SettingItemArray()->AppendL(itemAppID);
|
|
141 |
CleanupStack::PopAndDestroy(label);
|
|
142 |
CleanupStack::Pop(itemAppID);
|
|
143 |
|
|
144 |
iSettingsList->HandleChangeInItemArrayOrVisibilityL();
|
|
145 |
}
|
|
146 |
// -----------------------------------------------------------------------------
|
|
147 |
// CSettingsDialog::OkToExitL
|
|
148 |
// -----------------------------------------------------------------------------
|
|
149 |
//
|
|
150 |
TBool CSettingsDialog::OkToExitL(TInt aButtonId)
|
|
151 |
{
|
|
152 |
switch (aButtonId)
|
|
153 |
{
|
|
154 |
case EAknSoftkeySelect:
|
|
155 |
TInt index = iSettingsList->ListBox()->CurrentItemIndex();
|
|
156 |
CAknSettingItem *item = (*iSettingsList->SettingItemArray())[index];
|
|
157 |
|
|
158 |
iSettingsList->EditItemL(index, EFalse);
|
|
159 |
iSettingsList->StoreSettingsL();
|
|
160 |
switch (item->Identifier())
|
|
161 |
{
|
|
162 |
case 0:
|
|
163 |
{
|
|
164 |
TBool lengthOk = ETrue;
|
|
165 |
if(iSettings.iScriptsPath.Length()>KBuffer256)
|
|
166 |
lengthOk = EFalse;
|
|
167 |
//check file extension
|
|
168 |
TInt result = CheckFileName(iSettings.iScriptsPath);
|
|
169 |
|
|
170 |
//check drive
|
|
171 |
TInt err = iSettings.CheckDrive(iSettings.iScriptsPath);
|
|
172 |
|
|
173 |
if(iSettings.iScriptsPath.Right(1).Compare(KBsh)!=0)
|
|
174 |
iSettings.iScriptsPath.Append(KBsh);
|
|
175 |
|
|
176 |
TBool res = iSettings.CheckPathL(iSettings.iScriptsPath);
|
|
177 |
|
|
178 |
if(err != KErrNone || result == -1 || !res || !lengthOk)
|
|
179 |
{
|
|
180 |
//invalid drive Error note
|
|
181 |
CAknErrorNote* errorNote = new (ELeave) CAknErrorNote(ETrue);
|
|
182 |
errorNote->ExecuteLD(KINVALIDDRIVEEXT);
|
|
183 |
iSettings.iScriptsPath = KDefaultPath;
|
|
184 |
iSettings.StoreL();
|
|
185 |
}
|
|
186 |
else
|
|
187 |
{
|
|
188 |
static_cast<CUserEmulatorAppUi*>(iCoeEnv->AppUi())->ShowScriptsL();
|
|
189 |
static_cast<CUserEmulatorAppUi*>(iCoeEnv->AppUi())->RefreshFileNotification();
|
|
190 |
iSettings.StoreL();
|
|
191 |
return EFalse;
|
|
192 |
}
|
|
193 |
}
|
|
194 |
break;
|
|
195 |
case 1:
|
|
196 |
case 3:
|
|
197 |
case 5:
|
|
198 |
case 6:
|
|
199 |
iSettings.StoreL();
|
|
200 |
return EFalse;
|
|
201 |
|
|
202 |
case 4:
|
|
203 |
if(iSettings.iRandomTestAppIdStatus && iSettings.iRandomTestAppID.Length()<1)
|
|
204 |
{
|
|
205 |
CAknErrorNote* errorNote = new (ELeave) CAknErrorNote(ETrue);
|
|
206 |
errorNote->ExecuteLD(KAPPIDSTATUS);
|
|
207 |
iSettings.StoreL();
|
|
208 |
return CAknDialog::OkToExitL(aButtonId);
|
|
209 |
}
|
|
210 |
else
|
|
211 |
{
|
|
212 |
iSettings.StoreL();
|
|
213 |
return EFalse;
|
|
214 |
}
|
|
215 |
break;
|
|
216 |
case 2:
|
|
217 |
{
|
|
218 |
//Check whether log file exits or not
|
|
219 |
TBool lengthOk = ETrue;
|
|
220 |
if(iSettings.iLogPath.Length()>256)
|
|
221 |
lengthOk = EFalse;
|
|
222 |
TInt pos = iSettings.iLogPath.Find(KDOT);
|
|
223 |
if(pos == KErrNotFound)
|
|
224 |
{
|
|
225 |
iSettings.iLogPath.Append(KCSVEXT);
|
|
226 |
}
|
|
227 |
//check file extension
|
|
228 |
TInt result = CheckFileName(iSettings.iLogPath);
|
|
229 |
|
|
230 |
//check drive
|
|
231 |
TInt err = iSettings.CheckDrive(iSettings.iLogPath);
|
|
232 |
|
|
233 |
TBool res = iSettings.CheckPathL(iSettings.iLogPath);
|
|
234 |
|
|
235 |
if(err != KErrNone || result == -1 || !res || !lengthOk)
|
|
236 |
{
|
|
237 |
//invalid drive Error note
|
|
238 |
CAknErrorNote* errorNote = new (ELeave) CAknErrorNote(ETrue);
|
|
239 |
errorNote->ExecuteLD(KINVALIDDRIVEEXT);
|
|
240 |
iSettings.iLogPath = KDefaultLogPath;
|
|
241 |
iSettings.StoreL();
|
|
242 |
}
|
|
243 |
else
|
|
244 |
{
|
|
245 |
if(iSettings.iLogPath.Compare(iPrevLogPath)!=0)
|
|
246 |
{
|
|
247 |
iPrevLogPath.Copy(iSettings.iLogPath);
|
|
248 |
static_cast<CUserEmulatorAppUi*>(iCoeEnv->AppUi())->Logger().CloseFileHandles();
|
|
249 |
}
|
|
250 |
static_cast<CUserEmulatorAppUi*>(iCoeEnv->AppUi())->SetSystemInfoFlag(ETrue);
|
|
251 |
iSettings.StoreL();
|
|
252 |
return EFalse;
|
|
253 |
}
|
|
254 |
}
|
|
255 |
break;
|
|
256 |
}
|
|
257 |
return CAknDialog::OkToExitL(aButtonId);
|
|
258 |
}
|
|
259 |
return ETrue;
|
|
260 |
}
|
|
261 |
|
|
262 |
// -----------------------------------------------------------------------------
|
|
263 |
// CSettingsDialog::CheckFileName
|
|
264 |
// Function to validate file names
|
|
265 |
// -----------------------------------------------------------------------------
|
|
266 |
//
|
|
267 |
TInt CSettingsDialog::CheckFileName(const TDesC& aFilePath)
|
|
268 |
{
|
|
269 |
TInt len = aFilePath.Length();
|
|
270 |
TInt pos = aFilePath.Locate('.');
|
|
271 |
if(pos!=KErrNotFound && (len-pos)>0)
|
|
272 |
{
|
|
273 |
TPtrC fileExt = aFilePath.Right(len - pos);
|
|
274 |
if(fileExt.Compare(KCSVEXT) == 0 || fileExt.Compare(KXMLEXT)==0 )
|
|
275 |
return 0;
|
|
276 |
else
|
|
277 |
return -1;
|
|
278 |
}
|
|
279 |
else
|
|
280 |
return 0;
|
|
281 |
}
|
|
282 |
// -----------------------------------------------------------------------------
|
|
283 |
// CSettingsDialog::OfferKeyEventL
|
|
284 |
// -----------------------------------------------------------------------------
|
|
285 |
//
|
|
286 |
TKeyResponse CSettingsDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
|
|
287 |
{
|
|
288 |
return iSettingsList->OfferKeyEventL(aKeyEvent,aType);
|
|
289 |
}
|
|
290 |
// -----------------------------------------------------------------------------
|
|
291 |
// CSettingsDialog::CountComponentControls
|
|
292 |
// -----------------------------------------------------------------------------
|
|
293 |
//
|
|
294 |
TInt CSettingsDialog::CountComponentControls() const
|
|
295 |
{
|
|
296 |
return CAknDialog::CountComponentControls() + 1;
|
|
297 |
}
|
|
298 |
// -----------------------------------------------------------------------------
|
|
299 |
// CSettingsDialog::ComponentControl
|
|
300 |
// -----------------------------------------------------------------------------
|
|
301 |
//
|
|
302 |
CCoeControl* CSettingsDialog::ComponentControl(TInt aIndex) const
|
|
303 |
{
|
|
304 |
if (!aIndex--)
|
|
305 |
return iSettingsList;
|
|
306 |
return CAknDialog::ComponentControl(aIndex);
|
|
307 |
}
|