Commit c3947c75 authored by Rafał Malinowski's avatar Rafał Malinowski

notify: fix invoking callback on file transfer notifications

Signed-off-by: Rafał Malinowski's avatarRafał Przemysław Malinowski <rafal.przemyslaw.malinowski@gmail.com>
parent ef554911
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <QtWidgets/QVBoxLayout> #include <QtWidgets/QVBoxLayout>
#include "icons/icons-manager.h" #include "icons/icons-manager.h"
#include "notify/notification/aggregate-notification.h"
#include "notify/notification/notification.h" #include "notify/notification/notification.h"
#include "debug.h" #include "debug.h"
...@@ -84,25 +85,30 @@ void WindowNotifierWindow::createGui() ...@@ -84,25 +85,30 @@ void WindowNotifierWindow::createGui()
layout->addWidget(buttons, 0, Qt::AlignCenter); layout->addWidget(buttons, 0, Qt::AlignCenter);
const QList<Notification::Callback> callbacks = CurrentNotification->getCallbacks(); const QList<Notification::Callback> callbacks = CurrentNotification->getCallbacks();
auto callbackNotifiation = CurrentNotification;
if (qobject_cast<AggregateNotification *>(callbackNotifiation))
callbackNotifiation = qobject_cast<AggregateNotification *>(callbackNotifiation)->notifications()[0];
if (!callbacks.isEmpty()) if (!callbacks.isEmpty())
foreach(const Notification::Callback &i, callbacks) foreach(const Notification::Callback &i, callbacks)
addButton(buttons, i.Caption, i.Slot); {
addButton(callbackNotifiation, buttons, i.Caption, i.Slot);
}
else else
addButton(buttons, tr("OK"), SLOT(callbackAccept())); addButton(callbackNotifiation, buttons, tr("OK"), SLOT(callbackAccept()));
connect(CurrentNotification, SIGNAL(closed(Notification *)), this, SLOT(close())); connect(CurrentNotification, SIGNAL(closed(Notification *)), this, SLOT(close()));
buttons->setMaximumSize(buttons->sizeHint()); buttons->setMaximumSize(buttons->sizeHint());
} }
void WindowNotifierWindow::addButton(QWidget *parent, const QString &caption, const char *slot) void WindowNotifierWindow::addButton(Notification *notification, QWidget *parent, const QString &caption, const char *slot)
{ {
QPushButton *button = new QPushButton(); QPushButton *button = new QPushButton();
parent->layout()->addWidget(button); parent->layout()->addWidget(button);
button->setText(caption); button->setText(caption);
connect(button, SIGNAL(clicked()), CurrentNotification, slot); connect(button, SIGNAL(clicked()), notification, slot);
connect(button, SIGNAL(clicked()), CurrentNotification, SLOT(clearDefaultCallback())); connect(button, SIGNAL(clicked()), notification, SLOT(clearDefaultCallback()));
} }
#include "moc_window-notifier-window.cpp" #include "moc_window-notifier-window.cpp"
...@@ -37,7 +37,7 @@ class WindowNotifierWindow : public QDialog, DesktopAwareObject ...@@ -37,7 +37,7 @@ class WindowNotifierWindow : public QDialog, DesktopAwareObject
Notification *CurrentNotification; Notification *CurrentNotification;
void createGui(); void createGui();
void addButton(QWidget *parent, const QString &caption, const char *slot); void addButton(Notification *notification, QWidget *parent, const QString &caption, const char *slot);
public: public:
explicit WindowNotifierWindow(Notification *notification, QWidget *parent = 0); explicit WindowNotifierWindow(Notification *notification, QWidget *parent = 0);
......
...@@ -325,7 +325,11 @@ void FreedesktopNotify::actionInvoked(unsigned int id, QString action) ...@@ -325,7 +325,11 @@ void FreedesktopNotify::actionInvoked(unsigned int id, QString action)
if (!notification) if (!notification)
return; return;
const QMetaObject *metaObject = notification->metaObject(); auto callbackNotifiation = notification;
if (qobject_cast<AggregateNotification *>(callbackNotifiation))
callbackNotifiation = qobject_cast<AggregateNotification *>(callbackNotifiation)->notifications()[0];
const QMetaObject *metaObject = callbackNotifiation->metaObject();
int slotIndex = -1; int slotIndex = -1;
while (metaObject) while (metaObject)
...@@ -340,8 +344,8 @@ void FreedesktopNotify::actionInvoked(unsigned int id, QString action) ...@@ -340,8 +344,8 @@ void FreedesktopNotify::actionInvoked(unsigned int id, QString action)
if (-1 == slotIndex) if (-1 == slotIndex)
return; return;
QMetaMethod slot = notification->metaObject()->method(slotIndex); QMetaMethod slot = callbackNotifiation->metaObject()->method(slotIndex);
slot.invoke(notification, Qt::DirectConnection); slot.invoke(callbackNotifiation, Qt::DirectConnection);
notification->clearDefaultCallback(); notification->clearDefaultCallback();
QList<QVariant> args; QList<QVariant> args;
......
...@@ -77,6 +77,10 @@ Hint::Hint(QWidget *parent, Notification *notification) ...@@ -77,6 +77,10 @@ Hint::Hint(QWidget *parent, Notification *notification)
if (Application::instance()->configuration()->deprecatedApi()->readBoolEntry("Hints", "ShowOnlyNecessaryButtons") && !notification->requireCallback()) if (Application::instance()->configuration()->deprecatedApi()->readBoolEntry("Hints", "ShowOnlyNecessaryButtons") && !notification->requireCallback())
showButtons = false; showButtons = false;
auto callbackNotifiation = notification;
if (qobject_cast<AggregateNotification *>(callbackNotifiation))
callbackNotifiation = qobject_cast<AggregateNotification *>(callbackNotifiation)->notifications()[0];
if (showButtons) if (showButtons)
{ {
callbacksBox = new QHBoxLayout(); callbacksBox = new QHBoxLayout();
...@@ -86,8 +90,8 @@ Hint::Hint(QWidget *parent, Notification *notification) ...@@ -86,8 +90,8 @@ Hint::Hint(QWidget *parent, Notification *notification)
foreach (const Notification::Callback &i, callbacks) foreach (const Notification::Callback &i, callbacks)
{ {
QPushButton *button = new QPushButton(i.Caption, this); QPushButton *button = new QPushButton(i.Caption, this);
connect(button, SIGNAL(clicked(bool)), notification, i.Slot); connect(button, SIGNAL(clicked(bool)), callbackNotifiation, i.Slot);
connect(button, SIGNAL(clicked(bool)), notification, SLOT(clearDefaultCallback())); connect(button, SIGNAL(clicked(bool)), callbackNotifiation, SLOT(clearDefaultCallback()));
callbacksBox->addWidget(button); callbacksBox->addWidget(button);
callbacksBox->addStretch(1); callbacksBox->addStretch(1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment