appinstaller/AppinstUi/sisxsifplugin/tsrc/testinstaller/testinstaller.cpp
changeset 72 a0dc14075813
parent 67 3a625661d1ce
equal deleted inserted replaced
67:3a625661d1ce 72:a0dc14075813
    25 #include <hbcombobox.h>
    25 #include <hbcombobox.h>
    26 #include <hblabel.h>
    26 #include <hblabel.h>
    27 #include <hbmessagebox.h>
    27 #include <hbmessagebox.h>
    28 #include <QGraphicsLinearLayout>
    28 #include <QGraphicsLinearLayout>
    29 #include <QDir>
    29 #include <QDir>
       
    30 #include <QTimer>
    30 #include <xqappmgr.h>                       // XQApplicationManager
    31 #include <xqappmgr.h>                       // XQApplicationManager
    31 #include <usif/scr/scr.h>                   // RSoftwareComponentRegistry
    32 #include <usif/scr/scr.h>                   // RSoftwareComponentRegistry
    32 
    33 
    33 using namespace Usif;
    34 using namespace Usif;
    34 
    35 
    37 #define INSTALLS_PATH_3 "F:\\Installs\\"
    38 #define INSTALLS_PATH_3 "F:\\Installs\\"
    38 #define INSTALLS_PATH_4 "C:\\"
    39 #define INSTALLS_PATH_4 "C:\\"
    39 #define INSTALLS_PATH_5 "E:\\"
    40 #define INSTALLS_PATH_5 "E:\\"
    40 #define INSTALLS_PATH_6 "F:\\"
    41 #define INSTALLS_PATH_6 "F:\\"
    41 
    42 
       
    43 const int KCancelInstallDelay = 30000;  // milliseconds
       
    44 const int KCancelRemoveDelay = 5000;    // milliseconds
       
    45 
    42 
    46 
    43 TestInstaller::TestInstaller(int& argc, char* argv[]) : HbApplication(argc, argv),
    47 TestInstaller::TestInstaller(int& argc, char* argv[]) : HbApplication(argc, argv),
    44     mMainWindow(0), mInstallView(0), mRemoveView(0),
    48     mMainWindow(0), mInstallView(0), mRemoveView(0),
    45     mUseSilentInstall(false), mUseSilentUninstall(false), mUseRFileInstall(false), mOcsp(false),
    49     mUseSilentInstall(false), mUseSilentUninstall(false), mUseRFileInstall(false), mOcsp(false),
       
    50     mCancelInstallShortly(false), mCancelRemoveShortly(false),
    46     mInstallDirectories(0), mInstallableFiles(0), mRemovableApps(0),
    51     mInstallDirectories(0), mInstallableFiles(0), mRemovableApps(0),
    47     mCurrentDirPath(), mCurrentFile(), mRunner(0)
    52     mCurrentDirPath(), mCurrentFile(), mRunner(0)
    48 {
    53 {
    49     mMainWindow = new HbMainWindow();
    54     mMainWindow = new HbMainWindow();
    50 
    55 
    51     // Install view
    56     createInstallView();
       
    57     mMainWindow->addView(mInstallView);
       
    58 
       
    59     createRemoveView();
       
    60     mMainWindow->addView(mRemoveView);
       
    61 
       
    62     mMainWindow->setCurrentView(mInstallView);
       
    63     mMainWindow->show();
       
    64 
       
    65     changeDir(mInstallDirectories->currentText());
       
    66     getRemovableApps();
       
    67 }
       
    68 
       
    69 TestInstaller::~TestInstaller()
       
    70 {
       
    71     delete mRunner;
       
    72     delete mInstallView;
       
    73     delete mRemoveView;
       
    74     delete mMainWindow;
       
    75 }
       
    76 
       
    77 void TestInstaller::installViewActivated()
       
    78 {
       
    79     mMainWindow->setCurrentView(mInstallView);
       
    80 }
       
    81 
       
    82 void TestInstaller::removeViewActivated()
       
    83 {
       
    84     mMainWindow->setCurrentView(mRemoveView);
       
    85 }
       
    86 
       
    87 void TestInstaller::silentInstallCheckChanged(int state)
       
    88 {
       
    89     Qt::CheckState s = static_cast<Qt::CheckState>(state);
       
    90     mUseSilentInstall = (s == Qt::Checked);
       
    91 }
       
    92 
       
    93 void TestInstaller::silentRemoveCheckChanged(int state)
       
    94 {
       
    95     Qt::CheckState s = static_cast<Qt::CheckState>(state);
       
    96     mUseSilentUninstall = (s == Qt::Checked);
       
    97 }
       
    98 
       
    99 void TestInstaller::rfileCheckChanged(int state)
       
   100 {
       
   101     Qt::CheckState s = static_cast<Qt::CheckState>(state);
       
   102     mUseRFileInstall = (s == Qt::Checked);
       
   103 }
       
   104 
       
   105 void TestInstaller::ocspCheckChanged(int state)
       
   106 {
       
   107     Qt::CheckState s = static_cast<Qt::CheckState>(state);
       
   108     mOcsp = (s == Qt::Checked);
       
   109 }
       
   110 
       
   111 void TestInstaller::cancelInstallingChanged(int state)
       
   112 {
       
   113     Qt::CheckState s = static_cast<Qt::CheckState>(state);
       
   114     mCancelInstallShortly = (s == Qt::Checked);
       
   115 }
       
   116 
       
   117 void TestInstaller::cancelRemovingChanged(int state)
       
   118 {
       
   119     Qt::CheckState s = static_cast<Qt::CheckState>(state);
       
   120     mCancelRemoveShortly = (s == Qt::Checked);
       
   121 }
       
   122 
       
   123 void TestInstaller::installableDirChanged(int /*index*/)
       
   124 {
       
   125     if (mInstallDirectories) {
       
   126         changeDir(mInstallDirectories->currentText());
       
   127     }
       
   128 }
       
   129 
       
   130 void TestInstaller::installableFileChanged(int /*index*/)
       
   131 {
       
   132     if (mInstallableFiles) {
       
   133         mCurrentFile = mCurrentDirPath;
       
   134         mCurrentFile.append(mInstallableFiles->currentText());
       
   135     }
       
   136 }
       
   137 
       
   138 void TestInstaller::installUsingNewApi()
       
   139 {
       
   140     if (isFileSelected() && createRunner(true)) {
       
   141         doInstall(mCurrentFile);
       
   142     }
       
   143 }
       
   144 
       
   145 void TestInstaller::installUsingOldApi()
       
   146 {
       
   147     if (isFileSelected() && createRunner(false)) {
       
   148         doInstall(mCurrentFile);
       
   149     }
       
   150 }
       
   151 
       
   152 void TestInstaller::installByOpeningFile()
       
   153 {
       
   154     if (mInstallableFiles) {
       
   155         doOpenFile(mCurrentFile);
       
   156     }
       
   157 }
       
   158 
       
   159 void TestInstaller::removeUsingNewApi()
       
   160 {
       
   161     if (isFileSelected() && createRunner(true)) {
       
   162         removeSelectedUsingNewApi();
       
   163     }
       
   164 }
       
   165 
       
   166 void TestInstaller::removeUsingOldApi()
       
   167 {
       
   168     if (isFileSelected() && createRunner(false)) {
       
   169         removeSelectedUsingOldApi();
       
   170     }
       
   171 }
       
   172 
       
   173 void TestInstaller::handleComplete()
       
   174 {
       
   175     HbMessageBox::information(tr("Completed"));
       
   176 
       
   177     delete mRunner;
       
   178     mRunner = 0;
       
   179 
       
   180     changeDir(mCurrentDirPath);
       
   181     getRemovableApps();
       
   182 }
       
   183 
       
   184 void TestInstaller::handleError(int error)
       
   185 {
       
   186     QString messageText;
       
   187     if (error == KErrCancel) {
       
   188         messageText = tr("Cancelled");
       
   189     } else {
       
   190         messageText = tr("Error %1").arg(error);
       
   191     }
       
   192     HbMessageBox::warning(messageText);
       
   193 
       
   194     delete mRunner;
       
   195     mRunner = 0;
       
   196 }
       
   197 
       
   198 void TestInstaller::closeApp()
       
   199 {
       
   200     qApp->exit();
       
   201 }
       
   202 
       
   203 void TestInstaller::fileOpenOk(const QVariant &/*result*/)
       
   204 {
       
   205     HbMessageBox::information(tr("Open ok"));
       
   206 }
       
   207 
       
   208 void TestInstaller::fileOpenFailed(int errorCode, const QString &errorMsg)
       
   209 {
       
   210     HbMessageBox::warning(tr("Open failed: %1: %2").arg(errorCode).arg(errorMsg));
       
   211 }
       
   212 
       
   213 void TestInstaller::cancelInstalling()
       
   214 {
       
   215     HbMessageBox::warning(tr("Timeout, cancelling"));
       
   216     delete mRunner;
       
   217     mRunner = 0;
       
   218     HbMessageBox::warning(tr("Installing cancelled"));
       
   219 }
       
   220 
       
   221 void TestInstaller::cancelRemoving()
       
   222 {
       
   223     HbMessageBox::warning(tr("Timeout, cancelling"));
       
   224     delete mRunner;
       
   225     mRunner = 0;
       
   226     HbMessageBox::warning(tr("Removing cancelled"));
       
   227 }
       
   228 
       
   229 void TestInstaller::createInstallView()
       
   230 {
       
   231     Q_ASSERT( mInstallView == 0 );
    52     mInstallView = new HbView();
   232     mInstallView = new HbView();
    53     mInstallView->setTitle(tr("Test Installer"));
   233     mInstallView->setTitle(tr("Test Installer"));
    54 
   234 
    55     QGraphicsLinearLayout *installLayout = new QGraphicsLinearLayout(Qt::Vertical);
   235     QGraphicsLinearLayout *installLayout = new QGraphicsLinearLayout(Qt::Vertical);
    56 
   236 
    87     connect(ocspCheckBox, SIGNAL(stateChanged(int)), this, SLOT(ocspCheckChanged(int)));
   267     connect(ocspCheckBox, SIGNAL(stateChanged(int)), this, SLOT(ocspCheckChanged(int)));
    88     checkboxesLayout->addItem(ocspCheckBox);
   268     checkboxesLayout->addItem(ocspCheckBox);
    89     installLayout->addItem(checkboxesLayout);
   269     installLayout->addItem(checkboxesLayout);
    90     installLayout->addStretch();
   270     installLayout->addStretch();
    91 
   271 
       
   272     HbCheckBox *cancelInstall = new HbCheckBox;
       
   273     cancelInstall->setText(tr("Cancel after %1 seconds").arg(KCancelInstallDelay/1000));
       
   274     connect(cancelInstall, SIGNAL(stateChanged(int)), this, SLOT(cancelInstallingChanged(int)));
       
   275     installLayout->addItem(cancelInstall);
       
   276 
    92     HbPushButton *installNew = new HbPushButton(tr("Install using new API"));
   277     HbPushButton *installNew = new HbPushButton(tr("Install using new API"));
    93     installLayout->addItem(installNew);
   278     installLayout->addItem(installNew);
    94     HbPushButton *installOld = new HbPushButton(tr("Install using old API"));
   279     HbPushButton *installOld = new HbPushButton(tr("Install using old API"));
    95     installLayout->addItem(installOld);
   280     installLayout->addItem(installOld);
    96     HbPushButton *launchApp = new HbPushButton(tr("Install by opening file"));
   281     HbPushButton *launchApp = new HbPushButton(tr("Install by opening file"));
    97     installLayout->addItem(launchApp);
   282     installLayout->addItem(launchApp);
    98     HbPushButton *cancelInstall = new HbPushButton(tr("Cancel installing"));
       
    99     installLayout->addItem(cancelInstall);
       
   100     installLayout->addStretch();
   283     installLayout->addStretch();
   101     connect(installNew, SIGNAL(clicked()), this, SLOT(installUsingNewApi()));
   284     connect(installNew, SIGNAL(clicked()), this, SLOT(installUsingNewApi()));
   102     connect(installOld, SIGNAL(clicked()), this, SLOT(installUsingOldApi()));
   285     connect(installOld, SIGNAL(clicked()), this, SLOT(installUsingOldApi()));
   103     connect(launchApp, SIGNAL(clicked()), this, SLOT(installByOpeningFile()));
   286     connect(launchApp, SIGNAL(clicked()), this, SLOT(installByOpeningFile()));
   104     connect(cancelInstall, SIGNAL(clicked()), this, SLOT(cancelInstalling()));
       
   105 
   287 
   106     HbToolBar *installToolBar = new HbToolBar();
   288     HbToolBar *installToolBar = new HbToolBar();
   107     installToolBar->addAction(tr("RemoveView"), this, SLOT(removeViewActivated()));
   289     installToolBar->addAction(tr("RemoveView"), this, SLOT(removeViewActivated()));
   108     installToolBar->addAction(tr("Exit"), this, SLOT(closeApp()));
   290     installToolBar->addAction(tr("Exit"), this, SLOT(closeApp()));
   109     mInstallView->setToolBar(installToolBar);
   291     mInstallView->setToolBar(installToolBar);
   110 
   292 
   111     mInstallView->setLayout(installLayout);
   293     mInstallView->setLayout(installLayout);
   112     mMainWindow->addView(mInstallView);
   294 }
   113 
   295 
   114     // Remove view
   296 void TestInstaller::createRemoveView()
       
   297 {
       
   298     Q_ASSERT( mRemoveView == 0 );
   115     mRemoveView = new HbView();
   299     mRemoveView = new HbView();
   116     mRemoveView->setTitle(tr("Test Uninstaller"));
   300     mRemoveView->setTitle(tr("Test Uninstaller"));
   117 
   301 
   118     QGraphicsLinearLayout *removeLayout = new QGraphicsLinearLayout(Qt::Vertical);
   302     QGraphicsLinearLayout *removeLayout = new QGraphicsLinearLayout(Qt::Vertical);
   119 
   303 
   128     silentRemoveCheckBox->setText(tr("Silent"));
   312     silentRemoveCheckBox->setText(tr("Silent"));
   129     connect(silentRemoveCheckBox, SIGNAL(stateChanged(int)),
   313     connect(silentRemoveCheckBox, SIGNAL(stateChanged(int)),
   130             this, SLOT(silentCheckChanged(int)));
   314             this, SLOT(silentCheckChanged(int)));
   131     removeLayout->addItem(silentRemoveCheckBox);
   315     removeLayout->addItem(silentRemoveCheckBox);
   132     removeLayout->addStretch();
   316     removeLayout->addStretch();
       
   317 
       
   318     HbCheckBox *cancelRemove = new HbCheckBox;
       
   319     cancelRemove->setText(tr("Cancel after %1 seconds").arg(KCancelRemoveDelay/1000));
       
   320     connect(cancelRemove, SIGNAL(stateChanged(int)), this, SLOT(cancelRemovingChanged(int)));
       
   321     removeLayout->addItem(cancelRemove);
   133 
   322 
   134     HbPushButton *removeNew = new HbPushButton(tr("Remove using new API"));
   323     HbPushButton *removeNew = new HbPushButton(tr("Remove using new API"));
   135     removeLayout->addItem(removeNew);
   324     removeLayout->addItem(removeNew);
   136     HbPushButton *removeOld = new HbPushButton(tr("Remove using old API"));
   325     HbPushButton *removeOld = new HbPushButton(tr("Remove using old API"));
   137     removeLayout->addItem(removeOld);
   326     removeLayout->addItem(removeOld);
   138     removeLayout->addStretch();
   327     removeLayout->addStretch();
   139     connect(removeNew, SIGNAL(clicked()), this, SLOT(removeUsingNewApi()));
   328     connect(removeNew, SIGNAL(clicked()), this, SLOT(removeUsingNewApi()));
   140     connect(removeOld, SIGNAL(clicked()), this, SLOT(removeUsingOldApi()));
   329     connect(removeOld, SIGNAL(clicked()), this, SLOT(removeUsingOldApi()));
   141 
   330 
   142     mRemoveView->setLayout(removeLayout);
       
   143     mMainWindow->addView(mRemoveView);
       
   144 
       
   145     HbToolBar *removeToolBar = new HbToolBar();
   331     HbToolBar *removeToolBar = new HbToolBar();
   146     removeToolBar->addAction(tr("InstallView"), this, SLOT(installViewActivated()));
   332     removeToolBar->addAction(tr("InstallView"), this, SLOT(installViewActivated()));
   147     removeToolBar->addAction(tr("Exit"), this, SLOT(closeApp()));
   333     removeToolBar->addAction(tr("Exit"), this, SLOT(closeApp()));
   148     mRemoveView->setToolBar(removeToolBar);
   334     mRemoveView->setToolBar(removeToolBar);
   149 
   335 
   150     mMainWindow->setCurrentView(mInstallView);
   336     mRemoveView->setLayout(removeLayout);
   151     mMainWindow->show();
       
   152 
       
   153     changeDir(mInstallDirectories->currentText());
       
   154     getRemovableApps();
       
   155 }
       
   156 
       
   157 TestInstaller::~TestInstaller()
       
   158 {
       
   159     delete mRunner;
       
   160     delete mInstallView;
       
   161     delete mRemoveView;
       
   162     delete mMainWindow;
       
   163 }
       
   164 
       
   165 void TestInstaller::installViewActivated()
       
   166 {
       
   167     mMainWindow->setCurrentView(mInstallView);
       
   168 }
       
   169 
       
   170 void TestInstaller::removeViewActivated()
       
   171 {
       
   172     mMainWindow->setCurrentView(mRemoveView);
       
   173 }
       
   174 
       
   175 void TestInstaller::silentInstallCheckChanged(int state)
       
   176 {
       
   177     Qt::CheckState s = static_cast<Qt::CheckState>(state);
       
   178     mUseSilentInstall = (s == Qt::Checked);
       
   179 }
       
   180 
       
   181 void TestInstaller::silentRemoveCheckChanged(int state)
       
   182 {
       
   183     Qt::CheckState s = static_cast<Qt::CheckState>(state);
       
   184     mUseSilentUninstall = (s == Qt::Checked);
       
   185 }
       
   186 
       
   187 void TestInstaller::rfileCheckChanged(int state)
       
   188 {
       
   189     Qt::CheckState s = static_cast<Qt::CheckState>(state);
       
   190     mUseRFileInstall = (s == Qt::Checked);
       
   191 }
       
   192 
       
   193 void TestInstaller::ocspCheckChanged(int state)
       
   194 {
       
   195     Qt::CheckState s = static_cast<Qt::CheckState>(state);
       
   196     mOcsp = (s == Qt::Checked);
       
   197 }
       
   198 
       
   199 void TestInstaller::installableDirChanged(int /*index*/)
       
   200 {
       
   201     if (mInstallDirectories) {
       
   202         changeDir(mInstallDirectories->currentText());
       
   203     }
       
   204 }
       
   205 
       
   206 void TestInstaller::installableFileChanged(int /*index*/)
       
   207 {
       
   208     if (mInstallableFiles) {
       
   209         mCurrentFile = mCurrentDirPath;
       
   210         mCurrentFile.append(mInstallableFiles->currentText());
       
   211     }
       
   212 }
       
   213 
       
   214 void TestInstaller::installUsingNewApi()
       
   215 {
       
   216     if (isFileSelected() && createRunner(true)) {
       
   217         doInstall(mCurrentFile);
       
   218     }
       
   219 }
       
   220 
       
   221 void TestInstaller::installUsingOldApi()
       
   222 {
       
   223     if (isFileSelected() && createRunner(false)) {
       
   224         doInstall(mCurrentFile);
       
   225     }
       
   226 }
       
   227 
       
   228 void TestInstaller::installByOpeningFile()
       
   229 {
       
   230     if (mInstallableFiles) {
       
   231         doOpenFile(mCurrentFile);
       
   232     }
       
   233 }
       
   234 
       
   235 void TestInstaller::cancelInstalling()
       
   236 {
       
   237     if (mRunner) {
       
   238         delete mRunner;
       
   239         mRunner = 0;
       
   240         HbMessageBox::warning(tr("Running operation deleted"));
       
   241     } else {
       
   242         HbMessageBox::warning(tr("No operation running"));
       
   243     }
       
   244 }
       
   245 
       
   246 void TestInstaller::removeUsingNewApi()
       
   247 {
       
   248     if (isFileSelected() && createRunner(true)) {
       
   249         removeSelectedUsingNewApi();
       
   250     }
       
   251 }
       
   252 
       
   253 void TestInstaller::removeUsingOldApi()
       
   254 {
       
   255     if (isFileSelected() && createRunner(false)) {
       
   256         removeSelectedUsingOldApi();
       
   257     }
       
   258 }
       
   259 
       
   260 void TestInstaller::handleComplete()
       
   261 {
       
   262     HbMessageBox::information(tr("Completed"));
       
   263 
       
   264     delete mRunner;
       
   265     mRunner = 0;
       
   266 
       
   267     changeDir(mCurrentDirPath);
       
   268     getRemovableApps();
       
   269 }
       
   270 
       
   271 void TestInstaller::handleError(int error)
       
   272 {
       
   273     QString messageText;
       
   274     if (error == KErrCancel) {
       
   275         messageText = tr("Cancelled");
       
   276     } else {
       
   277         messageText = tr("Error %1").arg(error);
       
   278     }
       
   279     HbMessageBox::warning(messageText);
       
   280 
       
   281     delete mRunner;
       
   282     mRunner = 0;
       
   283 }
       
   284 
       
   285 void TestInstaller::closeApp()
       
   286 {
       
   287     qApp->exit();
       
   288 }
       
   289 
       
   290 void TestInstaller::fileOpenOk(const QVariant &/*result*/)
       
   291 {
       
   292     HbMessageBox::information(tr("Open ok"));
       
   293 }
       
   294 
       
   295 void TestInstaller::fileOpenFailed(int errorCode, const QString &errorMsg)
       
   296 {
       
   297     HbMessageBox::warning(tr("Open failed: %1: %2").arg(errorCode).arg(errorMsg));
       
   298 }
   337 }
   299 
   338 
   300 void TestInstaller::getInstallDirs(QStringList& dirList)
   339 void TestInstaller::getInstallDirs(QStringList& dirList)
   301 {
   340 {
   302     QStringList possibleDirs;
   341     QStringList possibleDirs;
   402 {
   441 {
   403     if (!mRunner) {
   442     if (!mRunner) {
   404         mRunner = new ActiveRunner(useSif);
   443         mRunner = new ActiveRunner(useSif);
   405         connect(mRunner, SIGNAL(opCompleted()), this, SLOT(handleComplete()));
   444         connect(mRunner, SIGNAL(opCompleted()), this, SLOT(handleComplete()));
   406         connect(mRunner, SIGNAL(opFailed(int)), this, SLOT(handleError(int)));
   445         connect(mRunner, SIGNAL(opFailed(int)), this, SLOT(handleError(int)));
       
   446 
       
   447         if (mCancelInstallShortly) {
       
   448             QTimer::singleShot(KCancelInstallDelay, this, SLOT(cancelInstalling()));
       
   449         }
   407     } else {
   450     } else {
   408         HbMessageBox::warning(tr("Already running"));
   451         HbMessageBox::warning(tr("Already running"));
   409         return false;
   452         return false;
   410     }
   453     }
   411     return true;
   454     return true;
   448 {
   491 {
   449     if (mRemovableApps && mRunner) {
   492     if (mRemovableApps && mRunner) {
   450         int index = mRemovableApps->currentIndex();
   493         int index = mRemovableApps->currentIndex();
   451         const TComponentId &compId(mRemovableComponentIds.at(index));
   494         const TComponentId &compId(mRemovableComponentIds.at(index));
   452         mRunner->remove(compId, mUseSilentUninstall);
   495         mRunner->remove(compId, mUseSilentUninstall);
       
   496 
       
   497         if (mCancelRemoveShortly) {
       
   498             QTimer::singleShot(KCancelRemoveDelay, this, SLOT(cancelRemoving()));
       
   499         }
   453     }
   500     }
   454 }
   501 }
   455 
   502 
   456 void TestInstaller::removeSelectedUsingOldApi()
   503 void TestInstaller::removeSelectedUsingOldApi()
   457 {
   504 {