readded snp 1.0 support

This commit is contained in:
Patrick von Reth 2011-11-12 18:27:41 +01:00
parent cf13a539fd
commit a6303e005c
5 changed files with 50 additions and 41 deletions

View File

@ -1,4 +1,3 @@
if(False)
#deprecated #deprecated
set( SNARL_NETWORK_SRC set( SNARL_NETWORK_SRC
snarlnetwork.cpp snarlnetwork.cpp
@ -8,4 +7,3 @@ automoc4_add_library(snarlnetwork MODULE ${SNARL_NETWORK_SRC} )
target_link_libraries(snarlnetwork snorecore ${QT_QTNETWORK_LIBRARY} ) target_link_libraries(snarlnetwork snorecore ${QT_QTNETWORK_LIBRARY} )
install(TARGETS snarlnetwork ${PLUGIN_INSTALL_PATH}) install(TARGETS snarlnetwork ${PLUGIN_INSTALL_PATH})
endif(False)

View File

@ -18,8 +18,8 @@
#include "snarlnetwork.h" #include "snarlnetwork.h"
#include "core/snoreserver.h" #include "core/snoreserver.h"
#include "core/notification.h" #include "core/notification/notification.h"
#include "core/utils.h"
#include <QDir> #include <QDir>
@ -30,6 +30,8 @@
#include <QObject> #include <QObject>
#include <QTcpSocket> #include <QTcpSocket>
using namespace Snore;
Parser::Parser(SnarlNetworkFrontend *snarl): Parser::Parser(SnarlNetworkFrontend *snarl):
QObject(snarl), QObject(snarl),
snarl(snarl) snarl(snarl)
@ -55,6 +57,7 @@ SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){
sNotification.httpClient=false; sNotification.httpClient=false;
sNotification.vailid=true; sNotification.vailid=true;
sNotification.clientSocket=client; sNotification.clientSocket=client;
sNotification.isNotification = false;
snpTypes action(ERROR); 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 = Notification(app,alert,title,text,icon,timeout);
sNotification.notification->setIsNotification(false); sNotification.notification.setSource(snarl);
sNotification.notification->insertHint("SnarlIcon",sntpIcon);
sNotification.notification.insertHint("SnarlIcon",sntpIcon);
switch(action){ switch(action){
case NOTIFICATION:{ case NOTIFICATION:{
qDebug()<<sNotification.notification->application(); qDebug()<<sNotification.notification.application();
Application * appl=snarl->snore()->aplications().value(sNotification.notification->application()); Application * appl=snarl->snore()->aplications().value(sNotification.notification.application());
if(!appl->isInitialized()){ if(!appl->isInitialized()){
snarl->snore()->applicationIsInitialized(appl); snarl->snore()->applicationIsInitialized(appl);
} }
if(!appl->alerts().value(sNotification.notification->alert())->isActive()) if(!appl->alerts().value(sNotification.notification.alert())->isActive())
break; break;
sNotification.notification->setIsNotification(true); sNotification.isNotification = true;
return sNotification; return sNotification;
break; break;
} }
case ADD_CLASS: case ADD_CLASS:
if(sNotification.notification->alert().isEmpty()){ if(sNotification.notification.alert().isEmpty()){
qDebug()<<"Error registering alert with empty name"; qDebug()<<"Error registering alert with empty name";
break; break;
} }
if(title.isEmpty()) if(title.isEmpty())
title = alert; 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; break;
case REGISTER: case REGISTER:
if(!snarl->snore()->aplications().contains(sNotification.notification->application())&&!sNotification.notification->application().isEmpty()){ if(!snarl->snore()->aplications().contains(sNotification.notification.application())&&!sNotification.notification.application().isEmpty()){
snarl->snore()->addApplication(new Application(sNotification.notification->application())); snarl->snore()->addApplication(new Application(sNotification.notification.application()));
} }
else else
qDebug()<<sNotification.notification->application()<<"already registred"; qDebug()<<sNotification.notification.application()<<"already registred";
break; break;
case UNREGISTER: case UNREGISTER:
snarl->snore()->removeApplication(sNotification.notification->application()); snarl->snore()->removeApplication(sNotification.notification.application());
break; break;
case ERROR: case ERROR:
default: default:
sNotification.vailid=false; sNotification.vailid=false;
break; break;
} }
sNotification.notification->insertHint("SNaction",sNotification.action); sNotification.notification.insertHint("SnarlAction",sNotification.action);
return sNotification; return sNotification;
} }

View File

@ -18,13 +18,12 @@
#define PARSER_H #define PARSER_H
#include <QString> #include <QString>
#include <QHash> #include <QHash>
#include "core/notification.h" #include "core/notification/notification.h"
#include <QSharedPointer> #include <QSharedPointer>
#include <QObject> #include <QObject>
class Parser:public QObject{ class Parser:public QObject{
Q_OBJECT Q_OBJECT
public: public:

View File

@ -22,9 +22,11 @@
#include <QTcpSocket> #include <QTcpSocket>
#include <iostream> #include <iostream>
using namespace Snore;
Q_EXPORT_PLUGIN2(snalnetwork,SnarlNetworkFrontend) Q_EXPORT_PLUGIN2(snalnetwork,SnarlNetworkFrontend)
SnarlNetworkFrontend::SnarlNetworkFrontend(SnoreServer *snore): SnarlNetworkFrontend::SnarlNetworkFrontend(SnoreServer *snore):
Notification_Frontend("SnarlNetworkFrontend",snore) Notification_Frontend("SnarlNetworkFrontend",snore)
{ {
@ -43,17 +45,17 @@ SnarlNetworkFrontend::~SnarlNetworkFrontend(){
} }
void SnarlNetworkFrontend::actionInvoked(Notificationnotification){ void SnarlNetworkFrontend::actionInvoked(Notification notification){
//TODO:fix callback //TODO:fix callback
SnarlNotification sn=notifications.value(notification->id()); SnarlNotification sn=notifications.value(notification.id());
if(notification->actionInvoked()==1) if(notification.actionInvoked()->id == 1 )
callback(sn,"SNP/1.1/304/Notification acknowledged/"); 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/"); callback(sn,"SNP/1.1/302/Notification cancelled/");
} }
void SnarlNetworkFrontend::notificationClosed(Notificationnotification){ void SnarlNetworkFrontend::notificationClosed(Notification notification){
SnarlNotification sn=notifications.value(notification->id()); SnarlNotification sn=notifications.value(notification.id());
if(notification->actionInvoked()==Notification::TIMED_OUT) if(notification.closeReason() == NotificationEnums::CloseReasons::TIMED_OUT)
callback(sn,"SNP/1.1/303/Notification timed out/"); callback(sn,"SNP/1.1/303/Notification timed out/");
else else
callback(sn,"SNP/1.1/307/Notification closed/"); callback(sn,"SNP/1.1/307/Notification closed/");
@ -76,16 +78,16 @@ void SnarlNetworkFrontend::handleMessages(){
SnarlNotification noti=parser->parse(s,client); SnarlNotification noti=parser->parse(s,client);
if(!noti.vailid) if(!noti.vailid)
continue; continue;
if(noti.notification->isNotification()){ if(noti.isNotification){
snore()->broadcastNotification(noti.notification); snore()->broadcastNotification(noti.notification);
if(noti.notification->id()!=0){ if(noti.notification.id()!=0){
out+="/"+QString::number(noti.notification->id()); out+="/"+QString::number(noti.notification.id());
notifications.insert(noti.notification->id(),noti); notifications.insert(noti.notification.id(),noti);
} }
} }
out+="\r\n"; out+="\r\n";
client->write(out.toLatin1()); client->write(out.toUtf8());
if(noti.httpClient){ if(noti.httpClient){
client->disconnectFromHost(); client->disconnectFromHost();
client->waitForDisconnected(); client->waitForDisconnected();
@ -95,9 +97,9 @@ void SnarlNetworkFrontend::handleMessages(){
} }
void SnarlNetworkFrontend::callback(const SnarlNotification &sn,QString msg){ void SnarlNetworkFrontend::callback(const SnarlNotification &sn,QString msg){
notifications.remove(sn.notification->id()); notifications.remove(sn.notification.id());
if(sn.clientSocket!=NULL&&!msg.isEmpty()){ if(sn.clientSocket!=NULL&&!msg.isEmpty()){
msg+=QString::number(sn.notification->id()); msg+=QString::number(sn.notification.id());
qDebug()<<msg; qDebug()<<msg;
sn.clientSocket->write(msg.toAscii()+"\r\n"); sn.clientSocket->write(msg.toAscii()+"\r\n");
sn.clientSocket->flush(); sn.clientSocket->flush();

View File

@ -21,26 +21,32 @@
#include <QPointer> #include <QPointer>
namespace Snore{
class Notification;
class SnoreServer;
}
struct SnarlNotification{ struct SnarlNotification{
class QSharedPointer<class Notification> notification; Snore::Notification notification;
QString action; QString action;
bool httpClient; bool httpClient;
bool vailid; bool vailid;
bool isNotification;
QPointer<class QTcpSocket> clientSocket; QPointer<class QTcpSocket> clientSocket;
}; };
class SnarlNetworkFrontend:public Notification_Frontend{ class SnarlNetworkFrontend:public Snore::Notification_Frontend{
Q_OBJECT Q_OBJECT
Q_INTERFACES(Notification_Frontend) Q_INTERFACES(Snore::Notification_Frontend)
friend class Parser; friend class Parser;
public: public:
static const int port=9887; static const int port=9887;
public: public:
SnarlNetworkFrontend(class SnoreServer *snore=0); SnarlNetworkFrontend(Snore::SnoreServer *snore=0);
~SnarlNetworkFrontend(); ~SnarlNetworkFrontend();
void actionInvoked(Notificationnotification); void actionInvoked(Snore::Notification notification);
void notificationClosed(Notificationnotification); void notificationClosed(Snore::Notification notification);
private slots: private slots:
void handleConnection(); void handleConnection();
@ -49,7 +55,7 @@ private slots:
private: private:
class QTcpServer *tcpServer; class QTcpServer *tcpServer;
Parser *parser; Parser *parser;
QHash<int,SnarlNotification> notifications; QHash<uint,SnarlNotification> notifications;
void callback(const SnarlNotification &sn,QString msg); void callback(const SnarlNotification &sn,QString msg);