improve plugin loading/error handling

This commit is contained in:
Patrick von Reth 2015-07-15 18:11:09 +02:00
parent eecd2b4217
commit 49a1f21e61
38 changed files with 163 additions and 201 deletions

View File

@ -56,7 +56,6 @@ SnorePlugin *PluginContainer::load()
m_plugin = qobject_cast<SnorePlugin *> (m_loader.instance()); m_plugin = qobject_cast<SnorePlugin *> (m_loader.instance());
m_plugin->m_container = this; m_plugin->m_container = this;
m_plugin->setDefaultSettings(); m_plugin->setDefaultSettings();
QMetaObject::invokeMethod(m_plugin, "load", Qt::QueuedConnection);
} }
return m_plugin; return m_plugin;
} }

View File

@ -35,14 +35,6 @@ SnorePlugin::SnorePlugin()
if (thread() != qApp->thread()) { if (thread() != qApp->thread()) {
snoreDebug(SNORE_WARNING) << "Plugin initialized in wrong thread."; snoreDebug(SNORE_WARNING) << "Plugin initialized in wrong thread.";
} }
connect(this, &SnorePlugin::loadedStateChanged, [this](bool b) {
snoreDebug(SNORE_DEBUG) << "Plugin:" << name() << "initialized" << b;
Q_ASSERT_X(!(b && m_initialized), Q_FUNC_INFO, "Plugin initialized multiple times.");
if (!b) {
disable();
}
m_initialized = b;
});
} }
SnorePlugin::~SnorePlugin() SnorePlugin::~SnorePlugin()
@ -50,11 +42,6 @@ SnorePlugin::~SnorePlugin()
snoreDebug(SNORE_DEBUG) << name() << this << "deleted"; snoreDebug(SNORE_DEBUG) << name() << this << "deleted";
} }
bool SnorePlugin::isLoaded() const
{
return m_initialized;
}
bool SnorePlugin::isEnabled() const bool SnorePlugin::isEnabled() const
{ {
return m_enabled; return m_enabled;
@ -106,6 +93,16 @@ const QString SnorePlugin::typeName() const
return SnorePlugin::typeToString(type()); return SnorePlugin::typeToString(type());
} }
bool SnorePlugin::isReady()
{
return m_error.isEmpty();
}
QString SnorePlugin::errorString() const
{
return m_error;
}
QString SnorePlugin::settingsVersion() const QString SnorePlugin::settingsVersion() const
{ {
return QLatin1String("v1"); return QLatin1String("v1");
@ -116,10 +113,16 @@ void SnorePlugin::setDefaultSettings()
setDefaultSettingsValue(QLatin1String("Enabled"), false, LOCAL_SETTING); setDefaultSettingsValue(QLatin1String("Enabled"), false, LOCAL_SETTING);
} }
void SnorePlugin::setErrorString(const QString &_error)
{
m_error = name() + tr(" encountered an error: ") + _error;
snoreDebug(SNORE_WARNING) << m_error;
disable();
emit error(_error);
}
void SnorePlugin::setEnabled(bool enabled) void SnorePlugin::setEnabled(bool enabled)
{ {
Q_ASSERT_X(!enabled || isLoaded(), Q_FUNC_INFO, "Plugin not initialized");
if (enabled != m_enabled) { if (enabled != m_enabled) {
emit enabledChanged(enabled); emit enabledChanged(enabled);
} }

View File

@ -53,13 +53,24 @@ public:
SnorePlugin(); SnorePlugin();
virtual ~SnorePlugin(); virtual ~SnorePlugin();
/**
* Sets the enabled state of the plugin to @param enabled.
*/
void setEnabled(bool enabled); void setEnabled(bool enabled);
/**
* Enables the plugin.
*/
void enable(); void enable();
/**
* Disables the plugin.
*/
void disable(); void disable();
bool isLoaded() const; /**
* Returns whether the Plugin is enabled.
*/
bool isEnabled() const; bool isEnabled() const;
/** /**
@ -77,6 +88,13 @@ public:
*/ */
const QString typeName() const; const QString typeName() const;
virtual bool isReady();
/**
* Returns the error string or an empty string.
*/
QString errorString() const;
QVariant settingsValue(const QString &key, SettingsType type = GLOBAL_SETTING) const; QVariant settingsValue(const QString &key, SettingsType type = GLOBAL_SETTING) const;
void setSettingsValue(const QString &key, const QVariant &settingsValue, SettingsType type = GLOBAL_SETTING); void setSettingsValue(const QString &key, const QVariant &settingsValue, SettingsType type = GLOBAL_SETTING);
void setDefaultSettingsValue(const QString &key, const QVariant &settingsValue, SettingsType type = GLOBAL_SETTING); void setDefaultSettingsValue(const QString &key, const QVariant &settingsValue, SettingsType type = GLOBAL_SETTING);
@ -84,11 +102,8 @@ public:
virtual PluginSettingsWidget *settingsWidget(); virtual PluginSettingsWidget *settingsWidget();
Q_SIGNALS: Q_SIGNALS:
void loadedStateChanged(bool loaded);
void enabledChanged(bool enabled); void enabledChanged(bool enabled);
void error(const QString &error);
private Q_SLOTS:
virtual void load() = 0;
protected: protected:
/** /**
@ -101,13 +116,15 @@ protected:
*/ */
virtual void setDefaultSettings(); virtual void setDefaultSettings();
void setErrorString(const QString &error);
private: private:
QString normaliseKey(const QString &key) const; QString normaliseKey(const QString &key) const;
void setDefaultSettingsPlugin(); void setDefaultSettingsPlugin();
bool m_initialized = false;
bool m_enabled = false; bool m_enabled = false;
PluginContainer *m_container = nullptr; PluginContainer *m_container = nullptr;
QString m_error;
friend class PluginContainer; friend class PluginContainer;

View File

@ -69,9 +69,19 @@ void SettingsDialog::initTabs()
addWidgets(ui->tabWidget_secondary_backends, ui->tab_secondaryBackends, SnorePlugin::SECONDARY_BACKEND); addWidgets(ui->tabWidget_secondary_backends, ui->tab_secondaryBackends, SnorePlugin::SECONDARY_BACKEND);
addWidgets(ui->tabWidget_frontends, ui->tab_frontends, SnorePlugin::FRONTEND); addWidgets(ui->tabWidget_frontends, ui->tab_frontends, SnorePlugin::FRONTEND);
addWidgets(ui->tabWidget_plugins, ui->tab_plugins, SnorePlugin::PLUGIN); addWidgets(ui->tabWidget_plugins, ui->tab_plugins, SnorePlugin::PLUGIN);
ui->errorLabel->setVisible(false);
ui->errorLineEdit->setVisible(false);
connect(&SnoreCore::instance(), &SnoreCore::prmaryNotificationBackendChanged, this, &SettingsDialog::loadPrimaryBackendBox);
connect(&SnoreCore::instance(), &SnoreCore::prmaryNotificationBackendError, [this](const QString & error) {
ui->errorLabel->setVisible(true);
ui->errorLineEdit->setVisible(true);
ui->errorLineEdit->setText(error);
});
} }
void Snore::SettingsDialog::on_pushButton_clicked() void SettingsDialog::on_pushButton_clicked()
{ {
SnoreCore::instance().displayExapleNotification(); SnoreCore::instance().displayExapleNotification();
} }
@ -79,22 +89,27 @@ void Snore::SettingsDialog::on_pushButton_clicked()
void SettingsDialog::load() void SettingsDialog::load()
{ {
snoreDebug(SNORE_DEBUG) << "loading"; snoreDebug(SNORE_DEBUG) << "loading";
loadPrimaryBackendBox(SnoreCore::instance().settingsValue(QLatin1String("PrimaryBackend"), LOCAL_SETTING).toString());
ui->timeoutSpinBox->setValue(SnoreCore::instance().settingsValue(QLatin1String("Timeout"), LOCAL_SETTING).toInt());
ui->disableNotificationSoundCheckBox->setChecked(SnoreCore::instance().settingsValue(QLatin1String("Silent"), LOCAL_SETTING).toBool());
for (auto widget : m_tabs) {
widget->loadSettings();
}
}
void SettingsDialog::loadPrimaryBackendBox(const QString &backend)
{
if (SnoreCore::instance().settingsValue(QLatin1String("PluginTypes"), LOCAL_SETTING).value<SnorePlugin::PluginTypes>() & SnorePlugin::BACKEND) { if (SnoreCore::instance().settingsValue(QLatin1String("PluginTypes"), LOCAL_SETTING).value<SnorePlugin::PluginTypes>() & SnorePlugin::BACKEND) {
ui->primaryBackendComboBox->clear(); ui->primaryBackendComboBox->clear();
QStringList list = SnoreCore::instance().pluginNames(SnorePlugin::BACKEND); QStringList list = SnoreCore::instance().pluginNames(SnorePlugin::BACKEND);
ui->primaryBackendComboBox->addItems(list); ui->primaryBackendComboBox->addItems(list);
ui->primaryBackendComboBox->setCurrentIndex(list.indexOf(SnoreCore::instance().settingsValue(QLatin1String("PrimaryBackend"), LOCAL_SETTING).toString())); ui->primaryBackendComboBox->setCurrentIndex(list.indexOf(backend));
ui->primaryBackendComboBox->setVisible(true); ui->primaryBackendComboBox->setVisible(true);
ui->primaryBackendLabel->setVisible(true); ui->primaryBackendLabel->setVisible(true);
} else { } else {
ui->primaryBackendComboBox->setVisible(false); ui->primaryBackendComboBox->setVisible(false);
ui->primaryBackendLabel->setVisible(false); ui->primaryBackendLabel->setVisible(false);
} }
ui->timeoutSpinBox->setValue(SnoreCore::instance().settingsValue(QLatin1String("Timeout"), LOCAL_SETTING).toInt());
ui->disableNotificationSoundCheckBox->setChecked(SnoreCore::instance().settingsValue(QLatin1String("Silent"), LOCAL_SETTING).toBool());
for (auto widget : m_tabs) {
widget->loadSettings();
}
} }
void SettingsDialog::save() void SettingsDialog::save()
@ -114,7 +129,7 @@ void SettingsDialog::save()
SnoreCore::instance().setSettingsValue(QLatin1String("Silent"), ui->disableNotificationSoundCheckBox->isChecked(), LOCAL_SETTING); SnoreCore::instance().setSettingsValue(QLatin1String("Silent"), ui->disableNotificationSoundCheckBox->isChecked(), LOCAL_SETTING);
if (dirty) { if (dirty) {
QMetaObject::invokeMethod(SnoreCorePrivate::instance(), "slotSyncSettings", Qt::QueuedConnection); SnoreCorePrivate::instance()->syncSettings();
} }
} }

View File

@ -71,6 +71,7 @@ public Q_SLOTS:
private Q_SLOTS: private Q_SLOTS:
void on_pushButton_clicked(); void on_pushButton_clicked();
void load(); void load();
void loadPrimaryBackendBox(const QString &backend);
void save(); void save();
private: private:

View File

@ -73,6 +73,20 @@
<item row="2" column="1"> <item row="2" column="1">
<widget class="QCheckBox" name="disableNotificationSoundCheckBox"/> <widget class="QCheckBox" name="disableNotificationSoundCheckBox"/>
</item> </item>
<item row="3" column="0">
<widget class="QLabel" name="errorLabel">
<property name="text">
<string>Error:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="errorLineEdit">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>

View File

@ -84,25 +84,13 @@ void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types)
case SnorePlugin::SECONDARY_BACKEND: case SnorePlugin::SECONDARY_BACKEND:
case SnorePlugin::FRONTEND: case SnorePlugin::FRONTEND:
case SnorePlugin::PLUGIN: case SnorePlugin::PLUGIN:
connect(plugin, &SnorePlugin::loadedStateChanged, [plugin](bool initialized) {
if (initialized) {
plugin->setEnabled(plugin->settingsValue(QLatin1String("Enabled"), LOCAL_SETTING).toBool()); plugin->setEnabled(plugin->settingsValue(QLatin1String("Enabled"), LOCAL_SETTING).toBool());
}
});
break; break;
default: default:
snoreDebug(SNORE_WARNING) << "Plugin Cache corrupted\n" << info->file() << info->type(); snoreDebug(SNORE_WARNING) << "Plugin Cache corrupted\n" << info->file() << info->type();
continue; continue;
} }
connect(plugin, &SnorePlugin::loadedStateChanged, [d, plugin](bool initialized) {
if (!initialized) {
//TODO: improve
d->m_pluginNames[plugin->type()].removeAll(plugin->name());
d->m_plugins.remove(qMakePair(plugin->type(), plugin->name()));
}
});
snoreDebug(SNORE_DEBUG) << info->name() << "is a" << info->type(); snoreDebug(SNORE_DEBUG) << info->name() << "is a" << info->type();
d->m_pluginNames[info->type()].append(info->name()); d->m_pluginNames[info->type()].append(info->name());
auto key = qMakePair(type, info->name()); auto key = qMakePair(type, info->name());

View File

@ -166,6 +166,16 @@ Q_SIGNALS:
*/ */
void notificationClosed(Snore::Notification); void notificationClosed(Snore::Notification);
/**
* This signal is emited in case the Primary backend encountered an error.
*/
void prmaryNotificationBackendError(const QString &error);
/**
* This signal is emited in case the Primary backend changed.
*/
void prmaryNotificationBackendChanged(const QString &erro);
private: private:
SnoreCore(QObject *parent); SnoreCore(QObject *parent);
SnoreCorePrivate *d_ptr; SnoreCorePrivate *d_ptr;

View File

@ -86,8 +86,10 @@ bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend)
} }
snoreDebug(SNORE_DEBUG) << "Setting Notification Backend to:" << backend; snoreDebug(SNORE_DEBUG) << "Setting Notification Backend to:" << backend;
SnoreBackend *b = qobject_cast<SnoreBackend *>(backends.value(backend)->load()); SnoreBackend *b = qobject_cast<SnoreBackend *>(backends.value(backend)->load());
if (!b->isLoaded()) { if (!b->isReady()) {
snoreDebug(SNORE_DEBUG) << "Failed to initialize" << b->name(); snoreDebug(SNORE_DEBUG) << "Backend not ready:" << b->errorString();
emit q->prmaryNotificationBackendError(b->errorString());
return false; return false;
} }
if (m_notificationBackend) { if (m_notificationBackend) {
@ -97,11 +99,10 @@ bool SnoreCorePrivate::setBackendIfAvailible(const QString &backend)
m_notificationBackend->enable(); m_notificationBackend->enable();
q->setSettingsValue(QLatin1String("PrimaryBackend"), backend, LOCAL_SETTING); q->setSettingsValue(QLatin1String("PrimaryBackend"), backend, LOCAL_SETTING);
connect(b, &SnoreBackend::loadedStateChanged, [this, b](bool initialized) { connect(b, &SnoreBackend::error, [this, b](const QString &) {
if (!initialized) {
slotInitPrimaryNotificationBackend(); slotInitPrimaryNotificationBackend();
}
}); });
emit q->prmaryNotificationBackendChanged(b->name());
return true; return true;
} }
return false; return false;
@ -159,7 +160,7 @@ void SnoreCorePrivate::setDefaultSettingsValueIntern(const QString &key, const Q
} }
} }
void SnoreCorePrivate::slotSyncSettings() void SnoreCorePrivate::syncSettings()
{ {
Q_Q(SnoreCore); Q_Q(SnoreCore);
QString newBackend = q->settingsValue(QLatin1String("PrimaryBackend"), LOCAL_SETTING).toString(); QString newBackend = q->settingsValue(QLatin1String("PrimaryBackend"), LOCAL_SETTING).toString();

View File

@ -71,6 +71,7 @@ public:
void startNotificationTimeoutTimer(Notification notification); void startNotificationTimeoutTimer(Notification notification);
void syncSettings();
private Q_SLOTS: private Q_SLOTS:
//TODO: find a better solutinon for the slots in this section //TODO: find a better solutinon for the slots in this section
friend class Snore::SnoreBackend; friend class Snore::SnoreBackend;
@ -79,8 +80,6 @@ private Q_SLOTS:
void slotNotificationClosed(Snore::Notification); void slotNotificationClosed(Snore::Notification);
void slotAboutToQuit(); void slotAboutToQuit();
void slotSyncSettings();
bool slotInitPrimaryNotificationBackend(); bool slotInitPrimaryNotificationBackend();
Q_SIGNALS: Q_SIGNALS:

View File

@ -12,6 +12,13 @@ using namespace Snore;
FreedesktopBackend::FreedesktopBackend() FreedesktopBackend::FreedesktopBackend()
{ {
m_interface = new org::freedesktop::Notifications(QLatin1String("org.freedesktop.Notifications"),
QLatin1String("/org/freedesktop/Notifications"),
QDBusConnection::sessionBus(), this);
QDBusPendingReply<QStringList> reply = m_interface->GetCapabilities();
reply.waitForFinished();
QStringList caps = reply.value();
m_supportsRichtext = caps.contains(QLatin1String("body-markup"));
connect(this, &SnoreSecondaryBackend::enabledChanged, [this](bool enabled) { connect(this, &SnoreSecondaryBackend::enabledChanged, [this](bool enabled) {
if (enabled) { if (enabled) {
connect(m_interface, &org::freedesktop::Notifications::ActionInvoked, this, &FreedesktopBackend::slotActionInvoked); connect(m_interface, &org::freedesktop::Notifications::ActionInvoked, this, &FreedesktopBackend::slotActionInvoked);
@ -24,18 +31,6 @@ FreedesktopBackend::FreedesktopBackend()
}); });
} }
void FreedesktopBackend::load()
{
m_interface = new org::freedesktop::Notifications(QLatin1String("org.freedesktop.Notifications"),
QLatin1String("/org/freedesktop/Notifications"),
QDBusConnection::sessionBus(), this);
QDBusPendingReply<QStringList> reply = m_interface->GetCapabilities();
reply.waitForFinished();
QStringList caps = reply.value();
m_supportsRichtext = caps.contains(QLatin1String("body-markup"));
emit loadedStateChanged(true);
}
bool FreedesktopBackend::canCloseNotification() const bool FreedesktopBackend::canCloseNotification() const
{ {
return true; return true;

View File

@ -22,9 +22,6 @@ public Q_SLOTS:
void slotActionInvoked(const uint &id, const QString &actionID); void slotActionInvoked(const uint &id, const QString &actionID);
void slotNotificationClosed(const uint &id, const uint &reason); void slotNotificationClosed(const uint &id, const uint &reason);
private Q_SLOTS:
void load() override;
private: private:
org::freedesktop::Notifications *m_interface; org::freedesktop::Notifications *m_interface;
QHash<uint, Snore::Notification> m_dbusIdMap; QHash<uint, Snore::Notification> m_dbusIdMap;

View File

@ -63,9 +63,13 @@ GrowlBackend::~GrowlBackend()
Growl::shutdown(); Growl::shutdown();
} }
void GrowlBackend::load() bool GrowlBackend::isReady()
{ {
emit loadedStateChanged(Growl::isRunning(GROWL_TCP, settingsValue(QLatin1String("Host")).toString().toUtf8().constData())); bool running = Growl::isRunning(GROWL_TCP, settingsValue(QLatin1String("Host")).toString().toUtf8().constData());
if (!running) {
setErrorString(tr("Growl is not running."));
}
return running;
} }
void GrowlBackend::slotRegisterApplication(const Application &application) void GrowlBackend::slotRegisterApplication(const Application &application)

View File

@ -33,6 +33,7 @@ public:
GrowlBackend(); GrowlBackend();
~GrowlBackend(); ~GrowlBackend();
Snore::PluginSettingsWidget *settingsWidget() override; Snore::PluginSettingsWidget *settingsWidget() override;
bool isReady() override;
protected: protected:
void setDefaultSettings() override; void setDefaultSettings() override;
@ -47,9 +48,6 @@ public Q_SLOTS:
void slotDeregisterApplication(const Snore::Application &application) override; void slotDeregisterApplication(const Snore::Application &application) override;
void slotNotify(Snore::Notification notification) override; void slotNotify(Snore::Notification notification) override;
private Q_SLOTS:
void load() override;
}; };
#endif // GROWL_BACKEND_H #endif // GROWL_BACKEND_H

View File

@ -33,9 +33,6 @@ public:
public Q_SLOTS: public Q_SLOTS:
void slotNotify(Snore::Notification notification) override; void slotNotify(Snore::Notification notification) override;
private Q_SLOTS:
void load() override;
}; };
#endif // OSXNOTIFICATIONCENTER_H #endif // OSXNOTIFICATIONCENTER_H

View File

@ -107,9 +107,4 @@ void OSXNotificationCenter::slotNotify(Snore::Notification notification)
slotNotificationDisplayed(notification); slotNotificationDisplayed(notification);
} }
void OSXNotificationCenter::load()
{
emit loadedStateChanged(true);
}

View File

@ -120,6 +120,7 @@ private:
SnarlBackend::SnarlBackend(): SnarlBackend::SnarlBackend():
m_eventLoop(new SnarlBackend::SnarlWidget(this)) m_eventLoop(new SnarlBackend::SnarlWidget(this))
{ {
} }
SnarlBackend::~SnarlBackend() SnarlBackend::~SnarlBackend()
@ -127,14 +128,6 @@ SnarlBackend::~SnarlBackend()
delete m_eventLoop; delete m_eventLoop;
} }
void SnarlBackend::load()
{
SnarlInterface *snarlInterface = new SnarlInterface();
emit loadedStateChanged(snarlInterface->IsSnarlRunning());
delete snarlInterface;
}
PluginSettingsWidget *SnarlBackend::settingsWidget() PluginSettingsWidget *SnarlBackend::settingsWidget()
{ {
return new SnarlSettings(this); return new SnarlSettings(this);
@ -150,6 +143,15 @@ bool SnarlBackend::canUpdateNotification() const
return true; return true;
} }
bool SnarlBackend::isReady()
{
bool running = SnarlInterface::IsSnarlRunning();
if (!running) {
setErrorString(tr("Snarl is not running."));
}
return running;
}
void SnarlBackend::setDefaultSettings() void SnarlBackend::setDefaultSettings()
{ {

View File

@ -34,6 +34,8 @@ public:
virtual bool canCloseNotification() const override; virtual bool canCloseNotification() const override;
virtual bool canUpdateNotification() const override; virtual bool canUpdateNotification() const override;
bool isReady() override;
protected: protected:
void setDefaultSettings() override; void setDefaultSettings() override;
@ -48,9 +50,6 @@ public Q_SLOTS:
void slotNotify(Snore::Notification notification); void slotNotify(Snore::Notification notification);
void slotCloseNotification(Snore::Notification notification); void slotCloseNotification(Snore::Notification notification);
private Q_SLOTS:
void load() override;
private: private:
QHash<LONG32, Snore::Notification> m_idMap; QHash<LONG32, Snore::Notification> m_idMap;

View File

@ -30,6 +30,23 @@ SnoreNotifier::SnoreNotifier():
m_widgets(3), m_widgets(3),
m_timer(new QTimer(this)) m_timer(new QTimer(this))
{ {
for (int i = 0; i < m_widgets.size(); ++i) {
NotifyWidget *w = new NotifyWidget(i, this);
m_widgets[i] = w;
connect(w, &NotifyWidget::dismissed, [this, w]() {
Notification notification = w->notification();
closeNotification(notification, Notification::DISMISSED);
slotCloseNotification(notification);
});
connect(w, &NotifyWidget::invoked, [this, w]() {
Notification notification = w->notification();
slotNotificationActionInvoked(notification);
closeNotification(notification, Notification::ACTIVATED);
slotCloseNotification(notification);
});
}
m_timer->setInterval(500); m_timer->setInterval(500);
connect(m_timer, &QTimer::timeout, [this]() { connect(m_timer, &QTimer::timeout, [this]() {
if (m_queue.isEmpty()) { if (m_queue.isEmpty()) {
@ -105,27 +122,6 @@ void SnoreNotifier::slotCloseNotification(Snore::Notification notification)
//the timer will show the next //the timer will show the next
} }
void SnoreNotifier::load()
{
for (int i = 0; i < m_widgets.size(); ++i) {
NotifyWidget *w = new NotifyWidget(i, this);
m_widgets[i] = w;
connect(w, &NotifyWidget::dismissed, [this, w]() {
Notification notification = w->notification();
closeNotification(notification, Notification::DISMISSED);
slotCloseNotification(notification);
});
connect(w, &NotifyWidget::invoked, [this, w]() {
Notification notification = w->notification();
slotNotificationActionInvoked(notification);
closeNotification(notification, Notification::ACTIVATED);
slotCloseNotification(notification);
});
}
emit loadedStateChanged(true);
}
bool SnoreNotifier::canCloseNotification() const bool SnoreNotifier::canCloseNotification() const
{ {
return true; return true;

View File

@ -44,11 +44,7 @@ public Q_SLOTS:
virtual void slotNotify(Snore::Notification notification) override; virtual void slotNotify(Snore::Notification notification) override;
virtual void slotCloseNotification(Snore::Notification notification) override; virtual void slotCloseNotification(Snore::Notification notification) override;
private Q_SLOTS:
void load() override;
private: private:
QList<Snore::Notification> m_queue; QList<Snore::Notification> m_queue;
QVector<NotifyWidget *> m_widgets; QVector<NotifyWidget *> m_widgets;
QTimer *m_timer; QTimer *m_timer;

View File

@ -14,13 +14,13 @@
using namespace Snore; using namespace Snore;
void SnoreToast::load() bool SnoreToast::isReady()
{ {
if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS8) { if (QSysInfo::windowsVersion() < QSysInfo::WV_WINDOWS8) {
snoreDebug(SNORE_DEBUG) << "SnoreToast does not work on windows" << QSysInfo::windowsVersion(); setErrorString(name() + tr(" needs at least Windows 8 to run."));
emit loadedStateChanged(false); return false;
} }
emit loadedStateChanged(true); return true;
} }
bool SnoreToast::canCloseNotification() const bool SnoreToast::canCloseNotification() const
@ -129,12 +129,11 @@ QProcess *SnoreToast::createProcess(Notification noti)
}); });
connect(p, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error), [this, p, noti](QProcess::ProcessError) { connect(p, static_cast<void (QProcess::*)(QProcess::ProcessError)>(&QProcess::error), [this, p, noti](QProcess::ProcessError) {
snoreDebug(SNORE_WARNING) << "SnoreToasts seems to be broken:" << p->errorString(); setErrorString(name() + tr("encoutered an error: ") + p->errorString());
snoreDebug(SNORE_DEBUG) << p->readAll(); snoreDebug(SNORE_DEBUG) << p->readAll();
if (noti.isValid()) { if (noti.isValid()) {
closeNotification(noti, Notification::NONE); closeNotification(noti, Notification::NONE);
} }
emit loadedStateChanged(false);
p->deleteLater(); p->deleteLater();
}); });
connect(qApp, &QApplication::aboutToQuit, p, &QProcess::kill); connect(qApp, &QApplication::aboutToQuit, p, &QProcess::kill);

View File

@ -15,14 +15,12 @@ public:
virtual bool canCloseNotification() const override; virtual bool canCloseNotification() const override;
bool isReady() override;
public Q_SLOTS: public Q_SLOTS:
void slotNotify(Snore::Notification notification) override; void slotNotify(Snore::Notification notification) override;
void slotRegisterApplication(const Snore::Application &application) override; void slotRegisterApplication(const Snore::Application &application) override;
void slotCloseNotification(Snore::Notification notification) override; void slotCloseNotification(Snore::Notification notification) override;
private Q_SLOTS:
void load() override;
private: private:
QString appId(const Snore::Application &application); QString appId(const Snore::Application &application);

View File

@ -6,10 +6,11 @@
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
using namespace Snore; using namespace Snore;
void TrayIconNotifer::load() TrayIconNotifer::TrayIconNotifer()
{ {
connect(this, &TrayIconNotifer::enabledChanged, [this](bool) {
m_currentlyDisplaying = false; m_currentlyDisplaying = false;
emit loadedStateChanged(true); });
} }
bool TrayIconNotifer::canCloseNotification() const bool TrayIconNotifer::canCloseNotification() const

View File

@ -15,7 +15,7 @@ class TrayIconNotifer: public Snore::SnoreBackend
Q_INTERFACES(Snore::SnoreBackend) Q_INTERFACES(Snore::SnoreBackend)
Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0" FILE "plugin.json") Q_PLUGIN_METADATA(IID "org.Snore.NotificationBackend/1.0" FILE "plugin.json")
public: public:
TrayIconNotifer() = default; TrayIconNotifer();
~TrayIconNotifer() = default; ~TrayIconNotifer() = default;
virtual bool canCloseNotification() const override; virtual bool canCloseNotification() const override;
@ -26,9 +26,6 @@ public Q_SLOTS:
void slotRegisterApplication(const Snore::Application &application) override; void slotRegisterApplication(const Snore::Application &application) override;
void slotDeregisterApplication(const Snore::Application &application) override; void slotDeregisterApplication(const Snore::Application &application) override;
private Q_SLOTS:
void load() override;
private: private:
QSystemTrayIcon *trayIcon(const Snore::Application &app); QSystemTrayIcon *trayIcon(const Snore::Application &app);
QList<Snore::Notification > m_notificationQue; QList<Snore::Notification > m_notificationQue;

View File

@ -37,12 +37,10 @@ FreedesktopFrontend::FreedesktopFrontend()
QDBusConnection dbus = QDBusConnection::sessionBus(); QDBusConnection dbus = QDBusConnection::sessionBus();
if (dbus.registerService(QLatin1String("org.freedesktop.Notifications"))) { if (dbus.registerService(QLatin1String("org.freedesktop.Notifications"))) {
if (!dbus.registerObject(QLatin1String("/org/freedesktop/Notifications"), this)) { if (!dbus.registerObject(QLatin1String("/org/freedesktop/Notifications"), this)) {
snoreDebug(SNORE_WARNING) << "Failed to initialize" << name() << "failed to register object"; setErrorString(tr("Failed to register dbus object."));
emit loadedStateChanged(false);
} }
} else { } else {
snoreDebug(SNORE_WARNING) << "Failed to initialize" << name() << "failed to register service"; setErrorString(tr("Failed to register dbus service."));
emit loadedStateChanged(false);
} }
} else { } else {
QDBusConnection dbus = QDBusConnection::sessionBus(); QDBusConnection dbus = QDBusConnection::sessionBus();
@ -54,14 +52,8 @@ FreedesktopFrontend::FreedesktopFrontend()
}); });
} }
void FreedesktopFrontend::load()
{
emit loadedStateChanged(true);
}
void FreedesktopFrontend::slotActionInvoked(Notification notification) void FreedesktopFrontend::slotActionInvoked(Notification notification)
{ {
if (notification.isActiveIn(this)) { if (notification.isActiveIn(this)) {
if (notification.actionInvoked().isValid()) { if (notification.actionInvoked().isValid()) {
emit ActionInvoked(notification.id(), QString::number(notification.actionInvoked().id())); emit ActionInvoked(notification.id(), QString::number(notification.actionInvoked().id()));

View File

@ -46,9 +46,6 @@ public Q_SLOTS:
void slotActionInvoked(Snore::Notification notification) override; void slotActionInvoked(Snore::Notification notification) override;
void slotNotificationClosed(Snore::Notification notification) override; void slotNotificationClosed(Snore::Notification notification) override;
private Q_SLOTS:
void load() override;
private: private:
Snore::Alert m_alert; Snore::Alert m_alert;
NotificationsAdaptor *m_adaptor; NotificationsAdaptor *m_adaptor;

View File

@ -51,11 +51,6 @@ PushoverFrontend::PushoverFrontend()
}); });
} }
void PushoverFrontend::load()
{
emit loadedStateChanged(true);
}
PluginSettingsWidget *PushoverFrontend::settingsWidget() PluginSettingsWidget *PushoverFrontend::settingsWidget()
{ {
return new PushoverSettings(this); return new PushoverSettings(this);

View File

@ -49,9 +49,6 @@ protected:
public Q_SLOTS: public Q_SLOTS:
void slotActionInvoked(Snore::Notification notification); void slotActionInvoked(Snore::Notification notification);
private Q_SLOTS:
void load() override;
Q_SIGNALS: Q_SIGNALS:
void loggedInChanged(bool isLoggedIn); void loggedInChanged(bool isLoggedIn);
void error(QString error); void error(QString error);

View File

@ -32,9 +32,14 @@ SnarlNetworkFrontend::SnarlNetworkFrontend():
{ {
connect(this, &SnarlNetworkFrontend::enabledChanged, [this](bool enabled) { connect(this, &SnarlNetworkFrontend::enabledChanged, [this](bool enabled) {
if (enabled) { if (enabled) {
tcpServer = new QTcpServer(this);
if (!tcpServer->listen(QHostAddress::Any, port)) {
setErrorString(tr("The port is already used by a different application."));
return;
}
connect(tcpServer, &QTcpServer::newConnection, this, SnarlNetworkFrontend::handleConnection); connect(tcpServer, &QTcpServer::newConnection, this, SnarlNetworkFrontend::handleConnection);
} else { } else {
disconnect(tcpServer, &QTcpServer::newConnection, this, SnarlNetworkFrontend::handleConnection); tcpServer->deleteLater();
} }
}); });
} }
@ -44,18 +49,6 @@ SnarlNetworkFrontend::~SnarlNetworkFrontend()
delete parser; delete parser;
} }
void SnarlNetworkFrontend::load()
{
tcpServer = new QTcpServer(this);
if (!tcpServer->listen(QHostAddress::Any, port)) {
snoreDebug(SNORE_DEBUG) << "The port is already used";
emit loadedStateChanged(false);
} else {
std::cout << "The Snarl Network Protokoll is developed for Snarl <http://www.fullphat.net/>" << std::endl;
}
emit loadedStateChanged(true);
}
void SnarlNetworkFrontend::slotActionInvoked(Snore::Notification notification) void SnarlNetworkFrontend::slotActionInvoked(Snore::Notification notification)
{ {

View File

@ -43,7 +43,6 @@ public Q_SLOTS:
void slotNotificationClosed(Snore::Notification notification) override; void slotNotificationClosed(Snore::Notification notification) override;
private Q_SLOTS: private Q_SLOTS:
void load() override;
void handleConnection(); void handleConnection();
void handleMessages(); void handleMessages();

View File

@ -59,11 +59,6 @@ void NotifyMyAndroid::slotNotify(Notification notification)
} }
void NotifyMyAndroid::load()
{
emit loadedStateChanged(true);
}
PluginSettingsWidget *NotifyMyAndroid::settingsWidget() PluginSettingsWidget *NotifyMyAndroid::settingsWidget()
{ {
return new NotifyMyAndroidSettings(this); return new NotifyMyAndroidSettings(this);

View File

@ -39,9 +39,6 @@ protected:
public Q_SLOTS: public Q_SLOTS:
void slotNotify(Snore::Notification notification) override; void slotNotify(Snore::Notification notification) override;
private Q_SLOTS:
void load() override;
private: private:
QNetworkAccessManager m_manager; QNetworkAccessManager m_manager;

View File

@ -120,11 +120,6 @@ void Pushover::slotNotify(Notification notification)
} }
void Pushover::load()
{
emit loadedStateChanged(true);
}
PluginSettingsWidget *Pushover::settingsWidget() PluginSettingsWidget *Pushover::settingsWidget()
{ {
return new PushoverSettings(this); return new PushoverSettings(this);

View File

@ -39,9 +39,6 @@ protected:
public Q_SLOTS: public Q_SLOTS:
void slotNotify(Snore::Notification notification) override; void slotNotify(Snore::Notification notification) override;
private Q_SLOTS:
void load() override;
private: private:
QNetworkAccessManager m_manager; QNetworkAccessManager m_manager;

View File

@ -34,12 +34,6 @@ Sound::Sound():
}); });
} }
void Sound::load()
{
m_player->setVolume(settingsValue(QLatin1String("Volume")).toInt());
emit loadedStateChanged(true);
}
PluginSettingsWidget *Sound::settingsWidget() PluginSettingsWidget *Sound::settingsWidget()
{ {
return new SoundSettings(this); return new SoundSettings(this);
@ -56,6 +50,7 @@ void Sound::slotNotificationDisplayed(Snore::Notification notification)
if (notification.hints().value("silent").toBool()) { if (notification.hints().value("silent").toBool()) {
return; return;
} }
m_player->setVolume(settingsValue(QLatin1String("Volume")).toInt());
QString sound = notification.hints().value("sound").toString(); QString sound = notification.hints().value("sound").toString();
if (sound.isEmpty()) { if (sound.isEmpty()) {

View File

@ -39,9 +39,6 @@ protected:
public Q_SLOTS: public Q_SLOTS:
void slotNotificationDisplayed(Snore::Notification notification) override; void slotNotificationDisplayed(Snore::Notification notification) override;
private Q_SLOTS:
void load() override;
private: private:
QMediaPlayer *m_player; QMediaPlayer *m_player;
}; };

View File

@ -77,11 +77,6 @@ void Toasty::slotNotify(Notification notification)
} }
void Toasty::load()
{
emit loadedStateChanged(true);
}
PluginSettingsWidget *Toasty::settingsWidget() PluginSettingsWidget *Toasty::settingsWidget()
{ {
return new ToastySettings(this); return new ToastySettings(this);

View File

@ -39,9 +39,6 @@ protected:
public Q_SLOTS: public Q_SLOTS:
void slotNotify(Snore::Notification notification) override; void slotNotify(Snore::Notification notification) override;
private Q_SLOTS:
void load() override;
private: private:
QNetworkAccessManager m_manager; QNetworkAccessManager m_manager;