Don't set plugin name in constructor.

This commit is contained in:
Patrick von Reth 2015-06-24 12:06:27 +02:00
parent 8fc1907d6d
commit 051e2d1818
29 changed files with 87 additions and 167 deletions

View File

@ -54,8 +54,7 @@ SnorePlugin *PluginContainer::load()
return nullptr;
}
SnorePlugin *plugin = qobject_cast<SnorePlugin *> (m_loader.instance());
Q_ASSERT_X(m_pluginName == plugin->name(), Q_FUNC_INFO, "The plugin name is different to the one in the meta data.");
plugin->m_type = type();
plugin->m_container = this;
return plugin;
}

View File

@ -29,28 +29,27 @@
using namespace Snore;
SnorePlugin::SnorePlugin(const QString &name) :
m_name(name)
SnorePlugin::SnorePlugin()
{
Q_ASSERT_X(thread() == qApp->thread(), Q_FUNC_INFO, "Plugin initialized in wrong thread");
if (thread() != qApp->thread()) {
snoreDebug(SNORE_WARNING) << "Plugin initialized in wrong thread.";
}
setDefaultValue("Enabled", false, LOCAL_SETTING);
}
SnorePlugin::~SnorePlugin()
{
snoreDebug(SNORE_DEBUG) << m_name << this << "deleted";
snoreDebug(SNORE_DEBUG) << name() << this << "deleted";
}
bool SnorePlugin::initialize()
{
setDefaultValue("Enabled", false, LOCAL_SETTING);
if (m_initialized) {
qFatal("Something went wrong, plugin %s is already initialized", this->name().toLatin1().constData());
return false;
}
snoreDebug(SNORE_DEBUG) << "Initialize" << m_name << this;
snoreDebug(SNORE_DEBUG) << "Initialize" << name() << this;
m_initialized = true;
return true;
}
@ -86,22 +85,24 @@ Snore::PluginSettingsWidget *SnorePlugin::settingsWidget()
QString SnorePlugin::normaliseKey(const QString &key) const
{
return QString("%1/%2.%3").arg(m_name, key, settingsVersion());
return QString("%1/%2.%3").arg(name(), key, settingsVersion());
}
const QString &SnorePlugin::name() const
{
return m_name;
Q_ASSERT_X(m_container, Q_FUNC_INFO, "Plugin container not set.");
return m_container->name();
}
SnorePlugin::PluginTypes SnorePlugin::type() const
{
return m_type;
Q_ASSERT_X(m_container, Q_FUNC_INFO, "Plugin container not set.");
return m_container->type();
}
const QString SnorePlugin::typeName() const
{
return SnorePlugin::typeToString(m_type);
return SnorePlugin::typeToString(type());
}
QString SnorePlugin::settingsVersion() const
@ -112,7 +113,7 @@ QString SnorePlugin::settingsVersion() const
bool SnorePlugin::deinitialize()
{
if (m_initialized) {
snoreDebug(SNORE_DEBUG) << "Deinitialize" << m_name << this;
snoreDebug(SNORE_DEBUG) << "Deinitialize" << name() << this;
m_initialized = false;
return true;
}

View File

@ -28,6 +28,8 @@
namespace Snore
{
class PluginContainer;
class SNORE_EXPORT SnorePlugin : public QObject
{
Q_OBJECT
@ -48,7 +50,7 @@ public:
static QString typeToString(const PluginTypes t);
static QList<PluginTypes> types();
SnorePlugin(const QString &name);
SnorePlugin();
virtual ~SnorePlugin();
virtual bool initialize();
virtual bool deinitialize();
@ -68,12 +70,10 @@ protected:
virtual QString settingsVersion() const;
private:
SnorePlugin() = delete;
QString normaliseKey(const QString &key) const;
QString m_name;
bool m_initialized = false;
PluginTypes m_type = NONE;
PluginContainer *m_container = nullptr;
friend class PluginContainer;

View File

@ -29,12 +29,6 @@
using namespace Snore;
SnoreBackend::SnoreBackend(const QString &name) :
SnorePlugin(name)
{
}
SnoreBackend::~SnoreBackend()
{
snoreDebug(SNORE_DEBUG) << "Deleting" << name();
@ -102,12 +96,6 @@ void SnoreBackend::slotCloseNotification(Notification notification)
Q_UNUSED(notification)
}
SnoreSecondaryBackend::SnoreSecondaryBackend(const QString &name):
SnorePlugin(name)
{
}
SnoreSecondaryBackend::~SnoreSecondaryBackend()
{
snoreDebug(SNORE_DEBUG) << "Deleting" << name();

View File

@ -31,7 +31,7 @@ class SNORE_EXPORT SnoreBackend : public SnorePlugin
Q_OBJECT
Q_INTERFACES(Snore::SnorePlugin)
public:
SnoreBackend(const QString &name);
SnoreBackend() = default;
virtual ~SnoreBackend();
virtual bool initialize() override;
virtual bool deinitialize() override;
@ -73,7 +73,7 @@ class SNORE_EXPORT SnoreSecondaryBackend : public SnorePlugin
Q_OBJECT
Q_INTERFACES(Snore::SnorePlugin Snore::SnorePlugin)
public:
SnoreSecondaryBackend(const QString &name);
SnoreSecondaryBackend() = default;
virtual ~SnoreSecondaryBackend();
virtual bool initialize();
virtual bool deinitialize();

View File

@ -21,12 +21,6 @@
using namespace Snore;
SnoreFrontend::SnoreFrontend(const QString &name) :
SnorePlugin(name)
{
}
SnoreFrontend::~SnoreFrontend()
{
snoreDebug(SNORE_DEBUG) << "Deleting" << name();

View File

@ -31,7 +31,7 @@ class SNORE_EXPORT SnoreFrontend: public SnorePlugin
Q_OBJECT
Q_INTERFACES(Snore::SnorePlugin)
public:
SnoreFrontend(const QString &name);
SnoreFrontend() = default;
virtual ~SnoreFrontend();
virtual bool initialize() override;

View File

@ -29,19 +29,12 @@ using namespace Snore;
GrowlBackend *GrowlBackend::s_instance = nullptr;
GrowlBackend::GrowlBackend():
SnoreBackend("Growl")
{
setDefaultValue("Host", "localhost");
setDefaultValue("Password", "");
}
GrowlBackend::~GrowlBackend()
{
}
bool GrowlBackend::initialize()
{
setDefaultValue("Host", "localhost");
setDefaultValue("Password", "");
s_instance = this;
auto func = [](growl_callback_data * data)->void {
snoreDebug(SNORE_DEBUG) << data->id << QString(data->reason) << QString(data->data);

View File

@ -30,8 +30,8 @@ class GrowlBackend: public Snore::SnoreBackend
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0" FILE "plugin.json")
public:
GrowlBackend();
~GrowlBackend();
GrowlBackend() = default;
~GrowlBackend() = default;
bool initialize() override;
bool deinitialize() override;
Snore::PluginSettingsWidget *settingsWidget() override;

View File

@ -111,19 +111,10 @@ private:
};
SnarlBackend::SnarlBackend():
SnoreBackend("Snarl")
{
setDefaultValue("Password", QString());
}
SnarlBackend::~SnarlBackend()
{
}
bool SnarlBackend::initialize()
{
setDefaultValue("Password", QString());
SnarlInterface *snarlInterface = new SnarlInterface();
if (!snarlInterface->IsSnarlRunning()) {
snoreDebug(SNORE_WARNING) << "Snarl is not running";

View File

@ -27,8 +27,8 @@ class SnarlBackend: public Snore::SnoreBackend
Q_INTERFACES(Snore::SnoreBackend)
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0" FILE "plugin.json")
public:
SnarlBackend();
~SnarlBackend();
SnarlBackend() = default;
~SnarlBackend() = default;
bool initialize() override;
bool deinitialize() override;
Snore::PluginSettingsWidget *settingsWidget() override;

View File

@ -27,18 +27,16 @@
using namespace Snore;
SnoreNotifier::SnoreNotifier():
SnoreBackend("Snore"),
m_widgets(3),
m_timer(new QTimer(this))
{
setDefaultValue("Position", Qt::TopRightCorner);
m_timer->setInterval(500);
connect(m_timer, &QTimer::timeout, [this]() {
if (m_queue.isEmpty()) {
snoreDebug(SNORE_DEBUG) << "queue is empty";
m_timer->stop();
} else {
foreach(NotifyWidget * w, m_widgets) {
for(NotifyWidget * w : m_widgets) {
if (w->acquire()) {
Notification notification = m_queue.takeFirst();
w->display(notification);
@ -88,7 +86,7 @@ void SnoreNotifier::slotNotify(Snore::Notification notification)
}
} else {
if (m_queue.isEmpty()) {
foreach(NotifyWidget * w, m_widgets) {
for(NotifyWidget * w : m_widgets) {
if (w->acquire()) {
display(w, notification);
return;
@ -109,6 +107,8 @@ void SnoreNotifier::slotCloseNotification(Snore::Notification notification)
bool SnoreNotifier::initialize()
{
setDefaultValue("Position", Qt::TopRightCorner);
if (SnoreBackend::initialize()) {
for (int i = 0; i < m_widgets.size(); ++i) {
NotifyWidget *w = new NotifyWidget(i, this);

View File

@ -35,8 +35,8 @@ public:
bool initialize() override;
bool deinitialize() override;
virtual bool canCloseNotification() const override;
virtual bool canUpdateNotification() const override;
bool canCloseNotification() const override;
bool canUpdateNotification() const override;
Snore::PluginSettingsWidget *settingsWidget() override;

View File

@ -14,16 +14,6 @@
using namespace Snore;
SnoreToast::SnoreToast():
SnoreBackend("Windows 8")
{
}
SnoreToast::~SnoreToast()
{
}
bool SnoreToast::initialize()
{
if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS8) {

View File

@ -10,8 +10,8 @@ class SnoreToast : public Snore::SnoreBackend
Q_INTERFACES(Snore::SnoreBackend)
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0" FILE "plugin.json")
public:
SnoreToast();
~SnoreToast();
SnoreToast() = default;
~SnoreToast() = default;
virtual bool initialize() override;
virtual bool canCloseNotification() const override;

View File

@ -6,17 +6,6 @@
#include <QSystemTrayIcon>
using namespace Snore;
TrayIconNotifer::TrayIconNotifer() :
SnoreBackend("System Tray Icon"),
m_currentlyDisplaying(false)
{
}
TrayIconNotifer::~TrayIconNotifer()
{
}
bool TrayIconNotifer::deinitialize()
{

View File

@ -15,8 +15,8 @@ class TrayIconNotifer: public Snore::SnoreBackend
Q_INTERFACES(Snore::SnoreBackend)
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0" FILE "plugin.json")
public:
TrayIconNotifer();
virtual ~TrayIconNotifer() override;
TrayIconNotifer() = default;
~TrayIconNotifer() = default;
virtual bool deinitialize() override;
virtual bool canCloseNotification() const override;
@ -31,7 +31,7 @@ private:
QSystemTrayIcon *trayIcon(const Snore::Application &app);
QList<Snore::Notification > m_notificationQue;
Snore::Notification m_displayed;
bool m_currentlyDisplaying;
bool m_currentlyDisplaying = false;
private slots:
void displayNotification(QSystemTrayIcon *icon);

View File

@ -29,16 +29,6 @@
using namespace Snore;
FreedesktopFrontend::FreedesktopFrontend():
SnoreFrontend("Freedesktop")
{
}
FreedesktopFrontend::~FreedesktopFrontend()
{
}
bool FreedesktopFrontend::initialize()
{
m_adaptor = new NotificationsAdaptor(this);

View File

@ -29,10 +29,10 @@ class FreedesktopFrontend : public Snore::SnoreFrontend
Q_INTERFACES(Snore::SnoreFrontend)
Q_PLUGIN_METADATA(IID "org.Snore.NotificationFrontend/1.0" FILE "plugin.json")
public:
FreedesktopFrontend();
~FreedesktopFrontend();
virtual bool initialize() override;
virtual bool deinitialize() override;
FreedesktopFrontend() = default;
~FreedesktopFrontend() = default;
bool initialize() override;
bool deinitialize() override;
uint 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);
void CloseNotification(uint id);

View File

@ -26,16 +26,6 @@
#include <iostream>
using namespace Snore;
SnarlNetworkFrontend::SnarlNetworkFrontend():
SnoreFrontend("SnarlNetwork")
{
}
SnarlNetworkFrontend::~SnarlNetworkFrontend()
{
}
bool SnarlNetworkFrontend::initialize()
{
parser = new Parser(this);

View File

@ -35,8 +35,8 @@ public:
static const int port = 9887;
public:
SnarlNetworkFrontend();
~SnarlNetworkFrontend();
SnarlNetworkFrontend() = default;
~SnarlNetworkFrontend() = default;
virtual bool initialize() override;
virtual bool deinitialize() override;

View File

@ -26,17 +26,6 @@
using namespace Snore;
NotifyMyAndroid::NotifyMyAndroid():
SnoreSecondaryBackend("NotifyMyAndroid")
{
setDefaultValue("ApiKey", "");
}
NotifyMyAndroid::~NotifyMyAndroid()
{
}
void NotifyMyAndroid::slotNotify(Notification notification)
{
QString key = value("ApiKey").toString();
@ -67,6 +56,12 @@ void NotifyMyAndroid::slotNotify(Notification notification)
}
bool NotifyMyAndroid::initialize()
{
setDefaultValue("ApiKey", "");
return SnoreSecondaryBackend::initialize();
}
PluginSettingsWidget *NotifyMyAndroid::settingsWidget()
{
return new NotifyMyAndroidSettings(this);

View File

@ -28,8 +28,10 @@ class NotifyMyAndroid : public Snore::SnoreSecondaryBackend
Q_INTERFACES(Snore::SnoreSecondaryBackend)
Q_PLUGIN_METADATA(IID "org.Snore.SecondaryNotificationBackend/1.0" FILE "plugin.json")
public:
NotifyMyAndroid();
~NotifyMyAndroid();
NotifyMyAndroid() = default;
~NotifyMyAndroid() = default;
virtual bool initialize() override;
Snore::PluginSettingsWidget *settingsWidget() override;

View File

@ -27,19 +27,6 @@
using namespace Snore;
Pushover::Pushover():
SnoreSecondaryBackend("Pushover")
{
setDefaultValue("UserKey", "");
setDefaultValue("Sound", "pushover", LOCAL_SETTING);
setDefaultValue("Devices", "", LOCAL_SETTING);
}
Pushover::~Pushover()
{
}
void Pushover::slotNotify(Notification notification)
{
QString key = value("ApiKey").toString();
@ -109,6 +96,14 @@ void Pushover::slotNotify(Notification notification)
}
bool Pushover::initialize()
{
setDefaultValue("UserKey", "");
setDefaultValue("Sound", "pushover", LOCAL_SETTING);
setDefaultValue("Devices", "", LOCAL_SETTING);
return SnoreSecondaryBackend::initialize();
}
PluginSettingsWidget *Pushover::settingsWidget()
{
return new PushoverSettings(this);

View File

@ -28,8 +28,10 @@ class Pushover : public Snore::SnoreSecondaryBackend
Q_INTERFACES(Snore::SnoreSecondaryBackend)
Q_PLUGIN_METADATA(IID "org.Snore.SecondaryNotificationBackend/1.0" FILE "plugin.json")
public:
Pushover();
~Pushover();
Pushover() = default;
~Pushover() = default;
bool initialize() override;
Snore::PluginSettingsWidget *settingsWidget() override;

View File

@ -24,11 +24,8 @@
using namespace Snore;
Sound::Sound():
SnoreSecondaryBackend("Sound"),
m_player(new QMediaPlayer(this))
{
setDefaultValue("Volume", 50);
m_player->setVolume(value("Volume").toInt());
// connect(m_player,QMediaPlayer::positionChanged,[](qint64 pos){
// snoreDebug(SNORE_DEBUG) << "Player: " << pos;
// });
@ -37,9 +34,12 @@ Sound::Sound():
});
}
Sound::~Sound()
bool Sound::initialize()
{
setDefaultValue("Volume", 50);
m_player->setVolume(value("Volume").toInt());
return SnoreSecondaryBackend::initialize();
}
PluginSettingsWidget *Sound::settingsWidget()

View File

@ -20,6 +20,8 @@
#include "libsnore/plugins/snorebackend.h"
class QMediaPlayer;
class Sound : public Snore::SnoreSecondaryBackend
{
Q_OBJECT
@ -27,14 +29,16 @@ class Sound : public Snore::SnoreSecondaryBackend
Q_PLUGIN_METADATA(IID "org.Snore.SecondaryNotificationBackend/1.0" FILE "plugin.json")
public:
Sound();
~Sound();
~Sound() = default;
virtual bool initialize() override;
Snore::PluginSettingsWidget *settingsWidget() override;
public slots:
void slotNotificationDisplayed(Snore::Notification notification) override;
private:
class QMediaPlayer *m_player;
QMediaPlayer *m_player;
};
#endif // SOUND_H

View File

@ -27,17 +27,6 @@
using namespace Snore;
Toasty::Toasty():
SnoreSecondaryBackend("Toasty")
{
setDefaultValue("DeviceID", "");
}
Toasty::~Toasty()
{
}
void Toasty::slotNotify(Notification notification)
{
QString key = value("DeviceID").toString();
@ -89,6 +78,12 @@ void Toasty::slotNotify(Notification notification)
}
bool Toasty::initialize()
{
setDefaultValue("DeviceID", "");
return SnoreSecondaryBackend::initialize();
}
PluginSettingsWidget *Toasty::settingsWidget()
{
return new ToastySettings(this);

View File

@ -28,8 +28,10 @@ class Toasty : public Snore::SnoreSecondaryBackend
Q_INTERFACES(Snore::SnoreSecondaryBackend)
Q_PLUGIN_METADATA(IID "org.Snore.SecondaryNotificationBackend/1.0" FILE "plugin.json")
public:
Toasty();
~Toasty();
Toasty() = default;
~Toasty() = default;
bool initialize() override;
Snore::PluginSettingsWidget *settingsWidget() override;