From: hama Date: Mon, 25 Jan 2016 23:14:25 +0000 (+0100) Subject: dayly work X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=744df61b0e379349f35b49fdce27d5712049d380;p=reqt dayly work --- diff --git a/appl/rebackgui/BackupEngine.cpp b/appl/rebackgui/BackupEngine.cpp index c01718e..a102d93 100644 --- a/appl/rebackgui/BackupEngine.cpp +++ b/appl/rebackgui/BackupEngine.cpp @@ -111,7 +111,7 @@ void SearchTask::processOneDirectory(const QString& source, const QString& target, int index){ QDirIterator it(source); QString relPath; - QString info; + QString info, node; int lengthBase = m_sourceDirs.at(index).length(); if (source.length() > lengthBase){ relPath = source.mid(lengthBase + 1) + OS_SEPARATOR_STR; @@ -121,19 +121,29 @@ void SearchTask::processOneDirectory(const QString& source, break; } it.next(); - if (it.fileInfo().isDir() && m_fileMatcher.matches(it.fileName()) >= 0){ + node = it.fileName(); + if (it.fileInfo().isDir()){ + // nothing to do + } else if (! m_fileMatcher.matches(node)){ m_mutex.lock(); m_totalFiles++; m_mutex.unlock(); } else { - bool doCopy = false; - if (! target.isEmpty()){ + bool doCopy = target.isEmpty(); + if (! doCopy){ QFileInfo trg(target + it.fileName()); - doCopy = trg.exists() && (trg.size() != it.fileInfo().size() - || trg.lastModified() > it.fileInfo().lastModified()); + if (! trg.exists()) + doCopy = true; + else { + const QFileInfo src = it.fileInfo(); + doCopy = trg.exists() && (trg.size() != src.size() + || src.lastModified() > trg.lastModified()); + } + } + if (doCopy){ + assert(index < 0x7fff); + info = QChar(1 + index) + relPath + "\t" + it.fileName(); } - if (doCopy) - info = relPath + "\t" + it.fileName(); m_mutex.lock(); if (doCopy){ m_files.append(info); @@ -181,17 +191,55 @@ void SearchTask::processOneDirectory(const QString& source, */ BackupTask::BackupTask(const QStringList& sourceDirs, const QString& targetDir, MainWindow* mainWindow) : - BackupEngine(sourceDirs, targetDir, mainWindow) + BackupEngine(sourceDirs, targetDir, mainWindow), + m_lastRelPath() { } +/** + * Copies the file into the target directory. + * + * @param index index of m_sourceDirs + * @param relpath the path relative to the base path, e.g. "abc/" + * @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; + m_mainWindow->addToFileList(source + " -> " + target); +} + /** * Do the backup task. */ void BackupTask::run() { - while(! m_searchReady) - QThread::sleep(50); + int count = 1; + QString relPath, node; + QString info; + while (! m_shouldStop){ + m_mutex.lock(); + if (m_files.size() == 0) + info.clear(); + else{ + info = m_files.first(); + m_files.removeFirst(); + } + m_mutex.unlock(); + if (info.isEmpty()){ + if (m_searchReady) + break; + else + QThread::sleep(50); + } else { + int index = int(info.at(0).unicode()) - 1; + int pos = info.indexOf('\t', 1); + relPath = info.mid(1, pos - 2); + node = info.mid(pos + 1); + copyFile(index, relPath, node); + } + } m_mainWindow->externalTaskFinished("ready"); } diff --git a/appl/rebackgui/BackupEngine.hpp b/appl/rebackgui/BackupEngine.hpp index fb665c5..028039e 100644 --- a/appl/rebackgui/BackupEngine.hpp +++ b/appl/rebackgui/BackupEngine.hpp @@ -60,6 +60,9 @@ public: public: virtual void run(); protected: + void copyFile(int index, const QString& relpath, const QString& node); +private: + QString m_lastRelPath; }; #endif // BACKUPPROCESSOR_HPP diff --git a/appl/rebackgui/Configuration.cpp b/appl/rebackgui/Configuration.cpp index 633261c..dc5d241 100644 --- a/appl/rebackgui/Configuration.cpp +++ b/appl/rebackgui/Configuration.cpp @@ -173,8 +173,10 @@ void Configuration::save(QString filename) + item.m_sources.join(';').toUtf8() + "\n"; buffer += "target." + QByteArray::number(ix) + "=" + item.m_target.toUtf8() + "\n"; - buffer += "target." + QByteArray::number(ix) + "=" - + item.m_target.toUtf8() + "\n"; + buffer += "filepatterns." + QByteArray::number(ix) + "=" + + item.m_filePatterns.toUtf8() + "\n"; + buffer += "dirpatterns." + QByteArray::number(ix) + "=" + + item.m_dirPatterns.toUtf8() + "\n"; buffer += "lastbackup." + QByteArray::number(ix) + "=" + item.m_lastBackup.toString("yyyy.MM.dd/hh:mm") + "\n"; if (fputs(buffer.constData(), fp) != buffer.length()) diff --git a/appl/rebackgui/mainwindow.cpp b/appl/rebackgui/mainwindow.cpp index 38ed855..c13ef37 100644 --- a/appl/rebackgui/mainwindow.cpp +++ b/appl/rebackgui/mainwindow.cpp @@ -73,6 +73,17 @@ void MainWindow::aboutToQuit() } +/** + * Appends a line to the filelist. + * + * Note: this method is called by a non main thread. + * + * @param info info to add + */ +void MainWindow::addToFileList(const QString info){ + externalAppend(ReGuiQueueItem::ListEnd, ui->listWidgetFile, info); +} + /** * Issues an error message. * @@ -260,9 +271,9 @@ void MainWindow::onSaveConfig(){ * * @return the target directory */ -QString MainWindow::buildTargetFile(){ - QString rc = ui->lineEditTarget->text(); - int ix = rc.indexOf(rc, ';'); +QString MainWindow::buildTargetDir(const QString& target){ + QString rc = target; + int ix = rc.indexOf(';'); if (ix == 0) rc.remove(0, 1); return rc; @@ -276,14 +287,16 @@ void MainWindow::onStart(){ 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, buildTargetFile(), - this); + item.m_sources, target, this); m_searchTask->start(); delete m_backupTask; - m_backupTask = new BackupTask(item.m_sources, buildTargetFile(), + m_backupTask = new BackupTask(item.m_sources, target, this); - + m_backupTask->start(); } /** * Stops the backup. diff --git a/appl/rebackgui/mainwindow.hpp b/appl/rebackgui/mainwindow.hpp index ea6a7fa..00215b0 100644 --- a/appl/rebackgui/mainwindow.hpp +++ b/appl/rebackgui/mainwindow.hpp @@ -23,7 +23,8 @@ public: explicit MainWindow(const QString& homeDir, QWidget *parent = 0); ~MainWindow(); public: - QString buildTargetFile(); + void addToFileList(const QString info); + QString buildTargetDir(const QString& target); bool error(const QString& message); bool log(const QString& message); virtual bool say(ReLoggerLevel level, const QString& message); diff --git a/appl/rebackgui/mainwindow.ui b/appl/rebackgui/mainwindow.ui index 945433d..6cf4e04 100644 --- a/appl/rebackgui/mainwindow.ui +++ b/appl/rebackgui/mainwindow.ui @@ -18,7 +18,7 @@ - 1 + 0 diff --git a/base/ReMatcher.cpp b/base/ReMatcher.cpp index ec7c9f0..5b3d9de 100644 --- a/base/ReMatcher.cpp +++ b/base/ReMatcher.cpp @@ -90,12 +90,10 @@ bool ReMatcher::matches(const QString& text) { */ void ReMatcher::setPattern(const QString& pattern, bool anchored) { m_anchored = anchored; - m_allMatching = false; + m_allMatching = pattern.isEmpty() || (pattern.length() == 1 && pattern.at(0) == '*'); m_pattern = pattern; m_needles.clear(); - if (pattern.isEmpty()) - m_needles.clear(); - else { + if (! m_allMatching){ m_needles = pattern.split('*'); // Eliminate empty entries but not first and next: for (int ix = m_needles.size() - 2; ix > 0; ix--) { diff --git a/gui/ReGuiQueue.cpp b/gui/ReGuiQueue.cpp index 7a79dcc..810eef0 100644 --- a/gui/ReGuiQueue.cpp +++ b/gui/ReGuiQueue.cpp @@ -11,7 +11,7 @@ #include "base/rebase.hpp" #include "gui/regui.hpp" - +#include /** * Constructor. */ @@ -92,6 +92,13 @@ bool ReGuiQueueItem::apply() const } break; } + case ListEnd: + { + QListWidget* list = reinterpret_cast(m_widget); + list->addItem(m_value); + list->setCurrentRow(list->count() - 1); + break; + } default: rc = false; break;