--- a/appinstaller/AppinstUi/sisxsifplugin/tsrc/testinstaller/testinstaller.cpp Fri Apr 16 15:05:20 2010 +0300
+++ b/appinstaller/AppinstUi/sisxsifplugin/tsrc/testinstaller/testinstaller.cpp Mon May 03 12:38:03 2010 +0300
@@ -26,13 +26,23 @@
#include <hbmessagebox.h>
#include <QGraphicsLinearLayout>
#include <QDir>
+#include <xqappmgr.h> // XQApplicationManager
+#include <usif/scr/scr.h> // RSoftwareComponentRegistry
-#define INSTALLS_PATH "C:\\Data\\Installs\\"
+using namespace Usif;
+
+#define INSTALLS_PATH_1 "C:\\Data\\Installs\\"
+#define INSTALLS_PATH_2 "E:\\Installs\\"
+#define INSTALLS_PATH_3 "F:\\Installs\\"
+#define INSTALLS_PATH_4 "C:\\"
+#define INSTALLS_PATH_5 "E:\\"
+#define INSTALLS_PATH_6 "F:\\"
TestInstaller::TestInstaller(int& argc, char* argv[]) : HbApplication(argc, argv),
- mMainWindow(0), mMainView(0), mFileNames(), mSelectableFiles(0),
- mUseSilentInstall(false), mRunner(0)
+ mMainWindow(0), mMainView(0), mUseSilentInstall(false),
+ mInstallDirectories(0), mInstallableFiles(0), mRemovableApps(0),
+ mCurrentDirPath(), mCurrentFile(), mRunner(0)
{
mMainWindow = new HbMainWindow();
mMainView = new HbView();
@@ -40,33 +50,67 @@
QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
- mSelectableFiles = new HbComboBox;
- mSelectableFiles->setEditable(false);
- connect(mSelectableFiles, SIGNAL(currentIndexChanged(int)),
- this, SLOT(selectedFileChanged(int)));
- layout->addItem(mSelectableFiles);
+ HbCheckBox *silentInstallCheckBox = new HbCheckBox;
+ silentInstallCheckBox->setText(tr("Silent install/uninstall"));
+ connect(silentInstallCheckBox, SIGNAL(stateChanged(int)),
+ this, SLOT(silentCheckChanged(int)));
+ layout->addItem(silentInstallCheckBox);
+ layout->addStretch();
+
+ HbLabel *installTitle = new HbLabel(tr("Install:"));
+ layout->addItem(installTitle);
- HbCheckBox *silentInstallCheckBox = new HbCheckBox;
- silentInstallCheckBox->setText(tr("Silent install"));
- connect(silentInstallCheckBox, SIGNAL(stateChanged(int)), this, SLOT(silentCheckChanged(int)));
- layout->addItem(silentInstallCheckBox);
+ mInstallDirectories = new HbComboBox;
+ mInstallDirectories->setEditable(false);
+ QStringList dirList;
+ getInstallDirs(dirList);
+ mInstallDirectories->setItems(dirList);
+ connect(mInstallDirectories, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(installableDirChanged(int)));
+ layout->addItem(mInstallDirectories);
+
+ mInstallableFiles = new HbComboBox;
+ mInstallableFiles->setEditable(false);
+ connect(mInstallableFiles, SIGNAL(currentIndexChanged(int)),
+ this, SLOT(installableFileChanged(int)));
+ layout->addItem(mInstallableFiles);
HbPushButton *installNew = new HbPushButton(tr("Install using new API"));
layout->addItem(installNew);
HbPushButton *installOld = new HbPushButton(tr("Install using old API"));
layout->addItem(installOld);
+ HbPushButton *launchApp = new HbPushButton(tr("Install by opening file"));
+ layout->addItem(launchApp);
+ connect(installNew, SIGNAL(clicked()), this, SLOT(installUsingNewApi()));
+ connect(installOld, SIGNAL(clicked()), this, SLOT(installUsingOldApi()));
+ connect(launchApp, SIGNAL(clicked()), this, SLOT(installByOpeningFile()));
+ layout->addStretch();
+
+ HbLabel *uninstallTitle = new HbLabel(tr("Uninstall:"));
+ layout->addItem(uninstallTitle);
+ mRemovableApps = new HbComboBox;
+ mRemovableApps->setEditable(false);
+ layout->addItem(mRemovableApps);
+
+ HbPushButton *removeNew = new HbPushButton(tr("Remove using new API"));
+ layout->addItem(removeNew);
+ HbPushButton *removeOld = new HbPushButton(tr("Remove using old API"));
+ layout->addItem(removeOld);
+ connect(removeNew, SIGNAL(clicked()), this, SLOT(removeUsingNewApi()));
+ connect(removeOld, SIGNAL(clicked()), this, SLOT(removeUsingOldApi()));
+ layout->addStretch();
+
HbPushButton *quit = new HbPushButton(tr("Exit"));
layout->addItem(quit);
- connect(installNew, SIGNAL(clicked()), this, SLOT(installUsingNewApi()));
- connect(installOld, SIGNAL(clicked()), this, SLOT(installUsingOldApi()));
connect(quit, SIGNAL(clicked()), this, SLOT(closeApp()));
mMainView->setLayout(layout);
mMainWindow->addView(mMainView);
mMainWindow->show();
- changeDir(INSTALLS_PATH);
+ changeDir(mInstallDirectories->currentText());
+ getRemovableApps();
}
TestInstaller::~TestInstaller()
@@ -76,38 +120,71 @@
delete mMainWindow;
}
-void TestInstaller::selectedFileChanged(int /*index*/)
-{
- if (mSelectableFiles) {
- mFileNames.clear();
- QString selectedFile(mDirPath);
- selectedFile.append(mSelectableFiles->currentText());
- mFileNames.append(selectedFile);
- }
-}
-
void TestInstaller::silentCheckChanged(int state)
{
Qt::CheckState s = static_cast<Qt::CheckState>(state);
mUseSilentInstall = (s == Qt::Checked);
}
+void TestInstaller::installableDirChanged(int /*index*/)
+{
+ if (mInstallDirectories) {
+ changeDir(mInstallDirectories->currentText());
+ }
+}
+
+void TestInstaller::installableFileChanged(int /*index*/)
+{
+ if (mInstallableFiles) {
+ mCurrentFile = mCurrentDirPath;
+ mCurrentFile.append(mInstallableFiles->currentText());
+ }
+}
+
void TestInstaller::installUsingNewApi()
{
- createRunner(true);
+ if (isFileSelected() && createRunner(true)) {
+ doInstall(mCurrentFile);
+ }
}
void TestInstaller::installUsingOldApi()
{
- createRunner(false);
+ if (isFileSelected() && createRunner(false)) {
+ doInstall(mCurrentFile);
+ }
+}
+
+void TestInstaller::installByOpeningFile()
+{
+ if (mInstallableFiles) {
+ doOpenFile(mCurrentFile);
+ }
+}
+
+void TestInstaller::removeUsingNewApi()
+{
+ if (isFileSelected() && createRunner(true)) {
+ removeSelectedUsingNewApi();
+ }
+}
+
+void TestInstaller::removeUsingOldApi()
+{
+ if (isFileSelected() && createRunner(false)) {
+ removeSelectedUsingOldApi();
+ }
}
void TestInstaller::handleComplete()
{
- HbMessageBox::information(tr("Installed"));
+ HbMessageBox::information(tr("Completed"));
delete mRunner;
mRunner = 0;
+
+ changeDir(mCurrentDirPath);
+ getRemovableApps();
}
void TestInstaller::handleError(int error)
@@ -129,61 +206,127 @@
qApp->exit();
}
+void TestInstaller::fileOpenOk(const QVariant &/*result*/)
+{
+ HbMessageBox::information(tr("Open ok"));
+}
+
+void TestInstaller::fileOpenFailed(int errorCode, const QString &errorMsg)
+{
+ HbMessageBox::warning(tr("Open failed: %1: %2").arg(errorCode).arg(errorMsg));
+}
+
+void TestInstaller::getInstallDirs(QStringList& dirList)
+{
+ QStringList possibleDirs;
+ possibleDirs << INSTALLS_PATH_1 << INSTALLS_PATH_2 << INSTALLS_PATH_3
+ << INSTALLS_PATH_4 << INSTALLS_PATH_5 << INSTALLS_PATH_6;
+
+ QListIterator<QString> iter(possibleDirs);
+ while (iter.hasNext()) {
+ QString dirName(iter.next());
+ QDir dir(dirName);
+ if (dir.exists()) {
+ dirList.append(dirName);
+ }
+ }
+}
+
void TestInstaller::changeDir(const QString& dirPath)
{
- bool filesFound = false;
-
QDir dir(dirPath);
if (dir.exists()) {
- mDirPath = dirPath;
- mSelectableFiles->clear();
+ mCurrentDirPath = dirPath;
+ mInstallableFiles->clear();
QFileInfoList list = dir.entryInfoList(QDir::Files);
QListIterator<QFileInfo> iter(list);
while (iter.hasNext()) {
const QFileInfo &info(iter.next());
- mSelectableFiles->addItem(info.fileName());
+ mInstallableFiles->addItem(info.fileName());
}
- filesFound = (mSelectableFiles->count() > 0);
-
- mFileNames.clear();
- if (filesFound) {
- QString fileSelectedByDefault(dirPath);
- fileSelectedByDefault.append(mSelectableFiles->currentText());
- mFileNames.append(fileSelectedByDefault);
- }
- }
- if (!filesFound) {
- HbMessageBox::warning(tr("No files in '%1'").arg(dirPath));
- }
-}
-
-void TestInstaller::createRunner(bool useSif)
-{
- if (!mFileNames.count()) {
- HbMessageBox::warning(tr("No files selected"));
- changeDir(INSTALLS_PATH);
- } else {
- if (!mRunner) {
- mRunner = new ActiveRunner(useSif);
- connect(mRunner, SIGNAL(opCompleted()), this, SLOT(handleComplete()));
- connect(mRunner, SIGNAL(opFailed(int)), this, SLOT(handleError(int)));
- installSelected();
- } else {
- HbMessageBox::warning(tr("Already running"));
+ mCurrentFile.clear();
+ if (mInstallableFiles->count()) {
+ mCurrentFile = mCurrentDirPath;
+ mCurrentFile.append(mInstallableFiles->currentText());
}
}
}
-void TestInstaller::installSelected()
+void TestInstaller::getRemovableApps()
+{
+ TRAP_IGNORE(doGetRemovableAppsL());
+}
+
+void TestInstaller::doGetRemovableAppsL()
{
- if (mFileNames.count()) {
- QStringListIterator fileNamesIterator(mFileNames);
- while (fileNamesIterator.hasNext()) {
- doInstall(fileNamesIterator.next());
+ mRemovableApps->clear();
+ mRemovableComponentIds.clear();
+ mRemovableUids.clear();
+ mRemovableSoftwareTypes.clear();
+
+ RSoftwareComponentRegistry registry;
+ User::LeaveIfError(registry.Connect());
+ CleanupClosePushL(registry);
+
+ RArray<TComponentId> componentIdList;
+ registry.GetComponentIdsL(componentIdList);
+ for (int i = 0; i < componentIdList.Count(); ++i) {
+ TComponentId compId = componentIdList[i];
+ CComponentEntry *compEntry = CComponentEntry::NewLC();
+ if (registry.GetComponentL(compId, *compEntry)) {
+ if (compEntry->IsRemovable()) {
+ TPtrC compName = compEntry->Name();
+ QString name = QString::fromUtf16(compName.Ptr(), compName.Length());
+ mRemovableApps->addItem(name);
+
+ mRemovableComponentIds.append(compId);
+
+ _LIT(KCompUid, "CompUid");
+ CPropertyEntry *property = registry.GetComponentPropertyL(compId, KCompUid);
+ CleanupStack::PushL(property);
+ CIntPropertyEntry* intProperty = dynamic_cast<CIntPropertyEntry*>(property);
+ mRemovableUids.append(TUid::Uid(intProperty->IntValue()));
+ CleanupStack::PopAndDestroy(property);
+
+ TPtrC softwareType = compEntry->SoftwareType();
+ if (softwareType == KSoftwareTypeNative) {
+ mRemovableSoftwareTypes.append(Native);
+ } else if (softwareType == KSoftwareTypeJava) {
+ mRemovableSoftwareTypes.append(Java);
+ } else {
+ mRemovableSoftwareTypes.append(Unknown);
+ }
+ }
}
+ CleanupStack::PopAndDestroy(compEntry);
}
+
+ CleanupStack::PopAndDestroy(®istry);
+}
+
+bool TestInstaller::isFileSelected()
+{
+ if (mCurrentFile.isEmpty()) {
+ HbMessageBox::warning(tr("No files selected"));
+ changeDir(mCurrentDirPath);
+ return false;
+ }
+ return true;
+}
+
+bool TestInstaller::createRunner(bool useSif)
+{
+ if (!mRunner) {
+ mRunner = new ActiveRunner(useSif);
+ connect(mRunner, SIGNAL(opCompleted()), this, SLOT(handleComplete()));
+ connect(mRunner, SIGNAL(opFailed(int)), this, SLOT(handleError(int)));
+ } else {
+ HbMessageBox::warning(tr("Already running"));
+ return false;
+ }
+ return true;
}
void TestInstaller::doInstall(const QString &fileName)
@@ -193,3 +336,58 @@
}
}
+void TestInstaller::doOpenFile(const QString &fileName)
+{
+ QFile file(fileName);
+ if (file.exists()) {
+ XQApplicationManager appManager;
+ XQAiwRequest *request = appManager.create(file);
+ if (request) {
+ connect(request, SIGNAL(requestOk(const QVariant &)),
+ this, SLOT(fileOpenOk(const QVariant &)));
+ connect(request, SIGNAL(requestError(int, const QString &)),
+ this, SLOT(fileOpenFailed(int, const QString &)));
+ QList<QVariant> args;
+ args << file.fileName();
+ request->setArguments(args);
+ if (request->send()) {
+ HbMessageBox::information(tr("Opening..."));
+ } else {
+ HbMessageBox::warning(tr("Cannot open"));
+ }
+ delete request;
+ } else {
+ HbMessageBox::warning(tr("No handler for file '%1'").arg(fileName));
+ }
+ }
+}
+
+void TestInstaller::removeSelectedUsingNewApi()
+{
+ if (mRemovableApps && mRunner) {
+ int index = mRemovableApps->currentIndex();
+ const TComponentId &compId(mRemovableComponentIds.at(index));
+ mRunner->remove(compId, mUseSilentInstall);
+ }
+}
+
+void TestInstaller::removeSelectedUsingOldApi()
+{
+ if (mRemovableApps && mRunner) {
+ int index = mRemovableApps->currentIndex();
+ const TUid &uid(mRemovableUids.at(index));
+
+ if (mRemovableSoftwareTypes.at(index) == Native) {
+ _LIT8(KSisxMimeType, "x-epoc/x-sisx-app");
+ mRunner->remove(uid, KSisxMimeType, mUseSilentInstall);
+ } else if (mRemovableSoftwareTypes.at(index) == Java) {
+ _LIT8(KJarMIMEType, "application/java-archive");
+ mRunner->remove(uid, KJarMIMEType, mUseSilentInstall);
+ } else {
+ HbMessageBox::warning(tr("Not supported software type"));
+ delete mRunner;
+ mRunner = 0;
+ }
+ }
+}
+