2012-08-01 00:21:15 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file flashpage.cpp
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2012.
|
|
|
|
* @addtogroup
|
|
|
|
* @{
|
|
|
|
* @addtogroup FlashPage
|
|
|
|
* @{
|
|
|
|
* @brief
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program 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.
|
|
|
|
*
|
|
|
|
* This program 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2012-08-21 01:07:38 +02:00
|
|
|
#include <QMessageBox>
|
2012-08-01 00:21:15 +02:00
|
|
|
#include "flashpage.h"
|
|
|
|
#include "ui_flashpage.h"
|
|
|
|
#include "setupwizard.h"
|
2012-08-19 23:25:50 +02:00
|
|
|
#include "vehicleconfigurationhelper.h"
|
2012-08-01 00:21:15 +02:00
|
|
|
|
|
|
|
FlashPage::FlashPage(SetupWizard *wizard, QWidget *parent) :
|
|
|
|
AbstractWizardPage(wizard, parent),
|
2012-08-19 23:25:50 +02:00
|
|
|
ui(new Ui::FlashPage), m_successfulWrite(false)
|
2012-08-01 00:21:15 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2012-08-19 23:25:50 +02:00
|
|
|
connect(ui->saveButton, SIGNAL(clicked()), this, SLOT(writeToController()));
|
2012-08-01 00:21:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FlashPage::~FlashPage()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FlashPage::validatePage()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2012-08-19 23:25:50 +02:00
|
|
|
|
|
|
|
bool FlashPage::isComplete() const
|
|
|
|
{
|
|
|
|
return m_successfulWrite;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FlashPage::writeToController()
|
|
|
|
{
|
2012-08-21 01:07:38 +02:00
|
|
|
if(!getWizard()->getConnectionManager()->isConnected()) {
|
|
|
|
QMessageBox msgBox;
|
|
|
|
msgBox.setText(tr("An OpenPilot controller must be connected to your computer to save the "
|
|
|
|
"configuration.\nPlease connect your OpenPilot controller to your computer and try again."));
|
|
|
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
|
|
|
msgBox.setDefaultButton(QMessageBox::Ok);
|
|
|
|
msgBox.exec();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-09-10 22:55:02 +02:00
|
|
|
enableButtons(false);
|
2012-08-19 23:25:50 +02:00
|
|
|
VehicleConfigurationHelper helper(getWizard());
|
|
|
|
connect(&helper, SIGNAL(saveProgress(int, int, QString)),this, SLOT(saveProgress(int, int, QString)));
|
2012-09-10 22:55:02 +02:00
|
|
|
|
2012-08-19 23:25:50 +02:00
|
|
|
m_successfulWrite = helper.setupVehicle();
|
2012-09-10 22:55:02 +02:00
|
|
|
|
2012-08-19 23:25:50 +02:00
|
|
|
disconnect(&helper, SIGNAL(saveProgress(int, int, QString)),this, SLOT(saveProgress(int, int, QString)));
|
|
|
|
ui->saveProgressLabel->setText(QString("<font color='%1'>%2</font>").arg(m_successfulWrite ? "green" : "red", ui->saveProgressLabel->text()));
|
2012-09-10 22:55:02 +02:00
|
|
|
enableButtons(true);
|
|
|
|
|
2012-08-21 01:07:38 +02:00
|
|
|
emit completeChanged();
|
2012-08-19 23:25:50 +02:00
|
|
|
}
|
|
|
|
|
2012-09-10 22:55:02 +02:00
|
|
|
void FlashPage::enableButtons(bool enable)
|
|
|
|
{
|
|
|
|
ui->saveButton->setEnabled(enable);
|
|
|
|
getWizard()->button(QWizard::NextButton)->setEnabled(enable);
|
|
|
|
getWizard()->button(QWizard::CancelButton)->setEnabled(enable);
|
|
|
|
getWizard()->button(QWizard::BackButton)->setEnabled(enable);
|
|
|
|
QApplication::processEvents();
|
|
|
|
}
|
|
|
|
|
2012-08-19 23:25:50 +02:00
|
|
|
void FlashPage::saveProgress(int total, int current, QString description)
|
|
|
|
{
|
2012-09-23 21:58:37 +02:00
|
|
|
qDebug() << "Progress " << current << "(" << total << ")";
|
2012-08-19 23:25:50 +02:00
|
|
|
if(ui->saveProgressBar->maximum() != total) {
|
|
|
|
ui->saveProgressBar->setMaximum(total);
|
|
|
|
}
|
|
|
|
if(ui->saveProgressBar->value() != current) {
|
|
|
|
ui->saveProgressBar->setValue(current);
|
|
|
|
}
|
|
|
|
if(ui->saveProgressLabel->text() != description) {
|
|
|
|
ui->saveProgressLabel->setText(description);
|
|
|
|
}
|
|
|
|
}
|