bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialognotifwidget.cpp
changeset 42 b72428996822
parent 29 48ae3789ce00
child 57 5ebadcda06cb
equal deleted inserted replaced
32:19bd632b5100 42:b72428996822
    20 #include "btdevicedialogplugintrace.h"
    20 #include "btdevicedialogplugintrace.h"
    21 #include <bluetoothdevicedialogs.h>
    21 #include <bluetoothdevicedialogs.h>
    22 #include <hbaction.h>
    22 #include <hbaction.h>
    23 #include <hbdialog.h>
    23 #include <hbdialog.h>
    24 #include "btdevicedialogpluginerrors.h"
    24 #include "btdevicedialogpluginerrors.h"
    25 
    25 #include <btuiiconutil.h>
    26 /*!
    26 /*!
    27     class Constructor
    27     class Constructor
    28  */
    28  */
    29 BtDeviceDialogNotifWidget::BtDeviceDialogNotifWidget( const QVariantMap &parameters )
    29 BtDeviceDialogNotifWidget::BtDeviceDialogNotifWidget( const QVariantMap &parameters )
    30 {
    30 {
    31     TRACE_ENTRY
    31     TRACE_ENTRY
    32     // set properties
    32     // set properties
    33     mLastError = NoError;
    33     mLastError = NoError;
    34     mShowEventReceived = false;
    34     mShowEventReceived = false;
       
    35     mNotificationDialog = new HbNotificationDialog();
    35     resetProperties();
    36     resetProperties();
    36     constructQueryDialog(parameters);
    37     constructNotifDialog(parameters);
    37     TRACE_EXIT
    38     TRACE_EXIT
       
    39 }
       
    40 
       
    41 /*!
       
    42     class Constructor
       
    43  */
       
    44 BtDeviceDialogNotifWidget::~BtDeviceDialogNotifWidget()
       
    45 {
       
    46     TRACE_ENTRY
       
    47     delete mNotificationDialog;
       
    48     return;
    38 }
    49 }
    39 
    50 
    40 /*!
    51 /*!
    41     Set parameters, implementation of interface
    52     Set parameters, implementation of interface
    42     Invoked when HbDeviceDialog::update calls.
    53     Invoked when HbDeviceDialog::update calls.
    68 {
    79 {
    69     TRACE_ENTRY
    80     TRACE_ENTRY
    70     Q_UNUSED(byClient);
    81     Q_UNUSED(byClient);
    71     // Closed by client or internally by server -> no action to be transmitted.
    82     // Closed by client or internally by server -> no action to be transmitted.
    72     mSendAction = false;
    83     mSendAction = false;
    73     close();
    84     mNotificationDialog->close();
    74     // If show event has been received, close is signalled from hide event. If not,
    85      // If show event has been received, close is signalled from hide event. If not,
    75     // hide event does not come and close is signalled from here.
    86     // hide event does not come and close is signalled from here.
    76     if (!mShowEventReceived) {
    87     if (!mShowEventReceived) {
    77         emit deviceDialogClosed();
    88         emit deviceDialogClosed();
    78     }
    89     }
    79     TRACE_EXIT
    90     TRACE_EXIT
    80 }
    91 }
    81 
    92 
    82 /*!
    93 /*!
    83     Return display widget, implementation of interface
    94     Return display widget, implementation of interface
    84  */
    95  */
    85 HbDialog *BtDeviceDialogNotifWidget::deviceDialogWidget() const
    96 HbPopup *BtDeviceDialogNotifWidget::deviceDialogWidget() const
    86 {
    97 {
    87     TRACE_ENTRY
    98     TRACE_ENTRY
    88     TRACE_EXIT
    99     TRACE_EXIT
       
   100     return mNotificationDialog;
       
   101 }
       
   102 
       
   103 QObject* BtDeviceDialogNotifWidget::signalSender() const
       
   104     {
    89     return const_cast<BtDeviceDialogNotifWidget*>(this);
   105     return const_cast<BtDeviceDialogNotifWidget*>(this);
    90 }
   106     }
    91 
   107 
    92 /*!
   108 /*!
    93     Construct display widget
   109     Construct display widget
    94  */
   110  */
    95 bool BtDeviceDialogNotifWidget::constructQueryDialog(const QVariantMap &parameters)
   111 bool BtDeviceDialogNotifWidget::constructNotifDialog(const QVariantMap &parameters)
    96 {
   112 {
    97     TRACE_ENTRY
   113     TRACE_ENTRY
    98     // analyze the parameters to compose the properties of the message box widget 
   114     // analyze the parameters to compose the properties of the message box widget 
    99     processParam(parameters);
   115     processParam(parameters);
   100  
   116     connect(mNotificationDialog, SIGNAL(finished(HbAction*)), this, SLOT(NotifClosed(HbAction*)));
   101     TRACE_EXIT
   117     TRACE_EXIT
   102     return true;
   118     return true;
   103 }
   119 }
   104 
   120 
   105 /*!
   121 /*!
   106     Take parameter values and generate relevant property of this widget
   122     Take parameter values and generate relevant property of this widget
   107  */
   123  */
   108 void BtDeviceDialogNotifWidget::processParam(const QVariantMap &parameters)
   124 void BtDeviceDialogNotifWidget::processParam(const QVariantMap &parameters)
   109 {
   125 {
   110     TRACE_ENTRY
   126     TRACE_ENTRY
   111     QString keyStr, prompt;
   127     QString keyStr, prompt,title;
       
   128     QVariant classOfDevice;
   112     keyStr.setNum( TBluetoothDialogParams::EResource );
   129     keyStr.setNum( TBluetoothDialogParams::EResource );
   113     // Validate if the resource item exists.
   130     // Validate if the resource item exists.
   114     QVariantMap::const_iterator i = parameters.constFind( keyStr );
   131     QVariantMap::const_iterator i = parameters.constFind( keyStr );
   115     // item of ResourceId is not found, can't continue.
   132     // item of ResourceId is not found, can't continue.
   116     if ( i == parameters.constEnd() ) {
   133     if ( i == parameters.constEnd() ) {
   117         mLastError = UnknownDeviceDialogError;
   134         mLastError = UnknownDeviceDialogError;
   118         return;
   135         return;
   119     }
   136     }
   120 
   137     HbIcon icon;
   121     QVariant param = parameters.value( keyStr );
   138     QVariant param = parameters.value( keyStr );
   122     int key = param.toInt();
   139     int key = param.toInt();
   123     switch ( key ) {
   140     switch ( key ) {
   124         // Note dialogs
       
   125         case EPairingSuccess:
   141         case EPairingSuccess:
   126             prompt = QString( tr( "Pairing with %1 complete" ) );
   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);
   127             break;
   147             break;
   128         case EPairingFailure:
   148         // todo: remove this Unpaired notification if not used
   129             prompt = QString( tr( "Unable to pair with %1" ) );
   149         case EUnpairedDevice:
   130             break;            
   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;
   131         case EVisibilityTimeout:
   156         case EVisibilityTimeout:
   132             prompt = QString( tr( "Phone is not detectable in searches made by other devices" ) );
   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"));
   133             break;
   160             break;
   134         default:
   161         default:
   135             mLastError = ParameterError;
   162             mLastError = ParameterError;
   136             break;
   163             break;
   137     }
   164     }
   138     // Could use QChar with ReplacementCharacter?
       
   139     int repls = prompt.count( QString( "%" ) );
   165     int repls = prompt.count( QString( "%" ) );
   140     if ( repls > 0 ) {
   166     if ( repls > 0 ) {
   141         QVariant name = parameters.value( QString::number( TBluetoothDeviceDialog::EDeviceName ) );
   167         QVariant name = parameters.value( QString::number( TBluetoothDeviceDialog::EDeviceName ) );
   142         prompt = prompt.arg( name.toString() );
   168         prompt = prompt.arg( name.toString() );
   143     }
   169     }
   144     // set property value to this dialog widget
   170     mNotificationDialog->setTitle( title );
   145     HbNotificationDialog::setTitle( prompt );
   171     mNotificationDialog->setText( prompt );
   146     TRACE_EXIT
   172     TRACE_EXIT
   147 }
   173 }
   148 
   174 
   149 /*!
   175 /*!
   150     Reset properties to default values
   176     Reset properties to default values
   155     mSendAction = true;
   181     mSendAction = true;
   156     TRACE_EXIT
   182     TRACE_EXIT
   157     return;
   183     return;
   158 }
   184 }
   159 
   185 
   160 /*!
   186 void BtDeviceDialogNotifWidget::NotifClosed(HbAction *action)
   161     Widget is about to hide. Closing effect has ended.
       
   162  */
       
   163 void BtDeviceDialogNotifWidget::hideEvent(QHideEvent *event)
       
   164 {
   187 {
   165     HbNotificationDialog::hideEvent(event);
   188     Q_UNUSED(action);
   166     emit deviceDialogClosed();
   189     emit deviceDialogClosed();
       
   190     mSendAction = false;
   167 }
   191 }
   168 
   192 
   169 /*!
       
   170     Widget is about to show
       
   171  */
       
   172 void BtDeviceDialogNotifWidget::showEvent(QShowEvent *event)
       
   173 {
       
   174     HbNotificationDialog::showEvent(event);
       
   175     mShowEventReceived = true;
       
   176 }