Allow compilation without QSystemTrayIcon
authorManuel Nickschas <sputnick@quassel-irc.org>
Sun, 17 Jan 2010 19:48:12 +0000 (20:48 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 17 Jan 2010 19:48:12 +0000 (20:48 +0100)
On some platforms (such as N900), Qt doesn't support a tray icon.
This adds tons of #defines to allow compilation in that case.

src/qtui/mainwin.cpp
src/qtui/mainwin.h
src/qtui/qtui.cpp
src/qtui/qtui.h
src/qtui/settingspages/appearancesettingspage.cpp
src/qtui/systemtray.cpp
src/qtui/systemtray.h
src/qtui/systraynotificationbackend.cpp
src/qtui/systraynotificationbackend.h

index 2a5b379..d0a623f 100644 (file)
@@ -194,7 +194,9 @@ void MainWin::init() {
 
 #ifndef HAVE_KDE
   QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
+#  ifndef QT_NO_SYSTEMTRAYICON
   QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
+#  endif
 #  ifdef HAVE_PHONON
   QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
 #  endif
@@ -277,9 +279,13 @@ void MainWin::restoreStateFromSettings(UiSettings &s) {
   move(_normalPos);
 #endif
 
-  if(s.value("MainWinHidden").toBool())
+#ifndef QT_NO_SYSTEMTRAYICON
+  if(s.value("MainWinHidden").toBool()) {
     hideToTray();
-  else if(s.value("MainWinMinimized").toBool())
+    return;
+  }
+#endif
+  if(s.value("MainWinMinimized").toBool())
     showMinimized();
   else if(maximized)
     showMaximized();
@@ -675,7 +681,9 @@ void MainWin::saveStatusBarStatus(bool enabled) {
 }
 
 void MainWin::setupSystray() {
+#ifndef QT_NO_SYSTEMTRAYICON
   _systemTray = new SystemTray(this);
+#endif
 }
 
 void MainWin::setupToolBars() {
@@ -739,7 +747,9 @@ void MainWin::setConnectedState() {
 
   _coreConnectionStatusWidget->setVisible(!Client::internalCore());
   updateIcon();
+#ifndef QT_NO_SYSTEMTRAYICON
   systemTray()->setState(SystemTray::Active);
+#endif
 
   if(Client::networkIds().isEmpty()) {
     IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
@@ -805,7 +815,9 @@ void MainWin::setDisconnectedState() {
   if(_msgProcessorStatusWidget)
     _msgProcessorStatusWidget->setProgress(0, 0);
   updateIcon();
+#ifndef QT_NO_SYSTEMTRAYICON
   systemTray()->setState(SystemTray::Inactive);
+#endif
 }
 
 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage) {
@@ -999,6 +1011,7 @@ void MainWin::resizeEvent(QResizeEvent *event) {
 }
 
 void MainWin::closeEvent(QCloseEvent *event) {
+#ifndef QT_NO_SYSTEMTRAYICON
   QtUiSettings s;
   QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
   Q_ASSERT(app);
@@ -1009,6 +1022,10 @@ void MainWin::closeEvent(QCloseEvent *event) {
     event->accept();
     quit();
   }
+#else
+  event->accept();
+  quit();
+#endif
 }
 
 void MainWin::changeEvent(QEvent *event) {
@@ -1020,6 +1037,8 @@ void MainWin::changeEvent(QEvent *event) {
   QMainWindow::changeEvent(event);
 }
 
+#ifndef QT_NO_SYSTEMTRAYICON
+
 void MainWin::hideToTray() {
   if(!systemTray()->isSystemTrayAvailable()) {
     qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
@@ -1052,6 +1071,8 @@ void MainWin::toggleMinimizedToTray() {
 #endif
 }
 
+#endif /* QT_NO_SYSTEMTRAYICON */
+
 void MainWin::forceActivated() {
 #ifdef HAVE_KDE
   show();
index bc4ba1e..4f3f750 100644 (file)
@@ -31,8 +31,6 @@
 #  include <windows.h>
 #endif
 
-#include <QSystemTrayIcon>
-
 #include "qtui.h"
 #include "titlesetter.h"
 #include "uisettings.h"
@@ -75,9 +73,11 @@ class MainWin
     void addBufferView(ClientBufferViewConfig *config);
     BufferView *allBuffersView() const;
 
-    BufferWidget *bufferWidget() const { return _bufferWidget; }
+    inline BufferWidget *bufferWidget() const { return _bufferWidget; }
 
-    inline SystemTray *systemTray() const;
+#ifndef QT_NO_SYSTEMTRAYICON
+    inline SystemTray *systemTray() const { return _systemTray; }
+#endif
 
     bool event(QEvent *event);
 
@@ -90,7 +90,9 @@ class MainWin
   public slots:
     void showStatusBarMessage(const QString &message);
 
+#ifndef QT_NO_SYSTEMTRAYICON
     void toggleMinimizedToTray();
+#endif
 
     //! Bring window to front and focus it
     void forceActivated();
@@ -189,9 +191,10 @@ class MainWin
     void updateIcon();
     void enableMenus();
 
+#ifndef QT_NO_SYSTEMTRAYICON
     void hideToTray();
-
     SystemTray *_systemTray;
+#endif
 
     QList<BufferViewDock *> _bufferViews;
     BufferWidget *_bufferWidget;
@@ -218,8 +221,4 @@ class MainWin
     friend class QtUi;
 };
 
-SystemTray *MainWin::systemTray() const {
-  return _systemTray;
-}
-
 #endif
index 0a2de59..5495758 100644 (file)
@@ -28,6 +28,7 @@
 #include "qtuimessageprocessor.h"
 #include "qtuisettings.h"
 #include "qtuistyle.h"
+#include "systemtray.h"
 #include "toolbaractionprovider.h"
 #include "types.h"
 #include "util.h"
@@ -88,6 +89,14 @@ void QtUi::disconnectedFromCore() {
   _mainWin->disconnectedFromCore();
 }
 
+bool QtUi::haveSystemTray() {
+#ifdef QT_NO_SYSTEMTRAYICON
+  return false;
+#else
+  return mainWindow()->systemTray()->isSystemTrayAvailable();
+#endif
+}
+
 void QtUi::registerNotificationBackend(AbstractNotificationBackend *backend) {
   if(!_notificationBackends.contains(backend)) {
     _notificationBackends.append(backend);
index 8b223af..33a8462 100644 (file)
@@ -49,6 +49,8 @@ public:
   inline static QtUiStyle *style();
   inline static MainWin *mainWindow();
 
+  static bool haveSystemTray();
+
   /* Notifications */
 
   static void registerNotificationBackend(AbstractNotificationBackend *);
index 7132f68..91369f9 100644 (file)
@@ -39,6 +39,9 @@ AppearanceSettingsPage::AppearanceSettingsPage(QWidget *parent)
 #ifdef Q_WS_MAC
   ui.minimizeOnClose->hide();
 #endif
+#ifdef QT_NO_SYSTEMTRAYICON
+  ui.useSystemTrayIcon->hide();
+#endif
 
   initAutoWidgets();
   initStyleComboBox();
index 225cd86..8c34655 100644 (file)
@@ -18,6 +18,8 @@
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
 
+#ifndef QT_NO_SYSTEMTRAYICON
+
 #include <QMenu>
 
 #include "systemtray.h"
@@ -193,3 +195,5 @@ void SystemTray::on_activated(QSystemTrayIcon::ActivationReason reason) {
 
   }
 }
+
+#endif /* QT_NO_SYSTEMTRAYICON */
index d98bf46..cdb66d7 100644 (file)
@@ -21,6 +21,8 @@
 #ifndef SYSTEMTRAY_H_
 #define SYSTEMTRAY_H_
 
+#ifndef QT_NO_SYSTEMTRAYICON
+
 #ifdef HAVE_KDE
 #  include <KSystemTrayIcon>
 #else
@@ -95,4 +97,6 @@ bool SystemTray::isSystemTrayAvailable() const { return QSystemTrayIcon::isSyste
 bool SystemTray::isAlerted() const { return _alert; }
 void SystemTray::setInhibitActivation() { _inhibitActivation = true; }
 
+#endif /* QT_NO_SYSTEMTRAYICON */
+
 #endif
index b665296..1c97d4f 100644 (file)
@@ -18,6 +18,8 @@
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
 
+#ifndef QT_NO_SYSTEMTRAYICON
+
 #include "systraynotificationbackend.h"
 
 #include <QtGui>
@@ -163,3 +165,5 @@ void SystrayNotificationBackend::ConfigWidget::save() {
   s.setValue("Systray/ShowBubble", _showBubbleBox->isChecked());
   load();
 }
+
+#endif /* QT_NO_SYSTEMTRAYICON */
index 2134617..7fdf4e8 100644 (file)
@@ -21,6 +21,8 @@
 #ifndef SYSTRAYNOTIFICATIONBACKEND_H_
 #define SYSTRAYNOTIFICATIONBACKEND_H_
 
+#ifndef QT_NO_SYSTEMTRAYICON
+
 #include <QSystemTrayIcon>
 
 #include "abstractnotificationbackend.h"
@@ -74,4 +76,6 @@ private:
   bool _showBubble, _animate;
 };
 
+#endif /* QT_NO_SYSTEMTRAYICON */
+
 #endif