From 830d46a208ec8792da1cb57438b33802bce4542f Mon Sep 17 00:00:00 2001 From: Patrick von Reth Date: Wed, 10 Aug 2011 11:26:44 -0700 Subject: [PATCH] cleaned up a mess and made it compile on linux, not stable yet --- CMakeLists.txt | 2 +- src/core/interface.h | 2 +- src/core/notification/icon.cpp | 7 +- src/core/notification/icon.h | 3 +- src/core/notification/notification.cpp | 4 +- src/core/notification/notification.h | 2 +- src/core/snoreserver.cpp | 2 +- src/core/snoreserver.h | 2 +- src/core/trayiconnotifer.cpp | 2 +- src/core/trayiconnotifer.h | 2 +- src/plugins/CMakeLists.txt | 2 - .../fredesktopnotification.cpp | 62 +------ .../fredesktopnotification.h | 18 -- .../freedesktopnotification_backend.cpp | 169 +++++++++--------- .../freedesktopnotification_backend.h | 38 +--- src/plugins/growl/CMakeLists.txt | 12 +- src/plugins/growl/growl_backend.cpp | 2 +- src/plugins/growl/growl_backend.h | 2 +- 18 files changed, 122 insertions(+), 211 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ced6b2..76d9203 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/core/interface.h b/src/core/interface.h index fc1d1f7..81d4037 100644 --- a/src/core/interface.h +++ b/src/core/interface.h @@ -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 diff --git a/src/core/notification/icon.cpp b/src/core/notification/icon.cpp index 3206005..39ca80a 100644 --- a/src/core/notification/icon.cpp +++ b/src/core/notification/icon.cpp @@ -17,7 +17,7 @@ #include "icon.h" #include "../snoreserver.h" -#include +#include #include #include #include @@ -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" diff --git a/src/core/notification/icon.h b/src/core/notification/icon.h index d3a0255..d815073 100644 --- a/src/core/notification/icon.h +++ b/src/core/notification/icon.h @@ -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: diff --git a/src/core/notification/notification.cpp b/src/core/notification/notification.cpp index 8be9e81..0ade431 100644 --- a/src/core/notification/notification.cpp +++ b/src/core/notification/notification.cpp @@ -16,7 +16,7 @@ #include "notification.h" #include "snoreserver.h" -#include "notification\icon.h" +#include "notification/icon.h" #include #include @@ -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; } diff --git a/src/core/notification/notification.h b/src/core/notification/notification.h index ebbf7c4..bf84ede 100644 --- a/src/core/notification/notification.h +++ b/src/core/notification/notification.h @@ -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 &actions() const; void addAction(Action *a); diff --git a/src/core/snoreserver.cpp b/src/core/snoreserver.cpp index d944612..1e6bdc4 100644 --- a/src/core/snoreserver.cpp +++ b/src/core/snoreserver.cpp @@ -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 ) diff --git a/src/core/snoreserver.h b/src/core/snoreserver.h index 431e9dc..f5a7d57 100644 --- a/src/core/snoreserver.h +++ b/src/core/snoreserver.h @@ -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 ); diff --git a/src/core/trayiconnotifer.cpp b/src/core/trayiconnotifer.cpp index 758e1aa..12a6e51 100644 --- a/src/core/trayiconnotifer.cpp +++ b/src/core/trayiconnotifer.cpp @@ -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){ diff --git a/src/core/trayiconnotifer.h b/src/core/trayiconnotifer.h index 6148216..f4b4ede 100644 --- a/src/core/trayiconnotifer.h +++ b/src/core/trayiconnotifer.h @@ -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: diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index 9bcfaea..089750c 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -4,5 +4,3 @@ add_subdirectory(freedesktopfrontend) add_subdirectory(snarlnetwork) add_subdirectory(snarl) add_subdirectory(growl) - - diff --git a/src/plugins/freedesktopnotification/fredesktopnotification.cpp b/src/plugins/freedesktopnotification/fredesktopnotification.cpp index 8ab267e..8852992 100644 --- a/src/plugins/freedesktopnotification/fredesktopnotification.cpp +++ b/src/plugins/freedesktopnotification/fredesktopnotification.cpp @@ -19,67 +19,17 @@ #include #include -#include -FreedesktopNotification::FreedesktopNotification() -{ - registerTypes(); + +static int imageHintID = qDBusRegisterMetaType(); + + +FreedesktopImageHint::FreedesktopImageHint(){ + } -FreedesktopNotification::FreedesktopNotification(Notification noti): - notification(noti) -{ - registerTypes(); -} - -void FreedesktopNotification::registerTypes() { - qDBusRegisterMetaType(); - qDBusRegisterMetaType(); -} - -QDBusArgument &operator<<(QDBusArgument &a, const FreedesktopNotification &i) { - // Q_ASSERT(!i.notification.isNull()); - qDebug()<>(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(); diff --git a/src/plugins/freedesktopnotification/fredesktopnotification.h b/src/plugins/freedesktopnotification/fredesktopnotification.h index 59e2134..36fe71e 100644 --- a/src/plugins/freedesktopnotification/fredesktopnotification.h +++ b/src/plugins/freedesktopnotification/fredesktopnotification.h @@ -23,24 +23,6 @@ #include -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: diff --git a/src/plugins/freedesktopnotification/freedesktopnotification_backend.cpp b/src/plugins/freedesktopnotification/freedesktopnotification_backend.cpp index 06c8741..2c8e41a 100644 --- a/src/plugins/freedesktopnotification/freedesktopnotification_backend.cpp +++ b/src/plugins/freedesktopnotification/freedesktopnotification_backend.cpp @@ -2,7 +2,7 @@ #include #include -#include "core/notification.h" +#include "core/notification/notification.h" #include #include #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"<title()<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<name; + } + args<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): - 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() <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() ) return; - close(); + Notification noti = activeNotifications[id]; + qDebug() <<"Closed"<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() <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 diff --git a/src/plugins/growl/CMakeLists.txt b/src/plugins/growl/CMakeLists.txt index 2052b74..cda3875 100644 --- a/src/plugins/growl/CMakeLists.txt +++ b/src/plugins/growl/CMakeLists.txt @@ -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) diff --git a/src/plugins/growl/growl_backend.cpp b/src/plugins/growl/growl_backend.cpp index c58b99c..f8ea663 100644 --- a/src/plugins/growl/growl_backend.cpp +++ b/src/plugins/growl/growl_backend.cpp @@ -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; diff --git a/src/plugins/growl/growl_backend.h b/src/plugins/growl/growl_backend.h index 0680009..ade9088 100644 --- a/src/plugins/growl/growl_backend.h +++ b/src/plugins/growl/growl_backend.h @@ -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); };