QString message = QString("<b><%1></b> %2").arg(n.sender, Qt::escape(n.message));
KNotification *notification = KNotification::event("Highlight", message, DesktopIcon("dialog-information"), QtUi::mainWindow(),
KNotification::Persistent|KNotification::RaiseWidgetOnActivation|KNotification::CloseWhenWidgetActivated);
- connect(notification, SIGNAL(activated()), SLOT(notificationActivated()));
+ connect(notification, SIGNAL(activated(uint)), SLOT(notificationActivated()));
+ connect(notification, SIGNAL(closed()), SLOT(notificationClosed()));
+ notification->setActions(QStringList("View"));
+ _notificationIds[notification] = n.notificationId;
+
QtUi::mainWindow()->systemTray()->setAlert(true);
}
}
void KNotificationBackend::notificationActivated() {
- emit activated();
+ uint id = 0;
+ KNotification *n = qobject_cast<KNotification *>(sender());
+ if(n && _notificationIds.contains(n))
+ id = _notificationIds.value(n);
+
+ emit activated(id);
+}
+
+void KNotificationBackend::notificationClosed() {
+ KNotification *n = qobject_cast<KNotification *>(sender());
+ if(n && _notificationIds.contains(n))
+ _notificationIds.remove(n);
}
SettingsPage *KNotificationBackend::createConfigWidget() const {
private slots:
void notificationActivated();
+ void notificationClosed();
private:
class ConfigWidget;
+
+ QHash<KNotification *, uint> _notificationIds;
};
class KNotificationBackend::ConfigWidget : public SettingsPage {
#include "abstractnotificationbackend.h"
#include "actioncollection.h"
+#include "buffermodel.h"
#include "chatlinemodel.h"
#include "contextmenuactionprovider.h"
#include "mainwin.h"
#include "util.h"
QHash<QString, ActionCollection *> QtUi::_actionCollections;
+
+#ifdef Q_WS_X11
+# include <QX11Info>
+#endif
+
QPointer<QtUi> QtUi::_instance = 0;
QPointer<MainWin> QtUi::_mainWin = 0;
QList<AbstractNotificationBackend *> QtUi::_notificationBackends;
void QtUi::registerNotificationBackend(AbstractNotificationBackend *backend) {
if(!_notificationBackends.contains(backend)) {
_notificationBackends.append(backend);
- instance()->connect(backend, SIGNAL(activated()), SLOT(notificationActivated()));
+ instance()->connect(backend, SIGNAL(activated(uint)), SLOT(notificationActivated(uint)));
}
}
return _notifications;
}
-void QtUi::notificationActivated() {
- // this might not work with some window managers
+void QtUi::notificationActivated(uint notificationId) {
+ if(notificationId != 0) {
+ QList<AbstractNotificationBackend::Notification>::iterator i = _notifications.begin();
+ while(i != _notifications.end()) {
+ if((*i).notificationId == notificationId) {
+ BufferId bufId = (*i).bufferId;
+ if(bufId.isValid())
+ Client::bufferModel()->switchToBuffer(bufId);
+ _notifications.erase(i);
+ break;
+ }
+ }
+ }
+
+#ifdef Q_WS_X11
+ // Bypass focus stealing prevention
+ QX11Info::setAppUserTime(QX11Info::appTime());
+#endif
+
+ if(_mainWin->windowState() & Qt::WindowMinimized) {
+ // restore
+ _mainWin->setWindowState((_mainWin->windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
+ _mainWin->show();
+ }
_mainWin->raise();
_mainWin->activateWindow();
}
protected slots:
void connectedToCore();
void disconnectedFromCore();
- void notificationActivated();
+ void notificationActivated(uint notificationId);
private:
static QPointer<QtUi> _instance;
#include "systemtray.h"
SystrayNotificationBackend::SystrayNotificationBackend(QObject *parent)
- : AbstractNotificationBackend(parent)
+ : AbstractNotificationBackend(parent), _activeId(0)
{
NotificationSettings notificationSettings;
_showBubble = notificationSettings.value("Systray/ShowBubble", true).toBool();
notificationSettings.notify("Systray/ShowBubble", this, SLOT(showBubbleChanged(const QVariant &)));
notificationSettings.notify("Systray/Animate", this, SLOT(animateChanged(const QVariant &)));
- connect(QtUi::mainWindow()->systemTray(), SIGNAL(messageClicked()), this, SIGNAL(activated()));
+ connect(QtUi::mainWindow()->systemTray(), SIGNAL(messageClicked()), SLOT(notificationActivated()));
}
void SystrayNotificationBackend::notify(const Notification ¬ification) {
// for now, we just show the last message
if(_notifications.isEmpty()) return;
Notification n = _notifications.takeLast();
+ _activeId = n.notificationId;
QString title = Client::networkModel()->networkName(n.bufferId) + " - " + Client::networkModel()->bufferName(n.bufferId);
QString message = QString("<%1> %2").arg(n.sender, n.message);
QtUi::mainWindow()->systemTray()->showMessage(title, message);
#endif
}
+void SystrayNotificationBackend::notificationActivated() {
+ emit activated(_activeId);
+}
+
void SystrayNotificationBackend::showBubbleChanged(const QVariant &v) {
_showBubble = v.toBool();
}
private slots:
void showBubble();
void closeBubble();
+ void notificationActivated();
void animateChanged(const QVariant &);
void showBubbleChanged(const QVariant &);
bool _showBubble;
bool _animate;
QList<Notification> _notifications;
+ uint _activeId;
};
class SystrayNotificationBackend::ConfigWidget : public SettingsPage {
signals:
//! May be emitted by the notification to tell the MainWin to raise itself
- void activated();
+ void activated(uint notificationId = 0);
};