style(bluetooth):Change the code style to conform to the code specification

调整代码书写以符合代码规范

(cherry picked from commit 05b50b174387eb5f8428a7f3d21dc41dd3c44f16)
(cherry picked from commit 56c16b455b2fa5b74d4c4d15de471f3a46bf7f79)
This commit is contained in:
zhaolong 2020-04-01 16:18:12 +08:00 committed by fpc_diesel
parent 1c6a463c15
commit 66118459e0
13 changed files with 96 additions and 49 deletions

View File

@ -21,11 +21,12 @@
*/ */
#include "bluetoothapplet.h" #include "bluetoothapplet.h"
#include "componments/switchitem.h" #include "componments/switchitem.h"
#include "componments/deviceitem.h" #include "componments/deviceitem.h"
#include "componments/adapter.h" #include "componments/adapter.h"
#include "componments/switchitem.h" #include "componments/switchitem.h"
#include "componments/adaptersmanager.h"
#include "componments/adapteritem.h"
const int Width = 200; const int Width = 200;

View File

@ -23,13 +23,16 @@
#ifndef BLUETOOTHAPPLET_H #ifndef BLUETOOTHAPPLET_H
#define BLUETOOTHAPPLET_H #define BLUETOOTHAPPLET_H
#include "componments/adaptersmanager.h" #include "componments/device.h"
#include "componments/adapteritem.h"
#include <QScrollArea>
#include <QLabel> #include <QLabel>
#include <QVBoxLayout> #include <QVBoxLayout>
class Adapter;
class AdapterItem; class AdapterItem;
class HorizontalSeparator;
class AdaptersManager;
class BluetoothApplet : public QScrollArea class BluetoothApplet : public QScrollArea
{ {
Q_OBJECT Q_OBJECT
@ -45,7 +48,7 @@ public slots :
signals: signals:
void powerChanged(bool state); void powerChanged(bool state);
void deviceStateChanged(int state); void deviceStateChanged(const Device::State state);
void noAdapter(); void noAdapter();
private: private:

View File

@ -22,18 +22,16 @@
#include "bluetoothitem.h" #include "bluetoothitem.h"
#include "constants.h" #include "constants.h"
#include "bluetoothapplet.h"
#include <QPainter>
#include <QIcon>
#include <QMouseEvent>
#include <QApplication>
#include <DApplication>
#include <DDBusSender>
#include "../widgets/tipswidget.h" #include "../widgets/tipswidget.h"
#include "../frame/util/imageutil.h" #include "../frame/util/imageutil.h"
#include "bluetoothapplet.h"
#include <DApplication>
#include <DDBusSender>
#include <DGuiApplicationHelper> #include <DGuiApplicationHelper>
#include <QPainter>
// menu actions // menu actions
#define SHIFT "shift" #define SHIFT "shift"
#define SETTINGS "settings" #define SETTINGS "settings"
@ -53,7 +51,7 @@ BluetoothItem::BluetoothItem(QWidget *parent)
m_adapterPowered = powered; m_adapterPowered = powered;
refreshIcon(); refreshIcon();
}); });
connect(m_applet, &BluetoothApplet::deviceStateChanged, [&](int state) { connect(m_applet, &BluetoothApplet::deviceStateChanged, [&](const Device::State state) {
m_devState = state; m_devState = state;
refreshIcon(); refreshIcon();
}); });
@ -123,7 +121,7 @@ void BluetoothItem::refreshIcon()
QString stateString; 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); QString iconString = QString("bluetooth-%1-symbolic").arg(stateString);

View File

@ -23,8 +23,9 @@
#ifndef BLUETOOTHITEM_H #ifndef BLUETOOTHITEM_H
#define BLUETOOTHITEM_H #define BLUETOOTHITEM_H
#include "componments/device.h"
#include <QWidget> #include <QWidget>
#include <QIcon>
#define BLUETOOTH_KEY "bluetooth-item-key" #define BLUETOOTH_KEY "bluetooth-item-key"
@ -60,7 +61,7 @@ private:
BluetoothApplet *m_applet; BluetoothApplet *m_applet;
QPixmap m_iconPixmap; QPixmap m_iconPixmap;
int m_devState; Device::State m_devState;
bool m_adapterPowered; bool m_adapterPowered;
}; };

View File

@ -21,6 +21,7 @@
*/ */
#include "adapter.h" #include "adapter.h"
#include "device.h"
#include <QJsonObject> #include <QJsonObject>
#include <QJsonDocument> #include <QJsonDocument>
@ -88,7 +89,6 @@ void Adapter::updateDevice(const QJsonObject &json)
auto constdevice = m_devices.value(id); auto constdevice = m_devices.value(id);
auto device = const_cast<Device *>(constdevice); auto device = const_cast<Device *>(constdevice);
if (device) { if (device) {
device->setId(id); device->setId(id);
device->setName(name); device->setName(name);

View File

@ -23,8 +23,10 @@
#ifndef ADAPTER_H #ifndef ADAPTER_H
#define ADAPTER_H #define ADAPTER_H
#include "device.h" #include <QObject>
#include <QMap>
class Device;
class Adapter : public QObject class Adapter : public QObject
{ {
Q_OBJECT Q_OBJECT

View File

@ -1,3 +1,25 @@
/*
* Copyright (C) 2016 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: zhaolong <zhaolong@uniontech.com>
*
* Maintainer: zhaolong <zhaolong@uniontech.com>
*
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "adapteritem.h" #include "adapteritem.h"
#include "switchitem.h" #include "switchitem.h"
#include "deviceitem.h" #include "deviceitem.h"
@ -30,7 +52,6 @@ AdapterItem::AdapterItem(AdaptersManager *adapterManager, Adapter *adapter, QWid
m_switchItem->setTitle(adapter->name()); m_switchItem->setTitle(adapter->name());
m_switchItem->setChecked(adapter->powered()); m_switchItem->setChecked(adapter->powered());
// m_deviceLayout->setMargin(5);
m_deviceLayout->addWidget(m_switchItem); m_deviceLayout->addWidget(m_switchItem);
m_deviceLayout->addWidget(m_line); m_deviceLayout->addWidget(m_line);
m_deviceLayout->addWidget(m_devGoupName); m_deviceLayout->addWidget(m_devGoupName);
@ -146,6 +167,7 @@ void AdapterItem::createDeviceItem(Device *device)
{ {
if (!device) if (!device)
return; return;
auto paired = device->paired(); auto paired = device->paired();
auto deviceId = device->id(); auto deviceId = device->id();
auto deviceItem = new DeviceItem(device->name(), this); auto deviceItem = new DeviceItem(device->name(), this);
@ -153,12 +175,13 @@ void AdapterItem::createDeviceItem(Device *device)
m_deviceItems[deviceId] = deviceItem; m_deviceItems[deviceId] = deviceItem;
if (paired) if (paired)
m_pairedDeviceItems[deviceId] = deviceItem; m_pairedDeviceItems[deviceId] = deviceItem;
deviceItem->setVisible(paired);
connect(device, &Device::pairedChanged, this, &AdapterItem::deviceItemPaired); connect(device, &Device::pairedChanged, this, &AdapterItem::deviceItemPaired);
connect(device, &Device::nameChanged, deviceItem, &DeviceItem::setTitle); connect(device, &Device::nameChanged, deviceItem, &DeviceItem::setTitle);
connect(device, &Device::stateChanged, deviceItem, &DeviceItem::chaneState); connect(device, &Device::stateChanged, deviceItem, &DeviceItem::chaneState);
connect(device, &Device::stateChanged, this, &AdapterItem::deviceStateChanged); connect(device, &Device::stateChanged, this, &AdapterItem::deviceStateChanged);
connect(deviceItem, &DeviceItem::clicked, m_adaptersManager, &AdaptersManager::connectDevice); connect(deviceItem, &DeviceItem::clicked, m_adaptersManager, &AdaptersManager::connectDevice);
deviceItem->setVisible(paired);
} }
void AdapterItem::updateView() void AdapterItem::updateView()

View File

@ -1,6 +1,30 @@
/*
* Copyright (C) 2016 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: zhaolong <zhaolong@uniontech.com>
*
* Maintainer: zhaolong <zhaolong@uniontech.com>
*
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef ADAPTERITEM_H #ifndef ADAPTERITEM_H
#define ADAPTERITEM_H #define ADAPTERITEM_H
#include "device.h"
#include <QScrollArea> #include <QScrollArea>
#include <QMap> #include <QMap>
#include <QVBoxLayout> #include <QVBoxLayout>
@ -10,7 +34,6 @@ class HorizontalSeparator;
class Adapter; class Adapter;
class SwitchItem; class SwitchItem;
class DeviceItem; class DeviceItem;
class Device;
class AdaptersManager; class AdaptersManager;
class MenueItem; class MenueItem;
class AdapterItem : public QScrollArea class AdapterItem : public QScrollArea
@ -23,7 +46,7 @@ public:
void setPowered(bool powered); void setPowered(bool powered);
signals: signals:
void deviceStateChanged(int state); void deviceStateChanged(const Device::State state);
void powerChanged(bool powered); void powerChanged(bool powered);
void sizeChange(); void sizeChange();

View File

@ -21,6 +21,8 @@
*/ */
#include "adaptersmanager.h" #include "adaptersmanager.h"
#include "adapter.h"
#include "device.h"
#include <QDBusInterface> #include <QDBusInterface>
#include <QDBusReply> #include <QDBusReply>
@ -99,15 +101,12 @@ void AdaptersManager::setAdapterPowered(const Adapter *adapter, const bool &powe
if (powered) { if (powered) {
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
connect(watcher, &QDBusPendingCallWatcher::finished, [this, call, adapter] { connect(watcher, &QDBusPendingCallWatcher::finished, [this, call, adapter] {
if (!call.isError()) if (!call.isError()) {
{
QDBusObjectPath dPath(adapter->id()); QDBusObjectPath dPath(adapter->id());
m_bluetoothInter->SetAdapterDiscoverableTimeout(dPath, 60 * 5); m_bluetoothInter->SetAdapterDiscoverableTimeout(dPath, 60 * 5);
m_bluetoothInter->SetAdapterDiscoverable(dPath, true); m_bluetoothInter->SetAdapterDiscoverable(dPath, true);
m_bluetoothInter->RequestDiscovery(dPath); m_bluetoothInter->RequestDiscovery(dPath);
} else } else {
{
qWarning() << call.error().message(); qWarning() << call.error().message();
} }
}); });
@ -132,16 +131,14 @@ void AdaptersManager::connectDevice(Device *device)
if (device) { if (device) {
QDBusObjectPath path(device->id()); QDBusObjectPath path(device->id());
switch (device->state()) { switch (device->state()) {
case 0: case Device::StateUnavailable: {
{
m_bluetoothInter->ConnectDevice(path); m_bluetoothInter->ConnectDevice(path);
qDebug() << "connect to device: " << device->name(); qDebug() << "connect to device: " << device->name();
} }
break; break;
case 1: case Device::StateAvailable:
break; break;
case 2: case Device::StateConnected: {
{
m_bluetoothInter->DisconnectDevice(path); m_bluetoothInter->DisconnectDevice(path);
qDebug() << "disconnect device: " << device->name(); qDebug() << "disconnect device: " << device->name();
} }
@ -247,9 +244,8 @@ void AdaptersManager::adapterAdd(Adapter *adapter, const QJsonObject &adpterObj)
QDBusPendingCall call = m_bluetoothInter->GetDevices(dPath); QDBusPendingCall call = m_bluetoothInter->GetDevices(dPath);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
connect(watcher, &QDBusPendingCallWatcher::finished, [this, adapter, call, watcher] { connect(watcher, &QDBusPendingCallWatcher::finished, [this, adapter, call, watcher] {
if (adapter) if (adapter) {
{ if (!call.isError()) {
if (!call.isError()) {
QDBusReply<QString> reply = call.reply(); QDBusReply<QString> reply = call.reply();
const QString replyStr = reply.value(); const QString replyStr = reply.value();
auto doc = QJsonDocument::fromJson(replyStr.toUtf8()); auto doc = QJsonDocument::fromJson(replyStr.toUtf8());

View File

@ -23,11 +23,11 @@
#ifndef ADAPTERSMANAGER_H #ifndef ADAPTERSMANAGER_H
#define ADAPTERSMANAGER_H #define ADAPTERSMANAGER_H
#include "adapter.h"
#include <com_deepin_daemon_bluetooth.h> #include <com_deepin_daemon_bluetooth.h>
using DBusBluetooth = com::deepin::daemon::Bluetooth; using DBusBluetooth = com::deepin::daemon::Bluetooth;
class Adapter;
class Device;
class AdaptersManager : public QObject class AdaptersManager : public QObject
{ {
Q_OBJECT Q_OBJECT

View File

@ -65,7 +65,7 @@ public:
Q_SIGNALS: Q_SIGNALS:
void nameChanged(const QString &name) const; void nameChanged(const QString &name) const;
void pairedChanged(const bool paired) 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 trustedChanged(const bool trusted) const;
void connectingChanged(const bool &connecting) const; void connectingChanged(const bool &connecting) const;

View File

@ -22,13 +22,11 @@
#include "deviceitem.h" #include "deviceitem.h"
#include "device.h"
#include <DStyle> #include <DStyle>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QPainter> #include <QPainter>
DeviceItem::DeviceItem(const QString &title, QWidget *parent) DeviceItem::DeviceItem(const QString &title, QWidget *parent)
: QWidget(parent) : QWidget(parent)
, m_title(new QLabel(title, this)) , m_title(new QLabel(title, this))
@ -70,7 +68,7 @@ void DeviceItem::enterEvent(QEvent *event)
{ {
QWidget::enterEvent(event); QWidget::enterEvent(event);
if (m_device) { if (m_device) {
if (2 == m_device->state()) { if (Device::StateConnected == m_device->state()) {
m_state->setPixmap(QPixmap(":/notify_close_press@2x.png")); m_state->setPixmap(QPixmap(":/notify_close_press@2x.png"));
} }
} }
@ -80,30 +78,30 @@ void DeviceItem::leaveEvent(QEvent *event)
{ {
QWidget::enterEvent(event); QWidget::enterEvent(event);
if (m_device) { if (m_device) {
if (2 == m_device->state()) { if (Device::StateConnected == m_device->state()) {
m_state->setPixmap(QPixmap(":/list_select@2x.png")); m_state->setPixmap(QPixmap(":/list_select@2x.png"));
} }
} }
} }
void DeviceItem::chaneState(int state) void DeviceItem::chaneState(const Device::State state)
{ {
switch (state) { switch (state) {
case 0: { case Device::StateUnavailable: {
m_state->setVisible(false); m_state->setVisible(false);
m_loadingStat->stop(); m_loadingStat->stop();
m_loadingStat->hide(); m_loadingStat->hide();
m_loadingStat->setVisible(false); m_loadingStat->setVisible(false);
} }
break; break;
case 1: { case Device::StateAvailable: {
m_state->setVisible(false); m_state->setVisible(false);
m_loadingStat->start(); m_loadingStat->start();
m_loadingStat->show(); m_loadingStat->show();
m_loadingStat->setVisible(true); m_loadingStat->setVisible(true);
} }
break; break;
case 2: { case Device::StateConnected: {
m_loadingStat->stop(); m_loadingStat->stop();
m_loadingStat->hide(); m_loadingStat->hide();
m_loadingStat->setVisible(false); m_loadingStat->setVisible(false);

View File

@ -23,12 +23,14 @@
#ifndef DEVICEITEM_H #ifndef DEVICEITEM_H
#define DEVICEITEM_H #define DEVICEITEM_H
#include "device.h"
#include <DSpinner> #include <DSpinner>
#include <QLabel> #include <QLabel>
DWIDGET_USE_NAMESPACE DWIDGET_USE_NAMESPACE
class Device;
class HorizontalSeparator; class HorizontalSeparator;
class DeviceItem : public QWidget class DeviceItem : public QWidget
{ {
@ -50,7 +52,7 @@ signals:
void clicked(Device *); void clicked(Device *);
public slots: public slots:
void chaneState(int state); void chaneState(const Device::State state);
private: private:
QLabel *m_title; QLabel *m_title;