fixed marcup in snarl-backend,added possebility to use Qwidgets

This commit is contained in:
theonering 2010-02-25 14:37:44 +01:00
parent 40bedb896a
commit 3a20a9427f
11 changed files with 46 additions and 29 deletions

View File

@ -8,7 +8,7 @@ include_directories (
add_subdirectory(core)
add_executable ( SnoreNotify main.cpp )
target_link_libraries ( SnoreNotify snore)
target_link_libraries ( SnoreNotify snore ${QT_QTGUI_LIBRARY})
add_dependencies(SnoreNotify snore)
add_subdirectory(webinterface)

View File

@ -7,6 +7,6 @@ set ( SnoreNotify_SRCS
automoc4_add_library( snore SHARED ${SnoreNotify_SRCS})
set_target_properties( snore PROPERTIES COMPILE_FLAGS "-DSNORECORE_DLL" )
target_link_libraries ( snore ${QT_QTCORE_LIBRARY} )
target_link_libraries ( snore ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} )

View File

@ -4,6 +4,8 @@
#include "snoreserver.h"
Notification::Notification():source("none"),timeout(10),notification(true){}
Notification::Notification(QString source,QString title,QString text,QString icon,int timeout):source(source),title(title),text(text),timeout(timeout),icon(icon),notification(true)
{

View File

@ -1,16 +1,11 @@
#ifndef NOTIFICATION_H
#define NOTIFICATION_H
#include "snore_exports.h"
#include <QString>
#include <QTcpSocket>
#include <QUrl>
#include <QHttp>
#include <QObject>
#include "QHash"
#include <QHash>
#include <QFile>
#include "application.h"
#include <QPointer>
#include <Qt>
#include <QTextEdit>
@ -18,6 +13,13 @@
class SNORE_EXPORT Notification:public QObject
{
Q_OBJECT
public:
static inline QString toPlainText(const QString &string){
if(!Qt::mightBeRichText ( string))return string;
QTextEdit te;
te.setHtml(string);
return te.toPlainText();
};
public:
Notification();
Notification(QString source,QString title,QString text,QString icon,int timeout);
@ -31,7 +33,7 @@ public:
ACTION_3=3,
CLOSED=4
};
};
actions actionInvoked;
QString source;

View File

@ -1,4 +1,4 @@
#include <QtCore/QCoreApplication>
#include <QtGui/QApplication>
#include "core/snoreserver.h"
#include <QDir>
#include <QFile>
@ -8,7 +8,7 @@
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QApplication a(argc, argv);
SnoreServer s;
QDir pluginsDir(a.applicationDirPath()+"/plugins");

View File

@ -7,5 +7,5 @@ add_subdirectory(webposter)
add_subdirectory(registredapps)
add_subdirectory(snarlnetwork)
add_subdirectory(snarl)
add_subdirectory(dbusbinding)
#add_subdirectory(dbusbinding)

View File

@ -1,5 +1,8 @@
#include "snarl_backend.h"
#include <QtCore>
#include <QTextEdit>
#include <iostream>
@ -14,10 +17,14 @@ Snarl_Backend::Snarl_Backend()
}
int Snarl_Backend::notify(QSharedPointer<Notification>notification){
int timeout=notification->timeout>=0?notification->timeout/1000:10;
if(notification->id==0){
return snarlInterface->ShowMessage(notification->title.toLocal8Bit().data(), notification->text.toLocal8Bit().data(),timeout, notification->getIcon().toLocal8Bit().data());
QString title=Notification::toPlainText(notification->title);
QString text=Notification::toPlainText(notification->text);
qDebug()<<"Calling Snarl"<<title<< text<<QString::number(timeout)<< notification->getIcon();
return snarlInterface->ShowMessage(title.toLocal8Bit().data(), text.toLocal8Bit().data(),timeout, notification->getIcon().toLocal8Bit().data());
}else{
//update message
snarlInterface->UpdateMessage(LONG32(notification->id),notification->title.toLocal8Bit().data(), notification->text.toLocal8Bit().data(),notification->getIcon().toLocal8Bit().data());

View File

@ -8,6 +8,7 @@
#include <QEventLoop>
#include <QNetworkReply>
#include <QObject>
#include <QTcpSocket>
Parser::Parser(SnarlNetworkFrontend *snarl):snarl(snarl)
{
@ -68,7 +69,7 @@ Parser::Parser(SnarlNetworkFrontend *snarl):snarl(snarl)
sNotification.notification->text=value;
break;
case ICON:
sNotification.notification->setIcon(download(value));
sNotification.notification->setIcon(downloadIcon(value));
break;
case CLASS:
sNotification.notification->alert=value;
@ -117,7 +118,7 @@ Parser::Parser(SnarlNetworkFrontend *snarl):snarl(snarl)
return sNotification;
}
QString Parser::download(const QString &address){
QString Parser::downloadIcon(const QString &address){
if(address=="")
return "";
if(address.startsWith("file://"))
@ -132,15 +133,7 @@ Parser::Parser(SnarlNetworkFrontend *snarl):snarl(snarl)
if(file.exists())
return filename;
QNetworkAccessManager manager;
QEventLoop loop;
QNetworkRequest request(url);
request.setRawHeader("User-Agent", "SnoreNotify");
QNetworkReply *reply=manager.get(request);
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
QNetworkReply * reply=download(url);
file.open(QIODevice::WriteOnly);
file.write(reply->readAll());
@ -150,5 +143,15 @@ Parser::Parser(SnarlNetworkFrontend *snarl):snarl(snarl)
}
QNetworkReply* Parser::download(const QUrl &address){
QNetworkAccessManager manager;
QEventLoop loop;
QNetworkRequest request(address);
request.setRawHeader("User-Agent", "SnoreNotify");
QNetworkReply *reply=manager.get(request);
QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
return reply;
}
//#include "parser.moc"

View File

@ -10,14 +10,17 @@
class Parser{
public:
static class QNetworkReply* download(const QUrl &address);
public:
Parser(class SnarlNetworkFrontend* snarl);
struct SnarlNotification parse(QString &msg,QTcpSocket* client);
struct SnarlNotification parse(QString &msg,class QTcpSocket* client);
private:
class SnarlNetworkFrontend *snarl;
QString download(const QString &address);
QString downloadIcon(const QString &address);
enum snpTypes{
TYPE,
APP,

View File

@ -68,6 +68,7 @@ void SnarlNetworkFrontend::clientDisconnecd(){
}
void SnarlNetworkFrontend::callback(const SnarlNotification &sn,QString msg){
notifications.remove(sn.notification->id);
if(sn.clientSocket!=NULL&&!msg.isEmpty()){
msg+=QString::number(sn.notification->id);
qDebug()<<msg;

View File

@ -18,7 +18,6 @@ int WebPoster::notify(QSharedPointer<Notification>notification){
connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
return -1;
}
void WebPoster::closeNotification(int id){