removed a lot of dead code

This commit is contained in:
Patrick von Reth 2011-01-02 16:11:23 +01:00
parent 857d91f100
commit 23da56b4a9
19 changed files with 6 additions and 825 deletions

View File

@ -27,6 +27,4 @@ install(TARGETS snorenotify RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
#add_subdirectory(webinterface)
add_subdirectory(plugins)

View File

@ -27,12 +27,12 @@
#include <QSystemTrayIcon>
QString const SnoreServer::version(){
return "0.1";
return "0.1";
}
QString const SnoreServer::snoreTMP(){
static const QString tmp = QDir::temp().path() +"/SnoreNotify/";
return tmp;
static const QString tmp = QDir::temp().path() +"/SnoreNotify/";
return tmp;
}
void SnoreServer::cleanupTMP(){
@ -206,7 +206,7 @@ void SnoreServer::setPrimaryNotificationBackend ( Notification_Backend *backend
}
Notification_Backend * SnoreServer::primaryNotificationBackend(){
return _notificationBackend;
return _notificationBackend;
}
SnoreNotificationInstance * SnoreServer::defaultNotificationInterface()

View File

@ -1,12 +1,7 @@
add_subdirectory(freedesktopnotification)
add_subdirectory(freedesktopfrontend)
#add_subdirectory(webposter)
add_subdirectory(snarlnetwork)
add_subdirectory(snarl)
#add_subdirectory(dbusbinding)
add_subdirectory(growl)
#find a clean solution for the webinterface
#add_subdirectory(redirector)
#add_subdirectory(registredapps)

View File

@ -1,13 +0,0 @@
if(QT_QTDBUS_FOUND)
message(STATUS "Found QtDBus, enabling D-Bus support")
add_definitions(-DHAVE_DBUS)
set( DBUSBINDING_SRC
dbusbinding.cpp
)
automoc4_add_library(dbusbinding MODULE ${DBUSBINDING_SRC} )
target_link_libraries(dbusbinding ${QT_QTDBUS_LIBRARY} snorecore )
install(TARGETS dbusbinding RUNTIME DESTINATION bin/snoreplugins
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif(QT_QTDBUS_FOUND)

View File

@ -1,140 +0,0 @@
/****************************************************************************************
* Copyright (c) 2010 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#include "dbusbinding.h"
#include <QtCore>
DBusBinding::DBusBinding(DBusPlugin* parent,SnoreServer* snore):
QDBusAbstractAdaptor(parent),
snore(snore)
{
registerTypes();
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.registerService( "org.SnoreNotify" );
dbus.registerObject( "/SnoreNotify", this );
connect(snore,SIGNAL(applicationListChanged()),this,SLOT(applicationListChangedSlot()));
}
DBusBinding::~DBusBinding(){
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.unregisterService( "/SnoreNotify" );
}
void DBusBinding::registerTypes(){
qDBusRegisterMetaType<ApplicationsList>();
qDBusRegisterMetaType<Application>();
qDBusRegisterMetaType<Alert>();
qDBusRegisterMetaType<AlertList>();
}
void DBusBinding::setAlertActive(const QString &application,const QString &name,const bool active){
QSharedPointer<Application> ap(snore->aplicationList().value(application));
ap->alerts.value(name)->active=active;
emit applicationListChanged(snore->aplicationList());
}
void DBusBinding::applicationListChangedSlot(){
emit applicationListChanged(snore->aplicationList());
}
QDBusArgument &operator<<(QDBusArgument &a, const ApplicationsList &ap) {
a.beginArray(qMetaTypeId<Application>());
qDebug()<<"ApplicationList:"<<ap.keys();
foreach(QSharedPointer<Application> appl,ap.values()){
a<<*appl.data();
}
a.endArray();
return a;
}
const QDBusArgument & operator >>(const QDBusArgument &a, ApplicationsList &ap) {
a.beginArray();
ap.clear();
Application aplication;
Application * ap_ptr;
while ( !a.atEnd() ) {
a>>aplication;
ap_ptr=new Application(aplication.name);
ap_ptr->alerts=aplication.alerts;
ap.insert(aplication.name,QSharedPointer<Application>(ap_ptr));
}
a.endArray();
return a;
}
QDBusArgument &operator<<(QDBusArgument &a, const Application &ap){
a.beginStructure();
a<<ap.name<<ap.alerts;
a.endStructure();
return a;
}
const QDBusArgument & operator >>(const QDBusArgument &a, Application &ap) {
a.beginStructure();
a>>ap.name;
a>>ap.alerts;
a.endStructure();
return a;
}
QDBusArgument &operator<<(QDBusArgument &a, const Alert &al){
a.beginStructure();
a<<al.name<<al.title<<al.active;
a.endStructure();
return a;
}
const QDBusArgument & operator >>(const QDBusArgument &a, Alert &al) {
a.beginStructure();
a>>al.name;
a>>al.title;
a>>al.active;
a.endStructure();
return a;
}
QDBusArgument &operator<<(QDBusArgument &a, const AlertList &al){
a.beginArray(qMetaTypeId<Alert>());
foreach(QSharedPointer<Alert> alls,al.values()){
a<<*alls.data();
}
a.endArray();
return a;
}
const QDBusArgument & operator >>(const QDBusArgument &a, AlertList &al) {
a.beginArray();
al.clear();
Alert alert;
while ( !a.atEnd() ) {
a>>alert;
al.insert(alert.name,QSharedPointer<Alert>(new Alert(alert.name,alert.title,alert.active)));
}
a.endArray();
return a;
}
Q_EXPORT_PLUGIN2(dbusbinding,DBusPlugin)
DBusPlugin::DBusPlugin(SnoreServer *snore):
SnorePlugin("DBusBackend",snore)
{
}
#include "dbusbinding.moc"

View File

@ -1,78 +0,0 @@
/****************************************************************************************
* Copyright (c) 2010 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#ifndef DBUSBINDING_H
#define DBUSBINDING_H
#include <QtDBus>
#include "core/interface.h"
#include "core/application.h"
#include "core/snoreserver.h"
class DBusPlugin;
class DBusBinding: public QDBusAbstractAdaptor{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.SnoreNotify")
public:
DBusBinding(DBusPlugin* db,SnoreServer* snore);
~DBusBinding();
static void registerTypes();
private:
QPointer<SnoreServer> snore;
public slots:
void setAlertActive(const QString &application,const QString &alert,const bool active);
signals:
void applicationListChanged(const ApplicationsList &);
private slots:
void applicationListChangedSlot();
};
class DBusPlugin:public QObject,SnorePlugin{
Q_OBJECT
Q_INTERFACES(SnorePlugin)
public:
DBusPlugin(class SnoreServer *snore=0);
};
Q_DECLARE_METATYPE(ApplicationsList);
QDBusArgument &operator<<(QDBusArgument &a, const ApplicationsList &ap);
const QDBusArgument & operator >>(const QDBusArgument &a, ApplicationsList &ap) ;
Q_DECLARE_METATYPE(Application);
QDBusArgument &operator<<(QDBusArgument &a, const Application &ap);
const QDBusArgument & operator >>(const QDBusArgument &a, Application &ap) ;
Q_DECLARE_METATYPE(Alert);
QDBusArgument &operator<<(QDBusArgument &a, const Alert &al);
const QDBusArgument & operator >>(const QDBusArgument &a, Alert &al) ;
Q_DECLARE_METATYPE(AlertList);
QDBusArgument &operator<<(QDBusArgument &a, const AlertList &al);
const QDBusArgument & operator >>(const QDBusArgument &a, AlertList &al) ;
#endif // DBUSBINDING_H

View File

@ -1,10 +0,0 @@
if(WITH_WEBINTERFACE)
set( REDIRECTOR_SRC
redirector.cpp
)
automoc4_add_library(redirector MODULE ${REDIRECTOR_SRC})
target_link_libraries(redirector snorecore snorewebinterface)
install(TARGETS redirector RUNTIME DESTINATION bin/snoreplugins
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif(WITH_WEBINTERFACE)

View File

@ -1,114 +0,0 @@
/****************************************************************************************
* Copyright (c) 2010 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#include "redirector.h"
#include "core/snoreserver.h"
#include "core/notification.h"
#include "core/utils.h"
#include <QDebug>
#include <QHostAddress>
#include <QtCore>
#include <QObject>
#include <QTcpSocket>
Q_EXPORT_PLUGIN2(redircetor,Redircetor)
Redircetor::Redircetor(SnoreServer *snore):
Notification_Backend("Redircetor",snore),
WebInterface_Plugin("Redircetor",snore)
{
WebInterface::getInstance()->publicatePlugin(this);
getArgument.insert("subscribe",SUBSCRIBE);
getArgument.insert("unsubscribe",UNSUBSCRIBE);
getArgument.insert("listsubscibers",LISTSUBSCRIBERS);
}
bool Redircetor::parseCommand(QTcpSocket *client, const QString &command){
QHostAddress addres=client->peerAddress();
QString out;
qDebug()<<"parsing";
qDebug()<<command;
qDebug()<<getArgument.value(command);
switch(getArgument.value(command)){
case UNSUBSCRIBE:
if(!subscribers.contains(addres.toString())){
out= "Unubscribe failed you are not a subscriber";
break;
}
subscribers.take(addres.toString()).clear();
out="Sucsefully unsuscribed";
break;
case SUBSCRIBE:{
if(subscribers.contains(addres.toString())){out="Allready suscribed";break;}
if(addres.toString()=="127.0.0.1"){out="Cant subscribe yourself";break;}
QSharedPointer<QTcpSocket> subscriber(new QTcpSocket);
subscriber->connectToHost(addres,port ,QTcpSocket::ReadWrite);
if(subscriber->waitForConnected()){
SnoreServer* snore(Notification_Backend::snore());
foreach(QSharedPointer<Application> a,snore->aplicationList().values()){
QString* app=&a->name;
subscriber->write(QString("type=SNP#?version=1.1#?action=register#?app="+*app+"\r\n").toUtf8());
foreach(const QSharedPointer<Alert> al,a->alerts.values()){
subscriber->write(QString("type=SNP#?version=1.1#?action=add_class#?app="+*app+"#?class="+al->name+"#?title="+al->title+"\r\n").toUtf8());
}
}
subscribers.insert(addres.toString(),subscriber);
out=addres.toString()+" Sucsefully suscribed";
}else
out="Subscription failed no client running?";
break;
}
case LISTSUBSCRIBERS:
out+="\nRegistred Subscriber\n";
foreach(const QString &s,subscribers.keys()){
out+=s+"\n";
}
break;
default:
return false;
}
if(!out.isEmpty()){
client->write(out.toUtf8());
client->disconnectFromHost();
client->waitForDisconnected();
return true;
}
return false;
}
int Redircetor::notify(QSharedPointer<Notification>notification){
foreach(QSharedPointer<QTcpSocket> s,subscribers.values()){
if(s->isWritable()){
qDebug()<<"Sending to subscriber"<<s->peerAddress();
s->write((Utils::notificationToSNTPString(notification)+"\r\n").toLatin1());
}
}
return -1;
}
void Redircetor::closeNotification(int nr){
qWarning()<<"Not supported";
}
QString Redircetor::display(){
return "<a href=\"/subscribe\" >Subscribe </a><br><a href=\"/unsubscribe\" >Unsubscribe </a><br><br><a href=\"/listsubscribers\" >Prints a list of all subscribers</a><br>";
}
#include "redirector.moc"

View File

@ -1,52 +0,0 @@
/****************************************************************************************
* Copyright (c) 2010 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#ifndef REDIRECTOR_H
#define REDIRECTOR_H
#include "core/interface.h"
#include <QHash>
#include "webinterface/webinterface.h"
class Redircetor:public Notification_Backend,WebInterface_Plugin{
Q_OBJECT
Q_INTERFACES(Notification_Backend WebInterface_Plugin)
public:
static const int port=9887;
public:
Redircetor(class SnoreServer *snore=0);
bool isPrimaryNotificationBackend(){return false;}
QString display();
bool parseCommand(QTcpSocket *client, const QString &command);
public slots:
int notify(QSharedPointer<class Notification>notification);
void closeNotification(int nr);
private:
QHash<QString,QSharedPointer<QTcpSocket> > subscribers;
enum ARGUMENTS{
SUBSCRIBE=1,
UNSUBSCRIBE=2,
LISTSUBSCRIBERS=3,
};
QHash<QString,Redircetor::ARGUMENTS> getArgument;
};
#endif//REDIRECTOR_H

View File

@ -1,13 +0,0 @@
if(WITH_WEBINTERFACE)
set( REGISTREDAPPS_SRC
registredapps.cpp
)
automoc4_add_library(registredapps MODULE ${REGISTREDAPPS_SRC} )
target_link_libraries(registredapps snorecore snorewebinterface)
install(TARGETS registredapps RUNTIME DESTINATION bin/snoreplugins
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif(WITH_WEBINTERFACE)

View File

@ -1,55 +0,0 @@
/****************************************************************************************
* Copyright (c) 2010 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#include "registredapps.h"
#include <QtCore>
#include <core/snoreserver.h>
Q_EXPORT_PLUGIN2(registredapps,RegistredApps)
RegistredApps::RegistredApps(SnoreServer *snore):
WebInterface_Plugin("RegistredApps",snore)
{
WebInterface::getInstance()->publicatePlugin(this);
}
bool RegistredApps::parseCommand(QTcpSocket *client, const QString &command){
qDebug()<<"Registred apps";
if(command.toLower()=="overview"){
QString out;
out+="Registred Applications\n";
SnoreServer *snore=WebInterface_Plugin::snore();
foreach(QSharedPointer<Application> a,snore->aplicationList().values()){
out+=a->name+"\n";
out+="Registred alerts of "+a->name+"\t alert\t title \t is Active\n";
foreach(const QSharedPointer<Alert> al,a->alerts.values())
out+=al->name+"\t"+al->title+"\t\t"+(al->active?"true":"false")+"\n";
}
client->write(out.toUtf8());
client->disconnectFromHost();
client->waitForDisconnected();
return true;
}
return false;
}
QString RegistredApps::display(){
return "<a href=\"/overview\" >Overview of Registred applications </a><br>";
}
#include "registredapps.moc"

View File

@ -1,33 +0,0 @@
/****************************************************************************************
* Copyright (c) 2010 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#ifndef REGISTREDAPPS_H
#define REGISTREDAPPS_H
#include "core/snore_exports.h"
#include "core/interface.h"
#include "webinterface/webinterface.h"
#include <QtNetwork>
class RegistredApps:public QObject,WebInterface_Plugin{
Q_OBJECT
Q_INTERFACES(SnorePlugin WebInterface_Plugin)
public:
RegistredApps(class SnoreServer *snore=0);
bool parseCommand(QTcpSocket *client, const QString &command);
QString display();
};
#endif//REGISTREDAPPS_H

View File

@ -79,8 +79,8 @@ void SnarlNetworkFrontend::handleMessages(){
if(noti.notification->isNotification()){
snore()->broadcastNotification(noti.notification);
if(noti.notification->id()!=0){
out+="/"+QString::number(noti.notification->id());
notifications.insert(noti.notification->id(),noti);
out+="/"+QString::number(noti.notification->id());
notifications.insert(noti.notification->id(),noti);
}
}
out+="\r\n";

View File

@ -1,7 +0,0 @@
set( WEBPOSTER_SRC
webposter.cpp
)
automoc4_add_library(webposter MODULE ${WEBPOSTER_SRC} )
target_link_libraries(webposter snorecore ${QT_QTNETWORK_LIBRARY} )
install(TARGETS webposter ${PLUGIN_INSTALL_PATH})

View File

@ -1,62 +0,0 @@
/****************************************************************************************
* Copyright (c) 2010 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#include "webposter.h"
#include <QDebug>
#include <QtCore>
#include <iostream>
#include "core/utils.h"
Q_EXPORT_PLUGIN2(webposter,WebPoster)
WebPoster::WebPoster(SnoreServer *snore):
Notification_Backend("WebPoster",snore)
{
manager=new QNetworkAccessManager(this);
}
void WebPoster::registerApplication(Application *application){
}
void WebPoster::unregisterApplication(Application *application){
}
int WebPoster::notify(QSharedPointer<Notification>notification){
QByteArray byte(Utils::notificationToSNTPString(notification).toLatin1().data());
QUrl url("http://www.pro-zeit.ch/index.php");
url.addEncodedQueryItem("action","add");
url.addEncodedQueryItem("data",QUrl::toPercentEncoding(byte.toBase64()));
QNetworkRequest request(url);
request.setRawHeader("User-Agent", "SnoreNotify");
QNetworkReply *reply=manager->get(request);
QEventLoop loop;
connect(reply, SIGNAL(readyRead()), &loop, SLOT(quit()));
loop.exec();
return -1;
}
void WebPoster::closeNotification(QSharedPointer<Notification> notification){
//not supportted
}
#include "webposter.moc"

View File

@ -1,42 +0,0 @@
/****************************************************************************************
* Copyright (c) 2010 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#ifndef WEBPOSTER_H
#define WEBPOSTER_H
#include "core/snore_exports.h"
#include "core/interface.h"
#include <QtNetwork>
class WebPoster: public Notification_Backend{
Q_OBJECT
Q_INTERFACES(Notification_Backend)
public:
WebPoster(class SnoreServer *snore=0);
bool isPrimaryNotificationBackend(){return false;}
public slots:
void registerApplication(Application *application);
void unregisterApplication(class Application *application);
int notify(QSharedPointer<Notification>notification);
void closeNotification(QSharedPointer<Notification> notification);
private:
QNetworkAccessManager *manager;
};
#endif//WEBPOSTER_H

View File

@ -1,14 +0,0 @@
if(WITH_WEBINTERFACE)
message(STATUS "Enabling WebInterface support")
set( WEBINTERFACE_SRC
webinterface.cpp
)
automoc4_add_library(snorewebinterface SHARED ${WEBINTERFACE_SRC} )
set_target_properties( snorewebinterface PROPERTIES COMPILE_FLAGS "-DWEBINTERFACE_DLL" )
target_link_libraries(snorewebinterface snorecore ${QT_QTNETWORK_LIBRARY} )
install(TARGETS snorewebinterface RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif(WITH_WEBINTERFACE)

View File

@ -1,102 +0,0 @@
/****************************************************************************************
* Copyright (c) 2010 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#include "webinterface.h"
#include "core/snoreserver.h"
#include <QTcpServer>
#include <QObject>
#include <QTcpSocket>
#include <QDebug>
#include <QtCore>
WebInterface* WebInterface::_instance=0;
WebInterface* WebInterface::getInstance()
{
if ( _instance==NULL )
_instance=new WebInterface();
return _instance;
}
WebInterface::WebInterface()
{
tcpServer=new QTcpServer ( this );
if ( !tcpServer->listen ( QHostAddress::Any,port ) )
{
qDebug() <<"The subscription port is already used";
}
getArgument.insert ( "",ROOT );
getArgument.insert ( "overview",OVERVIEW );
connect ( tcpServer, SIGNAL ( newConnection() ), this, SLOT ( handleConnection() ) );
}
WebInterface::~WebInterface()
{
qDebug() <<"Unloading Webinterface";
tcpServer->deleteLater();
}
void WebInterface::publicatePlugin ( WebInterface_Plugin *plugin )
{
webinterfaces.append ( plugin );
qDebug() <<"appending Webinterface Plugin";
}
void WebInterface::handleConnection()
{
QTcpSocket* client= tcpServer->nextPendingConnection();
connect ( client,SIGNAL ( readyRead() ),this,SLOT ( handleMessages() ) );
}
void WebInterface::handleMessages()
{
qDebug() <<"Webinteface";
QTcpSocket *client= ( QTcpSocket* ) sender();
QString in ( QString::fromUtf8 ( client->readAll() ) );
in=in.mid ( in.indexOf ( "/" ) +1 );
in=in.mid ( 0,in.indexOf ( " " ) );
QString out;
qDebug() <<getArgument.value ( in.toLower() );
if ( !in.isEmpty() )
foreach ( WebInterface_Plugin* pl,webinterfaces )
{
qDebug() <<"Paring in:";
if ( pl->parseCommand ( client,in.toLower() ) )
return;
}
out+="<html><head><TITLE>SnoreNotify Configuration</TITLE></head><body>";
foreach ( WebInterface_Plugin* plugin, webinterfaces )
out.append ( plugin->display() );
out+="</body></html>";
client->write ( out.toUtf8() );
qDebug() <<"Sending over web interface:\n"<<out;
client->disconnectFromHost();
client->waitForDisconnected();
}
WebInterface_Plugin::WebInterface_Plugin ( QString name,SnoreServer *snore ) :
SnorePlugin ( name,snore )
{
}
WebInterface_Plugin::~WebInterface_Plugin()
{
}
#include "webinterface.moc"

View File

@ -1,77 +0,0 @@
/****************************************************************************************
* Copyright (c) 2010 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#ifndef WEBINTERFACE_H
#define WEBINTERFACE_H
#include <QObject>
#include <QTcpServer>
#include <QHash>
#include "core/application.h"
#include "core/interface.h"
#ifdef WEBINTERFACE_DLL
# define WEBINTERFACE_EXPORT Q_DECL_EXPORT
#else
# define WEBINTERFACE_EXPORT Q_DECL_IMPORT
#endif
class WebInterface_Plugin;
class WEBINTERFACE_EXPORT WebInterface:public QObject
{
Q_OBJECT
public:
static const int port=9886;
static WebInterface* getInstance();
public:
void publicatePlugin ( WebInterface_Plugin* plugin );
public slots:
void handleConnection();
void handleMessages();
private:
static WebInterface *_instance;
WebInterface();
~WebInterface();
QList<WebInterface_Plugin*> webinterfaces;
QTcpServer *tcpServer;
enum ARGUMENTS
{
ROOT,
SUBSCRIBE,
UNSUBSCRIBE,
OVERVIEW
};
QHash<QString,WebInterface::ARGUMENTS> getArgument;
};
class WEBINTERFACE_EXPORT WebInterface_Plugin:public SnorePlugin
{
public:
WebInterface_Plugin ( QString name,class SnoreServer *snore=0 );
virtual ~WebInterface_Plugin();
virtual QString display() =0;
virtual bool parseCommand ( QTcpSocket *client,const QString &command ) =0;
};
Q_DECLARE_INTERFACE ( WebInterface_Plugin,
"org.Snore.WebInterface/1.0" )
#endif // WEBINTERFACE_H