2018-12-21 17:28:21 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
|
|
|
*
|
|
|
|
* Author: listenerri <listenerri@gmail.com>
|
|
|
|
*
|
|
|
|
* Maintainer: listenerri <listenerri@gmail.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 "onboardplugin.h"
|
2020-06-29 15:35:51 +08:00
|
|
|
#include "../widgets/tipswidget.h"
|
2022-09-16 20:12:52 +00:00
|
|
|
|
2022-11-18 17:08:32 +08:00
|
|
|
#include "org_deepin_dde_daemon_dock1.h"
|
|
|
|
#include "org_deepin_dde_daemon_dock1_entry.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
|
|
|
|
|
2022-09-16 20:12:52 +00:00
|
|
|
using DBusDock = org::deepin::dde::daemon::Dock1;
|
|
|
|
using DockEntryInter = org::deepin::dde::daemon::dock1::Entry;
|
2022-06-21 12:26:22 +08:00
|
|
|
|
2022-08-19 11:59:01 +00:00
|
|
|
static const QString serviceName = QString("org.deepin.dde.daemon.Dock1");
|
|
|
|
static const QString servicePath = QString("/org/deepin/dde/daemon/Dock1");
|
2022-06-21 12:26:22 +08:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-06-21 12:26:22 +08:00
|
|
|
DBusDock DockInter(serviceName, servicePath, QDBusConnection::sessionBus(), this);
|
2020-03-07 14:35:12 +08:00
|
|
|
|
|
|
|
for (auto entry : DockInter.entries()) {
|
2022-06-21 12:26:22 +08:00
|
|
|
DockEntryInter AppInter(serviceName, entry.path(), QDBusConnection::sessionBus(), this);
|
2020-03-07 14:35:12 +08:00
|
|
|
if(AppInter.name() == "Onboard-Settings" && !AppInter.isActive()) {
|
|
|
|
AppInter.Activate(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
return m_onboardItem->iconPixmap(24);
|
|
|
|
|
|
|
|
return m_onboardItem->iconPixmap(20);
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|