GUI: Use native file selection dialog when selecting report file.

This commit is contained in:
Kimmo Varis 2009-06-18 00:34:22 +03:00
parent 5d0d21d668
commit a19c9861da
1 changed files with 21 additions and 28 deletions

View File

@ -489,39 +489,32 @@ void MainWindow::ShowAuthors()
void MainWindow::Save() void MainWindow::Save()
{ {
QFileDialog dialog(this); QString selectedFilter;
dialog.setFileMode(QFileDialog::AnyFile); QString filter(tr("XML files (*.xml);;Text files (*.txt)"));
dialog.setAcceptMode(QFileDialog::AcceptSave); QString selectedFile = QFileDialog::getSaveFileName(this,
tr("Save the report file"),
QString(),
filter,
&selectedFilter);
QStringList filters; if (!selectedFile.isEmpty())
filters << tr("XML files (*.xml)") << tr("Text files (*.txt)");
dialog.setNameFilters(filters);
if (dialog.exec())
{ {
QStringList list = dialog.selectedFiles(); //Check if xml file type was selected
bool xml = selectedFilter == tr("XML files (*.xml)");
if (list.size() > 0) //Force xml extension to the file
if (xml && !selectedFile.endsWith(".xml", Qt::CaseInsensitive))
{ {
QString filename = list[0]; selectedFile += ".xml";
//Check if xml file type was selected
bool xml = (dialog.selectedNameFilter() == filters[0]);
//Force xml extension to the file
if (xml && !filename.endsWith(".xml", Qt::CaseInsensitive))
{
filename += ".xml";
}
//Force .txt extension
if (!xml && !filename.endsWith(".txt", Qt::CaseInsensitive))
{
filename += ".txt";
}
mResults.Save(filename, xml);
} }
//Force .txt extension
if (!xml && !selectedFile.endsWith(".txt", Qt::CaseInsensitive))
{
selectedFile += ".txt";
}
mResults.Save(selectedFile, xml);
} }
} }