bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialogquerywidget.cpp
changeset 63 bcf742120177
parent 52 4545c04e61e1
child 70 f5508c13dfe0
equal deleted inserted replaced
52:4545c04e61e1 63:bcf742120177
    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 <hblabel.h>
    24 #include <hblabel.h>
    25 #include "btdevicedialogpluginerrors.h"
    25 #include "btdevicedialogpluginerrors.h"
       
    26 #include <Bluetooth\hci\hcitypes.h>
       
    27 
       
    28 const int MaxPasskeyLength = 6;
    26 
    29 
    27 /*!
    30 /*!
    28     class Constructor
    31     class Constructor
    29  */
    32  */
    30 BtDeviceDialogQueryWidget::BtDeviceDialogQueryWidget(
    33 BtDeviceDialogQueryWidget::BtDeviceDialogQueryWidget(
   109     connect(mMessageBox, SIGNAL(finished(HbAction*)), this, SLOT(messageBoxClosed(HbAction*)));
   112     connect(mMessageBox, SIGNAL(finished(HbAction*)), this, SLOT(messageBoxClosed(HbAction*)));
   110     
   113     
   111     TRACE_EXIT
   114     TRACE_EXIT
   112     return true;
   115     return true;
   113 }
   116 }
       
   117 /*!
       
   118     Take parameter values and generate the input status string
       
   119  */
       
   120 QString& BtDeviceDialogQueryWidget::GetPasskeyEntryStatusString(int aStatus)
       
   121     {
       
   122         switch(aStatus)
       
   123             {
       
   124             case EPasskeyDigitEntered :
       
   125                 mDispPassKeyNumDigit ++; // keep count of remote entry
       
   126                 if(mDisplayPasskeyStatus.length()< MaxPasskeyLength + 1) // + 1 space
       
   127                     {
       
   128                     if(mDisplayPasskeyStatus.length()== 3)
       
   129                         {
       
   130                         mDisplayPasskeyStatus.append(tr(" ")); // cosmetic
       
   131                         }
       
   132                     mDisplayPasskeyStatus.append(tr("*"));
       
   133                     }
       
   134                 break;
       
   135             case EPasskeyDigitDeleted :
       
   136                 // passkey entry is limited to 6 digits
       
   137                 if((mDisplayPasskeyStatus.length()> 0 )&& (mDispPassKeyNumDigit < MaxPasskeyLength + 1))
       
   138                     {
       
   139                     if(mDisplayPasskeyStatus.length() == 5) // cosmetic
       
   140                         {
       
   141                         mDisplayPasskeyStatus = mDisplayPasskeyStatus.left(mDisplayPasskeyStatus.length()-1);
       
   142                         }
       
   143                     mDisplayPasskeyStatus = mDisplayPasskeyStatus.left(mDisplayPasskeyStatus.length()-1);
       
   144                     // we only decrement if the string is not zero
       
   145                     mDispPassKeyNumDigit --;
       
   146                     }
       
   147                 break;
       
   148             case EPasskeyCleared :
       
   149             case EPasskeyEntryStarted :
       
   150             case EPasskeyEntryCompleted :
       
   151             default:
       
   152                 mDispPassKeyNumDigit = 0;
       
   153                 mDisplayPasskeyStatus.clear();
       
   154                 mDisplayPasskeyStatus.append(tr(""));
       
   155                 break;
       
   156             }
       
   157         return mDisplayPasskeyStatus;
       
   158     }
   114 
   159 
   115 /*!
   160 /*!
   116     Take parameter values and generate relevant property of this widget
   161     Take parameter values and generate relevant property of this widget
   117  */
   162  */
   118 void BtDeviceDialogQueryWidget::processParam(const QVariantMap &parameters)
   163 void BtDeviceDialogQueryWidget::processParam(const QVariantMap &parameters)
   119 {
   164 {
   120     TRACE_ENTRY
   165     TRACE_ENTRY
   121     QString keyStr, prompt,title;
   166     QString keyStr, prompt,title;
   122     QVariant name,param,addval;
   167     int status = -1;
       
   168     QVariant name,param,addval,passkeyinputstatus;
   123     keyStr.setNum( TBluetoothDialogParams::EResource );
   169     keyStr.setNum( TBluetoothDialogParams::EResource );
   124     // Validate if the resource item exists.
   170     // Validate if the resource item exists.
   125     QVariantMap::const_iterator i = parameters.constFind( keyStr );
   171     QVariantMap::const_iterator i = parameters.constFind( keyStr );
   126     // item of ResourceId is not found, can't continue.
   172     // item of ResourceId is not found, can't continue.
   127     if ( i == parameters.constEnd() ) {
   173     if ( i == parameters.constEnd() ) {
   128         mLastError = UnknownDeviceDialogError;
   174         mLastError = UnknownDeviceDialogError;
   129         return;
   175         return;
   130     }
   176     }
   131 
   177     // For passkey display the dialog may be terminated by
       
   178     // a passkey entry completed event from the remote side
       
   179     mSendPasskeyEntryCompletedAction = false;
       
   180     
   132     param = parameters.value( keyStr );
   181     param = parameters.value( keyStr );
   133     int key = param.toInt();
   182     int key = param.toInt();
   134     switch ( key ) {
   183     switch ( key ) {
   135         case ENumericComparison:
   184         case ENumericComparison:
   136             prompt = QString( hbTrId( "txt_bt_info_does_this_code_match_the_code_on_1" ) );
   185             prompt = QString( hbTrId( "txt_bt_info_does_this_code_match_the_code_on_1" ) );
   162             {
   211             {
   163             addval = parameters.value( QString::number( TBluetoothDeviceDialog::EAdditionalDesc ) );
   212             addval = parameters.value( QString::number( TBluetoothDeviceDialog::EAdditionalDesc ) );
   164             // todo: Formating the prompt need to be discussed with UI designer
   213             // todo: Formating the prompt need to be discussed with UI designer
   165             // The passcode could be displayed on a separate row if it the label did support
   214             // The passcode could be displayed on a separate row if it the label did support
   166             // the use of newline escape character.
   215             // the use of newline escape character.
   167             prompt.append(tr("\n\n")); // insert 2 newlines for clarity
   216             prompt.append(tr("\n")); // insert 1 newlines for clarity
   168             prompt.append(addval.toString());
   217             prompt.append(addval.toString());
   169             if(key == EPasskeyDisplay)
   218             if(key == EPasskeyDisplay)
   170                 {
   219                 {
   171                 prompt.append("\n");   
   220                 prompt.append("\n");
       
   221                 bool ret = false;
       
   222                 passkeyinputstatus = parameters.value( QString::number( TBluetoothDeviceDialog::EAdditionalInt ));
       
   223                 status = passkeyinputstatus.toInt(&ret);
       
   224                 if(ret)
       
   225                     {
       
   226                         prompt.append(GetPasskeyEntryStatusString(status));
       
   227                     }
   172                 }
   228                 }
   173             }
   229             }
   174     }
   230     }
   175     // set property value to this dialog widget
   231     // set property value to this dialog widget
   176     if(key != EPairingFailureRetry && key != EPairingFailureOk)
   232     if(key != EPairingFailureRetry && key != EPairingFailureOk)
   177         {
   233         {
   178         title = QString(hbTrId("txt_bt_title_pairing_with_1"));
   234         title = QString(hbTrId("txt_bt_title_pairing_with_1"));
   179         title = title.arg(name.toString());
   235         title = title.arg(name.toString());
   180         mMessageBox->setHeadingWidget(new HbLabel(title));
   236         mMessageBox->setHeadingWidget(new HbLabel(title));
   181         mMessageBox->setIconVisible(false);
   237         mMessageBox->setIconVisible(false);
   182         mMessageBox->setStandardButtons( HbMessageBox::Yes | HbMessageBox::No);
   238         if(key == EPasskeyDisplay)
       
   239             {
       
   240             mMessageBox->setStandardButtons(HbMessageBox::Cancel);
       
   241             }
       
   242         else
       
   243             {
       
   244             mMessageBox->setStandardButtons( HbMessageBox::Yes | HbMessageBox::No);
       
   245             }
   183         }
   246         }
   184     else
   247     else
   185         {
   248         {
   186         if(key == EPairingFailureRetry)
   249         if(key == EPairingFailureRetry)
   187             {
   250             {
   191             {
   254             {
   192             mMessageBox->setStandardButtons( HbMessageBox::Ok);
   255             mMessageBox->setStandardButtons( HbMessageBox::Ok);
   193             }
   256             }
   194         }
   257         }
   195     mMessageBox->setText( prompt );
   258     mMessageBox->setText( prompt );
       
   259     if(status == EPasskeyEntryCompleted && key == EPasskeyDisplay)
       
   260         {
       
   261         mSendPasskeyEntryCompletedAction = true;
       
   262         mMessageBox->close();
       
   263         }
   196     TRACE_EXIT
   264     TRACE_EXIT
   197 }
   265 }
   198 
   266 
   199 /*!
   267 /*!
   200     Reset properties to default values
   268     Reset properties to default values
   205     // set to default values
   273     // set to default values
   206     mMessageBox->setModal(true);
   274     mMessageBox->setModal(true);
   207     mMessageBox->setTimeout(HbDialog::NoTimeout);
   275     mMessageBox->setTimeout(HbDialog::NoTimeout);
   208     mMessageBox->setDismissPolicy(HbDialog::NoDismiss);
   276     mMessageBox->setDismissPolicy(HbDialog::NoDismiss);
   209     mSendAction = true;
   277     mSendAction = true;
       
   278     mDispPassKeyNumDigit = 0;
   210     TRACE_EXIT
   279     TRACE_EXIT
   211     return;
   280     return;
   212 }
   281 }
   213 
   282 
   214 
   283 
   215 void BtDeviceDialogQueryWidget::messageBoxClosed(HbAction* action)
   284 void BtDeviceDialogQueryWidget::messageBoxClosed(HbAction* action)
   216 {
   285 {
       
   286     TRACE_ENTRY
   217     QVariantMap data;
   287     QVariantMap data;
   218     
   288     
   219     HbMessageBox *dlg=static_cast<HbMessageBox*>(sender());
   289     HbMessageBox *dlg=static_cast<HbMessageBox*>(sender());
   220     if(dlg->actions().first() == action) {
   290     if(dlg->actions().first() == action) 
   221         //Yes
   291         {
   222         data.insert( QString( "result" ), QVariant(true));
   292         if(dlg->actions().count() > 1)
   223     } 
   293             {
   224     else if(dlg->actions().at(1) == action) {
   294             data.insert( QString( "result" ), QVariant(true));
       
   295             }
       
   296         else
       
   297             {
       
   298             // this is a passkey display dialog with a cancel button
       
   299             data.insert( QString( "result" ), QVariant(false));
       
   300             }
       
   301         } 
       
   302     else if(dlg->actions().count() > 1)
       
   303         {
       
   304         if(dlg->actions().at(1) == action) {
   225         //No
   305         //No
   226         data.insert( QString( "result" ), QVariant(false));
   306         data.insert( QString( "result" ), QVariant(false));
   227     }
   307         }
   228     
   308     }
       
   309     if(mSendPasskeyEntryCompletedAction)
       
   310         {
       
   311         // complete successfully the dialog
       
   312         // The BT stack will determine if pairing was ok 
       
   313         data.insert( QString( "result" ), QVariant(true));
       
   314         mSendPasskeyEntryCompletedAction = false;
       
   315         }
   229     emit deviceDialogData(data);
   316     emit deviceDialogData(data);
   230     emit deviceDialogClosed();
   317     emit deviceDialogClosed();
   231     mSendAction = false;
   318     mSendAction = false;
   232 }
   319     TRACE_EXIT
       
   320 }