bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialoginputwidget.cpp
changeset 70 f5508c13dfe0
parent 57 5ebadcda06cb
equal deleted inserted replaced
67:16e4b9007960 70:f5508c13dfe0
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    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 <hbvalidator.h>
    25 #include <hbvalidator.h>
       
    26 #include <hbparameterlengthlimiter.h>
    26 #include "btdevicedialogpluginerrors.h"
    27 #include "btdevicedialogpluginerrors.h"
    27 
    28 
    28 const int PASSCODE_MAX_LEN = 16; // from BT specs
    29 const int PASSCODE_MAX_LEN = 16; // from BT specs
    29 
    30 
    30 /*!
    31 /*!
   122 {
   123 {
   123     TRACE_ENTRY
   124     TRACE_ENTRY
   124 
   125 
   125     QString keyStr, prompt,title,regExp;
   126     QString keyStr, prompt,title,regExp;
   126     QVariant name;
   127     QVariant name;
       
   128     bool minLenRequired = false;
       
   129     
   127     keyStr.setNum( TBluetoothDialogParams::EResource );
   130     keyStr.setNum( TBluetoothDialogParams::EResource );
   128     // Validate if the resource item exists.
   131     // Validate if the resource item exists.
   129     QVariantMap::const_iterator i = parameters.constFind( keyStr );
   132     QVariantMap::const_iterator i = parameters.constFind( keyStr );
   130     // item of ResourceId is not found, can't continue.
   133     // item of ResourceId is not found, can't continue.
   131     if ( i == parameters.constEnd() ) {
   134     if ( i == parameters.constEnd() ) {
   132         mLastError = UnknownDeviceDialogError;
   135         mLastError = UnknownDeviceDialogError;
   133         return;
   136         return;
   134     }
   137     }
   135 
   138 
   136     QVariant param = parameters.value( keyStr );
   139     QVariant param = parameters.value( keyStr );
   137     if ( param.toInt() == EPinInput ) {
   140   
   138         // Numeric value only
   141     if(param.toInt() != EPinInput)
   139         mInputDialog->setInputMode(HbInputDialog::RealInput);
   142         {
   140         title = QString(hbTrId("txt_bt_title_pairing_with_1"));
       
   141         // todo: Fix the multiline problem
       
   142         prompt = QString( hbTrId( "txt_bt_dialog_please_enter_the_passcode_for_1" ) );
       
   143     }
       
   144     else {
       
   145         mLastError = ParameterError;
   143         mLastError = ParameterError;
   146         return;
   144         return;
   147     }
   145         }
   148     
   146     mInputDialog->setInputMode(HbInputDialog::RealInput);
   149     // check if minLength of passcode required
   147     name = parameters.value( QString::number( TBluetoothDeviceDialog::EDeviceName ) );
       
   148     title = HbParameterLengthLimiter(hbTrId("txt_bt_title_pairing_with_1")).arg(name.toString());
       
   149     
       
   150     // Set minimum input length requirements
   150     keyStr.setNum( TBluetoothDeviceDialog::EAdditionalDesc );
   151     keyStr.setNum( TBluetoothDeviceDialog::EAdditionalDesc );
   151     i = parameters.constFind( keyStr );
   152     i = parameters.constFind( keyStr );
   152     // Mini Length required, update prompt
   153     // Min Length required
   153     // ToDo: The validator doesn't seem to work properly 
       
   154     if ( i != parameters.constEnd() ) {
   154     if ( i != parameters.constEnd() ) {
   155         // Todo : The string ID for the localization is not available yet
   155         minLenRequired = true;
   156         // for string : "Enter %1 digit passcode for device %2:"
       
   157         // I'm using the "Enter the passcode for device %1" instead
       
   158         prompt = QString( hbTrId( "txt_bt_dialog_please_enter_the_passcode_for_1" ) );
       
   159         param = parameters.value( keyStr );
   156         param = parameters.value( keyStr );
   160         regExp = tr("^\\d{%1,}$");
   157         regExp = "^\\d{%1,}$";
   161         regExp.arg(param.toString());
   158         regExp.arg(param.toString());
   162         HbValidator* validator = new HbValidator(mInputDialog->lineEdit());
   159         HbValidator* validator = new HbValidator(mInputDialog->lineEdit());
   163         validator->addField(
   160         validator->addField(
   164                 new QRegExpValidator(
   161                 new QRegExpValidator(
   165                         QRegExp(regExp, Qt::CaseInsensitive), validator ),"");
   162                         QRegExp(regExp, Qt::CaseInsensitive), validator ),"");
   166         mInputDialog->setValidator(validator);
   163         mInputDialog->setValidator(validator);
   167     }else{
   164     }else{
   168         // Minimum requirement is to have at least 1 digit
   165         // Minimum requirement is to have at least 1 digit
   169         regExp = tr("^\\d{1,}$");
   166         regExp = "^\\d{1,}$";
   170         HbValidator* validator = new HbValidator(mInputDialog->lineEdit());
   167         HbValidator* validator = new HbValidator(mInputDialog->lineEdit());
   171         validator->addField(
   168         validator->addField(
   172                 new QRegExpValidator(
   169                 new QRegExpValidator(
   173                         QRegExp(regExp, Qt::CaseInsensitive), validator ),"");
   170                         QRegExp(regExp, Qt::CaseInsensitive), validator ),"");
   174         mInputDialog->setValidator(validator);    
   171         mInputDialog->setValidator(validator);    
   175     }
   172     }
   176     // replace % with the minimum length and device name
   173     if(minLenRequired)
   177     int repls = prompt.count( QString( "%" ) );
   174         {
   178     if ( repls > 1 ) {
   175         // Todo : The string ID for the localization is not available yet
   179         prompt = prompt.arg( param.toString() );
   176         // for string : "Enter %1 digit passcode for device %2:"
   180     }
   177         // I'm using the "Enter the passcode for device %1" instead
   181     if ( repls > 0 ) {
   178         prompt = HbParameterLengthLimiter(hbTrId("txt_bt_dialog_please_enter_the_passcode_for_1" )).arg(name.toString());
   182         name = parameters.value( QString::number( TBluetoothDeviceDialog::EDeviceName ) );
   179         }
   183         prompt = prompt.arg( name.toString() );
   180     else
   184     }
   181         {
   185     repls = title.count(QString("%"));
   182         prompt = HbParameterLengthLimiter(hbTrId("txt_bt_dialog_please_enter_the_passcode_for_1" )).arg(name.toString());
   186     if(repls > 0){
   183         }
   187         title = title.arg( name.toString() );
       
   188     }
       
   189     mInputDialog->setHeadingWidget(new HbLabel(title));
   184     mInputDialog->setHeadingWidget(new HbLabel(title));
   190     mInputDialog->lineEdit(0)->setMaxLength(PASSCODE_MAX_LEN);
   185     mInputDialog->lineEdit(0)->setMaxLength(PASSCODE_MAX_LEN);
   191     mInputDialog->lineEdit(0)->setText(tr("")); // clear the input field
   186     mInputDialog->lineEdit(0)->setText(tr("")); // clear the input field
   192     mInputDialog->setPromptText(prompt);
   187     mInputDialog->setPromptText(prompt);
   193     TRACE_EXIT
   188     TRACE_EXIT