Make QtDBus optional (i.e. compile even if no dbus support is present)
authorManuel Nickschas <sputnick@quassel-irc.org>
Fri, 4 Jul 2008 00:00:22 +0000 (02:00 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Tue, 22 Jul 2008 19:42:35 +0000 (21:42 +0200)
CMakeLists.txt
src/qtui/CMakeLists.txt
src/qtui/mainwin.cpp
src/qtui/mainwin.h

index 57af949..01b33b6 100644 (file)
@@ -83,6 +83,12 @@ endif(QT)
 # Now that we have the correct $PATH, lets find Qt!
 find_package(Qt4 REQUIRED)
 
 # 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})
 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)
 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
   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)
 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 
   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 
index a636eb2..3dbfc88 100644 (file)
@@ -105,7 +105,10 @@ endforeach(FRM ${SP_FORMS})
 
 qt4_wrap_cpp(MOC ${MOC_HDRS} ${SPHDR})
 qt4_wrap_ui(UI ${FORMPATH} ${SPFRM})
 
 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
 
 include_directories(${CMAKE_SOURCE_DIR}/src/common
                     ${CMAKE_SOURCE_DIR}/src/client
index 7d22ac6..d874a21 100644 (file)
@@ -65,9 +65,6 @@
 #include "global.h"
 #include "qtuistyle.h"
 
 #include "global.h"
 #include "qtuistyle.h"
 
-#include "desktopnotifications.h"
-
-
 MainWin::MainWin(QtUi *_gui, QWidget *parent)
   : QMainWindow(parent),
     gui(_gui),
 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)),
     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<QLocale>());
 {
   UiSettings uiSettings;
   loadTranslation(uiSettings.value("Locale", QLocale::system()).value<QLocale>());
@@ -114,8 +106,15 @@ MainWin::MainWin(QtUi *_gui, QWidget *parent)
     QApplication::setStyle(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&)));
   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() {
 }
 
 void MainWin::init() {
@@ -609,13 +608,15 @@ void MainWin::receiveMessage(const Message &msg) {
     UiSettings uiSettings;
 
 #ifndef SPUTDEV
     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 || 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()) {
     }
 #endif
     if(uiSettings.value("AnimateTrayIcon", QVariant(true)).toBool()) {
@@ -631,58 +632,59 @@ bool MainWin::event(QEvent *event) {
   return QMainWindow::event(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
 */
 
 /*
 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;
-    UiSettings uiSettings;
+void MainWin::sendDesktopNotification(const QString &title, const QString &message) {
+  QStringList actions;
+  QMap<QString, QVariant> 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<uint> 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<uint> 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)
 {
 }
 
 
 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)
 {
 }
 
 
 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);
 
 void MainWin::displayTrayIconMessage(const QString &title, const QString &message) {
   systray->showMessage(title, message);
index 9787832..b2ea75a 100644 (file)
@@ -29,7 +29,6 @@
 #include <QSystemTrayIcon>
 #include <QTimer>
 
 #include <QSystemTrayIcon>
 #include <QTimer>
 
-
 class ServerListDlg;
 class ChannelListDlg;
 class CoreConnectDlg;
 class ServerListDlg;
 class ChannelListDlg;
 class CoreConnectDlg;
@@ -41,7 +40,9 @@ class Message;
 class NickListWidget;
 class DebugConsole;
 
 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 {
 
 //!\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);
     void addBufferView(BufferViewConfig *config = 0);
 
     void displayTrayIconMessage(const QString &title, const QString &message);
+
+#ifdef HAVE_DBUS
     void sendDesktopNotification(const QString &title, const QString &message);
     void sendDesktopNotification(const QString &title, const QString &message);
+#endif
 
     virtual bool event(QEvent *event);
 
 
     virtual bool event(QEvent *event);
 
@@ -103,8 +107,10 @@ class MainWin : public QMainWindow {
     void loadLayout();
     void saveLayout();
 
     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);
 
   signals:
     void connectToCore(const QVariantMap &connInfo);
@@ -154,8 +160,13 @@ class MainWin : public QMainWindow {
     QList<QDockWidget *> _netViews;
     NickListWidget *nickListWidget;
 
     QList<QDockWidget *> _netViews;
     NickListWidget *nickListWidget;
 
-       org::freedesktop::Notifications *desktopNotifications;
-       quint32 notificationId;
+    QAction *actionEditNetworks;
+    QList<QAction *> networkActions;
+
+#ifdef HAVE_DBUS
+    org::freedesktop::Notifications *desktopNotifications;
+    quint32 notificationId;
+#endif
 
     friend class QtUi;
 };
 
     friend class QtUi;
 };