int BackupEngine::m_totalDirs = 0;
bool BackupEngine::m_searchReady = false;
QMutex BackupEngine::m_mutex;
+QChar BackupEngine::m_separator = '\t';
+QString BackupEngine::m_separatorString = "\t";
/**
* Constructor.
*
+ * @param name name of the task
* @param sourceDirs the list of source directories to inspect
* @param targetDir the base of the target directories
* @param mainWindow the GUI module
*/
-BackupEngine::BackupEngine(const QStringList& sourceDirs, const QString& targetDir,
+BackupEngine::BackupEngine(const QString& name,
+ const QStringList& sourceDirs, const QString& targetDir,
MainWindow* mainWindow) :
QThread(),
m_sourceDirs(sourceDirs),
- m_targetDir(targetDir),
- m_mainWindow(mainWindow)
+ m_targetBaseDir(targetDir),
+ m_targetDirs(),
+ m_mainWindow(mainWindow),
+ m_name(name)
{
-
+ ReQStringUtils::ensureLastChar(m_targetBaseDir, OS_SEPARATOR);
+ for (int ix = 0; ix < sourceDirs.size(); ix++){
+ ReQStringUtils::ensureLastChar(m_sourceDirs[ix], OS_SEPARATOR);
+ QString node = ReFileUtils::nodeOf(m_sourceDirs.at(ix).mid(0,
+ m_sourceDirs.at(ix).length() - 1));
+ if (! node.isEmpty())
+ node += OS_SEPARATOR_STR;
+ m_targetDirs.append(m_targetBaseDir + node);
+ }
}
/**
/**
* Constructor.
*
+ * @param name name of the task
* @param filePatterns only files which match the patterns will be found
* @param dirPatterns only subdirectories which matches the patterns will be entered
* @param source the list of base directories to search
* @param targetDir the base target directory
* @param mainWindow the GUI module, the parent
*/
-SearchTask::SearchTask(const QString& filePatterns, const QString& dirPatterns,
- const QStringList& sourceDirs, const QString& targetDir,
- MainWindow* mainWindow) :
- BackupEngine(sourceDirs, targetDir, mainWindow),
+SearchTask::SearchTask(const QString& name,
+ const QString& filePatterns, const QString& dirPatterns,
+ const QStringList& sourceDirs, const QString& targetDir,
+ MainWindow* mainWindow) :
+ BackupEngine(name, sourceDirs, targetDir, mainWindow),
m_fileMatcher(filePatterns),
m_dirMatcher(dirPatterns)
{
qint64 start = QDateTime::currentMSecsSinceEpoch();
m_searchReady = false;
for (int ix = 0; ix < m_sourceDirs.size(); ix++){
- processOneDirectory(m_sourceDirs.at(ix), m_targetDir, ix);
+ processOneDirectory(m_sourceDirs.at(ix), m_targetBaseDir, ix);
}
m_searchReady = true;
m_mainWindow->externalLog(tr("%1 matching file(s) under %2 with %3 in %4 subdirs %5")
void SearchTask::processOneDirectory(const QString& source,
const QString& target, int index){
QDirIterator it(source);
- QString relPath;
+ QString prefix;
QString info, node;
int lengthBase = m_sourceDirs.at(index).length();
if (source.length() > lengthBase){
- relPath = source.mid(lengthBase + 1) + OS_SEPARATOR_STR;
+ prefix = QChar(1 + index) + source.mid(lengthBase) + OS_SEPARATOR_STR
+ + m_separator;
+ } else {
+ prefix = QChar(1 + index) + m_separatorString;
}
while (it.hasNext()){
if (m_shouldStop){
}
if (doCopy){
assert(index < 0x7fff);
- info = QChar(1 + index) + relPath + "\t" + it.fileName();
+ info = prefix + it.fileName();
}
m_mutex.lock();
if (doCopy){
/**
* Constructor.
*
+ * @param name name of the task
* @param sourceDirs the list of source directories to inspect
* @param targetDir the base of the target directories
* @param mainWindow the GUI module
*/
-BackupTask::BackupTask(const QStringList& sourceDirs, const QString& targetDir,
+BackupTask::BackupTask(const QString& name,
+ const QStringList& sourceDirs, const QString& targetDir,
MainWindow* mainWindow) :
- BackupEngine(sourceDirs, targetDir, mainWindow),
+ BackupEngine(name, sourceDirs, targetDir, mainWindow),
m_lastRelPath()
{
* @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;
+ QString source = m_sourceDirs.at(index) + relPath + node;
+ QString target = m_targetDirs.at(index) + relPath + node;
m_mainWindow->addToFileList(source + " -> " + target);
}
*/
void BackupTask::run()
{
- int count = 1;
QString relPath, node;
QString info;
- while (! m_shouldStop){
+ while (true){
m_mutex.lock();
if (m_files.size() == 0)
info.clear();
if (m_searchReady)
break;
else
- QThread::sleep(50);
+ QThread::msleep(50);
} else {
int index = int(info.at(0).unicode()) - 1;
- int pos = info.indexOf('\t', 1);
- relPath = info.mid(1, pos - 2);
+ int pos = info.indexOf(m_separator, 1);
+ if (pos == 1)
+ relPath.clear();
+ else
+ relPath = info.mid(1, pos - 1);
node = info.mid(pos + 1);
copyFile(index, relPath, node);
}
class BackupEngine : public QThread
{
public:
- BackupEngine(const QStringList& sourceDirs, const QString& targetDir,
+ BackupEngine(const QString& name,
+ const QStringList& sourceDirs, const QString& targetDir,
MainWindow* mainWindow);
public:
bool error(const QString& message);
protected:
virtual void run() = 0;
protected:
+ // list of source dirs, trailing with separator
QStringList m_sourceDirs;
- QString m_targetDir;
+ // target base directory, trailing with separator. Contains all target dirs
+ QString m_targetBaseDir;
+ // list of target dirs, trailing with separator. Same node as m_sourceDirs
+ QStringList m_targetDirs;
MainWindow* m_mainWindow;
+ QString m_name;
public:
static bool m_shouldStop;
static QStringList m_files;
static int m_totalDirs;
static bool m_searchReady;
static QMutex m_mutex;
+ static QChar m_separator;
+ static QString m_separatorString;
};
class SearchTask : public BackupEngine
{
public:
- SearchTask(const QString& filePatterns, const QString& dirPatterns,
+ SearchTask(const QString& name,
+ const QString& filePatterns, const QString& dirPatterns,
const QStringList& sourceDirs, const QString& targetDir,
MainWindow* mainWindow);
public:
class BackupTask : public BackupEngine
{
public:
- BackupTask(const QStringList& sourceDirs, const QString& targetDir,
+ BackupTask(const QString& name, const QStringList& sourceDirs, const QString& targetDir,
MainWindow* mainWindow);
public:
virtual void run();
const QString VERSION("2016.01.20");
+/**
+ * Constructor.
+ *
+ * @param homeDir the home directory. If "": usage of the user's homedir
+ * @param parent QT parent or NULL
+ */
MainWindow::MainWindow(const QString& homeDir, QWidget *parent) :
ReGuiApplication("rebackupgui", homeDir, 2, 100100100, parent),
ReGuiValidator(),
SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)),
this,
SLOT(onCurrentChanged(const QModelIndex&, const QModelIndex&)));
+ connect(ui->pushButtonClearFileList, SIGNAL(clicked()), this, SLOT(onClearFileList()));
+ connect(ui->pushButtonClearErrorList, SIGNAL(clicked()), this, SLOT(onClearErrorList()));
+ connect(ui->pushButtonClear, SIGNAL(clicked()), this, SLOT(onClearLog()));
m_configuration.load("");
updateTable();
updateItem(0);
}
}
-void MainWindow::onSelectionChanged(const QItemSelection& selected, const QItemSelection& deselected){
+/**
+ * @brief MainWindow::onSelectionChanged
+ * @param selected
+ * @param deselected
+ */
+void MainWindow::onSelectionChanged(const QItemSelection& selected,
+ const QItemSelection& deselected){
+ UNUSED_VAR(deselected);
int count = selected.indexes().size();
if (count > 0){
int ix = selected.indexes().at(0).row();
}
}
+/**
+ * Remove the lines of hte file list.
+ */
+void MainWindow::onClearErrorList()
+{
+ ui->listWidgetError->clear();
+}
+
+/**
+ * Remove the lines of the log list.
+ */
+void MainWindow::onClearLog()
+{
+ ui->listWidgetLog->clear();
+}
+
+/**
+ * Remove the lines of hte file list.
+ */
+void MainWindow::onClearFileList()
+{
+ ui->listWidgetFile->clear();
+}
+
/**
* Handles the push of the button "select directory".
*/
*/
void MainWindow::onCurrentChanged(const QModelIndex & current,
const QModelIndex & previous){
+ UNUSED_VAR(previous);
int row = current.row();
updateItem(row);
}
* Starts the backup.
*/
void MainWindow::onStart(){
- startStop(true);
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, target, this);
- m_searchTask->start();
- delete m_backupTask;
- m_backupTask = new BackupTask(item.m_sources, target,
- this);
- m_backupTask->start();
+ if (row < 0){
+ say(LOG_ERROR, tr("no backup item selected"));
+ } else {
+ startStop(true);
+ 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_name,
+ item.m_filePatterns, item.m_dirPatterns,
+ item.m_sources, target, this);
+ m_searchTask->start();
+ delete m_backupTask;
+ m_backupTask = new BackupTask(item.m_name, item.m_sources, target,
+ this);
+ m_backupTask->start();
+ }
}
/**
* Stops the backup.