[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r2217: Push the logic for deciding whether to use QSystemTrayIcon i (in trunk: . src/vidalia src/vidalia/tray)
Author: edmanm
Date: 2007-12-16 02:24:36 -0500 (Sun, 16 Dec 2007)
New Revision: 2217
Added:
trunk/config.h.in
Modified:
trunk/
trunk/CMakeLists.txt
trunk/src/vidalia/CMakeLists.txt
trunk/src/vidalia/mainwindow.cpp
trunk/src/vidalia/mainwindow.h
trunk/src/vidalia/tray/trayicon.cpp
trunk/src/vidalia/tray/trayicon.h
trunk/src/vidalia/tray/trayicon_mac.cpp
trunk/src/vidalia/tray/trayicon_mac.h
trunk/src/vidalia/tray/trayicon_win.cpp
trunk/src/vidalia/tray/trayicon_win.h
trunk/src/vidalia/tray/trayicon_x11.cpp
trunk/src/vidalia/tray/trayicon_x11.h
Log:
r2305@lysithea: edmanm | 2007-12-16 02:23:49 -0500
Push the logic for deciding whether to use QSystemTrayIcon into the TrayIcon
wrapper class and add a configure check for qsystemtrayicon.h. Hopefully this
will also make Vidalia compile on phobos's OS X Tiger with static-linked Qt libs.
Property changes on: trunk
___________________________________________________________________
svk:merge ticket from /local/vidalia/trunk [r2305] on 0108964c-5b0b-4c9e-969f-e2288315d100
Modified: trunk/CMakeLists.txt
===================================================================
--- trunk/CMakeLists.txt 2007-12-15 20:08:45 UTC (rev 2216)
+++ trunk/CMakeLists.txt 2007-12-16 07:24:36 UTC (rev 2217)
@@ -41,12 +41,26 @@
set(QT_USE_QTXML true)
include(${QT_USE_FILE})
include(VidaliaMacros.cmake)
+include(CheckIncludeFileCXX)
+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
## Define Vidalia-specific CMake options
if (APPLE)
option(OSX_FAT_BINARY "Build Vidalia as a Universal binary." OFF)
endif(APPLE)
+## Check for QSystemTrayIcon
+set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${QT_INCLUDES})
+if (NOT APPLE)
+ check_include_file_cxx("qsystemtrayicon.h" HAVE_QSYSTEMTRAYICON_H)
+endif(NOT APPLE)
+
+## Write out a configuration file
+configure_file(
+ ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
+ ${CMAKE_CURRENT_SOURCE_DIR}/config.h
+)
+
## Add the actual source directories
add_subdirectory(src)
add_subdirectory(doc)
Added: trunk/config.h.in
===================================================================
--- trunk/config.h.in (rev 0)
+++ trunk/config.h.in 2007-12-16 07:24:36 UTC (rev 2217)
@@ -0,0 +1,3 @@
+
+#cmakedefine HAVE_QSYSTEMTRAYICON_H
+
Property changes on: trunk/config.h.in
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: trunk/src/vidalia/CMakeLists.txt
===================================================================
--- trunk/src/vidalia/CMakeLists.txt 2007-12-15 20:08:45 UTC (rev 2216)
+++ trunk/src/vidalia/CMakeLists.txt 2007-12-16 07:24:36 UTC (rev 2217)
@@ -149,22 +149,28 @@
network/zimageview.h
)
-## Custom tray icon implementation sources
-## XXX: We should exclude these if QSystemTrayIcon is available
+## Choose the correct tray icon implementation for the current platform
set(vidalia_SRCS ${vidalia_SRCS} tray/trayicon.cpp)
qt4_wrap_cpp(vidalia_SRCS tray/trayicon.h)
-if(WIN32)
- set(vidalia_SRCS ${vidalia_SRCS} tray/trayicon_win.cpp)
- qt4_wrap_cpp(vidalia_SRCS tray/trayicon_win.h)
-else(WIN32)
- if(APPLE)
- set(vidalia_SRCS ${vidalia_SRCS} tray/trayicon_mac.cpp)
- qt4_wrap_cpp(vidalia_SRCS tray/trayicon_mac.h)
- else(APPLE)
- set(vidalia_SRCS ${vidalia_SRCS} tray/trayicon_x11.cpp)
- qt4_wrap_cpp(vidalia_SRCS tray/trayicon_x11.h)
- endif(APPLE)
-endif(WIN32)
+if(HAVE_QSYSTEMTRAYICON_H AND NOT APPLE)
+ ## Use Qt's QSystemTrayIcon implementation
+ set(vidalia_SRCS ${vidalia_SRCS} tray/trayicon_qt.cpp)
+ qt4_wrap_cpp(vidalia_SRCS tray/trayicon_qt.h)
+else(HAVE_QSYSTEMTRAYICON_H AND NOT APPLE)
+ ## Use our custom tray icon implementation
+ if(WIN32)
+ set(vidalia_SRCS ${vidalia_SRCS} tray/trayicon_win.cpp)
+ qt4_wrap_cpp(vidalia_SRCS tray/trayicon_win.h)
+ else(WIN32)
+ if(APPLE)
+ set(vidalia_SRCS ${vidalia_SRCS} tray/trayicon_mac.cpp)
+ qt4_wrap_cpp(vidalia_SRCS tray/trayicon_mac.h)
+ else(APPLE)
+ set(vidalia_SRCS ${vidalia_SRCS} tray/trayicon_x11.cpp)
+ qt4_wrap_cpp(vidalia_SRCS tray/trayicon_x11.h)
+ endif(APPLE)
+ endif(WIN32)
+endif(HAVE_QSYSTEMTRAYICON_H AND NOT APPLE)
## Main Vidalia sources
set(vidalia_SRCS ${vidalia_SRCS}
Modified: trunk/src/vidalia/mainwindow.cpp
===================================================================
--- trunk/src/vidalia/mainwindow.cpp 2007-12-15 20:08:45 UTC (rev 2216)
+++ trunk/src/vidalia/mainwindow.cpp 2007-12-16 07:24:36 UTC (rev 2217)
@@ -31,7 +31,6 @@
#include <QtGui>
#include <QTimer>
-#include <QSysInfo>
#include <vidalia.h>
#include <file.h>
#include <html.h>
@@ -163,7 +162,7 @@
connect(vApp, SIGNAL(running()), this, SLOT(running()));
connect(vApp, SIGNAL(shutdown()), this, SLOT(shutdown()));
- if (isTrayIconSupported()) {
+ if (TrayIcon::isTrayIconSupported()) {
/* Make the tray icon visible */
_trayIcon.show();
/* Check if we are supposed to show our main window on startup */
@@ -190,23 +189,6 @@
delete _configDialog;
}
-/** Returns true if we're running on a platform with tray icon support. */
-bool
-MainWindow::isTrayIconSupported()
-{
-#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
- /* We always have a tray on Win32 or a dock on OS X */
- return true;
-#elif defined(USE_QSYSTEMTRAYICON)
- /* Ask Qt if there is a tray available */
- return QSystemTrayIcon::isSystemTrayAvailable();
-#else
- /* XXX: This is too optimistic, but we need to make our own tray icon
- * implementation smart enough to detect a system tray on X11. */
- return true;
-#endif
-}
-
/** Catches and processes Tor client status events. */
void
MainWindow::customEvent(QEvent *event)
@@ -346,13 +328,7 @@
createMenuBar();
/* Create a tray menu and add it to the tray icon */
_trayIcon.setContextMenu(createTrayMenu());
-
-#if defined(USE_QSYSTEMTRAYICON)
- connect(&_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
- this, SLOT(trayActivated(QSystemTrayIcon::ActivationReason)));
-#else
connect(&_trayIcon, SIGNAL(doubleClicked()), this, SLOT(show()));
-#endif
}
/** Creates a QMenu object that contains QActions which compose the system
@@ -542,11 +518,7 @@
/* Update the tray icon */
if (!trayIconFile.isEmpty()) {
-#if defined(USE_QSYSTEMTRAYICON)
- _trayIcon.setIcon(QIcon(trayIconFile));
-#else
_trayIcon.setIcon(trayIconFile);
-#endif
}
/* Update the status banner on the control panel */
if (!statusIconFile.isEmpty())
@@ -558,16 +530,6 @@
return prevStatus;
}
-#if defined(USE_QSYSTEMTRAYICON)
-/** Displays the main window if <b>reason</b> is DoubleClick. */
-void
-MainWindow::trayActivated(QSystemTrayIcon::ActivationReason reason)
-{
- if (reason == QSystemTrayIcon::DoubleClick)
- show();
-}
-#endif
-
/** Called when the "show on startup" checkbox is toggled. */
void
MainWindow::toggleShowOnStartup(bool checked)
@@ -1151,23 +1113,10 @@
QTimer::singleShot(MIN_NEWIDENTITY_INTERVAL,
this, SLOT(enableNewIdentity()));
-#if defined(USE_QSYSTEMTRAYICON)
- /* Check if we support balloon messages. We support balloon messages only
- * if we are built with Qt >= 4.2, but not if we are running on OS X or
- * a version of Windows <= Windows 2000. */
-# if defined(Q_WS_WIN)
- if (QSystemTrayIcon::supportsMessages() &&
- QSysInfo::WindowsVersion > QSysInfo::WV_2000)
-# else
- if (QSystemTrayIcon::supportsMessages())
-# endif
- _trayIcon.showMessage(title, message, QSystemTrayIcon::Information);
+ if (TrayIcon::supportsBalloonMessages())
+ _trayIcon.showBalloonMessage(title, message, TrayIcon::Information);
else
VMessageBox::information(this, title, message, VMessageBox::Ok);
-#else
- /* No QSystemTrayIcon. Just show a message box */
- VMessageBox::information(this, title, message, VMessageBox::Ok);
-#endif
} else {
/* NEWNYM signal failed */
VMessageBox::warning(this,
Modified: trunk/src/vidalia/mainwindow.h
===================================================================
--- trunk/src/vidalia/mainwindow.h 2007-12-15 20:08:45 UTC (rev 2216)
+++ trunk/src/vidalia/mainwindow.h 2007-12-16 07:24:36 UTC (rev 2217)
@@ -31,17 +31,8 @@
#include <QMainWindow>
#include <torcontrol.h>
-/* QSystemTrayIcon appeared in Qt 4.2, but we need a bugfix to it on Mac
- * that won't appear until Qt 4.2.2. */
-#if QT_VERSION >= 0x040200 && !defined(Q_WS_MAC)
-#define USE_QSYSTEMTRAYICON 1
-#include <QSystemTrayIcon>
-#else
-#undef USE_QSYSTEMTRAYICON
-#include "tray/trayicon.h"
-#endif
-
#include "vidaliawindow.h"
+#include "tray/trayicon.h"
#include "about/aboutdialog.h"
#include "log/messagelog.h"
#include "bwgraph/bwgraph.h"
@@ -122,11 +113,6 @@
/** Called web the web browser failed to start */
void onBrowserFailed(QString errmsg);
-#if QT_VERSION >= 0x040200 && !defined(Q_WS_MAC)
- /** Displays the main window if <b>reason</b> is DoubleClick. */
- void trayActivated(QSystemTrayIcon::ActivationReason reason);
-#endif
-
private:
enum TorStatus {
Unset, /**< Tor's status has not yet been set. */
@@ -147,8 +133,6 @@
QMenu* createTrayMenu();
/** Creates a default menubar on Mac */
void createMenuBar();
- /** Returns true if we're running on a platform with tray icon support. */
- bool isTrayIconSupported();
/** Updates the UI to reflect Tor's current <b>status</b>. Returns the
* previously set TorStatus value. */
TorStatus updateTorStatus(TorStatus status);
@@ -196,13 +180,8 @@
/** Remembers the control password between when we start Tor with a hash of
* the password and when we need to provide the password itself. */
QString _controlPassword;
-
-#if QT_VERSION >= 0x040200 && !defined(Q_WS_MAC)
- QSystemTrayIcon _trayIcon; /**< The Vidalia icon that sits in the tray.
- (post-Qt 4.2) */
-#else
- TrayIcon _trayIcon; /**< The Vidalia icon that sits in the tray. (pre-Qt 4.2) */
-#endif
+ /** The Vidalia icon that sits in the tray. */
+ TrayIcon _trayIcon;
/** Defines the actions for the tray menu */
QAction* _controlPanelAct;
Modified: trunk/src/vidalia/tray/trayicon.cpp
===================================================================
--- trunk/src/vidalia/tray/trayicon.cpp 2007-12-15 20:08:45 UTC (rev 2216)
+++ trunk/src/vidalia/tray/trayicon.cpp 2007-12-16 07:24:36 UTC (rev 2217)
@@ -25,6 +25,7 @@
* \brief Places an icon with context menu in the system notification area
*/
+#include <QSysInfo>
#include "trayicon.h"
#if defined(Q_WS_MAC)
@@ -35,7 +36,8 @@
/** Default constructor. */
-TrayIcon::TrayIcon()
+TrayIcon::TrayIcon(QObject *parent)
+ : TrayIconImpl(parent)
{
_contextMenu = 0;
}
@@ -69,7 +71,7 @@
void
TrayIcon::mouseButtonPress(QMouseEvent *event)
{
-#if defined(Q_WS_X11)
+#if defined(Q_WS_X11) && !defined(HAVE_QSYSTEMTRAYICON_H)
if (_contextMenu) {
_contextMenu->popup(event->globalPos());
}
@@ -150,8 +152,66 @@
{
#if defined(Q_WS_MAC)
qt_mac_set_dock_menu(menu);
+#elif defined(HAVE_QSYSTEMTRAYICON_H)
+ TrayIconImpl::setContextMenu(menu);
#else
_contextMenu = menu;
#endif
}
+/** Displays a balloon message next to the tray icon. */
+void
+TrayIcon::showBalloonMessage(const QString &title, const QString &message,
+ BalloonMessageIcon balloonIcon)
+{
+#if defined(HAVE_QSYSTEMTRAYICON_H)
+ QSystemTrayIcon::MessageIcon icon;
+ switch (balloonIcon) {
+ NoIcon: icon = QSystemTrayIcon::NoIcon; break;
+ Warning: icon = QSystemTrayIcon::Warning; break;
+ Critical: icon = QSystemTrayIcon::Critical; break;
+ default: icon = QSystemTrayIcon::Information; break;
+ }
+ TrayIconImpl::showMessage(title, message, icon);
+#else
+ Q_UNUSED(title)
+ Q_UNUSED(message)
+ Q_UNUSED(icon)
+#endif
+}
+
+/** Returns true if the current platform and tray icon implementation supports
+ * tray icons. */
+bool
+TrayIcon::isTrayIconSupported()
+{
+#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
+ /* We always have a tray on Win32 or a dock on OS X */
+ return true;
+#elif defined(HAVE_QSYSTEMTRAYICON_H)
+ /* Ask Qt if there is a tray available */
+ return QSystemTrayIcon::isSystemTrayAvailable();
+#else
+ /* XXX:This is too optimistic, but we need to make our own tray icon
+ * implementation smart enough to detect a system tray on X11. */
+ return true;
+#endif
+}
+
+/** Returns true if the current platform and tray icon implementation supports
+ * tray icon balloon messages. */
+bool
+TrayIcon::supportsBalloonMessages()
+{
+#if defined(HAVE_QSYSTEMTRAYICON_H)
+#if defined(Q_WS_WIN)
+ return (QSystemTrayIcon::supportsMessages()
+ && QSysInfo::WindowsVersion > QSysInfo::WV_2000);
+#else
+ return QSystemTrayIcon::supportsMessages();
+#endif
+#else
+ return false;
+#endif
+}
+
Modified: trunk/src/vidalia/tray/trayicon.h
===================================================================
--- trunk/src/vidalia/tray/trayicon.h 2007-12-15 20:08:45 UTC (rev 2216)
+++ trunk/src/vidalia/tray/trayicon.h 2007-12-16 07:24:36 UTC (rev 2217)
@@ -32,9 +32,12 @@
#include <QString>
#include <QMenu>
#include <QMouseEvent>
+#include "config.h"
/* Include the correct tray icon implementation */
-#if defined(Q_WS_WIN)
+#if defined(HAVE_QSYSTEMTRAYICON_H)
+#include "trayicon_qt.h"
+#elif defined(Q_WS_WIN)
#include "trayicon_win.h"
#elif defined(Q_WS_X11)
#include "trayicon_x11.h"
@@ -48,8 +51,16 @@
Q_OBJECT
public:
+ /** Balloon message status icons. */
+ enum BalloonMessageIcon {
+ NoIcon = 0,
+ Information,
+ Warning,
+ Critical
+ };
+
/** Default constructor. */
- TrayIcon();
+ TrayIcon(QObject *parent = 0);
/** Show the tray icon. */
void show();
@@ -63,7 +74,17 @@
void setIcon(const QString &iconFile);
/** Sets the context menu displayed when the tray icon is selected. */
void setContextMenu(QMenu *contextMenu);
-
+ /** Displays a balloon message next to the tray icon. */
+ void showBalloonMessage(const QString &title, const QString &message,
+ BalloonMessageIcon icon);
+
+ /** Returns true if the current platform and tray icon implementation
+ * supports tray icons. */
+ static bool isTrayIconSupported();
+ /** Returns true if the current platform and tray icon implementation
+ * supports tray icon balloon messages. */
+ static bool supportsBalloonMessages();
+
signals:
/** Emitted when the user double-clicks on the tray icon. */
void doubleClicked();
Modified: trunk/src/vidalia/tray/trayicon_mac.cpp
===================================================================
--- trunk/src/vidalia/tray/trayicon_mac.cpp 2007-12-15 20:08:45 UTC (rev 2216)
+++ trunk/src/vidalia/tray/trayicon_mac.cpp 2007-12-16 07:24:36 UTC (rev 2217)
@@ -31,7 +31,8 @@
/** Default constructor */
-TrayIconImpl::TrayIconImpl()
+TrayIconImpl::TrayIconImpl(QObject *parent)
+ : QWidget(parent)
{
setObjectName("trayiconimpl");
_imageRef = 0;
Modified: trunk/src/vidalia/tray/trayicon_mac.h
===================================================================
--- trunk/src/vidalia/tray/trayicon_mac.h 2007-12-15 20:08:45 UTC (rev 2216)
+++ trunk/src/vidalia/tray/trayicon_mac.h 2007-12-16 07:24:36 UTC (rev 2217)
@@ -40,7 +40,7 @@
protected:
/** Default Constructor */
- TrayIconImpl();
+ TrayIconImpl(QObject *parent = 0);
/** Destructor */
~TrayIconImpl();
Modified: trunk/src/vidalia/tray/trayicon_win.cpp
===================================================================
--- trunk/src/vidalia/tray/trayicon_win.cpp 2007-12-15 20:08:45 UTC (rev 2216)
+++ trunk/src/vidalia/tray/trayicon_win.cpp 2007-12-16 07:24:36 UTC (rev 2217)
@@ -55,7 +55,8 @@
/** Default constructor. */
-TrayIconImpl::TrayIconImpl()
+TrayIconImpl::TrayIconImpl(QObject *parent)
+ : QWidget(parent)
{
setObjectName("trayiconimpl");
Modified: trunk/src/vidalia/tray/trayicon_win.h
===================================================================
--- trunk/src/vidalia/tray/trayicon_win.h 2007-12-15 20:08:45 UTC (rev 2216)
+++ trunk/src/vidalia/tray/trayicon_win.h 2007-12-16 07:24:36 UTC (rev 2217)
@@ -42,7 +42,7 @@
protected:
/** Default constructor. */
- TrayIconImpl();
+ TrayIconImpl(QObject *parent = 0);
/** Show the tray icon. */
void show();
Modified: trunk/src/vidalia/tray/trayicon_x11.cpp
===================================================================
--- trunk/src/vidalia/tray/trayicon_x11.cpp 2007-12-15 20:08:45 UTC (rev 2216)
+++ trunk/src/vidalia/tray/trayicon_x11.cpp 2007-12-16 07:24:36 UTC (rev 2217)
@@ -60,7 +60,8 @@
/* Default constructor */
-TrayIconImpl::TrayIconImpl()
+TrayIconImpl::TrayIconImpl(QObject *parent)
+ : QLabel(parent)
{
setObjectName("trayiconimpl");
Modified: trunk/src/vidalia/tray/trayicon_x11.h
===================================================================
--- trunk/src/vidalia/tray/trayicon_x11.h 2007-12-15 20:08:45 UTC (rev 2216)
+++ trunk/src/vidalia/tray/trayicon_x11.h 2007-12-16 07:24:36 UTC (rev 2217)
@@ -60,7 +60,7 @@
protected:
/** Default constructor. */
- TrayIconImpl();
+ TrayIconImpl(QObject *parent = 0);
/** Show the tray icon image. */
void show();