bluetoothengine/btui/btuimodel/btdevicedata.cpp
author hgs
Mon, 17 May 2010 11:06:23 +0300
changeset 31 a0ea99b6fa53
parent 29 48ae3789ce00
child 40 997690c3397a
permissions -rw-r--r--
201019_1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     1
/*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     3
* All rights reserved.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     8
*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
     9
* Initial Contributors:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    11
*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    12
* Contributors:
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    13
*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    14
* Description: 
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    15
*
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    16
*/
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    17
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    18
#include "btdevicedata.h"
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    19
#include <QDateTime>
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    20
#include <btservices/advancedevdiscoverer.h>
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    21
#include "btuiutil.h"
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    22
#include "btqtconstants.h"
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    23
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    24
class DevTypeIconMapping {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    25
public:    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    26
    int majorDevClass; // major device class value from CoD
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    27
    int minorDevClass; // minor device class value from CoD
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    28
    int majorProperty;   // one of major properties defined in BtDeviceModel
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    29
    int minorProperty;   // one of minor properties defined in BtDeviceModel
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    30
    char* connectedIcon; // the icon name for connected device
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    31
    char* unconnectedIcon; // the icon name for not connected device.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    32
};
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    33
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    34
// mapping table from major and minor Device Classes to device types and icons
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    35
// which are specifically defined in btapplication namespace.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    36
// (Note audio device mapping is not in this table due to its complex logic)
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    37
static const DevTypeIconMapping DeviceTypeIconMappingTable[] =
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    38
{
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    39
{EMajorDeviceComputer, 0, BtDeviceModel::Computer, 0, 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    40
        ":/icons/qgn_prop_bt_computer_connect.svg", ":/icons/qgn_prop_bt_computer.svg" },
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    41
{EMajorDevicePhone,    0, BtDeviceModel::Phone,    0, 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    42
        ":/icons/qgn_prop_bt_phone_connect.svg", ":/icons/qgn_prop_bt_phone.svg"},
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    43
{EMajorDeviceLanAccessPoint, 0, BtDeviceModel::LANAccessDev, 0, 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    44
        ":/icons/qgn_prop_bt_misc.svg", ":/icons/qgn_prop_bt_misc.svg" },
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    45
{EMajorDevicePeripheral, EMinorDevicePeripheralKeyboard, 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    46
        BtDeviceModel::Peripheral, BtDeviceModel::Keyboard,
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    47
        ":/icons/qgn_prop_bt_keyboard_connect.svg", ":/icons/qgn_prop_bt_keyboard.svg"},
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    48
{EMajorDevicePeripheral, EMinorDevicePeripheralPointer, 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    49
        BtDeviceModel::Peripheral, BtDeviceModel::Mouse,
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    50
        ":/icons/qgn_prop_bt_mouse_connect.svg", ":/icons/qgn_prop_bt_mouse.svg"},
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    51
{EMajorDeviceImaging, 0, BtDeviceModel::ImagingDev, 0, 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    52
        ":/icons/qgn_prop_bt_printer_connect.svg", ":/icons/qgn_prop_bt_printer.svg"},
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    53
{EMajorDeviceWearable, 0, BtDeviceModel::WearableDev, 0, 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    54
        ":/icons/qgn_prop_bt_misc.svg", ":/icons/qgn_prop_bt_misc.svg"},
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    55
{EMajorDeviceToy, 0, BtDeviceModel::Toy, 0,
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    56
        ":/icons/qgn_prop_bt_misc.svg", ":/icons/qgn_prop_bt_misc.svg"},
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    57
};
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    58
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    59
static const int DeviceTypeIconMappingTableSize = 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    60
        sizeof( DeviceTypeIconMappingTable ) / sizeof( DevTypeIconMapping );
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    61
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    62
/*!
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    63
    Constructor.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    64
 */
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    65
BtDeviceData::BtDeviceData( BtDeviceModel& model, QObject *parent )
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    66
    : QObject( parent ), mModel( model ), mDiscover( 0 )
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    67
{
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    68
    mDeviceRepo = 0;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    69
    isSearchingDevice = false;
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    70
    TRAP_IGNORE({
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    71
        mDeviceRepo = CBtDevRepository::NewL();
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    72
    });
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    73
    Q_CHECK_PTR( mDeviceRepo );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    74
    TRAP_IGNORE( mDeviceRepo->AddObserverL( this ) );
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    75
    
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    76
    if ( mDeviceRepo->IsInitialized() ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    77
        initializeDataStore();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    78
    }
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    79
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    80
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    81
/*!
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    82
    Destructor.
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    83
 */
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    84
BtDeviceData::~BtDeviceData()
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    85
{
48ae3789ce00 201017_2
hgs
parents:
diff changeset
    86
    delete mDeviceRepo;
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    87
    delete mDiscover;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    88
}
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    89
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    90
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    91
/*!
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    92
    Tells whether the given column is in the range of the setting list.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    93
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    94
    \param row the row number to be checked
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    95
    \param col the column number to be checked
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    96
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    97
    \return true if the given row and column are valid; false otherwise.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    98
*/
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
    99
bool BtDeviceData::isValid( int row, int column) const
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   100
{
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   101
    return row >= 0 && row < mData.count() && column == 0;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   102
}
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   103
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   104
/*!
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   105
    \return the total amount of rows.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   106
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   107
*/
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   108
int BtDeviceData::rowCount() const
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   109
{
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   110
    return mData.count();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   111
}
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   112
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   113
/*!
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   114
    \return the total amount of columns.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   115
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   116
*/
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   117
int BtDeviceData::columnCount() const
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   118
{
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   119
    return 1;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   120
}
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   121
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   122
/*!
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   123
    Gets the value within a data item.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   124
    \param val contains the value at return.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   125
    \param row the row number which the value is from
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   126
    \param col the column number which the value is from
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   127
    \param role the role idenfier of the value.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   128
 */
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   129
void BtDeviceData::data(QVariant& val, int row,  int col, int role ) const
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   130
{
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   131
    if ( isValid( row, col ) ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   132
        val = mData.at( row ).value( role );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   133
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   134
    else {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   135
        val = QVariant( QVariant::Invalid );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   136
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   137
}
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   138
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   139
/*!
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   140
    Gets the whole item data at the specified column
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   141
    \param row the row number of the item data to be returned
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   142
    \param col the column number of the item data to be returned
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   143
    \return the item data
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   144
 */
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   145
BtuiModelDataItem BtDeviceData::itemData( int row, int col ) const
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   146
{
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   147
    if ( isValid( row, col ) ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   148
        return mData.at( row );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   149
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   150
    return BtuiModelDataItem();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   151
}
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   152
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   153
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   154
/*!
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   155
    Requests the model to searching Bluetooth devices.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   156
    \return true if the request is accepted; false otherwise
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   157
 */
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   158
bool BtDeviceData::searchDevice()
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   159
{
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   160
    int err ( 0 );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   161
    removeTransientDevices();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   162
    if ( !mDiscover ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   163
        TRAP(err, mDiscover = CAdvanceDevDiscoverer::NewL( *mDeviceRepo, *this) );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   164
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   165
    if ( !err ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   166
        TRAP(err, mDiscover->DiscoverDeviceL() );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   167
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   168
    isSearchingDevice = true;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   169
    return err == 0;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   170
}
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   171
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   172
/*!
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   173
    Cancels a possible outstanding device search request.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   174
 */
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   175
void BtDeviceData::cancelSearchDevice()
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   176
{
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   177
    if ( mDiscover ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   178
        isSearchingDevice = false;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   179
        mDiscover->CancelDiscovery();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   180
    }
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   181
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   182
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   183
/*!
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   184
    Removes transient (not-in-registry) devices 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   185
    (added as the result of device search).
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   186
 */
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   187
void BtDeviceData::removeTransientDevices()
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   188
{
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   189
    // clear in-range property for all device items in this model.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   190
    int cnt = mData.count();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   191
    for ( int i = mData.count() - 1; i > -1; --i)
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   192
        {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   193
        const BtuiModelDataItem& qtdev = mData.at(i);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   194
        if(isDeviceInRange(qtdev)) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   195
            if(isDeviceInRegistry(qtdev)) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   196
                // we cannot remove this device as it is in registry.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   197
                // remove it in-range property.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   198
                setMajorProperty(mData[i], BtDeviceModel::InRange, false);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   199
                updateRssi(mData[i], RssiInvalid);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   200
                mModel.emitDataChanged( i, 0, this );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   201
            }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   202
            else {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   203
                // this device is not in-registry. Delete it from local
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   204
                // store.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   205
                mModel.beginRemoveRows(QModelIndex(), i, i);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   206
                mData.removeAt( i );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   207
                mModel.endRemoveRows();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   208
            }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   209
        }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   210
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   211
}
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   212
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   213
/*!
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   214
    callback from repository.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   215
    re-initialize our store.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   216
 */
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   217
void BtDeviceData::RepositoryInitialized() 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   218
{
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   219
    initializeDataStore();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   220
}
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   221
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   222
/*!
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   223
    callback from repository.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   224
    update our store.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   225
 */
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   226
void BtDeviceData::DeletedFromRegistry( const TBTDevAddr& addr ) 
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   227
{
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   228
    int i = indexOf( addr );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   229
    if ( i > -1 ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   230
        if ( isSearchingDevice && isDeviceInRange( mData.at(i) ) ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   231
            // device searching is ongoing, and it is in-range. we can not 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   232
            // remore it from model now.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   233
            // clear-registry related properties, so that
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   234
            // we get a chance to clean it after device searching later.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   235
            setMajorProperty(mData[i], BtDeviceModel::RegistryProperties, false);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   236
            mModel.emitDataChanged( i, 0, this );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   237
        }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   238
        else {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   239
            mModel.beginRemoveRows(QModelIndex(), i, i);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   240
            mData.removeAt( i );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   241
            mModel.endRemoveRows();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   242
        }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   243
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   244
}
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   245
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   246
/*!
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   247
    callback from repository.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   248
    update our store.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   249
 */
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   250
void BtDeviceData::AddedToRegistry( const CBtDevExtension& dev ) 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   251
{
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   252
    ChangedInRegistry( dev, 0 );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   253
}
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   254
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   255
/*!
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   256
    callback from repository.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   257
    update our store.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   258
 */
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   259
void BtDeviceData::ChangedInRegistry( 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   260
        const CBtDevExtension& dev, TUint similarity )
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   261
{
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   262
    int i = indexOf( dev.Addr() );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   263
    if ( i == -1 ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   264
        BtuiModelDataItem devData;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   265
        if ( !isSearchingDevice ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   266
            // Rssi is only available at device inquiry stage. 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   267
            // We initialize this property to an invalid value
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   268
            updateRssi(devData, RssiInvalid);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   269
        }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   270
        // add device-in-registry property:
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   271
        setMajorProperty(devData, BtDeviceModel::InRegistry, true);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   272
        updateDeviceProperty(devData, dev, 0 );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   273
        mModel.beginInsertRows( QModelIndex(), mData.count(), mData.count() );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   274
        mData.append( devData );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   275
        mModel.endInsertRows();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   276
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   277
    else {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   278
        updateDeviceProperty(mData[i], dev, similarity );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   279
        setMajorProperty(mData[i], BtDeviceModel::InRegistry, true);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   280
        mModel.emitDataChanged( i, 0, this );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   281
    }
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   282
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   283
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   284
/*!
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   285
    callback from repository.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   286
    update our store.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   287
 */
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   288
void BtDeviceData::ServiceConnectionChanged(
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   289
        const CBtDevExtension& dev, TBool connected )
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   290
{
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   291
    int i = indexOf( dev.Addr() );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   292
    if ( i > -1 ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   293
        int preconn =  BtDeviceModel::Connected 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   294
                & mData[i][BtDeviceModel::MajorPropertyRole].toInt();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   295
        // we only update and signal if connection status is really
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   296
        // changed:
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   297
        if ( ( preconn != 0 && !connected )
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   298
            || ( preconn == 0 && connected ) ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   299
            setMajorProperty(mData[i], BtDeviceModel::Connected, connected );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   300
            mModel.emitDataChanged( i, 0, this );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   301
        }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   302
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   303
    // it is impossible that a device has connected but it is not in
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   304
    // our local store according to current bteng services.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   305
    // need to take more care in future when this becomes possible.
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   306
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   307
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   308
/*!
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   309
    callback from device search.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   310
    update our store.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   311
 */
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   312
void BtDeviceData::HandleNextDiscoveryResultL( 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   313
        const TInquirySockAddr& inqAddr, const TDesC& name )
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   314
{
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   315
    int pos = indexOf( inqAddr.BTAddr() );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   316
    const CBtDevExtension* dev = mDeviceRepo->Device( inqAddr.BTAddr() );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   317
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   318
    //RssiRole
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   319
    int rssi( RssiInvalid ); // initialize to an invalid value.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   320
    if( inqAddr.ResultFlags() & TInquirySockAddr::ERssiValid ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   321
        rssi = inqAddr.Rssi();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   322
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   323
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   324
    if ( pos == -1 ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   325
        BtuiModelDataItem devData;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   326
        setMajorProperty(devData, BtDeviceModel::InRange, true);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   327
        updateRssi(devData, rssi);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   328
        CBtDevExtension* devExt(NULL);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   329
        TRAP_IGNORE( {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   330
            devExt = CBtDevExtension::NewLC( inqAddr, name );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   331
            CleanupStack::Pop(); });
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   332
        updateDeviceProperty(devData, *devExt, 0);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   333
        delete devExt;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   334
        mModel.beginInsertRows( QModelIndex(), mData.count(), mData.count() );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   335
        mData.append( devData );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   336
        mModel.endInsertRows();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   337
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   338
    else {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   339
        setMajorProperty(mData[pos], BtDeviceModel::InRange, true);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   340
        updateRssi(mData[pos], rssi);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   341
        mModel.emitDataChanged( pos, 0, this );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   342
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   343
}
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   344
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   345
/*!
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   346
    callback from device search.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   347
    inform client.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   348
 */
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   349
void BtDeviceData::HandleDiscoveryCompleted( TInt error )
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   350
{
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   351
    isSearchingDevice = false;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   352
    mModel.emitdeviceSearchCompleted( (int) error );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   353
}
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   354
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   355
void BtDeviceData::initializeDataStore()
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   356
    {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   357
    // it is possible that we are searching devices.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   358
    // We use a simple but not-so-efficient method to update the model.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   359
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   360
    // If the device store is not empty, we clear
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   361
    // registry property from these devices first.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   362
    for (int i = 0; i < mData.count(); ++i) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   363
        setMajorProperty(mData[i], BtDeviceModel::RegistryProperties, false);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   364
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   365
    if ( mData.count() ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   366
        // need to update view because we have changed device properties.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   367
        QModelIndex top = mModel.createIndex(0, 0, this);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   368
        QModelIndex bottom = mModel.createIndex(mData.count() - 1, 0, this);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   369
        mModel.emitDataChanged( top, bottom );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   370
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   371
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   372
    const RDevExtensionArray& devs = mDeviceRepo->AllDevices();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   373
    for (int i = 0; i < devs.Count(); ++i) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   374
        int pos = indexOf( devs[i]->Addr() );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   375
        if ( pos > -1 ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   376
            // add device-in-registry property:
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   377
            setMajorProperty(mData[pos], BtDeviceModel::InRegistry, true);            
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   378
            updateDeviceProperty(mData[pos], *(devs[i]), 0);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   379
            mModel.emitDataChanged( pos, 0, this );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   380
        }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   381
        else {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   382
            BtuiModelDataItem devData;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   383
            // add device-in-registry property:
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   384
            setMajorProperty(devData, BtDeviceModel::InRegistry, true);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   385
            updateDeviceProperty(devData, *( devs[i] ), 0 );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   386
            mModel.beginInsertRows(QModelIndex(), mData.count(), mData.count() );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   387
            mData.append( devData );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   388
            mModel.endInsertRows();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   389
        }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   390
    }
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   391
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   392
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   393
void BtDeviceData::updateDeviceProperty(BtuiModelDataItem& qtdev,
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   394
        const CBtDevExtension& dev, TUint similarity )
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   395
{
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   396
    // similarity is not used currently. 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   397
    // It is possible to gain better performance
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   398
    // with this info to avoid re-manipulate
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   399
    // unchanged properties.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   400
    Q_UNUSED(similarity);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   401
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   402
    //DevDisplayNameRole
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   403
    QString str = QString::fromUtf16( 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   404
            dev.Alias().Ptr(), dev.Alias().Length() );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   405
    qtdev[BtDeviceModel::NameAliasRole] = QVariant( str );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   406
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   407
    //DevAddrReadableRole
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   408
    addrSymbianToReadbleString( str, dev.Addr() );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   409
    qtdev[BtDeviceModel::ReadableBdaddrRole] = QVariant( str );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   410
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   411
    //LastUsedTimeRole
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   412
    TDateTime symDt = dev.Device().Used().DateTime();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   413
    QDate date( symDt.Year(), symDt.Month(), symDt.Day() );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   414
    QTime time( symDt.Hour(), symDt.Minute(), symDt.MicroSecond() / 1000 );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   415
    QDateTime qdt(date, time);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   416
    qtdev[BtDeviceModel::LastUsedTimeRole] = QVariant(qdt);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   417
 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   418
    // set paired status:
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   419
    setMajorProperty(qtdev, BtDeviceModel::Bonded, isBonded( dev.Device() ));
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   420
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   421
    // set blocked status:
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   422
    setMajorProperty(qtdev, BtDeviceModel::Blocked, 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   423
            dev.Device().GlobalSecurity().Banned() );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   424
    // set trusted status:
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   425
    setMajorProperty(qtdev, BtDeviceModel::Trusted, 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   426
            dev.Device().GlobalSecurity().NoAuthorise() );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   427
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   428
    //CoDRole
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   429
    //MinorPropertyRole
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   430
    int cod = static_cast<int>( dev.Device().DeviceClass().DeviceClass() );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   431
    qtdev[BtDeviceModel::CoDRole] = QVariant(cod);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   432
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   433
    // Initially, clear CoD related properties:
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   434
    int majorProperty = qtdev[BtDeviceModel::MajorPropertyRole].toInt() & 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   435
        ~BtDeviceModel::CodProperties;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   436
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   437
    int minorProperty = BtDeviceModel::NullProperty;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   438
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   439
    // device type must be mapped according to CoD:
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   440
    int majorDevCls = dev.Device().DeviceClass().MajorDeviceClass();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   441
    int minorDevCls = dev.Device().DeviceClass().MinorDeviceClass();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   442
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   443
    int i;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   444
    for (i = 0; i < DeviceTypeIconMappingTableSize; ++i ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   445
        if ( DeviceTypeIconMappingTable[i].majorDevClass == majorDevCls &&
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   446
             ( DeviceTypeIconMappingTable[i].minorDevClass == 0 || 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   447
               DeviceTypeIconMappingTable[i].minorDevClass == minorDevCls ) ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   448
             // device classes match a item in table, get the mapping:
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   449
            majorProperty |= DeviceTypeIconMappingTable[i].majorProperty;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   450
            minorProperty |= DeviceTypeIconMappingTable[i].minorProperty;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   451
            break;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   452
         }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   453
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   454
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   455
    // AV device mapping are not defined in the table, do mapping here if no device
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   456
    // type mapped so far:
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   457
    if ( i == DeviceTypeIconMappingTableSize) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   458
        // audio device, carkit, headset or speaker:
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   459
        if( ( majorDevCls == EMajorDeviceAV) 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   460
            || (dev.Device().DeviceClass().MajorServiceClass() == EMajorServiceRendering 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   461
            && majorDevCls != EMajorDeviceImaging) ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   462
            
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   463
            majorProperty |= BtDeviceModel::AVDev;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   464
            
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   465
            if( minorDevCls == EMinorDeviceAVCarAudio ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   466
                // carkit:
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   467
                minorProperty |= BtDeviceModel::Carkit; 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   468
            }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   469
            else {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   470
                // headset:
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   471
                minorProperty |= BtDeviceModel::Headset;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   472
            }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   473
        }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   474
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   475
    
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   476
    qtdev[BtDeviceModel::MajorPropertyRole] = QVariant( majorProperty );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   477
    qtdev[BtDeviceModel::MinorPropertyRole] = QVariant( minorProperty );
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   478
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   479
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   480
int BtDeviceData::indexOf( const TBTDevAddr& addr ) const
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   481
{
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   482
    QString addrStr;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   483
    addrSymbianToReadbleString( addrStr, addr );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   484
    for (int i = 0; i < mData.count(); ++i ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   485
        if ( mData.at( i ).value( BtDeviceModel::ReadableBdaddrRole ) 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   486
                == addrStr ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   487
            return i;
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   488
        }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   489
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   490
    return -1;
29
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   491
}
48ae3789ce00 201017_2
hgs
parents:
diff changeset
   492
31
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   493
void BtDeviceData::updateRssi(BtuiModelDataItem& qtdev, int rssi )
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   494
    {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   495
    qtdev[BtDeviceModel::RssiRole] = QVariant( rssi );
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   496
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   497
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   498
/*!
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   499
    Add the specified major property to the device if addto is true.
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   500
    Otherwise the property is removed from the device. 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   501
 */
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   502
void BtDeviceData::setMajorProperty(
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   503
        BtuiModelDataItem& qtdev, int prop, bool addto)
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   504
{
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   505
    if ( addto ) {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   506
        qtdev[BtDeviceModel::MajorPropertyRole] = 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   507
            QVariant( qtdev[BtDeviceModel::MajorPropertyRole].toInt() | prop);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   508
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   509
    else {
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   510
        qtdev[BtDeviceModel::MajorPropertyRole] = 
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   511
            QVariant( qtdev[BtDeviceModel::MajorPropertyRole].toInt() & ~prop);
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   512
    }
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   513
}
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   514
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   515
bool BtDeviceData::isDeviceInRange( const BtuiModelDataItem& qtdev )
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   516
{   
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   517
    return BtDeviceModel::InRange & qtdev[BtDeviceModel::MajorPropertyRole].toInt();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   518
}
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   519
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   520
bool BtDeviceData::isDeviceInRegistry( const BtuiModelDataItem& qtdev )
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   521
{
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   522
    return BtDeviceModel::InRegistry & qtdev[BtDeviceModel::MajorPropertyRole].toInt();
a0ea99b6fa53 201019_1
hgs
parents: 29
diff changeset
   523
}