From dd10a98793d8c158417a8830194ca9b5d1302424 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Fri, 4 Jul 2008 02:00:22 +0200 Subject: [PATCH] Make QtDBus optional (i.e. compile even if no dbus support is present) --- CMakeLists.txt | 10 ++++- src/qtui/CMakeLists.txt | 5 ++- src/qtui/mainwin.cpp | 86 +++++++++++++++++++++-------------------- src/qtui/mainwin.h | 23 ++++++++--- 4 files changed, 73 insertions(+), 51 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 57af9490..01b33b68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,6 +83,12 @@ endif(QT) # Now that we have the correct $PATH, lets find Qt! find_package(Qt4 REQUIRED) +if(QT_QTDBUS_FOUND) + add_definitions(-DHAVE_DBUS) + set(LINK_DBUS DBUS) + set(HAVE_DBUS true) +endif(QT_QTDBUS_FOUND) + set(QT_DONT_USE_QTGUI 1) include(${QT_USE_FILE}) include_directories(${QT_INCLUDES}) @@ -174,7 +180,7 @@ if(WANT_CORE) endif(WANT_CORE) if(WANT_QTCLIENT) - setup_qt4_variables(DBUS GUI NETWORK) + setup_qt4_variables(${LINK_DBUS} GUI NETWORK) add_executable(quasselclient WIN32 ${CMAKE_SOURCE_DIR}/src/common/main.cpp ${RC_ICONS} ${RC_QUASSEL_ICONS} ${RC_I18N} ${WIN32_RC}) set_target_properties(quasselclient PROPERTIES @@ -184,7 +190,7 @@ if(WANT_QTCLIENT) endif(WANT_QTCLIENT) if(WANT_MONO) - setup_qt4_variables(DBUS GUI NETWORK SCRIPT SQL) + setup_qt4_variables(${LINK_DBUS} GUI NETWORK SCRIPT SQL) add_executable(quassel WIN32 ${CMAKE_SOURCE_DIR}/src/common/main.cpp ${RC_ICONS} ${RC_QUASSEL_ICONS} ${RC_SQL} ${RC_I18N} ${WIN32_RC}) set_target_properties(quassel PROPERTIES diff --git a/src/qtui/CMakeLists.txt b/src/qtui/CMakeLists.txt index a636eb20..3dbfc88d 100644 --- a/src/qtui/CMakeLists.txt +++ b/src/qtui/CMakeLists.txt @@ -105,7 +105,10 @@ endforeach(FRM ${SP_FORMS}) qt4_wrap_cpp(MOC ${MOC_HDRS} ${SPHDR}) qt4_wrap_ui(UI ${FORMPATH} ${SPFRM}) -qt4_add_dbus_interface(DBUS ../../interfaces/org.freedesktop.Notifications.xml desktopnotifications) + +IF(HAVE_DBUS) + qt4_add_dbus_interface(DBUS ../../interfaces/org.freedesktop.Notifications.xml desktopnotifications) +ENDIF(HAVE_DBUS) include_directories(${CMAKE_SOURCE_DIR}/src/common ${CMAKE_SOURCE_DIR}/src/client diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 7d22ac6f..d874a215 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -65,9 +65,6 @@ #include "global.h" #include "qtuistyle.h" -#include "desktopnotifications.h" - - MainWin::MainWin(QtUi *_gui, QWidget *parent) : QMainWindow(parent), gui(_gui), @@ -82,12 +79,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()); @@ -114,8 +106,15 @@ MainWin::MainWin(QtUi *_gui, QWidget *parent) 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() { @@ -609,13 +608,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 +632,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; +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 + 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!"; + 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 - ); + 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 */ - qDebug() << "Error on sending notification..."; - return; - } + if (!reply.isValid()) + { + /* ERROR */ + qDebug() << "Error on sending notification..."; + 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; + 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(); + 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); diff --git a/src/qtui/mainwin.h b/src/qtui/mainwin.h index 9787832c..b2ea75a4 100644 --- a/src/qtui/mainwin.h +++ b/src/qtui/mainwin.h @@ -29,7 +29,6 @@ #include #include - class ServerListDlg; class ChannelListDlg; class CoreConnectDlg; @@ -41,7 +40,9 @@ class Message; class NickListWidget; class DebugConsole; -#include "desktopnotifications.h" +#ifdef HAVE_DBUS +# include "desktopnotifications.h" +#endif //!\brief The main window of Quassel's QtUi. class MainWin : public QMainWindow { @@ -55,7 +56,10 @@ class MainWin : public QMainWindow { void addBufferView(BufferViewConfig *config = 0); void displayTrayIconMessage(const QString &title, const QString &message); + +#ifdef HAVE_DBUS void sendDesktopNotification(const QString &title, const QString &message); +#endif virtual bool event(QEvent *event); @@ -103,8 +107,10 @@ class MainWin : public QMainWindow { void loadLayout(); void saveLayout(); - void desktopNotificationClosed(uint id, uint reason); - void desktopNotificationInvoked(uint id, const QString & action); +#ifdef HAVE_DBUS + void desktopNotificationClosed(uint id, uint reason); + void desktopNotificationInvoked(uint id, const QString & action); +#endif signals: void connectToCore(const QVariantMap &connInfo); @@ -154,8 +160,13 @@ class MainWin : public QMainWindow { QList _netViews; NickListWidget *nickListWidget; - org::freedesktop::Notifications *desktopNotifications; - quint32 notificationId; + QAction *actionEditNetworks; + QList networkActions; + +#ifdef HAVE_DBUS + org::freedesktop::Notifications *desktopNotifications; + quint32 notificationId; +#endif friend class QtUi; }; -- 2.20.1