more chanegs then I can tell
This commit is contained in:
parent
09da654af4
commit
fb830b9c2a
|
@ -34,6 +34,7 @@ if(Boost_USE_STATIC_RUNTIME)
|
|||
endif(Boost_USE_STATIC_RUNTIME)
|
||||
|
||||
set(PLUGIN_INSTALL_PATH LIBRARY DESTINATION bin/snoreplugins)
|
||||
add_definitions(-DLIBSNORE_PLUGIN_PATH="${CMAKE_INSTALL_PREFIX}/bin/snoreplugins")
|
||||
|
||||
add_subdirectory(data)
|
||||
add_subdirectory(share)
|
||||
|
|
|
@ -15,8 +15,7 @@ add_subdirectory(notification)
|
|||
set ( SnoreNotify_SRCS ${SnoreNotify_SRCS}
|
||||
snoreserver.cpp
|
||||
application.cpp
|
||||
interface.cpp
|
||||
trayiconnotifer.cpp
|
||||
interface.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/version.cpp
|
||||
)
|
||||
|
||||
|
@ -25,7 +24,7 @@ set ( SnoreNotify_HDR ${SnoreNotify_HDR}
|
|||
application.h
|
||||
interface.h
|
||||
snore_exports.h
|
||||
version.h
|
||||
version.h
|
||||
)
|
||||
|
||||
automoc4_add_library( snorecore SHARED ${SnoreNotify_SRCS})
|
||||
|
|
|
@ -22,6 +22,23 @@
|
|||
|
||||
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 ) :
|
||||
m_name ( name ),
|
||||
m_initialized(false)
|
||||
|
@ -99,7 +116,7 @@ bool Notification_Backend::init( SnoreServer *snore )
|
|||
connect( snore,SIGNAL( applicationInitialized( Snore::Application* ) ),this,SLOT( registerApplication( Snore::Application* ) ) );
|
||||
connect( snore,SIGNAL( applicationRemoved( Snore::Application* ) ),this,SLOT( unregisterApplication( Snore::Application* ) ) );
|
||||
if(!isPrimaryNotificationBackend())
|
||||
connect( snore,SIGNAL( notify(Snore::Notification) ),this,SLOT( notify( Snore::Notification ) ) );
|
||||
connect( snore,SIGNAL( notify(Snore::Notification) ),this,SLOT( notify( Snore::Notification ) ) );
|
||||
|
||||
foreach(Application *a,snore->aplications()){
|
||||
this->registerApplication(a);
|
||||
|
|
|
@ -25,6 +25,20 @@ namespace Snore{
|
|||
class Application;
|
||||
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
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -40,7 +54,7 @@ protected:
|
|||
QHash<uint,Notification> activeNotifications;
|
||||
void startTimeout(uint id,int timeout);
|
||||
private slots:
|
||||
void notificationTimedOut();
|
||||
void notificationTimedOut();
|
||||
|
||||
private:
|
||||
SnorePlugin() {}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
#include "snoreserver.h"
|
||||
#include "notification/notification.h"
|
||||
#include "trayiconnotifer.h"
|
||||
#include "version.h"
|
||||
|
||||
#include <iostream>
|
||||
|
@ -26,9 +25,12 @@
|
|||
#include <QDir>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QApplication>
|
||||
#include <QSettings>
|
||||
|
||||
namespace Snore{
|
||||
|
||||
QMap<QString,SnorePluginInfo*> SnoreServer::m_pluginCache = QMap<QString,SnorePluginInfo*>() ;
|
||||
|
||||
QString const SnoreServer::version(){
|
||||
return QString().append(Version::major()).append(".").append(Version::minor()).append(Version::suffix());
|
||||
}
|
||||
|
@ -40,8 +42,8 @@ QString const SnoreServer::snoreTMP(){
|
|||
|
||||
|
||||
SnoreServer::SnoreServer ( QSystemTrayIcon *trayIcon ) :
|
||||
m_notificationBackend ( NULL ),
|
||||
m_trayIcon ( trayIcon )
|
||||
m_notificationBackend ( NULL ),
|
||||
m_trayIcon ( trayIcon )
|
||||
{
|
||||
QDir home ( snoreTMP() );
|
||||
if ( !home.exists() ){
|
||||
|
@ -49,48 +51,108 @@ SnoreServer::SnoreServer ( QSystemTrayIcon *trayIcon ) :
|
|||
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 );
|
||||
qDebug()<<"Trying to load"<<fileName;
|
||||
QPluginLoader loader ( SnoreServer::pluginDir(QString()).absoluteFilePath(info->pluginFile ));
|
||||
qDebug()<<"Trying to load"<<info->pluginFile;
|
||||
if ( !loader.load())
|
||||
{
|
||||
qDebug() <<"Failed loading plugin: "<<loader.errorString();
|
||||
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 )
|
||||
{
|
||||
|
||||
|
||||
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";
|
||||
switch(info->pluginType){
|
||||
case SnorePluginInfo::BACKEND:{
|
||||
Notification_Backend * nb = qobject_cast<Notification_Backend *> ( loader.instance() );
|
||||
qDebug() <<info->pluginName<<"is a Notification_Backend";
|
||||
if ( nb->isPrimaryNotificationBackend() )
|
||||
{
|
||||
m_primaryNotificationBackends.append( pluginName);
|
||||
m_primaryNotificationBackends.append( info->pluginName);
|
||||
if ( m_notificationBackend == NULL )
|
||||
{
|
||||
m_notificationBackend = nb;
|
||||
|
@ -100,18 +162,30 @@ void SnoreServer::publicatePlugin ( SnorePlugin *plugin )
|
|||
nb->deleteLater();
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_notyfier.insert ( pluginName,nb );
|
||||
|
||||
}else{
|
||||
Notification_Frontend * nf = qobject_cast<Notification_Frontend*> ( plugin );
|
||||
if(nf != NULL){
|
||||
qDebug() <<pluginName<<"is a Notification_Frontend";
|
||||
if(nf->init( this ))
|
||||
m_frontends.insert(nf->name(),nf);
|
||||
else
|
||||
nf->deleteLater();
|
||||
}
|
||||
m_notyfier.insert ( info->pluginName,nb );
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SnorePluginInfo::FRONTEND:{
|
||||
Notification_Frontend * nf = qobject_cast<Notification_Frontend*> (loader.instance());
|
||||
qDebug() <<info->pluginName<<"is a Notification_Frontend";
|
||||
if(nf->init( this ))
|
||||
m_frontends.insert(nf->name(),nf);
|
||||
else
|
||||
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 )
|
||||
{
|
||||
_applications.insert ( application->name(),application );
|
||||
m_applications.insert ( application->name(),application );
|
||||
}
|
||||
|
||||
void SnoreServer::applicationIsInitialized ( Application *application )
|
||||
|
@ -161,13 +235,13 @@ void SnoreServer::applicationIsInitialized ( Application *application )
|
|||
void SnoreServer::removeApplication ( const QString& appName )
|
||||
{
|
||||
qDebug()<<"Remove Application"<<appName;
|
||||
emit applicationRemoved ( _applications.value ( appName ) );
|
||||
_applications.take ( appName )->deleteLater();
|
||||
emit applicationRemoved ( m_applications.value ( appName ) );
|
||||
m_applications.take ( appName )->deleteLater();
|
||||
}
|
||||
|
||||
const ApplicationsList &SnoreServer::aplications() const
|
||||
{
|
||||
return _applications;
|
||||
return m_applications;
|
||||
}
|
||||
|
||||
|
||||
|
@ -190,6 +264,10 @@ const QString &SnoreServer::primaryNotificationBackend(){
|
|||
return m_notificationBackend->name();
|
||||
}
|
||||
|
||||
QSystemTrayIcon *SnoreServer::trayIcon(){
|
||||
return m_trayIcon;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#include "snoreserver.moc"
|
||||
|
|
|
@ -23,20 +23,21 @@
|
|||
#include <QStringList>
|
||||
|
||||
class QSystemTrayIcon;
|
||||
class QDir;
|
||||
|
||||
namespace Snore{
|
||||
|
||||
class SNORE_EXPORT SnoreServer:public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static const QString version();
|
||||
static const QString snoreTMP();
|
||||
static QMap<QString,SnorePluginInfo*> pluginCache(const QString &pluginPath = QString());
|
||||
static QMap<QString,SnorePluginInfo*> updatePluginCache(const QString &pluginPath = QString());
|
||||
|
||||
public:
|
||||
SnoreServer (QSystemTrayIcon *trayIcon=0 );
|
||||
void publicatePlugin ( const QString &fileName );
|
||||
void publicatePlugin ( SnorePlugin *plugin );
|
||||
void publicatePlugin ( const SnorePluginInfo *info );
|
||||
|
||||
|
||||
uint broadcastNotification ( Notification notification );
|
||||
|
@ -51,11 +52,16 @@ public:
|
|||
const QStringList &primaryNotificationBackends() const;
|
||||
void setPrimaryNotificationBackend ( const QString &backend );
|
||||
const QString &primaryNotificationBackend();
|
||||
QSystemTrayIcon *trayIcon();
|
||||
|
||||
|
||||
|
||||
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;
|
||||
|
@ -64,7 +70,7 @@ private:
|
|||
Notification_Backend * m_notificationBackend;
|
||||
QHash<QString,SnorePlugin*> m_plugins;
|
||||
|
||||
class QSystemTrayIcon *m_trayIcon;
|
||||
QSystemTrayIcon *m_trayIcon;
|
||||
|
||||
|
||||
signals:
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
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(freedesktopfrontend)
|
||||
add_subdirectory(snarlnetwork)
|
||||
add_subdirectory(snarl)
|
||||
add_subdirectory(growl)
|
||||
add_subdirectory(trayicon)
|
||||
|
|
|
@ -27,7 +27,8 @@ if(QT_QTDBUS_FOUND AND WITH_FREEDESKTOP_FRONTEND)
|
|||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.Notifications.service
|
||||
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)
|
||||
|
||||
|
||||
|
|
|
@ -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} )
|
||||
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)
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ if( WITH_GROWL_BACKEND )
|
|||
target_link_libraries(growl_backend pthread)
|
||||
endif(UNIX)
|
||||
|
||||
install(TARGETS growl_backend ${PLUGIN_INSTALL_PATH})
|
||||
install(TARGETS growl_backend ${SNORE_BACKEND_INSTALL_PATH})
|
||||
else(CRYPTOPP_LIBRARIES AND Boost_SYSTEM_LIBRARY)
|
||||
if(NOT CRYPTOPP_LIBRARIES)
|
||||
message(STATUS "Cant build the growl backend because the dependency Cryptopp is missing")
|
||||
|
|
|
@ -7,6 +7,6 @@ if(WIN32)
|
|||
automoc4_add_library(snarln_backend MODULE ${SNARL__SRC} )
|
||||
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)
|
||||
|
|
|
@ -6,4 +6,4 @@ set( SNARL_NETWORK_SRC
|
|||
automoc4_add_library(snarlnetwork MODULE ${SNARL_NETWORK_SRC} )
|
||||
target_link_libraries(snarlnetwork snorecore ${QT_QTNETWORK_LIBRARY} )
|
||||
|
||||
install(TARGETS snarlnetwork ${PLUGIN_INSTALL_PATH})
|
||||
install(TARGETS snarlnetwork ${SNORE_FRONTEND_INSTALL_PATH})
|
||||
|
|
|
@ -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})
|
|
@ -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)
|
|
@ -1,20 +1,29 @@
|
|||
#include "trayiconnotifer.h"
|
||||
#include "snoreserver.h"
|
||||
#include "core/snoreserver.h"
|
||||
|
||||
#include <QtCore>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QTimer>
|
||||
#include <QTime>
|
||||
#include <QDebug>
|
||||
using namespace Snore;
|
||||
|
||||
Q_EXPORT_PLUGIN2(trayicon_backend,TrayIconNotifer)
|
||||
|
||||
TrayIconNotifer::TrayIconNotifer ( QSystemTrayIcon *icon ) :
|
||||
TrayIconNotifer::TrayIconNotifer () :
|
||||
Notification_Backend ( "SystemTray" ),
|
||||
_trayIcon ( icon ),
|
||||
_id ( 0 ),
|
||||
_displayed(-1)
|
||||
m_id ( 0 ),
|
||||
m_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 )
|
||||
|
@ -28,11 +37,11 @@ void TrayIconNotifer::unregisterApplication ( Application *application )
|
|||
|
||||
uint TrayIconNotifer::notify ( Notification notification )
|
||||
{
|
||||
_notificationQue.append(notification);
|
||||
if(_lastNotify.elapsed()> Notification::DefaultTimeout * 1000){
|
||||
m_notificationQue.append(notification);
|
||||
if(m_lastNotify.elapsed()> Notification::DefaultTimeout * 1000){
|
||||
displayNotification();
|
||||
}
|
||||
return _id++;
|
||||
return m_id++;
|
||||
}
|
||||
|
||||
void TrayIconNotifer::closeNotification ( Notification notification )
|
||||
|
@ -46,31 +55,31 @@ bool TrayIconNotifer::isPrimaryNotificationBackend()
|
|||
}
|
||||
|
||||
void TrayIconNotifer::displayNotification(){
|
||||
qDebug()<<"Display"<<_notificationQue.size();
|
||||
Notification notification = _notificationQue.takeFirst();
|
||||
if(!_notificationQue.isEmpty()){
|
||||
qDebug()<<"Display"<<m_notificationQue.size();
|
||||
Notification notification = m_notificationQue.takeFirst();
|
||||
if(!m_notificationQue.isEmpty()){
|
||||
QTimer::singleShot(notification.timeout()*1000,this,SLOT(closeNotification()));
|
||||
}
|
||||
|
||||
qDebug()<<"taking"<<notification.title();
|
||||
_displayed = notification.id();
|
||||
m_displayed = notification.id();
|
||||
activeNotifications.insert(notification.id(),notification);
|
||||
_trayIcon->showMessage ( Notification::toPlainText(notification.title()),Notification::toPlainText(notification.text()),QSystemTrayIcon::NoIcon,notification.timeout() *1000 );
|
||||
_lastNotify.restart();
|
||||
m_trayIcon->showMessage ( Notification::toPlainText(notification.title()),Notification::toPlainText(notification.text()),QSystemTrayIcon::NoIcon,notification.timeout() *1000 );
|
||||
m_lastNotify.restart();
|
||||
}
|
||||
|
||||
void TrayIconNotifer::closeNotification(){
|
||||
if(activeNotifications.contains(_displayed)){
|
||||
Notification noti = activeNotifications.take(_displayed);
|
||||
if(activeNotifications.contains(m_displayed)){
|
||||
Notification noti = activeNotifications.take(m_displayed);
|
||||
snore()->closeNotification(noti,NotificationEnums::CloseReasons::TIMED_OUT);
|
||||
}
|
||||
displayNotification();
|
||||
}
|
||||
|
||||
void TrayIconNotifer::actionInvoked(){
|
||||
qDebug()<<"Traicon invoked"<<_displayed;
|
||||
if(activeNotifications.contains(_displayed)){
|
||||
Notification noti = activeNotifications.take(_displayed);
|
||||
qDebug()<<"Traicon invoked"<<m_displayed;
|
||||
if(activeNotifications.contains(m_displayed)){
|
||||
Notification noti = activeNotifications.take(m_displayed);
|
||||
if(noti.actions().isEmpty()){
|
||||
noti.setActionInvoked(noti.actions().keys().first());
|
||||
snore()->notificationActionInvoked(noti);
|
|
@ -1,17 +1,23 @@
|
|||
#ifndef TRAYICONNOTIFER_H
|
||||
#define TRAYICONNOTIFER_H
|
||||
|
||||
#include "interface.h"
|
||||
#include "notification/notification.h"
|
||||
#include "core/interface.h"
|
||||
|
||||
#include <QTime>
|
||||
|
||||
namespace Snore{
|
||||
class SnoreServer;
|
||||
}
|
||||
|
||||
class QSystemTrayIcon;
|
||||
|
||||
class TrayIconNotifer:public Snore::Notification_Backend
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(Snore::Notification_Backend)
|
||||
public:
|
||||
TrayIconNotifer (class QSystemTrayIcon *icon=0 );
|
||||
TrayIconNotifer ();
|
||||
virtual bool init(Snore::SnoreServer *snore);
|
||||
bool isPrimaryNotificationBackend();
|
||||
|
||||
public slots:
|
||||
|
@ -21,11 +27,11 @@ public slots:
|
|||
void closeNotification ( Snore::Notification notification );
|
||||
|
||||
private:
|
||||
class QSystemTrayIcon *_trayIcon;
|
||||
QList<Snore::Notification > _notificationQue;
|
||||
QTime _lastNotify;
|
||||
uint _id;
|
||||
uint _displayed;
|
||||
QSystemTrayIcon *m_trayIcon;
|
||||
QList<Snore::Notification > m_notificationQue;
|
||||
QTime m_lastNotify;
|
||||
uint m_id;
|
||||
uint m_displayed;
|
||||
|
||||
private slots:
|
||||
void displayNotification();
|
|
@ -27,49 +27,49 @@
|
|||
#include <QSettings>
|
||||
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
SnoreNotify::SnoreNotify():
|
||||
_settings("TheOneRing","SnoreNotify")
|
||||
m_settings("TheOneRing","SnoreNotify")
|
||||
{
|
||||
_trayIcon = new TrayIcon();
|
||||
_snore = new Snore::SnoreServer(_trayIcon->trayIcon());
|
||||
m_trayIcon = new TrayIcon();
|
||||
m_snore = new Snore::SnoreServer(m_trayIcon->trayIcon());
|
||||
|
||||
QDir pluginsDir ( qApp->applicationDirPath() +"/snoreplugins" );
|
||||
foreach ( QString fileName, pluginsDir.entryList ( QDir::Files ) )
|
||||
QMap<QString,SnorePluginInfo*> plugins = SnoreServer::pluginCache();
|
||||
foreach ( SnorePluginInfo *info, plugins.values())
|
||||
{
|
||||
_snore->publicatePlugin ( pluginsDir.absoluteFilePath ( fileName ) );
|
||||
m_snore->publicatePlugin ( info );
|
||||
}
|
||||
|
||||
|
||||
load();
|
||||
|
||||
_trayIcon->initConextMenu(_snore);
|
||||
m_trayIcon->initConextMenu(m_snore);
|
||||
|
||||
connect(qApp,SIGNAL(aboutToQuit()),this,SLOT(exit()));
|
||||
}
|
||||
|
||||
SnoreNotify::~SnoreNotify(){
|
||||
delete _snore;
|
||||
delete _trayIcon;
|
||||
delete m_snore;
|
||||
delete m_trayIcon;
|
||||
}
|
||||
|
||||
void SnoreNotify::load(){
|
||||
_snore->setPrimaryNotificationBackend(_settings.value("notificationBackend").toString());
|
||||
m_snore->setPrimaryNotificationBackend(m_settings.value("notificationBackend").toString());
|
||||
}
|
||||
|
||||
void SnoreNotify::save(){
|
||||
_settings.setValue("notificationBackend",_snore->primaryNotificationBackend());
|
||||
m_settings.setValue("notificationBackend",m_snore->primaryNotificationBackend());
|
||||
}
|
||||
|
||||
void SnoreNotify::exit(){
|
||||
qDebug()<<"Saving snore settings";
|
||||
foreach(Application *a,_snore->aplications()){
|
||||
_snore->removeApplication(a->name());
|
||||
foreach(Application *a,m_snore->aplications()){
|
||||
m_snore->removeApplication(a->name());
|
||||
}
|
||||
save();
|
||||
_trayIcon->hide();
|
||||
m_trayIcon->hide();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include <QtCore>
|
||||
|
||||
namespace Snore{
|
||||
class SnoreServer;
|
||||
class SnoreServer;
|
||||
}
|
||||
|
||||
class SnoreNotify:public QObject
|
||||
|
@ -28,14 +28,14 @@ class SnoreNotify:public QObject
|
|||
Q_OBJECT
|
||||
public:
|
||||
SnoreNotify();
|
||||
~SnoreNotify();
|
||||
void load();
|
||||
void save();
|
||||
~SnoreNotify();
|
||||
void load();
|
||||
void save();
|
||||
|
||||
private:
|
||||
class TrayIcon *_trayIcon;
|
||||
Snore::SnoreServer *_snore;
|
||||
class QSettings _settings;
|
||||
class TrayIcon *m_trayIcon;
|
||||
Snore::SnoreServer *m_snore;
|
||||
class QSettings m_settings;
|
||||
|
||||
private slots:
|
||||
void exit();
|
||||
|
|
Loading…
Reference in New Issue