bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialogquerywidget.cpp
changeset 19 43824b19ee35
child 40 997690c3397a
equal deleted inserted replaced
17:f05641c183ff 19:43824b19ee35
       
     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 "btdevicedialogquerywidget.h"
       
    20 #include "btdevicedialogplugintrace.h"
       
    21 #include <bluetoothdevicedialogs.h>
       
    22 #include <hbaction.h>
       
    23 #include <hbdialog.h>
       
    24 #include "btdevicedialogpluginerrors.h"
       
    25 
       
    26 /*!
       
    27     class Constructor
       
    28  */
       
    29 BtDeviceDialogQueryWidget::BtDeviceDialogQueryWidget(
       
    30         HbMessageBox::MessageBoxType type, const QVariantMap &parameters)
       
    31 {
       
    32     TRACE_ENTRY
       
    33     // set properties
       
    34     mLastError = NoError;
       
    35     mShowEventReceived = false;
       
    36     mMessageBox = new HbMessageBox(type);
       
    37     
       
    38     resetProperties();
       
    39     constructQueryDialog(parameters);
       
    40     TRACE_EXIT
       
    41 }
       
    42 
       
    43 /*!
       
    44     Set parameters, implementation of interface
       
    45     Invoked when HbDeviceDialog::update calls.
       
    46  */
       
    47 bool BtDeviceDialogQueryWidget::setDeviceDialogParameters(
       
    48     const QVariantMap &parameters)
       
    49 {
       
    50     TRACE_ENTRY
       
    51     mLastError = NoError;
       
    52     processParam(parameters);
       
    53     TRACE_EXIT
       
    54     return true;
       
    55 }
       
    56 
       
    57 /*!
       
    58     Get error, implementation of interface
       
    59  */
       
    60 int BtDeviceDialogQueryWidget::deviceDialogError() const
       
    61 {
       
    62     TRACE_ENTRY
       
    63     TRACE_EXIT
       
    64     return mLastError;
       
    65 }
       
    66 
       
    67 /*!
       
    68     Close notification, implementation of interface
       
    69  */ 
       
    70 void BtDeviceDialogQueryWidget::closeDeviceDialog(bool byClient)
       
    71 {
       
    72     TRACE_ENTRY
       
    73     Q_UNUSED(byClient);
       
    74     // Closed by client or internally by server -> no action to be transmitted.
       
    75     mSendAction = false;
       
    76     mMessageBox->close();
       
    77     // If show event has been received, close is signalled from hide event. If not,
       
    78     // hide event does not come and close is signalled from here.
       
    79     if (!mShowEventReceived) {
       
    80         emit deviceDialogClosed();
       
    81     }
       
    82     TRACE_EXIT
       
    83 }
       
    84 
       
    85 /*!
       
    86     Return display widget, implementation of interface
       
    87  */
       
    88 HbDialog *BtDeviceDialogQueryWidget::deviceDialogWidget() const
       
    89 {
       
    90     TRACE_ENTRY
       
    91     TRACE_EXIT
       
    92     return mMessageBox;
       
    93 }
       
    94 
       
    95 QObject *BtDeviceDialogQueryWidget::signalSender() const
       
    96 {
       
    97     return const_cast<BtDeviceDialogQueryWidget*>(this);
       
    98 }        
       
    99 
       
   100 /*!
       
   101     Construct display widget
       
   102  */
       
   103 bool BtDeviceDialogQueryWidget::constructQueryDialog(const QVariantMap &parameters)
       
   104 {
       
   105     TRACE_ENTRY
       
   106     // analyze the parameters to compose the properties of the message box widget 
       
   107     processParam(parameters);
       
   108  
       
   109     connect(mMessageBox, SIGNAL(finished(HbAction*)), this, SLOT(messageBoxClosed(HbAction*)));
       
   110     
       
   111     TRACE_EXIT
       
   112     return true;
       
   113 }
       
   114 
       
   115 /*!
       
   116     Take parameter values and generate relevant property of this widget
       
   117  */
       
   118 void BtDeviceDialogQueryWidget::processParam(const QVariantMap &parameters)
       
   119 {
       
   120     TRACE_ENTRY
       
   121     QString keyStr, prompt;
       
   122     keyStr.setNum( TBluetoothDialogParams::EResource );
       
   123     // Validate if the resource item exists.
       
   124     QVariantMap::const_iterator i = parameters.constFind( keyStr );
       
   125     // item of ResourceId is not found, can't continue.
       
   126     if ( i == parameters.constEnd() ) {
       
   127         mLastError = UnknownDeviceDialogError;
       
   128         return;
       
   129     }
       
   130 
       
   131     QVariant param = parameters.value( keyStr );
       
   132     int key = param.toInt();
       
   133     switch ( key ) {
       
   134         // Query dialogs:
       
   135         case EAuthorization:
       
   136             prompt = QString( tr( "Accept connection request from:\n%1" ) );
       
   137             break;
       
   138         case EIncomingPairing:
       
   139             prompt = QString( tr( "Device '%1' is trying to pair with you. Allow pairing?" ) );
       
   140             break;
       
   141         case ENumericComparison:
       
   142             prompt = QString( tr( "Does this code match the one on %1?\n\n%2" ) );
       
   143             break;
       
   144         case EPasskeyDisplay:
       
   145             prompt = QString( tr( "Enter on %1:\n\n%2" ) );
       
   146             break;
       
   147         case ESetTrusted:
       
   148             prompt = QString( tr( "Authorise this device to make connections automatically?" ) );
       
   149             break;
       
   150         case EBlockUnpairedDevice:
       
   151             prompt = QString( tr( "Do you want to block all future connection attempts from device %1?" ) );
       
   152             break;
       
   153         case EBlockPairedDevice:
       
   154             prompt = QString( tr( "Do you want to block all future connection attempts from paired device %1? \nThis will delete your pairing with the device." ) );
       
   155             break;
       
   156         // Note dialogs, but not Notification dialogs
       
   157         // Input dialogs
       
   158         case EPinInput:
       
   159         case EObexPasskeyInput:
       
   160         // NULL parameters
       
   161         case ENoResource:
       
   162         case EUnusedResource:
       
   163         default:
       
   164             mLastError = ParameterError;
       
   165             break;
       
   166     }
       
   167     // Could use QChar with ReplacementCharacter?
       
   168     int repls = prompt.count( QString( "%" ) );
       
   169     if ( repls > 0 ) {
       
   170         QVariant name = parameters.value( QString::number( TBluetoothDeviceDialog::EDeviceName ) );
       
   171         prompt = prompt.arg( name.toString() );
       
   172         if ( repls > 1 ) {
       
   173             QVariant addval = parameters.value( QString::number( TBluetoothDeviceDialog::EAdditionalDesc ) );
       
   174             prompt = prompt.arg( addval.toString() );
       
   175         }
       
   176     }
       
   177     // set property value to this dialog widget
       
   178     mMessageBox->setText( prompt );
       
   179     TRACE_EXIT
       
   180 }
       
   181 
       
   182 /*!
       
   183     Reset properties to default values
       
   184  */
       
   185 void BtDeviceDialogQueryWidget::resetProperties()
       
   186 {
       
   187     TRACE_ENTRY
       
   188     // set to default values
       
   189     mMessageBox->setModal(true);
       
   190     mMessageBox->setTimeout(HbDialog::NoTimeout);
       
   191     mMessageBox->setDismissPolicy(HbDialog::NoDismiss);
       
   192     mSendAction = true;
       
   193     TRACE_EXIT
       
   194     return;
       
   195 }
       
   196 
       
   197 
       
   198 void BtDeviceDialogQueryWidget::messageBoxClosed(HbAction* action)
       
   199 {
       
   200     QVariantMap data;
       
   201     
       
   202     HbMessageBox *dlg=static_cast<HbMessageBox*>(sender());
       
   203     if(dlg->actions().first() == action) {
       
   204         //Yes
       
   205         data.insert( QString( "result" ), QVariant(true));
       
   206     } 
       
   207     else if(dlg->actions().at(1) == action) {
       
   208         //No
       
   209         data.insert( QString( "result" ), QVariant(false));
       
   210     }
       
   211     
       
   212     emit deviceDialogData(data);
       
   213     emit deviceDialogClosed();
       
   214     mSendAction = false;
       
   215 }