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
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)

View File

@ -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 <QDir>
@ -30,6 +30,8 @@
#include <QObject>
#include <QTcpSocket>
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()<<sNotification.notification->application();
Application * appl=snarl->snore()->aplications().value(sNotification.notification->application());
qDebug()<<sNotification.notification.application();
Application * appl=snarl->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()<<sNotification.notification->application()<<"already registred";
qDebug()<<sNotification.notification.application()<<"already registred";
break;
case UNREGISTER:
snarl->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;
}

View File

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

View File

@ -22,9 +22,11 @@
#include <QTcpSocket>
#include <iostream>
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()<<msg;
sn.clientSocket->write(msg.toAscii()+"\r\n");
sn.clientSocket->flush();

View File

@ -21,26 +21,32 @@
#include <QPointer>
namespace Snore{
class Notification;
class SnoreServer;
}
struct SnarlNotification{
class QSharedPointer<class Notification> notification;
Snore::Notification notification;
QString action;
bool httpClient;
bool vailid;
bool isNotification;
QPointer<class QTcpSocket> 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<int,SnarlNotification> notifications;
QHash<uint,SnarlNotification> notifications;
void callback(const SnarlNotification &sn,QString msg);