cleaned up a mess and made it compile on linux, not stable yet

This commit is contained in:
Patrick von Reth 2011-08-10 11:26:44 -07:00
parent e69ef3ff82
commit 830d46a208
18 changed files with 122 additions and 211 deletions

View File

@ -4,7 +4,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules ${C
set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package(KDE4) find_package(KDE4 REQUIRED)
if(MINGW) if(MINGW)
SET (CMAKE_RC_COMPILER_INIT windres) SET (CMAKE_RC_COMPILER_INIT windres)

View File

@ -63,7 +63,7 @@ public:
public slots: public slots:
virtual void registerApplication ( class Application *application ) =0; virtual void registerApplication ( class Application *application ) =0;
virtual void unregisterApplication ( 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 closeNotification (Notification notification ) =0;
// virtual void update // virtual void update

View File

@ -17,7 +17,7 @@
#include "icon.h" #include "icon.h"
#include "../snoreserver.h" #include "../snoreserver.h"
#include <QCryptographichash> #include <QCryptographicHash>
#include <QBuffer> #include <QBuffer>
#include <QHash> #include <QHash>
#include <QFile> #include <QFile>
@ -121,10 +121,13 @@ const QString &SnoreIcon::hash() const{
return d->_hash; return d->_hash;
} }
const bool SnoreIcon::isLocalFile() const bool SnoreIcon::isLocalFile() const
{ {
return d->_isLocalFile; return d->_isLocalFile;
} }
bool SnoreIcon::isEmpty() const{
return d->_hash.isEmpty() && d->_img.isNull() && d->_localFileName.isEmpty();
}
#include "icon.moc" #include "icon.moc"

View File

@ -36,7 +36,8 @@ public:
const QString &localUrl() const; const QString &localUrl() const;
const QByteArray &imageData() const; const QByteArray &imageData() const;
const QString &hash() const; const QString &hash() const;
const bool isLocalFile() const; bool isLocalFile() const;
bool isEmpty() const;
private: private:

View File

@ -16,7 +16,7 @@
#include "notification.h" #include "notification.h"
#include "snoreserver.h" #include "snoreserver.h"
#include "notification\icon.h" #include "notification/icon.h"
#include <QDebug> #include <QDebug>
#include <QTcpSocket> #include <QTcpSocket>
@ -174,7 +174,7 @@ const QString &Notification::alert() const
return d->_alert; return d->_alert;
} }
const bool Notification::sticky() const bool Notification::sticky() const
{ {
return d->_timeout == -1; return d->_timeout == -1;
} }

View File

@ -86,7 +86,7 @@ public:
const SnoreIcon &icon() const; const SnoreIcon &icon() const;
const QString &alert() const; const QString &alert() const;
void setSticky(); void setSticky();
const bool sticky() const; bool sticky() const;
const NotificationEnums::Prioritys::prioritys &priority() const; const NotificationEnums::Prioritys::prioritys &priority() const;
const QMap<int,Action*> &actions() const; const QMap<int,Action*> &actions() const;
void addAction(Action *a); void addAction(Action *a);

View File

@ -111,7 +111,7 @@ void SnoreServer::publicatePlugin ( SnorePlugin *plugin )
} }
} }
int SnoreServer::broadcastNotification ( Notification notification ) uint SnoreServer::broadcastNotification ( Notification notification )
{ {
emit notify ( notification ); emit notify ( notification );
if ( _notificationBackend!=NULL ) if ( _notificationBackend!=NULL )

View File

@ -36,7 +36,7 @@ public:
void publicatePlugin ( SnorePlugin *plugin ); void publicatePlugin ( SnorePlugin *plugin );
int broadcastNotification ( Notification notification ); uint broadcastNotification ( Notification notification );
void closeNotification ( Notification notification, const NotificationEnums::CloseReasons::closeReasons &reason ); void closeNotification ( Notification notification, const NotificationEnums::CloseReasons::closeReasons &reason );
void notificationActionInvoked ( Notification notification ); void notificationActionInvoked ( Notification notification );

View File

@ -24,7 +24,7 @@ void TrayIconNotifer::unregisterApplication ( Application *application )
Q_UNUSED ( application ) Q_UNUSED ( application )
} }
int TrayIconNotifer::notify ( Notification notification ) uint TrayIconNotifer::notify ( Notification notification )
{ {
_notificationQue.append(notification); _notificationQue.append(notification);
if(_lastNotify.elapsed()> Notification::DefaultTimeout * 1000){ if(_lastNotify.elapsed()> Notification::DefaultTimeout * 1000){

View File

@ -17,7 +17,7 @@ public:
public slots: public slots:
void registerApplication ( Application *application ); void registerApplication ( Application *application );
void unregisterApplication ( class Application *application ); void unregisterApplication ( class Application *application );
int notify ( Notification notification ); uint notify ( Notification notification );
void closeNotification ( Notification notification ); void closeNotification ( Notification notification );
private: private:

View File

@ -4,5 +4,3 @@ add_subdirectory(freedesktopfrontend)
add_subdirectory(snarlnetwork) add_subdirectory(snarlnetwork)
add_subdirectory(snarl) add_subdirectory(snarl)
add_subdirectory(growl) add_subdirectory(growl)

View File

@ -19,67 +19,17 @@
#include <QImage> #include <QImage>
#include <QtGlobal> #include <QtGlobal>
#include <iostream>
FreedesktopNotification::FreedesktopNotification()
{ static int imageHintID = qDBusRegisterMetaType<FreedesktopImageHint>();
registerTypes();
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) FreedesktopImageHint::FreedesktopImageHint(const QImage &img)
{ {
FreedesktopNotification::registerTypes();
QImage image(img.convertToFormat(QImage::Format_ARGB32)); QImage image(img.convertToFormat(QImage::Format_ARGB32));
this->imageData.append((char*)image.rgbSwapped().bits(),image.numBytes()); this->imageData.append((char*)image.rgbSwapped().bits(),image.numBytes());
width=image.width(); width=image.width();

View File

@ -23,24 +23,6 @@
#include <QMetaType> #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 class FreedesktopImageHint
{ {
public: public:

View File

@ -2,7 +2,7 @@
#include <QtGlobal> #include <QtGlobal>
#include <QDebug> #include <QDebug>
#include "core/notification.h" #include "core/notification/notification.h"
#include <QtCore> #include <QtCore>
#include <QImage> #include <QImage>
#include "fredesktopnotification.h" #include "fredesktopnotification.h"
@ -11,9 +11,18 @@
Q_EXPORT_PLUGIN2 ( freedesktopnotificationbackend,FreedesktopNotification_Backend ) 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 ) : 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() bool FreedesktopNotification_Backend::isPrimaryNotificationBackend()
@ -31,106 +40,90 @@ void FreedesktopNotification_Backend::unregisterApplication ( Application *appli
Q_UNUSED ( application ); Q_UNUSED ( application );
} }
int FreedesktopNotification_Backend::notify ( Notification noti ) uint FreedesktopNotification_Backend::notify ( Notification noti )
{ {
fNotification *n = new fNotification ( noti ); QDBusMessage message = QDBusMessage::createMethodCall(dbusServiceName, dbusPath, dbusInterfaceName, "Notify");
qDebug()<<"Sending Notification wit Freedesktop_Backend"<<noti->title()<<noti->text(); QVariantList args;
uint out = n->send();
n->deleteLater(); args<<noti.application() ; // app_name
return out; 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 ) void FreedesktopNotification_Backend::closeNotification ( Notification notification )
{ {
//TODO: fix activeNotifications.remove(notification.id());
fNotification *fn = new fNotification ( notification); QDBusMessage message = QDBusMessage::createMethodCall(dbusServiceName, dbusPath, dbusInterfaceName,"CloseNotification");
fn->close(); QVariantList args;
args<<notification.id();
message.setArguments(args);
QDBusConnection::sessionBus().send(message);
} }
QString fNotification::vendor ( "" ); //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)
{}
uint fNotification::send()
void FreedesktopNotification_Backend::closed ( const uint &id,const uint &reason )
{ {
Q_ASSERT(!_notification.isNull()); Notification noti = activeNotifications[id];
QVariant n = QVariant::fromValue ( FreedesktopNotification( _notification )); qDebug() <<"Closed"<<id<<"|"<<reason;
QDBusMessage recive = notificationInterface.call ( "Notify", n ); NotificationEnums::CloseReasons::closeReasons r = NotificationEnums::CloseReasons::NONE;
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();
if ( reason==1 ) if ( reason==1 )
_notification->setActionInvoked ( Notification::TIMED_OUT ); r = NotificationEnums::CloseReasons::TIMED_OUT;
if ( reason==2 ) else if ( reason==2 )
_notification->setActionInvoked ( Notification::CLOSED ); r = NotificationEnums::CloseReasons::DISMISSED;
parent->snore()->closeNotification ( _notification ); snore()->closeNotification ( noti ,r);
selfDelete();
} }
//QString fNotification::getVendor()
//{
void fNotification::close() // if ( vendor == "" )
{ // {
blockSignals ( true ); // QDBusMessage recive = notificationInterface.call ( QDBus::AutoDetect,"GetServerInformation" );
if ( !selfdistruct->isActive() ) // vendor=recive.arguments() [1].toString();
{ // qDebug() <<recive.arguments();
_notification->setActionInvoked ( Notification::TIMED_OUT ); // }
parent->snore()->closeNotification ( _notification ); // return vendor;
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();
}

View File

@ -17,41 +17,15 @@ public:
public slots: public slots:
void registerApplication ( Application *application ); void registerApplication ( Application *application );
void unregisterApplication ( Application *application ); void unregisterApplication ( Application *application );
int notify ( QSharedPointer<class Notification>notification ); uint notify ( Notification notification );
void closeNotification ( Notification notification ); void closeNotification ( Notification notification );
void actionInvoked(const uint &id,const QString &actionID);
};
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 closed ( const uint &id,const uint &reason ); 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 #endif // FREEDESKTOPNOTIFICATION_H

View File

@ -1,12 +1,22 @@
if( WITH_GROWL_BACKEND ) if( WITH_GROWL_BACKEND )
if(CRYPTOPP_LIBRARIES AND Boost_SYSTEM_LIBRARY) if(CRYPTOPP_LIBRARIES AND Boost_SYSTEM_LIBRARY)
message( STATUS "Found Boost and Cryptopp, adding libgrowl backend" ) 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 set( GROWL__SRC
growl_backend.cpp growl_backend.cpp
) )
automoc4_add_library(growl_backend MODULE ${GROWL__SRC} ) 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}) install(TARGETS growl_backend ${PLUGIN_INSTALL_PATH})
else(CRYPTOPP_LIBRARIES AND Boost_SYSTEM_LIBRARY) else(CRYPTOPP_LIBRARIES AND Boost_SYSTEM_LIBRARY)

View File

@ -68,7 +68,7 @@ void Growl_Backend::unregisterApplication(Application *application){
delete growl; delete growl;
} }
int Growl_Backend::notify(Notification notification){ uint Growl_Backend::notify(Notification notification){
gntp *growl = _applications.value(notification.application()); gntp *growl = _applications.value(notification.application());
if(growl == NULL) if(growl == NULL)
return -1; return -1;

View File

@ -38,7 +38,7 @@ private:
public slots: public slots:
void registerApplication(Application *application); void registerApplication(Application *application);
void unregisterApplication(class Application *application); void unregisterApplication(class Application *application);
int notify(Notification notification); uint notify(Notification notification);
void closeNotification(Notification notification); void closeNotification(Notification notification);
}; };