appinstaller/AppinstUi/sifuidevicedialogplugin/src/sifuidialogtitlewidget.cpp
changeset 25 98b66e4fb0be
child 29 26b6f0522fd8
equal deleted inserted replaced
24:84a16765cd86 25:98b66e4fb0be
       
     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: SIF UI dialog title widget.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "sifuidialogtitlewidget.h"
       
    19 #include "sifuidialog.h"                    // dialogType, dialogMode
       
    20 #include <QGraphicsLinearLayout>
       
    21 #include <hblabel.h>
       
    22 #include <hbpushbutton.h>
       
    23 
       
    24 // See definitions in sifuidevicedialogplugin.qrc
       
    25 const char KSifUiDialogIconCertificates[] = ":/cert_indi_icon.svg";
       
    26 
       
    27 
       
    28 // ----------------------------------------------------------------------------
       
    29 // SifUiDialogTitleWidget::SifUiDialogTitleWidget()
       
    30 // ----------------------------------------------------------------------------
       
    31 //
       
    32 SifUiDialogTitleWidget::SifUiDialogTitleWidget(QGraphicsItem *parent,
       
    33         Qt::WindowFlags flags): HbWidget(parent, flags),
       
    34         mLayout(0), mTitle(0), mCertButton(0)
       
    35 {
       
    36 }
       
    37 
       
    38 // ----------------------------------------------------------------------------
       
    39 // SifUiDialogTitleWidget::~SifUiDialogTitleWidget()
       
    40 // ----------------------------------------------------------------------------
       
    41 //
       
    42 SifUiDialogTitleWidget::~SifUiDialogTitleWidget()
       
    43 {
       
    44 }
       
    45 
       
    46 // ----------------------------------------------------------------------------
       
    47 // SifUiDialogTitleWidget::constructFromParameters()
       
    48 // ----------------------------------------------------------------------------
       
    49 //
       
    50 void SifUiDialogTitleWidget::constructFromParameters(const QVariantMap &parameters)
       
    51 {
       
    52     mLayout = new QGraphicsLinearLayout(Qt::Horizontal);
       
    53 
       
    54     Q_ASSERT(mTitle == 0);
       
    55     HbLabel *titleLabel = 0;
       
    56     if (parameters.contains(KSifUiDialogTitle)) {
       
    57         QString titleText = parameters.value(KSifUiDialogTitle).toString();
       
    58         titleLabel = new HbLabel(titleText);
       
    59     } else {
       
    60         SifUiDeviceDialogType type = SifUiDialog::dialogType(parameters);
       
    61         SifUiDeviceDialogMode mode = SifUiDialog::dialogMode(parameters);
       
    62         titleLabel = new HbLabel(defaultTitle(type, mode));
       
    63     }
       
    64     titleLabel->setFontSpec(HbFontSpec(HbFontSpec::Title));
       
    65     mLayout->addItem(titleLabel);
       
    66     mTitle = titleLabel;
       
    67 
       
    68     createCertButton();
       
    69 
       
    70     setLayout(mLayout);
       
    71 }
       
    72 
       
    73 // ----------------------------------------------------------------------------
       
    74 // SifUiDialogTitleWidget::updateFromParameters()
       
    75 // ----------------------------------------------------------------------------
       
    76 //
       
    77 void SifUiDialogTitleWidget::updateFromParameters(const QVariantMap &parameters)
       
    78 {
       
    79     Q_ASSERT(mTitle != 0);
       
    80 
       
    81     QString titleText;
       
    82     if (parameters.contains(KSifUiDialogTitle)) {
       
    83         titleText = parameters.value(KSifUiDialogTitle).toString();
       
    84     } else {
       
    85         SifUiDeviceDialogType type = SifUiDialog::dialogType(parameters);
       
    86         SifUiDeviceDialogMode mode = SifUiDialog::dialogMode(parameters);
       
    87         titleText = defaultTitle(type, mode);
       
    88     }
       
    89     if (titleText != mTitle->plainText()) {
       
    90         mTitle->setPlainText(titleText);
       
    91     }
       
    92 
       
    93     if (parameters.contains(KSifUiCertificates)) {
       
    94         createCertButton();
       
    95     } else {
       
    96         removeCertButton();
       
    97     }
       
    98 }
       
    99 
       
   100 // ----------------------------------------------------------------------------
       
   101 // SifUiDialogTitleWidget::defaultTitle()
       
   102 // ----------------------------------------------------------------------------
       
   103 //
       
   104 QString SifUiDialogTitleWidget::defaultTitle(SifUiDeviceDialogType type,
       
   105     SifUiDeviceDialogMode mode)
       
   106 {
       
   107     QString title;
       
   108     switch (mode) {
       
   109         case SifUiInstalling:
       
   110             switch (type) {
       
   111                 case SifUiConfirmationQuery:
       
   112                     //: Install confirmation query title. Installation starts if
       
   113                     //: the user accepts the query.
       
   114                     // TODO: enable when translations ready
       
   115                     //title = hbTrId("txt_sisxui_install_conf_head");
       
   116                     title = tr("Install?");
       
   117                     break;
       
   118                 case SifUiProgressNote:
       
   119                     //: Progress note title. Installation is going on and progress
       
   120                     //: bar shows how it proceeds.
       
   121                     // TODO: enable when translations ready
       
   122                     //title = hbTrId("txt_sisxui_installing_progress_head");
       
   123                     title = tr("Installing");
       
   124                     break;
       
   125                 case SifUiCompleteNote:
       
   126                     //: Installation complete note title. Indicates that installation
       
   127                     //: was succesfully completed. User has option to launch AppLib
       
   128                     // TODO: enable when translations ready
       
   129                     //title = hbTrId("txt_sisxui_install_complete_head");
       
   130                     title = tr("Installed");
       
   131                     break;
       
   132                 case SifUiErrorNote:
       
   133                     //: Installation failed note title. Indicates that installation failed.
       
   134                     // TODO: enable when translations ready
       
   135                     //title = hbTrId("txt_sisxui_install_failed_head");
       
   136                     title = tr("Install failed");
       
   137                     break;
       
   138                 case SifUiUnspecifiedDialog:
       
   139                 default:
       
   140                     break;
       
   141             }
       
   142             break;
       
   143         case SifUiUninstalling:
       
   144             switch (type) {
       
   145                 case SifUiConfirmationQuery:
       
   146                     //: Uninstall confirmation query title. Asks permission to
       
   147                     //: remove selected application/other content.
       
   148                     // TODO: enable when translations ready
       
   149                     //title = hbTrId("txt_sisxui_uninstall_conf_head");
       
   150                     title = tr("Remove?");
       
   151                     break;
       
   152                 case SifUiProgressNote:
       
   153                     //: Progress note title. Uninstallation is going on and progress
       
   154                     //: bar shows how it proceeds.
       
   155                     // TODO: enable when translations ready
       
   156                     //title = hbTrId("txt_sisxui_uninstalling_progress_head");
       
   157                     title = tr("Removing");
       
   158                     break;
       
   159                 case SifUiCompleteNote:
       
   160                     //: Uninstallation complete note title. Indicates that application
       
   161                     //: was succesfully removed.
       
   162                     // TODO: enable when translations ready
       
   163                     //title = hbTrId("txt_sisxui_uninstall_complete_head");
       
   164                     title = tr("Removed");
       
   165                     break;
       
   166                 case SifUiErrorNote:
       
   167                     //: Uninstallation failed note title. Indicates that uninstallation failed.
       
   168                     // TODO: enable when translations ready
       
   169                     //title = hbTrId("txt_sisxui_uninstall_failed_head");
       
   170                     title = tr("Uninstall failed");
       
   171                     break;
       
   172                 case SifUiUnspecifiedDialog:
       
   173                 default:
       
   174                     break;
       
   175             }
       
   176             break;
       
   177         case SifUiUnspecified:
       
   178         default:
       
   179             break;
       
   180     }
       
   181     return title;
       
   182 }
       
   183 
       
   184 // ----------------------------------------------------------------------------
       
   185 // SifUiDialogTitleWidget::createCertButton()
       
   186 // ----------------------------------------------------------------------------
       
   187 //
       
   188 void SifUiDialogTitleWidget::createCertButton()
       
   189 {
       
   190     if (!mCertButton) {
       
   191         HbPushButton *certButton = new HbPushButton;
       
   192         certButton->setIcon(HbIcon(KSifUiDialogIconCertificates));
       
   193         connect(certButton,SIGNAL(clicked()),this,SIGNAL(certificatesClicked()));
       
   194         mLayout->addStretch();
       
   195         mLayout->addItem(certButton);
       
   196         mLayout->setAlignment(certButton, Qt::AlignRight|Qt::AlignVCenter);
       
   197         mCertButton = certButton;
       
   198     }
       
   199 }
       
   200 
       
   201 // ----------------------------------------------------------------------------
       
   202 // SifUiDialogTitleWidget::removeCertButton()
       
   203 // ----------------------------------------------------------------------------
       
   204 //
       
   205 void SifUiDialogTitleWidget::removeCertButton()
       
   206 {
       
   207     if (mCertButton && mLayout) {
       
   208         mLayout->removeItem(mCertButton);
       
   209         delete mCertButton;
       
   210         mCertButton = 0;
       
   211     }
       
   212 }
       
   213