set default settings befor before initialize is called
This commit is contained in:
parent
92aa7901d9
commit
3f9d5ec325
|
@ -32,7 +32,7 @@ Alert::Alert(const QString &name, const Icon &icon):
|
|||
{}
|
||||
|
||||
Alert::Alert(const QString &key, const QString &name, const Icon &icon):
|
||||
d(new AlertData(key,name,icon))
|
||||
d(new AlertData(key, name, icon))
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -48,7 +48,6 @@ public:
|
|||
*/
|
||||
explicit Alert(const QString &name, const Icon &icon);
|
||||
|
||||
|
||||
/**
|
||||
* Creates an alert.
|
||||
* @param name the key of the Alert used in Application::alerts().
|
||||
|
@ -70,7 +69,6 @@ public:
|
|||
Alert &operator=(const Alert &other);
|
||||
~Alert();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the key of the Alert, used in Application::alerts().
|
||||
* Might be identically to name().
|
||||
|
|
|
@ -33,7 +33,7 @@ Application::Application(const QString &name, const Icon &icon) :
|
|||
}
|
||||
|
||||
Application::Application(const QString &key, const QString &name, const Icon &icon) :
|
||||
d(new ApplicationData(key,name,icon))
|
||||
d(new ApplicationData(key, name, icon))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ Application::~Application()
|
|||
void Application::addAlert(const Alert &alert)
|
||||
{
|
||||
Q_ASSERT_X(!SnoreCore::instance().aplications().contains(key()), Q_FUNC_INFO,
|
||||
"Alerts must be added before the application is Registered." );
|
||||
"Alerts must be added before the application is Registered.");
|
||||
d->m_alerts.insert(alert.key(), alert);
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,6 @@ public:
|
|||
*/
|
||||
explicit Application(const QString &key, const QString &name, const Icon &icon);
|
||||
|
||||
|
||||
/**
|
||||
* The copy constructor
|
||||
* @param other
|
||||
|
|
|
@ -47,7 +47,6 @@ public:
|
|||
|
||||
static Icon defaultIcon();
|
||||
|
||||
|
||||
/**
|
||||
* Creates an Icon from an QImage
|
||||
* @param img the image
|
||||
|
|
|
@ -125,7 +125,7 @@ const SnorePlugin *NotificationData::source() const
|
|||
|
||||
bool NotificationData::sourceAndTargetAreSimilar(const SnorePlugin *target)
|
||||
{
|
||||
if(source() && source()->name() == target->name()) {
|
||||
if (source() && source()->name() == target->name()) {
|
||||
snoreDebug(SNORE_DEBUG) << "Source" << source() << "and Target" << target << "are the same.";
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -60,12 +60,11 @@ public:
|
|||
*/
|
||||
void setSource(SnorePlugin *soure);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the source SnorePlugin.
|
||||
* This is used to prevent notification loops between the frontend and the backend.
|
||||
*/
|
||||
const SnorePlugin* source() const;
|
||||
const SnorePlugin *source() const;
|
||||
|
||||
/**
|
||||
* Returns true if the source->name() and the target->name() are the same.
|
||||
|
|
|
@ -54,6 +54,7 @@ SnorePlugin *PluginContainer::load()
|
|||
}
|
||||
SnorePlugin *plugin = qobject_cast<SnorePlugin *> (m_loader.instance());
|
||||
plugin->m_container = this;
|
||||
plugin->setDefaultSettings();
|
||||
return plugin;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@ SnorePlugin::~SnorePlugin()
|
|||
|
||||
bool SnorePlugin::initialize()
|
||||
{
|
||||
setDefaultSettingsValue(QLatin1String("Enabled"), false, LOCAL_SETTING);
|
||||
if (m_initialized) {
|
||||
qFatal("Something went wrong, plugin %s is already initialized", this->name().toLatin1().constData());
|
||||
return false;
|
||||
|
@ -110,6 +109,11 @@ QString SnorePlugin::settingsVersion() const
|
|||
return QLatin1String("v1");
|
||||
}
|
||||
|
||||
void SnorePlugin::setDefaultSettings()
|
||||
{
|
||||
setDefaultSettingsValue(QLatin1String("Enabled"), false, LOCAL_SETTING);
|
||||
}
|
||||
|
||||
bool SnorePlugin::deinitialize()
|
||||
{
|
||||
if (m_initialized) {
|
||||
|
|
|
@ -85,8 +85,14 @@ protected:
|
|||
*/
|
||||
virtual QString settingsVersion() const;
|
||||
|
||||
/**
|
||||
* Set default setting values for the Plugin.
|
||||
*/
|
||||
virtual void setDefaultSettings();
|
||||
|
||||
private:
|
||||
QString normaliseKey(const QString &key) const;
|
||||
void setDefaultSettingsPlugin();
|
||||
|
||||
bool m_initialized = false;
|
||||
PluginContainer *m_container = nullptr;
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
|
||||
class QAbstractButton;
|
||||
|
||||
|
||||
namespace Snore
|
||||
{
|
||||
class PluginSettingsWidget;
|
||||
|
|
|
@ -92,7 +92,7 @@ void SnoreCore::loadPlugins(SnorePlugin::PluginTypes types)
|
|||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
snoreDebug(SNORE_WARNING) << "Plugin Cache corrupted\n" << info->file() << info->type();
|
||||
continue;
|
||||
|
@ -244,7 +244,7 @@ void SnoreCore::displayExapleNotification()
|
|||
{
|
||||
Application app = SnoreCorePrivate::instance()->defaultApplication();
|
||||
QString text = QLatin1String("<i>") + tr("This is Snore") + QLatin1String("</i><br>") +
|
||||
QLatin1String("<a href=\"https://github.com/Snorenotify/Snorenotify\">") + tr("Project Website") + QLatin1String("</a><br>");
|
||||
QLatin1String("<a href=\"https://github.com/Snorenotify/Snorenotify\">") + tr("Project Website") + QLatin1String("</a><br>");
|
||||
if (!app.constHints().value("use-markup").toBool()) {
|
||||
text = Utils::normalizeMarkup(text, Utils::NO_MARKUP);
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ bool FreedesktopBackend::canUpdateNotification() const
|
|||
|
||||
void FreedesktopBackend::slotNotify(Notification noti)
|
||||
{
|
||||
if(noti.data()->sourceAndTargetAreSimilar(this)) {
|
||||
if (noti.data()->sourceAndTargetAreSimilar(this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,9 +31,6 @@ GrowlBackend *GrowlBackend::s_instance = nullptr;
|
|||
|
||||
bool GrowlBackend::initialize()
|
||||
{
|
||||
setDefaultSettingsValue(QLatin1String("Host"), QLatin1String("localhost"));
|
||||
setDefaultSettingsValue(QLatin1String("Password"), QString());
|
||||
|
||||
if (!SnoreBackend::initialize()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -127,3 +124,10 @@ PluginSettingsWidget *GrowlBackend::settingsWidget()
|
|||
return new GrowlSettings(this);
|
||||
}
|
||||
|
||||
void GrowlBackend::setDefaultSettings()
|
||||
{
|
||||
SnoreBackend::setDefaultSettings();
|
||||
setDefaultSettingsValue(QLatin1String("Host"), QLatin1String("localhost"));
|
||||
setDefaultSettingsValue(QLatin1String("Password"), QString());
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,9 @@ public:
|
|||
bool deinitialize() override;
|
||||
Snore::PluginSettingsWidget *settingsWidget() override;
|
||||
|
||||
protected:
|
||||
void setDefaultSettings() override;
|
||||
|
||||
private:
|
||||
//a static instance for the static callback methode
|
||||
static GrowlBackend *s_instance;
|
||||
|
|
|
@ -113,8 +113,6 @@ private:
|
|||
|
||||
bool SnarlBackend::initialize()
|
||||
{
|
||||
setDefaultSettingsValue(QLatin1String("Password"), QString());
|
||||
|
||||
if (!SnoreBackend::initialize()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -159,6 +157,13 @@ bool SnarlBackend::canUpdateNotification() const
|
|||
return true;
|
||||
}
|
||||
|
||||
void SnarlBackend::setDefaultSettings()
|
||||
{
|
||||
|
||||
setDefaultSettingsValue(QLatin1String("Password"), QString());
|
||||
SnoreBackend::setDefaultSettings();
|
||||
}
|
||||
|
||||
void SnarlBackend::slotRegisterApplication(const Application &application)
|
||||
{
|
||||
if (!m_eventLoop) {
|
||||
|
|
|
@ -36,6 +36,9 @@ public:
|
|||
virtual bool canCloseNotification() const override;
|
||||
virtual bool canUpdateNotification() const override;
|
||||
|
||||
protected:
|
||||
void setDefaultSettings() override;
|
||||
|
||||
private:
|
||||
class SnarlWidget;
|
||||
SnarlBackend::SnarlWidget *m_eventLoop;
|
||||
|
|
|
@ -107,8 +107,6 @@ void SnoreNotifier::slotCloseNotification(Snore::Notification notification)
|
|||
|
||||
bool SnoreNotifier::initialize()
|
||||
{
|
||||
setDefaultSettingsValue(QLatin1String("Position"), Qt::TopRightCorner);
|
||||
|
||||
if (SnoreBackend::initialize()) {
|
||||
for (int i = 0; i < m_widgets.size(); ++i) {
|
||||
NotifyWidget *w = new NotifyWidget(i, this);
|
||||
|
@ -156,3 +154,9 @@ PluginSettingsWidget *SnoreNotifier::settingsWidget()
|
|||
{
|
||||
return new SnoreNotifierSettings(this);
|
||||
}
|
||||
|
||||
void SnoreNotifier::setDefaultSettings()
|
||||
{
|
||||
setDefaultSettingsValue(QLatin1String("Position"), Qt::TopRightCorner);
|
||||
SnoreBackend::setDefaultSettings();
|
||||
}
|
||||
|
|
|
@ -40,6 +40,9 @@ public:
|
|||
|
||||
Snore::PluginSettingsWidget *settingsWidget() override;
|
||||
|
||||
protected:
|
||||
void setDefaultSettings() override;
|
||||
|
||||
public Q_SLOTS:
|
||||
virtual void slotNotify(Snore::Notification notification) override;
|
||||
virtual void slotCloseNotification(Snore::Notification notification) override;
|
||||
|
|
|
@ -46,9 +46,6 @@ PushoverFrontend::PushoverFrontend()
|
|||
|
||||
bool PushoverFrontend::initialize()
|
||||
{
|
||||
setDefaultSettingsValue(QLatin1String("Secret"), QString(), LOCAL_SETTING);
|
||||
setDefaultSettingsValue(QLatin1String("DeviceID"), QString(), LOCAL_SETTING);
|
||||
|
||||
if (!SnoreFrontend::initialize()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -120,6 +117,13 @@ QString PushoverFrontend::errorMessage()
|
|||
return m_errorMessage;
|
||||
}
|
||||
|
||||
void PushoverFrontend::setDefaultSettings()
|
||||
{
|
||||
setDefaultSettingsValue(QLatin1String("Secret"), QString(), LOCAL_SETTING);
|
||||
setDefaultSettingsValue(QLatin1String("DeviceID"), QString(), LOCAL_SETTING);
|
||||
SnoreFrontend::setDefaultSettings();
|
||||
}
|
||||
|
||||
void PushoverFrontend::slotActionInvoked(Notification notification)
|
||||
{
|
||||
if (notification.priority() == Notification::EMERGENCY) {
|
||||
|
|
|
@ -45,6 +45,9 @@ public:
|
|||
bool isLoggedIn() const;
|
||||
QString errorMessage();
|
||||
|
||||
protected:
|
||||
void setDefaultSettings() override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void slotActionInvoked(Snore::Notification notification);
|
||||
|
||||
|
|
|
@ -59,13 +59,13 @@ void NotifyMyAndroid::slotNotify(Notification notification)
|
|||
|
||||
}
|
||||
|
||||
bool NotifyMyAndroid::initialize()
|
||||
{
|
||||
setDefaultSettingsValue(QLatin1String("ApiKey"), QString());
|
||||
return SnoreSecondaryBackend::initialize();
|
||||
}
|
||||
|
||||
PluginSettingsWidget *NotifyMyAndroid::settingsWidget()
|
||||
{
|
||||
return new NotifyMyAndroidSettings(this);
|
||||
}
|
||||
|
||||
void NotifyMyAndroid::setDefaultSettings()
|
||||
{
|
||||
setDefaultSettingsValue(QLatin1String("ApiKey"), QString());
|
||||
SnoreSecondaryBackend::setDefaultSettings();
|
||||
}
|
||||
|
|
|
@ -31,10 +31,11 @@ public:
|
|||
NotifyMyAndroid() = default;
|
||||
~NotifyMyAndroid() = default;
|
||||
|
||||
virtual bool initialize() override;
|
||||
|
||||
Snore::PluginSettingsWidget *settingsWidget() override;
|
||||
|
||||
protected:
|
||||
void setDefaultSettings() override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void slotNotify(Snore::Notification notification) override;
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ using namespace Snore;
|
|||
|
||||
void Pushover::slotNotify(Notification notification)
|
||||
{
|
||||
if(notification.data()->sourceAndTargetAreSimilar(this)) {
|
||||
if (notification.data()->sourceAndTargetAreSimilar(this)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -120,15 +120,15 @@ void Pushover::slotNotify(Notification notification)
|
|||
|
||||
}
|
||||
|
||||
bool Pushover::initialize()
|
||||
{
|
||||
setDefaultSettingsValue(QLatin1String("UserKey"), QString());
|
||||
setDefaultSettingsValue(QLatin1String("Sound"), QLatin1String("pushover"), LOCAL_SETTING);
|
||||
setDefaultSettingsValue(QLatin1String("Devices"), QString(), LOCAL_SETTING);
|
||||
return SnoreSecondaryBackend::initialize();
|
||||
}
|
||||
|
||||
PluginSettingsWidget *Pushover::settingsWidget()
|
||||
{
|
||||
return new PushoverSettings(this);
|
||||
}
|
||||
|
||||
void Pushover::setDefaultSettings()
|
||||
{
|
||||
setDefaultSettingsValue(QLatin1String("UserKey"), QString());
|
||||
setDefaultSettingsValue(QLatin1String("Sound"), QLatin1String("pushover"), LOCAL_SETTING);
|
||||
setDefaultSettingsValue(QLatin1String("Devices"), QString(), LOCAL_SETTING);
|
||||
SnoreSecondaryBackend::setDefaultSettings();
|
||||
}
|
||||
|
|
|
@ -31,10 +31,11 @@ public:
|
|||
Pushover() = default;
|
||||
~Pushover() = default;
|
||||
|
||||
bool initialize() override;
|
||||
|
||||
Snore::PluginSettingsWidget *settingsWidget() override;
|
||||
|
||||
protected:
|
||||
void setDefaultSettings() override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void slotNotify(Snore::Notification notification) override;
|
||||
|
||||
|
|
|
@ -36,9 +36,7 @@ Sound::Sound():
|
|||
|
||||
bool Sound::initialize()
|
||||
{
|
||||
setDefaultSettingsValue(QLatin1String("Volume"), 50);
|
||||
m_player->setVolume(settingsValue(QLatin1String("Volume")).toInt());
|
||||
|
||||
return SnoreSecondaryBackend::initialize();
|
||||
}
|
||||
|
||||
|
@ -47,6 +45,12 @@ PluginSettingsWidget *Sound::settingsWidget()
|
|||
return new SoundSettings(this);
|
||||
}
|
||||
|
||||
void Sound::setDefaultSettings()
|
||||
{
|
||||
setDefaultSettingsValue(QLatin1String("Volume"), 50);
|
||||
SnoreSecondaryBackend::setDefaultSettings();
|
||||
}
|
||||
|
||||
void Sound::slotNotificationDisplayed(Snore::Notification notification)
|
||||
{
|
||||
if (notification.hints().value("silent").toBool()) {
|
||||
|
|
|
@ -35,6 +35,9 @@ public:
|
|||
|
||||
Snore::PluginSettingsWidget *settingsWidget() override;
|
||||
|
||||
protected:
|
||||
void setDefaultSettings() override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void slotNotificationDisplayed(Snore::Notification notification) override;
|
||||
private:
|
||||
|
|
|
@ -77,13 +77,13 @@ void Toasty::slotNotify(Notification notification)
|
|||
|
||||
}
|
||||
|
||||
bool Toasty::initialize()
|
||||
{
|
||||
setDefaultSettingsValue(QLatin1String("DeviceID"), QString());
|
||||
return SnoreSecondaryBackend::initialize();
|
||||
}
|
||||
|
||||
PluginSettingsWidget *Toasty::settingsWidget()
|
||||
{
|
||||
return new ToastySettings(this);
|
||||
}
|
||||
|
||||
void Toasty::setDefaultSettings()
|
||||
{
|
||||
setDefaultSettingsValue(QLatin1String("DeviceID"), QString());
|
||||
SnoreSecondaryBackend::setDefaultSettings();
|
||||
}
|
||||
|
|
|
@ -31,10 +31,11 @@ public:
|
|||
Toasty() = default;
|
||||
~Toasty() = default;
|
||||
|
||||
bool initialize() override;
|
||||
|
||||
Snore::PluginSettingsWidget *settingsWidget() override;
|
||||
|
||||
protected:
|
||||
void setDefaultSettings() override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void slotNotify(Snore::Notification notification) override;
|
||||
|
||||
|
|
Loading…
Reference in New Issue