2023-02-16 13:51:55 +08:00
|
|
|
// Copyright (C) 2016 ~ 2018 Deepin Technology Co., Ltd.
|
|
|
|
// SPDX-FileCopyrightText: 2018 - 2023 UnionTech Software Technology Co., Ltd.
|
2022-09-06 11:36:55 +08:00
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
2020-05-14 13:09:26 +08:00
|
|
|
|
|
|
|
#include "bluetoothplugin.h"
|
2022-10-27 07:03:28 +00:00
|
|
|
#include "adaptersmanager.h"
|
2022-11-28 13:54:13 +08:00
|
|
|
#include "bluetoothmainwidget.h"
|
2023-01-04 22:14:33 +08:00
|
|
|
#include "imageutil.h"
|
2020-05-14 13:09:26 +08:00
|
|
|
|
2022-11-23 05:27:16 +00:00
|
|
|
#include <DGuiApplicationHelper>
|
2020-05-14 13:09:26 +08:00
|
|
|
|
|
|
|
#define STATE_KEY "enable"
|
|
|
|
|
2022-11-23 05:27:16 +00:00
|
|
|
DGUI_USE_NAMESPACE
|
|
|
|
|
2020-05-14 13:09:26 +08:00
|
|
|
BluetoothPlugin::BluetoothPlugin(QObject *parent)
|
2022-10-27 07:03:28 +00:00
|
|
|
: QObject(parent)
|
|
|
|
, m_adapterManager(new AdaptersManager(this))
|
|
|
|
, m_bluetoothItem(nullptr)
|
2022-11-28 13:54:13 +08:00
|
|
|
, m_bluetoothWidget(nullptr)
|
2020-05-14 13:09:26 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString BluetoothPlugin::pluginName() const
|
|
|
|
{
|
|
|
|
return "bluetooth";
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString BluetoothPlugin::pluginDisplayName() const
|
|
|
|
{
|
|
|
|
return tr("Bluetooth");
|
|
|
|
}
|
|
|
|
|
|
|
|
void BluetoothPlugin::init(PluginProxyInterface *proxyInter)
|
|
|
|
{
|
|
|
|
m_proxyInter = proxyInter;
|
|
|
|
|
2020-04-08 11:05:47 +08:00
|
|
|
if (m_bluetoothItem)
|
|
|
|
return;
|
|
|
|
|
2022-10-27 07:03:28 +00:00
|
|
|
m_bluetoothItem.reset(new BluetoothItem(m_adapterManager));
|
2020-05-14 13:09:26 +08:00
|
|
|
|
2022-11-28 13:54:13 +08:00
|
|
|
m_bluetoothWidget.reset(new BluetoothMainWidget(m_adapterManager));
|
2020-05-14 13:09:26 +08:00
|
|
|
|
2023-01-14 19:45:12 +08:00
|
|
|
connect(m_bluetoothItem.data(), &BluetoothItem::justHasAdapter, [ this ] {
|
2022-12-01 19:36:53 +08:00
|
|
|
m_proxyInter->itemAdded(this, BLUETOOTH_KEY);
|
2020-04-23 18:29:59 +08:00
|
|
|
});
|
2023-01-14 19:45:12 +08:00
|
|
|
connect(m_bluetoothItem.data(), &BluetoothItem::requestHide, [ this ] {
|
|
|
|
m_proxyInter->requestSetAppletVisible(this, QUICK_ITEM_KEY, false);
|
|
|
|
});
|
|
|
|
connect(m_bluetoothItem.data(), &BluetoothItem::noAdapter, [ this ] {
|
2023-01-12 10:58:43 +08:00
|
|
|
m_proxyInter->requestSetAppletVisible(this, QUICK_ITEM_KEY, false);
|
|
|
|
m_proxyInter->requestSetAppletVisible(this, BLUETOOTH_KEY, false);
|
2022-12-01 19:36:53 +08:00
|
|
|
m_proxyInter->itemRemoved(this, BLUETOOTH_KEY);
|
2020-05-14 13:09:26 +08:00
|
|
|
});
|
2023-01-14 19:45:12 +08:00
|
|
|
connect(m_bluetoothWidget.data(), &BluetoothMainWidget::requestExpand, this, [ this ] {
|
2022-11-28 13:54:13 +08:00
|
|
|
m_proxyInter->requestSetAppletVisible(this, QUICK_ITEM_KEY, true);
|
2020-05-14 13:09:26 +08:00
|
|
|
});
|
|
|
|
|
2022-12-01 19:36:53 +08:00
|
|
|
if (m_bluetoothItem->hasAdapter())
|
2020-05-14 13:09:26 +08:00
|
|
|
m_proxyInter->itemAdded(this, BLUETOOTH_KEY);
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *BluetoothPlugin::itemWidget(const QString &itemKey)
|
|
|
|
{
|
|
|
|
if (itemKey == BLUETOOTH_KEY) {
|
2021-05-25 13:05:45 +08:00
|
|
|
return m_bluetoothItem.data();
|
2020-05-14 13:09:26 +08:00
|
|
|
}
|
|
|
|
|
2022-11-28 13:54:13 +08:00
|
|
|
if (itemKey == QUICK_ITEM_KEY)
|
|
|
|
return m_bluetoothWidget.data();
|
|
|
|
|
2020-05-14 13:09:26 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-05-06 18:44:11 +08:00
|
|
|
QWidget *BluetoothPlugin::itemTipsWidget(const QString &itemKey)
|
|
|
|
{
|
|
|
|
if (itemKey == BLUETOOTH_KEY) {
|
|
|
|
return m_bluetoothItem->tipsWidget();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-05-14 13:09:26 +08:00
|
|
|
|
|
|
|
QWidget *BluetoothPlugin::itemPopupApplet(const QString &itemKey)
|
|
|
|
{
|
|
|
|
if (itemKey == BLUETOOTH_KEY) {
|
|
|
|
return m_bluetoothItem->popupApplet();
|
|
|
|
}
|
|
|
|
|
2022-11-04 04:51:48 +00:00
|
|
|
if (itemKey == QUICK_ITEM_KEY) {
|
2022-10-27 07:03:28 +00:00
|
|
|
return m_bluetoothItem->popupApplet();
|
2020-05-14 13:09:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2021-03-09 13:29:02 +08:00
|
|
|
return m_proxyInter->getValue(this, key, 4).toInt();
|
2020-05-14 13:09:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-02 15:41:34 +08:00
|
|
|
QIcon BluetoothPlugin::icon(const DockPart &dockPart, DGuiApplicationHelper::ColorType themeType)
|
2020-05-14 13:09:26 +08:00
|
|
|
{
|
2023-01-04 22:14:33 +08:00
|
|
|
QString iconFile;
|
2022-11-23 05:27:16 +00:00
|
|
|
if (themeType == DGuiApplicationHelper::ColorType::DarkType)
|
2023-01-12 13:55:34 +08:00
|
|
|
iconFile = ":/bluetooth-active-symbolic.svg";
|
2023-01-04 22:14:33 +08:00
|
|
|
else
|
|
|
|
iconFile = ":/bluetooth-active-symbolic-dark.svg";
|
|
|
|
|
|
|
|
switch (dockPart) {
|
|
|
|
case DockPart::DCCSetting:
|
|
|
|
return ImageUtil::loadSvg(iconFile, QSize(18, 18));
|
|
|
|
case DockPart::QuickShow:
|
|
|
|
return ImageUtil::loadSvg(iconFile, QSize(18, 16));
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2022-11-23 05:27:16 +00:00
|
|
|
|
2023-01-04 22:14:33 +08:00
|
|
|
return QIcon();
|
2020-05-14 13:09:26 +08:00
|
|
|
}
|
|
|
|
|
2022-12-02 15:41:34 +08:00
|
|
|
PluginsItemInterface::PluginMode BluetoothPlugin::status() const
|
2020-05-14 13:09:26 +08:00
|
|
|
{
|
2022-10-27 07:03:28 +00:00
|
|
|
if (m_bluetoothItem.data()->isPowered())
|
2022-12-02 15:41:34 +08:00
|
|
|
return PluginMode::Active;
|
2022-10-27 07:03:28 +00:00
|
|
|
|
2022-12-02 15:41:34 +08:00
|
|
|
return PluginMode::Deactive;
|
2022-10-27 07:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString BluetoothPlugin::description() const
|
|
|
|
{
|
|
|
|
if (m_bluetoothItem.data()->isPowered())
|
2022-12-12 06:03:34 +00:00
|
|
|
return tr("Turn on");
|
2022-10-27 07:03:28 +00:00
|
|
|
|
2022-12-12 06:03:34 +00:00
|
|
|
return tr("Turn off");
|
2020-05-14 13:09:26 +08:00
|
|
|
}
|
2022-10-27 07:03:28 +00:00
|
|
|
|
2022-11-28 14:37:54 +08:00
|
|
|
PluginFlags BluetoothPlugin::flags() const
|
|
|
|
{
|
|
|
|
return PluginFlag::Type_Common
|
|
|
|
| PluginFlag::Quick_Multi
|
|
|
|
| PluginFlag::Attribute_CanDrag
|
|
|
|
| PluginFlag::Attribute_CanInsert
|
|
|
|
| PluginFlag::Attribute_CanSetting;
|
|
|
|
}
|
|
|
|
|