appinstaller/AppinstUi/sifuiinstallindicatorplugin/src/sifuiinstallindicator.cpp
changeset 42 d17dc5398051
parent 33 8110bf1194d1
child 55 ac7f90a6ff4c
equal deleted inserted replaced
37:6e7b00453237 42:d17dc5398051
    18 #include "sifuiinstallindicator.h"
    18 #include "sifuiinstallindicator.h"
    19 #include "sifuiinstallindicatorparams.h"
    19 #include "sifuiinstallindicatorparams.h"
    20 #include <QVariant>
    20 #include <QVariant>
    21 #include <qvaluespacepublisher.h>
    21 #include <qvaluespacepublisher.h>
    22 
    22 
    23 const char KSifUiDefaultApplicationIcon[] = "qtg_large_application.svg";
    23 const char KSifUiDefaultApplicationIcon[] = "qtg_large_application";
       
    24 const char KSifUiErrorIcon[] = "qtg_large_warning";
    24 const QString KSifUiPathSeparator = "/";
    25 const QString KSifUiPathSeparator = "/";
    25 
    26 
       
    27 
       
    28 // ======== LOCAL FUNCTIONS =========
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // getIntValue()
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 void getIntValue(const QVariant &variant, int &value)
       
    35 {
       
    36     bool ok = false;
       
    37     int temp = variant.toInt(&ok);
       
    38     if (ok) {
       
    39         value = temp;
       
    40     }
       
    41 }
       
    42 
       
    43 
       
    44 // ======== MEMBER FUNCTIONS ========
    26 
    45 
    27 // ---------------------------------------------------------------------------
    46 // ---------------------------------------------------------------------------
    28 // SifUiInstallIndicator::SifUiInstallIndicator()
    47 // SifUiInstallIndicator::SifUiInstallIndicator()
    29 // ---------------------------------------------------------------------------
    48 // ---------------------------------------------------------------------------
    30 //
    49 //
    31 SifUiInstallIndicator::SifUiInstallIndicator(const QString &indicatorType) :
    50 SifUiInstallIndicator::SifUiInstallIndicator(const QString &indicatorType) :
    32     HbIndicatorInterface(indicatorType, HbIndicatorInterface::ProgressCategory,
    51     HbIndicatorInterface(indicatorType, HbIndicatorInterface::ProgressCategory,
    33             InteractionActivated), mAppName(), mPublisher(0), mIsActive(false)
    52             InteractionActivated), mAppName(), mProgress(0), mPublisher(0),
       
    53             mIsActive(false), mPhase(Installing), mIsComplete(false), mErrorCode(0)
    34 {
    54 {
    35     mPublisher = new QTM_PREPEND_NAMESPACE(QValueSpacePublisher(KSifUiInstallIndicatorPath));
    55     mPublisher = new QTM_PREPEND_NAMESPACE(QValueSpacePublisher(KSifUiInstallIndicatorPath));
    36 }
    56 }
    37 
    57 
    38 // ---------------------------------------------------------------------------
    58 // ---------------------------------------------------------------------------
    72 {
    92 {
    73     QVariant data;
    93     QVariant data;
    74 
    94 
    75     switch(role) {
    95     switch(role) {
    76         case DecorationNameRole:
    96         case DecorationNameRole:
    77             data = QString(KSifUiDefaultApplicationIcon);
    97             if (mIsComplete && mErrorCode) {
    78             break;
    98                 data = QString(KSifUiErrorIcon);
       
    99             } else {
       
   100                 // TODO: how to set application specific icon if defined?
       
   101                 data = QString(KSifUiDefaultApplicationIcon);
       
   102             }
       
   103             break;
       
   104 
    79         case PrimaryTextRole:
   105         case PrimaryTextRole:
    80             //: Primary text for application installation progress displayed in
   106             if (mIsComplete) {
    81             //: universal indicator menu. Secondary text is the application name.
   107                 if (mErrorCode) {
    82             // TODO: use localised UI string when available
   108                     //: Indicates that application installation failed.
    83             data = tr("Installing");
   109                     // TODO: localized UI string needed
    84             // TODO: text must indicate installation phase, need to support also
   110                     data = tr("Installation failed");
    85             // tr("Downloading") and tr("Doing OCSP checks")
   111                 } else {
    86             break;
   112                     //: Indicates that application installation is completed.
       
   113                     // TODO: localized UI string needed
       
   114                     data = tr("Installed");
       
   115                 }
       
   116             } else {
       
   117                 switch(mPhase) {
       
   118                     case Installing:
       
   119                         //: Indicates that application installation is ongoing.
       
   120                         // TODO: localized UI string needed
       
   121                         data = tr("Installing");
       
   122                         break;
       
   123                     case Downloading:
       
   124                         //: Indicates that download is ongoing.
       
   125                         // TODO: localized UI string needed
       
   126                         data = tr("Downloading");
       
   127                         break;
       
   128                     case CheckingCerts:
       
   129                         //: Indicates that OCSP check is ongoing.
       
   130                         // TODO: localized UI string needed
       
   131                         data = tr("Checking certificates");
       
   132                         break;
       
   133                     default:
       
   134                         break;
       
   135                 }
       
   136             }
       
   137             break;
       
   138 
    87         case SecondaryTextRole:
   139         case SecondaryTextRole:
    88             if (!mAppName.isEmpty()) {
   140             if (mIsComplete) {
    89                 data = tr("%1 (%L2 %)").arg(mAppName).arg(mProgress);
   141                 data = mAppName;
    90             }
   142             } else {
       
   143                 if (!mAppName.isEmpty()) {
       
   144                     //: Application name %1 followed by installation progress %L2
       
   145                     // TODO: localized UI string needed
       
   146                     data = tr("%1 (%L2 %)").arg(mAppName).arg(mProgress);
       
   147                 }
       
   148             }
       
   149             break;
       
   150 
    91         default:
   151         default:
    92             break;
   152             break;
    93     }
   153     }
    94 
   154 
    95     return data;
   155     return data;
   123 // SifUiInstallIndicator::processParameters()
   183 // SifUiInstallIndicator::processParameters()
   124 // ---------------------------------------------------------------------------
   184 // ---------------------------------------------------------------------------
   125 //
   185 //
   126 void SifUiInstallIndicator::processParameters(const QVariant &parameter)
   186 void SifUiInstallIndicator::processParameters(const QVariant &parameter)
   127 {
   187 {
   128     if (parameter.isValid() && (parameter.type() == QVariant::String)) {
   188     if (parameter.isValid()) {
   129         mAppName = parameter.toString();
   189         if (parameter.type() == QVariant::String) {
   130         mProgress = 0;
   190             mAppName = parameter.toString();
   131 
   191         } else if (parameter.type() == QVariant::Int) {
   132         // TODO: get icon if standard icon needs to be replaced
   192             getIntValue(parameter, mProgress);
   133         // TODO: start listening USIF installation progress
   193         } else if (parameter.type() == QVariant::Map) {
       
   194             QVariantMap map = parameter.toMap();
       
   195             QMapIterator<QString,QVariant> iter(map);
       
   196             while (iter.hasNext()) {
       
   197                 iter.next();
       
   198                 if (iter.key() == KSifUiInstallIndicatorAppNameKey) {
       
   199                     mAppName = iter.value().toString();
       
   200                 } else if (iter.key() == KSifUiInstallIndicatorPhaseKey) {
       
   201                     int value = Installing;
       
   202                     getIntValue(iter.value(), value);
       
   203                     mPhase = static_cast<Phase>(value);
       
   204                 } else if (iter.key() == KSifUiInstallIndicatorProgressKey) {
       
   205                     getIntValue(iter.value(), mProgress);
       
   206                 } else if (iter.key() == KSifUiInstallIndicatorCompleteKey) {
       
   207                     mIsComplete = true;
       
   208                     mErrorCode = KErrNone;
       
   209                     getIntValue(iter.value(), mErrorCode);
       
   210                 } else if (iter.key() == KSifUiInstallIndicatorIconKey) {
       
   211                     // TODO: icon?
       
   212                 } else {
       
   213                     // ignore other types
       
   214                 }
       
   215             }
       
   216         } else {
       
   217             // ignore other types
       
   218         }
   134     }
   219     }
   135 }
   220 }
   136 
   221 
   137 // ---------------------------------------------------------------------------
   222 // ---------------------------------------------------------------------------
   138 // SifUiInstallIndicator::publishActivityStatus()
   223 // SifUiInstallIndicator::publishActivityStatus()