diff options
author | Alexis Menard <alexis.menard@nokia.com> | 2009-04-16 07:52:15 (GMT) |
---|---|---|
committer | Alexis Menard <alexis.menard@nokia.com> | 2009-04-16 08:00:55 (GMT) |
commit | a4c4f994fa51ff216f0d43098824617e14b8a284 (patch) | |
tree | 4060ed2a8f3bb0a66130241676fca010f079a17a | |
parent | 1ae4c7b989b04f89a5069d5a5db78c0d8914972b (diff) | |
download | Qt-a4c4f994fa51ff216f0d43098824617e14b8a284.zip Qt-a4c4f994fa51ff216f0d43098824617e14b8a284.tar.gz Qt-a4c4f994fa51ff216f0d43098824617e14b8a284.tar.bz2 |
QFileDialog: When passing an invalid path in static functions the native
dialog don't appear on Windows.
The problem is with the directory that you can specify when calling the
static functions. It can include a file in that path which means that
the file will be selected by default when the dialog appears. But if you
give an invalid file as a selection to the Windows API, then it simply
don't display the dialog. The patch is basically checking the dir we get
when we are called. workingDirectory tested it already and fallback
to the current directory if the argument is invalid. I just check now if
workingDirectory changed the path (that means the parameter value was
incorrect) and select nothing in that case. Using this trick avoid stating
again the complete path to check if the selection exist. (i.e. path()
on QFileInfo don't call stat()).
Task-number: 250120
Reviewed-by: jan-arve
Reviewed-by: jasplin
-rw-r--r-- | src/gui/dialogs/qfiledialog.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/gui/dialogs/qfiledialog.cpp b/src/gui/dialogs/qfiledialog.cpp index b20321f..f70669c 100644 --- a/src/gui/dialogs/qfiledialog.cpp +++ b/src/gui/dialogs/qfiledialog.cpp @@ -1593,7 +1593,12 @@ QString QFileDialog::getOpenFileName(QWidget *parent, args.parent = parent; args.caption = caption; args.directory = QFileDialogPrivate::workingDirectory(dir); - args.selection = QFileDialogPrivate::initialSelection(dir); + //If workingDirectory returned a different path than the initial one, + //it means that the initial path was invalid. There is no point to try select a file + if (args.directory != QFileInfo(dir).path()) + args.selection = QString(); + else + args.selection = QFileDialogPrivate::initialSelection(dir); args.filter = filter; args.mode = ExistingFile; args.options = options; @@ -1678,7 +1683,12 @@ QStringList QFileDialog::getOpenFileNames(QWidget *parent, args.parent = parent; args.caption = caption; args.directory = QFileDialogPrivate::workingDirectory(dir); - args.selection = QFileDialogPrivate::initialSelection(dir); + //If workingDirectory returned a different path than the initial one, + //it means that the initial path was invalid. There is no point to try select a file + if (args.directory != QFileInfo(dir).path()) + args.selection = QString(); + else + args.selection = QFileDialogPrivate::initialSelection(dir); args.filter = filter; args.mode = ExistingFiles; args.options = options; @@ -1764,7 +1774,12 @@ QString QFileDialog::getSaveFileName(QWidget *parent, args.parent = parent; args.caption = caption; args.directory = QFileDialogPrivate::workingDirectory(dir); - args.selection = QFileDialogPrivate::initialSelection(dir); + //If workingDirectory returned a different path than the initial one, + //it means that the initial path was invalid. There is no point to try select a file + if (args.directory != QFileInfo(dir).path()) + args.selection = QString(); + else + args.selection = QFileDialogPrivate::initialSelection(dir); args.filter = filter; args.mode = AnyFile; args.options = options; |