-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adjusted behavior of system tray icon #99
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,27 +104,34 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { | |
|
||
void MainWindow::setTrayIconEnabled(bool enable) { | ||
if (enable) { | ||
if (!m_trayIcon) | ||
// This seems to make the main window not close during closeEvent | ||
if (!m_trayIcon) { | ||
m_trayIcon = new QSystemTrayIcon{this}; | ||
m_trayIcon->setIcon(QIcon{QPixmap{":/tuxclocker-logo.svg"}}); | ||
m_trayIcon->setToolTip("TuxClocker"); | ||
m_trayIcon->setContextMenu(createTrayMenu()); | ||
m_trayIcon->show(); | ||
return; | ||
m_trayIcon->setIcon(QIcon{QPixmap{":/tuxclocker-logo.svg"}}); | ||
m_trayIcon->setToolTip("TuxClocker"); | ||
m_trayIcon->setContextMenu(createTrayMenu()); | ||
m_trayIcon->show(); | ||
return; | ||
} else | ||
return; | ||
} | ||
// Remove tray icon | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. =||= |
||
if (m_trayIcon) | ||
|
||
if (m_trayIcon) { | ||
delete m_trayIcon; | ||
m_trayIcon = nullptr; | ||
} | ||
} | ||
|
||
QMenu *MainWindow::createTrayMenu() { | ||
auto menu = new QMenu{this}; | ||
|
||
auto show = new QAction{_("&Maximize TuxClocker"), this}; | ||
auto show = new QAction{_("&Show TuxClocker"), this}; | ||
Comment on lines
-124
to
+127
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this needs changing, I think Maximize/Hide is clear enough, and translations would need to be changed |
||
connect(show, &QAction::triggered, this, &MainWindow::show); | ||
menu->addAction(show); | ||
|
||
auto hide = new QAction{_("&Hide TuxClocker"), this}; | ||
connect(hide, &QAction::triggered, this, &MainWindow::hide); | ||
menu->addAction(hide); | ||
|
||
auto quit = new QAction{_("&Quit"), this}; | ||
connect(quit, &QAction::triggered, this, &QApplication::quit); | ||
menu->addAction(quit); | ||
|
@@ -140,7 +147,21 @@ void MainWindow::restoreGeometryFromCache(QWidget *widget) { | |
} | ||
|
||
void MainWindow::closeEvent(QCloseEvent *event) { | ||
// if the tray icon is active, hide the application instead of closing it | ||
|
||
if (m_trayIcon && m_trayIcon->isVisible()) { | ||
QMessageBox::information(this, tr("TuxClocker"), | ||
tr("TuxClocker will continue to run " | ||
"in the background. To completely " | ||
"exit the application, choose <b><u>Q</u>uit</b> " | ||
"from the system tray icon")); | ||
hide(); | ||
event->ignore(); | ||
Comment on lines
+158
to
+159
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The window is already hidden in this condition, unless I'm missing something |
||
return; | ||
} | ||
|
||
Comment on lines
+150
to
+162
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure we need this, since using the tray isn't the default, and we inform the user about this behavior with a tooltip in the settings too |
||
// Save window geometry to user cache dir (XDG_CACHE_HOME on Linux) | ||
|
||
auto cacheFilePath = Utils::cacheFilePath(); | ||
|
||
QSettings settings{cacheFilePath, QSettings::NativeFormat}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove the comment?