bluetoothengine/btui/btuidelegate/btdelegateinquiry.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 31 Aug 2010 15:25:10 +0300
branchRCL_3
changeset 55 613943a21004
child 57 5ebadcda06cb
permissions -rw-r--r--
Revision: 201033 Kit: 201035

/*
* Copyright (c) 2010 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: 
*
*/


#include "btdelegateinquiry.h"
#include "btdelegatefactory.h"
#include "btqtconstants.h"

#include <btsettingmodel.h>
#include <btdevicemodel.h>
#include <bluetoothuitrace.h>


BtDelegateInquiry::BtDelegateInquiry(
        BtSettingModel* settingModel, 
        BtDeviceModel* deviceModel, QObject* parent )
    :BtAbstractDelegate( settingModel, deviceModel, parent )
{
    mAbstractDelegate = NULL;
}

BtDelegateInquiry::~BtDelegateInquiry()
{

}

void BtDelegateInquiry::exec( const QVariant& params )
{
    Q_UNUSED(params);
    
    if(isBtPowerOn()) {
        exec_inquiry();
    }
    else {
        //If Bt Power is off, switch it on and then perform pairing.
        //todo: Do we ask for user confirmation here..?
        if (!mAbstractDelegate) { 
            mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::ManagePower, 
                    getSettingModel(), getDeviceModel() ); 
            connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(powerDelegateCompleted(int)) );
            mAbstractDelegate->exec(QVariant(BtPowerOn));
        }
    }
}

void BtDelegateInquiry::powerDelegateCompleted(int error)
{
    if (mAbstractDelegate) {
        disconnect(mAbstractDelegate);
        delete mAbstractDelegate;
        mAbstractDelegate = 0;
    }
    if ( error == KErrNone ) {
        exec_inquiry();
    } 
    else {
        // error
        emit commandCompleted(error);
    }
}

void BtDelegateInquiry::exec_inquiry()
{
    bool err = getDeviceModel()->searchDevice();

    emit commandCompleted(err);  // in case of error, passing original error back
}

void BtDelegateInquiry::cancel()
{
    getDeviceModel()->cancelSearchDevice();
}