Commit a7ee3e36 authored by Don Gagne's avatar Don Gagne

Merge pull request #2446 from DonLakeFlyer/SavedFilesLocation

Use Documents as saved files location
parents ef2586f8 a145b8ac
......@@ -117,19 +117,13 @@ QGCApplication* QGCApplication::_app = NULL;
const char* QGCApplication::_deleteAllSettingsKey = "DeleteAllSettingsNextBoot";
const char* QGCApplication::_settingsVersionKey = "SettingsVersion";
const char* QGCApplication::_savedFilesLocationKey = "SavedFilesLocation";
const char* QGCApplication::_promptFlightDataSave = "PromptFLightDataSave";
const char* QGCApplication::_promptFlightDataSaveNotArmed = "PromptFLightDataSaveNotArmed";
const char* QGCApplication::_styleKey = "StyleIsDark";
const char* QGCApplication::_defaultSavedFileDirectoryName = "QGroundControl";
const char* QGCApplication::_savedFileMavlinkLogDirectoryName = "FlightData";
const char* QGCApplication::_savedFileParameterDirectoryName = "SavedParameters";
const char* QGCApplication::_darkStyleFile = ":/res/styles/style-dark.css";
const char* QGCApplication::_lightStyleFile = ":/res/styles/style-light.css";
// Qml Singleton factories
static QObject* screenToolsControllerSingletonFactory(QQmlEngine*, QJSEngine*)
......@@ -429,40 +423,6 @@ void QGCApplication::_initCommon(void)
"Your saved settings have been reset to defaults.");
}
// Load saved files location and validate
QString savedFilesLocation;
if (settings.contains(_savedFilesLocationKey)) {
savedFilesLocation = settings.value(_savedFilesLocationKey).toString();
if (!validatePossibleSavedFilesLocation(savedFilesLocation)) {
savedFilesLocation.clear();
}
}
if (savedFilesLocation.isEmpty()) {
// No location set (or invalid). Create a default one in Documents standard location.
QString documentsLocation = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
QDir documentsDir(documentsLocation);
if (!documentsDir.exists()) {
qWarning() << "Documents directory doesn't exist" << documentsDir.absolutePath();
}
bool pathCreated = documentsDir.mkpath(_defaultSavedFileDirectoryName);
Q_UNUSED(pathCreated);
Q_ASSERT(pathCreated);
savedFilesLocation = documentsDir.filePath(_defaultSavedFileDirectoryName);
}
if (!savedFilesLocation.isEmpty()) {
if (!validatePossibleSavedFilesLocation(savedFilesLocation)) {
savedFilesLocation.clear();
}
}
qDebug() << "Saved files location" << savedFilesLocation;
settings.setValue(_savedFilesLocationKey, savedFilesLocation);
settings.sync();
}
......@@ -487,14 +447,6 @@ bool QGCApplication::_initForNormalAppBoot(void)
MainWindow* mainWindow = MainWindow::_create();
Q_CHECK_PTR(mainWindow);
// If we made it this far and we still don't have a location. Either the specfied location was invalid
// or we coudn't create a default location. Either way, we need to let the user know and prompt for a new
/// settings.
QString savedFilesLocation = settings.value(_savedFilesLocationKey).toString();
if (savedFilesLocation.isEmpty()) {
showMessage("The location to save files to is invalid, or cannot be written to. Please provide a new one.");
}
// Now that main window is up check for lost log files
connect(this, &QGCApplication::checkForLostLogFiles, toolbox()->mavlinkProtocol(), &MAVLinkProtocol::checkForLostLogFiles);
emit checkForLostLogFiles();
......@@ -523,70 +475,6 @@ void QGCApplication::clearDeleteAllSettingsNextBoot(void)
settings.remove(_deleteAllSettingsKey);
}
void QGCApplication::setSavedFilesLocation(QString& location)
{
QSettings settings;
settings.setValue(_savedFilesLocationKey, location);
}
bool QGCApplication::validatePossibleSavedFilesLocation(QString& location)
{
// Make sure we can write to the directory
QString filename = QDir(location).filePath("QGCTempXXXXXXXX.tmp");
QGCTemporaryFile tempFile(filename);
if (!tempFile.open()) {
return false;
}
tempFile.remove();
return true;
}
QString QGCApplication::savedFilesLocation(void)
{
QSettings settings;
return settings.value(_savedFilesLocationKey).toString();
}
QString QGCApplication::savedParameterFilesLocation(void)
{
QString location;
QDir parentDir(savedFilesLocation());
location = parentDir.filePath(_savedFileParameterDirectoryName);
if (!QDir(location).exists()) {
// If directory doesn't exist, try to create it
if (!parentDir.mkpath(_savedFileParameterDirectoryName)) {
// Return an error
location.clear();
}
}
return location;
}
QString QGCApplication::mavlinkLogFilesLocation(void)
{
QString location;
QDir parentDir(savedFilesLocation());
location = parentDir.filePath(_savedFileMavlinkLogDirectoryName);
if (!QDir(location).exists()) {
// If directory doesn't exist, try to create it
if (!parentDir.mkpath(_savedFileMavlinkLogDirectoryName)) {
// Return an error
location.clear();
}
}
return location;
}
bool QGCApplication::promptFlightDataSave(void)
{
QSettings settings;
......@@ -655,7 +543,7 @@ void QGCApplication::saveTempFlightDataLogOnMainThread(QString tempLogfile)
QString saveFilename = QGCFileDialog::getSaveFileName(
MainWindow::instance(),
tr("Save Flight Data Log"),
qgcApp()->mavlinkLogFilesLocation(),
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation),
tr("Flight Data Log Files (*.mavlink)"),
"mavlink");
......
......@@ -83,21 +83,6 @@ public:
/// @brief Clears the persistent flag to delete all settings the next time QGroundControl is started.
void clearDeleteAllSettingsNextBoot(void);
/// @brief Returns the location of user visible saved file associated with QGroundControl
QString savedFilesLocation(void);
/// @brief Sets the location of user visible saved file associated with QGroundControl
void setSavedFilesLocation(QString& location);
/// @brief Location to save and load parameter files from.
QString savedParameterFilesLocation(void);
/// @brief Location to save and load mavlink log files from
QString mavlinkLogFilesLocation(void);
/// @brief Validates that the specified location will work for the saved files location.
bool validatePossibleSavedFilesLocation(QString& location);
/// @return true: Prompt to save log file when vehicle goes away
bool promptFlightDataSave(void);
......@@ -201,15 +186,10 @@ private:
static const char* _settingsVersionKey; ///< Settings key which hold settings version
static const char* _deleteAllSettingsKey; ///< If this settings key is set on boot, all settings will be deleted
static const char* _savedFilesLocationKey; ///< Settings key for user visible saved files location
static const char* _promptFlightDataSave; ///< Settings key for promptFlightDataSave
static const char* _promptFlightDataSaveNotArmed; ///< Settings key for promptFlightDataSaveNotArmed
static const char* _styleKey; ///< Settings key for UI style
static const char* _defaultSavedFileDirectoryName; ///< Default name for user visible save file directory
static const char* _savedFileMavlinkLogDirectoryName; ///< Name of mavlink log subdirectory
static const char* _savedFileParameterDirectoryName; ///< Name of parameter subdirectory
bool _runningUnitTests; ///< true: running unit tests, false: normal app
static const char* _darkStyleFile;
......
......@@ -96,13 +96,16 @@ void ParameterEditorController::clearRCToParam(void)
void ParameterEditorController::saveToFile(void)
{
#ifndef __mobile__
Q_ASSERT(_autopilot);
if (!_autopilot) {
qWarning() << "Internal error _autopilot==NULL";
return;
}
QString msgTitle("Save Parameters");
QString fileName = QGCFileDialog::getSaveFileName(NULL,
msgTitle,
qgcApp()->savedParameterFilesLocation(),
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation),
"Parameter Files (*.params)",
"params",
true);
......@@ -126,13 +129,16 @@ void ParameterEditorController::loadFromFile(void)
#ifndef __mobile__
QString errors;
Q_ASSERT(_autopilot);
if (!_autopilot) {
qWarning() << "Internal error _autopilot==NULL";
return;
}
QString msgTitle("Load Parameters");
QString fileName = QGCFileDialog::getOpenFileName(NULL,
msgTitle,
qgcApp()->savedParameterFilesLocation(),
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation),
"Parameter Files (*.params);;All Files (*)");
if (!fileName.isEmpty()) {
QFile file(fileName);
......
......@@ -104,7 +104,7 @@ void MavlinkLogTest::_bootLogDetectionSave_test(void)
// We should get a message box, followed by a getSaveFileName dialog.
setExpectedMessageBox(QMessageBox::Ok);
QDir logSaveDir(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
QDir logSaveDir(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
QString logSaveFile(logSaveDir.filePath(_saveLogFilename));
setExpectedFileDialog(getSaveFileName, QStringList(logSaveFile));
......@@ -144,7 +144,7 @@ void MavlinkLogTest::_connectLogWorker(bool arm)
QTest::qWait(1500); // Wait long enough for heartbeat to come through
// On Disconnect: We should get a getSaveFileName dialog.
logSaveDir.setPath(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
logSaveDir.setPath(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
QString logSaveFile(logSaveDir.filePath(_saveLogFilename));
setExpectedFileDialog(getSaveFileName, QStringList(logSaveFile));
}
......
......@@ -68,7 +68,7 @@ void QGCMAVLinkLogPlayer::_selectLogFileForPlayback(void)
QString logFilename = QGCFileDialog::getOpenFileName(
this,
tr("Load MAVLink Log File"),
qgcApp()->mavlinkLogFilesLocation(),
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation),
tr("MAVLink Log Files (*.mavlink);;All Files (*)"));
if (logFilename.isEmpty()) {
......
......@@ -38,7 +38,7 @@
#include "MainToolBarController.h"
#include "FlightMapSettings.h"
SettingsDialog::SettingsDialog(QWidget *parent, int showTab, Qt::WindowFlags flags)
SettingsDialog::SettingsDialog(QWidget *parent, Qt::WindowFlags flags)
: QDialog(parent, flags)
, _ui(new Ui::SettingsDialog)
{
......@@ -59,49 +59,10 @@ SettingsDialog::SettingsDialog(QWidget *parent, int showTab, Qt::WindowFlags fla
this->window()->setWindowTitle(tr("QGroundControl Settings"));
_ui->savedFilesLocation->setText(qgcApp()->savedFilesLocation());
// Connect signals
connect(_ui->browseSavedFilesLocation, &QPushButton::clicked, this, &SettingsDialog::_selectSavedFilesDirectory);
connect(_ui->buttonBox, &QDialogButtonBox::accepted, this, &SettingsDialog::_validateBeforeClose);
if (showTab == ShowMavlink) {
_ui->tabWidget->setCurrentWidget(pMavsettings);
}
_ui->tabWidget->setCurrentWidget(pMavsettings);
}
SettingsDialog::~SettingsDialog()
{
delete _ui;
}
/// @brief Validates the settings before closing
void SettingsDialog::_validateBeforeClose(void)
{
QGCApplication* app = qgcApp();
// Validate the saved file location
QString saveLocation = _ui->savedFilesLocation->text();
if (!app->validatePossibleSavedFilesLocation(saveLocation)) {
QGCMessageBox::warning(
tr("Invalid Save Location"),
tr("The location to save files is invalid, or cannot be written to. Please provide a valid directory."));
return;
}
// Locations is valid, save
app->setSavedFilesLocation(saveLocation);
// Close dialog
accept();
}
/// @brief Displays a directory picker dialog to allow the user to select a saved file location
void SettingsDialog::_selectSavedFilesDirectory(void)
{
QString newLocation = QGCFileDialog::getExistingDirectory(
this,
tr("Select the directory where you want to save files to."),
_ui->savedFilesLocation->text());
if (!newLocation.isEmpty()) {
_ui->savedFilesLocation->setText(newLocation);
}
}
......@@ -40,20 +40,9 @@ class SettingsDialog : public QDialog
Q_OBJECT
public:
enum {
ShowDefault,
ShowControllers,
ShowMavlink
};
SettingsDialog(QWidget *parent = 0, int showTab = ShowDefault, Qt::WindowFlags flags = Qt::Sheet);
SettingsDialog(QWidget *parent = 0, Qt::WindowFlags flags = Qt::Sheet);
~SettingsDialog();
private slots:
void _selectSavedFilesDirectory(void);
void _validateBeforeClose(void);
private:
Ui::SettingsDialog* _ui;
};
......
......@@ -21,91 +21,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QTabWidget" name="tabWidget">
<widget class="QWidget" name="general">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<attribute name="title">
<string>General</string>
</attribute>
<attribute name="toolTip">
<string>General Settings</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<widget class="QGroupBox" name="fileLocationsLayout">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="title">
<string>File Locations</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Specify the location you would like to save files:</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLineEdit" name="savedFilesLocation">
<property name="minimumSize">
<size>
<width>200</width>
<height>21</height>
</size>
</property>
<property name="maxLength">
<number>1024</number>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="browseSavedFilesLocation">
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QTabWidget" name="tabWidget"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
......
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