-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add plugin notification to show notification center. Notification is a fixed plugin. Log: add plugin notification Issue: linuxdeepin/developer-center#6695
- Loading branch information
Showing
9 changed files
with
310 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
set(PLUGIN_NAME "notification") | ||
find_package(Qt5 REQUIRED COMPONENTS DBus) | ||
find_package(Dtk REQUIRED COMPONENTS Widget) | ||
|
||
add_library(${PLUGIN_NAME} SHARED | ||
notification.h | ||
notification.cpp | ||
notificationplugin.h | ||
notificationplugin.cpp | ||
${CMAKE_SOURCE_DIR}/widgets/tipswidget.h | ||
${CMAKE_SOURCE_DIR}/widgets/tipswidget.cpp | ||
notification.qrc | ||
) | ||
target_compile_definitions(${PLUGIN_NAME} PRIVATE QT_PLUGIN) | ||
set_target_properties(${PLUGIN_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/plugins) | ||
|
||
target_include_directories(${PLUGIN_NAME} PRIVATE | ||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/interfaces> | ||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/widgets> | ||
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/frame/qtdbusextended> | ||
) | ||
|
||
target_link_libraries(${PLUGIN_NAME} PRIVATE | ||
Dtk::Widget | ||
Qt5::DBus | ||
) | ||
|
||
install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION lib/dde-dock/plugins) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
#include "notification.h" | ||
|
||
#include <QPainter> | ||
#include <QPainterPath> | ||
#include <QMouseEvent> | ||
#include <QApplication> | ||
#include <QIcon> | ||
|
||
#include <DStyle> | ||
#include <DGuiApplicationHelper> | ||
|
||
DWIDGET_USE_NAMESPACE; | ||
Notification::Notification(QWidget *parent) | ||
: QWidget(parent) | ||
, m_icon(QIcon::fromTheme("notification")) | ||
{ | ||
setMinimumSize(PLUGIN_BACKGROUND_MIN_SIZE, PLUGIN_BACKGROUND_MIN_SIZE); | ||
} | ||
|
||
QIcon Notification::icon() const | ||
{ | ||
return m_icon; | ||
} | ||
|
||
void Notification::paintEvent(QPaintEvent *e) | ||
{ | ||
Q_UNUSED(e) | ||
QPainter p(this); | ||
m_icon.paint(&p, rect()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
#ifndef NOTIFICATION_H | ||
#define NOTIFICATION_H | ||
#include "constants.h" | ||
|
||
#include <DGuiApplicationHelper> | ||
|
||
#include <QWidget> | ||
#include <QIcon> | ||
|
||
DGUI_USE_NAMESPACE | ||
class Notification : public QWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit Notification(QWidget *parent = nullptr); | ||
QIcon icon() const; | ||
|
||
protected: | ||
void paintEvent(QPaintEvent *e) override; | ||
|
||
private: | ||
QIcon m_icon; | ||
}; | ||
|
||
#endif // NOTIFICATION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"api": "2.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<RCC> | ||
<qresource prefix="/dsg/built-in-icons"> | ||
<file alias="notification.dci">icons/notification.dci</file> | ||
</qresource> | ||
</RCC> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
#include "notificationplugin.h" | ||
|
||
#include <DGuiApplicationHelper> | ||
|
||
#include <QIcon> | ||
#include <QSettings> | ||
#include <QPainter> | ||
|
||
Q_LOGGING_CATEGORY(qLcPluginNotification, "dock.plugin.notification") | ||
|
||
#define PLUGIN_STATE_KEY "enable" | ||
|
||
DGUI_USE_NAMESPACE | ||
using namespace Dock; | ||
|
||
NotificationPlugin::NotificationPlugin(QObject *parent) | ||
: QObject(parent) | ||
, m_pluginLoaded(false) | ||
, m_notification(nullptr) | ||
, m_tipsLabel(new TipsWidget) | ||
{ | ||
m_tipsLabel->setText(tr("Notification")); | ||
m_tipsLabel->setVisible(false); | ||
m_tipsLabel->setAccessibleName("Notification"); | ||
m_tipsLabel->setObjectName("NotificationTipsLabel"); | ||
} | ||
|
||
const QString NotificationPlugin::pluginName() const | ||
{ | ||
return "notification"; | ||
} | ||
|
||
const QString NotificationPlugin::pluginDisplayName() const | ||
{ | ||
return tr("Notification"); | ||
} | ||
|
||
QWidget *NotificationPlugin::itemWidget(const QString &itemKey) | ||
{ | ||
if (itemKey == pluginName()) | ||
return m_notification.data(); | ||
|
||
return nullptr; | ||
} | ||
|
||
QWidget *NotificationPlugin::itemTipsWidget(const QString &itemKey) | ||
{ | ||
Q_UNUSED(itemKey); | ||
|
||
return m_tipsLabel.data(); | ||
} | ||
|
||
void NotificationPlugin::init(PluginProxyInterface *proxyInter) | ||
{ | ||
m_proxyInter = proxyInter; | ||
|
||
if (!pluginIsDisable()) { | ||
loadPlugin(); | ||
} | ||
} | ||
|
||
void NotificationPlugin::pluginStateSwitched() | ||
{ | ||
m_proxyInter->saveValue(this, PLUGIN_STATE_KEY, pluginIsDisable()); | ||
|
||
refreshPluginItemsVisible(); | ||
} | ||
|
||
bool NotificationPlugin::pluginIsDisable() | ||
{ | ||
return !(m_proxyInter->getValue(this, PLUGIN_STATE_KEY, true).toBool()); | ||
} | ||
|
||
const QString NotificationPlugin::itemCommand(const QString &itemKey) | ||
{ | ||
Q_UNUSED(itemKey); | ||
|
||
return QString("dbus-send --session --print-reply --dest=org.deepin.dde.Widgets1 /org/deepin/dde/Widgets1 org.deepin.dde.Widgets1.Toggle"); | ||
} | ||
|
||
void NotificationPlugin::displayModeChanged(const Dock::DisplayMode displayMode) | ||
{ | ||
Q_UNUSED(displayMode); | ||
|
||
if (!pluginIsDisable()) { | ||
m_notification->update(); | ||
} | ||
} | ||
|
||
int NotificationPlugin::itemSortKey(const QString &itemKey) | ||
{ | ||
const QString key = QString("pos_%1_%2").arg(itemKey).arg(Dock::Efficient); | ||
return m_proxyInter->getValue(this, key, 3).toInt(); | ||
} | ||
|
||
void NotificationPlugin::setSortKey(const QString &itemKey, const int order) | ||
{ | ||
const QString key = QString("pos_%1_%2").arg(itemKey).arg(Dock::Efficient); | ||
m_proxyInter->saveValue(this, key, order); | ||
} | ||
|
||
void NotificationPlugin::pluginSettingsChanged() | ||
{ | ||
refreshPluginItemsVisible(); | ||
} | ||
|
||
QIcon NotificationPlugin::icon(const DockPart &dockPart, DGuiApplicationHelper::ColorType themeType) | ||
{ | ||
return m_notification->icon(); | ||
} | ||
|
||
PluginsItemInterface::PluginMode NotificationPlugin::status() const | ||
{ | ||
return PluginsItemInterface::PluginMode::Active; | ||
} | ||
|
||
QString NotificationPlugin::description() const | ||
{ | ||
return pluginDisplayName(); | ||
} | ||
|
||
void NotificationPlugin::loadPlugin() | ||
{ | ||
if (m_pluginLoaded) { | ||
return; | ||
} | ||
m_pluginLoaded = true; | ||
|
||
m_notification.reset(new Notification); | ||
|
||
m_proxyInter->itemAdded(this, pluginName()); | ||
displayModeChanged(displayMode()); | ||
} | ||
|
||
void NotificationPlugin::refreshPluginItemsVisible() | ||
{ | ||
if (pluginIsDisable()) | ||
{ | ||
m_proxyInter->itemRemoved(this, pluginName()); | ||
} else { | ||
if (!m_pluginLoaded) { | ||
loadPlugin(); | ||
return; | ||
} | ||
m_proxyInter->itemAdded(this, pluginName()); | ||
} | ||
} | ||
|
||
NotificationPlugin::PluginType NotificationPlugin::type() | ||
{ | ||
return PluginType::Normal; | ||
} | ||
|
||
PluginFlags NotificationPlugin::flags() const | ||
{ | ||
return PluginFlag::Type_Common | Attribute_ForceDock; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: LGPL-3.0-or-later | ||
#ifndef NOTIFICATIONPLUGIN_H | ||
#define NOTIFICATIONPLUGIN_H | ||
#include "pluginsiteminterface.h" | ||
#include "notification.h" | ||
#include "tipswidget.h" | ||
|
||
class NotificationPlugin : public QObject, public PluginsItemInterface | ||
{ | ||
Q_OBJECT | ||
Q_INTERFACES(PluginsItemInterface) | ||
Q_PLUGIN_METADATA(IID "com.deepin.dock.PluginsItemInterface" FILE "notification.json") | ||
|
||
public: | ||
explicit NotificationPlugin(QObject *parent = nullptr); | ||
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; | ||
void displayModeChanged(const Dock::DisplayMode displayMode) override; | ||
|
||
int itemSortKey(const QString &itemKey) override; | ||
void setSortKey(const QString &itemKey, const int order) override; | ||
|
||
void pluginSettingsChanged() override; | ||
QIcon icon(const DockPart &dockPart, DGuiApplicationHelper::ColorType themeType) override; | ||
PluginMode status() const override; | ||
PluginType type() override; | ||
PluginFlags flags() const override; | ||
QString description() const override; | ||
|
||
private: | ||
void loadPlugin(); | ||
void refreshPluginItemsVisible(); | ||
|
||
private: | ||
bool m_pluginLoaded; | ||
|
||
QScopedPointer<Notification> m_notification; | ||
QScopedPointer<Dock::TipsWidget> m_tipsLabel; | ||
}; | ||
|
||
#endif // NOTIFICATIONPLUGIN_H |