https://bugs.kde.org/show_bug.cgi?id=347365

Kristen McWilliam <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED
      Latest Commit|                            |https://invent.kde.org/pim/
                   |                            |ktimetracker/-/commit/4261f
                   |                            |699d62d934397ea62d4d14aac3f
                   |                            |f57a662b

--- Comment #6 from Kristen McWilliam <[email protected]> ---
Git commit 4261f699d62d934397ea62d4d14aac3ff57a662b by Kristen McWilliam, on
behalf of Marián Kadaňka.
Committed on 21/11/2026 at 16:54.
Pushed by merritt into branch 'master'.

Fix the system tray icon, and quit on close when it is switched off

<!--Thank you for submitting a merge request to make KDE Software better! Use
the information from the commit message(s) to fill in the template below.

### Original commit message(s)

* Add a test for closing the window with and without a tray icon

The test sends the main window the close event that a window manager sends when
the close button in the title bar is used. Without a tray icon the window has
to accept it and save and close the task file, which the test sees as the empty
temporary file turning into an iCalendar file. With a tray icon the window has
to refuse the close, hide itself and leave the task file open.

* Quit when the window is closed and there is no tray icon

Closing the window only hid it, on the assumption that the system tray icon
brings it back, but that icon is created only when "Place an icon to the system
tray" is enabled in the settings. With the setting off, the window is gone for
good while the process stays in the process list and goes on writing the
iCalendar file, and only "File -> Quit" ends it.

Hide the window only when the tray icon exists. Without one, close the open
file through the same call "File -> Quit" makes and let the window close end
the program.
Related: bug 337459, bug 337459

(For future reference, follow the guidelines at
https://cbea.ms/git-commit/#seven-rules)-->

### Reason for the change

Closing the main window with the title bar's close button only hid the window,
on the assumption that the system tray icon can bring it back. That icon is
created only when "Place an icon to the system tray" is enabled in Settings →
Configure KTimeTracker → Behavior, so with the setting off the window is gone
for good while the process stays in the process list, keeps its timers running
and goes on writing the iCalendar file. Only "File → Quit" ended the program,
which is what bugs 337459 and 347365 report, the second one noting that the
leftover processes can corrupt the .ics file. `MainWindow::queryClose()` now
hides the window only when the tray icon object exists, and otherwise closes
the open file through `TimeTrackerWidget::closeAllFiles()`, the call the Quit
action makes, before letting the close go through.

Review of the first version turned up two defects in the tray icon itself, and
the last commit fixes both. The icon was created but left in the Passive state
a KStatusNotifierItem starts in, and Plasma's system tray keeps Passive items
out of the panel, showing them only in its pop-up of hidden icons, so the icon
that is supposed to bring the window back was not where a user would look for
it. It now sets itself Active. The icon was also created once in `MainWindow`'s
constructor and never added or removed afterwards, so switching "Place an icon
to the system tray" on or off did nothing until the next start.
`TimeTrackerWidget::loadSettings()` now emits a `settingsChanged()` signal and
the main window adds or removes the icon in answer to it.

A later review found one more way to end up with nothing to click: the settings
are reachable from the tray icon's own context menu, so the icon could be
switched off while the window was hidden, leaving the program running with no
window and no icon. Switching the icon off now makes a hidden window reappear,
minimized into the task bar so that it does not cover the settings dialog.

### Test plan

The autotest `mainwindowtest` covers the three cases: a close request is
accepted and the task file written when no tray icon is configured and refused
with the window hidden when one is, switching the setting while the program
runs adds and removes the icon, and the icon's status is Active. Reverting any
one of the three fixes fails the matching test and leaves the others passing.
The whole suite passes.

Checked by hand on KDE neon User Edition with Plasma 6.8.2 on Wayland,
Frameworks 6.31 and Qt 6.11.1: with "Place an icon to the system tray" off,
closing the window ends the program and saves the task file, where the packaged
5.0.1 leaves the process running. With the setting on, the icon now appears in
the panel while the window is open, closing the window hides it to that icon,
and switching the setting takes effect immediately in both directions.

The autotest for the setting also covers the case where the icon is switched
off while the window is hidden: it closes the window so the window hides and
the icon remains, switches the icon off, and checks that the window is back and
minimized.

### Bugs fixed

M  +50   -8    src/base/mainwindow.cpp
M  +1    -0    src/base/mainwindow.h
M  +2    -0    src/base/timetrackerwidget.cpp
M  +5    -0    src/base/timetrackerwidget.h
M  +5    -0    src/base/tray.cpp
M  +4    -0    src/tests/CMakeLists.txt
A  +158  -0    src/tests/mainwindowtest.cpp     [License: GPL(3+eV) GPL(v3.0)
GPL(v2.0)]

https://invent.kde.org/pim/ktimetracker/-/commit/4261f699d62d934397ea62d4d14aac3ff57a662b

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to