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 ...@@ -477,12 +477,14 @@ void QGCApplication::criticalMessageBoxOnMainThread(const QString& title, const
void QGCApplication::saveTempFlightDataLogOnMainThread(QString tempLogfile) void QGCApplication::saveTempFlightDataLogOnMainThread(QString tempLogfile)
{ {
QString defaultSuffix("mavlink"); QString defaultSuffix("mavlink");
QString saveFilename = QGCFileDialog::getSaveFileName(MainWindow::instance(), QString saveFilename = QGCFileDialog::getSaveFileName(
tr("Select file to save Flight Data Log"), MainWindow::instance(),
qgcApp()->mavlinkLogFilesLocation(), tr("Select file to save Flight Data Log"),
tr("Flight Data Log (*.mavlink)"), qgcApp()->mavlinkLogFilesLocation(),
0,0, tr("Flight Data Log (*.mavlink)"),
&defaultSuffix); 0,0,
&defaultSuffix,
true);
if (!saveFilename.isEmpty()) { if (!saveFilename.isEmpty()) {
QFile::copy(tempLogfile, saveFilename); QFile::copy(tempLogfile, saveFilename);
} }
......
...@@ -28,10 +28,11 @@ ...@@ -28,10 +28,11 @@
#include "UnitTest.h" #include "UnitTest.h"
#endif #endif
QString QGCFileDialog::getExistingDirectory(QWidget* parent, QString QGCFileDialog::getExistingDirectory(
const QString& caption, QWidget* parent,
const QString& dir, const QString& caption,
Options options) const QString& dir,
Options options)
{ {
_validate(NULL, options); _validate(NULL, options);
...@@ -45,12 +46,13 @@ QString QGCFileDialog::getExistingDirectory(QWidget* parent, ...@@ -45,12 +46,13 @@ QString QGCFileDialog::getExistingDirectory(QWidget* parent,
} }
} }
QString QGCFileDialog::getOpenFileName(QWidget* parent, QString QGCFileDialog::getOpenFileName(
const QString& caption, QWidget* parent,
const QString& dir, const QString& caption,
const QString& filter, const QString& dir,
QString* selectedFilter, const QString& filter,
Options options) QString* selectedFilter,
Options options)
{ {
_validate(selectedFilter, options); _validate(selectedFilter, options);
...@@ -64,12 +66,13 @@ QString QGCFileDialog::getOpenFileName(QWidget* parent, ...@@ -64,12 +66,13 @@ QString QGCFileDialog::getOpenFileName(QWidget* parent,
} }
} }
QStringList QGCFileDialog::getOpenFileNames(QWidget* parent, QStringList QGCFileDialog::getOpenFileNames(
const QString& caption, QWidget* parent,
const QString& dir, const QString& caption,
const QString& filter, const QString& dir,
QString* selectedFilter, const QString& filter,
Options options) QString* selectedFilter,
Options options)
{ {
_validate(selectedFilter, options); _validate(selectedFilter, options);
...@@ -84,12 +87,13 @@ QStringList QGCFileDialog::getOpenFileNames(QWidget* parent, ...@@ -84,12 +87,13 @@ QStringList QGCFileDialog::getOpenFileNames(QWidget* parent,
} }
QString QGCFileDialog::getSaveFileName(QWidget* parent, QString QGCFileDialog::getSaveFileName(QWidget* parent,
const QString& caption, const QString& caption,
const QString& dir, const QString& dir,
const QString& filter, const QString& filter,
QString* selectedFilter, QString* selectedFilter,
Options options, Options options,
QString* defaultSuffix) QString* defaultSuffix,
bool strict)
{ {
_validate(selectedFilter, options); _validate(selectedFilter, options);
...@@ -114,10 +118,13 @@ QString QGCFileDialog::getSaveFileName(QWidget* parent, ...@@ -114,10 +118,13 @@ QString QGCFileDialog::getSaveFileName(QWidget* parent,
} }
dlg.setDefaultSuffix(*defaultSuffix); dlg.setDefaultSuffix(*defaultSuffix);
} }
if (dlg.exec()) { while (true) {
if (dlg.selectedFiles().count()) { if (dlg.exec()) {
return dlg.selectedFiles().first(); if (dlg.selectedFiles().count()) {
return dlg.selectedFiles().first();
}
} }
break;
} }
return QString(""); return QString("");
} }
......
...@@ -50,10 +50,11 @@ public: ...@@ -50,10 +50,11 @@ public:
@return The chosen path or \c QString("") if none. @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> @sa <a href="http://qt-project.org/doc/qt-5/qfiledialog.html#getExistingDirectory">QFileDialog::getExistingDirectory()</a>
*/ */
static QString getExistingDirectory(QWidget* parent = 0, static QString getExistingDirectory(
const QString& caption = QString(), QWidget* parent = 0,
const QString& dir = QString(), const QString& caption = QString(),
Options options = ShowDirsOnly); 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. //! Static helper that invokes a File Open dialog where the user can select a file to be opened.
/*! /*!
...@@ -66,12 +67,13 @@ public: ...@@ -66,12 +67,13 @@ public:
@return The full path and filename to be opened or \c QString("") if none. @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> @sa <a href="http://qt-project.org/doc/qt-5/qfiledialog.html#getOpenFileName">QFileDialog::getOpenFileName()</a>
*/ */
static QString getOpenFileName(QWidget* parent = 0, static QString getOpenFileName(
const QString& caption = QString(), QWidget* parent = 0,
const QString& dir = QString(), const QString& caption = QString(),
const QString& filter = QString(), const QString& dir = QString(),
QString* selectedFilter = 0, const QString& filter = QString(),
Options options = 0); 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. //! 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: ...@@ -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. @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> @sa <a href="http://qt-project.org/doc/qt-5/qfiledialog.html#getOpenFileNames">QFileDialog::getOpenFileNames()</a>
*/ */
static QStringList getOpenFileNames(QWidget* parent = 0, static QStringList getOpenFileNames(
const QString& caption = QString(), QWidget* parent = 0,
const QString& dir = QString(), const QString& caption = QString(),
const QString& filter = QString(), const QString& dir = QString(),
QString* selectedFilter = 0, const QString& filter = QString(),
Options options = 0); 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. //! 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: ...@@ -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[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] 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] 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. @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> @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, @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. 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, static QString getSaveFileName(
const QString& caption = QString(), QWidget* parent = 0,
const QString& dir = QString(), const QString& caption = QString(),
const QString& filter = QString(), const QString& dir = QString(),
QString* selectedFilter = 0, const QString& filter = QString(),
Options options = 0, QString* selectedFilter = 0,
QString* defaultSuffix = 0); Options options = 0,
QString* defaultSuffix = 0,
bool strict = false);
private slots: private slots:
/// @brief The exec slot is private becasue when only want QGCFileDialog users to use the static methods. Otherwise it will break /// @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() ...@@ -998,14 +998,14 @@ void MainWindow::startVideoCapture()
{ {
QString format("bmp"); QString format("bmp");
QString initialPath = QDir::currentPath() + tr("/untitled.") + format; QString initialPath = QDir::currentPath() + tr("/untitled.") + format;
QString screenFileName = QGCFileDialog::getSaveFileName(
QString screenFileName = QGCFileDialog::getSaveFileName(this, tr("Save As"), this, tr("Save As"),
initialPath, initialPath,
tr("%1 Files (*.%2);;All Files (*)") tr("%1 Files (*.%2);;All Files (*)")
.arg(format.toUpper()) .arg(format.toUpper())
.arg(format), .arg(format),
0,0, 0,0,
&format); &format);
delete videoTimer; delete videoTimer;
videoTimer = new QTimer(this); videoTimer = new QTimer(this);
} }
......
...@@ -106,15 +106,23 @@ void QGCBaseParamWidget::saveParametersToFile() ...@@ -106,15 +106,23 @@ void QGCBaseParamWidget::saveParametersToFile()
if (!mav) if (!mav)
return; return;
QString defaultSuffix("txt"); QString defaultSuffix("txt");
QString fileName = QGCFileDialog::getSaveFileName(this, tr("Save File"), qgcApp()->savedParameterFilesLocation(), tr("Parameter File (*.txt)"), 0, 0, &defaultSuffix); QString fileName = QGCFileDialog::getSaveFileName(
QFile file(fileName); this,
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { tr("Save Parameters"),
return; 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() ...@@ -578,7 +578,8 @@ void QGCToolWidget::exportWidget()
QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
tr("QGroundControl Widget (*%1)").arg(widgetFileExtension), tr("QGroundControl Widget (*%1)").arg(widgetFileExtension),
0,0, 0,0,
&defaultSuffix); &defaultSuffix,
true);
//-- Note that if the user enters foo.bar, this will end up foo.bar.qgw //-- Note that if the user enters foo.bar, this will end up foo.bar.qgw
if (!fileName.endsWith(widgetFileExtension)) if (!fileName.endsWith(widgetFileExtension))
{ {
......
...@@ -439,7 +439,8 @@ QString LinechartWidget::getLogSaveFilename() ...@@ -439,7 +439,8 @@ QString LinechartWidget::getLogSaveFilename()
QStandardPaths::writableLocation(QStandardPaths::DesktopLocation), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation),
tr("Logfile (*.log)"), tr("Logfile (*.log)"),
0,0, 0,0,
&defaultSuffix); &defaultSuffix,
true);
return fileName; 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