appinstaller/AppinstUi/sifuiinstallindicatorplugin/src/sifuiinstallindicator.cpp
branchRCL_3
changeset 25 7333d7932ef7
equal deleted inserted replaced
24:5cc91383ab1e 25:7333d7932ef7
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Software install progress indicator
       
    15 *
       
    16 */
       
    17 
       
    18 #include "sifuiinstallindicator.h"
       
    19 #include "sifuiinstallindicatorparams.h"
       
    20 #include <QVariant>
       
    21 #include <qvaluespacepublisher.h>
       
    22 
       
    23 const char KSifUiDefaultApplicationIcon[] = "qtg_large_application";
       
    24 const char KSifUiErrorIcon[] = "qtg_large_warning";
       
    25 const QString KSifUiPathSeparator = "/";
       
    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 ========
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // SifUiInstallIndicator::SifUiInstallIndicator()
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 SifUiInstallIndicator::SifUiInstallIndicator(const QString &indicatorType) :
       
    51     HbIndicatorInterface(indicatorType, HbIndicatorInterface::ProgressCategory,
       
    52             InteractionActivated), mAppName(), mProgress(0), mPublisher(0),
       
    53             mIsActive(false), mPhase(Installing), mIsComplete(false), mErrorCode(0)
       
    54 {
       
    55     mPublisher = new QTM_PREPEND_NAMESPACE(QValueSpacePublisher(KSifUiInstallIndicatorPath));
       
    56 }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // SifUiInstallIndicator::~SifUiInstallIndicator()
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 SifUiInstallIndicator::~SifUiInstallIndicator()
       
    63 {
       
    64     if (mPublisher && mIsActive) {
       
    65         publishActivityStatus(false);
       
    66     }
       
    67     delete mPublisher;
       
    68 }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // SifUiInstallIndicator::handleInteraction()
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 bool SifUiInstallIndicator::handleInteraction(InteractionType type)
       
    75 {
       
    76     bool handled = false;
       
    77 
       
    78     if (type == InteractionActivated) {
       
    79         emit deactivate();
       
    80         publishActivityStatus(false);
       
    81         handled = true;
       
    82     }
       
    83 
       
    84     return handled;
       
    85 }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // SifUiInstallIndicator::indicatorData()
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 QVariant SifUiInstallIndicator::indicatorData(int role) const
       
    92 {
       
    93     QVariant data;
       
    94 
       
    95     switch(role) {
       
    96         case DecorationNameRole:
       
    97             if (mIsComplete && mErrorCode) {
       
    98                 data = QString(KSifUiErrorIcon);
       
    99             } else {
       
   100                 // TODO: how to set application specific icon if defined?
       
   101                 data = QString(KSifUiDefaultApplicationIcon);
       
   102             }
       
   103             break;
       
   104 
       
   105         case PrimaryTextRole:
       
   106             if (mIsComplete) {
       
   107                 if (mErrorCode) {
       
   108                     //: Indicates that application installation failed.
       
   109                     // TODO: localized UI string needed
       
   110                     data = tr("Installation failed");
       
   111                 } else {
       
   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 
       
   139         case SecondaryTextRole:
       
   140             if (mIsComplete) {
       
   141                 data = mAppName;
       
   142             } else {
       
   143                 switch (mPhase) {
       
   144                     case Installing:
       
   145                     case Downloading:
       
   146                         if (!mAppName.isEmpty()) {
       
   147                             //: Application name %1 followed by installation progress %L2
       
   148                             // TODO: localized UI string needed
       
   149                             data = tr("%1 (%L2 %)").arg(mAppName).arg(mProgress);
       
   150                         }
       
   151                         break;
       
   152                     case CheckingCerts:
       
   153                     default:
       
   154                         data = mAppName;
       
   155                         break;
       
   156                 }
       
   157             }
       
   158             break;
       
   159 
       
   160         default:
       
   161             break;
       
   162     }
       
   163 
       
   164     return data;
       
   165 }
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // SifUiInstallIndicator::prepareDisplayName()
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 bool SifUiInstallIndicator::handleClientRequest(RequestType type, const QVariant &parameter)
       
   172 {
       
   173     bool indicatorDisplayed = false;
       
   174 
       
   175     switch (type) {
       
   176         case RequestActivate:
       
   177             processParameters(parameter);
       
   178             indicatorDisplayed = true;
       
   179             emit dataChanged();
       
   180             break;
       
   181         case RequestDeactivate:
       
   182             break;
       
   183         default:
       
   184             break;
       
   185     }
       
   186 
       
   187     publishActivityStatus(indicatorDisplayed);
       
   188     return indicatorDisplayed;
       
   189 }
       
   190 
       
   191 // ---------------------------------------------------------------------------
       
   192 // SifUiInstallIndicator::processParameters()
       
   193 // ---------------------------------------------------------------------------
       
   194 //
       
   195 void SifUiInstallIndicator::processParameters(const QVariant &parameter)
       
   196 {
       
   197     if (parameter.isValid()) {
       
   198         if (parameter.type() == QVariant::String) {
       
   199             mAppName = parameter.toString();
       
   200         } else if (parameter.type() == QVariant::Int) {
       
   201             getIntValue(parameter, mProgress);
       
   202         } else if (parameter.type() == QVariant::Map) {
       
   203             QVariantMap map = parameter.toMap();
       
   204             QMapIterator<QString,QVariant> iter(map);
       
   205             while (iter.hasNext()) {
       
   206                 iter.next();
       
   207                 if (iter.key() == KSifUiInstallIndicatorAppName) {
       
   208                     mAppName = iter.value().toString();
       
   209                 } else if (iter.key() == KSifUiInstallIndicatorPhase) {
       
   210                     int value = Installing;
       
   211                     getIntValue(iter.value(), value);
       
   212                     mPhase = static_cast<Phase>(value);
       
   213                 } else if (iter.key() == KSifUiInstallIndicatorProgress) {
       
   214                     getIntValue(iter.value(), mProgress);
       
   215                 } else if (iter.key() == KSifUiInstallIndicatorComplete) {
       
   216                     mIsComplete = true;
       
   217                     mErrorCode = KErrNone;
       
   218                     getIntValue(iter.value(), mErrorCode);
       
   219                 } else if (iter.key() == KSifUiInstallIndicatorIcon) {
       
   220                     // TODO: icon?
       
   221                 } else {
       
   222                     // ignore other types
       
   223                 }
       
   224             }
       
   225         } else {
       
   226             // ignore other types
       
   227         }
       
   228     }
       
   229 }
       
   230 
       
   231 // ---------------------------------------------------------------------------
       
   232 // SifUiInstallIndicator::publishActivityStatus()
       
   233 // ---------------------------------------------------------------------------
       
   234 //
       
   235 void SifUiInstallIndicator::publishActivityStatus(bool status)
       
   236 {
       
   237     if (status != mIsActive) {
       
   238         if (mPublisher) {
       
   239             int intStatus = status;
       
   240             mPublisher->setValue(KSifUiInstallIndicatorStatus, QVariant(intStatus));
       
   241             mPublisher->sync();
       
   242         }
       
   243         mIsActive = status;
       
   244     }
       
   245 }
       
   246