|
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 |
|
18 |
|
19 #include <hbprogressdialog.h> |
|
20 #include <hbmessagebox.h> |
|
21 |
|
22 #include <hbpopup.h> |
|
23 |
|
24 #include <QString> |
|
25 #include <QDate> |
|
26 |
|
27 #include <e32std.h> |
|
28 #include <e32base.h> |
|
29 |
|
30 #include "creator.hrh" // for command ids |
|
31 #include "notifications.h" |
|
32 #include "enginewrapper.h" |
|
33 #include "engine.h" |
|
34 #include "mainview.h" |
|
35 |
|
36 |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 |
|
40 EngineWrapper::EngineWrapper() |
|
41 : iEngine(0), iProgressDialog(0) |
|
42 { |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 |
|
47 EngineWrapper::~EngineWrapper() |
|
48 { |
|
49 if (iEngine != 0) { |
|
50 delete iEngine; |
|
51 } |
|
52 if (iProgressDialog != 0) { |
|
53 delete iProgressDialog; |
|
54 } |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 |
|
59 bool EngineWrapper::init() |
|
60 { |
|
61 TRAPD(err, iEngine = CCreatorEngine::NewL(this)); |
|
62 if(err != KErrNone) { |
|
63 return false; |
|
64 } |
|
65 else { |
|
66 return true; |
|
67 } |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 |
|
72 MemoryDetails EngineWrapper::GetMemoryDetails() |
|
73 { |
|
74 TMemoryDetails tMemoryDetails = iEngine->GetMemoryDetails(); |
|
75 MemoryDetails memoryDetails; |
|
76 |
|
77 // Convert TMemoryDetails to MemoryDetails |
|
78 memoryDetails.mCFree = QString((QChar*)tMemoryDetails.iCFree.Ptr(), tMemoryDetails.iCFree.Length()); |
|
79 memoryDetails.mDFree = QString((QChar*)tMemoryDetails.iDFree.Ptr(), tMemoryDetails.iDFree.Length()); |
|
80 memoryDetails.mEFree = QString((QChar*)tMemoryDetails.iEFree.Ptr(), tMemoryDetails.iEFree.Length()); |
|
81 memoryDetails.mHFree = QString((QChar*)tMemoryDetails.iHFree.Ptr(), tMemoryDetails.iHFree.Length()); |
|
82 |
|
83 memoryDetails.mCSize = QString((QChar*)tMemoryDetails.iCSize.Ptr(), tMemoryDetails.iCSize.Length()); |
|
84 memoryDetails.mDSize = QString((QChar*)tMemoryDetails.iDSize.Ptr(), tMemoryDetails.iDSize.Length()); |
|
85 memoryDetails.mHSize = QString((QChar*)tMemoryDetails.iHSize.Ptr(), tMemoryDetails.iHSize.Length()); |
|
86 |
|
87 if (tMemoryDetails.iENotAvailable == EFalse) { |
|
88 memoryDetails.mESize = QString((QChar*)tMemoryDetails.iESize.Ptr(), tMemoryDetails.iESize.Length()); |
|
89 memoryDetails.mENotAvailable = false; |
|
90 } |
|
91 else { |
|
92 memoryDetails.mENotAvailable = true; |
|
93 } |
|
94 return memoryDetails; |
|
95 } |
|
96 |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 |
|
100 void EngineWrapper::ShowErrorMessage(const TDesC& aErrorMessage) |
|
101 { |
|
102 QString errorMessage((QChar*)aErrorMessage.Ptr(),aErrorMessage.Length()); |
|
103 Notifications::error(errorMessage); |
|
104 |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 |
|
109 void EngineWrapper::ShowNote(const TDesC& aNoteMessage, TInt aResourceId) |
|
110 { |
|
111 QString note((QChar*)aNoteMessage.Ptr(),aNoteMessage.Length()); |
|
112 Notifications::showGlobalNote(note, HbMessageBox::MessageTypeInformation, HbPopup::ConfirmationNoteTimeout); |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 |
|
117 void EngineWrapper::ShowProgressBar(const TDesC& aPrompt, int aMax) |
|
118 { |
|
119 QString text((QChar*)aPrompt.Ptr(), aPrompt.Length()); |
|
120 iProgressDialog = Notifications::showProgressBar(text, aMax); |
|
121 connect(iProgressDialog, SIGNAL(cancelled()), this, SLOT(ProgressDialogCancelled())); |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 |
|
126 void EngineWrapper::IncrementProgressbarValue() |
|
127 { |
|
128 iProgressDialog->setProgressValue(iProgressDialog->progressValue() + 1); |
|
129 } |
|
130 |
|
131 // --------------------------------------------------------------------------- |
|
132 |
|
133 void EngineWrapper::CloseProgressbar() |
|
134 { |
|
135 delete iProgressDialog; |
|
136 iProgressDialog = 0; |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------------------------- |
|
140 |
|
141 TBool EngineWrapper::EntriesQueryDialog(TInt& aNumberOfEntries, const TDesC& aPrompt, TBool aAcceptsZero) |
|
142 { |
|
143 QString text((QChar*)aPrompt.Ptr(), aPrompt.Length()); |
|
144 bool err = Notifications::entriesQueryDialog(aNumberOfEntries, text, aAcceptsZero); |
|
145 return err; |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------------------------- |
|
149 |
|
150 TBool EngineWrapper::TimeQueryDialog(TTime aTime, const TDesC& aPrompt) |
|
151 { |
|
152 // TTime to QDate |
|
153 TBuf<20> timeString; |
|
154 _LIT(KDateString,"%D%M%Y%/0%1%/1%2%/2%3%/3"); |
|
155 TRAP_IGNORE( aTime.FormatL(timeString, KDateString) ); |
|
156 QString temp = QString::fromUtf16(timeString.Ptr(), timeString.Length()); |
|
157 temp.replace(QChar('/'), QChar('-')); |
|
158 QDate date = QDate::fromString(temp, "dd-MM-yyyy"); |
|
159 |
|
160 QString text((QChar*)aPrompt.Ptr(), aPrompt.Length()); |
|
161 bool err = Notifications::timeQueryDialog(date, text); |
|
162 return err; |
|
163 } |
|
164 |
|
165 TBool EngineWrapper::YesNoQueryDialog(const TDesC& aPrompt) |
|
166 { |
|
167 QString text((QChar*)aPrompt.Ptr(), aPrompt.Length()); |
|
168 return Notifications::yesNoQueryDialog(text); |
|
169 } |
|
170 |
|
171 // --------------------------------------------------------------------------- |
|
172 |
|
173 bool EngineWrapper::ExecuteOptionsMenuCommand(int commandId) |
|
174 { |
|
175 TInt err = KErrNone; |
|
176 if (commandId == ECmdCreateFromFile) { |
|
177 TRAP(err, iEngine->RunScriptL()); |
|
178 } |
|
179 else if (commandId == ECmdSelectRandomDataFile) { |
|
180 TFileName filename; |
|
181 TBool ret = EFalse; |
|
182 TRAP(err, ret = iEngine->GetRandomDataFilenameL(filename)); |
|
183 if (err != KErrNone) { |
|
184 Notifications::error("Error in getting random data."); |
|
185 return false; |
|
186 } |
|
187 if (ret == true) { |
|
188 TRAP(err, iEngine->GetRandomDataFromFileL(filename)); |
|
189 } |
|
190 } |
|
191 else { |
|
192 TRAP(err, iEngine->ExecuteOptionsMenuCommandL(commandId)); |
|
193 } |
|
194 // error handling |
|
195 if(err != KErrNone) { |
|
196 return false; |
|
197 } |
|
198 else { |
|
199 return true; |
|
200 } |
|
201 } |
|
202 |
|
203 // --------------------------------------------------------------------------- |
|
204 |
|
205 bool EngineWrapper::PopupListDialog(const TDesC& aPrompt, CDesCArray* aFileNameArray, TInt& aIndex) |
|
206 { |
|
207 QString text((QChar*)aPrompt.Ptr(), aPrompt.Length()); |
|
208 QStringList itemList; |
|
209 |
|
210 for (int i = 0; i < aFileNameArray->Count(); i++) { |
|
211 itemList.append(QString::fromUtf16( |
|
212 aFileNameArray->MdcaPoint(i).Ptr(), |
|
213 aFileNameArray->MdcaPoint(i).Length())); |
|
214 } |
|
215 // TODO: HbSelectionDialog handle close & user choice |
|
216 Notifications::popupListDialog(text, itemList, HbAbstractItemView::SingleSelection); |
|
217 return false; |
|
218 } |
|
219 |
|
220 // --------------------------------------------------------------------------- |
|
221 |
|
222 bool EngineWrapper::DirectoryQueryDialog(const TDesC& aPrompt, TFileName& aDirectory) |
|
223 { |
|
224 QString text((QChar*)aPrompt.Ptr(), aPrompt.Length()); |
|
225 QString directory = QString((QChar*)aDirectory.Ptr(), aDirectory.Length()); |
|
226 bool ret = Notifications::directoryQueryDialog(text, directory); |
|
227 if (ret == true) { |
|
228 aDirectory = TFileName(directory.utf16()); |
|
229 } |
|
230 return ret; |
|
231 |
|
232 } |
|
233 |
|
234 |
|
235 // --------------------------------------------------------------------------- |
|
236 |
|
237 void EngineWrapper::ProgressDialogCancelled() |
|
238 { |
|
239 CloseProgressbar(); |
|
240 TRAPD(err, iEngine->ProgressDialogCancelledL()); |
|
241 // error handling |
|
242 if(err != KErrNone) { |
|
243 Notifications::error("Error in operation cancel."); |
|
244 } |
|
245 } |
|
246 |
|
247 // --------------------------------------------------------------------------- |
|
248 |
|
249 bool EngineWrapper::ListQueryDialog(const TDesC& aPrompt, TListQueryId aId, TInt& aIndex) |
|
250 { |
|
251 bool ret = false; |
|
252 QString text((QChar*)aPrompt.Ptr(), aPrompt.Length()); |
|
253 QStringList itemList; |
|
254 |
|
255 switch (aId) { |
|
256 case R_CONTACT_CREATION_TYPE_QUERY: { |
|
257 itemList << "Default fields" << "Define..."; |
|
258 break; |
|
259 } |
|
260 case R_GROUP_CREATION_TYPE_QUERY: { |
|
261 itemList << "Random" << "Define..."; |
|
262 break; |
|
263 } |
|
264 case R_MESSAGE_TYPE_QUERY: { |
|
265 itemList << "SMS" << "MMS" << "AMS" << "Email" << "Smart Message" << "IR Message" << "BT Message"; |
|
266 break; |
|
267 } |
|
268 case R_FOLDER_TYPE_QUERY: { |
|
269 itemList << "Inbox" << "Drafts" << "Outbox" << "Sent"; |
|
270 break; |
|
271 } |
|
272 case R_UNREAD_QUERY: { |
|
273 itemList << "Read" << "New"; |
|
274 break; |
|
275 } |
|
276 case R_ATTACHMENT_MULTI_SELECTION_QUERY: { |
|
277 Notifications::error("Not supported resource id."); |
|
278 break; |
|
279 } |
|
280 case R_AMS_ATTACHMENT_SINGLE_SELECTION_QUERY: { |
|
281 itemList << "AMR 20kB"; |
|
282 break; |
|
283 } |
|
284 case R_ATTACHMENT_SINGLE_SELECTION_QUERY: { |
|
285 itemList << "JPEG 25kB" << "JPEG 300kB" << "JPEG 500kB" << "PNG 15kB" << "GIF 2kB" << "RNG 1kB" |
|
286 << "MIDI 10kB" << "WAVE 20kB" << "AMR 20kB" << "Excel 15kB" << "Word 20kB" << "PowerPoint 40kB" |
|
287 << "Text 10kB" << "Text 70kB" << "3GPP 70kB" << "MP3 250kB" << "AAC 100kB" << "RM 95kB"; |
|
288 break; |
|
289 } |
|
290 default: { |
|
291 Notifications::error("Error in resource id."); |
|
292 return ret; |
|
293 } |
|
294 } |
|
295 // TODO: HbSelectionDialog handle close & user choice |
|
296 Notifications::popupListDialog(text, itemList, HbAbstractItemView::SingleSelection); |
|
297 return false; |
|
298 |
|
299 } |
|
300 |
|
301 bool EngineWrapper::ListQueryDialog(const TDesC& aPrompt, TListQueryId aId, CArrayFixFlat<TInt>* aIndexes) |
|
302 { |
|
303 bool ret = false; |
|
304 QString text((QChar*)aPrompt.Ptr(), aPrompt.Length()); |
|
305 QStringList itemList; |
|
306 QList<int> indexes; |
|
307 if (aId == R_ATTACHMENT_MULTI_SELECTION_QUERY) { |
|
308 itemList << "None" << "JPEG 25kB" << "JPEG 300kB" << "JPEG 500kB" << "PNG 15kB" << "GIF 2kB" << "RNG 1kB" |
|
309 << "MIDI 10kB" << "WAVE 20kB" << "AMR 20kB" << "Excel 15kB" << "Word 20kB" << "PowerPoint 40kB" |
|
310 << "Text 10kB" << "Text 70kB" << "3GPP 70kB" << "MP3 250kB" << "AAC 100kB" << "RM 95kB"; |
|
311 |
|
312 //ret = Notifications::popupListDialog(text, itemList, indexes); |
|
313 // TODO: HbSelectionDialog handle close & user choice |
|
314 Notifications::popupListDialog(text, itemList, HbAbstractItemView::MultiSelection); |
|
315 |
|
316 if (ret == true) { |
|
317 aIndexes->Reset(); |
|
318 for (int i = 0; i < indexes.count(); i++) { |
|
319 aIndexes->AppendL(indexes.at(i)); |
|
320 } |
|
321 } |
|
322 } |
|
323 return ret; |
|
324 } |
|
325 |
|
326 void EngineWrapper::CloseCreatorApp() |
|
327 { |
|
328 MainView::closeApp(); |
|
329 } |