bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialognotifwidget.cpp
branchRCL_3
changeset 56 9386f31cc85b
parent 55 613943a21004
child 61 269724087bed
equal deleted inserted replaced
55:613943a21004 56:9386f31cc85b
     1 /*
       
     2 * Copyright (c) 2009 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:  BtDeviceDialogWidget class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "btdevicedialognotifwidget.h"
       
    20 #include "btdevicedialogplugintrace.h"
       
    21 #include <bluetoothdevicedialogs.h>
       
    22 #include <hbaction.h>
       
    23 #include <hbdialog.h>
       
    24 #include "btdevicedialogpluginerrors.h"
       
    25 #include <btuiiconutil.h>
       
    26 /*!
       
    27     class Constructor
       
    28  */
       
    29 BtDeviceDialogNotifWidget::BtDeviceDialogNotifWidget( const QVariantMap &parameters )
       
    30 {
       
    31     TRACE_ENTRY
       
    32     // set properties
       
    33     mLastError = NoError;
       
    34     mShowEventReceived = false;
       
    35     mNotificationDialog = new HbNotificationDialog();
       
    36     resetProperties();
       
    37     constructNotifDialog(parameters);
       
    38     TRACE_EXIT
       
    39 }
       
    40 
       
    41 /*!
       
    42     class Constructor
       
    43  */
       
    44 BtDeviceDialogNotifWidget::~BtDeviceDialogNotifWidget()
       
    45 {
       
    46     TRACE_ENTRY
       
    47     delete mNotificationDialog;
       
    48     return;
       
    49 }
       
    50 
       
    51 /*!
       
    52     Set parameters, implementation of interface
       
    53     Invoked when HbDeviceDialog::update calls.
       
    54  */
       
    55 bool BtDeviceDialogNotifWidget::setDeviceDialogParameters(
       
    56     const QVariantMap &parameters)
       
    57 {
       
    58     TRACE_ENTRY
       
    59     mLastError = NoError;
       
    60     processParam(parameters);
       
    61     TRACE_EXIT
       
    62     return true;
       
    63 }
       
    64 
       
    65 /*!
       
    66     Get error, implementation of interface
       
    67  */
       
    68 int BtDeviceDialogNotifWidget::deviceDialogError() const
       
    69 {
       
    70     TRACE_ENTRY
       
    71     TRACE_EXIT
       
    72     return mLastError;
       
    73 }
       
    74 
       
    75 /*!
       
    76     Close notification, implementation of interface
       
    77  */ 
       
    78 void BtDeviceDialogNotifWidget::closeDeviceDialog(bool byClient)
       
    79 {
       
    80     TRACE_ENTRY
       
    81     Q_UNUSED(byClient);
       
    82     // Closed by client or internally by server -> no action to be transmitted.
       
    83     mSendAction = false;
       
    84     mNotificationDialog->close();
       
    85      // If show event has been received, close is signalled from hide event. If not,
       
    86     // hide event does not come and close is signalled from here.
       
    87     if (!mShowEventReceived) {
       
    88         emit deviceDialogClosed();
       
    89     }
       
    90     TRACE_EXIT
       
    91 }
       
    92 
       
    93 /*!
       
    94     Return display widget, implementation of interface
       
    95  */
       
    96 HbPopup *BtDeviceDialogNotifWidget::deviceDialogWidget() const
       
    97 {
       
    98     TRACE_ENTRY
       
    99     TRACE_EXIT
       
   100     return mNotificationDialog;
       
   101 }
       
   102 
       
   103 QObject* BtDeviceDialogNotifWidget::signalSender() const
       
   104     {
       
   105     return const_cast<BtDeviceDialogNotifWidget*>(this);
       
   106     }
       
   107 
       
   108 /*!
       
   109     Construct display widget
       
   110  */
       
   111 bool BtDeviceDialogNotifWidget::constructNotifDialog(const QVariantMap &parameters)
       
   112 {
       
   113     TRACE_ENTRY
       
   114     // analyze the parameters to compose the properties of the message box widget 
       
   115     processParam(parameters);
       
   116     connect(mNotificationDialog, SIGNAL(finished(HbAction*)), this, SLOT(NotifClosed(HbAction*)));
       
   117     TRACE_EXIT
       
   118     return true;
       
   119 }
       
   120 
       
   121 /*!
       
   122     Take parameter values and generate relevant property of this widget
       
   123  */
       
   124 void BtDeviceDialogNotifWidget::processParam(const QVariantMap &parameters)
       
   125 {
       
   126     TRACE_ENTRY
       
   127     QString keyStr, prompt,title;
       
   128     QVariant classOfDevice;
       
   129     keyStr.setNum( TBluetoothDialogParams::EResource );
       
   130     // Validate if the resource item exists.
       
   131     QVariantMap::const_iterator i = parameters.constFind( keyStr );
       
   132     // item of ResourceId is not found, can't continue.
       
   133     if ( i == parameters.constEnd() ) {
       
   134         mLastError = UnknownDeviceDialogError;
       
   135         return;
       
   136     }
       
   137     HbIcon icon;
       
   138     QVariant param = parameters.value( keyStr );
       
   139     int key = param.toInt();
       
   140     switch ( key ) {
       
   141         case EPairingSuccess:
       
   142             title = QString(hbTrId( "txt_bt_dpophead_paired" ));
       
   143             prompt = QString( hbTrId( "txt_bt_dpopinfo_paired_to_1" ) );
       
   144             classOfDevice = parameters.value(QString::number( TBluetoothDeviceDialog::EDeviceClass ));
       
   145             icon = getBadgedDeviceTypeIcon(classOfDevice.toInt());
       
   146             mNotificationDialog->setIcon(icon);
       
   147             break;
       
   148         // todo: remove this Unpaired notification if not used
       
   149         case EUnpairedDevice:
       
   150             title = QString(hbTrId( "txt_bt_dpophead_unpaired" ));
       
   151             prompt = QString( hbTrId( "txt_bt_dpopinfo_with_1" ) );
       
   152             classOfDevice = parameters.value(QString::number( TBluetoothDeviceDialog::EDeviceClass ));
       
   153             icon = getBadgedDeviceTypeIcon(classOfDevice.toInt());
       
   154             mNotificationDialog->setIcon(icon);
       
   155             break;
       
   156         case EVisibilityTimeout:
       
   157             title = QString(hbTrId( "txt_bt_dpophead_bluetooth" ));
       
   158             prompt = QString( hbTrId( "txt_bt_dpopinfo_is_now_hidden" ) );
       
   159             mNotificationDialog->setIcon(HbIcon("qtg_large_bluetooth"));
       
   160             break;
       
   161         default:
       
   162             mLastError = ParameterError;
       
   163             break;
       
   164     }
       
   165     int repls = prompt.count( QString( "%" ) );
       
   166     if ( repls > 0 ) {
       
   167         QVariant name = parameters.value( QString::number( TBluetoothDeviceDialog::EDeviceName ) );
       
   168         prompt = prompt.arg( name.toString() );
       
   169     }
       
   170     mNotificationDialog->setTitle( title );
       
   171     mNotificationDialog->setText( prompt );
       
   172     TRACE_EXIT
       
   173 }
       
   174 
       
   175 /*!
       
   176     Reset properties to default values
       
   177  */
       
   178 void BtDeviceDialogNotifWidget::resetProperties()
       
   179 {
       
   180     TRACE_ENTRY
       
   181     mSendAction = true;
       
   182     TRACE_EXIT
       
   183     return;
       
   184 }
       
   185 
       
   186 void BtDeviceDialogNotifWidget::NotifClosed(HbAction *action)
       
   187 {
       
   188     Q_UNUSED(action);
       
   189     emit deviceDialogClosed();
       
   190     mSendAction = false;
       
   191 }
       
   192