diff --git a/src/ui/mainwindow.cc b/src/ui/mainwindow.cc index a430dca97..b166b12e2 100644 --- a/src/ui/mainwindow.cc +++ b/src/ui/mainwindow.cc @@ -597,21 +597,6 @@ MainWindow::MainWindow( Config::Class & cfg_ ): connect( ui.historyPane, &QDockWidget::visibilityChanged, this, &MainWindow::updateHistoryMenu ); connect( ui.showHideHistory, &QAction::triggered, this, &MainWindow::toggle_historyPane ); - -#if !defined( HAVE_X11 ) - // Show tray icon early so the user would be happy. It won't be functional - // though until the program inits fully. - // Do not create dummy tray icon in X. Cause QT5 failed to upgrade systemtray context menu. - // And as result menu for some DEs apppear to be empty, for example in MATE DE. - - if ( cfg.preferences.enableTrayIcon ) { - trayIcon = - new QSystemTrayIcon( QIcon::fromTheme( "goldendict-tray", QIcon( ":/icons/programicon_old.png" ) ), this ); - trayIcon->setToolTip( tr( "Loading..." ) ); - trayIcon->show(); - } -#endif - connect( navBack, &QAction::triggered, this, &MainWindow::backClicked ); connect( navForward, &QAction::triggered, this, &MainWindow::forwardClicked ); @@ -852,7 +837,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ): #endif installHotKeys(); - updateTrayIcon(); + trayIconUpdateOrInit(); } ); if ( cfg.preferences.startWithScanPopupOn ) { @@ -862,16 +847,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ): updateSearchPaneAndBar( cfg.preferences.searchInDock ); ui.searchPane->setVisible( cfg.preferences.searchInDock ); - if ( trayIcon ) { - // Upgrade existing dummy tray icon into a full-functional one - - trayIcon->setContextMenu( &trayIconMenu ); - trayIcon->show(); - - connect( trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::trayIconActivated ); - } - - updateTrayIcon(); + trayIconUpdateOrInit(); // Update zoomers adjustCurrentZoomFactor(); @@ -1391,30 +1367,26 @@ void MainWindow::updateAppearances( QString const & addonStyle, } } -void MainWindow::updateTrayIcon() +void MainWindow::trayIconUpdateOrInit() { - if ( !trayIcon && cfg.preferences.enableTrayIcon ) { - // Need to show it - trayIcon = - new QSystemTrayIcon( QIcon::fromTheme( "goldendict-tray", QIcon( ":/icons/programicon_old.png" ) ), this ); - trayIcon->setContextMenu( &trayIconMenu ); - trayIcon->show(); - - connect( trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::trayIconActivated ); - } - else if ( trayIcon && !cfg.preferences.enableTrayIcon ) { - // Need to hide it - delete trayIcon; - - trayIcon = nullptr; + if ( !cfg.preferences.enableTrayIcon ) { + if ( trayIcon ) { + delete trayIcon; + trayIcon = nullptr; + } } - if ( trayIcon ) { + else { + if ( !trayIcon ) { + trayIcon = new QSystemTrayIcon( this ); + trayIcon->setContextMenu( &trayIconMenu ); + trayIcon->setToolTip( QApplication::applicationName() ); + connect( trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::trayIconActivated ); + trayIcon->show(); + } // Update the icon to reflect the scanning mode trayIcon->setIcon( enableScanningAction->isChecked() ? QIcon::fromTheme( "goldendict-scan-tray", QIcon( ":/icons/programicon_scan.png" ) ) : QIcon::fromTheme( "goldendict-tray", QIcon( ":/icons/programicon_old.png" ) ) ); - - trayIcon->setToolTip( "GoldenDict-ng" ); } // The 'Close to tray' action is associated with the tray icon, so we hide @@ -2282,7 +2254,7 @@ void MainWindow::editPreferences() audioPlayerFactory.setPreferences( cfg.preferences ); - updateTrayIcon(); + trayIconUpdateOrInit(); applyProxySettings(); ui.tabWidget->setHideSingleTab( cfg.preferences.hideSingleTab ); diff --git a/src/ui/mainwindow.hh b/src/ui/mainwindow.hh index 190830f8e..5439dc639 100644 --- a/src/ui/mainwindow.hh +++ b/src/ui/mainwindow.hh @@ -195,7 +195,7 @@ private: /// Creates, destroys or otherwise updates tray icon, according to the /// current configuration and situation. - void updateTrayIcon(); + void trayIconUpdateOrInit(); void wheelEvent( QWheelEvent * ); void closeEvent( QCloseEvent * );