Merge lp:~cyphermox/ubuntu-system-settings/discoverability-annd-fixes into lp:ubuntu-system-settings

Proposed by Mathieu Trudel-Lapierre
Status: Merged
Approved by: Charles Kerr
Approved revision: 750
Merged at revision: 744
Proposed branch: lp:~cyphermox/ubuntu-system-settings/discoverability-annd-fixes
Merge into: lp:ubuntu-system-settings
Diff against target: 452 lines (+201/-6)
7 files modified
plugins/bluetooth/PageComponent.qml (+45/-1)
plugins/bluetooth/bluetooth.cpp (+20/-2)
plugins/bluetooth/bluetooth.h (+10/-0)
plugins/bluetooth/device.cpp (+25/-0)
plugins/bluetooth/device.h (+9/-0)
plugins/bluetooth/devicemodel.cpp (+74/-0)
plugins/bluetooth/devicemodel.h (+18/-3)
To merge this branch: bzr merge lp:~cyphermox/ubuntu-system-settings/discoverability-annd-fixes
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+223955@code.launchpad.net

Commit message

Implement discoverability and some bluetooth fixes:
  - Discoverability: make the system visible to other bluetooth devices
  - Trusted: when successfully paired and connected, mark device as Trusted so it can automatically connect again.
  - Connect the Audio interface for all audio devices, including Headsets. Some bluetooth audio devices that don't contain a microphone still show up as Headsets, and won't connect successfully otherwise. This will still work for standard headsets, since Audio connects all audio interfaces.
  - Stop discovery when a device is selected for connection, and it sometimes causes connection attempts to fail.

Description of the change

Implement discoverability and some bluetooth fixes:
  - Discoverability: make the system visible to other bluetooth devices
  - Trusted: when successfully paired and connected, mark device as Trusted so it can automatically connect again.
  - Connect the Audio interface for all audio devices, including Headsets. Some bluetooth audio devices that don't contain a microphone still show up as Headsets, and won't connect successfully otherwise. This will still work for standard headsets, since Audio connects all audio interfaces.
  - Stop discovery when a device is selected for connection, and it sometimes causes connection attempts to fail.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:747
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~mathieu-tl/ubuntu-system-settings/discoverability-annd-fixes/+merge/223955/+edit-commit-message

http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-ci/883/
Executed test runs:
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/1073
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/963
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-amd64-ci/75
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-armhf-ci/75
        deb: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-armhf-ci/75/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-i386-ci/75
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/1443
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/1877
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/1877/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/8682
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/831
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/1106
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/1106/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/ubuntu-system-settings-ci/883/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

There are a couple of things I'd like to see fixed here, but they're small.

Overall, looks very good! Nice work.

review: Needs Fixing
Revision history for this message
Charles Kerr (charlesk) wrote :

There are a couple of things I'd like to see fixed here, but they're small.

Overall, looks very good! Nice work.

review: Needs Fixing
748. By Mathieu Trudel-Lapierre

Remove qWarning's used as debug.

749. By Mathieu Trudel-Lapierre

Keep the discoverability timer as a private member, so it can be explicitly stopped.

750. By Mathieu Trudel-Lapierre

Follow proper convention for returning adapterName; make it const too.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:750
http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-ci/884/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-utopic-touch/1081
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-utopic/969
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-amd64-ci/76
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-armhf-ci/76
        deb: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-armhf-ci/76/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/ubuntu-system-settings-utopic-i386-ci/76
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/1451
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/1891
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-armhf/1891/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/8694
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-utopic/835
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/1112
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-utopic-amd64/1112/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/ubuntu-system-settings-ci/884/rebuild

review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/bluetooth/PageComponent.qml'
--- plugins/bluetooth/PageComponent.qml 2014-06-09 15:12:34 +0000
+++ plugins/bluetooth/PageComponent.qml 2014-06-20 22:19:44 +0000
@@ -142,8 +142,51 @@
142 value: bluetoothActionGroup.enabled.state142 value: bluetoothActionGroup.enabled.state
143 }143 }
144144
145 // Discoverability
146 ListItem.Subtitled {
147 enabled: bluetoothActionGroup.enabled
148
149 Rectangle {
150 color: "transparent"
151 anchors.fill: parent
152 anchors.topMargin: units.gu(1)
153
154 Label {
155 anchors {
156 top: parent.top
157 left: parent.left
158 topMargin: units.gu(1)
159 }
160 height: units.gu(3)
161 text: backend.discoverable ? i18n.tr("Discoverable") : i18n.tr("Not discoverable")
162 }
163
164 Label {
165 anchors {
166 top: parent.top
167 right: parent.right
168 topMargin: units.gu(1)
169 }
170 height: units.gu(3)
171 text: backend.discoverable ? backend.adapterName() : ""
172 color: "darkgrey"
173 visible: backend.discoverable
174 enabled: false
175 }
176
177 ActivityIndicator {
178 anchors {
179 top: parent.top
180 right: parent.right
181 topMargin: units.gu(1)
182 }
183 visible: !backend.discoverable
184 running: !backend.discoverable
185 }
186 }
187 }
188
145 // Connnected Headset(s)189 // Connnected Headset(s)
146
147 ListItem.Standard {190 ListItem.Standard {
148 id: connectedHeader191 id: connectedHeader
149 text: i18n.tr("Connected devices:")192 text: i18n.tr("Connected devices:")
@@ -194,6 +237,7 @@
194 iconName: iconName237 iconName: iconName
195 text: getDisplayName(connection, displayName)238 text: getDisplayName(connection, displayName)
196 onClicked: {239 onClicked: {
240 backend.stopDiscovery();
197 backend.connectDevice(addressName);241 backend.connectDevice(addressName);
198 }242 }
199 }243 }
200244
=== modified file 'plugins/bluetooth/bluetooth.cpp'
--- plugins/bluetooth/bluetooth.cpp 2014-06-09 15:12:34 +0000
+++ plugins/bluetooth/bluetooth.cpp 2014-06-20 22:19:44 +0000
@@ -53,6 +53,9 @@
53 QObject::connect(&m_devices, SIGNAL(discoveringChanged(bool)),53 QObject::connect(&m_devices, SIGNAL(discoveringChanged(bool)),
54 this, SIGNAL(discoveringChanged(bool)));54 this, SIGNAL(discoveringChanged(bool)));
5555
56 QObject::connect(&m_devices, SIGNAL(discoverableChanged(bool)),
57 this, SIGNAL(discoverableChanged(bool)));
58
56 QObject::connect(&m_agent, SIGNAL(onPairingDone()),59 QObject::connect(&m_agent, SIGNAL(onPairingDone()),
57 this, SLOT(onPairingDone()));60 this, SLOT(onPairingDone()));
58}61}
@@ -65,6 +68,21 @@
65 }68 }
66}69}
6770
71void Bluetooth::toggleDiscovery()
72{
73 m_devices.toggleDiscovery();
74}
75
76void Bluetooth::startDiscovery()
77{
78 m_devices.startDiscovery();
79}
80
81void Bluetooth::stopDiscovery()
82{
83 m_devices.stopDiscovery();
84}
85
68/***86/***
69****87****
70***/88***/
@@ -113,7 +131,7 @@
113 if (m_selectedDevice)131 if (m_selectedDevice)
114 type = m_selectedDevice->getType();132 type = m_selectedDevice->getType();
115 if (type == Device::Type::Headset)133 if (type == Device::Type::Headset)
116 m_selectedDevice->disconnect(Device::ConnectionMode::HeadsetMode);134 m_selectedDevice->disconnect(Device::ConnectionMode::Audio);
117 else if (type == Device::Type::Headphones)135 else if (type == Device::Type::Headphones)
118 m_selectedDevice->disconnect(Device::ConnectionMode::Audio);136 m_selectedDevice->disconnect(Device::ConnectionMode::Audio);
119 else if (type == Device::Type::OtherAudio)137 else if (type == Device::Type::OtherAudio)
@@ -131,7 +149,7 @@
131149
132 type = device->getType();150 type = device->getType();
133 if (type == Device::Type::Headset)151 if (type == Device::Type::Headset)
134 connMode = Device::ConnectionMode::HeadsetMode;152 connMode = Device::ConnectionMode::Audio;
135 else if (type == Device::Type::Headphones)153 else if (type == Device::Type::Headphones)
136 connMode = Device::ConnectionMode::Audio;154 connMode = Device::ConnectionMode::Audio;
137 else if (type == Device::Type::OtherAudio)155 else if (type == Device::Type::OtherAudio)
138156
=== modified file 'plugins/bluetooth/bluetooth.h'
--- plugins/bluetooth/bluetooth.h 2014-05-30 06:53:11 +0000
+++ plugins/bluetooth/bluetooth.h 2014-06-20 22:19:44 +0000
@@ -50,9 +50,14 @@
50 READ isDiscovering50 READ isDiscovering
51 NOTIFY discoveringChanged);51 NOTIFY discoveringChanged);
5252
53 Q_PROPERTY (bool discoverable
54 READ isDiscoverable
55 NOTIFY discoverableChanged);
56
53Q_SIGNALS:57Q_SIGNALS:
54 void selectedDeviceChanged();58 void selectedDeviceChanged();
55 void discoveringChanged(bool isActive);59 void discoveringChanged(bool isActive);
60 void discoverableChanged(bool isActive);
5661
57private Q_SLOTS:62private Q_SLOTS:
58 void onPairingDone();63 void onPairingDone();
@@ -61,9 +66,13 @@
61 Bluetooth(QObject *parent = 0);66 Bluetooth(QObject *parent = 0);
62 ~Bluetooth() {}67 ~Bluetooth() {}
6368
69 Q_INVOKABLE QString adapterName() const { return m_devices.adapterName(); }
64 Q_INVOKABLE void setSelectedDevice(const QString &address);70 Q_INVOKABLE void setSelectedDevice(const QString &address);
65 Q_INVOKABLE void connectDevice(const QString &address);71 Q_INVOKABLE void connectDevice(const QString &address);
66 Q_INVOKABLE void disconnectDevice();72 Q_INVOKABLE void disconnectDevice();
73 Q_INVOKABLE void toggleDiscovery();
74 Q_INVOKABLE void startDiscovery();
75 Q_INVOKABLE void stopDiscovery();
6776
68public:77public:
69 Agent * getAgent();78 Agent * getAgent();
@@ -72,6 +81,7 @@
72 QAbstractItemModel * getDisconnectedDevices();81 QAbstractItemModel * getDisconnectedDevices();
7382
74 bool isDiscovering() const { return m_devices.isDiscovering(); }83 bool isDiscovering() const { return m_devices.isDiscovering(); }
84 bool isDiscoverable() const { return m_devices.isDiscoverable(); }
7585
76private:86private:
77 QDBusConnection m_dbus;87 QDBusConnection m_dbus;
7888
=== modified file 'plugins/bluetooth/device.cpp'
--- plugins/bluetooth/device.cpp 2014-06-09 15:12:34 +0000
+++ plugins/bluetooth/device.cpp 2014-06-20 22:19:44 +0000
@@ -35,6 +35,7 @@
35 QObject::connect(this, SIGNAL(iconNameChanged()), this, SIGNAL(deviceChanged()));35 QObject::connect(this, SIGNAL(iconNameChanged()), this, SIGNAL(deviceChanged()));
36 QObject::connect(this, SIGNAL(addressChanged()), this, SIGNAL(deviceChanged()));36 QObject::connect(this, SIGNAL(addressChanged()), this, SIGNAL(deviceChanged()));
37 QObject::connect(this, SIGNAL(pairedChanged()), this, SIGNAL(deviceChanged()));37 QObject::connect(this, SIGNAL(pairedChanged()), this, SIGNAL(deviceChanged()));
38 QObject::connect(this, SIGNAL(trustedChanged()), this, SIGNAL(deviceChanged()));
38 QObject::connect(this, SIGNAL(typeChanged()), this, SIGNAL(deviceChanged()));39 QObject::connect(this, SIGNAL(typeChanged()), this, SIGNAL(deviceChanged()));
39 QObject::connect(this, SIGNAL(connectionChanged()), this, SIGNAL(deviceChanged()));40 QObject::connect(this, SIGNAL(connectionChanged()), this, SIGNAL(deviceChanged()));
40 QObject::connect(this, SIGNAL(strengthChanged()), this, SIGNAL(deviceChanged()));41 QObject::connect(this, SIGNAL(strengthChanged()), this, SIGNAL(deviceChanged()));
@@ -117,6 +118,16 @@
117 qWarning() << "Unhandled connection mode" << mode;118 qWarning() << "Unhandled connection mode" << mode;
118}119}
119120
121void Device::makeTrusted()
122{
123 QVariant value;
124 QDBusVariant trusted(true);
125
126 value.setValue(trusted);
127
128 m_deviceInterface->asyncCall("SetProperty", "Trusted", value);
129}
130
120/***131/***
121****132****
122***/133***/
@@ -162,6 +173,14 @@
162 }173 }
163}174}
164175
176void Device::setTrusted(bool trusted)
177{
178 if (m_trusted != trusted) {
179 m_trusted = trusted;
180 Q_EMIT(trustedChanged());
181 }
182}
183
165void Device::setConnection(Connection connection)184void Device::setConnection(Connection connection)
166{185{
167 if (m_connection != connection) {186 if (m_connection != connection) {
@@ -204,6 +223,9 @@
204 else223 else
205 c = m_isConnected ? Connection::Connected : Connection::Disconnected;224 c = m_isConnected ? Connection::Connected : Connection::Disconnected;
206225
226 if (m_isConnected && m_paired && !m_trusted)
227 makeTrusted();
228
207 setConnection(c);229 setConnection(c);
208}230}
209231
@@ -223,6 +245,9 @@
223 setType(getTypeFromClass(value.toUInt()));245 setType(getTypeFromClass(value.toUInt()));
224 } else if (key == "Paired") { // org.bluez.Device246 } else if (key == "Paired") { // org.bluez.Device
225 setPaired(value.toBool());247 setPaired(value.toBool());
248 updateConnection();
249 } else if (key == "Trusted") { // org.bluez.Device
250 setTrusted(value.toBool());
226 } else if (key == "Icon") { // org.bluez.Device251 } else if (key == "Icon") { // org.bluez.Device
227 m_fallbackIconName = value.toString();252 m_fallbackIconName = value.toString();
228 updateIcon ();253 updateIcon ();
229254
=== modified file 'plugins/bluetooth/device.h'
--- plugins/bluetooth/device.h 2014-05-30 06:53:11 +0000
+++ plugins/bluetooth/device.h 2014-06-20 22:19:44 +0000
@@ -49,6 +49,10 @@
49 READ isPaired49 READ isPaired
50 NOTIFY pairedChanged)50 NOTIFY pairedChanged)
5151
52 Q_PROPERTY(bool trusted
53 READ isTrusted
54 NOTIFY trustedChanged)
55
52 Q_PROPERTY(Connection connection56 Q_PROPERTY(Connection connection
53 READ getConnection57 READ getConnection
54 NOTIFY connectionChanged)58 NOTIFY connectionChanged)
@@ -81,6 +85,7 @@
81 void addressChanged();85 void addressChanged();
82 void typeChanged();86 void typeChanged();
83 void pairedChanged();87 void pairedChanged();
88 void trustedChanged();
84 void connectionChanged();89 void connectionChanged();
85 void strengthChanged();90 void strengthChanged();
86 void deviceChanged(); // catchall for any change91 void deviceChanged(); // catchall for any change
@@ -91,6 +96,7 @@
91 const QString& getIconName() const { return m_iconName; }96 const QString& getIconName() const { return m_iconName; }
92 Type getType() const { return m_type; }97 Type getType() const { return m_type; }
93 bool isPaired() const { return m_paired; }98 bool isPaired() const { return m_paired; }
99 bool isTrusted() const { return m_trusted; }
94 Connection getConnection() const { return m_connection; }100 Connection getConnection() const { return m_connection; }
95 Strength getStrength() const { return m_strength; }101 Strength getStrength() const { return m_strength; }
96 QString getPath() const { return m_deviceInterface->path(); }102 QString getPath() const { return m_deviceInterface->path(); }
@@ -103,6 +109,7 @@
103 QString m_fallbackIconName;109 QString m_fallbackIconName;
104 Type m_type = Type::Other;110 Type m_type = Type::Other;
105 bool m_paired = false;111 bool m_paired = false;
112 bool m_trusted = false;
106 Connection m_connection = Connection::Disconnected;113 Connection m_connection = Connection::Disconnected;
107 Strength m_strength = Strength::Fair;114 Strength m_strength = Strength::Fair;
108 bool m_isConnected = false;115 bool m_isConnected = false;
@@ -118,6 +125,7 @@
118 void setAddress(const QString &address);125 void setAddress(const QString &address);
119 void setType(Type type);126 void setType(Type type);
120 void setPaired(bool paired);127 void setPaired(bool paired);
128 void setTrusted(bool trusted);
121 void setConnection(Connection connection);129 void setConnection(Connection connection);
122 void setStrength(Strength strength);130 void setStrength(Strength strength);
123 void updateIcon();131 void updateIcon();
@@ -129,6 +137,7 @@
129 Device(const QString &path, QDBusConnection &bus);137 Device(const QString &path, QDBusConnection &bus);
130 bool isValid() const { return getType() != Type::Other; }138 bool isValid() const { return getType() != Type::Other; }
131 void connect(ConnectionMode);139 void connect(ConnectionMode);
140 void makeTrusted();
132 void disconnect(ConnectionMode);141 void disconnect(ConnectionMode);
133 void setProperties(const QMap<QString,QVariant> &properties);142 void setProperties(const QMap<QString,QVariant> &properties);
134143
135144
=== modified file 'plugins/bluetooth/devicemodel.cpp'
--- plugins/bluetooth/devicemodel.cpp 2014-05-30 06:53:11 +0000
+++ plugins/bluetooth/devicemodel.cpp 2014-06-20 22:19:44 +0000
@@ -19,6 +19,7 @@
19*/19*/
2020
21#include <QDBusReply>21#include <QDBusReply>
22#include <QDebug>
2223
23#include "devicemodel.h"24#include "devicemodel.h"
24#include "dbus-shared.h"25#include "dbus-shared.h"
@@ -135,6 +136,8 @@
135 const QString interface = m_bluezAdapter->interface();136 const QString interface = m_bluezAdapter->interface();
136137
137 stopDiscovery();138 stopDiscovery();
139 m_discoverableTimer.stop();
140 trySetDiscoverable(false);
138141
139 bus.disconnect(service, path, interface, "DeviceCreated",142 bus.disconnect(service, path, interface, "DeviceCreated",
140 this, SLOT(slotDeviceCreated(const QDBusObjectPath&)));143 this, SLOT(slotDeviceCreated(const QDBusObjectPath&)));
@@ -144,8 +147,11 @@
144 this, SLOT(slotDeviceFound(const QString&, const QMap<QString,QVariant>&)));147 this, SLOT(slotDeviceFound(const QString&, const QMap<QString,QVariant>&)));
145 bus.disconnect(service, path, interface, "DeviceDisappeared",148 bus.disconnect(service, path, interface, "DeviceDisappeared",
146 this, SLOT(slotDeviceDisappeared(const QString&)));149 this, SLOT(slotDeviceDisappeared(const QString&)));
150 bus.disconnect(service, path, interface, "PropertyChanged",
151 this, SLOT(slotPropertyChanged(const QString&, const QDBusVariant&)));
147152
148 m_bluezAdapter.reset(0);153 m_bluezAdapter.reset(0);
154 m_adapterName.clear();
149155
150 beginResetModel();156 beginResetModel();
151 m_devices.clear();157 m_devices.clear();
@@ -171,10 +177,22 @@
171 this, SLOT(slotDeviceFound(const QString&, const QMap<QString,QVariant>&)));177 this, SLOT(slotDeviceFound(const QString&, const QMap<QString,QVariant>&)));
172 m_dbus.connect(service, path, interface, "DeviceDisappeared", 178 m_dbus.connect(service, path, interface, "DeviceDisappeared",
173 this, SLOT(slotDeviceDisappeared(const QString&)));179 this, SLOT(slotDeviceDisappeared(const QString&)));
180 m_dbus.connect(service, path, interface, "PropertyChanged",
181 this, SLOT(slotPropertyChanged(const QString&, const QDBusVariant&)));
174182
175 m_bluezAdapter.reset(i);183 m_bluezAdapter.reset(i);
176 startDiscovery();184 startDiscovery();
177 updateDevices();185 updateDevices();
186
187 QDBusReply<QMap<QString,QVariant> > properties = m_bluezAdapter->call("GetProperties");
188 if (properties.isValid())
189 setProperties(properties.value());
190
191 // Delay enabling discoverability by 1 second.
192 m_discoverableTimer.setSingleShot(true);
193 connect(&m_discoverableTimer, SIGNAL(timeout()), this, SLOT(slotEnableDiscoverable()));
194 m_discoverableTimer.start(1000);
195
178 }196 }
179}197}
180198
@@ -199,6 +217,62 @@
199 }217 }
200}218}
201219
220void DeviceModel::setProperties(const QMap<QString,QVariant> &properties)
221{
222 QMapIterator<QString,QVariant> it(properties);
223 while (it.hasNext()) {
224 it.next();
225 updateProperty(it.key(), it.value());
226 }
227}
228
229void DeviceModel::updateProperty(const QString &key, const QVariant &value)
230{
231 if (key == "Name") {
232 m_adapterName = value.toString();
233 } else if (key == "Address") {
234 m_adapterAddress = value.toString();
235 } else if (key == "Pairable") {
236 m_isPairable = value.toBool();
237 } else if (key == "Discoverable") {
238 setDiscoverable(value.toBool());
239 }
240}
241
242void DeviceModel::setDiscoverable(bool discoverable)
243{
244 if (m_isDiscoverable != discoverable) {
245 m_isDiscoverable = discoverable;
246 Q_EMIT(discoverableChanged(m_isDiscoverable));
247 }
248}
249
250void DeviceModel::slotEnableDiscoverable()
251{
252 trySetDiscoverable(true);
253}
254
255void DeviceModel::trySetDiscoverable(bool discoverable)
256{
257 QVariant value;
258 QDBusVariant disc(discoverable);
259 QDBusReply<void > reply;
260
261 value.setValue(disc);
262
263 if (m_bluezAdapter && m_bluezAdapter->isValid()) {
264 reply = m_bluezAdapter->call("SetProperty", "Discoverable", value);
265 if (!reply.isValid())
266 qWarning() << "Error setting device discoverable:" << reply.error();
267 }
268}
269
270void DeviceModel::slotPropertyChanged(const QString &key,
271 const QDBusVariant &value)
272{
273 updateProperty (key, value.variant());
274}
275
202/***276/***
203****277****
204***/278***/
205279
=== modified file 'plugins/bluetooth/devicemodel.h'
--- plugins/bluetooth/devicemodel.h 2014-05-30 06:53:11 +0000
+++ plugins/bluetooth/devicemodel.h 2014-06-20 22:19:44 +0000
@@ -61,24 +61,37 @@
6161
62 QSharedPointer<Device> getDeviceFromAddress(const QString &address);62 QSharedPointer<Device> getDeviceFromAddress(const QString &address);
63 QSharedPointer<Device> getDeviceFromPath(const QString &path);63 QSharedPointer<Device> getDeviceFromPath(const QString &path);
64 QString adapterName() const { return m_adapterName; }
6465
65public:66public:
66 bool isDiscovering() const { return m_isDiscovering; }67 bool isDiscovering() const { return m_isDiscovering; }
68 bool isDiscoverable() const { return m_isDiscoverable; }
67 void pairDevice(const QString &address);69 void pairDevice(const QString &address);
70 void stopDiscovery();
71 void startDiscovery();
72 void toggleDiscovery();
6873
69Q_SIGNALS: 74Q_SIGNALS:
70 void discoveringChanged(bool isDiscovering);75 void discoveringChanged(bool isDiscovering);
76 void discoverableChanged(bool isDiscoverable);
7177
72private:78private:
73 QDBusConnection m_dbus;79 QDBusConnection m_dbus;
74 QDBusInterface m_bluezManager;80 QDBusInterface m_bluezManager;
7581
82 void setProperties(const QMap<QString,QVariant> &properties);
83 void updateProperty(const QString &key, const QVariant &value);
84
85 QString m_adapterName;
86 QString m_adapterAddress;
87 bool m_isPairable = false;
76 bool m_isDiscovering = false;88 bool m_isDiscovering = false;
89 bool m_isDiscoverable = false;
77 QTimer m_timer;90 QTimer m_timer;
78 void stopDiscovery();91 QTimer m_discoverableTimer;
79 void startDiscovery();
80 void toggleDiscovery();
81 void restartTimer();92 void restartTimer();
93 void trySetDiscoverable(bool discoverable);
94 void setDiscoverable(bool discoverable);
8295
83 QScopedPointer<QDBusInterface> m_bluezAdapter;96 QScopedPointer<QDBusInterface> m_bluezAdapter;
84 void clearAdapter();97 void clearAdapter();
@@ -93,7 +106,9 @@
93 void emitRowChanged(int row);106 void emitRowChanged(int row);
94107
95private Q_SLOTS:108private Q_SLOTS:
109 void slotPropertyChanged(const QString &key, const QDBusVariant &value);
96 void slotTimeout();110 void slotTimeout();
111 void slotEnableDiscoverable();
97 void slotDeviceChanged();112 void slotDeviceChanged();
98 void slotDeviceCreated(const QDBusObjectPath &);113 void slotDeviceCreated(const QDBusObjectPath &);
99 void slotDeviceRemoved(const QDBusObjectPath &);114 void slotDeviceRemoved(const QDBusObjectPath &);

Subscribers

People subscribed via source and target branches