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 @@
#include <QtWidgets/QVBoxLayout>
#include "icons/icons-manager.h"
#include "notify/notification/aggregate-notification.h"
#include "notify/notification/notification.h"
#include "debug.h"
......@@ -84,25 +85,30 @@ void WindowNotifierWindow::createGui()
layout->addWidget(buttons, 0, Qt::AlignCenter);
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())
foreach(const Notification::Callback &i, callbacks)
addButton(buttons, i.Caption, i.Slot);
{
addButton(callbackNotifiation, buttons, i.Caption, i.Slot);
}
else
addButton(buttons, tr("OK"), SLOT(callbackAccept()));
addButton(callbackNotifiation, buttons, tr("OK"), SLOT(callbackAccept()));
connect(CurrentNotification, SIGNAL(closed(Notification *)), this, SLOT(close()));
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();
parent->layout()->addWidget(button);
button->setText(caption);
connect(button, SIGNAL(clicked()), CurrentNotification, slot);
connect(button, SIGNAL(clicked()), CurrentNotification, SLOT(clearDefaultCallback()));
connect(button, SIGNAL(clicked()), notification, slot);
connect(button, SIGNAL(clicked()), notification, SLOT(clearDefaultCallback()));
}
#include "moc_window-notifier-window.cpp"
......@@ -37,7 +37,7 @@ class WindowNotifierWindow : public QDialog, DesktopAwareObject
Notification *CurrentNotification;
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:
explicit WindowNotifierWindow(Notification *notification, QWidget *parent = 0);
......
......@@ -325,7 +325,11 @@ void FreedesktopNotify::actionInvoked(unsigned int id, QString action)
if (!notification)
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;
while (metaObject)
......@@ -340,8 +344,8 @@ void FreedesktopNotify::actionInvoked(unsigned int id, QString action)
if (-1 == slotIndex)
return;
QMetaMethod slot = notification->metaObject()->method(slotIndex);
slot.invoke(notification, Qt::DirectConnection);
QMetaMethod slot = callbackNotifiation->metaObject()->method(slotIndex);
slot.invoke(callbackNotifiation, Qt::DirectConnection);
notification->clearDefaultCallback();
QList<QVariant> args;
......
......@@ -77,6 +77,10 @@ Hint::Hint(QWidget *parent, Notification *notification)
if (Application::instance()->configuration()->deprecatedApi()->readBoolEntry("Hints", "ShowOnlyNecessaryButtons") && !notification->requireCallback())
showButtons = false;
auto callbackNotifiation = notification;
if (qobject_cast<AggregateNotification *>(callbackNotifiation))
callbackNotifiation = qobject_cast<AggregateNotification *>(callbackNotifiation)->notifications()[0];
if (showButtons)
{
callbacksBox = new QHBoxLayout();
......@@ -86,8 +90,8 @@ Hint::Hint(QWidget *parent, Notification *notification)
foreach (const Notification::Callback &i, callbacks)
{
QPushButton *button = new QPushButton(i.Caption, this);
connect(button, SIGNAL(clicked(bool)), notification, i.Slot);
connect(button, SIGNAL(clicked(bool)), notification, SLOT(clearDefaultCallback()));
connect(button, SIGNAL(clicked(bool)), callbackNotifiation, i.Slot);
connect(button, SIGNAL(clicked(bool)), callbackNotifiation, SLOT(clearDefaultCallback()));
callbacksBox->addWidget(button);
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