Bug 427552 - KMainWindow::canBeRestored(1) inappropriately returns true when there is no session restore data
Summary: KMainWindow::canBeRestored(1) inappropriately returns true when there is no s...
Status: REPORTED
Alias: None
Product: frameworks-kxmlgui
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: kdelibs bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-11 19:09 UTC by Nate Graham
Modified: 2020-10-11 19:09 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nate Graham 2020-10-11 19:09:35 UTC
Consider the following code:

KConfigGui::setSessionConfig(QStringLiteral("myApp"), QStringLiteral("myApp"));
if (KMainWindow::canBeRestored(1)) {
    // do a bunch of stuff
}


KMainWindow::canBeRestored(1) will return true even though the newly-created session config is empty. This is because internally, it's doing this:

const int n = group.readEntry("NumberOfWindows", 1);
return number >= 1 && number <= n;


So NumberOfWindows is not set, which causes it to fall back to 1. And then the function returns true because the number 1 satisfies both criteria.

This can be trivially fixed by changing the default value of the readEntry() call from 1 to 0, and that's what I did in https://invent.kde.org/frameworks/kxmlgui/-/merge_requests/. However this so breaks Dolphin's manual session restore feature (which accidentally takes advantage of this bug to function) and I had to revert it.

This bug report tracks this issue so that the fix can be merged after Dolphin and potentially other apps are fixed, or KF6--whichever comes first.