more chanegs then I can tell

This commit is contained in:
Patrick von Reth 2012-01-27 20:38:47 +01:00
parent 09da654af4
commit fb830b9c2a
18 changed files with 266 additions and 113 deletions

View File

@ -34,6 +34,7 @@ if(Boost_USE_STATIC_RUNTIME)
endif(Boost_USE_STATIC_RUNTIME) endif(Boost_USE_STATIC_RUNTIME)
set(PLUGIN_INSTALL_PATH LIBRARY DESTINATION bin/snoreplugins) set(PLUGIN_INSTALL_PATH LIBRARY DESTINATION bin/snoreplugins)
add_definitions(-DLIBSNORE_PLUGIN_PATH="${CMAKE_INSTALL_PREFIX}/bin/snoreplugins")
add_subdirectory(data) add_subdirectory(data)
add_subdirectory(share) add_subdirectory(share)

View File

@ -16,7 +16,6 @@ set ( SnoreNotify_SRCS ${SnoreNotify_SRCS}
snoreserver.cpp snoreserver.cpp
application.cpp application.cpp
interface.cpp interface.cpp
trayiconnotifer.cpp
${CMAKE_CURRENT_BINARY_DIR}/version.cpp ${CMAKE_CURRENT_BINARY_DIR}/version.cpp
) )

View File

@ -22,6 +22,23 @@
namespace Snore{ namespace Snore{
SnorePluginInfo::type SnorePluginInfo::typeFromString(const QString &t){
if(t == QLatin1String("backend"))
return BACKEND;
if(t == QLatin1String("frontend"))
return FRONTEND;
return PLUGIN;
}
const QStringList &SnorePluginInfo::types(){
static QStringList *list =NULL;
if(list == NULL){
list = new QStringList();
*list<<"backend"<<"frontend"<<"plugin";
}
return *list;
}
SnorePlugin::SnorePlugin ( QString name ) : SnorePlugin::SnorePlugin ( QString name ) :
m_name ( name ), m_name ( name ),
m_initialized(false) m_initialized(false)

View File

@ -25,6 +25,20 @@ namespace Snore{
class Application; class Application;
class SnoreServer; class SnoreServer;
class SNORE_EXPORT SnorePluginInfo{
public:
enum type{
BACKEND,
FRONTEND,
PLUGIN
};
QString pluginFile;
QString pluginName;
type pluginType;
static type typeFromString(const QString &t);
static const QStringList &types();
};
class SNORE_EXPORT SnorePlugin:public QObject class SNORE_EXPORT SnorePlugin:public QObject
{ {
Q_OBJECT Q_OBJECT

View File

@ -16,7 +16,6 @@
#include "snoreserver.h" #include "snoreserver.h"
#include "notification/notification.h" #include "notification/notification.h"
#include "trayiconnotifer.h"
#include "version.h" #include "version.h"
#include <iostream> #include <iostream>
@ -26,9 +25,12 @@
#include <QDir> #include <QDir>
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include <QApplication> #include <QApplication>
#include <QSettings>
namespace Snore{ namespace Snore{
QMap<QString,SnorePluginInfo*> SnoreServer::m_pluginCache = QMap<QString,SnorePluginInfo*>() ;
QString const SnoreServer::version(){ QString const SnoreServer::version(){
return QString().append(Version::major()).append(".").append(Version::minor()).append(Version::suffix()); return QString().append(Version::major()).append(".").append(Version::minor()).append(Version::suffix());
} }
@ -49,48 +51,108 @@ SnoreServer::SnoreServer ( QSystemTrayIcon *trayIcon ) :
home.mkdir("SnoreNotify"); home.mkdir("SnoreNotify");
} }
if ( trayIcon!=NULL ) }
{
publicatePlugin ( new TrayIconNotifer ( trayIcon ) ); QMap<QString, SnorePluginInfo *> SnoreServer::pluginCache(const QString &pluginPath){
if(!m_pluginCache.isEmpty())
return m_pluginCache;
QSettings cache(SnoreServer::pluginDir(pluginPath).absoluteFilePath("plugin.cache"),QSettings::IniFormat);
int size = cache.beginReadArray("plugins");
if(size == 0)
return updatePluginCache(pluginPath);
for(int i=0;i< m_pluginCache.size();++i) {
cache.setArrayIndex(i);
SnorePluginInfo *info = new SnorePluginInfo();
info->pluginFile = cache.value("fileName").toString();
info->pluginName = cache.value("name").toString();
info->pluginType = (SnorePluginInfo::type)cache.value("type").toInt();
m_pluginCache[info->pluginName] = info;
}
cache.endArray();
return m_pluginCache;
}
QMap<QString, SnorePluginInfo *> SnoreServer::updatePluginCache(const QString &pluginPath){
QSettings cache(SnoreServer::pluginDir(pluginPath).absoluteFilePath("plugin.cache"),QSettings::IniFormat);
qDebug()<<"Updating plugin cache"<<cache.fileName();
m_pluginCache.clear();
foreach(const QString &type,SnorePluginInfo::types()){
QDir plPath(SnoreServer::pluginDir(pluginPath).absoluteFilePath(type));
qDebug()<<"Searching for plugins in"<<plPath.path();
foreach (QString fileName, plPath.entryList(QDir::Files)) {
QString filepath(plPath.absoluteFilePath(fileName));
qDebug()<<"adding"<<filepath;
QPluginLoader loader(filepath);
QObject *plugin = loader.instance();
if (plugin == NULL) {
qDebug()<<"Failed loading plugin: "<<filepath<<loader.errorString();
continue;
}
SnorePlugin *sp = dynamic_cast<SnorePlugin*>(plugin);
if(sp == NULL){
qDebug()<<"Error:"<<fileName.toLatin1().data()<<" is not a Snore plugin" ;
plugin->deleteLater();
continue;
}
SnorePluginInfo *info = new SnorePluginInfo();
info->pluginFile = SnoreServer::pluginDir(pluginPath).relativeFilePath(filepath);
info->pluginName = sp->name();
info->pluginType = SnorePluginInfo::typeFromString(type);
m_pluginCache.insert(info->pluginName,info);
sp->deleteLater();
qDebug()<<"added "<<info->pluginFile<<"to cache";
}
} }
qDebug()<<m_pluginCache.keys();
QList<SnorePluginInfo*> plugins = m_pluginCache.values();
cache.beginWriteArray("plugins");
for(int i=0;i< plugins.size();++i) {
cache.setArrayIndex(i);
cache.setValue("fileName",plugins[i]->pluginFile);
cache.setValue("name", plugins[i]->pluginName);
cache.setValue("type",plugins[i]->pluginType);
}
cache.endArray();
return m_pluginCache;
} }
void SnoreServer::publicatePlugin ( const QString &fileName )
const QDir &SnoreServer::pluginDir(const QString &pluginPath){
static QDir *plDir = NULL;
if(plDir == NULL){
if(!pluginPath.isEmpty())
plDir = new QDir(pluginPath);
if(pluginPath.isEmpty() || plDir->exists()){
plDir = new QDir(qApp->applicationDirPath()+"/snoreplugins");
if(!plDir->exists())
plDir = new QDir(LIBSNORE_PLUGIN_PATH);
}
}
return *plDir;
}
void SnoreServer::publicatePlugin ( const SnorePluginInfo *info )
{ {
QPluginLoader loader ( fileName ); QPluginLoader loader ( SnoreServer::pluginDir(QString()).absoluteFilePath(info->pluginFile ));
qDebug()<<"Trying to load"<<fileName; qDebug()<<"Trying to load"<<info->pluginFile;
if ( !loader.load()) if ( !loader.load())
{ {
qDebug() <<"Failed loading plugin: "<<loader.errorString(); qDebug() <<"Failed loading plugin: "<<loader.errorString();
return; return;
} }
SnorePlugin *sp = qobject_cast<SnorePlugin*> ( loader.instance());
if ( sp == NULL )
{
std::cerr<<"Error:"<<fileName.toLatin1().data() <<" is not a snarl plugin"<<std::endl ;
return;
}
publicatePlugin ( sp );
}
void SnoreServer::publicatePlugin ( SnorePlugin *plugin ) switch(info->pluginType){
{ case SnorePluginInfo::BACKEND:{
Notification_Backend * nb = qobject_cast<Notification_Backend *> ( loader.instance() );
qDebug() <<info->pluginName<<"is a Notification_Backend";
QString pluginName ( plugin->name() );
qDebug() <<"Loading plugin: "<<pluginName;
m_plugins.insert ( pluginName,plugin );
qDebug() <<pluginName<<"is a SnorePlugin";
Notification_Backend * nb = qobject_cast<Notification_Backend *> ( plugin );
if ( nb )
{
qDebug() <<pluginName<<"is a Notification_Backend";
if ( nb->isPrimaryNotificationBackend() ) if ( nb->isPrimaryNotificationBackend() )
{ {
m_primaryNotificationBackends.append( pluginName); m_primaryNotificationBackends.append( info->pluginName);
if ( m_notificationBackend == NULL ) if ( m_notificationBackend == NULL )
{ {
m_notificationBackend = nb; m_notificationBackend = nb;
@ -100,18 +162,30 @@ void SnoreServer::publicatePlugin ( SnorePlugin *plugin )
nb->deleteLater(); nb->deleteLater();
return; return;
} }
}
m_notyfier.insert ( pluginName,nb );
}else{ m_notyfier.insert ( info->pluginName,nb );
Notification_Frontend * nf = qobject_cast<Notification_Frontend*> ( plugin ); }
if(nf != NULL){ break;
qDebug() <<pluginName<<"is a Notification_Frontend"; }
case SnorePluginInfo::FRONTEND:{
Notification_Frontend * nf = qobject_cast<Notification_Frontend*> (loader.instance());
qDebug() <<info->pluginName<<"is a Notification_Frontend";
if(nf->init( this )) if(nf->init( this ))
m_frontends.insert(nf->name(),nf); m_frontends.insert(nf->name(),nf);
else else
nf->deleteLater(); nf->deleteLater();
break;
} }
case SnorePluginInfo::PLUGIN:{
SnorePlugin *plugin = qobject_cast<SnorePlugin*> ( loader.instance());
plugin->init(this);
m_plugins.insert ( info->pluginName ,plugin );
qDebug() <<info->pluginName<<"is a SnorePlugin";
break;
}
default:
std::cerr<<"Plugin Cache corrupted"<<std::endl ;
break;
} }
} }
@ -149,7 +223,7 @@ void SnoreServer::notificationActionInvoked ( Notification notification )
void SnoreServer::addApplication ( Application *application ) void SnoreServer::addApplication ( Application *application )
{ {
_applications.insert ( application->name(),application ); m_applications.insert ( application->name(),application );
} }
void SnoreServer::applicationIsInitialized ( Application *application ) void SnoreServer::applicationIsInitialized ( Application *application )
@ -161,13 +235,13 @@ void SnoreServer::applicationIsInitialized ( Application *application )
void SnoreServer::removeApplication ( const QString& appName ) void SnoreServer::removeApplication ( const QString& appName )
{ {
qDebug()<<"Remove Application"<<appName; qDebug()<<"Remove Application"<<appName;
emit applicationRemoved ( _applications.value ( appName ) ); emit applicationRemoved ( m_applications.value ( appName ) );
_applications.take ( appName )->deleteLater(); m_applications.take ( appName )->deleteLater();
} }
const ApplicationsList &SnoreServer::aplications() const const ApplicationsList &SnoreServer::aplications() const
{ {
return _applications; return m_applications;
} }
@ -190,6 +264,10 @@ const QString &SnoreServer::primaryNotificationBackend(){
return m_notificationBackend->name(); return m_notificationBackend->name();
} }
QSystemTrayIcon *SnoreServer::trayIcon(){
return m_trayIcon;
}
} }
#include "snoreserver.moc" #include "snoreserver.moc"

View File

@ -23,20 +23,21 @@
#include <QStringList> #include <QStringList>
class QSystemTrayIcon; class QSystemTrayIcon;
class QDir;
namespace Snore{ namespace Snore{
class SNORE_EXPORT SnoreServer:public QObject class SNORE_EXPORT SnoreServer:public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
static const QString version(); static const QString version();
static const QString snoreTMP(); static const QString snoreTMP();
static QMap<QString,SnorePluginInfo*> pluginCache(const QString &pluginPath = QString());
static QMap<QString,SnorePluginInfo*> updatePluginCache(const QString &pluginPath = QString());
public: public:
SnoreServer (QSystemTrayIcon *trayIcon=0 ); SnoreServer (QSystemTrayIcon *trayIcon=0 );
void publicatePlugin ( const QString &fileName ); void publicatePlugin ( const SnorePluginInfo *info );
void publicatePlugin ( SnorePlugin *plugin );
uint broadcastNotification ( Notification notification ); uint broadcastNotification ( Notification notification );
@ -51,11 +52,16 @@ public:
const QStringList &primaryNotificationBackends() const; const QStringList &primaryNotificationBackends() const;
void setPrimaryNotificationBackend ( const QString &backend ); void setPrimaryNotificationBackend ( const QString &backend );
const QString &primaryNotificationBackend(); const QString &primaryNotificationBackend();
QSystemTrayIcon *trayIcon();
private: private:
ApplicationsList _applications; static const QDir &pluginDir(const QString &pluginPath);
static QMap<QString,SnorePluginInfo*> m_pluginCache;
ApplicationsList m_applications;
QHash<QString,Notification_Backend*> m_notyfier; QHash<QString,Notification_Backend*> m_notyfier;
@ -64,7 +70,7 @@ private:
Notification_Backend * m_notificationBackend; Notification_Backend * m_notificationBackend;
QHash<QString,SnorePlugin*> m_plugins; QHash<QString,SnorePlugin*> m_plugins;
class QSystemTrayIcon *m_trayIcon; QSystemTrayIcon *m_trayIcon;
signals: signals:

View File

@ -1,6 +1,11 @@
set(CMAKE_SHARED_MODULE_PREFIX) set(CMAKE_SHARED_MODULE_PREFIX)
set(SNORE_BACKEND_INSTALL_PATH ${PLUGIN_INSTALL_PATH}/backend)
set(SNORE_FRONTEND_INSTALL_PATH ${PLUGIN_INSTALL_PATH}/frontend)
set(SNORE_PLUGINS_INSTALL_PATH ${PLUGIN_INSTALL_PATH}/plugin)
add_subdirectory(freedesktopnotification) add_subdirectory(freedesktopnotification)
add_subdirectory(freedesktopfrontend) add_subdirectory(freedesktopfrontend)
add_subdirectory(snarlnetwork) add_subdirectory(snarlnetwork)
add_subdirectory(snarl) add_subdirectory(snarl)
add_subdirectory(growl) add_subdirectory(growl)
add_subdirectory(trayicon)

View File

@ -27,7 +27,8 @@ if(QT_QTDBUS_FOUND AND WITH_FREEDESKTOP_FRONTEND)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Notifications.service install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Notifications.service
DESTINATION share/dbus-1/services/) DESTINATION share/dbus-1/services/)
install(TARGETS freedesktop_frontend ${PLUGIN_INSTALL_PATH}) install(TARGETS freedesktop_frontend ${SNORE_FRONTEND_INSTALL_PATH})
endif(QT_QTDBUS_FOUND AND WITH_FREEDESKTOP_FRONTEND) endif(QT_QTDBUS_FOUND AND WITH_FREEDESKTOP_FRONTEND)

View File

@ -7,6 +7,6 @@ if(QT_QTDBUS_FOUND AND NOT WITH_FREEDESKTOP_FRONTEND AND UNIX AND NOT APPLE)
automoc4_add_library(freedesktop_backend MODULE ${FREEDESKTOP_NOTIFICATION_SRC} ) automoc4_add_library(freedesktop_backend MODULE ${FREEDESKTOP_NOTIFICATION_SRC} )
target_link_libraries(freedesktop_backend snorecore ${QT_QTGUI_LIBRARY} ${QT_QTDBUS_LIBRARY} ) target_link_libraries(freedesktop_backend snorecore ${QT_QTGUI_LIBRARY} ${QT_QTDBUS_LIBRARY} )
install(TARGETS freedesktop_backend ${PLUGIN_INSTALL_PATH}) install(TARGETS freedesktop_backend ${SNORE_BACKEND_INSTALL_PATH})
endif(QT_QTDBUS_FOUND AND NOT WITH_FREEDESKTOP_FRONTEND AND UNIX AND NOT APPLE) endif(QT_QTDBUS_FOUND AND NOT WITH_FREEDESKTOP_FRONTEND AND UNIX AND NOT APPLE)

View File

@ -24,7 +24,7 @@ if( WITH_GROWL_BACKEND )
target_link_libraries(growl_backend pthread) target_link_libraries(growl_backend pthread)
endif(UNIX) endif(UNIX)
install(TARGETS growl_backend ${PLUGIN_INSTALL_PATH}) install(TARGETS growl_backend ${SNORE_BACKEND_INSTALL_PATH})
else(CRYPTOPP_LIBRARIES AND Boost_SYSTEM_LIBRARY) else(CRYPTOPP_LIBRARIES AND Boost_SYSTEM_LIBRARY)
if(NOT CRYPTOPP_LIBRARIES) if(NOT CRYPTOPP_LIBRARIES)
message(STATUS "Cant build the growl backend because the dependency Cryptopp is missing") message(STATUS "Cant build the growl backend because the dependency Cryptopp is missing")

View File

@ -7,6 +7,6 @@ if(WIN32)
automoc4_add_library(snarln_backend MODULE ${SNARL__SRC} ) automoc4_add_library(snarln_backend MODULE ${SNARL__SRC} )
target_link_libraries(snarln_backend snorecore ${QT_QTCORE_LIBRARY} ) target_link_libraries(snarln_backend snorecore ${QT_QTCORE_LIBRARY} )
install(TARGETS snarln_backend ${PLUGIN_INSTALL_PATH}) install(TARGETS snarln_backend ${SNORE_BACKEND_INSTALL_PATH})
endif(WIN32) endif(WIN32)

View File

@ -6,4 +6,4 @@ set( SNARL_NETWORK_SRC
automoc4_add_library(snarlnetwork MODULE ${SNARL_NETWORK_SRC} ) automoc4_add_library(snarlnetwork MODULE ${SNARL_NETWORK_SRC} )
target_link_libraries(snarlnetwork snorecore ${QT_QTNETWORK_LIBRARY} ) target_link_libraries(snarlnetwork snorecore ${QT_QTNETWORK_LIBRARY} )
install(TARGETS snarlnetwork ${PLUGIN_INSTALL_PATH}) install(TARGETS snarlnetwork ${SNORE_FRONTEND_INSTALL_PATH})

View File

@ -0,0 +1,7 @@
set( trayicon_SRC
trayiconnotifer.cpp
)
automoc4_add_library(trayicon_backend MODULE ${trayicon_SRC} )
target_link_libraries(trayicon_backend snorecore ${QT_QTCORE_LIBRARY} )
install(TARGETS trayicon_backend ${SNORE_BACKEND_INSTALL_PATH})

View File

@ -0,0 +1,10 @@
set( trayicon_SRC
trayiconnotifer.cpp
)
automoc4_add_library(trayicon_backend MODULE ${trayicon_SRC} )
target_link_libraries(trayicon_backend snorecore ${QT_QTCORE_LIBRARY} )
install(TARGETS snarln_backend ${SNORE_BACKEND_INSTALL_PATH})
endif(WIN32)

View File

@ -1,20 +1,29 @@
#include "trayiconnotifer.h" #include "trayiconnotifer.h"
#include "snoreserver.h" #include "core/snoreserver.h"
#include <QtCore>
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include <QTimer> #include <QTimer>
#include <QTime> #include <QTime>
#include <QDebug> #include <QDebug>
using namespace Snore; using namespace Snore;
Q_EXPORT_PLUGIN2(trayicon_backend,TrayIconNotifer)
TrayIconNotifer::TrayIconNotifer ( QSystemTrayIcon *icon ) : TrayIconNotifer::TrayIconNotifer () :
Notification_Backend ( "SystemTray" ), Notification_Backend ( "SystemTray" ),
_trayIcon ( icon ), m_id ( 0 ),
_id ( 0 ), m_displayed(-1)
_displayed(-1)
{ {
connect(_trayIcon,SIGNAL(messageClicked()),this,SLOT(actionInvoked()));
}
bool TrayIconNotifer::init(SnoreServer *snore){
connect(m_trayIcon,SIGNAL(messageClicked()),this,SLOT(actionInvoked()));
m_trayIcon = snore->trayIcon();
if(m_trayIcon == NULL)
return false;
return Notification_Backend::init(snore);
} }
void TrayIconNotifer::registerApplication ( Application *application ) void TrayIconNotifer::registerApplication ( Application *application )
@ -28,11 +37,11 @@ void TrayIconNotifer::unregisterApplication ( Application *application )
uint TrayIconNotifer::notify ( Notification notification ) uint TrayIconNotifer::notify ( Notification notification )
{ {
_notificationQue.append(notification); m_notificationQue.append(notification);
if(_lastNotify.elapsed()> Notification::DefaultTimeout * 1000){ if(m_lastNotify.elapsed()> Notification::DefaultTimeout * 1000){
displayNotification(); displayNotification();
} }
return _id++; return m_id++;
} }
void TrayIconNotifer::closeNotification ( Notification notification ) void TrayIconNotifer::closeNotification ( Notification notification )
@ -46,31 +55,31 @@ bool TrayIconNotifer::isPrimaryNotificationBackend()
} }
void TrayIconNotifer::displayNotification(){ void TrayIconNotifer::displayNotification(){
qDebug()<<"Display"<<_notificationQue.size(); qDebug()<<"Display"<<m_notificationQue.size();
Notification notification = _notificationQue.takeFirst(); Notification notification = m_notificationQue.takeFirst();
if(!_notificationQue.isEmpty()){ if(!m_notificationQue.isEmpty()){
QTimer::singleShot(notification.timeout()*1000,this,SLOT(closeNotification())); QTimer::singleShot(notification.timeout()*1000,this,SLOT(closeNotification()));
} }
qDebug()<<"taking"<<notification.title(); qDebug()<<"taking"<<notification.title();
_displayed = notification.id(); m_displayed = notification.id();
activeNotifications.insert(notification.id(),notification); activeNotifications.insert(notification.id(),notification);
_trayIcon->showMessage ( Notification::toPlainText(notification.title()),Notification::toPlainText(notification.text()),QSystemTrayIcon::NoIcon,notification.timeout() *1000 ); m_trayIcon->showMessage ( Notification::toPlainText(notification.title()),Notification::toPlainText(notification.text()),QSystemTrayIcon::NoIcon,notification.timeout() *1000 );
_lastNotify.restart(); m_lastNotify.restart();
} }
void TrayIconNotifer::closeNotification(){ void TrayIconNotifer::closeNotification(){
if(activeNotifications.contains(_displayed)){ if(activeNotifications.contains(m_displayed)){
Notification noti = activeNotifications.take(_displayed); Notification noti = activeNotifications.take(m_displayed);
snore()->closeNotification(noti,NotificationEnums::CloseReasons::TIMED_OUT); snore()->closeNotification(noti,NotificationEnums::CloseReasons::TIMED_OUT);
} }
displayNotification(); displayNotification();
} }
void TrayIconNotifer::actionInvoked(){ void TrayIconNotifer::actionInvoked(){
qDebug()<<"Traicon invoked"<<_displayed; qDebug()<<"Traicon invoked"<<m_displayed;
if(activeNotifications.contains(_displayed)){ if(activeNotifications.contains(m_displayed)){
Notification noti = activeNotifications.take(_displayed); Notification noti = activeNotifications.take(m_displayed);
if(noti.actions().isEmpty()){ if(noti.actions().isEmpty()){
noti.setActionInvoked(noti.actions().keys().first()); noti.setActionInvoked(noti.actions().keys().first());
snore()->notificationActionInvoked(noti); snore()->notificationActionInvoked(noti);

View File

@ -1,17 +1,23 @@
#ifndef TRAYICONNOTIFER_H #ifndef TRAYICONNOTIFER_H
#define TRAYICONNOTIFER_H #define TRAYICONNOTIFER_H
#include "interface.h" #include "core/interface.h"
#include "notification/notification.h"
#include <QTime> #include <QTime>
namespace Snore{
class SnoreServer;
}
class QSystemTrayIcon;
class TrayIconNotifer:public Snore::Notification_Backend class TrayIconNotifer:public Snore::Notification_Backend
{ {
Q_OBJECT Q_OBJECT
Q_INTERFACES(Snore::Notification_Backend) Q_INTERFACES(Snore::Notification_Backend)
public: public:
TrayIconNotifer (class QSystemTrayIcon *icon=0 ); TrayIconNotifer ();
virtual bool init(Snore::SnoreServer *snore);
bool isPrimaryNotificationBackend(); bool isPrimaryNotificationBackend();
public slots: public slots:
@ -21,11 +27,11 @@ public slots:
void closeNotification ( Snore::Notification notification ); void closeNotification ( Snore::Notification notification );
private: private:
class QSystemTrayIcon *_trayIcon; QSystemTrayIcon *m_trayIcon;
QList<Snore::Notification > _notificationQue; QList<Snore::Notification > m_notificationQue;
QTime _lastNotify; QTime m_lastNotify;
uint _id; uint m_id;
uint _displayed; uint m_displayed;
private slots: private slots:
void displayNotification(); void displayNotification();

View File

@ -27,49 +27,49 @@
#include <QSettings> #include <QSettings>
#include <iostream> #include <iostream>
#include <stdlib.h>
using namespace Snore; using namespace Snore;
SnoreNotify::SnoreNotify(): SnoreNotify::SnoreNotify():
_settings("TheOneRing","SnoreNotify") m_settings("TheOneRing","SnoreNotify")
{ {
_trayIcon = new TrayIcon(); m_trayIcon = new TrayIcon();
_snore = new Snore::SnoreServer(_trayIcon->trayIcon()); m_snore = new Snore::SnoreServer(m_trayIcon->trayIcon());
QDir pluginsDir ( qApp->applicationDirPath() +"/snoreplugins" ); QMap<QString,SnorePluginInfo*> plugins = SnoreServer::pluginCache();
foreach ( QString fileName, pluginsDir.entryList ( QDir::Files ) ) foreach ( SnorePluginInfo *info, plugins.values())
{ {
_snore->publicatePlugin ( pluginsDir.absoluteFilePath ( fileName ) ); m_snore->publicatePlugin ( info );
} }
load(); load();
m_trayIcon->initConextMenu(m_snore);
_trayIcon->initConextMenu(_snore);
connect(qApp,SIGNAL(aboutToQuit()),this,SLOT(exit())); connect(qApp,SIGNAL(aboutToQuit()),this,SLOT(exit()));
} }
SnoreNotify::~SnoreNotify(){ SnoreNotify::~SnoreNotify(){
delete _snore; delete m_snore;
delete _trayIcon; delete m_trayIcon;
} }
void SnoreNotify::load(){ void SnoreNotify::load(){
_snore->setPrimaryNotificationBackend(_settings.value("notificationBackend").toString()); m_snore->setPrimaryNotificationBackend(m_settings.value("notificationBackend").toString());
} }
void SnoreNotify::save(){ void SnoreNotify::save(){
_settings.setValue("notificationBackend",_snore->primaryNotificationBackend()); m_settings.setValue("notificationBackend",m_snore->primaryNotificationBackend());
} }
void SnoreNotify::exit(){ void SnoreNotify::exit(){
qDebug()<<"Saving snore settings"; qDebug()<<"Saving snore settings";
foreach(Application *a,_snore->aplications()){ foreach(Application *a,m_snore->aplications()){
_snore->removeApplication(a->name()); m_snore->removeApplication(a->name());
} }
save(); save();
_trayIcon->hide(); m_trayIcon->hide();
} }

View File

@ -20,7 +20,7 @@
#include <QtCore> #include <QtCore>
namespace Snore{ namespace Snore{
class SnoreServer; class SnoreServer;
} }
class SnoreNotify:public QObject class SnoreNotify:public QObject
@ -33,9 +33,9 @@ public:
void save(); void save();
private: private:
class TrayIcon *_trayIcon; class TrayIcon *m_trayIcon;
Snore::SnoreServer *_snore; Snore::SnoreServer *m_snore;
class QSettings _settings; class QSettings m_settings;
private slots: private slots:
void exit(); void exit();