LP-106 Setup Wizard refresh : Add dual servo setup (dual aileron or
[librepilot.git] / ground / gcs / src / plugins / setupwizard / pages / savepage.cpp
blob8ab43e761a967d47d25b69825d8274a5c096195d
1 /**
2 ******************************************************************************
4 * @file savepage.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
6 * @addtogroup
7 * @{
8 * @addtogroup SavePage
9 * @{
10 * @brief
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <QMessageBox>
29 #include "savepage.h"
30 #include "ui_savepage.h"
31 #include "setupwizard.h"
32 #include "vehicleconfigurationhelper.h"
34 SavePage::SavePage(SetupWizard *wizard, QWidget *parent) :
35 AbstractWizardPage(wizard, parent),
36 ui(new Ui::SavePage), m_successfulWrite(false)
38 ui->setupUi(this);
39 connect(ui->saveButton, SIGNAL(clicked()), this, SLOT(writeToController()));
42 SavePage::~SavePage()
44 delete ui;
47 bool SavePage::validatePage()
49 return true;
52 bool SavePage::isComplete() const
54 return m_successfulWrite;
57 void SavePage::writeToController()
59 if (!getWizard()->getConnectionManager()->isConnected()) {
60 QMessageBox msgBox;
61 msgBox.setText(tr("A compatible flight controller must be connected to your computer to save the "
62 "configuration.\nPlease connect your flight controller to your computer and try again."));
63 msgBox.setStandardButtons(QMessageBox::Ok);
64 msgBox.setDefaultButton(QMessageBox::Ok);
65 msgBox.exec();
66 return;
69 enableButtons(false);
70 VehicleConfigurationHelper helper(getWizard());
71 connect(&helper, SIGNAL(saveProgress(int, int, QString)), this, SLOT(saveProgress(int, int, QString)));
73 m_successfulWrite = helper.setupVehicle();
75 disconnect(&helper, SIGNAL(saveProgress(int, int, QString)), this, SLOT(saveProgress(int, int, QString)));
76 ui->saveProgressLabel->setText(QString("<font color='%1'>%2</font>").arg(m_successfulWrite ? "green" : "red", ui->saveProgressLabel->text()));
77 if (m_successfulWrite) {
78 getWizard()->reboot();
80 enableButtons(true);
82 emit completeChanged();
84 if (m_successfulWrite) {
85 getWizard()->next();
89 void SavePage::enableButtons(bool enable)
91 ui->saveButton->setEnabled(enable);
92 getWizard()->button(QWizard::NextButton)->setEnabled(enable);
93 getWizard()->button(QWizard::CancelButton)->setEnabled(enable);
94 getWizard()->button(QWizard::BackButton)->setEnabled(enable);
95 getWizard()->button(QWizard::CustomButton1)->setEnabled(enable);
96 QApplication::processEvents();
99 void SavePage::saveProgress(int total, int current, QString description)
101 qDebug() << "Progress " << current << "(" << total << ")";
102 if (ui->saveProgressBar->maximum() != total) {
103 ui->saveProgressBar->setMaximum(total);
105 if (ui->saveProgressBar->value() != current) {
106 ui->saveProgressBar->setValue(current);
108 if (ui->saveProgressLabel->text() != description) {
109 ui->saveProgressLabel->setText(description);