diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index a76b1bc1d4802f837ebbceec041fc9e3894d89e7..f7922cbd6845b7b370ce1933cb683da24af8fa21 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -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"); diff --git a/src/QGCApplication.h b/src/QGCApplication.h index ca4f98a21d7bee4f401a0d417f1348ee5a0b9dab..ff1649b47f4921e91e16bd04cc597f71551f6669 100644 --- a/src/QGCApplication.h +++ b/src/QGCApplication.h @@ -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; diff --git a/src/QmlControls/ParameterEditorController.cc b/src/QmlControls/ParameterEditorController.cc index 8c22847750bba6cbf5ccfdc73d83389aecda9de9..58824d49fac1f337dda62673e16b3721fbd76856 100644 --- a/src/QmlControls/ParameterEditorController.cc +++ b/src/QmlControls/ParameterEditorController.cc @@ -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); diff --git a/src/qgcunittest/MavlinkLogTest.cc b/src/qgcunittest/MavlinkLogTest.cc index 27890648ee33195f2171ed851fc3b1dc1fee6f84..3954a860577d5680888ef2edaa88fd0615d66e73 100644 --- a/src/qgcunittest/MavlinkLogTest.cc +++ b/src/qgcunittest/MavlinkLogTest.cc @@ -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)); } diff --git a/src/ui/QGCMAVLinkLogPlayer.cc b/src/ui/QGCMAVLinkLogPlayer.cc index 78332fcb59fdb781b8931be3423ec2a813c72f58..1befe1f317b8ed75f9bf6d3520df65e8d93a23b7 100644 --- a/src/ui/QGCMAVLinkLogPlayer.cc +++ b/src/ui/QGCMAVLinkLogPlayer.cc @@ -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()) { diff --git a/src/ui/SettingsDialog.cc b/src/ui/SettingsDialog.cc index e4216cb423e2ddacfbf589daa1b4815b3eb11bf9..e72ed0164e5c10564ee5feac08c135e81b53321f 100644 --- a/src/ui/SettingsDialog.cc +++ b/src/ui/SettingsDialog.cc @@ -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); - } -} diff --git a/src/ui/SettingsDialog.h b/src/ui/SettingsDialog.h index 7e8432747e7f03b8ec754a0fb450b83d986b8762..b4c5b4a318a49db6eb8bc364f23f34ff5b172b23 100644 --- a/src/ui/SettingsDialog.h +++ b/src/ui/SettingsDialog.h @@ -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; }; diff --git a/src/ui/SettingsDialog.ui b/src/ui/SettingsDialog.ui index d304d06bee1cfb4494e1c101570aa6b7650cf49a..a2169229b031208d499c506a0ebc8b272963d04b 100644 --- a/src/ui/SettingsDialog.ui +++ b/src/ui/SettingsDialog.ui @@ -21,91 +21,7 @@ - - - - - 0 - 0 - - - - General - - - General Settings - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - File Locations - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - Specify the location you would like to save files: - - - true - - - - - - - - - - 200 - 21 - - - - 1024 - - - - - - - Browse - - - - - - - - - - - +