mirror of
https://github.com/opentx/opentx.git
synced 2025-07-26 09:45:21 +03:00
Fixes #2580
This commit is contained in:
parent
23c985ffd6
commit
f5f1a052ca
7 changed files with 148 additions and 122 deletions
|
@ -667,17 +667,23 @@ void MainWindow::contributors()
|
||||||
|
|
||||||
void MainWindow::sdsync()
|
void MainWindow::sdsync()
|
||||||
{
|
{
|
||||||
|
QString sdPath = g.profile[g.id()].sdPath();
|
||||||
|
if (sdPath.isEmpty()) {
|
||||||
|
QMessageBox::warning(this, QObject::tr("Synchronization error"), QObject::tr("No SD directory configured!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
QString massstoragePath = findMassstoragePath("SOUNDS");
|
QString massstoragePath = findMassstoragePath("SOUNDS");
|
||||||
if (massstoragePath.isEmpty()) {
|
if (massstoragePath.isEmpty()) {
|
||||||
QMessageBox::warning(this, QObject::tr("Synchronization error"), QObject::tr("No Radio connected!"));
|
QMessageBox::warning(this, QObject::tr("Synchronization error"), QObject::tr("No Radio connected!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
massstoragePath += "/..";
|
massstoragePath = massstoragePath.left(massstoragePath.length() - 7);
|
||||||
ProgressDialog progressDialog(this, tr("Synchronize SD"), CompanionIcon("sdsync.png"));
|
ProgressDialog progressDialog(this, tr("Synchronize SD"), CompanionIcon("sdsync.png"));
|
||||||
SyncProcess syncProcess(massstoragePath, g.profile[g.id()].sdPath(), progressDialog.progress());
|
SyncProcess syncProcess(massstoragePath, g.profile[g.id()].sdPath(), progressDialog.progress());
|
||||||
syncProcess.run();
|
if (!syncProcess.run()) {
|
||||||
progressDialog.exec();
|
progressDialog.exec();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::changelog()
|
void MainWindow::changelog()
|
||||||
{
|
{
|
||||||
|
@ -687,21 +693,21 @@ void MainWindow::changelog()
|
||||||
|
|
||||||
void MainWindow::fwchangelog()
|
void MainWindow::fwchangelog()
|
||||||
{
|
{
|
||||||
Firmware *currfirm = GetCurrentFirmware();
|
Firmware * firmware = GetCurrentFirmware();
|
||||||
QString rn=currfirm->getReleaseNotesUrl();
|
QString url = firmware->getReleaseNotesUrl();
|
||||||
if (rn.isEmpty()) {
|
if (url.isEmpty()) {
|
||||||
QMessageBox::information(this, tr("Firmware updates"), tr("Current firmware does not provide release notes informations."));
|
QMessageBox::information(this, tr("Firmware updates"), tr("Current firmware does not provide release notes informations."));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ReleaseNotesFirmwareDialog * dialog = new ReleaseNotesFirmwareDialog(this, rn);
|
ReleaseNotesFirmwareDialog * dialog = new ReleaseNotesFirmwareDialog(this, url);
|
||||||
dialog->exec();
|
dialog->exec();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::customizeSplash()
|
void MainWindow::customizeSplash()
|
||||||
{
|
{
|
||||||
customizeSplashDialog *cd = new customizeSplashDialog(this);
|
customizeSplashDialog * dialog = new customizeSplashDialog(this);
|
||||||
cd->exec();
|
dialog->exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::cut()
|
void MainWindow::cut()
|
||||||
|
|
|
@ -5,94 +5,105 @@
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QEventLoop>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
SyncProcess::SyncProcess(const QString & folder1, const QString & folder2, ProgressWidget * progress):
|
SyncProcess::SyncProcess(const QString & folder1, const QString & folder2, ProgressWidget * progress):
|
||||||
folder1(folder1),
|
folder1(folder1),
|
||||||
folder2(folder2),
|
folder2(folder2),
|
||||||
progress(progress),
|
progress(progress),
|
||||||
simulation(false),
|
index(0),
|
||||||
index(0)
|
count(0),
|
||||||
|
closed(false)
|
||||||
{
|
{
|
||||||
|
connect(progress, SIGNAL(stopped()),this, SLOT(onClosed()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SyncProcess::run()
|
void SyncProcess::onClosed()
|
||||||
{
|
{
|
||||||
simulation = true;
|
closed = true;
|
||||||
index = 0;
|
|
||||||
if (synchronize()) {
|
|
||||||
int count = index;
|
|
||||||
progress->setMaximum(count);
|
|
||||||
simulation = false;
|
|
||||||
index = 0;
|
|
||||||
synchronize();
|
|
||||||
progress->setValue(count);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SyncProcess::synchronize()
|
bool SyncProcess::run()
|
||||||
{
|
{
|
||||||
if (!QFile::exists(folder1)) {
|
if (!QFile::exists(folder1)) {
|
||||||
QMessageBox::warning(NULL, QObject::tr("Synchronization error"), QObject::tr("The directory '%1' doesn't exist!").arg(folder1));
|
QMessageBox::warning(NULL, QObject::tr("Synchronization error"), QObject::tr("The directory '%1' doesn't exist!").arg(folder1));
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!QFile::exists(folder2)) {
|
|
||||||
QMessageBox::warning(NULL, QObject::tr("Synchronization error"), QObject::tr("The directory '%1' doesn't exist!").arg(folder2));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
QStringList errors = updateDir(folder1, folder2) + updateDir(folder2, folder1);
|
|
||||||
if (errors.count() > 0) {
|
|
||||||
QMessageBox::warning(NULL, QObject::tr("Synchronization error"), errors.join("\n"));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList SyncProcess::updateDir(const QDir &source, const QDir &destination)
|
if (!QFile::exists(folder2)) {
|
||||||
|
QMessageBox::warning(NULL, QObject::tr("Synchronization error"), QObject::tr("The directory '%1' doesn't exist!").arg(folder2));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
count = getFilesCount(folder1) + getFilesCount(folder2);
|
||||||
|
progress->setMaximum(count);
|
||||||
|
|
||||||
|
QStringList errors = updateDir(folder1, folder2) + updateDir(folder2, folder1);
|
||||||
|
if (errors.count() > 0) {
|
||||||
|
QMessageBox::warning(NULL, QObject::tr("Synchronization error"), errors.join("\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// don't close the window unless the user wanted
|
||||||
|
return closed;
|
||||||
|
}
|
||||||
|
|
||||||
|
int SyncProcess::getFilesCount(const QString & directory)
|
||||||
|
{
|
||||||
|
int result = 0;
|
||||||
|
QDirIterator it(directory, QDirIterator::Subdirectories);
|
||||||
|
while (it.hasNext()) {
|
||||||
|
it.next();
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList SyncProcess::updateDir(const QString & source, const QString & destination)
|
||||||
{
|
{
|
||||||
QDirIterator it(source, QDirIterator::Subdirectories);
|
QDirIterator it(source, QDirIterator::Subdirectories);
|
||||||
while (it.hasNext()) {
|
while (!closed && it.hasNext()) {
|
||||||
if (!simulation) {
|
QEventLoop loop;
|
||||||
|
QTimer::singleShot(10, &loop, SLOT(quit()));
|
||||||
|
loop.exec();
|
||||||
|
index++;
|
||||||
|
progress->setInfo(tr("%1/%2 files").arg(index).arg(count));
|
||||||
progress->setValue(index);
|
progress->setValue(index);
|
||||||
|
QString result = updateEntry(it.next(), source, destination);
|
||||||
|
if (!result.isEmpty()) {
|
||||||
|
errors << result;
|
||||||
}
|
}
|
||||||
QString path = it.next();
|
}
|
||||||
// qDebug() << path;
|
return errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString SyncProcess::updateEntry(const QString & path, const QDir & source, const QDir & destination)
|
||||||
|
{
|
||||||
QFileInfo sourceInfo(path);
|
QFileInfo sourceInfo(path);
|
||||||
QString relativePath = source.relativeFilePath(path);
|
QString relativePath = source.relativeFilePath(path);
|
||||||
QString destinationPath = destination.absoluteFilePath(relativePath);
|
QString destinationPath = destination.absoluteFilePath(relativePath);
|
||||||
QFileInfo destinationInfo(destinationPath);
|
QFileInfo destinationInfo(destinationPath);
|
||||||
if (sourceInfo.isDir()) {
|
if (sourceInfo.isDir()) {
|
||||||
if (!destinationInfo.exists()) {
|
if (!destinationInfo.exists()) {
|
||||||
++index;
|
|
||||||
if (!simulation) {
|
|
||||||
progress->addText(tr("Create directory %1\n").arg(destinationPath));
|
progress->addText(tr("Create directory %1\n").arg(destinationPath));
|
||||||
if (!destination.mkdir(relativePath)) {
|
if (!destination.mkdir(relativePath)) {
|
||||||
errors << QObject::tr("Create '%1' failed").arg(destinationPath);
|
return QObject::tr("Create '%1' failed").arg(destinationPath);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!destinationInfo.exists()) {
|
if (!destinationInfo.exists()) {
|
||||||
// qDebug() << "Copy" << path << "to" << destinationPath;
|
// qDebug() << "Copy" << path << "to" << destinationPath;
|
||||||
++index;
|
|
||||||
if (!simulation) {
|
|
||||||
progress->addText(tr("Copy %1 to %2\n").arg(path).arg(destinationPath));
|
progress->addText(tr("Copy %1 to %2\n").arg(path).arg(destinationPath));
|
||||||
if (!QFile::copy(path, destinationPath)) {
|
if (!QFile::copy(path, destinationPath)) {
|
||||||
errors << QObject::tr("Copy '%1' to '%2' failed").arg(path).arg(destinationPath);
|
return QObject::tr("Copy '%1' to '%2' failed").arg(path).arg(destinationPath);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (sourceInfo.lastModified() > destinationInfo.lastModified()) {
|
else if (sourceInfo.lastModified() > destinationInfo.lastModified()) {
|
||||||
++index;
|
|
||||||
if (!simulation) {
|
|
||||||
progress->addText(tr("Read %1\n").arg(path));
|
|
||||||
// retrieve source contents
|
// retrieve source contents
|
||||||
QFile sourceFile(path);
|
QFile sourceFile(path);
|
||||||
if (!sourceFile.open(QFile::ReadOnly)) {
|
if (!sourceFile.open(QFile::ReadOnly)) {
|
||||||
errors << QObject::tr("Open '%1' failed").arg(path);
|
return QObject::tr("Open '%1' failed").arg(path);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
QString sourceContents = sourceFile.readAll();
|
QString sourceContents = sourceFile.readAll();
|
||||||
sourceFile.close();
|
sourceFile.close();
|
||||||
|
@ -103,12 +114,11 @@ QStringList SyncProcess::updateDir(const QDir &source, const QDir &destination)
|
||||||
destinationFile.close();
|
destinationFile.close();
|
||||||
if (sourceContents == destinationContents) {
|
if (sourceContents == destinationContents) {
|
||||||
// qDebug() << "Skip" << path;
|
// qDebug() << "Skip" << path;
|
||||||
continue;
|
return QString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!destinationFile.open(QFile::WriteOnly)) {
|
if (!destinationFile.open(QFile::WriteOnly)) {
|
||||||
errors << QObject::tr("Write '%1' failed").arg(destinationPath);
|
return QObject::tr("Write '%1' failed").arg(destinationPath);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
progress->addText(tr("Write %1\n").arg(destinationPath));
|
progress->addText(tr("Write %1\n").arg(destinationPath));
|
||||||
// qDebug() << "Write" << destinationPath;
|
// qDebug() << "Write" << destinationPath;
|
||||||
|
@ -117,7 +127,5 @@ QStringList SyncProcess::updateDir(const QDir &source, const QDir &destination)
|
||||||
destinationFile.close();
|
destinationFile.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return QString();
|
||||||
}
|
|
||||||
return errors;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#ifndef SYNCPROCESS_H_
|
#ifndef SYNCPROCESS_H_
|
||||||
#define SYNCPROCESS_H_
|
#define SYNCPROCESS_H_
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
|
@ -14,17 +13,22 @@ class SyncProcess : public QObject
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SyncProcess(const QString & folder1, const QString & folder2, ProgressWidget * progress);
|
SyncProcess(const QString & folder1, const QString & folder2, ProgressWidget * progress);
|
||||||
void run();
|
bool run();
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
void onClosed();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool synchronize();
|
int getFilesCount(const QString & directory);
|
||||||
QStringList updateDir(const QDir &source, const QDir &destination);
|
QStringList updateDir(const QString & source, const QString & destination);
|
||||||
|
QString updateEntry(const QString & path, const QDir & source, const QDir & destination);
|
||||||
QString folder1;
|
QString folder1;
|
||||||
QString folder2;
|
QString folder2;
|
||||||
ProgressWidget * progress;
|
ProgressWidget * progress;
|
||||||
QStringList errors;
|
QStringList errors;
|
||||||
bool simulation;
|
|
||||||
int index;
|
int index;
|
||||||
|
int count;
|
||||||
|
bool closed;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SYNCPROCESS_H_ */
|
#endif /* SYNCPROCESS_H_ */
|
||||||
|
|
|
@ -31,6 +31,7 @@ ProgressWidget *ProgressDialog::progress()
|
||||||
void ProgressDialog::on_closeButton_clicked()
|
void ProgressDialog::on_closeButton_clicked()
|
||||||
{
|
{
|
||||||
if (!locked) {
|
if (!locked) {
|
||||||
|
ui->outputProgress->stop();
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,11 @@ ProgressWidget::~ProgressWidget()
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProgressWidget::stop()
|
||||||
|
{
|
||||||
|
emit stopped();
|
||||||
|
}
|
||||||
|
|
||||||
void ProgressWidget::forceOpen()
|
void ProgressWidget::forceOpen()
|
||||||
{
|
{
|
||||||
ui->checkBox->hide();
|
ui->checkBox->hide();
|
||||||
|
|
|
@ -24,10 +24,12 @@ class ProgressWidget : public QWidget
|
||||||
void setProgressColor(const QColor &color);
|
void setProgressColor(const QColor &color);
|
||||||
void addSeparator();
|
void addSeparator();
|
||||||
void forceOpen();
|
void forceOpen();
|
||||||
|
void stop();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void detailsToggled();
|
void detailsToggled();
|
||||||
void locked(bool);
|
void locked(bool);
|
||||||
|
void stopped();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void on_checkBox_toggled(bool checked);
|
void on_checkBox_toggled(bool checked);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue