mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
refactor: standalone shutdown plugin
Change-Id: I78658ba139bbbd7528b3831594d497454223b1bd
This commit is contained in:
parent
2d273cdff3
commit
540b716655
Notes:
gerrit
2018-10-29 13:26:59 +08:00
Verified+1: <jenkins@deepin.com> Verified+1: zhaofangfangdeepin <zhaofangfang@linuxdeepin.com> Code-Review+2: listenerri <listenerri@gmail.com> Submitted-by: listenerri <listenerri@gmail.com> Submitted-at: Mon, 29 Oct 2018 13:26:59 +0800 Reviewed-on: https://cr.deepin.io/39284 Project: dde/dde-dock Branch: refs/heads/master
@ -2,7 +2,7 @@
|
||||
add_subdirectory("datetime")
|
||||
#add_subdirectory("disk-mount")
|
||||
#add_subdirectory("network")
|
||||
#add_subdirectory("shutdown")
|
||||
add_subdirectory("shutdown")
|
||||
#add_subdirectory("sound")
|
||||
add_subdirectory("system-tray")
|
||||
add_subdirectory("trash")
|
||||
|
27
plugins/shutdown/CMakeLists.txt
Normal file
27
plugins/shutdown/CMakeLists.txt
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
set(PLUGIN_NAME "shutdown")
|
||||
|
||||
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} shutdown.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)
|
49
plugins/shutdown/dbus/dbusaccount.cpp
Normal file
49
plugins/shutdown/dbus/dbusaccount.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* Author: sbw <sbw@sbw.so>
|
||||
*
|
||||
* Maintainer: sbw <sbw@sbw.so>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file was generated by qdbusxml2cpp version 0.8
|
||||
* Command line was: qdbusxml2cpp -c DBusAccount -p dbusaccount com.deepin.daemon.Accounts.xml
|
||||
*
|
||||
* qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
|
||||
*
|
||||
* This is an auto-generated file.
|
||||
* This file may have been hand-edited. Look for HAND-EDIT comments
|
||||
* before re-generating it.
|
||||
*/
|
||||
|
||||
#include "dbusaccount.h"
|
||||
|
||||
/*
|
||||
* Implementation of interface class DBusAccount
|
||||
*/
|
||||
|
||||
DBusAccount::DBusAccount(QObject *parent)
|
||||
: QDBusAbstractInterface(staticService(), staticInterfacePath(), staticInterfaceName(), QDBusConnection::systemBus(), parent)
|
||||
{
|
||||
QDBusConnection::systemBus().connect(this->service(), this->path(), "org.freedesktop.DBus.Properties", "PropertiesChanged","sa{sv}as", this, SLOT(__propertyChanged__(QDBusMessage)));
|
||||
}
|
||||
|
||||
DBusAccount::~DBusAccount()
|
||||
{
|
||||
QDBusConnection::systemBus().disconnect(service(), path(), "org.freedesktop.DBus.Properties", "PropertiesChanged", "sa{sv}as", this, SLOT(propertyChanged(QDBusMessage)));
|
||||
}
|
||||
|
98
plugins/shutdown/dbus/dbusaccount.h
Normal file
98
plugins/shutdown/dbus/dbusaccount.h
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (C) 2015 ~ 2018 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* Author: sbw <sbw@sbw.so>
|
||||
*
|
||||
* Maintainer: sbw <sbw@sbw.so>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file was generated by qdbusxml2cpp version 0.8
|
||||
* Command line was: qdbusxml2cpp -c DBusAccount -p dbusaccount com.deepin.daemon.Accounts.xml
|
||||
*
|
||||
* qdbusxml2cpp is Copyright (C) 2015 Digia Plc and/or its subsidiary(-ies).
|
||||
*
|
||||
* This is an auto-generated file.
|
||||
* Do not edit! All changes made to it will be lost.
|
||||
*/
|
||||
|
||||
#ifndef DBUSACCOUNT_H_1439464396
|
||||
#define DBUSACCOUNT_H_1439464396
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtDBus/QtDBus>
|
||||
|
||||
/*
|
||||
* Proxy class for interface com.deepin.daemon.Accounts
|
||||
*/
|
||||
class DBusAccount: public QDBusAbstractInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_SLOT void __propertyChanged__(const QDBusMessage &msg)
|
||||
{
|
||||
QList<QVariant> arguments = msg.arguments();
|
||||
if (3 != arguments.count()) {
|
||||
return;
|
||||
}
|
||||
QString interfaceName = msg.arguments().at(0).toString();
|
||||
if (interfaceName != "com.deepin.daemon.Accounts") {
|
||||
return;
|
||||
}
|
||||
QVariantMap changedProps = qdbus_cast<QVariantMap>(arguments.at(1).value<QDBusArgument>());
|
||||
QStringList keys = changedProps.keys();
|
||||
foreach(const QString & prop, keys) {
|
||||
const QMetaObject *self = metaObject();
|
||||
for (int i = self->propertyOffset(); i < self->propertyCount(); ++i) {
|
||||
QMetaProperty p = self->property(i);
|
||||
if (p.name() == prop) {
|
||||
Q_EMIT p.notifySignal().invoke(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public:
|
||||
static inline const char *staticService()
|
||||
{ return "com.deepin.daemon.Accounts"; }
|
||||
static inline const char *staticInterfacePath()
|
||||
{ return "/com/deepin/daemon/Accounts"; }
|
||||
static inline const char *staticInterfaceName()
|
||||
{ return "com.deepin.daemon.Accounts"; }
|
||||
|
||||
public:
|
||||
DBusAccount(QObject *parent = 0);
|
||||
|
||||
~DBusAccount();
|
||||
|
||||
Q_PROPERTY(QStringList UserList READ userList)
|
||||
inline QStringList userList() const
|
||||
{ return qvariant_cast< QStringList >(property("UserList")); }
|
||||
};
|
||||
|
||||
//namespace com {
|
||||
// namespace deepin {
|
||||
// namespace daemon {
|
||||
// typedef ::DBusAccount Accounts;
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
#endif
|
107
plugins/shutdown/pluginwidget.cpp
Normal file
107
plugins/shutdown/pluginwidget.cpp
Normal file
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* Author: sbw <sbw@sbw.so>
|
||||
*
|
||||
* Maintainer: sbw <sbw@sbw.so>
|
||||
*
|
||||
* 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 "pluginwidget.h"
|
||||
|
||||
#include <QSvgRenderer>
|
||||
#include <QPainter>
|
||||
#include <QMouseEvent>
|
||||
#include <QApplication>
|
||||
|
||||
PluginWidget::PluginWidget(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
m_hover(false)
|
||||
{
|
||||
}
|
||||
|
||||
QSize PluginWidget::sizeHint() const
|
||||
{
|
||||
return QSize(26, 26);
|
||||
}
|
||||
|
||||
void PluginWidget::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
|
||||
QPixmap pixmap;
|
||||
do
|
||||
{
|
||||
const Dock::DisplayMode displayMode = qApp->property(PROP_DISPLAY_MODE).value<Dock::DisplayMode>();
|
||||
|
||||
if (displayMode == Dock::Efficient)
|
||||
{
|
||||
pixmap = loadSvg(":/icons/resources/icons/normal.svg", QSize(16, 16));
|
||||
break;
|
||||
}
|
||||
|
||||
const int iconSize = std::min(width(), height()) * 0.8;
|
||||
pixmap = loadSvg(":/icons/resources/icons/fashion.svg", QSize(iconSize, iconSize));
|
||||
|
||||
} while (false);
|
||||
|
||||
QPainter painter(this);
|
||||
painter.drawPixmap(rect().center() - pixmap.rect().center() / qApp->devicePixelRatio(), pixmap);
|
||||
}
|
||||
|
||||
void PluginWidget::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(QString());
|
||||
return;
|
||||
}
|
||||
|
||||
return QWidget::mousePressEvent(e);
|
||||
}
|
||||
|
||||
void PluginWidget::enterEvent(QEvent *e)
|
||||
{
|
||||
e->accept();
|
||||
m_hover = true;
|
||||
}
|
||||
|
||||
void PluginWidget::leaveEvent(QEvent *e)
|
||||
{
|
||||
e->accept();
|
||||
m_hover = false;
|
||||
}
|
||||
|
||||
const QPixmap PluginWidget::loadSvg(const QString &fileName, const QSize &size) const
|
||||
{
|
||||
const auto ratio = qApp->devicePixelRatio();
|
||||
|
||||
QPixmap pixmap(size * ratio);
|
||||
QSvgRenderer renderer(fileName);
|
||||
pixmap.fill(Qt::transparent);
|
||||
|
||||
QPainter painter;
|
||||
painter.begin(&pixmap);
|
||||
renderer.render(&painter);
|
||||
painter.end();
|
||||
|
||||
pixmap.setDevicePixelRatio(ratio);
|
||||
|
||||
return pixmap;
|
||||
}
|
57
plugins/shutdown/pluginwidget.h
Normal file
57
plugins/shutdown/pluginwidget.h
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* Author: sbw <sbw@sbw.so>
|
||||
*
|
||||
* Maintainer: sbw <sbw@sbw.so>
|
||||
*
|
||||
* 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 PLUGINWIDGET_H
|
||||
#define PLUGINWIDGET_H
|
||||
|
||||
#include "constants.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class PluginWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PluginWidget(QWidget *parent = 0);
|
||||
|
||||
signals:
|
||||
void requestContextMenu(const QString &itemKey) 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:
|
||||
void refershIconPixmap();
|
||||
|
||||
private:
|
||||
bool m_hover;
|
||||
Dock::DisplayMode m_displayMode;
|
||||
};
|
||||
|
||||
#endif // PLUGINWIDGET_H
|
20
plugins/shutdown/resources/icons/fashion.svg
Normal file
20
plugins/shutdown/resources/icons/fashion.svg
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg width="48px" height="48px" viewBox="0 0 48 48" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<!-- Generator: Sketch 39.1 (31720) - http://www.bohemiancoding.com/sketch -->
|
||||
<title>关机按钮</title>
|
||||
<desc>Created with Sketch.</desc>
|
||||
<defs>
|
||||
<linearGradient x1="50.0009524%" y1="99.9990476%" x2="50.0009524%" y2="-0.000952380952%" id="linearGradient-1">
|
||||
<stop stop-color="#5F00F4" offset="0%"></stop>
|
||||
<stop stop-color="#AF4DEB" offset="100%"></stop>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
||||
<g id="关机按钮">
|
||||
<image id="Bitmap" x="1" y="2" width="46" height="46" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC4AAAAuCAYAAABXuSs3AAAABGdBTUEAA1teXP8meAAAA25JREFUaAXV2IlunTAQheGm+6LuUtv3f8Xuazof4Vgm4SJocnPpSBMbGNv/HAZD7tmd69vZOEVah33f8bk/o6WfNuc3tZcXWDs447T87jgQTO9OJyatc3/KE+d4cxIm22KJBxrY39UHssWMvTcOMDbjVycQkDWLiu2Bf64ZtCLmwRiTBFbBrwEXE2jtr/JVk49Aaxrz3h/nlYD5F9fI7aq4WQt0JgV9LAOcElqEBrAEHpVBq2N+bEutW3PRDoH30Go5Ey5OdkMXqW09tX9Q+TnwlIeBSuM2oWu5iVF+dv05cHWWAbdRHhPS7oDafc1P1HehN2pLRnvMB7Ffc6mvTHumFtsrLkAiSuR7izh9R6k8LJ+UzGXFJSJgclvq+JSGBVMv8qAwqKittn84sTPDhI3QWBu4voxktye1cbFwNdVTKrKQ0U19f1jspg0bxqa4DpfEHnaSwpg1bCmVsyieh3J2xI5Otoc0GaS+d8Q4i6LWsTbFJTDZJ2eHnf4kxqFKUipq/H8BnzycEjjld8nae4kRayuVIYu1o08c1xQPR9vcc2KHbWNMjedp3SHrBKntfsBBt/1xEra/A+BYz3vFvU73bhgJfbEnViuL/L7h/F4N47Btp1SyFe4ZPmxYW6k48M37tHyvhg3jIHIUVze+vh6V73FPx4QNI9ameMBl87x8b4YJW8DbwwnUBf8kPyvPblPdkxsWTNiGMkHU3kQORrPluC3fcuLE7ata307ytRz4ZDus48FcEPC4fA8PKgYsga7uhc0pnmsvqzO5PblwS63fUt6Wfy4Px6C29Q+BuzVqC/yX8jag+rdhuN6XU9r6rUSqP9ghcKDgXX9drt7bg1H9YxqlP5RTmdr+u78i3CHwih2Cozx4W9Gxf76we7wrp3QPvQm8xg6q5zYpG69dSlyZqM5dx5Tlm/IX5YADTbjZtZYUrzGDGUxtrSfcAt5kEriumcd2R2X2qVxNpzxmoQWueb2L4ZKk+JPRqUSZj+Vbf29Ux96GSoMgSoMDzh0+CF0xq8DFMfBgJWBhL6l4FpdAngUt80KTsNY4iZvHHYvn48k8i8B1fbA1iidWm/gkACZggZOY64kFAoiSSYqy+tx519kqaIGZXH+LZZyWg+2B58D7BC6Xw2rgQAYgx//SZo605uj7jnuw9NO6vtn+AqnV1gO6qnTBAAAAAElFTkSuQmCC"></image>
|
||||
<path d="M3,24 C3,12.421 12.42,3 24,3 C35.579,3 45,12.421 45,24 C45,35.579 35.579,45 24,45 C12.42,45 3,35.579 3,24 Z" id="path-2" fill="url(#linearGradient-1)"></path>
|
||||
<path d="M23.968,24 C23.416,24 22.968,23.552 22.968,23 L22.968,13 C22.968,12.448 23.416,12 23.968,12 C24.52,12 24.968,12.448 24.968,13 L24.968,23 C24.968,23.552 24.52,24 23.968,24 L23.968,24 L23.968,24 Z" id="path14594" fill="#FFFFFF"></path>
|
||||
<path d="M29.963,15.98 C32.395,17.804 33.968,20.711 33.968,23.984 C33.968,29.507 29.491,33.984 23.968,33.984 C18.445,33.984 13.968,29.507 13.968,23.984 C13.968,20.713 15.539,17.808 17.968,15.984" id="path14596" stroke="#FFFFFF" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.8 KiB |
18
plugins/shutdown/resources/icons/normal.svg
Normal file
18
plugins/shutdown/resources/icons/normal.svg
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- Generator: Adobe Illustrator 18.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px"
|
||||
y="0px" viewBox="0 0 16 16" style="enable-background:new 0 0 16 16;" xml:space="preserve">
|
||||
<g>
|
||||
<g>
|
||||
<path style="fill:#FFFFFF;" d="M7.458,13.976c-3.074,0-5.575-2.501-5.575-5.575c0-1.71,0.77-3.303,2.111-4.368
|
||||
c0.248-0.196,0.611-0.157,0.808,0.093c0.197,0.249,0.156,0.61-0.093,0.808C3.644,5.779,3.033,7.042,3.033,8.4
|
||||
c0,2.44,1.984,4.425,4.425,4.425s4.425-1.984,4.425-4.425c0-1.347-0.603-2.605-1.653-3.45C9.982,4.751,9.942,4.39,10.142,4.142
|
||||
s0.563-0.286,0.809-0.088c1.323,1.064,2.083,2.649,2.083,4.346C13.033,11.475,10.532,13.976,7.458,13.976z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path style="fill:#FFFFFF;" d="M7.5,8.497c-0.276,0-0.5-0.224-0.5-0.5v-5c0-0.276,0.224-0.5,0.5-0.5S8,2.72,8,2.997v5
|
||||
C8,8.273,7.776,8.497,7.5,8.497z"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.1 KiB |
3
plugins/shutdown/shutdown.json
Normal file
3
plugins/shutdown/shutdown.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"api": "1.0"
|
||||
}
|
6
plugins/shutdown/shutdown.qrc
Normal file
6
plugins/shutdown/shutdown.qrc
Normal file
@ -0,0 +1,6 @@
|
||||
<RCC>
|
||||
<qresource prefix="/icons">
|
||||
<file>resources/icons/fashion.svg</file>
|
||||
<file>resources/icons/normal.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
226
plugins/shutdown/shutdownplugin.cpp
Normal file
226
plugins/shutdown/shutdownplugin.cpp
Normal file
@ -0,0 +1,226 @@
|
||||
/*
|
||||
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* Author: sbw <sbw@sbw.so>
|
||||
*
|
||||
* Maintainer: sbw <sbw@sbw.so>
|
||||
*
|
||||
* 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 "shutdownplugin.h"
|
||||
#include "dbus/dbusaccount.h"
|
||||
|
||||
#include <QIcon>
|
||||
#include <QSettings>
|
||||
|
||||
#define PLUGIN_STATE_KEY "enable"
|
||||
|
||||
ShutdownPlugin::ShutdownPlugin(QObject *parent)
|
||||
: QObject(parent),
|
||||
|
||||
m_pluginLoaded(false),
|
||||
m_settings("deepin", "dde-dock-shutdown"),
|
||||
m_tipsLabel(new TipsWidget)
|
||||
{
|
||||
m_tipsLabel->setText(tr("Shutdown"));
|
||||
m_tipsLabel->setVisible(false);
|
||||
}
|
||||
|
||||
const QString ShutdownPlugin::pluginName() const
|
||||
{
|
||||
return "shutdown";
|
||||
}
|
||||
|
||||
const QString ShutdownPlugin::pluginDisplayName() const
|
||||
{
|
||||
return tr("Shutdown");
|
||||
}
|
||||
|
||||
QWidget *ShutdownPlugin::itemWidget(const QString &itemKey)
|
||||
{
|
||||
Q_UNUSED(itemKey);
|
||||
|
||||
return m_shutdownWidget;
|
||||
}
|
||||
|
||||
QWidget *ShutdownPlugin::itemTipsWidget(const QString &itemKey)
|
||||
{
|
||||
Q_UNUSED(itemKey);
|
||||
|
||||
return m_tipsLabel;
|
||||
}
|
||||
|
||||
void ShutdownPlugin::init(PluginProxyInterface *proxyInter)
|
||||
{
|
||||
m_proxyInter = proxyInter;
|
||||
|
||||
if (!pluginIsDisable()) {
|
||||
loadPlugin();
|
||||
}
|
||||
}
|
||||
|
||||
void ShutdownPlugin::pluginStateSwitched()
|
||||
{
|
||||
m_settings.setValue(PLUGIN_STATE_KEY, !m_settings.value(PLUGIN_STATE_KEY, true).toBool());
|
||||
|
||||
if (pluginIsDisable())
|
||||
{
|
||||
m_proxyInter->itemRemoved(this, QString());
|
||||
} else {
|
||||
if (!m_pluginLoaded) {
|
||||
loadPlugin();
|
||||
return;
|
||||
}
|
||||
m_proxyInter->itemAdded(this, QString());
|
||||
}
|
||||
}
|
||||
|
||||
bool ShutdownPlugin::pluginIsDisable()
|
||||
{
|
||||
return !m_settings.value(PLUGIN_STATE_KEY, true).toBool();
|
||||
}
|
||||
|
||||
const QString ShutdownPlugin::itemCommand(const QString &itemKey)
|
||||
{
|
||||
Q_UNUSED(itemKey);
|
||||
|
||||
return QString("dbus-send --print-reply --dest=com.deepin.dde.shutdownFront /com/deepin/dde/shutdownFront com.deepin.dde.shutdownFront.Show");
|
||||
}
|
||||
|
||||
const QString ShutdownPlugin::itemContextMenu(const QString &itemKey)
|
||||
{
|
||||
QList<QVariant> items;
|
||||
items.reserve(6);
|
||||
|
||||
QMap<QString, QVariant> shutdown;
|
||||
shutdown["itemId"] = "Shutdown";
|
||||
shutdown["itemText"] = tr("Shut down");
|
||||
shutdown["isActive"] = true;
|
||||
items.push_back(shutdown);
|
||||
|
||||
QMap<QString, QVariant> reboot;
|
||||
reboot["itemId"] = "Restart";
|
||||
reboot["itemText"] = tr("Restart");
|
||||
reboot["isActive"] = true;
|
||||
items.push_back(reboot);
|
||||
|
||||
QMap<QString, QVariant> suspend;
|
||||
suspend["itemId"] = "Suspend";
|
||||
suspend["itemText"] = tr("Suspend");
|
||||
suspend["isActive"] = true;
|
||||
items.push_back(suspend);
|
||||
|
||||
QMap<QString, QVariant> lock;
|
||||
lock["itemId"] = "Lock";
|
||||
lock["itemText"] = tr("Lock");
|
||||
lock["isActive"] = true;
|
||||
items.push_back(lock);
|
||||
|
||||
QMap<QString, QVariant> logout;
|
||||
logout["itemId"] = "Logout";
|
||||
logout["itemText"] = tr("Log out");
|
||||
logout["isActive"] = true;
|
||||
items.push_back(logout);
|
||||
|
||||
if (DBusAccount().userList().count() > 1)
|
||||
{
|
||||
QMap<QString, QVariant> switchUser;
|
||||
switchUser["itemId"] = "SwitchUser";
|
||||
switchUser["itemText"] = tr("Switch account");
|
||||
switchUser["isActive"] = true;
|
||||
items.push_back(switchUser);
|
||||
}
|
||||
|
||||
QMap<QString, QVariant> power;
|
||||
power["itemId"] = "power";
|
||||
power["itemText"] = tr("Power settings");
|
||||
power["isActive"] = true;
|
||||
items.push_back(power);
|
||||
|
||||
QMap<QString, QVariant> menu;
|
||||
menu["items"] = items;
|
||||
menu["checkableMenu"] = false;
|
||||
menu["singleCheck"] = false;
|
||||
|
||||
return QJsonDocument::fromVariant(menu).toJson();
|
||||
}
|
||||
|
||||
void ShutdownPlugin::invokedMenuItem(const QString &itemKey, const QString &menuId, const bool checked)
|
||||
{
|
||||
Q_UNUSED(itemKey)
|
||||
Q_UNUSED(checked)
|
||||
|
||||
if (menuId == "power")
|
||||
QProcess::startDetached("dbus-send --print-reply --dest=com.deepin.dde.ControlCenter /com/deepin/dde/ControlCenter com.deepin.dde.ControlCenter.ShowModule \"string:power\"");
|
||||
else if (menuId == "Lock")
|
||||
QProcess::startDetached("dbus-send", QStringList() << "--print-reply"
|
||||
<< "--dest=com.deepin.dde.lockFront"
|
||||
<< "/com/deepin/dde/lockFront"
|
||||
<< QString("com.deepin.dde.lockFront.Show"));
|
||||
else
|
||||
QProcess::startDetached("dbus-send", QStringList() << "--print-reply"
|
||||
<< "--dest=com.deepin.dde.shutdownFront"
|
||||
<< "/com/deepin/dde/shutdownFront"
|
||||
<< QString("com.deepin.dde.shutdownFront.%1").arg(menuId));
|
||||
}
|
||||
|
||||
void ShutdownPlugin::displayModeChanged(const Dock::DisplayMode displayMode)
|
||||
{
|
||||
Q_UNUSED(displayMode);
|
||||
|
||||
m_shutdownWidget->update();
|
||||
}
|
||||
|
||||
int ShutdownPlugin::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_settings.value(key, 4).toInt();
|
||||
//} else {
|
||||
//return m_settings.value(key, 4).toInt();
|
||||
//}
|
||||
|
||||
return m_settings.value(key, 4).toInt();
|
||||
}
|
||||
|
||||
void ShutdownPlugin::setSortKey(const QString &itemKey, const int order)
|
||||
{
|
||||
const QString key = QString("pos_%1_%2").arg(itemKey).arg(displayMode());
|
||||
m_settings.setValue(key, order);
|
||||
}
|
||||
|
||||
void ShutdownPlugin::requestContextMenu(const QString &itemKey)
|
||||
{
|
||||
m_proxyInter->requestContextMenu(this, itemKey);
|
||||
}
|
||||
|
||||
void ShutdownPlugin::loadPlugin()
|
||||
{
|
||||
if (m_pluginLoaded) {
|
||||
qDebug() << "shutdown plugin has been loaded! return";
|
||||
return;
|
||||
}
|
||||
|
||||
m_pluginLoaded = true;
|
||||
|
||||
m_shutdownWidget = new PluginWidget;
|
||||
|
||||
connect(m_shutdownWidget, &PluginWidget::requestContextMenu, this, &ShutdownPlugin::requestContextMenu);
|
||||
|
||||
m_proxyInter->itemAdded(this, QString());
|
||||
displayModeChanged(displayMode());
|
||||
}
|
70
plugins/shutdown/shutdownplugin.h
Normal file
70
plugins/shutdown/shutdownplugin.h
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* Author: sbw <sbw@sbw.so>
|
||||
*
|
||||
* Maintainer: sbw <sbw@sbw.so>
|
||||
*
|
||||
* 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 SHUTDOWNPLUGIN_H
|
||||
#define SHUTDOWNPLUGIN_H
|
||||
|
||||
#include "pluginsiteminterface.h"
|
||||
#include "pluginwidget.h"
|
||||
#include "../widgets/tipswidget.h"
|
||||
|
||||
#include <QLabel>
|
||||
|
||||
class ShutdownPlugin : public QObject, PluginsItemInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(PluginsItemInterface)
|
||||
Q_PLUGIN_METADATA(IID "com.deepin.dock.PluginsItemInterface" FILE "shutdown.json")
|
||||
|
||||
public:
|
||||
explicit ShutdownPlugin(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);
|
||||
void setSortKey(const QString &itemKey, const int order);
|
||||
|
||||
private:
|
||||
void requestContextMenu(const QString &itemKey);
|
||||
void loadPlugin();
|
||||
|
||||
private:
|
||||
bool m_pluginLoaded;
|
||||
QSettings m_settings;
|
||||
|
||||
PluginWidget *m_shutdownWidget;
|
||||
TipsWidget *m_tipsLabel;
|
||||
};
|
||||
|
||||
#endif // SHUTDOWNPLUGIN_H
|
@ -21,7 +21,6 @@
|
||||
|
||||
#include "systemtraysmanager.h"
|
||||
#include "sound/soundtrayloader.h"
|
||||
#include "shutdown/shutdowntrayloader.h"
|
||||
#include "shutdown/powertrayloader.h"
|
||||
#include "network/networktrayloader.h"
|
||||
|
||||
@ -29,19 +28,15 @@ SystemTraysManager::SystemTraysManager(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
AbstractTrayLoader *soundLoader = new SoundTrayLoader(this);
|
||||
AbstractTrayLoader *shutdownLoader = new ShutdownTrayLoader(this);
|
||||
AbstractTrayLoader *powerLoader = new PowerTrayLoader(this);
|
||||
AbstractTrayLoader *networkLoader = new NetworkTrayLoader(this);
|
||||
|
||||
m_loaderList.append(soundLoader);
|
||||
m_loaderList.append(shutdownLoader);
|
||||
m_loaderList.append(powerLoader);
|
||||
m_loaderList.append(networkLoader);
|
||||
|
||||
connect(soundLoader, &AbstractTrayLoader::systemTrayAdded, this, &SystemTraysManager::systemTrayWidgetAdded);
|
||||
connect(soundLoader, &AbstractTrayLoader::systemTrayRemoved, this, &SystemTraysManager::systemTrayWidgetRemoved);
|
||||
connect(shutdownLoader, &AbstractTrayLoader::systemTrayAdded, this, &SystemTraysManager::systemTrayWidgetAdded);
|
||||
connect(shutdownLoader, &AbstractTrayLoader::systemTrayRemoved, this, &SystemTraysManager::systemTrayWidgetRemoved);
|
||||
connect(powerLoader, &AbstractTrayLoader::systemTrayAdded, this, &SystemTraysManager::systemTrayWidgetAdded);
|
||||
connect(powerLoader, &AbstractTrayLoader::systemTrayRemoved, this, &SystemTraysManager::systemTrayWidgetRemoved);
|
||||
connect(networkLoader, &AbstractTrayLoader::systemTrayAdded, this, &SystemTraysManager::systemTrayWidgetAdded);
|
||||
|
Loading…
x
Reference in New Issue
Block a user