bluetoothengine/btui/btuidelegate/btdelegatepair.cpp
author hgs
Mon, 17 May 2010 11:06:23 +0300
changeset 31 a0ea99b6fa53
child 40 997690c3397a
child 42 b72428996822
permissions -rw-r--r--
201019_1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     1
/*
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     3
* All rights reserved.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     8
*
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     9
* Initial Contributors:
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    11
*
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    12
* Contributors:
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    13
*
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    14
* Description: 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    15
*
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    16
*/
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    17
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    18
#include "btdelegatepair.h"
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    19
#include "btuiutil.h"
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    20
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    21
#include <QModelIndex>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    22
#include <btsettingmodel.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    23
#include <btdevicemodel.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    24
#include <bluetoothuitrace.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    25
#include <hbnotificationdialog.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    26
#include <hblabel.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    27
#include <hbprogressbar.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    28
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    29
// docml to load
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    30
const char* BTUI_PAIR_WAIT_DOCML = ":/docml/pairwaitingdialog.docml";
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    32
BtDelegatePair::BtDelegatePair(
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    33
        BtSettingModel* settingModel, 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    34
        BtDeviceModel* deviceModel, 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    35
        QObject *parent) :
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    36
    BtAbstractDelegate(settingModel, deviceModel, parent), mBtengConnMan(0)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    37
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    38
    mLoader = new HbDocumentLoader();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    39
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    40
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    41
BtDelegatePair::~BtDelegatePair()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    42
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    43
    delete mBtengConnMan;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    44
    delete mLoader;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    45
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    46
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    47
void BtDelegatePair::exec( const QVariant &params )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    48
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    49
    int error = KErrNone;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    50
    QModelIndex index = params.value<QModelIndex>();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    51
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    52
    mdeviceName = getDeviceModel()->data(index,BtDeviceModel::NameAliasRole).toString();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    53
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    54
    QString strBtAddr = getDeviceModel()->data(index,BtDeviceModel::ReadableBdaddrRole).toString();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    55
    int cod = getDeviceModel()->data(index,BtDeviceModel::CoDRole).toInt();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    56
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    57
    if ( ! mBtengConnMan ){
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    58
        TRAP( error, mBtengConnMan = CBTEngConnMan::NewL(this) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    59
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    60
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    61
    if ( !error ) {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    62
        TBTDevAddr btEngddr;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    63
        addrReadbleStringToSymbian( strBtAddr, btEngddr );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    64
        TBTDeviceClass btEngDeviceClass(cod);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    65
        error = mBtengConnMan->PairDevice(btEngddr, btEngDeviceClass);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    66
        launchWaitDialog();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    67
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    68
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    69
    if(error) {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    70
        emitCommandComplete(error);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    71
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    72
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    73
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    74
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    75
void BtDelegatePair::launchWaitDialog()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    76
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    77
    QString headingText(hbTrId("Pairing with %1"));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    78
    HbLabel *heading;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    79
    HbProgressBar* progressBar;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    80
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    81
    bool ok = false;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    82
    mLoader->load( BTUI_PAIR_WAIT_DOCML, &ok );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    83
    // Exit if the file format is invalid
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    84
    BTUI_ASSERT_X( ok, "BTUI_PAIR_WAIT_DOCML", "Invalid docml file" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    85
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    86
    mWaitDialog = qobject_cast<HbDialog *>( mLoader->findWidget( "dialog" ) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    87
    BTUI_ASSERT_X( mWaitDialog != 0, "BTUI_PAIR_WAIT_DOCML", "dialog not found" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    88
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    89
    heading = qobject_cast<HbLabel *>( mLoader->findWidget( "heading" ) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    90
    BTUI_ASSERT_X( heading != 0, "BTUI_PAIR_WAIT_DOCML", "heading not found" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    91
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    92
    progressBar = qobject_cast<HbProgressBar *>( mLoader->findWidget( "progressBar" ) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    93
    BTUI_ASSERT_X( progressBar != 0, "BTUI_PAIR_WAIT_DOCML", "progressBar not found" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    94
    progressBar->setRange(0,0);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    95
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    96
    heading->setPlainText(headingText.arg(mdeviceName));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    97
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    98
    mWaitDialog->setDismissPolicy(HbPopup::NoDismiss);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    99
    mWaitDialog->setTimeout(HbPopup::NoTimeout);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   100
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   101
    mWaitDialog->show();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   102
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   103
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   104
void BtDelegatePair::ConnectComplete( TBTDevAddr& aAddr, TInt aErr, 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   105
                                   RBTDevAddrArray* aConflicts )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   106
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   107
    Q_UNUSED(aAddr);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   108
    Q_UNUSED(aErr);    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   109
    Q_UNUSED(aConflicts);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   110
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   111
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   112
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   113
void BtDelegatePair::DisconnectComplete( TBTDevAddr& aAddr, TInt aErr )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   114
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   115
    Q_UNUSED(aAddr);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   116
    Q_UNUSED(aErr);    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   117
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   118
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   119
void BtDelegatePair::PairingComplete( TBTDevAddr& aAddr, TInt aErr )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   120
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   121
    Q_UNUSED(aAddr);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   122
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   123
    mWaitDialog->close();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   124
    emitCommandComplete(aErr);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   125
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   126
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   127
void BtDelegatePair::emitCommandComplete(int error)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   128
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   129
    QString str(hbTrId("Paired to %1"));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   130
    QString err(hbTrId("Pairing with %1 Failed"));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   131
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   132
    if(error != KErrNone) {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   133
        HbNotificationDialog::launchDialog(err.arg(mdeviceName));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   134
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   135
    else {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   136
        HbNotificationDialog::launchDialog(str.arg(mdeviceName));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   137
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   138
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   139
    emit commandCompleted(error);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   140
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   141
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   142
void BtDelegatePair::cancel()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   143
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   144
    if ( mBtengConnMan ) {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   145
        mBtengConnMan->CancelPairDevice();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   146
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   147
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   148
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   149
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   150