diff --git a/plugins/dde-dock/notification/notification.cpp b/plugins/dde-dock/notification/notification.cpp index 3b8aac70..79823cb4 100644 --- a/plugins/dde-dock/notification/notification.cpp +++ b/plugins/dde-dock/notification/notification.cpp @@ -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 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 @@ -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 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) diff --git a/plugins/dde-dock/notification/notification.h b/plugins/dde-dock/notification/notification.h index e5bc42d3..1125dd73 100644 --- a/plugins/dde-dock/notification/notification.h +++ b/plugins/dde-dock/notification/notification.h @@ -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); diff --git a/plugins/dde-dock/notification/notificationplugin.cpp b/plugins/dde-dock/notification/notificationplugin.cpp index 269698bc..85ba5713 100644 --- a/plugins/dde-dock/notification/notificationplugin.cpp +++ b/plugins/dde-dock/notification/notificationplugin.cpp @@ -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());