Skip to content
This repository was archived by the owner on Dec 9, 2021. It is now read-only.

Adds 'close to tray' option in settings#140

Closed
plafue wants to merge 1 commit intokeepassx:masterfrom
plafue:close-to-tray
Closed

Adds 'close to tray' option in settings#140
plafue wants to merge 1 commit intokeepassx:masterfrom
plafue:close-to-tray

Conversation

@plafue
Copy link
Copy Markdown

@plafue plafue commented Dec 12, 2015

WIP
(see https://www.keepassx.org/dev/issues/364#change-1035)

I'd like to add this functionality, however i can not manually test this, as it seems like assets like icons and images are not properly loaded when i run the compiled version (e.g. i see the alternative caption "Add new entry" in the menu bar instead of its icon). The try icon is not displayed at all.

I'm not that familiar with C/Qt development, so any hints are very much appreciated.

Good work, by the way!

@nmschulte
Copy link
Copy Markdown

I just tested this myself and it seems to work well. @debfx, what can I do to help get this in the next release?


if (config()->get("GUI/CloseToTray").toBool()) {
event->ignore();
QTimer::singleShot(0, this, SLOT(hide()));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I've never worked with QT before. Is the singleShot hide to release the event thread?

@kopr12
Copy link
Copy Markdown

kopr12 commented Feb 8, 2016

Working fine, but how do you actually close the application if you want it ?
Right click on tray -> Quit doesn't work, same happens when selecting Quit from the Menu.

@nmschulte
Copy link
Copy Markdown

Send the process a SIGTERM or SIGKILL signal; that's the only way to close it with this change and the feature enabled.

@kopr12
Copy link
Copy Markdown

kopr12 commented Feb 9, 2016

Well yeah, anyway I added something to quit with a middle click on tray icon and it works.

src/gui/MainWindow.cpp

void MainWindow::trayIconTriggered(QSystemTrayIcon::ActivationReason reason)
 {
     if (reason == QSystemTrayIcon::Trigger) {
         toggleWindow();
    }
+    if (reason == QSystemTrayIcon::MiddleClick) {
+         reallyQuit();
+     }
 }



+void MainWindow::reallyQuit()
+{
+    bool accept = saveLastDatabases();
+
+    if (accept) {
+        saveWindowInformation();
+        QApplication::quit();
+    }
+    else {
+      QApplication::quit();
+    }
+}
+
 void MainWindow::lockDatabasesAfterInactivity()
 {

src/gui/MainWindow.h

     void toggleWindow();
+    void reallyQuit();
     void lockDatabasesAfterInactivity();

@nmschulte
Copy link
Copy Markdown

I think choosing the "Quit" option from the tray context-menu should actually kill the program; when would you ever want to use that (remember, from the tray...) to minimize the program? If someone did want the minimize action, it'd probably be better to add a "Minimize" entry.

Oh, hah: clicking the tray icon already does this "minimize" behavior. I think that basically settles the point then: the Quit option from the tray should reallyQuit. What do you think?

<bool>false</bool>
</property>
<property name="text">
<string>Hide window to system tray when closing main window (Use Ctrl+Q or Database -> Exit to exit).</string>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@kajzersoze, I see what you're getting at now. This text will definitely need to change to match whatever the decided behavior is: it doesn't match even the patch it comes with. Either that, or "exit" means "hide", with this option.

@kopr12
Copy link
Copy Markdown

kopr12 commented Feb 9, 2016

Yeah exactly, that's how it should be.
I just didn't know how to do that (quit from the tray -> reallyQuit) so I added middle click thingy, which works from me atm until someone smarter figure out the real Quit from the tray :)

@nmschulte
Copy link
Copy Markdown

I'll try and clean this up and see if I can get it in. @plafue, are you still wanting to see this included too?

@kopr12
Copy link
Copy Markdown

kopr12 commented Feb 9, 2016

I figured out actually how to add an option to the tray and it works.
Now probably good idea would be to remove Quit from the tray menu, not sure though what to do with the Quit option from Main Menu. Middle click on tray is also not needed now.
Here's the addition to the tray menu, needs reallyQuit() from earlier.
src/gui/MainWindow.cpp

             QAction* actionToggle = new QAction(tr("Toggle window"), menu);
             menu->addAction(actionToggle);
+       QAction* actionToggle = new QAction(tr("Really Quit"), menu);
+            menu->addAction(actionReallyQuit); 

             menu->addAction(m_ui->actionQuit);

             connect(m_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
                     SLOT(trayIconTriggered(QSystemTrayIcon::ActivationReason)));
             connect(actionToggle, SIGNAL(triggered()), SLOT(toggleWindow()));
+       connect(actionReallyQuit, SIGNAL(triggered()), SLOT(reallyQuit()));

             m_trayIcon->setContextMenu(menu);
             m_trayIcon->show();

daniellandau pushed a commit to daniellandau/keepassx that referenced this pull request Feb 9, 2017
* KeePassCR -> KeePassXC in INSTALL
* Added .md extension to INSTALL.
@plafue plafue closed this Nov 4, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants