mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
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:
parent
1c6a463c15
commit
66118459e0
@ -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;
|
||||
|
||||
|
@ -23,13 +23,16 @@
|
||||
#ifndef BLUETOOTHAPPLET_H
|
||||
#define BLUETOOTHAPPLET_H
|
||||
|
||||
#include "componments/adaptersmanager.h"
|
||||
#include "componments/adapteritem.h"
|
||||
#include "componments/device.h"
|
||||
|
||||
#include <QScrollArea>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
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:
|
||||
|
@ -22,18 +22,16 @@
|
||||
|
||||
#include "bluetoothitem.h"
|
||||
#include "constants.h"
|
||||
#include "bluetoothapplet.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QIcon>
|
||||
#include <QMouseEvent>
|
||||
#include <QApplication>
|
||||
#include <DApplication>
|
||||
#include <DDBusSender>
|
||||
#include "../widgets/tipswidget.h"
|
||||
#include "../frame/util/imageutil.h"
|
||||
#include "bluetoothapplet.h"
|
||||
|
||||
#include <DApplication>
|
||||
#include <DDBusSender>
|
||||
#include <DGuiApplicationHelper>
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
// 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);
|
||||
|
||||
|
@ -23,8 +23,9 @@
|
||||
#ifndef BLUETOOTHITEM_H
|
||||
#define BLUETOOTHITEM_H
|
||||
|
||||
#include "componments/device.h"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QIcon>
|
||||
|
||||
#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;
|
||||
};
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "adapter.h"
|
||||
#include "device.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
@ -88,7 +89,6 @@ void Adapter::updateDevice(const QJsonObject &json)
|
||||
|
||||
auto constdevice = m_devices.value(id);
|
||||
auto device = const_cast<Device *>(constdevice);
|
||||
|
||||
if (device) {
|
||||
device->setId(id);
|
||||
device->setName(name);
|
||||
|
@ -23,8 +23,10 @@
|
||||
#ifndef ADAPTER_H
|
||||
#define ADAPTER_H
|
||||
|
||||
#include "device.h"
|
||||
#include <QObject>
|
||||
#include <QMap>
|
||||
|
||||
class Device;
|
||||
class Adapter : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -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 "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()
|
||||
|
@ -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
|
||||
#define ADAPTERITEM_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#include <QScrollArea>
|
||||
#include <QMap>
|
||||
#include <QVBoxLayout>
|
||||
@ -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();
|
||||
|
||||
|
@ -21,6 +21,8 @@
|
||||
*/
|
||||
|
||||
#include "adaptersmanager.h"
|
||||
#include "adapter.h"
|
||||
#include "device.h"
|
||||
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusReply>
|
||||
@ -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<QString> reply = call.reply();
|
||||
const QString replyStr = reply.value();
|
||||
auto doc = QJsonDocument::fromJson(replyStr.toUtf8());
|
||||
|
@ -23,11 +23,11 @@
|
||||
#ifndef ADAPTERSMANAGER_H
|
||||
#define ADAPTERSMANAGER_H
|
||||
|
||||
#include "adapter.h"
|
||||
|
||||
#include <com_deepin_daemon_bluetooth.h>
|
||||
using DBusBluetooth = com::deepin::daemon::Bluetooth;
|
||||
|
||||
class Adapter;
|
||||
class Device;
|
||||
class AdaptersManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -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;
|
||||
|
||||
|
@ -22,13 +22,11 @@
|
||||
|
||||
#include "deviceitem.h"
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#include <DStyle>
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QPainter>
|
||||
|
||||
|
||||
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);
|
||||
|
@ -23,12 +23,14 @@
|
||||
#ifndef DEVICEITEM_H
|
||||
#define DEVICEITEM_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
#include <DSpinner>
|
||||
|
||||
#include <QLabel>
|
||||
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user