mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
feat: add overlay warning plugin
https://github.com/linuxdeepin/internal-discussion/issues/1126
This commit is contained in:
parent
974bb8808f
commit
da3b42a85e
1
debian/dde-dock.install
vendored
1
debian/dde-dock.install
vendored
@ -5,5 +5,6 @@
|
||||
/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/liboverlay-warning.so
|
||||
/usr/lib/dde-dock/plugins/system-trays
|
||||
/etc/dde-dock
|
||||
|
@ -9,3 +9,4 @@ add_subdirectory("tray")
|
||||
add_subdirectory("trash")
|
||||
add_subdirectory("keyboard-layout")
|
||||
add_subdirectory("onboard")
|
||||
add_subdirectory("overlay-warning")
|
||||
|
31
plugins/overlay-warning/CMakeLists.txt
Normal file
31
plugins/overlay-warning/CMakeLists.txt
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
set(PLUGIN_NAME "overlay-warning")
|
||||
|
||||
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} overlay-warning.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)
|
||||
|
||||
# policy kit
|
||||
install(FILES com.deepin.dde.dock.overlay.policy
|
||||
DESTINATION share/polkit-1/actions/)
|
20
plugins/overlay-warning/com.deepin.dde.dock.overlay.policy
Normal file
20
plugins/overlay-warning/com.deepin.dde.dock.overlay.policy
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE policyconfig PUBLIC
|
||||
"-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
|
||||
"http://www.freedesktop.org/standards/PolicyKit/1/policyconfig.dtd">
|
||||
<policyconfig>
|
||||
<vendor>Deepin</vendor>
|
||||
<action id="com.deepin.dde.dock.overlay">
|
||||
<icon_name>dialog-warning</icon_name>
|
||||
<message>The system is in overlay mode, and all your work will not be saved. Do you want to exit this mode and restart?</message>
|
||||
<defaults>
|
||||
<allow_any>no</allow_any>
|
||||
<allow_inactive>no</allow_inactive>
|
||||
<allow_active>auth_admin_keep</allow_active>
|
||||
</defaults>
|
||||
<message xml:lang="zh_CN">本次启动处于 overlay 保护模式下,您的所有操作将不会被保存,是否要关闭此模式并重启?</message>
|
||||
<annotate key="org.freedesktop.policykit.exec.path">/usr/sbin/overlayroot-disable</annotate>
|
||||
<annotate key="org.freedesktop.policykit.exec.allow_gui">true</annotate>
|
||||
</action>
|
||||
|
||||
</policyconfig>
|
170
plugins/overlay-warning/overlay-warning-plugin.cpp
Normal file
170
plugins/overlay-warning/overlay-warning-plugin.cpp
Normal file
@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* Author: sbw <sbw@sbw.so>
|
||||
* 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 "overlay-warning-plugin.h"
|
||||
|
||||
#include <QIcon>
|
||||
#include <QStorageInfo>
|
||||
|
||||
#include <ddialog.h>
|
||||
|
||||
#define PLUGIN_STATE_KEY "enable"
|
||||
#define OverlayFileSystemType "overlay"
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
OverlayWarningPlugin::OverlayWarningPlugin(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_pluginLoaded(false)
|
||||
{
|
||||
}
|
||||
|
||||
const QString OverlayWarningPlugin::pluginName() const
|
||||
{
|
||||
return "overlay-warning";
|
||||
}
|
||||
|
||||
const QString OverlayWarningPlugin::pluginDisplayName() const
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
||||
QWidget *OverlayWarningPlugin::itemWidget(const QString &itemKey)
|
||||
{
|
||||
Q_UNUSED(itemKey);
|
||||
|
||||
return m_warningWidget;
|
||||
}
|
||||
|
||||
QWidget *OverlayWarningPlugin::itemTipsWidget(const QString &itemKey)
|
||||
{
|
||||
Q_UNUSED(itemKey);
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void OverlayWarningPlugin::init(PluginProxyInterface *proxyInter)
|
||||
{
|
||||
m_proxyInter = proxyInter;
|
||||
|
||||
if (!pluginIsDisable()) {
|
||||
loadPlugin();
|
||||
}
|
||||
}
|
||||
|
||||
void OverlayWarningPlugin::pluginStateSwitched()
|
||||
{
|
||||
m_proxyInter->saveValue(this, PLUGIN_STATE_KEY, !m_proxyInter->getValue(this, PLUGIN_STATE_KEY, true).toBool());
|
||||
|
||||
if (pluginIsDisable())
|
||||
{
|
||||
m_proxyInter->itemRemoved(this, pluginName());
|
||||
} else {
|
||||
if (!m_pluginLoaded) {
|
||||
loadPlugin();
|
||||
return;
|
||||
}
|
||||
m_proxyInter->itemAdded(this, pluginName());
|
||||
}
|
||||
}
|
||||
|
||||
bool OverlayWarningPlugin::pluginIsDisable()
|
||||
{
|
||||
return !m_proxyInter->getValue(this, PLUGIN_STATE_KEY, true).toBool();
|
||||
}
|
||||
|
||||
const QString OverlayWarningPlugin::itemCommand(const QString &itemKey)
|
||||
{
|
||||
Q_UNUSED(itemKey);
|
||||
|
||||
showCloseOverlayDialog();
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
void OverlayWarningPlugin::displayModeChanged(const Dock::DisplayMode displayMode)
|
||||
{
|
||||
Q_UNUSED(displayMode);
|
||||
|
||||
if (!pluginIsDisable()) {
|
||||
m_warningWidget->update();
|
||||
}
|
||||
}
|
||||
|
||||
int OverlayWarningPlugin::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, 2).toInt();
|
||||
} else {
|
||||
return m_proxyInter->getValue(this, key, 5).toInt();
|
||||
}
|
||||
}
|
||||
|
||||
void OverlayWarningPlugin::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 OverlayWarningPlugin::loadPlugin()
|
||||
{
|
||||
if (m_pluginLoaded) {
|
||||
qDebug() << "overlay-warning plugin has been loaded! return";
|
||||
return;
|
||||
}
|
||||
|
||||
m_pluginLoaded = true;
|
||||
|
||||
m_warningWidget = new PluginWidget;
|
||||
|
||||
if (!isOverlayRoot()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_proxyInter->itemAdded(this, pluginName());
|
||||
displayModeChanged(displayMode());
|
||||
|
||||
QTimer::singleShot(3000, this, &OverlayWarningPlugin::showCloseOverlayDialog);
|
||||
}
|
||||
|
||||
bool OverlayWarningPlugin::isOverlayRoot()
|
||||
{
|
||||
// ignore live/recovery mode
|
||||
if (QString(QFile("/proc/cmdline").readAll()).contains("boot=live")) {
|
||||
return false;
|
||||
}
|
||||
return QString(QStorageInfo::root().fileSystemType()) == OverlayFileSystemType;
|
||||
}
|
||||
|
||||
void OverlayWarningPlugin::showCloseOverlayDialog()
|
||||
{
|
||||
const int result = QProcess::execute("/usr/bin/pkexec overlayroot-disable");
|
||||
|
||||
if (result == 0) {
|
||||
QProcess::startDetached("reboot");
|
||||
} else {
|
||||
qDebug() << "close overlayroot failed, the return code is" << result;
|
||||
}
|
||||
}
|
76
plugins/overlay-warning/overlay-warning-plugin.h
Normal file
76
plugins/overlay-warning/overlay-warning-plugin.h
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* Author: sbw <sbw@sbw.so>
|
||||
* 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 SHUTDOWNPLUGIN_H
|
||||
#define SHUTDOWNPLUGIN_H
|
||||
|
||||
#include "pluginsiteminterface.h"
|
||||
#include "pluginwidget.h"
|
||||
#include "../widgets/tipswidget.h"
|
||||
|
||||
#include <QLabel>
|
||||
|
||||
namespace Dtk {
|
||||
namespace Widget {
|
||||
class DDialog;
|
||||
}
|
||||
}
|
||||
|
||||
class OverlayWarningPlugin : public QObject, PluginsItemInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(PluginsItemInterface)
|
||||
Q_PLUGIN_METADATA(IID "com.deepin.dock.PluginsItemInterface" FILE "overlay-warning.json")
|
||||
|
||||
public:
|
||||
explicit OverlayWarningPlugin(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 false; }
|
||||
bool pluginIsDisable() override;
|
||||
|
||||
QWidget *itemWidget(const QString &itemKey) override;
|
||||
QWidget *itemTipsWidget(const QString &itemKey) override;
|
||||
const QString itemCommand(const QString &itemKey) 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 loadPlugin();
|
||||
bool isOverlayRoot();
|
||||
|
||||
private slots:
|
||||
void showCloseOverlayDialog();
|
||||
|
||||
private:
|
||||
bool m_pluginLoaded;
|
||||
|
||||
PluginWidget *m_warningWidget;
|
||||
};
|
||||
|
||||
#endif // SHUTDOWNPLUGIN_H
|
3
plugins/overlay-warning/overlay-warning.json
Normal file
3
plugins/overlay-warning/overlay-warning.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"api": "1.1.1"
|
||||
}
|
5
plugins/overlay-warning/overlay-warning.qrc
Normal file
5
plugins/overlay-warning/overlay-warning.qrc
Normal file
@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/icons">
|
||||
<file>resources/icons/overlay-warning.svg</file>
|
||||
</qresource>
|
||||
</RCC>
|
72
plugins/overlay-warning/pluginwidget.cpp
Normal file
72
plugins/overlay-warning/pluginwidget.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* Author: sbw <sbw@sbw.so>
|
||||
* 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 "pluginwidget.h"
|
||||
|
||||
#include <QSvgRenderer>
|
||||
#include <QPainter>
|
||||
#include <QMouseEvent>
|
||||
#include <QApplication>
|
||||
#include <QIcon>
|
||||
|
||||
PluginWidget::PluginWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QSize PluginWidget::sizeHint() const
|
||||
{
|
||||
return QSize(26, 26);
|
||||
}
|
||||
|
||||
void PluginWidget::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
|
||||
QPixmap pixmap;
|
||||
QString iconName = ":/icons/resources/icons/overlay-warning.svg";
|
||||
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);
|
||||
}
|
||||
|
||||
const QPixmap PluginWidget::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;
|
||||
}
|
48
plugins/overlay-warning/pluginwidget.h
Normal file
48
plugins/overlay-warning/pluginwidget.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2011 ~ 2018 Deepin Technology Co., Ltd.
|
||||
*
|
||||
* Author: sbw <sbw@sbw.so>
|
||||
* 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 PLUGINWIDGET_H
|
||||
#define PLUGINWIDGET_H
|
||||
|
||||
#include "constants.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class PluginWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PluginWidget(QWidget *parent = 0);
|
||||
|
||||
protected:
|
||||
QSize sizeHint() const;
|
||||
void paintEvent(QPaintEvent *e);
|
||||
|
||||
private:
|
||||
const QPixmap loadSvg(const QString &fileName, const QSize &size) const;
|
||||
|
||||
private:
|
||||
Dock::DisplayMode m_displayMode;
|
||||
};
|
||||
|
||||
#endif // PLUGINWIDGET_H
|
@ -0,0 +1,3 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">
|
||||
<path fill="#EB9900" d="M7.63381441,2.50138835 L1.86522449,12.5002775 C1.5892354,12.9786586 1.75330654,13.5901965 2.23168762,13.8661856 C2.38364083,13.9538509 2.55598208,14 2.73141008,14 L14.2685899,14 C14.8208747,14 15.2685899,13.5522847 15.2685899,13 C15.2685899,12.824572 15.2224408,12.6522307 15.1347755,12.5002775 L9.36618559,2.50138835 C9.0901965,2.02300726 8.47865864,1.85893613 8.00027755,2.13492522 C7.84804196,2.22275344 7.72164264,2.34915276 7.63381441,2.50138835 Z M8,5 L9,5 L9,9 L8,9 L8,5 Z M8.5,12 C7.948,12 7.5,11.552 7.5,11 C7.5,10.448 7.948,10 8.5,10 C9.052,10 9.5,10.448 9.5,11 C9.5,11.552 9.052,12 8.5,12 Z"/>
|
||||
</svg>
|
After Width: | Height: | Size: 722 B |
Loading…
x
Reference in New Issue
Block a user