Use SnoreCore by reference instead of global static for Backend

Signed-off-by: Max Risuhin <risuhin.max@gmail.com>
This commit is contained in:
Max Risuhin 2018-10-15 13:10:36 +03:00
parent 3bf3082ca7
commit e176aada26
No known key found for this signature in database
GPG Key ID: BF733F5ACA0B4448
5 changed files with 34 additions and 20 deletions

View File

@ -45,7 +45,13 @@ SnorePlugin::~SnorePlugin()
void SnorePlugin::setSnoreCoreInstance(SnoreCore *instance) void SnorePlugin::setSnoreCoreInstance(SnoreCore *instance)
{ {
SnoreCore::setInstance(instance); m_snoreCore = instance;
}
SnoreCore *SnorePlugin::getSnoreCore() const
{
Q_ASSERT(m_snoreCore);
return m_snoreCore;
} }
bool SnorePlugin::isEnabled() const bool SnorePlugin::isEnabled() const
@ -55,17 +61,17 @@ bool SnorePlugin::isEnabled() const
QVariant SnorePlugin::settingsValue(const SettingsKey &key) const QVariant SnorePlugin::settingsValue(const SettingsKey &key) const
{ {
return SnoreCore::instance().settingsValue(normaliseKey(key)); return getSnoreCore()->settingsValue(normaliseKey(key));
} }
void SnorePlugin::setSettingsValue(const SettingsKey &key, const QVariant &value) void SnorePlugin::setSettingsValue(const SettingsKey &key, const QVariant &value)
{ {
SnoreCore::instance().setSettingsValue(normaliseKey(key), value); getSnoreCore()->setSettingsValue(normaliseKey(key), value);
} }
void SnorePlugin::setDefaultSettingsValue(const SettingsKey &key, const QVariant &value) void SnorePlugin::setDefaultSettingsValue(const SettingsKey &key, const QVariant &value)
{ {
SnoreCore::instance().setDefaultSettingsValue(normaliseKey(key), value); getSnoreCore()->setDefaultSettingsValue(normaliseKey(key), value);
} }
const Hint &SnorePlugin::constHints() const const Hint &SnorePlugin::constHints() const

View File

@ -93,6 +93,7 @@ public:
virtual ~SnorePlugin(); virtual ~SnorePlugin();
void setSnoreCoreInstance(SnoreCore* instance); void setSnoreCoreInstance(SnoreCore* instance);
SnoreCore* getSnoreCore() const;
/** /**
* Sets the enabled state of the plugin to @param enabled . * Sets the enabled state of the plugin to @param enabled .
@ -168,6 +169,7 @@ private:
QString m_name; QString m_name;
QString m_error; QString m_error;
Hint m_hints; Hint m_hints;
SnoreCore *m_snoreCore = nullptr;
friend class PluginContainer; friend class PluginContainer;

View File

@ -33,24 +33,24 @@ SnoreBackend::SnoreBackend()
{ {
connect(this, &SnoreBackend::enabledChanged, [this](bool enabled) { connect(this, &SnoreBackend::enabledChanged, [this](bool enabled) {
if (enabled) { if (enabled) {
connect(SnoreCorePrivate::instance(), &SnoreCorePrivate::applicationRegistered, this, &SnoreBackend::slotRegisterApplication, Qt::QueuedConnection); connect(getSnoreCore()->impl(), &SnoreCorePrivate::applicationRegistered, this, &SnoreBackend::slotRegisterApplication, Qt::QueuedConnection);
connect(SnoreCorePrivate::instance(), &SnoreCorePrivate::applicationDeregistered, this, &SnoreBackend::slotDeregisterApplication, Qt::QueuedConnection); connect(getSnoreCore()->impl(), &SnoreCorePrivate::applicationDeregistered, this, &SnoreBackend::slotDeregisterApplication, Qt::QueuedConnection);
connect(this, &SnoreBackend::notificationClosed, SnoreCorePrivate::instance(), &SnoreCorePrivate::slotNotificationClosed, Qt::QueuedConnection); connect(this, &SnoreBackend::notificationClosed, getSnoreCore()->impl(), &SnoreCorePrivate::slotNotificationClosed, Qt::QueuedConnection);
connect(SnoreCorePrivate::instance(), &SnoreCorePrivate::notify, this, &SnoreBackend::slotNotify, Qt::QueuedConnection); connect(getSnoreCore()->impl(), &SnoreCorePrivate::notify, this, &SnoreBackend::slotNotify, Qt::QueuedConnection);
for (const Application &a : SnoreCore::instance().aplications()) { for (const Application &a : getSnoreCore()->aplications()) {
slotRegisterApplication(a); slotRegisterApplication(a);
} }
} else { } else {
for (const Application &a : SnoreCore::instance().aplications()) { for (const Application &a : getSnoreCore()->aplications()) {
slotDeregisterApplication(a); slotDeregisterApplication(a);
} }
disconnect(SnoreCorePrivate::instance(), &SnoreCorePrivate::applicationRegistered, this, &SnoreBackend::slotRegisterApplication); disconnect(getSnoreCore()->impl(), &SnoreCorePrivate::applicationRegistered, this, &SnoreBackend::slotRegisterApplication);
disconnect(SnoreCorePrivate::instance(), &SnoreCorePrivate::applicationDeregistered, this, &SnoreBackend::slotDeregisterApplication); disconnect(getSnoreCore()->impl(), &SnoreCorePrivate::applicationDeregistered, this, &SnoreBackend::slotDeregisterApplication);
disconnect(this, &SnoreBackend::notificationClosed, SnoreCorePrivate::instance(), &SnoreCorePrivate::slotNotificationClosed); disconnect(this, &SnoreBackend::notificationClosed, getSnoreCore()->impl(), &SnoreCorePrivate::slotNotificationClosed);
disconnect(SnoreCorePrivate::instance(), &SnoreCorePrivate::notify, this, &SnoreBackend::slotNotify); disconnect(getSnoreCore()->impl(), &SnoreCorePrivate::notify, this, &SnoreBackend::slotNotify);
} }
}); });
} }
@ -122,12 +122,12 @@ void SnoreBackend::slotDeregisterApplication(const Application &application)
void SnoreBackend::slotNotificationDisplayed(Notification notification) void SnoreBackend::slotNotificationDisplayed(Notification notification)
{ {
notification.addActiveIn(this); notification.addActiveIn(this);
SnoreCorePrivate::instance()->slotNotificationDisplayed(notification); getSnoreCore()->impl()->slotNotificationDisplayed(notification);
} }
void SnoreBackend::slotNotificationActionInvoked(Notification notification, const Action &action) void SnoreBackend::slotNotificationActionInvoked(Notification notification, const Action &action)
{ {
notification.data()->setActionInvoked(action); notification.data()->setActionInvoked(action);
SnoreCorePrivate::instance()->slotNotificationActionInvoked(notification); getSnoreCore()->impl()->slotNotificationActionInvoked(notification);
} }

View File

@ -25,11 +25,11 @@ SnoreFrontend::SnoreFrontend()
{ {
connect(this, &SnoreFrontend::enabledChanged, [this](bool enabled) { connect(this, &SnoreFrontend::enabledChanged, [this](bool enabled) {
if (enabled) { if (enabled) {
connect(&SnoreCore::instance(), &SnoreCore::notificationClosed, this, &SnoreFrontend::slotNotificationClosed, Qt::QueuedConnection); connect(getSnoreCore(), &SnoreCore::notificationClosed, this, &SnoreFrontend::slotNotificationClosed, Qt::QueuedConnection);
connect(&SnoreCore::instance(), &SnoreCore::actionInvoked, this, &SnoreFrontend::slotActionInvoked, Qt::QueuedConnection); connect(getSnoreCore(), &SnoreCore::actionInvoked, this, &SnoreFrontend::slotActionInvoked, Qt::QueuedConnection);
} else { } else {
disconnect(&SnoreCore::instance(), &SnoreCore::notificationClosed, this, &SnoreFrontend::slotNotificationClosed); disconnect(getSnoreCore(), &SnoreCore::notificationClosed, this, &SnoreFrontend::slotNotificationClosed);
disconnect(&SnoreCore::instance(), &SnoreCore::actionInvoked, this, &SnoreFrontend::slotActionInvoked); disconnect(getSnoreCore(), &SnoreCore::actionInvoked, this, &SnoreFrontend::slotActionInvoked);
} }
}); });
} }

View File

@ -63,6 +63,12 @@ public:
static void setInstance(SnoreCore* i); static void setInstance(SnoreCore* i);
~SnoreCore(); ~SnoreCore();
SnoreCorePrivate * impl()
{
return d_ptr;
}
/** /**
* Load a set of plugins * Load a set of plugins
* *