From 6f0920f37588b1416999d8cdfbaeb3f3de321a6f Mon Sep 17 00:00:00 2001 From: Hamatoma Date: Sun, 14 Feb 2016 19:36:47 +0100 Subject: [PATCH] rebackgui: bugfixes --- appl/rebackgui/BackupEngine.cpp | 56 ++++++++++++++++++++------------- appl/rebackgui/mainwindow.cpp | 25 +++++++++++---- appl/rebackgui/mainwindow.hpp | 1 + base/ReQStringUtils.cpp | 2 +- 4 files changed, 56 insertions(+), 28 deletions(-) diff --git a/appl/rebackgui/BackupEngine.cpp b/appl/rebackgui/BackupEngine.cpp index 1f71848..00c224b 100644 --- a/appl/rebackgui/BackupEngine.cpp +++ b/appl/rebackgui/BackupEngine.cpp @@ -182,6 +182,8 @@ void BackupTask::run() QString relPath, node; QString info; QDateTime start = QDateTime::currentDateTime(); + int hotFiles, processedFiles; + qint64 processedBytes, hotBytes; while (! m_shouldStop){ m_mutex.lock(); if (m_files.size() == 0) @@ -190,6 +192,10 @@ void BackupTask::run() info = m_files.first(); m_files.removeFirst(); } + hotBytes = m_hotBytes; + processedBytes = m_processedBytes; + hotFiles = m_hotFiles; + processedFiles = m_processedFiles; m_mutex.unlock(); if (info.isEmpty()){ if (m_searchReady) @@ -207,13 +213,15 @@ void BackupTask::run() copyFile(index, relPath, node); if (m_verboseLevel > VerboseQuiet){ qint64 duration = QDateTime::currentMSecsSinceEpoch() - start.toMSecsSinceEpoch(); - double factor = double(m_processedBytes) / max(1LL, m_hotBytes); + double factor = processedBytes / max(1.0, (double) hotBytes); + if (factor > 1.0) + factor = 1; m_mainWindow->externalAppend(ReGuiQueueItem::StatusLine, NULL, tr("%1 of %2 (%3 of %4) %5 MB/sec runtime: %6") - .arg(m_processedFiles).arg(m_hotFiles) - .arg(ReQStringUtils::readableSize(m_processedBytes)) - .arg(ReQStringUtils::readableSize(m_hotBytes)) - .arg(m_processedBytes / 1024.0 / 1024 * 1000 / max(1LL, duration), 0, 'f', 3) + .arg(processedFiles).arg(hotFiles) + .arg(ReQStringUtils::readableSize(processedBytes)) + .arg(ReQStringUtils::readableSize(hotBytes)) + .arg(processedBytes / 1024.0 / 1024 * 1000 / max(1LL, duration), 0, 'f', 3) .arg(ReQStringUtils::runtimeEstimation(start, factor))); } } @@ -408,7 +416,9 @@ void ChecksumOfTargetTask::run() m_mutex.unlock(); now = QDateTime::currentMSecsSinceEpoch(); qint64 duration = (now - start.toMSecsSinceEpoch()); - double factor = processedBytes / double(max(1LL, hotBytes)); + double factor = processedBytes / max(1.0, (double) hotBytes); + if (factor > 1) + factor = 1; m_mainWindow->externalAppend(ReGuiQueueItem::StatusLine, NULL, tr("%1 of %2 (%3 of %4) %5 MB/sec runtime: %6") .arg(processedFiles).arg(hotFiles * 2) @@ -480,7 +490,7 @@ void CleanTask::run() node = info.mid(pos + 2); switch(command){ case CmdRemove: - if (unlink(I18N::s2b(relPath)) != 0){ + if (_unlink(I18N::s2b(relPath)) != 0){ int errNo = errno; if (stat(I18N::s2b(relPath), &info2) == 0) error(QObject::tr("cannot delete (%1): %2").arg(errNo) @@ -510,7 +520,7 @@ void CleanTask::run() QByteArray shadow2 = I18N::s2b(shadow); struct stat info; if (stat(shadow2.constData(), &info) == 0){ - if (unlink(shadow2.constData()) != 0){ + if (_unlink(shadow2.constData()) != 0){ error(QObject::tr("cannot delete shadow file (%1): %2").arg(errno).arg(shadow)); } } @@ -540,7 +550,7 @@ void CleanTask::run() } } } - m_mainWindow->externalTaskFinished(tr("backup complete after %1. Errors: %2") + m_mainWindow->externalTaskFinished(tr("clean complete after %1. Errors: %2") .arg(ReQStringUtils::readableDuration( QDateTime::currentMSecsSinceEpoch() - start.toMSecsSinceEpoch())) .arg(m_mainWindow->errors())); @@ -692,7 +702,7 @@ void SearchTask::searchOneDirectory(const QString& source, else subTarget += OS_SEPARATOR_STR; } - searchOneDirectory(it2.filePath(), subTarget, index); + searchOneDirectory(ReFileUtils::nativePath(it2.filePath()), subTarget, index); } } } @@ -741,15 +751,15 @@ bool SearchTargetTask::removeOlder(const QString& directory, const QDateTime& ti node = it.fileName(); if (it.fileInfo().isDir()){ if (node != "." && node != ".."){ - if (! removeOlder(it.filePath(), time)) + if (! removeOlder(ReFileUtils::nativePath(it.filePath()), time)) isEmpty = false; } } else if (it.fileInfo().lastModified() < time){ if (m_verboseLevel >= VerboseChatty) - m_mainWindow->addToFileList("% " + it.filePath() + " " + m_mainWindow->addToFileList("% " + ReFileUtils::nativePath(it.filePath()) + " " + it.fileInfo().lastModified().toString("yyyy.MM.dd/hh:mm:ss")); isEmpty = false; - info = QChar(MAX_INDEX) + it.filePath() + m_separatorString + info = QChar(MAX_INDEX) + ReFileUtils::nativePath(it.filePath()) + m_separatorString + QChar(CmdRemove); m_mutex.lock(); m_files.append(info); @@ -757,8 +767,10 @@ bool SearchTargetTask::removeOlder(const QString& directory, const QDateTime& ti m_hotBytes += it.fileInfo().size(); m_totalFiles++; m_mutex.unlock(); - } - } + }else { + isEmpty = false; + } + } if (isEmpty){ if (m_verboseLevel >= VerboseChatty) m_mainWindow->addToFileList("x " + directory); @@ -791,9 +803,9 @@ void SearchTargetTask::searchOneDirectory(const QString& target, m_mutex.lock(); m_totalDirs++; m_mutex.unlock(); - if (source.length() > lengthBase){ - relPath = ReFileUtils::nativePath(source.mid(lengthBase)); - prefix = QChar(1 + index) + relPath + OS_SEPARATOR_STR + m_separator; + if (target.length() > lengthBase){ + relPath = ReFileUtils::nativePath(target.mid(lengthBase)) + OS_SEPARATOR_STR; + prefix = QChar(1 + index) + relPath + m_separator; } else { prefix = QChar(1 + index) + m_separatorString; } @@ -816,7 +828,8 @@ void SearchTargetTask::searchOneDirectory(const QString& target, QDateTime trgTime = trg.lastModified(); if (trgTime < m_maxAge){ command = CmdRemove; - info = QChar(1 + index) + it.filePath() + "\t" + QChar(command); + info = QChar(1 + index) + ReFileUtils::nativePath(it.filePath()) + + "\t" + QChar(command); } else { command = CmdMove; info = prefix + QChar(command) + it.fileName(); @@ -845,9 +858,10 @@ void SearchTargetTask::searchOneDirectory(const QString& target, QString newSource = source + it2.fileName(); QFileInfo src(newSource); if (src.exists() && src.isDir()) - searchOneDirectory(it2.filePath(), newSource + OS_SEPARATOR_STR, index); + searchOneDirectory(ReFileUtils::nativePath(it2.filePath()), + newSource + OS_SEPARATOR_STR, index); else{ - moveToShadow(it2.filePath(), relPath, index); + moveToShadow(ReFileUtils::nativePath(it2.filePath()), relPath, index); } } } diff --git a/appl/rebackgui/mainwindow.cpp b/appl/rebackgui/mainwindow.cpp index 60a2f92..6319648 100644 --- a/appl/rebackgui/mainwindow.cpp +++ b/appl/rebackgui/mainwindow.cpp @@ -13,7 +13,7 @@ #include "aboutdialog.hpp" #include -const QString VERSION("2016.02.13"); +const QString VERSION("2016.02.14"); /** * Constructor. @@ -73,6 +73,7 @@ MainWindow::MainWindow(const QString& homeDir, QWidget *parent) : connect(ui->pushButtonClearErrorList, SIGNAL(clicked()), this, SLOT(onClearErrorList())); connect(ui->pushButtonClear, SIGNAL(clicked()), this, SLOT(onClearLog())); connect(ui->pushButtonClean, SIGNAL(clicked()), this, SLOT(onClean())); + connect(ui->comboBoxVerbose, SIGNAL(currentIndexChanged(int)), this, SLOT(onVerboseIndexChanged(int))); m_configuration.load(""); ui->tableWidgetConfiguration->selectRow(0); updateTable(); @@ -190,9 +191,11 @@ void MainWindow::onGuiTimerUpdate() * otherwise: error occurred */ bool MainWindow::initializeStart(){ + setStatusMessage(LOG_INFO, QObject::tr("Search started...")); bool rc = true; - BackupEngine::m_searchReady = false; - BackupEngine::m_hotBytes = 0; + BackupEngine::m_shouldStop = false; + BackupEngine::m_searchReady = false; + BackupEngine::m_hotBytes = 0; BackupEngine::m_hotFiles = 0; BackupEngine::m_matchedFiles = 0; BackupEngine::m_totalDirs = 0; @@ -492,7 +495,16 @@ void MainWindow::onUpdate(){ item.m_sources.append(ui->listWidgetSource->item(ix)->text()); } updateTable(); - saveState(); + saveState(); +} + +/** + * The verbose level has been changed. + * @param index the new current index of the combobox + */ +void MainWindow::onVerboseIndexChanged(int index) +{ + BackupEngine::m_verboseLevel = (ReVerbose_t) index; } /** @@ -553,8 +565,9 @@ void MainWindow::startStop(bool isStart){ ui->actionStop->setEnabled(isStart); ui->pushButtonBackup->setEnabled(! isStart); ui->pushButtonStop->setEnabled(isStart); - ui->pushButtonChecksum->setEnabled(! isStart); - ui->actionChecksums->setEnabled(! isStart); + ui->pushButtonChecksum->setEnabled(! isStart); + ui->pushButtonClean->setEnabled(! isStart); + ui->actionChecksums->setEnabled(! isStart); if (isStart) BackupEngine::m_verboseLevel = (ReVerbose_t) ui->comboBoxVerbose->currentIndex(); } diff --git a/appl/rebackgui/mainwindow.hpp b/appl/rebackgui/mainwindow.hpp index d12b988..b043ff4 100644 --- a/appl/rebackgui/mainwindow.hpp +++ b/appl/rebackgui/mainwindow.hpp @@ -60,6 +60,7 @@ private slots: void onStop(); void onLoadConfig(); void onUpdate(); + void onVerboseIndexChanged(int index); void updateItem(int index); void updateTable(QTableWidget* target = NULL); void updateTableRow(int row, BackupItem& item, QTableWidget* target = NULL); diff --git a/base/ReQStringUtils.cpp b/base/ReQStringUtils.cpp index c4609df..dfb3346 100644 --- a/base/ReQStringUtils.cpp +++ b/base/ReQStringUtils.cpp @@ -547,7 +547,7 @@ QString ReQStringUtils::readableDuration(qint64 durationMilliSec){ QString ReQStringUtils::runtimeEstimation(const QDateTime& start, double factor){ qint64 duration = QDateTime::currentMSecsSinceEpoch() - start.toMSecsSinceEpoch(); - if (factor < 1) + if (factor > 1) factor = 1; else if (factor <= 0.001) factor = 0.001; -- 2.39.5