rpldoc.zip
build/
appl/build-reidos-Desktop-Debug/
+.metadata
* Constructor.
*/
FileFinder::FileFinder() :
- m_lines(0),
- m_patterns(),
- m_antiPatterns(),
- m_minSize(0),
- m_maxSize(-1),
- m_youngerThan(),
- m_olderThan(),
- m_fileTypes(QDir::NoFilter),
- m_minDepth(0),
- m_maxDepth(512),
- m_baseDir(""),
- m_checkDates(false),
- m_excludedDirs(),
- m_textFinder(NULL){
+ m_lines(0),
+ m_patterns(),
+ m_antiPatterns(),
+ m_minSize(0),
+ m_maxSize(-1),
+ m_youngerThan(),
+ m_olderThan(),
+ m_fileTypes(QDir::NoFilter),
+ m_minDepth(0),
+ m_maxDepth(512),
+ m_baseDir(""),
+ m_checkDates(false),
+ m_excludedDirs(),
+ m_textFinder(NULL){
m_youngerThan.setMSecsSinceEpoch(0);
m_olderThan.setMSecsSinceEpoch(0);
}
QString typeOf(const QFileInfo& info){
QString rc;
if (info.isSymLink()){
- if (info.isDir())
- rc = QObject::tr("link (dir)");
- else
- rc = QObject::tr("link (file)");
+ if (info.isDir())
+ rc = QObject::tr("link (dir)");
+ else
+ rc = QObject::tr("link (file)");
}else if (info.isDir())
- rc = QObject::tr("dir");
+ rc = QObject::tr("dir");
else
- rc = QObject::tr("file");
+ rc = QObject::tr("file");
return rc;
}
table->setSortingEnabled(false);
QDir::Filters filters = m_fileTypes | QDir::NoDotAndDotDot;
if (m_patterns.count() == 0)
- entries = dir.entryInfoList(filters, QDir::NoSort);
+ entries = dir.entryInfoList(filters, QDir::NoSort);
else
- entries = dir.entryInfoList(m_patterns, filters, QDir::NoSort);
- QString relativePath = ReQStringUtil::nativePath(
- path.mid(1 + m_baseDir.length()));
+ entries = dir.entryInfoList(m_patterns, filters, QDir::NoSort);
+ QString relativePath = ReQStringUtils::nativePath(
+ path.mid(1 + m_baseDir.length()));
QString node, ext;
QList<QRegExp*> antiPatterns;
QStringList::const_iterator it3;
for (it3 = m_antiPatterns.begin(); it3 != m_antiPatterns.end(); ++it3){
- QString pattern(*it3);
- antiPatterns.append(new QRegExp(pattern, Qt::CaseInsensitive, QRegExp::Wildcard));
+ QString pattern(*it3);
+ antiPatterns.append(new QRegExp(pattern, Qt::CaseInsensitive, QRegExp::Wildcard));
}
QList<QRegExp*>::const_iterator it2;
QList <QFileInfo>::const_iterator it;
for (it = entries.begin(); it != entries.end(); ++it){
- node = it->fileName();
- if (node == "." || node == "..")
- continue;
- bool ignore = false;
- for (it2 = antiPatterns.begin(); it2 != antiPatterns.end(); ++it2){
- if ((*it2)->indexIn(node) >= 0){
- ignore = true;
- break;
- }
- }
- if (ignore)
- continue;
- if (depth >= m_minDepth && isValid(*it)){
- if (m_lines >= table->rowCount()){
- table->setRowCount(m_lines + 500);
- }
- bool isDir = it->isDir();
- if (isDir)
- statistics.m_dirs++;
- else
- statistics.m_files++;
- table->setItem(m_lines, TC_NODE, new QTableWidgetItem(node));
- int ix = node.lastIndexOf('.');
- ext = ix <= 0 ? "" : node.mid(ix + 1).toLower();
- table->setItem(m_lines, TC_EXT, new QTableWidgetItem(ext));
- table->setItem(m_lines, TC_TYPE, new QTableWidgetItem(typeOf(*it)));
- table->setItem(m_lines, TC_PATH, new QTableWidgetItem(relativePath));
- QTableWidgetItem* item = new QTableWidgetItem(
- isDir ? "" : fileSize(it->size()));
- if (!isDir)
- statistics.m_bytes += it->size();
- item->setTextAlignment(Qt::AlignRight);
- table->setItem(m_lines, TC_SIZE, item);
- table->setItem(m_lines, TC_MODIFIED,
- new QTableWidgetItem(
- it->lastModified().toString("yyyy.MM.dd/hh:mm:ss")));
- m_lines++;
- }
+ node = it->fileName();
+ if (node == "." || node == "..")
+ continue;
+ bool ignore = false;
+ for (it2 = antiPatterns.begin(); it2 != antiPatterns.end(); ++it2){
+ if ((*it2)->indexIn(node) >= 0){
+ ignore = true;
+ break;
+ }
+ }
+ if (ignore)
+ continue;
+ if (depth >= m_minDepth && isValid(*it)){
+ if (m_lines >= table->rowCount()){
+ table->setRowCount(m_lines + 500);
+ }
+ bool isDir = it->isDir();
+ if (isDir)
+ statistics.m_dirs++;
+ else
+ statistics.m_files++;
+ table->setItem(m_lines, TC_NODE, new QTableWidgetItem(node));
+ int ix = node.lastIndexOf('.');
+ ext = ix <= 0 ? "" : node.mid(ix + 1).toLower();
+ table->setItem(m_lines, TC_EXT, new QTableWidgetItem(ext));
+ table->setItem(m_lines, TC_TYPE, new QTableWidgetItem(typeOf(*it)));
+ table->setItem(m_lines, TC_PATH, new QTableWidgetItem(relativePath));
+ QTableWidgetItem* item = new QTableWidgetItem(
+ isDir ? "" : fileSize(it->size()));
+ if (!isDir)
+ statistics.m_bytes += it->size();
+ item->setTextAlignment(Qt::AlignRight);
+ table->setItem(m_lines, TC_SIZE, item);
+ table->setItem(m_lines, TC_MODIFIED,
+ new QTableWidgetItem(
+ it->lastModified().toString("yyyy.MM.dd/hh:mm:ss")));
+ m_lines++;
+ }
}
for (it2 = antiPatterns.begin(); it2 != antiPatterns.end(); ++it2){
- delete *it2;
+ delete *it2;
}
if (depth < m_maxDepth || m_maxDepth < 0){
- entries = dir.entryInfoList(
- QDir::NoSymLinks | QDir::NoDotAndDotDot | QDir::AllDirs, QDir::NoSort);
- bool filtered = m_excludedDirs.length() > 0;
- for (it = entries.begin(); it != entries.end(); ++it){
- QString node = it->fileName();
- if (!filtered || !isExcludedDir(node))
- fillTable(path + QDir::separator() + node, depth + 1, table,
- statistics);
- }
+ entries = dir.entryInfoList(
+ QDir::NoSymLinks | QDir::NoDotAndDotDot | QDir::AllDirs, QDir::NoSort);
+ bool filtered = m_excludedDirs.length() > 0;
+ for (it = entries.begin(); it != entries.end(); ++it){
+ QString node = it->fileName();
+ if (!filtered || !isExcludedDir(node))
+ fillTable(path + QDir::separator() + node, depth + 1, table,
+ statistics);
+ }
}
table->setRowCount(m_lines);
}
bool rc = false;
QList <QString>::iterator it;
for (it = m_excludedDirs.begin(); it != m_excludedDirs.end(); ++it){
- if (QString::compare(node, *it, Qt::CaseInsensitive) == 0){
- rc = true;
- break;
- }
+ if (QString::compare(node, *it, Qt::CaseInsensitive) == 0){
+ rc = true;
+ break;
+ }
}
return rc;
}
bool rc = size >= m_minSize && (m_maxSize < 0 || size <= m_maxSize);
bool checkYounger;
if (rc
- && ((checkYounger = m_youngerThan.toMSecsSinceEpoch() > 0)
- || m_olderThan.toMSecsSinceEpoch() > 0)){
- QDateTime date = file.lastModified();
- rc = !checkYounger || date >= m_youngerThan;
- if (rc)
- rc = m_olderThan.toMSecsSinceEpoch() == 0 || date <= m_olderThan;
+ && ((checkYounger = m_youngerThan.toMSecsSinceEpoch() > 0)
+ || m_olderThan.toMSecsSinceEpoch() > 0)){
+ QDateTime date = file.lastModified();
+ rc = !checkYounger || date >= m_youngerThan;
+ if (rc)
+ rc = m_olderThan.toMSecsSinceEpoch() == 0 || date <= m_olderThan;
}
if (rc && m_textFinder != NULL){
- QString full = file.absoluteFilePath();
- TextFinder textFinder(full, file.size());
- textFinder.getSearchParameter(*m_textFinder);
- rc = textFinder.contains();
+ QString full = file.absoluteFilePath();
+ TextFinder textFinder(full, file.size());
+ textFinder.getSearchParameter(*m_textFinder);
+ rc = textFinder.contains();
}
return rc;
}
void FileFinder::setOlderThan(const QDateTime& olderThan){
m_olderThan = olderThan;
if (m_olderThan.toMSecsSinceEpoch() > 0)
- m_checkDates = true;
+ m_checkDates = true;
}
/**
m_antiPatterns.clear();
QStringList::const_iterator it;
for (it = patterns.begin(); it != patterns.end(); ++it){
- QString pattern = *it;
- if (pattern.startsWith("-")){
- if (pattern.length() > 1)
- m_antiPatterns.append(pattern.mid(1));
- } else {
- if (pattern.length() > 0)
- m_patterns.append(pattern);
- }
+ QString pattern = *it;
+ if (pattern.startsWith("-")){
+ if (pattern.length() > 1)
+ m_antiPatterns.append(pattern.mid(1));
+ } else {
+ if (pattern.length() > 0)
+ m_patterns.append(pattern);
+ }
}
}
void FileFinder::setYoungerThan(const QDateTime& youngerThan){
m_youngerThan = youngerThan;
if (youngerThan.toMSecsSinceEpoch() > 0)
- m_checkDates = true;
+ m_checkDates = true;
}
m_lastOrder(Qt::DescendingOrder),
m_homeDir(homeDir),
m_storageFile(),
- m_contextHandlers(){
+ m_contextHandlers(),
+ m_logger(new ReMemoryLogger()){
ui->setupUi(this);
initializeHome();
m_statusMessage = new QLabel(tr("Welcome at refind"));
QString rc(m_lastBaseDir.absolutePath());
QString value = cellAsText(row, TC_PATH);
if (!value.isEmpty()){
- ReQStringUtil::ensureLastChar(rc, '/');
+ ReQStringUtils::ensureLastChar(rc, '/');
rc += value;
}
if (withNode){
- ReQStringUtil::ensureLastChar(rc, '/');
+ ReQStringUtils::ensureLastChar(rc, '/');
rc += cellAsText(row, TC_NODE);
}
if (uriFormat){
QTextStream stream(fp);
exportToStream(stream);
fclose(fp);
- setStatusMessage(false, tr("result exported to ") + fn);
+ say(LOG_INFO, tr("result exported to ") + fn);
}
}else{
QString value;
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(value);
if (m_errors == 0)
- setStatusMessage(false, tr("result exported to the clipboard"));
+ say(LOG_INFO, tr("result exported to the clipboard"));
}
}
QString line = ui->comboBoxTemplate->currentText();
QMap < QString, QString > placeholders;
QString path = m_lastBaseDir.absoluteFilePath(
- ReQStringUtil::pathAppend(ui->tableWidget->item(ii, TC_PATH)->text(),
+ ReFileUtils::pathAppend(ui->tableWidget->item(ii, TC_PATH)->text(),
ui->tableWidget->item(ii, TC_NODE)->text()));
- placeholders.insert("full", ReQStringUtil::nativePath(path));
+ placeholders.insert("full", ReQStringUtils::nativePath(path));
placeholders.insert("path", ui->tableWidget->item(ii, TC_PATH)->text());
placeholders.insert("ext", ui->tableWidget->item(ii, TC_EXT)->text());
placeholders.insert("node", ui->tableWidget->item(ii, TC_NODE)->text());
placeholders.insert("modified",
ui->tableWidget->item(ii, TC_MODIFIED)->text());
placeholders.insert("size", ui->tableWidget->item(ii, TC_SIZE)->text());
- if (!ReQStringUtil::replacePlaceholders(line, placeholders, &error)){
+ if (!ReQStringUtils::replacePlaceholders(line, placeholders, &error)){
guiError(ui->comboBoxTemplate, error);
break;
}
QPainter painter(&image);
QString msg;
if (urls.size() == 1)
- msg = tr("copy ") + ReQStringUtil::nodeOf(urls.at(0).toString());
+ msg = tr("copy ") + ReFileUtils::nodeOf(urls.at(0).toString());
else if (files > 0 && dirs > 0)
msg = tr("copy %1 file(s) and %2 dir(s)").arg(files).arg(dirs);
else if (files > 0)
mimeData->setText(textList);
QClipboard *clipboard = QApplication::clipboard();
clipboard->setMimeData(mimeData);
- setStatusMessage(false,
+ say(LOG_INFO,
tr("%1 entry/entries copied to clipboard").arg(urls.length()));
}
placeholders.insert("full", full);
placeholders.insert("node", node);
placeholders.insert("path", parent);
- placeholders.insert("ext", ReQStringUtil::extensionOf(node));
+ placeholders.insert("ext", ReFileUtils::extensionOf(node));
QString error;
QStringList args = arguments.split(' ');
bool hasErrors = false;
for (int ix = 0; ix < args.size(); ix++){
QString arg = args.at(ix);
- if (!ReQStringUtil::replacePlaceholders(arg, placeholders, &error)){
+ if (!ReQStringUtils::replacePlaceholders(arg, placeholders, &error)){
guiError(NULL, error);
hasErrors = true;
break;
}
if (!hasErrors){
QProcess::startDetached(handler->m_program, args, dir, NULL);
- setStatusMessage(false,
+ say(LOG_INFO,
tr("started:") + " " + handler->m_program + " " + arguments);
}
}
QString node = ui->tableWidget->item(currentRow, TC_NODE)->text();
QString parent = buildAbsPath(currentRow);
- QString full = ReQStringUtil::pathAppend(parent, node);
+ QString full = ReFileUtils::pathAppend(parent, node);
QFileInfo file(full);
bool isDir = file.isDir();
QList <ContextHandler*>::const_iterator it;
QMap <QString, QString>& placeholders){
QString rc = combo->currentText();
QString error;
-if (!ReQStringUtil::replacePlaceholders(rc, placeholders, &error))
+if (!ReQStringUtils::replacePlaceholders(rc, placeholders, &error))
guiError(combo, error);
return replaceEscSequences(rc);
}
* Reads the history of the widget values and other parameters and set it.
*/
void MainWindow::restoreState(){
-ReStateStorage storage(m_storageFile);
+ReStateStorage storage(m_storageFile, m_logger);
storage.setForm("main");
storage.restore(ui->comboBoxDirectory, "comboBoxDirectory", true);
storage.restore(ui->comboBoxExcludedDirs, "comboBoxExcludedDirs", true);
* Stores the history of the widget values and other parameters.
*/
void MainWindow::saveState(){
-ReStateStorage storage(m_storageFile);
+ReStateStorage storage(m_storageFile, m_logger);
storage.setForm("main");
storage.store(ui->comboBoxDirectory, "comboBoxDirectory");
storage.store(ui->comboBoxExcludedDirs, "comboBoxExcludedDirs");
"Found: %d dir(s) and %d file(s) with %.6f MByte. Duration of the search: %.3f sec").toUtf8(),
m_statistics.m_dirs, m_statistics.m_files,
m_statistics.m_bytes / 1000000.0, m_statistics.m_runtimeSeconds);
- setStatusMessage(false, msg);
+ say(LOG_INFO, msg);
}
}
QApplication::restoreOverrideCursor();
}
/**
- * Writes a text to the status line.
+ * Issues a message in the status line.
*
- * @param error <code>true</code>: the message is an error message
- * @param message the text to set
- */
-void MainWindow::setStatusMessage(bool error, const QString& message){
-if (m_stdLabelBackgroundRole == NULL)
- m_stdLabelBackgroundRole = new QPalette::ColorRole(
- m_statusMessage->backgroundRole());
-m_statusMessage->setBackgroundRole(
- error ? QPalette::HighlightedText : *m_stdLabelBackgroundRole);
-m_statusMessage->setText(message);
+ * @param level type of the message, e.g. LOG_INFO or LOG_ERROR
+ * @param message the message to issue. Use QString::arg() to format,
+ * e.g. <code>say(QString("name: %1 no: %2).arg(name).arg(no)</code>
+ * @return <code>false</code>: level == LOG_ERROR or LOG_WARNING<br>
+ * <code>true</code>: level >= LOG_INFO
+ */
+bool MainWindow::say(ReLoggerLevel level, const QString& message){
+ bool rc = level >= LOG_INFO;
+ if (m_stdLabelBackgroundRole == NULL)
+ m_stdLabelBackgroundRole = new QPalette::ColorRole(
+ m_statusMessage->backgroundRole());
+ m_statusMessage->setBackgroundRole(
+ ! rc ? QPalette::HighlightedText : *m_stdLabelBackgroundRole);
+ m_statusMessage->setText(message);
+ return rc;
}
/**
QString replaceGlobalPlaceholders(QComboBox* combo,
QMap <QString, QString>& placeholders);
void restoreState();
- virtual void setStatusMessage(bool error, const QString& message);
+ virtual bool say(ReLoggerLevel level, const QString& message);
private:
Ui::MainWindow *ui;
QLabel* m_statusMessage;
QAction* m_actionEditor;
QAction* m_actionStartShell;
ContextHandlerList m_contextHandlers;
+ ReLogger* m_logger;
};
#endif // MAINWINDOW_HPP
SOURCES += main.cpp\
mainwindow.cpp \
../../base/ReException.cpp \
- ../../base/ReQStringUtil.cpp \
+ ../../base/ReQStringUtils.cpp \
+ ../../base/ReFileUtils.cpp \
../../base/ReLogger.cpp \
filefinder.cpp \
textfinder.cpp \
* Constructor.
*/
TextFinder::TextFinder() :
- m_ignoreBinary(false),
- m_filename(),
- m_length(0),
- m_file(),
- m_valid(false),
- m_regExpr(NULL),
- m_isRegExpr(false),
- m_ignoreCase(false),
- m_ownsRegExpr(false),
- m_text(){
+ m_ignoreBinary(false),
+ m_filename(),
+ m_length(0),
+ m_file(),
+ m_valid(false),
+ m_regExpr(NULL),
+ m_isRegExpr(false),
+ m_ignoreCase(false),
+ m_ownsRegExpr(false),
+ m_text(){
}
TextFinder::TextFinder(const QString& fullName, int64_t length) :
- m_ignoreBinary(false),
- m_filename(fullName),
- m_length(length),
- m_file(fullName),
- m_valid(false),
- m_regExpr(NULL),
- m_isRegExpr(false),
- m_ignoreCase(false),
- m_ownsRegExpr(false),
- m_text(){
+ m_ignoreBinary(false),
+ m_filename(fullName),
+ m_length(length),
+ m_file(fullName),
+ m_valid(false),
+ m_regExpr(NULL),
+ m_isRegExpr(false),
+ m_ignoreCase(false),
+ m_ownsRegExpr(false),
+ m_text(){
m_valid = m_file.open(QIODevice::ReadOnly);
}
*/
TextFinder::~TextFinder(){
if (m_ownsRegExpr){
- delete m_regExpr;
- m_regExpr = NULL;
+ delete m_regExpr;
+ m_regExpr = NULL;
}
}
bool TextFinder::contains(){
bool rc = false;
if (!m_ignoreBinary || !isBinary()){
- m_file.seek(0);
- QTextStream stream(&m_file);
- QString line;
- if (m_regExpr != NULL){
- QRegularExpressionMatch match;
- while (!stream.atEnd()){
- line = stream.readLine();
- match = m_regExpr->match(line);
- if (match.hasMatch()){
- rc = true;
- break;
- }
- }
- }else{
- Qt::CaseSensitivity mode =
- m_ignoreCase ? Qt::CaseInsensitive : Qt::CaseSensitive;
- while (!stream.atEnd()){
- line = stream.readLine();
- if (line.indexOf(m_text, 0, mode) >= 0){
- rc = true;
- break;
- }
- }
- }
+ m_file.seek(0);
+ QTextStream stream(&m_file);
+ QString line;
+ if (m_regExpr != NULL){
+ QRegularExpressionMatch match;
+ while (!stream.atEnd()){
+ line = stream.readLine();
+ match = m_regExpr->match(line);
+ if (match.hasMatch()){
+ rc = true;
+ break;
+ }
+ }
+ }else{
+ Qt::CaseSensitivity mode =
+ m_ignoreCase ? Qt::CaseInsensitive : Qt::CaseSensitive;
+ while (!stream.atEnd()){
+ line = stream.readLine();
+ if (line.indexOf(m_text, 0, mode) >= 0){
+ rc = true;
+ break;
+ }
+ }
+ }
}
return rc;
}
QByteArray data = m_file.read(64 * 1024);
int length = data.length();
const char* ptr = reinterpret_cast <const char*>(memchr(data.constData(),
- '\0', length));
+ '\0', length));
bool rc = ptr != NULL;
return rc;
}
uint8_t byte1;
bool rc = true;
while ((byte1 = *ptr++) != '\0'){
- // ASCII with control chars:
- if (byte1 < ' ' && byte1 != '\t' && byte1 != '\n' && byte1 != '\r'){
- rc = false;
- break;
- }
- if (rc > 0x7f)
- isAscii = false;
+ // ASCII with control chars:
+ if (byte1 < ' ' && byte1 != '\t' && byte1 != '\n' && byte1 != '\r'){
+ rc = false;
+ break;
+ }
+ if (byte1 > 0x7f)
+ isAscii = false;
}
if (trueAscii != NULL)
- *trueAscii = rc && isAscii;
+ *trueAscii = rc && isAscii;
return rc;
}
uint8_t byte1;
bool rc = true;
while ((byte1 = *ptr++) != '\0'){
- // ASCII with control chars:
- if ((0x20 <= byte1 && byte1 <= 0x7E) || byte1 == '\t' || byte1 == '\n'
- || byte1 == '\r'){
- continue;
- }
- isAscii = false;
- uint8_t byte2 = *ptr++;
- // non-overlong 2-byte
- if (0xC2 <= byte1 && byte1 <= 0xDF && 0x80 <= byte2 && byte2 <= 0xBF){
- continue;
- }
- uint8_t byte3 = *ptr++;
- // excluding overlongs
- if ((byte1 == 0xE0 && 0xA0 <= byte2 && byte2 <= 0xBF && 0x80 <= byte3
- && byte3 <= 0xBF)
- // straight 3-byte
- || (((0xE1 <= byte1 && byte1 <= 0xEC) || byte1 == 0xEE || byte1 == 0xEF)
- && 0x80 <= byte2 && byte2 <= 0xBF && 0x80 <= byte3 && byte3 <= 0xBF)
- // excluding surrogates
- || (byte1 == 0xED && (0x80 <= byte2 && byte2 <= 0x9F)
- && (0x80 <= byte3 && byte3 <= 0xBF))){
- continue;
- }
- uint8_t byte4 = *ptr++;
- if ( // planes 1-3
- (byte1 == 0xF0 && 0x90 <= byte2 && byte2 <= 0xBF && 0x80 <= byte3
- && byte3 <= 0xBF && 0x80 <= byte4 && byte4 <= 0xBF)
- // planes 4-15
- || (0xF1 <= byte1 && byte1 <= 0xF3 && 0x80 <= byte2 && byte2 <= 0xBF
- && 0x80 <= byte3 && byte3 <= 0xBF && 0x80 <= byte4 && byte4 <= 0xBF)
- // plane 16
- || (byte1 == 0xF4 && 0x80 <= byte2 && byte2 <= 0x8F && 0x80 <= byte3
- && byte3 <= 0xBF && 0x80 <= byte4 && byte4 <= 0xBF)){
- continue;
- }
+ // ASCII with control chars:
+ if ((0x20 <= byte1 && byte1 <= 0x7E) || byte1 == '\t' || byte1 == '\n'
+ || byte1 == '\r'){
+ continue;
+ }
+ isAscii = false;
+ uint8_t byte2 = *ptr++;
+ // non-overlong 2-byte
+ if (0xC2 <= byte1 && byte1 <= 0xDF && 0x80 <= byte2 && byte2 <= 0xBF){
+ continue;
+ }
+ uint8_t byte3 = *ptr++;
+ // excluding overlongs
+ if ((byte1 == 0xE0 && 0xA0 <= byte2 && byte2 <= 0xBF && 0x80 <= byte3
+ && byte3 <= 0xBF)
+ // straight 3-byte
+ || (((0xE1 <= byte1 && byte1 <= 0xEC) || byte1 == 0xEE || byte1 == 0xEF)
+ && 0x80 <= byte2 && byte2 <= 0xBF && 0x80 <= byte3 && byte3 <= 0xBF)
+ // excluding surrogates
+ || (byte1 == 0xED && (0x80 <= byte2 && byte2 <= 0x9F)
+ && (0x80 <= byte3 && byte3 <= 0xBF))){
+ continue;
+ }
+ uint8_t byte4 = *ptr++;
+ if ( // planes 1-3
+ (byte1 == 0xF0 && 0x90 <= byte2 && byte2 <= 0xBF && 0x80 <= byte3
+ && byte3 <= 0xBF && 0x80 <= byte4 && byte4 <= 0xBF)
+ // planes 4-15
+ || (0xF1 <= byte1 && byte1 <= 0xF3 && 0x80 <= byte2 && byte2 <= 0xBF
+ && 0x80 <= byte3 && byte3 <= 0xBF && 0x80 <= byte4 && byte4 <= 0xBF)
+ // plane 16
+ || (byte1 == 0xF4 && 0x80 <= byte2 && byte2 <= 0x8F && 0x80 <= byte3
+ && byte3 <= 0xBF && 0x80 <= byte4 && byte4 <= 0xBF)){
+ continue;
+ }
- rc = false;
- break;
+ rc = false;
+ break;
}
if (trueAscii != NULL)
- *trueAscii = rc && isAscii;
+ *trueAscii = rc && isAscii;
return rc;
}
/**
m_isRegExpr = isRegExpr;
m_ignoreBinary = ignoreBinary;
if (!isRegExpr || text.isEmpty()){
- delete m_regExpr;
- m_regExpr = NULL;
+ delete m_regExpr;
+ m_regExpr = NULL;
}else{
- QRegularExpression::PatternOption option =
- ignoreCase ?
- QRegularExpression::CaseInsensitiveOption :
- QRegularExpression::NoPatternOption;
- m_ownsRegExpr = true;
- m_regExpr = new QRegularExpression(text, option);
+ QRegularExpression::PatternOption option =
+ ignoreCase ?
+ QRegularExpression::CaseInsensitiveOption :
+ QRegularExpression::NoPatternOption;
+ m_ownsRegExpr = true;
+ m_regExpr = new QRegularExpression(text, option);
}
}
QString TextFinder::regExprError(){
QString rc;
if (m_regExpr != NULL && !m_regExpr->isValid())
- rc = m_regExpr->errorString();
+ rc = m_regExpr->errorString();
return rc;
}
* Constructor.
*/
ContextHandler::ContextHandler(IntrinsicType intrinsicType, const QString& text) :
- m_text(text),
- m_program(),
- m_arguments(),
- m_directoryMode(DM_UNDEF),
- m_fileType(FT_ALL),
- m_intrinsicType(intrinsicType){
+ m_text(text),
+ m_program(),
+ m_arguments(),
+ m_directoryMode(DM_UNDEF),
+ m_fileType(FT_ALL),
+ m_intrinsicType(intrinsicType){
}
/**
* Constructor.
*/
ContextHandler::ContextHandler() :
- m_text(),
- m_program(),
- m_arguments(),
- m_directoryMode(DM_TO_PARENT),
- m_fileType(FT_FILE),
- m_intrinsicType(IT_UNDEF){
+ m_text(),
+ m_program(),
+ m_arguments(),
+ m_directoryMode(DM_TO_PARENT),
+ m_fileType(FT_FILE),
+ m_intrinsicType(IT_UNDEF){
}
/**
* Constructor.
*/
ContextHandlerList::ContextHandlerList() :
- m_list(){
+ m_list(){
}
/**
* @return the instance itself
*/
ContextHandlerList::ContextHandlerList(const ContextHandlerList& source) :
- m_list(){
+ m_list(){
copy(source);
}
*/
void ContextHandlerList::addIntrinsics(){
m_list.append(
- new ContextHandler(ContextHandler::IT_COPY, QObject::tr("copy")));
+ new ContextHandler(ContextHandler::IT_COPY, QObject::tr("copy")));
}
/**
void ContextHandlerList::clear(){
QList <ContextHandler*>::const_iterator it;
for (it = m_list.begin(); it != m_list.end(); ++it){
- delete *it;
+ delete *it;
}
m_list.clear();
}
clear();
QList <ContextHandler*>::const_iterator it;
for (it = source.m_list.begin(); it != source.m_list.end(); ++it){
- ContextHandler* handler = *it;
- if (handler->intrinsicType() == ContextHandler::IT_UNDEF)
- m_list.append(handler);
+ ContextHandler* handler = *it;
+ if (handler->intrinsicType() == ContextHandler::IT_UNDEF)
+ m_list.append(handler);
}
addIntrinsics();
return *this;
* @param storage IN/OUT: the storage
*/
void ContextHandlerList::save(ReStateStorage& storage){
- QString name = "context.program";
+ const char* name = "context.program";
QString value;
for (int ix = 0; ix < m_list.size(); ix++){
- ContextHandler* handler = m_list.at(ix);
- if (handler->intrinsicType() == ContextHandler::IT_UNDEF){
- value = handler->m_text + "\t" + handler->m_program + "\t"
- + handler->m_arguments + "\t" + QString::number(handler->m_fileType)
- + "\t" + QString::number(handler->m_directoryMode);
- storage.store(name, value, ix);
- }
+ ContextHandler* handler = m_list.at(ix);
+ if (handler->intrinsicType() == ContextHandler::IT_UNDEF){
+ value = handler->m_text + "\t" + handler->m_program + "\t"
+ + handler->m_arguments + "\t" + QString::number(handler->m_fileType)
+ + "\t" + QString::number(handler->m_directoryMode);
+ storage.store(name, value, ix);
+ }
}
}
QFileInfo info(file);
ContextHandler* handler = NULL;
if (info.exists()){
- handler = new ContextHandler;
- handler->m_text = ReQStringUtil::nodeOf(file);
- handler->m_program = file;
- handler->m_arguments = "${full}";
+ handler = new ContextHandler;
+ handler->m_text = ReFileUtils::nodeOf(file);
+ handler->m_program = file;
+ handler->m_arguments = "${full}";
#if defined WIN32
- if (handler->m_text == "cmd.exe")
- handler->m_arguments = "";
+ if (handler->m_text == "cmd.exe")
+ handler->m_arguments = "";
#endif
- handler->m_fileType = fileType;
- handler->m_directoryMode =
- fileType == ContextHandler::FT_FILE ?
- ContextHandler::DM_TO_PARENT : ContextHandler::DM_TO_FILE;
+ handler->m_fileType = fileType;
+ handler->m_directoryMode =
+ fileType == ContextHandler::FT_FILE ?
+ ContextHandler::DM_TO_PARENT : ContextHandler::DM_TO_FILE;
}
return handler;
}
* @param storage
*/
void ContextHandlerList::restore(ReStateStorage& storage){
- QString name = "context.program";
+ const char* name = "context.program";
clear();
int ix = -1;
QString value;
QStringList cols;
ContextHandler* handler;
while (true){
- ix++;
- value = storage.restore(name, ix);
- if (value.isEmpty())
- break;
- cols = value.split('\t');
- if (cols.size() < 3)
- continue;
- handler = new ContextHandler;
- handler->m_text = cols.at(0);
- handler->m_program = cols.at(1);
- handler->m_arguments = cols.at(2);
- const char* sValue = cols.at(3).toUtf8().constData();
- handler->m_fileType = ContextHandler::FileType(atol(sValue));
- sValue = cols.at(4).toUtf8().constData();
- handler->m_directoryMode = ContextHandler::DirMode(atol(sValue));
- m_list.append(handler);
+ ix++;
+ value = storage.restore(name, ix);
+ if (value.isEmpty())
+ break;
+ cols = value.split('\t');
+ if (cols.size() < 3)
+ continue;
+ handler = new ContextHandler;
+ handler->m_text = cols.at(0);
+ handler->m_program = cols.at(1);
+ handler->m_arguments = cols.at(2);
+ const char* sValue = cols.at(3).toUtf8().constData();
+ handler->m_fileType = ContextHandler::FileType(atol(sValue));
+ sValue = cols.at(4).toUtf8().constData();
+ handler->m_directoryMode = ContextHandler::DirMode(atol(sValue));
+ m_list.append(handler);
}
if (m_list.size() == 0){
#if defined __linux__
- handler = createHandlerIfExists("/usr/bin/kate");
- if (handler == NULL)
- handler = createHandlerIfExists("/usr/bin/geany");
- if (handler == NULL)
- handler = createHandlerIfExists("/usr/bin/kwrite");
- if (handler == NULL)
- handler = createHandlerIfExists("/usr/bin/gedit");
- if (handler != NULL)
- m_list.append(handler);
- handler = createHandlerIfExists("/usr/bin/konsole", ContextHandler::FT_DIR);
- if (handler == NULL)
- handler = createHandlerIfExists("/usr/bin/gnome-terminal", ContextHandler::FT_DIR);
- if (handler != NULL)
- m_list.append(handler);
+ handler = createHandlerIfExists("/usr/bin/kate");
+ if (handler == NULL)
+ handler = createHandlerIfExists("/usr/bin/geany");
+ if (handler == NULL)
+ handler = createHandlerIfExists("/usr/bin/kwrite");
+ if (handler == NULL)
+ handler = createHandlerIfExists("/usr/bin/gedit");
+ if (handler != NULL)
+ m_list.append(handler);
+ handler = createHandlerIfExists("/usr/bin/konsole", ContextHandler::FT_DIR);
+ if (handler == NULL)
+ handler = createHandlerIfExists("/usr/bin/gnome-terminal", ContextHandler::FT_DIR);
+ if (handler != NULL)
+ m_list.append(handler);
#elif defined WIN32
- handler = createHandlerIfExists("c:\\windows\\system32\\notepad.exe");
- if (handler != NULL)
- m_list.append(handler);
- handler = createHandlerIfExists("c:\\windows\\system32\\cmd.exe", ContextHandler::FT_DIR);
- if (handler != NULL)
- m_list.append(handler);
+ handler = createHandlerIfExists("c:\\windows\\system32\\notepad.exe");
+ if (handler != NULL)
+ m_list.append(handler);
+ handler = createHandlerIfExists("c:\\windows\\system32\\cmd.exe", ContextHandler::FT_DIR);
+ if (handler != NULL)
+ m_list.append(handler);
#endif
}
if (url.startsWith("file:", Qt::CaseInsensitive)){
} else {
- m_main->setStatusMessage(true, QObject::tr("unknown protocol in url: ") + url);
+ m_main->say(LOG_ERROR, QObject::tr("unknown protocol in url: ") + url);
}
}
/**
* Writes a text to the status line.
*
- * @param error <code>true</code>: the message is an error message
+ * @param level the type of the message, e.g. LOG_ERROR
* @param message the text to set
+ * @return <code>false</code>: level == LOG_ERROR or LOG_WARNING<br>
+ * <code>true</code>: level == LOG_INFO
*/
-void IDosMain::setStatusMessage(bool error, const QString& message){
- m_statusMessage->setText(error ? "+++ " + message : message);
+bool IDosMain::say(ReLoggerLevel level, const QString& message){
+ bool rc = level == LOG_INFO;
+ m_statusMessage->setText(! rc ? "+++ " + message : message);
+ return rc;
}
/**
public:
void error(const QString& message);
- virtual void setStatusMessage(bool error, const QString& message);
+ virtual bool say(ReLoggerLevel level, const QString& message);
protected:
void initializeHome();
void restoreState();
if (withBase && (rmdir(path.toUtf8())) != 0) {
rc = false;
logger->logv(LOG_ERROR, LOC_DELETE_TREE_3,
- "cannot delete directory (%d): %s", errno, path.toUtf8().constData());
+ "cannot delete directory (%d): %s", errno, path.toUtf8().constData());
}
return rc;
}
return rc;
}
+/**
+ * Extracts the path of a full filename.
+ *
+ * @param filename the filename (with or without path)
+ * @return "": no path available<br>
+ * "/": filename = "/"<br>
+ * otherwise: the path of <code>filename</code> including
+ * trailing separator
+ */
+QString ReFileUtils::parentOf(const QString& filename) {
+ QString rc;
+
+ int ix = filename.size() - 1;
+ while (ix >= 0) {
+ if (filename[ix] == '/' || filename[ix] == '\\') {
+ rc = filename.mid(ix + 1);
+ break;
+ }
+ ix--;
+ }
+ if (ix >= 0)
+ rc = filename.mid(0, ix + 1);
+ return rc;
+}
+
/** Normalizes a file path.
*
* Removes duplicated slashes and "." and "..", but not leading ".."
class ReFileUtils {
public:
static bool deleteTree(const QString& path, bool withBase,
- ReLogger* logger);
+ ReLogger* logger);
static QByteArray cleanPath(const char* path);
static QString extensionOf(const QString& filename);
static QByteArray extensionOf(const char* filename);
static bool isAbsolutPath(const char* path);
static QString nodeOf(const QString& filename);
static QByteArray nodeOf(const char* filename);
+ static QString parentOf(const QString& filename);
static QString pathAppend(const QString& base, const QString& path);
static QByteArray pathAppend(const char* base, const char* path);
static QByteArray& readFromFile(const char* filename, QByteArray& buffer);
static QByteArray replaceExtension(const char* path, const char* ext);
static int seek(FILE* file, int64_t offset, int whence);
static bool setTimes(const char* filename, const QDateTime& modified,
- const QDateTime& accessed = m_undefinedTime, ReLogger* logger = NULL);
+ const QDateTime& accessed = m_undefinedTime, ReLogger* logger = NULL);
static int64_t tell(FILE* file);
static QByteArray tempDir(const char* node, const char* parent = NULL,
- bool withSeparator = true);
+ bool withSeparator = true);
static QByteArray tempDirEmpty(const char* node, const char* parent = NULL,
- bool withSeparator = true);
+ bool withSeparator = true);
static QByteArray tempFile(const char* node, const char* parent = NULL,
- bool deleteIfExists = true);
+ bool deleteIfExists = true);
static void writeToFile(const char* filename, const char* content,
- size_t contentLength = (size_t) - 1, const char* mode = "w");
+ size_t contentLength = (size_t) - 1, const char* mode = "w");
public:
static QDateTime m_undefinedTime;
};
*/
class ReLogger;
class ReConfig;
+
/**
* @brief Logging level: for controlling of the logging.
*
LOG_DEBUG = 25 ///< for debug purpose only
};
+/**
+ * Very poor logger normally used for GUI programs with status line.
+ *
+ * This is a pure abstract class: implementation of the method say() is needed.
+ */
+class ReAnnouncer{
+public:
+ /**
+ * Issues a message.
+ *
+ * @param level type of the message, e.g. LOG_INFO or LOG_ERROR
+ * @param message the message to issue. Use QString::arg() to format,
+ * e.g. <code>say(QString("name: %1 no: %2).arg(name).arg(no)</code>
+ * @return <code>false</code>: level == LOG_ERROR or LOG_WARNING<br>
+ * <code>true</code>: level >= LOG_INFO
+ */
+ virtual bool say(ReLoggerLevel level, const QString& message) = 0;
+};
+
class ReAppender {
public:
ReAppender(const QByteArray& name);
static ReString chomp(const ReString& text);
static int countOf(const QString& value, QChar toFind, int start = 0);
static QString& ensureLastChar(QString& value, QChar lastChar);
- static QString extensionOf(const QString& filename);
- static QByteArray extensionOf(const char* filename);
static int lengthOfDate(const ReString& text, int start = 0, QDate* value =
NULL);
static int lengthOfDateTime(const ReString& text, int start = 0,
void drawScrollbars(QPainter& painter, const QRect& rect,
double sizeVertical, double posVertical, double sizeHorizontal,
double posHorizontal);
- void ensureCursorVisible();protected slots:
+ void ensureCursorVisible();
+protected slots:
void keyPressEvent(QKeyEvent* event);
void paintEvent(QPaintEvent *);
void mouseMoveEvent(QMouseEvent* event);
void ReGuiValidator::guiError(QWidget* widget, const QString& message) {
if (widget != NULL)
widget->setFocus(Qt::OtherFocusReason);
- setStatusMessage(true, message);
+ say(LOG_ERROR, message);
m_errors++;
}
#include <QComboBox>
#include <QStatusBar>
-class ReGuiValidator {
+class ReGuiValidator : public ReAnnouncer {
public:
ReGuiValidator();
~ReGuiValidator();
public:
QDateTime comboDate(QComboBox* combo);
int comboInt(QComboBox* combo, int defaultValue, const char* specialString =
- NULL, int specialValue = 0);
+ NULL, int specialValue = 0);
int64_t comboSize(QComboBox* combo);
QString comboText(QComboBox* combo);
virtual void guiError(QWidget* widget, const QString& message);
void setInHistory(QComboBox* combo, const QString& value);
- virtual void setStatusMessage(bool error, const QString& message) = 0;
protected:
int m_errors;
tableWidget(new QTableWidget(this)),
fileSystem(NULL),
matcher("*"),
- m_dateFormat("yyyy.MM.dd hh:mm:ss")
+ m_dateFormat("yyyy.MM.dd hh:mm:ss"),
+ announcer(NULL)
{
setLayout(mainLayout);
mainLayout->setSpacing(0);
tableWidget->setColumnWidth(TYPE, 60);
tableWidget->setColumnWidth(SIZE, 125);
tableWidget->setColumnWidth(MODIFIED, 175);
- connect(this, SIGNAL(keyPress(QKeyEvent*)), SLOT(keyPressEvent(QKeyEvent*)));
+ connect(pushButtonUp, SIGNAL(clicked()), SLOT(pushButtonUpClicked()));
+ connect(pushButtonRoot, SIGNAL(clicked()), SLOT(pushButtonRootClicked()));
tableWidget->setHorizontalHeaderLabels(labels);
tableWidget->horizontalHeader()->setStretchLastSection(true);
+ tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
}
/**
tableWidget->setRowCount(list.length());
int row = 0;
for (it = list.cbegin(); it != list.cend(); ++it){
- // TC_EXT, TC_SIZE, TC_MODIFIED, TC_NODE
+ bool isDir = S_ISDIR(it->m_mode);
QString modified = it->m_modified.toString(m_dateFormat);
- QString size = QString::number(it->m_size);
- QString ext = ReFileUtils::extensionOf(it->m_node);
+ QString size = isDir ? ReQStringUtils::m_empty : QString::number(it->m_size);
+ QString ext = isDir ? tr("<dir>") : ReFileUtils::extensionOf(it->m_node);
if (tableWidget->item(row, 0) == NULL){
- tableWidget->setItem(row, NAME, new QTableWidgetItem(it->m_node));
- tableWidget->setItem(row, MODIFIED, new QTableWidgetItem(modified));
- tableWidget->setItem(row, TYPE, new QTableWidgetItem(ext));
- QTableWidgetItem* item = new QTableWidgetItem(size);
- item->setTextAlignment(Qt::AlignRight);
+ QTableWidgetItem* item = new QTableWidgetItem(it->m_node);
+ item->setFlags(item->flags() ^ Qt::ItemIsEditable);
+ tableWidget->setItem(row, NAME, item);
+ item = new QTableWidgetItem(modified);
+ item->setFlags(item->flags() ^ Qt::ItemIsEditable);
+ tableWidget->setItem(row, MODIFIED, item);
+ item = new QTableWidgetItem(ext);
+ item->setFlags(item->flags() ^ Qt::ItemIsEditable);
+ tableWidget->setItem(row, TYPE, item);
+ item = new QTableWidgetItem(size);
+ item->setFlags(item->flags() ^ Qt::ItemIsEditable);
+ item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
tableWidget->setItem(row, SIZE, item);
} else {
tableWidget->item(row, NAME)->setText(it->m_node);
}
}
+/**
+ * Changes the current directory.
+ *
+ * @param directory full path of the new directory
+ */
+void ReFileTable::chDir(const QString& directory){
+ if (directory != fileSystem->directory()){
+ if (directory.indexOf('*') < 0){
+ if (fileSystem->setDirectory(directory) != ReFileSystem::EC_SUCCESS){
+ say(LOG_ERROR, tr("unknown directory:") + " " + directory);
+ } else {
+ comboBoxPath->setCurrentText(directory);
+ // update the history:
+ comboText(comboBoxPath);
+ fillTable();
+ }
+ } else {
+
+ }
+ }
+}
+
/**
* Handles the key press event.
*
- * @param event
+ * @param event event data
*/
-void ReFileTable::keyPress(QKeyEvent* event){
- if (event->key() == Qt::Key_Return){
- /*
- if (changeDirectory(box->currentText())){
- comboText(box);
- fillTable(m_topIsActive ? ui->tableWidgetTop : ui->tableWidgetTop);
+void ReFileTable::keyPressEvent(QKeyEvent* event){
+ Qt::KeyboardModifiers modifiers = event->modifiers();
+ QWidget* sender = QApplication::focusWidget();
+ int key = event->key();
+ if (sender == comboBoxPath){
+ if (key == Qt::Key_Return){
+ if (modifiers == Qt::NoModifier)
+ chDir(comboBoxPath->currentText());
}
- */
+ } else if (sender == comboBoxPatterns){
+
+ } else if (sender == tableWidget){
+
}
}
+/**
+ * Handles the event push button "up" clicked()
+ */
+void ReFileTable::pushButtonUpClicked()
+{
+ chDir(ReFileUtils::parentOf(comboBoxPath->currentText()));
+}
+
+/**
+ * Handles the event push button "root" clicked()
+ */
+void ReFileTable::pushButtonRootClicked()
+{
+ chDir("/");
+}
+
+/**
+ * Handles user messages including errors/warnings.
+ *
+ * @param level type of the message: LOG_ERROR...
+ * @param message message for the user
+ * @return <code>false</code>: level == LOG_ERROR or LOG_WARNING<br>
+ * <code>true</code>: level >= LOG_INFO
+ */
+bool ReFileTable::say(ReLoggerLevel level, const QString& message)
+{
+ if (announcer != NULL)
+ announcer->say(level, message);
+ return level >= LOG_INFO;
+}
// needed for moc_ReFileTable.cpp
#include "guiwidget/reguiwidget.hpp"
#endif
-class ReFileTable : public QWidget
+class ReFileTable : public QWidget, public ReGuiValidator
{
public:
enum { TYPE, MODIFIED, SIZE, NAME, COL_COUNT };
public:
void fillTable();
- void keyPress(QKeyEvent* event);
-
+ void chDir(const QString& directory);
+protected slots:
+ void keyPressEvent(QKeyEvent* event);
+ void pushButtonUpClicked();
+ void pushButtonRootClicked();
protected:
QVBoxLayout* mainLayout;
QHBoxLayout* horizontalLayout;
QString m_dateFormat;
+ virtual bool say(ReLoggerLevel level, const QString& message);
public:
QComboBox* comboBoxPath;
QComboBox* comboBoxPatterns;
QTableWidget* tableWidget;
ReFileSystem* fileSystem;
ReIncludeExcludeMatcher matcher;
+ ReAnnouncer* announcer;
};
#endif // REFILETABLE_HPP
#include "QTableWidget"
#include "QHeaderView"
#include "QKeyEvent"
+#include "QApplication"
#include "guiwidget/ReFileTable.hpp"
#endif // REGUIWIDGET_HPP
*/
ReFileSystem::ErrorCode ReLocalFileSystem::setDirectory(const QString& path) {
ErrorCode rc;
- if (ReFileUtils::isAbsolutPath(path))
- rc = m_dir.setCurrent(path) ? EC_SUCCESS : EC_PATH_NOT_FOUND;
- else
+ if (ReFileUtils::isAbsolutPath(path)){
+ m_dir.setPath(path);
+ rc = m_dir.exists() ? EC_SUCCESS : EC_PATH_NOT_FOUND;
+ } else
rc = m_dir.setCurrent(ReFileUtils::pathAppend(
m_dir.absolutePath(), path))
? EC_SUCCESS : EC_PATH_NOT_FOUND;
- m_directory = m_dir.absolutePath();
- ReQStringUtils::ensureLastChar(m_directory, OS_SEPARATOR);
+ if (rc == EC_SUCCESS){
+ m_directory = m_dir.absolutePath();
+ ReQStringUtils::ensureLastChar(m_directory, OS_SEPARATOR);
+ }
return rc;
}