[Kleopatra] Fix size saving/restore
ClosedPublic

Authored by andreylegayev on Apr 4 2020, 11:02 PM.

Details

Summary

Fixes applied:

  1. Make sure MainWindow destructor executed on app exit
  2. MainWindow: Remove standard KDE Session Manager methods - they work only in KDE login/logout and don't work in Windows
  3. MainWindow, SignEncrypt dialog, DecryptVerify dialog: Use custom save/read config methods based on helper functions from KWindowConfig

New implementation works fine with KDE SM:

  • saved session load happens after custom readConfig() and overrides window settings with values from session
  • session save happens before custom writeConfig() and saves data to ~/.config/session/ - it doesn't impact writeConfig()

This implementation works fine under Win10 on multi-monitor multi-dpi setup.
Appropriate setting is loaded in case of display switch or main monitor switch.

Example of config file which stores size for several resolutions:

[SignEncryptFilesWizard]
Height 1200=604
Height 720=451
Width 1280=458
Width 1920=597

Related bug reports:

Test Plan

MainWindow Size

  1. Run kleopatra and resize main window

Check configuration file - new window size should be saved automatically to section "MainWindow"

  1. Exit kleopatra via SysTrayIcon menu

Check that configuration file - size should be saved to section "MainWindow"

  1. Change screen resolution, run Kleo and exit from it

Check that configuration file - new size should be saved to section "MainWindow" in parallel to old one

  1. Change screen resolution to previous value, run Kleo - main window should be of size from configuration file

SignEncrypt and DecryptVerify dialogs
Try to use dialogs on different screen resolutions. Sizes saved on dialog window close.
You should see several sizes in corresponding sections of configuration file.
Size should be restored when you start dialog again.

KDE Sessions

  1. Run Kleopatra
  2. Change main window size
  3. Logout
  4. Login

Window size should be the same as before logout

Diff Detail

Repository
R168 Kleopatra
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
andreylegayev created this revision.Apr 4 2020, 11:02 PM
Restricted Application added a project: KDE PIM. · View Herald TranscriptApr 4 2020, 11:02 PM
Restricted Application added a subscriber: kde-pim. · View Herald Transcript
andreylegayev requested review of this revision.Apr 4 2020, 11:02 PM

Removed debug code in MainWindow::MainWindow()

andreylegayev edited the test plan for this revision. (Show Details)Apr 5 2020, 9:23 AM
mlaurent added inline comments.
src/kleopatraapplication.cpp
111

not the same patch as it.
Create another one please

dfaure requested changes to this revision.Apr 5 2020, 4:50 PM
dfaure added a subscriber: dfaure.
dfaure added inline comments.
src/kleopatraapplication.cpp
227

This if() is not needed.
delete nullptr is valid in C++ (no-op).

src/mainwindow.cpp
696

Is this needed? Unlike the dialogs above in this patch, this class is a KXmlGuiWindow which inherits from KMainWindow which has this code already.

This revision now requires changes to proceed.Apr 5 2020, 4:50 PM
andreylegayev edited the summary of this revision. (Show Details)Apr 6 2020, 8:00 AM
andreylegayev marked an inline comment as done.Apr 10 2020, 8:04 AM

@dfaure could you review my comments?

src/kleopatraapplication.cpp
111
227

Fixing it.. thanks!

src/mainwindow.cpp
696

I agree - MainWindow inherits it from KMainWindow, but it works only with KDE session management.
Methods readProperties() and saveProperties() are called when you save session (this is how I debugged it) and when you run app with parameter -session

There is also builtin timer which saves window settings automatically once you resize window, but there is no code which loads saved settings.
If you run most recent Kleopatra on your machine you'll get window size 1024x500 regardless previously saved size.

In this class I could call KMainWindow methods directly, but I wanted to have universal code snippet for all windows to save geometry on multi-dpi/-screen without annoying Qt bug. I re-used it in dialogs as you saw.

Annoying Qt bug - win10:
I literally cannot make SignEncrypt window appear to me.
The only way is to delete geometry from kleopatrarc and restart Kleopatra.
It so annoyed me that I configured dev environment and started all this debug :-)

dfaure added inline comments.Apr 10 2020, 8:23 AM
src/mainwindow.cpp
696

The code to load autosaved settings is the end of KMainWindow::setAutoSaveSettings.
This works for all other KMainWindow-based applications, you know ;)

To enable the autosave functionality, you call setAutoSaveSettings at creation time, and it will load the previously saved settings.

readProperties and saveProperties are called from here, so obviously not just for session management purposes.

I would really like kleopatra to do like all other KMainWindow-based applications and rely on the KMainWindow code as much as possible. This makes long term maintenance easier.

I see that we're missing something similar for dialogs, which means we should have something in a KDE Frameworks about that, but for now I'm ok with your solution of duplicating a bit of code in every one of kleopatra's dialogs. For the mainwindow, though, I'd like it to do the right thing since that is available.

706

Shorter form:

setVisible(cfgGroup.readEntry("hidden", false));

@dfaure could you review my comments?

BTW they only appeared today. You need to remember to click the Submit button at the very bottom otherwise your comments aren't posted.

andreylegayev marked 3 inline comments as done.Apr 11 2020, 12:03 PM

@dfaure now I know that I need to click "Submit" :)

src/mainwindow.cpp
696

Thanks for the hint with setAutoSaveSettings(). I've added it to constructor.
I've reverted back the rest to original version, but removed geometry save/load.

readProperties and saveProperties are really called only from session management.
I've re-checked it by setting breakpoints and by investigating source code:
https://github.com/vasi/kdelibs/blob/master/kdeui/widgets/kmainwindow.cpp

Call chain from constructor - readProperties() isn't called:

1. setAutoSaveSettings()
2. applyMainWindowSettings()

Call chain from session management:

1. restore()
2. readPropertiesInternal()
3. applyMainWindowSettings() + readProperties()
706

Replaced, but setHidden()

andreylegayev marked 2 inline comments as done.
dfaure accepted this revision.Apr 11 2020, 1:02 PM
dfaure added inline comments.
src/mainwindow.cpp
696

I know. However I mistakenly thought kleopatra's code was calling readProperties() directly. It's not -- that's only in a readProperties() reimplementation, which I overlooked for lack of context in this patch (better use arc, but don't worry about that, we're moving to gitlab real soon now hopefully).

Sorry for the confusion.

706

Oops, I missed a ! in my suggested line of code, indeed. Or setHidden, which is equivalent indeed.

This revision is now accepted and ready to land.Apr 11 2020, 1:02 PM

Updates:
I've got KDE developer access.
Before committing anything I wanted to test it again and found that last version doesn't restore size on startup :-/
It's fixed now and it's ready to be committed:

  • I've tested it on Kde Neon and Windows 10
  • Unit tests passed

Changes:

  • removed resize(1024, 500) and setAutoSaveSettings() in MainWindow constructor
  • add q->resize(QSize(1024, 500)) in MainWindow::Private::Private

I've found that setAutoSaveSettings() is already added MainWindow::Private::Private()
There is no need to add it in MainWindow constructor.

@dfaure could you take a look at it last time?
Should I push this commit directly to master?

dfaure accepted this revision.Apr 19 2020, 5:17 PM

Yes you can push to master.

src/crypto/gui/decryptverifyfilesdialog.cpp
45

unused

47

unused

andreylegayev marked 2 inline comments as done.Apr 19 2020, 5:36 PM
andreylegayev added inline comments.
src/crypto/gui/decryptverifyfilesdialog.cpp
45

removed

47

removed

This revision was automatically updated to reflect the committed changes.
andreylegayev marked 2 inline comments as done.