Skip to content

Commit

Permalink
fix: notification number doesn't change
Browse files Browse the repository at this point in the history
new notification changes the signal name.

task: https://pms.uniontech.com/task-view-365219.html
  • Loading branch information
18202781743 committed Oct 15, 2024
1 parent cdaa230 commit 9a7a652
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 33 deletions.
74 changes: 41 additions & 33 deletions plugins/dde-dock/notification/notification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,6 @@ Notification::Notification(QWidget *parent)
setMinimumSize(PLUGIN_BACKGROUND_MIN_SIZE, PLUGIN_BACKGROUND_MIN_SIZE);
connect(this, &Notification::dndModeChanged, this, &Notification::refreshIcon);
connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &Notification::refreshIcon);
QtConcurrent::run([this](){
m_dbus.reset(new QDBusInterface("org.deepin.dde.Notification1", "/org/deepin/dde/Notification1", "org.deepin.dde.Notification1"));
// Refresh icon for the first time, cause org.deepin.dde.Notification1 might depend on dock's DBus,
// we should not call org.deepin.dde.Notification1 in the main thread before dock's dbus is initialized.
// Just refresh icon in the other thread.
QDBusReply<QDBusVariant> dnd = m_dbus->call(QLatin1String("GetSystemInfo"), QVariant::fromValue(0u));
if (!dnd.isValid()) {
qCWarning(qLcPluginNotification) << dnd.error();
} else {
m_dndMode = dnd.value().variant().toBool();
refreshIcon();
}
QDBusConnection::sessionBus().connect("org.deepin.dde.Notification1",
"/org/deepin/dde/Notification1",
"org.deepin.dde.Notification1",
"SystemInfoChanged",
this,
SLOT(onSystemInfoChanged(quint32,QDBusVariant))
);
auto recordCountVariant = m_dbus->property("recordCount");
if (!recordCountVariant.isValid()) {
qCWarning(qLcPluginNotification) << dnd.error();
} else {
setNotificationCount(recordCountVariant.toUInt());
}
QDBusConnection::sessionBus().connect("org.deepin.dde.Notification1",
"/org/deepin/dde/Notification1",
"org.deepin.dde.Notification1",
"recordCountChanged",
this,
SLOT(setNotificationCount(uint))
);
});
}

QIcon Notification::icon() const
Expand Down Expand Up @@ -104,6 +71,47 @@ uint Notification::notificationCount() const
return m_notificationCount;
}

void Notification::watchNotification(bool newNotification)
{
QtConcurrent::run([this, newNotification](){
m_dbus.reset(new QDBusInterface("org.deepin.dde.Notification1", "/org/deepin/dde/Notification1", "org.deepin.dde.Notification1"));
// Refresh icon for the first time, cause org.deepin.dde.Notification1 might depend on dock's DBus,
// we should not call org.deepin.dde.Notification1 in the main thread before dock's dbus is initialized.
// Just refresh icon in the other thread.
QDBusReply<QDBusVariant> dnd = m_dbus->call(QLatin1String("GetSystemInfo"), QVariant::fromValue(0u));
if (!dnd.isValid()) {
qCWarning(qLcPluginNotification) << dnd.error();
} else {
m_dndMode = dnd.value().variant().toBool();
refreshIcon();
}
QDBusConnection::sessionBus().connect("org.deepin.dde.Notification1",
"/org/deepin/dde/Notification1",
"org.deepin.dde.Notification1",
"SystemInfoChanged",
this,
SLOT(onSystemInfoChanged(quint32,QDBusVariant))
);
auto recordCountVariant = m_dbus->property("recordCount");
if (!recordCountVariant.isValid()) {
qCWarning(qLcPluginNotification) << dnd.error();
} else {
setNotificationCount(recordCountVariant.toUInt());
}

const QString countChangedSlot = newNotification ?
"RecordCountChanged" :
"recordCountChanged";
QDBusConnection::sessionBus().connect("org.deepin.dde.Notification1",
"/org/deepin/dde/Notification1",
"org.deepin.dde.Notification1",
countChangedSlot,
this,
SLOT(setNotificationCount(uint))
);
});
}

void Notification::paintEvent(QPaintEvent *e)
{
Q_UNUSED(e)
Expand Down
2 changes: 2 additions & 0 deletions plugins/dde-dock/notification/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Notification : public QWidget
void setDndMode(bool dnd);
uint notificationCount() const;

void watchNotification(bool newNotification);

Q_SIGNALS:
void iconRefreshed();
void dndModeChanged(bool dnd);
Expand Down
1 change: 1 addition & 0 deletions plugins/dde-dock/notification/notificationplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ void NotificationPlugin::loadPlugin()
}
m_pluginLoaded = true;
m_notification.reset(new Notification);
m_notification->watchNotification(newNotifications());
connect(m_notification.data(), &Notification::iconRefreshed, this, [this]() { m_proxyInter->itemUpdate(this, pluginName()); });
connect(m_notification.data(), &Notification::notificationCountChanged, this, &NotificationPlugin::updateTipsText);
m_proxyInter->itemAdded(this, pluginName());
Expand Down

0 comments on commit 9a7a652

Please sign in to comment.