Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions src/tuxclocker-qt/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the comment?

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
Copy link
Owner

Choose a reason for hiding this comment

The 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
Copy link
Owner

Choose a reason for hiding this comment

The 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);
Expand All @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The 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
Copy link
Owner

Choose a reason for hiding this comment

The 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};
Expand Down