2 ******************************************************************************
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
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
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>
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)
39 connect(ui
->saveButton
, SIGNAL(clicked()), this, SLOT(writeToController()));
47 bool SavePage::validatePage()
52 bool SavePage::isComplete() const
54 return m_successfulWrite
;
57 void SavePage::writeToController()
59 if (!getWizard()->getConnectionManager()->isConnected()) {
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
);
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();
82 emit
completeChanged();
84 if (m_successfulWrite
) {
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
);