This commit is contained in:
Patrick von Reth 2013-07-02 19:17:06 +02:00
parent 7f6700c6a3
commit 6e43a0a872
13 changed files with 37 additions and 35 deletions

Binary file not shown.

View File

@ -245,6 +245,11 @@ void Notification::insertHint ( const QString &key, const QVariant &val )
d->m_hints.insert ( key,val );
}
bool Notification::isValid() const
{
return d != NULL;
}
const QObject *Notification::data() const
{
return d;

View File

@ -95,6 +95,8 @@ public:
bool hintExists ( const QString &key );
void insertHint ( const QString &key,const QVariant &val );
bool isValid() const;
const QObject *data() const;

View File

@ -82,8 +82,8 @@ void SnorePlugin::startTimeout(uint id,int timeout){
void SnorePlugin::notificationTimedOut(){
uint id = m_timeout_order.takeFirst();
m_timeouts.take(id)->deleteLater();
if(m_activeNotifications.contains(id)){
Notification n = m_activeNotifications.take(id);
Notification n = snore()->getActiveNotificationByID(id);
if(n.isValid()){
snore()->closeNotification(n,NotificationEnums::CloseReasons::TIMED_OUT);
}
}

View File

@ -39,7 +39,6 @@ public:
const QString &name() const;
protected:
QHash<uint,Notification> m_activeNotifications;
void startTimeout(uint id,int timeout);
private slots:
void notificationTimedOut();

View File

@ -224,6 +224,7 @@ uint SnoreCore::broadcastNotification ( Notification notification )
qApp->quit();
}
notification.setId(m_notificationBackend->notify( notification ));
m_activeNotifications[notification.id()] = notification;
return notification.id();
}
return -1;
@ -232,6 +233,7 @@ uint SnoreCore::broadcastNotification ( Notification notification )
void SnoreCore::closeNotification ( Notification notification,const NotificationEnums::CloseReasons::closeReasons &reason )
{
notification.setCloseReason(reason);
m_activeNotifications.remove(notification.id());
emit closeNotify ( notification );
}
@ -314,6 +316,11 @@ QSystemTrayIcon *SnoreCore::trayIcon(){
return m_trayIcon;
}
Notification SnoreCore::getActiveNotificationByID(uint id)
{
return m_activeNotifications[id];
}
}
#include "snore.moc"

View File

@ -28,6 +28,7 @@ class QSystemTrayIcon;
class QDir;
class QSettings;
namespace Snore{
class SNORE_EXPORT SnoreCore:public QObject
{
@ -61,6 +62,8 @@ public:
const QString &primaryNotificationBackend();
QSystemTrayIcon *trayIcon();
Notification getActiveNotificationByID(uint id);
private:
@ -71,6 +74,7 @@ private:
static QDir *s_pluginDir;
ApplicationsList m_applications;
QHash<uint,Notification> m_activeNotifications;
QStringList m_notificationBackends;

View File

@ -79,7 +79,6 @@ uint Growl::notify(Notification notification){
Notification::toPlainText(notification.title()).toUtf8().constData(),
Notification::toPlainText(notification.text()).toUtf8().constData(),
notification.icon().localUrl().isEmpty()?NULL:notification.icon().localUrl().toUtf8().constData(),NULL,"1");
m_activeNotifications.insert(m_id,notification);
}catch(const std::exception& e){
qDebug()<<"Growl:"<<e.what();
@ -93,7 +92,7 @@ void Growl::closeNotification(Notification notification){
void Growl::gntpCallback(const int &id,const std::string &reason,const std::string &data){
qDebug()<<"Growl Callback"<<id<<QString(reason.c_str())<<QString(data.c_str());
Notification n = s_instance->m_activeNotifications.take(id);
Notification n = s_instance->snore()->getActiveNotificationByID(id);
NotificationEnums::CloseReasons::closeReasons r = NotificationEnums::CloseReasons::NONE;
if(reason == "TIMEDOUT")
r = NotificationEnums::CloseReasons::TIMED_OUT;

View File

@ -46,6 +46,7 @@ public:
}
bool winEvent( MSG * msg, long * result ){
Q_UNUSED(result);
if(msg->message == SNARL_GLOBAL_MESSAGE){
int action = msg->wParam;
if(action == SnarlEnums::SnarlLaunched){
@ -58,8 +59,7 @@ public:
int action = msg->wParam & 0xffff;
int data = (msg->wParam & 0xffffffff) >> 16;
uint notificationID = msg->lParam;
qDebug()<<"_snarl->activeNotifications"<<m_snarl->m_activeNotifications.keys();
Notification notification(m_snarl->m_activeNotifications[notificationID]);
Notification notification = m_snarl->snore()->getActiveNotificationByID(notificationID);
qDebug()<<"recived a Snarl callback id:"<<notificationID<<"action:"<<action<<"data:"<<data;
NotificationEnums::CloseReasons::closeReasons reason = NotificationEnums::CloseReasons::NONE;
switch(action){
@ -80,12 +80,9 @@ public:
//away stuff
case SnarlEnums::SnarlUserAway:
qDebug()<<"Snalr user has gone away";
m_snarl->m_away = true;
break;
case SnarlEnums::SnarlUserBack:
qDebug()<<"Snalr user has returned";
m_snarl->m_activeNotifications.clear();
m_snarl->m_away = false;
break;
default:
qDebug()<<"Unknown snarl action found!!";
@ -106,8 +103,7 @@ private:
SnarlBackend::SnarlBackend():
SnoreBackend("Snarl"),
m_defautSnarlinetrface(NULL),
m_away(false)
m_defautSnarlinetrface(NULL)
{
}
@ -189,9 +185,6 @@ uint SnarlBackend::notify(Notification notification){
foreach(const Notification::Action *a, notification.actions()){
snarlInterface->AddAction(id,a->name.toUtf8().constData(),QString("@").append(QString::number(a->id)).toUtf8().constData());
}
//add ack stuff
if(!m_away)
m_activeNotifications[id] = notification;
}else{
//update message
snarlInterface->Update(notification.id(),
@ -209,7 +202,6 @@ uint SnarlBackend::notify(Notification notification){
void SnarlBackend::closeNotification(Notification notification){
m_defautSnarlinetrface->Hide(notification.id());
m_activeNotifications.remove(notification.id());
}
#include "snarl.moc"

View File

@ -35,7 +35,6 @@ private:
SnarlBackend::SnarlWidget* m_eventLoop;
QHash<QString,Snarl::V42::SnarlInterface*> m_applications;
Snarl::V42::SnarlInterface* m_defautSnarlinetrface;
bool m_away;
public slots:
void registerApplication(Snore::Application *application);

View File

@ -66,7 +66,6 @@ uint SnoreToast::notify(Notification notification)
uint id = p->pid()->dwProcessId;
p->setProperty("SNORE_NOTIFICATION_ID",id);
m_activeNotifications[id] = notification;
return id;
}
@ -79,7 +78,7 @@ void SnoreToast::closeNotification(Notification notification)
void SnoreToast::slotToastNotificationClosed(int code, QProcess::ExitStatus)
{
QProcess *p = qobject_cast<QProcess*>(sender());
Notification n = m_activeNotifications.take(p->property("SNORE_NOTIFICATION_ID").toUInt());
Notification n = snore()->getActiveNotificationByID(p->property("SNORE_NOTIFICATION_ID").toUInt());
NotificationEnums::CloseReasons::closeReason reason = NotificationEnums::CloseReasons::CLOSED;
@ -89,7 +88,7 @@ void SnoreToast::slotToastNotificationClosed(int code, QProcess::ExitStatus)
reason = NotificationEnums::CloseReasons::CLOSED;
if(!n.actions().isEmpty())
{
n.setActionInvoked(n.actions().begin().key());
n.setActionInvoked(n.actions().keys().first());
snore()->notificationActionInvoked(n);
}
break;

View File

@ -64,28 +64,28 @@ void TrayIconNotifer::displayNotification(){
qDebug()<<"taking"<<notification.title();
m_displayed = notification.id();
m_activeNotifications.insert(notification.id(),notification);
m_trayIcon->showMessage ( Notification::toPlainText(notification.title()),Notification::toPlainText(notification.text()),QSystemTrayIcon::NoIcon,notification.timeout() *1000 );
m_lastNotify.restart();
}
void TrayIconNotifer::closeNotification(){
if(m_activeNotifications.contains(m_displayed)){
Notification noti = m_activeNotifications.take(m_displayed);
snore()->closeNotification(noti,NotificationEnums::CloseReasons::TIMED_OUT);
Notification n = snore()->getActiveNotificationByID(m_displayed);
if(n.isValid()){
snore()->closeNotification(n,NotificationEnums::CloseReasons::TIMED_OUT);
}
displayNotification();
}
void TrayIconNotifer::actionInvoked(){
qDebug()<<"Traicon invoked"<<m_displayed;
if(m_activeNotifications.contains(m_displayed)){
Notification noti = m_activeNotifications.take(m_displayed);
if(noti.actions().isEmpty()){
noti.setActionInvoked(noti.actions().keys().first());
snore()->notificationActionInvoked(noti);
Notification n = snore()->getActiveNotificationByID(m_displayed);
if(n.isValid()){
if(n.actions().isEmpty()){
n.setActionInvoked(n.actions().keys().first());
snore()->notificationActionInvoked(n);
}
snore()->closeNotification(noti,NotificationEnums::CloseReasons::CLOSED);
snore()->closeNotification(n,NotificationEnums::CloseReasons::CLOSED);
}

View File

@ -57,8 +57,6 @@ void FreedesktopFrontend::actionInvoked(Notification notification) {
void FreedesktopFrontend::notificationClosed(Notification notification) {
qDebug()<<"Closing Dbus notification"<<notification.id()<<"reason:"<<(int)notification.closeReason();
m_activeNotifications.remove(notification.id());
qDebug()<<"Active Dbus Notifications"<<m_activeNotifications.keys();
emit NotificationClosed(notification.id(),notification.closeReason());
}
@ -99,7 +97,6 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
}
snore()->broadcastNotification(noti);
m_activeNotifications[noti.id()] = noti;
startTimeout(noti.id(),noti.timeout());
return noti.id();
}
@ -107,8 +104,7 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
void FreedesktopFrontend::CloseNotification(uint id){
Notification noti = m_activeNotifications.take(id);
qDebug()<<"Active Dbus Notifications"<<m_activeNotifications.keys();
Notification noti = snore()->getActiveNotificationByID(id);
snore()->closeNotification(noti,NotificationEnums::CloseReasons::TIMED_OUT);
}