From: Hamatoma Date: Sat, 30 Jan 2016 18:29:26 +0000 (+0100) Subject: rebackgui works (windows) X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=9588d29478f89fab1e4d54020897776dac6ea09b;p=reqt rebackgui works (windows) --- diff --git a/appl/rebackgui/BackupEngine.cpp b/appl/rebackgui/BackupEngine.cpp index 025c0a4..2b28086 100644 --- a/appl/rebackgui/BackupEngine.cpp +++ b/appl/rebackgui/BackupEngine.cpp @@ -253,7 +253,7 @@ void BackupTask::copyFile(int index, const QString& relPath, bool isFile; if (! ReFileUtils::isDirectory(targetDir, &isFile)){ if (isFile){ - if (unlink(I18N::s2b(targetDir).constData()) != 0) + if (_unlink(I18N::s2b(targetDir).constData()) != 0) error(tr("cannot remove file (for making a directory (%1): %2") .arg(errno).arg(targetDir)); } @@ -318,7 +318,8 @@ void BackupTask::run() .arg(ReQStringUtils::readableDuration(estimated))); } } - m_mainWindow->externalTaskFinished(tr("backup complete after ") - + ReQStringUtils::readableDuration( - QDateTime::currentMSecsSinceEpoch() - start)); + m_mainWindow->externalTaskFinished(tr("backup complete after %1. Errors: %2") + .arg(ReQStringUtils::readableDuration( + QDateTime::currentMSecsSinceEpoch() - start)) + .arg(m_mainWindow->errors())); } diff --git a/appl/rebackgui/mainwindow.cpp b/appl/rebackgui/mainwindow.cpp index 4a03b99..40746c9 100644 --- a/appl/rebackgui/mainwindow.cpp +++ b/appl/rebackgui/mainwindow.cpp @@ -10,7 +10,7 @@ #include "aboutdialog.hpp" #include -const QString VERSION("2016.01.20"); +const QString VERSION("2016.01.30"); /** * Constructor. @@ -27,7 +27,8 @@ MainWindow::MainWindow(const QString& homeDir, QWidget *parent) : m_currentRowBackup(0), m_lastSource(), m_searchTask(NULL), - m_backupTask(NULL) + m_backupTask(NULL), + m_errors(0) { ui->setupUi(this); initializeGuiElements(); @@ -113,6 +114,7 @@ void MainWindow::expandFileList(const QString info){ bool MainWindow::error(const QString& message){ ui->listWidgetError->addItem(message); ui->listWidgetError->setCurrentRow(ui->listWidgetError->count() - 1); + m_errors++; return false; } @@ -254,12 +256,41 @@ void MainWindow::onSelectionChanged(const QItemSelection& selected, * Handles the push of the button "select directory". */ void MainWindow::onAddSource(){ - QString dir = QFileDialog::getExistingDirectory(this, - tr("Select Source Directory"), m_lastSource, - QFileDialog::ShowDirsOnly); - if (!dir.isEmpty()){ - m_lastSource = ReFileUtils::nativePath(dir); - ui->listWidgetSource->addItem(m_lastSource); + QFileDialog dialog(NULL); + dialog.setOption(QFileDialog::ShowDirsOnly, true); + // native dialog does not support multiselection: + dialog.setOption(QFileDialog::DontUseNativeDialog,true); + dialog.setFileMode(QFileDialog::Directory); + dialog.setWindowTitle(tr("Select Source Directory")); + dialog.setDirectory(ReFileUtils::parentOf(m_lastSource)); + QListView *listView = dialog.findChild("listView"); + if (listView) { + listView->setSelectionMode(QAbstractItemView::MultiSelection); + } + QTreeView *treeView = dialog.findChild(); + if (treeView) { + treeView->setSelectionMode(QAbstractItemView::MultiSelection); + } + + if (dialog.exec()){ + QStringList dirs = dialog.selectedFiles(); + if (dirs.size() > 0){ + m_lastSource = ReFileUtils::nativePath(dirs.at(0)); + for (int ix = 0; ix < dirs.size(); ix++){ + QString newEntry = ReFileUtils::nativePath(dirs.at(ix)); + bool found = false; + for (int ix2 = 0; ! found && ix2 < ui->listWidgetSource->count(); ix2++){ + QString oldEntry = ui->listWidgetSource->item(ix2)->text(); + if (oldEntry.isEmpty()){ + ui->listWidgetSource->takeItem(ix2); + ix2--; + } + found = oldEntry == newEntry; + } + if (! found) + ui->listWidgetSource->addItem(newEntry); + } + } } } @@ -347,7 +378,7 @@ void MainWindow::onStart(){ BackupEngine::m_totalFiles = 0; BackupEngine::m_processedFiles = 0; BackupEngine::m_processedBytes = 0; - + m_errors = 0; QString target = BackupUtils::findTarget(item, &m_logger); if (target.isEmpty()){ say(LOG_ERROR, tr("Target not available")); @@ -461,15 +492,17 @@ void MainWindow::startStop(bool isStart){ */ void MainWindow::updateItem(int index){ m_currentRowConfiguration = index; - BackupItem& item = m_configuration.items()[index]; - ui->lineEditName->setText(item.m_name); - ui->lineEditTarget->setText(item.m_target); - ui->listWidgetSource->clear(); - ui->comboBoxFilePatterns->setEditText(item.m_filePatterns); - ui->comboBoxDirPatterns->setEditText(item.m_dirPatterns); - for (int ix = 0; ix < item.m_sources.size(); ix++){ - ui->listWidgetSource->insertItem(ix, m_lastSource = item.m_sources.at(ix)); - } + if (index < m_configuration.items().size()){ + BackupItem& item = m_configuration.items()[index]; + ui->lineEditName->setText(item.m_name); + ui->lineEditTarget->setText(item.m_target); + ui->listWidgetSource->clear(); + ui->comboBoxFilePatterns->setEditText(item.m_filePatterns); + ui->comboBoxDirPatterns->setEditText(item.m_dirPatterns); + for (int ix = 0; ix < item.m_sources.size(); ix++){ + ui->listWidgetSource->insertItem(ix, m_lastSource = item.m_sources.at(ix)); + } + } } /** @@ -511,6 +544,11 @@ void MainWindow::updateTableRow(int row, BackupItem& item, QTableWidget* target) target->setItem(row, base + 3, new QTableWidgetItem(item.m_sources.join(" "))); } } +int MainWindow::errors() const +{ + return m_errors; +} + diff --git a/appl/rebackgui/mainwindow.hpp b/appl/rebackgui/mainwindow.hpp index c3c96fc..9380514 100644 --- a/appl/rebackgui/mainwindow.hpp +++ b/appl/rebackgui/mainwindow.hpp @@ -26,6 +26,7 @@ public: void addToFileList(const QString info); QString buildTargetDir(const QString& target); bool error(const QString& message); + int errors() const; void expandFileList(const QString info); bool log(const QString& message); virtual bool say(ReLoggerLevel level, const QString& message); @@ -33,6 +34,7 @@ public: void startStop(bool isStart); void restoreState(); void saveState(); + private: QString extractTarget(const QString& dir); private slots: @@ -65,6 +67,7 @@ private: QString m_lastSource; SearchTask* m_searchTask; BackupTask* m_backupTask; + int m_errors; }; #endif // MAINWINDOW_HPP diff --git a/base/ReFileUtils.cpp b/base/ReFileUtils.cpp index 35a69f4..4e36b44 100644 --- a/base/ReFileUtils.cpp +++ b/base/ReFileUtils.cpp @@ -405,8 +405,9 @@ bool ReFileUtils::isRootDir(const char* path) * @return the permissions used by linux, * e.G. S_IRUSR | S_IWGRP */ -mode_t ReFileUtils::linuxPermissions(QFile::Permissions permissions){ +mode_t ReFileUtils::nativePermissions(QFile::Permissions permissions){ mode_t rc = 0; +#if defined __linux__ if (permissions.testFlag(QFile::ReadOwner)) rc |= S_IRUSR; if (permissions.testFlag(QFile::ReadGroup)) @@ -425,6 +426,12 @@ mode_t ReFileUtils::linuxPermissions(QFile::Permissions permissions){ rc |= S_IXGRP; if (permissions.testFlag(QFile::ExeOther)) rc |= S_IXOTH; +#elif defined _WIN32 + if (permissions.testFlag(QFile::ReadOwner) || permissions.testFlag(QFile::ReadOther)) + rc |= _S_IREAD; + if (permissions.testFlag(QFile::ReadOwner) ||permissions.testFlag(QFile::WriteOther)) + rc |= _S_IWRITE; +#endif return rc; } @@ -484,6 +491,8 @@ bool ReFileUtils::makeDirWithParents(const char* path, ReLogger* logger) { else { const char* end; const char* start = path; + rc = true; + dir.clear(); while (rc && (end = strchr(start, OS_SEPARATOR)) != NULL) { if (end == path) { start++; @@ -492,8 +501,10 @@ bool ReFileUtils::makeDirWithParents(const char* path, ReLogger* logger) { dir.append(start, end - start); start = end + 1; #if defined _WIN32 - if (dir.length() == 2 && dir.at(1) == ':') + if (dir.length() == 2 && dir.at(1) == ':'){ + dir.append(OS_SEPARATOR); continue; + } #endif rc = makeDir(dir.constData(), logger); dir += OS_SEPARATOR; @@ -793,7 +804,7 @@ void ReFileUtils::splitUrl(const QString& url, QString* protocol, QString* host, bool ReFileUtils::setPermissions(const char* filename, QFile::Permissions permissions, ReLogger* logger) { bool rc = true; - if (chmod(filename, linuxPermissions(permissions)) != 0){ + if (chmod(filename, nativePermissions(permissions)) != 0){ if (logger != NULL) logger->logv(LOG_ERROR, LOC_SET_TIMES_1, "cannot change permissions (%d): $s", errno, filename); diff --git a/base/ReFileUtils.hpp b/base/ReFileUtils.hpp index 2aed733..1f52787 100644 --- a/base/ReFileUtils.hpp +++ b/base/ReFileUtils.hpp @@ -41,7 +41,7 @@ public: static bool isAbsolutPath(const char* path); static bool isDirectory(const QString& path, bool* isFile = NULL); static bool isRootDir(const char* path); - static mode_t linuxPermissions(QFile::Permissions permissions); + static mode_t nativePermissions(QFile::Permissions permissions); /** Returns a path with native separators. * QT under windows can operator with 2 separators: '\\' and '/'. * '\\' is the native separator. diff --git a/base/rebase.hpp b/base/rebase.hpp index 2b9a535..9322374 100644 --- a/base/rebase.hpp +++ b/base/rebase.hpp @@ -66,6 +66,7 @@ typedef QString ReString; #ifdef _WIN32 typedef quint64 uint64_t; typedef short int int16_t; +typedef int mode_t; #endif #ifdef __linux__ #define _strcasecmp strcasecmp