mirror of
https://bitbucket.org/smil3y/kde-workspace.git
synced 2025-02-23 10:22:49 +00:00
plasma: use singletons for the notifications applet adaptors
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
1759cc5a69
commit
42a08098d1
7 changed files with 81 additions and 11 deletions
|
@ -123,7 +123,7 @@ bool sendVisualNotification(const QString &text, const QString &title, const QSt
|
|||
notificationData.insert("appIcon", icon);
|
||||
notificationData.insert("summary", title);
|
||||
notificationData.insert("body", text);
|
||||
notificationData.insert("timeout", timeout); // expire timout, unused
|
||||
// NOTE: missing appRealName, not configurable
|
||||
reply = notificationInterface.call("updateNotification", notificationId, notificationData);
|
||||
if (!reply.isValid()) {
|
||||
// kDebug() << "Error: failed to send D-Bus message" << reply.error().message();
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
#include "applicationswidget.h"
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QTimer>
|
||||
#include <QGraphicsGridLayout>
|
||||
#include <Plasma/Animation>
|
||||
|
@ -142,7 +141,7 @@ ApplicationsWidget::ApplicationsWidget(QGraphicsItem *parent, NotificationsWidge
|
|||
m_layout->addStretch();
|
||||
setLayout(m_layout);
|
||||
|
||||
m_adaptor = new NotificationsAdaptor(this);
|
||||
m_adaptor = NotificationsAdaptor::self();
|
||||
connect(
|
||||
m_adaptor, SIGNAL(notificationAdded(QString)),
|
||||
this, SLOT(slotNotificationAdded(QString))
|
||||
|
@ -151,12 +150,12 @@ ApplicationsWidget::ApplicationsWidget(QGraphicsItem *parent, NotificationsWidge
|
|||
m_adaptor, SIGNAL(notificationUpdated(QString,QVariantMap)),
|
||||
this, SLOT(slotNotificationUpdated(QString,QVariantMap))
|
||||
);
|
||||
QDBusConnection session = QDBusConnection::sessionBus();
|
||||
session.registerObject("/Notifications", this);
|
||||
m_adaptor->registerObject();
|
||||
}
|
||||
|
||||
ApplicationsWidget::~ApplicationsWidget()
|
||||
{
|
||||
m_adaptor->unregisterObject();
|
||||
}
|
||||
|
||||
int ApplicationsWidget::count() const
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
#include "jobswidget.h"
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QGraphicsGridLayout>
|
||||
#include <Plasma/Animation>
|
||||
#include <KLocale>
|
||||
|
@ -145,7 +144,7 @@ JobsWidget::JobsWidget(QGraphicsItem *parent, NotificationsWidget *notifications
|
|||
m_layout->addItem(m_label);
|
||||
setLayout(m_layout);
|
||||
|
||||
m_adaptor = new JobTrackerAdaptor(this);
|
||||
m_adaptor = JobTrackerAdaptor::self();
|
||||
connect(
|
||||
m_adaptor, SIGNAL(jobAdded(QString)),
|
||||
this, SLOT(slotJobAdded(QString))
|
||||
|
@ -154,12 +153,12 @@ JobsWidget::JobsWidget(QGraphicsItem *parent, NotificationsWidget *notifications
|
|||
m_adaptor, SIGNAL(jobUpdated(QString,QVariantMap)),
|
||||
this, SLOT(slotJobUpdated(QString,QVariantMap))
|
||||
);
|
||||
QDBusConnection session = QDBusConnection::sessionBus();
|
||||
session.registerObject("/JobTracker", this);
|
||||
m_adaptor->registerObject();
|
||||
}
|
||||
|
||||
JobsWidget::~JobsWidget()
|
||||
{
|
||||
m_adaptor->unregisterObject();
|
||||
}
|
||||
|
||||
int JobsWidget::count() const
|
||||
|
|
|
@ -19,8 +19,15 @@
|
|||
|
||||
#include "jobtrackeradaptor.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDBusConnection>
|
||||
#include <KGlobal>
|
||||
|
||||
K_GLOBAL_STATIC_WITH_ARGS(JobTrackerAdaptor, kJobTrackerAdaptor, (qApp))
|
||||
|
||||
JobTrackerAdaptor::JobTrackerAdaptor(QObject *parent)
|
||||
: QDBusAbstractAdaptor(parent)
|
||||
: QDBusAbstractAdaptor(parent),
|
||||
m_ref(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -39,4 +46,25 @@ void JobTrackerAdaptor::stopJob(const QString &name)
|
|||
emit stopRequested(name);
|
||||
}
|
||||
|
||||
JobTrackerAdaptor* JobTrackerAdaptor::self()
|
||||
{
|
||||
return kJobTrackerAdaptor;
|
||||
}
|
||||
|
||||
void JobTrackerAdaptor::registerObject()
|
||||
{
|
||||
if (m_ref == 0) {
|
||||
QDBusConnection::sessionBus().registerObject("/JobTracker", qApp);
|
||||
}
|
||||
m_ref.ref();
|
||||
}
|
||||
|
||||
void JobTrackerAdaptor::unregisterObject()
|
||||
{
|
||||
m_ref.deref();
|
||||
if (m_ref == 0) {
|
||||
QDBusConnection::sessionBus().unregisterObject("/JobTracker");
|
||||
}
|
||||
}
|
||||
|
||||
#include "moc_jobtrackeradaptor.cpp"
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <QDBusAbstractAdaptor>
|
||||
#include <QVariantMap>
|
||||
#include <QAtomicInt>
|
||||
|
||||
// Adaptor class for interface org.kde.JobTracker
|
||||
class JobTrackerAdaptor: public QDBusAbstractAdaptor
|
||||
|
@ -31,6 +32,10 @@ class JobTrackerAdaptor: public QDBusAbstractAdaptor
|
|||
public:
|
||||
JobTrackerAdaptor(QObject *parent);
|
||||
|
||||
static JobTrackerAdaptor* self();
|
||||
void registerObject();
|
||||
void unregisterObject();
|
||||
|
||||
public Q_SLOTS:
|
||||
void addJob(const QString &name);
|
||||
void updateJob(const QString &name, const QVariantMap &data);
|
||||
|
@ -41,6 +46,9 @@ Q_SIGNALS:
|
|||
void jobUpdated(const QString &name, const QVariantMap &data);
|
||||
|
||||
void stopRequested(const QString &name);
|
||||
|
||||
private:
|
||||
QAtomicInt m_ref;
|
||||
};
|
||||
|
||||
#endif // JOBTRACKERADAPTOR_H
|
||||
|
|
|
@ -19,8 +19,15 @@
|
|||
|
||||
#include "notificationsadaptor.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDBusConnection>
|
||||
#include <KGlobal>
|
||||
|
||||
K_GLOBAL_STATIC_WITH_ARGS(NotificationsAdaptor, kNotificationsAdaptor, (qApp))
|
||||
|
||||
NotificationsAdaptor::NotificationsAdaptor(QObject *parent)
|
||||
: QDBusAbstractAdaptor(parent)
|
||||
: QDBusAbstractAdaptor(parent),
|
||||
m_ref(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -44,4 +51,25 @@ void NotificationsAdaptor::invokeAction(const QString &name, const QString &acti
|
|||
emit actionRequested(name, action);
|
||||
}
|
||||
|
||||
NotificationsAdaptor* NotificationsAdaptor::self()
|
||||
{
|
||||
return kNotificationsAdaptor;
|
||||
}
|
||||
|
||||
void NotificationsAdaptor::registerObject()
|
||||
{
|
||||
if (m_ref == 0) {
|
||||
QDBusConnection::sessionBus().registerObject("/Notifications", qApp);
|
||||
}
|
||||
m_ref.ref();
|
||||
}
|
||||
|
||||
void NotificationsAdaptor::unregisterObject()
|
||||
{
|
||||
m_ref.deref();
|
||||
if (m_ref == 0) {
|
||||
QDBusConnection::sessionBus().unregisterObject("/Notifications");
|
||||
}
|
||||
}
|
||||
|
||||
#include "moc_notificationsadaptor.cpp"
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include <QDBusAbstractAdaptor>
|
||||
#include <QVariantMap>
|
||||
#include <QAtomicInt>
|
||||
|
||||
// Adaptor class for interface org.kde.Notifications
|
||||
class NotificationsAdaptor: public QDBusAbstractAdaptor
|
||||
|
@ -31,6 +32,10 @@ class NotificationsAdaptor: public QDBusAbstractAdaptor
|
|||
public:
|
||||
NotificationsAdaptor(QObject *parent);
|
||||
|
||||
static NotificationsAdaptor* self();
|
||||
void registerObject();
|
||||
void unregisterObject();
|
||||
|
||||
public Q_SLOTS:
|
||||
void addNotification(const QString &name);
|
||||
void updateNotification(const QString &name, const QVariantMap &data);
|
||||
|
@ -43,6 +48,9 @@ Q_SIGNALS:
|
|||
|
||||
void closeRequested(const QString &name);
|
||||
void actionRequested(const QString &name, const QString &action);
|
||||
|
||||
private:
|
||||
QAtomicInt m_ref;
|
||||
};
|
||||
|
||||
#endif // NOTIFICATIONSADAPTOR_H
|
||||
|
|
Loading…
Add table
Reference in a new issue