[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r1465: Make our tray icon implementation match Qt's tray icon imple (trunk/src/gui/tray)
Author: edmanm
Date: 2006-11-20 23:45:15 -0500 (Mon, 20 Nov 2006)
New Revision: 1465
Modified:
trunk/src/gui/tray/trayicon.cpp
trunk/src/gui/tray/trayicon.h
trunk/src/gui/tray/trayicon_mac.cpp
trunk/src/gui/tray/trayicon_mac.h
trunk/src/gui/tray/trayicon_win.cpp
trunk/src/gui/tray/trayicon_win.h
trunk/src/gui/tray/trayicon_x11.cpp
trunk/src/gui/tray/trayicon_x11.h
Log:
Make our tray icon implementation match Qt's tray icon implementation (now
that it has one) a little better, so we can switch between the two more
easily. Also add the tray icon's context menu to the dock icon on Mac (Ticket #135).
Modified: trunk/src/gui/tray/trayicon.cpp
===================================================================
--- trunk/src/gui/tray/trayicon.cpp 2006-11-19 17:24:06 UTC (rev 1464)
+++ trunk/src/gui/tray/trayicon.cpp 2006-11-21 04:45:15 UTC (rev 1465)
@@ -27,11 +27,17 @@
#include "trayicon.h"
-/** Constructor. */
-TrayIcon::TrayIcon(const QString &iconFile, const QString &toolTip, QMenu *popupMenu)
-: TrayIconImpl(iconFile, toolTip)
+#if defined(Q_WS_MAC)
+/* Exported by Qt, but not declared in the header files.
+ * See http://doc.trolltech.com/exportedfunctions.html */
+void qt_mac_set_dock_menu(QMenu *menu);
+#endif
+
+
+/** Default constructor. */
+TrayIcon::TrayIcon()
{
- _popupMenu = popupMenu;
+ _contextMenu = 0;
}
/** Catches and handles mouse-related events. */
@@ -64,8 +70,8 @@
TrayIcon::mouseButtonPress(QMouseEvent *event)
{
#if defined(Q_WS_X11)
- if (_popupMenu) {
- _popupMenu->popup(event->globalPos());
+ if (_contextMenu) {
+ _contextMenu->popup(event->globalPos());
}
#else
Q_UNUSED(event);
@@ -78,12 +84,12 @@
TrayIcon::mouseButtonRelease(QMouseEvent *event)
{
#if defined(Q_WS_WIN)
- if (_popupMenu) {
+ if (_contextMenu) {
/* This little activateWindow() dance is necessary to make menu closing
* work properly on Windows. */
- _popupMenu->activateWindow();
- _popupMenu->popup(event->globalPos());
- _popupMenu->activateWindow();
+ _contextMenu->activateWindow();
+ _contextMenu->popup(event->globalPos());
+ _contextMenu->activateWindow();
}
#else
Q_UNUSED(event);
@@ -137,3 +143,15 @@
TrayIconImpl::setIcon(iconFile);
}
+/** Sets the context menu displayed when the tray icon is selected. On Mac,
+ * the context menu is displayed when the dock icon is clicked. */
+void
+TrayIcon::setContextMenu(QMenu *menu)
+{
+#if defined(Q_WS_MAC)
+ qt_mac_set_dock_menu(menu);
+#else
+ _contextMenu = menu;
+#endif
+}
+
Modified: trunk/src/gui/tray/trayicon.h
===================================================================
--- trunk/src/gui/tray/trayicon.h 2006-11-19 17:24:06 UTC (rev 1464)
+++ trunk/src/gui/tray/trayicon.h 2006-11-21 04:45:15 UTC (rev 1465)
@@ -48,8 +48,8 @@
Q_OBJECT
public:
- /** Constructor */
- TrayIcon(const QString &iconFile, const QString &toolTip, QMenu *popupMenu = 0);
+ /** Default constructor. */
+ TrayIcon();
/** Show the tray icon. */
void show();
@@ -61,7 +61,9 @@
void setToolTip(const QString &toolTip);
/** Update the tray icon's image. */
void setIcon(const QString &iconFile);
-
+ /** Sets the context menu displayed when the tray icon is selected. */
+ void setContextMenu(QMenu *contextMenu);
+
signals:
/** Emitted when the user double-clicks on the tray icon. */
void doubleClicked();
@@ -77,7 +79,7 @@
void mouseButtonDblClick(QMouseEvent *event);
private:
- QMenu* _popupMenu; /**< Menu to display when the tray icon is clicked. */
+ QMenu* _contextMenu; /**< Menu to display when the tray icon is clicked. */
};
#endif
Modified: trunk/src/gui/tray/trayicon_mac.cpp
===================================================================
--- trunk/src/gui/tray/trayicon_mac.cpp 2006-11-19 17:24:06 UTC (rev 1464)
+++ trunk/src/gui/tray/trayicon_mac.cpp 2006-11-21 04:45:15 UTC (rev 1465)
@@ -30,18 +30,12 @@
#include "trayicon_mac.h"
-/** Constructor. */
-TrayIconImpl::TrayIconImpl(const QString &iconFile, const QString &toolTip)
+/** Default constructor */
+TrayIconImpl::TrayIconImpl()
{
setObjectName("trayiconimpl");
_imageRef = 0;
_shown = false;
-
- /* Add the tool tip to the structure */
- setIcon(iconFile);
-
- /* And give it an icon */
- setToolTip(toolTip);
}
/** Destructor */
@@ -134,11 +128,17 @@
/* Create a CFStringRef that we can use to build the resource URL */
CFStringRef iconFileRef = CFStringCreateWithCString(NULL, qPrintable(iconFile),
kCFStringEncodingASCII);
+ if (!iconFileRef) {
+ return NULL;
+ }
/* Build a URL to the requested .icns in our resource bundle */
CFURLRef url = CFBundleCopyResourceURL(CFBundleGetMainBundle(),
iconFileRef, CFSTR("icns"), NULL);
-
+ if (!url) {
+ return NULL;
+ }
+
/* Try to find the resource in the bundle */
if (CFURLGetFSRef(url, &ref)) {
FSSpec fileSpec;
Modified: trunk/src/gui/tray/trayicon_mac.h
===================================================================
--- trunk/src/gui/tray/trayicon_mac.h 2006-11-19 17:24:06 UTC (rev 1464)
+++ trunk/src/gui/tray/trayicon_mac.h 2006-11-21 04:45:15 UTC (rev 1465)
@@ -37,8 +37,8 @@
class TrayIconImpl : protected QWidget
{
protected:
- /** Constructor */
- TrayIconImpl(const QString &iconFile, const QString &toolTip);
+ /** Default Constructor */
+ TrayIconImpl();
/** Destructor */
~TrayIconImpl();
Modified: trunk/src/gui/tray/trayicon_win.cpp
===================================================================
--- trunk/src/gui/tray/trayicon_win.cpp 2006-11-19 17:24:06 UTC (rev 1464)
+++ trunk/src/gui/tray/trayicon_win.cpp 2006-11-21 04:45:15 UTC (rev 1465)
@@ -54,19 +54,13 @@
UINT WM_TASKBARCREATED; /**< Message sent when taskbar is created. */
-/** Constructor. */
-TrayIconImpl::TrayIconImpl(const QString &iconFile, const QString &toolTip)
+/** Default constructor. */
+TrayIconImpl::TrayIconImpl()
{
setObjectName("trayiconimpl");
/* We want to know when Explorer crashes and recreates the taskbar. */
WM_TASKBARCREATED = RegisterWindowMessage(TEXT("TaskbarCreated"));
-
- /* Set the tray icon image */
- setIcon(iconFile);
-
- /* Add the tool tip to the structure */
- setToolTip(toolTip);
}
/** Updates the tray icon. */
Modified: trunk/src/gui/tray/trayicon_win.h
===================================================================
--- trunk/src/gui/tray/trayicon_win.h 2006-11-19 17:24:06 UTC (rev 1464)
+++ trunk/src/gui/tray/trayicon_win.h 2006-11-21 04:45:15 UTC (rev 1465)
@@ -39,8 +39,8 @@
class TrayIconImpl : protected QWidget
{
protected:
- /** Constructor */
- TrayIconImpl(const QString &iconFile, const QString &toolTip);
+ /** Default constructor. */
+ TrayIconImpl();
/** Show the tray icon. */
void show();
Modified: trunk/src/gui/tray/trayicon_x11.cpp
===================================================================
--- trunk/src/gui/tray/trayicon_x11.cpp 2006-11-19 17:24:06 UTC (rev 1464)
+++ trunk/src/gui/tray/trayicon_x11.cpp 2006-11-21 04:45:15 UTC (rev 1465)
@@ -59,9 +59,19 @@
#define SYSTEM_TRAY_CANCEL_MESSAGE 2
-TrayIconImpl::TrayIconImpl(const QString &iconFile, const QString &toolTip)
+/* Default constructor */
+TrayIconImpl::TrayIconImpl()
{
setObjectName("trayiconimpl");
+
+ /* Add this widget to the system notification area */
+ addToTray();
+}
+
+/** Adds this widget to the system notification area. */
+void
+TrayIconImpl::addToTray()
+{
setMinimumSize(22, 22);
setMaximumSize(22, 22);
//setBackgroundRole(QPalette::Base);
@@ -103,15 +113,10 @@
long data = 0;
Atom dockwindow = XInternAtom(dpy, "KWM_DOCKWINDOW", false);
Atom traywindow = XInternAtom(dpy, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
- XChangeProperty(dpy, winId(), dockwindow, dockwindow, 32, PropModeReplace, (uchar*)&data, 1);
- XChangeProperty(dpy, winId(), traywindow, XA_WINDOW, 32, PropModeReplace, (uchar*)&data, 1);
-
- /* Set the initial icon and tooltip */
- setIcon(iconFile);
- setToolTip(toolTip);
-
- //setAttribute(Qt::WA_NoBackground);
- //XSetWindowBackgroundPixmap(dpy, trayWin, None);
+ XChangeProperty(dpy, winId(), dockwindow, dockwindow, 32,
+ PropModeReplace, (uchar*)&data, 1);
+ XChangeProperty(dpy, winId(), traywindow, XA_WINDOW, 32,
+ PropModeReplace, (uchar*)&data, 1);
}
/** Process events when the mouse enters the icon area. */
Modified: trunk/src/gui/tray/trayicon_x11.h
===================================================================
--- trunk/src/gui/tray/trayicon_x11.h 2006-11-19 17:24:06 UTC (rev 1464)
+++ trunk/src/gui/tray/trayicon_x11.h 2006-11-21 04:45:15 UTC (rev 1465)
@@ -57,8 +57,8 @@
class TrayIconImpl : protected QLabel
{
protected:
- /** Constructor */
- TrayIconImpl(const QString &iconFile, const QString &toolTip);
+ /** Default constructor. */
+ TrayIconImpl();
/** Show the tray icon image. */
void show();
@@ -71,6 +71,10 @@
/** Process events when the mouse enters the icon area. */
void enterEvent(QEvent *event);
+
+private:
+ /** Adds this widget to the system notification area. */
+ void addToTray();
};
#endif