SettingsDialog.cc 3.55 KB
Newer Older
1
/*=====================================================================
2

3
 QGroundControl Open Source Ground Control Station
4

5
 (c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
6

7
 This file is part of the QGROUNDCONTROL project
8

9 10 11 12
 QGROUNDCONTROL is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
13

14 15 16 17
 QGROUNDCONTROL is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
18

19 20
 You should have received a copy of the GNU General Public License
 along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
21

22 23
 ======================================================================*/

24
#include <QSettings>
25
#include <QDesktopWidget>
26

Don Gagne's avatar
Don Gagne committed
27
#include "SettingsDialog.h"
28
#include "MainWindow.h"
Don Gagne's avatar
Don Gagne committed
29
#include "ui_SettingsDialog.h"
lm's avatar
lm committed
30

31 32 33
#include "LinkManager.h"
#include "MAVLinkProtocol.h"
#include "MAVLinkSettingsWidget.h"
34
#include "GAudioOutput.h"
Don Gagne's avatar
Don Gagne committed
35
#include "QGCApplication.h"
Don Gagne's avatar
Don Gagne committed
36
#include "QGCFileDialog.h"
Don Gagne's avatar
Don Gagne committed
37
#include "QGCMessageBox.h"
38
#include "MainToolBarController.h"
39
#include "FlightMapSettings.h"
40

41
SettingsDialog::SettingsDialog(QWidget *parent, int showTab, Qt::WindowFlags flags)
42 43
    : QDialog(parent, flags)
    , _ui(new Ui::SettingsDialog)
lm's avatar
lm committed
44
{
45
    _ui->setupUi(this);
46

47
    // Center the window on the screen.
48 49 50
    QDesktopWidget *desktop = QApplication::desktop();
    int screen = desktop->screenNumber(parent);

51
    QRect position = frameGeometry();
52
    position.moveCenter(QApplication::desktop()->availableGeometry(screen).center());
53
    move(position.topLeft());
54

55
    MAVLinkSettingsWidget* pMavsettings  = new MAVLinkSettingsWidget(qgcApp()->toolbox()->mavlinkProtocol(), this);
56 57 58 59

    // Add the MAVLink settings pane
    _ui->tabWidget->addTab(pMavsettings,  "MAVLink");

60
    this->window()->setWindowTitle(tr("QGroundControl Settings"));
61

62
    _ui->savedFilesLocation->setText(qgcApp()->savedFilesLocation());
63

64 65 66
    // Connect signals
    connect(_ui->browseSavedFilesLocation, &QPushButton::clicked, this, &SettingsDialog::_selectSavedFilesDirectory);
    connect(_ui->buttonBox, &QDialogButtonBox::accepted, this, &SettingsDialog::_validateBeforeClose);
67 68 69

    if (showTab == ShowMavlink) {
        _ui->tabWidget->setCurrentWidget(pMavsettings);
70
    }
lm's avatar
lm committed
71 72
}

73
SettingsDialog::~SettingsDialog()
lm's avatar
lm committed
74
{
75
    delete _ui;
lm's avatar
lm committed
76
}
77

78 79 80 81 82 83 84
/// @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)) {
85 86 87
        QGCMessageBox::warning(
            tr("Invalid Save Location"),
            tr("The location to save files is invalid, or cannot be written to. Please provide a valid directory."));
88 89 90 91
        return;
    }
    // Locations is valid, save
    app->setSavedFilesLocation(saveLocation);
92

93 94 95 96 97 98 99
    // Close dialog
    accept();
}

/// @brief Displays a directory picker dialog to allow the user to select a saved file location
void SettingsDialog::_selectSavedFilesDirectory(void)
{
100 101 102 103
    QString newLocation = QGCFileDialog::getExistingDirectory(
        this,
        tr("Select the directory where you want to save files to."),
        _ui->savedFilesLocation->text());
104 105
    if (!newLocation.isEmpty()) {
        _ui->savedFilesLocation->setText(newLocation);
106
    }
107
}