From fa92da30d7a151273b7e9f76e4158d19a14f4876 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Mon, 18 Jul 2011 18:58:02 +0200 Subject: [PATCH] QSharedData is copy on write and so wrong for what I need --- src/core/notification.cpp | 18 ++++++++---------- src/core/notification.h | 15 ++++++++------- src/plugins/snarl/snarl_backend.cpp | 18 ++++++++++-------- src/plugins/snarl/snarl_backend.h | 2 +- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/core/notification.cpp b/src/core/notification.cpp index 8aa4555..3f724cd 100644 --- a/src/core/notification.cpp +++ b/src/core/notification.cpp @@ -24,16 +24,9 @@ #include -class Notification::NotificationData:public QSharedData +class Notification::NotificationData { public: - NotificationData(): - _id ( 0), - _timeout ( 10 ), - _source ( NULL ), - _closeReason(Notification::NONE), - _notification( false ){}; - NotificationData ( uint id=0 ): _id ( id ), _timeout ( 10 ), @@ -90,12 +83,12 @@ QString Notification::toPlainText ( const QString &string ) Notification::Notification ( uint id ) { - d = new NotificationData(id); + d = QSharedPointer(new NotificationData(id)); } Notification::Notification ( Notification_Frontend *source, const QString &application, const QString &alert, const QString &title, const QString &text, const QString &icon, int timeout, uint id ) { - d = new NotificationData(source,application,alert,title,text,icon,timeout,id); + d = QSharedPointer(new NotificationData(source,application,alert,title,text,icon,timeout,id)); } Notification::Notification ( const Notification &other ): @@ -158,6 +151,11 @@ void Notification::setActionInvoked ( Action *action ) d->_actionInvoked = action; } +void Notification::setActionInvoked ( const int &id) +{ + d->_actionInvoked = d->_actions[id]; +} + Notification_Frontend *Notification::source() const { return d->_source; diff --git a/src/core/notification.h b/src/core/notification.h index c709a7d..6291f35 100644 --- a/src/core/notification.h +++ b/src/core/notification.h @@ -21,7 +21,7 @@ #include -#include +#include class Action { @@ -39,10 +39,10 @@ public: static QString toPlainText ( const QString &string ); enum closeReason { - NONE=0, - TIMED_OUT=1, - DISMISSED=2, - CLOSED=3 + NONE, + TIMED_OUT, + DISMISSED, + CLOSED }; Q_DECLARE_FLAGS(closeReasons, closeReason) public: @@ -50,7 +50,7 @@ public: Notification ( class Notification_Frontend *source,const QString &application,const QString &alert,const QString &title,const QString &text,const QString &icon,int timeout=10,uint id=0 ); Notification ( const Notification &other ); ~Notification(); - Notification& operator=(const Notification& other); + Notification &operator=(const Notification& other); QString toString() const; bool isNotification(); @@ -61,6 +61,7 @@ public: const int &timeout() const; //void setActionInvoked ( const Notification::defaultActions &action ); void setActionInvoked ( Action *action ); + void setActionInvoked ( const int &actionID); //const Notification::defaultActions &actionInvoked() const; const Action* actionInvoked() const; class Notification_Frontend *source() const; @@ -80,7 +81,7 @@ public: private: class NotificationData; - QSharedDataPointer d; + QSharedPointer d; }; Q_DECLARE_OPERATORS_FOR_FLAGS(Notification::closeReasons) diff --git a/src/plugins/snarl/snarl_backend.cpp b/src/plugins/snarl/snarl_backend.cpp index 6ad810f..ad660f1 100644 --- a/src/plugins/snarl/snarl_backend.cpp +++ b/src/plugins/snarl/snarl_backend.cpp @@ -37,7 +37,6 @@ Q_EXPORT_PLUGIN2(snarl_backend,Snarl_Backend); Snarl_Backend::Snarl_Backend(SnoreServer *snore): Notification_Backend("SnarlBackend",snore) { - activeNotifications = new QHash ; winIDWidget = new SnarlWidget(this); SnarlInterface *snarlInterface = new SnarlInterface(); _applications.insert("SnoreNotify",snarlInterface); @@ -53,7 +52,6 @@ Snarl_Backend::~Snarl_Backend() unregisterApplication(a); } delete _defautSnarlinetrface; - delete activeNotifications; } void Snarl_Backend::registerApplication(Application *application){ @@ -105,7 +103,7 @@ int Snarl_Backend::notify(Notification notification){ snarlInterface->AddAction(id,a->name.toUtf8().constData(),QString("@").append(QString::number(a->id)).toUtf8().constData()); } //add ack stuff - activeNotifications->insert(id,notification); + activeNotifications[id] = notification; }else{ //update message snarlInterface->Update(notification.id(), @@ -120,7 +118,7 @@ int Snarl_Backend::notify(Notification notification){ void Snarl_Backend::closeNotification(Notification notification){ _defautSnarlinetrface->Hide(notification.id()); - activeNotifications->remove(notification.id()); + activeNotifications.remove(notification.id()); } bool Snarl_Backend::isPrimaryNotificationBackend(){ @@ -146,16 +144,20 @@ bool SnarlWidget::winEvent(MSG * msg, long * result){ int action = msg->wParam & 0xffff; int data = (msg->wParam & 0xffffffff) >> 16; uint notificationID = msg->lParam; - qDebug()<<_snarl->activeNotifications->keys(); - Notification notification = _snarl->activeNotifications->value(notificationID); + qDebug()<<_snarl->activeNotifications.keys(); + Notification notification(_snarl->activeNotifications[notificationID]); qDebug()<<"arg"<snore()->notificationActionInvoked(notification); break; case SnarlEnums::CallbackClosed: diff --git a/src/plugins/snarl/snarl_backend.h b/src/plugins/snarl/snarl_backend.h index 0af097e..d4f5b85 100644 --- a/src/plugins/snarl/snarl_backend.h +++ b/src/plugins/snarl/snarl_backend.h @@ -31,7 +31,7 @@ public: Snarl_Backend(class SnoreServer *snore=0); ~Snarl_Backend(); bool isPrimaryNotificationBackend(); - QHash* activeNotifications; + QHash activeNotifications; private: SnarlWidget* winIDWidget;