]> gitweb.hamatoma.de Git - reqt/commitdiff
dayly work
authorhama <hama@siduction.net>
Mon, 25 Jan 2016 23:14:25 +0000 (00:14 +0100)
committerhama <hama@siduction.net>
Mon, 25 Jan 2016 23:14:25 +0000 (00:14 +0100)
appl/rebackgui/BackupEngine.cpp
appl/rebackgui/BackupEngine.hpp
appl/rebackgui/Configuration.cpp
appl/rebackgui/mainwindow.cpp
appl/rebackgui/mainwindow.hpp
appl/rebackgui/mainwindow.ui
base/ReMatcher.cpp
gui/ReGuiQueue.cpp

index c01718ed84e2063b96662a34522769df7a1b9ab8..a102d938b5659e39a6099316d95b2ec95890d8eb 100644 (file)
@@ -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");
 }
index fb665c5c14b1c791baddd67f9c5c8ac55787be33..028039ed40f0886de9db848d70541762858654cd 100644 (file)
@@ -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
index 633261c1f452de0ac7221d451f5c05d92c2b7a68..dc5d2410b0b291d9727aab2096efcf8a7d2c47ba 100644 (file)
@@ -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())
index 38ed8559de7b891b9abe2e1ad0f81aa1719d30c3..c13ef37cacebf19b8e01545147587dc73b10490f 100644 (file)
@@ -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.
index ea6a7fa36349bdf2316cb4609c282b7d92ffbff7..00215b0257cd787164c2af9c3a76e85a881e9378 100644 (file)
@@ -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);
index 945433d8f24a7e51f1cb4f3757c2141bbb349750..6cf4e042b056f5a79652585402a944cce0f4cc3c 100644 (file)
@@ -18,7 +18,7 @@
     <item>
      <widget class="QTabWidget" name="tabWidget">
       <property name="currentIndex">
-       <number>1</number>
+       <number>0</number>
       </property>
       <widget class="QWidget" name="tab">
        <attribute name="title">
index ec7c9f04698182d805356031b07b0438130949bc..5b3d9de1b6e9b94d150acb06f4bd1a3b2e07fd47 100644 (file)
@@ -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--) {
index 7a79dccae1aa726402b89a624a0df7346309166b..810eef020095ddb7a0e647e41de399c0b712e049 100644 (file)
@@ -11,7 +11,7 @@
 
 #include "base/rebase.hpp"
 #include "gui/regui.hpp"
-
+#include <QListWidget>
 /**
  * Constructor.
  */
@@ -92,6 +92,13 @@ bool ReGuiQueueItem::apply() const
                        }
                        break;
                }
+               case ListEnd:
+               {
+                       QListWidget* list = reinterpret_cast<QListWidget*>(m_widget);
+                       list->addItem(m_value);
+                       list->setCurrentRow(list->count() - 1);
+                       break;
+               }
                default:
                        rc = false;
                        break;