appinstaller/AppinstUi/sifuidevicedialogplugin/src/sifuidialog.cpp
changeset 42 d17dc5398051
parent 37 6e7b00453237
child 44 329d304c1aa1
equal deleted inserted replaced
37:6e7b00453237 42:d17dc5398051
    17 
    17 
    18 #include "sifuidialog.h"
    18 #include "sifuidialog.h"
    19 #include "sifuidialogtitlewidget.h"
    19 #include "sifuidialogtitlewidget.h"
    20 #include "sifuidialogcontentwidget.h"
    20 #include "sifuidialogcontentwidget.h"
    21 #include "sifuiinstallindicatorparams.h"
    21 #include "sifuiinstallindicatorparams.h"
       
    22 #include <QFile>
    22 #include <hblabel.h>
    23 #include <hblabel.h>
    23 #include <hbaction.h>
    24 #include <hbaction.h>
    24 #include <hbindicator.h>
    25 #include <hbindicator.h>
    25 #include <QTranslator>
    26 #include <hbtranslator.h>
    26 #include <QApplication>                     // qApp()
       
    27 #include <QFile>
       
    28 #include <hbmessagebox.h>
    27 #include <hbmessagebox.h>
    29 #include <qvaluespacesubscriber.h>
    28 #include <qvaluespacesubscriber.h>
    30 #include <xqappmgr.h>                       // XQApplicationManager
    29 #include <xqappmgr.h>                       // XQApplicationManager
    31 
    30 
    32 QTM_USE_NAMESPACE
    31 QTM_USE_NAMESPACE
    33 
    32 
    34 const QString KTranslationsPath = "resource/qt/translations/";
    33 const QString KTranslationsPath = "/resource/qt/translations/";
    35 const QString KTranslationsFile = "sifuidevicedialogplugin";
    34 const QString KSifUiTranslationsFile = "sifuidevicedialogplugin";
       
    35 const QString KCommonTranslationsFile = "common";
    36 const QString KSwiErrorsFile = "c:\\temp\\swierrors.txt";
    36 const QString KSwiErrorsFile = "c:\\temp\\swierrors.txt";
    37 const QString KSwiErrorFormat = " (%1)";
    37 const QString KSwiErrorFormat = " (%1)";
    38 
    38 
    39 
    39 
    40 // ----------------------------------------------------------------------------
    40 // ----------------------------------------------------------------------------
    41 // SifUiDialog::SifUiDialog()
    41 // SifUiDialog::SifUiDialog()
    42 // ----------------------------------------------------------------------------
    42 // ----------------------------------------------------------------------------
    43 //
    43 //
    44 SifUiDialog::SifUiDialog(const QVariantMap &parameters) : HbDialog(),
    44 SifUiDialog::SifUiDialog(const QVariantMap &parameters) : HbDialog(),
    45     mLastDialogError(KErrNone), mShowEventReceived(false),
    45     mCommonTranslator(0), mSifUITranslator(0), mLastDialogError(KErrNone),
    46     mDialogType(SifUiUnspecifiedDialog),
    46     mShowEventReceived(false), mDialogType(SifUiUnspecifiedDialog),
    47     mTitle(0), mContent(0), mResultMap(),
    47     mTitle(0), mContent(0), mResultMap(),
    48     mIgnoreCloseAction(0), mIndicator(0), mSubscriber(0)
    48     mIgnoreCloseAction(0), mPrimaryAction(0), mSecondaryAction(0),
    49 {
    49     mIndicator(0), mSubscriber(0)
    50     // TODO: enable when translations ready
    50 {
    51     //installTranslator();
    51     mCommonTranslator = new HbTranslator(KTranslationsPath, KCommonTranslationsFile);
       
    52     mSifUITranslator = new HbTranslator(KTranslationsPath, KSifUiTranslationsFile);
    52     constructDialog(parameters);
    53     constructDialog(parameters);
    53 }
    54 }
    54 
    55 
    55 // ----------------------------------------------------------------------------
    56 // ----------------------------------------------------------------------------
    56 // SifUiDialog::~SifUiDialog()
    57 // SifUiDialog::~SifUiDialog()
    57 // ----------------------------------------------------------------------------
    58 // ----------------------------------------------------------------------------
    58 //
    59 //
    59 SifUiDialog::~SifUiDialog()
    60 SifUiDialog::~SifUiDialog()
    60 {
    61 {
    61     delete mSubscriber;
    62     delete mSubscriber;
    62 
    63     delete mPrimaryAction;
    63     // TODO: enable when translations ready
    64     delete mSecondaryAction;
    64     //removeTranslator();
    65     mIgnoreCloseAction = 0;
       
    66     delete mSifUITranslator;
       
    67     delete mCommonTranslator;
    65 }
    68 }
    66 
    69 
    67 // ----------------------------------------------------------------------------
    70 // ----------------------------------------------------------------------------
    68 // SifUiDialog::dialogType()
    71 // SifUiDialog::dialogType()
    69 // ----------------------------------------------------------------------------
    72 // ----------------------------------------------------------------------------
    83 // SifUiDialog::setDeviceDialogParameters()
    86 // SifUiDialog::setDeviceDialogParameters()
    84 // ----------------------------------------------------------------------------
    87 // ----------------------------------------------------------------------------
    85 //
    88 //
    86 bool SifUiDialog::setDeviceDialogParameters(const QVariantMap &parameters)
    89 bool SifUiDialog::setDeviceDialogParameters(const QVariantMap &parameters)
    87 {
    90 {
    88    return updateFromParameters(parameters);
    91     setVisible(!isInstallIndicatorActive());
       
    92     return updateFromParameters(parameters);
    89 }
    93 }
    90 
    94 
    91 // ----------------------------------------------------------------------------
    95 // ----------------------------------------------------------------------------
    92 // SifUiDialog::deviceDialogError()
    96 // SifUiDialog::deviceDialogError()
    93 // ----------------------------------------------------------------------------
    97 // ----------------------------------------------------------------------------
   158     HbDialog::showEvent(event);
   162     HbDialog::showEvent(event);
   159     mShowEventReceived = true;
   163     mShowEventReceived = true;
   160 }
   164 }
   161 
   165 
   162 // ----------------------------------------------------------------------------
   166 // ----------------------------------------------------------------------------
   163 // SifUiDialog::installTranslator()
   167 // SifUiDialog::isInstallIndicatorActive()
   164 // ----------------------------------------------------------------------------
   168 // ----------------------------------------------------------------------------
   165 //
   169 //
   166 void SifUiDialog::installTranslator()
   170 bool SifUiDialog::isInstallIndicatorActive()
   167 {
   171 {
   168     mTranslator = new QTranslator(this);
   172     bool isActive = false;
   169     QString lang = QLocale::system().name();
   173     if (!mSubscriber) {
   170     mTranslator->load(KTranslationsFile + lang, KTranslationsPath);
   174         mSubscriber = new QTM_PREPEND_NAMESPACE(QValueSpaceSubscriber(
   171     qApp->installTranslator(mTranslator);
   175             KSifUiInstallIndicatorStatusPath));
   172 }
   176     }
   173 
   177     QVariant variant = mSubscriber->value();
   174 // ----------------------------------------------------------------------------
   178     bool valueOk = false;
   175 // SifUiDialog::removeTranslator()
   179     int intValue = variant.toInt(&valueOk);
   176 // ----------------------------------------------------------------------------
   180     if (valueOk && intValue) {
   177 //
   181         isActive = true;
   178 void SifUiDialog::removeTranslator()
   182     }
   179 {
   183     return isActive;
   180     QApplication *app = qApp;
       
   181     if (mTranslator && app) {
       
   182         app->removeTranslator(mTranslator);
       
   183         mTranslator = 0;
       
   184     }
       
   185 }
   184 }
   186 
   185 
   187 // ----------------------------------------------------------------------------
   186 // ----------------------------------------------------------------------------
   188 // SifUiDialog::constructDialog()
   187 // SifUiDialog::constructDialog()
   189 // ----------------------------------------------------------------------------
   188 // ----------------------------------------------------------------------------
   206     mContent->constructFromParameters(parameters);
   205     mContent->constructFromParameters(parameters);
   207     connect(mContent, SIGNAL(memorySelectionChanged(const QChar &)),
   206     connect(mContent, SIGNAL(memorySelectionChanged(const QChar &)),
   208             this, SLOT(handleMemorySelectionChanged(const QChar &)));
   207             this, SLOT(handleMemorySelectionChanged(const QChar &)));
   209     setContentWidget(mContent);
   208     setContentWidget(mContent);
   210 
   209 
   211     updateButtons();
   210     updateButtons(parameters);
   212 
   211 
   213     return true;
   212     return true;
   214 }
   213 }
   215 
   214 
   216 // ----------------------------------------------------------------------------
   215 // ----------------------------------------------------------------------------
   228     if (mContent)
   227     if (mContent)
   229         {
   228         {
   230         mContent->updateFromParameters(parameters);
   229         mContent->updateFromParameters(parameters);
   231         }
   230         }
   232     if (prevDialogType != mDialogType) {
   231     if (prevDialogType != mDialogType) {
   233         updateButtons();
   232         updateButtons(parameters);
   234     }
   233     }
   235     if (parameters.contains(KSifUiErrorCode)) {
   234     if (parameters.contains(KSifUiErrorCode)) {
   236         mInstallError = parameters.value(KSifUiErrorCode).toInt();
   235         mInstallError = parameters.value(KSifUiErrorCode).toInt();
   237     }
   236     }
   238     return true;
   237     return true;
   240 
   239 
   241 // ----------------------------------------------------------------------------
   240 // ----------------------------------------------------------------------------
   242 // SifUiDialog::updateButtons()
   241 // SifUiDialog::updateButtons()
   243 // ----------------------------------------------------------------------------
   242 // ----------------------------------------------------------------------------
   244 //
   243 //
   245 void SifUiDialog::updateButtons()
   244 void SifUiDialog::updateButtons(const QVariantMap &parameters)
   246 {
   245 {
   247     mIgnoreCloseAction = 0;
   246     mIgnoreCloseAction = 0;
   248 
   247 
   249     HbAction *primaryAction = 0;
   248     if (mPrimaryAction) {
       
   249         removeAction(mPrimaryAction);
       
   250         delete mPrimaryAction;
       
   251         mPrimaryAction = 0;
       
   252     }
   250     switch (mDialogType) {
   253     switch (mDialogType) {
   251         case SifUiConfirmationQuery:
   254         case SifUiConfirmationQuery:
   252             //: Accepts the SW install confirmation query and starts installation.
   255             //: Accepts the SW install confirmation query and starts installation.
   253             // TODO: enable when translations ready
   256             mPrimaryAction = new HbAction(hbTrId("txt_common_button_ok"));
   254             //primaryAction = new HbAction(hbTrId("txt_sisxui_install_ok"), this);
   257             connect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(handleAccepted()));
   255             primaryAction = new HbAction(tr("Ok"), this);
   258             mIgnoreCloseAction = mPrimaryAction;
   256             connect(primaryAction, SIGNAL(triggered()), this, SLOT(handleAccepted()));
       
   257             mIgnoreCloseAction = primaryAction;
       
   258             break;
   259             break;
   259         case SifUiProgressNote:
   260         case SifUiProgressNote:
   260             //: Hides the progress dialog. Progress note moves into universal indicator.
   261             if (!parameters.contains(KSifUiProgressNoteIsHideButtonHidden)) {
   261             // TODO: enable when translations ready
   262                 //: Hides the progress dialog. Progress note moves into universal indicator.
   262             //primaryAction = new HbAction(hbTrId("txt_sisxui_install_hide"), this);
   263                 mPrimaryAction = new HbAction(hbTrId("txt_common_button_hide"));
   263             primaryAction = new HbAction(tr("Hide"), this);
   264                 connect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(handleHidePressed()));
   264             connect(primaryAction, SIGNAL(triggered()), this, SLOT(handleHide()));
   265                 mIgnoreCloseAction = mPrimaryAction;
   265             mIgnoreCloseAction = primaryAction;
   266             }
   266             break;
   267             break;
   267         case SifUiCompleteNote:
   268         case SifUiCompleteNote:
   268             //: Opens Application Library to view the installed application.
   269             if (!parameters.contains(KSifUiCompleteNoteIsShowButtonHidden)) {
   269             // TODO: enable when translations ready
   270                 //: Opens Application Library to view the installed application.
   270             //primaryAction = new HbAction(hbTrId("txt_sisxui_install_show"), this);
   271                 mPrimaryAction = new HbAction(hbTrId("txt_installer_button_show"));
   271             primaryAction = new HbAction(tr("Show"), this);
   272                 connect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(handleShowInstalled()));
   272             connect(primaryAction, SIGNAL(triggered()), this, SLOT(handleShowInstalled()));
   273             }
   273             mIgnoreCloseAction = primaryAction;
       
   274             break;
   274             break;
   275         case SifUiErrorNote:
   275         case SifUiErrorNote:
   276             //: Shows a dialog with further info about the failure (i.e. why installation failed).
   276             if (!parameters.contains(KSifUiErrorNoteIsDetailsButtonHidden)) {
   277             // TODO: enable when translations ready
   277                 //: Shows a dialog with further info about the failure (i.e. why installation failed).
   278             //primaryAction = new HbAction(hbTrId("txt_sisxui_install_error_details"), this);
   278                 mPrimaryAction = new HbAction(hbTrId("txt_installer_button_details"));
   279             primaryAction = new HbAction(tr("Details"), this);
   279                 connect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(handleErrorDetails()));
   280             connect(primaryAction, SIGNAL(triggered()), this, SLOT(handleErrorDetails()));
   280                 mIgnoreCloseAction = mPrimaryAction;
   281             mIgnoreCloseAction = primaryAction;
   281             }
   282             break;
   282             break;
   283         default:
   283         default:
   284             break;
   284             break;
   285     }
   285     }
   286     setPrimaryAction(primaryAction);
   286     if (mPrimaryAction) {
   287 
   287         addAction(mPrimaryAction);
   288     HbAction *secondaryAction = 0;
   288     }
       
   289 
       
   290     if (mSecondaryAction) {
       
   291         removeAction(mSecondaryAction);
       
   292         delete mSecondaryAction;
       
   293         mSecondaryAction = 0;
       
   294     }
   289     switch (mDialogType) {
   295     switch (mDialogType) {
   290         case SifUiConfirmationQuery:
   296         case SifUiConfirmationQuery:
   291         case SifUiProgressNote:
   297         case SifUiProgressNote:
   292             //: Cancels the SW install confirmation query and closes the dialog.
   298             if (!parameters.contains(KSifUiProgressNoteIsCancelButtonHidden)) {
   293             // TODO: enable when translations ready
   299                 //: Cancels the SW install confirmation query and closes the dialog.
   294             //secondaryAction = new HbAction(hbTrId("txt_sisxui_install_cancel"), this);
   300                 mSecondaryAction = new HbAction(hbTrId("txt_common_button_cancel"));
   295             secondaryAction = new HbAction(tr("Cancel"), this);
   301                 connect(mSecondaryAction, SIGNAL(triggered()), this, SLOT(handleCancelled()));
   296             connect(secondaryAction, SIGNAL(triggered()), this, SLOT(handleCancelled()));
   302             }
   297             break;
   303             break;
   298         case SifUiCompleteNote:
   304         case SifUiCompleteNote:
   299         case SifUiErrorNote:
   305         case SifUiErrorNote:
   300             //: Closes the dialog. Control returns back to where the installation was started.
   306             //: Closes the dialog. Control returns back to where the installation was started.
   301             // TODO: enable when translations ready
   307             mSecondaryAction = new HbAction(hbTrId("txt_common_button_close"));
   302             //secondaryAction = new HbAction(hbTrId("txt_sisxui_install_close"), this);
   308             connect(mSecondaryAction, SIGNAL(triggered()), this, SLOT(close()));
   303             secondaryAction = new HbAction(tr("Close"), this);
       
   304             connect(secondaryAction, SIGNAL(triggered()), this, SLOT(close()));
       
   305             break;
   309             break;
   306         default:
   310         default:
   307             break;
   311             break;
   308     }
   312     }
   309     setSecondaryAction(secondaryAction);
   313     if (mSecondaryAction) {
       
   314         addAction(mSecondaryAction);
       
   315     }
   310 }
   316 }
   311 
   317 
   312 // ----------------------------------------------------------------------------
   318 // ----------------------------------------------------------------------------
   313 // SifUiDialog::sendResult()
   319 // SifUiDialog::sendResult()
   314 // ----------------------------------------------------------------------------
   320 // ----------------------------------------------------------------------------
   315 //
   321 //
   316 void SifUiDialog::sendResult(bool accepted)
   322 void SifUiDialog::sendResult(SifUiDeviceDialogReturnValue value)
   317 {
   323 {
   318     QVariant acceptedValue(accepted);
   324     QVariant returnValue(value);
   319     mResultMap.insert(KSifUiQueryAccepted, acceptedValue);
   325     mResultMap.insert(KSifUiQueryReturnValue, returnValue);
   320     emit deviceDialogData(mResultMap);
   326     emit deviceDialogData(mResultMap);
   321 }
   327 }
   322 
   328 
   323 // ----------------------------------------------------------------------------
   329 // ----------------------------------------------------------------------------
   324 // SifUiDialog::monitorIndicatorActivity()
       
   325 // ----------------------------------------------------------------------------
       
   326 //
       
   327 void SifUiDialog::monitorIndicatorActivity()
       
   328 {
       
   329     if (!mSubscriber) {
       
   330         mSubscriber = new QValueSpaceSubscriber(KSifUiInstallIndicatorStatusPath);
       
   331         connect(mSubscriber, SIGNAL(contentsChanged()),
       
   332             this, SLOT(handleIndicatorActivityChanged()));
       
   333     }
       
   334 }
       
   335 
       
   336 // ----------------------------------------------------------------------------
       
   337 // SifUiDialog::handleAccepted()
   330 // SifUiDialog::handleAccepted()
   338 // ----------------------------------------------------------------------------
   331 // ----------------------------------------------------------------------------
   339 //
   332 //
   340 void SifUiDialog::handleAccepted()
   333 void SifUiDialog::handleAccepted()
   341 {
   334 {
   342     mContent->changeType(SifUiProgressNote);
   335     mContent->changeType(SifUiProgressNote);
   343     sendResult(true);
   336     sendResult(SifUiContinue);
   344 }
   337 }
   345 
   338 
   346 // ----------------------------------------------------------------------------
   339 // ----------------------------------------------------------------------------
   347 // SifUiDialog::handleCancelled()
   340 // SifUiDialog::handleCancelled()
   348 // ----------------------------------------------------------------------------
   341 // ----------------------------------------------------------------------------
   349 //
   342 //
   350 void SifUiDialog::handleCancelled()
   343 void SifUiDialog::handleCancelled()
   351 {
   344 {
   352     sendResult(false);
   345     sendResult(SifUiCancel);
   353 }
   346 }
   354 
   347 
   355 // ----------------------------------------------------------------------------
   348 // ----------------------------------------------------------------------------
   356 // SifUiDialog::handleMemorySelectionChanged()
   349 // SifUiDialog::handleMemorySelectionChanged()
   357 // ----------------------------------------------------------------------------
   350 // ----------------------------------------------------------------------------
   366 // SifUiDialog::handleHidePressed()
   359 // SifUiDialog::handleHidePressed()
   367 // ----------------------------------------------------------------------------
   360 // ----------------------------------------------------------------------------
   368 //
   361 //
   369 void SifUiDialog::handleHidePressed()
   362 void SifUiDialog::handleHidePressed()
   370 {
   363 {
   371     if (!mIndicator) {
   364     sendResult(SifUiIndicator);
   372         mIndicator = new HbIndicator(this);
   365     hide();
   373         QVariant applicationName(mContent->applicationName());
       
   374         if (!mContent->isDefaultIconUsed()) {
       
   375             // TODO: send icon to indicator
       
   376         }
       
   377         if (mIndicator->activate(KSifUiInstallIndicatorType, applicationName)) {
       
   378             hide();
       
   379             monitorIndicatorActivity();
       
   380         }
       
   381     }
       
   382 }
       
   383 
       
   384 // ----------------------------------------------------------------------------
       
   385 // SifUiDialog::handleIndicatorActivityChanged()
       
   386 // ----------------------------------------------------------------------------
       
   387 //
       
   388 void SifUiDialog::handleIndicatorActivityChanged()
       
   389 {
       
   390     QVariant variant = mSubscriber->value();
       
   391     if (variant.isValid() && (variant.type() == QVariant::Int)) {
       
   392         bool valueOk = false;
       
   393         int intValue = variant.toInt(&valueOk);
       
   394         if (valueOk && intValue) {
       
   395             show();
       
   396         }
       
   397     }
       
   398 }
   366 }
   399 
   367 
   400 // ----------------------------------------------------------------------------
   368 // ----------------------------------------------------------------------------
   401 // SifUiDialog::handleShowInstalled()
   369 // SifUiDialog::handleShowInstalled()
   402 // ----------------------------------------------------------------------------
   370 // ----------------------------------------------------------------------------