bluetoothengine/btui/btcpplugin/btcpuideviceview.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) 2009 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 "btcpuideviceview.h"
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    19
#include "btuiviewutil.h"
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    20
#include <QtGui/QGraphicsLinearLayout>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    21
#include <HbInstance>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    22
#include <hbdocumentloader.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    23
#include <hbdataform.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    24
#include <hbgroupbox.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    25
#include <hbpushbutton.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    26
#include <hblabel.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    27
#include <hbtextedit.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    28
#include <hblistview.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    29
#include <hbmenu.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    30
#include <qstring>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    31
#include <qstringlist>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    32
#include <qdebug>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    33
#include <bluetoothuitrace.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    34
#include "btcpuimainview.h"
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    35
#include <btabstractdelegate.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    36
#include <btdelegatefactory.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    37
#include <QModelIndex>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    38
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    39
// docml to load
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    40
const char* BTUI_DEVICEVIEW_DOCML = ":/docml/bt-device-view.docml";
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    41
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    42
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    43
BtCpUiDeviceView::BtCpUiDeviceView(
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    44
        BtSettingModel &settingModel, 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    45
        BtDeviceModel &deviceModel, 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    46
        QGraphicsItem *parent) :
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    47
    BtCpUiBaseView(settingModel,deviceModel,parent),
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    48
    mPairStatus(false), mConnectStatus(false), mConnectable(false), mAbstractDelegate(0)   
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    49
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    50
    mDeviceIndex = QModelIndex();//is it needed to initialize mIndex???
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    51
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    52
    mMainView = (BtCpUiMainView *) parent;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    53
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    54
    mMainWindow = hbInstance->allMainWindows().first();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    55
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    56
    mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    57
    BTUI_ASSERT_X(mSoftKeyBackAction, "BtCpUiBaseView::BtCpUiBaseView", "can't create back action");
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    58
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    59
    // read view info from docml file
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    60
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    61
    // Create view for the application.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    62
    // Set the name for the view. The name should be same as the view's
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    63
    // name in docml.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    64
    setObjectName("bt_device_view");
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    65
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    66
    QObjectList objectList;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    67
    objectList.append(this);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    68
    // Pass the view to documentloader. Document loader uses this view
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    69
    // when docml is parsed, instead of creating new view.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    70
    mLoader = new HbDocumentLoader();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    71
    mLoader->setObjectTree(objectList);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    72
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    73
    bool ret = false;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    74
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    75
    bool ok = false;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    76
    mLoader->load( BTUI_DEVICEVIEW_DOCML, &ok );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    77
    // Exit if the file format is invalid
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    78
    BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    79
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    80
    // Set title for the control panel
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    81
    // ToDo:  check if deprecated API
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    82
    setTitle("Control Panel");
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    83
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    84
    // assign automatically created widgets to local variables
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    85
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    86
    mGroupBox = 0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    87
    mGroupBox = qobject_cast<HbGroupBox *>( mLoader->findWidget( "groupBox_deviceView" ) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    88
    BTUI_ASSERT_X( mGroupBox != 0, "bt-device-view", "Device groupbox not found" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    89
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    90
    mDeviceIcon=0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    91
    //can't use qobject_cast since HbIcon is not derived from QObject!
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    92
    mDeviceIcon = qobject_cast<HbLabel *>( mLoader->findWidget( "deviceIcon" ) );  
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    93
    BTUI_ASSERT_X( mDeviceIcon != 0, "bt-device-view", "Device Icon not found" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    94
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    95
    mDeviceName=0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    96
    mDeviceName = qobject_cast<HbTextEdit *>( mLoader->findWidget( "deviceName" ) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    97
    BTUI_ASSERT_X( mDeviceName != 0, "bt-device-view", "Device Name not found" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    98
    ret = connect(mDeviceName, SIGNAL(editingFinished ()), this, SLOT(changeBtDeviceName()));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    99
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   100
    mDeviceCategory=0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   101
    mDeviceCategory = qobject_cast<HbLabel *>( mLoader->findWidget( "deviceCategory" ) );  
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   102
    BTUI_ASSERT_X( mDeviceCategory != 0, "bt-device-view", "Device Category not found" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   103
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   104
    mDeviceStatus=0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   105
    mDeviceStatus = qobject_cast<HbLabel *>( mLoader->findWidget( "deviceStatus" ) );  
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   106
    BTUI_ASSERT_X( mDeviceStatus != 0, "bt-device-view", "Device status not found" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   107
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   108
    mPair_Unpair=0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   109
    mPair_Unpair = qobject_cast<HbPushButton *>( mLoader->findWidget( "pushButton_0" ) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   110
    BTUI_ASSERT_X( mPair_Unpair != 0, "bt-device-view", "pair/unpair button not found" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   111
    ret =  connect(mPair_Unpair, SIGNAL(clicked()), this, SLOT(pairUnpair()));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   112
    BTUI_ASSERT_X( ret, "BtCpUiDeviceView::BtCpUiDeviceView", "can't connect pair button" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   113
 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   114
    mConnect_Disconnect=0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   115
    mConnect_Disconnect = qobject_cast<HbPushButton *>( mLoader->findWidget( "pushButton_1" ) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   116
    BTUI_ASSERT_X( mConnect_Disconnect != 0, "bt-device-view", "connect/disconnect button not found" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   117
    ret =  connect(mConnect_Disconnect, SIGNAL(clicked()), this, SLOT(connectDisconnect()));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   118
    BTUI_ASSERT_X( ret, "BtCpUiDeviceView::BtCpUiDeviceView", "can't connect disconnect button" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   119
      
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   120
    mDeviceSetting = 0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   121
    mDeviceSetting = qobject_cast<HbPushButton *>( mLoader->findWidget( "pushButton_2" ) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   122
    BTUI_ASSERT_X( mDeviceSetting != 0, "bt-device-view", "settings button not found" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   123
        
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   124
    // read landscape orientation section from docml file if needed
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   125
    // mOrientation = ((BTUIViewManager*)parent)->orientation();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   126
    mOrientation = Qt::Vertical;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   127
    if (mOrientation == Qt::Horizontal) {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   128
        mLoader->load(BTUI_DEVICEVIEW_DOCML, "landscape", &ok);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   129
        BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file: landscape section problem" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   130
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   131
 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   132
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   133
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   134
BtCpUiDeviceView::~BtCpUiDeviceView()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   135
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   136
    setNavigationAction(0);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   137
    delete mSoftKeyBackAction;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   138
    if(mAbstractDelegate)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   139
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   140
        delete mAbstractDelegate;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   141
        mAbstractDelegate = 0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   142
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   143
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   144
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   145
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   146
void BtCpUiDeviceView::setSoftkeyBack()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   147
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   148
    if (navigationAction() != mSoftKeyBackAction) {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   149
        setNavigationAction(mSoftKeyBackAction);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   150
        connect( mSoftKeyBackAction, SIGNAL(triggered()), this, SLOT(switchToPreviousView()) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   151
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   152
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   153
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   154
void BtCpUiDeviceView::switchToPreviousView()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   155
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   156
    BTUI_ASSERT_X(mMainView, "BtCpUiSearchView::switchToPreviousView", "invalid mMainView");
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   157
    mMainView->switchToPreviousView();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   158
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   159
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   160
void BtCpUiDeviceView::activateView( const QVariant& value, int cmdId )
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   161
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   162
    Q_UNUSED(cmdId);  
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   163
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   164
    setSoftkeyBack();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   165
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   166
    QModelIndex index = value.value<QModelIndex>();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   167
    mDeviceBdAddr = (mDeviceModel->data(index, BtDeviceModel::ReadableBdaddrRole));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   168
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   169
    //activate view is called when device is selected
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   170
    clearViewData();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   171
    updateDeviceData();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   172
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   173
    bool ret(false);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   174
    ret=connect(mDeviceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   175
           this, SLOT(updateDeviceData()));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   176
    BTUI_ASSERT_X( ret, "Btui, BtCpUiDeviceView::activateView", "dataChanged() connect failed");
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   177
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   178
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   179
void BtCpUiDeviceView::deactivateView()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   180
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   181
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   182
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   183
void BtCpUiDeviceView::clearViewData()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   184
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   185
    mDeviceIcon->clear();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   186
    mDeviceCategory->clear();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   187
    mDeviceStatus->clear();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   188
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   189
    mPairStatus = false;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   190
    mConnectStatus = false;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   191
    mConnectable = false;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   192
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   193
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   194
void BtCpUiDeviceView::updateDeviceData()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   195
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   196
    QModelIndex localIndex = mSettingModel->index( BtSettingModel::LocalBtNameRow, 0);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   197
    QString localName = (mSettingModel->data(localIndex,BtSettingModel::settingDisplayRole)).toString();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   198
    QString groupBoxTitle (tr("Bluetooth-"));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   199
    mGroupBox->setHeading(groupBoxTitle.append(localName));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   200
    //Get the QModelIndex of the device using the device BDAddres
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   201
    QModelIndex start = mDeviceModel->index(0,0);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   202
    QModelIndexList indexList = mDeviceModel->match(start,BtDeviceModel::ReadableBdaddrRole, mDeviceBdAddr);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   203
    mDeviceIndex = indexList.at(0);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   204
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   205
    //populate device view with device data fetched from UiModel
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   206
    QString deviceName = (mDeviceModel->data(mDeviceIndex, 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   207
             BtDeviceModel::NameAliasRole)).toString(); 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   208
    mDeviceName->setPlainText(deviceName);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   209
     
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   210
    int cod = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::CoDRole)).toInt();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   211
     
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   212
    int majorRole = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::MajorPropertyRole)).toInt();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   213
    int minorRole = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::MinorPropertyRole)).toInt();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   214
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   215
	setDeviceCategory(cod, majorRole, minorRole);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   216
    setDeviceStatus(majorRole);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   217
    setTextAndVisibilityOfButtons();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   218
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   219
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   220
void BtCpUiDeviceView::setDeviceCategory(int cod,int majorRole, int minorRole)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   221
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   222
    //TODO: change the hardcoded numeric value to enumerations
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   223
    if (cod)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   224
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   225
        if (majorRole & 0x00020000)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   226
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   227
            //this is a phone
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   228
            mDeviceCategory->setPlainText(tr("Phone"));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   229
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   230
        else if (majorRole & 0x00010000)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   231
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   232
            //this is a computer
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   233
            mDeviceCategory->setPlainText(tr("Computer"));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   234
        
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   235
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   236
        else if (majorRole & 0x00080000)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   237
        {  
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   238
            //this is a A/V device
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   239
            //int minorRole = (mDeviceModel->data(mIndex,BtDeviceModel::MinorPropertyRole)).toInt();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   240
            if ( minorRole & 0x00000002)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   241
            {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   242
                //this is a Headset, it is possible to connect
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   243
                mConnectable = true;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   244
                mDeviceCategory->setPlainText(tr("Headset"));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   245
            }  
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   246
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   247
        else 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   248
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   249
            mDeviceCategory->setPlainText(tr("Uncategorized Dev"));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   250
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   251
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   252
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   253
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   254
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   255
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   256
void BtCpUiDeviceView::setDeviceStatus(int majorRole)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   257
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   258
    //TODO: change the hardcoded numeric value to enumerations
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   259
    QString deviceStatus;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   260
    if (majorRole & 0x00000001)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   261
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   262
        deviceStatus = deviceStatus.append(tr("Paired"));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   263
        mPairStatus = true;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   264
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   265
    else
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   266
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   267
        mPairStatus = false;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   268
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   269
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   270
    if ((majorRole & 0x00000020)&& (mConnectable))
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   271
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   272
        //if the device is connected and it is a headset NOTE! two phone can be paired but not be connected
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   273
        deviceStatus = deviceStatus.append(tr(", connected"));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   274
        mConnectStatus = true;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   275
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   276
    else 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   277
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   278
        mConnectStatus = false;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   279
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   280
    mDeviceStatus->setPlainText(deviceStatus);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   281
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   282
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   283
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   284
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   285
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   286
void BtCpUiDeviceView::setTextAndVisibilityOfButtons()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   287
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   288
    if (mPairStatus)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   289
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   290
        mPair_Unpair->setText(tr("Unpair"));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   291
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   292
    else
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   293
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   294
        mPair_Unpair->setText(tr("Pair"));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   295
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   296
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   297
    if (mConnectable)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   298
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   299
        if (mConnectStatus)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   300
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   301
            mConnect_Disconnect->setText(tr("Disconnect"));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   302
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   303
        else
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   304
        {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   305
            mConnect_Disconnect->setText(tr("Connect"));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   306
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   307
        
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   308
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   309
    else
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   310
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   311
        //it is not possible to connect, set the button invisible
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   312
        mConnect_Disconnect->setVisible(false);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   313
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   314
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   315
    mDeviceSetting->setVisible(false);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   316
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   317
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   318
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   319
void BtCpUiDeviceView::changeBtDeviceName()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   320
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   321
    /*
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   322
    if (!mAbstractDelegate) 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   323
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   324
        mAbstractDelegate = BtDelegateFactory::newDelegate(BtDelegate::DeviceName, mModel); 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   325
        connect( mAbstractDelegate, SIGNAL(commandCompleted(int,QVariant)), this, SLOT(btNameDelegateCompleted(int,QVariant)) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   326
        mAbstractDelegate->exec(mDeviceNameEdit->text ());
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   327
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   328
    */
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   329
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   330
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   331
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   332
void BtCpUiDeviceView::pairUnpair()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   333
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   334
    if (mPairStatus)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   335
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   336
        //if the device is paired, call unpairDevice() when the button is tabbed
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   337
        unpairDevice();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   338
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   339
    else
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   340
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   341
        //if the device is unpaired, call pairDevice() when the button is tabbed
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   342
        pairDevice();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   343
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   344
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   345
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   346
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   347
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   348
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   349
void BtCpUiDeviceView::connectDisconnect()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   350
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   351
    if (mConnectStatus)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   352
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   353
        //if the device is connected, call disconnectDevice() when the button is tabbed
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   354
        disconnectDevice();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   355
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   356
    else
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   357
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   358
        //if the device is disconnected, call connectDevice() when the button is tabbed
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   359
        connectDevice();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   360
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   361
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   362
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   363
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   364
void BtCpUiDeviceView::pairDevice()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   365
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   366
    if (!mAbstractDelegate)//if there is no other delegate running
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   367
    { 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   368
        QVariant params;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   369
        params.setValue(mDeviceIndex);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   370
        mAbstractDelegate = BtDelegateFactory::newDelegate(
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   371
                BtDelegate::Pair, mSettingModel, mDeviceModel); 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   372
        connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(pairDelegateCompleted(int)) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   373
        mAbstractDelegate->exec(params);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   374
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   375
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   376
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   377
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   378
void BtCpUiDeviceView::pairDelegateCompleted(int status)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   379
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   380
    Q_UNUSED(status);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   381
    //TODO: handle the error here
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   382
    if (mAbstractDelegate)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   383
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   384
        disconnect(mAbstractDelegate);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   385
        delete mAbstractDelegate;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   386
        mAbstractDelegate = 0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   387
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   388
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   389
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   390
void BtCpUiDeviceView::unpairDevice()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   391
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   392
    if (!mAbstractDelegate)//if there is no other delegate running
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   393
    { 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   394
        QVariant params;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   395
        params.setValue(mDeviceIndex);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   396
        mAbstractDelegate = BtDelegateFactory::newDelegate(
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   397
                BtDelegate::Unpair, mSettingModel, mDeviceModel); 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   398
        connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(unpairDelegateCompleted(int)) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   399
        mAbstractDelegate->exec(params);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   400
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   401
        
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   402
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   403
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   404
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   405
void BtCpUiDeviceView::unpairDelegateCompleted(int status)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   406
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   407
    Q_UNUSED(status);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   408
    //TODO: handle the error here 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   409
    if (mAbstractDelegate)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   410
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   411
        disconnect(mAbstractDelegate);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   412
        delete mAbstractDelegate;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   413
        mAbstractDelegate = 0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   414
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   415
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   416
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   417
void BtCpUiDeviceView::connectDevice()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   418
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   419
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   420
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   421
    if (!mAbstractDelegate)//if there is no other delegate running
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   422
    { 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   423
        QVariant params;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   424
        params.setValue(mDeviceIndex);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   425
        mAbstractDelegate = BtDelegateFactory::newDelegate(
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   426
                BtDelegate::Connect, mSettingModel, mDeviceModel); 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   427
        connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(connectDelegateCompleted(int)) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   428
        mAbstractDelegate->exec(params);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   429
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   430
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   431
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   432
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   433
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   434
void BtCpUiDeviceView::connectDelegateCompleted(int status)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   435
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   436
    Q_UNUSED(status);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   437
    if (mAbstractDelegate)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   438
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   439
        disconnect(mAbstractDelegate);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   440
        delete mAbstractDelegate;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   441
        mAbstractDelegate = 0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   442
    }   
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   443
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   444
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   445
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   446
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   447
void BtCpUiDeviceView::disconnectDevice()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   448
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   449
    if (!mAbstractDelegate)//if there is no other delegate running
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   450
        { 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   451
            QVariant params;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   452
            params.setValue(mDeviceIndex);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   453
            mAbstractDelegate = BtDelegateFactory::newDelegate(
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   454
                    BtDelegate::Disconnect, mSettingModel, mDeviceModel); 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   455
            connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(disconnectDelegateCompleted(int)) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   456
            mAbstractDelegate->exec(params);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   457
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   458
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   459
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   460
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   461
void BtCpUiDeviceView::disconnectDelegateCompleted(int status)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   462
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   463
    Q_UNUSED(status);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   464
    if (mAbstractDelegate)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   465
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   466
        disconnect(mAbstractDelegate);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   467
        delete mAbstractDelegate;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   468
        mAbstractDelegate = 0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   469
    }   
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   470
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   471
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   472
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   473