feat: add new plugin for onboard

https://github.com/linuxdeepin/internal-discussion/issues/610

Change-Id: Iada7d06f804a6a7d6df7078781f93be08694bce4
This commit is contained in:
listenerri 2018-12-21 17:28:21 +08:00
parent 3ab60d0633
commit 06d55e20d6
Notes: gerrit 2018-12-24 10:16:59 +08:00
Verified+1: <jenkins@deepin.com>
Verified+1: liuwen123 <liuwen@linuxdeepin.com>
Code-Review+2: listenerri <listenerri@gmail.com>
Submitted-by: listenerri <listenerri@gmail.com>
Submitted-at: Mon, 24 Dec 2018 10:16:59 +0800
Reviewed-on: https://cr.deepin.io/40780
Project: dde/dde-dock
Branch: refs/heads/master
12 changed files with 446 additions and 3 deletions

8
debian/control vendored
View File

@ -19,7 +19,7 @@ Homepage: http://www.deepin.org/
Package: dde-dock
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, deepin-menu
Recommends: dde-disk-mount-plugin
Recommends: dde-disk-mount-plugin, dde-dock-onboard-plugin
Conflicts:
dde-workspace (<< 2.90.5),
dde-dock-applets,
@ -35,3 +35,9 @@ Architecture: all
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: deepin desktop-environment - dock module development files
Deepin desktop environment - dock module development files.
Package: dde-dock-onboard-plugin
Architecture: all
Depends: ${shlibs:Depends}, ${misc:Depends}, onboard
Description: deepin desktop-environment - dock plugin
Deepin desktop environment - dock plugin for onboard

View File

@ -0,0 +1 @@
/usr/lib/dde-dock/plugins/libonboard.so

View File

@ -1,4 +1,9 @@
/usr/share
/usr/bin
/usr/lib/dde-dock
/usr/lib/dde-dock/plugins/libdatetime.so
/usr/lib/dde-dock/plugins/libkeyboard-layout.so
/usr/lib/dde-dock/plugins/libshutdown.so
/usr/lib/dde-dock/plugins/libtrash.so
/usr/lib/dde-dock/plugins/libtray.so
/usr/lib/dde-dock/plugins/system-trays
/etc/dde-dock

View File

@ -8,3 +8,4 @@ add_subdirectory("sound")
add_subdirectory("tray")
add_subdirectory("trash")
add_subdirectory("keyboard-layout")
add_subdirectory("onboard")

View File

@ -0,0 +1,27 @@
set(PLUGIN_NAME "onboard")
project(${PLUGIN_NAME})
# Sources files
file(GLOB_RECURSE SRCS "*.h" "*.cpp" "../../widgets/*.h" "../../widgets/*.cpp")
find_package(PkgConfig REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Svg REQUIRED)
find_package(Qt5DBus REQUIRED)
find_package(DtkWidget REQUIRED)
add_definitions("${QT_DEFINITIONS} -DQT_PLUGIN")
add_library(${PLUGIN_NAME} SHARED ${SRCS} onboard.qrc)
set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ../)
target_include_directories(${PLUGIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS}
${Qt5DBus_INCLUDE_DIRS}
../../interfaces)
target_link_libraries(${PLUGIN_NAME} PRIVATE
${DtkWidget_LIBRARIES}
${Qt5Widgets_LIBRARIES}
${Qt5Svg_LIBRARIES}
)
install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION lib/dde-dock/plugins)

View File

@ -0,0 +1,3 @@
{
"api": "1.1"
}

View File

@ -0,0 +1,4 @@
<RCC>
<qresource prefix="/icons">
</qresource>
</RCC>

View File

@ -0,0 +1,99 @@
/*
* 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 "onboarditem.h"
#include <QSvgRenderer>
#include <QPainter>
#include <QMouseEvent>
#include <QApplication>
#include <QIcon>
OnboardItem::OnboardItem(QWidget *parent)
: QWidget(parent),
m_hover(false)
{
}
QSize OnboardItem::sizeHint() const
{
return QSize(26, 26);
}
void OnboardItem::paintEvent(QPaintEvent *e)
{
Q_UNUSED(e);
QPixmap pixmap;
QString iconName = "deepin-virtualkeyboard";
int iconSize;
const Dock::DisplayMode displayMode = qApp->property(PROP_DISPLAY_MODE).value<Dock::DisplayMode>();
if (displayMode == Dock::Efficient) {
iconName = iconName + "-symbolic";
iconSize = 16;
} else {
iconSize = std::min(width(), height()) * 0.8;
}
pixmap = loadSvg(iconName, QSize(iconSize, iconSize));
QPainter painter(this);
painter.drawPixmap(rect().center() - pixmap.rect().center() / qApp->devicePixelRatio(), pixmap);
}
void OnboardItem::mousePressEvent(QMouseEvent *e)
{
if (e->button() != Qt::RightButton)
return QWidget::mousePressEvent(e);
const QPoint p(e->pos() - rect().center());
if (p.manhattanLength() < std::min(width(), height()) * 0.8 * 0.5)
{
emit requestContextMenu();
return;
}
return QWidget::mousePressEvent(e);
}
void OnboardItem::enterEvent(QEvent *e)
{
e->accept();
m_hover = true;
}
void OnboardItem::leaveEvent(QEvent *e)
{
e->accept();
m_hover = false;
}
const QPixmap OnboardItem::loadSvg(const QString &fileName, const QSize &size) const
{
const auto ratio = qApp->devicePixelRatio();
QPixmap pixmap;
pixmap = QIcon::fromTheme(fileName).pixmap(size * ratio);
pixmap.setDevicePixelRatio(ratio);
return pixmap;
}

View File

@ -0,0 +1,54 @@
/*
* 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/>.
*/
#ifndef ONBOARDITEM_H
#define ONBOARDITEM_H
#include "constants.h"
#include <QWidget>
class OnboardItem : public QWidget
{
Q_OBJECT
public:
explicit OnboardItem(QWidget *parent = nullptr);
signals:
void requestContextMenu() const;
protected:
QSize sizeHint() const;
void paintEvent(QPaintEvent *e);
void mousePressEvent(QMouseEvent *e);
void enterEvent(QEvent *e);
void leaveEvent(QEvent *e);
private:
const QPixmap loadSvg(const QString &fileName, const QSize &size) const;
private:
bool m_hover;
Dock::DisplayMode m_displayMode;
};
#endif // ONBOARDITEM_H

View File

@ -0,0 +1,174 @@
/*
* 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"
#include <QIcon>
#include <QSettings>
#define PLUGIN_STATE_KEY "enable"
OnboardPlugin::OnboardPlugin(QObject *parent)
: QObject(parent),
m_pluginLoaded(false),
m_tipsLabel(new TipsWidget)
{
m_tipsLabel->setText(tr("Onboard"));
m_tipsLabel->setVisible(false);
}
const QString OnboardPlugin::pluginName() const
{
return "onboard";
}
const QString OnboardPlugin::pluginDisplayName() const
{
return tr("Onboard");
}
QWidget *OnboardPlugin::itemWidget(const QString &itemKey)
{
Q_UNUSED(itemKey);
return m_onboardItem;
}
QWidget *OnboardPlugin::itemTipsWidget(const QString &itemKey)
{
Q_UNUSED(itemKey);
return m_tipsLabel;
}
void OnboardPlugin::init(PluginProxyInterface *proxyInter)
{
m_proxyInter = proxyInter;
if (!pluginIsDisable()) {
loadPlugin();
}
}
void OnboardPlugin::pluginStateSwitched()
{
m_proxyInter->saveValue(this, PLUGIN_STATE_KEY, pluginIsDisable());
if (pluginIsDisable())
{
m_proxyInter->itemRemoved(this, pluginName());
} else {
if (!m_pluginLoaded) {
loadPlugin();
return;
}
m_proxyInter->itemAdded(this, pluginName());
}
}
bool OnboardPlugin::pluginIsDisable()
{
return !m_proxyInter->getValue(this, PLUGIN_STATE_KEY, false).toBool();
}
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");
}
const QString OnboardPlugin::itemContextMenu(const QString &itemKey)
{
QList<QVariant> items;
QMap<QString, QVariant> onboardSettings;
onboardSettings["itemId"] = "onboard-settings";
onboardSettings["itemText"] = tr("Settings");
onboardSettings["isActive"] = true;
items.push_back(onboardSettings);
QMap<QString, QVariant> menu;
menu["items"] = items;
menu["checkableMenu"] = false;
menu["singleCheck"] = false;
return QJsonDocument::fromVariant(menu).toJson();
}
void OnboardPlugin::invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked)
{
Q_UNUSED(itemKey)
Q_UNUSED(checked)
if (menuId == "onboard-settings")
QProcess::startDetached("onboard-settings");
}
void OnboardPlugin::displayModeChanged(const Dock::DisplayMode displayMode)
{
Q_UNUSED(displayMode);
if (!pluginIsDisable()) {
m_onboardItem->update();
}
}
int OnboardPlugin::itemSortKey(const QString &itemKey)
{
Dock::DisplayMode mode = displayMode();
const QString key = QString("pos_%1_%2").arg(itemKey).arg(mode);
if (mode == Dock::DisplayMode::Fashion) {
return m_proxyInter->getValue(this, key, 1).toInt();
} else {
return m_proxyInter->getValue(this, key, 4).toInt();
}
}
void OnboardPlugin::setSortKey(const QString &itemKey, const int order)
{
const QString key = QString("pos_%1_%2").arg(itemKey).arg(displayMode());
m_proxyInter->saveValue(this, key, order);
}
void OnboardPlugin::requestContextMenu()
{
m_proxyInter->requestContextMenu(this, pluginName());
}
void OnboardPlugin::loadPlugin()
{
if (m_pluginLoaded) {
qDebug() << "onboard plugin has been loaded! return";
return;
}
m_pluginLoaded = true;
m_onboardItem = new OnboardItem;
connect(m_onboardItem, &OnboardItem::requestContextMenu, this, &OnboardPlugin::requestContextMenu);
m_proxyInter->itemAdded(this, pluginName());
displayModeChanged(displayMode());
}

View File

@ -0,0 +1,69 @@
/*
* 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/>.
*/
#ifndef ONBOARDPLUGIN_H
#define ONBOARDPLUGIN_H
#include "pluginsiteminterface.h"
#include "onboarditem.h"
#include "../widgets/tipswidget.h"
#include <QLabel>
class OnboardPlugin : public QObject, PluginsItemInterface
{
Q_OBJECT
Q_INTERFACES(PluginsItemInterface)
Q_PLUGIN_METADATA(IID "com.deepin.dock.PluginsItemInterface" FILE "onboard.json")
public:
explicit OnboardPlugin(QObject *parent = 0);
const QString pluginName() const override;
const QString pluginDisplayName() const override;
void init(PluginProxyInterface *proxyInter) override;
void pluginStateSwitched() override;
bool pluginIsAllowDisable() override { return true; }
bool pluginIsDisable() override;
QWidget *itemWidget(const QString &itemKey) override;
QWidget *itemTipsWidget(const QString &itemKey) override;
const QString itemCommand(const QString &itemKey) override;
const QString itemContextMenu(const QString &itemKey) override;
void invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked) override;
void displayModeChanged(const Dock::DisplayMode displayMode) override;
int itemSortKey(const QString &itemKey) Q_DECL_OVERRIDE;
void setSortKey(const QString &itemKey, const int order) Q_DECL_OVERRIDE;
private:
void requestContextMenu();
void loadPlugin();
private:
bool m_pluginLoaded;
OnboardItem *m_onboardItem;
TipsWidget *m_tipsLabel;
};
#endif // ONBOARDPLUGIN_H

View File

@ -198,7 +198,7 @@ int ShutdownPlugin::itemSortKey(const QString &itemKey)
if (mode == Dock::DisplayMode::Fashion) {
return m_proxyInter->getValue(this, key, 2).toInt();
} else {
return m_proxyInter->getValue(this, key, 4).toInt();
return m_proxyInter->getValue(this, key, 5).toInt();
}
}