Skip to content

Commit

Permalink
Added actions to dbus popup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed Apr 9, 2024
1 parent 7c75fc3 commit dcdda57
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/psidbusnotifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ PsiDBusNotifier::PsiDBusNotifier(QObject *parent) :
QDBusConnection::sessionBus().connect("org.freedesktop.Notifications", "/org/freedesktop/Notifications",
"org.freedesktop.Notifications", "NotificationClosed", this,
SLOT(popupClosed(uint, uint)));
QDBusConnection::sessionBus().connect("org.freedesktop.Notifications", "/org/freedesktop/Notifications",
"org.freedesktop.Notifications", "ActionInvoked", this,
SLOT(actionInvoked(uint, QString)));
lifeTimer_->setSingleShot(true);
connect(lifeTimer_, SIGNAL(timeout()), SLOT(readyToDie()));
}
Expand Down Expand Up @@ -291,15 +294,14 @@ void PsiDBusNotifier::popup(PsiAccount *account, PopupManager::PopupType type, c
args << QVariant("");
args << QString(title);
args << QString(text);
args << QStringList();
args << (QStringList() << "open" << tr("Open"));
args << hints;
args << lifeTime;
m.setArguments(args);
QDBusPendingCall call = QDBusConnection::sessionBus().asyncCall(m);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);

connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher *)), this,
SLOT(asyncCallFinished(QDBusPendingCallWatcher *)));
connect(watcher, &QDBusPendingCallWatcher::finished, this, &PsiDBusNotifier::asyncCallFinished);

lifeTime = (lifeTime < 0) ? lifeTime : qMax(minLifeTime, lifeTime);
if (lifeTime >= 0)
Expand Down Expand Up @@ -374,28 +376,27 @@ void PsiDBusNotifier::asyncCallFinished(QDBusPendingCallWatcher *watcher)
void PsiDBusNotifier::popupClosed(uint id, uint reason)
{
if (id_ != 0 && id_ == id) {
if (reason == 2) {
if (account_) {
if (event_) {
account_->psi()->processEvent(event_, UserAction);
} else if (jid_.isValid()) {
account_->actionDefault(Jid(jid_.bare()));
}
}
}
readyToDie();
}
}

void PsiDBusNotifier::actionInvoked(uint id, const QString &actionKey)
{
if (id_ != 0 && id_ == id && account_) {
Q_UNUSED(actionKey);
if (event_) {
account_->psi()->processEvent(event_, UserAction);
} else if (jid_.isValid()) {
account_->actionDefault(Jid(jid_.bare()));
}
}
}

void PsiDBusNotifier::readyToDie()
{
if (lifeTimer_->isActive()) {
lifeTimer_->stop();
}

QDBusConnection::sessionBus().disconnect("org.freedesktop.Notifications", "/org/freedesktop/Notifications",
"org.freedesktop.Notifications", "NotificationClosed", this,
SLOT(popupClosed(uint, uint)));
deleteLater();
}

Expand Down
1 change: 1 addition & 0 deletions src/psidbusnotifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class PsiDBusNotifier : public QObject, public PsiPopupInterface {

private slots:
void popupClosed(uint id, uint reason);
void actionInvoked(uint id, const QString &actionKey);
void asyncCallFinished(QDBusPendingCallWatcher *);
void readyToDie();

Expand Down

0 comments on commit dcdda57

Please sign in to comment.