|
1 /** |
|
2 * Copyright (c) 2010 Sasken Communication Technologies Ltd. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "{License}" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "{LicenseUrl}". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Narasimhulu Kavadapu, Sasken Communication Technologies Ltd - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Settings UI class of SMF |
|
16 */ |
|
17 |
|
18 #include "SMFSettings.h" |
|
19 #include "qmessagebox.h" |
|
20 #include "qdesktopwidget.h" |
|
21 #include "qmenubar.h" //menubar |
|
22 |
|
23 /* |
|
24 * Constructor |
|
25 * param@Qwidget - Parenet widget |
|
26 */ |
|
27 SMFSettings::SMFSettings(/*QWidget *parent*/) |
|
28 |
|
29 { |
|
30 ui = new Ui::SMFSettingsClass; |
|
31 QWidget *widget = new QWidget; |
|
32 setCentralWidget(widget); |
|
33 //Set up UI |
|
34 ui->setupUi(widget); |
|
35 QDesktopWidget *desktop = QApplication::desktop(); |
|
36 //get client rect. |
|
37 QRect clientRect = desktop->availableGeometry(); |
|
38 widget->setGeometry(clientRect); |
|
39 |
|
40 //createActions(); |
|
41 createMenuActions(); |
|
42 |
|
43 //Instance of CSettingsRepository |
|
44 #ifdef __FOR_SYMBIAN__ |
|
45 iSettingsRepository = CSettingsRepository::NewL(); |
|
46 #else |
|
47 iSettingsRepository = new CPFIndSettings; |
|
48 #endif |
|
49 |
|
50 //Call method to get default/initial settings |
|
51 GetDefaultSettings(); |
|
52 //make a connection for savebutton,on click it should call SaveSettings slot. |
|
53 //connect(ui->SaveButton,SIGNAL(clicked()),this,SLOT(SaveSettings())); |
|
54 //make a connection for Cancelebutton,on click it should clear the settings in UI. |
|
55 //connect(ui->CancelButton,SIGNAL(clicked()),this,SLOT(ClearData())); |
|
56 } |
|
57 |
|
58 /* |
|
59 * Destructor |
|
60 */ |
|
61 SMFSettings::~SMFSettings() |
|
62 { |
|
63 //delete the ui object. |
|
64 delete ui; |
|
65 |
|
66 if(iSettingsRepository){ |
|
67 delete iSettingsRepository; |
|
68 iSettingsRepository = NULL; |
|
69 } |
|
70 } |
|
71 void SMFSettings::createMenuActions() |
|
72 { |
|
73 QAction *saveAct = new QAction(tr("&Save"), this); |
|
74 saveAct->setShortcut(tr("Ctrl+S", "Save")); |
|
75 menuBar()->addAction(saveAct); |
|
76 connect(saveAct, SIGNAL(triggered()), this, SLOT(SaveSettings())); |
|
77 |
|
78 QAction *resetAct = new QAction(tr("&Reset"), this); |
|
79 menuBar()->addAction(resetAct); |
|
80 connect(resetAct, SIGNAL(triggered()), this, SLOT(ClearData())); |
|
81 |
|
82 } |
|
83 /*void SMFSettings::createMenus() |
|
84 { |
|
85 QMenu *saveMenu = menuBar()->addMenu(tr("&Save")); |
|
86 //saveMenu->addAction(saveAct); |
|
87 connect(saveMenu->activeAction(), SIGNAL(triggered()), this, SLOT(SaveSettings())); |
|
88 |
|
89 menuBar()->addSeparator(); |
|
90 |
|
91 QMenu *resetMenu = menuBar()->addMenu(tr("&Reset")); |
|
92 connect(resetMenu->activeAction(), SIGNAL(triggered()), this, SLOT(ClearData())); |
|
93 //resetMenu->addAction(resetAct); |
|
94 }*/ |
|
95 /* |
|
96 * Method to set the PluginDetails to UI |
|
97 * Param - @aPluginStatus,holds the Plgugin Status. |
|
98 */ |
|
99 void SMFSettings::SetPluginDetails(QString aPluginName,QString aPluginStatus) |
|
100 { |
|
101 int indice; |
|
102 |
|
103 indice = ui->PluginlistboxBox->findText(aPluginName); |
|
104 if(indice == -1) |
|
105 ui->PluginlistboxBox->setCurrentIndex(0) ; |
|
106 else |
|
107 ui->PluginlistboxBox->setCurrentIndex(indice) ; |
|
108 |
|
109 indice = ui->pluginstatusbox->findText(aPluginStatus); |
|
110 if(indice == -1) |
|
111 ui->pluginstatusbox->setCurrentIndex(0) ; |
|
112 else |
|
113 ui->pluginstatusbox->setCurrentIndex(indice) ; |
|
114 |
|
115 } |
|
116 /* |
|
117 * Method to set the Auth Expiry Value to UI |
|
118 * Param - @aVal,Auth Expiry Value |
|
119 */ |
|
120 void SMFSettings::SetAuthExpirationValue(QString aVal) |
|
121 { |
|
122 int indice = ui->AuthExplimitbox->findText(aVal); |
|
123 if(indice == -1) |
|
124 ui->AuthExplimitbox->setCurrentIndex(0) ; |
|
125 else |
|
126 ui->AuthExplimitbox->setCurrentIndex(indice) ; |
|
127 } |
|
128 /* |
|
129 * Method to set the Max. Data Transfer Limit to UI |
|
130 * Param - @aVal,Max. Data Transfer Limit Value |
|
131 */ |
|
132 void SMFSettings::SetMaxDataTransferLimit(QString aVal) |
|
133 { |
|
134 int indice = ui->MaxDataTransferlimitBox->findText(aVal); |
|
135 if(indice == -1) |
|
136 ui->MaxDataTransferlimitBox->setCurrentIndex(0) ; |
|
137 else |
|
138 ui->MaxDataTransferlimitBox->setCurrentIndex(indice) ; |
|
139 } |
|
140 /* |
|
141 * Method to set the Roaming Status for Data Transfer to UI |
|
142 * Param - @aStatus,Rpaming Status value for Data Transfer |
|
143 */ |
|
144 void SMFSettings::SetRoamingStatusforDataTransfer(QString aStatus) |
|
145 { |
|
146 int indice = ui->RoamingStatusBox->findText(aStatus); |
|
147 if(indice == -1) |
|
148 ui->RoamingStatusBox->setCurrentIndex(0) ; |
|
149 else |
|
150 ui->RoamingStatusBox->setCurrentIndex(indice) ; |
|
151 } |
|
152 /* |
|
153 * Method to set the Upload File Type to UI |
|
154 * Param - @aStatus,Upload File Type Value |
|
155 */ |
|
156 void SMFSettings::SetUploadFileType(QString aFileType) |
|
157 { |
|
158 int indice = ui->Uploadfiletypebox->findText(aFileType); |
|
159 if(indice == -1) |
|
160 ui->Uploadfiletypebox->setCurrentIndex(0) ; |
|
161 else |
|
162 ui->Uploadfiletypebox->setCurrentIndex(indice) ; |
|
163 } |
|
164 /* |
|
165 * Method to Get the PluginDetails from UI |
|
166 */ |
|
167 QStringList SMFSettings::GetPluginDetails() const |
|
168 { |
|
169 QStringList PluginDetails; |
|
170 PluginDetails.append(ui->PluginlistboxBox->currentText()); |
|
171 PluginDetails.append(ui->pluginstatusbox->currentText()); |
|
172 return PluginDetails; |
|
173 } |
|
174 /* |
|
175 * Method to Get the Auth Expiry Value from UI |
|
176 */ |
|
177 QString SMFSettings::GetAuthExpirationValue() const |
|
178 { |
|
179 return ui->AuthExplimitbox->currentText(); |
|
180 } |
|
181 /* |
|
182 * Method to Get the Max. Data Transfer Limit from UI |
|
183 */ |
|
184 QString SMFSettings::GetMaxDataTransferLimit() const |
|
185 { |
|
186 return ui->MaxDataTransferlimitBox->currentText(); |
|
187 } |
|
188 /* |
|
189 * Method to Get the Roaming Status for Data Transfer from UI |
|
190 */ |
|
191 QString SMFSettings::GetRoamingStatusforDataTransfer() const |
|
192 { |
|
193 return ui->RoamingStatusBox->currentText(); |
|
194 } |
|
195 /* |
|
196 * Method to Get the Upload File Type from UI |
|
197 */ |
|
198 QString SMFSettings::GetUploadFileType() const |
|
199 { |
|
200 return ui->Uploadfiletypebox->currentText(); |
|
201 } |
|
202 /* |
|
203 * Method to Reset the UI settings. |
|
204 */ |
|
205 void SMFSettings::ClearData() |
|
206 { |
|
207 //Reset the |
|
208 ui->PluginlistboxBox->setCurrentIndex(0) ; |
|
209 ui->pluginstatusbox->setCurrentIndex(0) ; |
|
210 ui->AuthExplimitbox->setCurrentIndex(0) ; |
|
211 ui->MaxDataTransferlimitBox->setCurrentIndex(0) ; |
|
212 ui->RoamingStatusBox->setCurrentIndex(0) ; |
|
213 ui->Uploadfiletypebox->setCurrentIndex(0) ; |
|
214 } |
|
215 |
|
216 /* |
|
217 * slot written to set/Save the User input/settings to xml. |
|
218 */ |
|
219 void SMFSettings::SaveSettings() |
|
220 { |
|
221 QStringList PLuginDetails = GetPluginDetails(); |
|
222 |
|
223 #ifdef __FOR_SYMBIAN__ |
|
224 //conversion from QString to Descriptor |
|
225 TPtrC PluginName(static_cast<const TUint16*>(PLuginDetails[0].utf16()), PLuginDetails[0].length()); |
|
226 TPtrC PluginStatus(static_cast<const TUint16*>(PLuginDetails[1].utf16()), PLuginDetails[1].length()); |
|
227 #else |
|
228 QString PluginName(PLuginDetails[0]); |
|
229 QString PluginStatus(PLuginDetails[1]); |
|
230 #endif |
|
231 |
|
232 iSettingsRepository->SetPluginDetails(PluginName,PluginStatus); |
|
233 |
|
234 |
|
235 #ifdef __FOR_SYMBIAN__ |
|
236 //conversion from QString to Descriptor |
|
237 TPtrC AthExpValue(static_cast<const TUint16*>(GetAuthExpirationValue().utf16()), GetAuthExpirationValue().length()); |
|
238 #else |
|
239 QString AthExpValue = GetAuthExpirationValue(); |
|
240 #endif |
|
241 |
|
242 iSettingsRepository->SetAuthExpirationValue(AthExpValue); |
|
243 |
|
244 #ifdef __FOR_SYMBIAN__ |
|
245 //conversion from QString to Descriptor |
|
246 TPtrC MaxDataTrValue(static_cast<const TUint16*>(GetMaxDataTransferLimit().utf16()), GetMaxDataTransferLimit().length()); |
|
247 #else |
|
248 QString MaxDataTrValue = GetMaxDataTransferLimit(); |
|
249 #endif |
|
250 iSettingsRepository->SetMaxDataTransferLimit(MaxDataTrValue); |
|
251 |
|
252 #ifdef __FOR_SYMBIAN__ |
|
253 //conversion from QString to Descriptor |
|
254 TPtrC RoamingStatus(static_cast<const TUint16*>(GetRoamingStatusforDataTransfer().utf16()), GetRoamingStatusforDataTransfer().length()); |
|
255 #else |
|
256 QString RoamingStatus = GetRoamingStatusforDataTransfer(); |
|
257 #endif |
|
258 |
|
259 iSettingsRepository->SetRoamingStatusforDataTransfer(RoamingStatus); |
|
260 |
|
261 #ifdef __FOR_SYMBIAN__ |
|
262 //conversion from QString to Descriptor |
|
263 TPtrC UploadFileType(static_cast<const TUint16*>(GetUploadFileType().utf16()), GetUploadFileType().length()); |
|
264 #else |
|
265 QString UploadFileType = GetUploadFileType(); |
|
266 #endif |
|
267 iSettingsRepository->SetUploadFileType(UploadFileType); |
|
268 |
|
269 |
|
270 //Create information message box |
|
271 QMessageBox::information(this, "Information", "Settings Saved!"); |
|
272 |
|
273 |
|
274 } |
|
275 /* |
|
276 * Method to get the default/initial settings from xml. |
|
277 */ |
|
278 void SMFSettings::GetDefaultSettings() |
|
279 { |
|
280 |
|
281 |
|
282 #ifdef __FOR_SYMBIAN__ |
|
283 QString myString; |
|
284 TBuf<KMaxSettingValue> Buf; |
|
285 //conversion from Descriptor to QString |
|
286 myString = QString::fromUtf16(iSettingsRepository->GetPluginDetails()[0].Ptr(), iSettingsRepository->GetPluginDetails()[0].Length()); |
|
287 QString PluginStatus = QString::fromUtf16(iSettingsRepository->GetPluginDetails()[1].Ptr(), iSettingsRepository->GetPluginDetails()[1].Length()); |
|
288 //Reset the Plugin Details array |
|
289 iSettingsRepository->GetPluginDetails().Close(); |
|
290 SetPluginDetails(myString,PluginStatus); |
|
291 |
|
292 Buf.Copy(iSettingsRepository->GetAuthExpirationValue()); |
|
293 //conversion from Descriptor to QString |
|
294 myString = QString::fromUtf16(Buf.Ptr(), Buf.Length()); |
|
295 SetAuthExpirationValue(myString); |
|
296 |
|
297 Buf.Copy(iSettingsRepository->GetMaxDataTransferLimit()); |
|
298 //conversion from Descriptor to QString |
|
299 myString = QString::fromUtf16(Buf.Ptr(), Buf.Length()); |
|
300 SetMaxDataTransferLimit(myString); |
|
301 |
|
302 Buf.Copy(iSettingsRepository->GetRoamingStatusforDataTransfer()); |
|
303 //conversion from Descriptor to QString |
|
304 myString = QString::fromUtf16(Buf.Ptr(), Buf.Length()); |
|
305 SetRoamingStatusforDataTransfer(myString); |
|
306 |
|
307 Buf.Copy(iSettingsRepository->GetUploadFileType()); |
|
308 //conversion from Descriptor to QString |
|
309 myString = QString::fromUtf16(Buf.Ptr(), Buf.Length()); |
|
310 SetUploadFileType(myString); |
|
311 #else |
|
312 |
|
313 SetPluginDetails(iSettingsRepository->GetPluginDetails()[0],iSettingsRepository->GetPluginDetails()[1]); |
|
314 |
|
315 SetAuthExpirationValue(iSettingsRepository->GetAuthExpirationValue()); |
|
316 SetMaxDataTransferLimit(iSettingsRepository->GetMaxDataTransferLimit()); |
|
317 SetRoamingStatusforDataTransfer(iSettingsRepository->GetRoamingStatusforDataTransfer()); |
|
318 SetUploadFileType(iSettingsRepository->GetUploadFileType()); |
|
319 #endif |
|
320 |
|
321 } |