Use SnoreCore by reference instead of global static for Backend
Signed-off-by: Max Risuhin <risuhin.max@gmail.com>
This commit is contained in:
parent
3bf3082ca7
commit
e176aada26
|
@ -45,7 +45,13 @@ SnorePlugin::~SnorePlugin()
|
|||
|
||||
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
|
||||
|
@ -55,17 +61,17 @@ bool SnorePlugin::isEnabled() 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)
|
||||
{
|
||||
SnoreCore::instance().setSettingsValue(normaliseKey(key), value);
|
||||
getSnoreCore()->setSettingsValue(normaliseKey(key), 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
|
||||
|
|
|
@ -93,6 +93,7 @@ public:
|
|||
virtual ~SnorePlugin();
|
||||
|
||||
void setSnoreCoreInstance(SnoreCore* instance);
|
||||
SnoreCore* getSnoreCore() const;
|
||||
|
||||
/**
|
||||
* Sets the enabled state of the plugin to @param enabled .
|
||||
|
@ -168,6 +169,7 @@ private:
|
|||
QString m_name;
|
||||
QString m_error;
|
||||
Hint m_hints;
|
||||
SnoreCore *m_snoreCore = nullptr;
|
||||
|
||||
friend class PluginContainer;
|
||||
|
||||
|
|
|
@ -33,24 +33,24 @@ SnoreBackend::SnoreBackend()
|
|||
{
|
||||
connect(this, &SnoreBackend::enabledChanged, [this](bool enabled) {
|
||||
if (enabled) {
|
||||
connect(SnoreCorePrivate::instance(), &SnoreCorePrivate::applicationRegistered, this, &SnoreBackend::slotRegisterApplication, Qt::QueuedConnection);
|
||||
connect(SnoreCorePrivate::instance(), &SnoreCorePrivate::applicationDeregistered, this, &SnoreBackend::slotDeregisterApplication, Qt::QueuedConnection);
|
||||
connect(getSnoreCore()->impl(), &SnoreCorePrivate::applicationRegistered, this, &SnoreBackend::slotRegisterApplication, Qt::QueuedConnection);
|
||||
connect(getSnoreCore()->impl(), &SnoreCorePrivate::applicationDeregistered, this, &SnoreBackend::slotDeregisterApplication, Qt::QueuedConnection);
|
||||
|
||||
connect(this, &SnoreBackend::notificationClosed, SnoreCorePrivate::instance(), &SnoreCorePrivate::slotNotificationClosed, Qt::QueuedConnection);
|
||||
connect(SnoreCorePrivate::instance(), &SnoreCorePrivate::notify, this, &SnoreBackend::slotNotify, Qt::QueuedConnection);
|
||||
connect(this, &SnoreBackend::notificationClosed, getSnoreCore()->impl(), &SnoreCorePrivate::slotNotificationClosed, 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);
|
||||
}
|
||||
} else {
|
||||
for (const Application &a : SnoreCore::instance().aplications()) {
|
||||
for (const Application &a : getSnoreCore()->aplications()) {
|
||||
slotDeregisterApplication(a);
|
||||
}
|
||||
disconnect(SnoreCorePrivate::instance(), &SnoreCorePrivate::applicationRegistered, this, &SnoreBackend::slotRegisterApplication);
|
||||
disconnect(SnoreCorePrivate::instance(), &SnoreCorePrivate::applicationDeregistered, this, &SnoreBackend::slotDeregisterApplication);
|
||||
disconnect(getSnoreCore()->impl(), &SnoreCorePrivate::applicationRegistered, this, &SnoreBackend::slotRegisterApplication);
|
||||
disconnect(getSnoreCore()->impl(), &SnoreCorePrivate::applicationDeregistered, this, &SnoreBackend::slotDeregisterApplication);
|
||||
|
||||
disconnect(this, &SnoreBackend::notificationClosed, SnoreCorePrivate::instance(), &SnoreCorePrivate::slotNotificationClosed);
|
||||
disconnect(SnoreCorePrivate::instance(), &SnoreCorePrivate::notify, this, &SnoreBackend::slotNotify);
|
||||
disconnect(this, &SnoreBackend::notificationClosed, getSnoreCore()->impl(), &SnoreCorePrivate::slotNotificationClosed);
|
||||
disconnect(getSnoreCore()->impl(), &SnoreCorePrivate::notify, this, &SnoreBackend::slotNotify);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -122,12 +122,12 @@ void SnoreBackend::slotDeregisterApplication(const Application &application)
|
|||
void SnoreBackend::slotNotificationDisplayed(Notification notification)
|
||||
{
|
||||
notification.addActiveIn(this);
|
||||
SnoreCorePrivate::instance()->slotNotificationDisplayed(notification);
|
||||
getSnoreCore()->impl()->slotNotificationDisplayed(notification);
|
||||
}
|
||||
|
||||
void SnoreBackend::slotNotificationActionInvoked(Notification notification, const Action &action)
|
||||
{
|
||||
notification.data()->setActionInvoked(action);
|
||||
SnoreCorePrivate::instance()->slotNotificationActionInvoked(notification);
|
||||
getSnoreCore()->impl()->slotNotificationActionInvoked(notification);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,11 +25,11 @@ SnoreFrontend::SnoreFrontend()
|
|||
{
|
||||
connect(this, &SnoreFrontend::enabledChanged, [this](bool enabled) {
|
||||
if (enabled) {
|
||||
connect(&SnoreCore::instance(), &SnoreCore::notificationClosed, this, &SnoreFrontend::slotNotificationClosed, Qt::QueuedConnection);
|
||||
connect(&SnoreCore::instance(), &SnoreCore::actionInvoked, this, &SnoreFrontend::slotActionInvoked, Qt::QueuedConnection);
|
||||
connect(getSnoreCore(), &SnoreCore::notificationClosed, this, &SnoreFrontend::slotNotificationClosed, Qt::QueuedConnection);
|
||||
connect(getSnoreCore(), &SnoreCore::actionInvoked, this, &SnoreFrontend::slotActionInvoked, Qt::QueuedConnection);
|
||||
} else {
|
||||
disconnect(&SnoreCore::instance(), &SnoreCore::notificationClosed, this, &SnoreFrontend::slotNotificationClosed);
|
||||
disconnect(&SnoreCore::instance(), &SnoreCore::actionInvoked, this, &SnoreFrontend::slotActionInvoked);
|
||||
disconnect(getSnoreCore(), &SnoreCore::notificationClosed, this, &SnoreFrontend::slotNotificationClosed);
|
||||
disconnect(getSnoreCore(), &SnoreCore::actionInvoked, this, &SnoreFrontend::slotActionInvoked);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -63,6 +63,12 @@ public:
|
|||
static void setInstance(SnoreCore* i);
|
||||
~SnoreCore();
|
||||
|
||||
SnoreCorePrivate * impl()
|
||||
{
|
||||
return d_ptr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load a set of plugins
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue