#include "backupgui.hpp"
//#define WITH_TRACE
#include "base/retrace.hpp"
-DECLARE_TRACER(s_traceSearch, "/tmp/bup_search.log");
-DECLARE_TRACER(s_traceBackup, "/tmp/bup_backup.log");
-DECLARE_TRACER(s_traceChecksum, "/tmp/bup_sum.log");
-DECLARE_TRACER(s_traceClean, "/tmp/bup_clean.log");
+DECLARE_TRACER(s_traceSearch, "/tmp/bup_search.log")
+DECLARE_TRACER(s_traceBackup, "/tmp/bup_backup.log")
+DECLARE_TRACER(s_traceChecksum, "/tmp/bup_sum.log")
+DECLARE_TRACER(s_traceClean, "/tmp/bup_clean.log")
+#ifdef USE_MUTEX
+#define MUTEX_LOCK(mutex) mutex.lock()
+#define MUTEX_UNLOCK(mutex) m_mutex.release()
+#else
+#define MUTEX_LOCK(mutex)
+#define MUTEX_UNLOCK(mutex)
+#endif
ReVerbose_t BackupEngine::m_verboseLevel = VerboseStandard;
bool BackupEngine::m_shouldStop = false;
QStringList BackupEngine::m_files;
-qint64 BackupEngine::m_hotBytes = 0;
-qint64 BackupEngine::m_processedBytes = 0;
-int BackupEngine::m_processedFiles = 0;
-int BackupEngine::m_matchedFiles = 0;
-int BackupEngine::m_hotFiles = 0;
-int BackupEngine::m_totalFiles = 0;
-int BackupEngine::m_totalDirs = 0;
bool BackupEngine::m_searchReady = false;
QMutex BackupEngine::m_mutex;
QChar BackupEngine::m_separator = '\t';
*/
BackupEngine::BackupEngine(const QString& name,
const QStringList& sourceDirs, const QString& targetDir,
- MainWindow* mainWindow) :
+ ReFileTreeStatistic& statistic, MainWindow* mainWindow) :
QThread(),
m_sourceDirs(sourceDirs),
m_targetBaseDir(targetDir),
m_shadowBaseDir(),
m_shadowDirs(),
m_mainWindow(mainWindow),
+ m_statistic(statistic),
m_name(name)
{
+ m_statistic.clear();
ReQStringUtils::ensureLastChar(m_targetBaseDir, OS_SEPARATOR);
for (int ix = 0; ix < sourceDirs.size(); ix++){
ReQStringUtils::ensureLastChar(m_sourceDirs[ix], OS_SEPARATOR);
*/
BackupTask::BackupTask(const QString& name,
const QStringList& sourceDirs, const QString& targetDir,
- MainWindow* mainWindow) :
- BackupEngine(name, sourceDirs, targetDir, mainWindow),
+ ReFileTreeStatistic& statistic, MainWindow* mainWindow) :
+ BackupEngine(name, sourceDirs, targetDir, statistic, mainWindow),
m_lastRelPath(),
m_buffer()
{
QFileInfo sourceInfo(source);
if (m_verboseLevel >= VerboseStandard)
m_mainWindow->addToFileList(target + " " + ReQStringUtils::readableSize(sourceInfo.size()));
- m_mutex.lock();
- m_processedFiles++;
- m_processedBytes += sourceInfo.size();
- m_mutex.unlock();
+ MUTEX_LOCK(m_mutex);
+ m_statistic.m_processed.addFile(sourceInfo.size());
+ MUTEX_UNLOCK(m_mutex);
QString errorMsg = ReFileUtils::copy(source, target, &sourceInfo, m_buffer);
if (! errorMsg.isEmpty()){
qint64 processedBytes, hotBytes;
int lastIndex = -1;
while (! m_shouldStop){
- m_mutex.lock();
+ MUTEX_LOCK(m_mutex);
if (m_files.size() == 0)
info.clear();
else{
info = m_files.first();
m_files.removeFirst();
}
- hotBytes = m_hotBytes;
- processedBytes = m_processedBytes;
- hotFiles = m_hotFiles;
- processedFiles = m_processedFiles;
- m_mutex.unlock();
+ hotBytes = m_statistic.m_hot.bytes();
+ processedBytes = m_statistic.m_processed.bytes();
+ hotFiles = m_statistic.m_hot.files();
+ processedFiles = m_statistic.m_processed.files();;
+ MUTEX_UNLOCK(m_mutex);
if (info.isEmpty()){
if (m_searchReady)
break;
}
FILETRACE_IT(s_traceBackup, (s_traceBackup.m_fp,
"=== backup ready\n"));
- m_mainWindow->externalTaskFinished(QObject::tr("backup complete after %1. Errors: %2")
- .arg(ReQStringUtils::readableDuration(
- QDateTime::currentMSecsSinceEpoch() - start.toMSecsSinceEpoch()))
- .arg(m_mainWindow->errors()));
+ m_mainWindow->taskFinished(tr("Backup"),
+ QDateTime::currentMSecsSinceEpoch() - start.toMSecsSinceEpoch());
+
}
/**
*/
ChecksumTask::ChecksumTask(const QString& name,
const QStringList& sourceDirs, const QString& targetDir,
- MainWindow* mainWindow) :
- BackupEngine(name, sourceDirs, targetDir, mainWindow),
+ ReFileTreeStatistic& statistic, MainWindow* mainWindow) :
+ BackupEngine(name, sourceDirs, targetDir, statistic, mainWindow),
m_lastRelPath(),
m_buffer()
{
filename = m_targetDirs.at(index) + relpath + node;
qint64 size = 0;
QByteArray rc = ReFileUtils::buildChecksum(filename, m_buffer, &size).toHex();
- m_mutex.lock();
- m_processedFiles++;
- m_processedBytes += size;
- m_mutex.unlock();
+ MUTEX_LOCK(m_mutex);
+ m_statistic.m_processed.addFile(size);
+ MUTEX_UNLOCK(m_mutex);
if (rc.isEmpty()){
error(QObject::tr("cannot build checksum: %1").arg(filename) );
} if (m_verboseLevel >= VerboseStandard){
*/
ChecksumOfSourceTask::ChecksumOfSourceTask(const QString& name,
const QStringList& sourceDirs, const QString& targetDir,
- MainWindow* mainWindow) :
- ChecksumTask(name, sourceDirs, targetDir, mainWindow)
+ ReFileTreeStatistic& statistic, MainWindow* mainWindow) :
+ ChecksumTask(name, sourceDirs, targetDir, statistic, mainWindow)
{
}
QString info;
int count = 0;
while (! m_shouldStop){
- m_mutex.lock();
+ MUTEX_LOCK(m_mutex);
if (m_files.size() == 0)
info.clear();
else{
info = m_files.first();
m_files.removeFirst();
}
- m_mutex.unlock();
+ MUTEX_UNLOCK(m_mutex);
if (info.isEmpty()){
if (m_searchReady)
break;
if (! checksum.isEmpty()){
QString info = QChar(1 + index) + relPath + m_separator
+ node + m_separatorString + checksum;
- m_mutex.lock();
+ MUTEX_LOCK(m_mutex);
m_checksumInfo.append(info);
- m_mutex.unlock();
+ MUTEX_UNLOCK(m_mutex);
}
}
}
*/
ChecksumOfTargetTask::ChecksumOfTargetTask(const QString& name,
const QStringList& sourceDirs, const QString& targetDir,
- MainWindow* mainWindow) :
- ChecksumTask(name, sourceDirs, targetDir, mainWindow)
+ ReFileTreeStatistic& statistic, MainWindow* mainWindow) :
+ ChecksumTask(name, sourceDirs, targetDir, statistic, mainWindow)
{
}
QString info;
int count = 0;
while (! m_shouldStop){
- m_mutex.lock();
+ MUTEX_LOCK(m_mutex);
if (m_checksumInfo.size() == 0)
info.clear();
else{
info = m_checksumInfo.first();
m_checksumInfo.removeFirst();
}
- m_mutex.unlock();
+ MUTEX_UNLOCK(m_mutex);
if (info.isEmpty()){
if (m_sourceProcessingReady)
break;
if (m_verboseLevel > VerboseQuiet){
qint64 processedBytes, hotBytes;
int hotFiles, processedFiles;
- m_mutex.lock();
- hotFiles = m_hotFiles;
- hotBytes = m_hotBytes * 2;
- processedBytes = m_processedBytes;
- processedFiles = m_processedFiles;
- m_mutex.unlock();
+ MUTEX_LOCK(m_mutex);
+ hotFiles = m_statistic.m_hot.files();
+ // We must read pairs of source/target files which have mostly
+ // the same size:
+ hotBytes = m_statistic.m_hot.bytes() * 2;
+ processedBytes = m_statistic.m_processed.bytes();
+ processedFiles = m_statistic.m_processed.files();
+ MUTEX_UNLOCK(m_mutex);
now = QDateTime::currentMSecsSinceEpoch();
qint64 duration = (now - start.toMSecsSinceEpoch());
double factor = processedBytes / max(1.0, (double) hotBytes);
*/
CleanTask::CleanTask(const QString& name, const QStringList& sourceDirs,
- const QString& targetDir, MainWindow* mainWindow) :
- BackupEngine(name, sourceDirs, targetDir, mainWindow)
+ const QString& targetDir, ReFileTreeStatistic& statistic,
+ MainWindow* mainWindow) :
+ BackupEngine(name, sourceDirs, targetDir, statistic, mainWindow)
{
initializeShadowDir();
}
QDateTime start = QDateTime::currentDateTime();
int processedFiles = 0, hotFiles = 0;
while (! m_shouldStop){
- m_mutex.lock();
+ MUTEX_LOCK(m_mutex);
if (m_files.size() == 0)
info.clear();
else{
info = m_files.first();
m_files.removeFirst();
}
- hotFiles = m_hotFiles;
- if (! info.isEmpty())
- processedFiles = ++m_processedFiles;
- m_mutex.unlock();
+ hotFiles = m_statistic.m_hot.files();
+ if (! info.isEmpty()){
+ //@ToDo: 0???????????
+ m_statistic.m_processed.addFile(0);
+ processedFiles = m_statistic.m_processed.files();
+ }
+ MUTEX_UNLOCK(m_mutex);
if (info.isEmpty()){
if (m_searchReady)
break;
SearchTask::SearchTask(bool compareWithTarget, const QString& name,
const QString& filePatterns, const QString& dirPatterns,
const QStringList& sourceDirs, const QString& targetDir,
- MainWindow* mainWindow) :
- BackupEngine(name, sourceDirs, targetDir, mainWindow),
+ ReFileTreeStatistic& statistic, MainWindow* mainWindow) :
+ BackupEngine(name, sourceDirs, targetDir, statistic, mainWindow),
m_fileMatcher(filePatterns),
m_dirMatcher(dirPatterns),
m_compareWithTarget(compareWithTarget)
m_mainWindow->externalLog(QObject::tr(
"Search finished: to process: %1 with %2 matching: %3 total: %4 "
"subdirs: %5 runtime: %6")
- .arg(m_hotFiles)
- .arg(ReQStringUtils::readableSize(m_hotBytes))
- .arg(m_matchedFiles).arg(m_totalFiles)
- .arg(m_totalDirs)
+ .arg( m_statistic.m_hot.files())
+ .arg(ReQStringUtils::readableSize(m_statistic.m_hot.bytes()))
+ .arg(m_statistic.m_matched.files()).arg(m_statistic.m_total.files())
+ .arg(m_statistic.m_total.directories())
.arg(ReQStringUtils::readableDuration(
QDateTime::currentMSecsSinceEpoch() - start)));
}
int lengthBase = m_sourceDirs.at(index).length();
assert(index < MAX_INDEX);
QString prefix;
- m_mutex.lock();
- m_totalDirs++;
- m_mutex.unlock();
+ MUTEX_LOCK(m_mutex);
+ m_statistic.m_total.addDir();
+ MUTEX_UNLOCK(m_mutex);
if (source.length() > lengthBase){
prefix = QChar(1 + index)
+ ReFileUtils::nativePath(source.mid(lengthBase)) + OS_SEPARATOR_STR
if (! fileInfo.isSymLink() && fileInfo.isDir()){
// nothing to do
} else if (! m_fileMatcher.matches(node)){
- m_mutex.lock();
- m_totalFiles++;
- m_mutex.unlock();
+ MUTEX_LOCK(m_mutex);
+ m_statistic.m_total.addFile(fileInfo.size());
+ MUTEX_UNLOCK(m_mutex);
} else {
qint64 diff = 0;
bool doTransfer = false;
}
FILETRACE_IT(s_traceSearch, (s_traceSearch.m_fp, ">%s\n",
node.toLocal8Bit().constData()));
- m_mutex.lock();
+ qint64 size = it.fileInfo().size();
+ MUTEX_LOCK(m_mutex);
if (doTransfer){
m_files.append(info);
- m_hotFiles++;
- m_hotBytes += it.fileInfo().size();
+ m_statistic.m_hot.addFile(size);
}
- m_totalFiles++;
- m_matchedFiles++;
- m_mutex.unlock();
+ m_statistic.m_total.addFile(size);
+ m_statistic.m_matched.addFile(size);
+ MUTEX_UNLOCK(m_mutex);
}
}
if (! m_shouldStop){
*/
SearchTargetTask::SearchTargetTask(const QString& name, const QStringList& sourceDirs,
- const QString& targetDir, qint64 maxAgeSec, MainWindow* mainWindow) :
- BackupEngine(name, sourceDirs, targetDir, mainWindow),
+ const QString& targetDir, qint64 maxAgeSec,
+ ReFileTreeStatistic& statistic, MainWindow* mainWindow) :
+ BackupEngine(name, sourceDirs, targetDir, statistic, mainWindow),
m_maxAge(QDateTime::currentDateTime().addSecs(- maxAgeSec))
{
initializeShadowDir();
QDirIterator it(directory);
QString info, node;
IF_TRACE(QByteArray directory2(directory.toLocal8Bit()));
- m_mutex.lock();
- m_totalDirs++;
- m_mutex.unlock();
+ MUTEX_LOCK(m_mutex);
+ m_statistic.m_total.addDir();
+ MUTEX_UNLOCK(m_mutex);
FILETRACE_IT(s_traceSearch, (s_traceSearch.m_fp, "=removeOlder: %s\n",
directory2.constData()));
bool isEmpty = true;
+ qint64 size = 0;
while (it.hasNext()){
if (m_shouldStop){
break;
isEmpty = false;
info = QChar(MAX_INDEX) + ReFileUtils::nativePath(it.filePath()) + m_separatorString
+ QChar(CmdRemove);
- m_mutex.lock();
+ MUTEX_LOCK(m_mutex);
m_files.append(info);
- m_hotFiles++;
- m_hotBytes += it.fileInfo().size();
- m_totalFiles++;
- m_mutex.unlock();
+ size = it.fileInfo().size();
+ m_statistic.m_hot.addFile(size);
+ MUTEX_UNLOCK(m_mutex);
FILETRACE_IT(s_traceSearch, (s_traceSearch.m_fp, "-%s/%s\n",
directory2.constData(),
fileInfo.baseName().toLocal8Bit().constData()));
m_mainWindow->addToFileList("x " + directory);
info = QChar(MAX_INDEX) + directory + m_separatorString
+ QChar(CmdRemoveDir);
- m_mutex.lock();
+ MUTEX_LOCK(m_mutex);
m_files.append(info);
- m_matchedFiles++;
- m_hotFiles++;
- m_mutex.unlock();
+ m_statistic.m_matched.addFile(size);
+ m_statistic.m_total.addFile(size);
+ MUTEX_UNLOCK(m_mutex);
FILETRACE_IT(s_traceSearch, (s_traceSearch.m_fp, "-%s\n",
directory2.constData()));
}
int lengthBase = m_targetDirs.at(index).length();
assert(index < MAX_INDEX);
QString prefix;
- m_mutex.lock();
- m_totalDirs++;
- m_mutex.unlock();
+ MUTEX_LOCK(m_mutex);
+ m_statistic.m_total.addDir();
+ MUTEX_UNLOCK(m_mutex);
if (target.length() > lengthBase){
relPath = ReFileUtils::nativePath(target.mid(lengthBase)) + OS_SEPARATOR_STR;
prefix = QChar(1 + index) + relPath + m_separator;
info = prefix + QChar(command) + it.fileName();
}
}
- m_mutex.lock();
+ qint64 size = it.fileInfo().size();
+ MUTEX_LOCK(m_mutex);
if (command != CmdUndef){
m_files.append(info);
- m_hotFiles++;
- m_hotBytes += it.fileInfo().size();
+ m_statistic.m_hot.addFile(size);
}
- m_totalFiles++;
- m_mutex.unlock();
+ m_statistic.m_total.addFile(size);
+ MUTEX_UNLOCK(m_mutex);
}
}
if (! m_shouldStop){
m_mainWindow->externalLog(QObject::tr(
"Search in target finished: to process: %1 with %2 dirs to delete: %3 total: %4 "
"subdirs: %5 runtime: %6")
- .arg(m_hotFiles)
- .arg(ReQStringUtils::readableSize(m_hotBytes))
- .arg(m_matchedFiles).arg(m_totalFiles)
- .arg(m_totalDirs)
+ .arg(m_statistic.m_hot.files())
+ .arg(ReQStringUtils::readableSize(m_statistic.m_hot.files()))
+ .arg(m_statistic.m_matched.files()).arg(m_statistic.m_total.files())
+ .arg(m_statistic.m_total.directories())
.arg(ReQStringUtils::readableDuration(
QDateTime::currentMSecsSinceEpoch() - start)));
}
public:
BackupEngine(const QString& name,
const QStringList& sourceDirs, const QString& targetDir,
- MainWindow* mainWindow);
+ ReFileTreeStatistic& statistic, MainWindow* mainWindow);
public:
bool error(const QString& message);
bool log(const QString& message);
// list of shadow dirs.
QStringList m_shadowDirs;
MainWindow* m_mainWindow;
+ ReFileTreeStatistic& m_statistic;
QString m_name;
public:
static ReVerbose_t m_verboseLevel;
static bool m_shouldStop;
/// Entry: <index_of_source_dir><relative_path>TAB<node>
static QStringList m_files;
- static qint64 m_hotBytes;
- static int m_processedFiles;
- static qint64 m_processedBytes;
- static int m_hotFiles;
- static int m_matchedFiles;
- static int m_totalFiles;
- static int m_totalDirs;
static bool m_searchReady;
static QMutex m_mutex;
static QChar m_separator;
class BackupTask : public BackupEngine
{
public:
- BackupTask(const QString& name, const QStringList& sourceDirs, const QString& targetDir,
- MainWindow* mainWindow);
+ BackupTask(const QString& name, const QStringList& sourceDirs,
+ const QString& targetDir,
+ ReFileTreeStatistic& statistic, MainWindow* mainWindow);
public:
virtual void run();
protected:
class ChecksumTask : public BackupEngine
{
public:
- ChecksumTask(const QString& name, const QStringList& sourceDirs, const QString& targetDir,
- MainWindow* mainWindow);
+ ChecksumTask(const QString& name, const QStringList& sourceDirs,
+ const QString& targetDir,
+ ReFileTreeStatistic& statistic, MainWindow* mainWindow);
public:
virtual void run() = 0;
protected:
class ChecksumOfSourceTask : public ChecksumTask
{
public:
- ChecksumOfSourceTask(const QString& name, const QStringList& sourceDirs, const QString& targetDir,
+ ChecksumOfSourceTask(const QString& name, const QStringList& sourceDirs,
+ const QString& targetDir, ReFileTreeStatistic& statistic,
MainWindow* mainWindow);
public:
virtual void run();
class ChecksumOfTargetTask : public ChecksumTask
{
public:
- ChecksumOfTargetTask(const QString& name, const QStringList& sourceDirs, const QString& targetDir,
+ ChecksumOfTargetTask(const QString& name, const QStringList& sourceDirs,
+ const QString& targetDir, ReFileTreeStatistic& statistic,
MainWindow* mainWindow);
public:
virtual void run();
{
public:
CleanTask(const QString& name, const QStringList& sourceDirs, const QString& targetDir,
- MainWindow* mainWindow);
+ ReFileTreeStatistic& statistic, MainWindow* mainWindow);
public:
virtual void run();
};
SearchTask(bool compareWithTarget, const QString& name,
const QString& filePatterns, const QString& dirPatterns,
const QStringList& sourceDirs, const QString& targetDir,
- MainWindow* mainWindow);
+ ReFileTreeStatistic& statistic, MainWindow* mainWindow);
public:
virtual void run();
private:
public:
SearchTargetTask(const QString& name,
const QStringList& sourceDirs, const QString& targetDir,
- qint64 maxAgeSec, MainWindow* mainWindow);
+ qint64 maxAgeSec, ReFileTreeStatistic& statistic,
+ MainWindow* mainWindow);
public:
virtual void run();
private:
*/
#include "backupgui.hpp"
-#define WITH_TRACE
+//#define WITH_TRACE
#include "base/retrace.hpp"
-DECLARE_TRACER(s_traceConfig, "/tmp/bup_conf.log");
+DECLARE_TRACER(s_traceConfig, "/tmp/bup_conf.log")
/**
* Constructor.
#include "backupgui.hpp"
#include "aboutdialog.hpp"
#include <QFileDialog>
-#define WITH_TRACE
+//#define WITH_TRACE
#include "base/retrace.hpp"
-DECLARE_TRACER(s_traceMain, "/tmp/bup_main.log");
+DECLARE_TRACER(s_traceMain, "/tmp/bup_main.log")
-const QString VERSION("2016.10.01");
+const QString VERSION("2016.10.05");
/**
* Constructor.
m_lastDirectory(""),
m_lastTarget(""),
m_textChangeLocked(false),
- m_temporaryMounted("")
+ m_temporaryMounted(""),
+ m_statisticSearch(),
+ m_statisticTask()
{
initializeGui();
}
initializeGuiLanguage(ui->actionEnglish, ui->actionGerman);
startStop(false);
ui->actionAutosave->setChecked(true);
- connect(ui->actionStart, SIGNAL(triggered()), this,
+ connect(ui->actionStart, SIGNAL(triggered()), this,
SLOT(onStart()));
connect(ui->actionChecksums, SIGNAL(triggered()), this,
SLOT(onChecksums()));
ReSuccess_t rc = true;
BackupEngine::m_shouldStop = false;
BackupEngine::m_searchReady = false;
- BackupEngine::m_hotBytes = 0;
- BackupEngine::m_hotFiles = 0;
- BackupEngine::m_matchedFiles = 0;
- BackupEngine::m_totalDirs = 0;
- BackupEngine::m_totalFiles = 0;
- BackupEngine::m_processedFiles = 0;
- BackupEngine::m_processedBytes = 0;
BackupEngine::m_files.clear();
ChecksumTask::m_sourceProcessingReady = false;
if ( (m_maxListSize = comboInt(ui->comboBoxMaxListLength, -999)) == -999){
delete m_searchTask;
m_searchTask = new SearchTask(false, item.m_name,
item.m_filePatterns, item.m_dirPatterns,
- item.m_sources, target, this);
+ item.m_sources, target,
+ m_statisticSearch, this);
m_searchTask->start();
delete m_checksumOfSourceTask;
m_checksumOfSourceTask = new ChecksumOfSourceTask(item.m_name,
- item.m_sources, target, this);
+ item.m_sources, target, m_statisticTask, this);
m_checksumOfSourceTask->start();
delete m_checksumOfTargetTask;
m_checksumOfTargetTask = new ChecksumOfTargetTask(item.m_name,
- item.m_sources, target, this);
+ item.m_sources, target, m_statisticTask2, this);
m_checksumOfTargetTask->start();
}
}
initializeStart();
delete m_searchTargetTask;
m_searchTargetTask = new SearchTargetTask(item.m_name,
- item.m_sources, target, 14*24*3600, this);
+ item.m_sources, target, 14*24*3600,
+ m_statisticSearch, this);
m_searchTargetTask->start();
delete m_cleanTask;
m_cleanTask = new CleanTask(item.m_name, item.m_sources, target,
- this);
+ m_statisticTask, this);
m_cleanTask->start();
}
}
delete m_searchTask;
m_searchTask = new SearchTask(true, item.m_name,
item.m_filePatterns, item.m_dirPatterns,
- item.m_sources, target, this);
+ item.m_sources, target,
+ m_statisticSearch, this);
m_searchTask->start();
delete m_backupTask;
m_backupTask = new BackupTask(item.m_name, item.m_sources, target,
- this);
+ m_statisticTask, this);
m_backupTask->start();
}
}
storage.close();
}
+/**
+ * Logs a message about the end of a task.
+ *
+ * Note: This method is called from other threads.
+ *
+ * @param taskName the name of the task (translated)
+ * @param duration the duration in milliseconds
+ */
+void MainWindow::taskFinished(const QString& taskName, qint64 duration)
+{
+ externalTaskFinished(QObject::tr("%1 complete after %1. Errors: %2 File(s): %3 of %4")
+ .arg(taskName)
+ .arg(ReQStringUtils::readableDuration(duration))
+ .arg(errors()));
+
+}
+
/**
* Writes a message.
*
void setLastFile(const QString& lastFile);
void setLastFile(const QString& lastDir, const QString& lastFile);
void saveState();
+ void taskFinished(const QString& taskName, qint64 duration);
#ifdef __linux__
void unmount(const QString& device);
#endif
QString m_lastTarget;
bool m_textChangeLocked;
QString m_temporaryMounted;
+ ReFileTreeStatistic m_statisticSearch;
+ ReFileTreeStatistic m_statisticTask;
+ ReFileTreeStatistic m_statisticTask2;
};
#endif // MAINWINDOW_HPP
*/
CommandProcessor::CommandProcessor(MainWindow* mainWindow) :
m_mainWindow(mainWindow),
- m_random()
+ m_random(),
+ m_variables(),
+ m_regExprVariables("\\$(\\w+)|\\$\\{(\\w+)\\}")
{
m_random.modifySeed(ReRandomizer::nearTrueRandom());
-
}
/**
m_mainWindow->say(LOG_INFO, message);
}
+/**
+ * Sets a variable to a given value.
+ *
+ * @param name name of the variable
+ * @param value value of the variable
+ */
+void CommandProcessor::setVariable(const QString& name, const QString& value)
+{
+ m_variables[name] = value;
+}
+
/**
* @brief CommandProcessor::tail
* @param args
}
}
+/**
+ * Replaces the variables by the value of their values.
+ *
+ * @param text the text to process
+ * @return all variables are replaced
+ */
+QString CommandProcessor::expandVariables(const QString& text)
+{
+ QString rc = text;
+ bool found = true;
+ int differenceOfLength = 0;
+ while (found){
+ found = false;
+ QRegularExpressionMatchIterator i = m_regExprVariables.globalMatch(rc);
+ QString variable;
+ while(i.hasNext()){
+ QRegularExpressionMatch match = i.next();
+ variable = match.captured(1);
+ if (variable.isEmpty())
+ variable = match.captured(2);
+
+ if (m_variables.contains(variable)){
+ found = true;
+ QString value = m_variables.value(variable);
+ int varLength = match.capturedLength(0);
+ int ixStart = match.capturedStart(0);
+ rc = rc.mid(0, ixStart + differenceOfLength) + value
+ + rc.mid(ixStart + varLength);
+ differenceOfLength += value.length() - varLength;
+ }
+ }
+ }
+ return rc;
+}
+
/**
* Displays an error message.
*
void lotto(const QStringList& args);
void nOfM(const QStringList& args);
void out(const QString& message);
+ void setVariable(const QString& name, const QString& value);
void tail(const QStringList& args);
void time(const QStringList& args);
void statement(int lineNo, const QString& text);
+protected:
+ QString expandVariables(const QString& text);
protected:
MainWindow* m_mainWindow;
ReKISSRandomizer m_random;
+ QMap<QString, QString> m_variables;
+ QRegularExpression m_regExprVariables;
};
#endif // COMMANDPROCESSOR_HPP
--- /dev/null
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+*/
+#include "base/rebase.hpp"
+#include "CommandProcessor.hpp"
+
+/**
+ * @brief Unit test for <code>CommandProcessor</code>
+ */
+class TestCommandProcessor: public ReTest, public CommandProcessor {
+public:
+ TestCommandProcessor() :
+ ReTest("CommandProcessor"),
+ CommandProcessor(NULL){
+ doIt();
+ }
+
+public:
+ void shouldExpandVariables() {
+ setVariable("x", "y");
+ setVariable("y", "1234");
+ checkEqu("abcy...", expandVariables("abc$x..."));
+ checkEqu("abc123...", expandVariables("abc$$x..."));
+ checkEqu("y", expandVariables("${x}"));
+ }
+
+ virtual void runTests() {
+ shouldExpandVariables();
+ }
+};
+
+void testCommandProcessor() {
+ TestCommandProcessor test;
+}
+
#include <QApplication>
char** g_argv;
int main(int argc, char *argv[]){
- g_argv = argv;
- QString homeDir = argc > 1 ? argv[1] : "";
- QApplication a(argc, argv);
- MainWindow w(a, homeDir);
- w.show();
- return a.exec();
+ if (argc >= 2 && strcmp(argv[1], "--test") == 0){
+ extern void testCommandProcessor();
+ testCommandProcessor();
+ return 0;
+ } else {
+ g_argv = argv;
+ QString homeDir = argc > 1 ? argv[1] : "";
+ QApplication a(argc, argv);
+ MainWindow w(a, homeDir);
+ w.show();
+ return a.exec();
+ }
}
../../base/ReRandomizer.cpp \
../../base/ReStringUtils.cpp \
../../base/ReProgramArgs.cpp \
+ ../../base/ReTest.cpp \
../../gui/ReStateStorage.cpp \
../../gui/ReGuiApplication.cpp \
../../gui/ReGuiValidator.cpp \
../../gui/ReGuiUtils.cpp \
mainwindow.cpp \
CommandProcessor.cpp \
- ../../base/ReProcess.cpp
+ ../../base/ReProcess.cpp \
+ cuCommandProcessor.cpp
HEADERS += mainwindow.hpp \
CommandProcessor.hpp \
--- /dev/null
+#include "SearchEngine.hpp"
+#include <QStringList>
+#include <QTextStream>
+#include <QFile>
+
+/**
+ * Constructor.
+ *
+ * @param fullName filename with path
+ */
+FileBuffer::FileBuffer(const QString &fullName)
+{
+ read(fullName);
+}
+
+/**
+ * Reads a file into the internal line list.
+ *
+ * @param fullName filename with path
+ */
+void FileBuffer::read(const QString &fullName)
+{
+ QFile textFile(fullName);
+ if (textFile.exists()){
+ QString line;
+ OpenMode mode;
+ if (textFile.open(QIODevice::ReadOnly)){
+ QTextStream textStream(&textFile);
+ while (true)
+ {
+ line = textStream.readLine();
+ if (line.isNull())
+ break;
+ else
+ m_lines.append(line);
+ }
+ }
+ textFile.close();
+ }
+}
+
+/**
+ * Constructor.
+ */
+SearchEngine::SearchEngine()
+{
+
+}
--- /dev/null
+#ifndef SEARCHENGINE_H
+#define SEARCHENGINE_H
+
+class FileBuffer {
+public:
+ FileBuffer(const QString& fullName);
+ ~FileBuffer();
+public:
+ void read(const QString& fullName);
+
+private:
+ QString m_node;
+ QString m_path;
+ QList<QString> m_lines;
+};
+
+class SearchEngine
+{
+public:
+ SearchEngine();
+public:
+private:
+
+};
+
+#endif // SEARCHENGINE_H
<enum>QTabWidget::North</enum>
</property>
<property name="currentIndex">
- <number>0</number>
+ <number>3</number>
</property>
<property name="tabsClosable">
<bool>false</bool>
m_perspectives.addPerspective(mainPerspective);
m_perspectives.change(mainPerspective->name());
m_perspectives.addPerspective(new ProjectPerspective(proj, this));
- m_delayedStorage = new ReDelayedStorage(m_workspace->historyFile())
+ m_delayedStorage = new ReDelayedStorage(m_workspace->fileHistory(),
+ m_logger);
}
/**
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
- <widget class="QWidget" name="">
+ <widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
- <bool>true</bool>
+ <bool>false</bool>
</attribute>
<column>
<property name="text">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible">
- <bool>true</bool>
+ <bool>false</bool>
</attribute>
<column>
<property name="text">
<x>0</x>
<y>0</y>
<width>803</width>
- <height>35</height>
+ <height>31</height>
</rect>
</property>
+ <widget class="QMenu" name="menuFile">
+ <property name="title">
+ <string>Fi&le</string>
+ </property>
+ <addaction name="actionOpen_2"/>
+ <addaction name="separator"/>
+ <addaction name="actionExit"/>
+ </widget>
+ <widget class="QMenu" name="menuEdit">
+ <property name="title">
+ <string>Edi&t</string>
+ </property>
+ </widget>
+ <widget class="QMenu" name="menuAction">
+ <property name="title">
+ <string>A&ction</string>
+ </property>
+ <addaction name="actionFile_search"/>
+ </widget>
+ <widget class="QMenu" name="menuHelp">
+ <property name="title">
+ <string>Help</string>
+ </property>
+ <addaction name="actionAbout"/>
+ </widget>
+ <addaction name="menuFile"/>
+ <addaction name="menuEdit"/>
+ <addaction name="menuAction"/>
+ <addaction name="menuHelp"/>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<string>Ctrl+S</string>
</property>
</action>
+ <action name="actionOpen_2">
+ <property name="text">
+ <string>Open</string>
+ </property>
+ </action>
+ <action name="actionExit">
+ <property name="text">
+ <string>Exit</string>
+ </property>
+ </action>
+ <action name="actionFile_search">
+ <property name="text">
+ <string>File search</string>
+ </property>
+ </action>
+ <action name="actionAbout">
+ <property name="text">
+ <string>About</string>
+ </property>
+ </action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
../../gui/ReStateStorage.cpp \
../../gui/ReSettings.cpp \
../../base/ReFile.cpp \
+ ../../base/ReProcess.cpp \
+ ../../base/ReStringUtils.cpp \
+ ../../base/ReMatcher.cpp \
../../gui/ReFileTree.cpp \
mainwindow.cpp \
../../base/ReLogger.cpp \
views/ProjectPerspective.cpp \
views/StartPerspective.cpp \
views/StartView.cpp \
- main.cpp
+ main.cpp \
+ SearchEngine.cpp
HEADERS += mainwindow.hpp \
project.hpp \
reide.hpp \
filesearch.hpp \
- views/StartView.hpp
+ views/StartView.hpp \
+ SearchEngine.hpp
FORMS += mainwindow.ui \
projectselection.ui \
* @param logger the logger
*/
Workspace::Workspace(const QString& path, ReLogger* logger) :
- ReSettings(path, ".reditor.ws", logger) {
+ ReSettings(path, ".reditor.ws", logger)
+{
insertProperty(
- new ReProperty("editor.tabwidth", QObject::tr("Tabulator width"),
- QObject::tr("Maximal length of the gap displaying a tabulator"),
- "4", PT_INT, "[1,16]"));
+ new ReProperty("editor.tabwidth", QObject::tr("Tabulator width"),
+ QObject::tr("Maximal length of the gap displaying a tabulator"),
+ "4", PT_INT, "[1,16]"));
insertProperty(
- new ReProperty("history.max_projects",
- QObject::tr("Maximal project entries"),
- QObject::tr(
- "Maximal number of projects in the 'last opened projects'"),
- "20", PT_INT, "[1,100]"));
+ new ReProperty("history.max_projects",
+ QObject::tr("Maximal project entries"),
+ QObject::tr(
+ "Maximal number of projects in the 'last opened projects'"),
+ "20", PT_INT, "[1,100]"));
insertProperty(
- new ReProperty("history.max_files", QObject::tr("Maximal file entries"),
- QObject::tr("Maximal number of files in the 'last opened files'"),
- "20", PT_INT, "[1,100]"));
+ new ReProperty("history.max_files", QObject::tr("Maximal file entries"),
+ QObject::tr("Maximal number of files in the 'last opened files'"),
+ "20", PT_INT, "[1,100]"));
}
../../base/ReLogger.cpp \
../../base/ReRandomizer.cpp \
../../base/ReStringUtils.cpp \
+ ../../base/ReQStringUtils.cpp \
../../base/ReException.cpp \
Prime.cpp
--- /dev/null
+/*
+ * aboutdialog.cpp
+ *
+ * (Un)License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * More info: http://unlicense.org
+ * The latest sources: https://github.com/republib
+ */
+
+#include "aboutdialog.hpp"
+#include "ui_aboutdialog.h"
+
+AboutDialog::AboutDialog(const QString& version, QWidget *parent) :
+ QDialog(parent), ui(new Ui::AboutDialog){
+ ui->setupUi(this);
+ ui->labelVersion->setText(version);
+}
+
+AboutDialog::~AboutDialog(){
+ delete ui;
+}
--- /dev/null
+/*
+ * aboutdialog.hpp
+ *
+ * (Un)License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * More info: http://unlicense.org
+ * The latest sources: https://github.com/republib
+ */
+
+#ifndef ABOUTDIALOG_HPP
+#define ABOUTDIALOG_HPP
+
+#include <QDialog>
+
+namespace Ui {
+class AboutDialog;
+}
+
+class AboutDialog: public QDialog {
+ Q_OBJECT
+
+public:
+ explicit AboutDialog(const QString& version, QWidget *parent = 0);
+ ~AboutDialog();
+
+private:
+ Ui::AboutDialog *ui;
+};
+
+#endif // ABOUTDIALOG_HPP
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>AboutDialog</class>
+ <widget class="QDialog" name="AboutDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>423</width>
+ <height>276</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Dialog</string>
+ </property>
+ <widget class="QTextEdit" name="textEdit">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>20</y>
+ <width>381</width>
+ <height>181</height>
+ </rect>
+ </property>
+ <property name="readOnly">
+ <bool>true</bool>
+ </property>
+ <property name="html">
+ <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
+<html><head><meta name="qrichtext" content="1" /><style type="text/css">
+p, li { white-space: pre-wrap; }
+</style></head><body style=" font-family:'Noto Sans'; font-size:10pt; font-weight:400; font-style:normal;">
+<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif'; font-size:9pt; font-weight:600;">ReSearch</span><span style=" font-family:'Sans Serif'; font-size:9pt;"> for text searching/filtering in files</span></p>
+<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif'; font-size:9pt;">This is a program of the project</span></p>
+<p align="center" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif'; font-size:9pt; font-weight:600;">Re</span><span style=" font-family:'Sans Serif'; font-size:9pt;">al </span><span style=" font-family:'Sans Serif'; font-size:9pt; font-weight:600;">Pub</span><span style=" font-family:'Sans Serif'; font-size:9pt;">lic </span><span style=" font-family:'Sans Serif'; font-size:9pt; font-weight:600;">Lib</span><span style=" font-family:'Sans Serif'; font-size:9pt;">rary (RePubLib)</span></p>
+<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif'; font-size:9pt;">Sources are public domain and available under</span></p>
+<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><a href="https://github.com/republib"><span style=" font-family:'Sans Serif'; font-size:9pt; text-decoration: underline; color:#0000ff;">https://github.com/republib</span></a><span style=" font-family:'Sans Serif'; font-size:9pt;"> </span></p>
+<p style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans Serif'; font-size:9pt;">Implemented in QT (C++) 5.x</span></p></body></html></string>
+ </property>
+ <property name="acceptRichText">
+ <bool>false</bool>
+ </property>
+ <property name="textInteractionFlags">
+ <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
+ </property>
+ </widget>
+ <widget class="QWidget" name="layoutWidget">
+ <property name="geometry">
+ <rect>
+ <x>20</x>
+ <y>220</y>
+ <width>381</width>
+ <height>35</height>
+ </rect>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Version:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="labelVersion">
+ <property name="text">
+ <string>2015.05.00</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButtonOK">
+ <property name="text">
+ <string>&Close</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>pushButtonOK</sender>
+ <signal>clicked()</signal>
+ <receiver>AboutDialog</receiver>
+ <slot>close()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>357</x>
+ <y>237</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>211</x>
+ <y>137</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
--- /dev/null
+#include "research.hpp"
+#include "mainwindow.hpp"
+char** g_argv;
+int main(int argc, char* argv[]) {
+ g_argv = argv;
+ QString homeDir = argc > 1 ? argv[1] : "";
+ QApplication a(argc, argv);
+ MainWindow w(a, homeDir);
+ w.show();
+ return a.exec();
+}
--- /dev/null
+#include "research.hpp"
+#include "mainwindow.hpp"
+#include "ui_mainwindow.h"
+#include "aboutdialog.hpp"
+
+static const char* VERSION = "2016.11.16";
+
+MainWindow::MainWindow(QApplication& application, const QString& homeDir,
+ QWidget *parent) :
+ ReGuiApplication(application, "rsearch", homeDir, 2, 10100100, "de", parent),
+ ReGuiValidator(),
+ ui(new Ui::MainWindow)
+{
+ ReComboBox::setDefaultHistorySize(20);
+ initializeGui();
+}
+
+MainWindow::~MainWindow()
+{
+ delete ui;
+}
+
+/**
+ * Initializes the Graphical User Interface.
+ */
+void MainWindow::initializeGui(){
+ ui->setupUi(this);
+ initializeGuiElements();
+ // restoreState();
+ m_guiIsInitialized = false;
+ connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(onAbout()));
+ connect(ui->comboBoxBaseDirectory, SIGNAL(textEdited(const QString&, const QString&)),
+ this, SLOT(textEdited(const QString&, const QString&)));
+
+}
+
+/**
+ * Shows the "about" window.
+ */
+void MainWindow::onAbout()
+{
+ AboutDialog dialog(VERSION);
+ dialog.exec();
+}
+/**
+ * Called at the program's end.
+ */
+void MainWindow::onAboutToQuit()
+{
+ saveState();
+ ReGuiApplication::onAboutToQuit();
+}
+
+/**
+ * Set GUI elements from the queue when the GUI timer is triggered.
+ */
+void MainWindow::onGuiTimerUpdate()
+{
+}
+
+
+/**
+ * The language has been changed.
+ */
+void MainWindow::onLanguageChange()
+{
+ initializeGui();
+}
+
+/**
+ * Writes a message.
+ *
+ * @param level mode of the message, e.g. LOG_ERROR
+ * @param message the message
+ * @return <code>false</code>level is error or warning
+ */
+bool MainWindow::say(ReLoggerLevel level, const QString& message){
+ setStatusMessage(level, message);
+ return level >= LOG_INFO;
+}
+
+/**
+ * Event
+ * @param oldString
+ * @param newString
+ */
+void MainWindow::textEdited(const QString& oldString, const QString& newString)
+{
+ ReUseParameter(oldString);
+ ReUseParameter(newString);
+}
+
--- /dev/null
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#ifndef REBASE_HPP
+#include "base/rebase.hpp"
+#endif
+#ifndef REGUI_HPP
+#include "gui/regui.hpp"
+#endif
+
+namespace Ui {
+class MainWindow;
+}
+
+class MainWindow : public ReGuiApplication, public ReGuiValidator
+{
+ Q_OBJECT
+
+public:
+ explicit MainWindow(QApplication& application, const QString& homeDir,
+ QWidget *parent = 0);
+ ~MainWindow();
+public:
+ virtual bool say(ReLoggerLevel level, const QString& message);
+
+private:
+ void initializeGui();
+
+private slots:
+ void onAbout();
+ virtual void onAboutToQuit();
+ virtual void onGuiTimerUpdate();
+ virtual void onLanguageChange();
+ void textEdited(const QString& oldString, const QString& newString);
+
+private:
+ Ui::MainWindow *ui;
+};
+#endif // MAINWINDOW_H
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>869</width>
+ <height>627</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>MainWindow</string>
+ </property>
+ <widget class="QWidget" name="centralWidget">
+ <layout class="QVBoxLayout" name="verticalLayout_4">
+ <item>
+ <widget class="QTabWidget" name="tabWidget">
+ <property name="currentIndex">
+ <number>0</number>
+ </property>
+ <widget class="QWidget" name="tabFiles">
+ <attribute name="title">
+ <string>Files</string>
+ </attribute>
+ <layout class="QHBoxLayout" name="horizontalLayout_4">
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout" stretch="0,1">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_3" stretch="5,1">
+ <item>
+ <widget class="QTabWidget" name="tabWidgetFileSearch">
+ <property name="maximumSize">
+ <size>
+ <width>16777215</width>
+ <height>175</height>
+ </size>
+ </property>
+ <property name="currentIndex">
+ <number>0</number>
+ </property>
+ <widget class="QWidget" name="tabDirectorySearch">
+ <attribute name="title">
+ <string>Directory search</string>
+ </attribute>
+ <layout class="QFormLayout" name="formLayout_3">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Base directory:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="ReComboBox" name="comboBoxBaseDirectory">
+ <property name="maximumSize">
+ <size>
+ <width>16777215</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="toolTip">
+ <string>The files will be searched in this directory or its subdirectories</string>
+ </property>
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ <property name="currentText">
+ <string notr="true"/>
+ </property>
+ <property name="sizeAdjustPolicy">
+ <enum>QComboBox::AdjustToContents</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButtonSelectBase">
+ <property name="maximumSize">
+ <size>
+ <width>50</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="text">
+ <string notr="true">...</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="1" column="1">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QCheckBox" name="checkBoxRecursive">
+ <property name="text">
+ <string>Recursive</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>188</width>
+ <height>17</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Max. depth:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="lineEditMaxDepth">
+ <property name="minimumSize">
+ <size>
+ <width>50</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>50</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>99</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_5">
+ <property name="text">
+ <string>Min. depth:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="lineEditMinDepth">
+ <property name="minimumSize">
+ <size>
+ <width>50</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>50</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>0</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_12">
+ <property name="text">
+ <string>Patterns:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="ReComboBox" name="comboBoxFilePatterns">
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="tabSingleFiles">
+ <attribute name="title">
+ <string>Single files</string>
+ </attribute>
+ </widget>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="maximumSize">
+ <size>
+ <width>16777215</width>
+ <height>175</height>
+ </size>
+ </property>
+ <property name="title">
+ <string>Activity</string>
+ </property>
+ <widget class="QPushButton" name="pushButtonAdd">
+ <property name="geometry">
+ <rect>
+ <x>19</x>
+ <y>27</y>
+ <width>85</width>
+ <height>33</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>&Add</string>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="pushButtonClear">
+ <property name="geometry">
+ <rect>
+ <x>19</x>
+ <y>67</y>
+ <width>85</width>
+ <height>33</height>
+ </rect>
+ </property>
+ <property name="text">
+ <string>&Clear</string>
+ </property>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QTableWidget" name="tableWidget">
+ <attribute name="horizontalHeaderStretchLastSection">
+ <bool>true</bool>
+ </attribute>
+ <column>
+ <property name="text">
+ <string>Name</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Size</string>
+ </property>
+ <property name="textAlignment">
+ <set>AlignTrailing|AlignVCenter</set>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Date</string>
+ </property>
+ <property name="textAlignment">
+ <set>AlignLeading|AlignVCenter</set>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Directory</string>
+ </property>
+ </column>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="tabText">
+ <attribute name="title">
+ <string>Text</string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,0,1">
+ <item>
+ <widget class="QTabWidget" name="tabWidgetText">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Minimum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>16777215</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="currentIndex">
+ <number>1</number>
+ </property>
+ <widget class="QWidget" name="tabFileFilterPatterns">
+ <attribute name="title">
+ <string>Filter patterns</string>
+ </attribute>
+ <layout class="QFormLayout" name="formLayout_2">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_6">
+ <property name="text">
+ <string>Including pattern:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="ReComboBox" name="comboBoxIncludingPattern">
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_7">
+ <property name="text">
+ <string>Exluding pattern:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="ReComboBox" name="comboBoxExcludingPattern">
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="tabOptions">
+ <attribute name="title">
+ <string>Options</string>
+ </attribute>
+ <widget class="QWidget" name="">
+ <property name="geometry">
+ <rect>
+ <x>175</x>
+ <y>10</y>
+ <width>321</width>
+ <height>35</height>
+ </rect>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout_6">
+ <item>
+ <widget class="QLabel" name="label_8">
+ <property name="text">
+ <string>Lines above:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="ReComboBox" name="comboBoxLinesAbove">
+ <property name="maximumSize">
+ <size>
+ <width>50</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ <property name="currentText">
+ <string>0</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_9">
+ <property name="text">
+ <string>Lines below:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="ReComboBox" name="comboBoxLinesBelow">
+ <property name="maximumSize">
+ <size>
+ <width>50</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ <property name="currentText">
+ <string notr="true">0</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_5">
+ <item>
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_10">
+ <property name="text">
+ <string>From hit:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="ReComboBox" name="comboBoxFromHit">
+ <property name="maximumSize">
+ <size>
+ <width>100</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ <property name="currentText">
+ <string>0</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_11">
+ <property name="text">
+ <string>To hit:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="ReComboBox" name="comboBoxToHit">
+ <property name="maximumSize">
+ <size>
+ <width>100</width>
+ <height>16777215</height>
+ </size>
+ </property>
+ <property name="editable">
+ <bool>true</bool>
+ </property>
+ <property name="currentText">
+ <string>100</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QListWidget" name="listWidgetHits"/>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="tabBlock">
+ <attribute name="title">
+ <string>Block</string>
+ </attribute>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menuBar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>869</width>
+ <height>31</height>
+ </rect>
+ </property>
+ <widget class="QMenu" name="menuFile">
+ <property name="title">
+ <string>Fi&le</string>
+ </property>
+ <addaction name="actionExit"/>
+ </widget>
+ <widget class="QMenu" name="menuHilfe">
+ <property name="title">
+ <string>Hel&p</string>
+ </property>
+ <addaction name="actionAbout"/>
+ </widget>
+ <addaction name="menuFile"/>
+ <addaction name="menuHilfe"/>
+ </widget>
+ <widget class="QToolBar" name="mainToolBar">
+ <attribute name="toolBarArea">
+ <enum>TopToolBarArea</enum>
+ </attribute>
+ <attribute name="toolBarBreak">
+ <bool>false</bool>
+ </attribute>
+ </widget>
+ <widget class="QStatusBar" name="statusBar"/>
+ <action name="actionExit">
+ <property name="text">
+ <string>&Exit</string>
+ </property>
+ </action>
+ <action name="actionAbout">
+ <property name="text">
+ <string>&About</string>
+ </property>
+ </action>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <customwidgets>
+ <customwidget>
+ <class>ReComboBox</class>
+ <extends>QComboBox</extends>
+ <header>gui/ReComboBox.hpp</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
--- /dev/null
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+*/
+
+#ifndef RESEARCH_HPP
+#define RESEARCH_HPP
+#include "base/rebase.hpp"
+#include "gui/regui.hpp"
+#include <QMainWindow>
+#endif // RESEARCH_HPP
--- /dev/null
+#-------------------------------------------------
+#
+# Project created by QtCreator 2016-11-15T23:03:11
+#
+#-------------------------------------------------
+
+QT += core gui
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+TARGET = research
+TEMPLATE = app
+INCLUDEPATH = ../..
+
+
+SOURCES += main.cpp \
+ ../../base/ReException.cpp \
+ ../../base/ReConfig.cpp \
+ ../../base/ReProcess.cpp \
+ ../../base/ReQStringUtils.cpp \
+ ../../base/ReFileUtils.cpp \
+ ../../base/ReMatcher.cpp \
+ ../../base/ReLogger.cpp \
+ ../../base/ReRandomizer.cpp \
+ ../../base/ReStringUtils.cpp \
+ ../../gui/ReComboBox.cpp \
+ ../../gui/ReStateStorage.cpp \
+ ../../gui/ReGuiApplication.cpp \
+ ../../gui/ReGuiValidator.cpp \
+ ../../gui/ReGuiQueue.cpp \
+ ../../gui/ReGuiUtils.cpp \
+ mainwindow.cpp \
+ aboutdialog.cpp \
+ ../../base/ReFileSearch.cpp
+
+HEADERS += mainwindow.hpp \
+ ../../base/rebase.hpp \
+ ../../base/ReQStringUtils.hpp \
+ ../../gui/ReComboBox.hpp \
+ ../../gui/ReStateStorage.hpp \
+ ../../gui/ReGuiValidator.hpp \
+ ../../gui/regui.hpp \
+ ../../gui/ReGuiUtils.hpp \
+ aboutdialog.hpp \
+ research.hpp \
+ ../../base/ReFileSearch.hpp
+
+FORMS += mainwindow.ui \
+ aboutdialog.ui
bool includeIgnoreCase, const QString& excludePattern,
bool excludeIsRegExpr, bool excludeIgnoreCase, int& lineNo, QString* line) {
bool rc = false;
+ ReUseParameter(includeIgnoreCase);
+ ReUseParameter(includeIsRegExpr);
+ ReUseParameter(excludeIsRegExpr);
+ ReUseParameter(excludeIgnoreCase);
+ ReUseParameter(excludePattern);
if (line != NULL)
*line = "";
lineNo = 0;
--- /dev/null
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+*/
+
+#include "base/rebase.hpp"
+
+/**
+ * Constructor.
+ */
+ReFileSearch::ReFileSearch() :
+ m_minDepth(0),
+ m_maxDepth(9999),
+ m_searchMode(smFilesAndDirs),
+ m_matcher()
+{
+}
+
+/**
+ * Returns the current maximal depth.
+ *
+ * @return the current maximal depth
+ */
+int ReFileSearch::maxDepth() const
+{
+ return m_maxDepth;
+}
+
+/**
+ * Returns the current minimal depth.
+ *
+ * @return the current minimal depth
+ */
+int ReFileSearch::minDepth() const
+{
+ return m_minDepth;
+}
+
+void ReFileSearch::oneDirectory(const QString& directory, int depth)
+{
+ QDir dir(directory);
+ QStringList files = dir.entryList();
+ QString node;
+ QString full;
+ QStringList dirs;
+ for (int ix = 0; ix < files.size(); ix++){
+ node = files[ix];
+ if (node == "." || node == "..")
+ continue;
+ full = directory;
+ full += OS_SEPARATOR;
+ full += node;
+ QFileInfo info(full);
+ if (! info.isDir()){
+ if (m_searchMode == smDirs || depth < m_minDepth){
+ continue;
+ }
+ } else {
+ if (depth < m_maxDepth)
+ dirs += full;
+
+ if (m_searchMode == smFiles || depth < m_minDepth){
+ continue;
+ }
+ }
+ if (m_matcher.matches(node))
+ handleFile(full, directory, node);
+ }
+ ++depth;
+ for (int ix = 0; ix < dirs.size(); ix++){
+ oneDirectory(directory + OS_SEPARATOR_STR + dirs[ix], depth);
+ }
+}
+
+/**
+ * Returns the current search mode.
+ *
+ * @return the current search mode, e.g. <i>smFilesAndDirs</i>
+ */
+ReFileSearch::SearchMode ReFileSearch::searchMode() const
+{
+ return m_searchMode;
+}
+
+/**
+ * Sets the file search mode.
+ *
+ * @param searchMode the new mode, e.g. <i>smFilesAndDirs</i>
+ */
+void ReFileSearch::setSearchMode(const SearchMode& searchMode)
+{
+ m_searchMode = searchMode;
+}
+
+/**
+ * Sets the maximal depth.
+ *
+ * @param maxDepth the maximal depth
+ */
+void ReFileSearch::setMaxDepth(int maxDepth)
+{
+ m_maxDepth = maxDepth;
+}
+
+/**
+ * Sets the minimal depth.
+ *
+ * @param maxDepth the minimal depth
+ */
+void ReFileSearch::setMinDepth(int minDepth)
+{
+ m_minDepth = minDepth;
+}
+
+/**
+ * Sets the search patterns.
+ *
+ * @param includeExcludePatterns a list of patterns, separated by ','.
+ * Exclude patterns start with '-'
+ */
+void ReFileSearch::setPatterns(const QString& includeExcludePatterns)
+{
+ m_matcher.setPatterns(includeExcludePatterns, ',', '-');
+}
--- /dev/null
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+*/
+
+#ifndef REFILESEARCH_HPP
+#define REFILESEARCH_HPP
+
+/**
+ * An abstract class to search files in a directory tree.
+ *
+ *
+ */
+class ReFileSearch
+{
+public:
+ enum SearchMode {
+ smUndef,
+ smFiles,
+ smDirs,
+ smFilesAndDirs
+ };
+
+public:
+ ReFileSearch();
+public:
+ virtual void handleFile(const QString& full, const QString& path, const QString& node) = 0;
+ int maxDepth() const;
+ int minDepth() const;
+ void oneDirectory(const QString& directory, int depth);
+ SearchMode searchMode() const;
+ void setMaxDepth(int maxDepth);
+ void setMinDepth(int minDepth);
+ void setPatterns(const QString& includeExcludePattern);
+ void setSearchMode(const SearchMode& searchMode);
+public:
+ int m_minDepth;
+ int m_maxDepth;
+ SearchMode m_searchMode;
+ ReIncludeExcludeMatcher m_matcher;
+};
+
+#endif // REFILESEARCH_HPP
ReMountInfo* ReMountInfo::m_instance = NULL;
ReBlockDevices* ReBlockDevices::m_instance = NULL;
#endif
-/**
- * Constructor.
- */
-ReTreeStatistic::ReTreeStatistic() :
- m_files(0),
- m_directories(0),
- m_fileSizes(0L) {
-}
/**
* Builds a checksum of the given file.
}
}
}
- if (! rc)
+ if (! rc && logger != NULL)
logger->log(LOG_ERROR, LOC_MAKE_DIR_WITH_PARENT_1,
QObject::tr("can't create directory (%1): %2").arg(errno)
.arg(path));
#define REFILEUTILS_HPP
/**
- * Statistic of a directory tree.
+ * Simple counters of a directory tree.
*/
-class ReTreeStatistic {
- ReTreeStatistic();
+class ReFileTreeCounter
+{
public:
+ /**
+ * Constructor.
+ */
+ ReFileTreeCounter() :
+ m_bytes(0),
+ m_files(0),
+ m_directories(0LL)
+ {}
+ /**
+ * Copy Constructor.
+ * @param source instance to copy
+ */
+ ReFileTreeCounter(const ReFileTreeCounter& source) :
+ m_bytes(source.m_bytes),
+ m_files(source.m_files),
+ m_directories(source.m_directories)
+ {
+ }
+ /**
+ * Assignment operator.
+ * @param source
+ * @return
+ */
+ ReFileTreeCounter& operator =(const ReFileTreeCounter& source){
+ m_bytes = source.m_bytes;
+ m_files = source.m_files;
+ m_directories = source.m_directories;
+ return *this;
+ }
+public:
+ /**
+ * Sets the counters to 0.
+ */
+ inline void clear(){
+ m_files = m_directories = 0;
+ m_bytes = 0;
+ }
+ /**
+ * Add a file to the statistic.
+ *
+ * @param size the file's size
+ */
+ inline void addFile(qint64 size){
+ m_bytes += size;
+ ++m_files;
+ }
+ /**
+ * Increments the count of directories.
+ */
+ inline void addDir(){
+ ++m_directories;
+ }
+ /**
+ * Returns the sum of file sizes.
+ * @return the sum of file sizes
+ */
+ qint64 bytes() const {
+ return m_bytes;
+ }
+ /**
+ * Returns the number of files.
+ * @return the number of files
+ */
+ int files() const {
+ return m_files;
+ }
+ /**
+ * Returns the number of files.
+ * @return the number of files
+ */
+ int directories() const {
+ return m_directories;
+ }
+protected:
+ qint64 m_bytes;
int m_files;
int m_directories;
- int64_t m_fileSizes;
+};
+
+/**
+ * Statistic of a directory tree.
+ */
+class ReFileTreeStatistic
+{
+public:
+ /**
+ * Constructor.
+ */
+ ReFileTreeStatistic() :
+ m_hot(),
+ m_processed(),
+ m_matched(),
+ m_total()
+ {}
+public:
+ /**
+ * Sets all counters to 0.
+ */
+ inline void clear(){
+ m_hot.clear();
+ m_processed.clear();
+ m_matched.clear();
+ m_total.clear();
+ }
+public:
+ ReFileTreeCounter m_hot;
+ ReFileTreeCounter m_processed;
+ ReFileTreeCounter m_matched;
+ ReFileTreeCounter m_total;
};
/**
inline int abs(int x) {
return x < 0 ? -x : x;
}
+#ifndef _GLIBCXX_CSTDLIB
inline int64_t abs(int64_t x){
return x < 0 ? -x : x;
}
-
+#endif
#endif
/**
#include "base/ReFile.hpp"
#include "base/ReDiff.hpp"
#include "base/ReMatcher.hpp"
+#include "base/ReFileSearch.hpp"
#include "base/ReTest.hpp"
#include "base/ReRandomizer.hpp"
#endif // REBASE_HPP
#define TRACE2(format, a1, a2) printf(format, a1, a2)
#define TRACE_IT(args) printf args
#define IF_TRACE(statem) statem
-#define DECLARE_TRACER(varName, fileName) static ReTracer varName(fileName)
+#define DECLARE_TRACER(varName, fileName) static ReTracer varName(fileName);
// Example: FILETRACE_IT(s_tracerLoop, (s_tracerLoop.m_fp, "value: %d", 33));
#define FILETRACE_IT(varName, args) do { if (varName.m_fp != NULL) { \
fprintf args; fflush(varName.m_fp); } } while(false)
static bool s_allTest = false;
static void testBase() {
+ void testReFileSearch();
void testReProgArgs();
void testReProcess();
void testReRandomizer();
void testReWriter();
void testReFile();
void testReMatcher();
+ testReFileSearch();
testReFileUtils();
testReQStringUtil();
testReProgArgs();
--- /dev/null
+/*
+ * cuReFileSearch.cpp
+ *
+ * (Un)License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * More info: http://unlicense.org
+ * The latest sources: https://github.com/republib
+ */
+#include "base/rebase.hpp"
+#include <QMap>
+
+/** @file
+ * @brief Unit test of the basic exceptions.
+ */
+
+class TestReFileSearch: public ReTest, public ReFileSearch {
+public:
+ TestReFileSearch() :
+ ReTest("ReFileSearch") {
+ doIt();
+ }
+
+public:
+ void testBasic() {
+ m_found.clear();
+ setPatterns("test3.txt");
+ setSearchMode(smFiles);
+ oneDirectory(m_baseDir, 0);
+ checkEqu(5, m_found.size());
+ checkT(m_found.contains("file3.txt"));
+ checkT(m_found.contains("dir1/file3.txt"));
+ checkT(m_found.contains("dir1/dir2/file3.txt"));
+ checkT(m_found.contains("dir1/dir2/dir3/file3.txt"));
+ checkT(m_found.contains("dir1/dir2/dir3/dir4/file3.txt"));
+ }
+ virtual void handleFile(const QString& full, const QString& path, const QString& node){
+ checkEqu(full, path + OS_SEPARATOR_STR + node);
+ QString relPath = full.mid(m_baseDir.length() + 1);
+ relPath.replace(OS_SEPARATOR, "/");
+ m_found.insert(relPath, 0);
+ }
+private:
+ void makeFile(const QString& name){
+ ReFileUtils::writeToFile(name.toUtf8().data(), name.toUtf8().data());
+ }
+
+ void makeTree(){
+ m_baseDir = ReFileUtils::tempDir("ReFileSearch", NULL, false);
+ QString path = m_baseDir;
+ for (int depth = 0; depth < 5; depth++){
+ if (depth > 0)
+ path += OS_SEPARATOR_STR + QString("dir") + QString::number(depth);
+ ReFileUtils::makeDirWithParents(path);
+ for (int ix = 1; ix <= 5; ix++){
+ QString name = path + OS_SEPARATOR_STR + "file" + QString::number(ix) + ".txt";
+ makeFile(name);
+ }
+ }
+ }
+
+ virtual void runTests() {
+ makeTree();
+ testBasic();
+ }
+private:
+ QString m_baseDir;
+ QMap<QString, int> m_found;
+};
+void testReFileSearch() {
+ TestReFileSearch test;
+}
+
../base/ReContainer.cpp \
../base/ReException.cpp \
../base/ReFile.cpp \
+ ../base/ReFileSearch.cpp \
../base/ReFileUtils.cpp \
../base/ReQStringUtils.cpp \
../base/ReLogger.cpp \
cuReByteStorage.cpp \
cuReProgArgs.cpp \
../base/ReProcess.cpp \
- ../base/ReProgramArgs.cpp
+ ../base/ReProgramArgs.cpp \
+ ../cunit/cuReFileSearch.cpp
+
RESERVE = \
cuReEdit.cpp \
cuReCryptFileSystem.cpp \
HEADERS += \
- ../base/ReFile.hpp \
+ ../base/ReFileSearch.hpp \
../base/rebase.hpp \
../gui/ReEdit.hpp \
../math/ReMatrix.hpp \
*/
#include "base/rebase.hpp"
#include "gui/regui.hpp"
+#include "gui/ReComboBox.hpp"
+
+int ReComboBox::m_defaultHistorySize = 20;
/**
* Constructor.
ReComboBox::ReComboBox(QWidget *parent) :
QComboBox(parent),
m_oldString(),
- m_historySize(0)
+ m_historySize(m_defaultHistorySize)
+{
+}
+
+/**
+ * Destructor.
+ */
+ReComboBox::~ReComboBox()
{
}
removeItem(m_historySize);
}
- comboTextEdited(m_oldString, current);
+ emit textEdited(m_oldString, current);
}
}
QComboBox::focusOutEvent(event);
}
/**
- * @brief ReComboBox::setHistorySize
- * @param size
+ * Sets the history size of the instance.
+ *
+ * @param size the new size
*/
void ReComboBox::setHistorySize(int size)
{
m_historySize = size;
}
+
+/**
+ * Sets the default history size used at the initialization of a <i>ReComboBox</i>.
+ *
+ * @param size the new size
+ */
+void ReComboBox::setDefaultHistorySize(int size)
+{
+ m_defaultHistorySize = size;
+}
Q_OBJECT
public:
explicit ReComboBox(QWidget *parent = 0);
+ virtual ~ReComboBox();
public:
int historySize() const;
void setHistorySize(int size);
-
+public:
+ static void setDefaultHistorySize(int size);
signals:
- void comboTextEdited(const QString& oldText, const QString& newText);
+ /**
+ * Signal if the text of the combobox has changed after loosing the focus.
+ *
+ * @param oldText the old text (while got the focus)
+ * @param newText the current text
+ */
+ void textEdited(const QString&, const QString&);
private:
- virtual void focusInEvent(QFocusEvent* event);
- virtual void focusOutEvent(QFocusEvent* event);
+ void focusInEvent(QFocusEvent* event);
+ void focusOutEvent(QFocusEvent* event);
private:
QString m_oldString;
int m_historySize;
+private:
+ static int m_defaultHistorySize;
};
#endif // RECOMBOBOX_HPP
class ReSettings {
public:
- static QString sTRUE;
- static QString sFALSE;
+ static QString TRUE;
+ static QString FALSE;
public:
ReSettings(const QString& path, const QString& prefix, ReLogger* logger);
~ReSettings();
#include <QListWidget>
#include <QAction>
#include <QApplication>
+#include "gui/ReComboBox.hpp"
#include "gui/ReGuiUtils.hpp"
#include "gui/ReGuiQueue.hpp"
#include "gui/ReStateStorage.hpp"
#include "gui/ReEdit.hpp"
#include "gui/ReSettings.hpp"
#include "gui/ReFileTree.hpp"
-#include "gui/ReComboBox.hpp"
/**
* Tests whether a point is inside the rectangle (including border).
*/
ReFileSystem::ErrorCode ReCryptFileSystem::read(const ReFileMetaData& source,
int64_t offset, int size, QByteArray& buffer) {
+ ReUseParameter(source);
+ ReUseParameter(offset);
+ ReUseParameter(size);
+ ReUseParameter(buffer);
return EC_SUCCESS;
}
*/
ReFileSystem::ErrorCode ReCryptFileSystem::remove(const ReFileMetaData& node)
{
+ ReUseParameter(node);
return EC_SUCCESS;
}
*/
ReFileSystem::ErrorCode ReCryptFileSystem::setDirectory(const QString& path)
{
+ ReUseParameter(path);
return EC_SUCCESS;
}
ReFileSystem::ErrorCode ReCryptFileSystem::setProperties(const ReFileMetaData& source,
ReFileMetaData& target, bool force)
{
+ ReUseParameter(source);
+ ReUseParameter(target);
+ ReUseParameter(force);
return EC_SUCCESS;
}
rc = ! m_logger->logv(LOG_ERROR, LOC_REMOVE_ENTRY_1, "cannot remove file %s: not found",
I18N::s2b(node).constData());
else {
- ReFileMetaData& entry2 = *(ReFileMetaData*) entry;
+ //ReFileMetaData& entry2 = *(ReFileMetaData*) entry;
//@ToDo:
//m_list.removeOne(entry2);
assert(false);
*/
ReFileSystem::ErrorCode ReCryptLeafFile::read(int size, QByteArray& buffer)
{
+ ReUseParameter(size);
+ ReUseParameter(buffer);
ReFileSystem::ErrorCode rc = ReFileSystem::EC_SUCCESS;
return rc;