|
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 #include <xqconversions.h> |
|
19 #include <hbinputdialog.h> |
|
20 #include <bautils.h> |
|
21 #include <shareuidialog.h> |
|
22 #include <eikenv.h> |
|
23 #include <hbprogressdialog.h> |
|
24 #include <hbaction.h> |
|
25 #include <QDebug> |
|
26 |
|
27 #include "launchermainwindow.h" |
|
28 #include "notifications.h" |
|
29 #include "enginewrapper.h" |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 |
|
33 EngineWrapper::EngineWrapper(LauncherMainWindow* mainWindow) |
|
34 : mEngine(0), |
|
35 mMainWindow(mainWindow), |
|
36 mProgressDialog(0), |
|
37 mWaitDialog(0) |
|
38 { |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 |
|
43 EngineWrapper::~EngineWrapper() |
|
44 { |
|
45 if (mEngine != NULL) { |
|
46 delete mEngine; |
|
47 mEngine = NULL; |
|
48 } |
|
49 if (mProgressDialog != NULL) { |
|
50 delete mProgressDialog; |
|
51 mProgressDialog = NULL; |
|
52 } |
|
53 if (mWaitDialog != NULL) { |
|
54 delete mWaitDialog; |
|
55 mWaitDialog = NULL; |
|
56 } |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 |
|
61 bool EngineWrapper::init() |
|
62 { |
|
63 |
|
64 // construct engine |
|
65 TRAPD(error, mEngine = CLauncherEngine::NewL(this)); |
|
66 if (error != KErrNone) { |
|
67 return false; |
|
68 } |
|
69 |
|
70 return true; |
|
71 |
|
72 } |
|
73 |
|
74 // --------------------------------------------------------------------------- |
|
75 |
|
76 bool EngineWrapper::listOfAllApps(QStringList &allAppsQStringList){ |
|
77 |
|
78 // Get application CDesCArray list from engine |
|
79 CDesCArray* allAppsCDescArray = 0; |
|
80 TRAPD(error, allAppsCDescArray = mEngine->ListOfAllAppsL()); |
|
81 if(error != KErrNone) { |
|
82 return false; |
|
83 } |
|
84 |
|
85 //convert CDesCArray to QStringList |
|
86 for (int i = 0; i < allAppsCDescArray->Count(); i++) { |
|
87 allAppsQStringList.append(QString::fromUtf16( |
|
88 allAppsCDescArray->MdcaPoint(i).Ptr(), |
|
89 allAppsCDescArray->MdcaPoint(i).Length())); |
|
90 } |
|
91 return true; |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 bool EngineWrapper::startAppLaunching(const QModelIndexList &qList, bool autoClose) |
|
96 { |
|
97 |
|
98 // check if used has not selected any files |
|
99 if (qList.size() == 0) { |
|
100 Notifications::showErrorNote("Nothing selected"); |
|
101 return false; |
|
102 } |
|
103 |
|
104 bool retval(true); |
|
105 CArrayFix<TInt>* pArrayFix = NULL; |
|
106 try{ |
|
107 // Create CArrayFix for application numbers that are launched and Qlist into CArrayFix |
|
108 QT_TRAP_THROWING( pArrayFix = QModelIndexListToCArrayFixL(qList) ); |
|
109 |
|
110 // Start launching applications |
|
111 QT_TRAP_THROWING(mEngine->StartAppLaunchingL(pArrayFix, autoClose ? ETrue : EFalse)); |
|
112 } |
|
113 catch (const std::exception &e){ |
|
114 qDebug() << "EngineWrapper::startAppLaunching - exception: " << e.what(); |
|
115 retval = false; |
|
116 } |
|
117 |
|
118 if(pArrayFix) |
|
119 delete pArrayFix; |
|
120 |
|
121 return retval; |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 |
|
126 bool EngineWrapper::stopLaunching() |
|
127 { |
|
128 TRAPD(error, mEngine->StopLaunchingL()); |
|
129 if (error != KErrNone) { |
|
130 return false; |
|
131 } |
|
132 else { |
|
133 return true; |
|
134 } |
|
135 } |
|
136 |
|
137 // --------------------------------------------------------------------------- |
|
138 |
|
139 bool EngineWrapper::sendLog() |
|
140 { |
|
141 ShareUi dialog; |
|
142 QList<QVariant> fileList; |
|
143 |
|
144 if( mEngine->LogFileExists() ) |
|
145 { |
|
146 const TDesC& logFilePath = mEngine->LogFilePath(); |
|
147 fileList.append( QString::fromUtf16( logFilePath.Ptr(), logFilePath.Length() ) ); |
|
148 } |
|
149 if( mEngine->BCLogFileExists() ) |
|
150 { |
|
151 const TDesC& BCLogFilePath = mEngine->BCLogFilePath(); |
|
152 fileList.append( QString::fromUtf16( BCLogFilePath.Ptr(), BCLogFilePath.Length() ) ); |
|
153 } |
|
154 |
|
155 if( !fileList.empty()){ |
|
156 dialog.init(fileList,true); |
|
157 return true; |
|
158 } |
|
159 else{ |
|
160 return false; |
|
161 } |
|
162 |
|
163 } |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 |
|
167 bool EngineWrapper::deleteLog() |
|
168 { |
|
169 // if log file exists delete it. |
|
170 if (mEngine->LogFileExists()) { |
|
171 if (mEngine->DeleteLogFile() != KErrNone) { |
|
172 return false; |
|
173 } |
|
174 } |
|
175 |
|
176 //if BC log file exists, delete it. |
|
177 if (mEngine->BCLogFileExists()) { |
|
178 if (mEngine->DeleteBCLogFile() != KErrNone) { |
|
179 return false; |
|
180 } |
|
181 } |
|
182 |
|
183 return true; |
|
184 |
|
185 } |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 |
|
189 bool EngineWrapper::sendListOfDlls() |
|
190 { |
|
191 const TDesC& systemDllsFilePath = mEngine->SystemDllsFilePath(); |
|
192 |
|
193 if ( BaflUtils::FileExists( CEikonEnv::Static()->FsSession(), systemDllsFilePath) ){ |
|
194 ShareUi dialog; |
|
195 QList<QVariant> fileList; |
|
196 fileList.append( QString::fromUtf16( systemDllsFilePath.Ptr(), systemDllsFilePath.Length() ) ); |
|
197 dialog.init(fileList,true); |
|
198 return true; |
|
199 } |
|
200 else{ |
|
201 Notifications::showErrorNote("DLL list does not exist"); |
|
202 return false; |
|
203 } |
|
204 } |
|
205 |
|
206 // --------------------------------------------------------------------------- |
|
207 |
|
208 void EngineWrapper::doCompareDlls(HbAction* action) |
|
209 { |
|
210 HbInputDialog *dlg = static_cast<HbInputDialog*>(sender()); |
|
211 if( action && !action->text().compare("ok", Qt::CaseInsensitive) ) |
|
212 { |
|
213 TFileName fileName( dlg->value().toString().utf16() ); |
|
214 TRAPD(error, mEngine->AnalyseDLLsL( fileName ) ); |
|
215 if( error != KErrNone ) |
|
216 { |
|
217 HideWaitDialog(); |
|
218 HideProgressBar(); |
|
219 Notifications::showErrorNote( QString("Error in analyse: %1").arg( error ) ); |
|
220 } |
|
221 } |
|
222 } |
|
223 |
|
224 // --------------------------------------------------------------------------- |
|
225 |
|
226 void EngineWrapper::compareDlls() |
|
227 { |
|
228 const TDesC& requiredDllsFileName = mEngine->RequiredDllsFilePath(); |
|
229 QString fileName = QString::fromUtf16( requiredDllsFileName.Ptr(), requiredDllsFileName.Length() ); |
|
230 HbInputDialog::getText( "Select input file for BC analysis:", this, SLOT(doCompareDlls(HbAction*)), fileName ); |
|
231 } |
|
232 |
|
233 // --------------------------------------------------------------------------- |
|
234 void EngineWrapper::ShowProgressBar(const TDesC& descText, TInt minimum, TInt maximum) |
|
235 { |
|
236 QString qStringText = XQConversions::s60DescToQString(descText); |
|
237 |
|
238 if(mProgressDialog){ |
|
239 delete mProgressDialog; |
|
240 mProgressDialog = NULL; |
|
241 } |
|
242 mProgressDialog = new HbProgressDialog( HbProgressDialog::ProgressDialog ); |
|
243 |
|
244 if( maximum > 0 ) |
|
245 mProgressDialog->setRange(minimum, maximum); |
|
246 //iProgressDialog->setAutoClose(true); |
|
247 mProgressDialog->setText(qStringText); |
|
248 connect(mProgressDialog, SIGNAL(cancelled()), this, SLOT(CancelDllBCanalysis())); |
|
249 mProgressDialog->show(); |
|
250 } |
|
251 |
|
252 // --------------------------------------------------------------------------- |
|
253 void EngineWrapper::SetProgressBarValue(TInt value) |
|
254 { |
|
255 if (mProgressDialog && value > 0 ){ |
|
256 mProgressDialog->setProgressValue(value); |
|
257 } |
|
258 } |
|
259 |
|
260 // --------------------------------------------------------------------------- |
|
261 void EngineWrapper::HideProgressBar() |
|
262 { |
|
263 if (mProgressDialog != NULL) { |
|
264 disconnect(mProgressDialog, SIGNAL(cancelled), this, SLOT(CancelDllBCanalysis())); |
|
265 delete mProgressDialog; |
|
266 mProgressDialog = NULL; |
|
267 } |
|
268 } |
|
269 |
|
270 // --------------------------------------------------------------------------- |
|
271 void EngineWrapper::CancelDllBCanalysis() |
|
272 { |
|
273 mEngine->CancelBCAnalysis(); |
|
274 } |
|
275 |
|
276 // --------------------------------------------------------------------------- |
|
277 void EngineWrapper::ShowWaitDialog(const TDesC& descText) |
|
278 { |
|
279 QString qStringText = XQConversions::s60DescToQString(descText); |
|
280 |
|
281 if(mWaitDialog){ |
|
282 delete mWaitDialog; |
|
283 mWaitDialog = NULL; |
|
284 } |
|
285 mWaitDialog = Notifications::showWaitDialog(qStringText); |
|
286 } |
|
287 |
|
288 // --------------------------------------------------------------------------- |
|
289 void EngineWrapper::HideWaitDialog() |
|
290 { |
|
291 if (mWaitDialog != NULL) { |
|
292 delete mWaitDialog; |
|
293 mWaitDialog = NULL; |
|
294 } |
|
295 } |
|
296 |
|
297 // --------------------------------------------------------------------------- |
|
298 |
|
299 void EngineWrapper::setSkipHiddenAndEmbedOnly(bool skip) |
|
300 { |
|
301 if(skip) { |
|
302 mEngine->SetSkipHiddenAndEmbedOnly(ETrue); |
|
303 } |
|
304 else { |
|
305 mEngine->SetSkipHiddenAndEmbedOnly(EFalse); |
|
306 } |
|
307 } |
|
308 |
|
309 // --------------------------------------------------------------------------- |
|
310 |
|
311 void EngineWrapper::ChangeFocusToOutputView() |
|
312 { |
|
313 mMainWindow->openOutputView(); |
|
314 } |
|
315 |
|
316 // --------------------------------------------------------------------------- |
|
317 |
|
318 void EngineWrapper::PrintText(const TDesC& descText) |
|
319 { |
|
320 |
|
321 // Convert the descriptor to QString |
|
322 QString qStringText = XQConversions::s60DescToQString(descText); |
|
323 mMainWindow->printText(qStringText); |
|
324 } |
|
325 |
|
326 // --------------------------------------------------------------------------- |
|
327 |
|
328 CArrayFix<TInt>* EngineWrapper::QModelIndexListToCArrayFixL(const QModelIndexList& qlist) |
|
329 { |
|
330 CArrayFix<TInt>* pArrayFix = new (ELeave) CArrayFixFlat<TInt>( qlist.size() ); |
|
331 CleanupStack::PushL(pArrayFix); |
|
332 for (int j = 0; j < qlist.size(); j++) { |
|
333 pArrayFix->AppendL(qlist.at(j).row()); |
|
334 } |
|
335 CleanupStack::Pop(pArrayFix); |
|
336 return pArrayFix; |
|
337 } |
|
338 |
|
339 // --------------------------------------------------------------------------- |
|
340 |
|
341 void EngineWrapper::ShowErrorMessage(const TDesC& descText) |
|
342 { |
|
343 QString qStringText = XQConversions::s60DescToQString(descText); |
|
344 Notifications::showErrorNote(qStringText); |
|
345 } |
|
346 |
|
347 // --------------------------------------------------------------------------- |
|
348 |
|
349 void EngineWrapper::ShowInfoMessage(const TDesC& descText) |
|
350 { |
|
351 QString qStringText = XQConversions::s60DescToQString(descText); |
|
352 Notifications::showInformationNote(qStringText); |
|
353 } |
|
354 |
|
355 // End of File |