this should be better -.-

This commit is contained in:
Patrick von Reth 2015-04-19 20:15:46 +02:00
parent 80f6710868
commit 0fb7f2d6b2
9 changed files with 25 additions and 25 deletions

View File

@ -147,25 +147,24 @@ bool Notification::isValid() const
}
void Notification::addActiveIn(SnorePlugin *o)
void Notification::addActiveIn(const QObject *o)
{
d->m_activeIn.insert(o);
o->m_activeNotifications[id()] = *this;
SnoreCorePrivate::instance()->m_activeNotifications[id()] = *this;
}
bool Notification::isActiveIn(const SnorePlugin *o) const
bool Notification::isActiveIn(const QObject *o) const
{
return d->m_activeIn.contains(o);
}
bool Notification::removeActiveIn(SnorePlugin *o)
bool Notification::removeActiveIn(const QObject *o)
{
bool out = d->m_activeIn.remove(o);
if (out) {
o->m_activeNotifications.remove(id());
return true;
if (d->m_activeIn.isEmpty()) {
SnoreCorePrivate::instance()->m_activeNotifications.remove(id());
}
return false;
return out;
}
NotificationData *Notification::data()

View File

@ -266,9 +266,10 @@ public:
*/
static int defaultTimeout();
void addActiveIn(SnorePlugin *o);
bool isActiveIn(const Snore::SnorePlugin *o) const;
bool removeActiveIn(SnorePlugin *o);
void addActiveIn(const QObject *o);
bool isActiveIn(const QObject *o) const;
bool removeActiveIn(const QObject* o);
private:
QExplicitlySharedDataPointer<NotificationData> d;

View File

@ -60,11 +60,6 @@ bool SnorePlugin::isInitialized() const
return m_initialized;
}
Notification SnorePlugin::activeNotificationById(uint id)
{
return m_activeNotifications.value(id);
}
QVariant SnorePlugin::value(const QString &key, SettingsType type) const
{
return SnoreCore::instance().value(normaliseKey(key), type);
@ -119,7 +114,6 @@ bool SnorePlugin::deinitialize()
if (m_initialized) {
snoreDebug(SNORE_DEBUG) << "Deinitialize" << m_name << this;
m_initialized = false;
m_activeNotifications.clear();
return true;
}
return false;

View File

@ -53,8 +53,6 @@ public:
virtual bool deinitialize();
bool isInitialized() const;
Snore::Notification activeNotificationById(uint id);
const QString &name() const;
PluginTypes type() const;
const QString typeName() const;
@ -77,9 +75,6 @@ private:
bool m_initialized = false;
PluginTypes m_type = NONE;
QHash<uint,Snore::Notification> m_activeNotifications;
friend class Notification;
friend class PluginContainer;
};

View File

@ -231,3 +231,10 @@ void SnoreCore::setDefaultValue(const QString &key, const QVariant &value, Setti
d->m_settings->setValue(nk, value);
}
}
Notification SnoreCore::activeNotificationById(uint id) const
{
Q_D(const SnoreCore);
return d->m_activeNotifications.value(id);
}

View File

@ -150,6 +150,7 @@ public:
void setValue(const QString &key, const QVariant &value, SettingsType type = GLOBAL_SETTING);
void setDefaultValue(const QString &key, const QVariant &value, SettingsType type = GLOBAL_SETTING);
Notification activeNotificationById(uint id) const;
signals:
/**
* This signal is emitted when an action on the Notification was performed.

View File

@ -109,6 +109,9 @@ private:
QString m_localSettingsPrefix = qApp->applicationName().isEmpty() ? "SnoreNotify" : qApp->applicationName();
QSettings *m_settings;
QHash<uint,Snore::Notification> m_activeNotifications;
friend class Snore::Notification;
};
}

View File

@ -45,7 +45,7 @@ bool GrowlBackend::initialize()
s_instance = this;
auto func = [](growl_callback_data *data)->void{
snoreDebug(SNORE_DEBUG) << data->id << QString(data->reason) << QString(data->data);
Notification n = s_instance->activeNotificationById(data->id);
Notification n = Snore::SnoreCore::instance().activeNotificationById(data->id);
if (!n.isValid()) {
return;
}

View File

@ -124,7 +124,7 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
}
Notification noti;
Notification toReplace = activeNotificationById(replaces_id);
Notification toReplace = SnoreCore::instance().activeNotificationById(replaces_id);
if (replaces_id != 0 && toReplace.isValid()) {
noti = Notification(toReplace, summary, body, icon, timeout == -1 ? Notification::defaultTimeout() : timeout / 1000, priotity);
} else {
@ -141,7 +141,7 @@ uint FreedesktopFrontend::Notify(const QString &app_name, uint replaces_id,
void FreedesktopFrontend::CloseNotification(uint id)
{
Notification noti = activeNotificationById(id);
Notification noti = SnoreCore::instance().activeNotificationById(id);
if (noti.isValid()) {
SnoreCore::instance().requestCloseNotification(noti, Notification::TIMED_OUT);
}