Bugfix: wrong folder selection dialog behavior
Review Request #129989 - Created March 6, 2017 and submitted
There are 2 problems with directory selection dialog.
1. If you scan very first page you'll get SaveLocation dialog but if you press the "..." button in it to specify folder for scans - a file selection dialog will be opened. Not directory selection, but file selection. If you select a file in it - a directory selection dialog pop up just after you close previous one. So you'll get a second dialog. Your first file selection result will be overwritten by folder selection.
2. If you choose for example "/tmp/" in directory selection dialog you'll get "/tmp" in the text box. Without trailing path separator. And resulted filename preview will be "/prefix-0001.png", not "/tmp/prefix-0001.png". If you didn't notice that and press ok you'll get an error as nothing can be saved to root. If you selected another folder you later may realize that your scans are in parent directory. Why? Bcs SkanLite doesn't check trailing path separator in directory path and believes that "/tmp" is a file tmp in the root folder. And Qt's directory selection dialogs always return directory name without trailing path separator in it.
I've fixed both problems.
Second one is easy, just
if (!dir.endsWith(QDir::separator())) dir = dir.append(QDir::separator());before proceeding with directory selection results.
First one is a bit awkward. There is a slot
getDir()and 2 widgets connected to it.
u_urlRequesterfrom SaveLocation dialog and
getDirButtonfrom Settings dialog. the slot opens QFileDialog::getExistingDirectory(). It's fine for getDirButton which is a QButton. But u_urlRequester is a KUrlRequester and contains own button and launches own file selection dialog which is for files by default. That's obviously wrong.
There are notes in
// FIXME KF5. Seems to be this discussion. I believe it's irrelevant to this problem. Perhaps this problem is a former workaround for KF5 problem which is already disappeared.
All you need to fix this behavior is to disconnect KUrlRequester from getDir() which explicitly calls getExistingDirectory() and let it use it's own. We just need to switch it in directory selection mode with
Qt:separator() usage has been replaced with QDir::cleanPath(dir).append('/').
QDir::cleanPath() seems to remove trailing separator for all paths except root '/'. And it would cause a problem, but u_urlRequester returns root as "file:/", so it's fine.
Revision 2 (+4 -5)