use kicon to get the application icon woho(looks cool),require kde for kicon :P, added priority support to freedesktop notifications...

This commit is contained in:
Patrick von Reth 2011-07-23 13:14:37 +02:00
parent a7aff40dc2
commit c914445e0e
11 changed files with 195 additions and 159 deletions

View File

@ -4,43 +4,19 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules ${C
set(CMAKE_INCLUDE_CURRENT_DIR ON)
find_package( Qt4 REQUIRED )
find_package( Automoc4 REQUIRED)
find_package(KDE4)
if(KDE4_FOUND)
add_definitions(-DHAVE_KDE ${KDE4_DEFINITIONS} -D_UNICODE)
include_directories(${KDE4_INCLUDES})
else(KDE4_FOUND)
include(NoKDE)
endif(KDE4_FOUND)
find_package( CryptoPP )
find_package( Boost COMPONENTS system )
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})
if (CMAKE_COMPILER_IS_GNUCXX)
set (KDE4_ENABLE_EXCEPTIONS -fexceptions)
# Select flags.
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG -DQT_NO_DEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O2 -fno-reorder-blocks -fno-schedule-insns -fno-inline")
set(CMAKE_CXX_FLAGS_DEBUGFULL "-g3 -fno-inline")
set(CMAKE_CXX_FLAGS_PROFILE "-g3 -fno-inline -ftest-coverage -fprofile-arcs")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG -DQT_NO_DEBUG")
set(CMAKE_C_FLAGS_DEBUG "-g -O2 -fno-reorder-blocks -fno-schedule-insns -fno-inline")
set(CMAKE_C_FLAGS_DEBUGFULL "-g3 -fno-inline")
set(CMAKE_C_FLAGS_PROFILE "-g3 -fno-inline -ftest-coverage -fprofile-arcs")
if (CMAKE_SYSTEM_NAME MATCHES Linux)
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-long-long -std=iso9899:1990 -Wundef -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security -Wmissing-format-attribute -fno-common")
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Wno-long-long -ansi -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wpointer-arith -Wformat-security -fno-exceptions -fno-check-new -fno-common")
add_definitions (-D_BSD_SOURCE)
endif (CMAKE_SYSTEM_NAME MATCHES Linux)
endif(CMAKE_COMPILER_IS_GNUCXX)
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:wchar_t-")
endif(MSVC)
option(WITH_FREEDESKTOP_FRONTEND "Build the freedesktop frontend" OFF)
option(WITH_GROWL_BACKEND "Build the Growl backend" ON)

33
cmake/modules/NoKDE.cmake Normal file
View File

@ -0,0 +1,33 @@
find_package( Qt4 REQUIRED )
find_package( Automoc4 REQUIRED)
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})
include( ${QT_USE_FILE} )
if (CMAKE_COMPILER_IS_GNUCXX)
set (KDE4_ENABLE_EXCEPTIONS -fexceptions)
# Select flags.
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG -DQT_NO_DEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O2 -fno-reorder-blocks -fno-schedule-insns -fno-inline")
set(CMAKE_CXX_FLAGS_DEBUGFULL "-g3 -fno-inline")
set(CMAKE_CXX_FLAGS_PROFILE "-g3 -fno-inline -ftest-coverage -fprofile-arcs")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG -DQT_NO_DEBUG")
set(CMAKE_C_FLAGS_DEBUG "-g -O2 -fno-reorder-blocks -fno-schedule-insns -fno-inline")
set(CMAKE_C_FLAGS_DEBUGFULL "-g3 -fno-inline")
set(CMAKE_C_FLAGS_PROFILE "-g3 -fno-inline -ftest-coverage -fprofile-arcs")
if (CMAKE_SYSTEM_NAME MATCHES Linux)
set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-long-long -std=iso9899:1990 -Wundef -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security -Wmissing-format-attribute -fno-common")
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Wno-long-long -ansi -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wpointer-arith -Wformat-security -fno-exceptions -fno-check-new -fno-common")
add_definitions (-D_BSD_SOURCE)
endif (CMAKE_SYSTEM_NAME MATCHES Linux)
endif(CMAKE_COMPILER_IS_GNUCXX)

View File

@ -67,7 +67,7 @@ void Application::setInitialized ( bool b )
_initialized = b;
}
Alert::Alert (const QString &name, const QString &title, const QString &icon, bool active) :
Alert::Alert (const QString &name, const QString &title, const SnoreIcon &icon, bool active) :
_name ( name ),
_title ( title ),
_icon(icon),
@ -89,7 +89,7 @@ const QString &Alert::title() const
return _title;
}
const QString &Alert::icon() const
const SnoreIcon &Alert::icon() const
{
return _icon;
}

View File

@ -28,7 +28,7 @@ class SNORE_EXPORT Application:public QObject
{
Q_OBJECT
public:
Application ( const QString &name, const SnoreIcon &icon = SnoreIcon(QImage(":/root/zzz.png")));
Application ( const QString &name, const SnoreIcon &icon = SnoreIcon(":/root/zzz.png"));
Application();
~Application();
void addAlert ( Alert *alert );
@ -51,17 +51,17 @@ class SNORE_EXPORT Alert:public QObject
{
Q_OBJECT
public:
Alert ( const QString &name,const QString &title="",const QString &icon="",bool active=true );
Alert ( const QString &name,const QString &title="",const SnoreIcon &icon = SnoreIcon(":/root/zzz.png"),bool active=true );
Alert();
const QString &name() const;
const QString &title() const;
const QString &icon() const;
const SnoreIcon &icon() const;
bool isActive() const;
private:
QString _name;
QString _title;
QString _icon;
SnoreIcon _icon;
bool _active;
};

View File

@ -42,10 +42,13 @@ public:
if(QFile(url).exists()){
_isLocalFile = true;
_localFileName = url;
}
}else if(url.startsWith(":/")){
_img = QImage(url);
_isLocalFile = false;
}
}
~SnoreIconData()
{ }
{/*nothing to do*/ }
QImage _img;

View File

@ -26,11 +26,13 @@
namespace NotificationEnums{
namespace Prioritys{
enum prioritys{
enum priority{
LOW=-1,
NORMAL,
HIGH
};
Q_DECLARE_FLAGS(prioritys, priority)
Q_DECLARE_OPERATORS_FOR_FLAGS(prioritys)
}
namespace CloseReasons{
enum closeReason

View File

@ -11,6 +11,9 @@ if(QT_QTDBUS_FOUND AND WITH_FREEDESKTOP_FRONTEND)
automoc4_add_library(freedesktop_frontend MODULE ${FREEDESKTOP_NOTIFICATION_FRONTEND_SRC} )
target_link_libraries(freedesktop_frontend snorecore ${QT_QTDBUS_LIBRARY} ${QT_QTGUI_LIBRARY} )
if(KDE4_FOUND)
target_link_libraries(freedesktop_frontend ${KDE4_KDEUI_LIBRARY})
endif(KDE4_FOUND)
install(TARGETS freedesktop_frontend ${PLUGIN_INSTALL_PATH})
endif(QT_QTDBUS_FOUND AND WITH_FREEDESKTOP_FRONTEND)

View File

@ -1,111 +1,131 @@
/****************************************************************************************
* Copyright (c) 2010 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#include "freedesktopnotificationfrontend.h"
#include "notificationsadaptor.h"
#include "plugins/freedesktopnotification/fredesktopnotification.h"
#include "core/snoreserver.h"
#include <QtCore>
#include <QtDBus>
#include <QImage>
Q_EXPORT_PLUGIN2(freedesktop_frontend,FreedesktopNotification_Frontend)
FreedesktopNotification_Frontend::FreedesktopNotification_Frontend(SnoreServer *snore):
Notification_Frontend("FreedesktopNotification_Frontend",snore)
{
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(Notification notification) {
emit ActionInvoked(notification.id(),QString::number(notification.actionInvoked()->id));
}
void FreedesktopNotification_Frontend::notificationClosed(Notification notification) {
qDebug()<<"Closing Dbus notification"<<notification.id()<<"reason:"<<(int)notification.closeReason();
activeNotifications.take(notification.id());
emit NotificationClosed(notification.id(),notification.closeReason());
}
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;
SnoreIcon icon;
if(hints.contains("image_data")){
FreedesktopImageHint image;
hints["image_data"].value<QDBusArgument>()>>image;
icon = SnoreIcon(image.toQImage());
}
if(!snore()->aplications().contains(app_name)){
Application *a = new Application(app_name,SnoreIcon(QImage(":/root/images/freedesktop-dbus.png")));
a->addAlert(new Alert("DBus Alert","DBus Alert",app_icon));
snore()->addApplication(a);
snore()->applicationIsInitialized(a);
}
Notification noti(this,app_name,"DBus Alert",summary,body,icon,timeout==-1?Notification::DefaultTimeout:timeout/1000,replaces_id);
qDebug()<<"Actions"<<actions;
for(int i = 0;i < actions.length(); i+=2){
noti.addAction(new Notification::Action(actions.at(i).toInt(),actions.at(i+1)));
}
snore()->broadcastNotification(noti);
activeNotifications[noti.id()] = noti;
return noti.id();
}
void FreedesktopNotification_Frontend::CloseNotification(uint id){
Notification noti = activeNotifications.take(id);
snore()->closeNotification(noti,NotificationEnums::CloseReasons::TIMED_OUT);
}
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 = "Snore";
version = snore()->version();
specVersion = "0";
return "Snore";
}
#include "freedesktopnotificationfrontend.moc"
/****************************************************************************************
* Copyright (c) 2010 Patrick von Reth <patrick.vonreth@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify it under *
* the terms of the GNU General Public License as published by the Free Software *
* Foundation; either version 2 of the License, or (at your option) any later *
* version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT ANY *
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
* PARTICULAR PURPOSE. See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License along with *
* this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************************/
#include "freedesktopnotificationfrontend.h"
#include "notificationsadaptor.h"
#include "plugins/freedesktopnotification/fredesktopnotification.h"
#include "core/snoreserver.h"
#include <QtCore>
#include <QtDBus>
#include <QImage>
#ifdef HAVE_KDE
#include <KIcon>
#endif
Q_EXPORT_PLUGIN2(freedesktop_frontend,FreedesktopNotification_Frontend)
FreedesktopNotification_Frontend::FreedesktopNotification_Frontend(SnoreServer *snore):
Notification_Frontend("FreedesktopNotification_Frontend",snore)
{
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(Notification notification) {
emit ActionInvoked(notification.id(),QString::number(notification.actionInvoked()->id));
}
void FreedesktopNotification_Frontend::notificationClosed(Notification notification) {
qDebug()<<"Closing Dbus notification"<<notification.id()<<"reason:"<<(int)notification.closeReason();
activeNotifications.take(notification.id());
emit NotificationClosed(notification.id(),notification.closeReason());
}
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;
SnoreIcon icon;
NotificationEnums::Prioritys::prioritys priotity = NotificationEnums::Prioritys::NORMAL;
if(hints.contains("image_data")){
FreedesktopImageHint image;
hints["image_data"].value<QDBusArgument>()>>image;
icon = SnoreIcon(image.toQImage());
}
if(!snore()->aplications().contains(app_name)){
SnoreIcon appIcon;
#ifdef HAVE_KDE
KIcon kicon(app_icon);
appIcon = SnoreIcon(kicon.pixmap(100,100).toImage());
#else
appIcon = SnoreIcon(":/root/images/freedesktop-dbus.png");
#endif
Application *a = new Application(app_name,SnoreIcon(appIcon));
a->addAlert(new Alert("DBus Alert","DBus Alert",SnoreIcon(":/root/images/freedesktop-dbus.png")));
snore()->addApplication(a);
snore()->applicationIsInitialized(a);
}
if (hints.contains("urgency")) {
priotity = NotificationEnums::Prioritys::prioritys(hints["urgency"].toInt()-1);
}
Notification noti(this,app_name,"DBus Alert",summary,body,icon,timeout==-1?Notification::DefaultTimeout:timeout/1000,replaces_id,priotity);
qDebug()<<"Actions"<<actions;
for(int i = 0;i < actions.length(); i+=2){
noti.addAction(new Notification::Action(actions.at(i).toInt(),actions.at(i+1)));
}
snore()->broadcastNotification(noti);
activeNotifications[noti.id()] = noti;
return noti.id();
}
void FreedesktopNotification_Frontend::CloseNotification(uint id){
Notification noti = activeNotifications.take(id);
snore()->closeNotification(noti,NotificationEnums::CloseReasons::TIMED_OUT);
}
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 = "Snore";
version = snore()->version();
specVersion = "0";
return "Snore";
}
#include "freedesktopnotificationfrontend.moc"

View File

@ -55,8 +55,8 @@ namespace V42 {
// workaround for mingw-w64 bug
#ifdef __MINGW64_VERSION_MAJOR
extern "C" {
__declspec(dllimport) errno_t __cdecl strcpy_s(char * _Dst, size_t _SizeInBytes, const char *_Src);
__declspec(dllimport) errno_t __cdecl wcscpy_s(wchar_t * _Dst, size_t _SizeInBytes, const wchar_t *_Src);
__declspec(dllimport) errno_t __cdecl strcpy_s(char * _Dst, size_t _SizeInBytes, const char *_Src);
__declspec(dllimport) errno_t __cdecl wcscpy_s(wchar_t * _Dst, size_t _SizeInBytes, const wchar_t *_Src);
__declspec(dllimport) errno_t __cdecl strncat_s(char *_Dst, size_t _DstSizeInChars, const char *_Src, size_t _MaxCount);
}
#endif //__MINGW64_VERSION_MAJOR

View File

@ -3,7 +3,7 @@
#ifdef __MINGW32__
#define MINGW_HAS_SECURE_API
#endif
#endif
#include <tchar.h>
#include <windows.h>
@ -16,7 +16,6 @@
#define SMTO_NOTIMEOUTIFNOTHUNG 8
#endif
namespace Snarl {
namespace V42 {

View File

@ -73,7 +73,7 @@ void Snarl_Backend::registerApplication(Application *application){
foreach(Alert *alert,application->alerts()){
snarlInterface->AddClass(application->name().toUtf8().constData(),
alert->name().toUtf8().constData(),
0,0,alert->icon().toUtf8().constData());
0,0,alert->icon().localUrl().toUtf8().constData());
}
}