diff -r f05641c183ff -r 43824b19ee35 bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialoginputwidget.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothengine/btnotif/btdevicedialogplugin/src/btdevicedialoginputwidget.cpp Fri May 14 16:01:46 2010 +0300 @@ -0,0 +1,201 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: BtDeviceDialogWidget class implementation. +* +*/ + + +#include "btdevicedialoginputwidget.h" +#include "btdevicedialogplugintrace.h" +#include +#include +#include +#include "btdevicedialogpluginerrors.h" + +/*! + class Constructor + */ +BtDeviceDialogInputWidget::BtDeviceDialogInputWidget( + const QVariantMap ¶meters) +{ + TRACE_ENTRY + // set properties + mLastError = NoError; + mShowEventReceived = false; + mInputDialog = new HbInputDialog(); + + resetProperties(); + constructInputDialog(parameters); + TRACE_EXIT +} + +/*! + Set parameters, implementation of interface + Invoked when HbDeviceDialog::update calls. + */ +bool BtDeviceDialogInputWidget::setDeviceDialogParameters( + const QVariantMap ¶meters) +{ + TRACE_ENTRY + mLastError = NoError; + processParam(parameters); + TRACE_EXIT + return true; +} + +/*! + Get error, implementation of interface + */ +int BtDeviceDialogInputWidget::deviceDialogError() const +{ + TRACE_ENTRY + TRACE_EXIT + return mLastError; +} + +/*! + Close notification, implementation of interface + */ +void BtDeviceDialogInputWidget::closeDeviceDialog(bool byClient) +{ + TRACE_ENTRY + Q_UNUSED(byClient); + // Closed by client or internally by server -> no action to be transmitted. + mSendAction = false; + mInputDialog->close(); + // If show event has been received, close is signalled from hide event. If not, + // hide event does not come and close is signalled from here. + if (!mShowEventReceived) { + emit deviceDialogClosed(); + } + TRACE_EXIT +} + +/*! + Return display widget, implementation of interface + */ +HbDialog *BtDeviceDialogInputWidget::deviceDialogWidget() const +{ + TRACE_ENTRY + TRACE_EXIT + return mInputDialog; +} + +QObject *BtDeviceDialogInputWidget::signalSender() const +{ + return const_cast(this); +} + +/*! + Construct display widget + */ +bool BtDeviceDialogInputWidget::constructInputDialog(const QVariantMap ¶meters) +{ + TRACE_ENTRY + // analyze the parameters to compose the properties of the widget + processParam(parameters); + connect(mInputDialog, SIGNAL(finished(HbAction*)), this, SLOT(inputClosed(HbAction*))); + + TRACE_EXIT + return true; +} + +/*! + Take parameter values and generate relevant property of this widget + */ +void BtDeviceDialogInputWidget::processParam(const QVariantMap ¶meters) +{ + TRACE_ENTRY + + QString keyStr, prompt; + keyStr.setNum( TBluetoothDialogParams::EResource ); + // Validate if the resource item exists. + QVariantMap::const_iterator i = parameters.constFind( keyStr ); + // item of ResourceId is not found, can't continue. + if ( i == parameters.constEnd() ) { + mLastError = UnknownDeviceDialogError; + return; + } + + QVariant param = parameters.value( keyStr ); + if ( param.toInt() == EPinInput ) { + prompt = QString( tr( "Passcode for device %1:" ) ); + } + else { + mLastError = ParameterError; + return; + } + + // check if minLength of passcode required + keyStr.setNum( TBluetoothDeviceDialog::EAdditionalDesc ); + i = parameters.constFind( keyStr ); + // Mini Length required, update prompt + // ToDo: use Validator to check input length. + if ( i != parameters.constEnd() ) { + prompt = QString( tr( "Enter %1 digit passcode for device %2:" ) ); + param = parameters.value( keyStr ); + } + + // replace % with the miniLength and device name + int repls = prompt.count( QString( "%" ) ); + if ( repls > 1 ) { + prompt = prompt.arg( param.toString() ); + } + if ( repls > 0 ) { + QVariant name = parameters.value( QString::number( TBluetoothDeviceDialog::EDeviceName ) ); + prompt = prompt.arg( name.toString() ); + } + // set property value to this dialog widget + mInputDialog->setPromptText( prompt ); + TRACE_EXIT +} + +/*! + Reset properties to default values + */ +void BtDeviceDialogInputWidget::resetProperties() +{ + TRACE_ENTRY + // set to default values + mInputDialog->setModal(true); + mInputDialog->setTimeout(HbDialog::NoTimeout); + mInputDialog->setDismissPolicy(HbDialog::NoDismiss); + mSendAction = true; + // Todo: clean the Validator + TRACE_EXIT + return; +} + +void BtDeviceDialogInputWidget::inputClosed(HbAction *action) +{ + QVariantMap data; + + HbInputDialog *dlg=static_cast(sender()); + if(dlg->actions().first() == action) { + //Ok + QVariant result( dlg->value().toString().toUtf8() ); + data.insert( QString( "result" ), QVariant(true)); + data.insert( QString( "input" ), result ); + } + else if(dlg->actions().at(1) == action) { + //Cancel + data.insert( QString( "result" ), QVariant(false)); + } + + emit deviceDialogData(data); + emit deviceDialogClosed(); + mSendAction = false; +} + +