Commit 6ee1a423 authored by dogmaphobic's avatar dogmaphobic

Initial work on enforcing extension.

parent c245ce3e
......@@ -477,12 +477,14 @@ void QGCApplication::criticalMessageBoxOnMainThread(const QString& title, const
void QGCApplication::saveTempFlightDataLogOnMainThread(QString tempLogfile)
{
QString defaultSuffix("mavlink");
QString saveFilename = QGCFileDialog::getSaveFileName(MainWindow::instance(),
tr("Select file to save Flight Data Log"),
qgcApp()->mavlinkLogFilesLocation(),
tr("Flight Data Log (*.mavlink)"),
0,0,
&defaultSuffix);
QString saveFilename = QGCFileDialog::getSaveFileName(
MainWindow::instance(),
tr("Select file to save Flight Data Log"),
qgcApp()->mavlinkLogFilesLocation(),
tr("Flight Data Log (*.mavlink)"),
0,0,
&defaultSuffix,
true);
if (!saveFilename.isEmpty()) {
QFile::copy(tempLogfile, saveFilename);
}
......
......@@ -28,10 +28,11 @@
#include "UnitTest.h"
#endif
QString QGCFileDialog::getExistingDirectory(QWidget* parent,
const QString& caption,
const QString& dir,
Options options)
QString QGCFileDialog::getExistingDirectory(
QWidget* parent,
const QString& caption,
const QString& dir,
Options options)
{
_validate(NULL, options);
......@@ -45,12 +46,13 @@ QString QGCFileDialog::getExistingDirectory(QWidget* parent,
}
}
QString QGCFileDialog::getOpenFileName(QWidget* parent,
const QString& caption,
const QString& dir,
const QString& filter,
QString* selectedFilter,
Options options)
QString QGCFileDialog::getOpenFileName(
QWidget* parent,
const QString& caption,
const QString& dir,
const QString& filter,
QString* selectedFilter,
Options options)
{
_validate(selectedFilter, options);
......@@ -64,12 +66,13 @@ QString QGCFileDialog::getOpenFileName(QWidget* parent,
}
}
QStringList QGCFileDialog::getOpenFileNames(QWidget* parent,
const QString& caption,
const QString& dir,
const QString& filter,
QString* selectedFilter,
Options options)
QStringList QGCFileDialog::getOpenFileNames(
QWidget* parent,
const QString& caption,
const QString& dir,
const QString& filter,
QString* selectedFilter,
Options options)
{
_validate(selectedFilter, options);
......@@ -84,12 +87,13 @@ QStringList QGCFileDialog::getOpenFileNames(QWidget* parent,
}
QString QGCFileDialog::getSaveFileName(QWidget* parent,
const QString& caption,
const QString& dir,
const QString& filter,
QString* selectedFilter,
Options options,
QString* defaultSuffix)
const QString& caption,
const QString& dir,
const QString& filter,
QString* selectedFilter,
Options options,
QString* defaultSuffix,
bool strict)
{
_validate(selectedFilter, options);
......@@ -114,10 +118,13 @@ QString QGCFileDialog::getSaveFileName(QWidget* parent,
}
dlg.setDefaultSuffix(*defaultSuffix);
}
if (dlg.exec()) {
if (dlg.selectedFiles().count()) {
return dlg.selectedFiles().first();
while (true) {
if (dlg.exec()) {
if (dlg.selectedFiles().count()) {
return dlg.selectedFiles().first();
}
}
break;
}
return QString("");
}
......
......@@ -50,10 +50,11 @@ public:
@return The chosen path or \c QString("") if none.
@sa <a href="http://qt-project.org/doc/qt-5/qfiledialog.html#getExistingDirectory">QFileDialog::getExistingDirectory()</a>
*/
static QString getExistingDirectory(QWidget* parent = 0,
const QString& caption = QString(),
const QString& dir = QString(),
Options options = ShowDirsOnly);
static QString getExistingDirectory(
QWidget* parent = 0,
const QString& caption = QString(),
const QString& dir = QString(),
Options options = ShowDirsOnly);
//! Static helper that invokes a File Open dialog where the user can select a file to be opened.
/*!
......@@ -66,12 +67,13 @@ public:
@return The full path and filename to be opened or \c QString("") if none.
@sa <a href="http://qt-project.org/doc/qt-5/qfiledialog.html#getOpenFileName">QFileDialog::getOpenFileName()</a>
*/
static QString getOpenFileName(QWidget* parent = 0,
const QString& caption = QString(),
const QString& dir = QString(),
const QString& filter = QString(),
QString* selectedFilter = 0,
Options options = 0);
static QString getOpenFileName(
QWidget* parent = 0,
const QString& caption = QString(),
const QString& dir = QString(),
const QString& filter = QString(),
QString* selectedFilter = 0,
Options options = 0);
//! Static helper that invokes a File Open dialog where the user can select one or more files to be opened.
/*!
......@@ -84,12 +86,13 @@ public:
@return A <a href="http://qt-project.org/doc/qt-5/qstringlist.html">QStringList</a> object containing zero or more files to be opened.
@sa <a href="http://qt-project.org/doc/qt-5/qfiledialog.html#getOpenFileNames">QFileDialog::getOpenFileNames()</a>
*/
static QStringList getOpenFileNames(QWidget* parent = 0,
const QString& caption = QString(),
const QString& dir = QString(),
const QString& filter = QString(),
QString* selectedFilter = 0,
Options options = 0);
static QStringList getOpenFileNames(
QWidget* parent = 0,
const QString& caption = QString(),
const QString& dir = QString(),
const QString& filter = QString(),
QString* selectedFilter = 0,
Options options = 0);
//! Static helper that invokes a File Save dialog where the user can select a directory and enter a filename to be saved.
/*!
......@@ -100,18 +103,21 @@ public:
@param[out] selectedFilter **NOT IMPLEMENTED - Set to NULL** Returns the filter that the user selected in the file dialog.
@param[in] options Set the various options that affect the look and feel of the dialog.
@param[in] defaultSuffix Specifies a string that will be added to the filename if it has no suffix already. The suffix is typically used to indicate the file type (e.g. "txt" indicates a text file).
@param[in] strict Makes the default suffix mandatory. Only files with those extensions will be allowed.
@return The full path and filename to be used to save the file or \c QString("") if none.
@sa <a href="http://qt-project.org/doc/qt-5/qfiledialog.html#getSaveFileName">QFileDialog::getSaveFileName()</a>
@remark If a default suffix is given, it will be appended to the filename if the user does not enter one themselves. That is, if the user simply enters \e foo and the default suffix is set to \e bar,
the returned filename will be \e foo.bar. However, if the user specifies a suffix, none will be added. That is, if the user enters \e foo.txt, that's what you will receive in return.
*/
static QString getSaveFileName(QWidget* parent = 0,
const QString& caption = QString(),
const QString& dir = QString(),
const QString& filter = QString(),
QString* selectedFilter = 0,
Options options = 0,
QString* defaultSuffix = 0);
static QString getSaveFileName(
QWidget* parent = 0,
const QString& caption = QString(),
const QString& dir = QString(),
const QString& filter = QString(),
QString* selectedFilter = 0,
Options options = 0,
QString* defaultSuffix = 0,
bool strict = false);
private slots:
/// @brief The exec slot is private becasue when only want QGCFileDialog users to use the static methods. Otherwise it will break
......
......@@ -998,14 +998,14 @@ void MainWindow::startVideoCapture()
{
QString format("bmp");
QString initialPath = QDir::currentPath() + tr("/untitled.") + format;
QString screenFileName = QGCFileDialog::getSaveFileName(this, tr("Save As"),
initialPath,
tr("%1 Files (*.%2);;All Files (*)")
.arg(format.toUpper())
.arg(format),
0,0,
&format);
QString screenFileName = QGCFileDialog::getSaveFileName(
this, tr("Save As"),
initialPath,
tr("%1 Files (*.%2);;All Files (*)")
.arg(format.toUpper())
.arg(format),
0,0,
&format);
delete videoTimer;
videoTimer = new QTimer(this);
}
......
......@@ -106,15 +106,23 @@ void QGCBaseParamWidget::saveParametersToFile()
if (!mav)
return;
QString defaultSuffix("txt");
QString fileName = QGCFileDialog::getSaveFileName(this, tr("Save File"), qgcApp()->savedParameterFilesLocation(), tr("Parameter File (*.txt)"), 0, 0, &defaultSuffix);
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
return;
QString fileName = QGCFileDialog::getSaveFileName(
this,
tr("Save Parameters"),
qgcApp()->savedParameterFilesLocation(),
tr("Parameter File (*.txt)"),
0, 0,
&defaultSuffix,
true);
if (!fileName.isEmpty()) {
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
return;
}
QTextStream outstream(&file);
paramMgr->writeOnboardParamsToStream(outstream,mav->getUASName());
file.close();
}
QTextStream outstream(&file);
paramMgr->writeOnboardParamsToStream(outstream,mav->getUASName());
file.close();
}
......
......@@ -578,7 +578,8 @@ void QGCToolWidget::exportWidget()
QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
tr("QGroundControl Widget (*%1)").arg(widgetFileExtension),
0,0,
&defaultSuffix);
&defaultSuffix,
true);
//-- Note that if the user enters foo.bar, this will end up foo.bar.qgw
if (!fileName.endsWith(widgetFileExtension))
{
......
......@@ -439,7 +439,8 @@ QString LinechartWidget::getLogSaveFilename()
QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
tr("Logfile (*.log)"),
0,0,
&defaultSuffix);
&defaultSuffix,
true);
return fileName;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment