88#include " notificationsetting.h"
99#include " notifyentity.h"
1010
11- #include < QDateTime>
1211#include < DDesktopServices>
1312#include < DSGApplication>
14- #include < QDBusConnection>
1513#include < QDBusConnectionInterface>
1614
1715#include < DConfig>
1816
17+ #include < QAbstractItemModel>
18+ #include < QDBusInterface>
19+ #include < QProcess>
20+ #include < QTimer>
21+ #include < QLoggingCategory>
1922#include < QJsonArray>
2023#include < QJsonDocument>
2124#include < QJsonObject>
@@ -44,7 +47,6 @@ NotificationManager::NotificationManager(QObject *parent)
4447 : QObject(parent)
4548 , m_persistence(DataAccessorProxy::instance())
4649 , m_setting(new NotificationSetting(this ))
47- , m_userSessionManager(new UserSessionManager(SessionDBusService, SessionDaemonDBusPath, QDBusConnection::sessionBus(), this ))
4850 , m_pendingTimeout(new QTimer(this ))
4951{
5052 m_pendingTimeout->setSingleShot (true );
@@ -74,6 +76,8 @@ NotificationManager::NotificationManager(QObject *parent)
7476 m_systemApps = config->value (" systemApps" ).toStringList ();
7577 // TODO temporary fix for AppNamesMap
7678 m_appNamesMap = config->value (" AppNamesMap" ).toMap ();
79+
80+ initScreenLockedState ();
7781}
7882
7983NotificationManager::~NotificationManager ()
@@ -216,8 +220,7 @@ uint NotificationManager::Notify(const QString &appName, uint replacesId, const
216220 bool lockScreenShow = true ;
217221 bool dndMode = isDoNotDisturb ();
218222 bool systemNotification = m_systemApps.contains (appId);
219- bool lockScreen = m_userSessionManager->locked ();
220- const bool desktopScreen = !lockScreen;
223+ const bool desktopScreen = !m_screenLocked;
221224
222225 if (!systemNotification) {
223226 lockScreenShow = m_setting->appValue (appId, NotificationSetting::ShowOnLockScreen).toBool ();
@@ -232,7 +235,7 @@ uint NotificationManager::Notify(const QString &appName, uint replacesId, const
232235
233236 if (systemNotification) { // 系统通知
234237 entity.setProcessedType (NotifyEntity::NotProcessed);
235- } else if (lockScreen && !lockScreenShow) { // 锁屏不显示通知
238+ } else if (m_screenLocked && !lockScreenShow) { // 锁屏不显示通知
236239 entity.setProcessedType (NotifyEntity::Processed);
237240 } else if (desktopScreen && !onDesktopShow) { // 桌面不显示通知
238241 entity.setProcessedType (NotifyEntity::Processed);
@@ -351,9 +354,8 @@ bool NotificationManager::isDoNotDisturb() const
351354 return true ;
352355 }
353356
354- bool lockScreen = m_userSessionManager->locked ();
355357 // 点击锁屏时 并且 锁屏状态 任何时候都勿扰模式
356- if (m_setting->systemValue (NotificationSetting::LockScreenOpenDNDMode).toBool () && lockScreen )
358+ if (m_setting->systemValue (NotificationSetting::LockScreenOpenDNDMode).toBool () && m_screenLocked )
357359 return true ;
358360
359361 QTime currentTime = QTime::fromString (QDateTime::currentDateTime ().toString (" hh:mm" ));
@@ -550,6 +552,26 @@ bool NotificationManager::invokeShellAction(const QString &data)
550552 return false ;
551553}
552554
555+ void NotificationManager::initScreenLockedState ()
556+ {
557+ const QString interfaceAndServiceName = " org.deepin.dde.LockFront1" ;
558+ const QString path = " /org/deepin/dde/LockFront1" ;
559+
560+ QDBusInterface interface (interfaceAndServiceName, path,
561+ " org.freedesktop.DBus.Properties" , QDBusConnection::sessionBus ());
562+
563+ QDBusReply<QDBusVariant> reply = interface.call (" Get" , " org.deepin.dde.LockFront1" , " Visible" );
564+ if (reply.isValid ()) {
565+ m_screenLocked = reply.value ().variant ().toBool ();
566+ } else {
567+ m_screenLocked = false ;
568+ qWarning (notifyLog) << " Failed to get the lock visible property:" << reply.error ().message ();
569+ }
570+
571+ QDBusConnection::sessionBus ().connect (interfaceAndServiceName, path, interfaceAndServiceName,
572+ " Visible" , this , SLOT (onScreenLockedChanged (bool )));
573+ }
574+
553575void NotificationManager::onHandingPendingEntities ()
554576{
555577 QList<NotifyEntity> timeoutEntities;
@@ -600,4 +622,9 @@ void NotificationManager::removePendingEntity(const NotifyEntity &entity)
600622 }
601623}
602624
625+ void NotificationManager::onScreenLockedChanged (bool screenLocked)
626+ {
627+ m_screenLocked = screenLocked;
628+ }
629+
603630} // notification
0 commit comments