2020-05-14 13:09:26 +08:00
|
|
|
/*
|
|
|
|
* 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"
|
2022-10-27 07:03:28 +00:00
|
|
|
#include "adaptersmanager.h"
|
2022-11-28 13:54:13 +08:00
|
|
|
#include "bluetoothmainwidget.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));
|
|
|
|
|
2021-05-25 13:05:45 +08:00
|
|
|
connect(m_bluetoothItem.data(), &BluetoothItem::justHasAdapter, [&] {
|
2022-12-01 19:36:53 +08:00
|
|
|
m_proxyInter->itemAdded(this, BLUETOOTH_KEY);
|
2020-04-23 18:29:59 +08:00
|
|
|
});
|
2021-05-25 13:05:45 +08:00
|
|
|
connect(m_bluetoothItem.data(), &BluetoothItem::noAdapter, [&] {
|
2022-12-01 19:36:53 +08:00
|
|
|
m_proxyInter->itemRemoved(this, BLUETOOTH_KEY);
|
2020-05-14 13:09:26 +08:00
|
|
|
});
|
2022-11-28 13:54:13 +08:00
|
|
|
connect(m_bluetoothWidget.data(), &BluetoothMainWidget::requestExpand, this, [ = ] {
|
|
|
|
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)
|
2022-11-23 05:27:16 +00:00
|
|
|
{
|
2022-11-28 13:54:13 +08:00
|
|
|
if (dockPart == DockPart::QuickPanel)
|
|
|
|
return QIcon();
|
|
|
|
|
2022-11-23 05:27:16 +00:00
|
|
|
if (themeType == DGuiApplicationHelper::ColorType::DarkType)
|
|
|
|
return QIcon(":/bluetooth-active-symbolic.svg");
|
|
|
|
|
|
|
|
return QIcon(":/bluetooth-active-symbolic-dark.svg");
|
|
|
|
}
|
|
|
|
|
2022-12-02 15:41:34 +08:00
|
|
|
PluginsItemInterface::PluginMode BluetoothPlugin::status() const
|
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())
|
|
|
|
return tr("open");
|
|
|
|
|
|
|
|
return tr("close");
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|