mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
refactor(bluetooth&network):code self test
task21255 [任务栏]蓝牙和网络插件部分的代码自检 (cherry picked from commit 581050c5b811ccbd36202d74b0c8007d5d4b29f4)
This commit is contained in:
parent
0d835e0fec
commit
20bb074f01
@ -30,6 +30,10 @@
|
|||||||
#include "componments/bluetoothconstants.h"
|
#include "componments/bluetoothconstants.h"
|
||||||
|
|
||||||
#include <DApplicationHelper>
|
#include <DApplicationHelper>
|
||||||
|
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
DGUI_USE_NAMESPACE
|
DGUI_USE_NAMESPACE
|
||||||
|
|
||||||
extern void initFontColor(QWidget *widget)
|
extern void initFontColor(QWidget *widget)
|
||||||
@ -60,7 +64,7 @@ BluetoothApplet::BluetoothApplet(QWidget *parent)
|
|||||||
{
|
{
|
||||||
m_line->setVisible(false);
|
m_line->setVisible(false);
|
||||||
|
|
||||||
auto defaultFont = font();
|
QFont defaultFont = font();
|
||||||
auto titlefont = QFont(defaultFont.family(), defaultFont.pointSize() + 2);
|
auto titlefont = QFont(defaultFont.family(), defaultFont.pointSize() + 2);
|
||||||
|
|
||||||
m_appletName->setText(tr("Bluetooth"));
|
m_appletName->setText(tr("Bluetooth"));
|
||||||
@ -97,7 +101,7 @@ BluetoothApplet::BluetoothApplet(QWidget *parent)
|
|||||||
|
|
||||||
void BluetoothApplet::setAdapterPowered(bool powered)
|
void BluetoothApplet::setAdapterPowered(bool powered)
|
||||||
{
|
{
|
||||||
for (auto adapterItem : m_adapterItems) {
|
for (AdapterItem *adapterItem : m_adapterItems) {
|
||||||
if (adapterItem)
|
if (adapterItem)
|
||||||
adapterItem->setPowered(powered);
|
adapterItem->setPowered(powered);
|
||||||
}
|
}
|
||||||
@ -113,15 +117,14 @@ bool BluetoothApplet::hasAadapter()
|
|||||||
return m_adaptersManager->adaptersCount();
|
return m_adaptersManager->adaptersCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BluetoothApplet::onPowerChanged(bool state)
|
void BluetoothApplet::onPowerChanged()
|
||||||
{
|
{
|
||||||
Q_UNUSED(state)
|
|
||||||
bool powerState = false;
|
bool powerState = false;
|
||||||
for (auto adapterItem : m_adapterItems) {
|
for (AdapterItem *adapterItem : m_adapterItems) {
|
||||||
if (adapterItem->isPowered()) {
|
if (adapterItem->isPowered()) {
|
||||||
powerState = true;
|
powerState = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
emit powerChanged(powerState);
|
emit powerChanged(powerState);
|
||||||
}
|
}
|
||||||
@ -129,7 +132,7 @@ void BluetoothApplet::onPowerChanged(bool state)
|
|||||||
void BluetoothApplet::onDeviceStateChanged()
|
void BluetoothApplet::onDeviceStateChanged()
|
||||||
{
|
{
|
||||||
Device::State deviceState = Device::StateUnavailable;
|
Device::State deviceState = Device::StateUnavailable;
|
||||||
for (auto adapterItem : m_adapterItems) {
|
for (AdapterItem *adapterItem : m_adapterItems) {
|
||||||
if (Device::StateAvailable == adapterItem->currentDeviceState()) {
|
if (Device::StateAvailable == adapterItem->currentDeviceState()) {
|
||||||
deviceState = Device::StateAvailable;
|
deviceState = Device::StateAvailable;
|
||||||
continue;
|
continue;
|
||||||
@ -152,24 +155,24 @@ void BluetoothApplet::addAdapter(Adapter *adapter)
|
|||||||
emit justHasAdapter();
|
emit justHasAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto adapterId = adapter->id();
|
QString adapterId = adapter->id();
|
||||||
auto adatpterItem = new AdapterItem(m_adaptersManager, adapter);
|
auto adatpterItem = new AdapterItem(m_adaptersManager, adapter, this);
|
||||||
// m_adapterItems[adapterId] = adatpterItem;
|
m_adapterItems[adapterId] = adatpterItem;
|
||||||
// m_centrealLayout->addWidget(adatpterItem);
|
m_centrealLayout->addWidget(adatpterItem);
|
||||||
// getDevieInitState(adatpterItem);
|
getDevieInitState(adatpterItem);
|
||||||
|
|
||||||
// connect(adatpterItem, &AdapterItem::deviceStateChanged, this, &BluetoothApplet::onDeviceStateChanged);
|
connect(adatpterItem, &AdapterItem::deviceStateChanged, this, &BluetoothApplet::onDeviceStateChanged);
|
||||||
// connect(adatpterItem, &AdapterItem::powerChanged, this, &BluetoothApplet::onPowerChanged);
|
connect(adatpterItem, &AdapterItem::powerChanged, this, &BluetoothApplet::onPowerChanged);
|
||||||
// connect(adatpterItem, &AdapterItem::sizeChange, this, &BluetoothApplet::updateView);
|
connect(adatpterItem, &AdapterItem::sizeChange, this, &BluetoothApplet::updateView);
|
||||||
|
|
||||||
// updateView();
|
updateView();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BluetoothApplet::removeAdapter(Adapter *adapter)
|
void BluetoothApplet::removeAdapter(Adapter *adapter)
|
||||||
{
|
{
|
||||||
if (adapter) {
|
if (adapter) {
|
||||||
auto adapterId = adapter->id();
|
QString adapterId = adapter->id();
|
||||||
auto adapterItem = m_adapterItems.value(adapterId);
|
AdapterItem *adapterItem = m_adapterItems.value(adapterId);
|
||||||
if (adapterItem) {
|
if (adapterItem) {
|
||||||
m_centrealLayout->removeWidget(adapterItem);
|
m_centrealLayout->removeWidget(adapterItem);
|
||||||
delete adapterItem;
|
delete adapterItem;
|
||||||
@ -185,7 +188,7 @@ void BluetoothApplet::updateView()
|
|||||||
{
|
{
|
||||||
int contentHeight = 0;
|
int contentHeight = 0;
|
||||||
int itemCount = 0;
|
int itemCount = 0;
|
||||||
for (auto adapterItem : m_adapterItems) {
|
for (AdapterItem *adapterItem : m_adapterItems) {
|
||||||
if (adapterItem) {
|
if (adapterItem) {
|
||||||
contentHeight += adapterItem->viewHeight();
|
contentHeight += adapterItem->viewHeight();
|
||||||
if (adapterItem->isPowered())
|
if (adapterItem->isPowered())
|
||||||
@ -193,7 +196,7 @@ void BluetoothApplet::updateView()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto adaptersCnt = m_adapterItems.size();
|
int adaptersCnt = m_adapterItems.size();
|
||||||
if (adaptersCnt > 1) {
|
if (adaptersCnt > 1) {
|
||||||
m_line->setVisible(true);
|
m_line->setVisible(true);
|
||||||
m_appletName->setVisible(true);
|
m_appletName->setVisible(true);
|
||||||
@ -218,7 +221,7 @@ void BluetoothApplet::getDevieInitState(AdapterItem *item)
|
|||||||
|
|
||||||
Device::State deviceState = item->initDeviceState();
|
Device::State deviceState = item->initDeviceState();
|
||||||
Device::State otherDeviceState = Device::StateUnavailable;
|
Device::State otherDeviceState = Device::StateUnavailable;
|
||||||
for (auto adapterItem : m_adapterItems) {
|
for (AdapterItem *adapterItem : m_adapterItems) {
|
||||||
if (adapterItem != item) {
|
if (adapterItem != item) {
|
||||||
if (Device::StateAvailable == adapterItem->currentDeviceState()) {
|
if (Device::StateAvailable == adapterItem->currentDeviceState()) {
|
||||||
otherDeviceState = Device::StateAvailable;
|
otherDeviceState = Device::StateAvailable;
|
||||||
|
@ -26,9 +26,9 @@
|
|||||||
#include "componments/device.h"
|
#include "componments/device.h"
|
||||||
|
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
#include <QLabel>
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
|
|
||||||
|
class QLabel;
|
||||||
|
class QVBoxLayout;
|
||||||
class Adapter;
|
class Adapter;
|
||||||
class AdapterItem;
|
class AdapterItem;
|
||||||
class HorizontalSeparator;
|
class HorizontalSeparator;
|
||||||
@ -43,17 +43,17 @@ public:
|
|||||||
bool hasAadapter();
|
bool hasAadapter();
|
||||||
|
|
||||||
public slots :
|
public slots :
|
||||||
void addAdapter(Adapter *constadapter);
|
void addAdapter(Adapter *adapter);
|
||||||
void removeAdapter(Adapter *adapter);
|
void removeAdapter(Adapter *adapter);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void powerChanged(bool state);
|
void powerChanged(bool powered);
|
||||||
void deviceStateChanged(const Device::State state);
|
void deviceStateChanged(const Device::State state);
|
||||||
void noAdapter();
|
void noAdapter();
|
||||||
void justHasAdapter();
|
void justHasAdapter();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onPowerChanged(bool state);
|
void onPowerChanged();
|
||||||
void onDeviceStateChanged();
|
void onDeviceStateChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -33,8 +33,8 @@
|
|||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
// menu actions
|
// menu actions
|
||||||
#define SHIFT "shift"
|
#define SHIFT "shift"
|
||||||
#define SETTINGS "settings"
|
#define SETTINGS "settings"
|
||||||
|
|
||||||
DWIDGET_USE_NAMESPACE
|
DWIDGET_USE_NAMESPACE
|
||||||
DGUI_USE_NAMESPACE
|
DGUI_USE_NAMESPACE
|
||||||
@ -134,7 +134,7 @@ void BluetoothItem::refreshIcon()
|
|||||||
m_timer->start();
|
m_timer->start();
|
||||||
stateString = "waiting";
|
stateString = "waiting";
|
||||||
iconString = QString("bluetooth-%1-symbolic").arg(stateString);
|
iconString = QString("bluetooth-%1-symbolic").arg(stateString);
|
||||||
const auto ratio = devicePixelRatioF();
|
const qreal ratio = devicePixelRatioF();
|
||||||
int iconSize = PLUGIN_ICON_MAX_SIZE;
|
int iconSize = PLUGIN_ICON_MAX_SIZE;
|
||||||
if (height() <= PLUGIN_BACKGROUND_MIN_SIZE && DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType)
|
if (height() <= PLUGIN_BACKGROUND_MIN_SIZE && DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType)
|
||||||
iconString.append(PLUGIN_MIN_ICON_NAME);
|
iconString.append(PLUGIN_MIN_ICON_NAME);
|
||||||
@ -155,7 +155,7 @@ void BluetoothItem::refreshIcon()
|
|||||||
m_timer->stop();
|
m_timer->stop();
|
||||||
iconString = QString("bluetooth-%1-symbolic").arg(stateString);
|
iconString = QString("bluetooth-%1-symbolic").arg(stateString);
|
||||||
|
|
||||||
const auto ratio = devicePixelRatioF();
|
const qreal ratio = devicePixelRatioF();
|
||||||
int iconSize = PLUGIN_ICON_MAX_SIZE;
|
int iconSize = PLUGIN_ICON_MAX_SIZE;
|
||||||
if (height() <= PLUGIN_BACKGROUND_MIN_SIZE && DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType)
|
if (height() <= PLUGIN_BACKGROUND_MIN_SIZE && DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType)
|
||||||
iconString.append(PLUGIN_MIN_ICON_NAME);
|
iconString.append(PLUGIN_MIN_ICON_NAME);
|
||||||
@ -170,9 +170,9 @@ bool BluetoothItem::hasAdapter()
|
|||||||
return m_applet->hasAadapter();
|
return m_applet->hasAadapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BluetoothItem::resizeEvent(QResizeEvent *e)
|
void BluetoothItem::resizeEvent(QResizeEvent *event)
|
||||||
{
|
{
|
||||||
QWidget::resizeEvent(e);
|
QWidget::resizeEvent(event);
|
||||||
|
|
||||||
const Dock::Position position = qApp->property(PROP_POSITION).value<Dock::Position>();
|
const Dock::Position position = qApp->property(PROP_POSITION).value<Dock::Position>();
|
||||||
// 保持横纵比
|
// 保持横纵比
|
||||||
@ -187,9 +187,9 @@ void BluetoothItem::resizeEvent(QResizeEvent *e)
|
|||||||
refreshIcon();
|
refreshIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BluetoothItem::paintEvent(QPaintEvent *e)
|
void BluetoothItem::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
QWidget::paintEvent(e);
|
QWidget::paintEvent(event);
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
const QRectF &rf = QRectF(rect());
|
const QRectF &rf = QRectF(rect());
|
||||||
|
@ -49,8 +49,8 @@ public:
|
|||||||
bool hasAdapter();
|
bool hasAdapter();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *e);
|
void resizeEvent(QResizeEvent *event);
|
||||||
void paintEvent(QPaintEvent *e);
|
void paintEvent(QPaintEvent *event);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void requestContextMenu() const;
|
void requestContextMenu() const;
|
||||||
|
@ -72,7 +72,7 @@ void Adapter::addDevice(const QJsonObject &deviceObj)
|
|||||||
|
|
||||||
void Adapter::removeDevice(const QString &deviceId)
|
void Adapter::removeDevice(const QString &deviceId)
|
||||||
{
|
{
|
||||||
auto constDevice = m_devices.value(deviceId);
|
const Device *constDevice = m_devices.value(deviceId);
|
||||||
auto device = const_cast<Device *>(constDevice);
|
auto device = const_cast<Device *>(constDevice);
|
||||||
if (device) {
|
if (device) {
|
||||||
m_devices.remove(deviceId);
|
m_devices.remove(deviceId);
|
||||||
@ -82,15 +82,15 @@ void Adapter::removeDevice(const QString &deviceId)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Adapter::updateDevice(const QJsonObject &json)
|
void Adapter::updateDevice(const QJsonObject &dviceJson)
|
||||||
{
|
{
|
||||||
const QString id = json["Path"].toString();
|
const QString id = dviceJson["Path"].toString();
|
||||||
const QString name = json["Alias"].toString();
|
const QString name = dviceJson["Alias"].toString();
|
||||||
const bool paired = json["Paired"].toBool();
|
const bool paired = dviceJson["Paired"].toBool();
|
||||||
const int rssi = json["RSSI"].toInt();
|
const int rssi = dviceJson["RSSI"].toInt();
|
||||||
const Device::State state = Device::State(json["State"].toInt());
|
const Device::State state = Device::State(dviceJson["State"].toInt());
|
||||||
|
|
||||||
auto constdevice = m_devices.value(id);
|
const Device *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);
|
||||||
@ -142,9 +142,9 @@ void Adapter::setPowered(bool powered)
|
|||||||
|
|
||||||
void Adapter::initDevicesList(const QJsonDocument &doc)
|
void Adapter::initDevicesList(const QJsonDocument &doc)
|
||||||
{
|
{
|
||||||
auto arr = doc.array();
|
QJsonArray arr = doc.array();
|
||||||
for (QJsonValue val : arr) {
|
for (QJsonValue val : arr) {
|
||||||
auto deviceObj = val.toObject();
|
QJsonObject deviceObj = val.toObject();
|
||||||
const QString adapterId = deviceObj["AdapterPath"].toString();
|
const QString adapterId = deviceObj["AdapterPath"].toString();
|
||||||
const QString id = deviceObj["Path"].toString();
|
const QString id = deviceObj["Path"].toString();
|
||||||
const QString name = deviceObj["Alias"].toString();
|
const QString name = deviceObj["Alias"].toString();
|
||||||
|
@ -51,7 +51,7 @@ public:
|
|||||||
void initDevicesList(const QJsonDocument &doc);
|
void initDevicesList(const QJsonDocument &doc);
|
||||||
void addDevice(const QJsonObject &deviceObj);
|
void addDevice(const QJsonObject &deviceObj);
|
||||||
void removeDevice(const QString &deviceId);
|
void removeDevice(const QString &deviceId);
|
||||||
void updateDevice(const QJsonObject &json);
|
void updateDevice(const QJsonObject &dviceJson);
|
||||||
void removeAllDevices();
|
void removeAllDevices();
|
||||||
const QMap<QString, const Device *> &paredDevices() const;
|
const QMap<QString, const Device *> &paredDevices() const;
|
||||||
int paredDevicesCount() const;
|
int paredDevicesCount() const;
|
||||||
|
@ -29,6 +29,9 @@
|
|||||||
|
|
||||||
#include <DDBusSender>
|
#include <DDBusSender>
|
||||||
|
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
extern void initFontColor(QWidget *widget);
|
extern void initFontColor(QWidget *widget);
|
||||||
|
|
||||||
AdapterItem::AdapterItem(AdaptersManager *adapterManager, Adapter *adapter, QWidget *parent)
|
AdapterItem::AdapterItem(AdaptersManager *adapterManager, Adapter *adapter, QWidget *parent)
|
||||||
@ -67,15 +70,15 @@ AdapterItem::AdapterItem(AdaptersManager *adapterManager, Adapter *adapter, QWid
|
|||||||
m_centralWidget->setAutoFillBackground(false);
|
m_centralWidget->setAutoFillBackground(false);
|
||||||
viewport()->setAutoFillBackground(false);
|
viewport()->setAutoFillBackground(false);
|
||||||
|
|
||||||
auto myDevices = adapter->devices();
|
QMap<QString, const Device *> myDevices = adapter->devices();
|
||||||
for (auto constDevice : myDevices) {
|
for (const Device *constDevice : myDevices) {
|
||||||
auto device = const_cast<Device *>(constDevice);
|
auto device = const_cast<Device *>(constDevice);
|
||||||
if (device)
|
if (device)
|
||||||
createDeviceItem(device);
|
createDeviceItem(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_initDeviceState = Device::StateUnavailable;
|
m_initDeviceState = Device::StateUnavailable;
|
||||||
for (auto constDevice : myDevices) {
|
for (const Device *constDevice : myDevices) {
|
||||||
auto device = const_cast<Device *>(constDevice);
|
auto device = const_cast<Device *>(constDevice);
|
||||||
if (device) {
|
if (device) {
|
||||||
if (device->state() == Device::StateAvailable) {
|
if (device->state() == Device::StateAvailable) {
|
||||||
@ -133,7 +136,7 @@ void AdapterItem::deviceItemPaired(const bool paired)
|
|||||||
{
|
{
|
||||||
auto device = qobject_cast<Device *>(sender());
|
auto device = qobject_cast<Device *>(sender());
|
||||||
if (device) {
|
if (device) {
|
||||||
auto deviceItem = m_deviceItems.value(device->id());
|
DeviceItem *deviceItem = m_deviceItems.value(device->id());
|
||||||
if (paired) {
|
if (paired) {
|
||||||
m_sortUnConnect.removeOne(deviceItem);
|
m_sortUnConnect.removeOne(deviceItem);
|
||||||
m_sortConnected << deviceItem;
|
m_sortConnected << deviceItem;
|
||||||
@ -149,8 +152,8 @@ void AdapterItem::deviceRssiChanged()
|
|||||||
{
|
{
|
||||||
auto device = qobject_cast<Device *>(sender());
|
auto device = qobject_cast<Device *>(sender());
|
||||||
if (device) {
|
if (device) {
|
||||||
auto deviceItem = m_deviceItems.value(device->id());
|
DeviceItem *deviceItem = m_deviceItems.value(device->id());
|
||||||
auto state = device->state();
|
Device::State state = device->state();
|
||||||
if (deviceItem && Device::StateConnected == state)
|
if (deviceItem && Device::StateConnected == state)
|
||||||
qSort(m_sortConnected);
|
qSort(m_sortConnected);
|
||||||
else
|
else
|
||||||
@ -164,7 +167,7 @@ void AdapterItem::removeDeviceItem(const Device *device)
|
|||||||
if (!device)
|
if (!device)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto deviceItem = m_deviceItems.value(device->id());
|
DeviceItem *deviceItem = m_deviceItems.value(device->id());
|
||||||
if (deviceItem) {
|
if (deviceItem) {
|
||||||
m_deviceItems.remove(device->id());
|
m_deviceItems.remove(device->id());
|
||||||
m_sortConnected.removeOne(deviceItem);
|
m_sortConnected.removeOne(deviceItem);
|
||||||
@ -196,7 +199,7 @@ void AdapterItem::deviceChangeState(const Device::State state)
|
|||||||
{
|
{
|
||||||
auto device = qobject_cast<Device *>(sender());
|
auto device = qobject_cast<Device *>(sender());
|
||||||
if (device) {
|
if (device) {
|
||||||
auto deviceItem = m_deviceItems.value(device->id());
|
DeviceItem *deviceItem = m_deviceItems.value(device->id());
|
||||||
if (deviceItem) {
|
if (deviceItem) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case Device::StateUnavailable: {
|
case Device::StateUnavailable: {
|
||||||
@ -254,7 +257,7 @@ void AdapterItem::createDeviceItem(Device *device)
|
|||||||
if (!device)
|
if (!device)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto deviceId = device->id();
|
QString deviceId = device->id();
|
||||||
auto deviceItem = new DeviceItem(device->name(), this);
|
auto deviceItem = new DeviceItem(device->name(), this);
|
||||||
deviceItem->setDevice(device);
|
deviceItem->setDevice(device);
|
||||||
m_deviceItems[deviceId] = deviceItem;
|
m_deviceItems[deviceId] = deviceItem;
|
||||||
@ -273,14 +276,14 @@ void AdapterItem::createDeviceItem(Device *device)
|
|||||||
|
|
||||||
void AdapterItem::updateView()
|
void AdapterItem::updateView()
|
||||||
{
|
{
|
||||||
auto contentHeight = m_switchItem->height();
|
int contentHeight = m_switchItem->height();
|
||||||
contentHeight += (m_deviceLayout->count() - 3) * ITEMHEIGHT;
|
contentHeight += (m_deviceLayout->count() - 3) * ITEMHEIGHT;
|
||||||
m_centralWidget->setFixedHeight(contentHeight);
|
m_centralWidget->setFixedHeight(contentHeight);
|
||||||
setFixedHeight(contentHeight);
|
setFixedHeight(contentHeight);
|
||||||
emit sizeChange();
|
emit sizeChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdapterItem::showDevices(bool change)
|
void AdapterItem::showDevices(bool powered)
|
||||||
{
|
{
|
||||||
if (m_sortConnected.size())
|
if (m_sortConnected.size())
|
||||||
qSort(m_sortConnected);
|
qSort(m_sortConnected);
|
||||||
@ -291,15 +294,15 @@ void AdapterItem::showDevices(bool change)
|
|||||||
deviceItems << m_sortConnected << m_sortUnConnect;
|
deviceItems << m_sortConnected << m_sortUnConnect;
|
||||||
|
|
||||||
for (DeviceItem *deviceItem : deviceItems) {
|
for (DeviceItem *deviceItem : deviceItems) {
|
||||||
if (change)
|
if (powered)
|
||||||
m_deviceLayout->addWidget(deviceItem);
|
m_deviceLayout->addWidget(deviceItem);
|
||||||
else
|
else
|
||||||
m_deviceLayout->removeWidget(deviceItem);
|
m_deviceLayout->removeWidget(deviceItem);
|
||||||
deviceItem->setVisible(change);
|
deviceItem->setVisible(powered);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto itemCount = m_deviceItems.size();
|
int itemCount = m_deviceItems.size();
|
||||||
m_line->setVisible(change);
|
m_line->setVisible(powered);
|
||||||
m_openControlCenter->setVisible(!itemCount);
|
m_openControlCenter->setVisible(!itemCount);
|
||||||
updateView();
|
updateView();
|
||||||
}
|
}
|
||||||
|
@ -26,10 +26,9 @@
|
|||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
#include <QMap>
|
|
||||||
#include <QVBoxLayout>
|
|
||||||
#include <QLabel>
|
|
||||||
|
|
||||||
|
class QLabel;
|
||||||
|
class QVBoxLayout;
|
||||||
class HorizontalSeparator;
|
class HorizontalSeparator;
|
||||||
class Adapter;
|
class Adapter;
|
||||||
class SwitchItem;
|
class SwitchItem;
|
||||||
@ -65,7 +64,7 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
void createDeviceItem(Device *device);
|
void createDeviceItem(Device *device);
|
||||||
void updateView();
|
void updateView();
|
||||||
void showDevices(bool change);
|
void showDevices(bool powered);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWidget *m_centralWidget;
|
QWidget *m_centralWidget;
|
||||||
@ -77,7 +76,7 @@ private:
|
|||||||
|
|
||||||
Adapter *m_adapter;
|
Adapter *m_adapter;
|
||||||
SwitchItem *m_switchItem;
|
SwitchItem *m_switchItem;
|
||||||
QMap<QString, DeviceItem*> m_deviceItems;
|
QMap<QString, DeviceItem *> m_deviceItems;
|
||||||
Device::State m_initDeviceState;
|
Device::State m_initDeviceState;
|
||||||
Device::State m_currentDeviceState;
|
Device::State m_currentDeviceState;
|
||||||
QList<DeviceItem *> m_sortConnected;
|
QList<DeviceItem *> m_sortConnected;
|
||||||
|
@ -35,6 +35,7 @@ AdaptersManager::AdaptersManager(QObject *parent)
|
|||||||
"/com/deepin/daemon/Bluetooth",
|
"/com/deepin/daemon/Bluetooth",
|
||||||
QDBusConnection::sessionBus(),
|
QDBusConnection::sessionBus(),
|
||||||
this))
|
this))
|
||||||
|
, m_defaultAdapterState(false)
|
||||||
{
|
{
|
||||||
connect(m_bluetoothInter, &DBusBluetooth::AdapterAdded, this, &AdaptersManager::addAdapter);
|
connect(m_bluetoothInter, &DBusBluetooth::AdapterAdded, this, &AdaptersManager::addAdapter);
|
||||||
connect(m_bluetoothInter, &DBusBluetooth::AdapterRemoved, this, &AdaptersManager::removeAdapter);
|
connect(m_bluetoothInter, &DBusBluetooth::AdapterRemoved, this, &AdaptersManager::removeAdapter);
|
||||||
@ -77,10 +78,7 @@ AdaptersManager::AdaptersManager(QObject *parent)
|
|||||||
for (int index = 0; index < arr.size(); index++) {
|
for (int index = 0; index < arr.size(); index++) {
|
||||||
auto *adapter = new Adapter(this);
|
auto *adapter = new Adapter(this);
|
||||||
adapterAdd(adapter, arr[index].toObject());
|
adapterAdd(adapter, arr[index].toObject());
|
||||||
if (!index) {
|
m_defaultAdapterState |= adapter->powered();
|
||||||
adapter->setCurrent(true);
|
|
||||||
m_defaultAdapterState = adapter->powered();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +177,7 @@ void AdaptersManager::onDevicePropertiesChanged(const QString &json)
|
|||||||
{
|
{
|
||||||
const QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
|
const QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
|
||||||
const QJsonObject obj = doc.object();
|
const QJsonObject obj = doc.object();
|
||||||
for (auto constAdapter : m_adapters) {
|
for (const Adapter *constAdapter : m_adapters) {
|
||||||
auto adapter = const_cast<Adapter *>(constAdapter);
|
auto adapter = const_cast<Adapter *>(constAdapter);
|
||||||
if (adapter)
|
if (adapter)
|
||||||
adapter->updateDevice(obj);
|
adapter->updateDevice(obj);
|
||||||
@ -254,7 +252,7 @@ void AdaptersManager::adapterAdd(Adapter *adapter, const QJsonObject &adpterObj)
|
|||||||
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());
|
QJsonDocument doc = QJsonDocument::fromJson(replyStr.toUtf8());
|
||||||
adapter->initDevicesList(doc);
|
adapter->initDevicesList(doc);
|
||||||
emit this->adapterIncreased(adapter);
|
emit this->adapterIncreased(adapter);
|
||||||
} else {
|
} else {
|
||||||
@ -264,7 +262,7 @@ void AdaptersManager::adapterAdd(Adapter *adapter, const QJsonObject &adpterObj)
|
|||||||
delete watcher;
|
delete watcher;
|
||||||
});
|
});
|
||||||
|
|
||||||
auto id = adapter->id();
|
QString id = adapter->id();
|
||||||
if (!id.isEmpty()) {
|
if (!id.isEmpty()) {
|
||||||
m_adapters[id] = adapter;
|
m_adapters[id] = adapter;
|
||||||
}
|
}
|
||||||
|
@ -86,11 +86,11 @@ bool DeviceItem::operator <(const DeviceItem &item)
|
|||||||
return this->device()->rssi() < item.device()->rssi();
|
return this->device()->rssi() < item.device()->rssi();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceItem::setDevice(Device *d)
|
void DeviceItem::setDevice(Device *device)
|
||||||
{
|
{
|
||||||
if (d) {
|
if (device) {
|
||||||
m_device = d;
|
m_device = device;
|
||||||
changeState(d->state());
|
changeState(device->state());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +105,6 @@ void DeviceItem::enterEvent(QEvent *event)
|
|||||||
QWidget::enterEvent(event);
|
QWidget::enterEvent(event);
|
||||||
if (m_device) {
|
if (m_device) {
|
||||||
if (Device::StateConnected == m_device->state()) {
|
if (Device::StateConnected == m_device->state()) {
|
||||||
// m_state->setPixmap(QPixmap(":/notify_close_press@2x.png"));
|
|
||||||
m_state->setPixmap(QPixmap(":/disconnect" + m_statSuffix));
|
m_state->setPixmap(QPixmap(":/disconnect" + m_statSuffix));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,7 +115,6 @@ void DeviceItem::leaveEvent(QEvent *event)
|
|||||||
QWidget::enterEvent(event);
|
QWidget::enterEvent(event);
|
||||||
if (m_device) {
|
if (m_device) {
|
||||||
if (Device::StateConnected == m_device->state()) {
|
if (Device::StateConnected == m_device->state()) {
|
||||||
// m_state->setPixmap(QPixmap(":/list_select@2x.png"));
|
|
||||||
m_state->setPixmap(QPixmap(":/select" + m_statSuffix));
|
m_state->setPixmap(QPixmap(":/select" + m_statSuffix));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public:
|
|||||||
|
|
||||||
inline void setTitle(const QString &name) { m_title->setText(name); }
|
inline void setTitle(const QString &name) { m_title->setText(name); }
|
||||||
|
|
||||||
void setDevice(Device *d);
|
void setDevice(Device *device);
|
||||||
inline Device *device() { return m_device; }
|
inline Device *device() { return m_device; }
|
||||||
inline const Device *device() const { return m_device; }
|
inline const Device *device() const { return m_device; }
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QFontMetrics>
|
#include <QFontMetrics>
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
extern void initFontColor(QWidget *widget);
|
extern void initFontColor(QWidget *widget);
|
||||||
|
|
||||||
@ -40,7 +41,7 @@ SwitchItem::SwitchItem(QWidget *parent)
|
|||||||
m_switchBtn->setFixedWidth(SWITCHBUTTONWIDTH);
|
m_switchBtn->setFixedWidth(SWITCHBUTTONWIDTH);
|
||||||
|
|
||||||
setFixedHeight(CONTROLHEIGHT);
|
setFixedHeight(CONTROLHEIGHT);
|
||||||
auto switchLayout = new QHBoxLayout(this);
|
auto switchLayout = new QHBoxLayout;
|
||||||
switchLayout->setSpacing(0);
|
switchLayout->setSpacing(0);
|
||||||
switchLayout->setMargin(0);
|
switchLayout->setMargin(0);
|
||||||
switchLayout->addSpacing(MARGIN);
|
switchLayout->addSpacing(MARGIN);
|
||||||
|
@ -25,10 +25,9 @@
|
|||||||
|
|
||||||
#include <DSwitchButton>
|
#include <DSwitchButton>
|
||||||
|
|
||||||
#include <QLabel>
|
|
||||||
|
|
||||||
DWIDGET_USE_NAMESPACE
|
DWIDGET_USE_NAMESPACE
|
||||||
|
|
||||||
|
class QLabel;
|
||||||
class SwitchItem : public QWidget
|
class SwitchItem : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Loading…
x
Reference in New Issue
Block a user