• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MerginMaps / input / 5983636709

26 Aug 2023 07:50AM UTC coverage: 62.064% (+1.1%) from 60.955%
5983636709

push

github

web-flow
Lcov to lnx (#2772)

move lcov to linux tests

7552 of 12168 relevant lines covered (62.06%)

102.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/app/bluetoothdiscoverymodel.cpp
1
/***************************************************************************
2
 *                                                                         *
3
 *   This program is free software; you can redistribute it and/or modify  *
4
 *   it under the terms of the GNU General Public License as published by  *
5
 *   the Free Software Foundation; either version 2 of the License, or     *
6
 *   (at your option) any later version.                                   *
7
 *                                                                         *
8
 ***************************************************************************/
9

10
#include "bluetoothdiscoverymodel.h"
11
#include "coreutils.h"
12

13
#ifdef HAVE_BLUETOOTH
14
#include <QBluetoothUuid>
15
#endif
16

17

18
BluetoothDiscoveryModel::BluetoothDiscoveryModel( QObject *parent ) : QAbstractListModel( parent )
×
19
{
20
#ifdef HAVE_BLUETOOTH
21
  mDiscoveryAgent = std::unique_ptr<QBluetoothDeviceDiscoveryAgent>( new QBluetoothDeviceDiscoveryAgent() );
×
22

23
  connect( mDiscoveryAgent.get(), &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this, &BluetoothDiscoveryModel::deviceDiscovered );
×
24
  connect( mDiscoveryAgent.get(), &QBluetoothDeviceDiscoveryAgent::deviceUpdated, this, &BluetoothDiscoveryModel::deviceUpdated );
×
25
  connect( mDiscoveryAgent.get(), &QBluetoothDeviceDiscoveryAgent::canceled, this, &BluetoothDiscoveryModel::finishedDiscovery );
×
26
  connect( mDiscoveryAgent.get(), &QBluetoothDeviceDiscoveryAgent::finished, this, &BluetoothDiscoveryModel::finishedDiscovery );
×
27

28
  connect( mDiscoveryAgent.get(), &QBluetoothDeviceDiscoveryAgent::errorOccurred, this, [ = ]( QBluetoothDeviceDiscoveryAgent::Error error )
×
29
  {
30
    CoreUtils::log( "Bluetooth discovery", QString( "Error occured during device discovery, error code #%1" ).arg( error ) );
×
31
    finishedDiscovery();
×
32
  } );
×
33
#endif
34
}
×
35

36
BluetoothDiscoveryModel::~BluetoothDiscoveryModel() = default;
×
37

38
QHash<int, QByteArray> BluetoothDiscoveryModel::roleNames() const
×
39
{
40
  QHash<int, QByteArray> roles;
×
41

42
#ifdef HAVE_BLUETOOTH
43
  roles.insert( DataRoles::DeviceAddress, "DeviceAddress" );
×
44
  roles.insert( DataRoles::DeviceName, "DeviceName" );
×
45
  roles.insert( DataRoles::SignalStrength, "SignalStrength" );
×
46
#endif
47

48
  return roles;
×
49
}
×
50

51
int BluetoothDiscoveryModel::rowCount( const QModelIndex & ) const
×
52
{
53
#ifdef HAVE_BLUETOOTH
54
  return mFoundDevices.count();
×
55
#else
56
  return 0;
57
#endif
58
}
59

60
QVariant BluetoothDiscoveryModel::data( const QModelIndex &index, int role ) const
×
61
{
62
#ifdef HAVE_BLUETOOTH
63
  if ( !index.isValid() )
×
64
    return QVariant();
×
65

66
  int deviceIndex = index.row();
×
67

68
  if ( deviceIndex < 0 || deviceIndex >= mFoundDevices.count() )
×
69
    return QVariant();
×
70

71
  QBluetoothDeviceInfo device = mFoundDevices[deviceIndex];
×
72

73
  switch ( role )
×
74
  {
75
    case DataRoles::DeviceAddress:
×
76
    {
77
      return device.address().toString();
×
78
    }
79

80
    case DataRoles::DeviceName:
×
81
    {
82
      return device.name();
×
83
    }
84

85
    case DataRoles::SignalStrength:
×
86
    {
87
      return device.rssi();
×
88
    }
89

90
    default: return QVariant();
×
91
  }
92
#else
93
  return QVariant();
94
#endif
95
}
×
96

97
bool BluetoothDiscoveryModel::discovering() const
×
98
{
99
  return mDiscovering;
×
100
}
101

102
void BluetoothDiscoveryModel::setDiscovering( bool discovering )
×
103
{
104
  if ( mDiscovering == discovering )
×
105
    return;
×
106

107
#ifdef HAVE_BLUETOOTH
108
  if ( discovering )
×
109
  {
110
    mDiscoveryAgent->start();
×
111
    CoreUtils::log( QStringLiteral( "Bluetooth discovery" ), QStringLiteral( "Started discovering devices, method %1" ).arg( mDiscoveryAgent->supportedDiscoveryMethods() ) );
×
112
  }
113
  else
114
  {
115
    mDiscoveryAgent->stop();
×
116
  }
117
#endif
118

119
  mDiscovering = discovering;
×
120
  emit discoveringChanged( mDiscovering );
×
121
}
122

123
#ifdef HAVE_BLUETOOTH
124
void BluetoothDiscoveryModel::deviceDiscovered( const QBluetoothDeviceInfo &device )
×
125
{
126
  for ( int i = 0; i < mFoundDevices.count(); i++ )
×
127
  {
128
    if ( mFoundDevices[i].address() == device.address() )
×
129
    {
130
      return; // duplicated device
×
131
    }
132
  }
133

134
  // ignore devices with invalid address (apple devices)
135
  if ( device.address().isNull() )
×
136
    return;
×
137

138
  int insertIndex = mFoundDevices.count();
×
139
  beginInsertRows( QModelIndex(), insertIndex, insertIndex );
×
140

141
  mFoundDevices << device;
×
142

143
  endInsertRows();
×
144
}
145

146
void BluetoothDiscoveryModel::deviceUpdated( const QBluetoothDeviceInfo &device, QBluetoothDeviceInfo::Fields )
×
147
{
148
  // ignore devices with invalid address (apple devices)
149
  if ( device.address().isNull() )
×
150
    return;
×
151

152
  for ( int i = 0; i < mFoundDevices.count(); i++ )
×
153
  {
154
    if ( mFoundDevices[i].address() == device.address() )
×
155
    {
156
      mFoundDevices[i] = device;
×
157
      emit dataChanged( index( i ), index( i ) );
×
158
      break;
×
159
    }
160
  }
161
}
162
#endif
163

164
void BluetoothDiscoveryModel::finishedDiscovery()
×
165
{
166
  setDiscovering( false );
×
167
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc