From: hama Date: Sun, 14 Feb 2016 22:59:38 +0000 (+0100) Subject: rebackgui: reload of last backup date, menu X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=50f7a6f8045ef7f4e532fbba2189220e8333d1c9;p=reqt rebackgui: reload of last backup date, menu --- diff --git a/appl/rebackgui/BackupUtils.cpp b/appl/rebackgui/BackupUtils.cpp index 551f489..620ec14 100644 --- a/appl/rebackgui/BackupUtils.cpp +++ b/appl/rebackgui/BackupUtils.cpp @@ -8,119 +8,118 @@ * More info: http://unlicense.org * The latest sources: https://github.com/republib */ -#include "backupgui.hpp" - -BackupUtils::BackupUtils() -{ - -} -/** - * Converts a date time to a string. - * - * @param dateTime the timepoint to convert - * @return the string representation - */ -QString BackupUtils::dateToString(const QDateTime &dateTime) -{ - QString rc = dateTime.toString("yyyy.MM.dd/hh:mm:ss"); - return rc; -} - -/** - * Finds the real path of a target directory. - * - * Note: if the medium of the target is an external medium - * the path can change. - * - * @param item the info about the backup item - * @return "": not found
- * otherwise: the full path of the target directory - */ -QString BackupUtils::findTarget(const BackupItem& item, ReLogger* logger) -{ - QString rc; -#if defined __linux__ - if (item.m_target.startsWith(";/")){ - // the path is an absolute path on a fixed disk: - rc = item.m_target.mid(1); - } else { - - } -#elif defined _WIN32 - QStringList drives = ReFileUtils::findRootDirs(); - QStringList::const_iterator it; - for (it = drives.cbegin(); it != drives.cend(); ++it){ - QString path = *it; - ReQStringUtils::ensureLastChar(path, OS_SEPARATOR); - int pos = item.m_target.indexOf(';'); - if (pos >= 0) - path += item.m_target.mid(pos + 1); - else - path += item.m_target; - QString markerFile = nameOfTargetDescription(path); - if (QFileInfo(markerFile).exists()){ - if (rc.isEmpty()) - rc = ReFileUtils::parentOf(markerFile); - ReConfig config(I18N::s2b(markerFile), true, logger); - if (! config.asString((item.m_uid + ".created").toLatin1(), - "").isEmpty()){ - rc = ReFileUtils::parentOf(markerFile); - break; - } - } - } -#endif - return rc; -} - -/** - * Returns the name of the file marking a backup target. - * - * @param path the path of the file - * @return the full name of the file - */ -QString BackupUtils::nameOfTargetDescription(const QString& path){ - QString fname = path; - ReQStringUtils::ensureLastChar(fname, OS_SEPARATOR); - fname += ".rebackgui.target"; - return fname; -} - -/** - * Prepares the target base directory. - * - * Creates a file. The program uses this file to recognize a target directory. - * - * @param path the target base directory - * @param item the info about the backup item - * @param logger the logger - * @return true: target is already initialized - */ -bool BackupUtils::prepareTarget(const QString& path, BackupItem &item, - ReLogger* logger) -{ - bool rc = false; - QString fname = nameOfTargetDescription(path); - ReConfig config(I18N::s2b(fname), false, logger); - QByteArray key = item.m_uid.toLatin1() + ".created"; - if (config.asString(key.constData(), "").isEmpty()){ - config.put(key, dateToString(QDateTime::currentDateTime()).toLatin1().constData()); - rc = true; - } - return rc; -} - -/** - * Converts a string into a date time. - * - * @param dateTime the string convert - * @return the date time - */ -QDateTime BackupUtils::stringToDate(const QString &dateTime) -{ - QDateTime rc; - rc.fromString(dateTime, "yyyy.MM.dd/hh:mm:ss"); - return rc; -} - - +#include "backupgui.hpp" + +BackupUtils::BackupUtils() +{ + +} +/** + * Converts a date time to a string. + * + * @param dateTime the timepoint to convert + * @return the string representation + */ +QString BackupUtils::dateToString(const QDateTime &dateTime) +{ + QString rc = dateTime.toString("yyyy.MM.dd/hh:mm:ss"); + return rc; +} + +/** + * Finds the real path of a target directory. + * + * Note: if the medium of the target is an external medium + * the path can change. + * + * @param item the info about the backup item + * @return "": not found
+ * otherwise: the full path of the target directory + */ +QString BackupUtils::findTarget(const BackupItem& item, ReLogger* logger) +{ + QString rc; +#if defined __linux__ + if (item.m_target.startsWith(";/")){ + // the path is an absolute path on a fixed disk: + rc = item.m_target.mid(1); + } else { + + } +#elif defined _WIN32 + QStringList drives = ReFileUtils::findRootDirs(); + QStringList::const_iterator it; + for (it = drives.cbegin(); it != drives.cend(); ++it){ + QString path = *it; + ReQStringUtils::ensureLastChar(path, OS_SEPARATOR); + int pos = item.m_target.indexOf(';'); + if (pos >= 0) + path += item.m_target.mid(pos + 1); + else + path += item.m_target; + QString markerFile = nameOfTargetDescription(path); + if (QFileInfo(markerFile).exists()){ + if (rc.isEmpty()) + rc = ReFileUtils::parentOf(markerFile); + ReConfig config(I18N::s2b(markerFile), true, logger); + if (! config.asString((item.m_uid + ".created").toLatin1(), + "").isEmpty()){ + rc = ReFileUtils::parentOf(markerFile); + break; + } + } + } +#endif + return rc; +} + +/** + * Returns the name of the file marking a backup target. + * + * @param path the path of the file + * @return the full name of the file + */ +QString BackupUtils::nameOfTargetDescription(const QString& path){ + QString fname = path; + ReQStringUtils::ensureLastChar(fname, OS_SEPARATOR); + fname += ".rebackgui.target"; + return fname; +} + +/** + * Prepares the target base directory. + * + * Creates a file. The program uses this file to recognize a target directory. + * + * @param path the target base directory + * @param item the info about the backup item + * @param logger the logger + * @return true: target is already initialized + */ +bool BackupUtils::prepareTarget(const QString& path, BackupItem &item, + ReLogger* logger) +{ + bool rc = false; + QString fname = nameOfTargetDescription(path); + ReConfig config(I18N::s2b(fname), false, logger); + QByteArray key = item.m_uid.toLatin1() + ".created"; + if (config.asString(key.constData(), "").isEmpty()){ + config.put(key, dateToString(QDateTime::currentDateTime()).toLatin1().constData()); + rc = true; + } + return rc; +} + +/** + * Converts a string into a date time. + * + * @param dateTime the string convert + * @return the date time + */ +QDateTime BackupUtils::stringToDate(const QString &dateTime) +{ + QDateTime rc = QDateTime::fromString(dateTime, "yyyy.MM.dd/hh:mm:ss"); + return rc; +} + + diff --git a/appl/rebackgui/Configuration.cpp b/appl/rebackgui/Configuration.cpp index b6edc2c..e0f0c4c 100644 --- a/appl/rebackgui/Configuration.cpp +++ b/appl/rebackgui/Configuration.cpp @@ -20,7 +20,8 @@ BackupItem::BackupItem() : m_name(), m_sources(), m_target(), - m_lastBackup(){ + m_lastBackup(), + m_active(false){ } /** @@ -34,7 +35,8 @@ BackupItem::BackupItem(int no) : m_name(), m_sources(), m_target(), - m_lastBackup(){ + m_lastBackup(), + m_active(false){ } /** @@ -155,6 +157,7 @@ void Configuration::load(QString filename) m_items.clear(); QList::iterator it; for (it = keys.begin(); it != keys.end(); ++it){ + readBackupDate(map[*it]); m_items.append(map[*it]); } } @@ -163,6 +166,32 @@ void Configuration::load(QString filename) check(); } +/** + * Reads the last backup date from the target description file. + * + * @param item the item to inspect + * @return true: the last backup date has been found (and + * set in item) + */ +bool Configuration::readBackupDate(BackupItem& item){ + bool rc = false; + QString target = BackupUtils::findTarget(item, m_mainWindow->logger()); + if (! target.isEmpty()){ + item.m_active = true; + QString name = BackupUtils::nameOfTargetDescription(target); + ReConfig config(I18N::s2b(name).constData()); + rc = item.m_active = config.exists(); + if (rc){ + QByteArray key = item.m_uid.toLatin1() + ".lastbackup"; + QByteArray date = config.asString(key, ""); + if (date.length() > 1){ + item.m_lastBackup = BackupUtils::stringToDate(date); + } + } + } + return rc; +} + /** * Saves the configuration file. * diff --git a/appl/rebackgui/Configuration.hpp b/appl/rebackgui/Configuration.hpp index 4c4ca6e..17933c9 100644 --- a/appl/rebackgui/Configuration.hpp +++ b/appl/rebackgui/Configuration.hpp @@ -20,13 +20,14 @@ public: BackupItem(int no); public: int m_no; - QString m_uid; + QString m_uid; QString m_name; QStringList m_sources; QString m_target; QDateTime m_lastBackup; QString m_filePatterns; QString m_dirPatterns; + bool m_active; }; typedef QMap BackupItemMap; typedef QList BackupItemList; @@ -40,6 +41,7 @@ public: void check(); BackupItemList& items(); void load(QString filename); + bool readBackupDate(BackupItem& item); void save(QString filename); private: diff --git a/appl/rebackgui/mainwindow.cpp b/appl/rebackgui/mainwindow.cpp index 6319648..ce0cec6 100644 --- a/appl/rebackgui/mainwindow.cpp +++ b/appl/rebackgui/mainwindow.cpp @@ -45,6 +45,8 @@ MainWindow::MainWindow(const QString& homeDir, QWidget *parent) : SLOT(onStart())); connect(ui->actionChecksums, SIGNAL(triggered()), this, SLOT(onChecksums())); + connect(ui->actionClean, SIGNAL(triggered()), this, + SLOT(onClean())); connect(ui->actionStop, SIGNAL(triggered()), this, SLOT(onStop())); connect(ui->pushButtonBackup, SIGNAL(clicked()), this, SLOT(onStart())); @@ -191,11 +193,11 @@ void MainWindow::onGuiTimerUpdate() * otherwise: error occurred */ bool MainWindow::initializeStart(){ - setStatusMessage(LOG_INFO, QObject::tr("Search started...")); + setStatusMessage(LOG_INFO, QObject::tr("Search started...")); bool rc = true; - BackupEngine::m_shouldStop = false; - 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; @@ -495,7 +497,7 @@ void MainWindow::onUpdate(){ item.m_sources.append(ui->listWidgetSource->item(ix)->text()); } updateTable(); - saveState(); + saveState(); } /** @@ -504,7 +506,7 @@ void MainWindow::onUpdate(){ */ void MainWindow::onVerboseIndexChanged(int index) { - BackupEngine::m_verboseLevel = (ReVerbose_t) index; + BackupEngine::m_verboseLevel = (ReVerbose_t) index; } /** @@ -565,9 +567,10 @@ void MainWindow::startStop(bool isStart){ ui->actionStop->setEnabled(isStart); ui->pushButtonBackup->setEnabled(! isStart); ui->pushButtonStop->setEnabled(isStart); - ui->pushButtonChecksum->setEnabled(! isStart); - ui->pushButtonClean->setEnabled(! isStart); - ui->actionChecksums->setEnabled(! isStart); + ui->pushButtonChecksum->setEnabled(! isStart); + ui->pushButtonClean->setEnabled(! isStart); + ui->actionChecksums->setEnabled(! isStart); + ui->actionClean->setEnabled(! isStart); if (isStart) BackupEngine::m_verboseLevel = (ReVerbose_t) ui->comboBoxVerbose->currentIndex(); } @@ -625,6 +628,9 @@ void MainWindow::updateTableRow(int row, BackupItem& item, QTableWidget* target) updateTableRow(row, item, ui->tableWidgetConfiguration); } else { int base = target == ui->tableWidget ? 1 : 0; + QString active = QObject::tr(item.m_active ? "yes" : "no"); + if (base == 1) + target->setItem(row, 0, new QTableWidgetItem(active)); target->setItem(row, base + 0, new QTableWidgetItem(item.m_name)); target->setItem(row, base + 1, new QTableWidgetItem(item.m_target)); target->setItem(row, base + 2, new QTableWidgetItem(! item.m_lastBackup.isValid() ? "" : diff --git a/appl/rebackgui/mainwindow.ui b/appl/rebackgui/mainwindow.ui index 884d43f..1d967cf 100644 --- a/appl/rebackgui/mainwindow.ui +++ b/appl/rebackgui/mainwindow.ui @@ -806,6 +806,7 @@ + @@ -859,6 +860,11 @@ Calculates checksums for source and target files and reports differences + + + Clean + + diff --git a/base/ReConfig.cpp b/base/ReConfig.cpp index 593d9a1..ca86e2d 100644 --- a/base/ReConfig.cpp +++ b/base/ReConfig.cpp @@ -55,7 +55,8 @@ ReConfig::ReConfig(const char* file, bool readOnly, ReLogger* logger) : m_readOnly(readOnly), m_logger(logger), m_ownLogger(logger == NULL), - m_modified(false){ + m_modified(false), + m_exists(false){ if (logger == NULL) { initLogger(); } @@ -90,6 +91,15 @@ void ReConfig::initLogger() { m_logger->addAppender(appender2); } +/** + * Returns whether the configuration file exists. + * @return true: the file exists. + */ +bool ReConfig::exists() const +{ + return m_exists; +} + /** * Returns configuration value as an integer. * @@ -190,6 +200,7 @@ bool ReConfig::read(const char* file) { if (file == NULL) file = m_file.constData(); FILE* fp = fopen(file, "r"); + m_exists = fp != NULL; if (fp == NULL) { m_logger->logv(LOG_ERROR, LOC_READ_1, "cannot read: %s", file); rc = false; diff --git a/base/ReConfig.hpp b/base/ReConfig.hpp index a862ed0..617e566 100644 --- a/base/ReConfig.hpp +++ b/base/ReConfig.hpp @@ -14,7 +14,7 @@ class ReConfig: public ReConfigurator, protected QHash { public: ReConfig(const char* file = NULL, bool readOnly = true, ReLogger* logger = - NULL); + NULL); virtual ~ReConfig(); public: @@ -22,6 +22,7 @@ public: virtual int asInt(const char* key, int defaultValue) const; virtual QByteArray asString(const char* key, const char* defaultValue); void clear(); + bool exists() const; const QList& getLines() const; void put(const char* key, bool value); void put(const char* key, int value); @@ -39,6 +40,7 @@ private: // true: the logger must be destroyed in the destructor bool m_ownLogger; bool m_modified; + bool m_exists; }; #endif // RECONFIG_HPP