diff --git a/companion/src/companion.qrc b/companion/src/companion.qrc
index 1a842d240..e7f2400fe 100644
--- a/companion/src/companion.qrc
+++ b/companion/src/companion.qrc
@@ -886,6 +886,7 @@
themes/yerico/16/contributors.png
themes/yerico/16/stop.png
themes/yerico/16/write_eeprom.png
+ themes/yerico/16/sdsync.png
themes/yerico/24/paintbrush.png
themes/yerico/24/open.png
themes/yerico/24/edit.png
@@ -929,6 +930,7 @@
themes/yerico/24/contributors.png
themes/yerico/24/stop.png
themes/yerico/24/write_eeprom.png
+ themes/yerico/24/sdsync.png
themes/yerico/32/paintbrush.png
themes/yerico/32/open.png
themes/yerico/32/edit.png
@@ -972,6 +974,7 @@
themes/yerico/32/contributors.png
themes/yerico/32/stop.png
themes/yerico/32/write_eeprom.png
+ themes/yerico/32/sdsync.png
themes/yerico/48/paintbrush.png
themes/yerico/48/open.png
themes/yerico/48/edit.png
@@ -1015,5 +1018,6 @@
themes/yerico/48/contributors.png
themes/yerico/48/stop.png
themes/yerico/48/write_eeprom.png
+ themes/yerico/48/sdsync.png
diff --git a/companion/src/firmwares/opentx/opentxTaranisSimulator.cpp b/companion/src/firmwares/opentx/opentxTaranisSimulator.cpp
index 0e6a76db4..1c1f9fbd9 100644
--- a/companion/src/firmwares/opentx/opentxTaranisSimulator.cpp
+++ b/companion/src/firmwares/opentx/opentxTaranisSimulator.cpp
@@ -198,7 +198,7 @@ using namespace Open9xX9D;
OpentxTaranisSimulator::OpentxTaranisSimulator()
{
taranisSimulatorBoard = GetEepromInterface()->getBoard();
- QString path=g.profile[g.id()].sdPath()+"/";
+ QString path = g.profile[g.id()].sdPath()+"/";
int i=0;
for (i=0; i< std::min(path.length(),1022); i++) {
simuSdDirectory[i]=path.at(i).toAscii();
diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp
index ae76e8d93..9eb230d37 100644
--- a/companion/src/mainwindow.cpp
+++ b/companion/src/mainwindow.cpp
@@ -64,6 +64,7 @@
#include "helpers.h"
#include "appdata.h"
#include "radionotfound.h"
+#include "foldersync.h"
#define OPENTX_COMPANION_DOWNLOADS "http://downloads-20.open-tx.org/companion"
#define DONATE_STR "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QUZ48K4SEXDP2"
@@ -667,6 +668,15 @@ void MainWindow::contributors()
cd->exec();
}
+void MainWindow::sdsync()
+{
+ QString massstoragePath = FindMassstoragePath("SOUNDS");
+ if (!massstoragePath.isEmpty())
+ massstoragePath += "/..";
+ FoldersSyncTask syncTask(massstoragePath, g.profile[g.id()].sdPath());
+ syncTask.run();
+}
+
void MainWindow::changelog()
{
contributorsDialog *cd = new contributorsDialog(this,1);
@@ -1462,8 +1472,11 @@ void MainWindow::updateMenus()
updateLanguageActions();
updateIconSizeActions();
updateIconThemeActions();
+ sdsyncAct->setEnabled(!FindMassstoragePath("SOUNDS").isEmpty());
setWindowTitle(tr("OpenTX Companion - FW: %1 - Profile: %2").arg(GetCurrentFirmware()->getName()).arg( g.profile[g.id()].name() ));
+
+ qDebug() << "updateMenus";
}
MdiChild *MainWindow::createMdiChild()
@@ -1600,6 +1613,7 @@ void MainWindow::createActions()
writeBackupToRadioAct = addAct("write_eeprom_file.png", tr("Write Backup to Radio"), tr("Write Backup from file to Radio"), SLOT(writeBackup()));
readBackupToFileAct = addAct("read_eeprom_file.png", tr("Backup Radio to File"), tr("Save a complete backup file of all settings and model data in the Radio"), SLOT(readBackup()));
contributorsAct = addAct("contributors.png", tr("Contributors..."), tr("A tribute to those who have contributed to OpenTX and Companion"), SLOT(contributors()));
+ sdsyncAct = addAct("sdsync.png", tr("SD Synchro"), tr("SD card synchronization"), SLOT(sdsync()));
compareAct->setEnabled(false);
simulateAct->setEnabled(false);
@@ -1629,6 +1643,7 @@ void MainWindow::createMenus()
fileMenu->addAction(simulateAct);
fileMenu->addAction(printAct);
fileMenu->addAction(compareAct);
+ fileMenu->addAction(sdsyncAct);
fileMenu->addSeparator();
fileMenu->addAction(exitAct);
@@ -1778,6 +1793,7 @@ void MainWindow::createToolBars()
fileToolBar->addAction(simulateAct);
fileToolBar->addAction(printAct);
fileToolBar->addAction(compareAct);
+ fileToolBar->addAction(sdsyncAct);
editToolBar = addToolBar(tr("Edit"));
editToolBar->setIconSize(size);
diff --git a/companion/src/mainwindow.h b/companion/src/mainwindow.h
index 25e0c135f..e9725b792 100644
--- a/companion/src/mainwindow.h
+++ b/companion/src/mainwindow.h
@@ -146,6 +146,7 @@ class MainWindow : public QMainWindow
void burnFuses();
void simulate();
void contributors();
+ void sdsync();
void changelog();
void fwchangelog();
void customizeSplash();
@@ -237,6 +238,7 @@ class MainWindow : public QMainWindow
QAction *fwPrefsAct;
QAction *checkForUpdatesAct;
QAction *contributorsAct;
+ QAction *sdsyncAct;
QAction *changelogAct;
QAction *fwchangelogAct;
QAction *compareAct;
diff --git a/companion/src/shared/foldersync.cpp b/companion/src/shared/foldersync.cpp
index 694dc5487..4d377c63f 100644
--- a/companion/src/shared/foldersync.cpp
+++ b/companion/src/shared/foldersync.cpp
@@ -13,9 +13,17 @@ FoldersSyncTask::FoldersSyncTask(const QString &folder1, const QString &folder2)
void FoldersSyncTask::run()
{
+ if (!QFile::exists(folders[0])) {
+ QMessageBox::warning(NULL, QObject::tr("Synchronization error"), QObject::tr("The directory '%1' doesn't exist!").arg(folders[0]));
+ return;
+ }
+ if (!QFile::exists(folders[1])) {
+ QMessageBox::warning(NULL, QObject::tr("Synchronization error"), QObject::tr("The directory '%1' doesn't exist!").arg(folders[1]));
+ return;
+ }
QStringList errors = updateDir(folders[0], folders[1]) + updateDir(folders[1], folders[0]);
if (errors.count() > 0) {
- QMessageBox::warning(NULL, QObject::tr("Copy errors"), errors.join("\n"));
+ QMessageBox::warning(NULL, QObject::tr("Synchronization error"), errors.join("\n"));
}
}
@@ -25,6 +33,7 @@ QStringList FoldersSyncTask::updateDir(const QDir &source, const QDir &destinati
QDirIterator it(source, QDirIterator::Subdirectories);
while (it.hasNext()) {
QString path = it.next();
+ // qDebug() << path;
QFileInfo sourceInfo(path);
QString relativePath = source.relativeFilePath(path);
QString destinationPath = destination.absoluteFilePath(relativePath);
@@ -39,7 +48,7 @@ QStringList FoldersSyncTask::updateDir(const QDir &source, const QDir &destinati
}
else {
if (!destinationInfo.exists()) {
- // qDebug() << "Copy" << path << "to" << destinationPath;
+ qDebug() << "Copy" << path << "to" << destinationPath;
if (!QFile::copy(path, destinationPath)) {
errors << QObject::tr("Copy '%1' to '%2' failed").arg(path).arg(destinationPath);
continue;
@@ -68,7 +77,7 @@ QStringList FoldersSyncTask::updateDir(const QDir &source, const QDir &destinati
errors << QObject::tr("Write '%1' failed").arg(destinationPath);
continue;
}
- // qDebug() << "Write" << destinationPath;
+ qDebug() << "Write" << destinationPath;
QTextStream destinationStream(&destinationFile);
destinationStream << sourceContents;
destinationFile.close();