QSharedData is copy on write and so wrong for what I need
This commit is contained in:
parent
9e918f7435
commit
fa92da30d7
|
@ -24,16 +24,9 @@
|
|||
#include <QTextDocument>
|
||||
|
||||
|
||||
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<NotificationData>(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<NotificationData>(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;
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
|
||||
#include <QVariant>
|
||||
#include <QtCore/QSharedDataPointer>
|
||||
#include <QSharedPointer>
|
||||
|
||||
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<NotificationData> d;
|
||||
QSharedPointer<NotificationData> d;
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(Notification::closeReasons)
|
||||
|
|
|
@ -37,7 +37,6 @@ Q_EXPORT_PLUGIN2(snarl_backend,Snarl_Backend);
|
|||
Snarl_Backend::Snarl_Backend(SnoreServer *snore):
|
||||
Notification_Backend("SnarlBackend",snore)
|
||||
{
|
||||
activeNotifications = new QHash<uint,Notification > ;
|
||||
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"<<notification.toString();
|
||||
qDebug()<<notification.id();
|
||||
qDebug()<<"recived a Snarl callback id:"<<notificationID<<"action:"<<action;
|
||||
qDebug()<<"data:"<<data;
|
||||
Notification::closeReasons reason = Notification::NONE;
|
||||
switch(action){
|
||||
case SnarlEnums::NotifyInvoked:
|
||||
reason = Notification::CLOSED;
|
||||
case SnarlEnums::CallbackInvoked:
|
||||
reason = Notification::CLOSED;
|
||||
break;
|
||||
case SnarlEnums::CallbackMenuSelected:
|
||||
reason = Notification::CLOSED;
|
||||
notification.setActionInvoked(data);
|
||||
_snarl->snore()->notificationActionInvoked(notification);
|
||||
break;
|
||||
case SnarlEnums::CallbackClosed:
|
||||
|
|
|
@ -31,7 +31,7 @@ public:
|
|||
Snarl_Backend(class SnoreServer *snore=0);
|
||||
~Snarl_Backend();
|
||||
bool isPrimaryNotificationBackend();
|
||||
QHash<uint,Notification>* activeNotifications;
|
||||
QHash<uint,Notification> activeNotifications;
|
||||
|
||||
private:
|
||||
SnarlWidget* winIDWidget;
|
||||
|
|
Loading…
Reference in New Issue