appinstaller/AppinstUi/sifuidevicedialogplugin/src/sifuidialog.cpp
changeset 52 92f864ef0288
parent 42 d17dc5398051
child 55 ac7f90a6ff4c
child 60 245df5276b97
equal deleted inserted replaced
42:d17dc5398051 52:92f864ef0288
    42 // ----------------------------------------------------------------------------
    42 // ----------------------------------------------------------------------------
    43 //
    43 //
    44 SifUiDialog::SifUiDialog(const QVariantMap &parameters) : HbDialog(),
    44 SifUiDialog::SifUiDialog(const QVariantMap &parameters) : HbDialog(),
    45     mCommonTranslator(0), mSifUITranslator(0), mLastDialogError(KErrNone),
    45     mCommonTranslator(0), mSifUITranslator(0), mLastDialogError(KErrNone),
    46     mShowEventReceived(false), mDialogType(SifUiUnspecifiedDialog),
    46     mShowEventReceived(false), mDialogType(SifUiUnspecifiedDialog),
    47     mTitle(0), mContent(0), mResultMap(),
    47     mTitle(0), mContent(0), mResultMap(), mPrimaryAction(0),
    48     mIgnoreCloseAction(0), mPrimaryAction(0), mSecondaryAction(0),
    48     mSecondaryAction(0), mIndicator(0), mSubscriber(0)
    49     mIndicator(0), mSubscriber(0)
       
    50 {
    49 {
    51     mCommonTranslator = new HbTranslator(KTranslationsPath, KCommonTranslationsFile);
    50     mCommonTranslator = new HbTranslator(KTranslationsPath, KCommonTranslationsFile);
    52     mSifUITranslator = new HbTranslator(KTranslationsPath, KSifUiTranslationsFile);
    51     mSifUITranslator = new HbTranslator(KTranslationsPath, KSifUiTranslationsFile);
    53     constructDialog(parameters);
    52     constructDialog(parameters);
    54 }
    53 }
    60 SifUiDialog::~SifUiDialog()
    59 SifUiDialog::~SifUiDialog()
    61 {
    60 {
    62     delete mSubscriber;
    61     delete mSubscriber;
    63     delete mPrimaryAction;
    62     delete mPrimaryAction;
    64     delete mSecondaryAction;
    63     delete mSecondaryAction;
    65     mIgnoreCloseAction = 0;
       
    66     delete mSifUITranslator;
    64     delete mSifUITranslator;
    67     delete mCommonTranslator;
    65     delete mCommonTranslator;
    68 }
    66 }
    69 
    67 
    70 // ----------------------------------------------------------------------------
    68 // ----------------------------------------------------------------------------
   122 // ----------------------------------------------------------------------------
   120 // ----------------------------------------------------------------------------
   123 //
   121 //
   124 HbDialog *SifUiDialog::deviceDialogWidget() const
   122 HbDialog *SifUiDialog::deviceDialogWidget() const
   125 {
   123 {
   126     return const_cast<SifUiDialog*>(this);
   124     return const_cast<SifUiDialog*>(this);
   127 }
       
   128 
       
   129 // ----------------------------------------------------------------------------
       
   130 // SifUiDialog::closeEvent()
       
   131 // ----------------------------------------------------------------------------
       
   132 //
       
   133 void SifUiDialog::closeEvent(QCloseEvent *event)
       
   134 {
       
   135     if (mIgnoreCloseAction) {
       
   136         HbAction *closingAction = qobject_cast<HbAction *>(sender());
       
   137         if (closingAction == mIgnoreCloseAction) {
       
   138             // Prevents the dialog from begin closed when "Ok" pressed
       
   139             event->ignore();
       
   140             return;
       
   141         }
       
   142     }
       
   143     HbDialog::closeEvent(event);
       
   144 }
   125 }
   145 
   126 
   146 // ----------------------------------------------------------------------------
   127 // ----------------------------------------------------------------------------
   147 // SifUiDialog::hideEvent()
   128 // SifUiDialog::hideEvent()
   148 // ----------------------------------------------------------------------------
   129 // ----------------------------------------------------------------------------
   230         }
   211         }
   231     if (prevDialogType != mDialogType) {
   212     if (prevDialogType != mDialogType) {
   232         updateButtons(parameters);
   213         updateButtons(parameters);
   233     }
   214     }
   234     if (parameters.contains(KSifUiErrorCode)) {
   215     if (parameters.contains(KSifUiErrorCode)) {
   235         mInstallError = parameters.value(KSifUiErrorCode).toInt();
   216         bool ok = false;
       
   217         int errorCode = parameters.value(KSifUiErrorCode).toInt(&ok);
       
   218         if (ok) {
       
   219             mInstallError = errorCode;
       
   220         }
   236     }
   221     }
   237     return true;
   222     return true;
   238 }
   223 }
   239 
   224 
   240 // ----------------------------------------------------------------------------
   225 // ----------------------------------------------------------------------------
   241 // SifUiDialog::updateButtons()
   226 // SifUiDialog::updateButtons()
   242 // ----------------------------------------------------------------------------
   227 // ----------------------------------------------------------------------------
   243 //
   228 //
   244 void SifUiDialog::updateButtons(const QVariantMap &parameters)
   229 void SifUiDialog::updateButtons(const QVariantMap &parameters)
   245 {
   230 {
   246     mIgnoreCloseAction = 0;
       
   247 
       
   248     if (mPrimaryAction) {
   231     if (mPrimaryAction) {
   249         removeAction(mPrimaryAction);
   232         removeAction(mPrimaryAction);
   250         delete mPrimaryAction;
   233         delete mPrimaryAction;
   251         mPrimaryAction = 0;
   234         mPrimaryAction = 0;
   252     }
   235     }
   253     switch (mDialogType) {
   236     switch (mDialogType) {
   254         case SifUiConfirmationQuery:
   237         case SifUiConfirmationQuery:
   255             //: Accepts the SW install confirmation query and starts installation.
   238             //: Accepts the SW install confirmation query and starts installation.
   256             mPrimaryAction = new HbAction(hbTrId("txt_common_button_ok"));
   239             mPrimaryAction = new HbAction(hbTrId("txt_common_button_ok"));
       
   240             addAction(mPrimaryAction);
       
   241             disconnect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(close()));
   257             connect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(handleAccepted()));
   242             connect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(handleAccepted()));
   258             mIgnoreCloseAction = mPrimaryAction;
       
   259             break;
   243             break;
   260         case SifUiProgressNote:
   244         case SifUiProgressNote:
   261             if (!parameters.contains(KSifUiProgressNoteIsHideButtonHidden)) {
   245             if (!parameters.contains(KSifUiProgressNoteIsHideButtonHidden)) {
   262                 //: Hides the progress dialog. Progress note moves into universal indicator.
   246                 //: Hides the progress dialog. Progress note moves into universal indicator.
   263                 mPrimaryAction = new HbAction(hbTrId("txt_common_button_hide"));
   247                 mPrimaryAction = new HbAction(hbTrId("txt_common_button_hide"));
       
   248                 addAction(mPrimaryAction);
       
   249                 disconnect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(close()));
   264                 connect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(handleHidePressed()));
   250                 connect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(handleHidePressed()));
   265                 mIgnoreCloseAction = mPrimaryAction;
       
   266             }
   251             }
   267             break;
   252             break;
   268         case SifUiCompleteNote:
   253         case SifUiCompleteNote:
   269             if (!parameters.contains(KSifUiCompleteNoteIsShowButtonHidden)) {
   254             if (!parameters.contains(KSifUiCompleteNoteIsShowButtonHidden)) {
   270                 //: Opens Application Library to view the installed application.
   255                 //: Opens Application Library to view the installed application.
   271                 mPrimaryAction = new HbAction(hbTrId("txt_installer_button_show"));
   256                 mPrimaryAction = new HbAction(hbTrId("txt_installer_button_show"));
       
   257                 addAction(mPrimaryAction);
       
   258                 disconnect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(close()));
   272                 connect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(handleShowInstalled()));
   259                 connect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(handleShowInstalled()));
   273             }
   260             }
   274             break;
   261             break;
   275         case SifUiErrorNote:
   262         case SifUiErrorNote:
   276             if (!parameters.contains(KSifUiErrorNoteIsDetailsButtonHidden)) {
   263             if (!parameters.contains(KSifUiErrorNoteIsDetailsButtonHidden)) {
   277                 //: Shows a dialog with further info about the failure (i.e. why installation failed).
   264                 //: Shows a dialog with further info about the failure (i.e. why installation failed).
   278                 mPrimaryAction = new HbAction(hbTrId("txt_installer_button_details"));
   265                 mPrimaryAction = new HbAction(hbTrId("txt_installer_button_details"));
       
   266                 addAction(mPrimaryAction);
       
   267                 disconnect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(close()));
   279                 connect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(handleErrorDetails()));
   268                 connect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(handleErrorDetails()));
   280                 mIgnoreCloseAction = mPrimaryAction;
       
   281             }
   269             }
   282             break;
   270             break;
   283         default:
   271         default:
   284             break;
   272             break;
   285     }
       
   286     if (mPrimaryAction) {
       
   287         addAction(mPrimaryAction);
       
   288     }
   273     }
   289 
   274 
   290     if (mSecondaryAction) {
   275     if (mSecondaryAction) {
   291         removeAction(mSecondaryAction);
   276         removeAction(mSecondaryAction);
   292         delete mSecondaryAction;
   277         delete mSecondaryAction;
   296         case SifUiConfirmationQuery:
   281         case SifUiConfirmationQuery:
   297         case SifUiProgressNote:
   282         case SifUiProgressNote:
   298             if (!parameters.contains(KSifUiProgressNoteIsCancelButtonHidden)) {
   283             if (!parameters.contains(KSifUiProgressNoteIsCancelButtonHidden)) {
   299                 //: Cancels the SW install confirmation query and closes the dialog.
   284                 //: Cancels the SW install confirmation query and closes the dialog.
   300                 mSecondaryAction = new HbAction(hbTrId("txt_common_button_cancel"));
   285                 mSecondaryAction = new HbAction(hbTrId("txt_common_button_cancel"));
       
   286                 addAction(mSecondaryAction);
       
   287                 disconnect(mSecondaryAction, SIGNAL(triggered()), this, SLOT(close()));
   301                 connect(mSecondaryAction, SIGNAL(triggered()), this, SLOT(handleCancelled()));
   288                 connect(mSecondaryAction, SIGNAL(triggered()), this, SLOT(handleCancelled()));
   302             }
   289             }
   303             break;
   290             break;
   304         case SifUiCompleteNote:
   291         case SifUiCompleteNote:
   305         case SifUiErrorNote:
   292         case SifUiErrorNote:
   306             //: Closes the dialog. Control returns back to where the installation was started.
   293             //: Closes the dialog. Control returns back to where the installation was started.
   307             mSecondaryAction = new HbAction(hbTrId("txt_common_button_close"));
   294             mSecondaryAction = new HbAction(hbTrId("txt_common_button_close"));
   308             connect(mSecondaryAction, SIGNAL(triggered()), this, SLOT(close()));
   295             addAction(mSecondaryAction);
   309             break;
   296             break;
   310         default:
   297         default:
   311             break;
   298             break;
   312     }
       
   313     if (mSecondaryAction) {
       
   314         addAction(mSecondaryAction);
       
   315     }
   299     }
   316 }
   300 }
   317 
   301 
   318 // ----------------------------------------------------------------------------
   302 // ----------------------------------------------------------------------------
   319 // SifUiDialog::sendResult()
   303 // SifUiDialog::sendResult()
   341 // ----------------------------------------------------------------------------
   325 // ----------------------------------------------------------------------------
   342 //
   326 //
   343 void SifUiDialog::handleCancelled()
   327 void SifUiDialog::handleCancelled()
   344 {
   328 {
   345     sendResult(SifUiCancel);
   329     sendResult(SifUiCancel);
       
   330     close();
   346 }
   331 }
   347 
   332 
   348 // ----------------------------------------------------------------------------
   333 // ----------------------------------------------------------------------------
   349 // SifUiDialog::handleMemorySelectionChanged()
   334 // SifUiDialog::handleMemorySelectionChanged()
   350 // ----------------------------------------------------------------------------
   335 // ----------------------------------------------------------------------------
   385             QString messageText = tr("Unable to open AppLib. Error %1").arg(error);
   370             QString messageText = tr("Unable to open AppLib. Error %1").arg(error);
   386             HbMessageBox::warning(messageText);
   371             HbMessageBox::warning(messageText);
   387         }
   372         }
   388         delete request;
   373         delete request;
   389     }
   374     }
       
   375 
       
   376     close();
   390 }
   377 }
   391 
   378 
   392 // ----------------------------------------------------------------------------
   379 // ----------------------------------------------------------------------------
   393 // SifUiDialog::handleErrorDetails()
   380 // SifUiDialog::handleErrorDetails()
   394 // ----------------------------------------------------------------------------
   381 // ----------------------------------------------------------------------------
   395 //
   382 //
   396 void SifUiDialog::handleErrorDetails()
   383 void SifUiDialog::handleErrorDetails()
   397 {
   384 {
   398     // TODO: show proper error details dialog
   385     // TODO: show proper error details dialog
   399     QString messageText;
   386     QString messageText;
   400     messageText = tr("Not implemented yet.\n\nError code %1").arg(mInstallError);
   387     messageText = tr("Error code %1").arg(mInstallError);
   401 
   388 
   402     if (QFile::exists(KSwiErrorsFile)) {
   389     if (QFile::exists(KSwiErrorsFile)) {
   403         messageText.append(KSwiErrorFormat.arg(mInstallError));
   390         messageText.append(KSwiErrorFormat.arg(mInstallError));
   404     }
   391     }
   405     HbMessageBox::warning(messageText);
   392     HbMessageBox::warning(messageText);