From: hama Date: Tue, 26 Jan 2016 22:37:35 +0000 (+0100) Subject: rebackgui: GUI works, missing copy X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=005722ac22cb0b595362a91cd8f24810d9e4db5b;p=reqt rebackgui: GUI works, missing copy --- diff --git a/appl/rebackgui/BackupEngine.cpp b/appl/rebackgui/BackupEngine.cpp index a102d93..4fee13e 100644 --- a/appl/rebackgui/BackupEngine.cpp +++ b/appl/rebackgui/BackupEngine.cpp @@ -16,22 +16,36 @@ int BackupEngine::m_totalFiles = 0; int BackupEngine::m_totalDirs = 0; bool BackupEngine::m_searchReady = false; QMutex BackupEngine::m_mutex; +QChar BackupEngine::m_separator = '\t'; +QString BackupEngine::m_separatorString = "\t"; /** * Constructor. * + * @param name name of the task * @param sourceDirs the list of source directories to inspect * @param targetDir the base of the target directories * @param mainWindow the GUI module */ -BackupEngine::BackupEngine(const QStringList& sourceDirs, const QString& targetDir, +BackupEngine::BackupEngine(const QString& name, + const QStringList& sourceDirs, const QString& targetDir, MainWindow* mainWindow) : QThread(), m_sourceDirs(sourceDirs), - m_targetDir(targetDir), - m_mainWindow(mainWindow) + m_targetBaseDir(targetDir), + m_targetDirs(), + m_mainWindow(mainWindow), + m_name(name) { - + ReQStringUtils::ensureLastChar(m_targetBaseDir, OS_SEPARATOR); + for (int ix = 0; ix < sourceDirs.size(); ix++){ + ReQStringUtils::ensureLastChar(m_sourceDirs[ix], OS_SEPARATOR); + QString node = ReFileUtils::nodeOf(m_sourceDirs.at(ix).mid(0, + m_sourceDirs.at(ix).length() - 1)); + if (! node.isEmpty()) + node += OS_SEPARATOR_STR; + m_targetDirs.append(m_targetBaseDir + node); + } } /** @@ -61,16 +75,18 @@ bool BackupEngine::log(const QString& message){ /** * Constructor. * + * @param name name of the task * @param filePatterns only files which match the patterns will be found * @param dirPatterns only subdirectories which matches the patterns will be entered * @param source the list of base directories to search * @param targetDir the base target directory * @param mainWindow the GUI module, the parent */ -SearchTask::SearchTask(const QString& filePatterns, const QString& dirPatterns, - const QStringList& sourceDirs, const QString& targetDir, - MainWindow* mainWindow) : - BackupEngine(sourceDirs, targetDir, mainWindow), +SearchTask::SearchTask(const QString& name, + const QString& filePatterns, const QString& dirPatterns, + const QStringList& sourceDirs, const QString& targetDir, + MainWindow* mainWindow) : + BackupEngine(name, sourceDirs, targetDir, mainWindow), m_fileMatcher(filePatterns), m_dirMatcher(dirPatterns) { @@ -85,7 +101,7 @@ void SearchTask::run() qint64 start = QDateTime::currentMSecsSinceEpoch(); m_searchReady = false; for (int ix = 0; ix < m_sourceDirs.size(); ix++){ - processOneDirectory(m_sourceDirs.at(ix), m_targetDir, ix); + processOneDirectory(m_sourceDirs.at(ix), m_targetBaseDir, ix); } m_searchReady = true; m_mainWindow->externalLog(tr("%1 matching file(s) under %2 with %3 in %4 subdirs %5") @@ -110,11 +126,14 @@ void SearchTask::run() void SearchTask::processOneDirectory(const QString& source, const QString& target, int index){ QDirIterator it(source); - QString relPath; + QString prefix; QString info, node; int lengthBase = m_sourceDirs.at(index).length(); if (source.length() > lengthBase){ - relPath = source.mid(lengthBase + 1) + OS_SEPARATOR_STR; + prefix = QChar(1 + index) + source.mid(lengthBase) + OS_SEPARATOR_STR + + m_separator; + } else { + prefix = QChar(1 + index) + m_separatorString; } while (it.hasNext()){ if (m_shouldStop){ @@ -142,7 +161,7 @@ void SearchTask::processOneDirectory(const QString& source, } if (doCopy){ assert(index < 0x7fff); - info = QChar(1 + index) + relPath + "\t" + it.fileName(); + info = prefix + it.fileName(); } m_mutex.lock(); if (doCopy){ @@ -185,13 +204,15 @@ void SearchTask::processOneDirectory(const QString& source, /** * Constructor. * + * @param name name of the task * @param sourceDirs the list of source directories to inspect * @param targetDir the base of the target directories * @param mainWindow the GUI module */ -BackupTask::BackupTask(const QStringList& sourceDirs, const QString& targetDir, +BackupTask::BackupTask(const QString& name, + const QStringList& sourceDirs, const QString& targetDir, MainWindow* mainWindow) : - BackupEngine(sourceDirs, targetDir, mainWindow), + BackupEngine(name, sourceDirs, targetDir, mainWindow), m_lastRelPath() { @@ -205,9 +226,8 @@ BackupTask::BackupTask(const QStringList& sourceDirs, const QString& targetDir, * @param node the node of source and target */ void BackupTask::copyFile(int index, const QString& relPath, const QString& node){ - QString source = m_sourceDirs.at(index) + OS_SEPARATOR_STR + relPath - + node; - QString target = m_targetDir + relPath + node; + QString source = m_sourceDirs.at(index) + relPath + node; + QString target = m_targetDirs.at(index) + relPath + node; m_mainWindow->addToFileList(source + " -> " + target); } @@ -216,10 +236,9 @@ void BackupTask::copyFile(int index, const QString& relPath, const QString& node */ void BackupTask::run() { - int count = 1; QString relPath, node; QString info; - while (! m_shouldStop){ + while (true){ m_mutex.lock(); if (m_files.size() == 0) info.clear(); @@ -232,11 +251,14 @@ void BackupTask::run() if (m_searchReady) break; else - QThread::sleep(50); + QThread::msleep(50); } else { int index = int(info.at(0).unicode()) - 1; - int pos = info.indexOf('\t', 1); - relPath = info.mid(1, pos - 2); + int pos = info.indexOf(m_separator, 1); + if (pos == 1) + relPath.clear(); + else + relPath = info.mid(1, pos - 1); node = info.mid(pos + 1); copyFile(index, relPath, node); } diff --git a/appl/rebackgui/BackupEngine.hpp b/appl/rebackgui/BackupEngine.hpp index 028039e..889294a 100644 --- a/appl/rebackgui/BackupEngine.hpp +++ b/appl/rebackgui/BackupEngine.hpp @@ -13,7 +13,8 @@ class BackupEngine : public QThread { public: - BackupEngine(const QStringList& sourceDirs, const QString& targetDir, + BackupEngine(const QString& name, + const QStringList& sourceDirs, const QString& targetDir, MainWindow* mainWindow); public: bool error(const QString& message); @@ -21,9 +22,14 @@ public: protected: virtual void run() = 0; protected: + // list of source dirs, trailing with separator QStringList m_sourceDirs; - QString m_targetDir; + // target base directory, trailing with separator. Contains all target dirs + QString m_targetBaseDir; + // list of target dirs, trailing with separator. Same node as m_sourceDirs + QStringList m_targetDirs; MainWindow* m_mainWindow; + QString m_name; public: static bool m_shouldStop; static QStringList m_files; @@ -33,12 +39,15 @@ public: static int m_totalDirs; static bool m_searchReady; static QMutex m_mutex; + static QChar m_separator; + static QString m_separatorString; }; class SearchTask : public BackupEngine { public: - SearchTask(const QString& filePatterns, const QString& dirPatterns, + SearchTask(const QString& name, + const QString& filePatterns, const QString& dirPatterns, const QStringList& sourceDirs, const QString& targetDir, MainWindow* mainWindow); public: @@ -55,7 +64,7 @@ private: class BackupTask : public BackupEngine { public: - BackupTask(const QStringList& sourceDirs, const QString& targetDir, + BackupTask(const QString& name, const QStringList& sourceDirs, const QString& targetDir, MainWindow* mainWindow); public: virtual void run(); diff --git a/appl/rebackgui/mainwindow.cpp b/appl/rebackgui/mainwindow.cpp index c13ef37..95419d3 100644 --- a/appl/rebackgui/mainwindow.cpp +++ b/appl/rebackgui/mainwindow.cpp @@ -12,6 +12,12 @@ const QString VERSION("2016.01.20"); +/** + * Constructor. + * + * @param homeDir the home directory. If "": usage of the user's homedir + * @param parent QT parent or NULL + */ MainWindow::MainWindow(const QString& homeDir, QWidget *parent) : ReGuiApplication("rebackupgui", homeDir, 2, 100100100, parent), ReGuiValidator(), @@ -52,6 +58,9 @@ MainWindow::MainWindow(const QString& homeDir, QWidget *parent) : SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(onCurrentChanged(const QModelIndex&, const QModelIndex&))); + connect(ui->pushButtonClearFileList, SIGNAL(clicked()), this, SLOT(onClearFileList())); + connect(ui->pushButtonClearErrorList, SIGNAL(clicked()), this, SLOT(onClearErrorList())); + connect(ui->pushButtonClear, SIGNAL(clicked()), this, SLOT(onClearLog())); m_configuration.load(""); updateTable(); updateItem(0); @@ -193,7 +202,14 @@ void MainWindow::onDeleteSource() } } -void MainWindow::onSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected){ +/** + * @brief MainWindow::onSelectionChanged + * @param selected + * @param deselected + */ +void MainWindow::onSelectionChanged(const QItemSelection& selected, + const QItemSelection& deselected){ + UNUSED_VAR(deselected); int count = selected.indexes().size(); if (count > 0){ int ix = selected.indexes().at(0).row(); @@ -214,6 +230,30 @@ void MainWindow::onAddSource(){ } } +/** + * Remove the lines of hte file list. + */ +void MainWindow::onClearErrorList() +{ + ui->listWidgetError->clear(); +} + +/** + * Remove the lines of the log list. + */ +void MainWindow::onClearLog() +{ + ui->listWidgetLog->clear(); +} + +/** + * Remove the lines of hte file list. + */ +void MainWindow::onClearFileList() +{ + ui->listWidgetFile->clear(); +} + /** * Handles the push of the button "select directory". */ @@ -248,6 +288,7 @@ void MainWindow::findTarget(const QString& dir){ */ void MainWindow::onCurrentChanged(const QModelIndex & current, const QModelIndex & previous){ + UNUSED_VAR(previous); int row = current.row(); updateItem(row); } @@ -283,20 +324,25 @@ QString MainWindow::buildTargetDir(const QString& target){ * Starts the backup. */ void MainWindow::onStart(){ - startStop(true); int row = ui->tableWidget->currentRow(); - const BackupItem& item = m_configuration.items().at(row); - delete m_searchTask; - BackupEngine::m_searchReady = false; - QString target = buildTargetDir(item.m_target); - ReQStringUtils::ensureLastChar(target, OS_SEPARATOR); - m_searchTask = new SearchTask(item.m_filePatterns, item.m_dirPatterns, - item.m_sources, target, this); - m_searchTask->start(); - delete m_backupTask; - m_backupTask = new BackupTask(item.m_sources, target, - this); - m_backupTask->start(); + if (row < 0){ + say(LOG_ERROR, tr("no backup item selected")); + } else { + startStop(true); + const BackupItem& item = m_configuration.items().at(row); + delete m_searchTask; + BackupEngine::m_searchReady = false; + QString target = buildTargetDir(item.m_target); + ReQStringUtils::ensureLastChar(target, OS_SEPARATOR); + m_searchTask = new SearchTask(item.m_name, + item.m_filePatterns, item.m_dirPatterns, + item.m_sources, target, this); + m_searchTask->start(); + delete m_backupTask; + m_backupTask = new BackupTask(item.m_name, item.m_sources, target, + this); + m_backupTask->start(); + } } /** * Stops the backup. diff --git a/appl/rebackgui/mainwindow.hpp b/appl/rebackgui/mainwindow.hpp index 00215b0..ef63a8e 100644 --- a/appl/rebackgui/mainwindow.hpp +++ b/appl/rebackgui/mainwindow.hpp @@ -39,6 +39,9 @@ private slots: void onAbout(); void onAddItem(); void onAddSource(); + void onClearFileList(); + void onClearErrorList(); + void onClearLog(); void onCurrentChanged(const QModelIndex& current, const QModelIndex& previous); void onDeleteItem(); void onDeleteSource(); diff --git a/appl/reimgconvert/converter.cpp b/appl/reimgconvert/converter.cpp index 3302c0d..0f391a0 100644 --- a/appl/reimgconvert/converter.cpp +++ b/appl/reimgconvert/converter.cpp @@ -458,7 +458,7 @@ void TaskConverter::run(){ if (m_searchReady) break; else - QThread::sleep(50); + QThread::msleep(50); } else { int ix = info.indexOf('\t'); node = info.mid(ix + 1);