mirror of
https://github.com/status-im/snorenotify.git
synced 2025-02-25 22:45:23 +00:00
cleaned up a mess and made it compile on linux, not stable yet
This commit is contained in:
parent
e69ef3ff82
commit
830d46a208
@ -4,7 +4,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules ${C
|
||||
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
|
||||
find_package(KDE4)
|
||||
find_package(KDE4 REQUIRED)
|
||||
|
||||
if(MINGW)
|
||||
SET (CMAKE_RC_COMPILER_INIT windres)
|
||||
|
@ -63,7 +63,7 @@ public:
|
||||
public slots:
|
||||
virtual void registerApplication ( class Application *application ) =0;
|
||||
virtual void unregisterApplication ( class Application *application ) =0;
|
||||
virtual int notify ( Notification notification ) =0;
|
||||
virtual uint notify ( Notification notification ) =0;
|
||||
virtual void closeNotification (Notification notification ) =0;
|
||||
|
||||
// virtual void update
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include "icon.h"
|
||||
#include "../snoreserver.h"
|
||||
|
||||
#include <QCryptographichash>
|
||||
#include <QCryptographicHash>
|
||||
#include <QBuffer>
|
||||
#include <QHash>
|
||||
#include <QFile>
|
||||
@ -121,10 +121,13 @@ const QString &SnoreIcon::hash() const{
|
||||
return d->_hash;
|
||||
}
|
||||
|
||||
const bool SnoreIcon::isLocalFile() const
|
||||
bool SnoreIcon::isLocalFile() const
|
||||
{
|
||||
return d->_isLocalFile;
|
||||
}
|
||||
|
||||
bool SnoreIcon::isEmpty() const{
|
||||
return d->_hash.isEmpty() && d->_img.isNull() && d->_localFileName.isEmpty();
|
||||
}
|
||||
|
||||
#include "icon.moc"
|
||||
|
@ -36,7 +36,8 @@ public:
|
||||
const QString &localUrl() const;
|
||||
const QByteArray &imageData() const;
|
||||
const QString &hash() const;
|
||||
const bool isLocalFile() const;
|
||||
bool isLocalFile() const;
|
||||
bool isEmpty() const;
|
||||
|
||||
|
||||
private:
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
#include "notification.h"
|
||||
#include "snoreserver.h"
|
||||
#include "notification\icon.h"
|
||||
#include "notification/icon.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QTcpSocket>
|
||||
@ -174,7 +174,7 @@ const QString &Notification::alert() const
|
||||
return d->_alert;
|
||||
}
|
||||
|
||||
const bool Notification::sticky() const
|
||||
bool Notification::sticky() const
|
||||
{
|
||||
return d->_timeout == -1;
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ public:
|
||||
const SnoreIcon &icon() const;
|
||||
const QString &alert() const;
|
||||
void setSticky();
|
||||
const bool sticky() const;
|
||||
bool sticky() const;
|
||||
const NotificationEnums::Prioritys::prioritys &priority() const;
|
||||
const QMap<int,Action*> &actions() const;
|
||||
void addAction(Action *a);
|
||||
|
@ -111,7 +111,7 @@ void SnoreServer::publicatePlugin ( SnorePlugin *plugin )
|
||||
}
|
||||
}
|
||||
|
||||
int SnoreServer::broadcastNotification ( Notification notification )
|
||||
uint SnoreServer::broadcastNotification ( Notification notification )
|
||||
{
|
||||
emit notify ( notification );
|
||||
if ( _notificationBackend!=NULL )
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
void publicatePlugin ( SnorePlugin *plugin );
|
||||
|
||||
|
||||
int broadcastNotification ( Notification notification );
|
||||
uint broadcastNotification ( Notification notification );
|
||||
void closeNotification ( Notification notification, const NotificationEnums::CloseReasons::closeReasons &reason );
|
||||
void notificationActionInvoked ( Notification notification );
|
||||
|
||||
|
@ -24,7 +24,7 @@ void TrayIconNotifer::unregisterApplication ( Application *application )
|
||||
Q_UNUSED ( application )
|
||||
}
|
||||
|
||||
int TrayIconNotifer::notify ( Notification notification )
|
||||
uint TrayIconNotifer::notify ( Notification notification )
|
||||
{
|
||||
_notificationQue.append(notification);
|
||||
if(_lastNotify.elapsed()> Notification::DefaultTimeout * 1000){
|
||||
|
@ -17,7 +17,7 @@ public:
|
||||
public slots:
|
||||
void registerApplication ( Application *application );
|
||||
void unregisterApplication ( class Application *application );
|
||||
int notify ( Notification notification );
|
||||
uint notify ( Notification notification );
|
||||
void closeNotification ( Notification notification );
|
||||
|
||||
private:
|
||||
|
@ -4,5 +4,3 @@ add_subdirectory(freedesktopfrontend)
|
||||
add_subdirectory(snarlnetwork)
|
||||
add_subdirectory(snarl)
|
||||
add_subdirectory(growl)
|
||||
|
||||
|
||||
|
@ -19,67 +19,17 @@
|
||||
#include <QImage>
|
||||
#include <QtGlobal>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
FreedesktopNotification::FreedesktopNotification()
|
||||
{
|
||||
registerTypes();
|
||||
|
||||
static int imageHintID = qDBusRegisterMetaType<FreedesktopImageHint>();
|
||||
|
||||
|
||||
FreedesktopImageHint::FreedesktopImageHint(){
|
||||
|
||||
}
|
||||
|
||||
FreedesktopNotification::FreedesktopNotification(Notification noti):
|
||||
notification(noti)
|
||||
{
|
||||
registerTypes();
|
||||
}
|
||||
|
||||
void FreedesktopNotification::registerTypes() {
|
||||
qDBusRegisterMetaType<FreedesktopImageHint>();
|
||||
qDBusRegisterMetaType<FreedesktopNotification>();
|
||||
}
|
||||
|
||||
QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopNotification &i) {
|
||||
// Q_ASSERT(!i.notification.isNull());
|
||||
qDebug()<<i.notification.toString();
|
||||
a<<i.notification.application();
|
||||
a<<uint(0);
|
||||
a<<i.notification.icon().image();
|
||||
a<<i.notification.title();
|
||||
a<<i.notification.text();
|
||||
QStringList actions;
|
||||
actions<<"1"<<" "<<"2"<<" ";
|
||||
a<<actions;
|
||||
a.beginMap();
|
||||
QImage img(i.notification.icon().image());
|
||||
if (!img.isNull()) {
|
||||
img=img.scaledToWidth(50,Qt::FastTransformation);
|
||||
a.beginMapEntry();
|
||||
a<<"image_data";
|
||||
FreedesktopImageHint fh(img);
|
||||
a<<fh;
|
||||
a.endMapEntry();
|
||||
}
|
||||
a.endMap();
|
||||
a<<i.notification.timeout()*1000;
|
||||
return a;
|
||||
}
|
||||
|
||||
const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopNotification &) {
|
||||
//not supported
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
FreedesktopImageHint::FreedesktopImageHint()
|
||||
{
|
||||
FreedesktopNotification::registerTypes();
|
||||
}
|
||||
|
||||
|
||||
FreedesktopImageHint::FreedesktopImageHint(const QImage &img)
|
||||
{
|
||||
FreedesktopNotification::registerTypes();
|
||||
QImage image(img.convertToFormat(QImage::Format_ARGB32));
|
||||
this->imageData.append((char*)image.rgbSwapped().bits(),image.numBytes());
|
||||
width=image.width();
|
||||
|
@ -23,24 +23,6 @@
|
||||
#include <QMetaType>
|
||||
|
||||
|
||||
class FreedesktopImageHint;
|
||||
|
||||
class FreedesktopNotification{
|
||||
public:
|
||||
static void registerTypes();
|
||||
|
||||
public:
|
||||
FreedesktopNotification();
|
||||
FreedesktopNotification(Notification noti);
|
||||
|
||||
Notification notification;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(FreedesktopNotification);
|
||||
|
||||
QDBusArgument &operator<<(QDBusArgument &a,const FreedesktopNotification &i);
|
||||
const QDBusArgument & operator >>(const QDBusArgument &a, FreedesktopNotification &i) ;
|
||||
|
||||
class FreedesktopImageHint
|
||||
{
|
||||
public:
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QDebug>
|
||||
#include "core/notification.h"
|
||||
#include "core/notification/notification.h"
|
||||
#include <QtCore>
|
||||
#include <QImage>
|
||||
#include "fredesktopnotification.h"
|
||||
@ -11,9 +11,18 @@
|
||||
|
||||
Q_EXPORT_PLUGIN2 ( freedesktopnotificationbackend,FreedesktopNotification_Backend )
|
||||
|
||||
static const char dbusServiceName[] = "org.freedesktop.Notifications";
|
||||
static const char dbusInterfaceName[] = "org.freedesktop.Notifications";
|
||||
static const char dbusPath[] = "/org/freedesktop/Notifications";
|
||||
|
||||
|
||||
FreedesktopNotification_Backend::FreedesktopNotification_Backend ( SnoreServer *snore ) :
|
||||
Notification_Backend ( "FreedesktopNotification_Backend",snore )
|
||||
Notification_Backend ( "FreedesktopNotification_Backend",snore )
|
||||
{
|
||||
QDBusConnection::sessionBus().connect ( "org.freedesktop.Notifications","/org/freedesktop/Notifications","org.freedesktop.Notifications","ActionInvoked",this,SLOT ( actionInvoked( uint,QString ) ) );
|
||||
// if ( getVendor() =="GNOME" )
|
||||
QDBusConnection::sessionBus().connect ( "org.freedesktop.Notifications","/org/freedesktop/Notifications","org.freedesktop.Notifications","NotificationClosed",this,SLOT ( closed ( uint,uint ) ) );
|
||||
|
||||
}
|
||||
|
||||
bool FreedesktopNotification_Backend::isPrimaryNotificationBackend()
|
||||
@ -31,106 +40,90 @@ void FreedesktopNotification_Backend::unregisterApplication ( Application *appli
|
||||
Q_UNUSED ( application );
|
||||
}
|
||||
|
||||
int FreedesktopNotification_Backend::notify ( Notification noti )
|
||||
{
|
||||
fNotification *n = new fNotification ( noti );
|
||||
qDebug()<<"Sending Notification wit Freedesktop_Backend"<<noti->title()<<noti->text();
|
||||
uint out = n->send();
|
||||
n->deleteLater();
|
||||
return out;
|
||||
uint FreedesktopNotification_Backend::notify ( Notification noti )
|
||||
{
|
||||
QDBusMessage message = QDBusMessage::createMethodCall(dbusServiceName, dbusPath, dbusInterfaceName, "Notify");
|
||||
QVariantList args;
|
||||
|
||||
args<<noti.application() ; // app_name
|
||||
args<<noti.id() ; // replaces_id
|
||||
args<<"" ; // app_icon
|
||||
args<<noti.title() ; // summary
|
||||
args<<noti.text() ; // body
|
||||
|
||||
QStringList actions;
|
||||
foreach(int k,noti.actions().keys()){
|
||||
actions<<QString::number(k)<<noti.actions()[k]->name;
|
||||
}
|
||||
args<<actions;
|
||||
|
||||
if(!noti.icon().isEmpty()){
|
||||
QVariantMap image_data;
|
||||
QVariant img = QVariant::fromValue(FreedesktopImageHint(noti.icon().image().scaledToWidth(50,Qt::FastTransformation)));
|
||||
image_data.insert(QString("image_data"),img);
|
||||
args<<image_data;
|
||||
}
|
||||
|
||||
args<<noti.timeout()*1000;
|
||||
|
||||
message.setArguments(args);
|
||||
|
||||
QDBusMessage replyMsg = QDBusConnection::sessionBus().call(message);
|
||||
uint id = replyMsg.arguments().last().toInt();
|
||||
activeNotifications[id] = noti;
|
||||
startTimeout(id,noti.timeout());
|
||||
return id;
|
||||
}
|
||||
void FreedesktopNotification_Backend::actionInvoked(const uint &id, const QString &actionID){
|
||||
Notification noti = activeNotifications[id];
|
||||
qDebug() <<"Action"<<id<<"|"<<actionID ;
|
||||
noti.setActionInvoked ( actionID == "default"?1:actionID.toInt() );
|
||||
snore()->notificationActionInvoked ( noti );
|
||||
snore()->closeNotification(noti,NotificationEnums::CloseReasons::CLOSED);
|
||||
|
||||
}
|
||||
|
||||
void FreedesktopNotification_Backend::closeNotification ( Notification notification )
|
||||
{
|
||||
//TODO: fix
|
||||
fNotification *fn = new fNotification ( notification);
|
||||
fn->close();
|
||||
activeNotifications.remove(notification.id());
|
||||
QDBusMessage message = QDBusMessage::createMethodCall(dbusServiceName, dbusPath, dbusInterfaceName,"CloseNotification");
|
||||
QVariantList args;
|
||||
args<<notification.id();
|
||||
message.setArguments(args);
|
||||
QDBusConnection::sessionBus().send(message);
|
||||
}
|
||||
|
||||
|
||||
QString fNotification::vendor ( "" );
|
||||
|
||||
QDBusInterface fNotification::notificationInterface ( "org.freedesktop.Notifications","/org/freedesktop/Notifications","org.freedesktop.Notifications" );
|
||||
|
||||
fNotification::fNotification(QSharedPointer< Notification > notification):
|
||||
QObject(notification.data()),
|
||||
_notification(notification)
|
||||
{}
|
||||
//QString fNotification::vendor ( "" );
|
||||
|
||||
|
||||
|
||||
uint fNotification::send()
|
||||
|
||||
void FreedesktopNotification_Backend::closed ( const uint &id,const uint &reason )
|
||||
{
|
||||
Q_ASSERT(!_notification.isNull());
|
||||
QVariant n = QVariant::fromValue ( FreedesktopNotification( _notification ));
|
||||
QDBusMessage recive = notificationInterface.call ( "Notify", n );
|
||||
uint id=recive.arguments().last().toInt();
|
||||
selfdistruct = new QTimer(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 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->setActionInvoked ( action_key=="default"?Notification::ACTION_1:Notification::actions ( action_key.toInt() ) );
|
||||
parent->snore()->notificationActionInvoked ( _notification );
|
||||
selfDelete();
|
||||
}
|
||||
|
||||
void fNotification::closed ( const uint &id,const uint &reason )
|
||||
{
|
||||
qDebug() <<id<<"|"<<reason;;
|
||||
if ( id!=_notification->id() ) return;
|
||||
close();
|
||||
Notification noti = activeNotifications[id];
|
||||
qDebug() <<"Closed"<<id<<"|"<<reason;
|
||||
NotificationEnums::CloseReasons::closeReasons r = NotificationEnums::CloseReasons::NONE;
|
||||
if ( reason==1 )
|
||||
_notification->setActionInvoked ( Notification::TIMED_OUT );
|
||||
if ( reason==2 )
|
||||
_notification->setActionInvoked ( Notification::CLOSED );
|
||||
parent->snore()->closeNotification ( _notification );
|
||||
selfDelete();
|
||||
r = NotificationEnums::CloseReasons::TIMED_OUT;
|
||||
else if ( reason==2 )
|
||||
r = NotificationEnums::CloseReasons::DISMISSED;
|
||||
snore()->closeNotification ( noti ,r);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void fNotification::close()
|
||||
{
|
||||
blockSignals ( true );
|
||||
if ( !selfdistruct->isActive() )
|
||||
{
|
||||
_notification->setActionInvoked ( Notification::TIMED_OUT );
|
||||
parent->snore()->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();
|
||||
}
|
||||
//QString fNotification::getVendor()
|
||||
//{
|
||||
// if ( vendor == "" )
|
||||
// {
|
||||
// QDBusMessage recive = notificationInterface.call ( QDBus::AutoDetect,"GetServerInformation" );
|
||||
// vendor=recive.arguments() [1].toString();
|
||||
// qDebug() <<recive.arguments();
|
||||
// }
|
||||
// return vendor;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -17,41 +17,15 @@ public:
|
||||
public slots:
|
||||
void registerApplication ( Application *application );
|
||||
void unregisterApplication ( Application *application );
|
||||
int notify ( QSharedPointer<class Notification>notification );
|
||||
uint notify ( Notification notification );
|
||||
void closeNotification ( Notification notification );
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
class fNotification:public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class FreedesktopNotification_Backend;
|
||||
public:
|
||||
static QDBusInterface notificationInterface;
|
||||
private:
|
||||
static QString vendor;
|
||||
|
||||
public:
|
||||
fNotification ( Notification notification);
|
||||
uint send();
|
||||
Notification notification();
|
||||
|
||||
|
||||
private:
|
||||
Notification_Backend* parent;
|
||||
QString getVendor();
|
||||
QTimer *selfdistruct;
|
||||
Notification _notification;
|
||||
|
||||
private slots:
|
||||
void action ( const uint &id, const QString &action_key );
|
||||
void actionInvoked(const uint &id,const QString &actionID);
|
||||
void closed ( const uint &id,const uint &reason );
|
||||
void close();
|
||||
void selfDelete();
|
||||
|
||||
};
|
||||
QDBusArgument &operator<<(QDBusArgument &a,const Notification &i);
|
||||
const QDBusArgument & operator >>(const QDBusArgument &a, Notification &i) ;
|
||||
|
||||
|
||||
|
||||
#endif // FREEDESKTOPNOTIFICATION_H
|
||||
|
@ -1,12 +1,22 @@
|
||||
if( WITH_GROWL_BACKEND )
|
||||
if(CRYPTOPP_LIBRARIES AND Boost_SYSTEM_LIBRARY)
|
||||
message( STATUS "Found Boost and Cryptopp, adding libgrowl backend" )
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
|
||||
endif(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set( GROWL__SRC
|
||||
growl_backend.cpp
|
||||
)
|
||||
|
||||
automoc4_add_library(growl_backend MODULE ${GROWL__SRC} )
|
||||
target_link_libraries(growl_backend snorecore ${QT_QTCORE_LIBRARY} ${CRYPTOPP_LIBRARIES} ${Boost_SYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY} wsock32 ws2_32)
|
||||
target_link_libraries(growl_backend snorecore ${QT_QTCORE_LIBRARY} ${CRYPTOPP_LIBRARIES} ${Boost_SYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY})
|
||||
if(WIN32)
|
||||
target_link_libraries(growl_backend wsock32 ws2_32)
|
||||
endif(WIN32)
|
||||
|
||||
if(UNIX)
|
||||
target_link_libraries(growl_backend pthread)
|
||||
endif(UNIX)
|
||||
|
||||
install(TARGETS growl_backend ${PLUGIN_INSTALL_PATH})
|
||||
else(CRYPTOPP_LIBRARIES AND Boost_SYSTEM_LIBRARY)
|
||||
|
@ -68,7 +68,7 @@ void Growl_Backend::unregisterApplication(Application *application){
|
||||
delete growl;
|
||||
}
|
||||
|
||||
int Growl_Backend::notify(Notification notification){
|
||||
uint Growl_Backend::notify(Notification notification){
|
||||
gntp *growl = _applications.value(notification.application());
|
||||
if(growl == NULL)
|
||||
return -1;
|
||||
|
@ -38,7 +38,7 @@ private:
|
||||
public slots:
|
||||
void registerApplication(Application *application);
|
||||
void unregisterApplication(class Application *application);
|
||||
int notify(Notification notification);
|
||||
uint notify(Notification notification);
|
||||
void closeNotification(Notification notification);
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user