mirror of
https://github.com/status-im/snorenotify.git
synced 2025-01-10 00:25:43 +00:00
fixed marcup in snarl-backend,added possebility to use Qwidgets
This commit is contained in:
parent
40bedb896a
commit
3a20a9427f
@ -8,7 +8,7 @@ include_directories (
|
|||||||
add_subdirectory(core)
|
add_subdirectory(core)
|
||||||
|
|
||||||
add_executable ( SnoreNotify main.cpp )
|
add_executable ( SnoreNotify main.cpp )
|
||||||
target_link_libraries ( SnoreNotify snore)
|
target_link_libraries ( SnoreNotify snore ${QT_QTGUI_LIBRARY})
|
||||||
add_dependencies(SnoreNotify snore)
|
add_dependencies(SnoreNotify snore)
|
||||||
|
|
||||||
add_subdirectory(webinterface)
|
add_subdirectory(webinterface)
|
||||||
|
@ -7,6 +7,6 @@ set ( SnoreNotify_SRCS
|
|||||||
|
|
||||||
automoc4_add_library( snore SHARED ${SnoreNotify_SRCS})
|
automoc4_add_library( snore SHARED ${SnoreNotify_SRCS})
|
||||||
set_target_properties( snore PROPERTIES COMPILE_FLAGS "-DSNORECORE_DLL" )
|
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} )
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include "snoreserver.h"
|
#include "snoreserver.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Notification::Notification():source("none"),timeout(10),notification(true){}
|
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)
|
Notification::Notification(QString source,QString title,QString text,QString icon,int timeout):source(source),title(title),text(text),timeout(timeout),icon(icon),notification(true)
|
||||||
{
|
{
|
||||||
|
@ -1,16 +1,11 @@
|
|||||||
#ifndef NOTIFICATION_H
|
#ifndef NOTIFICATION_H
|
||||||
#define NOTIFICATION_H
|
#define NOTIFICATION_H
|
||||||
#include "snore_exports.h"
|
#include "snore_exports.h"
|
||||||
#include <QString>
|
#include <QHash>
|
||||||
#include <QTcpSocket>
|
|
||||||
#include <QUrl>
|
|
||||||
#include <QHttp>
|
|
||||||
#include <QObject>
|
|
||||||
#include "QHash"
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include "application.h"
|
#include "application.h"
|
||||||
#include <QPointer>
|
#include <Qt>
|
||||||
|
#include <QTextEdit>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -18,6 +13,13 @@
|
|||||||
class SNORE_EXPORT Notification:public QObject
|
class SNORE_EXPORT Notification:public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
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:
|
public:
|
||||||
Notification();
|
Notification();
|
||||||
Notification(QString source,QString title,QString text,QString icon,int timeout);
|
Notification(QString source,QString title,QString text,QString icon,int timeout);
|
||||||
@ -31,7 +33,7 @@ public:
|
|||||||
ACTION_3=3,
|
ACTION_3=3,
|
||||||
CLOSED=4
|
CLOSED=4
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
actions actionInvoked;
|
actions actionInvoked;
|
||||||
QString source;
|
QString source;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include <QtCore/QCoreApplication>
|
#include <QtGui/QApplication>
|
||||||
#include "core/snoreserver.h"
|
#include "core/snoreserver.h"
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QCoreApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
SnoreServer s;
|
SnoreServer s;
|
||||||
|
|
||||||
QDir pluginsDir(a.applicationDirPath()+"/plugins");
|
QDir pluginsDir(a.applicationDirPath()+"/plugins");
|
||||||
|
@ -7,5 +7,5 @@ add_subdirectory(webposter)
|
|||||||
add_subdirectory(registredapps)
|
add_subdirectory(registredapps)
|
||||||
add_subdirectory(snarlnetwork)
|
add_subdirectory(snarlnetwork)
|
||||||
add_subdirectory(snarl)
|
add_subdirectory(snarl)
|
||||||
add_subdirectory(dbusbinding)
|
#add_subdirectory(dbusbinding)
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
#include "snarl_backend.h"
|
#include "snarl_backend.h"
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
|
#include <QTextEdit>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -14,10 +17,14 @@ Snarl_Backend::Snarl_Backend()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Snarl_Backend::notify(QSharedPointer<Notification>notification){
|
int Snarl_Backend::notify(QSharedPointer<Notification>notification){
|
||||||
int timeout=notification->timeout>=0?notification->timeout/1000:10;
|
int timeout=notification->timeout>=0?notification->timeout/1000:10;
|
||||||
if(notification->id==0){
|
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{
|
}else{
|
||||||
//update message
|
//update message
|
||||||
snarlInterface->UpdateMessage(LONG32(notification->id),notification->title.toLocal8Bit().data(), notification->text.toLocal8Bit().data(),notification->getIcon().toLocal8Bit().data());
|
snarlInterface->UpdateMessage(LONG32(notification->id),notification->title.toLocal8Bit().data(), notification->text.toLocal8Bit().data(),notification->getIcon().toLocal8Bit().data());
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include <QEventLoop>
|
#include <QEventLoop>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QTcpSocket>
|
||||||
|
|
||||||
Parser::Parser(SnarlNetworkFrontend *snarl):snarl(snarl)
|
Parser::Parser(SnarlNetworkFrontend *snarl):snarl(snarl)
|
||||||
{
|
{
|
||||||
@ -68,7 +69,7 @@ Parser::Parser(SnarlNetworkFrontend *snarl):snarl(snarl)
|
|||||||
sNotification.notification->text=value;
|
sNotification.notification->text=value;
|
||||||
break;
|
break;
|
||||||
case ICON:
|
case ICON:
|
||||||
sNotification.notification->setIcon(download(value));
|
sNotification.notification->setIcon(downloadIcon(value));
|
||||||
break;
|
break;
|
||||||
case CLASS:
|
case CLASS:
|
||||||
sNotification.notification->alert=value;
|
sNotification.notification->alert=value;
|
||||||
@ -117,7 +118,7 @@ Parser::Parser(SnarlNetworkFrontend *snarl):snarl(snarl)
|
|||||||
return sNotification;
|
return sNotification;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Parser::download(const QString &address){
|
QString Parser::downloadIcon(const QString &address){
|
||||||
if(address=="")
|
if(address=="")
|
||||||
return "";
|
return "";
|
||||||
if(address.startsWith("file://"))
|
if(address.startsWith("file://"))
|
||||||
@ -132,15 +133,7 @@ Parser::Parser(SnarlNetworkFrontend *snarl):snarl(snarl)
|
|||||||
if(file.exists())
|
if(file.exists())
|
||||||
return filename;
|
return filename;
|
||||||
|
|
||||||
QNetworkAccessManager manager;
|
QNetworkReply * reply=download(url);
|
||||||
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();
|
|
||||||
|
|
||||||
|
|
||||||
file.open(QIODevice::WriteOnly);
|
file.open(QIODevice::WriteOnly);
|
||||||
file.write(reply->readAll());
|
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"
|
//#include "parser.moc"
|
||||||
|
@ -10,14 +10,17 @@
|
|||||||
|
|
||||||
|
|
||||||
class Parser{
|
class Parser{
|
||||||
|
public:
|
||||||
|
static class QNetworkReply* download(const QUrl &address);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Parser(class SnarlNetworkFrontend* snarl);
|
Parser(class SnarlNetworkFrontend* snarl);
|
||||||
|
|
||||||
struct SnarlNotification parse(QString &msg,QTcpSocket* client);
|
struct SnarlNotification parse(QString &msg,class QTcpSocket* client);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class SnarlNetworkFrontend *snarl;
|
class SnarlNetworkFrontend *snarl;
|
||||||
QString download(const QString &address);
|
QString downloadIcon(const QString &address);
|
||||||
enum snpTypes{
|
enum snpTypes{
|
||||||
TYPE,
|
TYPE,
|
||||||
APP,
|
APP,
|
||||||
|
@ -68,6 +68,7 @@ void SnarlNetworkFrontend::clientDisconnecd(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SnarlNetworkFrontend::callback(const SnarlNotification &sn,QString msg){
|
void SnarlNetworkFrontend::callback(const SnarlNotification &sn,QString msg){
|
||||||
|
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;
|
||||||
|
@ -18,7 +18,6 @@ int WebPoster::notify(QSharedPointer<Notification>notification){
|
|||||||
connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
|
connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebPoster::closeNotification(int id){
|
void WebPoster::closeNotification(int id){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user