initial commit

This commit is contained in:
theonering 2010-02-20 16:30:03 +01:00
commit d5d1290397
57 changed files with 5910 additions and 0 deletions

19
CMakeLists.txt Normal file
View File

@ -0,0 +1,19 @@
project( SnoreNotify )
cmake_minimum_required( VERSION 2.6 )
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
add_definitions ( -Wall )
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package ( Qt4 REQUIRED )
find_package(Automoc4 REQUIRED)
set ( EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/build )
set(LIBRARY_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH})
if(MINGW)
include_directories (${CMAKE_SOURCE_DIR}/include)
add_definitions(-D_WIN32_WINNT=0x0500)
endif(MINGW)
option(WITH_WEBINTERFACE "Buld with WebInterface" OFF)
add_subdirectory(src)

322
include/specstrings.h Normal file
View File

@ -0,0 +1,322 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the w64 mingw-runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#define __specstrings
#ifdef __cplusplus
#ifndef __nothrow
#define __nothrow __declspec(nothrow)
#endif
extern "C" {
#else
#ifndef __nothrow
#define __nothrow
#endif
#endif
#define SAL__deref_in
#define SAL__deref_in_ecount(size)
#define SAL__deref_in_bcount(size)
#define SAL__deref_in_opt
#define SAL__deref_in_ecount_opt(size)
#define SAL__deref_in_bcount_opt(size)
#define SAL__deref_opt_in
#define SAL__deref_opt_in_ecount(size)
#define SAL__deref_opt_in_bcount(size)
#define SAL__deref_opt_in_opt
#define SAL__deref_opt_in_ecount_opt(size)
#define SAL__deref_opt_in_bcount_opt(size)
#define SAL__out_awcount(expr,size)
#define SAL__in_awcount(expr,size)
/* Renamed __null to SAL__null for avoiding private keyword conflicts between
gcc and MS world. */
#define SAL__null
#define SAL__notnull
#define SAL__maybenull
#define SAL__readonly
#define SAL__notreadonly
#define SAL__maybereadonly
#define SAL__valid
#define SAL__notvalid
#define SAL__maybevalid
#define SAL__readableTo(extent)
#define SAL__elem_readableTo(size)
#define SAL__byte_readableTo(size)
#define SAL__writableTo(size)
#define SAL__elem_writableTo(size)
#define SAL__byte_writableTo(size)
#define SAL__deref
#define SAL__pre
#define SAL__post
#define SAL__precond(expr)
#define SAL__postcond(expr)
#define SAL__exceptthat
#define SAL__execeptthat
#define SAL__inner_success(expr)
#define SAL__inner_checkReturn
#define SAL__inner_typefix(ctype)
#define SAL__inner_override
#define SAL__inner_callback
#define SAL__inner_blocksOn(resource)
#define SAL__inner_fallthrough_dec
#define SAL__inner_fallthrough
#define __refparam
#define SAL__inner_control_entrypoint(category)
#define SAL__inner_data_entrypoint(category)
#define SAL__ecount(size)
#define SAL__bcount(size)
#define SAL__in
#define SAL__in_opt
#define SAL__in_nz
#define SAL__in_nz_opt
#define SAL__in_z
#define SAL__in_z_opt
#define SAL__in_ecount(size)
#define SAL__in_ecount_nz(size)
#define SAL__in_ecount_z(size)
#define SAL__in_bcount(size)
#define SAL__in_bcount_z(size)
#define SAL__in_bcount_nz(size)
#define SAL__in_ecount_opt(size)
#define SAL__in_bcount_opt(size)
#define SAL__in_ecount_z_opt(size)
#define SAL__in_bcount_z_opt(size)
#define SAL__in_ecount_nz_opt(size)
#define SAL__in_bcount_nz_opt(size)
#define SAL__out
#define SAL__out_ecount(size)
#define SAL__out_z
#define SAL__out_nz
#define SAL__out_nz_opt
#define SAL__out_z_opt
#define SAL__out_ecount_part(size,length)
#define SAL__out_ecount_full(size)
#define SAL__out_ecount_nz(size)
#define SAL__out_ecount_z(size)
#define SAL__out_ecount_part_z(size,length)
#define SAL__out_ecount_full_z(size)
#define SAL__out_bcount(size)
#define SAL__out_bcount_part(size,length)
#define SAL__out_bcount_full(size)
#define SAL__out_bcount_z(size)
#define SAL__out_bcount_part_z(size,length)
#define SAL__out_bcount_full_z(size)
#define SAL__out_bcount_nz(size)
#define SAL__inout
#define SAL__inout_ecount(size)
#define SAL__inout_bcount(size)
#define SAL__inout_ecount_part(size,length)
#define SAL__inout_bcount_part(size,length)
#define SAL__inout_ecount_full(size)
#define SAL__inout_bcount_full(size)
#define SAL__inout_z
#define SAL__inout_ecount_z(size)
#define SAL__inout_bcount_z(size)
#define SAL__inout_nz
#define SAL__inout_ecount_nz(size)
#define SAL__inout_bcount_nz(size)
#define SAL__ecount_opt(size)
#define SAL__bcount_opt(size)
#define SAL__out_opt
#define SAL__out_ecount_opt(size)
#define SAL__out_bcount_opt(size)
#define SAL__out_ecount_part_opt(size,length)
#define SAL__out_bcount_part_opt(size,length)
#define SAL__out_ecount_full_opt(size)
#define SAL__out_bcount_full_opt(size)
#define SAL__out_ecount_z_opt(size)
#define SAL__out_bcount_z_opt(size)
#define SAL__out_ecount_part_z_opt(size,length)
#define SAL__out_bcount_part_z_opt(size,length)
#define SAL__out_ecount_full_z_opt(size)
#define SAL__out_bcount_full_z_opt(size)
#define SAL__out_ecount_nz_opt(size)
#define SAL__out_bcount_nz_opt(size)
#define SAL__inout_opt
#define SAL__inout_ecount_opt(size)
#define SAL__inout_bcount_opt(size)
#define SAL__inout_ecount_part_opt(size,length)
#define SAL__inout_bcount_part_opt(size,length)
#define SAL__inout_ecount_full_opt(size)
#define SAL__inout_bcount_full_opt(size)
#define SAL__inout_z_opt
#define SAL__inout_ecount_z_opt(size)
#define SAL__inout_bcount_z_opt(size)
#define SAL__inout_nz_opt
#define SAL__inout_ecount_nz_opt(size)
#define SAL__inout_bcount_nz_opt(size)
#define SAL__deref_ecount(size)
#define SAL__deref_bcount(size)
#define SAL__deref_out
#define SAL__deref_out_ecount(size)
#define SAL__deref_out_bcount(size)
#define SAL__deref_out_ecount_part(size,length)
#define SAL__deref_out_bcount_part(size,length)
#define SAL__deref_out_ecount_full(size)
#define SAL__deref_out_bcount_full(size)
#define SAL__deref_out_z
#define SAL__deref_out_ecount_z(size)
#define SAL__deref_out_bcount_z(size)
#define SAL__deref_out_nz
#define SAL__deref_out_ecount_nz(size)
#define SAL__deref_out_bcount_nz(size)
#define SAL__deref_inout
#define SAL__deref_inout_ecount(size)
#define SAL__deref_inout_bcount(size)
#define SAL__deref_inout_ecount_part(size,length)
#define SAL__deref_inout_bcount_part(size,length)
#define SAL__deref_inout_ecount_full(size)
#define SAL__deref_inout_bcount_full(size)
#define SAL__deref_inout_z
#define SAL__deref_inout_ecount_z(size)
#define SAL__deref_inout_bcount_z(size)
#define SAL__deref_inout_nz
#define SAL__deref_inout_ecount_nz(size)
#define SAL__deref_inout_bcount_nz(size)
#define SAL__deref_ecount_opt(size)
#define SAL__deref_bcount_opt(size)
#define SAL__deref_out_opt
#define SAL__deref_out_ecount_opt(size)
#define SAL__deref_out_bcount_opt(size)
#define SAL__deref_out_ecount_part_opt(size,length)
#define SAL__deref_out_bcount_part_opt(size,length)
#define SAL__deref_out_ecount_full_opt(size)
#define SAL__deref_out_bcount_full_opt(size)
#define SAL__deref_out_z_opt
#define SAL__deref_out_ecount_z_opt(size)
#define SAL__deref_out_bcount_z_opt(size)
#define SAL__deref_out_nz_opt
#define SAL__deref_out_ecount_nz_opt(size)
#define SAL__deref_out_bcount_nz_opt(size)
#define SAL__deref_inout_opt
#define SAL__deref_inout_ecount_opt(size)
#define SAL__deref_inout_bcount_opt(size)
#define SAL__deref_inout_ecount_part_opt(size,length)
#define SAL__deref_inout_bcount_part_opt(size,length)
#define SAL__deref_inout_ecount_full_opt(size)
#define SAL__deref_inout_bcount_full_opt(size)
#define SAL__deref_inout_z_opt
#define SAL__deref_inout_ecount_z_opt(size)
#define SAL__deref_inout_bcount_z_opt(size)
#define SAL__deref_inout_nz_opt
#define SAL__deref_inout_ecount_nz_opt(size)
#define SAL__deref_inout_bcount_nz_opt(size)
#define SAL__deref_opt_ecount(size)
#define SAL__deref_opt_bcount(size)
#define SAL__deref_opt_out
#define SAL__deref_opt_out_z
#define SAL__deref_opt_out_ecount(size)
#define SAL__deref_opt_out_bcount(size)
#define SAL__deref_opt_out_ecount_part(size,length)
#define SAL__deref_opt_out_bcount_part(size,length)
#define SAL__deref_opt_out_ecount_full(size)
#define SAL__deref_opt_out_bcount_full(size)
#define SAL__deref_opt_inout
#define SAL__deref_opt_inout_ecount(size)
#define SAL__deref_opt_inout_bcount(size)
#define SAL__deref_opt_inout_ecount_part(size,length)
#define SAL__deref_opt_inout_bcount_part(size,length)
#define SAL__deref_opt_inout_ecount_full(size)
#define SAL__deref_opt_inout_bcount_full(size)
#define SAL__deref_opt_inout_z
#define SAL__deref_opt_inout_ecount_z(size)
#define SAL__deref_opt_inout_bcount_z(size)
#define SAL__deref_opt_inout_nz
#define SAL__deref_opt_inout_ecount_nz(size)
#define SAL__deref_opt_inout_bcount_nz(size)
#define SAL__deref_opt_ecount_opt(size)
#define SAL__deref_opt_bcount_opt(size)
#define SAL__deref_opt_out_opt
#define SAL__deref_opt_out_ecount_opt(size)
#define SAL__deref_opt_out_bcount_opt(size)
#define SAL__deref_opt_out_ecount_part_opt(size,length)
#define SAL__deref_opt_out_bcount_part_opt(size,length)
#define SAL__deref_opt_out_ecount_full_opt(size)
#define SAL__deref_opt_out_bcount_full_opt(size)
#define SAL__deref_opt_out_z_opt
#define SAL__deref_opt_out_ecount_z_opt(size)
#define SAL__deref_opt_out_bcount_z_opt(size)
#define SAL__deref_opt_out_nz_opt
#define SAL__deref_opt_out_ecount_nz_opt(size)
#define SAL__deref_opt_out_bcount_nz_opt(size)
#define SAL__deref_opt_inout_opt
#define SAL__deref_opt_inout_ecount_opt(size)
#define SAL__deref_opt_inout_bcount_opt(size)
#define SAL__deref_opt_inout_ecount_part_opt(size,length)
#define SAL__deref_opt_inout_bcount_part_opt(size,length)
#define SAL__deref_opt_inout_ecount_full_opt(size)
#define SAL__deref_opt_inout_bcount_full_opt(size)
#define SAL__deref_opt_inout_z_opt
#define SAL__deref_opt_inout_ecount_z_opt(size)
#define SAL__deref_opt_inout_bcount_z_opt(size)
#define SAL__deref_opt_inout_nz_opt
#define SAL__deref_opt_inout_ecount_nz_opt(size)
#define SAL__deref_opt_inout_bcount_nz_opt(size)
#define SAL__success(expr)
#define SAL__nullterminated
#define SAL__nullnullterminated
#define SAL__reserved
#define SAL__checkReturn
#define SAL__typefix(ctype)
#define SAL__override
#define SAL__callback
#define SAL__format_string
#define SAL__blocksOn(resource)
#define SAL__control_entrypoint(category)
#define SAL__data_entrypoint(category)
#ifndef __fallthrough
#define __fallthrough
#endif
#ifndef __analysis_assume
#define __analysis_assume(expr)
#endif
#ifndef __CLR_OR_THIS_CALL
#define __CLR_OR_THIS_CALL
#endif
#ifndef __CLRCALL_OR_CDECL
#define __CLRCALL_OR_CDECL __cdecl
#endif
#ifndef __STDC_WANT_SECURE_LIB__
#define __STDC_WANT_SECURE_LIB__ 0
#endif
#ifndef _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_DEPRECATE
#endif
#ifndef RC_INVOKED
#ifndef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 0
#endif
#ifndef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT 0
#endif
#ifndef _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES
#define _CRT_SECURE_CPP_OVERLOAD_SECURE_NAMES 0
#endif
#endif
#ifndef DECLSPEC_ADDRSAFE
#define DECLSPEC_ADDRSAFE
#endif
#ifdef __cplusplus
}
#endif

2281
include/strsafe.h Normal file

File diff suppressed because it is too large Load Diff

16
src/CMakeLists.txt Normal file
View File

@ -0,0 +1,16 @@
include ( ${QT_USE_FILE} )
include_directories (
${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
${QT_QTCORE_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR}
${QT_QTNETWORK_INCLUDE_DIR} ${QT_QTDBUS_INCLUDE_DIR}
)
add_subdirectory(core)
add_executable ( SnoreNotify main.cpp )
target_link_libraries ( SnoreNotify snore)
add_dependencies(SnoreNotify snore)
add_subdirectory(webinterface)
add_subdirectory(plugins)

View File

@ -0,0 +1,17 @@
# -------------------------------------------------
# Project created by QtCreator 2009-11-24T23:39:55
# -------------------------------------------------
QT += dbus
QT += gui
QT += network
TARGET = SnoreNotifyGui
TEMPLATE = app
INCLUDEPATH += ../. ./
HEADERS += mainwindow.h \
../dbusbinding.h \
../application.h
FORMS += mainwindow.ui
SOURCES += ../dbusbinding.cpp \
../application.cpp \
gmain.cpp\
mainwindow.cpp

11
src/Gui/gmain.cpp Normal file
View File

@ -0,0 +1,11 @@
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
DBusBinding::registerTypes();
MainWindow w;
w.show();
return a.exec();
}

75
src/Gui/mainwindow.cpp Normal file
View File

@ -0,0 +1,75 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
itemsList_applications=new QStandardItemModel(this);
itemsList_alerts=new QStandardItemModel(this);
ui->listView_applicationList->setModel(itemsList_applications);
ui->listView_AlertList->setModel(itemsList_alerts);
QDBusReply<ApplicationsList> reply= DBusBinding::snoreInterface.call("getApplicationList");
if(reply.isValid())
applicationListChanged(reply);
else
qDebug()<<reply.error();
DBusBinding::snoreInterface.connection().connect(DBusBinding::snoreInterface.service(),DBusBinding::snoreInterface.path(),DBusBinding::snoreInterface.interface(),"applicationListChanged",this,SLOT(applicationListChanged(ApplicationsList)));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::applicationListChanged(const ApplicationsList &apls){
itemsList_applications->setHorizontalHeaderItem(0,new QStandardItem("Registred Applications"));
applicationList=apls;
itemsList_applications->clear();
QStandardItem *item;
foreach(const QString &s,applicationList.keys()){
item=new QStandardItem(s);
item->setEditable(false);
itemsList_applications->appendRow(item);
}
itemsList_alerts->clear();
if(!currentSelectedApplication.isEmpty()&&applicationList.contains(currentSelectedApplication)){
foreach(QSharedPointer<Alert> al,applicationList.value(currentSelectedApplication)->alerts.values()){
item=new QStandardItem(al->name);
item->setEnabled(al->active);
item->setEditable(false);
itemsList_alerts->appendRow(item);
}
}
}
void MainWindow::on_listView_applicationList_clicked(QModelIndex index)
{
currentSelectedApplication=itemsList_applications->item(index.row(),index.column())->text();
itemsList_alerts->setHorizontalHeaderItem(0,new QStandardItem("Alerts"));
itemsList_alerts->setHorizontalHeaderItem(1,new QStandardItem("Active"));
itemsList_alerts->clear();
QStandardItem *item;
foreach(QSharedPointer<Alert> al,applicationList.value(currentSelectedApplication)->alerts.values()){
item=new QStandardItem(al->name);
item->setEnabled(al->active);
itemsList_alerts->appendRow(item);
}
}
void MainWindow::on_listView_AlertList_clicked(QModelIndex index)
{
qDebug()<<DBusBinding::snoreInterface.call(QDBus::AutoDetect,"setAlertActive",currentSelectedApplication,itemsList_alerts->item(index.row(),index.column())->text(),!itemsList_alerts->item(index.row(),index.column())->isEnabled());
}

36
src/Gui/mainwindow.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
#include "application.h"
#include "dbusbinding.h"
#include <QStandardItemModel>
namespace Ui
{
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
ApplicationsList applicationList;
QStandardItemModel* itemsList_applications;
QStandardItemModel* itemsList_alerts;
public slots:
void applicationListChanged(const ApplicationsList &apls);
private:
Ui::MainWindow *ui;
QString currentSelectedApplication;
private slots:
void on_listView_AlertList_clicked(QModelIndex index);
void on_listView_applicationList_clicked(QModelIndex index);
};
#endif // MAINWINDOW_H

61
src/Gui/mainwindow.ui Normal file
View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string>Snore Notify</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QListView" name="listView_applicationList">
<property name="geometry">
<rect>
<x>20</x>
<y>60</y>
<width>141</width>
<height>301</height>
</rect>
</property>
</widget>
<widget class="QListView" name="listView_AlertList">
<property name="geometry">
<rect>
<x>160</x>
<y>60</y>
<width>256</width>
<height>301</height>
</rect>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>20</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

80
src/Gui/ui_mainwindow.h Normal file
View File

@ -0,0 +1,80 @@
/********************************************************************************
** Form generated from reading UI file 'mainwindow.ui'
**
** Created: Tue 29. Dec 01:35:26 2009
** by: Qt User Interface Compiler version 4.6.0
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QHeaderView>
#include <QtGui/QListView>
#include <QtGui/QMainWindow>
#include <QtGui/QMenuBar>
#include <QtGui/QStatusBar>
#include <QtGui/QToolBar>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public:
QWidget *centralWidget;
QListView *listView_applicationList;
QListView *listView_AlertList;
QMenuBar *menuBar;
QToolBar *mainToolBar;
QStatusBar *statusBar;
void setupUi(QMainWindow *MainWindow)
{
if (MainWindow->objectName().isEmpty())
MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
MainWindow->resize(600, 400);
centralWidget = new QWidget(MainWindow);
centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
listView_applicationList = new QListView(centralWidget);
listView_applicationList->setObjectName(QString::fromUtf8("listView_applicationList"));
listView_applicationList->setGeometry(QRect(20, 60, 141, 301));
listView_AlertList = new QListView(centralWidget);
listView_AlertList->setObjectName(QString::fromUtf8("listView_AlertList"));
listView_AlertList->setGeometry(QRect(160, 60, 256, 301));
MainWindow->setCentralWidget(centralWidget);
menuBar = new QMenuBar(MainWindow);
menuBar->setObjectName(QString::fromUtf8("menuBar"));
menuBar->setGeometry(QRect(0, 0, 600, 20));
MainWindow->setMenuBar(menuBar);
mainToolBar = new QToolBar(MainWindow);
mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
statusBar = new QStatusBar(MainWindow);
statusBar->setObjectName(QString::fromUtf8("statusBar"));
MainWindow->setStatusBar(statusBar);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "Snore Notify", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_MAINWINDOW_H

12
src/core/CMakeLists.txt Normal file
View File

@ -0,0 +1,12 @@
set ( SnoreNotify_SRCS
notification.cpp
snoreserver.cpp
application.cpp
interface.cpp
)
automoc4_add_library( snore SHARED ${SnoreNotify_SRCS})
set_target_properties( snore PROPERTIES COMPILE_FLAGS "-DSNORECORE_DLL" )
target_link_libraries ( snore ${QT_QTCORE_LIBRARY} )

19
src/core/application.cpp Normal file
View File

@ -0,0 +1,19 @@
#include "application.h"
Application::Application(const QString &name):name(name){}
Application::Application():name("Error: Uninitialized Application"){}
void Application::addAlert(const QString &alert,const QString &title){
alerts.insert(alert,QSharedPointer<Alert>(new Alert(alert,title)));
}
Alert::Alert(const QString &name,const QString &title):name(name),title(title),active(true){}
Alert::Alert(const QString &name,const QString &title,bool active):name(name),title(title),active(active){}
Alert::Alert():active(false){}

35
src/core/application.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef APPLICATION_H
#define APPLICATION_H
#include "snore_exports.h"
#include <QString>
#include <QStringList>
#include <QDebug>
#include <QHash>
#include <QSharedPointer>
typedef QHash<QString,QSharedPointer<class Application> > ApplicationsList ;
typedef QHash<QString,QSharedPointer<class Alert> > AlertList;
class SNORE_EXPORT Application
{
public:
Application(const QString &name);
Application();
AlertList alerts;
QString name;
void addAlert(const QString &alert,const QString &title);
};
class SNORE_EXPORT Alert{
public:
Alert(const QString &name,const QString &title);
Alert(const QString &name,const QString &title,bool active);
Alert();
QString name;
QString title;
bool active;
};
#endif // APPLICATION_H

14
src/core/interface.cpp Normal file
View File

@ -0,0 +1,14 @@
#include "interface.h"
#include "snoreserver.h"
void SnorePlugin::setSnore(SnoreServer *snore){
this->snore=snore;
}
SnoreServer* SnorePlugin::getSnore(){
return snore.data();
}
#include "interface.moc"

53
src/core/interface.h Normal file
View File

@ -0,0 +1,53 @@
#ifndef INTERFACE_H
#define INTERFACE_H
#include "snore_exports.h"
#include "notification.h"
#include <QObject>
#include <QTcpSocket>
#include <QSharedPointer>
#include <QPointer>
class SNORE_EXPORT SnorePlugin{
public:
virtual ~SnorePlugin(){};
virtual void setSnore(class SnoreServer* snore);
virtual class SnoreServer* getSnore();
private:
QPointer<class SnoreServer> snore;
};
class SNORE_EXPORT Notification_Backend:public QObject,public SnorePlugin
{
Q_OBJECT
public:
virtual ~Notification_Backend() {}
virtual bool isPrimaryNotificationBackend()=0;
public slots:
virtual int notify(QSharedPointer<Notification> notification)=0;
virtual void closeNotification(int id)=0;
// virtual void update
};
class SNORE_EXPORT Notification_Frontend:public SnorePlugin{
public:
virtual ~Notification_Frontend() {}
virtual void actionInvoked(QSharedPointer<Notification> notification)=0;
virtual void notificationClosed(QSharedPointer<Notification> notification)=0;
};
Q_DECLARE_INTERFACE(SnorePlugin,
"org.Snore.SnorePlugin/1.0")
Q_DECLARE_INTERFACE(Notification_Frontend,
"org.Snore.NotificationFrontend/1.0")
Q_DECLARE_INTERFACE(Notification_Backend,
"org.Snore.NotificationBackend/1.0")
#endif//INTERFACE_H

9
src/core/libgrowl.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef LIBGROWL_H
#define LIBGROWL_H
//registers all alert classes in the aray as default alerts
void reister(string classes[]);
//send a notification and return its registration id
int send(string title,string body,string iconPath,int timeout);
#endif // LIBGROWL_H

38
src/core/notification.cpp Normal file
View File

@ -0,0 +1,38 @@
#include "notification.h"
#include <QDebug>
#include <QTcpSocket>
#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)
{
}
QString Notification::getIcon(){
return icon;
}
bool Notification::isNotification(){
return notification;
}
QString Notification::toSnalrString()const{
QString out("type=SNP#?version=1.1");
if(hints.contains("SNaction"))
out+=QString("#?action="+hints.value("SNaction").value<QString>());
if(!app.isEmpty())
out+=QString("#?app="+app);
if(!alert.isEmpty())
out+=QString("#?class="+alert);
out+=QString("#?title="+title+"#?text="+text+"#?timeout="+QString::number(timeout));
return out;
}
QDataStream & operator<< ( QDataStream & stream, const Notification & noti){
stream<<noti.toSnalrString();
return stream;
}
#include "notification.moc"

65
src/core/notification.h Normal file
View File

@ -0,0 +1,65 @@
#ifndef NOTIFICATION_H
#define NOTIFICATION_H
#include "snore_exports.h"
#include <QString>
#include <QTcpSocket>
#include <QUrl>
#include <QHttp>
#include <QObject>
#include "QHash"
#include <QFile>
#include "application.h"
#include <QPointer>
class SNORE_EXPORT Notification:public QObject
{
Q_OBJECT
public:
Notification();
Notification(QString source,QString title,QString text,QString icon,int timeout);
bool isNotification();
QString toSnalrString()const;
enum actions{
TIMED_OUT=0,
ACTION_1=1,
ACTION_2=2,
ACTION_3=3,
CLOSED=4
};
actions actionInvoked;
QString source;
QString app;
QString title;
QString text;
QString alert;
int timeout;
void setIcon(const QString &icon){this->icon=icon; }
QString getIcon();
QVariantHash hints;
int id;
private:
QString icon;
bool notification;
};
QDataStream & operator<< ( QDataStream & stream, const Notification & noti);
#endif // NOTIFICATION_H

12
src/core/snore_exports.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef SNORE_EXPORT_H
#define SNORE_EXPORT_H
#ifdef SNORECORE_DLL
# define SNORE_EXPORT Q_DECL_EXPORT
#else
# define SNORE_EXPORT Q_DECL_IMPORT
#endif
#endif//SNORE_EXPORT_H

101
src/core/snoreserver.cpp Normal file
View File

@ -0,0 +1,101 @@
#include "snoreserver.h"
#include <QDebug>
#include "notification.h"
#include <QPluginLoader>
QString const SnoreServer::snoreTMP=QDir::temp().path()+"/SnoreNotify";
SnoreServer::SnoreServer():primaryNotificationBackend(0)
{ qDebug()<<"Inititalized";
QDir home(snoreTMP);
if(home.exists()){
QStringList filetypes;
filetypes<<"*.png"<<"*.jpg";
QStringList toDell;
toDell=home.entryList(filetypes);
foreach(QString s,toDell){
home.remove(s);
}
}else
QDir::temp().mkpath("SnoreNotify");
}
void SnoreServer::publicatePlugin(QObject *plugin){
qDebug()<<"Loading plugin: "<<plugin->property("name").value<QString>();
SnorePlugin *sp=qobject_cast<SnorePlugin*>(plugin);
if(sp){
plugins.insert(plugin->property("name").value<QString>(),plugin);
qDebug()<<plugin->property("name").value<QString>()<<"is a SnorePlugin";
sp->setSnore(this);
}
Notification_Frontend *nf=qobject_cast<Notification_Frontend*>(plugin);
if(nf){
qDebug()<<plugin->property("name").value<QString>()<<"is a Notification_Frontend";
nf->setSnore(this);
}
Notification_Backend * nb=qobject_cast<Notification_Backend *>(plugin);
if(nb){
qDebug()<<plugin->property("name").value<QString>()<<"is a Notification_Backend";
if(nb->isPrimaryNotificationBackend())
primaryNotificationBackend=nb;
else{
notyfier.append(nb);
connect(this,SIGNAL(notify(QSharedPointer<Notification>)),nb,SLOT(notify(QSharedPointer<Notification>)));
}
connect(this,SIGNAL(closeNotify(int)),nb,SLOT(closeNotification(int)));
nb->setSnore(this);
}
}
int SnoreServer::broadcastNotification(QSharedPointer<Notification> notification){
emit notify(notification);
qDebug()<<"Broadcasting notification:"<<notification->toSnalrString();
if(primaryNotificationBackend!=NULL){
return primaryNotificationBackend->notify(notification);
}
return -1;
}
void SnoreServer::closeNotification(QSharedPointer<Notification> notification){
emit closeNotify(notification->id);
Notification_Frontend *nf= qobject_cast<Notification_Frontend*>(plugins.value(notification->source));
if(nf!=0){
nf->notificationClosed(notification);
}
}
void SnoreServer::notificationActionInvoked(QSharedPointer<Notification> notification){
Notification_Frontend *nf= qobject_cast<Notification_Frontend*>(plugins.value(notification->source));
if(nf!=0){
nf->actionInvoked(notification);
}
}
void SnoreServer::addApplication(QSharedPointer<Application> application){
applications.insert(application->name,application);
emit applicationListChanged();
}
bool SnoreServer::applicationListConontainsAlert(const QString &applicationName,const QString &alertName){
return applications.contains(applicationName)&&applications.value(applicationName)->alerts.contains(alertName)
&&!applications.value(applicationName)->alerts.value(alertName)->active;
}
void SnoreServer::addAlert(const QString &appName,const QString &alertName, const QString &alertTitle){
applications.value(appName)->addAlert(alertName,alertTitle);
emit applicationListChanged();
}
void SnoreServer::removeApplication(const QString& appName){
applications.take(appName).clear();
emit applicationListChanged();
}
#include "snoreserver.moc"

60
src/core/snoreserver.h Normal file
View File

@ -0,0 +1,60 @@
#ifndef SNORESERVER_H
#define SNORESERVER_H
#include "snore_exports.h"
#include <QTcpServer>
#include <QTcpSocket>
#include <QObject>
#include <QDir>
#include <QQueue>
#include <QTimer>
#include <QSharedPointer>
#include "application.h"
#include <QSharedPointer>
#include "interface.h"
#include <QDir>
class SNORE_EXPORT SnoreServer:public QObject
{
Q_OBJECT
public:
static const QString snoreTMP;
public:
SnoreServer();
void publicatePlugin(QObject* plugin);
int broadcastNotification(QSharedPointer<Notification> notification);
void closeNotification(QSharedPointer<Notification> notification);
void notificationActionInvoked(QSharedPointer<Notification> notification);
void addApplication(QSharedPointer<Application> application);
bool applicationListConontainsAlert(const QString &applicationName,const QString &alertName);
void addAlert(const QString &appName,const QString &alertName, const QString &alertTitle);
void removeApplication(const QString& appName);
ApplicationsList* getAplicationList(){
return &applications;
}
QHash<QString,QObject*> plugins;
private:
ApplicationsList applications;
QList<Notification_Backend*> notyfier;
Notification_Backend * primaryNotificationBackend;
signals:
void applicationListChanged();
void notify(QSharedPointer<Notification> noti);
void closeNotify(int id);
};
#endif // SNORESERVER_H

28
src/main.cpp Normal file
View File

@ -0,0 +1,28 @@
#include <QtCore/QCoreApplication>
#include "core/snoreserver.h"
#include <QDir>
#include <QFile>
#include <QList>
#include <QDebug>
#include <QPluginLoader>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
SnoreServer s;
QDir pluginsDir(a.applicationDirPath()+"/plugins");
foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
QObject *plugin = loader.instance();
if (plugin) {
s.publicatePlugin(plugin);
}else
qDebug()<<"Failed loading plugin: "<<loader.errorString();
}
return a.exec();
}

View File

@ -0,0 +1,11 @@
SET(LIBRARY_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH}/plugins)
add_subdirectory(freedesktopnotification)
add_subdirectory(freedesktopfrontend)
add_subdirectory(redirector)
add_subdirectory(webposter)
add_subdirectory(registredapps)
add_subdirectory(snarlnetwork)
add_subdirectory(snarl)
add_subdirectory(dbusbinding)

View File

@ -0,0 +1,9 @@
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} snore )
endif(QT_QTDBUS_FOUND)

View File

@ -0,0 +1,127 @@
#include "dbusbinding.h"
#include <QtCore>
Q_EXPORT_PLUGIN2(dbusbinding,DBusPlugin)
void DBusPlugin::setSnore(SnoreServer *snore){
new DBusBinding(this,snore);
}
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>();
}
ApplicationsList DBusBinding::getApplicationList(){
//workaround for the "" application bug
if(snore->getAplicationList()->contains("")){
snore->getAplicationList()->take("").clear();
qDebug()<<"Removed wrong entry ("") in application list";
}
return *snore->getAplicationList();
}
void DBusBinding::setAlertActive(const QString &application,const QString &name,const bool active){
QSharedPointer<Application> ap(snore->getAplicationList()->value(application));
ap->alerts.value(name)->active=active;
emit applicationListChanged(*snore->getAplicationList());
}
void DBusBinding::applicationListChangedSlot(){
emit applicationListChanged(*snore->getAplicationList());
}
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;
}
#include "dbusbinding.moc"

View File

@ -0,0 +1,63 @@
#ifndef DBUSBINDING_H
#define DBUSBINDING_H
#include <QtDBus>
#include "core/interface.h"
#include "core/application.h"
#include "core/snoreserver.h"
class DBusPlugin:public QObject,SnorePlugin{
Q_OBJECT
Q_INTERFACES(SnorePlugin)
public:
DBusPlugin(){
setProperty("name","DbusBinding");
};
void setSnore(SnoreServer *snore);
};
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:
ApplicationsList getApplicationList();
void setAlertActive(const QString &application,const QString &alert,const bool active);
signals:
void applicationListChanged(const ApplicationsList &);
private slots:
void applicationListChangedSlot();
};
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

@ -0,0 +1,17 @@
if(QT_QTDBUS_FOUND)
message(STATUS "Adding freedesktop notification frontend")
set ( FREEDESKTOP_NOTIFICATION_FRONTEND_SRC
freedesktopnotificationfrontend.cpp
../freedesktopnotification/fredesktopnotification.cpp
)
qt4_add_dbus_adaptor( FREEDESKTOP_NOTIFICATION_FRONTEND_SRC org.freedesktop.Notifications.xml freedesktopnotificationfrontend.h FreedesktopNotification_Frontend)
automoc4_add_library(freedesktop_frontend MODULE ${FREEDESKTOP_NOTIFICATION_FRONTEND_SRC} )
target_link_libraries(freedesktop_frontend snore ${QT_QTDBUS_LIBRARY} ${QT_QTGUI_LIBRARY} )
endif(QT_QTDBUS_FOUND)

View File

@ -0,0 +1,104 @@
#include "freedesktopnotificationfrontend.h"
#include "notificationsadaptor.h"
#include <QtCore>
#include <QtDBus>
#include <QImage>
#include "plugins/freedesktopnotification/fredesktopnotification.h"
#include "core/snoreserver.h"
Q_EXPORT_PLUGIN2(freedesktop_frontend,FreedesktopNotification_Frontend)
FreedesktopNotification_Frontend::FreedesktopNotification_Frontend(){
setProperty("name","FreedesktopNotification_Frontend");
new NotificationsAdaptor(this);
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.registerService( "org.freedesktop.Notifications" );
dbus.registerObject( "/org/freedesktop/Notifications", this );
}
FreedesktopNotification_Frontend::~FreedesktopNotification_Frontend(){
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.unregisterService( "org.freedesktop.Notifications" );
}
void FreedesktopNotification_Frontend::actionInvoked(QSharedPointer<Notification>notification){
emit ActionInvoked(notification->id,QString::number(notification->actionInvoked));
}
void FreedesktopNotification_Frontend::notificationClosed(QSharedPointer<Notification>notification){
uint reason;
switch(notification->actionInvoked){
case Notification::TIMED_OUT:
reason=1;
break;
case Notification::ACTION_1:
case Notification::ACTION_2:
case Notification::ACTION_3:
reason=2;
break;
default:
reason=4;
}
emit NotificationClosed(notification->id,reason);
}
QString FreedesktopNotification_Frontend::getImagefromHint(const FreedesktopImageHint &img){
QCryptographicHash hash(QCryptographicHash::Md5);
hash.addData(img.imageData);
QString filename=SnoreServer::snoreTMP+hash.result().toHex()+".png";
QFile file(filename);
if(file.exists())return filename;
QImage qimage=img.toQImage();
qimage.save(filename,"PNG");
qDebug()<<"Saving to "<<filename;
return filename;
}
uint FreedesktopNotification_Frontend::Notify(const QString &app_name, uint replaces_id,
const QString &app_icon, const QString &summary, const QString &body,
const QStringList &actions, const QVariantMap &hints, int timeout)
{
qDebug()<<app_name<<summary<<body<<app_icon;
QString icon;
if(hints.contains("image_data")){
FreedesktopImageHint image;
hints["image_data"].value<QDBusArgument>()>>image;
icon=getImagefromHint(image);
}
QSharedPointer<Notification> noti(new Notification(property("name").value<QString>(),summary,body,icon,timeout));
noti->id=replaces_id;
return getSnore()->broadcastNotification(noti);
}
void FreedesktopNotification_Frontend::CloseNotification(uint id){
QSharedPointer<Notification> n(new Notification());
n->id=id;
getSnore()->closeNotification(n);
}
QStringList FreedesktopNotification_Frontend::GetCapabilities()
{
return QStringList()
<< "body"
// << "body-hyperlinks"
// << "body-markup"
<< "icon-static"
<< "actions"
;
}
QString FreedesktopNotification_Frontend::GetServerInformation(QString& vendor, QString& version, QString& specVersion)
{
vendor = "SnoreNotify";
version = "0.01";
specVersion = "0";
return "SnoreNotify";
}
#include "freedesktopnotificationfrontend.moc"

View File

@ -0,0 +1,34 @@
#ifndef FREEDESKTOPNOTIFICATION_FRONTEND_H
#define FREEDESKTOPNOTIFICATION_FRONTEND_H
#include "core/interface.h"
#include <QtDBus>
class FreedesktopNotification_Frontend:public QObject,Notification_Frontend{
Q_OBJECT
Q_INTERFACES(Notification_Frontend)
public:
FreedesktopNotification_Frontend();
~FreedesktopNotification_Frontend();
QString getImagefromHint(const class FreedesktopImageHint &img);
void actionInvoked(QSharedPointer<Notification>notification);
void notificationClosed(QSharedPointer<Notification>notification);
uint Notify(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantMap &hints, int timeout);
void CloseNotification( uint id );
QStringList GetCapabilities();
QString GetServerInformation(QString& vendor, QString& version, QString& specVersion);
signals:
void NotificationClosed( uint id, uint reason );
void ActionInvoked( uint id, const QString& actionKey );
};
#endif//FREEDESKTOPNOTIFICATION_FRONTEND_H

View File

@ -0,0 +1,37 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.freedesktop.Notifications">
<signal name="NotificationClosed">
<arg name="id" type="u" direction="out"/>
<arg name="reason" type="u" direction="out"/>
</signal>
<signal name="ActionInvoked">
<arg name="id" type="u" direction="out"/>
<arg name="action_key" type="s" direction="out"/>
</signal>
<method name="Notify">
<annotation name="com.trolltech.QtDBus.QtTypeName.In6" value="QVariantMap"/>
<arg type="u" direction="out"/>
<arg name="app_name" type="s" direction="in"/>
<arg name="replaces_id" type="u" direction="in"/>
<arg name="app_icon" type="s" direction="in"/>
<arg name="summary" type="s" direction="in"/>
<arg name="body" type="s" direction="in"/>
<arg name="actions" type="as" direction="in"/>
<arg name="hints" type="a{sv}" direction="in"/>
<arg name="timeout" type="i" direction="in"/>
</method>
<method name="CloseNotification">
<arg name="id" type="u" direction="in"/>
</method>
<method name="GetCapabilities">
<arg type="as" name="caps" direction="out"/>
</method>
<method name="GetServerInformation">
<arg type="s" name="name" direction="out"/>
<arg type="s" name="vendor" direction="out"/>
<arg type="s" name="version" direction="out"/>
<arg type="s" name="spec_version" direction="out"/>
</method>
</interface>
</node>

View File

@ -0,0 +1,12 @@
if(QT_QTDBUS_FOUND)
message(STATUS "Adding Freedesktop notification backend")
set ( FREEDESKTOP_NOTIFICATION_SRC
freedesktopnotification_backend.cpp
fredesktopnotification.cpp
)
automoc4_add_library(freedesktop_backend MODULE ${FREEDESKTOP_NOTIFICATION_SRC} )
target_link_libraries(freedesktop_backend snore ${QT_QTGUI_LIBRARY} ${QT_QTDBUS_LIBRARY} )
else(QT_QTDBUS_FOUND)
message(STATUS "Adding Freedesktop notification backend.... for Freedesktop notification backend support QDBus is needed")
endif(QT_QTDBUS_FOUND)

View File

@ -0,0 +1,78 @@
#include "fredesktopnotification.h"
#include <QImage>
FreedesktopNotification::FreedesktopNotification(){
registerTypes();
}
FreedesktopNotification::FreedesktopNotification(Notification *noti):notification(noti){
registerTypes();
}
void FreedesktopNotification::registerTypes(){
qDBusRegisterMetaType<FreedesktopImageHint>();
qDBusRegisterMetaType<FreedesktopNotification>();
}
QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopNotification &i){
QStringList actions;
actions<<"1"<<" "<<"2"<<" ";
a<<i.notification->app<<uint(0)<<i.notification->getIcon()<<i.notification->title<<i.notification->text<<actions;
a.beginMap();
QImage img(i.notification->getIcon());
if(!img.isNull()){
img=img.scaledToWidth(50,Qt::FastTransformation);
a.beginMapEntry();
a<<"image_data";
a<<new FreedesktopImageHint(img);
a.endMapEntry();
}
a.endMap();
a<<i.notification->timeout*1000;
return a;
}
const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopNotification &i){
//not supported
return a;
}
FreedesktopImageHint::FreedesktopImageHint(){
FreedesktopNotification::registerTypes();
}
FreedesktopImageHint::FreedesktopImageHint(const QImage &img){
FreedesktopNotification::registerTypes();
QImage image(img.convertToFormat(QImage::Format_ARGB32));
width=image.width();
height=image.height();
rowstride=image.bytesPerLine();
hasAlpha=image.hasAlphaChannel();
channels =image.isGrayscale()?1:hasAlpha?4:3;
bitsPerSample=image.depth()/channels;
this->imageData.append((char*)image.rgbSwapped().bits(),image.numBytes());
}
QImage FreedesktopImageHint::toQImage()const{
return QImage((uchar*)imageData.data(),width,height,QImage::Format_ARGB32 ).rgbSwapped();
}
QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint &i) {
a.beginStructure();
a << i.width<<i.height<<i.rowstride<<i.hasAlpha<<i.bitsPerSample<<i.channels<<i.imageData;
a.endStructure();
return a;
}
const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopImageHint &i) {
a.beginStructure();
a >> i.width>> i.height>> i.rowstride>> i.hasAlpha>> i.bitsPerSample>> i.channels>> i.imageData;
a.endStructure();
return a;
}
#include "fredesktopnotification.moc"

View File

@ -0,0 +1,53 @@
#ifndef FreedesktopNotification_H
#define FreedesktopNotification_H
#include <QtDBus>
#include <QPointer>
#include "core/notification.h"
#include <QMetaType>
class FreedesktopImageHint;
class FreedesktopNotification{
public:
static void registerTypes();
public:
FreedesktopNotification();
FreedesktopNotification(Notification *noti);
QPointer<FreedesktopImageHint> image;
Notification toNotification();
QPointer<Notification> notification;
};
Q_DECLARE_METATYPE(FreedesktopNotification);
QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopNotification &i);
const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopNotification &i) ;
class FreedesktopImageHint
{
public:
FreedesktopImageHint();
FreedesktopImageHint(const QImage &img);
QImage toQImage()const;
int width;
int height;
int rowstride;
bool hasAlpha;
int bitsPerSample;
int channels;
QByteArray imageData;
};
Q_DECLARE_METATYPE(FreedesktopImageHint);
QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopImageHint &i);
const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopImageHint &i) ;
#endif // FreedesktopNotification_H

View File

@ -0,0 +1,105 @@
#include "freedesktopnotification_backend.h"
#include <QDebug>
#include "core/notification.h"
#include <QtCore>
#include <QImage>
#include "fredesktopnotification.h"
#include "core/snoreserver.h"
#include <QtDBus>
Q_EXPORT_PLUGIN2(freedesktopnotificationbackend,FreedesktopNotification_Backend)
int FreedesktopNotification_Backend::notify( QSharedPointer<Notification> noti){
fNotification *n=new fNotification(this);
qDebug()<<noti;
n->notification=noti;
return n->send();
}
void FreedesktopNotification_Backend::closeNotification(int id){
//TODO: fix
// fNotification *fn=new fNotification();
// fn->notification=new Notification();
// fn->notification->id=id;
// fn->close();
}
QString fNotification::vendor("");
QDBusInterface fNotification::notificationInterface("org.freedesktop.Notifications","/org/freedesktop/Notifications","org.freedesktop.Notifications");
fNotification::fNotification(FreedesktopNotification_Backend* parent):parent(parent){
setParent(parent);
}
int fNotification::send(){
qDebug("Sending a notification");
FreedesktopNotification n(notification.data());
QDBusMessage recive=notificationInterface.call("Notify", QVariant::fromValue(n));
n.notification->id=recive.arguments().last().toInt();
selfdistruct.setParent(this);
selfdistruct.setSingleShot(true);
connect(&selfdistruct, SIGNAL(timeout()), this, SLOT(close()));
selfdistruct.start(notification->timeout*1000);
QDBusConnection::sessionBus().connect("org.freedesktop.Notifications","/org/freedesktop/Notifications","org.freedesktop.Notifications","ActionInvoked",this,SLOT(action(uint,QString)));
if(getVendor()=="GNOME")
QDBusConnection::sessionBus().connect("org.freedesktop.Notifications","/org/freedesktop/Notifications","org.freedesktop.Notifications","NotificationClosed",this,SLOT(closed(uint,uint)));
return n.notification->id;
}
void fNotification::action(const uint &id, const QString &action_key){
if(id!=notification->id)return;
close();
qDebug()<<id<<"|"<<action_key ;
notificationInterface.call(QDBus::AutoDetect,"CloseNotification",id);
//default is only working on gnome
notification->actionInvoked=(action_key=="default"?Notification::ACTION_1:Notification::actions(action_key.toInt()));
parent->getSnore()->notificationActionInvoked(notification);
selfDelete();
}
void fNotification::closed(const uint &id,const uint &reason){
qDebug()<<id<<"|"<<reason;;
if(id!=notification->id)return;
close();
if(reason==1)
notification->actionInvoked=Notification::TIMED_OUT;
if(reason==2)
notification->actionInvoked=Notification::CLOSED;
parent->getSnore()->closeNotification(notification);
selfDelete();
}
void fNotification::close(){
blockSignals(true);
if( !selfdistruct.isActive()){
notification->actionInvoked=Notification::TIMED_OUT;
parent->getSnore()->closeNotification(notification);
selfDelete();
}
selfdistruct.stop();
}
QString fNotification::getVendor(){
if(vendor==""){
QDBusMessage recive= notificationInterface.call(QDBus::AutoDetect,"GetServerInformation");
vendor=recive.arguments()[1].toString();
qDebug()<<recive.arguments();
}
return vendor;
}
void fNotification::selfDelete(){
notification.clear();
delete this;
}

View File

@ -0,0 +1,53 @@
#ifndef FREEDESKTOPNOTIFICATION_H
#define FREEDESKTOPNOTIFICATION_H
#include "core/interface.h"
#include <QtDBus>
class fNotification;
class FreedesktopNotification_Backend:public Notification_Backend
{
Q_OBJECT
Q_INTERFACES(Notification_Backend)
public:
FreedesktopNotification_Backend()
{
setProperty("name","FreedesktopNotification_Backend");
};
bool isPrimaryNotificationBackend(){return true;}
public slots:
int notify(QSharedPointer<class Notification>notification);
void closeNotification(int id);
};
class fNotification:public QObject{
Q_OBJECT
public:
static QDBusInterface notificationInterface;
private:
static QString vendor;
public:
fNotification(FreedesktopNotification_Backend* parent);
int send();
QSharedPointer<Notification> notification;
private:
Notification_Backend* parent;
QString getVendor();
QTimer selfdistruct;
private slots:
void action(const uint &id, const QString &action_key);
void closed(const uint &id,const uint &reason);
void close();
void selfDelete();
};
#endif // FREEDESKTOPNOTIFICATION_H

View File

@ -0,0 +1,7 @@
if(WITH_WEBINTERFACE)
set( REDIRECTOR_SRC
redirector.cpp
)
automoc4_add_library(redirector MODULE ${REDIRECTOR_SRC})
target_link_libraries(redirector snore webinterface)
endif(WITH_WEBINTERFACE)

View File

@ -0,0 +1,98 @@
#include "redirector.h"
#include <QDebug>
#include <QHostAddress>
#include "core/snoreserver.h"
#include "core/notification.h"
#include <QtCore>
#include <QObject>
Q_EXPORT_PLUGIN2(redircetor,Redircetor)
Redircetor::Redircetor(){
setProperty("name","Redircetor");
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(getSnore());
foreach(QSharedPointer<Application> a,snore->getAplicationList()->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((notification->toSnalrString()+"\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>";
}
SnoreServer* Redircetor::getSnore(){
return this->snore.data();
}
void Redircetor::setSnore(SnoreServer *snore){
this->WebInterface_Plugin::setSnore(snore);
}
#include "redirector.moc"

View File

@ -0,0 +1,38 @@
#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();
bool isPrimaryNotificationBackend(){return false;}
QString display();
bool parseCommand(QTcpSocket *client, const QString &command);
class SnoreServer* getSnore();
void setSnore(class SnoreServer *snore);
public slots:
int notify(QSharedPointer<class Notification>notification);
void closeNotification(int nr);
private:
QHash<QString,QSharedPointer<QTcpSocket> > subscribers;
QPointer<class SnoreServer> snore;
enum ARGUMENTS{
SUBSCRIBE=1,
UNSUBSCRIBE=2,
LISTSUBSCRIBERS=3,
};
QHash<QString,Redircetor::ARGUMENTS> getArgument;
};
#endif//REDIRECTOR_H

View File

@ -0,0 +1,8 @@
if(WITH_WEBINTERFACE)
set( REGISTREDAPPS_SRC
registredapps.cpp
)
automoc4_add_library(registredapps MODULE ${REGISTREDAPPS_SRC} )
target_link_libraries(registredapps snore webinterface)
endif(WITH_WEBINTERFACE)

View File

@ -0,0 +1,38 @@
#include "registredapps.h"
#include <QtCore>
#include <core/snoreserver.h>
Q_EXPORT_PLUGIN2(registredapps,RegistredApps)
RegistredApps::RegistredApps(){
setProperty("name","RegistredApps");
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=getSnore();
foreach(QSharedPointer<Application> a,snore->getAplicationList()->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

@ -0,0 +1,17 @@
#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();
bool parseCommand(QTcpSocket *client, const QString &command);
QString display();
};
#endif//REGISTREDAPPS_H

View File

@ -0,0 +1,9 @@
if(WIN32)
message(STATUS "Adding Snarl notification backend")
set( SNARL__SRC
SnarlInterface.cpp
snarl_backend.cpp
)
automoc4_add_library(snarln_backend MODULE ${SNARL__SRC} )
target_link_libraries(snarln_backend snore ${QT_QTCORE_LIBRARY} )
endif(WIN32)

View File

@ -0,0 +1,813 @@
// About:
// Snarl C++ interface implementation
// To understand what the different functions do and what they return, please
// have a look at the API on http://www.fullphat.net/dev/api.htm.
// Also have a look at mSnarl_i.bas found in the CVS/SVN repository for Snarl.
//
// The functions in SnarlInterface both have ANSI(UTF8) and UNICODE versions.
// If the LPCWSTR (unicode) version of the functions are called, the strings
// are converted to UTF8 by SnarlInterface before sent to Snarl. So using the
// ANSI/UTF8/LPCSTR versions of the functions are faster!
//
//
// Difference to VB implementation:
// Please note that string functions return NULL when they fail and not an
// empty string. So check for NULL...
// Function names doesn't have the pre "sn".
//
//
// Authors:
// Written and maintained by Toke Noer Nøttrup
// Original C++ version by "Whitman"
//
// License etc. :
// Feel free to use this code and class as you see fit.
// If you improve the code, it would be nice of you to take contact to the
// authors, so all can get the benifit.
//
// There is no guarantee that the code is correct or functional.
// USE AT YOUR OWN RISK
//-----------------------------------------------------------------------------
// History
// 2008/12/31 : Implemented V39 API
// : Moved SnarlInterface into new Snarl namespace and moved enums etc. out of class
// : Added WCHAR overloads for all functions
// 2008/08/27 : Fixed return value of IsMessageVisible and HideMessage (returns false on failure now)
// : Fixed critical error in the new overloaded UpdateMessage() function
// 2008/08/27 : x64 compiler fix
// 2008/08/24 : Renamed all functions to not have prepended "sn".
// : Memory allocation functions added. (Use FreeString to free strings returned by Snarl)
// : Added m_nLastMessageId to the class. (Use GetLastMessageId() to get it)
// : Overloaded a few functions, so one don't have include the message id. (UpdateMessage f.i.)
// 2008/06/20 : Fixed snShowMessageEx so it actually sends the extended version - oops
// : Fixed compiler warning C4800: forcing value to bool 'true' or 'false' (performance warning)
// 2008/05/19 : uSend and uSendEx would always set return value to M_OK on successfull call
// 2008/04/14 : Updated to follow (what should be) the final Snarl 2.0 API
// 2008/03/28 : Few fixes for Snarl 2.0
// 2007/05/23 : snGetGlobalMsg & snGetSnarlWindow made static
// 2007/03/25 : 1.6 RC1 fixup
// 2007/03/04 : Added - snGetAppPath, snGetIconsPath, snGetVersionEx,
// snSetTimeout, uSendEx
#include "SnarlInterface.h"
#include <winuser.h>
using namespace Snarl;
//-----------------------------------------------------------------------------
// Constructor/Destructor
//-----------------------------------------------------------------------------
SnarlInterface::SnarlInterface()
: m_hwndFrom(NULL), m_nLastMessageId(0)
{
}
SnarlInterface::~SnarlInterface()
{
}
//-----------------------------------------------------------------------------
// snShowMessage()
/// Displays a message with Title and Text. Timeout controls how long the
/// message is displayed for (in seconds) (omitting this value means the message
/// is displayed indefinately). IconPath specifies the location of a PNG image
/// which will be displayed alongside the message text.
/// <returns>Message Id on success or M_RESULT on failure</returns>
LONG32 SnarlInterface::ShowMessage(LPCSTR szTitle, LPCSTR szText, LONG32 timeout, LPCSTR szIconPath, HWND hWndReply, WPARAM uReplyMsg)
{
SNARLSTRUCT ss;
ZeroMemory((void*)&ss, sizeof(ss));
ss.Cmd = SNARL_SHOW;
StringCbCopyA((LPSTR)&ss.Title, SNARL_STRING_LENGTH, szTitle);
StringCbCopyA((LPSTR)&ss.Text, SNARL_STRING_LENGTH, szText);
StringCbCopyA((LPSTR)&ss.Icon, SNARL_STRING_LENGTH, szIconPath);
ss.Timeout = timeout;
ss.LngData2 = reinterpret_cast<LONG32>(hWndReply);
ss.Id = static_cast<LONG32>(uReplyMsg);
m_nLastMessageId = Send(ss);
return m_nLastMessageId;
}
LONG32 SnarlInterface::ShowMessage(LPCWSTR szTitle, LPCWSTR szText, LONG32 timeout, LPCWSTR szIconPath, HWND hWndReply, WPARAM uReplyMsg)
{
LPSTR szUTF8Title = WideToUTF8(szTitle);
LPSTR szUTF8Text = WideToUTF8(szText);
LPSTR szUFT8IconPath = WideToUTF8(szIconPath);
LONG32 result = ShowMessage(szUTF8Title, szUTF8Text, timeout, szUFT8IconPath, hWndReply, uReplyMsg);
delete [] szUTF8Title;
delete [] szUTF8Text;
delete [] szUFT8IconPath;
return result;
}
//-----------------------------------------------------------------------------
// snShowMessageEx()
/// Displays a notification. This function is identical to snShowMessage()
/// except that Class specifies an alert previously registered with
/// snRegisterAlert() and SoundFile can optionally specify a WAV sound to play
/// when the notification is displayed on screen.
/// <returns>Message Id on success or M_RESULT on failure</returns>
LONG32 SnarlInterface::ShowMessageEx(LPCSTR szClass, LPCSTR szTitle, LPCSTR szText, LONG32 timeout, LPCSTR szIconPath, HWND hWndReply, WPARAM uReplyMsg, LPCSTR szSoundFile)
{
SNARLSTRUCTEX ssex;
ZeroMemory((void*)&ssex, sizeof(ssex));
ssex.Cmd = SNARL_EX_SHOW;
ssex.Timeout = timeout;
ssex.LngData2 = reinterpret_cast<LONG32>(hWndReply);
ssex.Id = static_cast<LONG32>(uReplyMsg);
StringCbCopyA((LPSTR)&ssex.Class, SNARL_STRING_LENGTH, szClass);
StringCbCopyA((LPSTR)&ssex.Title, SNARL_STRING_LENGTH, szTitle);
StringCbCopyA((LPSTR)&ssex.Text, SNARL_STRING_LENGTH, szText);
StringCbCopyA((LPSTR)&ssex.Icon, SNARL_STRING_LENGTH, szIconPath);
StringCbCopyA((LPSTR)&ssex.Extra, SNARL_STRING_LENGTH, szSoundFile);
m_nLastMessageId = Send(ssex);
return m_nLastMessageId;
}
LONG32 SnarlInterface::ShowMessageEx(LPCWSTR szClass, LPCWSTR szTitle, LPCWSTR szText, LONG32 timeout, LPCWSTR szIconPath, HWND hWndReply, WPARAM uReplyMsg, LPCWSTR szSoundFile)
{
LPSTR szUTF8Class = WideToUTF8(szClass);
LPSTR szUTF8Title = WideToUTF8(szTitle);
LPSTR szUTF8Text = WideToUTF8(szText);
LPSTR szUFT8IconPath = WideToUTF8(szIconPath);
LPSTR szUFT8SoundFile = WideToUTF8(szSoundFile);
LONG32 result = ShowMessageEx(szUTF8Class, szUTF8Title, szUTF8Text, timeout, szUFT8IconPath, hWndReply, uReplyMsg, szUFT8SoundFile);
delete [] szUTF8Class;
delete [] szUTF8Title;
delete [] szUTF8Text;
delete [] szUFT8IconPath;
delete [] szUFT8SoundFile;
return result;
}
//-----------------------------------------------------------------------------
// snHideMessage()
/// Hides the notification specified by Id. Id is the value returned by
/// snShowMessage() or snShowMessageEx() when the notification was initially
/// created. This function returns True if the notification was successfully
/// hidden or False otherwise (for example, the notification may no longer exist).
BOOL SnarlInterface::HideMessage(LONG32 Id)
{
SNARLSTRUCT ss;
ss.Cmd = SNARL_HIDE;
ss.Id = Id;
LONG32 n = Send(ss);
return (n == -1 || n == 1) ? TRUE : FALSE;
}
BOOL SnarlInterface::HideMessage()
{
return HideMessage(m_nLastMessageId);
}
//-----------------------------------------------------------------------------
// snIsMessageVisible()
/// Returns True if the notification specified by Id is still visible, or
/// False if not. Id is the value returned by snShowMessage() or
/// snShowMessageEx() when the notification was initially created.
BOOL SnarlInterface::IsMessageVisible(LONG32 Id)
{
SNARLSTRUCT ss;
ss.Cmd = SNARL_IS_VISIBLE;
ss.Id = Id;
// We are getting -1 when true, checking for 1 just in case. We don't want to return true for the other M_RESULT returns
LONG32 n = Send(ss);
return (n == -1 || n == 1) ? TRUE : FALSE;
}
BOOL SnarlInterface::IsMessageVisible()
{
if (m_nLastMessageId == 0)
return FALSE;
return IsMessageVisible(m_nLastMessageId);
}
//-----------------------------------------------------------------------------
// snUpdateMessage()
/// Changes the title and text in the message specified by Id to the values
/// specified by Title and Text respectively. Id is the value returned by
/// snShowMessage() or snShowMessageEx() when the notification was originally
/// created. To change the timeout parameter of a notification, use snSetTimeout()
M_RESULT SnarlInterface::UpdateMessage(LONG32 id, LPCSTR szTitle, LPCSTR szText, LPCSTR szIconPath)
{
SNARLSTRUCT ss;
ZeroMemory((void*)&ss, sizeof(ss));
ss.Cmd = SNARL_UPDATE;
ss.Id = id;
StringCbCopyA((LPSTR)&ss.Title, SNARL_STRING_LENGTH, szTitle);
StringCbCopyA((LPSTR)&ss.Text, SNARL_STRING_LENGTH, szText);
StringCbCopyA((LPSTR)&ss.Icon, SNARL_STRING_LENGTH, szIconPath);
return static_cast<M_RESULT>(Send(ss));
}
M_RESULT SnarlInterface::UpdateMessage(LONG32 id, LPCWSTR szTitle, LPCWSTR szText, LPCWSTR szIconPath)
{
LPSTR szParam1 = WideToUTF8(szTitle);
LPSTR szParam2 = WideToUTF8(szText);
LPSTR szParam3 = WideToUTF8(szIconPath);
M_RESULT result = UpdateMessage(id, szParam1, szParam2, szParam3);
delete [] szParam1;
delete [] szParam2;
delete [] szParam3;
return result;
}
M_RESULT SnarlInterface::UpdateMessage(LPCSTR szTitle, LPCSTR szText, LPCSTR szIconPath)
{
return UpdateMessage(m_nLastMessageId, szTitle, szText, szIconPath);
}
M_RESULT SnarlInterface::UpdateMessage(LPCWSTR szTitle, LPCWSTR szText, LPCWSTR szIconPath)
{
return UpdateMessage(m_nLastMessageId, szTitle, szText, szIconPath);
}
//-----------------------------------------------------------------------------
// snRegisterConfig
/// Registers an application's configuration interface with Snarl.
/// AppName is the text that's displayed in the Applications list so it should
/// be people friendly ("My cool app" rather than "my_cool_app").
M_RESULT SnarlInterface::RegisterConfig(HWND hWnd, LPCSTR szAppName, LONG32 replyMsg)
{
return RegisterConfig2(hWnd, szAppName, replyMsg, "");
}
M_RESULT SnarlInterface::RegisterConfig(HWND hWnd, LPCWSTR szAppName, LONG32 replyMsg)
{
return RegisterConfig2(hWnd, szAppName, replyMsg, L"");
}
//-----------------------------------------------------------------------------
// snRegisterConfig2
/// Registers an application's configuration interface with Snarl.
/// This function is identical to snRegisterConfig() except that Icon can be
/// used to specify a PNG image which will be displayed against the
/// application's entry in Snarl's Preferences panel.
M_RESULT SnarlInterface::RegisterConfig2(HWND hWnd, LPCSTR szAppName, LONG32 replyMsg, LPCSTR szIcon)
{
if (!szAppName || !szIcon)
return M_BAD_POINTER;
SNARLSTRUCT ss;
m_hwndFrom = hWnd;
ss.Cmd = SNARL_REGISTER_CONFIG_WINDOW_2;
ss.LngData2 = reinterpret_cast<LONG32>(hWnd);
ss.Id = replyMsg;
StringCbCopyA((LPSTR)&ss.Title, SNARL_STRING_LENGTH, szAppName);
StringCbCopyA((LPSTR)&ss.Icon, SNARL_STRING_LENGTH, szIcon);
return static_cast<M_RESULT>(Send(ss));
}
M_RESULT SnarlInterface::RegisterConfig2(HWND hWnd, LPCWSTR szAppName, LONG32 replyMsg, LPCWSTR szIcon)
{
LPSTR szParam1 = WideToUTF8(szAppName);
LPSTR szParam2 = WideToUTF8(szIcon);
M_RESULT result = RegisterConfig2(hWnd, szParam1, replyMsg, szParam2);
delete [] szParam1;
delete [] szParam2;
return result;
}
//-----------------------------------------------------------------------------
// snRevokeConfig
/// Removes the application previously registered using snRegisterConfig() or
/// snRegisterConfig2(). hWnd should be the same as that used during registration.
M_RESULT SnarlInterface::RevokeConfig(HWND hWnd)
{
SNARLSTRUCT ss;
m_hwndFrom = NULL;
ss.Cmd = SNARL_REVOKE_CONFIG_WINDOW;
ss.LngData2 = reinterpret_cast<LONG32>(hWnd);
return static_cast<M_RESULT>(Send(ss));
}
//-----------------------------------------------------------------------------
// snGetVersion()
/// Checks if Snarl is currently running and, if it is, retrieves the major and
/// minor release version numbers in Major and Minor respectively.
/// Returns True if Snarl is running, False otherwise.
BOOL SnarlInterface::GetVersion(WORD* Major, WORD* Minor)
{
SNARLSTRUCT ss;
ss.Cmd = SNARL_GET_VERSION;
LONG32 versionInfo = Send(ss);
if (versionInfo > 0 && versionInfo != M_FAILED && versionInfo != M_TIMED_OUT) {
*Major = HIWORD(versionInfo);
*Minor = LOWORD(versionInfo);
return TRUE;
}
return FALSE;
}
//-----------------------------------------------------------------------------
// snGetVersionEx
/// Returns the Snarl system version number. This is an integer value which
/// represents the system build number and can be used to identify the specific
/// version of Snarl running
LONG32 SnarlInterface::GetVersionEx()
{
SNARLSTRUCT ss;
ss.Cmd = SNARL_GET_VERSION_EX;
return Send(ss);
}
//-----------------------------------------------------------------------------
// snSetTimeout()
/// Sets the timeout of existing notification Id to Timeout seconds. Id is the
/// value returned by snShowMessage() or snShowMessageEx() when the notification
/// was first created.
M_RESULT SnarlInterface::SetTimeout(LONG32 Id, LONG32 Timeout)
{
SNARLSTRUCT ss;
ss.Cmd = SNARL_SET_TIMEOUT;
ss.Id = Id;
ss.LngData2 = Timeout;
return static_cast<M_RESULT>(Send(ss));
}
M_RESULT SnarlInterface::SetTimeout(LONG32 Timeout)
{
return SetTimeout(m_nLastMessageId, Timeout);
}
//-----------------------------------------------------------------------------
// snRegisterAlert()
/// Registers an alert of Class for application AppName which must have previously
/// been registered with either snRegisterConfig() or snRegisterConfig2().
M_RESULT SnarlInterface::RegisterAlert(LPCSTR szAppName, LPCSTR szClass)
{
SNARLSTRUCT ss;
ss.Cmd = SNARL_REGISTER_ALERT;
StringCbCopyA((LPSTR)&ss.Title, SNARL_STRING_LENGTH, szAppName);
StringCbCopyA((LPSTR)&ss.Text, SNARL_STRING_LENGTH, szClass);
return static_cast<M_RESULT>(Send(ss));
}
M_RESULT SnarlInterface::RegisterAlert(LPCWSTR szAppName, LPCWSTR szClass)
{
LPSTR szParam1 = WideToUTF8(szAppName);
LPSTR szParam2 = WideToUTF8(szClass);
M_RESULT result = RegisterAlert(szParam1, szParam2);
delete [] szParam1;
delete [] szParam2;
return result;
}
//-----------------------------------------------------------------------------
// snGetGlobalMsg()
/// Returns the atom that corresponds to the "SnarlGlobalEvent" registered
/// Windows message. This message is sent by Snarl when it is first starts and
/// when it shuts down.
LONG32 SnarlInterface::GetGlobalMsg()
{
return RegisterWindowMessage(SNARL_GLOBAL_MSG);
}
//-----------------------------------------------------------------------------
// snGetSnarlWindow
HWND SnarlInterface::GetSnarlWindow()
{
return FindWindow(NULL, _T("Snarl"));
}
//-----------------------------------------------------------------------------
// snGetAppPath()
/// Returns a pointer to the path.
/// ** Remember to call FreeString
LPCTSTR SnarlInterface::GetAppPath()
{
HWND hWnd = GetSnarlWindow();
if (hWnd)
{
HWND hWndPath = FindWindowEx(hWnd, 0, _T("static"), NULL);
if (hWndPath)
{
TCHAR strTmp[MAX_PATH] = {0};
int nReturn = GetWindowText(hWndPath, strTmp, MAX_PATH);
if (nReturn > 0) {
TCHAR* strReturn = AllocateString(nReturn + 1);
StringCchCopy(strReturn, nReturn + 1, strTmp);
return strReturn;
}
}
}
return NULL;
}
//-----------------------------------------------------------------------------
// snGetIconsPath()
/// Returns a pointer to the iconpath.
/// ** Remember to call FreeString when done with the string
LPCTSTR SnarlInterface::GetIconsPath()
{
TCHAR* szIconPath = NULL;
LPCTSTR szPath = GetAppPath();
if (!szPath)
return NULL;
size_t nLen = 0;
if (SUCCEEDED(StringCbLength(szPath, MAX_PATH, &nLen)))
{
nLen += 10 + 1; // etc\\icons\\ + NULL
szIconPath = AllocateString(nLen);
StringCbCopy(szIconPath, nLen * sizeof(TCHAR), szPath);
StringCbCat(szIconPath, nLen * sizeof(TCHAR), _T("etc\\icons\\"));
}
FreeString(szPath);
return szIconPath;
}
//-----------------------------------------------------------------------------
// snSetAsSnarlApp()
/// Identifies an application as a Snarl App. (V39)
void SnarlInterface::SetAsSnarlApp(HWND hWndOwner, SNARL_APP_FLAGS Flags)
{
if (IsWindow(hWndOwner)) {
SetProp(hWndOwner, _T("snarl_app"), reinterpret_cast<HANDLE>(1));
SetProp(hWndOwner, _T("snarl_app_flags"), reinterpret_cast<HANDLE>(Flags));
}
}
//-----------------------------------------------------------------------------
// snGetAppMsg()
/// Returns the global Snarl Application message (V39)
LONG32 SnarlInterface::GetAppMsg()
{
return RegisterWindowMessage(SNARL_APP_MSG);
}
//-----------------------------------------------------------------------------
// snRegisterApp()
/// Registers an application with Snarl (V39)
M_RESULT SnarlInterface::RegisterApp(LPCSTR Application, LPCSTR SmallIcon, LPCSTR LargeIcon, HWND hWnd, LONG32 ReplyMsg)
{
m_hwndFrom = hWnd;
SNARLSTRUCT ss;
ss.Cmd = SNARL_REGISTER_APP;
StringCbCopyA((LPSTR)&ss.Title, SNARL_STRING_LENGTH, Application);
StringCbCopyA((LPSTR)&ss.Icon, SNARL_STRING_LENGTH, SmallIcon);
StringCbCopyA((LPSTR)&ss.Text, SNARL_STRING_LENGTH, LargeIcon);
ss.LngData2 = reinterpret_cast<LONG32>(hWnd);
ss.Id = ReplyMsg;
ss.Timeout = GetCurrentProcessId();
return static_cast<M_RESULT>(Send(ss));
}
M_RESULT SnarlInterface::RegisterApp(LPCWSTR Application, LPCWSTR SmallIcon, LPCWSTR LargeIcon, HWND hWnd, LONG32 ReplyMsg)
{
LPSTR szParam1 = WideToUTF8(Application);
LPSTR szParam2 = WideToUTF8(SmallIcon);
LPSTR szParam3 = WideToUTF8(LargeIcon);
M_RESULT result = RegisterApp(szParam1, szParam2, szParam3, hWnd, ReplyMsg);
delete [] szParam1;
delete [] szParam2;
delete [] szParam3;
return result;
}
//-----------------------------------------------------------------------------
// snUnregisterApp()
/// Unregisters an application with Snarl (V39)
M_RESULT SnarlInterface::UnregisterApp()
{
SNARLSTRUCT ss;
ss.Cmd = SNARL_UNREGISTER_APP;
ss.LngData2 = GetCurrentProcessId();
m_hwndFrom = NULL;
return static_cast<M_RESULT>(Send(ss));
}
//-----------------------------------------------------------------------------
// snShowNotification()
/// Displays a Snarl notification using registered class (V39)
/// <returns>Message Id on success or M_RESULT on failure</returns>
LONG32 SnarlInterface::ShowNotification(LPCSTR Class, LPCSTR Title, LPCSTR Text, LONG32 Timeout, LPCSTR Icon, HWND hWndReply, LONG32 uReplyMsg, LPCSTR Sound)
{
SNARLSTRUCTEX ssex;
ssex.Cmd = SNARL_SHOW_NOTIFICATION;
StringCbCopyExA((LPSTR)&ssex.Title, SNARL_STRING_LENGTH, Title, NULL, NULL, STRSAFE_IGNORE_NULLS);
StringCbCopyExA((LPSTR)&ssex.Text, SNARL_STRING_LENGTH, Text, NULL, NULL, STRSAFE_IGNORE_NULLS);
StringCbCopyExA((LPSTR)&ssex.Icon, SNARL_STRING_LENGTH, Icon, NULL, NULL, STRSAFE_IGNORE_NULLS);
ssex.Timeout = Timeout;
ssex.LngData2 = reinterpret_cast<LONG32>(hWndReply);
ssex.Id = uReplyMsg;
StringCbCopyExA((LPSTR)&ssex.Extra, SNARL_STRING_LENGTH, Sound, NULL, NULL, STRSAFE_IGNORE_NULLS);
StringCbCopyA((LPSTR)&ssex.Class, SNARL_STRING_LENGTH, Class);
ssex.Reserved1 = GetCurrentProcessId();
m_nLastMessageId = Send(ssex);
return m_nLastMessageId;
}
LONG32 SnarlInterface::ShowNotification(LPCWSTR Class, LPCWSTR Title, LPCWSTR Text, LONG32 Timeout, LPCWSTR Icon, HWND hWndReply, LONG32 uReplyMsg, LPCWSTR Sound)
{
LPSTR szParam1 = WideToUTF8(Class);
LPSTR szParam2 = WideToUTF8(Title);
LPSTR szParam3 = WideToUTF8(Text);
LPSTR szParam4 = WideToUTF8(Icon);
LPSTR szParam5 = WideToUTF8(Sound);
LONG32 result = ShowNotification(szParam1, szParam2, szParam3, Timeout, szParam4, hWndReply, uReplyMsg, szParam5);
delete [] szParam1;
delete [] szParam2;
delete [] szParam3;
delete [] szParam4;
delete [] szParam5;
return result;
}
//-----------------------------------------------------------------------------
// snChangeAttribute()
/// (V39)
M_RESULT SnarlInterface::ChangeAttribute(LONG32 Id, SNARL_ATTRIBUTES Attr, LPCSTR Value)
{
SNARLSTRUCT ss;
ss.Cmd = SNARL_CHANGE_ATTR;
ss.Id = Id;
ss.LngData2 = Attr;
StringCbCopyExA((LPSTR)&ss.Text, SNARL_STRING_LENGTH, Value, NULL, NULL, STRSAFE_IGNORE_NULLS);
return static_cast<M_RESULT>(Send(ss));
}
M_RESULT SnarlInterface::ChangeAttribute(LONG32 Id, SNARL_ATTRIBUTES Attr, LPCWSTR Value)
{
LPSTR szParam1 = WideToUTF8(Value);
M_RESULT result = ChangeAttribute(Id, Attr, szParam1);
delete [] szParam1;
return result;
}
M_RESULT SnarlInterface::ChangeAttribute(SNARL_ATTRIBUTES Attr, LPCSTR Value)
{
return ChangeAttribute(m_nLastMessageId, Attr, Value);
}
M_RESULT SnarlInterface::ChangeAttribute(SNARL_ATTRIBUTES Attr, LPCWSTR Value)
{
return ChangeAttribute(m_nLastMessageId, Attr, Value);
}
//-----------------------------------------------------------------------------
// snSetClassDefault()
/// Sets the default value for an alert class (V39)
M_RESULT SnarlInterface::SetClassDefault(LPCSTR Class, SNARL_ATTRIBUTES Attr, LPCSTR Value)
{
SNARLSTRUCT ss;
ss.Cmd = SNARL_SET_CLASS_DEFAULT;
ss.LngData2 = Attr;
ss.Timeout = GetCurrentProcessId();
StringCbCopyExA((LPSTR)&ss.Text, SNARL_STRING_LENGTH, Class, NULL, NULL, STRSAFE_IGNORE_NULLS);
StringCbCopyExA((LPSTR)&ss.Icon, SNARL_STRING_LENGTH, Value, NULL, NULL, STRSAFE_IGNORE_NULLS);
return static_cast<M_RESULT>(Send(ss));
}
M_RESULT SnarlInterface::SetClassDefault(LPCWSTR Class, SNARL_ATTRIBUTES Attr, LPCWSTR Value)
{
LPSTR szParam1 = WideToUTF8(Class);
LPSTR szParam2 = WideToUTF8(Value);
M_RESULT result = SetClassDefault(szParam1, Attr, szParam2);
delete [] szParam1;
delete [] szParam2;
return result;
}
//-----------------------------------------------------------------------------
// snGetRevision()
/// Gets the current Snarl revision (build) number (V39)
/// Returns the build version number, or M_RESULT on failure.
LONG32 SnarlInterface::GetRevision()
{
SNARLSTRUCT ss;
ss.Cmd = SNARL_GET_REVISION;
ss.LngData2 = 0xFFFE;
return Send(ss);
}
//-----------------------------------------------------------------------------
// snAddClass()
/// (V39)
M_RESULT SnarlInterface::AddClass(LPCSTR Class, LPCSTR Description, SNARL_CLASS_FLAGS Flags, LPCSTR DefaultTitle, LPCSTR DefaultIcon, LONG32 DefaultTimeout)
{
SNARLSTRUCT ss;
ss.Cmd = SNARL_ADD_CLASS;
ss.LngData2 = Flags;
ss.Timeout = GetCurrentProcessId();
StringCbCopyExA((LPSTR)&ss.Text, SNARL_STRING_LENGTH, Class, NULL, NULL, STRSAFE_IGNORE_NULLS);
StringCbCopyExA((LPSTR)&ss.Title, SNARL_STRING_LENGTH, Description, NULL, NULL, STRSAFE_IGNORE_NULLS);
LONG32 result = Send(ss);
if (static_cast<M_RESULT>(result) == M_OK)
{
SetClassDefault(Class, SNARL_ATTRIBUTE_TITLE, DefaultTitle);
SetClassDefault(Class, SNARL_ATTRIBUTE_ICON, DefaultIcon);
if (DefaultTimeout > 0) {
char str[64] = {0};
StringCbPrintfA((LPSTR)&str, sizeof(str), "%d", DefaultTimeout);
SetClassDefault(Class, SNARL_ATTRIBUTE_TIMEOUT, str);
}
return M_OK;
}
else
return M_FAILED;
}
M_RESULT SnarlInterface::AddClass(LPCWSTR Class, LPCWSTR Description, SNARL_CLASS_FLAGS Flags, LPCWSTR DefaultTitle, LPCWSTR DefaultIcon, LONG32 DefaultTimeout)
{
LPCSTR szClass = WideToUTF8(Class);
LPCSTR szDescription = WideToUTF8(Description);
LPCSTR szDefaultTitle = WideToUTF8(DefaultTitle);
LPCSTR szDefaultIcon = WideToUTF8(DefaultIcon);
M_RESULT result = AddClass(szClass, szDescription, Flags, szDefaultTitle, szDefaultIcon, DefaultTimeout);
delete [] szClass;
delete [] szDescription;
delete [] szDefaultTitle;
delete [] szDefaultIcon;
return result;
}
//-----------------------------------------------------------------------------
// Private functions
//-----------------------------------------------------------------------------
template <class T>
LONG32 SnarlInterface::Send(T ss)
{
DWORD_PTR nReturn = M_FAILED;
HWND hWnd = GetSnarlWindow();
if (IsWindow(hWnd))
{
COPYDATASTRUCT cds;
cds.dwData = 2;
cds.cbData = sizeof(ss);
cds.lpData = &ss;
if (SendMessageTimeout(hWnd, WM_COPYDATA, (WPARAM)m_hwndFrom, (LPARAM)&cds, SMTO_ABORTIFHUNG | SMTO_NOTIMEOUTIFNOTHUNG, 1000, &nReturn) == 0)
{
if (GetLastError() == ERROR_TIMEOUT)
nReturn = M_TIMED_OUT;
}
}
return static_cast<LONG32>(nReturn);
}
//-----------------------------------------------------------------------------
// Remember to : delete [] returned string
LPSTR SnarlInterface::WideToUTF8(LPCWSTR szWideStr)
{
if (szWideStr == NULL)
return NULL;
int nSize = WideCharToMultiByte(CP_UTF8, 0, szWideStr, -1, NULL, 0, NULL, NULL);
LPSTR szUTF8 = new char[nSize];
WideCharToMultiByte(CP_UTF8, 0, szWideStr, -1, szUTF8, nSize, NULL, NULL);
return szUTF8;
}

View File

@ -0,0 +1,218 @@
#ifndef SNARL_INTERFACE
#define SNARL_INTERFACE
#include <tchar.h>
#include <windows.h>
#include <strsafe.h>
namespace Snarl {
static const LPCTSTR SNARL_GLOBAL_MSG = _T("SnarlGlobalEvent");
static const LPCTSTR SNARL_APP_MSG = _T("SnarlAppMessage");
static const int SNARL_STRING_LENGTH = 1024;
static const int SNARL_UNICODE_LENGTH = SNARL_STRING_LENGTH / 2;
static const LONG32 SNARL_LAUNCHED = 1; // Snarl has just started running
static const LONG32 SNARL_QUIT = 2; // Snarl is about to stop running
static const LONG32 SNARL_ASK_APPLET_VER = 3; // (R1.5) Reserved for future use
static const LONG32 SNARL_SHOW_APP_UI = 4; // (R1.6) Application should show its UI
static const LONG32 SNARL_NOTIFICATION_CLICKED = 32; // notification was right-clicked by user
static const LONG32 SNARL_NOTIFICATION_TIMED_OUT = 33;
static const LONG32 SNARL_NOTIFICATION_ACK = 34; // notification was left-clicked by user
static const LONG32 SNARL_NOTIFICATION_MENU = 35; // V39 - menu item selected
static const LONG32 SNARL_NOTIFICATION_MIDDLE_BUTTON = 36; // V39 - notification middle-clicked by user
static const LONG32 SNARL_NOTIFICATION_CLOSED = 37; // V39 - user clicked the close gadget
static const LONG32 SNARL_NOTIFICATION_CANCELLED = SNARL_NOTIFICATION_CLICKED; // Added in R1.6
static const DWORD WM_SNARLTEST = WM_USER + 237; // note hardcoded WM_USER value!
// --------------------------------------------------------------------
typedef enum M_RESULT {
M_ABORTED = 0x80000007,
M_ACCESS_DENIED = 0x80000009,
M_ALREADY_EXISTS = 0x8000000C,
M_BAD_HANDLE = 0x80000006,
M_BAD_POINTER = 0x80000005,
M_FAILED = 0x80000008,
M_INVALID_ARGS = 0x80000003,
M_NO_INTERFACE = 0x80000004,
M_NOT_FOUND = 0x8000000B,
M_NOT_IMPLEMENTED = 0x80000001,
M_OK = 0x00000000,
M_OUT_OF_MEMORY = 0x80000002,
M_TIMED_OUT = 0x8000000A
};
enum SNARL_COMMANDS {
SNARL_SHOW = 1,
SNARL_HIDE,
SNARL_UPDATE,
SNARL_IS_VISIBLE,
SNARL_GET_VERSION,
SNARL_REGISTER_CONFIG_WINDOW,
SNARL_REVOKE_CONFIG_WINDOW,
/* R1.6 onwards */
SNARL_REGISTER_ALERT,
SNARL_REVOKE_ALERT, // for future use
SNARL_REGISTER_CONFIG_WINDOW_2,
SNARL_GET_VERSION_EX,
SNARL_SET_TIMEOUT,
/* following introduced in Snarl V39 (R2.1) */
SNARL_SET_CLASS_DEFAULT,
SNARL_CHANGE_ATTR,
SNARL_REGISTER_APP,
SNARL_UNREGISTER_APP,
SNARL_ADD_CLASS,
/* extended commands (all use SNARLSTRUCTEX) */
SNARL_EX_SHOW = 0x20,
SNARL_SHOW_NOTIFICATION // V39
};
static const SNARL_COMMANDS SNARL_GET_REVISION = SNARL_REVOKE_ALERT;
typedef enum SNARL_APP_FLAGS {
SNARL_APP_HAS_PREFS = 1,
SNARL_APP_HAS_ABOUT = 2
};
static const LONG32 SNARL_APP_PREFS = 1;
static const LONG32 SNARL_APP_ABOUT = 2;
/* --------------- V39 additions --------------- */
/* snAddClass() flags */
enum SNARL_CLASS_FLAGS {
SNARL_CLASS_ENABLED = 0,
SNARL_CLASS_DISABLED = 1,
SNARL_CLASS_NO_DUPLICATES = 2, // means Snarl will suppress duplicate notifications
SNARL_CLASS_DELAY_DUPLICATES = 4 // means Snarl will suppress duplicate notifications within a pre-set time period
};
/* Class attributes */
typedef enum SNARL_ATTRIBUTES {
SNARL_ATTRIBUTE_TITLE = 1,
SNARL_ATTRIBUTE_TEXT,
SNARL_ATTRIBUTE_ICON,
SNARL_ATTRIBUTE_TIMEOUT,
SNARL_ATTRIBUTE_SOUND,
SNARL_ATTRIBUTE_ACK, // file to run on ACK
SNARL_ATTRIBUTE_MENU
};
/* ------------------- end of V39 additions ------------------ */
struct SNARLSTRUCT {
SNARL_COMMANDS Cmd;
LONG32 Id;
LONG32 Timeout;
LONG32 LngData2;
char Title[SNARL_STRING_LENGTH];
char Text[SNARL_STRING_LENGTH];
char Icon[SNARL_STRING_LENGTH];
};
struct SNARLSTRUCTEX {
SNARL_COMMANDS Cmd;
LONG32 Id;
LONG32 Timeout;
LONG32 LngData2;
char Title[SNARL_STRING_LENGTH];
char Text[SNARL_STRING_LENGTH];
char Icon[SNARL_STRING_LENGTH];
char Class[SNARL_STRING_LENGTH];
char Extra[SNARL_STRING_LENGTH];
char Extra2[SNARL_STRING_LENGTH];
LONG32 Reserved1;
LONG32 Reserved2;
};
// ------------------------------------------------------------------------
// SnarlInterface class definition
// ------------------------------------------------------------------------
class SnarlInterface {
public:
SnarlInterface();
~SnarlInterface();
static HWND GetSnarlWindow();
static LONG32 GetGlobalMsg();
LPTSTR AllocateString(size_t n) { return new TCHAR[n]; }
void FreeString(LPCTSTR str) { delete [] str; str = NULL; }
LONG32 ShowMessage(LPCSTR szTitle, LPCSTR szText, LONG32 timeout = 0, LPCSTR szIconPath = "", HWND hWndReply = NULL, WPARAM uReplyMsg = 0);
LONG32 ShowMessage(LPCWSTR szTitle, LPCWSTR szText, LONG32 timeout = 0, LPCWSTR szIconPath = L"", HWND hWndReply = NULL, WPARAM uReplyMsg = 0);
LONG32 ShowMessageEx(LPCSTR szClass, LPCSTR szTitle, LPCSTR szText, LONG32 timeout = 0, LPCSTR szIconPath = "", HWND hWndReply = NULL, WPARAM uReplyMsg = 0, LPCSTR szSoundFile = "");
LONG32 ShowMessageEx(LPCWSTR szClass, LPCWSTR szTitle, LPCWSTR szText, LONG32 timeout = 0, LPCWSTR szIconPath = L"", HWND hWndReply = NULL, WPARAM uReplyMsg = 0, LPCWSTR szSoundFile = L"");
LPCTSTR GetAppPath(); // ** Remember to FreeString when finished with the string !
LPCTSTR GetIconsPath(); // ** Remember to FreeString when finished with the string !
BOOL GetVersion(WORD* Major, WORD* Minor);
LONG32 GetVersionEx();
BOOL HideMessage();
BOOL HideMessage(LONG32 Id);
BOOL IsMessageVisible();
BOOL IsMessageVisible(LONG32 Id);
M_RESULT RegisterAlert(LPCSTR szAppName, LPCSTR szClass);
M_RESULT RegisterAlert(LPCWSTR szAppName, LPCWSTR szClass);
M_RESULT RegisterConfig(HWND hWnd, LPCSTR szAppName, LONG32 replyMsg);
M_RESULT RegisterConfig(HWND hWnd, LPCWSTR szAppName, LONG32 replyMsg);
M_RESULT RegisterConfig2(HWND hWnd, LPCSTR szAppName, LONG32 replyMsg, LPCSTR szIcon);
M_RESULT RegisterConfig2(HWND hWnd, LPCWSTR szAppName, LONG32 replyMsg, LPCWSTR szIcon);
M_RESULT RevokeConfig(HWND hWnd);
M_RESULT SetTimeout(LONG32 Timeout);
M_RESULT SetTimeout(LONG32 Id, LONG32 Timeout);
M_RESULT UpdateMessage(LPCSTR szTitle, LPCSTR szText, LPCSTR szIconPath = "");
M_RESULT UpdateMessage(LPCWSTR szTitle, LPCWSTR szText, LPCWSTR szIconPath = L"");
M_RESULT UpdateMessage(LONG32 Id, LPCSTR szTitle, LPCSTR szText, LPCSTR szIconPath = "");
M_RESULT UpdateMessage(LONG32 Id, LPCWSTR szTitle, LPCWSTR szText, LPCWSTR szIconPath = L"");
/* V39 */
M_RESULT AddClass(LPCSTR Class, LPCSTR Description = NULL, SNARL_CLASS_FLAGS Flags = SNARL_CLASS_ENABLED, LPCSTR DefaultTitle = NULL, LPCSTR DefaultIcon = NULL, LONG32 DefaultTimeout = 0);
M_RESULT AddClass(LPCWSTR Class, LPCWSTR Description = NULL, SNARL_CLASS_FLAGS Flags = SNARL_CLASS_ENABLED, LPCWSTR DefaultTitle = NULL, LPCWSTR DefaultIcon = NULL, LONG32 DefaultTimeout = 0);
M_RESULT ChangeAttribute(SNARL_ATTRIBUTES Attr, LPCSTR Value);
M_RESULT ChangeAttribute(SNARL_ATTRIBUTES Attr, LPCWSTR Value);
M_RESULT ChangeAttribute(LONG32 Id, SNARL_ATTRIBUTES Attr, LPCSTR Value);
M_RESULT ChangeAttribute(LONG32 Id, SNARL_ATTRIBUTES Attr, LPCWSTR Value);
LONG32 GetAppMsg();
LONG32 GetRevision();
M_RESULT RegisterApp(LPCSTR Application, LPCSTR SmallIcon, LPCSTR LargeIcon, HWND hWnd = 0, LONG32 ReplyMsg = 0);
M_RESULT RegisterApp(LPCWSTR Application, LPCWSTR SmallIcon, LPCWSTR LargeIcon, HWND hWnd = 0, LONG32 ReplyMsg = 0);
void SetAsSnarlApp(HWND hWndOwner, SNARL_APP_FLAGS Flags = (SNARL_APP_FLAGS)(SNARL_APP_HAS_ABOUT | SNARL_APP_HAS_PREFS));
M_RESULT SetClassDefault(LPCSTR Class, SNARL_ATTRIBUTES Attr, LPCSTR Value);
M_RESULT SetClassDefault(LPCWSTR Class, SNARL_ATTRIBUTES Attr, LPCWSTR Value);
LONG32 ShowNotification(LPCSTR Class, LPCSTR Title = NULL, LPCSTR Text = NULL, LONG32 Timeout = 0, LPCSTR Icon = NULL, HWND hWndReply = NULL, LONG32 uReplyMsg = 0, LPCSTR Sound = NULL);
LONG32 ShowNotification(LPCWSTR Class, LPCWSTR Title = NULL, LPCWSTR Text = NULL, LONG32 Timeout = 0, LPCWSTR Icon = NULL, HWND hWndReply = NULL, LONG32 uReplyMsg = 0, LPCWSTR Sound = NULL);
M_RESULT UnregisterApp();
LONG32 GetLastMessageId() { return m_nLastMessageId; }
private:
template <class T> LONG32 Send(T ss);
LPSTR WideToUTF8(LPCWSTR szWideStr);
LONG32 m_nLastMessageId;
HWND m_hwndFrom; // set during snRegisterConfig() or snRegisterConfig2()
};
}
#endif // SNARL_INTERFACE

View File

@ -0,0 +1,37 @@
#include "snarl_backend.h"
#include <QtCore>
Q_EXPORT_PLUGIN2(snarl_backend,Snarl_Backend)
Snarl_Backend::Snarl_Backend()
{
setProperty("name","Snarl_Backend");
snarlInterface=new Snarl::SnarlInterface();
qDebug()<<"Initiating Snarl Backend, Snarl version: "<<snarlInterface->GetVersionExA();
this->installEventFilter(this);
}
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());
}else{
//update message
snarlInterface->UpdateMessage(LONG32(notification->id),notification->title.toLocal8Bit().data(), notification->text.toLocal8Bit().data(),notification->getIcon().toLocal8Bit().data());
return notification->id;
}
}
void Snarl_Backend::closeNotification(int nr){
snarlInterface->HideMessage(nr);
}
bool Snarl_Backend::eventFilter(QObject *obj, QEvent *event){
qDebug()<<obj->objectName();
return true;
}
#include "snarl_backend.moc"

View File

@ -0,0 +1,27 @@
#ifndef SNARL_BACKEND_H
#define SNARL_BACKEND_H
#include "core/interface.h"
#include "SnarlInterface.h"
class Snarl_Backend:public Notification_Backend
{
Q_OBJECT
Q_INTERFACES(Notification_Backend)
public:
Snarl_Backend();
bool isPrimaryNotificationBackend(){return true;}
protected:
bool eventFilter(QObject *obj, QEvent *event);
private:
Snarl::SnarlInterface *snarlInterface;
public slots:
int notify(QSharedPointer<Notification>notification);
void closeNotification(int nr);
};
#endif // SNARL_BACKEND_H

View File

@ -0,0 +1,6 @@
set( SNARL_NETWORK_SRC
snarlnetwork.cpp
parser.cpp
)
automoc4_add_library(snarlnetwork MODULE ${SNARL_NETWORK_SRC} )
target_link_libraries(snarlnetwork snore ${QT_QTNETWORK_LIBRARY} )

View File

@ -0,0 +1,154 @@
#include "parser.h"
#include "core/snoreserver.h"
#include "snarlnetwork.h"
#include "core/notification.h"
#include <QDir>
#include <QCryptographicHash>
#include <QNetworkAccessManager>
#include <QEventLoop>
#include <QNetworkReply>
#include <QObject>
Parser::Parser(SnarlNetworkFrontend *snarl):snarl(snarl)
{
getSnpType.insert("type",TYPE);
getSnpType.insert("app",APP);
getSnpType.insert("version",VERSION);
getSnpType.insert("action",ACTION);
getSnpType.insert("register",REGISTER);
getSnpType.insert("add_class",ADD_CLASS);
getSnpType.insert("notification",NOTIFICATION);
getSnpType.insert("unregister",UNREGISTER);
getSnpType.insert("class",CLASS);
getSnpType.insert("title",TITLE);
getSnpType.insert("text",TEXT);
getSnpType.insert("icon",ICON);
getSnpType.insert("timeout",TIMEOUT);
}
SnarlNotification Parser::parse(QString &msg,QTcpSocket* client){
msg=msg.trimmed();
SnarlNotification sNotification;
sNotification.httpClient=false;
sNotification.vailid=true;
sNotification.notification=QSharedPointer<Notification>(new Notification());
sNotification.clientSocket=client;
snpTypes action(ERROR);
if(msg.startsWith("GET ")){
msg=msg.mid(msg.indexOf("/")+1);
msg=msg.mid(0,msg.indexOf(" "));
QByteArray dat(QByteArray::fromBase64(msg.toLatin1().data()));
msg=QString(dat);
qDebug()<<"Notification from a browser"<<msg;
sNotification.httpClient=true;
}
QString key;
QString value;
QStringList splitted=msg.split("#?");
foreach(QString s,splitted){
key=s.mid(0,s.indexOf("=")).toLower();
value=s.mid(s.indexOf("=")+1);
switch(getSnpType.value(key)){
case APP:
sNotification.notification->app=value;
break;
case ACTION:
action=getSnpType.value(value);
sNotification.action=value;
break;
case TITLE:
sNotification.notification->title=value;
break;
case TEXT:
sNotification.notification->text=value;
break;
case ICON:
sNotification.notification->setIcon(download(value));
break;
case CLASS:
sNotification.notification->alert=value;
case TIMEOUT:
sNotification.notification->timeout=value.toInt();
break;
default:
break;
}
}
switch(action){
case NOTIFICATION:
if(snarl->getSnore()->applicationListConontainsAlert(sNotification.notification->app,sNotification.notification->alert))
break;
return sNotification;
break;
case ADD_CLASS:
if(sNotification.notification->alert.isEmpty()){
qDebug()<<"Error registering alert with empty name";
break;
}
if(sNotification.notification->title.isEmpty())
sNotification.notification->title = sNotification.notification->alert;
snarl->getSnore()->addAlert(sNotification.notification->app,sNotification.notification->alert,sNotification.notification->title);
break;
case REGISTER:
qDebug()<<snarl->getSnore()->getAplicationList()->keys();
if(!snarl->getSnore()->getAplicationList()->contains(sNotification.notification->app)&&!sNotification.notification->app.isEmpty()){
snarl->getSnore()->addApplication(QSharedPointer<Application>(new Application(sNotification.notification->app)));
}
else
qDebug()<<sNotification.notification->app<<"already registred";
break;
case UNREGISTER:
snarl->getSnore()->removeApplication(sNotification.notification->app);
break;
case ERROR:
default:
sNotification.vailid=false;
break;
}
qDebug()<<sNotification.notification->toSnalrString();
sNotification.notification->hints.insert("SNaction",sNotification.action);
return sNotification;
}
QString Parser::download(const QString &address){
if(address=="")
return "";
if(address.startsWith("file://"))
return QString(address.mid(7));
QByteArray arr=address.toUtf8();
QUrl url=QUrl::fromEncoded(arr);
QCryptographicHash hash(QCryptographicHash::Md5);
hash.addData(arr);
QString filename=QDir::temp().path()+"/SnoreNotify/"+hash.result().toHex()+address.mid(address.lastIndexOf(".")-1);
QFile file(filename);
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();
file.open(QIODevice::WriteOnly);
file.write(reply->readAll());
reply->deleteLater();
return filename;
}
//#include "parser.moc"

View File

@ -0,0 +1,43 @@
#ifndef PARSER_H
#define PARSER_H
#include <QString>
#include <QHash>
#include "core/notification.h"
#include <QSharedPointer>
#include <QObject>
class Parser{
public:
Parser(class SnarlNetworkFrontend* snarl);
struct SnarlNotification parse(QString &msg,QTcpSocket* client);
private:
class SnarlNetworkFrontend *snarl;
QString download(const QString &address);
enum snpTypes{
TYPE,
APP,
VERSION,
ACTION,
REGISTER,
ADD_CLASS,
NOTIFICATION,
UNREGISTER,
CLASS,
TITLE,
TEXT,
ICON,
TIMEOUT,
ERROR
};
QHash<QString,Parser::snpTypes> getSnpType;
};
#endif // PARSER_H

View File

@ -0,0 +1,86 @@
#include "snarlnetwork.h"
#include "core/snoreserver.h"
#include <QtCore>
#include <QTcpServer>
Q_EXPORT_PLUGIN2(snalnetwork,SnarlNetworkFrontend)
SnarlNetworkFrontend::SnarlNetworkFrontend():parser(this){
setProperty("name","SnarlNetworkFrontend");
tcpServer=new QTcpServer(this);
if(!tcpServer->listen(QHostAddress::Any,port)){
qDebug()<<"The port is already used";
}
connect(tcpServer, SIGNAL(newConnection()), this, SLOT(handleConnection()));
}
void SnarlNetworkFrontend::actionInvoked(QSharedPointer<Notification>notification){
//TODO:fix callback
SnarlNotification sn=notifications.value(notification->id);
if(notification->actionInvoked==1)
callback(sn,"SNP/1.1/304/Notification acknowledged/");
else if(notification->actionInvoked==2)
callback(sn,"SNP/1.1/302/Notification cancelled/");
}
void SnarlNetworkFrontend::notificationClosed(QSharedPointer<Notification>notification){
SnarlNotification sn=notifications.value(notification->id);
if(notification->actionInvoked==Notification::TIMED_OUT)
callback(sn,"SNP/1.1/303/Notification timed out/");
else
callback(sn,"SNP/1.1/307/Notification closed/");
}
void SnarlNetworkFrontend::handleConnection(){
QTcpSocket *client = tcpServer->nextPendingConnection();
connect(client,SIGNAL(readyRead()),this,SLOT(handleMessages()));
connect(client,SIGNAL(disconnected()), this, SLOT(deleteLater()));
}
void SnarlNetworkFrontend::handleMessages(){
QString out("SNP/1.1/0/OK");
QTcpSocket *client=qobject_cast<QTcpSocket*>(sender());
QStringList incommings(QString::fromUtf8(client->readAll()).split("\r\n"));
foreach(QString s,incommings){
SnarlNotification noti=parser.parse(s,client);
notifications.insert(noti.notification->id,noti);
if(!noti.vailid)
continue;
int notificationNR=getSnore()->broadcastNotification(noti.notification);
if(notificationNR!=-1){
out+="/"+QString::number(notificationNR)+"\r\n";
}else{
out+="\r\n";
}
client->write(out.toUtf8());
if(noti.httpClient){
client->disconnectFromHost();
client->waitForDisconnected();
}
qDebug()<<out;
}
}
void SnarlNetworkFrontend::clientDisconnecd(){
QTcpSocket *client=(QTcpSocket*)sender();
client->deleteLater();
}
void SnarlNetworkFrontend::callback(const SnarlNotification &sn,QString msg){
if(sn.clientSocket!=NULL&&!msg.isEmpty()){
msg+=QString::number(sn.notification->id);
qDebug()<<msg;
sn.clientSocket->write(msg.toAscii()+"\n");
sn.clientSocket->flush();
if(sn.httpClient){
sn.clientSocket->waitForBytesWritten(-1);
sn.clientSocket->disconnectFromHost();
}
}
}
#include "snarlnetwork.moc"

View File

@ -0,0 +1,40 @@
#ifndef SNARLNETWORK_H
#define SNARLNETWORK_H
#include "core/interface.h"
#include "parser.h"
struct SnarlNotification{
class QSharedPointer<class Notification> notification;
QString action;
bool httpClient;
bool vailid;
class QPointer<class QTcpSocket> clientSocket;
};
class SnarlNetworkFrontend:public QObject,Notification_Frontend{
Q_OBJECT
Q_INTERFACES(Notification_Frontend)
friend class Parser;
public:
static const int port=9887;
public:
SnarlNetworkFrontend();
void actionInvoked(QSharedPointer<Notification>notification);
void notificationClosed(QSharedPointer<Notification>notification);
private slots:
void handleConnection();
void handleMessages();
void clientDisconnecd();
private:
class QTcpServer *tcpServer;
Parser parser;
QHash<int,SnarlNotification> notifications;
void callback(const SnarlNotification &sn,QString msg);
};
#endif //SNARLNETWORK_H

View File

@ -0,0 +1,5 @@
set( WEBPOSTER_SRC
webposter.cpp
)
automoc4_add_library(webposter MODULE ${WEBPOSTER_SRC} )
target_link_libraries(webposter snore ${QT_QTNETWORK_LIBRARY} )

View File

@ -0,0 +1,38 @@
#include "webposter.h"
#include <QDebug>
#include <QtCore>
Q_EXPORT_PLUGIN2(webposter,WebPoster)
WebPoster::WebPoster():manager(new QNetworkAccessManager(this)){
setProperty("name","WebPoster");
}
int WebPoster::notify(QSharedPointer<Notification>notification){
QByteArray byte(notification->toSnalrString().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);
connect(reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
return -1;
}
void WebPoster::closeNotification(int id){
//not supportted
}
void WebPoster::slotReadyRead(){
QNetworkReply *reply=qobject_cast<QNetworkReply*>(sender());
qDebug()<<reply->url();
qDebug()<<reply->readAll();
if(reply->errorString()!="Unknown error")
qWarning()<<reply->errorString();
reply->deleteLater();
}
#include "webposter.moc"

View File

@ -0,0 +1,25 @@
#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();
bool isPrimaryNotificationBackend(){return false;}
public slots:
int notify(QSharedPointer<Notification>notification);
void closeNotification(int id);
private:
QNetworkAccessManager *manager;
public slots:
void slotReadyRead();
};
#endif//WEBPOSTER_H

View File

@ -0,0 +1,10 @@
if(WITH_WEBINTERFACE)
message(STATUS "Enabling WebInterface support")
set( WEBINTERFACE_SRC
webinterface.cpp
)
automoc4_add_library(webinterface SHARED ${WEBINTERFACE_SRC} )
set_target_properties( webinterface PROPERTIES COMPILE_FLAGS "-DWEBINTERFACE_DLL" )
target_link_libraries(webinterface snore ${QT_QTNETWORK_LIBRARY} )
endif(WITH_WEBINTERFACE)

View File

@ -0,0 +1,70 @@
#include "webinterface.h"
#include "core/snoreserver.h"
#include <QTcpServer>
#include <QObject>
#include <QTcpSocket>
#include <QDebug>
#include <QtCore>
QPointer<WebInterface> WebInterface::instance=0;
WebInterface* WebInterface::getInstance(){
if(instance.isNull())
instance=new WebInterface();
return instance.data();
}
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();
}
#include "webinterface.moc"

View File

@ -0,0 +1,56 @@
#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_EXPORT WebInterface_Plugin:public SnorePlugin{
public:
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")
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 QPointer<WebInterface> instance;
WebInterface();
~WebInterface();
QList<WebInterface_Plugin*> webinterfaces;
QTcpServer *tcpServer;
enum ARGUMENTS{
ROOT,
SUBSCRIBE,
UNSUBSCRIBE,
OVERVIEW
};
QHash<QString,WebInterface::ARGUMENTS> getArgument;
};
#endif // WEBINTERFACE_H