GUI: Use native file selection dialog to select viewer application.

In Windows use *.exe filter since almost all executable applications have that extension so it makes no sense to show all files.
This commit is contained in:
Kimmo Varis 2009-06-18 00:54:39 +03:00
parent a19c9861da
commit 269e823c63
1 changed files with 22 additions and 18 deletions

View File

@ -84,27 +84,31 @@ ApplicationDialog::~ApplicationDialog()
void ApplicationDialog::Browse()
{
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::ExistingFiles);
if (dialog.exec())
{
QStringList list = dialog.selectedFiles();
if (list.size() > 0)
{
QString path(QDir::toNativeSeparators(list[0]));
// In Windows we must surround paths including spaces with quotation marks.
QString filter;
#ifdef Q_WS_WIN
if (path.indexOf(" ") > -1)
{
path.insert(0, "\"");
path.append("\"");
}
// In Windows (almost) all executables have .exe extension
// so it does not make sense to show everything.
filter += tr("Executable files (*.exe);;All files(*.*)");
#endif // Q_WS_WIN
QString selectedFile = QFileDialog::getOpenFileName(this,
tr("Select viewer application"),
QString(),
filter);
if (!selectedFile.isEmpty())
{
QString path(QDir::toNativeSeparators(selectedFile));
// In Windows we must surround paths including spaces with quotation marks.
#ifdef Q_WS_WIN
if (path.indexOf(" ") > -1)
{
path.insert(0, "\"");
path.append("\"");
}
#endif // Q_WS_WIN
mPath->setText(path);
}
mPath->setText(path);
}
}