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;
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);
*/
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");
}
public:
virtual void run();
protected:
+ void copyFile(int index, const QString& relpath, const QString& node);
+private:
+ QString m_lastRelPath;
};
#endif // BACKUPPROCESSOR_HPP
+ 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())
}
+/**
+ * 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.
*
*
* @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;
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.
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);
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
- <number>1</number>
+ <number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
*/
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--) {
#include "base/rebase.hpp"
#include "gui/regui.hpp"
-
+#include <QListWidget>
/**
* Constructor.
*/
}
break;
}
+ case ListEnd:
+ {
+ QListWidget* list = reinterpret_cast<QListWidget*>(m_widget);
+ list->addItem(m_value);
+ list->setCurrentRow(list->count() - 1);
+ break;
+ }
default:
rc = false;
break;