src/hbplugins/devicedialogs/deviceprogressdialogplugin/hbdeviceprogressdialogwidget.cpp
changeset 0 16d8024aca5e
child 2 06ff229162e9
equal deleted inserted replaced
-1:000000000000 0:16d8024aca5e
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbPlugins module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 
       
    26 #include <hbdialog.h>
       
    27 #include <hbaction.h>
       
    28 #include <hbprogressdialog.h>
       
    29 #include <hbdevicedialogtrace_p.h>
       
    30 #include <hbiconanimationmanager.h>
       
    31 #include "hbdeviceprogressdialogwidget_p.h"
       
    32 #include "hbdeviceprogressdialogpluginerrors_p.h"
       
    33 
       
    34 // Constructor
       
    35 HbDeviceProgressDialogWidget::HbDeviceProgressDialogWidget(HbProgressDialog::ProgressDialogType progressDialogType,
       
    36     const QVariantMap &parameters) : HbProgressDialog(progressDialogType)
       
    37 {
       
    38     TRACE_ENTRY
       
    39     mLastError = NoError;
       
    40     mProgressDialogType = progressDialogType;
       
    41     mShowEventReceived = false;
       
    42     mPrimaryAction = 0;
       
    43     resetProperties();
       
    44     constructDialog(parameters);
       
    45     if (!mPrimaryAction) {
       
    46         // If HbProgressDialog default button is used, connect into its triggered signal.
       
    47         HbAction *action = primaryAction();
       
    48         if (action) {
       
    49             connect(action, SIGNAL(triggered()), SLOT(primaryActionTriggered()));
       
    50         }
       
    51     }
       
    52     setBackgroundFaded(true);
       
    53     TRACE_EXIT
       
    54 }
       
    55 
       
    56 // Destructor
       
    57 HbDeviceProgressDialogWidget::~HbDeviceProgressDialogWidget()
       
    58 {
       
    59     delete mPrimaryAction;
       
    60 }
       
    61 
       
    62 // Set parameters
       
    63 bool HbDeviceProgressDialogWidget::setDeviceDialogParameters(const QVariantMap &parameters)
       
    64 {
       
    65     TRACE_ENTRY
       
    66     mLastError = NoError;
       
    67     bool ret(false);
       
    68     if (checkProperties(parameters)) {
       
    69         setProperties(parameters);
       
    70         ret = true;
       
    71     } else {
       
    72         mLastError = ParameterError;
       
    73         ret = false;
       
    74     }
       
    75     TRACE_EXIT
       
    76     return ret;
       
    77 }
       
    78 
       
    79 // Get error
       
    80 int HbDeviceProgressDialogWidget::deviceDialogError() const
       
    81 {
       
    82     TRACE_ENTRY
       
    83     TRACE_EXIT
       
    84     return mLastError;
       
    85 }
       
    86 
       
    87 // Close device dialog
       
    88 void HbDeviceProgressDialogWidget::closeDeviceDialog(bool byClient)
       
    89 {
       
    90     TRACE_ENTRY
       
    91     Q_UNUSED(byClient);
       
    92     cancel();
       
    93     // If show event has been received, close is signalled from hide event. If not,
       
    94     // hide event does not come and close is signalled from here.
       
    95     if (!mShowEventReceived) {
       
    96         emit deviceDialogClosed();
       
    97     }
       
    98     TRACE_EXIT
       
    99 }
       
   100 
       
   101 // Return display widget
       
   102 HbDialog *HbDeviceProgressDialogWidget::deviceDialogWidget() const
       
   103 {
       
   104     TRACE_ENTRY
       
   105     TRACE_EXIT
       
   106     return const_cast<HbDeviceProgressDialogWidget*>(this);
       
   107 }
       
   108 
       
   109 // Get dialog type from parameters
       
   110 bool HbDeviceProgressDialogWidget::getDialogType(HbProgressDialog::ProgressDialogType &progressDialogType,
       
   111     QVariantMap &parameters)
       
   112 {
       
   113     TRACE_STATIC_ENTRY
       
   114     const char *key = "progressDialogType";
       
   115     progressDialogType = HbProgressDialog::WaitDialog;
       
   116     bool dialogTypeOk = true;
       
   117     QVariantMap::const_iterator i = parameters.find(key);
       
   118     if (i != parameters.constEnd()) {
       
   119         progressDialogType = static_cast<HbProgressDialog::ProgressDialogType>(i.value().toInt(&dialogTypeOk));
       
   120         dialogTypeOk = dialogTypeOk && progressDialogType >= HbProgressDialog::ProgressDialog &&
       
   121             progressDialogType <= HbProgressDialog::WaitDialog;
       
   122         parameters.remove(key);
       
   123     }
       
   124     TRACE_EXIT
       
   125     return dialogTypeOk;
       
   126 }
       
   127 
       
   128 // Construct device dialog
       
   129 bool HbDeviceProgressDialogWidget::constructDialog(const QVariantMap &parameters)
       
   130 {
       
   131     TRACE_ENTRY
       
   132     bool ret(false);
       
   133     // Check that parameters are valid
       
   134     if (!checkProperties(parameters)) {
       
   135         mLastError = ParameterError;
       
   136         ret = false;
       
   137     } else {
       
   138         setProperties(parameters);
       
   139         ret = true;
       
   140     }
       
   141     TRACE_EXIT
       
   142     return ret;
       
   143 }
       
   144 
       
   145 // Check that device dialog parameters are valid
       
   146 bool HbDeviceProgressDialogWidget::checkProperties(const QVariantMap &parameters)
       
   147 {
       
   148     TRACE_ENTRY
       
   149     QVariantMap::const_iterator i = parameters.constBegin();
       
   150     while (i != parameters.constEnd()) {
       
   151         QByteArray key = i.key().toAscii();
       
   152         if (!property(key.constData()).isValid()) {
       
   153             TRACE_EXIT
       
   154             return false;
       
   155         }
       
   156         ++i;
       
   157     }
       
   158     TRACE_EXIT
       
   159     return true;
       
   160 }
       
   161 
       
   162 // Set properties
       
   163 void HbDeviceProgressDialogWidget::setProperties(const QVariantMap &parameters)
       
   164 {
       
   165     TRACE_ENTRY
       
   166     QVariantMap::const_iterator i = parameters.constBegin();
       
   167     while (i != parameters.constEnd()) {
       
   168         QByteArray key = i.key().toAscii();
       
   169         if (property(key.constData()).isValid()) {
       
   170             setProperty(key.constData(), i.value());
       
   171         }
       
   172         ++i;
       
   173     }
       
   174     TRACE_EXIT
       
   175     return;
       
   176 }
       
   177 
       
   178 // Reset properties to default values
       
   179 void HbDeviceProgressDialogWidget::resetProperties()
       
   180 {
       
   181     TRACE_ENTRY
       
   182     mIconName.clear();
       
   183     setModal(true);
       
   184     setTimeout(HbPopup::NoTimeout);
       
   185     setDismissPolicy(HbPopup::NoDismiss);
       
   186     TRACE_EXIT
       
   187     return;
       
   188 }
       
   189 
       
   190 QString HbDeviceProgressDialogWidget::iconName() const
       
   191 {
       
   192     return mIconName;
       
   193 }
       
   194 
       
   195 void HbDeviceProgressDialogWidget::setIconName(QString &iconName)
       
   196 {
       
   197     TRACE_ENTRY
       
   198     if (mIconName != iconName) {
       
   199         mIconName = iconName;
       
   200         setIcon(HbIcon(mIconName));
       
   201     }
       
   202     TRACE_EXIT
       
   203     return;
       
   204 }
       
   205 
       
   206 QString HbDeviceProgressDialogWidget::primaryActionText() const
       
   207 {
       
   208     HbAction *action = primaryAction();
       
   209     return action ? action->text() : QString();
       
   210 }
       
   211 
       
   212 void HbDeviceProgressDialogWidget::setPrimaryActionText(QString &actionText)
       
   213 {
       
   214     TRACE_ENTRY
       
   215     HbAction *action = primaryAction();
       
   216     if (action) {
       
   217         action->setText(actionText);
       
   218     } else {
       
   219         if (!mPrimaryAction) {
       
   220             mPrimaryAction = new HbAction(actionText);
       
   221             connect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(primaryActionTriggered()));
       
   222         } else {
       
   223             mPrimaryAction->setText(actionText);
       
   224         }
       
   225         setPrimaryAction(mPrimaryAction);
       
   226     }
       
   227     TRACE_EXIT
       
   228 }
       
   229 
       
   230 bool HbDeviceProgressDialogWidget::primaryActionNull() const
       
   231 {
       
   232     return primaryAction() == 0;
       
   233 }
       
   234 
       
   235 void HbDeviceProgressDialogWidget::setPrimaryActionNull(bool isNull)
       
   236 {
       
   237     TRACE_ENTRY
       
   238     if (isNull) {
       
   239         // If there is a message box's default action, disconnect from it.
       
   240         HbAction *action = primaryAction();
       
   241         if (action && mPrimaryAction == 0) {
       
   242             action->disconnect(SIGNAL(triggered()), this, SLOT(primaryActionTriggered()));
       
   243         }
       
   244         setPrimaryAction(0);
       
   245     } else {
       
   246         QString text = mPrimaryAction ? mPrimaryAction->text() : QString();
       
   247         setPrimaryActionText(text);
       
   248     }
       
   249     TRACE_EXIT
       
   250 }
       
   251 
       
   252 QString HbDeviceProgressDialogWidget::animationDefinition() const
       
   253 {
       
   254     return mAnimationDefinition;
       
   255 }
       
   256 
       
   257 void HbDeviceProgressDialogWidget::setAnimationDefinition(QString &animationDefinition)
       
   258 {
       
   259     // Load animation definition
       
   260     HbIconAnimationManager *manager = HbIconAnimationManager::global();
       
   261     manager->addDefinitionFile(animationDefinition);
       
   262     mAnimationDefinition = animationDefinition;
       
   263 }
       
   264 
       
   265 // Widget is about to hide. Closing effect has ended.
       
   266 void HbDeviceProgressDialogWidget::hideEvent(QHideEvent *event)
       
   267 {
       
   268     HbProgressDialog::hideEvent(event);
       
   269     emit deviceDialogClosed();
       
   270 }
       
   271 
       
   272 // Widget is about to show
       
   273 void HbDeviceProgressDialogWidget::showEvent(QShowEvent *event)
       
   274 {
       
   275     HbProgressDialog::showEvent(event);
       
   276     mShowEventReceived = true;
       
   277 }
       
   278 
       
   279 // Primary action triggered
       
   280 void HbDeviceProgressDialogWidget::primaryActionTriggered()
       
   281 {
       
   282     TRACE_ENTRY
       
   283     QVariantMap data;
       
   284     data.insert("act", "p");
       
   285     emit deviceDialogData(data);
       
   286     TRACE_EXIT
       
   287 }