chore(cpn): refactor firmware flashing to use edgetx rs_dfu (#6521)
Co-authored-by: raphaelcoeffic <1050031+raphaelcoeffic@users.noreply.github.com>
This commit is contained in:
co-authored by
raphaelcoeffic
parent
23830197b3
commit
dbce54dec6
@@ -0,0 +1,42 @@
|
||||
|
||||
project(flash)
|
||||
|
||||
set(${PROJECT_NAME}_NAMES
|
||||
customizesplashdialog
|
||||
flashfirmwaredialog
|
||||
process_copy
|
||||
process_sync
|
||||
radiointerface
|
||||
splashlibrarydialog
|
||||
)
|
||||
|
||||
AddHeadersSources()
|
||||
|
||||
# these have no cpp
|
||||
set(${PROJECT_NAME}_HDRS
|
||||
${${PROJECT_NAME}_HDRS}
|
||||
splashlabel.h
|
||||
)
|
||||
|
||||
qt_wrap_cpp(${PROJECT_NAME}_SRCS
|
||||
)
|
||||
|
||||
add_library(${PROJECT_NAME}
|
||||
${${PROJECT_NAME}_HDRS}
|
||||
${${PROJECT_NAME}_SRCS}
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
${CPN_COMMON_LIB}
|
||||
${RS_DFU_LIBRARIES}
|
||||
)
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
"${CMAKE_SOURCE_DIR}"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}"
|
||||
PUBLIC
|
||||
"${CMAKE_CURRENT_LIST_DIR}"
|
||||
"${RS_DFU_INCLUDE_DIRS}"
|
||||
)
|
||||
@@ -0,0 +1,288 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "customizesplashdialog.h"
|
||||
#include "ui_customizesplashdialog.h"
|
||||
#include "flashfirmwaredialog.h"
|
||||
#include "appdata.h"
|
||||
#include "helpers.h"
|
||||
#include "firmwareinterface.h"
|
||||
#include "splashlibrarydialog.h"
|
||||
|
||||
//*** Side Class ***
|
||||
|
||||
Side::Side(QDialog* parent):
|
||||
parent(parent)
|
||||
{
|
||||
imageLabel = 0;
|
||||
fileNameEdit = 0;
|
||||
saveButton = 0;
|
||||
invertButton = 0;
|
||||
libraryButton = 0;
|
||||
loadFwButton=0;
|
||||
loadPictButton = 0;
|
||||
loadProfileButton = 0;
|
||||
saveToFileName = new QString("");
|
||||
source = new Source(UNDEFINED);
|
||||
format = new LCDFormat(LCDTARANIS);
|
||||
}
|
||||
|
||||
void Side::markSourceButton()
|
||||
{
|
||||
loadFwButton->setChecked(*source == FW ? true : false );
|
||||
loadPictButton->setChecked(*source == PICT ? true : false );
|
||||
loadProfileButton->setChecked(*source == PROFILE ? true : false );
|
||||
}
|
||||
|
||||
void Side::copyImage( Side side )
|
||||
{
|
||||
if ((*source!=UNDEFINED) && (*side.source!=UNDEFINED))
|
||||
imageLabel->setPixmap(side.imageLabel->pixmap(Qt::ReturnByValue));
|
||||
}
|
||||
|
||||
bool Side::displayImage(QString fileName, Source pictSource)
|
||||
{
|
||||
QImage image;
|
||||
|
||||
if (fileName.isEmpty())
|
||||
return false;
|
||||
|
||||
// Determine which picture format to use
|
||||
if (pictSource == FW) {
|
||||
FirmwareInterface firmware(fileName, parent);
|
||||
if (!firmware.hasSplash())
|
||||
return false;
|
||||
else
|
||||
image = firmware.getSplash();
|
||||
*format = (firmware.getSplashWidth()==WIDTH_TARANIS ? LCDTARANIS : LCD9X);
|
||||
}
|
||||
else {
|
||||
image.load(fileName);
|
||||
if (pictSource== PICT)
|
||||
*format = image.width()>WIDTH_9X ? LCDTARANIS : LCD9X;
|
||||
else if (pictSource == PROFILE)
|
||||
*format = (g.profile[g.id()].fwType().contains("x9")) ? LCDTARANIS : LCD9X;
|
||||
}
|
||||
|
||||
if (image.isNull()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Load image
|
||||
QPixmap pixmap = makePixMap(image);
|
||||
imageLabel->setPixmap(pixmap);
|
||||
imageLabel->setFixedSize(pixmap.width()*2, pixmap.height()*2);
|
||||
|
||||
switch (pictSource) {
|
||||
case FW:
|
||||
fileNameEdit->setText(CustomizeSplashDialog::tr("FW: %1").arg(fileName));
|
||||
*saveToFileName = fileName;
|
||||
*source = FW;
|
||||
break;
|
||||
case PICT:
|
||||
fileNameEdit->setText(CustomizeSplashDialog::tr("Pict: %1").arg(fileName));
|
||||
*saveToFileName = fileName;
|
||||
*source = PICT;
|
||||
break;
|
||||
case PROFILE:
|
||||
fileNameEdit->setText(CustomizeSplashDialog::tr("Profile image"));
|
||||
*saveToFileName = fileName;
|
||||
*source = PROFILE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
saveButton->setEnabled(true);
|
||||
libraryButton->setEnabled(true);
|
||||
invertButton->setEnabled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Side::refreshImage()
|
||||
{
|
||||
return displayImage( *saveToFileName, *source );
|
||||
}
|
||||
|
||||
bool Side::saveImage()
|
||||
{
|
||||
if (*source == FW )
|
||||
{
|
||||
FirmwareInterface firmware(*saveToFileName, parent);
|
||||
if (!firmware.hasSplash()) {
|
||||
return false;
|
||||
}
|
||||
QImage image = imageLabel->pixmap(Qt::ReturnByValue).toImage().scaled(firmware.getSplashWidth(), firmware.getSplashHeight());
|
||||
if (firmware.setSplash(image) && (firmware.save(*saveToFileName) > 0)) {
|
||||
g.flashDir( QFileInfo(*saveToFileName).dir().absolutePath() );
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (*source == PICT) {
|
||||
QImage image = imageLabel->pixmap(Qt::ReturnByValue).toImage().scaled(imageLabel->width()/2, imageLabel->height()/2).convertToFormat(QImage::Format_Indexed8);
|
||||
if (image.save(*saveToFileName)) {
|
||||
g.imagesDir( QFileInfo(*saveToFileName).dir().absolutePath() );
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (*source == PROFILE) {
|
||||
QImage image = imageLabel->pixmap(Qt::ReturnByValue).toImage().scaled(imageLabel->width()/2, imageLabel->height()/2).convertToFormat(QImage::Format_Indexed8);
|
||||
if (!image.save(*saveToFileName)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
CustomizeSplashDialog::CustomizeSplashDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
left(this),
|
||||
right(this),
|
||||
ui(new Ui::CustomizeSplashDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setWindowIcon(CompanionIcon("paintbrush.png"));
|
||||
ui->leftLibraryButton->setIcon(CompanionIcon("library.png"));
|
||||
ui->rightLibraryButton->setIcon(CompanionIcon("library.png"));
|
||||
|
||||
left.imageLabel = ui->leftImageLabel;
|
||||
right.imageLabel = ui->rightImageLabel;
|
||||
left.fileNameEdit = ui->leftFileNameEdit;
|
||||
right.fileNameEdit = ui->rightFileNameEdit;
|
||||
left.saveButton = ui->leftSaveButton;
|
||||
right.saveButton = ui->rightSaveButton;
|
||||
left.libraryButton = ui->leftLibraryButton;
|
||||
right.libraryButton = ui->rightLibraryButton;
|
||||
left.invertButton = ui->leftInvertButton;
|
||||
right.invertButton = ui->rightInvertButton;
|
||||
|
||||
left.loadFwButton = ui->leftLoadFwButton;
|
||||
right.loadFwButton = ui->rightLoadFwButton;
|
||||
left.loadPictButton = ui->leftLoadPictButton;
|
||||
right.loadPictButton = ui->rightLoadPictButton;
|
||||
left.loadProfileButton = ui->leftLoadProfileButton;
|
||||
right.loadProfileButton = ui->rightLoadProfileButton;
|
||||
|
||||
loadProfile(left);
|
||||
left.markSourceButton();
|
||||
|
||||
resize(0,0);
|
||||
}
|
||||
|
||||
CustomizeSplashDialog::~CustomizeSplashDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void CustomizeSplashDialog::on_copyRightToLeftButton_clicked() {
|
||||
left.copyImage(right);
|
||||
}
|
||||
void CustomizeSplashDialog::on_copyLeftToRightButton_clicked() {
|
||||
right.copyImage(left);
|
||||
}
|
||||
|
||||
void CustomizeSplashDialog::on_leftLoadFwButton_clicked() {loadFirmware(left);}
|
||||
void CustomizeSplashDialog::on_rightLoadFwButton_clicked() {loadFirmware(right);}
|
||||
void CustomizeSplashDialog::loadFirmware(Side side)
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Firmware File"), g.flashDir(), FIRMWARE_FILES_FILTER);
|
||||
if (!fileName.isEmpty()) {
|
||||
if (!side.displayImage( fileName, FW ))
|
||||
QMessageBox::critical(this, CPN_STR_TTL_ERROR, tr("Can not load embedded image from firmware file %1.").arg(fileName));
|
||||
else
|
||||
g.flashDir( QFileInfo(fileName).dir().absolutePath() );
|
||||
}
|
||||
side.markSourceButton();
|
||||
}
|
||||
|
||||
void CustomizeSplashDialog::on_leftLoadPictButton_clicked() {loadPicture(left);}
|
||||
void CustomizeSplashDialog::on_rightLoadPictButton_clicked() {loadPicture(right);}
|
||||
void CustomizeSplashDialog::loadPicture(Side side)
|
||||
{
|
||||
QString supportedImageFormats;
|
||||
for (int formatIndex = 0; formatIndex < QImageReader::supportedImageFormats().count(); formatIndex++) {
|
||||
supportedImageFormats += QLatin1String(" *.") + QImageReader::supportedImageFormats()[formatIndex];
|
||||
}
|
||||
QString fileName = QFileDialog::getOpenFileName(this,
|
||||
tr("Open Image to load"), g.imagesDir(), tr("Images (%1)").arg(supportedImageFormats));
|
||||
|
||||
if (!fileName.isEmpty()) {
|
||||
if (!side.displayImage( fileName, PICT ))
|
||||
QMessageBox::critical(this, CPN_STR_TTL_ERROR, tr("Cannot load the image file %1.").arg(fileName));
|
||||
else
|
||||
g.imagesDir( QFileInfo(fileName).dir().absolutePath() );
|
||||
}
|
||||
side.markSourceButton();
|
||||
}
|
||||
|
||||
void CustomizeSplashDialog::on_leftLoadProfileButton_clicked() {loadProfile(left);}
|
||||
void CustomizeSplashDialog::on_rightLoadProfileButton_clicked() {loadProfile(right);}
|
||||
void CustomizeSplashDialog::loadProfile(Side side)
|
||||
{
|
||||
QString fileName=g.profile[g.id()].splashFile();
|
||||
|
||||
if (!fileName.isEmpty()) {
|
||||
if (!side.displayImage( fileName, PROFILE ))
|
||||
QMessageBox::critical(this, CPN_STR_TTL_ERROR, tr("Cannot load profile image %1.").arg(fileName));
|
||||
}
|
||||
side.markSourceButton();
|
||||
}
|
||||
|
||||
void CustomizeSplashDialog::on_leftLibraryButton_clicked(){libraryButton_clicked(left);}
|
||||
void CustomizeSplashDialog::on_rightLibraryButton_clicked(){libraryButton_clicked(right);}
|
||||
void CustomizeSplashDialog::libraryButton_clicked( Side side )
|
||||
{
|
||||
QString fileName;
|
||||
SplashLibraryDialog *ld = new SplashLibraryDialog(this,&fileName);
|
||||
ld->exec();
|
||||
if (!fileName.isEmpty()) {
|
||||
if (!side.displayImage( fileName, UNDEFINED ))
|
||||
QMessageBox::critical(this, CPN_STR_TTL_ERROR, tr("Cannot load the library image %1.").arg(fileName));
|
||||
}
|
||||
}
|
||||
|
||||
void CustomizeSplashDialog::on_leftSaveButton_clicked(){saveButton_clicked(left);}
|
||||
void CustomizeSplashDialog::on_rightSaveButton_clicked(){saveButton_clicked(right);}
|
||||
void CustomizeSplashDialog::saveButton_clicked( Side side )
|
||||
{
|
||||
if (side.saveImage()){
|
||||
QMessageBox::information(this, tr("File Saved"), tr("The image was saved to the file %1").arg(*side.saveToFileName));
|
||||
if ( !side.refreshImage()){
|
||||
QMessageBox::critical(this, tr("Image Refresh Error"), tr("Failed to refresh image from file %1").arg(*side.saveToFileName));
|
||||
}
|
||||
}
|
||||
else
|
||||
QMessageBox::critical(this, tr("File Save Error"), tr("Failed to write image to %1").arg(*side.saveToFileName));
|
||||
}
|
||||
|
||||
void CustomizeSplashDialog::on_leftInvertButton_clicked(){invertButton_clicked(left);}
|
||||
void CustomizeSplashDialog::on_rightInvertButton_clicked(){invertButton_clicked(right);}
|
||||
void CustomizeSplashDialog::invertButton_clicked(Side side)
|
||||
{
|
||||
QImage image = side.imageLabel->pixmap(Qt::ReturnByValue).toImage();
|
||||
image.invertPixels();
|
||||
side.imageLabel->setPixmap(QPixmap::fromImage(image));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _CUSTOMIZESPLASHDIALOG_H_
|
||||
#define _CUSTOMIZESPLASHDIALOG_H_
|
||||
|
||||
#include <QtWidgets>
|
||||
#include "firmwareinterface.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class CustomizeSplashDialog;
|
||||
}
|
||||
|
||||
const int WIDTH_TARANIS = 212;
|
||||
const int HEIGHT_TARANIS = 64;
|
||||
const int WIDTH_9X = 128;
|
||||
const int HEIGHT_9X = 64;
|
||||
|
||||
enum Source {FW, PICT, PROFILE, UNDEFINED};
|
||||
enum LCDFormat {LCD9X, LCDTARANIS};
|
||||
|
||||
class Side
|
||||
{
|
||||
public:
|
||||
Side(QDialog* parent);
|
||||
void markSourceButton();
|
||||
void copyImage( Side );
|
||||
bool displayImage( QString fileName, Source source );
|
||||
bool saveImage();
|
||||
bool refreshImage();
|
||||
|
||||
QLabel *imageLabel;
|
||||
QLineEdit *fileNameEdit;
|
||||
QPushButton *saveButton;
|
||||
QPushButton *invertButton;
|
||||
QToolButton *libraryButton;
|
||||
QPushButton *loadFwButton;
|
||||
QPushButton *loadPictButton;
|
||||
QPushButton *loadProfileButton;
|
||||
|
||||
QString *saveToFileName;
|
||||
|
||||
private:
|
||||
QDialog* parent;
|
||||
Source *source;
|
||||
LCDFormat *format;
|
||||
};
|
||||
|
||||
class CustomizeSplashDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Side left;
|
||||
Side right;
|
||||
|
||||
public:
|
||||
explicit CustomizeSplashDialog(QWidget *parent = 0);
|
||||
~CustomizeSplashDialog();
|
||||
|
||||
private slots:
|
||||
void on_leftLoadFwButton_clicked();
|
||||
void on_leftLoadPictButton_clicked();
|
||||
void on_leftLoadProfileButton_clicked();
|
||||
void on_leftLibraryButton_clicked();
|
||||
void on_leftSaveButton_clicked();
|
||||
void on_leftInvertButton_clicked();
|
||||
|
||||
void on_rightLoadFwButton_clicked();
|
||||
void on_rightLoadPictButton_clicked();
|
||||
void on_rightLoadProfileButton_clicked();
|
||||
void on_rightLibraryButton_clicked();
|
||||
void on_rightSaveButton_clicked();
|
||||
void on_rightInvertButton_clicked();
|
||||
|
||||
void on_copyRightToLeftButton_clicked();
|
||||
void on_copyLeftToRightButton_clicked();
|
||||
|
||||
private:
|
||||
void loadFirmware( Side );
|
||||
void loadPicture( Side );
|
||||
void loadProfile( Side );
|
||||
void libraryButton_clicked( Side );
|
||||
void saveButton_clicked( Side );
|
||||
void invertButton_clicked( Side );
|
||||
|
||||
Ui::CustomizeSplashDialog *ui;
|
||||
enum sideEnum { LEFT, RIGHT };
|
||||
};
|
||||
|
||||
#endif // _CUSTOMIZESPLASHDIALOG_H_
|
||||
@@ -0,0 +1,667 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CustomizeSplashDialog</class>
|
||||
<widget class="QDialog" name="CustomizeSplashDialog">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1087</width>
|
||||
<height>298</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Transmitter Splash Screen Editor</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_13">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="Line" name="line_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<item>
|
||||
<widget class="Line" name="line_13">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_11">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_11">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="leftFileNameEdit">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>424</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>426</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_12">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_11">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_9">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_6">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="leftImageLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>424</width>
|
||||
<height>128</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>424</width>
|
||||
<height>128</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_7">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QPushButton" name="leftInvertButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Invert</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="leftLibraryButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Open Splash Library</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<widget class="QPushButton" name="leftLoadProfileButton">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Load Profile</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="leftLoadFwButton">
|
||||
<property name="text">
|
||||
<string>Load FW</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="leftLoadPictButton">
|
||||
<property name="text">
|
||||
<string>Load Pict</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="leftSaveButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_9">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_7">
|
||||
<item>
|
||||
<widget class="QToolButton" name="copyRightToLeftButton">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="arrowType">
|
||||
<enum>Qt::LeftArrow</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="copyLeftToRightButton">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="arrowType">
|
||||
<enum>Qt::RightArrow</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_8">
|
||||
<item>
|
||||
<widget class="Line" name="line_14">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_12">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_9">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="rightFileNameEdit">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>426</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>424</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_10">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_12">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_10">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_8">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="rightImageLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>424</width>
|
||||
<height>128</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>424</width>
|
||||
<height>128</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_7">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_8">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
<item>
|
||||
<widget class="QPushButton" name="rightInvertButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Invert</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="rightLibraryButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Open Splash Library</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>24</width>
|
||||
<height>24</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_7">
|
||||
<item>
|
||||
<widget class="QPushButton" name="rightLoadProfileButton">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Load Profile</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="rightLoadFwButton">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Load FW</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="rightLoadPictButton">
|
||||
<property name="text">
|
||||
<string>Load Pict</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="rightSaveButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_10">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_6">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>leftFileNameEdit</tabstop>
|
||||
<tabstop>leftInvertButton</tabstop>
|
||||
<tabstop>leftLibraryButton</tabstop>
|
||||
<tabstop>leftLoadProfileButton</tabstop>
|
||||
<tabstop>leftLoadFwButton</tabstop>
|
||||
<tabstop>leftLoadPictButton</tabstop>
|
||||
<tabstop>leftSaveButton</tabstop>
|
||||
<tabstop>copyLeftToRightButton</tabstop>
|
||||
<tabstop>copyRightToLeftButton</tabstop>
|
||||
<tabstop>rightFileNameEdit</tabstop>
|
||||
<tabstop>rightInvertButton</tabstop>
|
||||
<tabstop>rightLibraryButton</tabstop>
|
||||
<tabstop>rightLoadProfileButton</tabstop>
|
||||
<tabstop>rightLoadFwButton</tabstop>
|
||||
<tabstop>rightLoadPictButton</tabstop>
|
||||
<tabstop>rightSaveButton</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="companion.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,403 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "flashfirmwaredialog.h"
|
||||
#include "ui_flashfirmwaredialog.h"
|
||||
#include "appdata.h"
|
||||
#include "helpers.h"
|
||||
#include "radiointerface.h"
|
||||
#include "firmwareinterface.h"
|
||||
#include "progressdialog.h"
|
||||
#include "progresswidget.h"
|
||||
#include "splashlibrarydialog.h"
|
||||
#include "storage.h"
|
||||
|
||||
FlashFirmwareDialog::FlashFirmwareDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::FlashFirmwareDialog),
|
||||
fwName(g.profile[g.id()].fwName())
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
if (!g.currentProfile().splashFile().isEmpty()){
|
||||
imageSource = PROFILE;
|
||||
imageFile = g.currentProfile().splashFile();
|
||||
ui->useProfileSplash->setChecked(true);
|
||||
} else {
|
||||
imageSource = FIRMWARE;
|
||||
imageFile = "";
|
||||
ui->useProfileSplash->setDisabled(true);
|
||||
}
|
||||
|
||||
ui->checkHardwareCompatibility->setChecked(g.checkHardwareCompatibility());
|
||||
ui->checkBackup->setChecked(g.backupOnFlash());
|
||||
|
||||
detectClicked(true);
|
||||
updateUI();
|
||||
|
||||
connect(ui->detectButton, &QPushButton::clicked, this, &FlashFirmwareDialog::detectClicked);
|
||||
connect(ui->loadButton, &QPushButton::clicked, this, &FlashFirmwareDialog::loadClicked);
|
||||
connect(ui->useProfileSplash, &QRadioButton::clicked, this, &FlashFirmwareDialog::useProfileSplashClicked);
|
||||
connect(ui->useFirmwareSplash, &QRadioButton::clicked, this, &FlashFirmwareDialog::useFirmwareSplashClicked);
|
||||
connect(ui->useLibrarySplash, &QRadioButton::clicked, this, &FlashFirmwareDialog::useLibrarySplashClicked);
|
||||
connect(ui->useExternalSplash, &QRadioButton::clicked, this, &FlashFirmwareDialog::useExternalSplashClicked);
|
||||
connect(ui->writeButton, &QPushButton::clicked, this, &FlashFirmwareDialog::writeButtonClicked);
|
||||
connect(ui->cancelButton, &QPushButton::clicked, [this]() { close(); } );
|
||||
}
|
||||
|
||||
FlashFirmwareDialog::~FlashFirmwareDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void FlashFirmwareDialog::updateUI()
|
||||
{
|
||||
ui->firmwareFilename->setText(fwName);
|
||||
|
||||
if (connectionMode) {
|
||||
ui->loadButton->setEnabled(true);
|
||||
ui->writeButton->setEnabled(isFileConnectionCompatible() && QFile(fwName).exists());
|
||||
} else {
|
||||
ui->loadButton->setEnabled(false);
|
||||
ui->writeButton->setEnabled(false);
|
||||
}
|
||||
|
||||
FirmwareInterface firmware(fwName);
|
||||
if (firmware.isValid()) {
|
||||
ui->firmwareInfoFrame->show();
|
||||
ui->date->setText(firmware.getDate() + " " + firmware.getTime());
|
||||
ui->version->setText(firmware.getVersion());
|
||||
ui->variant->setText(firmware.getFlavour());
|
||||
ui->date->setEnabled(true);
|
||||
ui->version->setEnabled(true);
|
||||
ui->variant->setEnabled(true);
|
||||
|
||||
if (firmware.hasSplash()) {
|
||||
ui->splashFrame->show();
|
||||
ui->splash->setFixedSize(firmware.getSplashWidth(), firmware.getSplashHeight());
|
||||
} else {
|
||||
ui->splashFrame->hide();
|
||||
}
|
||||
} else {
|
||||
imageSource = FIRMWARE;
|
||||
ui->firmwareInfoFrame->hide();
|
||||
ui->splashFrame->hide();
|
||||
}
|
||||
|
||||
QImage image;
|
||||
switch (imageSource) {
|
||||
case FIRMWARE:
|
||||
ui->useFirmwareSplash->setChecked(true);
|
||||
image = firmware.getSplash();
|
||||
break;
|
||||
case PROFILE:
|
||||
ui->useProfileSplash->setChecked(true);
|
||||
image.load(g.currentProfile().splashFile());
|
||||
break;
|
||||
case LIBRARY:
|
||||
ui->useLibrarySplash->setChecked(true);
|
||||
image.load(imageFile);
|
||||
break;
|
||||
case EXTERNAL:
|
||||
ui->useExternalSplash->setChecked(true);
|
||||
image.load(imageFile);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!image.isNull())
|
||||
ui->splash->setPixmap(makePixMap(image));
|
||||
|
||||
QTimer::singleShot(0, [=]() { adjustSize(); });
|
||||
}
|
||||
|
||||
void FlashFirmwareDialog::loadClicked()
|
||||
{
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Firmware File"),
|
||||
g.flashDir(),
|
||||
getFirmwareFilesFilter());
|
||||
if (!fileName.isEmpty()) {
|
||||
if (!firmwareFileExtensions().contains(QFileInfo(fileName).suffix().toLower())) {
|
||||
QMessageBox::critical(this, tr("Open Firmware File"),
|
||||
tr("%1 has an unsupported file extension")
|
||||
.arg(fileName));
|
||||
return;
|
||||
}
|
||||
|
||||
FirmwareInterface fw(fileName);
|
||||
|
||||
if (!fw.isValid()) {
|
||||
QMessageBox::critical(this, tr("Open Firmware File"),
|
||||
tr("%1 is not a valid firmware file")
|
||||
.arg(fileName));
|
||||
return;
|
||||
}
|
||||
|
||||
if (connectionMode == CONNECTION_UF2) {
|
||||
const Uf2Info uf2(getUf2Info());
|
||||
if (fw.getFlavour() != uf2.board) {
|
||||
QMessageBox::critical(this, tr("Open Firmware File"),
|
||||
tr("%1 \nFirmware file is for %2 radio however connected radio is %3")
|
||||
.arg(fileName)
|
||||
.arg(fw.getFlavour())
|
||||
.arg(uf2.board));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (fw.getFlavour() != getCurrentFirmware()->getFlavour()) {
|
||||
QMessageBox::critical(this, tr("Open Firmware File"),
|
||||
tr("%1 \nFirmware file is for %2 radio however profile is for %3 radio")
|
||||
.arg(fileName)
|
||||
.arg(fw.getFlavour())
|
||||
.arg(getCurrentFirmware()->getFlavour()));
|
||||
return;
|
||||
}
|
||||
|
||||
fwName = fileName;
|
||||
updateUI();
|
||||
}
|
||||
}
|
||||
|
||||
void FlashFirmwareDialog::useFirmwareSplashClicked()
|
||||
{
|
||||
FirmwareInterface firmware(fwName);
|
||||
|
||||
if (!firmware.isValid()) {
|
||||
QMessageBox::warning(this, CPN_STR_TTL_ERROR, tr( "The firmware file is not valid." ));
|
||||
} else if (!firmware.hasSplash()) {
|
||||
QMessageBox::warning(this, CPN_STR_TTL_ERROR,
|
||||
tr( "There is no start screen image in the firmware file." ));
|
||||
} else {
|
||||
imageSource = FIRMWARE;
|
||||
}
|
||||
|
||||
updateUI();
|
||||
}
|
||||
|
||||
void FlashFirmwareDialog::useProfileSplashClicked()
|
||||
{
|
||||
QString fileName = g.currentProfile().splashFile();
|
||||
|
||||
if (!fileName.isEmpty()) {
|
||||
QImage image(fileName);
|
||||
if (image.isNull()) {
|
||||
QMessageBox::critical(this, CPN_STR_TTL_ERROR,
|
||||
tr("Profile image %1 is invalid.").arg(fileName));
|
||||
} else {
|
||||
imageSource = PROFILE;
|
||||
}
|
||||
}
|
||||
|
||||
updateUI();
|
||||
}
|
||||
|
||||
void FlashFirmwareDialog::useExternalSplashClicked()
|
||||
{
|
||||
QString supportedImageFormats;
|
||||
|
||||
for (int formatIndex = 0; formatIndex < QImageReader::supportedImageFormats().count(); formatIndex++) {
|
||||
supportedImageFormats += QLatin1String(" *.") + QImageReader::supportedImageFormats()[formatIndex];
|
||||
}
|
||||
|
||||
QString fileName = QFileDialog::getOpenFileName(this, tr("Open image file to use as radio start screen"),
|
||||
g.imagesDir(),
|
||||
tr("Images (%1)").arg(supportedImageFormats));
|
||||
|
||||
if (!fileName.isEmpty()){
|
||||
g.imagesDir( QFileInfo(fileName).dir().absolutePath() );
|
||||
QImage image(fileName);
|
||||
|
||||
if (image.isNull()) {
|
||||
QMessageBox::critical(this, CPN_STR_TTL_ERROR,
|
||||
tr("Image could not be loaded from %1")
|
||||
.arg(fileName));
|
||||
} else {
|
||||
imageSource = EXTERNAL;
|
||||
imageFile = fileName;
|
||||
}
|
||||
}
|
||||
|
||||
updateUI();
|
||||
}
|
||||
|
||||
void FlashFirmwareDialog::useLibrarySplashClicked()
|
||||
{
|
||||
QString fileName;
|
||||
SplashLibraryDialog(this, &fileName).exec();
|
||||
|
||||
if (!fileName.isEmpty()) {
|
||||
QImage image(fileName);
|
||||
|
||||
if (image.isNull()) {
|
||||
QMessageBox::critical(this, CPN_STR_TTL_ERROR, tr("The library image could not be loaded"));
|
||||
} else {
|
||||
imageSource = LIBRARY;
|
||||
imageFile = fileName;
|
||||
}
|
||||
}
|
||||
|
||||
updateUI();
|
||||
}
|
||||
|
||||
void FlashFirmwareDialog::writeButtonClicked()
|
||||
{
|
||||
g.flashDir(QFileInfo(fwName).dir().absolutePath());
|
||||
g.currentProfile().fwName(fwName);
|
||||
g.checkHardwareCompatibility(ui->checkHardwareCompatibility->isChecked());
|
||||
g.backupOnFlash(ui->checkBackup->isChecked());
|
||||
|
||||
if (imageSource != FIRMWARE) {
|
||||
// load the splash image
|
||||
const QPixmap pixmap = ui->splash->pixmap(Qt::ReturnByValue);
|
||||
QImage image;
|
||||
image = pixmap.toImage().scaled(ui->splash->width(), ui->splash->height());
|
||||
|
||||
if (image.isNull()) {
|
||||
QMessageBox::critical(this, CPN_STR_TTL_WARNING, tr("Splash image not found"));
|
||||
return;
|
||||
}
|
||||
|
||||
// write the customized firmware
|
||||
QString tempFile;
|
||||
tempFile = generateProcessUniqueTempFileName("flash.bin");
|
||||
qDebug() << "patching" << fwName << "with custom splash screen and saving to" << tempFile;
|
||||
FirmwareInterface firmware(fwName);
|
||||
firmware.setSplash(image);
|
||||
|
||||
if (firmware.save(tempFile) <= 0) {
|
||||
QMessageBox::critical(this, CPN_STR_TTL_WARNING, tr("Cannot save customised firmware"));
|
||||
return;
|
||||
}
|
||||
|
||||
startWrite(tempFile);
|
||||
} else {
|
||||
startWrite(fwName);
|
||||
}
|
||||
}
|
||||
|
||||
void FlashFirmwareDialog::startWrite(const QString &filename)
|
||||
{
|
||||
close();
|
||||
|
||||
ProgressDialog progressDialog(this, tr("Flash Firmware to Radio"),
|
||||
CompanionIcon("write_flash.png"));
|
||||
|
||||
auto progress = progressDialog.progress();
|
||||
progress->addMessage(tr("Flashing with file: %1").arg(filename));
|
||||
bool checkHw = g.checkHardwareCompatibility();
|
||||
bool backup = g.backupOnFlash();
|
||||
FirmwareInterface newfw(filename);
|
||||
|
||||
if (g.checkHardwareCompatibility() || backup) {
|
||||
readFirmware(
|
||||
[this, &newfw, progress, checkHw, backup](const QByteArray &_data) {
|
||||
FirmwareInterface currfw(_data);
|
||||
if (!currfw.isValid()) {
|
||||
QString errMsg(tr("Firmware read from radio invalid"));
|
||||
progress->addMessage(errMsg, QtFatalMsg);
|
||||
progress->setInfo(errMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (backup) {
|
||||
if (!writeFirmwareToFile(this, _data, progress)) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
progress->addMessage(tr("Backup of old firmware not requested"));
|
||||
}
|
||||
|
||||
if (checkHw) {
|
||||
if (!newfw.isHardwareCompatible(currfw)) {
|
||||
QString errMsg(tr("New firmware is not compatible"));
|
||||
progress->addMessage(errMsg, QtFatalMsg);
|
||||
progress->setInfo(errMsg);
|
||||
return;
|
||||
} else {
|
||||
progress->addMessage(tr("New firmware is compatible"));
|
||||
}
|
||||
} else {
|
||||
progress->addMessage(tr("New firmware compatibity check not requested"));
|
||||
}
|
||||
|
||||
progress->addMessage(tr("Start flashing firmware"));
|
||||
writeFirmware(newfw.getFlash(), progress);
|
||||
},
|
||||
[this, progress](const QString &err) {
|
||||
progress->addMessage(tr("Could not read current firmware: %1").arg(err));
|
||||
},
|
||||
progress);
|
||||
} else {
|
||||
progress->addMessage(tr("Start flashing firmware (no backup or compatiblity check)"));
|
||||
writeFirmware(newfw.getFlash(), progress);
|
||||
}
|
||||
|
||||
progressDialog.exec();
|
||||
|
||||
if (isTempFileName(filename)) {
|
||||
qDebug() << "Removing temporary file" << filename;
|
||||
qunlink(filename);
|
||||
}
|
||||
}
|
||||
|
||||
void FlashFirmwareDialog::detectClicked(bool atLoad)
|
||||
{
|
||||
QString connectionMsg;
|
||||
|
||||
if (isUf2DeviceFound()) {
|
||||
connectionMode = CONNECTION_UF2;
|
||||
connectionMsg = tr("Radio connection mode: UF2");
|
||||
} else if (isDfuDeviceFound()) {
|
||||
connectionMode = CONNECTION_DFU;
|
||||
connectionMsg = tr("Radio connection mode: DFU");
|
||||
} else {
|
||||
connectionMode = CONNECTION_NONE;
|
||||
connectionMsg = tr("ALERT: No radio connected");
|
||||
}
|
||||
|
||||
ui->connectionMode->setText(connectionMsg);
|
||||
|
||||
if (!connectionMode) {
|
||||
QMessageBox::warning((atLoad ? (QWidget *)parent(): this), tr("Detect Radio"),
|
||||
tr("Radio could not be detected by DFU or UF2 modes") % ".\n" %
|
||||
tr("Check cable is securely connected and radio lights are illuminated") % ".\n" %
|
||||
tr("Note: USB mode is not suitable for flashing firmware."));
|
||||
}
|
||||
|
||||
if (!isFileConnectionCompatible())
|
||||
fwName.clear();
|
||||
|
||||
if (!atLoad)
|
||||
updateUI();
|
||||
}
|
||||
|
||||
bool FlashFirmwareDialog::isFileConnectionCompatible()
|
||||
{
|
||||
if (!fwName.isEmpty()) {
|
||||
const QString extn(QFileInfo(fwName).suffix().toLower());
|
||||
if ((connectionMode == CONNECTION_DFU && dfuFileExtensions().contains(extn)) ||
|
||||
(connectionMode == CONNECTION_UF2 && uf2FileExtensions().contains(extn))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class FlashFirmwareDialog;
|
||||
}
|
||||
|
||||
class FlashFirmwareDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FlashFirmwareDialog(QWidget *parent = 0);
|
||||
~FlashFirmwareDialog();
|
||||
|
||||
private slots:
|
||||
void detectClicked(bool atLoad = false);
|
||||
void loadClicked();
|
||||
void writeButtonClicked();
|
||||
void useProfileSplashClicked();
|
||||
void useFirmwareSplashClicked();
|
||||
void useLibrarySplashClicked();
|
||||
void useExternalSplashClicked();
|
||||
|
||||
protected:
|
||||
void updateUI();
|
||||
void startWrite(const QString &filename);
|
||||
|
||||
private:
|
||||
enum ConnectionModes { CONNECTION_NONE, CONNECTION_UF2, CONNECTION_DFU };
|
||||
enum ImageSource {FIRMWARE, PROFILE, LIBRARY, EXTERNAL};
|
||||
|
||||
Ui::FlashFirmwareDialog *ui;
|
||||
QString fwName;
|
||||
ImageSource imageSource;
|
||||
QString imageFile;
|
||||
int connectionMode;
|
||||
bool isFileConnectionCompatible();
|
||||
};
|
||||
@@ -0,0 +1,369 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>FlashFirmwareDialog</class>
|
||||
<widget class="QDialog" name="FlashFirmwareDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>421</width>
|
||||
<height>390</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Flash Firmware</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="../companion.qrc">
|
||||
<normaloff>:/icon.png</normaloff>:/icon.png</iconset>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout2">
|
||||
<item>
|
||||
<widget class="QLabel" name="connectionMode">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Radio connection: Unknown</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="detectButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Detect the boot mode of the connected radio</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Detect</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout4">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="firmwareFilename">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>250</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="loadButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Select and load a firmware file. The file extension must be one suitable for the boot mode.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Load...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="firmwareInfoFrame">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Raised</enum>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_5">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="dateLabel">
|
||||
<property name="text">
|
||||
<string>Date & Time</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="version">
|
||||
<property name="toolTip">
|
||||
<string>Firmware build version</string>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="variantLabel">
|
||||
<property name="text">
|
||||
<string>Radio</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="variant">
|
||||
<property name="toolTip">
|
||||
<string>Target radio for which the firmware was built</string>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="versionLabel">
|
||||
<property name="text">
|
||||
<string>Version</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="date">
|
||||
<property name="toolTip">
|
||||
<string>Buid timestamp</string>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="splashFrame">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout3">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="useProfileSplash">
|
||||
<property name="text">
|
||||
<string>Use profile start screen</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="useFirmwareSplash">
|
||||
<property name="text">
|
||||
<string>Use firmware start screen</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="useLibrarySplash">
|
||||
<property name="text">
|
||||
<string>Use library start screen</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="useExternalSplash">
|
||||
<property name="text">
|
||||
<string>Use another start screen</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="splash">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>128</width>
|
||||
<height>64</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>214</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkHardwareCompatibility">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Checks the new firmware matches the connected radio. If not the process will be aborted.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Check hardware compatibility (recommended)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBackup">
|
||||
<property name="toolTip">
|
||||
<string>Read the connected radio firmware and write to the backup folder.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Backup radio firmware before flashing</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="spacer2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout1">
|
||||
<item>
|
||||
<spacer name="spacer1">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="cancelButton">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>90</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="writeButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>90</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Performing optional processes and write the loaded file to the conneced radio.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Write to TX</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>writeButton</tabstop>
|
||||
<tabstop>firmwareFilename</tabstop>
|
||||
<tabstop>loadButton</tabstop>
|
||||
<tabstop>version</tabstop>
|
||||
<tabstop>variant</tabstop>
|
||||
<tabstop>cancelButton</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../companion.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "process_copy.h"
|
||||
#include "constants.h"
|
||||
#include "progresswidget.h"
|
||||
#include <QEventLoop>
|
||||
#include <QFile>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
|
||||
#define BLKSIZE 512
|
||||
|
||||
CopyProcess::CopyProcess(const QString &source, const QString &destination, ProgressWidget *progress):
|
||||
progress(progress),
|
||||
source(source),
|
||||
destination(destination),
|
||||
result(true)
|
||||
{
|
||||
}
|
||||
|
||||
bool CopyProcess::run()
|
||||
{
|
||||
progress->lock(true);
|
||||
// progress->setInfo(tr("Copying file..."));
|
||||
|
||||
QEventLoop loop;
|
||||
connect(this, SIGNAL(finished()), &loop, SLOT(quit()));
|
||||
QTimer::singleShot(500, this, SLOT(onTimer()));
|
||||
loop.exec();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void CopyProcess::onTimer()
|
||||
{
|
||||
char buf[BLKSIZE];
|
||||
|
||||
QFile sourceFile(source);
|
||||
int blocks = (sourceFile.size() + BLKSIZE - 1) / BLKSIZE;
|
||||
progress->setMaximum(blocks-1);
|
||||
|
||||
if (sourceFile.open(QIODevice::ReadOnly)) {
|
||||
QFile destinationFile(destination);
|
||||
if (destinationFile.open(QIODevice::ReadWrite)) {
|
||||
// progress->addText(tr("Writing file: "));
|
||||
for (int i=0; i<blocks; i++) {
|
||||
int read = sourceFile.read(buf, BLKSIZE);
|
||||
if (destinationFile.write(buf, read) == read) {
|
||||
destinationFile.flush();
|
||||
progress->setValue(i);
|
||||
}
|
||||
else {
|
||||
QMessageBox::warning(NULL, CPN_STR_TTL_ERROR, tr("Write error"));
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
destinationFile.close();
|
||||
}
|
||||
else {
|
||||
QMessageBox::warning(NULL, CPN_STR_TTL_ERROR,tr("Cannot write %1 (reason: %2)").arg(destinationFile.fileName()).arg(sourceFile.errorString()));
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
QMessageBox::warning(NULL, CPN_STR_TTL_ERROR,tr("Cannot open %1 (reason: %2)").arg(sourceFile.fileName()).arg(sourceFile.errorString()));
|
||||
result = false;
|
||||
}
|
||||
|
||||
sourceFile.close();
|
||||
|
||||
progress->lock(false);
|
||||
emit finished();
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _PROCESS_COPY_H_
|
||||
#define _PROCESS_COPY_H_
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
class ProgressWidget;
|
||||
|
||||
class CopyProcess : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CopyProcess(const QString &source, const QString &destination, ProgressWidget *progress);
|
||||
bool run();
|
||||
|
||||
signals:
|
||||
void finished();
|
||||
|
||||
protected slots:
|
||||
void onTimer();
|
||||
|
||||
protected:
|
||||
ProgressWidget *progress;
|
||||
const QString source;
|
||||
const QString destination;
|
||||
bool result;
|
||||
};
|
||||
|
||||
#endif // _PROCESS_COPY_H_
|
||||
@@ -0,0 +1,420 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "process_sync.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCryptographicHash>
|
||||
#include <QElapsedTimer>
|
||||
#include <QMutexLocker>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <QNtfsPermissionCheckGuard>
|
||||
#endif
|
||||
|
||||
#define SYNC_MAX_ERRORS 50 // give up after this many errors per destination
|
||||
|
||||
// a flood of log messages can make the UI unresponsive so we'll introduce a dynamic sleep period based on log frequency (values in [us])
|
||||
#define PAUSE_FACTOR 60UL
|
||||
#define PAUSE_RECOVERY (PAUSE_FACTOR / 3 * 2)
|
||||
#define PAUSE_MINTM 100UL
|
||||
#define PAUSE_MAXTM 75000UL
|
||||
|
||||
#define PRINT_CREATE(str) emitProgressMessage((str), QtInfoMsg)
|
||||
#define PRINT_REPLACE(str) emitProgressMessage((str), QtWarningMsg)
|
||||
//#define PRINT_DELETE(str) emitProgressMessage((str), QtCriticalMsg) // unused
|
||||
#define PRINT_ERROR(str) emitProgressMessage((str), QtFatalMsg)
|
||||
#define PRINT_SKIP(str) emitProgressMessage((str), QtDebugMsg)
|
||||
#define PRINT_INFO(str) emit progressMessage((str)) // this is always emitted regardless of logLevel option
|
||||
#define PRINT_SEP() PRINT_INFO(QString(70, '='))
|
||||
|
||||
SyncProcess::SyncProcess(const SyncProcess::SyncOptions & options) :
|
||||
m_options(options),
|
||||
m_pauseTime(PAUSE_MINTM),
|
||||
stopping(false)
|
||||
{
|
||||
qRegisterMetaType<SyncProcess::SyncStatus>();
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
QNtfsPermissionCheckGuard permissionGuard; // check is enabled
|
||||
#endif
|
||||
|
||||
if (m_options.compareType == OVERWR_ALWAYS && (m_options.direction == SYNC_A2B_B2A || m_options.direction == SYNC_B2A_A2B))
|
||||
m_options.compareType = OVERWR_IF_DIFF;
|
||||
|
||||
m_dirFilters = QDir::Filters(m_options.dirFilterFlags);
|
||||
if (!(m_dirFilters & QDir::Dirs))
|
||||
m_dirFilters &= ~(QDir::AllDirs);
|
||||
|
||||
if (!m_options.includeFilter.isEmpty() && m_options.includeFilter != "*")
|
||||
m_dirIteratorFilters = m_options.includeFilter.split(',', Qt::SkipEmptyParts);
|
||||
|
||||
if (!m_options.excludeFilter.isEmpty()) {
|
||||
for (const QString & f : m_options.excludeFilter.split(',', Qt::SkipEmptyParts))
|
||||
m_excludeFilters.append(QRegularExpression(QRegularExpression::wildcardToRegularExpression(f),
|
||||
((m_dirFilters & QDir::CaseSensitive) ? QRegularExpression::NoPatternOption : QRegularExpression::CaseInsensitiveOption)));
|
||||
}
|
||||
|
||||
if (m_options.flags & OPT_DRY_RUN)
|
||||
testRunStr = tr("[TEST RUN] ");
|
||||
|
||||
//qDebug() << m_options;
|
||||
} // for Q_OS_WIN as the permissionGuard goes out of scope the check is disabled
|
||||
|
||||
SyncProcess::~SyncProcess()
|
||||
{
|
||||
}
|
||||
|
||||
void SyncProcess::stop()
|
||||
{
|
||||
QWriteLocker locker(&stopReqMutex);
|
||||
stopping = true;
|
||||
}
|
||||
|
||||
bool SyncProcess::isStopRequsted()
|
||||
{
|
||||
QReadLocker locker(&stopReqMutex);
|
||||
return stopping;
|
||||
}
|
||||
|
||||
void SyncProcess::run()
|
||||
{
|
||||
const QString folderA = (m_options.direction == SYNC_B2A_A2B ? m_options.folderB : m_options.folderA);
|
||||
const QString folderB = (m_options.direction == SYNC_B2A_A2B ? m_options.folderA : m_options.folderB);
|
||||
const SyncDirection direction = (m_options.direction == SYNC_B2A_A2B ? SYNC_A2B_B2A : SyncDirection(m_options.direction));
|
||||
const QString gathering = tr("Gathering file information for %1...");
|
||||
const QString noFiles = tr("No files found in %1");
|
||||
int count = 0;
|
||||
|
||||
m_stat.clear();
|
||||
m_startTime = QDateTime::currentDateTime();
|
||||
|
||||
emit started();
|
||||
emit fileCountChanged(0);
|
||||
emit statusUpdate(m_stat);
|
||||
|
||||
if (direction == SYNC_A2B_B2A || direction == SYNC_A2B) {
|
||||
emit statusMessage(gathering.arg(folderA));
|
||||
count = getFilesCount(folderA);
|
||||
|
||||
if (isStopRequsted())
|
||||
goto endrun;
|
||||
|
||||
if (count) {
|
||||
m_stat.count = count;
|
||||
if (m_options.direction == SYNC_A2B_B2A)
|
||||
count *= 2; // assume this direction is only 50% of total, exact will be calculated later
|
||||
emit fileCountChanged(count);
|
||||
updateDir(folderA, folderB);
|
||||
if (isStopRequsted())
|
||||
goto endrun;
|
||||
}
|
||||
else {
|
||||
PRINT_INFO(noFiles.arg(folderA));
|
||||
PRINT_SEP();
|
||||
}
|
||||
}
|
||||
|
||||
if (direction == SYNC_A2B_B2A || direction == SYNC_B2A) {
|
||||
emit statusMessage(gathering.arg(folderB));
|
||||
count = getFilesCount(folderB);
|
||||
|
||||
if (isStopRequsted())
|
||||
goto endrun;
|
||||
|
||||
m_stat.count += count;
|
||||
emit fileCountChanged(m_stat.count);
|
||||
|
||||
if (count) {
|
||||
updateDir(folderB, folderA);
|
||||
}
|
||||
else {
|
||||
PRINT_INFO(noFiles.arg(folderB));
|
||||
PRINT_SEP();
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_stat.count) {
|
||||
emit statusMessage(tr("Synchronization failed, nothing found to copy."), QtWarningMsg);
|
||||
emit finished();
|
||||
return;
|
||||
}
|
||||
|
||||
endrun:
|
||||
finish();
|
||||
}
|
||||
|
||||
void SyncProcess::finish()
|
||||
{
|
||||
const lldiv_t elapsed = lldiv(m_startTime.secsTo(QDateTime::currentDateTime()), 60);
|
||||
QString endStr = testRunStr;
|
||||
if (m_stat.index < m_stat.count)
|
||||
endStr.append(tr("Synchronization aborted at %1 of %2 files.").arg(m_stat.index).arg(m_stat.count));
|
||||
else
|
||||
endStr.append(tr("Synchronization finished with %1 files in %2m %3s.").arg(m_stat.count).arg(elapsed.quot).arg(elapsed.rem));
|
||||
emit statusMessage(endStr);
|
||||
emit finished();
|
||||
}
|
||||
|
||||
SyncProcess::FileFilterResult SyncProcess::fileFilter(const QFileInfo & fileInfo)
|
||||
{
|
||||
// Windows Junctions (mount points) are not detected as links (QTBUG-45344), but that's OK since they're really "hard links."
|
||||
const bool chkDirLnk = ((m_dirFilters & QDir::NoSymLinks) && !(m_dirFilters & QDir::AllDirs)) || ((m_options.flags & OPT_SKIP_DIR_LINKS) && fileInfo.isDir());
|
||||
if ((chkDirLnk || ((m_dirFilters & QDir::NoSymLinks) && fileInfo.isFile())) && QFileInfo(fileInfo.absoluteFilePath()).isSymLink()) // MUST create a new QFileInfo here (QTBUG-69001)
|
||||
return FILE_LINK_IGNORE;
|
||||
|
||||
if (m_options.maxFileSize > 0 && fileInfo.isFile() && fileInfo.size() > m_options.maxFileSize)
|
||||
return FILE_OVERSIZE;
|
||||
|
||||
if (!m_excludeFilters.isEmpty() && (!(m_dirFilters & QDir::AllDirs) || fileInfo.isFile())) {
|
||||
for (QVector<QRegularExpression>::const_iterator it = m_excludeFilters.constBegin(), end = m_excludeFilters.constEnd(); it != end; ++it) {
|
||||
if (QRegularExpression(*it).match(fileInfo.fileName()).hasMatch())
|
||||
return FILE_EXCLUDE;
|
||||
}
|
||||
}
|
||||
|
||||
return FILE_ALLOW;
|
||||
}
|
||||
|
||||
QFileInfoList SyncProcess::dirInfoList(const QString & directory)
|
||||
{
|
||||
QDir::Filters flt = m_dirFilters;
|
||||
if (!(flt & QDir::Dirs) && (m_options.flags & OPT_RECURSIVE))
|
||||
flt |= ((m_options.dirFilterFlags & QDir::AllDirs) ? QDir::AllDirs : QDir::Dirs);
|
||||
return QDir(directory).entryInfoList(m_dirIteratorFilters, flt, QDir::Name | QDir::DirsLast);
|
||||
}
|
||||
|
||||
void SyncProcess::pushDirEntries(const QFileInfo & fileInfo, QMutableListIterator<QFileInfo> & it)
|
||||
{
|
||||
if ((m_options.flags & OPT_RECURSIVE) && fileInfo.isDir()) {
|
||||
for (const QFileInfo &fi : dirInfoList(fileInfo.absoluteFilePath()))
|
||||
it.insert(fi);
|
||||
}
|
||||
}
|
||||
|
||||
int SyncProcess::getFilesCount(const QString & directory)
|
||||
{
|
||||
if (!QFile::exists(directory))
|
||||
return 0;
|
||||
|
||||
int result = 0;
|
||||
QFileInfoList infoList = dirInfoList(directory);
|
||||
QMutableListIterator<QFileInfo> it(infoList);
|
||||
it.toBack();
|
||||
while (it.hasPrevious() && !isStopRequsted()) {
|
||||
const QFileInfo fi(it.previous());
|
||||
it.remove();
|
||||
if (fileFilter(fi) == FILE_ALLOW) {
|
||||
pushDirEntries(fi, it);
|
||||
if (fi.isFile()) {
|
||||
result++;
|
||||
}
|
||||
}
|
||||
QApplication::processEvents();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void SyncProcess::updateDir(const QString & source, const QString & destination)
|
||||
{
|
||||
SyncStatus pStat = m_stat;
|
||||
const QDir srcDir(source), dstDir(destination);
|
||||
FileFilterResult ffr;
|
||||
emit statusMessage(testRunStr % tr("Synchronizing: %1\n To: %2").arg(source, destination));
|
||||
PRINT_INFO(testRunStr % tr("Starting synchronization:\n %1 -> %2\n").arg(source, destination));
|
||||
|
||||
QFileInfoList infoList = dirInfoList(source);
|
||||
QMutableListIterator<QFileInfo> it(infoList);
|
||||
it.toBack();
|
||||
while (it.hasPrevious() && !isStopRequsted()) {
|
||||
const QFileInfo fi(it.previous());
|
||||
it.remove();
|
||||
if ((ffr = fileFilter(fi)) == FILE_ALLOW) {
|
||||
pushDirEntries(fi, it);
|
||||
if ((m_dirFilters & QDir::Dirs) || fi.isFile()) {
|
||||
updateEntry(fi.filePath(), srcDir, dstDir);
|
||||
if (fi.isFile())
|
||||
++m_stat.index;
|
||||
emit statusUpdate(m_stat);
|
||||
if (m_stat.errored - pStat.errored > SYNC_MAX_ERRORS) {
|
||||
PRINT_ERROR(tr("\nToo many errors, giving up."));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (m_options.logLevel == QtDebugMsg) {
|
||||
switch (ffr) {
|
||||
case FILE_OVERSIZE:
|
||||
PRINT_SKIP(tr("Skipping large file: %1 (%2KB)").arg(fi.fileName()).arg(int(fi.size() / 1024)));
|
||||
break;
|
||||
case FILE_EXCLUDE:
|
||||
PRINT_SKIP(tr("Skipping filtered file: %1").arg(fi.fileName()));
|
||||
break;
|
||||
case FILE_LINK_IGNORE:
|
||||
PRINT_SKIP(tr("Skipping linked file: %1").arg(fi.fileName()));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// don't count as skipped because these weren't included in the total file count to begin with
|
||||
}
|
||||
// throttle if needed
|
||||
m_pauseTime = qMax(m_pauseTime - PAUSE_RECOVERY, PAUSE_MINTM);
|
||||
pause();
|
||||
}
|
||||
|
||||
QString endStr = "\n" % testRunStr;
|
||||
if (isStopRequsted())
|
||||
endStr.append(tr("Aborted synchronization of:"));
|
||||
else
|
||||
endStr.append(tr("Finished synchronizing:"));
|
||||
endStr.append(QString("\n %1 -> %2\n ").arg(source, destination));
|
||||
endStr.append(tr("Created: %1; Updated: %2; Skipped: %3; Errors: %4;").arg(m_stat.created-pStat.created).arg(m_stat.updated-pStat.updated).arg(m_stat.skipped-pStat.skipped).arg(m_stat.errored-pStat.errored));
|
||||
PRINT_INFO(endStr);
|
||||
PRINT_SEP();
|
||||
}
|
||||
|
||||
bool SyncProcess::updateEntry(const QString & entry, const QDir & source, const QDir & destination)
|
||||
{
|
||||
const QString srcPath = QDir::toNativeSeparators(source.absoluteFilePath(entry));
|
||||
const QString destPath = QDir::toNativeSeparators(destination.absoluteFilePath(source.relativeFilePath(entry)));
|
||||
const QFileInfo sourceInfo(srcPath);
|
||||
const QFileInfo destInfo(destPath);
|
||||
static QString lastMkPath;
|
||||
|
||||
// check if this is a directory OR if we're copying a file with a path which doesn't exist yet.
|
||||
if (sourceInfo.isDir() || !destInfo.absoluteDir().exists()) {
|
||||
const QString mkPath = sourceInfo.isDir() ? destPath : QDir::toNativeSeparators(destInfo.absolutePath());
|
||||
if (!destination.exists(mkPath)) {
|
||||
if (mkPath == lastMkPath) {
|
||||
// we've already tried, and apparently failed, to create this folder... bail out but log as error.
|
||||
if (!(m_options.flags & OPT_DRY_RUN)) {
|
||||
++m_stat.errored;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
lastMkPath = mkPath;
|
||||
PRINT_CREATE(tr("Creating directory: %1").arg(mkPath));
|
||||
if (!(m_options.flags & OPT_DRY_RUN) && !destination.mkpath(mkPath)) {
|
||||
PRINT_ERROR(tr("Could not create directory: %1").arg(mkPath));
|
||||
++m_stat.errored;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (m_dirFilters & QDir::Dirs) {
|
||||
PRINT_SKIP(tr("Directory exists: %1").arg(mkPath));
|
||||
}
|
||||
if (sourceInfo.isDir())
|
||||
return true;
|
||||
}
|
||||
|
||||
//qDebug() << destPath;
|
||||
QFile sourceFile(srcPath);
|
||||
QFile destinationFile(destPath);
|
||||
const bool destExists = destInfo.exists();
|
||||
bool checkDate = (m_options.compareType == OVERWR_NEWER_IF_DIFF || m_options.compareType == OVERWR_NEWER_ALWAYS);
|
||||
bool checkContent = (m_options.compareType == OVERWR_NEWER_IF_DIFF || m_options.compareType == OVERWR_IF_DIFF);
|
||||
bool existed = false;
|
||||
|
||||
if (destExists && checkDate) {
|
||||
const QDate cmprDate = QDate::currentDate();
|
||||
if (sourceInfo.lastModified().date() > cmprDate || destInfo.lastModified().date() > cmprDate) {
|
||||
PRINT_ERROR(tr("At least one of the file modification dates is in the future, error on: %1").arg(srcPath));
|
||||
++m_stat.errored;
|
||||
return false;
|
||||
}
|
||||
if (sourceInfo.lastModified() <= destInfo.lastModified()) {
|
||||
PRINT_SKIP(tr("Skipping older file: %1").arg(srcPath));
|
||||
++m_stat.skipped;
|
||||
return true;
|
||||
}
|
||||
checkDate = false;
|
||||
}
|
||||
|
||||
if (destExists && checkContent) {
|
||||
if (!sourceFile.open(QFile::ReadOnly)) {
|
||||
PRINT_ERROR(tr("Could not open source file '%1': %2").arg(srcPath, sourceFile.errorString()));
|
||||
++m_stat.errored;
|
||||
return false;
|
||||
}
|
||||
if (!destinationFile.open(QFile::ReadOnly)) {
|
||||
PRINT_ERROR(tr("Could not open destination file '%1': %2").arg(destPath, destinationFile.errorString()));
|
||||
++m_stat.errored;
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool skip = QCryptographicHash::hash(sourceFile.readAll(), QCryptographicHash::Md5) == QCryptographicHash::hash(destinationFile.readAll(), QCryptographicHash::Md5);
|
||||
sourceFile.close();
|
||||
destinationFile.close();
|
||||
if (skip) {
|
||||
PRINT_SKIP(tr("Skipping identical file: %1").arg(srcPath));
|
||||
++m_stat.skipped;
|
||||
return true;
|
||||
}
|
||||
checkContent = false;
|
||||
}
|
||||
|
||||
if (!destExists || (!checkDate && !checkContent)) {
|
||||
if (destInfo.exists()) {
|
||||
existed = true;
|
||||
PRINT_REPLACE(tr("Replacing file: %1").arg(destPath));
|
||||
if (!(m_options.flags & OPT_DRY_RUN) && !destinationFile.remove()) {
|
||||
PRINT_ERROR(tr("Could not delete destination file '%1': %2").arg(destPath, destinationFile.errorString()));
|
||||
++m_stat.errored;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PRINT_CREATE(tr("Creating file: %1").arg(destPath));
|
||||
}
|
||||
if (!(m_options.flags & OPT_DRY_RUN) && !sourceFile.copy(destPath)) {
|
||||
PRINT_ERROR(tr("Copy failed: '%1' to '%2': %3").arg(srcPath, destPath, sourceFile.errorString()));
|
||||
++m_stat.errored;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (existed)
|
||||
++m_stat.updated;
|
||||
else
|
||||
++m_stat.created;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SyncProcess::pause()
|
||||
{
|
||||
QElapsedTimer tim;
|
||||
const qint64 exp = m_pauseTime * 1000;
|
||||
tim.start();
|
||||
while (tim.nsecsElapsed() < exp && !isStopRequsted())
|
||||
QApplication::processEvents();
|
||||
}
|
||||
|
||||
void SyncProcess::emitProgressMessage(const QString & text, int type)
|
||||
{
|
||||
if (m_options.logLevel == QtDebugMsg || (m_options.logLevel == QtInfoMsg && type > QtDebugMsg) || (type < QtInfoMsg && type >= m_options.logLevel)) {
|
||||
emit progressMessage(text, type);
|
||||
m_pauseTime = qMin(m_pauseTime + PAUSE_FACTOR, PAUSE_MAXTM);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QDirIterator>
|
||||
#include <QReadWriteLock>
|
||||
#include <QRegularExpression>
|
||||
#include <QVector>
|
||||
|
||||
class SyncProcess : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum SyncDirection {
|
||||
SYNC_A2B_B2A = 0,
|
||||
SYNC_B2A_A2B,
|
||||
SYNC_A2B,
|
||||
SYNC_B2A
|
||||
};
|
||||
Q_ENUM(SyncDirection)
|
||||
|
||||
enum SyncCompareType {
|
||||
OVERWR_NEWER_IF_DIFF = 0,
|
||||
OVERWR_NEWER_ALWAYS,
|
||||
OVERWR_IF_DIFF,
|
||||
OVERWR_ALWAYS
|
||||
};
|
||||
Q_ENUM(SyncCompareType)
|
||||
|
||||
enum SyncOptionFlag {
|
||||
OPT_NONE = 0,
|
||||
OPT_DRY_RUN = 0x01,
|
||||
OPT_SKIP_EMPTY_DIR = 0x02,
|
||||
OPT_RECURSIVE = 0x04,
|
||||
OPT_SKIP_DIR_LINKS = 0x08
|
||||
};
|
||||
Q_DECLARE_FLAGS(SyncOptionFlags, SyncOptionFlag)
|
||||
Q_FLAG(SyncOptionFlags)
|
||||
|
||||
// TODO: perhaps move this to AppData/saved settings once that refactoring is merged.
|
||||
struct SyncOptions {
|
||||
explicit SyncOptions() { reset(); }
|
||||
|
||||
QString folderA;
|
||||
QString folderB;
|
||||
QString excludeFilter; // CSV list of glob pattern(s)
|
||||
QString includeFilter; // CSV list of glob pattern(s)
|
||||
qint64 maxFileSize; // Bytes
|
||||
int direction; // SyncDirection
|
||||
int compareType; // SyncCompareType
|
||||
int flags; // SyncOptionFlags
|
||||
int dirFilterFlags; // QDir::Filters
|
||||
int logLevel; // QtMsgType (see ProgressWidget::addMessage())
|
||||
int sessionId; // Last run radio profile
|
||||
|
||||
void reset()
|
||||
{
|
||||
excludeFilter = QStringLiteral(".*,System Volume*");
|
||||
includeFilter.clear();
|
||||
direction = SYNC_A2B_B2A;
|
||||
compareType = OVERWR_NEWER_IF_DIFF;
|
||||
maxFileSize = 2 * 1024 * 1024;
|
||||
logLevel = QtWarningMsg;
|
||||
flags = OPT_RECURSIVE;
|
||||
dirFilterFlags = QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot;
|
||||
sessionId = -1;
|
||||
}
|
||||
|
||||
friend inline QDebug operator<<(QDebug debug, const SyncOptions &o) {
|
||||
return debug << "Incl:" << o.includeFilter << "Excl:" << o.excludeFilter << SyncDirection(o.direction) << SyncCompareType(o.compareType) << SyncOptionFlags(o.flags) << QDir::Filters(o.dirFilterFlags);
|
||||
}
|
||||
};
|
||||
|
||||
struct SyncStatus {
|
||||
int index;
|
||||
int count;
|
||||
int created;
|
||||
int updated;
|
||||
int skipped;
|
||||
int errored;
|
||||
void clear() { memset(this, 0, sizeof(SyncStatus)); }
|
||||
};
|
||||
|
||||
explicit SyncProcess(const SyncOptions & options);
|
||||
~SyncProcess();
|
||||
|
||||
public slots:
|
||||
void run();
|
||||
void stop();
|
||||
|
||||
signals:
|
||||
void started();
|
||||
void finished();
|
||||
void fileCountChanged(int count);
|
||||
void statusUpdate(const SyncProcess::SyncStatus & status);
|
||||
void statusMessage(const QString & text, const int & type = QtInfoMsg);
|
||||
void progressMessage(const QString & text, const int & type = QtInfoMsg, bool richText = false);
|
||||
|
||||
protected:
|
||||
enum FileFilterResult { FILE_ALLOW, FILE_OVERSIZE, FILE_EXCLUDE, FILE_LINK_IGNORE };
|
||||
|
||||
bool isStopRequsted();
|
||||
void finish();
|
||||
FileFilterResult fileFilter(const QFileInfo & fileInfo);
|
||||
QFileInfoList dirInfoList(const QString & directory);
|
||||
int getFilesCount(const QString & directory);
|
||||
void updateDir(const QString & source, const QString & destination);
|
||||
void pushDirEntries(const QFileInfo & fi, QMutableListIterator<QFileInfo> &it);
|
||||
bool updateEntry(const QString & entry, const QDir & source, const QDir & destination);
|
||||
void pause();
|
||||
void emitProgressMessage(const QString &text, int type);
|
||||
|
||||
SyncOptions m_options;
|
||||
SyncStatus m_stat;
|
||||
QReadWriteLock stopReqMutex;
|
||||
QString testRunStr;
|
||||
QVector<QRegularExpression> m_excludeFilters;
|
||||
QStringList m_dirIteratorFilters;
|
||||
QDir::Filters m_dirFilters;
|
||||
QDateTime m_startTime;
|
||||
unsigned long m_pauseTime;
|
||||
bool stopping;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(SyncProcess::SyncOptions)
|
||||
Q_DECLARE_TYPEINFO(SyncProcess::SyncOptions, Q_MOVABLE_TYPE);
|
||||
Q_DECLARE_METATYPE(SyncProcess::SyncStatus)
|
||||
Q_DECLARE_TYPEINFO(SyncProcess::SyncStatus, Q_PRIMITIVE_TYPE);
|
||||
@@ -0,0 +1,832 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "radiointerface.h"
|
||||
|
||||
#include "appdata.h"
|
||||
#include "progresswidget.h"
|
||||
#include "storage.h"
|
||||
#include "helpers.h"
|
||||
#include "firmwareinterface.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QFileDialog>
|
||||
|
||||
#include <chrono>
|
||||
#include <stdexcept>
|
||||
|
||||
#define TR(msg) QCoreApplication::translate("RadioInterface", msg)
|
||||
|
||||
constexpr int UF2_TRANSFER_SIZE {4 * 1024};
|
||||
constexpr char UF2_FIRMWARE_FILENAME[] {"CURRENT.UF2"};
|
||||
constexpr char UF2_INFO_FILENAME[] {"INFO_UF2.TXT"};
|
||||
constexpr char UF2_INDEX_FILENAME[] {"INDEX.HTM"};
|
||||
constexpr char UF2_NEW_FIRMWARE_FILENAME[] {"firmware.uf2"};
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
FirmwareReaderWorker::FirmwareReaderWorker(QObject *parent) :
|
||||
QThread(parent)
|
||||
{
|
||||
}
|
||||
|
||||
FirmwareReaderWorker::~FirmwareReaderWorker()
|
||||
{
|
||||
//qDebug() << "FirmwareReaderWorker destructor called";
|
||||
}
|
||||
|
||||
void FirmwareReaderWorker::run()
|
||||
{
|
||||
isUf2DeviceFound() ? runUf2() : runDfu();
|
||||
}
|
||||
|
||||
void FirmwareReaderWorker::runDfu()
|
||||
{
|
||||
try {
|
||||
auto device_filter = DfuDeviceFilter::empty_filter();
|
||||
auto devices = device_filter->find_devices();
|
||||
|
||||
if (devices.empty()) {
|
||||
throw std::runtime_error(tr("No DFU devices found").toStdString());
|
||||
} else if (devices.size() > 1) {
|
||||
throw std::runtime_error(tr("More than one DFU device found").toStdString());
|
||||
}
|
||||
|
||||
emit statusChanged("Resetting state...");
|
||||
auto &device = devices[0];
|
||||
device.reset_state();
|
||||
|
||||
auto addr = device.default_start_address();
|
||||
auto ctx = device.start_upload(addr, 0);
|
||||
|
||||
size_t total_length = ctx->get_length();
|
||||
size_t xfer_size = ctx->get_transfer_size();
|
||||
size_t bytes_uploaded = 0;
|
||||
|
||||
QByteArray data;
|
||||
while (bytes_uploaded < total_length) {
|
||||
auto rest_length = uint32_t(total_length - bytes_uploaded);
|
||||
auto single_xfer_size = std::min(uint32_t(xfer_size), rest_length);
|
||||
bytes_uploaded += single_xfer_size;
|
||||
|
||||
emit progressChanged(bytes_uploaded, total_length);
|
||||
emit statusChanged(tr("Reading %1 of %2").arg(bytes_uploaded).arg(total_length));
|
||||
data.append(ctx->upload(single_xfer_size));
|
||||
}
|
||||
|
||||
qDebug() << "Reading done";
|
||||
emit statusChanged("Reading done");
|
||||
emit complete(data);
|
||||
|
||||
// TODO: handle shouldStop
|
||||
|
||||
} catch (const std::exception &e) {
|
||||
emit error(QString("DFU failed: %1").arg(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
void FirmwareReaderWorker::runUf2()
|
||||
{
|
||||
try {
|
||||
QString path = findMassStoragePath(UF2_FIRMWARE_FILENAME);
|
||||
QStorageInfo si(path);
|
||||
QFile fw(path);
|
||||
char buf[UF2_TRANSFER_SIZE];
|
||||
const int blockstotal = (fw.size() + UF2_TRANSFER_SIZE - 1) / UF2_TRANSFER_SIZE;
|
||||
emit progressChanged(0, blockstotal);
|
||||
emit statusChanged(tr("Reading..."));
|
||||
|
||||
qDebug() << "Reading started - file:" << fw.fileName()
|
||||
<< "size:" << fw.size()
|
||||
<< "blocks:" << blockstotal;
|
||||
|
||||
QByteArray data;
|
||||
if (fw.open(QIODevice::ReadOnly)) {
|
||||
int blockcnt = 0;
|
||||
qint64 bytesread = 0;
|
||||
int read = fw.read(buf, UF2_TRANSFER_SIZE);
|
||||
if (read == 0 && fw.size() > 0) {
|
||||
throw std::runtime_error(tr("Error reading %1 (reason: no data read)")
|
||||
.arg(fw.fileName()).toStdString());
|
||||
} else if (read < 0) {
|
||||
throw std::runtime_error(tr("Error reading %1 (reason: %2)")
|
||||
.arg(fw.fileName())
|
||||
.arg(fw.errorString()).toStdString());
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
// qDebug() << "read:" << read;
|
||||
bytesread += read;
|
||||
blockcnt++;
|
||||
data.append(buf, read);
|
||||
emit progressChanged(blockcnt, blockstotal);
|
||||
emit statusChanged(tr("Read block %1 of %2").arg(blockcnt).arg(blockstotal));
|
||||
read = fw.read(buf, UF2_TRANSFER_SIZE);
|
||||
} while (read > 0);
|
||||
|
||||
if (read < 0) {
|
||||
data.clear();
|
||||
throw std::runtime_error(tr("Error reading %1 (reason: %2)")
|
||||
.arg(fw.fileName())
|
||||
.arg(fw.errorString()).toStdString());
|
||||
} else if (bytesread < fw.size()) {
|
||||
data.clear();
|
||||
throw std::runtime_error(tr("Error reading %1 (reason: read %2 of %3)")
|
||||
.arg(fw.fileName())
|
||||
.arg(bytesread)
|
||||
.arg(fw.size()).toStdString());
|
||||
}
|
||||
|
||||
} else {
|
||||
throw std::runtime_error(tr("Cannot open %1 (reason: %2)")
|
||||
.arg(fw.fileName())
|
||||
.arg(fw.errorString()).toStdString());
|
||||
}
|
||||
|
||||
fw.close();
|
||||
qDebug() << "Reading done";
|
||||
emit statusChanged("Reading done");
|
||||
emit complete(data);
|
||||
|
||||
} catch (const std::exception &e) {
|
||||
emit error(QString("UF2 failed: %1").arg(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
FirmwareWriterWorker::FirmwareWriterWorker(const QByteArray &data, QObject *parent) :
|
||||
QThread(parent),
|
||||
firmwareData(data)
|
||||
{
|
||||
}
|
||||
|
||||
FirmwareWriterWorker::~FirmwareWriterWorker()
|
||||
{
|
||||
//qDebug() << "FirmwareWriterWorker destructor called";
|
||||
}
|
||||
|
||||
void FirmwareWriterWorker::run()
|
||||
{
|
||||
isUf2DeviceFound() ? runUf2() : runDfu();
|
||||
}
|
||||
|
||||
void FirmwareWriterWorker::runUf2()
|
||||
{
|
||||
try {
|
||||
QString path = findMassStoragePath(UF2_FIRMWARE_FILENAME, true);
|
||||
if (path.isEmpty()) {
|
||||
throw std::runtime_error(tr("Cannot find USB device containing %1")
|
||||
.arg(UF2_FIRMWARE_FILENAME).toStdString());
|
||||
}
|
||||
|
||||
QStorageInfo si(path);
|
||||
if (si.bytesAvailable() < firmwareData.size()) {
|
||||
throw std::runtime_error(tr("Insufficient free space on %1 to write new firmware")
|
||||
.arg(QDir::toNativeSeparators(path)).toStdString());
|
||||
}
|
||||
|
||||
QFile newfw(Helpers::concatPath(path, UF2_NEW_FIRMWARE_FILENAME));
|
||||
int blockstotal = (firmwareData.size() + UF2_TRANSFER_SIZE - 1) / UF2_TRANSFER_SIZE;
|
||||
emit progressChanged(0, blockstotal);
|
||||
emit statusChanged(tr("Writing..."));
|
||||
|
||||
if (firmwareData.size() == 0)
|
||||
throw std::runtime_error(tr("No data to write to new firmware file").toStdString());
|
||||
|
||||
qDebug() << "Writing started - file:"
|
||||
<< newfw.fileName()
|
||||
<< "size:" << firmwareData.size()
|
||||
<< "blocks:" << blockstotal;
|
||||
|
||||
if (newfw.open(QIODevice::ReadWrite)) {
|
||||
int blockcnt = 0;
|
||||
qint64 byteswritten = 0;
|
||||
QByteArray ba = firmwareData.mid(blockcnt * UF2_TRANSFER_SIZE, UF2_TRANSFER_SIZE);
|
||||
|
||||
do
|
||||
{
|
||||
qint64 written = newfw.write(ba, ba.size());
|
||||
if (written < 0) {
|
||||
throw std::runtime_error(tr("Error writing %1 (reason: %2)")
|
||||
.arg(QDir::toNativeSeparators(newfw.fileName()))
|
||||
.arg(newfw.errorString()).toStdString());
|
||||
} else if (written < ba.size()) {
|
||||
throw std::runtime_error(tr("Error writing block to %1 (reason: bytes written %2 of %3)")
|
||||
.arg(QDir::toNativeSeparators(newfw.fileName()))
|
||||
.arg(written)
|
||||
.arg(ba.size()).toStdString());
|
||||
}
|
||||
|
||||
newfw.flush();
|
||||
byteswritten += written;
|
||||
blockcnt++;
|
||||
emit progressChanged(blockcnt, blockstotal);
|
||||
emit statusChanged(tr("Writing block %1 of %2").arg(blockcnt).arg(blockstotal));
|
||||
|
||||
ba.clear(); // just to be on the safe side
|
||||
ba = firmwareData.mid(blockcnt * UF2_TRANSFER_SIZE, UF2_TRANSFER_SIZE);
|
||||
} while (ba.size() > 0);
|
||||
|
||||
if (byteswritten < firmwareData.size()) {
|
||||
throw std::runtime_error(tr("Error writing %1 (reason: written %2 of %3)")
|
||||
.arg(QDir::toNativeSeparators(newfw.fileName()))
|
||||
.arg(byteswritten)
|
||||
.arg(firmwareData.size()).toStdString());
|
||||
}
|
||||
|
||||
} else {
|
||||
throw std::runtime_error(tr("Cannot open %1 (reason: %2)")
|
||||
.arg(QDir::toNativeSeparators(newfw.fileName()))
|
||||
.arg(newfw.errorString()).toStdString());
|
||||
}
|
||||
|
||||
newfw.close();
|
||||
qDebug() << "Writing done";
|
||||
emit statusChanged("Writing done");
|
||||
emit complete();
|
||||
|
||||
} catch (const std::exception &e) {
|
||||
emit error(QString("UF2 failed: %1").arg(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
void FirmwareWriterWorker::runDfu()
|
||||
{
|
||||
try {
|
||||
auto device_filter = DfuDeviceFilter::empty_filter();
|
||||
auto devices = device_filter->find_devices();
|
||||
|
||||
if (devices.empty()) {
|
||||
throw std::runtime_error(tr("No DFU devices found").toStdString());
|
||||
} else if (devices.size() > 1) {
|
||||
throw std::runtime_error(tr("More than one DFU device found").toStdString());
|
||||
}
|
||||
|
||||
emit statusChanged("Resetting state...");
|
||||
auto &device = devices[0];
|
||||
device.reset_state();
|
||||
|
||||
SliceU8 buffer_slice((const uint8_t *)firmwareData.constData(),
|
||||
firmwareData.size());
|
||||
|
||||
if (!is_uf2_payload(buffer_slice)) {
|
||||
auto addr = device.default_start_address();
|
||||
writeRegion(device, addr, buffer_slice);
|
||||
} else {
|
||||
writeUf2(device, buffer_slice);
|
||||
}
|
||||
|
||||
device.leave();
|
||||
|
||||
emit statusChanged("Flashing done");
|
||||
emit complete();
|
||||
|
||||
// TODO: handle shouldStop
|
||||
|
||||
} catch (const std::exception &e) {
|
||||
emit error(QString("DFU failed: %1").arg(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
void FirmwareWriterWorker::writeUf2(DfuDevice &device, const SliceU8 &data)
|
||||
{
|
||||
auto range_it = UF2RangeIterator::from_slice(data);
|
||||
auto addr_range = UF2AddressRange::new_empty();
|
||||
|
||||
while (range_it->next(*addr_range)) {
|
||||
auto addr = addr_range->start_address();
|
||||
const auto &payload = addr_range->payload();
|
||||
|
||||
uint32_t reboot_address = 0;
|
||||
|
||||
if (addr_range->reboot_address(reboot_address)) {
|
||||
rebootAndRediscover(device, addr, payload, reboot_address, 30s);
|
||||
} else {
|
||||
writeRegion(device, addr, payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FirmwareWriterWorker::writeRegion(const DfuDevice &device, uint32_t addr,
|
||||
const SliceU8 &data)
|
||||
{
|
||||
auto start_address = addr;
|
||||
auto end_address = start_address + data.size() - 1;
|
||||
|
||||
auto ctx = device.start_download(start_address, end_address);
|
||||
auto erase_pages = ctx->get_erase_pages();
|
||||
auto pages = erase_pages.size();
|
||||
|
||||
for (size_t i = 0; i < pages; i++) {
|
||||
updateEraseStatus(i + 1, pages);
|
||||
ctx->page_erase(erase_pages[i]);
|
||||
}
|
||||
|
||||
size_t bytes_downloaded = 0;
|
||||
auto data_ptr = data.data();
|
||||
auto xfer_size = ctx->get_transfer_size();
|
||||
|
||||
while (bytes_downloaded < data.size()) {
|
||||
auto single_xfer_size =
|
||||
std::min(uint32_t(xfer_size), uint32_t(data.size() - bytes_downloaded));
|
||||
bytes_downloaded += single_xfer_size;
|
||||
updateDownloadStatus(bytes_downloaded, data.size());
|
||||
ctx->download(addr, SliceU8(data_ptr, single_xfer_size));
|
||||
addr += single_xfer_size;
|
||||
data_ptr += single_xfer_size;
|
||||
}
|
||||
}
|
||||
|
||||
void FirmwareWriterWorker::updateEraseStatus(size_t page, size_t pages)
|
||||
{
|
||||
emit progressChanged(page, pages);
|
||||
emit statusChanged(tr("Erasing page %1 of %2").arg(page).arg(pages));
|
||||
}
|
||||
|
||||
void FirmwareWriterWorker::updateDownloadStatus(size_t bytes, size_t total)
|
||||
{
|
||||
emit progressChanged(bytes, total);
|
||||
emit statusChanged(tr("Writing %1 of %2").arg(bytes).arg(total));
|
||||
}
|
||||
|
||||
template <typename Duration>
|
||||
void FirmwareWriterWorker::rebootAndRediscover(DfuDevice &device, uint32_t addr,
|
||||
const SliceU8 &data,
|
||||
uint32_t reboot_addr,
|
||||
Duration timeout)
|
||||
{
|
||||
emit statusChanged(tr("Rebooting into DFU..."));
|
||||
emit progressChanged(0, 2);
|
||||
|
||||
device.reboot(addr, data, reboot_addr);
|
||||
emit progressChanged(1, 2);
|
||||
|
||||
emit statusChanged(tr("Waiting for device to reconnect..."));
|
||||
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
|
||||
while (std::chrono::steady_clock::now() - start < timeout) {
|
||||
if (device.rediscover()) {
|
||||
emit statusChanged(tr("Device reconnected"));
|
||||
emit progressChanged(2, 2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw std::runtime_error(
|
||||
tr("Timeout while reconnecting to device").toStdString());
|
||||
}
|
||||
|
||||
template <typename Worker>
|
||||
void connectProgress(Worker *worker, ProgressWidget *progress)
|
||||
{
|
||||
// lock the progress dialog for as long as the thread is running
|
||||
progress->connect(worker, &QThread::started, progress,
|
||||
[progress]() { progress->lock(true); });
|
||||
|
||||
progress->connect(worker, &QThread::finished, progress,
|
||||
[progress]() { progress->lock(false); });
|
||||
|
||||
// delete worker once the thread is finished
|
||||
progress->connect(worker, &QThread::finished, worker, &QObject::deleteLater);
|
||||
|
||||
// progress and status handling
|
||||
progress->connect(worker, &Worker::progressChanged, progress,
|
||||
[progress](int val, int max) {
|
||||
if (progress->maximum() != max)
|
||||
progress->setMaximum(max);
|
||||
progress->setValue(val);
|
||||
});
|
||||
|
||||
progress->connect(worker, &Worker::statusChanged, progress,
|
||||
[progress](const QString& status) {
|
||||
progress->addMessage(status);
|
||||
progress->setInfo(status);
|
||||
});
|
||||
|
||||
progress->connect(worker, &Worker::error, progress,
|
||||
[progress](const QString& status) {
|
||||
progress->addMessage(status, QtFatalMsg);
|
||||
progress->setInfo(status);
|
||||
});
|
||||
}
|
||||
|
||||
bool readFirmware(const std::function<void(const QByteArray &)>& onComplete,
|
||||
const std::function<void(const QString &)>& onError,
|
||||
ProgressWidget *progress)
|
||||
{
|
||||
auto worker = std::make_unique<FirmwareReaderWorker>();
|
||||
connectProgress(worker.get(), progress);
|
||||
|
||||
// connect closures
|
||||
progress->connect(worker.get(), &FirmwareReaderWorker::complete, progress, onComplete);
|
||||
progress->connect(worker.get(), &FirmwareReaderWorker::error, progress, onError);
|
||||
|
||||
// now start it!
|
||||
worker.release()->start();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool readFirmware(const std::function<void(const QByteArray &)>& onComplete,
|
||||
ProgressWidget *progress)
|
||||
{
|
||||
auto worker = std::make_unique<FirmwareReaderWorker>(progress);
|
||||
connectProgress(worker.get(), progress);
|
||||
|
||||
// write data to file on success
|
||||
progress->connect(worker.get(), &FirmwareReaderWorker::complete, progress, onComplete);
|
||||
|
||||
// now start it!
|
||||
worker.release()->start();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool readFirmware(const QString &filename, ProgressWidget *progress)
|
||||
{
|
||||
QFile::remove(filename);
|
||||
return readFirmware(
|
||||
[filename](const QByteArray &data) {
|
||||
QFile file(filename);
|
||||
if (!file.open(QFile::WriteOnly)) {
|
||||
qDebug() << "Unable to write to " << filename;
|
||||
} else {
|
||||
file.write(data);
|
||||
file.close();
|
||||
qDebug() << "Firmware written to " << filename;
|
||||
}
|
||||
},
|
||||
progress);
|
||||
}
|
||||
|
||||
bool readFirmware(QByteArray &data, ProgressWidget *progress)
|
||||
{
|
||||
return readFirmware([&data](const QByteArray &_data) { data = _data; },
|
||||
progress);
|
||||
}
|
||||
|
||||
bool writeFirmware(const QString &filename, ProgressWidget *progress)
|
||||
{
|
||||
QFile f(filename);
|
||||
if (!f.open(QIODeviceBase::ReadOnly)) {
|
||||
QMessageBox::critical(nullptr, TR("Write Firmware"),
|
||||
TR("Cannot open file '%1': %2")
|
||||
.arg(QDir::toNativeSeparators(filename))
|
||||
.arg(f.errorString()));
|
||||
}
|
||||
|
||||
auto data = f.readAll();
|
||||
f.close();
|
||||
|
||||
return writeFirmware(data, progress);
|
||||
}
|
||||
|
||||
bool writeFirmware(const QByteArray &data, ProgressWidget *progress)
|
||||
{
|
||||
auto worker = std::make_unique<FirmwareWriterWorker>(data, progress);
|
||||
connectProgress(worker.get(), progress);
|
||||
|
||||
// now start it!
|
||||
worker.release()->start();
|
||||
return true;
|
||||
}
|
||||
|
||||
QString printDevicesInfo(const Vec<DfuDevice> &devices)
|
||||
{
|
||||
QString ret;
|
||||
for (const auto &device : devices) {
|
||||
auto dev_info = device.device_info();
|
||||
ret.append(QString("%1:%2: %3 (%4)\n").arg(QString::number(dev_info.vendor_id, 16))
|
||||
.arg(QString::number(dev_info.product_id, 16))
|
||||
.arg(dev_info.product_string.c_str())
|
||||
.arg(QString::number(device.default_start_address(), 16)));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
QString getDevicesInfo()
|
||||
{
|
||||
try {
|
||||
auto device_filter = DfuDeviceFilter::empty_filter();
|
||||
auto devices = device_filter->find_devices();
|
||||
if (devices.empty()) {
|
||||
return QString("No DFU devices found");
|
||||
}
|
||||
|
||||
return printDevicesInfo(devices);
|
||||
|
||||
} catch (const std::exception& e) {
|
||||
return QString("Error: %1").arg(e.what());
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool readSettings(const QString &filename, ProgressWidget *progress)
|
||||
{
|
||||
QFile file(filename);
|
||||
if (file.exists() && !file.remove()) {
|
||||
QMessageBox::warning(nullptr, CPN_STR_TTL_ERROR,
|
||||
TR("Could not delete temporary file: %1")
|
||||
.arg(QDir::toNativeSeparators(filename)));
|
||||
return false;
|
||||
}
|
||||
|
||||
return readSettingsSDCard(filename, progress);
|
||||
}
|
||||
|
||||
bool readSettingsSDCard(const QString &filename, ProgressWidget *progress,
|
||||
bool fromRadio)
|
||||
{
|
||||
QString radioPath;
|
||||
if (fromRadio) {
|
||||
radioPath = findMassStoragePath("RADIO", true, progress);
|
||||
qDebug() << "Searching for SD card, found" << radioPath;
|
||||
} else {
|
||||
radioPath = g.currentProfile().sdPath();
|
||||
if (!QFile::exists(radioPath % "/RADIO"))
|
||||
radioPath.clear();
|
||||
}
|
||||
|
||||
if (radioPath.isEmpty()) {
|
||||
QMessageBox::critical(progress, CPN_STR_TTL_ERROR, TR("Unable to find SD card!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
RadioData radioData;
|
||||
Storage inputStorage(radioPath);
|
||||
|
||||
if (!inputStorage.load(radioData)) {
|
||||
QString errorMsg = inputStorage.error();
|
||||
if (errorMsg.isEmpty())
|
||||
errorMsg = TR("Failed to read Models and Settings from")
|
||||
% QDir::toNativeSeparators(radioPath);
|
||||
|
||||
QMessageBox::critical(progress, CPN_STR_TTL_ERROR, errorMsg);
|
||||
return false;
|
||||
}
|
||||
|
||||
Storage outputStorage(filename);
|
||||
if (!outputStorage.write(radioData)) {
|
||||
QMessageBox::critical(progress, CPN_STR_TTL_ERROR,
|
||||
TR("Failed to write Models and Setting file") % " "
|
||||
% QDir::toNativeSeparators(filename));
|
||||
return false;
|
||||
}
|
||||
|
||||
return QFileInfo(filename).exists();
|
||||
}
|
||||
|
||||
QString findMassStoragePath(const QString &filename, bool onlyPath, ProgressWidget *progress)
|
||||
{
|
||||
QString foundPath;
|
||||
QString foundProbefile;
|
||||
int found = 0;
|
||||
// Linux: "vfat"; macOS: "msdos" or "lifs"; Win: "FAT32"
|
||||
QRegularExpression fstypeRe("^(v?fat|msdos|lifs)",
|
||||
QRegularExpression::CaseInsensitiveOption);
|
||||
|
||||
foreach (const QStorageInfo &si, QStorageInfo::mountedVolumes()) {
|
||||
if (!si.isReady() || si.isReadOnly() || !QString(si.fileSystemType()).contains(fstypeRe))
|
||||
continue;
|
||||
|
||||
qDebug() << "device:" << si.device()
|
||||
<< "type:" << si.fileSystemType()
|
||||
<< "block size:" << si.blockSize()
|
||||
<< "capacity:" << si.bytesTotal() / 1000 / 1000 << "MB"
|
||||
<< "available:" << si.bytesFree() / 1000/ 1000 << "MB"
|
||||
<< "root path:" << si.rootPath();
|
||||
|
||||
QString temppath = si.rootPath();
|
||||
QString probefile = Helpers::concatPath(temppath, filename);
|
||||
qDebug() << "Searching for" << probefile;
|
||||
if (QFile::exists(probefile)) {
|
||||
found++;
|
||||
foundPath = temppath;
|
||||
foundProbefile = probefile;
|
||||
qDebug() << probefile << "found";
|
||||
}
|
||||
}
|
||||
|
||||
if (found == 1) {
|
||||
return onlyPath ? foundPath : foundProbefile;
|
||||
} else if (found > 1) {
|
||||
QMessageBox::critical(progress, CPN_STR_TTL_ERROR, QDir::toNativeSeparators(filename)
|
||||
% " " % TR("found in multiple locations"));
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString getFirmwareFilesFilter()
|
||||
{
|
||||
return isUf2DeviceFound() ? QString(UF2_FILES_FILTER) : QString(FIRMWARE_FILES_FILTER);
|
||||
}
|
||||
|
||||
Uf2Info getUf2Info()
|
||||
{
|
||||
Uf2Info info;
|
||||
QString path = findMassStoragePath(UF2_INFO_FILENAME);
|
||||
if (path.isEmpty())
|
||||
return info;
|
||||
|
||||
QFile file(path);
|
||||
if (!file.open(QFile::ReadOnly)) {
|
||||
QMessageBox::critical(nullptr, CPN_STR_TTL_ERROR,
|
||||
TR("Error opening file %1:\n%2.")
|
||||
.arg(QDir::toNativeSeparators(path)).arg(file.errorString()));
|
||||
return info;
|
||||
}
|
||||
|
||||
QByteArray filedata;
|
||||
const char *version_label = "UF2 Bootloader";
|
||||
const char *board_label = "Board-ID:";
|
||||
const char *date_label = "Date:";
|
||||
|
||||
filedata = file.readLine();
|
||||
|
||||
do
|
||||
{
|
||||
if (filedata.startsWith(version_label))
|
||||
info.version = filedata.mid(QString(version_label).size()).trimmed();
|
||||
else if (filedata.startsWith(board_label))
|
||||
info.board = filedata.mid(QString(board_label).size()).trimmed();
|
||||
else if (filedata.startsWith(date_label))
|
||||
info.date = filedata.mid(QString(date_label).size()).trimmed();
|
||||
|
||||
filedata = file.readLine();
|
||||
|
||||
} while (!filedata.isEmpty());
|
||||
|
||||
file.close();
|
||||
|
||||
qDebug() << "UF2 information - version:" << info.version
|
||||
<< "board:" << info.board
|
||||
<< "date:" << info.date;
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
bool isUf2DeviceFound()
|
||||
{
|
||||
return !findMassStoragePath("INFO_UF2.TXT", false).isEmpty();
|
||||
}
|
||||
|
||||
bool isDfuDeviceFound()
|
||||
{
|
||||
try {
|
||||
auto device_filter = DfuDeviceFilter::empty_filter();
|
||||
auto devices = device_filter->find_devices();
|
||||
if (devices.empty()) {
|
||||
return false;
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool isRadioConnected()
|
||||
{
|
||||
return isUf2DeviceFound() || isDfuDeviceFound();
|
||||
}
|
||||
|
||||
bool writeFirmwareToFile(QWidget *parent, const QByteArray &data, ProgressWidget *progress, bool promptForFile)
|
||||
{
|
||||
QString msg(TR("Writing radio firmware to file starting..."));
|
||||
progress->setInfo(msg);
|
||||
progress->addMessage(msg);
|
||||
|
||||
FirmwareInterface fw(data);
|
||||
if (!fw.isValid()) {
|
||||
QString errMsg(TR("Firmware is not invalid"));
|
||||
progress->addMessage(errMsg, QtFatalMsg);
|
||||
progress->setInfo(errMsg);
|
||||
return false;
|
||||
}
|
||||
|
||||
QString backupDir;
|
||||
|
||||
if (g.currentProfile().getVariantFromType() == fw.getFlavour()) {
|
||||
progress->addMessage(TR("Current profile firmware type matches radio"));
|
||||
backupDir = g.currentProfile().pBackupDir();
|
||||
}
|
||||
else {
|
||||
// try to find a profile but there could be more than one profile for same variant
|
||||
// if more than one take safer approach and use global
|
||||
progress->addMessage(TR("Searching profiles for firmware type..."));
|
||||
int cnt = 0;
|
||||
int profId = 0;
|
||||
QMap<int, QString> map;
|
||||
map = g.getActiveProfiles();
|
||||
if (map.size() > 0) {
|
||||
QMapIterator<int, QString> i(map);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
if (g.getProfile(i.key()).getVariantFromType() == fw.getFlavour()) {
|
||||
progress->addMessage(TR("Firmware type match found in profile %1 %2")
|
||||
.arg(QString::number(i.key()))
|
||||
.arg(i.value()));
|
||||
profId = i.key();
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
progress->addMessage(TR("%1 matches found. Using profile %2 %3")
|
||||
.arg(QString::number(cnt))
|
||||
.arg(QString::number(profId))
|
||||
.arg(g.getProfile(profId).name()));
|
||||
|
||||
if (cnt > 0)
|
||||
backupDir = g.getProfile(profId).pBackupDir();
|
||||
}
|
||||
}
|
||||
|
||||
if (backupDir.isEmpty())
|
||||
backupDir = g.backupDir();
|
||||
|
||||
progress->addMessage(TR("Backup directory: %1").arg(QDir::toNativeSeparators(backupDir)));
|
||||
|
||||
// include time in file name as there could be multiple backups in a day
|
||||
QString filePath = QString("%1/fw-%2-%3-%4.%5")
|
||||
.arg(backupDir.replace("\\", "/")) // for Windows
|
||||
.arg(fw.getFlavour())
|
||||
.arg(QDate(QDate::currentDate()).toString("yyyyMMdd"))
|
||||
.arg(QTime(QTime::currentTime()).toString("HHmmss"))
|
||||
.arg(fw.typeFileExtn());
|
||||
|
||||
if (promptForFile) {
|
||||
filePath = QFileDialog::getSaveFileName(parent, TR("Save Firmware to File"),
|
||||
filePath, getFirmwareFilesFilter());
|
||||
|
||||
if (filePath.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
} else if (backupDir.isEmpty()) {
|
||||
progress->addMessage(TR("Backup directory not configured for profile or application"),
|
||||
QtFatalMsg);
|
||||
return false;
|
||||
} else if (!QFileInfo::exists(backupDir)) {
|
||||
progress->addMessage(TR("Backup directory does not exist: %1")
|
||||
.arg(QDir::toNativeSeparators(backupDir)), QtFatalMsg);
|
||||
return false;
|
||||
}
|
||||
|
||||
progress->addMessage(TR("Writing firmware to: %1").arg(QDir::toNativeSeparators(filePath)));
|
||||
|
||||
QFile f(filePath);
|
||||
if (!f.open(QIODevice::ReadWrite)) {
|
||||
progress->addMessage(TR("Error opening file for writing: %1 (reason: %2)")
|
||||
.arg(QDir::toNativeSeparators(f.fileName()))
|
||||
.arg(f.errorString()), QtFatalMsg);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (f.write(data) <= 0) {
|
||||
progress->addMessage(TR("Error writing to file: %1 (reason: %2)")
|
||||
.arg(QDir::toNativeSeparators(f.fileName()))
|
||||
.arg(f.errorString()), QtFatalMsg);
|
||||
f.close();
|
||||
return false;
|
||||
} else {
|
||||
msg = TR("Writing radio firmware to file finished");
|
||||
progress->addMessage(msg);
|
||||
progress->setInfo(msg);
|
||||
}
|
||||
|
||||
f.close();
|
||||
return true;
|
||||
}
|
||||
QStringList dfuFileExtensions()
|
||||
{
|
||||
return QStringList() << "bin" << "uf2";
|
||||
}
|
||||
|
||||
QStringList uf2FileExtensions()
|
||||
{
|
||||
return QStringList() << "uf2";
|
||||
}
|
||||
|
||||
QStringList firmwareFileExtensions()
|
||||
{
|
||||
return dfuFileExtensions();
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "rs_dfu.h"
|
||||
|
||||
#include <QThread>
|
||||
#include <QString>
|
||||
|
||||
using SliceU8 = rust::Slice<const uint8_t>;
|
||||
using ::rust::Vec;
|
||||
|
||||
class FirmwareReaderWorker : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FirmwareReaderWorker(QObject *parent = nullptr);
|
||||
~FirmwareReaderWorker();
|
||||
|
||||
protected:
|
||||
void run() override;
|
||||
|
||||
signals:
|
||||
void progressChanged(int value, int total);
|
||||
void statusChanged(const QString &status);
|
||||
void error(const QString &error);
|
||||
void complete(const QByteArray& data);
|
||||
|
||||
private:
|
||||
void runDfu();
|
||||
void runUf2();
|
||||
};
|
||||
|
||||
class FirmwareWriterWorker : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
QByteArray firmwareData;
|
||||
|
||||
public:
|
||||
explicit FirmwareWriterWorker(const QByteArray &data, QObject *parent = nullptr);
|
||||
~FirmwareWriterWorker();
|
||||
|
||||
protected:
|
||||
void run() override;
|
||||
|
||||
signals:
|
||||
void progressChanged(int value, int total);
|
||||
void statusChanged(const QString &status);
|
||||
void error(const QString &error);
|
||||
void complete();
|
||||
|
||||
private:
|
||||
void writeUf2(DfuDevice &device, const SliceU8 &data);
|
||||
void writeRegion(const DfuDevice &device, uint32_t addr, const SliceU8 &data);
|
||||
void updateEraseStatus(size_t page, size_t pages);
|
||||
void updateDownloadStatus(size_t bytes, size_t total);
|
||||
void runDfu();
|
||||
void runUf2();
|
||||
|
||||
template <typename Duration>
|
||||
void rebootAndRediscover(DfuDevice &device, uint32_t addr,
|
||||
const SliceU8 &data, uint32_t reboot_addr,
|
||||
Duration timeout);
|
||||
};
|
||||
|
||||
|
||||
class ProgressWidget;
|
||||
|
||||
// TODO make a class
|
||||
struct Uf2Info {
|
||||
QString version;
|
||||
QString board;
|
||||
QString date;
|
||||
};
|
||||
|
||||
QString findMassStoragePath(const QString &filename, bool onlyPath = false, ProgressWidget *progress = nullptr);
|
||||
|
||||
bool readFirmware(const std::function<void(const QByteArray &)>& onComplete,
|
||||
const std::function<void(const QString &)>& onError,
|
||||
ProgressWidget *progress);
|
||||
|
||||
bool readFirmware(QByteArray &data, ProgressWidget *progress);
|
||||
bool readFirmware(const QString &filename, ProgressWidget *progress);
|
||||
|
||||
bool writeFirmware(const QByteArray &data, ProgressWidget *progress);
|
||||
bool writeFirmware(const QString &filename, ProgressWidget *progress);
|
||||
|
||||
bool readSettings(const QString &filename, ProgressWidget *progress);
|
||||
bool readSettingsSDCard(const QString &filename, ProgressWidget *progress, bool fromRadio = true);
|
||||
|
||||
bool writeSettings(const QString &filename, ProgressWidget *progress);
|
||||
|
||||
QString printDevicesInfo(const Vec<DfuDevice> &devices);
|
||||
QString getDevicesInfo();
|
||||
QString getFirmwareFilesFilter();
|
||||
Uf2Info getUf2Info();
|
||||
bool isDfuDeviceFound();
|
||||
bool isUf2DeviceFound();
|
||||
bool isRadioConnected();
|
||||
bool writeFirmwareToFile(QWidget *parent, const QByteArray &data, ProgressWidget *progress, bool promptForFile = false);
|
||||
QStringList dfuFileExtensions();
|
||||
QStringList uf2FileExtensions();
|
||||
QStringList firmwareFileExtensions();
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
class SplashLabel : public QLabel
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
explicit SplashLabel(QDialog * parent = 0) : QLabel(parent) {}
|
||||
|
||||
virtual void setId(int labelindex) { index = labelindex; }
|
||||
virtual int getId() { return index; }
|
||||
|
||||
protected:
|
||||
|
||||
virtual void mousePressEvent(QMouseEvent * event)
|
||||
{
|
||||
if (event->type() == QEvent::MouseButtonDblClick) {
|
||||
emit clicked(Qt::Key_Enter);
|
||||
}
|
||||
else {
|
||||
emit clicked(Qt::Key_Select);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void mouseReleaseEvent(QMouseEvent * event)
|
||||
{
|
||||
setFocus();
|
||||
}
|
||||
|
||||
signals:
|
||||
void clicked(int button);
|
||||
|
||||
private:
|
||||
int index;
|
||||
};
|
||||
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "splashlibrarydialog.h"
|
||||
#include "ui_splashlibrarydialog.h"
|
||||
#include "appdata.h"
|
||||
#include "helpers.h"
|
||||
#include "firmwareinterface.h"
|
||||
#include "helpers.h"
|
||||
|
||||
SplashLibraryDialog::SplashLibraryDialog(QWidget *parent, QString * filename):
|
||||
QDialog(parent),
|
||||
ui(new Ui::SplashLibraryDialog),
|
||||
splashFileName(filename)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setWindowIcon(CompanionIcon("library.png"));
|
||||
ui->nextPage->setIcon(CompanionIcon("arrow-right.png"));
|
||||
ui->prevPage->setIcon(CompanionIcon("arrow-left.png"));
|
||||
page = 0;
|
||||
getFileList();
|
||||
|
||||
if (imageList.size() > 20)
|
||||
ui->nextPage->setEnabled(true);
|
||||
|
||||
setupPage(page);
|
||||
|
||||
foreach(SplashLabel *sl, findChildren<SplashLabel *>()) {
|
||||
connect(sl, &SplashLabel::clicked, this, &SplashLibraryDialog::imageClicked);
|
||||
}
|
||||
|
||||
connect(ui->nextPage, &QPushButton::clicked, this, &SplashLibraryDialog::nextPageClicked);
|
||||
connect(ui->prevPage, &QPushButton::clicked, this, &SplashLibraryDialog::prevPageClicked);
|
||||
}
|
||||
|
||||
SplashLibraryDialog::~SplashLibraryDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void SplashLibraryDialog::setupPage(int page)
|
||||
{
|
||||
SplashLabel *sl[] = { ui->FwImage_01, ui->FwImage_02, ui->FwImage_03, ui->FwImage_04 ,
|
||||
ui->FwImage_05, ui->FwImage_06, ui->FwImage_07, ui->FwImage_08 ,
|
||||
ui->FwImage_09, ui->FwImage_10, ui->FwImage_11, ui->FwImage_12 ,
|
||||
ui->FwImage_13, ui->FwImage_14, ui->FwImage_15, ui->FwImage_16 ,
|
||||
ui->FwImage_17, ui->FwImage_18, ui->FwImage_19, ui->FwImage_20 };
|
||||
|
||||
for(int i = 0; i < 20; i++) {
|
||||
if ((i + 20 * page) < imageList.size()) {
|
||||
QImage image(imageList.at(i + 20 * page));
|
||||
if (!image.isNull()) {
|
||||
sl[i]->setPixmap(makePixMap(image));
|
||||
sl[i]->setEnabled(true);
|
||||
sl[i]->setId((i + 20 * page));
|
||||
sl[i]->setStyleSheet("border:1px solid; border-color:#999999;");
|
||||
} else {
|
||||
sl[i]->clear();
|
||||
sl[i]->setDisabled(true);
|
||||
sl[i]->setStyleSheet("border:1px;");
|
||||
sl[i]->setId(-1);
|
||||
}
|
||||
} else {
|
||||
sl[i]->clear();
|
||||
sl[i]->setDisabled(true);
|
||||
sl[i]->setStyleSheet("border:1px;");
|
||||
sl[i]->setId(-1);
|
||||
}
|
||||
}
|
||||
setWindowTitle(tr("Splash Library - page %1 of %2").arg(page + 1).arg(ceil((float) imageList.size() / 20.0)));
|
||||
}
|
||||
|
||||
void SplashLibraryDialog::getFileList()
|
||||
{
|
||||
imageList.clear();
|
||||
if (g.embedSplashes()) {
|
||||
const QString imgLocn(":/images/library");
|
||||
QDir myRes(imgLocn);
|
||||
QStringList tmp = myRes.entryList();
|
||||
|
||||
for (int i = 0; i < tmp.size(); i++) {
|
||||
QFileInfo fileInfo(tmp.at(i));
|
||||
imageList.append(imgLocn + "/" + fileInfo.fileName());
|
||||
}
|
||||
}
|
||||
|
||||
QString libraryPath = g.libDir();
|
||||
|
||||
if (!libraryPath.isEmpty()) {
|
||||
if (QDir(libraryPath).exists()) {
|
||||
QStringList supportedImageFormats;
|
||||
for (int formatIndex = 0; formatIndex < QImageReader::supportedImageFormats().count(); formatIndex++) {
|
||||
supportedImageFormats << QLatin1String("*.") + QImageReader::supportedImageFormats()[formatIndex];
|
||||
}
|
||||
QDir myDir(libraryPath);
|
||||
myDir.setNameFilters(supportedImageFormats);
|
||||
QStringList tmp = myDir.entryList();
|
||||
for (int i = 0; i < tmp.size(); i++) {
|
||||
QFileInfo fileInfo(tmp.at(i));
|
||||
QString filename = libraryPath + "/" + fileInfo.fileName();
|
||||
QImage image(filename);
|
||||
if (!image.isNull()) {
|
||||
imageList.append(filename);
|
||||
} else {
|
||||
QMessageBox::warning(this, CPN_STR_TTL_WARNING, tr("Invalid image in library %1").arg(filename));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (imageList.size() == 0) {
|
||||
QMessageBox::information(this, CPN_STR_TTL_INFO, tr("No valid image found in library, check your settings"));
|
||||
QTimer::singleShot(0, [=]() { close(); });
|
||||
}
|
||||
else {
|
||||
imageList.sort();
|
||||
}
|
||||
}
|
||||
|
||||
void SplashLibraryDialog::imageClicked(int button)
|
||||
{
|
||||
SplashLabel * myLabel = qobject_cast<SplashLabel *>(sender());
|
||||
|
||||
foreach(SplashLabel *sl, findChildren<SplashLabel *>()) {
|
||||
if (sl->isEnabled()) {
|
||||
sl->setStyleSheet("border:1px solid; border-color:#999999;");
|
||||
}
|
||||
}
|
||||
|
||||
if (button == Qt::Key_Enter) {
|
||||
int id = myLabel->getId();
|
||||
splashFileName->clear();
|
||||
splashFileName->append(imageList.at(id));
|
||||
close();
|
||||
}
|
||||
|
||||
myLabel->setStyleSheet("border:1px solid; border-color:#00ffff");
|
||||
}
|
||||
|
||||
void SplashLibraryDialog::nextPageClicked() {
|
||||
page++;
|
||||
|
||||
if (page >= (imageList.size() / 20)) {
|
||||
ui->nextPage->setDisabled(true);
|
||||
}
|
||||
|
||||
ui->prevPage->setEnabled(true);
|
||||
setupPage(page);
|
||||
}
|
||||
|
||||
void SplashLibraryDialog::prevPageClicked() {
|
||||
page--;
|
||||
|
||||
if (page == 0) {
|
||||
ui->prevPage->setDisabled(true);
|
||||
}
|
||||
|
||||
if (imageList.size() > 20) {
|
||||
ui->nextPage->setEnabled(true);
|
||||
}
|
||||
setupPage(page);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui {
|
||||
class SplashLibraryDialog;
|
||||
}
|
||||
|
||||
class SplashLibraryDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SplashLibraryDialog(QWidget *parent = 0, QString *fileName = nullptr);
|
||||
~SplashLibraryDialog();
|
||||
|
||||
private slots:
|
||||
void imageClicked(int button);
|
||||
void nextPageClicked();
|
||||
void prevPageClicked();
|
||||
|
||||
private:
|
||||
Ui::SplashLibraryDialog *ui;
|
||||
QString *splashFileName;
|
||||
QString libraryPath;
|
||||
QStringList imageList;
|
||||
int page;
|
||||
|
||||
void getFileList();
|
||||
void setupPage(int page);
|
||||
};
|
||||
@@ -0,0 +1,928 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>SplashLibraryDialog</class>
|
||||
<widget class="QDialog" name="SplashLibraryDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>650</width>
|
||||
<height>374</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QToolButton" name="prevPage">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>34</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>34</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>50</width>
|
||||
<height>50</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SizeConstraint::SetNoConstraint</enum>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="SplashLabel" name="FwImage_01">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>130</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>214</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border:1px;</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Raised</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="midLineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="SplashLabel" name="FwImage_02">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>130</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>214</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border:1px;</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="SplashLabel" name="FwImage_04">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>130</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>214</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border:1px;</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="SplashLabel" name="FwImage_05">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>214</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border:1px;</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="SplashLabel" name="FwImage_06">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>214</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border:1px;</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="SplashLabel" name="FwImage_07">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>214</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border:1px;</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="SplashLabel" name="FwImage_08">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>214</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border:1px;</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="SplashLabel" name="FwImage_09">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>214</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border:1px;</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="SplashLabel" name="FwImage_10">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>214</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border:1px;</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="SplashLabel" name="FwImage_11">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>214</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border:1px;</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="SplashLabel" name="FwImage_12">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>214</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border:1px;</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="SplashLabel" name="FwImage_13">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>214</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border:1px;</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="SplashLabel" name="FwImage_14">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>214</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border:1px;</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<widget class="SplashLabel" name="FwImage_15">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>214</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border:1px;</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="3">
|
||||
<widget class="SplashLabel" name="FwImage_16">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>214</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border:1px;</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="SplashLabel" name="FwImage_17">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>214</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border:1px;</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="SplashLabel" name="FwImage_18">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>214</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border:1px;</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<widget class="SplashLabel" name="FwImage_19">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>214</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border:1px;</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="3">
|
||||
<widget class="SplashLabel" name="FwImage_20">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>214</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border:1px;</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="SplashLabel" name="FwImage_03">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>130</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>214</width>
|
||||
<height>66</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="mouseTracking">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">border:1px;</string>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="4">
|
||||
<widget class="QToolButton" name="nextPage">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>34</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>34</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>50</width>
|
||||
<height>50</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>SplashLabel</class>
|
||||
<extends>QLabel</extends>
|
||||
<header location="global">splashlabel.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../companion.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user