dde-dock/plugins/bluetooth/componments/bluetoothadapteritem.h
xiaoyaobing 4e2dcf118b feat: 修复任务栏与控制中心是否显示没有名称的蓝牙设备不同步
解析蓝牙Dbus中的数据,通过判断json数据中的name字段值是否为空判断是否未命名,
根据控制中心的设置,同步更新是否在蓝牙视图中显示没有名称的蓝牙设备

Log: 修复任务栏不显示没有名称的蓝牙设备问题
Task: https://pms.uniontech.com/zentao/task-view-62958.html
Change-Id: Idd3c84721258a40161b0e1ce565518887f1add37
2021-03-01 10:53:54 +08:00

138 lines
4.0 KiB
C++

/*
* Copyright (C) 2016 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: chenwei <chenwei@uniontech.com>
*
* Maintainer: chenwei <chenwei@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 BLUETOOTHADAPTERITEM_H
#define BLUETOOTHADAPTERITEM_H
#include "componments/device.h"
#include <QWidget>
#include <DStyleHelper>
#include <DApplicationHelper>
#include <com_deepin_daemon_bluetooth.h>
using DBusBluetooth = com::deepin::daemon::Bluetooth;
DWIDGET_USE_NAMESPACE
DWIDGET_BEGIN_NAMESPACE
class DSwitchButton;
class DStandardItem;
class DListView;
class DSpinner;
DWIDGET_END_NAMESPACE
class Adapter;
class SettingLabel;
class QStandardItemModel;
class RefreshButton;
const QString LightString = QString(":/light/buletooth_%1_light.svg");
const QString DarkString = QString(":/dark/buletooth_%1_dark.svg");
class BluetoothDeviceItem : public QObject
{
Q_OBJECT
public:
explicit BluetoothDeviceItem(QStyle *style = nullptr, const Device *device = nullptr, DListView *parent = nullptr);
virtual ~BluetoothDeviceItem();
DStandardItem *standardItem() { return m_standarditem; }
const Device *device() { return m_device; }
public slots:
// 系统主题发生改变时更新蓝牙图标
void updateIconTheme(DGuiApplicationHelper::ColorType type);
// 更新蓝牙设备的连接状态
void updateDeviceState(Device::State state);
signals:
void requestTopDeviceItem(DStandardItem *item);
void deviceStateChanged(const Device* device);
private:
void initActionList();
void initConnect();
DStyleHelper m_style;
QString m_deviceIcon;
const Device *m_device = nullptr;
DStandardItem *m_standarditem = nullptr;
DViewItemAction *m_labelAction = nullptr;
DViewItemAction *m_stateAction = nullptr;
DSpinner *m_loading = nullptr;
};
class BluetoothAdapterItem : public QWidget
{
Q_OBJECT
public:
explicit BluetoothAdapterItem(Adapter *adapter, QWidget *parent = nullptr);
~BluetoothAdapterItem();
Adapter *adapter() { return m_adapter; }
int currentDeviceCount();
QStringList connectedDevicesName();
public slots:
// 添加蓝牙设备
void onDeviceAdded(const Device *device);
// 移除蓝牙设备
void onDeviceRemoved(const Device *device);
// 连接蓝牙设备
void onConnectDevice(const QModelIndex &index);
// 将已连接的蓝牙设备放到列表第一个
void onTopDeviceItem(DStandardItem* item);
// 设置蓝牙适配器名称
void onAdapterNameChanged(const QString name);
void updateIconTheme(DGuiApplicationHelper::ColorType type);
signals:
void adapterPowerChanged();
void requestSetAdapterPower(Adapter *adapter, bool state);
void requestRefreshAdapter(Adapter *adapter);
void connectDevice(const Device *device, Adapter *adapter);
void deviceCountChanged();
void deviceStateChanged(const Device* device);
private:
void initData();
void initUi();
void initConnect();
void setUnnamedDevicesVisible(bool isShow);
Adapter *m_adapter = nullptr;
SettingLabel *m_adapterLabel = nullptr;
DSwitchButton *m_adapterStateBtn = nullptr;
DListView *m_deviceListview = nullptr;
QStandardItemModel *m_deviceModel = nullptr;
RefreshButton *m_refreshBtn = nullptr;
DBusBluetooth *m_bluetoothInter;
bool m_showUnnamedDevices;
QMap<QString, BluetoothDeviceItem *> m_deviceItems;
};
#endif // BLUETOOTHADAPTERITEM_H