bluetoothengine/btui/btcpplugin/btcpuideviceview.cpp
author hgs
Mon, 12 Jul 2010 18:51:05 +0300
changeset 42 b72428996822
parent 31 a0ea99b6fa53
child 47 9e2a905b887f
permissions -rw-r--r--
201025
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
     1
/*
42
hgs
parents: 31
diff changeset
     2
 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
31
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>
42
hgs
parents: 31
diff changeset
    24
#include <hbdataformmodel.h>
hgs
parents: 31
diff changeset
    25
#include <hbdataformmodelitem.h>
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    26
#include <hbgroupbox.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    27
#include <hbpushbutton.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    28
#include <hblabel.h>
42
hgs
parents: 31
diff changeset
    29
#include <hbicon.h>
hgs
parents: 31
diff changeset
    30
#include <hblineedit.h>
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    31
#include <hblistview.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    32
#include <hbmenu.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    33
#include <qstring>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    34
#include <qstringlist>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    35
#include <qdebug>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    36
#include <bluetoothuitrace.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    37
#include "btcpuimainview.h"
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    38
#include <btabstractdelegate.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    39
#include <btdelegatefactory.h>
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    40
#include <QModelIndex>
42
hgs
parents: 31
diff changeset
    41
#include "btuiiconutil.h"
hgs
parents: 31
diff changeset
    42
#include "btuidevtypemap.h"
hgs
parents: 31
diff changeset
    43
hgs
parents: 31
diff changeset
    44
#include "btcpuidevicedetail.h"
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    45
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    46
// docml to load
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    47
const char* BTUI_DEVICEVIEW_DOCML = ":/docml/bt-device-view.docml";
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    48
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    49
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    50
BtCpUiDeviceView::BtCpUiDeviceView(
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    51
        BtSettingModel &settingModel, 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    52
        BtDeviceModel &deviceModel, 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    53
        QGraphicsItem *parent) :
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    54
    BtCpUiBaseView(settingModel,deviceModel,parent),
42
hgs
parents: 31
diff changeset
    55
    mPairedStatus(false), mConnectedStatus(false), mTrustedStatus(false), mBlockedStatus(false), 
hgs
parents: 31
diff changeset
    56
    mConnectable(false), mAbstractDelegate(0), mDeviceDetail(0)   
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    57
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    58
    mDeviceIndex = QModelIndex();//is it needed to initialize mIndex???
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    59
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    60
    mMainView = (BtCpUiMainView *) parent;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    61
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    62
    mMainWindow = hbInstance->allMainWindows().first();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    63
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    64
    mSoftKeyBackAction = new HbAction(Hb::BackNaviAction, this);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    65
    BTUI_ASSERT_X(mSoftKeyBackAction, "BtCpUiBaseView::BtCpUiBaseView", "can't create back action");
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    66
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    67
    // read view info from docml file
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    68
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    69
    // Create view for the application.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    70
    // Set the name for the view. The name should be same as the view's
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    71
    // name in docml.
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    72
    setObjectName("bt_device_view");
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    73
42
hgs
parents: 31
diff changeset
    74
    mLoader = new HbDocumentLoader();
hgs
parents: 31
diff changeset
    75
    // Pass the view to documentloader. Document loader uses this view
hgs
parents: 31
diff changeset
    76
    // when docml is parsed, instead of creating new view.
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    77
    QObjectList objectList;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    78
    objectList.append(this);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    79
    mLoader->setObjectTree(objectList);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    80
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    81
    bool ret = false;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    82
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    83
    bool ok = false;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    84
    mLoader->load( BTUI_DEVICEVIEW_DOCML, &ok );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    85
    // Exit if the file format is invalid
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    86
    BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
    87
    
42
hgs
parents: 31
diff changeset
    88
    mOrientation = mMainWindow->orientation();
hgs
parents: 31
diff changeset
    89
        
hgs
parents: 31
diff changeset
    90
    if (mOrientation == Qt::Horizontal) {
hgs
parents: 31
diff changeset
    91
        mLoader->load(BTUI_DEVICEVIEW_DOCML, "landscape", &ok);
hgs
parents: 31
diff changeset
    92
        BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file: landscape section problem" );
hgs
parents: 31
diff changeset
    93
    }
hgs
parents: 31
diff changeset
    94
    else {
hgs
parents: 31
diff changeset
    95
        mLoader->load(BTUI_DEVICEVIEW_DOCML, "portrait", &ok);
hgs
parents: 31
diff changeset
    96
        BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file: landscape section problem" );        
hgs
parents: 31
diff changeset
    97
    }
hgs
parents: 31
diff changeset
    98
    
hgs
parents: 31
diff changeset
    99
    // listen for orientation changes
hgs
parents: 31
diff changeset
   100
    ret = connect(mMainWindow, SIGNAL(orientationChanged(Qt::Orientation)),
hgs
parents: 31
diff changeset
   101
            this, SLOT(changeOrientation(Qt::Orientation)));
hgs
parents: 31
diff changeset
   102
    BTUI_ASSERT_X( ret, "BtCpUiDeviceView::BtCpUiDeviceView()", "connect orientationChanged() failed");
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   103
42
hgs
parents: 31
diff changeset
   104
    
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   105
    // assign automatically created widgets to local variables
42
hgs
parents: 31
diff changeset
   106
    /*
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   107
    mGroupBox = 0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   108
    mGroupBox = qobject_cast<HbGroupBox *>( mLoader->findWidget( "groupBox_deviceView" ) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   109
    BTUI_ASSERT_X( mGroupBox != 0, "bt-device-view", "Device groupbox not found" );
42
hgs
parents: 31
diff changeset
   110
    */
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   111
    mDeviceIcon=0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   112
    //can't use qobject_cast since HbIcon is not derived from QObject!
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   113
    mDeviceIcon = qobject_cast<HbLabel *>( mLoader->findWidget( "deviceIcon" ) );  
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   114
    BTUI_ASSERT_X( mDeviceIcon != 0, "bt-device-view", "Device Icon not found" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   115
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   116
    mDeviceName=0;
42
hgs
parents: 31
diff changeset
   117
    mDeviceName = qobject_cast<HbLineEdit *>( mLoader->findWidget( "deviceName" ) );
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   118
    BTUI_ASSERT_X( mDeviceName != 0, "bt-device-view", "Device Name not found" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   119
    ret = connect(mDeviceName, SIGNAL(editingFinished ()), this, SLOT(changeBtDeviceName()));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   120
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   121
    mDeviceCategory=0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   122
    mDeviceCategory = qobject_cast<HbLabel *>( mLoader->findWidget( "deviceCategory" ) );  
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   123
    BTUI_ASSERT_X( mDeviceCategory != 0, "bt-device-view", "Device Category not found" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   124
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   125
    mDeviceStatus=0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   126
    mDeviceStatus = qobject_cast<HbLabel *>( mLoader->findWidget( "deviceStatus" ) );  
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   127
    BTUI_ASSERT_X( mDeviceStatus != 0, "bt-device-view", "Device status not found" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   128
    
42
hgs
parents: 31
diff changeset
   129
    
hgs
parents: 31
diff changeset
   130
    mConnectionCombobox = 0;
hgs
parents: 31
diff changeset
   131
    mConnectionCombobox = qobject_cast<HbDataForm *>( mLoader->findWidget( "connectionCombobox" ) );
hgs
parents: 31
diff changeset
   132
    BTUI_ASSERT_X( mConnectionCombobox != 0, "bt-device-view", "connection combobox not found" );
hgs
parents: 31
diff changeset
   133
    
hgs
parents: 31
diff changeset
   134
    mConnectionComboboxModel = new HbDataFormModel();
hgs
parents: 31
diff changeset
   135
    
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   136
    mPair_Unpair=0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   137
    mPair_Unpair = qobject_cast<HbPushButton *>( mLoader->findWidget( "pushButton_0" ) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   138
    BTUI_ASSERT_X( mPair_Unpair != 0, "bt-device-view", "pair/unpair button not found" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   139
    ret =  connect(mPair_Unpair, SIGNAL(clicked()), this, SLOT(pairUnpair()));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   140
    BTUI_ASSERT_X( ret, "BtCpUiDeviceView::BtCpUiDeviceView", "can't connect pair button" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   141
 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   142
    mConnect_Disconnect=0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   143
    mConnect_Disconnect = qobject_cast<HbPushButton *>( mLoader->findWidget( "pushButton_1" ) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   144
    BTUI_ASSERT_X( mConnect_Disconnect != 0, "bt-device-view", "connect/disconnect button not found" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   145
    ret =  connect(mConnect_Disconnect, SIGNAL(clicked()), this, SLOT(connectDisconnect()));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   146
    BTUI_ASSERT_X( ret, "BtCpUiDeviceView::BtCpUiDeviceView", "can't connect disconnect button" );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   147
      
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   148
    mDeviceSetting = 0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   149
    mDeviceSetting = qobject_cast<HbPushButton *>( mLoader->findWidget( "pushButton_2" ) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   150
    BTUI_ASSERT_X( mDeviceSetting != 0, "bt-device-view", "settings button not found" );
42
hgs
parents: 31
diff changeset
   151
    
hgs
parents: 31
diff changeset
   152
    
hgs
parents: 31
diff changeset
   153
    ret = connect(mDeviceSetting, SIGNAL(clicked()), this,
hgs
parents: 31
diff changeset
   154
            SLOT(handleDeviceSetting()));
hgs
parents: 31
diff changeset
   155
    BTUI_ASSERT_X( ret, "Btui, BtCpUiDeviceView::BtCpUiDeviceView", "clicked() connect failed");
hgs
parents: 31
diff changeset
   156
hgs
parents: 31
diff changeset
   157
    setConnectionCombobox();
hgs
parents: 31
diff changeset
   158
     
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   159
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   160
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   161
BtCpUiDeviceView::~BtCpUiDeviceView()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   162
{
42
hgs
parents: 31
diff changeset
   163
    delete mLoader; // Also deletes all widgets that it constructed.
hgs
parents: 31
diff changeset
   164
    
hgs
parents: 31
diff changeset
   165
    delete mConnectionComboboxModel;
hgs
parents: 31
diff changeset
   166
    
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   167
    setNavigationAction(0);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   168
    delete mSoftKeyBackAction;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   169
    if(mAbstractDelegate)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   170
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   171
        delete mAbstractDelegate;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   172
        mAbstractDelegate = 0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   173
    }
42
hgs
parents: 31
diff changeset
   174
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   175
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   176
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   177
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   178
void BtCpUiDeviceView::setSoftkeyBack()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   179
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   180
    if (navigationAction() != mSoftKeyBackAction) {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   181
        setNavigationAction(mSoftKeyBackAction);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   182
        connect( mSoftKeyBackAction, SIGNAL(triggered()), this, SLOT(switchToPreviousView()) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   183
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   184
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   185
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   186
void BtCpUiDeviceView::switchToPreviousView()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   187
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   188
    BTUI_ASSERT_X(mMainView, "BtCpUiSearchView::switchToPreviousView", "invalid mMainView");
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   189
    mMainView->switchToPreviousView();
42
hgs
parents: 31
diff changeset
   190
    delete mDeviceDetail;
hgs
parents: 31
diff changeset
   191
    mDeviceDetail = 0;
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   192
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   193
42
hgs
parents: 31
diff changeset
   194
void BtCpUiDeviceView::activateView( const QVariant& value, bool fromBackButton )
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   195
{
42
hgs
parents: 31
diff changeset
   196
    Q_UNUSED( fromBackButton );  
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   197
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   198
    setSoftkeyBack();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   199
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   200
    QModelIndex index = value.value<QModelIndex>();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   201
    mDeviceBdAddr = (mDeviceModel->data(index, BtDeviceModel::ReadableBdaddrRole));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   202
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   203
    //activate view is called when device is selected
42
hgs
parents: 31
diff changeset
   204
    //clearViewData();
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   205
    updateDeviceData();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   206
    
42
hgs
parents: 31
diff changeset
   207
    mDeviceSetting->setVisible(false);
hgs
parents: 31
diff changeset
   208
    
hgs
parents: 31
diff changeset
   209
    mDeviceDetail = new BtCpUiDeviceDetail();
hgs
parents: 31
diff changeset
   210
    
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   211
    bool ret(false);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   212
    ret=connect(mDeviceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   213
           this, SLOT(updateDeviceData()));
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   214
    BTUI_ASSERT_X( ret, "Btui, BtCpUiDeviceView::activateView", "dataChanged() connect failed");
42
hgs
parents: 31
diff changeset
   215
hgs
parents: 31
diff changeset
   216
    ret=connect(mDeviceDetail, SIGNAL(deviceSettingsChanged(bool)),
hgs
parents: 31
diff changeset
   217
           this, SLOT(handleDeviceSettingsChange(bool)));
hgs
parents: 31
diff changeset
   218
    BTUI_ASSERT_X( ret, "Btui, BtCpUiDeviceView::activateView", "deviceSettingsChanged() connect failed");
hgs
parents: 31
diff changeset
   219
hgs
parents: 31
diff changeset
   220
    
hgs
parents: 31
diff changeset
   221
    mDeviceDetail->loadDeviceDetailPlugins(mDeviceBdAddr.toString(), mDeviceName->text());
hgs
parents: 31
diff changeset
   222
    
hgs
parents: 31
diff changeset
   223
}
hgs
parents: 31
diff changeset
   224
hgs
parents: 31
diff changeset
   225
void BtCpUiDeviceView::handleDeviceSettingsChange(bool status)
hgs
parents: 31
diff changeset
   226
{
hgs
parents: 31
diff changeset
   227
    mDeviceSetting->setVisible(status);        
hgs
parents: 31
diff changeset
   228
}
hgs
parents: 31
diff changeset
   229
hgs
parents: 31
diff changeset
   230
void BtCpUiDeviceView::handleDeviceSetting()
hgs
parents: 31
diff changeset
   231
{
hgs
parents: 31
diff changeset
   232
    mDeviceDetail->loadDeviceDetailsView();
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   233
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   234
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   235
void BtCpUiDeviceView::deactivateView()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   236
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   237
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   238
42
hgs
parents: 31
diff changeset
   239
// called due to real orientation change event coming from main window
hgs
parents: 31
diff changeset
   240
void BtCpUiDeviceView::changeOrientation( Qt::Orientation orientation )
hgs
parents: 31
diff changeset
   241
{
hgs
parents: 31
diff changeset
   242
    bool ok = false;
hgs
parents: 31
diff changeset
   243
    mOrientation = orientation;
hgs
parents: 31
diff changeset
   244
    if( orientation == Qt::Vertical ) {
hgs
parents: 31
diff changeset
   245
        // load "portrait" section
hgs
parents: 31
diff changeset
   246
        mLoader->load( BTUI_DEVICEVIEW_DOCML, "portrait", &ok );
hgs
parents: 31
diff changeset
   247
        BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file: portrait section problem" );
hgs
parents: 31
diff changeset
   248
    } else {
hgs
parents: 31
diff changeset
   249
        // load "landscape" section
hgs
parents: 31
diff changeset
   250
        mLoader->load( BTUI_DEVICEVIEW_DOCML, "landscape", &ok );
hgs
parents: 31
diff changeset
   251
        BTUI_ASSERT_X( ok, "bt-device-view", "Invalid docml file: landscape section problem" );
hgs
parents: 31
diff changeset
   252
    }
hgs
parents: 31
diff changeset
   253
}
hgs
parents: 31
diff changeset
   254
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   255
void BtCpUiDeviceView::clearViewData()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   256
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   257
    mDeviceIcon->clear();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   258
    mDeviceCategory->clear();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   259
    mDeviceStatus->clear();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   260
    
42
hgs
parents: 31
diff changeset
   261
    mPairedStatus = false;
hgs
parents: 31
diff changeset
   262
    mConnectedStatus = false;
hgs
parents: 31
diff changeset
   263
    mTrustedStatus = false;
hgs
parents: 31
diff changeset
   264
    mBlockedStatus = false;
hgs
parents: 31
diff changeset
   265
    
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   266
    mConnectable = false;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   267
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   268
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   269
void BtCpUiDeviceView::updateDeviceData()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   270
{
42
hgs
parents: 31
diff changeset
   271
    clearViewData();
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   272
    //Get the QModelIndex of the device using the device BDAddres
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   273
    QModelIndex start = mDeviceModel->index(0,0);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   274
    QModelIndexList indexList = mDeviceModel->match(start,BtDeviceModel::ReadableBdaddrRole, mDeviceBdAddr);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   275
    mDeviceIndex = indexList.at(0);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   276
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   277
    //populate device view with device data fetched from UiModel
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   278
    QString deviceName = (mDeviceModel->data(mDeviceIndex, 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   279
             BtDeviceModel::NameAliasRole)).toString(); 
42
hgs
parents: 31
diff changeset
   280
    mDeviceName->setText(deviceName);
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   281
     
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   282
    int cod = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::CoDRole)).toInt();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   283
     
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   284
    int majorRole = (mDeviceModel->data(mDeviceIndex,BtDeviceModel::MajorPropertyRole)).toInt();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   285
    
42
hgs
parents: 31
diff changeset
   286
	setDeviceCategory(cod, majorRole);
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   287
    setDeviceStatus(majorRole);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   288
    setTextAndVisibilityOfButtons();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   289
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   290
42
hgs
parents: 31
diff changeset
   291
void BtCpUiDeviceView::setDeviceCategory(int cod,int majorRole)
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   292
{
42
hgs
parents: 31
diff changeset
   293
    mDeviceCategory->setPlainText( getDeviceTypeString( cod ));
hgs
parents: 31
diff changeset
   294
    HbIcon icon =
hgs
parents: 31
diff changeset
   295
    getBadgedDeviceTypeIcon(cod, majorRole,
hgs
parents: 31
diff changeset
   296
                            BtuiBottomLeft | BtuiBottomRight | BtuiTopLeft | BtuiTopRight );
hgs
parents: 31
diff changeset
   297
    mDeviceIcon->setIcon(icon);
hgs
parents: 31
diff changeset
   298
hgs
parents: 31
diff changeset
   299
    if (majorRole & BtuiDevProperty::Connectable ) {
hgs
parents: 31
diff changeset
   300
        mConnectable = true;
hgs
parents: 31
diff changeset
   301
    } 
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   302
}
42
hgs
parents: 31
diff changeset
   303
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   304
void BtCpUiDeviceView::setDeviceStatus(int majorRole)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   305
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   306
    QString deviceStatus;
42
hgs
parents: 31
diff changeset
   307
    
hgs
parents: 31
diff changeset
   308
    updateStatusVariables(majorRole);  // should we use bitmap instead??
hgs
parents: 31
diff changeset
   309
    
hgs
parents: 31
diff changeset
   310
    if (majorRole & BtuiDevProperty::Bonded && 
hgs
parents: 31
diff changeset
   311
        majorRole & BtuiDevProperty::Trusted &&
hgs
parents: 31
diff changeset
   312
        majorRole & BtuiDevProperty::Connected ) {
hgs
parents: 31
diff changeset
   313
        mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_trused_connected"));
hgs
parents: 31
diff changeset
   314
    } 
hgs
parents: 31
diff changeset
   315
    else if (majorRole & BtuiDevProperty::Bonded && 
hgs
parents: 31
diff changeset
   316
             majorRole & BtuiDevProperty::Connected ) {
hgs
parents: 31
diff changeset
   317
        mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_connected"));
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   318
    }
42
hgs
parents: 31
diff changeset
   319
    else if (majorRole & BtuiDevProperty::Bonded && 
hgs
parents: 31
diff changeset
   320
             majorRole & BtuiDevProperty::Trusted ) {
hgs
parents: 31
diff changeset
   321
        mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired_trusted"));
hgs
parents: 31
diff changeset
   322
    } 
hgs
parents: 31
diff changeset
   323
    else if (majorRole & BtuiDevProperty::Bonded) {
hgs
parents: 31
diff changeset
   324
        mDeviceStatus->setPlainText(hbTrId("txt_bt_info_paired"));
hgs
parents: 31
diff changeset
   325
    }
hgs
parents: 31
diff changeset
   326
    else if (majorRole & BtuiDevProperty::Connected) {
hgs
parents: 31
diff changeset
   327
        mDeviceStatus->setPlainText(hbTrId("txt_bt_info_connected"));
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   328
    }
42
hgs
parents: 31
diff changeset
   329
    else if (majorRole & BtuiDevProperty::Blocked) {
hgs
parents: 31
diff changeset
   330
        mDeviceStatus->setPlainText(hbTrId("txt_bt_info_blocked"));
hgs
parents: 31
diff changeset
   331
    }
hgs
parents: 31
diff changeset
   332
    else {
hgs
parents: 31
diff changeset
   333
        // device not paired, connected, trusted or blocked.  is this ok?
hgs
parents: 31
diff changeset
   334
    }
hgs
parents: 31
diff changeset
   335
hgs
parents: 31
diff changeset
   336
}
hgs
parents: 31
diff changeset
   337
hgs
parents: 31
diff changeset
   338
void BtCpUiDeviceView::setConnectionCombobox(){
hgs
parents: 31
diff changeset
   339
    
hgs
parents: 31
diff changeset
   340
    //create a model class
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   341
    
42
hgs
parents: 31
diff changeset
   342
    mConnectionComboboxModel->appendDataFormItem(
hgs
parents: 31
diff changeset
   343
    HbDataFormModelItem::ComboBoxItem, QString("Connection"), mConnectionComboboxModel->invisibleRootItem());
hgs
parents: 31
diff changeset
   344
    
hgs
parents: 31
diff changeset
   345
    //set the model to the view, once model and data class are created
hgs
parents: 31
diff changeset
   346
    mConnectionCombobox->setModel(mConnectionComboboxModel);
hgs
parents: 31
diff changeset
   347
hgs
parents: 31
diff changeset
   348
hgs
parents: 31
diff changeset
   349
hgs
parents: 31
diff changeset
   350
}
hgs
parents: 31
diff changeset
   351
hgs
parents: 31
diff changeset
   352
hgs
parents: 31
diff changeset
   353
/*!
hgs
parents: 31
diff changeset
   354
 *  instead of using separate boolean variables we could use bitmap in single variable
hgs
parents: 31
diff changeset
   355
 */
hgs
parents: 31
diff changeset
   356
void BtCpUiDeviceView::updateStatusVariables(int majorRole)
hgs
parents: 31
diff changeset
   357
{
hgs
parents: 31
diff changeset
   358
    if (majorRole & BtuiDevProperty::Trusted ) {
hgs
parents: 31
diff changeset
   359
        mTrustedStatus = true;
hgs
parents: 31
diff changeset
   360
    } 
hgs
parents: 31
diff changeset
   361
    else {
hgs
parents: 31
diff changeset
   362
        mTrustedStatus = false;
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   363
    }
42
hgs
parents: 31
diff changeset
   364
    if (majorRole & BtuiDevProperty::Bonded) {
hgs
parents: 31
diff changeset
   365
        mPairedStatus = true;
hgs
parents: 31
diff changeset
   366
    }
hgs
parents: 31
diff changeset
   367
    else {
hgs
parents: 31
diff changeset
   368
        mPairedStatus = false;
hgs
parents: 31
diff changeset
   369
    }
hgs
parents: 31
diff changeset
   370
    if (majorRole & BtuiDevProperty::Connected) {
hgs
parents: 31
diff changeset
   371
        mConnectedStatus = true;
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   372
    }
42
hgs
parents: 31
diff changeset
   373
    else {
hgs
parents: 31
diff changeset
   374
        mConnectedStatus = false;
hgs
parents: 31
diff changeset
   375
    }
hgs
parents: 31
diff changeset
   376
    if (majorRole & BtuiDevProperty::Blocked) {
hgs
parents: 31
diff changeset
   377
        mBlockedStatus = true;
hgs
parents: 31
diff changeset
   378
    }
hgs
parents: 31
diff changeset
   379
    else {
hgs
parents: 31
diff changeset
   380
        mBlockedStatus = false;
hgs
parents: 31
diff changeset
   381
    }
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   382
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   383
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   384
void BtCpUiDeviceView::setTextAndVisibilityOfButtons()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   385
{
42
hgs
parents: 31
diff changeset
   386
    mPair_Unpair->setStretched(true);
hgs
parents: 31
diff changeset
   387
    if (mPairedStatus)
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   388
    {
42
hgs
parents: 31
diff changeset
   389
        HbIcon icon("qtg_mono_bt_unpair");
hgs
parents: 31
diff changeset
   390
        icon.setIconName("qtg_mono_bt_unpair");
hgs
parents: 31
diff changeset
   391
        mPair_Unpair->setIcon(icon);
hgs
parents: 31
diff changeset
   392
        mPair_Unpair->setText(hbTrId("txt_bt_button_unpair"));
hgs
parents: 31
diff changeset
   393
				
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   394
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   395
    else
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   396
    {
42
hgs
parents: 31
diff changeset
   397
        HbIcon icon("qtg_mono_bt_pair");
hgs
parents: 31
diff changeset
   398
        icon.setIconName("qtg_mono_bt_pair");
hgs
parents: 31
diff changeset
   399
        mPair_Unpair->setIcon(icon);
hgs
parents: 31
diff changeset
   400
        mPair_Unpair->setText(hbTrId("txt_bt_button_pair"));
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   401
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   402
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   403
    if (mConnectable)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   404
    {
42
hgs
parents: 31
diff changeset
   405
        mConnect_Disconnect->setStretched(true);
hgs
parents: 31
diff changeset
   406
        if (mConnectedStatus)
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   407
        {
42
hgs
parents: 31
diff changeset
   408
            HbIcon icon("qtg_mono_speaker_off");
hgs
parents: 31
diff changeset
   409
            icon.setIconName("qtg_mono_speaker_off");
hgs
parents: 31
diff changeset
   410
            mConnect_Disconnect->setIcon(icon);
hgs
parents: 31
diff changeset
   411
            mConnect_Disconnect->setText(hbTrId("txt_bt_button_disconnect"));
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   412
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   413
        else
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   414
        {
42
hgs
parents: 31
diff changeset
   415
            HbIcon icon("qtg_mono_speaker");
hgs
parents: 31
diff changeset
   416
            icon.setIconName("qtg_mono_speaker");
hgs
parents: 31
diff changeset
   417
            mConnect_Disconnect->setIcon(icon);
hgs
parents: 31
diff changeset
   418
            mConnect_Disconnect->setText(hbTrId("txt_bt_button_connect"));
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   419
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   420
        
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   421
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   422
    else
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   423
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   424
        //it is not possible to connect, set the button invisible
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   425
        mConnect_Disconnect->setVisible(false);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   426
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   427
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   428
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   429
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   430
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   431
void BtCpUiDeviceView::pairUnpair()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   432
{
42
hgs
parents: 31
diff changeset
   433
    if (mPairedStatus)
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   434
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   435
        //if the device is paired, call unpairDevice() when the button is tabbed
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   436
        unpairDevice();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   437
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   438
    else
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   439
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   440
        //if the device is unpaired, call pairDevice() when the button is tabbed
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   441
        pairDevice();
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
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   448
void BtCpUiDeviceView::connectDisconnect()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   449
{
42
hgs
parents: 31
diff changeset
   450
    if (mConnectedStatus)
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   451
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   452
        //if the device is connected, call disconnectDevice() when the button is tabbed
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   453
        disconnectDevice();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   454
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   455
    else
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   456
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   457
        //if the device is disconnected, call connectDevice() when the button is tabbed
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   458
        connectDevice();
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   459
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   460
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   461
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   462
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   463
void BtCpUiDeviceView::pairDevice()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   464
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   465
    if (!mAbstractDelegate)//if there is no other delegate running
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   466
    { 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   467
        QVariant params;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   468
        params.setValue(mDeviceIndex);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   469
        mAbstractDelegate = BtDelegateFactory::newDelegate(
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   470
                BtDelegate::Pair, mSettingModel, mDeviceModel); 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   471
        connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(pairDelegateCompleted(int)) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   472
        mAbstractDelegate->exec(params);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   473
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   474
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   475
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   476
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   477
void BtCpUiDeviceView::pairDelegateCompleted(int status)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   478
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   479
    Q_UNUSED(status);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   480
    //TODO: handle the error here
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   481
    if (mAbstractDelegate)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   482
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   483
        disconnect(mAbstractDelegate);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   484
        delete mAbstractDelegate;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   485
        mAbstractDelegate = 0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   486
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   487
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   488
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   489
void BtCpUiDeviceView::unpairDevice()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   490
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   491
    if (!mAbstractDelegate)//if there is no other delegate running
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   492
    { 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   493
        QVariant params;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   494
        params.setValue(mDeviceIndex);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   495
        mAbstractDelegate = BtDelegateFactory::newDelegate(
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   496
                BtDelegate::Unpair, mSettingModel, mDeviceModel); 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   497
        connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(unpairDelegateCompleted(int)) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   498
        mAbstractDelegate->exec(params);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   499
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   500
        
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   501
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   502
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   503
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   504
void BtCpUiDeviceView::unpairDelegateCompleted(int status)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   505
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   506
    Q_UNUSED(status);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   507
    //TODO: handle the error here 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   508
    if (mAbstractDelegate)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   509
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   510
        disconnect(mAbstractDelegate);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   511
        delete mAbstractDelegate;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   512
        mAbstractDelegate = 0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   513
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   514
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   515
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   516
void BtCpUiDeviceView::connectDevice()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   517
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   518
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   519
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   520
    if (!mAbstractDelegate)//if there is no other delegate running
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   521
    { 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   522
        QVariant params;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   523
        params.setValue(mDeviceIndex);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   524
        mAbstractDelegate = BtDelegateFactory::newDelegate(
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   525
                BtDelegate::Connect, mSettingModel, mDeviceModel); 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   526
        connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(connectDelegateCompleted(int)) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   527
        mAbstractDelegate->exec(params);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   528
    }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   529
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   530
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   531
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   532
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   533
void BtCpUiDeviceView::connectDelegateCompleted(int status)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   534
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   535
    Q_UNUSED(status);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   536
    if (mAbstractDelegate)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   537
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   538
        disconnect(mAbstractDelegate);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   539
        delete mAbstractDelegate;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   540
        mAbstractDelegate = 0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   541
    }   
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   542
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   543
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   544
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   545
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   546
void BtCpUiDeviceView::disconnectDevice()
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   547
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   548
    if (!mAbstractDelegate)//if there is no other delegate running
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   549
        { 
42
hgs
parents: 31
diff changeset
   550
           
hgs
parents: 31
diff changeset
   551
            
hgs
parents: 31
diff changeset
   552
            DisconnectOption discoOpt = ServiceLevel;
hgs
parents: 31
diff changeset
   553
                    
hgs
parents: 31
diff changeset
   554
            QList<QVariant>list;
hgs
parents: 31
diff changeset
   555
            QVariant paramFirst;
hgs
parents: 31
diff changeset
   556
            paramFirst.setValue(mDeviceIndex);
hgs
parents: 31
diff changeset
   557
            
hgs
parents: 31
diff changeset
   558
            QVariant paramSecond;
hgs
parents: 31
diff changeset
   559
            paramSecond.setValue((int)discoOpt);
hgs
parents: 31
diff changeset
   560
                    
hgs
parents: 31
diff changeset
   561
            list.append(paramFirst);
hgs
parents: 31
diff changeset
   562
            list.append(paramSecond);
hgs
parents: 31
diff changeset
   563
                    
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   564
            QVariant params;
42
hgs
parents: 31
diff changeset
   565
            params.setValue(list);
hgs
parents: 31
diff changeset
   566
            
hgs
parents: 31
diff changeset
   567
            
hgs
parents: 31
diff changeset
   568
            //params.setValue(mDeviceIndex);
31
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   569
            mAbstractDelegate = BtDelegateFactory::newDelegate(
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   570
                    BtDelegate::Disconnect, mSettingModel, mDeviceModel); 
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   571
            connect( mAbstractDelegate, SIGNAL(commandCompleted(int)), this, SLOT(disconnectDelegateCompleted(int)) );
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   572
            mAbstractDelegate->exec(params);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   573
        }
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   574
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   575
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   576
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   577
void BtCpUiDeviceView::disconnectDelegateCompleted(int status)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   578
{
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   579
    Q_UNUSED(status);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   580
    if (mAbstractDelegate)
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   581
    {
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   582
        disconnect(mAbstractDelegate);
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   583
        delete mAbstractDelegate;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   584
        mAbstractDelegate = 0;
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   585
    }   
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   586
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   587
    
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   588
}
a0ea99b6fa53 201019_1
hgs
parents:
diff changeset
   589
42
hgs
parents: 31
diff changeset
   590
void BtCpUiDeviceView::changeBtDeviceName(){
hgs
parents: 31
diff changeset
   591
    if (!mAbstractDelegate)//if there is no other delegate running
hgs
parents: 31
diff changeset
   592
    { 
hgs
parents: 31
diff changeset
   593
        QList<QVariant>list;
hgs
parents: 31
diff changeset
   594
        
hgs
parents: 31
diff changeset
   595
        QVariant index;
hgs
parents: 31
diff changeset
   596
        index.setValue(mDeviceIndex);
hgs
parents: 31
diff changeset
   597
        
hgs
parents: 31
diff changeset
   598
        QVariant name;
hgs
parents: 31
diff changeset
   599
        name.setValue(mDeviceName->text());
hgs
parents: 31
diff changeset
   600
        
hgs
parents: 31
diff changeset
   601
        list.append(index);
hgs
parents: 31
diff changeset
   602
        list.append(name);
hgs
parents: 31
diff changeset
   603
        
hgs
parents: 31
diff changeset
   604
        QVariant params;
hgs
parents: 31
diff changeset
   605
        params.setValue(list);
hgs
parents: 31
diff changeset
   606
        
hgs
parents: 31
diff changeset
   607
        mAbstractDelegate = BtDelegateFactory::newDelegate(
hgs
parents: 31
diff changeset
   608
                BtDelegate::RemoteDevName, mSettingModel, mDeviceModel); 
hgs
parents: 31
diff changeset
   609
        connect( mAbstractDelegate, SIGNAL(commandCompleted(int, QVariant)), this, SLOT(changeDevNameDelegateCompleted(int, QVariant)) );
hgs
parents: 31
diff changeset
   610
        mAbstractDelegate->exec(params);
hgs
parents: 31
diff changeset
   611
    }
hgs
parents: 31
diff changeset
   612
    
hgs
parents: 31
diff changeset
   613
}
hgs
parents: 31
diff changeset
   614
hgs
parents: 31
diff changeset
   615
void BtCpUiDeviceView::changeDevNameDelegateCompleted(int status, QVariant param)
hgs
parents: 31
diff changeset
   616
{
hgs
parents: 31
diff changeset
   617
    
hgs
parents: 31
diff changeset
   618
    
hgs
parents: 31
diff changeset
   619
    if(KErrNone == status) {
hgs
parents: 31
diff changeset
   620
        mDeviceName->setText(param.toString());
hgs
parents: 31
diff changeset
   621
    }
hgs
parents: 31
diff changeset
   622
    else {
hgs
parents: 31
diff changeset
   623
        //setPrevBtLocalName();
hgs
parents: 31
diff changeset
   624
    }
hgs
parents: 31
diff changeset
   625
    //TODO:Error handling has to be done.    
hgs
parents: 31
diff changeset
   626
    if (mAbstractDelegate)
hgs
parents: 31
diff changeset
   627
    {
hgs
parents: 31
diff changeset
   628
        disconnect(mAbstractDelegate);
hgs
parents: 31
diff changeset
   629
        delete mAbstractDelegate;
hgs
parents: 31
diff changeset
   630
        mAbstractDelegate = 0;
hgs
parents: 31
diff changeset
   631
    }
hgs
parents: 31
diff changeset
   632
    
hgs
parents: 31
diff changeset
   633
    
hgs
parents: 31
diff changeset
   634
}