]> gitweb.hamatoma.de Git - reqt/commitdiff
rebackgui works (windows)
authorHamatoma <git.tortouse@hm.f-r-e-i.de>
Sat, 30 Jan 2016 18:29:26 +0000 (19:29 +0100)
committerHamatoma <git.tortouse@hm.f-r-e-i.de>
Sat, 30 Jan 2016 18:29:26 +0000 (19:29 +0100)
appl/rebackgui/BackupEngine.cpp
appl/rebackgui/mainwindow.cpp
appl/rebackgui/mainwindow.hpp
base/ReFileUtils.cpp
base/ReFileUtils.hpp
base/rebase.hpp

index 025c0a429b92627f99b16b37d597bcd1fd7793cd..2b280868fb32a05b508fe50388404e9fa6e49797 100644 (file)
@@ -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()));
 }
index 4a03b99a56291484f056eb79d4a3c9b40aa710ec..40746c9e29c7aff785ea64903f8accdb5c17907f 100644 (file)
@@ -10,7 +10,7 @@
 #include "aboutdialog.hpp"
 #include <QFileDialog>
 
-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<QListView*>("listView");
+    if (listView) {
+         listView->setSelectionMode(QAbstractItemView::MultiSelection);
+     }
+    QTreeView *treeView = dialog.findChild<QTreeView*>();
+     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;
+}
+
 
 
 
index c3c96fcf9fde0d91ebe64b866c93e9d2d3723e1a..9380514fd4f1ca8b49a09504f5a5e541bf2fff2d 100644 (file)
@@ -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
index 35a69f47ccf669552e62fde088091d9519b80582..4e36b449cd6f7caf7cc6bd12e4c3d2b5bb819d56 100644 (file)
@@ -405,8 +405,9 @@ bool ReFileUtils::isRootDir(const char* path)
  * @return                             the permissions used by linux,
  *                                             e.G. <code>S_IRUSR | S_IWGRP</code>
  */
-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);
index 2aed73313e4d142462c7ea0af9f69d344e6f9cc5..1f52787d32c5a7e6f784b5f218f1d7009d076888 100644 (file)
@@ -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.
index 2b9a535c2a6b73e21a1eda7b096d8769d4d65ecf..9322374a09f1aa228f07e533a9d0cc797228913e 100644 (file)
@@ -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