2023-02-16 13:51:55 +08:00
|
|
|
// Copyright (C) 2011 ~ 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
|
2018-12-21 17:28:21 +08:00
|
|
|
|
|
|
|
#include "onboardplugin.h"
|
2020-06-29 15:35:51 +08:00
|
|
|
#include "../widgets/tipswidget.h"
|
2018-12-21 17:28:21 +08:00
|
|
|
|
2022-12-01 12:38:38 +08:00
|
|
|
#include <DGuiApplicationHelper>
|
|
|
|
|
2018-12-21 17:28:21 +08:00
|
|
|
#include <QIcon>
|
|
|
|
#include <QSettings>
|
2022-12-01 12:38:38 +08:00
|
|
|
#include <QPainter>
|
2018-12-21 17:28:21 +08:00
|
|
|
|
|
|
|
#define PLUGIN_STATE_KEY "enable"
|
|
|
|
|
2022-12-01 12:38:38 +08:00
|
|
|
DGUI_USE_NAMESPACE
|
|
|
|
|
2020-06-29 15:35:51 +08:00
|
|
|
using namespace Dock;
|
2018-12-21 17:28:21 +08:00
|
|
|
OnboardPlugin::OnboardPlugin(QObject *parent)
|
2021-05-25 13:05:45 +08:00
|
|
|
: QObject(parent)
|
|
|
|
, m_pluginLoaded(false)
|
|
|
|
, m_startupState(false)
|
|
|
|
, m_onboardItem(nullptr)
|
|
|
|
, m_tipsLabel(new TipsWidget)
|
2018-12-21 17:28:21 +08:00
|
|
|
{
|
|
|
|
m_tipsLabel->setText(tr("Onboard"));
|
|
|
|
m_tipsLabel->setVisible(false);
|
2020-06-04 14:52:58 +08:00
|
|
|
m_tipsLabel->setAccessibleName("Onboard");
|
2018-12-21 17:28:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString OnboardPlugin::pluginName() const
|
|
|
|
{
|
|
|
|
return "onboard";
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString OnboardPlugin::pluginDisplayName() const
|
|
|
|
{
|
|
|
|
return tr("Onboard");
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *OnboardPlugin::itemWidget(const QString &itemKey)
|
|
|
|
{
|
2022-11-09 02:31:27 +00:00
|
|
|
if (itemKey == pluginName())
|
|
|
|
return m_onboardItem.data();
|
2018-12-21 17:28:21 +08:00
|
|
|
|
2022-11-09 02:31:27 +00:00
|
|
|
return nullptr;
|
2018-12-21 17:28:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *OnboardPlugin::itemTipsWidget(const QString &itemKey)
|
|
|
|
{
|
|
|
|
Q_UNUSED(itemKey);
|
|
|
|
|
2021-05-25 13:05:45 +08:00
|
|
|
return m_tipsLabel.data();
|
2018-12-21 17:28:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnboardPlugin::init(PluginProxyInterface *proxyInter)
|
|
|
|
{
|
|
|
|
m_proxyInter = proxyInter;
|
|
|
|
|
|
|
|
if (!pluginIsDisable()) {
|
|
|
|
loadPlugin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnboardPlugin::pluginStateSwitched()
|
|
|
|
{
|
|
|
|
m_proxyInter->saveValue(this, PLUGIN_STATE_KEY, pluginIsDisable());
|
|
|
|
|
2019-01-30 18:00:46 +08:00
|
|
|
refreshPluginItemsVisible();
|
2018-12-21 17:28:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OnboardPlugin::pluginIsDisable()
|
|
|
|
{
|
2019-10-09 16:19:18 +08:00
|
|
|
return !(m_proxyInter->getValue(this, PLUGIN_STATE_KEY, true).toBool());
|
2018-12-21 17:28:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const QString OnboardPlugin::itemCommand(const QString &itemKey)
|
|
|
|
{
|
|
|
|
Q_UNUSED(itemKey);
|
|
|
|
|
|
|
|
return QString("dbus-send --print-reply --dest=org.onboard.Onboard /org/onboard/Onboard/Keyboard org.onboard.Onboard.Keyboard.ToggleVisible");
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnboardPlugin::invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked)
|
|
|
|
{
|
|
|
|
Q_UNUSED(itemKey)
|
|
|
|
Q_UNUSED(checked)
|
|
|
|
|
2022-11-04 06:29:03 +00:00
|
|
|
if (menuId != "onboard-settings")
|
|
|
|
return;
|
|
|
|
|
2020-03-07 14:35:12 +08:00
|
|
|
if(!m_startupState) {
|
|
|
|
QProcess *process = new QProcess;
|
|
|
|
connect(process,&QProcess::started, this, [ = ] {
|
|
|
|
m_startupState = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
|
|
|
[ = ](int exitCode, QProcess::ExitStatus exitStatus){
|
|
|
|
Q_UNUSED(exitCode)
|
|
|
|
Q_UNUSED(exitStatus)
|
|
|
|
|
|
|
|
m_startupState = false;
|
|
|
|
process->close();
|
|
|
|
process->deleteLater();
|
|
|
|
});
|
2022-11-04 06:29:03 +00:00
|
|
|
process->start("onboard-settings", QStringList());
|
2020-03-07 14:35:12 +08:00
|
|
|
}
|
|
|
|
|
2018-12-21 17:28:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnboardPlugin::displayModeChanged(const Dock::DisplayMode displayMode)
|
|
|
|
{
|
|
|
|
Q_UNUSED(displayMode);
|
|
|
|
|
|
|
|
if (!pluginIsDisable()) {
|
|
|
|
m_onboardItem->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int OnboardPlugin::itemSortKey(const QString &itemKey)
|
|
|
|
{
|
2020-01-11 10:35:29 +08:00
|
|
|
const QString key = QString("pos_%1_%2").arg(itemKey).arg(Dock::Efficient);
|
|
|
|
return m_proxyInter->getValue(this, key, 3).toInt();
|
2018-12-21 17:28:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnboardPlugin::setSortKey(const QString &itemKey, const int order)
|
|
|
|
{
|
2020-01-11 10:35:29 +08:00
|
|
|
const QString key = QString("pos_%1_%2").arg(itemKey).arg(Dock::Efficient);
|
2018-12-21 17:28:21 +08:00
|
|
|
m_proxyInter->saveValue(this, key, order);
|
|
|
|
}
|
|
|
|
|
2019-01-30 18:00:46 +08:00
|
|
|
void OnboardPlugin::pluginSettingsChanged()
|
|
|
|
{
|
|
|
|
refreshPluginItemsVisible();
|
|
|
|
}
|
|
|
|
|
2022-12-02 15:41:34 +08:00
|
|
|
QIcon OnboardPlugin::icon(const DockPart &dockPart, DGuiApplicationHelper::ColorType themeType)
|
2022-11-09 02:31:27 +00:00
|
|
|
{
|
2022-12-01 12:38:38 +08:00
|
|
|
if (dockPart == DockPart::DCCSetting) {
|
|
|
|
if (themeType == DGuiApplicationHelper::ColorType::LightType)
|
|
|
|
return QIcon(":/icons/icon/dcc_keyboard.svg");
|
|
|
|
|
|
|
|
QPixmap pixmap(":/icons/icon/dcc_keyboard.svg");
|
|
|
|
QPainter pa(&pixmap);
|
|
|
|
pa.setCompositionMode(QPainter::CompositionMode_SourceIn);
|
|
|
|
pa.fillRect(pixmap.rect(), Qt::white);
|
|
|
|
return pixmap;
|
|
|
|
}
|
2022-11-23 05:27:16 +00:00
|
|
|
|
2022-11-09 02:31:27 +00:00
|
|
|
if (dockPart == DockPart::QuickPanel)
|
2023-01-12 13:55:34 +08:00
|
|
|
return m_onboardItem->iconPixmap(QSize(24, 24), themeType);
|
2022-11-09 02:31:27 +00:00
|
|
|
|
2023-01-12 13:55:34 +08:00
|
|
|
return m_onboardItem->iconPixmap(QSize(18, 16), themeType);
|
2022-11-09 02:31:27 +00:00
|
|
|
}
|
|
|
|
|
2022-12-02 15:41:34 +08:00
|
|
|
PluginsItemInterface::PluginMode OnboardPlugin::status() const
|
2022-11-09 02:31:27 +00:00
|
|
|
{
|
2022-12-02 15:41:34 +08:00
|
|
|
return PluginsItemInterface::PluginMode::Active;
|
2022-11-09 02:31:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QString OnboardPlugin::description() const
|
|
|
|
{
|
|
|
|
return pluginDisplayName();
|
|
|
|
}
|
|
|
|
|
2018-12-21 17:28:21 +08:00
|
|
|
void OnboardPlugin::loadPlugin()
|
|
|
|
{
|
|
|
|
if (m_pluginLoaded) {
|
|
|
|
qDebug() << "onboard plugin has been loaded! return";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pluginLoaded = true;
|
|
|
|
|
2021-05-25 13:05:45 +08:00
|
|
|
m_onboardItem.reset(new OnboardItem);
|
2018-12-21 17:28:21 +08:00
|
|
|
|
|
|
|
m_proxyInter->itemAdded(this, pluginName());
|
|
|
|
displayModeChanged(displayMode());
|
|
|
|
}
|
2019-01-30 18:00:46 +08:00
|
|
|
|
|
|
|
void OnboardPlugin::refreshPluginItemsVisible()
|
|
|
|
{
|
|
|
|
if (pluginIsDisable())
|
|
|
|
{
|
|
|
|
m_proxyInter->itemRemoved(this, pluginName());
|
|
|
|
} else {
|
|
|
|
if (!m_pluginLoaded) {
|
|
|
|
loadPlugin();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_proxyInter->itemAdded(this, pluginName());
|
|
|
|
}
|
|
|
|
}
|