feat(bluetooth):add bluetooth plugin

添加蓝牙插件 bug:9128

(cherry picked from commit 7412d26cda31a617318842cb919242558e135a69)

(cherry picked from commit 1f62819e0fc3a97723c386b6cdf2fc68d1318827)
This commit is contained in:
fpc_diesel 2020-05-14 13:09:26 +08:00
parent 5469493e26
commit 1c6a463c15
37 changed files with 2648 additions and 2 deletions

View File

@ -12,3 +12,4 @@ add_subdirectory("onboard")
add_subdirectory("overlay-warning")
add_subdirectory("show-desktop")
add_subdirectory("multitasking")
add_subdirectory("bluetooth")

View File

@ -0,0 +1,35 @@
set(PLUGIN_NAME "bluetooth")
project(${PLUGIN_NAME})
# Sources files
file(GLOB_RECURSE SRCS "*.h" "*.cpp" "../../widgets/*.h" "../../widgets/*.cpp" "../../frame/util/imageutil.h" "../../frame/util/imageutil.cpp")
find_package(PkgConfig REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Svg REQUIRED)
find_package(Qt5DBus REQUIRED)
find_package(DtkWidget REQUIRED)
pkg_check_modules(DFrameworkDBus REQUIRED dframeworkdbus)
pkg_check_modules(QGSettings REQUIRED gsettings-qt)
add_definitions("${QT_DEFINITIONS} -DQT_PLUGIN")
add_library(${PLUGIN_NAME} SHARED ${SRCS} resources/bluetooth.qrc)
set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../system-trays)
target_include_directories(${PLUGIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS}
${DFrameworkDBus_INCLUDE_DIRS}
${QGSettings_INCLUDE_DIRS}
../../interfaces
../../frame)
target_link_libraries(${PLUGIN_NAME} PRIVATE
${DtkWidget_LIBRARIES}
${DFrameworkDBus_LIBRARIES}
${QGSettings_LIBRARIES}
${Qt5DBus_LIBRARIES}
${Qt5Widgets_LIBRARIES}
${Qt5Svg_LIBRARIES}
)
install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION lib/dde-dock/plugins/system-trays)

View File

@ -0,0 +1,4 @@
{
"api": "1.1.1",
"depends-daemon-dbus-service": "com.deepin.daemon.Bluetooth"
}

View File

@ -0,0 +1,144 @@
/*
* 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 "bluetoothapplet.h"
#include "componments/switchitem.h"
#include "componments/deviceitem.h"
#include "componments/adapter.h"
#include "componments/switchitem.h"
const int Width = 200;
BluetoothApplet::BluetoothApplet(QWidget *parent)
: QScrollArea(parent)
, m_line(new HorizontalSeparator(this))
, m_appletName(new QLabel(this))
, m_centralWidget(new QWidget(this))
, m_centrealLayout(new QVBoxLayout)
, m_adaptersManager(new AdaptersManager(this))
{
m_line->setVisible(false);
m_appletName->setText(tr("Bluetooth"));
m_appletName->setVisible(false);
m_centrealLayout->setMargin(0);
m_centrealLayout->setSpacing(0);
m_centrealLayout->addWidget(m_appletName);
m_centrealLayout->addWidget(m_line);
m_centralWidget->setLayout(m_centrealLayout);
m_centralWidget->setFixedWidth(Width);
m_centralWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
setFixedWidth(Width);
setWidget(m_centralWidget);
setFrameShape(QFrame::NoFrame);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_centralWidget->setAutoFillBackground(false);
viewport()->setAutoFillBackground(false);
connect(m_adaptersManager, &AdaptersManager::adapterIncreased, this, &BluetoothApplet::addAdapter);
connect(m_adaptersManager, &AdaptersManager::adapterDecreased, this, &BluetoothApplet::removeAdapter);
}
void BluetoothApplet::setAdapterPowered(bool powered)
{
for (auto adapterItem : m_adapterItems) {
if (adapterItem)
adapterItem->setPowered(powered);
}
}
bool BluetoothApplet::poweredInitState()
{
return m_adaptersManager->defaultAdapterInitPowerState();
}
bool BluetoothApplet::hasAadapter()
{
return m_adaptersManager->adaptersCount();
}
void BluetoothApplet::addAdapter(Adapter *adapter)
{
if (!adapter)
return;
auto adapterId = adapter->id();
auto adatpterItem = new AdapterItem(m_adaptersManager, adapter, this);
m_adapterItems[adapterId] = adatpterItem;
m_centrealLayout->addWidget(adatpterItem);
connect(adatpterItem, &AdapterItem::deviceStateChanged, this, &BluetoothApplet::deviceStateChanged);
connect(adatpterItem, &AdapterItem::powerChanged, this, &BluetoothApplet::powerChanged);
connect(adatpterItem, &AdapterItem::sizeChange, this, &BluetoothApplet::updateView);
updateView();
}
void BluetoothApplet::removeAdapter(Adapter *adapter)
{
if (adapter) {
auto adapterId = adapter->id();
auto adapterItem = m_adapterItems.value(adapterId);
if (adapterItem) {
delete adapterItem;
m_adapterItems.remove(adapterId);
updateView();
if (!m_adapterItems.size())
emit noAdapter();
}
}
}
void BluetoothApplet::updateView()
{
int itemCount = 0;
for (auto adapterItem : m_adapterItems) {
if (adapterItem)
itemCount += adapterItem->pairedDeviceCount();
}
if (m_adapterItems.size() > 1) {
m_line->setVisible(true);
m_appletName->setVisible(true);
} else {
m_line->setVisible(false);
m_appletName->setVisible(false);
}
int contentHeight = 0;
if (itemCount <= 16) {
contentHeight = m_centralWidget->sizeHint().height();
m_centralWidget->setFixedHeight(contentHeight);
setFixedHeight(contentHeight);
if (16 == itemCount)
sixteenDeviceHeight = contentHeight;
} else {
contentHeight = m_centralWidget->sizeHint().height();
m_centralWidget->setFixedHeight(contentHeight);
setFixedHeight(sixteenDeviceHeight);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
}
}

View File

@ -0,0 +1,66 @@
/*
* 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 BLUETOOTHAPPLET_H
#define BLUETOOTHAPPLET_H
#include "componments/adaptersmanager.h"
#include "componments/adapteritem.h"
#include <QLabel>
#include <QVBoxLayout>
class AdapterItem;
class BluetoothApplet : public QScrollArea
{
Q_OBJECT
public:
explicit BluetoothApplet(QWidget *parent = nullptr);
void setAdapterPowered(bool powered);
bool poweredInitState();
bool hasAadapter();
public slots :
void addAdapter(Adapter *constadapter);
void removeAdapter(Adapter *adapter);
signals:
void powerChanged(bool state);
void deviceStateChanged(int state);
void noAdapter();
private:
void updateView();
private:
HorizontalSeparator *m_line;
QLabel *m_appletName;
QWidget *m_centralWidget;
QVBoxLayout *m_centrealLayout;
int sixteenDeviceHeight = 0;
AdaptersManager *m_adaptersManager;
QMap<QString, AdapterItem *> m_adapterItems;
};
#endif // BLUETOOTHAPPLET_H

View File

@ -0,0 +1,171 @@
/*
* 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 "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 <DGuiApplicationHelper>
// menu actions
#define SHIFT "shift"
#define SETTINGS "settings"
DWIDGET_USE_NAMESPACE
DGUI_USE_NAMESPACE
BluetoothItem::BluetoothItem(QWidget *parent)
: QWidget(parent)
, m_applet(new BluetoothApplet(this))
{
m_applet->setVisible(false);
m_adapterPowered = m_applet->poweredInitState();
connect(m_applet, &BluetoothApplet::powerChanged, [&](bool powered) {
m_adapterPowered = powered;
refreshIcon();
});
connect(m_applet, &BluetoothApplet::deviceStateChanged, [&](int state) {
m_devState = state;
refreshIcon();
});
connect(m_applet, SIGNAL(noAdapter()), this, SIGNAL(noAdapter()));
}
//QWidget *BluetoothItem::tipsWidget()
//{
//}
QWidget *BluetoothItem::popupApplet()
{
return m_applet->hasAadapter() ? m_applet : nullptr;
}
const QString BluetoothItem::contextMenu() const
{
QList<QVariant> items;
if (m_applet->hasAadapter()) {
items.reserve(2);
QMap<QString, QVariant> shift;
shift["itemId"] = SHIFT;
if (m_adapterPowered)
shift["itemText"] = tr("Turn off");
else
shift["itemText"] = tr("Turn on");
shift["isActive"] = true;
items.push_back(shift);
QMap<QString, QVariant> settings;
settings["itemId"] = SETTINGS;
settings["itemText"] = tr("Bluetooth settings");
settings["isActive"] = true;
items.push_back(settings);
QMap<QString, QVariant> menu;
menu["items"] = items;
menu["checkableMenu"] = false;
menu["singleCheck"] = false;
return QJsonDocument::fromVariant(menu).toJson();
}
return QByteArray();
}
void BluetoothItem::invokeMenuItem(const QString menuId, const bool checked)
{
Q_UNUSED(checked);
if (menuId == SHIFT) {
m_applet->setAdapterPowered(!m_adapterPowered);
}
else if (menuId == SETTINGS)
DDBusSender()
.service("com.deepin.dde.ControlCenter")
.interface("com.deepin.dde.ControlCenter")
.path("/com/deepin/dde/ControlCenter")
.method(QString("ShowModule"))
.arg(QString("bluetooth"))
.call();
}
void BluetoothItem::refreshIcon()
{
if (!m_applet)
return;
QString stateString;
m_adapterPowered ? (m_devState == 2 ? stateString = "waiting" : stateString = "active") : stateString = "disable";
QString iconString = QString("bluetooth-%1-symbolic").arg(stateString);
const auto ratio = devicePixelRatioF();
int iconSize = PLUGIN_ICON_MAX_SIZE;
if (height() <= PLUGIN_BACKGROUND_MIN_SIZE && DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType)
iconString.append(PLUGIN_MIN_ICON_NAME);
m_iconPixmap = ImageUtil::loadSvg(iconString, ":/", iconSize, ratio);
update();
}
bool BluetoothItem::hasAdapter()
{
return m_applet->hasAadapter();
}
void BluetoothItem::resizeEvent(QResizeEvent *e)
{
QWidget::resizeEvent(e);
const Dock::Position position = qApp->property(PROP_POSITION).value<Dock::Position>();
// 保持横纵比
if (position == Dock::Bottom || position == Dock::Top) {
setMaximumWidth(height());
setMaximumHeight(QWIDGETSIZE_MAX);
} else {
setMaximumHeight(width());
setMaximumWidth(QWIDGETSIZE_MAX);
}
refreshIcon();
}
void BluetoothItem::paintEvent(QPaintEvent *e)
{
QWidget::paintEvent(e);
QPainter painter(this);
const QRectF &rf = QRectF(rect());
const QRectF &rfp = QRectF(m_iconPixmap.rect());
painter.drawPixmap(rf.center() - rfp.center() / m_iconPixmap.devicePixelRatioF(), m_iconPixmap);
}

View File

@ -0,0 +1,67 @@
/*
* 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 BLUETOOTHITEM_H
#define BLUETOOTHITEM_H
#include <QWidget>
#include <QIcon>
#define BLUETOOTH_KEY "bluetooth-item-key"
class BluetoothApplet;
class TipsWidget;
class BluetoothItem : public QWidget
{
Q_OBJECT
public:
explicit BluetoothItem(QWidget *parent = nullptr);
// QWidget *tipsWidget();
QWidget *popupApplet();
const QString contextMenu() const;
void invokeMenuItem(const QString menuId, const bool checked);
void refreshIcon();
bool hasAdapter();
protected:
void resizeEvent(QResizeEvent *e);
void paintEvent(QPaintEvent *e);
signals:
void requestContextMenu() const;
void noAdapter();
private:
// TipsWidget *m_tipsLabel;
BluetoothApplet *m_applet;
QPixmap m_iconPixmap;
int m_devState;
bool m_adapterPowered;
};
#endif // BLUETOOTHITEM_H

View File

@ -0,0 +1,147 @@
/*
* 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 "bluetoothplugin.h"
#define STATE_KEY "enable"
BluetoothPlugin::BluetoothPlugin(QObject *parent)
: QObject(parent),
m_bluetoothItem(nullptr)
{
}
const QString BluetoothPlugin::pluginName() const
{
return "bluetooth";
}
const QString BluetoothPlugin::pluginDisplayName() const
{
return tr("Bluetooth");
}
void BluetoothPlugin::init(PluginProxyInterface *proxyInter)
{
m_proxyInter = proxyInter;
m_bluetoothItem = new BluetoothItem;
connect(m_bluetoothItem, &BluetoothItem::noAdapter, [&]{
m_enableState = false;
pluginIsDisable();
});
m_enableState = m_bluetoothItem->hasAdapter();
if (!pluginIsDisable())
m_proxyInter->itemAdded(this, BLUETOOTH_KEY);
}
void BluetoothPlugin::pluginStateSwitched()
{
m_proxyInter->saveValue(this, STATE_KEY, pluginIsDisable());
refreshPluginItemsVisible();
}
bool BluetoothPlugin::pluginIsDisable()
{
return !m_proxyInter->getValue(this, STATE_KEY, m_enableState).toBool();
}
QWidget *BluetoothPlugin::itemWidget(const QString &itemKey)
{
if (itemKey == BLUETOOTH_KEY) {
return m_bluetoothItem;
}
return nullptr;
}
//QWidget *BluetoothPlugin::itemTipsWidget(const QString &itemKey)
//{
// if (itemKey == BLUETOOTH_KEY) {
// return m_bluetoothItem->tipsWidget();
// }
// return nullptr;
//}
QWidget *BluetoothPlugin::itemPopupApplet(const QString &itemKey)
{
if (itemKey == BLUETOOTH_KEY) {
return m_bluetoothItem->popupApplet();
}
return nullptr;
}
const QString BluetoothPlugin::itemContextMenu(const QString &itemKey)
{
if (itemKey == BLUETOOTH_KEY) {
return m_bluetoothItem->contextMenu();
}
return QString();
}
void BluetoothPlugin::invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked)
{
if (itemKey == BLUETOOTH_KEY) {
m_bluetoothItem->invokeMenuItem(menuId, checked);
}
}
int BluetoothPlugin::itemSortKey(const QString &itemKey)
{
const QString key = QString("pos_%1_%2").arg(itemKey).arg(Dock::Efficient);
return m_proxyInter->getValue(this, key, 5).toInt();
}
void BluetoothPlugin::setSortKey(const QString &itemKey, const int order)
{
const QString key = QString("pos_%1_%2").arg(itemKey).arg(Dock::Efficient);
m_proxyInter->saveValue(this, key, order);
}
void BluetoothPlugin::refreshIcon(const QString &itemKey)
{
if (itemKey == BLUETOOTH_KEY) {
m_bluetoothItem->refreshIcon();
}
}
void BluetoothPlugin::pluginSettingsChanged()
{
refreshPluginItemsVisible();
}
void BluetoothPlugin::refreshPluginItemsVisible()
{
if (pluginIsDisable())
m_proxyInter->itemRemoved(this, BLUETOOTH_KEY);
else
m_proxyInter->itemAdded(this, BLUETOOTH_KEY);
}

View File

@ -0,0 +1,62 @@
/*
* 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 BLUETOOTHPLUGIN_H
#define BLUETOOTHPLUGIN_H
#include "pluginsiteminterface.h"
#include "bluetoothitem.h"
class BluetoothPlugin : public QObject, PluginsItemInterface
{
Q_OBJECT
Q_INTERFACES(PluginsItemInterface)
Q_PLUGIN_METADATA(IID "com.deepin.dock.PluginsItemInterface" FILE "bluetooth.json")
public:
explicit BluetoothPlugin(QObject *parent = nullptr);
const QString pluginName() const Q_DECL_OVERRIDE;
const QString pluginDisplayName() const Q_DECL_OVERRIDE;
void init(PluginProxyInterface *proxyInter) Q_DECL_OVERRIDE;
void pluginStateSwitched() Q_DECL_OVERRIDE;
bool pluginIsAllowDisable() Q_DECL_OVERRIDE { return true; }
bool pluginIsDisable() Q_DECL_OVERRIDE;
QWidget *itemWidget(const QString &itemKey) Q_DECL_OVERRIDE;
// QWidget *itemTipsWidget(const QString &itemKey) Q_DECL_OVERRIDE;
QWidget *itemPopupApplet(const QString &itemKey) Q_DECL_OVERRIDE;
const QString itemContextMenu(const QString &itemKey) Q_DECL_OVERRIDE;
void invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked) Q_DECL_OVERRIDE;
int itemSortKey(const QString &itemKey) Q_DECL_OVERRIDE;
void setSortKey(const QString &itemKey, const int order) Q_DECL_OVERRIDE;
void refreshIcon(const QString &itemKey) Q_DECL_OVERRIDE;
void pluginSettingsChanged() Q_DECL_OVERRIDE;
private:
void refreshPluginItemsVisible();
private:
BluetoothItem *m_bluetoothItem;
bool m_enableState = true;
};
#endif // BLUETOOTHPLUGIN_H

View File

@ -0,0 +1,175 @@
/*
* 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 "adapter.h"
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonValue>
Adapter::Adapter(QObject *parent)
: QObject(parent)
, m_id("")
, m_name("")
, m_powered(false)
, m_current(false)
{
}
void Adapter::setName(const QString &name)
{
if (name != m_name) {
m_name = name;
Q_EMIT nameChanged(name);
}
}
void Adapter::addDevice(const QJsonObject &deviceObj)
{
const QString id = deviceObj["Path"].toString();
const QString name = deviceObj["Alias"].toString();
const bool paired = deviceObj["Paired"].toBool();
const Device::State state = Device::State(deviceObj["State"].toInt());
removeDevice(id);
auto device = new Device(this);
device->setId(id);
device->setName(name);
device->setPaired(paired);
device->setState(state);
device->setAdapterId(m_id);
m_devices[id] = device;
divideDevice(device);
emit deviceAdded(device);
}
void Adapter::removeDevice(const QString &deviceId)
{
auto constDevice = m_devices.value(deviceId);
auto device = const_cast<Device *>(constDevice);
if (device) {
m_devices.remove(deviceId);
m_paredDev.remove(deviceId);
emit deviceRemoved(device);
delete device;
}
}
void Adapter::updateDevice(const QJsonObject &json)
{
const QString id = json["Path"].toString();
const QString name = json["Alias"].toString();
const bool paired = json["Paired"].toBool();
const Device::State state = Device::State(json["State"].toInt());
auto constdevice = m_devices.value(id);
auto device = const_cast<Device *>(constdevice);
if (device) {
device->setId(id);
device->setName(name);
device->setPaired(paired);
device->setState(state);
}
}
void Adapter::removeAllDevices()
{
QMapIterator<QString, const Device *> iterator(m_devices);
while (iterator.hasNext()) {
iterator.next();
auto device = const_cast<Device *>(iterator.value());
if (device) {
m_devices.remove(device->id());
m_paredDev.remove(device->id());
delete device;
}
}
}
const QMap<QString, const Device *> &Adapter::paredDevices() const
{
return m_paredDev;
}
int Adapter::paredDevicesCount() const
{
return m_paredDev.size();
}
void Adapter::divideDevice(const Device *device)
{
if (device->paired()) {
m_paredDev[device->id()] = device;
}
}
void Adapter::setPowered(bool powered)
{
if (powered != m_powered) {
m_powered = powered;
Q_EMIT poweredChanged(powered);
}
}
void Adapter::initDevicesList(const QJsonDocument &doc)
{
auto arr = doc.array();
for (QJsonValue val : arr) {
auto deviceObj = val.toObject();
const QString adapterId = deviceObj["AdapterPath"].toString();
const QString id = deviceObj["Path"].toString();
const QString name = deviceObj["Alias"].toString();
const bool paired = deviceObj["Paired"].toBool();
const Device::State state = Device::State(deviceObj["State"].toInt());
auto device = new Device(this);
device->setId(id);
device->setName(name);
device->setPaired(paired);
device->setState(state);
device->setAdapterId(adapterId);
m_devices[id] = device;
divideDevice(device);
}
}
QMap<QString, const Device *> Adapter::devices() const
{
return m_devices;
}
const Device *Adapter::deviceById(const QString &id) const
{
return m_devices.keys().contains(id) ? m_devices[id] : nullptr;
}
void Adapter::setId(const QString &id)
{
m_id = id;
}

View File

@ -0,0 +1,76 @@
/*
* 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 ADAPTER_H
#define ADAPTER_H
#include "device.h"
class Adapter : public QObject
{
Q_OBJECT
public:
explicit Adapter(QObject *parent = nullptr);
inline QString name() const { return m_name; }
void setName(const QString &name);
inline QString id() const { return m_id; }
void setId(const QString &id);
QMap<QString, const Device *> devices() const;
const Device *deviceById(const QString &id) const;
inline bool powered() const { return m_powered; }
void setPowered(bool powered);
inline bool isCurrent() { return m_current; }
inline void setCurrent(bool c) { m_current = c; }
void initDevicesList(const QJsonDocument &doc);
void addDevice(const QJsonObject &deviceObj);
void removeDevice(const QString &deviceId);
void updateDevice(const QJsonObject &json);
void removeAllDevices();
const QMap<QString, const Device *> &paredDevices() const;
int paredDevicesCount() const;
Q_SIGNALS:
void nameChanged(const QString &name) const;
void deviceAdded(const Device *device) const;
void deviceRemoved(const Device *device) const;
void poweredChanged(const bool powered) const;
private:
void divideDevice(const Device *device);
private:
QString m_id;
QString m_name;
bool m_powered;
bool m_current;
QMap<QString, const Device *> m_devices;
QMap<QString, const Device *> m_paredDev;
};
#endif // ADAPTER_H

View File

@ -0,0 +1,187 @@
#include "adapteritem.h"
#include "switchitem.h"
#include "deviceitem.h"
#include "adapter.h"
#include "adaptersmanager.h"
#include <DDBusSender>
const int Width = 200;
AdapterItem::AdapterItem(AdaptersManager *adapterManager, Adapter *adapter, QWidget *parent)
: QScrollArea(parent)
, m_centralWidget(new QWidget(this))
, m_line(new HorizontalSeparator(this))
, m_devGoupName(new QLabel(this))
, m_deviceLayout(new QVBoxLayout)
, m_openControlCenter(new MenueItem(this))
, m_adaptersManager(adapterManager)
, m_adapter(adapter)
, m_switchItem(new SwitchItem(this))
{
m_centralWidget->setFixedWidth(Width);
m_line->setVisible(true);
m_devGoupName->setText(tr("My Device"));
m_devGoupName->setVisible(false);
m_deviceLayout->setMargin(0);
m_deviceLayout->setSpacing(0);
m_openControlCenter->setText("Bluetooth settings");
m_openControlCenter->setVisible(false);
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);
m_deviceLayout->addWidget(m_openControlCenter);
m_centralWidget->setFixedWidth(Width);
m_centralWidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
m_centralWidget->setLayout(m_deviceLayout);
setFixedWidth(Width);
setWidget(m_centralWidget);
setFrameShape(QFrame::NoFrame);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_centralWidget->setAutoFillBackground(false);
viewport()->setAutoFillBackground(false);
auto myDevices = adapter->devices();
for (auto constDevice : myDevices) {
auto device = const_cast<Device *>(constDevice);
if (device) {
createDeviceItem(device);
}
}
connect(m_switchItem, &SwitchItem::checkedChanged, this, &AdapterItem::showAndConnect);
connect(adapter, &Adapter::nameChanged, m_switchItem, &SwitchItem::setTitle);
connect(adapter, &Adapter::deviceAdded, this, &AdapterItem::addDeviceItem);
connect(adapter, &Adapter::deviceRemoved, this, &AdapterItem::removeDeviceItem);
connect(adapter, &Adapter::poweredChanged, m_switchItem, &SwitchItem::setChecked);
connect(m_openControlCenter, &MenueItem::clicked, []{
DDBusSender()
.service("com.deepin.dde.ControlCenter")
.interface("com.deepin.dde.ControlCenter")
.path("/com/deepin/dde/ControlCenter")
.method(QString("ShowModule"))
.arg(QString("bluetooth"))
.call();
});
showDevices(adapter->powered());
}
int AdapterItem::pairedDeviceCount()
{
return m_pairedDeviceItems.size();
}
int AdapterItem::deviceCount()
{
return m_deviceItems.size();
}
void AdapterItem::setPowered(bool powered)
{
m_switchItem->setChecked(powered);
}
void AdapterItem::deviceItemPaired(const bool paired)
{
auto device = qobject_cast<Device *>(sender());
if (device) {
auto deviceId = device->id();
auto deviceItem = m_deviceItems.value(deviceId);
if (deviceItem) {
if (paired)
m_pairedDeviceItems[deviceId] = deviceItem;
else
m_pairedDeviceItems.remove(deviceId);
}
showDevices(m_adapter->powered());
}
}
void AdapterItem::removeDeviceItem(const Device *device)
{
if (!device)
return;
auto deviceItem = m_deviceItems.value(device->id());
if (deviceItem) {
m_deviceItems.remove(device->id());
if (device->paired()) {
m_pairedDeviceItems.remove(device->id());
m_deviceLayout->removeWidget(deviceItem);
}
delete deviceItem;
showDevices(m_adapter->powered());
}
}
void AdapterItem::showAndConnect(bool change)
{
showDevices(change);
m_adaptersManager->setAdapterPowered(m_adapter, change);
if (change) {
m_adaptersManager->connectAllPairedDevice(m_adapter);
}
emit powerChanged(change);
}
void AdapterItem::addDeviceItem(const Device *constDevice)
{
auto device = const_cast<Device *>(constDevice);
if (!device)
return;
createDeviceItem(device);
showDevices(m_adapter->powered());
}
void AdapterItem::createDeviceItem(Device *device)
{
if (!device)
return;
auto paired = device->paired();
auto deviceId = device->id();
auto deviceItem = new DeviceItem(device->name(), this);
deviceItem->setDevice(device);
m_deviceItems[deviceId] = deviceItem;
if (paired)
m_pairedDeviceItems[deviceId] = deviceItem;
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()
{
auto contentHeight = m_centralWidget->sizeHint().height();
m_centralWidget->setFixedHeight(contentHeight);
setFixedHeight(contentHeight);
emit sizeChange();
}
void AdapterItem::showDevices(bool change)
{
for (auto deviceItem : m_pairedDeviceItems) {
if (change)
m_deviceLayout->addWidget(deviceItem);
else {
m_deviceLayout->removeWidget(deviceItem);
}
deviceItem->setVisible(change);
}
auto itemCount = m_pairedDeviceItems.size();
m_line->setVisible(change);
m_devGoupName->setVisible(itemCount && change);
m_openControlCenter->setVisible(!itemCount);
updateView();
}

View File

@ -0,0 +1,56 @@
#ifndef ADAPTERITEM_H
#define ADAPTERITEM_H
#include <QScrollArea>
#include <QMap>
#include <QVBoxLayout>
#include <QLabel>
class HorizontalSeparator;
class Adapter;
class SwitchItem;
class DeviceItem;
class Device;
class AdaptersManager;
class MenueItem;
class AdapterItem : public QScrollArea
{
Q_OBJECT
public:
explicit AdapterItem(AdaptersManager *a, Adapter *adapter, QWidget *parent = nullptr);
int pairedDeviceCount();
int deviceCount();
void setPowered(bool powered);
signals:
void deviceStateChanged(int state);
void powerChanged(bool powered);
void sizeChange();
private slots:
void deviceItemPaired(const bool paired);
void removeDeviceItem(const Device *device);
void showAndConnect(bool change);
void addDeviceItem(const Device *constDevice);
private:
void createDeviceItem(Device *device);
void updateView();
void showDevices(bool change);
private:
QWidget *m_centralWidget;
HorizontalSeparator *m_line;
QLabel *m_devGoupName;
QVBoxLayout *m_deviceLayout;
MenueItem *m_openControlCenter;
AdaptersManager *m_adaptersManager;
Adapter *m_adapter;
SwitchItem *m_switchItem;
QMap<QString, DeviceItem*> m_deviceItems;
QMap<QString, DeviceItem*> m_pairedDeviceItems;
};
#endif // ADAPTERITEM_H

View File

@ -0,0 +1,283 @@
/*
* 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 "adaptersmanager.h"
#include <QDBusInterface>
#include <QDBusReply>
#include <QJsonDocument>
#include <QJsonArray>
AdaptersManager::AdaptersManager(QObject *parent)
: QObject(parent)
, m_bluetoothInter(new DBusBluetooth("com.deepin.daemon.Bluetooth",
"/com/deepin/daemon/Bluetooth",
QDBusConnection::sessionBus(),
this))
{
connect(m_bluetoothInter, &DBusBluetooth::AdapterAdded, this, &AdaptersManager::addAdapter);
connect(m_bluetoothInter, &DBusBluetooth::AdapterRemoved, this, &AdaptersManager::removeAdapter);
connect(m_bluetoothInter, &DBusBluetooth::AdapterPropertiesChanged, this, &AdaptersManager::onAdapterPropertiesChanged);
connect(m_bluetoothInter, &DBusBluetooth::DeviceAdded, this, &AdaptersManager::addDevice);
connect(m_bluetoothInter, &DBusBluetooth::DeviceRemoved, this, &AdaptersManager::removeDevice);
connect(m_bluetoothInter, &DBusBluetooth::DevicePropertiesChanged, this, &AdaptersManager::onDevicePropertiesChanged);
connect(m_bluetoothInter, &DBusBluetooth::RequestAuthorization, this, [](const QDBusObjectPath & in0) {
qDebug() << "request authorization: " << in0.path();
});
connect(m_bluetoothInter, &DBusBluetooth::RequestPasskey, this, [](const QDBusObjectPath & in0) {
qDebug() << "request passkey: " << in0.path();
});
connect(m_bluetoothInter, &DBusBluetooth::RequestPinCode, this, [](const QDBusObjectPath & in0) {
qDebug() << "request pincode: " << in0.path();
});
connect(m_bluetoothInter, &DBusBluetooth::DisplayPasskey, this, [](const QDBusObjectPath & in0, uint in1, uint in2) {
qDebug() << "request display passkey: " << in0.path() << in1 << in2;
});
connect(m_bluetoothInter, &DBusBluetooth::DisplayPinCode, this, [](const QDBusObjectPath & in0, const QString & in1) {
qDebug() << "request display pincode: " << in0.path() << in1;
});
QDBusInterface *inter = new QDBusInterface("com.deepin.daemon.Bluetooth",
"/com/deepin/daemon/Bluetooth",
"com.deepin.daemon.Bluetooth",
QDBusConnection::sessionBus());
QDBusReply<QString> reply = inter->call(QDBus::Block, "GetAdapters");
const QString replyStr = reply.value();
QJsonDocument doc = QJsonDocument::fromJson(replyStr.toUtf8());
QJsonArray arr = doc.array();
for (int index = 0; index < arr.size(); index++) {
auto *adapter = new Adapter(this);
adapterAdd(adapter, arr[index].toObject());
if (!index) {
adapter->setCurrent(true);
m_defaultAdapterState = adapter->powered();
}
}
}
QMap<QString, const Adapter *> AdaptersManager::adapters() const
{
return m_adapters;
}
const Adapter *AdaptersManager::adapterById(const QString &id)
{
return m_adapters.keys().contains(id) ? m_adapters[id] : nullptr;
}
void AdaptersManager::setAdapterPowered(const Adapter *adapter, const bool &powered)
{
if (adapter) {
QDBusObjectPath path(adapter->id());
QDBusPendingCall call = m_bluetoothInter->SetAdapterPowered(path, powered);
if (powered) {
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
connect(watcher, &QDBusPendingCallWatcher::finished, [this, call, adapter] {
if (!call.isError())
{
QDBusObjectPath dPath(adapter->id());
m_bluetoothInter->SetAdapterDiscoverableTimeout(dPath, 60 * 5);
m_bluetoothInter->SetAdapterDiscoverable(dPath, true);
m_bluetoothInter->RequestDiscovery(dPath);
} else
{
qWarning() << call.error().message();
}
});
}
}
}
void AdaptersManager::connectAllPairedDevice(const Adapter *adapter)
{
for (const Device *d : adapter->devices()) {
Device *vd = const_cast<Device *>(d);
if (vd) {
QDBusObjectPath path(vd->id());
m_bluetoothInter->ConnectDevice(path);
qDebug() << "connect to device: " << vd->name();
}
}
}
void AdaptersManager::connectDevice(Device *device)
{
if (device) {
QDBusObjectPath path(device->id());
switch (device->state()) {
case 0:
{
m_bluetoothInter->ConnectDevice(path);
qDebug() << "connect to device: " << device->name();
}
break;
case 1:
break;
case 2:
{
m_bluetoothInter->DisconnectDevice(path);
qDebug() << "disconnect device: " << device->name();
}
break;
}
}
}
bool AdaptersManager::defaultAdapterInitPowerState()
{
return m_defaultAdapterState;
}
int AdaptersManager::adaptersCount()
{
return m_adapters.size();
}
void AdaptersManager::onAdapterPropertiesChanged(const QString &json)
{
const QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
const QJsonObject obj = doc.object();
const QString id = obj["Path"].toString();
Adapter *adapter = const_cast<Adapter *>(m_adapters[id]);
if (adapter) {
inflateAdapter(adapter, obj);
}
}
void AdaptersManager::onDevicePropertiesChanged(const QString &json)
{
const QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
const QJsonObject obj = doc.object();
for (auto constAdapter : m_adapters) {
auto adapter = const_cast<Adapter *>(constAdapter);
if (adapter)
adapter->updateDevice(obj);
}
}
void AdaptersManager::addAdapter(const QString &json)
{
const QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
auto adapter = new Adapter(this);
adapterAdd(adapter, doc.object());
}
void AdaptersManager::removeAdapter(const QString &json)
{
QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
QJsonObject obj = doc.object();
const QString id = obj["Path"].toString();
const Adapter *result = m_adapters[id];
Adapter *adapter = const_cast<Adapter *>(result);
if (adapter) {
m_adapters.remove(id);
emit adapterDecreased(adapter);
adapter->deleteLater();
}
}
void AdaptersManager::addDevice(const QString &json)
{
const QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
const QJsonObject obj = doc.object();
const QString adapterId = obj["AdapterPath"].toString();
const QString deviceId = obj["Path"].toString();
const Adapter *result = m_adapters[adapterId];
Adapter *adapter = const_cast<Adapter *>(result);
if (adapter) {
const Device *result1 = adapter->deviceById(deviceId);
Device *device = const_cast<Device *>(result1);
if (!device) {
adapter->addDevice(obj);
}
}
}
void AdaptersManager::removeDevice(const QString &json)
{
QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
QJsonObject obj = doc.object();
const QString adapterId = obj["AdapterPath"].toString();
const QString deviceId = obj["Path"].toString();
const Adapter *result = m_adapters[adapterId];
Adapter *adapter = const_cast<Adapter *>(result);
if (adapter) {
adapter->removeDevice(deviceId);
}
}
void AdaptersManager::adapterAdd(Adapter *adapter, const QJsonObject &adpterObj)
{
if (!adapter)
return;
inflateAdapter(adapter, adpterObj);
QDBusObjectPath dPath(adpterObj["Path"].toString());
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()) {
QDBusReply<QString> reply = call.reply();
const QString replyStr = reply.value();
auto doc = QJsonDocument::fromJson(replyStr.toUtf8());
adapter->initDevicesList(doc);
emit this->adapterIncreased(adapter);
} else {
qWarning() << call.error().message();
}
}
delete watcher;
});
auto id = adapter->id();
if (!id.isEmpty()) {
m_adapters[id] = adapter;
}
}
void AdaptersManager::inflateAdapter(Adapter *adapter, const QJsonObject &adapterObj)
{
if (!adapter)
return;
const QString path = adapterObj["Path"].toString();
const QString alias = adapterObj["Alias"].toString();
const bool powered = adapterObj["Powered"].toBool();
adapter->setId(path);
adapter->setName(alias);
adapter->setPowered(powered);
}

View File

@ -0,0 +1,71 @@
/*
* 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 ADAPTERSMANAGER_H
#define ADAPTERSMANAGER_H
#include "adapter.h"
#include <com_deepin_daemon_bluetooth.h>
using DBusBluetooth = com::deepin::daemon::Bluetooth;
class AdaptersManager : public QObject
{
Q_OBJECT
public:
explicit AdaptersManager(QObject *parent = nullptr);
QMap<QString, const Adapter *> adapters() const;
const Adapter *adapterById(const QString &id);
void setAdapterPowered(const Adapter *adapter, const bool &powered);
void connectAllPairedDevice(const Adapter *adapter);
void connectDevice(Device *deviceId);
bool defaultAdapterInitPowerState();
int adaptersCount();
signals:
void adapterIncreased(Adapter *adapter);
void adapterDecreased(Adapter *adapter);
private slots:
void onAdapterPropertiesChanged(const QString &json);
void onDevicePropertiesChanged(const QString &json);
void addAdapter(const QString &json);
void removeAdapter(const QString &json);
void addDevice(const QString &json);
void removeDevice(const QString &json);
private:
void adapterAdd(Adapter *adapter, const QJsonObject &adpterObj);
void inflateAdapter(Adapter *adapter, const QJsonObject &adapterObj);
private:
DBusBluetooth *m_bluetoothInter;
QMap<QString, const Adapter *> m_adapters;
bool m_defaultAdapterState;
};
#endif // ADAPTERSMANAGER_H

View File

@ -0,0 +1,89 @@
/*
* 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 "device.h"
Device::Device(QObject *parent) :
QObject(parent),
m_id(""),
m_name(""),
m_paired(false),
m_trusted(false),
m_connecting(false),
m_state(StateUnavailable),
m_adapterId(QString())
{
}
void Device::setId(const QString &id)
{
m_id = id;
}
void Device::setName(const QString &name)
{
if (name != m_name) {
m_name = name;
Q_EMIT nameChanged(name);
}
}
void Device::setPaired(bool paired)
{
if (paired != m_paired) {
m_paired = paired;
Q_EMIT pairedChanged(paired);
}
}
void Device::setState(const State &state)
{
if (state != m_state) {
m_state = state;
Q_EMIT stateChanged(state);
}
}
void Device::setTrusted(bool trusted)
{
if (trusted != m_trusted) {
m_trusted = trusted;
Q_EMIT trustedChanged(trusted);
}
}
void Device::setConnecting(bool connecting)
{
if (connecting != m_connecting) {
m_connecting = connecting;
Q_EMIT connectingChanged(connecting);
}
}
QDebug &operator<<(QDebug &stream, const Device *device)
{
stream << "Device name:" << device->name()
<< " paired:" << device->paired()
<< " state:" << device->state();
return stream;
}

View File

@ -0,0 +1,84 @@
/*
* 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 DEVICE_H
#define DEVICE_H
#include <QObject>
#include <QDebug>
class Device : public QObject
{
Q_OBJECT
public:
enum State {
StateUnavailable = 0,
StateAvailable = 1,
StateConnected = 2
};
Q_ENUM(State)
public:
explicit Device(QObject *parent = nullptr);
inline QString id() const { return m_id; }
void setId(const QString &id);
inline QString name() const { return m_name; }
void setName(const QString &name);
inline bool paired() const { return m_paired; }
void setPaired(bool paired);
inline State state() const { return m_state; }
void setState(const State &state);
inline bool trusted() const { return m_trusted; }
void setTrusted(bool trusted);
inline bool connecting() const { return m_connecting; }
void setConnecting(bool connecting);
inline void setAdapterId(const QString &id) { m_adapterId = id; }
inline const QString &getAdapterId() const { return m_adapterId; }
Q_SIGNALS:
void nameChanged(const QString &name) const;
void pairedChanged(const bool paired) const;
void stateChanged(int state) const;
void trustedChanged(const bool trusted) const;
void connectingChanged(const bool &connecting) const;
private:
QString m_id;
QString m_name;
bool m_paired;
bool m_trusted;
bool m_connecting;
State m_state;
QString m_adapterId;
};
QDebug &operator<<(QDebug &stream, const Device *device);
#endif // DEVICE_H

View File

@ -0,0 +1,140 @@
/*
* 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 "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))
, m_state(new QLabel(this))
, m_loadingStat(new DSpinner)
, m_line(new HorizontalSeparator(this))
{
m_state->setPixmap(QPixmap(":/list_select@2x.png"));
m_line->setVisible(true);
m_state->setVisible(false);
m_loadingStat->setFixedSize(20, 20);
m_loadingStat->setVisible(false);
auto deviceLayout = new QVBoxLayout(this);
deviceLayout->setMargin(0);
deviceLayout->setSpacing(0);
deviceLayout->addWidget(m_line);
auto itemLayout = new QHBoxLayout(this);
itemLayout->setMargin(0);
itemLayout->setSpacing(0);
itemLayout->addSpacing(5);
itemLayout->addWidget(m_title);
itemLayout->addStretch();
itemLayout->addWidget(m_state);
itemLayout->addWidget(m_loadingStat);
itemLayout->addSpacing(5);
deviceLayout->addLayout(itemLayout);
setLayout(deviceLayout);
}
void DeviceItem::mousePressEvent(QMouseEvent *event)
{
emit clicked(m_device);
QWidget::mousePressEvent(event);
}
void DeviceItem::enterEvent(QEvent *event)
{
QWidget::enterEvent(event);
if (m_device) {
if (2 == m_device->state()) {
m_state->setPixmap(QPixmap(":/notify_close_press@2x.png"));
}
}
}
void DeviceItem::leaveEvent(QEvent *event)
{
QWidget::enterEvent(event);
if (m_device) {
if (2 == m_device->state()) {
m_state->setPixmap(QPixmap(":/list_select@2x.png"));
}
}
}
void DeviceItem::chaneState(int state)
{
switch (state) {
case 0: {
m_state->setVisible(false);
m_loadingStat->stop();
m_loadingStat->hide();
m_loadingStat->setVisible(false);
}
break;
case 1: {
m_state->setVisible(false);
m_loadingStat->start();
m_loadingStat->show();
m_loadingStat->setVisible(true);
}
break;
case 2: {
m_loadingStat->stop();
m_loadingStat->hide();
m_loadingStat->setVisible(false);
m_state->setVisible(true);
}
break;
}
}
HorizontalSeparator::HorizontalSeparator(QWidget *parent)
: QWidget(parent)
{
setFixedHeight(1);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
}
void HorizontalSeparator::paintEvent(QPaintEvent *e)
{
QWidget::paintEvent(e);
QPainter painter(this);
painter.fillRect(rect(), QColor(0, 0, 0, 125));
}
MenueItem::MenueItem(QWidget *parent)
: QLabel(parent)
{
}
void MenueItem::mousePressEvent(QMouseEvent *event)
{
QLabel::mousePressEvent(event);
emit clicked();
}

View File

@ -0,0 +1,84 @@
/*
* 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 DEVICEITEM_H
#define DEVICEITEM_H
#include <DSpinner>
#include <QLabel>
DWIDGET_USE_NAMESPACE
class Device;
class HorizontalSeparator;
class DeviceItem : public QWidget
{
Q_OBJECT
public:
explicit DeviceItem(const QString &title, QWidget *parent = nullptr);
inline void setTitle(const QString &name) { m_title->setText(name); }
inline void setDevice(Device *d) { m_device = d; }
inline Device *device() { return m_device; }
protected:
void mousePressEvent(QMouseEvent *event) override;
void enterEvent(QEvent *event) override;
void leaveEvent(QEvent *event) override;
signals:
void clicked(Device *);
public slots:
void chaneState(int state);
private:
QLabel *m_title;
QLabel *m_state;
DSpinner *m_loadingStat;
Device *m_device = nullptr;
HorizontalSeparator *m_line;
};
class HorizontalSeparator : public QWidget
{
Q_OBJECT
public:
explicit HorizontalSeparator(QWidget *parent = nullptr);
protected:
void paintEvent(QPaintEvent *e);
};
class MenueItem : public QLabel
{
Q_OBJECT
public:
explicit MenueItem(QWidget *parent = nullptr);
signals:
void clicked();
protected:
void mousePressEvent(QMouseEvent *event) override;
};
#endif // DEVICEITEM_H

View File

@ -0,0 +1,59 @@
/*
* 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 "switchitem.h"
#include "QHBoxLayout"
SwitchItem::SwitchItem(QWidget *parent)
: QWidget(parent)
, m_title(new QLabel(this))
, m_switchBtn(new DSwitchButton(this))
, m_default(false)
{
auto switchLayout = new QHBoxLayout(this);
switchLayout->setMargin(2);
switchLayout->addWidget(m_title);
switchLayout->addStretch();
switchLayout->addWidget(m_switchBtn);
setLayout(switchLayout);
connect(m_switchBtn, &DSwitchButton::toggled, [&](bool change) {
emit checkedChanged(change);
});
}
void SwitchItem::setChecked(const bool checked)
{
m_switchBtn->setChecked(checked);
}
void SwitchItem::setTitle(const QString &title)
{
m_title->setText(title);
}
//void SwitchItem::mousePressEvent(QMouseEvent *event)
//{
// emit clicked(m_adapterId);
// QWidget::mousePressEvent(event);
//}

View File

@ -0,0 +1,56 @@
/*
* 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 SWITCHITEM_H
#define SWITCHITEM_H
#include <DSwitchButton>
#include <QLabel>
DWIDGET_USE_NAMESPACE
class SwitchItem : public QWidget
{
Q_OBJECT
public:
explicit SwitchItem(QWidget *parent = nullptr);
void setChecked(const bool checked = true);
void setTitle(const QString &title);
inline bool isdefault() { return m_default; }
inline void setDefault(bool def) { m_default = def; }
//protected:
// void mousePressEvent(QMouseEvent *event) override;
signals:
void checkedChanged(bool checked);
// void clicked(const QString &adapterId);
private:
QLabel *m_title;
DSwitchButton *m_switchBtn;
bool m_default;
};
#endif // SWITCHITEM_H

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20">
<path fill-rule="evenodd" d="M10,1 C13.8659932,1 17,5.02943725 17,10 C17,14.9705627 13.8659932,19 10,19 C6.13400675,19 3,14.9705627 3,10 C3,5.02943725 6.13400675,1 10,1 Z M9.70970381,4.04658915 C9.38851738,3.89590423 9,4.12745532 9,4.50085676 L9,4.50085676 L8.99993692,9.199 L6.01843775,7.30168117 C5.78546706,7.15342709 5.47642333,7.22210348 5.32816926,7.45507417 C5.17991518,7.68804485 5.24859157,7.99708858 5.48156225,8.14534266 L5.48156225,8.14534266 L8.57293692,10.112 L5.48156225,12.079026 L5.41006254,12.1340743 C5.2360083,12.2950173 5.19638786,12.5622095 5.32816926,12.7692945 L5.32816926,12.7692945 L5.38321754,12.8407942 C5.54416054,13.0148485 5.81135269,13.0544689 6.01843775,12.9226875 L6.01843775,12.9226875 L8.99993692,11.024 L9,15.7235119 C9,16.1256365 9.4505882,16.3632483 9.78242105,16.1361114 L9.78242105,16.1361114 L14.0324211,13.2270205 C14.3284434,13.0243956 14.3210831,12.5851828 14.0184377,12.3925903 L14.0184377,12.3925903 L10.4339369,10.112 L14.0184377,7.83177842 L14.0936502,7.77350167 C14.3199141,7.5612843 14.3015323,7.18155266 14.0324211,6.99734817 L14.0324211,6.99734817 L9.78242105,4.08825726 Z M10,11.0207121 L12.8425812,12.8296274 L10,14.7753515 L10,11.0207121 Z M10,5.4490172 L12.8425812,7.39474123 L10,9.20365655 L10,5.4490172 Z"/>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20">
<path fill="#FFF" fill-rule="evenodd" d="M10,1 C13.8659932,1 17,5.02943725 17,10 C17,14.9705627 13.8659932,19 10,19 C6.13400675,19 3,14.9705627 3,10 C3,5.02943725 6.13400675,1 10,1 Z M9.70970381,4.04658915 C9.38851738,3.89590423 9,4.12745532 9,4.50085676 L9,4.50085676 L8.99993692,9.199 L6.01843775,7.30168117 C5.78546706,7.15342709 5.47642333,7.22210348 5.32816926,7.45507417 C5.17991518,7.68804485 5.24859157,7.99708858 5.48156225,8.14534266 L5.48156225,8.14534266 L8.57293692,10.112 L5.48156225,12.079026 L5.41006254,12.1340743 C5.2360083,12.2950173 5.19638786,12.5622095 5.32816926,12.7692945 L5.32816926,12.7692945 L5.38321754,12.8407942 C5.54416054,13.0148485 5.81135269,13.0544689 6.01843775,12.9226875 L6.01843775,12.9226875 L8.99993692,11.024 L9,15.7235119 C9,16.1256365 9.4505882,16.3632483 9.78242105,16.1361114 L9.78242105,16.1361114 L14.0324211,13.2270205 C14.3284434,13.0243956 14.3210831,12.5851828 14.0184377,12.3925903 L14.0184377,12.3925903 L10.4339369,10.112 L14.0184377,7.83177842 L14.0936502,7.77350167 C14.3199141,7.5612843 14.3015323,7.18155266 14.0324211,6.99734817 L14.0324211,6.99734817 L9.78242105,4.08825726 Z M10,11.0207121 L12.8425812,12.8296274 L10,14.7753515 L10,11.0207121 Z M10,5.4490172 L12.8425812,7.39474123 L10,9.20365655 L10,5.4490172 Z"/>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20">
<path fill-opacity=".3" fill-rule="evenodd" d="M10,1 C13.8659932,1 17,5.02943725 17,10 C17,14.9705627 13.8659932,19 10,19 C6.13400675,19 3,14.9705627 3,10 C3,5.02943725 6.13400675,1 10,1 Z M9.70970381,4.04658915 C9.38851738,3.89590423 9,4.12745532 9,4.50085676 L9,4.50085676 L8.99993692,9.199 L6.01843775,7.30168117 C5.78546706,7.15342709 5.47642333,7.22210348 5.32816926,7.45507417 C5.17991518,7.68804485 5.24859157,7.99708858 5.48156225,8.14534266 L5.48156225,8.14534266 L8.57293692,10.112 L5.48156225,12.079026 L5.41006254,12.1340743 C5.2360083,12.2950173 5.19638786,12.5622095 5.32816926,12.7692945 L5.32816926,12.7692945 L5.38321754,12.8407942 C5.54416054,13.0148485 5.81135269,13.0544689 6.01843775,12.9226875 L6.01843775,12.9226875 L8.99993692,11.024 L9,15.7235119 C9,16.1256365 9.4505882,16.3632483 9.78242105,16.1361114 L9.78242105,16.1361114 L14.0324211,13.2270205 C14.3284434,13.0243956 14.3210831,12.5851828 14.0184377,12.3925903 L14.0184377,12.3925903 L10.4339369,10.112 L14.0184377,7.83177842 L14.0936502,7.77350167 C14.3199141,7.5612843 14.3015323,7.18155266 14.0324211,6.99734817 L14.0324211,6.99734817 L9.78242105,4.08825726 Z M10,11.0207121 L12.8425812,12.8296274 L10,14.7753515 L10,11.0207121 Z M10,5.4490172 L12.8425812,7.39474123 L10,9.20365655 L10,5.4490172 Z"/>
</svg>

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -0,0 +1,3 @@
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20">
<path fill="#FFF" fill-rule="evenodd" d="M10,1 C13.8659932,1 17,5.02943725 17,10 C17,14.9705627 13.8659932,19 10,19 C6.13400675,19 3,14.9705627 3,10 C3,5.02943725 6.13400675,1 10,1 Z M9.70970381,4.04658915 C9.38851738,3.89590423 9,4.12745532 9,4.50085676 L9,4.50085676 L8.99993692,9.199 L6.01843775,7.30168117 C5.78546706,7.15342709 5.47642333,7.22210348 5.32816926,7.45507417 C5.17991518,7.68804485 5.24859157,7.99708858 5.48156225,8.14534266 L5.48156225,8.14534266 L8.57293692,10.112 L5.48156225,12.079026 L5.41006254,12.1340743 C5.2360083,12.2950173 5.19638786,12.5622095 5.32816926,12.7692945 L5.32816926,12.7692945 L5.38321754,12.8407942 C5.54416054,13.0148485 5.81135269,13.0544689 6.01843775,12.9226875 L6.01843775,12.9226875 L8.99993692,11.024 L9,15.7235119 C9,16.1256365 9.4505882,16.3632483 9.78242105,16.1361114 L9.78242105,16.1361114 L14.0324211,13.2270205 C14.3284434,13.0243956 14.3210831,12.5851828 14.0184377,12.3925903 L14.0184377,12.3925903 L10.4339369,10.112 L14.0184377,7.83177842 L14.0936502,7.77350167 C14.3199141,7.5612843 14.3015323,7.18155266 14.0324211,6.99734817 L14.0324211,6.99734817 L9.78242105,4.08825726 Z M10,11.0207121 L12.8425812,12.8296274 L10,14.7753515 L10,11.0207121 Z M10,5.4490172 L12.8425812,7.39474123 L10,9.20365655 L10,5.4490172 Z" opacity=".3"/>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -0,0 +1,31 @@
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20">
<g fill-rule="evenodd" transform="translate(2 2)">
<circle cx="3.67" cy="10.5" r="2" opacity=".01" transform="rotate(-120 3.67 10.5)"/>
<circle cx="3.302" cy="9.71" r="2" opacity=".02" transform="rotate(-110 3.302 9.71)"/>
<circle cx="3.076" cy="8.868" r="2" opacity=".03" transform="rotate(-100 3.076 8.868)"/>
<circle cx="3" cy="8" r="2" opacity=".04" transform="rotate(-90 3 8)"/>
<circle cx="3.076" cy="7.132" r="2" opacity=".05" transform="rotate(-80 3.076 7.132)"/>
<circle cx="3.302" cy="6.29" r="2" opacity=".1" transform="rotate(-70 3.302 6.29)"/>
<circle cx="3.67" cy="5.5" r="2" opacity=".15" transform="rotate(-60 3.67 5.5)"/>
<circle cx="4.17" cy="4.786" r="2" opacity=".3" transform="rotate(-50 4.17 4.786)"/>
<circle cx="4.786" cy="4.17" r="2" transform="rotate(-40 4.786 4.17)"/>
<circle cx="8" cy="3" r="2" opacity=".01"/>
<circle cx="8.868" cy="3.076" r="2" opacity=".02" transform="rotate(10 8.868 3.076)"/>
<circle cx="9.71" cy="3.302" r="2" opacity=".03" transform="rotate(20 9.71 3.302)"/>
<circle cx="10.5" cy="3.67" r="2" opacity=".04" transform="rotate(30 10.5 3.67)"/>
<circle cx="11.214" cy="4.17" r="2" opacity=".05" transform="rotate(40 11.214 4.17)"/>
<circle cx="11.83" cy="4.786" r="2" opacity=".1" transform="rotate(50 11.83 4.786)"/>
<circle cx="12.33" cy="5.5" r="2" opacity=".15" transform="rotate(60 12.33 5.5)"/>
<circle cx="12.698" cy="6.29" r="2" opacity=".3" transform="rotate(70 12.698 6.29)"/>
<circle cx="12.924" cy="7.132" r="2" transform="rotate(80 12.924 7.132)"/>
<circle cx="12.33" cy="10.5" r="2" opacity=".01" transform="rotate(120 12.33 10.5)"/>
<circle cx="11.83" cy="11.214" r="2" opacity=".02" transform="rotate(130 11.83 11.214)"/>
<circle cx="11.214" cy="11.83" r="2" opacity=".03" transform="rotate(140 11.214 11.83)"/>
<circle cx="10.5" cy="12.33" r="2" opacity=".04" transform="rotate(150 10.5 12.33)"/>
<circle cx="9.71" cy="12.698" r="2" opacity=".05" transform="rotate(160 9.71 12.698)"/>
<circle cx="8.868" cy="12.924" r="2" opacity=".1" transform="rotate(170 8.868 12.924)"/>
<circle cx="8" cy="13" r="2" opacity=".15" transform="rotate(180 8 13)"/>
<circle cx="7.132" cy="12.924" r="2" opacity=".3" transform="rotate(-170 7.132 12.924)"/>
<circle cx="6.29" cy="12.698" r="2" transform="rotate(-160 6.29 12.698)"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -0,0 +1,31 @@
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20">
<g fill="#FFF" fill-rule="evenodd" transform="translate(2 2)">
<circle cx="3.67" cy="10.5" r="2" opacity=".01" transform="rotate(-120 3.67 10.5)"/>
<circle cx="3.302" cy="9.71" r="2" opacity=".02" transform="rotate(-110 3.302 9.71)"/>
<circle cx="3.076" cy="8.868" r="2" opacity=".03" transform="rotate(-100 3.076 8.868)"/>
<circle cx="3" cy="8" r="2" opacity=".04" transform="rotate(-90 3 8)"/>
<circle cx="3.076" cy="7.132" r="2" opacity=".05" transform="rotate(-80 3.076 7.132)"/>
<circle cx="3.302" cy="6.29" r="2" opacity=".1" transform="rotate(-70 3.302 6.29)"/>
<circle cx="3.67" cy="5.5" r="2" opacity=".15" transform="rotate(-60 3.67 5.5)"/>
<circle cx="4.17" cy="4.786" r="2" opacity=".3" transform="rotate(-50 4.17 4.786)"/>
<circle cx="4.786" cy="4.17" r="2" transform="rotate(-40 4.786 4.17)"/>
<circle cx="8" cy="3" r="2" opacity=".01"/>
<circle cx="8.868" cy="3.076" r="2" opacity=".02" transform="rotate(10 8.868 3.076)"/>
<circle cx="9.71" cy="3.302" r="2" opacity=".03" transform="rotate(20 9.71 3.302)"/>
<circle cx="10.5" cy="3.67" r="2" opacity=".04" transform="rotate(30 10.5 3.67)"/>
<circle cx="11.214" cy="4.17" r="2" opacity=".05" transform="rotate(40 11.214 4.17)"/>
<circle cx="11.83" cy="4.786" r="2" opacity=".1" transform="rotate(50 11.83 4.786)"/>
<circle cx="12.33" cy="5.5" r="2" opacity=".15" transform="rotate(60 12.33 5.5)"/>
<circle cx="12.698" cy="6.29" r="2" opacity=".3" transform="rotate(70 12.698 6.29)"/>
<circle cx="12.924" cy="7.132" r="2" transform="rotate(80 12.924 7.132)"/>
<circle cx="12.33" cy="10.5" r="2" opacity=".01" transform="rotate(120 12.33 10.5)"/>
<circle cx="11.83" cy="11.214" r="2" opacity=".02" transform="rotate(130 11.83 11.214)"/>
<circle cx="11.214" cy="11.83" r="2" opacity=".03" transform="rotate(140 11.214 11.83)"/>
<circle cx="10.5" cy="12.33" r="2" opacity=".04" transform="rotate(150 10.5 12.33)"/>
<circle cx="9.71" cy="12.698" r="2" opacity=".05" transform="rotate(160 9.71 12.698)"/>
<circle cx="8.868" cy="12.924" r="2" opacity=".1" transform="rotate(170 8.868 12.924)"/>
<circle cx="8" cy="13" r="2" opacity=".15" transform="rotate(180 8 13)"/>
<circle cx="7.132" cy="12.924" r="2" opacity=".3" transform="rotate(-170 7.132 12.924)"/>
<circle cx="6.29" cy="12.698" r="2" transform="rotate(-160 6.29 12.698)"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -0,0 +1,14 @@
<RCC>
<qresource prefix="/">
<file>bluetooth-active-symbolic-dark.svg</file>
<file>bluetooth-active-symbolic.svg</file>
<file>bluetooth-disable-symbolic-dark.svg</file>
<file>bluetooth-disable-symbolic.svg</file>
<file>bluetooth-waiting-symbolic-dark.svg</file>
<file>bluetooth-waiting-symbolic.svg</file>
<file>list_select.png</file>
<file>list_select@2x.png</file>
<file>notify_close_press.png</file>
<file>notify_close_press@2x.png</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 508 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 749 B

View File

@ -0,0 +1,90 @@
#include "wirelist.h"
#include <QTimer>
#include <QDebug>
using namespace dde::network;
const int Width = 300;
const int ItemHeight = 30;
WireList::WireList(WiredDevice *device, QWidget *parent)
: QScrollArea(parent)
, m_device(device)
, m_updateAPTimer(new QTimer(this))
, m_deviceName(new QLabel(this))
, m_switchBtn(new DSwitchButton(this))
{
m_updateAPTimer->setSingleShot(true);
m_updateAPTimer->setInterval(100);
auto centralWidget = new QWidget(this);
centralWidget->setFixedWidth(Width);
m_centralLayout = new QVBoxLayout;
m_centralLayout->setMargin(0);
m_centralLayout->setSpacing(0);
centralWidget->setLayout(m_centralLayout);
auto controlPanel = new QWidget(this);
controlPanel->setFixedWidth(Width);
controlPanel->setFixedHeight(ItemHeight);
auto controlPanelLayout = new QHBoxLayout;
controlPanelLayout->setMargin(0);
controlPanelLayout->setSpacing(0);
controlPanelLayout->addSpacing(5);
controlPanelLayout->addWidget(m_deviceName);
controlPanelLayout->addStretch();
controlPanelLayout->addWidget(m_switchBtn);
controlPanelLayout->addSpacing(5);
controlPanel->setLayout(controlPanelLayout);
m_centralLayout->addWidget(controlPanel);
setWidget(centralWidget);
setFixedWidth(Width);
setFrameShape(QFrame::NoFrame);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
centralWidget->setAutoFillBackground(false);
viewport()->setAutoFillBackground(false);
connect(m_device, &WiredDevice::connectionsChanged, this, &WireList::changeConnections);
connect(m_device, &WiredDevice::activeWiredConnectionInfoChanged, this, &WireList::changeActiveWiredConnectionInfo);
connect(m_device, &WiredDevice::activeConnectionsChanged, this, &WireList::changeActiveConnections);
connect(m_device, &WiredDevice::activeConnectionsInfoChanged, this, &WireList::changeActiveConnectionsInfo);
connect(m_switchBtn, &DSwitchButton::checkedChanged, this, &WireList::deviceEnabled);
connect(m_updateAPTimer, &QTimer::timeout, this, &WireList::updateConnectionList);
QMetaObject::invokeMethod(this, "loadConnectionList", Qt::QueuedConnection);
}
void WireList::changeConnections(const QList<QJsonObject> &connections)
{
for (auto object : connections) {
qDebug() << object;
}
}
void WireList::changeActiveWiredConnectionInfo(const QJsonObject &connInfo)
{
for (auto object : connInfo) {
qDebug() << object;
}
}
void WireList::changeActiveConnections(const QList<QJsonObject> &activeConns)
{
for (auto object : activeConns) {
qDebug() << object;
}
}
void WireList::changeActiveConnectionsInfo(const QList<QJsonObject> &activeConnInfoList)
{
for (auto object : activeConnInfoList) {
qDebug() << object;
}
}

View File

@ -0,0 +1,43 @@
#ifndef WIRELIST_H
#define WIRELIST_H
#include <QScrollArea>
#include <QPointer>
#include <QVBoxLayout>
#include <QLabel>
#include <WiredDevice>
#include <dpicturesequenceview.h>
#include <DSwitchButton>
DWIDGET_USE_NAMESPACE
class WireList : public QScrollArea
{
Q_OBJECT
public:
WireList(dde::network::WiredDevice *device, QWidget *parent = nullptr);
public slots:
void changeConnections(const QList<QJsonObject> &connections);
void changeActiveWiredConnectionInfo(const QJsonObject &connInfo);
void changeActiveConnections(const QList<QJsonObject> &activeConns);
void changeActiveConnectionsInfo(const QList<QJsonObject> &activeConnInfoList);
void deviceEnabled(bool enabled);
void updateConnectionList();
private slots:
void loadConnectionList();
private:
QPointer<dde::network::WiredDevice> m_device;
QTimer *m_updateAPTimer;
QLabel *m_deviceName;
DSwitchButton *m_switchBtn;
QVBoxLayout *m_centralLayout;
};
#endif // WIRELIST_H

View File

@ -0,0 +1,80 @@
#include "plugincase.h"
PluginCase::PluginCase(QObject *parent)
: QObject(parent)
{
wireOpenState = new WireOpenState(this);
wireCloseState = new WireCloseState(this);
wireConnectingState = new WireConnetingState(this);
wireNoCableState = new WireNoCableState(this);
wireNoIpState = new WireNoIpState(this);
wireNoInternetState = new WireNoInternetState(this);
wirelessOpenState = new WirelessOpenState(this);
wirelessCloseState = new WirelessCloseState(this);
wirelessNoIp = new WirelessNoIp(this);
wirelessNoInternet = new WirelessNoInternet(this);
}
void PluginCase::setState(PluginState *state)
{
m_state = state;
state->setPluginCase(this);
}
PluginState *PluginCase::getState()
{
return m_state;
}
void PluginCase::openWire()
{
m_state->openWire();
}
void PluginCase::closeWire()
{
m_state->closeWire();
}
void PluginCase::wireConnect()
{
m_state->wireConnect();
}
void PluginCase::openWireless()
{
m_state->openWireless();
}
void PluginCase::closeWireless()
{
m_state->closeWireless();
}
void PluginCase::wirelessConnect()
{
m_state->wirelessConnect();
}
void WireOpenState::closeWire()
{
m_pluginCase->setState(m_pluginCase->wireCloseState);
m_pluginCase->closeWire();
}
void WireOpenState::wireConnect()
{
m_pluginCase->setState(m_pluginCase->wireConnectingState);
m_pluginCase->wireLinkCheck();
}
void WireConnetingState::wireLinkCheck()
{
if (m_pluginCase->cablePluged) {
m_pluginCase->setState(m_pluginCase->wireConnectingState);
m_pluginCase->wireIpCheck();
}
else {
m_pluginCase->setState(m_pluginCase->wireNoCableState);
}
}

View File

@ -0,0 +1,250 @@
#ifndef PLUGINCASE_H
#define PLUGINCASE_H
#include <QObject>
class PluginCase;
class PluginState : public QObject
{
Q_OBJECT
public:
void setPluginCase(PluginCase *pcase) {m_pluginCase = pcase;}
virtual void openWire() {}
virtual void closeWire() {}
virtual void wireConnect() {}
virtual void wireLinkCheck() {}
virtual void wireIpCheck() {}
virtual void wireInternetCheck() {}
virtual void openWireless() {}
virtual void closeWireless() {}
virtual void wirelessConnect() {}
protected:
explicit PluginState(QObject *parent = nullptr) : QObject(parent) {}
protected:
PluginCase *m_pluginCase;
};
class WireOpenState : public PluginState
{
Q_OBJECT
public:
explicit WireOpenState(QObject *parent = nullptr);
void closeWire() override;
void wireConnect() override;
void openWireless() override;
void closeWireless() override;
void wirelessConnect() override;
};
class WireCloseState : public PluginState
{
Q_OBJECT
public:
explicit WireCloseState(QObject *parent = nullptr);
void openWire() override;
void closeWire() override;
void wireConnect() override;
void openWireless() override;
void closeWireless() override;
void wirelessConnect() override;
};
class WireOpenWirelessCloseState : public PluginState
{
Q_OBJECT
public:
explicit WireOpenWirelessCloseState(QObject *parent = nullptr);
void closeWire() override;
void wireConnect() override;
void openWireless() override;
void closeWireless() override;
void wirelessConnect() override;
};
class WireCloseWirelessOpenState : public PluginState
{
Q_OBJECT
public:
explicit WireCloseWirelessOpenState(QObject *parent = nullptr);
void closeWire() override;
void wireConnect() override;
void openWireless() override;
void closeWireless() override;
void wirelessConnect() override;
};
class WireConnetingState : public PluginState
{
Q_OBJECT
public:
explicit WireConnetingState(QObject *parent = nullptr);
void openWire() override;
void closeWire() override;
void wireLinkCheck() override;
void wireIpCheck() override;
void wireInternetCheck() override;
void openWireless() override;
void closeWireless() override;
void wirelessConnect() override;
};
class WireNoCableState : public PluginState
{
Q_OBJECT
public:
explicit WireNoCableState(QObject *parent = nullptr);
void openWire() override;
void closeWire() override;
void wireConnect() override;
void openWireless() override;
void closeWireless() override;
void wirelessConnect() override;
};
class WireNoIpState : public PluginState
{
Q_OBJECT
public:
explicit WireNoIpState(QObject *parent = nullptr);
void openWire() override;
void closeWire() override;
void wireConnect() override;
void openWireless() override;
void closeWireless() override;
void wirelessConnect() override;
};
class WireNoInternetState : public PluginState
{
Q_OBJECT
public:
explicit WireNoInternetState(QObject *parent = nullptr);
void openWire() override;
void closeWire() override;
void wireConnect() override;
void openWireless() override;
void closeWireless() override;
void wirelessConnect() override;
};
class WirelessOpenState : public PluginState
{
Q_OBJECT
public:
explicit WirelessOpenState(QObject *parent = nullptr);
void openWire() override;
void closeWire() override;
void wireConnect() override;
void openWireless() override;
void closeWireless() override;
void wirelessConnect() override;
};
class WirelessCloseState : public PluginState
{
Q_OBJECT
public:
explicit WirelessCloseState(QObject *parent = nullptr);
void openWire() override;
void closeWire() override;
void wireConnect() override;
void openWireless() override;
void closeWireless() override;
void wirelessConnect() override;
};
class WirelessNoIp : public PluginState
{
Q_OBJECT
public:
explicit WirelessNoIp(QObject *parent = nullptr);
void openWire() override;
void closeWire() override;
void wireConnect() override;
void openWireless() override;
void closeWireless() override;
void wirelessConnect() override;
};
class WirelessNoInternet : public PluginState
{
Q_OBJECT
public:
explicit WirelessNoInternet(QObject *parent = nullptr);
void openWire() override;
void closeWire() override;
void wireConnect() override;
void openWireless() override;
void closeWireless() override;
void wirelessConnect() override;
};
class AllOpenState : public PluginState
{
Q_OBJECT
public:
explicit AllOpenState(QObject *parent = nullptr);
void openWire() override;
void closeWire() override;
void wireConnect() override;
void openWireless() override;
void closeWireless() override;
void wirelessConnect() override;
};
class AllCloseState : public PluginState
{
Q_OBJECT
public:
explicit AllCloseState(QObject *parent = nullptr);
void openWire() override;
void closeWire() override;
void wireConnect() override;
void openWireless() override;
void closeWireless() override;
void wirelessConnect() override;
};
class PluginCase : public QObject
{
Q_OBJECT
public:
explicit PluginCase(QObject *parent = nullptr);
void setState(PluginState *state);
PluginState *getState();
void openWire();
void closeWire();
void wireConnect();
void wireConnecting();
void wireLinkCheck();
void wireIpCheck();
void wireInternetCheck();
void openWireless();
void closeWireless();
void wirelessConnect();
signals:
public slots:
public:
WireOpenState *wireOpenState;
WireCloseState *wireCloseState;
WireConnetingState *wireConnectingState;
WireNoCableState *wireNoCableState;
WireNoIpState *wireNoIpState;
WireNoInternetState *wireNoInternetState;
WirelessOpenState *wirelessOpenState;
WirelessCloseState *wirelessCloseState;
WirelessNoIp *wirelessNoIp;
WirelessNoInternet *wirelessNoInternet;
bool cablePluged;
private:
PluginState *m_state = nullptr;
};
#endif // PLUGINCASE_H

View File

@ -1,4 +1,6 @@
<?xml version="1.0" ?><!DOCTYPE TS><TS language="en" version="2.1">
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="en">
<context>
<name>AbstractPluginsController</name>
<message>
@ -6,6 +8,42 @@
<translation>The plugin %1 is not compatible with the system.</translation>
</message>
</context>
<context>
<name>AdapterItem</name>
<message>
<source>My Device</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BluetoothApplet</name>
<message>
<source>Bluetooth</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BluetoothItem</name>
<message>
<source>Turn off</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Turn on</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Bluetooth settings</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>BluetoothPlugin</name>
<message>
<source>Bluetooth</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>DBusAdaptors</name>
<message>
@ -383,4 +421,4 @@
<translation>Wireless Network %1</translation>
</message>
</context>
</TS>
</TS>