mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 02:42:48 +00:00
kdeui: send notifications to plasma-windowed from KNotificationManager
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
bbf7da7475
commit
f9d58bcec1
1 changed files with 87 additions and 36 deletions
|
@ -68,10 +68,16 @@ private Q_SLOTS:
|
||||||
void slotDirty(const QString &path);
|
void slotDirty(const QString &path);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QDBusInterface* createInterface(const QString &service);
|
||||||
|
bool callAddMethod(const QString ¬ifyid);
|
||||||
|
void callUpdateMethod(const QString ¬ifyid, const QVariantMap &eventdata);
|
||||||
|
void callCloseMethod(const QString ¬ifyid);
|
||||||
|
|
||||||
QMutex m_mutex;
|
QMutex m_mutex;
|
||||||
KConfig *m_config;
|
KConfig *m_config;
|
||||||
KDirWatch m_configwatch;
|
KDirWatch m_configwatch;
|
||||||
QDBusInterface* m_notificationsiface;
|
QDBusInterface* m_desktopiface;
|
||||||
|
QDBusInterface* m_windowediface;
|
||||||
QDBusInterface* m_kaudioplayeriface;
|
QDBusInterface* m_kaudioplayeriface;
|
||||||
QMap<KNotification*,QVariantMap> m_notifications;
|
QMap<KNotification*,QVariantMap> m_notifications;
|
||||||
};
|
};
|
||||||
|
@ -80,7 +86,8 @@ K_GLOBAL_STATIC(KNotificationManager, kNotificationManager);
|
||||||
KNotificationManager::KNotificationManager()
|
KNotificationManager::KNotificationManager()
|
||||||
: m_config(nullptr),
|
: m_config(nullptr),
|
||||||
m_configwatch(this),
|
m_configwatch(this),
|
||||||
m_notificationsiface(nullptr),
|
m_desktopiface(nullptr),
|
||||||
|
m_windowediface(nullptr),
|
||||||
m_kaudioplayeriface(nullptr)
|
m_kaudioplayeriface(nullptr)
|
||||||
{
|
{
|
||||||
// NOTE: the default poll interval of QFileSystemWatcher is 1sec
|
// NOTE: the default poll interval of QFileSystemWatcher is 1sec
|
||||||
|
@ -149,21 +156,13 @@ void KNotificationManager::send(KNotification *notification, const bool persiste
|
||||||
}
|
}
|
||||||
// qDebug() << Q_FUNC_INFO << eventactions << notification->actions();
|
// qDebug() << Q_FUNC_INFO << eventactions << notification->actions();
|
||||||
if (eventactions.contains(s_popupaction)) {
|
if (eventactions.contains(s_popupaction)) {
|
||||||
if (!m_notificationsiface) {
|
if (!m_desktopiface) {
|
||||||
m_notificationsiface = new QDBusInterface(
|
m_desktopiface = createInterface("org.kde.plasma-desktop");
|
||||||
"org.kde.plasma-desktop", "/Notifications", "org.kde.Notifications",
|
|
||||||
QDBusConnection::sessionBus(), this
|
|
||||||
);
|
|
||||||
connect(
|
|
||||||
m_notificationsiface, SIGNAL(closeRequested(QString)),
|
|
||||||
this, SLOT(slotCloseRequested(QString))
|
|
||||||
);
|
|
||||||
connect(
|
|
||||||
m_notificationsiface, SIGNAL(actionRequested(QString,QString)),
|
|
||||||
this, SLOT(slotActionRequested(QString,QString))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (!m_notificationsiface || !m_notificationsiface->isValid()) {
|
if (!m_windowediface) {
|
||||||
|
m_windowediface = createInterface("org.kde.plasma-windowed");
|
||||||
|
}
|
||||||
|
if (!m_desktopiface->isValid() && !m_windowediface->isValid()) {
|
||||||
kWarning(s_knotificationarea) << "notifications interface is not valid";
|
kWarning(s_knotificationarea) << "notifications interface is not valid";
|
||||||
const QPixmap eventpixmap = KIconLoader::global()->loadIcon(eventicon, KIconLoader::Small);
|
const QPixmap eventpixmap = KIconLoader::global()->loadIcon(eventicon, KIconLoader::Small);
|
||||||
KPassivePopup* kpassivepopup = new KPassivePopup(notification->widget());
|
KPassivePopup* kpassivepopup = new KPassivePopup(notification->widget());
|
||||||
|
@ -194,23 +193,10 @@ void KNotificationManager::send(KNotification *notification, const bool persiste
|
||||||
eventdata.insert("actions", eventactions);
|
eventdata.insert("actions", eventactions);
|
||||||
// NOTE: has to be set to be configurable via plasma notifications applet
|
// NOTE: has to be set to be configurable via plasma notifications applet
|
||||||
eventdata.insert("appRealName", spliteventid.at(0));
|
eventdata.insert("appRealName", spliteventid.at(0));
|
||||||
bool updatenotification = false;
|
if (addnotification && callAddMethod(notifyid)) {
|
||||||
QDBusReply<void> notifyreply;
|
|
||||||
if (addnotification) {
|
|
||||||
notifyreply = m_notificationsiface->call(s_addmethod, notifyid);
|
|
||||||
if (!notifyreply.isValid()) {
|
|
||||||
kWarning(s_knotificationarea) << "invalid add reply" << notifyreply.error().message();
|
|
||||||
} else {
|
|
||||||
updatenotification = true;
|
|
||||||
m_notifications.insert(notification, eventdata);
|
m_notifications.insert(notification, eventdata);
|
||||||
}
|
}
|
||||||
}
|
callUpdateMethod(notifyid, eventdata);
|
||||||
if (updatenotification) {
|
|
||||||
notifyreply = m_notificationsiface->call(s_updatemethod, notifyid, eventdata);
|
|
||||||
if (!notifyreply.isValid()) {
|
|
||||||
kWarning(s_knotificationarea) << "invalid update reply" << notifyreply.error().message();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,15 +245,80 @@ void KNotificationManager::close(KNotification *notification)
|
||||||
if (iter.key() == notification) {
|
if (iter.key() == notification) {
|
||||||
const QString notifyid = kNotifyID(iter.key());
|
const QString notifyid = kNotifyID(iter.key());
|
||||||
iter.remove();
|
iter.remove();
|
||||||
QDBusReply<void> closereply = m_notificationsiface->call(s_closemethod, notifyid);
|
callCloseMethod(notifyid);
|
||||||
if (!closereply.isValid()) {
|
|
||||||
kWarning(s_knotificationarea) << "invalid close reply" << closereply.error().message();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDBusInterface* KNotificationManager::createInterface(const QString &service)
|
||||||
|
{
|
||||||
|
QDBusInterface* interface = new QDBusInterface(
|
||||||
|
service, "/Notifications", "org.kde.Notifications",
|
||||||
|
QDBusConnection::sessionBus(), this
|
||||||
|
);
|
||||||
|
connect(
|
||||||
|
interface, SIGNAL(closeRequested(QString)),
|
||||||
|
this, SLOT(slotCloseRequested(QString))
|
||||||
|
);
|
||||||
|
connect(
|
||||||
|
interface, SIGNAL(actionRequested(QString,QString)),
|
||||||
|
this, SLOT(slotActionRequested(QString,QString))
|
||||||
|
);
|
||||||
|
return interface;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KNotificationManager::callAddMethod(const QString ¬ifyid)
|
||||||
|
{
|
||||||
|
QDBusReply<void> desktopreply;
|
||||||
|
QDBusReply<void> windowedreply;
|
||||||
|
if (m_desktopiface && m_desktopiface->isValid()) {
|
||||||
|
desktopreply = m_desktopiface->call(s_addmethod, notifyid);
|
||||||
|
if (!desktopreply.isValid()) {
|
||||||
|
kWarning(s_knotificationarea) << "invalid desktop add reply" << desktopreply.error().message();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (m_windowediface && m_windowediface->isValid()) {
|
||||||
|
windowedreply = m_windowediface->call(s_addmethod, notifyid);
|
||||||
|
if (!windowedreply.isValid()) {
|
||||||
|
kWarning(s_knotificationarea) << "invalid windowed add reply" << windowedreply.error().message();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (desktopreply.isValid() || windowedreply.isValid());
|
||||||
|
}
|
||||||
|
|
||||||
|
void KNotificationManager::callUpdateMethod(const QString ¬ifyid, const QVariantMap &eventdata)
|
||||||
|
{
|
||||||
|
if (m_desktopiface && m_desktopiface->isValid()) {
|
||||||
|
QDBusReply<void> updatereply = m_desktopiface->call(s_updatemethod, notifyid, eventdata);
|
||||||
|
if (!updatereply.isValid()) {
|
||||||
|
kWarning(s_knotificationarea) << "invalid desktop update reply" << updatereply.error().message();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (m_windowediface && m_windowediface->isValid()) {
|
||||||
|
QDBusReply<void> updatereply = m_windowediface->call(s_updatemethod, notifyid, eventdata);
|
||||||
|
if (!updatereply.isValid()) {
|
||||||
|
kWarning(s_knotificationarea) << "invalid windowed update reply" << updatereply.error().message();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KNotificationManager::callCloseMethod(const QString ¬ifyid)
|
||||||
|
{
|
||||||
|
if (m_desktopiface && m_desktopiface->isValid()) {
|
||||||
|
QDBusReply<void> closereply = m_desktopiface->call(s_closemethod, notifyid);
|
||||||
|
if (!closereply.isValid()) {
|
||||||
|
kWarning(s_knotificationarea) << "invalid desktop close reply" << closereply.error().message();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (m_windowediface && m_windowediface->isValid()) {
|
||||||
|
QDBusReply<void> closereply = m_windowediface->call(s_closemethod, notifyid);
|
||||||
|
if (!closereply.isValid()) {
|
||||||
|
kWarning(s_knotificationarea) << "invalid windowed close reply" << closereply.error().message();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void KNotificationManager::slotCloseRequested(const QString &eventid)
|
void KNotificationManager::slotCloseRequested(const QString &eventid)
|
||||||
{
|
{
|
||||||
kDebug(s_knotificationarea) << "closing notifications due to interface" << eventid;
|
kDebug(s_knotificationarea) << "closing notifications due to interface" << eventid;
|
||||||
|
|
Loading…
Add table
Reference in a new issue