some cleaning up
This commit is contained in:
parent
17d899f151
commit
bfe963cb64
|
@ -18,9 +18,10 @@
|
|||
*/
|
||||
|
||||
#include "application.h"
|
||||
namespace Snore{
|
||||
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
Application::Application (const QString &name, const Icon &icon) :
|
||||
m_name ( name ),
|
||||
m_icon(icon),
|
||||
|
@ -34,14 +35,11 @@ Application::Application() :
|
|||
|
||||
Application::~Application()
|
||||
{
|
||||
foreach ( Alert *a,m_alerts )
|
||||
{
|
||||
a->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void Application::addAlert ( Alert *alert )
|
||||
{
|
||||
alert->setParent(this);
|
||||
m_alerts.insert ( alert->name(),alert );
|
||||
}
|
||||
|
||||
|
@ -102,4 +100,3 @@ bool Alert::isActive() const
|
|||
return m_active;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -70,6 +70,9 @@ public:
|
|||
QString m_hash;
|
||||
bool m_isLocalFile;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(IconData)
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -23,34 +23,36 @@
|
|||
#include "snorebackend.h"
|
||||
#include "snorefrontend.h"
|
||||
|
||||
|
||||
#include <QTimer>
|
||||
#include <QPluginLoader>
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
|
||||
namespace Snore{
|
||||
using namespace Snore;
|
||||
|
||||
PluginContainer::PluginContainer(QString fileName, QString pluginName, PluginContainer::PluginType type)
|
||||
:m_pluginFile(fileName),
|
||||
m_pluginName(pluginName),
|
||||
m_pluginType(type)
|
||||
PluginContainer::PluginContainer(QString fileName, QString pluginName, PluginContainer::PluginType type):
|
||||
m_pluginFile(fileName),
|
||||
m_pluginName(pluginName),
|
||||
m_pluginType(type)
|
||||
{
|
||||
}
|
||||
|
||||
PluginContainer::~PluginContainer(){
|
||||
PluginContainer::~PluginContainer()
|
||||
{
|
||||
if(m_instance)
|
||||
{
|
||||
m_instance->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
SnorePlugin *PluginContainer::load(){
|
||||
SnorePlugin *PluginContainer::load()
|
||||
{
|
||||
if(m_instance != NULL)
|
||||
return m_instance;
|
||||
QPluginLoader loader ( SnoreCore::pluginDir().absoluteFilePath(file()));
|
||||
qDebug()<<"Trying to load"<<file();
|
||||
qDebug() << "Trying to load" << file();
|
||||
if ( !loader.load())
|
||||
{
|
||||
qDebug() <<"Failed loading plugin: "<<loader.errorString();
|
||||
qDebug() << "Failed loading plugin: " << loader.errorString();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -73,23 +75,32 @@ PluginContainer::PluginType PluginContainer::type()
|
|||
return m_pluginType;
|
||||
}
|
||||
|
||||
PluginContainer::PluginType PluginContainer::typeFromString(const QString &t){
|
||||
PluginContainer::PluginType PluginContainer::typeFromString(const QString &t)
|
||||
{
|
||||
PluginContainer::PluginType type = PLUGIN;
|
||||
if(t == QLatin1String("backend"))
|
||||
return BACKEND;
|
||||
if(t == QLatin1String("secondary_backend"))
|
||||
return SECONDARY_BACKEND;
|
||||
if(t == QLatin1String("frontend"))
|
||||
return FRONTEND;
|
||||
return PLUGIN;
|
||||
}
|
||||
|
||||
const QStringList &PluginContainer::types(){
|
||||
static QStringList *list = NULL;
|
||||
if(list == NULL){
|
||||
list = new QStringList();
|
||||
*list<<"backend"<<"secondary_backend"<<"frontend"<<"plugin";
|
||||
{
|
||||
type = BACKEND;
|
||||
}
|
||||
return *list;
|
||||
else if(t == QLatin1String("secondary_backend"))
|
||||
{
|
||||
type = SECONDARY_BACKEND;
|
||||
}
|
||||
else if(t == QLatin1String("frontend"))
|
||||
{
|
||||
type = FRONTEND;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
const QStringList &PluginContainer::types()
|
||||
{
|
||||
static QStringList list;
|
||||
if(list.isEmpty()){
|
||||
list << "backend"
|
||||
<< "secondary_backend"
|
||||
<< "frontend"
|
||||
<< "plugin";
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
|
|
@ -35,18 +35,17 @@
|
|||
#include <QApplication>
|
||||
#include <QSettings>
|
||||
|
||||
namespace Snore{
|
||||
using namespace Snore;
|
||||
|
||||
QHash<QString,PluginContainer*> SnoreCore::s_pluginCache = QHash<QString,PluginContainer*>() ;
|
||||
|
||||
QDir *SnoreCore::s_pluginDir = NULL;
|
||||
|
||||
QSettings *SnoreCore::cacheFile(){
|
||||
QSettings &SnoreCore::cacheFile(){
|
||||
#ifdef Q_OS_LINUX
|
||||
return new QSettings("TheOneRing","libsnore");
|
||||
static QSettings cache("TheOneRing","libsnore");
|
||||
#else
|
||||
return new QSettings(SnoreCore::pluginDir().absoluteFilePath("plugin.cache"),QSettings::IniFormat);
|
||||
static QSettings cache(SnoreCore::pluginDir().absoluteFilePath("plugin.cache"),QSettings::IniFormat);
|
||||
#endif
|
||||
return cache;
|
||||
}
|
||||
|
||||
void SnoreCore::slotNotificationClosed(Notification n)
|
||||
|
@ -54,11 +53,6 @@ void SnoreCore::slotNotificationClosed(Notification n)
|
|||
emit notificationClosed(n);
|
||||
}
|
||||
|
||||
QString const SnoreCore::version(){
|
||||
static QString ver(QString().append(Version::major()).append(".").append(Version::minor()).append(Version::suffix()));
|
||||
return ver;
|
||||
}
|
||||
|
||||
QString const SnoreCore::snoreTMP(){
|
||||
static const QString tmp = QString("%1/SnoreNotify/").arg(QDir::temp().path());
|
||||
return tmp;
|
||||
|
@ -79,30 +73,30 @@ SnoreCore::SnoreCore ( QSystemTrayIcon *trayIcon ) :
|
|||
QHash<QString, PluginContainer *> SnoreCore::pluginCache(){
|
||||
if(!s_pluginCache.isEmpty())
|
||||
return s_pluginCache;
|
||||
QSettings *cache = cacheFile();
|
||||
QString version = cache->value("version").toString();
|
||||
QString path = cache->value("pluginPath").toString();
|
||||
int size = cache->beginReadArray("plugins");
|
||||
QSettings &cache = cacheFile();
|
||||
QString version = cache.value("version").toString();
|
||||
QString path = cache.value("pluginPath").toString();
|
||||
int size = cache.beginReadArray("plugins");
|
||||
if(size == 0 || version != Version::revision() || path != pluginDir().path()){
|
||||
qDebug() << version << "!=" << Version::revision();
|
||||
qDebug() << path << "!=" << pluginDir().path();
|
||||
updatePluginCache();
|
||||
}else{
|
||||
for(int i=0;i<size;++i) {
|
||||
cache->setArrayIndex(i);
|
||||
PluginContainer::PluginType type = (PluginContainer::PluginType)cache->value("type").toInt();
|
||||
PluginContainer *info = new PluginContainer(cache->value("fileName").toString(),cache->value("name").toString(),type);
|
||||
cache.setArrayIndex(i);
|
||||
PluginContainer::PluginType type = (PluginContainer::PluginType)cache.value("type").toInt();
|
||||
PluginContainer *info = new PluginContainer(cache.value("fileName").toString(),cache.value("name").toString(),type);
|
||||
s_pluginCache.insert(info->name(),info);
|
||||
}
|
||||
cache->endArray();
|
||||
cache.endArray();
|
||||
}
|
||||
|
||||
return s_pluginCache;
|
||||
}
|
||||
|
||||
void SnoreCore::updatePluginCache(){
|
||||
QSettings *cache = cacheFile();
|
||||
qDebug() << "Updating plugin cache" << cache->fileName();
|
||||
QSettings &cache = cacheFile();
|
||||
qDebug() << "Updating plugin cache" << cache.fileName();
|
||||
|
||||
s_pluginCache.clear();
|
||||
|
||||
|
@ -132,57 +126,47 @@ void SnoreCore::updatePluginCache(){
|
|||
}
|
||||
|
||||
qDebug()<<s_pluginCache.keys();
|
||||
cache->setValue("version",Version::revision());
|
||||
cache->setValue("pluginPath",pluginDir().path());
|
||||
cache.setValue("version",Version::revision());
|
||||
cache.setValue("pluginPath",pluginDir().path());
|
||||
QList<PluginContainer*> plugins = s_pluginCache.values();
|
||||
cache->beginWriteArray("plugins");
|
||||
cache.beginWriteArray("plugins");
|
||||
for(int i=0;i< plugins.size();++i) {
|
||||
cache->setArrayIndex(i);
|
||||
cache->setValue("fileName",plugins[i]->file());
|
||||
cache->setValue("name", plugins[i]->name());
|
||||
cache->setValue("type",(int)plugins[i]->type());
|
||||
cache.setArrayIndex(i);
|
||||
cache.setValue("fileName",plugins[i]->file());
|
||||
cache.setValue("name", plugins[i]->name());
|
||||
cache.setValue("type",(int)plugins[i]->type());
|
||||
}
|
||||
cache->endArray();
|
||||
cache.endArray();
|
||||
}
|
||||
|
||||
const QDir &SnoreCore::pluginDir(){
|
||||
if(s_pluginDir == NULL)
|
||||
setPluginDir();
|
||||
qDebug()<<"SnorePluginDir:"<<s_pluginDir->path();
|
||||
return *s_pluginDir;
|
||||
static QDir path(QString("%1/snoreplugins").arg(qApp->applicationDirPath()));
|
||||
if(!path.exists())
|
||||
{
|
||||
path = QDir(LIBSNORE_PLUGIN_PATH);
|
||||
}
|
||||
qDebug() << "PluginDir" << path.absolutePath();
|
||||
return path;
|
||||
}
|
||||
|
||||
void SnoreCore::setPluginDir(const QString &path){
|
||||
if(!path.isEmpty()){//path is not empty
|
||||
QDir *tmp = new QDir(path);
|
||||
if(tmp->exists()){//path exists
|
||||
s_pluginDir = tmp;
|
||||
}else{
|
||||
delete tmp;
|
||||
}
|
||||
}
|
||||
//if pluginpath is not initialized try snoreplugins/ in application dir
|
||||
if(s_pluginDir == NULL){
|
||||
s_pluginDir = new QDir(qApp->applicationDirPath()+"/snoreplugins");
|
||||
qDebug()<<"PluginDir"<<s_pluginDir->absolutePath();
|
||||
if(!s_pluginDir->exists())//still not existing? use the path defined on compile time
|
||||
s_pluginDir = new QDir(LIBSNORE_PLUGIN_PATH);
|
||||
}
|
||||
}
|
||||
|
||||
void SnoreCore::loadPlugins ( PluginContainer::PluginTypes types )
|
||||
{
|
||||
qDebug()<<"PluginInfo"<<SnoreCore::pluginCache().keys();
|
||||
qDebug() << "PluginInfo" << SnoreCore::pluginCache().keys();
|
||||
foreach ( PluginContainer *info, SnoreCore::pluginCache().values())
|
||||
{
|
||||
if(types == PluginContainer::ALL or types.testFlag(info->type())){
|
||||
switch(info->type()){
|
||||
case PluginContainer::BACKEND:{
|
||||
if(types == PluginContainer::ALL or types.testFlag(info->type()))
|
||||
{
|
||||
switch(info->type())
|
||||
{
|
||||
case PluginContainer::BACKEND:
|
||||
{
|
||||
qDebug() <<info->name()<<"is a Notification_Backend";
|
||||
m_notificationBackends.append( info->name());
|
||||
break;
|
||||
}
|
||||
case PluginContainer::SECONDARY_BACKEND:{
|
||||
case PluginContainer::SECONDARY_BACKEND:
|
||||
{
|
||||
SnoreSecondaryBackend *nb = qobject_cast<SnoreSecondaryBackend *> ( info->load() );
|
||||
if(!nb->init( this )){
|
||||
nb->deleteLater();
|
||||
|
@ -191,7 +175,8 @@ void SnoreCore::loadPlugins ( PluginContainer::PluginTypes types )
|
|||
m_secondaryNotificationBackends.append(info->name());
|
||||
break;
|
||||
}
|
||||
case PluginContainer::FRONTEND:{
|
||||
case PluginContainer::FRONTEND:
|
||||
{
|
||||
SnoreFrontend * nf = qobject_cast<SnoreFrontend*> (info->load());
|
||||
qDebug() <<info->name()<<"is a Notification_Frontend";
|
||||
if(!nf->init( this )){
|
||||
|
@ -201,7 +186,8 @@ void SnoreCore::loadPlugins ( PluginContainer::PluginTypes types )
|
|||
m_Frontends.append(info->name());
|
||||
break;
|
||||
}
|
||||
case PluginContainer::PLUGIN:{
|
||||
case PluginContainer::PLUGIN:
|
||||
{
|
||||
qDebug() <<info->name()<<"is a SnorePlugin";
|
||||
if(!info->load()->init(this)){
|
||||
info->load()->deleteLater();
|
||||
|
@ -210,9 +196,10 @@ void SnoreCore::loadPlugins ( PluginContainer::PluginTypes types )
|
|||
m_plugins.append(info->name());
|
||||
break;
|
||||
}
|
||||
default:{
|
||||
default:
|
||||
{
|
||||
std::cerr<<"Plugin Cache corrupted"<<std::endl;
|
||||
std::cerr<<info->file().toLatin1().constData()<<QString::number((int)info->type()).toLatin1().constData()<<std::endl;
|
||||
std::cerr<<info->file().toLocal8Bit().constData()<<QString::number((int)info->type()).toLatin1().constData()<<std::endl;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
|
@ -240,7 +227,7 @@ void SnoreCore::broadcastNotification ( Notification notification )
|
|||
void SnoreCore::notificationActionInvoked ( Notification notification )
|
||||
{
|
||||
emit actionInvoked(notification);
|
||||
SnoreFrontend *nf= notification.source();
|
||||
SnoreFrontend *nf = notification.source();
|
||||
if ( nf != NULL )
|
||||
{
|
||||
nf->actionInvoked ( notification );
|
||||
|
@ -372,5 +359,3 @@ bool SnoreCore::primaryBackendSupportsRichtext()
|
|||
{
|
||||
return m_notificationBackend->supportsRichtext();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,15 +33,13 @@ class QSettings;
|
|||
|
||||
|
||||
namespace Snore{
|
||||
class SNORE_EXPORT SnoreCore:public QObject
|
||||
class SNORE_EXPORT SnoreCore : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static const QString version();
|
||||
static const QString snoreTMP();
|
||||
static void updatePluginCache();
|
||||
static const QDir &pluginDir();
|
||||
static void setPluginDir(const QString &path = "");
|
||||
|
||||
public:
|
||||
SnoreCore (QSystemTrayIcon *trayIcon = NULL );
|
||||
|
@ -76,10 +74,9 @@ public:
|
|||
|
||||
private:
|
||||
static QHash<QString,PluginContainer*> pluginCache();
|
||||
static QSettings *cacheFile();
|
||||
static QSettings &cacheFile();
|
||||
|
||||
static QHash<QString,PluginContainer*> s_pluginCache;
|
||||
static QDir *s_pluginDir;
|
||||
|
||||
ApplicationsList m_applications;
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include "plugins/backends/freedesktop/fredesktopnotification.h"
|
||||
#include "core/snore.h"
|
||||
#include "core/version.h"
|
||||
|
||||
#include <QtCore>
|
||||
#include <QtDBus>
|
||||
|
@ -126,16 +127,15 @@ QStringList FreedesktopFrontend::GetCapabilities()
|
|||
return QStringList()
|
||||
<< "body"
|
||||
// << "body-hyperlinks"
|
||||
// << "body-markup"
|
||||
<< "body-markup"
|
||||
<< "icon-static"
|
||||
<< "actions"
|
||||
;
|
||||
<< "actions";
|
||||
}
|
||||
|
||||
QString FreedesktopFrontend::GetServerInformation(QString& vendor, QString& version, QString& specVersion)
|
||||
{
|
||||
vendor = "Snore";
|
||||
version = snore()->version();
|
||||
version = Version::version();
|
||||
specVersion = "0";
|
||||
return "Snore";
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include <QMenu>
|
||||
#include <QAction>
|
||||
|
||||
#include "core/version.h"
|
||||
|
||||
using namespace Snore;
|
||||
|
||||
TrayIcon::TrayIcon()
|
||||
|
@ -36,7 +38,7 @@ void TrayIcon::initConextMenu(SnoreCore *snore){
|
|||
_trayIcon->setVisible(true);
|
||||
|
||||
_trayMenu = new QMenu("SnoreNotify");
|
||||
_trayMenu->addAction(QString("SnoreNotify ").append(_snore->version()));
|
||||
_trayMenu->addAction(QString("SnoreNotify ").append(Version::version()));
|
||||
_trayMenu->addSeparator();
|
||||
foreach(const QString &back,_snore->notificationBackends()){
|
||||
QAction *b= new QAction(back,this);
|
||||
|
|
Loading…
Reference in New Issue