summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2012-04-28 16:41:32 (GMT)
committerRemko Tronçon <git@el-tramo.be>2012-04-28 16:41:32 (GMT)
commit3b129ea8f24bb87c946e3879f74a8437be27376c (patch)
treeac87fcfd9f4e30d7e729763ecbe95c7bb18b25c7 /Swift
parentf60d331a3e32eff632a9af3b7bd5fc1c1811365f (diff)
downloadswift-contrib-3b129ea8f24bb87c946e3879f74a8437be27376c.zip
swift-contrib-3b129ea8f24bb87c946e3879f74a8437be27376c.tar.bz2
Add a show/hide menu to the system tray on Ubuntu.
Resolves: #1112
Diffstat (limited to 'Swift')
-rw-r--r--Swift/QtUI/QtSystemTray.cpp21
-rw-r--r--Swift/QtUI/QtSystemTray.h3
2 files changed, 23 insertions, 1 deletions
diff --git a/Swift/QtUI/QtSystemTray.cpp b/Swift/QtUI/QtSystemTray.cpp
index 123e6a3..bc8e40a 100644
--- a/Swift/QtUI/QtSystemTray.cpp
+++ b/Swift/QtUI/QtSystemTray.cpp
@@ -4,22 +4,41 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
+#pragma GCC diagnostic ignored "-Wredundant-decls"
+
#include "Swift/QtUI/QtSystemTray.h"
+#include <QtDebug>
+#include <QDBusInterface>
#include <QIcon>
#include <QPixmap>
#include <QResource>
+#include <QMenu>
+#include <QAction>
namespace Swift {
-QtSystemTray::QtSystemTray() : QObject(), onlineIcon_(":icons/online.png"), awayIcon_(":icons/away.png"), dndIcon_(":icons/dnd.png"), offlineIcon_(":icons/offline.png"), newMessageIcon_(":icons/new-chat.png"), throbberMovie_(":/icons/connecting.mng"), unreadMessages_(false), connecting_(false) {
+QtSystemTray::QtSystemTray() : QObject(), trayMenu_(0), onlineIcon_(":icons/online.png"), awayIcon_(":icons/away.png"), dndIcon_(":icons/dnd.png"), offlineIcon_(":icons/offline.png"), newMessageIcon_(":icons/new-chat.png"), throbberMovie_(":/icons/connecting.mng"), unreadMessages_(false), connecting_(false) {
trayIcon_ = new QSystemTrayIcon(offlineIcon_);
trayIcon_->setToolTip("Swift");
connect(trayIcon_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(handleIconActivated(QSystemTrayIcon::ActivationReason)));
connect(&throbberMovie_, SIGNAL(frameChanged(int)), this, SLOT(handleThrobberFrameChanged(int)));
+#ifdef Q_WS_X11
+ bool isUnity = QDBusInterface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher").isValid();
+ if (isUnity) {
+ // Add an activation menu, because this is the only way to get the application to the
+ // front on Unity. See the README for sni-qt (which handles Qt tray icons for Unity)
+ trayMenu_ = new QMenu();
+ QAction* showAction = new QAction(QString("Show/Hide"), this);
+ connect(showAction, SIGNAL(triggered()), SIGNAL(clicked()));
+ trayMenu_->addAction(showAction);
+ trayIcon_->setContextMenu(trayMenu_);
+ }
+#endif
trayIcon_->show();
}
QtSystemTray::~QtSystemTray() {
+ delete trayMenu_;
delete trayIcon_;
}
diff --git a/Swift/QtUI/QtSystemTray.h b/Swift/QtUI/QtSystemTray.h
index cc7321b..8691e19 100644
--- a/Swift/QtUI/QtSystemTray.h
+++ b/Swift/QtUI/QtSystemTray.h
@@ -12,8 +12,10 @@
#include <QMovie>
class QIcon;
+class QMenu;
namespace Swift {
+
class QtSystemTray : public QObject, public SystemTray {
Q_OBJECT
public:
@@ -35,6 +37,7 @@ namespace Swift {
void updateStatusIcon();
StatusShow::Type statusType_;
QSystemTrayIcon* trayIcon_;
+ QMenu* trayMenu_;
QIcon onlineIcon_;
QIcon awayIcon_;
QIcon dndIcon_;