forked from quickshell/quickshell
		
	service/notifications: make notifications Retainable
This commit is contained in:
		
							parent
							
								
									609834d8f2
								
							
						
					
					
						commit
						e23923d9a2
					
				
					 3 changed files with 19 additions and 2 deletions
				
			
		| 
						 | 
					@ -39,6 +39,11 @@ QString NotificationAction::identifier() const { return this->mIdentifier; }
 | 
				
			||||||
QString NotificationAction::text() const { return this->mText; }
 | 
					QString NotificationAction::text() const { return this->mText; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void NotificationAction::invoke() {
 | 
					void NotificationAction::invoke() {
 | 
				
			||||||
 | 
						if (this->notification->isRetained()) {
 | 
				
			||||||
 | 
							qCritical() << "Cannot invoke destroyed notification" << this;
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	NotificationServer::instance()->ActionInvoked(this->notification->id(), this->mIdentifier);
 | 
						NotificationServer::instance()->ActionInvoked(this->notification->id(), this->mIdentifier);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!this->notification->isResident()) {
 | 
						if (!this->notification->isResident()) {
 | 
				
			||||||
| 
						 | 
					@ -57,6 +62,11 @@ void Notification::expire() { this->close(NotificationCloseReason::Expired); }
 | 
				
			||||||
void Notification::dismiss() { this->close(NotificationCloseReason::Dismissed); }
 | 
					void Notification::dismiss() { this->close(NotificationCloseReason::Dismissed); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Notification::close(NotificationCloseReason::Enum reason) {
 | 
					void Notification::close(NotificationCloseReason::Enum reason) {
 | 
				
			||||||
 | 
						if (this->isRetained()) {
 | 
				
			||||||
 | 
							qCritical() << "Cannot close destroyed notification" << this;
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	this->mCloseReason = reason;
 | 
						this->mCloseReason = reason;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (reason != 0) {
 | 
						if (reason != 0) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -8,6 +8,8 @@
 | 
				
			||||||
#include <qqmlintegration.h>
 | 
					#include <qqmlintegration.h>
 | 
				
			||||||
#include <qtmetamacros.h>
 | 
					#include <qtmetamacros.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "../../core/retainable.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace qs::service::notifications {
 | 
					namespace qs::service::notifications {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class NotificationImage;
 | 
					class NotificationImage;
 | 
				
			||||||
| 
						 | 
					@ -50,7 +52,12 @@ public:
 | 
				
			||||||
class NotificationAction;
 | 
					class NotificationAction;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
///! A notification emitted by a NotificationServer.
 | 
					///! A notification emitted by a NotificationServer.
 | 
				
			||||||
class Notification: public QObject {
 | 
					/// A notification emitted by a NotificationServer.
 | 
				
			||||||
 | 
					/// > [!INFO] This type is [Retainable](/docs/types/quickshell/retainable). It
 | 
				
			||||||
 | 
					/// > can be retained after destruction if necessary.
 | 
				
			||||||
 | 
					class Notification
 | 
				
			||||||
 | 
					    : public QObject
 | 
				
			||||||
 | 
					    , public Retainable {
 | 
				
			||||||
	Q_OBJECT;
 | 
						Q_OBJECT;
 | 
				
			||||||
	/// Id of the notification as given to the client.
 | 
						/// Id of the notification as given to the client.
 | 
				
			||||||
	Q_PROPERTY(quint32 id READ id CONSTANT);
 | 
						Q_PROPERTY(quint32 id READ id CONSTANT);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -105,7 +105,7 @@ void NotificationServer::deleteNotification(
 | 
				
			||||||
	this->idMap.remove(notification->id());
 | 
						this->idMap.remove(notification->id());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	emit this->NotificationClosed(notification->id(), reason);
 | 
						emit this->NotificationClosed(notification->id(), reason);
 | 
				
			||||||
	delete notification;
 | 
						notification->retainedDestroy();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void NotificationServer::tryRegister() {
 | 
					void NotificationServer::tryRegister() {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue