24 #include <hbcombobox.h> |
24 #include <hbcombobox.h> |
25 #include <hblabel.h> |
25 #include <hblabel.h> |
26 #include <hbmessagebox.h> |
26 #include <hbmessagebox.h> |
27 #include <QGraphicsLinearLayout> |
27 #include <QGraphicsLinearLayout> |
28 #include <QDir> |
28 #include <QDir> |
29 |
29 #include <xqappmgr.h> // XQApplicationManager |
30 #define INSTALLS_PATH "C:\\Data\\Installs\\" |
30 #include <usif/scr/scr.h> // RSoftwareComponentRegistry |
|
31 |
|
32 using namespace Usif; |
|
33 |
|
34 #define INSTALLS_PATH_1 "C:\\Data\\Installs\\" |
|
35 #define INSTALLS_PATH_2 "E:\\Installs\\" |
|
36 #define INSTALLS_PATH_3 "F:\\Installs\\" |
|
37 #define INSTALLS_PATH_4 "C:\\" |
|
38 #define INSTALLS_PATH_5 "E:\\" |
|
39 #define INSTALLS_PATH_6 "F:\\" |
31 |
40 |
32 |
41 |
33 TestInstaller::TestInstaller(int& argc, char* argv[]) : HbApplication(argc, argv), |
42 TestInstaller::TestInstaller(int& argc, char* argv[]) : HbApplication(argc, argv), |
34 mMainWindow(0), mMainView(0), mFileNames(), mSelectableFiles(0), |
43 mMainWindow(0), mMainView(0), mUseSilentInstall(false), |
35 mUseSilentInstall(false), mRunner(0) |
44 mInstallDirectories(0), mInstallableFiles(0), mRemovableApps(0), |
|
45 mCurrentDirPath(), mCurrentFile(), mRunner(0) |
36 { |
46 { |
37 mMainWindow = new HbMainWindow(); |
47 mMainWindow = new HbMainWindow(); |
38 mMainView = new HbView(); |
48 mMainView = new HbView(); |
39 mMainView->setTitle(tr("Test Installer")); |
49 mMainView->setTitle(tr("Test Installer")); |
40 |
50 |
41 QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical); |
51 QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical); |
42 |
52 |
43 mSelectableFiles = new HbComboBox; |
|
44 mSelectableFiles->setEditable(false); |
|
45 connect(mSelectableFiles, SIGNAL(currentIndexChanged(int)), |
|
46 this, SLOT(selectedFileChanged(int))); |
|
47 layout->addItem(mSelectableFiles); |
|
48 |
|
49 HbCheckBox *silentInstallCheckBox = new HbCheckBox; |
53 HbCheckBox *silentInstallCheckBox = new HbCheckBox; |
50 silentInstallCheckBox->setText(tr("Silent install")); |
54 silentInstallCheckBox->setText(tr("Silent install/uninstall")); |
51 connect(silentInstallCheckBox, SIGNAL(stateChanged(int)), this, SLOT(silentCheckChanged(int))); |
55 connect(silentInstallCheckBox, SIGNAL(stateChanged(int)), |
|
56 this, SLOT(silentCheckChanged(int))); |
52 layout->addItem(silentInstallCheckBox); |
57 layout->addItem(silentInstallCheckBox); |
|
58 layout->addStretch(); |
|
59 |
|
60 HbLabel *installTitle = new HbLabel(tr("Install:")); |
|
61 layout->addItem(installTitle); |
|
62 |
|
63 mInstallDirectories = new HbComboBox; |
|
64 mInstallDirectories->setEditable(false); |
|
65 QStringList dirList; |
|
66 getInstallDirs(dirList); |
|
67 mInstallDirectories->setItems(dirList); |
|
68 connect(mInstallDirectories, SIGNAL(currentIndexChanged(int)), |
|
69 this, SLOT(installableDirChanged(int))); |
|
70 layout->addItem(mInstallDirectories); |
|
71 |
|
72 mInstallableFiles = new HbComboBox; |
|
73 mInstallableFiles->setEditable(false); |
|
74 connect(mInstallableFiles, SIGNAL(currentIndexChanged(int)), |
|
75 this, SLOT(installableFileChanged(int))); |
|
76 layout->addItem(mInstallableFiles); |
53 |
77 |
54 HbPushButton *installNew = new HbPushButton(tr("Install using new API")); |
78 HbPushButton *installNew = new HbPushButton(tr("Install using new API")); |
55 layout->addItem(installNew); |
79 layout->addItem(installNew); |
56 HbPushButton *installOld = new HbPushButton(tr("Install using old API")); |
80 HbPushButton *installOld = new HbPushButton(tr("Install using old API")); |
57 layout->addItem(installOld); |
81 layout->addItem(installOld); |
|
82 HbPushButton *launchApp = new HbPushButton(tr("Install by opening file")); |
|
83 layout->addItem(launchApp); |
|
84 connect(installNew, SIGNAL(clicked()), this, SLOT(installUsingNewApi())); |
|
85 connect(installOld, SIGNAL(clicked()), this, SLOT(installUsingOldApi())); |
|
86 connect(launchApp, SIGNAL(clicked()), this, SLOT(installByOpeningFile())); |
|
87 layout->addStretch(); |
|
88 |
|
89 HbLabel *uninstallTitle = new HbLabel(tr("Uninstall:")); |
|
90 layout->addItem(uninstallTitle); |
|
91 mRemovableApps = new HbComboBox; |
|
92 mRemovableApps->setEditable(false); |
|
93 layout->addItem(mRemovableApps); |
|
94 |
|
95 HbPushButton *removeNew = new HbPushButton(tr("Remove using new API")); |
|
96 layout->addItem(removeNew); |
|
97 HbPushButton *removeOld = new HbPushButton(tr("Remove using old API")); |
|
98 layout->addItem(removeOld); |
|
99 connect(removeNew, SIGNAL(clicked()), this, SLOT(removeUsingNewApi())); |
|
100 connect(removeOld, SIGNAL(clicked()), this, SLOT(removeUsingOldApi())); |
|
101 layout->addStretch(); |
|
102 |
58 HbPushButton *quit = new HbPushButton(tr("Exit")); |
103 HbPushButton *quit = new HbPushButton(tr("Exit")); |
59 layout->addItem(quit); |
104 layout->addItem(quit); |
60 |
105 |
61 connect(installNew, SIGNAL(clicked()), this, SLOT(installUsingNewApi())); |
|
62 connect(installOld, SIGNAL(clicked()), this, SLOT(installUsingOldApi())); |
|
63 connect(quit, SIGNAL(clicked()), this, SLOT(closeApp())); |
106 connect(quit, SIGNAL(clicked()), this, SLOT(closeApp())); |
64 |
107 |
65 mMainView->setLayout(layout); |
108 mMainView->setLayout(layout); |
66 mMainWindow->addView(mMainView); |
109 mMainWindow->addView(mMainView); |
67 mMainWindow->show(); |
110 mMainWindow->show(); |
68 |
111 |
69 changeDir(INSTALLS_PATH); |
112 changeDir(mInstallDirectories->currentText()); |
|
113 getRemovableApps(); |
70 } |
114 } |
71 |
115 |
72 TestInstaller::~TestInstaller() |
116 TestInstaller::~TestInstaller() |
73 { |
117 { |
74 delete mRunner; |
118 delete mRunner; |
75 delete mMainView; |
119 delete mMainView; |
76 delete mMainWindow; |
120 delete mMainWindow; |
77 } |
121 } |
78 |
122 |
79 void TestInstaller::selectedFileChanged(int /*index*/) |
|
80 { |
|
81 if (mSelectableFiles) { |
|
82 mFileNames.clear(); |
|
83 QString selectedFile(mDirPath); |
|
84 selectedFile.append(mSelectableFiles->currentText()); |
|
85 mFileNames.append(selectedFile); |
|
86 } |
|
87 } |
|
88 |
|
89 void TestInstaller::silentCheckChanged(int state) |
123 void TestInstaller::silentCheckChanged(int state) |
90 { |
124 { |
91 Qt::CheckState s = static_cast<Qt::CheckState>(state); |
125 Qt::CheckState s = static_cast<Qt::CheckState>(state); |
92 mUseSilentInstall = (s == Qt::Checked); |
126 mUseSilentInstall = (s == Qt::Checked); |
93 } |
127 } |
94 |
128 |
|
129 void TestInstaller::installableDirChanged(int /*index*/) |
|
130 { |
|
131 if (mInstallDirectories) { |
|
132 changeDir(mInstallDirectories->currentText()); |
|
133 } |
|
134 } |
|
135 |
|
136 void TestInstaller::installableFileChanged(int /*index*/) |
|
137 { |
|
138 if (mInstallableFiles) { |
|
139 mCurrentFile = mCurrentDirPath; |
|
140 mCurrentFile.append(mInstallableFiles->currentText()); |
|
141 } |
|
142 } |
|
143 |
95 void TestInstaller::installUsingNewApi() |
144 void TestInstaller::installUsingNewApi() |
96 { |
145 { |
97 createRunner(true); |
146 if (isFileSelected() && createRunner(true)) { |
|
147 doInstall(mCurrentFile); |
|
148 } |
98 } |
149 } |
99 |
150 |
100 void TestInstaller::installUsingOldApi() |
151 void TestInstaller::installUsingOldApi() |
101 { |
152 { |
102 createRunner(false); |
153 if (isFileSelected() && createRunner(false)) { |
|
154 doInstall(mCurrentFile); |
|
155 } |
|
156 } |
|
157 |
|
158 void TestInstaller::installByOpeningFile() |
|
159 { |
|
160 if (mInstallableFiles) { |
|
161 doOpenFile(mCurrentFile); |
|
162 } |
|
163 } |
|
164 |
|
165 void TestInstaller::removeUsingNewApi() |
|
166 { |
|
167 if (isFileSelected() && createRunner(true)) { |
|
168 removeSelectedUsingNewApi(); |
|
169 } |
|
170 } |
|
171 |
|
172 void TestInstaller::removeUsingOldApi() |
|
173 { |
|
174 if (isFileSelected() && createRunner(false)) { |
|
175 removeSelectedUsingOldApi(); |
|
176 } |
103 } |
177 } |
104 |
178 |
105 void TestInstaller::handleComplete() |
179 void TestInstaller::handleComplete() |
106 { |
180 { |
107 HbMessageBox::information(tr("Installed")); |
181 HbMessageBox::information(tr("Completed")); |
108 |
182 |
109 delete mRunner; |
183 delete mRunner; |
110 mRunner = 0; |
184 mRunner = 0; |
|
185 |
|
186 changeDir(mCurrentDirPath); |
|
187 getRemovableApps(); |
111 } |
188 } |
112 |
189 |
113 void TestInstaller::handleError(int error) |
190 void TestInstaller::handleError(int error) |
114 { |
191 { |
115 QString messageText; |
192 QString messageText; |
127 void TestInstaller::closeApp() |
204 void TestInstaller::closeApp() |
128 { |
205 { |
129 qApp->exit(); |
206 qApp->exit(); |
130 } |
207 } |
131 |
208 |
|
209 void TestInstaller::fileOpenOk(const QVariant &/*result*/) |
|
210 { |
|
211 HbMessageBox::information(tr("Open ok")); |
|
212 } |
|
213 |
|
214 void TestInstaller::fileOpenFailed(int errorCode, const QString &errorMsg) |
|
215 { |
|
216 HbMessageBox::warning(tr("Open failed: %1: %2").arg(errorCode).arg(errorMsg)); |
|
217 } |
|
218 |
|
219 void TestInstaller::getInstallDirs(QStringList& dirList) |
|
220 { |
|
221 QStringList possibleDirs; |
|
222 possibleDirs << INSTALLS_PATH_1 << INSTALLS_PATH_2 << INSTALLS_PATH_3 |
|
223 << INSTALLS_PATH_4 << INSTALLS_PATH_5 << INSTALLS_PATH_6; |
|
224 |
|
225 QListIterator<QString> iter(possibleDirs); |
|
226 while (iter.hasNext()) { |
|
227 QString dirName(iter.next()); |
|
228 QDir dir(dirName); |
|
229 if (dir.exists()) { |
|
230 dirList.append(dirName); |
|
231 } |
|
232 } |
|
233 } |
|
234 |
132 void TestInstaller::changeDir(const QString& dirPath) |
235 void TestInstaller::changeDir(const QString& dirPath) |
133 { |
236 { |
134 bool filesFound = false; |
|
135 |
|
136 QDir dir(dirPath); |
237 QDir dir(dirPath); |
137 if (dir.exists()) { |
238 if (dir.exists()) { |
138 mDirPath = dirPath; |
239 mCurrentDirPath = dirPath; |
139 mSelectableFiles->clear(); |
240 mInstallableFiles->clear(); |
140 |
241 |
141 QFileInfoList list = dir.entryInfoList(QDir::Files); |
242 QFileInfoList list = dir.entryInfoList(QDir::Files); |
142 QListIterator<QFileInfo> iter(list); |
243 QListIterator<QFileInfo> iter(list); |
143 while (iter.hasNext()) { |
244 while (iter.hasNext()) { |
144 const QFileInfo &info(iter.next()); |
245 const QFileInfo &info(iter.next()); |
145 mSelectableFiles->addItem(info.fileName()); |
246 mInstallableFiles->addItem(info.fileName()); |
146 } |
247 } |
147 filesFound = (mSelectableFiles->count() > 0); |
248 |
148 |
249 mCurrentFile.clear(); |
149 mFileNames.clear(); |
250 if (mInstallableFiles->count()) { |
150 if (filesFound) { |
251 mCurrentFile = mCurrentDirPath; |
151 QString fileSelectedByDefault(dirPath); |
252 mCurrentFile.append(mInstallableFiles->currentText()); |
152 fileSelectedByDefault.append(mSelectableFiles->currentText()); |
253 } |
153 mFileNames.append(fileSelectedByDefault); |
254 } |
154 } |
255 } |
155 } |
256 |
156 |
257 void TestInstaller::getRemovableApps() |
157 if (!filesFound) { |
258 { |
158 HbMessageBox::warning(tr("No files in '%1'").arg(dirPath)); |
259 TRAP_IGNORE(doGetRemovableAppsL()); |
159 } |
260 } |
160 } |
261 |
161 |
262 void TestInstaller::doGetRemovableAppsL() |
162 void TestInstaller::createRunner(bool useSif) |
263 { |
163 { |
264 mRemovableApps->clear(); |
164 if (!mFileNames.count()) { |
265 mRemovableComponentIds.clear(); |
|
266 mRemovableUids.clear(); |
|
267 mRemovableSoftwareTypes.clear(); |
|
268 |
|
269 RSoftwareComponentRegistry registry; |
|
270 User::LeaveIfError(registry.Connect()); |
|
271 CleanupClosePushL(registry); |
|
272 |
|
273 RArray<TComponentId> componentIdList; |
|
274 registry.GetComponentIdsL(componentIdList); |
|
275 for (int i = 0; i < componentIdList.Count(); ++i) { |
|
276 TComponentId compId = componentIdList[i]; |
|
277 CComponentEntry *compEntry = CComponentEntry::NewLC(); |
|
278 if (registry.GetComponentL(compId, *compEntry)) { |
|
279 if (compEntry->IsRemovable()) { |
|
280 TPtrC compName = compEntry->Name(); |
|
281 QString name = QString::fromUtf16(compName.Ptr(), compName.Length()); |
|
282 mRemovableApps->addItem(name); |
|
283 |
|
284 mRemovableComponentIds.append(compId); |
|
285 |
|
286 _LIT(KCompUid, "CompUid"); |
|
287 CPropertyEntry *property = registry.GetComponentPropertyL(compId, KCompUid); |
|
288 CleanupStack::PushL(property); |
|
289 CIntPropertyEntry* intProperty = dynamic_cast<CIntPropertyEntry*>(property); |
|
290 mRemovableUids.append(TUid::Uid(intProperty->IntValue())); |
|
291 CleanupStack::PopAndDestroy(property); |
|
292 |
|
293 TPtrC softwareType = compEntry->SoftwareType(); |
|
294 if (softwareType == KSoftwareTypeNative) { |
|
295 mRemovableSoftwareTypes.append(Native); |
|
296 } else if (softwareType == KSoftwareTypeJava) { |
|
297 mRemovableSoftwareTypes.append(Java); |
|
298 } else { |
|
299 mRemovableSoftwareTypes.append(Unknown); |
|
300 } |
|
301 } |
|
302 } |
|
303 CleanupStack::PopAndDestroy(compEntry); |
|
304 } |
|
305 |
|
306 CleanupStack::PopAndDestroy(®istry); |
|
307 } |
|
308 |
|
309 bool TestInstaller::isFileSelected() |
|
310 { |
|
311 if (mCurrentFile.isEmpty()) { |
165 HbMessageBox::warning(tr("No files selected")); |
312 HbMessageBox::warning(tr("No files selected")); |
166 changeDir(INSTALLS_PATH); |
313 changeDir(mCurrentDirPath); |
|
314 return false; |
|
315 } |
|
316 return true; |
|
317 } |
|
318 |
|
319 bool TestInstaller::createRunner(bool useSif) |
|
320 { |
|
321 if (!mRunner) { |
|
322 mRunner = new ActiveRunner(useSif); |
|
323 connect(mRunner, SIGNAL(opCompleted()), this, SLOT(handleComplete())); |
|
324 connect(mRunner, SIGNAL(opFailed(int)), this, SLOT(handleError(int))); |
167 } else { |
325 } else { |
168 if (!mRunner) { |
326 HbMessageBox::warning(tr("Already running")); |
169 mRunner = new ActiveRunner(useSif); |
327 return false; |
170 connect(mRunner, SIGNAL(opCompleted()), this, SLOT(handleComplete())); |
328 } |
171 connect(mRunner, SIGNAL(opFailed(int)), this, SLOT(handleError(int))); |
329 return true; |
172 installSelected(); |
|
173 } else { |
|
174 HbMessageBox::warning(tr("Already running")); |
|
175 } |
|
176 } |
|
177 } |
|
178 |
|
179 void TestInstaller::installSelected() |
|
180 { |
|
181 if (mFileNames.count()) { |
|
182 QStringListIterator fileNamesIterator(mFileNames); |
|
183 while (fileNamesIterator.hasNext()) { |
|
184 doInstall(fileNamesIterator.next()); |
|
185 } |
|
186 } |
|
187 } |
330 } |
188 |
331 |
189 void TestInstaller::doInstall(const QString &fileName) |
332 void TestInstaller::doInstall(const QString &fileName) |
190 { |
333 { |
191 if (mRunner) { |
334 if (mRunner) { |
192 mRunner->install(fileName, mUseSilentInstall); |
335 mRunner->install(fileName, mUseSilentInstall); |
193 } |
336 } |
194 } |
337 } |
195 |
338 |
|
339 void TestInstaller::doOpenFile(const QString &fileName) |
|
340 { |
|
341 QFile file(fileName); |
|
342 if (file.exists()) { |
|
343 XQApplicationManager appManager; |
|
344 XQAiwRequest *request = appManager.create(file); |
|
345 if (request) { |
|
346 connect(request, SIGNAL(requestOk(const QVariant &)), |
|
347 this, SLOT(fileOpenOk(const QVariant &))); |
|
348 connect(request, SIGNAL(requestError(int, const QString &)), |
|
349 this, SLOT(fileOpenFailed(int, const QString &))); |
|
350 QList<QVariant> args; |
|
351 args << file.fileName(); |
|
352 request->setArguments(args); |
|
353 if (request->send()) { |
|
354 HbMessageBox::information(tr("Opening...")); |
|
355 } else { |
|
356 HbMessageBox::warning(tr("Cannot open")); |
|
357 } |
|
358 delete request; |
|
359 } else { |
|
360 HbMessageBox::warning(tr("No handler for file '%1'").arg(fileName)); |
|
361 } |
|
362 } |
|
363 } |
|
364 |
|
365 void TestInstaller::removeSelectedUsingNewApi() |
|
366 { |
|
367 if (mRemovableApps && mRunner) { |
|
368 int index = mRemovableApps->currentIndex(); |
|
369 const TComponentId &compId(mRemovableComponentIds.at(index)); |
|
370 mRunner->remove(compId, mUseSilentInstall); |
|
371 } |
|
372 } |
|
373 |
|
374 void TestInstaller::removeSelectedUsingOldApi() |
|
375 { |
|
376 if (mRemovableApps && mRunner) { |
|
377 int index = mRemovableApps->currentIndex(); |
|
378 const TUid &uid(mRemovableUids.at(index)); |
|
379 |
|
380 if (mRemovableSoftwareTypes.at(index) == Native) { |
|
381 _LIT8(KSisxMimeType, "x-epoc/x-sisx-app"); |
|
382 mRunner->remove(uid, KSisxMimeType, mUseSilentInstall); |
|
383 } else if (mRemovableSoftwareTypes.at(index) == Java) { |
|
384 _LIT8(KJarMIMEType, "application/java-archive"); |
|
385 mRunner->remove(uid, KJarMIMEType, mUseSilentInstall); |
|
386 } else { |
|
387 HbMessageBox::warning(tr("Not supported software type")); |
|
388 delete mRunner; |
|
389 mRunner = 0; |
|
390 } |
|
391 } |
|
392 } |
|
393 |