X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fmainwin.cpp;h=e134bc0bd1f2e85337acf9309a8d37566f344583;hp=7d22ac6f89f1fc486cfdf794fa8b26bbf17b4724;hb=87fd2da996b379382b871eb2da0c40e5c46bbbef;hpb=5931bed270b86e110480561a2bf665dc59747280 diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 7d22ac6f..e134bc0b 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -45,8 +45,6 @@ #include "qtuisettings.h" #include "jumpkeyhandler.h" -#include "uisettings.h" - #include "selectionmodelsynchronizer.h" #include "mappedselectionmodel.h" @@ -59,15 +57,12 @@ #include "settingspages/highlightsettingspage.h" #include "settingspages/identitiessettingspage.h" #include "settingspages/networkssettingspage.h" - +#include "settingspages/notificationssettingspage.h" #include "debugconsole.h" #include "global.h" #include "qtuistyle.h" -#include "desktopnotifications.h" - - MainWin::MainWin(QtUi *_gui, QWidget *parent) : QMainWindow(parent), gui(_gui), @@ -82,12 +77,7 @@ MainWin::MainWin(QtUi *_gui, QWidget *parent) timer(new QTimer(this)), channelListDlg(new ChannelListDlg(this)), settingsDlg(new SettingsDlg(this)), - debugConsole(new DebugConsole(this)), - desktopNotifications(new org::freedesktop::Notifications( - "org.freedesktop.Notifications", - "/org/freedesktop/Notifications", - QDBusConnection::sessionBus(), this)), - notificationId(0) + debugConsole(new DebugConsole(this)) { UiSettings uiSettings; loadTranslation(uiSettings.value("Locale", QLocale::system()).value()); @@ -108,14 +98,15 @@ MainWin::MainWin(QtUi *_gui, QWidget *parent) installEventFilter(new JumpKeyHandler(this)); - UiSettings uiSettings; - QString style = uiSettings.value("Style", QString("")).toString(); - if(style != "") { - QApplication::setStyle(style); - } - +#ifdef HAVE_DBUS + desktopNotifications = new org::freedesktop::Notifications( + "org.freedesktop.Notifications", + "/org/freedesktop/Notifications", + QDBusConnection::sessionBus(), this); + notificationId = 0; connect(desktopNotifications, SIGNAL(NotificationClosed(uint, uint)), this, SLOT(desktopNotificationClosed(uint, uint))); connect(desktopNotifications, SIGNAL(ActionInvoked(uint, const QString&)), this, SLOT(desktopNotificationInvoked(uint, const QString&))); +#endif } void MainWin::init() { @@ -250,6 +241,7 @@ void MainWin::setupSettingsDlg() { settingsDlg->registerSettingsPage(new GeneralSettingsPage(settingsDlg)); settingsDlg->registerSettingsPage(new HighlightSettingsPage(settingsDlg)); settingsDlg->registerSettingsPage(new AliasesSettingsPage(settingsDlg)); + settingsDlg->registerSettingsPage(new NotificationsSettingsPage(settingsDlg)); //Category: General settingsDlg->registerSettingsPage(new IdentitiesSettingsPage(settingsDlg)); settingsDlg->registerSettingsPage(new NetworksSettingsPage(settingsDlg)); @@ -609,13 +601,15 @@ void MainWin::receiveMessage(const Message &msg) { UiSettings uiSettings; #ifndef SPUTDEV - bool displayBubble = uiSettings.value("NotificationBubble", QVariant(true)).toBool(); - bool displayDesktop = uiSettings.value("NotificationDesktop", QVariant(true)).toBool(); + bool displayBubble = uiSettings.value("NotificationBubble", QVariant(true)).toBool(); + bool displayDesktop = uiSettings.value("NotificationDesktop", QVariant(true)).toBool(); if(displayBubble || displayDesktop) { // FIXME don't invoke style engine for this! QString text = QtUi::style()->styleString(Message::mircToInternal(msg.contents())).plainText; - if (displayBubble) displayTrayIconMessage(title, text); - if (displayDesktop) sendDesktopNotification(title, text); + if(displayBubble) displayTrayIconMessage(title, text); +# ifdef HAVE_DBUS + if(displayDesktop) sendDesktopNotification(title, text); +# endif } #endif if(uiSettings.value("AnimateTrayIcon", QVariant(true)).toBool()) { @@ -631,58 +625,59 @@ bool MainWin::event(QEvent *event) { return QMainWindow::event(event); } +#ifdef HAVE_DBUS /* 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 hints; - UiSettings uiSettings; - - hints["x"] = uiSettings.value("NotificationDesktopHintX", QVariant(0)).toInt(); // Standard hint: x location for the popup to show up - hints["y"] = uiSettings.value("NotificationDesktopHintY", QVariant(0)).toInt(); // Standard hint: y location for the popup to show up - - actions << "click" << "Click Me!"; - - QDBusReply reply = desktopNotifications->Notify( - "Quassel", // Application name - notificationId, // ID of previous notification to replace - "", // Icon to display - title, // Summary / Header of the message to display - QString("%1: %2:\n%3").arg(QTime::currentTime().toString()).arg(title).arg(message), // Body of the message to display - actions, // Actions from which the user may choose - hints, // Hints to the server displaying the message - uiSettings.value("NotificationDesktopTimeout", QVariant(5000)).toInt() // Timeout in milliseconds - ); +void MainWin::sendDesktopNotification(const QString &title, const QString &message) { + QStringList actions; + QMap hints; + UiSettings uiSettings; - if (!reply.isValid()) - { - /* ERROR */ - qDebug() << "Error on sending notification..."; - return; - } + hints["x"] = uiSettings.value("NotificationDesktopHintX", QVariant(0)).toInt(); // Standard hint: x location for the popup to show up + hints["y"] = uiSettings.value("NotificationDesktopHintY", QVariant(0)).toInt(); // Standard hint: y location for the popup to show up + + actions << "click" << "Click Me!"; + + QDBusReply reply = desktopNotifications->Notify( + "Quassel", // Application name + notificationId, // ID of previous notification to replace + "", // Icon to display + title, // Summary / Header of the message to display + QString("%1: %2:\n%3").arg(QTime::currentTime().toString()).arg(title).arg(message), // Body of the message to display + actions, // Actions from which the user may choose + hints, // Hints to the server displaying the message + uiSettings.value("NotificationDesktopTimeout", QVariant(5000)).toInt() // Timeout in milliseconds + ); + + if(!reply.isValid()) { + /* ERROR */ + // could also happen if no notification service runs, so... whatever :) + //qDebug() << "Error on sending notification..." << reply.error(); + return; + } - notificationId = reply.value(); + notificationId = reply.value(); - qDebug() << "ID: " << notificationId << " Time: " << QTime::currentTime().toString(); + // qDebug() << "ID: " << notificationId << " Time: " << QTime::currentTime().toString(); } -void MainWin::desktopNotificationClosed(uint id, uint reason) -{ - qDebug() << "OID: " << notificationId << " ID: " << id << " Reason: " << reason << " Time: " << QTime::currentTime().toString(); - notificationId = 0; +void MainWin::desktopNotificationClosed(uint id, uint reason) { + Q_UNUSED(id); Q_UNUSED(reason); + // qDebug() << "OID: " << notificationId << " ID: " << id << " Reason: " << reason << " Time: " << QTime::currentTime().toString(); + notificationId = 0; } -void MainWin::desktopNotificationInvoked(uint id, const QString & action) -{ - qDebug() << "OID: " << notificationId << " ID: " << id << " Action: " << action << " Time: " << QTime::currentTime().toString(); +void MainWin::desktopNotificationInvoked(uint id, const QString & action) { + Q_UNUSED(id); Q_UNUSED(action); + // qDebug() << "OID: " << notificationId << " ID: " << id << " Action: " << action << " Time: " << QTime::currentTime().toString(); } +#endif /* HAVE_DBUS */ void MainWin::displayTrayIconMessage(const QString &title, const QString &message) { systray->showMessage(title, message);