From a6303e005c154f2a53c38f1a6fff6ae082feb029 Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Sat, 12 Nov 2011 18:27:41 +0100 Subject: [PATCH] readded snp 1.0 support --- src/plugins/snarlnetwork/CMakeLists.txt | 2 -- src/plugins/snarlnetwork/parser.cpp | 36 +++++++++++++---------- src/plugins/snarlnetwork/parser.h | 3 +- src/plugins/snarlnetwork/snarlnetwork.cpp | 30 ++++++++++--------- src/plugins/snarlnetwork/snarlnetwork.h | 20 ++++++++----- 5 files changed, 50 insertions(+), 41 deletions(-) diff --git a/src/plugins/snarlnetwork/CMakeLists.txt b/src/plugins/snarlnetwork/CMakeLists.txt index f769056..db64a7a 100644 --- a/src/plugins/snarlnetwork/CMakeLists.txt +++ b/src/plugins/snarlnetwork/CMakeLists.txt @@ -1,4 +1,3 @@ -if(False) #deprecated set( SNARL_NETWORK_SRC snarlnetwork.cpp @@ -8,4 +7,3 @@ automoc4_add_library(snarlnetwork MODULE ${SNARL_NETWORK_SRC} ) target_link_libraries(snarlnetwork snorecore ${QT_QTNETWORK_LIBRARY} ) install(TARGETS snarlnetwork ${PLUGIN_INSTALL_PATH}) -endif(False) \ No newline at end of file diff --git a/src/plugins/snarlnetwork/parser.cpp b/src/plugins/snarlnetwork/parser.cpp index ba3a2fe..378a2f6 100644 --- a/src/plugins/snarlnetwork/parser.cpp +++ b/src/plugins/snarlnetwork/parser.cpp @@ -18,8 +18,8 @@ #include "snarlnetwork.h" #include "core/snoreserver.h" -#include "core/notification.h" -#include "core/utils.h" +#include "core/notification/notification.h" + #include @@ -30,6 +30,8 @@ #include #include +using namespace Snore; + Parser::Parser(SnarlNetworkFrontend *snarl): QObject(snarl), snarl(snarl) @@ -55,6 +57,7 @@ SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){ sNotification.httpClient=false; sNotification.vailid=true; sNotification.clientSocket=client; + sNotification.isNotification = false; snpTypes action(ERROR); @@ -109,50 +112,51 @@ SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){ } } - sNotification.notification=Notification(new Notification(snarl,app,alert,title,text,icon,timeout)); - sNotification.notification->setIsNotification(false); - sNotification.notification->insertHint("SnarlIcon",sntpIcon); + sNotification.notification = Notification(app,alert,title,text,icon,timeout); + sNotification.notification.setSource(snarl); + + sNotification.notification.insertHint("SnarlIcon",sntpIcon); switch(action){ case NOTIFICATION:{ - qDebug()<application(); - Application * appl=snarl->snore()->aplications().value(sNotification.notification->application()); + qDebug()<snore()->aplications().value(sNotification.notification.application()); if(!appl->isInitialized()){ snarl->snore()->applicationIsInitialized(appl); } - if(!appl->alerts().value(sNotification.notification->alert())->isActive()) + if(!appl->alerts().value(sNotification.notification.alert())->isActive()) break; - sNotification.notification->setIsNotification(true); + sNotification.isNotification = true; return sNotification; break; } case ADD_CLASS: - if(sNotification.notification->alert().isEmpty()){ + if(sNotification.notification.alert().isEmpty()){ qDebug()<<"Error registering alert with empty name"; break; } if(title.isEmpty()) title = alert; - snarl->snore()->aplications().value(sNotification.notification->application())->addAlert(new Alert(alert,title)); + snarl->snore()->aplications().value(sNotification.notification.application())->addAlert(new Alert(alert,title)); break; case REGISTER: - if(!snarl->snore()->aplications().contains(sNotification.notification->application())&&!sNotification.notification->application().isEmpty()){ - snarl->snore()->addApplication(new Application(sNotification.notification->application())); + if(!snarl->snore()->aplications().contains(sNotification.notification.application())&&!sNotification.notification.application().isEmpty()){ + snarl->snore()->addApplication(new Application(sNotification.notification.application())); } else - qDebug()<application()<<"already registred"; + qDebug()<snore()->removeApplication(sNotification.notification->application()); + snarl->snore()->removeApplication(sNotification.notification.application()); break; case ERROR: default: sNotification.vailid=false; break; } - sNotification.notification->insertHint("SNaction",sNotification.action); + sNotification.notification.insertHint("SnarlAction",sNotification.action); return sNotification; } diff --git a/src/plugins/snarlnetwork/parser.h b/src/plugins/snarlnetwork/parser.h index a078686..26def44 100644 --- a/src/plugins/snarlnetwork/parser.h +++ b/src/plugins/snarlnetwork/parser.h @@ -18,13 +18,12 @@ #define PARSER_H #include #include -#include "core/notification.h" +#include "core/notification/notification.h" #include #include - class Parser:public QObject{ Q_OBJECT public: diff --git a/src/plugins/snarlnetwork/snarlnetwork.cpp b/src/plugins/snarlnetwork/snarlnetwork.cpp index 1cb5668..4164ba0 100644 --- a/src/plugins/snarlnetwork/snarlnetwork.cpp +++ b/src/plugins/snarlnetwork/snarlnetwork.cpp @@ -22,9 +22,11 @@ #include #include +using namespace Snore; Q_EXPORT_PLUGIN2(snalnetwork,SnarlNetworkFrontend) + SnarlNetworkFrontend::SnarlNetworkFrontend(SnoreServer *snore): Notification_Frontend("SnarlNetworkFrontend",snore) { @@ -43,17 +45,17 @@ SnarlNetworkFrontend::~SnarlNetworkFrontend(){ } -void SnarlNetworkFrontend::actionInvoked(Notificationnotification){ +void SnarlNetworkFrontend::actionInvoked(Notification notification){ //TODO:fix callback - SnarlNotification sn=notifications.value(notification->id()); - if(notification->actionInvoked()==1) + SnarlNotification sn=notifications.value(notification.id()); + if(notification.actionInvoked()->id == 1 ) callback(sn,"SNP/1.1/304/Notification acknowledged/"); - else if(notification->actionInvoked()==2) + else if(notification.actionInvoked()->id == 2) callback(sn,"SNP/1.1/302/Notification cancelled/"); } -void SnarlNetworkFrontend::notificationClosed(Notificationnotification){ - SnarlNotification sn=notifications.value(notification->id()); - if(notification->actionInvoked()==Notification::TIMED_OUT) +void SnarlNetworkFrontend::notificationClosed(Notification notification){ + SnarlNotification sn=notifications.value(notification.id()); + if(notification.closeReason() == NotificationEnums::CloseReasons::TIMED_OUT) callback(sn,"SNP/1.1/303/Notification timed out/"); else callback(sn,"SNP/1.1/307/Notification closed/"); @@ -76,16 +78,16 @@ void SnarlNetworkFrontend::handleMessages(){ SnarlNotification noti=parser->parse(s,client); if(!noti.vailid) continue; - if(noti.notification->isNotification()){ + if(noti.isNotification){ snore()->broadcastNotification(noti.notification); - if(noti.notification->id()!=0){ - out+="/"+QString::number(noti.notification->id()); - notifications.insert(noti.notification->id(),noti); + if(noti.notification.id()!=0){ + out+="/"+QString::number(noti.notification.id()); + notifications.insert(noti.notification.id(),noti); } } out+="\r\n"; - client->write(out.toLatin1()); + client->write(out.toUtf8()); if(noti.httpClient){ client->disconnectFromHost(); client->waitForDisconnected(); @@ -95,9 +97,9 @@ void SnarlNetworkFrontend::handleMessages(){ } void SnarlNetworkFrontend::callback(const SnarlNotification &sn,QString msg){ - notifications.remove(sn.notification->id()); + notifications.remove(sn.notification.id()); if(sn.clientSocket!=NULL&&!msg.isEmpty()){ - msg+=QString::number(sn.notification->id()); + msg+=QString::number(sn.notification.id()); qDebug()<write(msg.toAscii()+"\r\n"); sn.clientSocket->flush(); diff --git a/src/plugins/snarlnetwork/snarlnetwork.h b/src/plugins/snarlnetwork/snarlnetwork.h index 619d18a..4fc0b64 100644 --- a/src/plugins/snarlnetwork/snarlnetwork.h +++ b/src/plugins/snarlnetwork/snarlnetwork.h @@ -21,26 +21,32 @@ #include +namespace Snore{ + class Notification; + class SnoreServer; +} + struct SnarlNotification{ - class QSharedPointer notification; + Snore::Notification notification; QString action; bool httpClient; bool vailid; + bool isNotification; QPointer clientSocket; }; -class SnarlNetworkFrontend:public Notification_Frontend{ +class SnarlNetworkFrontend:public Snore::Notification_Frontend{ Q_OBJECT - Q_INTERFACES(Notification_Frontend) + Q_INTERFACES(Snore::Notification_Frontend) friend class Parser; public: static const int port=9887; public: - SnarlNetworkFrontend(class SnoreServer *snore=0); + SnarlNetworkFrontend(Snore::SnoreServer *snore=0); ~SnarlNetworkFrontend(); - void actionInvoked(Notificationnotification); - void notificationClosed(Notificationnotification); + void actionInvoked(Snore::Notification notification); + void notificationClosed(Snore::Notification notification); private slots: void handleConnection(); @@ -49,7 +55,7 @@ private slots: private: class QTcpServer *tcpServer; Parser *parser; - QHash notifications; + QHash notifications; void callback(const SnarlNotification &sn,QString msg);