Add extension while saving streams and sessions, if user doesn't specify one.
Fixes #187
This commit is contained in:
parent
cd100aa6e0
commit
75efed5ec4
@ -220,11 +220,28 @@ void MainWindow::on_actionSaveSession_triggered()
|
|||||||
if (fileTypes.size())
|
if (fileTypes.size())
|
||||||
fileType = fileTypes.at(0);
|
fileType = fileTypes.at(0);
|
||||||
|
|
||||||
|
_retry:
|
||||||
fileName = QFileDialog::getSaveFileName(this, tr("Save Session"),
|
fileName = QFileDialog::getSaveFileName(this, tr("Save Session"),
|
||||||
fileName, fileTypes.join(";;"), &fileType, options);
|
fileName, fileTypes.join(";;"), &fileType, options);
|
||||||
if (fileName.isEmpty())
|
if (fileName.isEmpty())
|
||||||
goto _exit;
|
goto _exit;
|
||||||
|
|
||||||
|
if (QFileInfo(fileName).suffix().isEmpty()) {
|
||||||
|
QString fileExt = fileType.section(QRegExp("[\\*\\)]"), 1, 1);
|
||||||
|
qDebug("Adding extension '%s' to '%s'",
|
||||||
|
qPrintable(fileExt), qPrintable(fileName));
|
||||||
|
fileName.append(fileExt);
|
||||||
|
if (QFileInfo(fileName).exists()) {
|
||||||
|
if (QMessageBox::warning(this, tr("Overwrite File?"),
|
||||||
|
QString("The file \"%1\" already exists.\n\n"
|
||||||
|
"Do you wish to overwrite it?")
|
||||||
|
.arg(QFileInfo(fileName).fileName()),
|
||||||
|
QMessageBox::Yes|QMessageBox::No,
|
||||||
|
QMessageBox::No) != QMessageBox::Yes)
|
||||||
|
goto _retry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!saveSession(fileName, fileType, errorStr))
|
if (!saveSession(fileName, fileType, errorStr))
|
||||||
QMessageBox::critical(this, qApp->applicationName(), errorStr);
|
QMessageBox::critical(this, qApp->applicationName(), errorStr);
|
||||||
else if (!errorStr.isEmpty())
|
else if (!errorStr.isEmpty())
|
||||||
|
@ -895,9 +895,8 @@ void PortsWindow::on_actionSave_Streams_triggered()
|
|||||||
current = proxyPortModel->mapToSource(current);
|
current = proxyPortModel->mapToSource(current);
|
||||||
|
|
||||||
// On Mac OS with Native Dialog, getSaveFileName() ignores fileType
|
// On Mac OS with Native Dialog, getSaveFileName() ignores fileType
|
||||||
// which we need.On some Linux distros the native dialog can't
|
// which we need
|
||||||
// distinguish between Ostinato(*) and PCAP(*)
|
#if defined(Q_OS_MAC)
|
||||||
#if defined(Q_OS_MAC) || defined(Q_OS_UNIX)
|
|
||||||
options |= QFileDialog::DontUseNativeDialog;
|
options |= QFileDialog::DontUseNativeDialog;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -912,6 +911,22 @@ _retry:
|
|||||||
if (fileName.isEmpty())
|
if (fileName.isEmpty())
|
||||||
goto _exit;
|
goto _exit;
|
||||||
|
|
||||||
|
if (QFileInfo(fileName).suffix().isEmpty()) {
|
||||||
|
QString fileExt = fileType.section(QRegExp("[\\*\\)]"), 1, 1);
|
||||||
|
qDebug("Adding extension '%s' to '%s'",
|
||||||
|
qPrintable(fileExt), qPrintable(fileName));
|
||||||
|
fileName.append(fileExt);
|
||||||
|
if (QFileInfo(fileName).exists()) {
|
||||||
|
if (QMessageBox::warning(this, tr("Overwrite File?"),
|
||||||
|
QString("The file \"%1\" already exists.\n\n"
|
||||||
|
"Do you wish to overwrite it?")
|
||||||
|
.arg(QFileInfo(fileName).fileName()),
|
||||||
|
QMessageBox::Yes|QMessageBox::No,
|
||||||
|
QMessageBox::No) != QMessageBox::Yes)
|
||||||
|
goto _retry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fileType = fileType.remove(QRegExp("\\(.*\\)")).trimmed();
|
fileType = fileType.remove(QRegExp("\\(.*\\)")).trimmed();
|
||||||
if (!fileType.startsWith("Ostinato")
|
if (!fileType.startsWith("Ostinato")
|
||||||
&& !fileType.startsWith("Python"))
|
&& !fileType.startsWith("Python"))
|
||||||
|
@ -51,7 +51,7 @@ QStringList StreamFileFormat::supportedFileTypes(Operation op)
|
|||||||
|
|
||||||
fileTypes
|
fileTypes
|
||||||
<< "Ostinato (*.ostm)"
|
<< "Ostinato (*.ostm)"
|
||||||
<< "PCAP (*)"
|
<< "PCAP (*.pcap)"
|
||||||
<< "PDML (*.pdml)";
|
<< "PDML (*.pdml)";
|
||||||
|
|
||||||
if (op == kSaveFile)
|
if (op == kSaveFile)
|
||||||
|
Loading…
Reference in New Issue
Block a user