1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-26 17:55:19 +03:00

Version automatically appended to the firmware name. Is now calculated

BEFORE the user chooses a filename!
This commit is contained in:
bsongis 2014-05-28 15:11:57 +02:00
parent 9919ad026b
commit 483e36e646
5 changed files with 111 additions and 122 deletions

View file

@ -87,6 +87,7 @@ void downloadDialog::fileError()
reject(); reject();
} }
#if 0
void downloadDialog::closeEvent( QCloseEvent * event) void downloadDialog::closeEvent( QCloseEvent * event)
{ {
// Delay closing 2 seconds to avoid unpleasant flashing download dialogs // Delay closing 2 seconds to avoid unpleasant flashing download dialogs
@ -96,4 +97,4 @@ void downloadDialog::closeEvent( QCloseEvent * event)
event->accept(); event->accept();
} }
#endif

View file

@ -27,7 +27,9 @@ private slots:
void updateDataReadProgress(qint64 bytesRead, qint64 totalBytes); void updateDataReadProgress(qint64 bytesRead, qint64 totalBytes);
private: private:
#if 0
void closeEvent( QCloseEvent * event); void closeEvent( QCloseEvent * event);
#endif
Ui::downloadDialog *ui; Ui::downloadDialog *ui;
QNetworkAccessManager qnam; QNetworkAccessManager qnam;

View file

@ -40,7 +40,7 @@ void FirmwarePreferencesDialog::on_checkFWUpdates_clicked()
void FirmwarePreferencesDialog::on_fw_dnld_clicked() void FirmwarePreferencesDialog::on_fw_dnld_clicked()
{ {
MainWindow * mw = (MainWindow *)this->parent(); MainWindow * mw = (MainWindow *)this->parent();
mw->downloadLatestFW(current_firmware_variant); mw->dowloadLastFirmwareUpdate();
initSettings(); initSettings();
} }

View file

@ -138,15 +138,15 @@ MainWindow::MainWindow():
printfilename=strl[count]; printfilename=strl[count];
} }
} }
if(strl.count()>1) str = strl[1]; if (strl.count()>1) str = strl[1];
if(!str.isEmpty()) { if (!str.isEmpty()) {
int fileType = getFileType(str); int fileType = getFileType(str);
if(fileType==FILE_TYPE_HEX) { if (fileType==FILE_TYPE_HEX) {
writeFlash(str); writeFlash(str);
} }
if(fileType==FILE_TYPE_EEPE || fileType==FILE_TYPE_EEPM || fileType==FILE_TYPE_BIN) { if (fileType==FILE_TYPE_EEPE || fileType==FILE_TYPE_EEPM || fileType==FILE_TYPE_BIN) {
MdiChild *child = createMdiChild(); MdiChild *child = createMdiChild();
if (child->loadFile(str)) { if (child->loadFile(str)) {
if (!(printing && (model >=0 && model<GetEepromInterface()->getMaxModels()) && !printfilename.isEmpty() )) { if (!(printing && (model >=0 && model<GetEepromInterface()->getMaxModels()) && !printfilename.isEmpty() )) {
@ -207,11 +207,17 @@ void MainWindow::checkForFirmwareUpdate()
checkForUpdates(); checkForUpdates();
} }
void MainWindow::dowloadLastFirmwareUpdate()
{
checkForUpdatesState = CHECK_FIRMWARE | AUTOMATIC_DOWNLOAD | SHOW_DIALOG_WAIT;
checkForUpdates();
}
void MainWindow::checkForUpdates() void MainWindow::checkForUpdates()
{ {
if (checkForUpdatesState & SHOW_DIALOG_WAIT) { if (checkForUpdatesState & SHOW_DIALOG_WAIT) {
checkForUpdatesState -= SHOW_DIALOG_WAIT; checkForUpdatesState -= SHOW_DIALOG_WAIT;
downloadDialog_forWait = new downloadDialog(this, tr("Checking for updates")); downloadDialog_forWait = new downloadDialog(NULL, tr("Checking for updates"));
downloadDialog_forWait->show(); downloadDialog_forWait->show();
} }
@ -320,18 +326,6 @@ void MainWindow::updateDownloaded()
} }
} }
void MainWindow::downloadLatestFW(FirmwareVariant & firmware)
{
QString url, ext;
url = firmware.getFirmwareUrl();
ext = url.mid(url.lastIndexOf("."));
QString filename = QFileDialog::getSaveFileName(this, tr("Save As"), g.flashDir() + "/" + firmware.id + ext);
if (!filename.isEmpty()) {
needRename = true;
startFirmwareDownload(url, filename);
}
}
void MainWindow::firmwareDownloadAccepted() void MainWindow::firmwareDownloadAccepted()
{ {
QString errormsg; QString errormsg;
@ -370,29 +364,11 @@ void MainWindow::firmwareDownloadAccepted()
return; return;
} }
file.close(); file.close();
FlashInterface flash(g.profile[g.id()].fwName()); g.fwRev.set(current_firmware_variant.id, version2index(firmwareVersionString));
int stamp = flash.getVersionId(); if (g.profile[g.id()].burnFirmware()) {
if (stamp > 0) { int ret = QMessageBox::question(this, "Companion", tr("Do you want to write the firmware to the radio now ?"), QMessageBox::Yes | QMessageBox::No);
#if 0 if (ret == QMessageBox::Yes) {
if (g.profile[g.id()].renameFwFiles() && needRename) { writeFlash(g.profile[g.id()].fwName());
QFileInfo fi(g.profile[g.id()].fwName());
QString path=fi.path()+QDir::separator ();
path.append(fi.completeBaseName());
path.append(rev.mid(pos));
path.append(".");
path.append(fi.suffix());
QDir qd;
qd.remove(path);
qd.rename(g.profile[g.id()].fwName(),path);
g.profile[g.id()].fwName(path);
}
#endif
g.fwRev.set(current_firmware_variant.id, stamp);
if (g.profile[g.id()].burnFirmware()) {
int ret = QMessageBox::question(this, "Companion", tr("Do you want to write the firmware to the radio now ?"), QMessageBox::Yes | QMessageBox::No);
if (ret == QMessageBox::Yes) {
writeFlash(g.profile[g.id()].fwName());
}
} }
} }
} }
@ -411,85 +387,91 @@ void MainWindow::checkForFirmwareUpdateFinished(QNetworkReply * reply)
QString versionString; QString versionString;
if (versionIndex > 0 && dateIndex > 0) { if (versionIndex > 0 && dateIndex > 0) {
versionString = qba.mid(versionIndex+10, qba.indexOf("\"", versionIndex+10)-versionIndex-10); firmwareVersionString = qba.mid(versionIndex+10, qba.indexOf("\"", versionIndex+10)-versionIndex-10);
QString dateString = qba.mid(dateIndex+10, 10); QString dateString = qba.mid(dateIndex+10, 10);
version = version2index(versionString); version = version2index(firmwareVersionString);
versionString = QString("%1 (%2)").arg(versionString).arg(dateString); versionString = QString("%1 (%2)").arg(firmwareVersionString).arg(dateString);
} }
if (version > 0) { if (version > 0) {
int currentVersion = g.fwRev.get(current_firmware_variant.id); if (checkForUpdatesState & AUTOMATIC_DOWNLOAD) {
QString currentVersionString = index2version(currentVersion); checkForUpdatesState -= AUTOMATIC_DOWNLOAD;
download = true;
QMessageBox msgBox;
QSpacerItem * horizontalSpacer = new QSpacerItem(500, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
QGridLayout * layout = (QGridLayout*)msgBox.layout();
layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
if (currentVersion == 0) {
QString rn = GetFirmware(current_firmware_variant.id)->getReleaseNotesUrl();
QAbstractButton *rnButton = NULL;
msgBox.setWindowTitle("Companion");
msgBox.setInformativeText(tr("Firmware %1 does not seem to have ever been downloaded.\nRelease %2 is available.\nDo you want to download it now?").arg(current_firmware_variant.id).arg(versionString));
QAbstractButton *YesButton = msgBox.addButton(trUtf8("Yes"), QMessageBox::YesRole);
msgBox.addButton(trUtf8("No"), QMessageBox::NoRole);
if (!rn.isEmpty()) {
rnButton = msgBox.addButton(trUtf8("Release Notes"), QMessageBox::ActionRole);
}
msgBox.setIcon(QMessageBox::Question);
msgBox.resize(0, 0);
msgBox.exec();
if (msgBox.clickedButton() == rnButton) {
contributorsDialog *cd = new contributorsDialog(this,2,rn);
cd->exec();
int ret2 = QMessageBox::question(this, "Companion", tr("Do you want to download release %1 %2 now ?").arg(versionString), QMessageBox::Yes | QMessageBox::No);
if (ret2 == QMessageBox::Yes)
download = true;
else
ignore = true;
}
else if (msgBox.clickedButton() == YesButton ) {
download = true;
}
else {
ignore = true;
}
} }
else if (version > currentVersion) { else {
QString rn = GetFirmware(current_firmware_variant.id)->getReleaseNotesUrl(); int currentVersion = g.fwRev.get(current_firmware_variant.id);
QAbstractButton *rnButton; QString currentVersionString = index2version(currentVersion);
msgBox.setText("Companion");
msgBox.setInformativeText(tr("A new version of %1 firmware is available:\n - current is %2\n - newer is %3\n\nDo you want to download it now ?").arg(current_firmware_variant.id).arg(currentVersionString).arg(versionString)); QMessageBox msgBox;
QAbstractButton *YesButton = msgBox.addButton(trUtf8("Yes"), QMessageBox::YesRole); QSpacerItem * horizontalSpacer = new QSpacerItem(500, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
msgBox.addButton(trUtf8("No"), QMessageBox::NoRole); QGridLayout * layout = (QGridLayout*)msgBox.layout();
if (!rn.isEmpty()) { layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount());
rnButton = msgBox.addButton(trUtf8("Release Notes"), QMessageBox::ActionRole);
} if (currentVersion == 0) {
msgBox.setIcon(QMessageBox::Question); QString rn = GetFirmware(current_firmware_variant.id)->getReleaseNotesUrl();
msgBox.resize(0,0); QAbstractButton *rnButton = NULL;
msgBox.exec(); msgBox.setWindowTitle("Companion");
if( msgBox.clickedButton() == rnButton ) { msgBox.setInformativeText(tr("Firmware %1 does not seem to have ever been downloaded.\nRelease %2 is available.\nDo you want to download it now?").arg(current_firmware_variant.id).arg(versionString));
contributorsDialog *cd = new contributorsDialog(this, 2, rn); QAbstractButton *YesButton = msgBox.addButton(trUtf8("Yes"), QMessageBox::YesRole);
cd->exec(); msgBox.addButton(trUtf8("No"), QMessageBox::NoRole);
int ret2 = QMessageBox::question(this, "Companion", tr("Do you want to download release %1 now ?").arg(versionString), if (!rn.isEmpty()) {
QMessageBox::Yes | QMessageBox::No); rnButton = msgBox.addButton(trUtf8("Release Notes"), QMessageBox::ActionRole);
if (ret2 == QMessageBox::Yes) { }
msgBox.setIcon(QMessageBox::Question);
msgBox.resize(0, 0);
msgBox.exec();
if (msgBox.clickedButton() == rnButton) {
contributorsDialog *cd = new contributorsDialog(this,2,rn);
cd->exec();
int ret2 = QMessageBox::question(this, "Companion", tr("Do you want to download release %1 %2 now ?").arg(versionString), QMessageBox::Yes | QMessageBox::No);
if (ret2 == QMessageBox::Yes)
download = true;
else
ignore = true;
}
else if (msgBox.clickedButton() == YesButton ) {
download = true; download = true;
} }
else { else {
ignore = true; ignore = true;
} }
} }
else if (msgBox.clickedButton() == YesButton ) { else if (version > currentVersion) {
download = true; QString rn = GetFirmware(current_firmware_variant.id)->getReleaseNotesUrl();
QAbstractButton *rnButton;
msgBox.setText("Companion");
msgBox.setInformativeText(tr("A new version of %1 firmware is available:\n - current is %2\n - newer is %3\n\nDo you want to download it now ?").arg(current_firmware_variant.id).arg(currentVersionString).arg(versionString));
QAbstractButton *YesButton = msgBox.addButton(trUtf8("Yes"), QMessageBox::YesRole);
msgBox.addButton(trUtf8("No"), QMessageBox::NoRole);
if (!rn.isEmpty()) {
rnButton = msgBox.addButton(trUtf8("Release Notes"), QMessageBox::ActionRole);
}
msgBox.setIcon(QMessageBox::Question);
msgBox.resize(0,0);
msgBox.exec();
if( msgBox.clickedButton() == rnButton ) {
contributorsDialog *cd = new contributorsDialog(this, 2, rn);
cd->exec();
int ret2 = QMessageBox::question(this, "Companion", tr("Do you want to download release %1 now ?").arg(versionString),
QMessageBox::Yes | QMessageBox::No);
if (ret2 == QMessageBox::Yes) {
download = true;
}
else {
ignore = true;
}
}
else if (msgBox.clickedButton() == YesButton ) {
download = true;
}
else {
ignore = true;
}
} }
else { else {
ignore = true; if (downloadDialog_forWait && checkForUpdatesState==0) {
} QMessageBox::information(this, "Companion", tr("No updates available at this time."));
} }
else {
if (downloadDialog_forWait && checkForUpdatesState==0) {
QMessageBox::information(this, "Companion", tr("No updates available at this time."));
} }
} }
@ -500,11 +482,7 @@ void MainWindow::checkForFirmwareUpdateFinished(QNetworkReply * reply)
} }
} }
else if (download == true) { else if (download == true) {
QString url = GetFirmwareVariant(current_firmware_variant.id).getFirmwareUrl(); startFirmwareDownload();
QString ext = url.mid(url.lastIndexOf("."));
needRename = false;
QString filename = QFileDialog::getSaveFileName(this, tr("Save As"), g.flashDir() + "/" + current_firmware_variant.id + ext);
startFirmwareDownload(url, filename);
} }
} }
else { else {
@ -515,8 +493,17 @@ void MainWindow::checkForFirmwareUpdateFinished(QNetworkReply * reply)
checkForUpdates(); checkForUpdates();
} }
void MainWindow::startFirmwareDownload(QString url, QString filename) void MainWindow::startFirmwareDownload()
{ {
QString url = current_firmware_variant.getFirmwareUrl();
QString ext = url.mid(url.lastIndexOf("."));
QString defaultFilename = g.flashDir() + "/" + current_firmware_variant.id;
if (g.profile[g.id()].renameFwFiles()) {
defaultFilename += "-" + firmwareVersionString;
}
defaultFilename += ext;
QString filename = QFileDialog::getSaveFileName(this, tr("Save As"), defaultFilename);
if (!filename.isEmpty()) { if (!filename.isEmpty()) {
g.profile[g.id()].fwName(filename); g.profile[g.id()].fwName(filename);
g.flashDir(QFileInfo(filename).dir().absolutePath()); g.flashDir(QFileInfo(filename).dir().absolutePath());

View file

@ -61,9 +61,10 @@ class QMdiSubWindow;
class QSignalMapper; class QSignalMapper;
QT_END_NAMESPACE QT_END_NAMESPACE
#define CHECK_COMPANION 1 #define CHECK_COMPANION 1
#define CHECK_FIRMWARE 2 #define CHECK_FIRMWARE 2
#define SHOW_DIALOG_WAIT 4 #define SHOW_DIALOG_WAIT 4
#define AUTOMATIC_DOWNLOAD 8
class MainWindow : public QMainWindow class MainWindow : public QMainWindow
{ {
@ -76,14 +77,12 @@ class MainWindow : public QMainWindow
MainWindow(); MainWindow();
protected: protected:
void startFirmwareDownload(QString url, QString filename); void dowloadLastFirmwareUpdate();
void startFirmwareDownload();
void closeEvent(QCloseEvent *event); void closeEvent(QCloseEvent *event);
void dragEnterEvent(QDragEnterEvent *event); void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event); void dropEvent(QDropEvent *event);
public slots:
void downloadLatestFW(FirmwareVariant & firmware);
private slots: private slots:
void openDocURL(); void openDocURL();
@ -209,8 +208,8 @@ class MainWindow : public QMainWindow
QString installer_fileName; QString installer_fileName;
downloadDialog * downloadDialog_forWait; downloadDialog * downloadDialog_forWait;
bool needRename;
unsigned int checkForUpdatesState; unsigned int checkForUpdatesState;
QString firmwareVersionString;
QNetworkAccessManager *networkManager; QNetworkAccessManager *networkManager;