diff --git a/src/GUI.cpp b/src/GUI.cpp index 4851755e0..1c045d7a2 100644 --- a/src/GUI.cpp +++ b/src/GUI.cpp @@ -65,6 +65,7 @@ #include "statusbar.h" #ifdef Q_WS_MAC #include "qmacapplication.h" +void qt_mac_set_dock_menu(QMenu *menu); #endif using namespace libtorrent; @@ -216,6 +217,9 @@ GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), dis } } #endif +#ifdef Q_WS_MAC + qt_mac_set_dock_menu(getTrayIconMenu()); +#endif } // Destructor @@ -258,6 +262,8 @@ GUI::~GUI() { } if(systrayIcon) { delete systrayIcon; + } + if(myTrayIconMenu) { delete myTrayIconMenu; } delete tabs; @@ -722,6 +728,7 @@ void GUI::optionsSaved() { // Load program preferences void GUI::loadPreferences(bool configure_session) { BTSession->addConsoleMessage(tr("Options were saved successfully.")); +#ifndef Q_WS_MAC const bool newSystrayIntegration = Preferences::systrayIntegration(); if(newSystrayIntegration != (systrayIcon!=0)) { if(newSystrayIntegration) { @@ -745,6 +752,7 @@ void GUI::loadPreferences(bool configure_session) { delete myTrayIconMenu; } } +#endif // General const bool new_displaySpeedInTitle = Preferences::speedInTitleBar(); if(!new_displaySpeedInTitle && new_displaySpeedInTitle != displaySpeedInTitle) { @@ -820,8 +828,9 @@ void GUI::trackerAuthenticationRequired(QTorrentHandle& h) { // Check connection status and display right icon void GUI::updateGUI() { // update global informations +#ifndef Q_WS_MAC if(systrayIcon) { -#if defined(Q_WS_X11) || defined(Q_WS_MAC) +#if defined(Q_WS_X11) QString html = "
"; html += tr("qBittorrent"); html += "
"; @@ -839,6 +848,7 @@ void GUI::updateGUI() { #endif systrayIcon->setToolTip(html); // tray icon } +#endif if(displaySpeedInTitle) { setWindowTitle(tr("qBittorrent %1 (Down: %2/s, Up: %3/s)", "%1 is qBittorrent version").arg(QString::fromUtf8(VERSION)).arg(misc::friendlyUnit(BTSession->getSessionStatus().payload_download_rate)).arg(misc::friendlyUnit(BTSession->getSessionStatus().payload_upload_rate))); } @@ -859,8 +869,10 @@ void GUI::showNotificationBaloon(QString title, QString msg) const { } } #endif +#ifndef Q_WS_MAC if(systrayIcon) systrayIcon->showMessage(title, msg, QSystemTrayIcon::Information, TIME_TRAY_BALLOON); +#endif } } @@ -894,6 +906,7 @@ void GUI::downloadFromURLList(const QStringList& url_list) { *****************************************************/ void GUI::createSystrayDelayed() { +#ifndef Q_WS_MAC static int timeout = 20; if(QSystemTrayIcon::isSystemTrayAvailable()) { // Ok, systray integration is now supported @@ -914,6 +927,7 @@ void GUI::createSystrayDelayed() { Preferences::setSystrayIntegration(false); } } +#endif } void GUI::updateAltSpeedsBtn(bool alternative) { @@ -926,14 +940,9 @@ void GUI::updateAltSpeedsBtn(bool alternative) { } } -void GUI::createTrayIcon() { - // Tray icon -#ifdef Q_WS_WIN - systrayIcon = new QSystemTrayIcon(QIcon(QString::fromUtf8(":/Icons/skin/qbittorrent16.png")), this); -#endif -#ifndef Q_WS_WIN - systrayIcon = new QSystemTrayIcon(QIcon(QString::fromUtf8(":/Icons/skin/qbittorrent22.png")), this); -#endif +QMenu* GUI::getTrayIconMenu() { + if(myTrayIconMenu) + return myTrayIconMenu; // Tray icon Menu myTrayIconMenu = new QMenu(this); myTrayIconMenu->addAction(actionOpen); @@ -948,7 +957,18 @@ void GUI::createTrayIcon() { myTrayIconMenu->addAction(actionPause_All); myTrayIconMenu->addSeparator(); myTrayIconMenu->addAction(actionExit); - systrayIcon->setContextMenu(myTrayIconMenu); + return myTrayIconMenu; +} + +void GUI::createTrayIcon() { + // Tray icon +#ifdef Q_WS_WIN + systrayIcon = new QSystemTrayIcon(QIcon(QString::fromUtf8(":/Icons/skin/qbittorrent16.png")), this); +#else + systrayIcon = new QSystemTrayIcon(QIcon(QString::fromUtf8(":/Icons/skin/qbittorrent22.png")), this); +#endif + + systrayIcon->setContextMenu(getTrayIconMenu()); connect(systrayIcon, SIGNAL(messageClicked()), this, SLOT(balloonClicked())); // End of Icon Menu connect(systrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(toggleVisibility(QSystemTrayIcon::ActivationReason))); diff --git a/src/GUI.h b/src/GUI.h index 8ca8e5ece..b5570464c 100644 --- a/src/GUI.h +++ b/src/GUI.h @@ -69,6 +69,7 @@ public: // Methods int getCurrentTabIndex() const; TransferListWidget* getTransferList() const { return transferList; } + QMenu* getTrayIconMenu(); public slots: void trackerAuthenticationRequired(QTorrentHandle& h); @@ -142,7 +143,7 @@ private: QPointer downloadFromURLDialog; QPointer systrayIcon; QPointer systrayCreator; - QMenu *myTrayIconMenu; + QPointer myTrayIconMenu; TransferListWidget *transferList; TransferListFiltersWidget *transferListFilters; PropertiesWidget *properties; diff --git a/src/options_imp.cpp b/src/options_imp.cpp index f04058d06..65febc0b7 100644 --- a/src/options_imp.cpp +++ b/src/options_imp.cpp @@ -151,7 +151,12 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){ // Load options loadOptions(); // Disable systray integration if it is not supported by the system +#ifdef Q_WS_MAC + if(1){ +#else if(!QSystemTrayIcon::isSystemTrayAvailable()){ +#endif + checkNoSystray->setChecked(true); checkNoSystray->setEnabled(false); } // Connect signals / slots @@ -277,7 +282,11 @@ options_imp::options_imp(QWidget *parent):QDialog(parent){ connect(textWebUiPassword, SIGNAL(textChanged(QString)), this, SLOT(enableApplyButton())); // Disable apply Button applyButton->setEnabled(false); +#ifdef Q_WS_MAC + if(1) { +#else if(!QSystemTrayIcon::supportsMessages()){ +#endif // Mac OS X doesn't support it yet checkSystrayBalloons->setChecked(false); checkSystrayBalloons->setEnabled(false); @@ -1023,6 +1032,9 @@ bool options_imp::startMinimized() const { } bool options_imp::systrayIntegration() const{ +#ifdef Q_WS_MAC + return false; +#endif if (!QSystemTrayIcon::isSystemTrayAvailable()) return false; return (!checkNoSystray->isChecked()); }