diff --git a/plugins/bluetooth/bluetoothapplet.cpp b/plugins/bluetooth/bluetoothapplet.cpp index 2ac4412f6..4462d46ce 100644 --- a/plugins/bluetooth/bluetoothapplet.cpp +++ b/plugins/bluetooth/bluetoothapplet.cpp @@ -21,11 +21,12 @@ */ #include "bluetoothapplet.h" - #include "componments/switchitem.h" #include "componments/deviceitem.h" #include "componments/adapter.h" #include "componments/switchitem.h" +#include "componments/adaptersmanager.h" +#include "componments/adapteritem.h" const int Width = 200; diff --git a/plugins/bluetooth/bluetoothapplet.h b/plugins/bluetooth/bluetoothapplet.h index 58f9bce67..20feced90 100644 --- a/plugins/bluetooth/bluetoothapplet.h +++ b/plugins/bluetooth/bluetoothapplet.h @@ -23,13 +23,16 @@ #ifndef BLUETOOTHAPPLET_H #define BLUETOOTHAPPLET_H -#include "componments/adaptersmanager.h" -#include "componments/adapteritem.h" +#include "componments/device.h" +#include #include #include +class Adapter; class AdapterItem; +class HorizontalSeparator; +class AdaptersManager; class BluetoothApplet : public QScrollArea { Q_OBJECT @@ -45,7 +48,7 @@ public slots : signals: void powerChanged(bool state); - void deviceStateChanged(int state); + void deviceStateChanged(const Device::State state); void noAdapter(); private: diff --git a/plugins/bluetooth/bluetoothitem.cpp b/plugins/bluetooth/bluetoothitem.cpp index 094c15fff..4e7fcb0fc 100644 --- a/plugins/bluetooth/bluetoothitem.cpp +++ b/plugins/bluetooth/bluetoothitem.cpp @@ -22,18 +22,16 @@ #include "bluetoothitem.h" #include "constants.h" -#include "bluetoothapplet.h" - -#include -#include -#include -#include -#include -#include #include "../widgets/tipswidget.h" #include "../frame/util/imageutil.h" +#include "bluetoothapplet.h" + +#include +#include #include +#include + // menu actions #define SHIFT "shift" #define SETTINGS "settings" @@ -53,7 +51,7 @@ BluetoothItem::BluetoothItem(QWidget *parent) m_adapterPowered = powered; refreshIcon(); }); - connect(m_applet, &BluetoothApplet::deviceStateChanged, [&](int state) { + connect(m_applet, &BluetoothApplet::deviceStateChanged, [&](const Device::State state) { m_devState = state; refreshIcon(); }); @@ -123,7 +121,7 @@ void BluetoothItem::refreshIcon() QString stateString; - m_adapterPowered ? (m_devState == 2 ? stateString = "waiting" : stateString = "active") : stateString = "disable"; + m_adapterPowered ? (m_devState == Device::StateConnected ? stateString = "waiting" : stateString = "active") : stateString = "disable"; QString iconString = QString("bluetooth-%1-symbolic").arg(stateString); diff --git a/plugins/bluetooth/bluetoothitem.h b/plugins/bluetooth/bluetoothitem.h index bac321a61..479b866f4 100644 --- a/plugins/bluetooth/bluetoothitem.h +++ b/plugins/bluetooth/bluetoothitem.h @@ -23,8 +23,9 @@ #ifndef BLUETOOTHITEM_H #define BLUETOOTHITEM_H +#include "componments/device.h" + #include -#include #define BLUETOOTH_KEY "bluetooth-item-key" @@ -60,7 +61,7 @@ private: BluetoothApplet *m_applet; QPixmap m_iconPixmap; - int m_devState; + Device::State m_devState; bool m_adapterPowered; }; diff --git a/plugins/bluetooth/componments/adapter.cpp b/plugins/bluetooth/componments/adapter.cpp index 35e0405b0..f94e9407d 100644 --- a/plugins/bluetooth/componments/adapter.cpp +++ b/plugins/bluetooth/componments/adapter.cpp @@ -21,6 +21,7 @@ */ #include "adapter.h" +#include "device.h" #include #include @@ -88,7 +89,6 @@ void Adapter::updateDevice(const QJsonObject &json) auto constdevice = m_devices.value(id); auto device = const_cast(constdevice); - if (device) { device->setId(id); device->setName(name); diff --git a/plugins/bluetooth/componments/adapter.h b/plugins/bluetooth/componments/adapter.h index 0b9a265bd..efad96230 100644 --- a/plugins/bluetooth/componments/adapter.h +++ b/plugins/bluetooth/componments/adapter.h @@ -23,8 +23,10 @@ #ifndef ADAPTER_H #define ADAPTER_H -#include "device.h" +#include +#include +class Device; class Adapter : public QObject { Q_OBJECT diff --git a/plugins/bluetooth/componments/adapteritem.cpp b/plugins/bluetooth/componments/adapteritem.cpp index f5c2c22d4..2c192098b 100644 --- a/plugins/bluetooth/componments/adapteritem.cpp +++ b/plugins/bluetooth/componments/adapteritem.cpp @@ -1,3 +1,25 @@ +/* + * Copyright (C) 2016 ~ 2018 Deepin Technology Co., Ltd. + * + * Author: zhaolong + * + * Maintainer: zhaolong + * + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #include "adapteritem.h" #include "switchitem.h" #include "deviceitem.h" @@ -30,7 +52,6 @@ AdapterItem::AdapterItem(AdaptersManager *adapterManager, Adapter *adapter, QWid m_switchItem->setTitle(adapter->name()); m_switchItem->setChecked(adapter->powered()); -// m_deviceLayout->setMargin(5); m_deviceLayout->addWidget(m_switchItem); m_deviceLayout->addWidget(m_line); m_deviceLayout->addWidget(m_devGoupName); @@ -146,6 +167,7 @@ void AdapterItem::createDeviceItem(Device *device) { if (!device) return; + auto paired = device->paired(); auto deviceId = device->id(); auto deviceItem = new DeviceItem(device->name(), this); @@ -153,12 +175,13 @@ void AdapterItem::createDeviceItem(Device *device) m_deviceItems[deviceId] = deviceItem; if (paired) m_pairedDeviceItems[deviceId] = deviceItem; + deviceItem->setVisible(paired); + connect(device, &Device::pairedChanged, this, &AdapterItem::deviceItemPaired); connect(device, &Device::nameChanged, deviceItem, &DeviceItem::setTitle); connect(device, &Device::stateChanged, deviceItem, &DeviceItem::chaneState); connect(device, &Device::stateChanged, this, &AdapterItem::deviceStateChanged); connect(deviceItem, &DeviceItem::clicked, m_adaptersManager, &AdaptersManager::connectDevice); - deviceItem->setVisible(paired); } void AdapterItem::updateView() diff --git a/plugins/bluetooth/componments/adapteritem.h b/plugins/bluetooth/componments/adapteritem.h index 88141ac1c..991765299 100644 --- a/plugins/bluetooth/componments/adapteritem.h +++ b/plugins/bluetooth/componments/adapteritem.h @@ -1,6 +1,30 @@ +/* + * Copyright (C) 2016 ~ 2018 Deepin Technology Co., Ltd. + * + * Author: zhaolong + * + * Maintainer: zhaolong + * + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + #ifndef ADAPTERITEM_H #define ADAPTERITEM_H +#include "device.h" + #include #include #include @@ -10,7 +34,6 @@ class HorizontalSeparator; class Adapter; class SwitchItem; class DeviceItem; -class Device; class AdaptersManager; class MenueItem; class AdapterItem : public QScrollArea @@ -23,7 +46,7 @@ public: void setPowered(bool powered); signals: - void deviceStateChanged(int state); + void deviceStateChanged(const Device::State state); void powerChanged(bool powered); void sizeChange(); diff --git a/plugins/bluetooth/componments/adaptersmanager.cpp b/plugins/bluetooth/componments/adaptersmanager.cpp index fcb43b723..d7eea02a5 100644 --- a/plugins/bluetooth/componments/adaptersmanager.cpp +++ b/plugins/bluetooth/componments/adaptersmanager.cpp @@ -21,6 +21,8 @@ */ #include "adaptersmanager.h" +#include "adapter.h" +#include "device.h" #include #include @@ -99,15 +101,12 @@ void AdaptersManager::setAdapterPowered(const Adapter *adapter, const bool &powe if (powered) { QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this); connect(watcher, &QDBusPendingCallWatcher::finished, [this, call, adapter] { - if (!call.isError()) - { + if (!call.isError()) { QDBusObjectPath dPath(adapter->id()); m_bluetoothInter->SetAdapterDiscoverableTimeout(dPath, 60 * 5); m_bluetoothInter->SetAdapterDiscoverable(dPath, true); - m_bluetoothInter->RequestDiscovery(dPath); - } else - { + } else { qWarning() << call.error().message(); } }); @@ -132,16 +131,14 @@ void AdaptersManager::connectDevice(Device *device) if (device) { QDBusObjectPath path(device->id()); switch (device->state()) { - case 0: - { + case Device::StateUnavailable: { m_bluetoothInter->ConnectDevice(path); qDebug() << "connect to device: " << device->name(); } break; - case 1: + case Device::StateAvailable: break; - case 2: - { + case Device::StateConnected: { m_bluetoothInter->DisconnectDevice(path); qDebug() << "disconnect device: " << device->name(); } @@ -247,9 +244,8 @@ void AdaptersManager::adapterAdd(Adapter *adapter, const QJsonObject &adpterObj) QDBusPendingCall call = m_bluetoothInter->GetDevices(dPath); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this); connect(watcher, &QDBusPendingCallWatcher::finished, [this, adapter, call, watcher] { - if (adapter) - { - if (!call.isError()) { + if (adapter) { + if (!call.isError()) { QDBusReply reply = call.reply(); const QString replyStr = reply.value(); auto doc = QJsonDocument::fromJson(replyStr.toUtf8()); diff --git a/plugins/bluetooth/componments/adaptersmanager.h b/plugins/bluetooth/componments/adaptersmanager.h index 39c073dc8..ecb4e5f99 100644 --- a/plugins/bluetooth/componments/adaptersmanager.h +++ b/plugins/bluetooth/componments/adaptersmanager.h @@ -23,11 +23,11 @@ #ifndef ADAPTERSMANAGER_H #define ADAPTERSMANAGER_H -#include "adapter.h" - #include using DBusBluetooth = com::deepin::daemon::Bluetooth; +class Adapter; +class Device; class AdaptersManager : public QObject { Q_OBJECT diff --git a/plugins/bluetooth/componments/device.h b/plugins/bluetooth/componments/device.h index 103a39864..199d8fb68 100644 --- a/plugins/bluetooth/componments/device.h +++ b/plugins/bluetooth/componments/device.h @@ -65,7 +65,7 @@ public: Q_SIGNALS: void nameChanged(const QString &name) const; void pairedChanged(const bool paired) const; - void stateChanged(int state) const; + void stateChanged(const State state) const; void trustedChanged(const bool trusted) const; void connectingChanged(const bool &connecting) const; diff --git a/plugins/bluetooth/componments/deviceitem.cpp b/plugins/bluetooth/componments/deviceitem.cpp index d7865ffe7..f1d06ba49 100644 --- a/plugins/bluetooth/componments/deviceitem.cpp +++ b/plugins/bluetooth/componments/deviceitem.cpp @@ -22,13 +22,11 @@ #include "deviceitem.h" -#include "device.h" - #include + #include #include - DeviceItem::DeviceItem(const QString &title, QWidget *parent) : QWidget(parent) , m_title(new QLabel(title, this)) @@ -70,7 +68,7 @@ void DeviceItem::enterEvent(QEvent *event) { QWidget::enterEvent(event); if (m_device) { - if (2 == m_device->state()) { + if (Device::StateConnected == m_device->state()) { m_state->setPixmap(QPixmap(":/notify_close_press@2x.png")); } } @@ -80,30 +78,30 @@ void DeviceItem::leaveEvent(QEvent *event) { QWidget::enterEvent(event); if (m_device) { - if (2 == m_device->state()) { + if (Device::StateConnected == m_device->state()) { m_state->setPixmap(QPixmap(":/list_select@2x.png")); } } } -void DeviceItem::chaneState(int state) +void DeviceItem::chaneState(const Device::State state) { switch (state) { - case 0: { + case Device::StateUnavailable: { m_state->setVisible(false); m_loadingStat->stop(); m_loadingStat->hide(); m_loadingStat->setVisible(false); } break; - case 1: { + case Device::StateAvailable: { m_state->setVisible(false); m_loadingStat->start(); m_loadingStat->show(); m_loadingStat->setVisible(true); } break; - case 2: { + case Device::StateConnected: { m_loadingStat->stop(); m_loadingStat->hide(); m_loadingStat->setVisible(false); diff --git a/plugins/bluetooth/componments/deviceitem.h b/plugins/bluetooth/componments/deviceitem.h index 592cbf697..81f59b193 100644 --- a/plugins/bluetooth/componments/deviceitem.h +++ b/plugins/bluetooth/componments/deviceitem.h @@ -23,12 +23,14 @@ #ifndef DEVICEITEM_H #define DEVICEITEM_H +#include "device.h" + #include + #include DWIDGET_USE_NAMESPACE -class Device; class HorizontalSeparator; class DeviceItem : public QWidget { @@ -50,7 +52,7 @@ signals: void clicked(Device *); public slots: - void chaneState(int state); + void chaneState(const Device::State state); private: QLabel *m_title;