+void MainWin::receiveMessage(const Message &msg) {
+ if(QApplication::activeWindow() != 0)
+ return;
+
+ if(msg.flags() & Message::Highlight || msg.bufferInfo().type() == BufferInfo::QueryBuffer) {
+ QString title = msg.bufferInfo().bufferName();;
+ if(msg.bufferInfo().type() != BufferInfo::QueryBuffer) {
+ QString sender = msg.sender();
+ int i = sender.indexOf("!");
+ if(i != -1)
+ sender = sender.left(i);
+ title += QString(" - %1").arg(sender);
+ }
+
+ UiSettings uiSettings;
+
+#ifndef SPUTDEV
+ if(uiSettings.value("DisplayPopupMessages", QVariant(true)).toBool()) {
+ // FIXME don't invoke style engine for this!
+ QString text = QtUi::style()->styleString(Message::mircToInternal(msg.contents())).plainText;
+ displayTrayIconMessage(title, text);
+ sendDesktopNotification(title, text);
+ }
+#endif
+ if(uiSettings.value("AnimateTrayIcon", QVariant(true)).toBool()) {
+ QApplication::alert(this);
+ setTrayIconActivity(true);
+ }
+ }
+}
+
+bool MainWin::event(QEvent *event) {
+ if(event->type() == QEvent::WindowActivate)
+ setTrayIconActivity(false);
+ return QMainWindow::event(event);
+}
+
+
+/*
+Using the notification-daemon from Freedesktop's Galago project
+http://www.galago-project.org/specs/notification/0.9/x408.html#command-notify
+*/
+void MainWin::sendDesktopNotification(const QString &title, const QString &message)
+{
+ QStringList actions;
+ QMap<QString, QVariant> hints;
+ QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "", "Notify");
+
+ hints["x"] = 100; // Standard hint: x location for the popup to show up
+ hints["y"] = 100; // Standard hint: y location for the popup to show up
+
+ msg << "Quassel"; // Application name
+ msg << quint32(0); // ID of previous notification to replace
+ msg << ""; // Icon to display
+ msg << "Quassel: " + title; // Summary / Header of the message to display
+ msg << message; // Body of the message to display
+ msg << actions; // Actions from which the user may choose
+ msg << hints; // Hints to the server displaying the message
+ msg << qint32(10000); // Timeout in milliseconds
+
+ (void)QDBusConnection::sessionBus().call(msg); // Would return a message containing the id of this notification
+}
+
+
+void MainWin::displayTrayIconMessage(const QString &title, const QString &message) {
+ systray->showMessage(title, message);
+}
+
+void MainWin::setTrayIconActivity(bool active) {
+ if(active) {
+ if(!timer->isActive())
+ timer->start(500);
+ } else {
+ timer->stop();
+ systray->setIcon(onlineTrayIcon);
+ }
+}
+
+void MainWin::makeTrayIconBlink() {
+ if(trayIconActive) {
+ systray->setIcon(onlineTrayIcon);
+ trayIconActive = false;
+ } else {
+ systray->setIcon(activeTrayIcon);
+ trayIconActive = true;
+ }