From 54126c727a87d8975446b077a968488ea8b79a82 Mon Sep 17 00:00:00 2001 From: hama Date: Sun, 1 Nov 2015 01:17:11 +0100 Subject: [PATCH] dayly work --- .gitignore | 1 + appl/refind/filefinder.cpp | 196 ++++++++++++++++---------------- appl/refind/mainwindow.cpp | 64 ++++++----- appl/refind/mainwindow.hpp | 3 +- appl/refind/refind.pro | 3 +- appl/refind/textfinder.cpp | 204 +++++++++++++++++----------------- appl/refind/utils.cpp | 148 ++++++++++++------------ appl/reidos/FileCommander.cpp | 2 +- appl/reidos/idosmain.cpp | 10 +- appl/reidos/idosmain.hpp | 2 +- base/ReFileUtils.cpp | 27 ++++- base/ReFileUtils.hpp | 13 ++- base/ReLogger.cpp | 1 + base/ReLogger.hpp | 20 ++++ base/ReQStringUtils.hpp | 2 - gui/ReEdit.hpp | 3 +- gui/ReGuiValidator.cpp | 2 +- gui/ReGuiValidator.hpp | 5 +- guiwidget/ReFileTable.cpp | 103 ++++++++++++++--- guiwidget/ReFileTable.hpp | 11 +- guiwidget/reguiwidget.hpp | 1 + os/ReFileSystem.cpp | 13 ++- 22 files changed, 484 insertions(+), 350 deletions(-) diff --git a/.gitignore b/.gitignore index 5c1c43b..a427b8f 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ doc/ rpldoc.zip build/ appl/build-reidos-Desktop-Debug/ +.metadata diff --git a/appl/refind/filefinder.cpp b/appl/refind/filefinder.cpp index 9dbc692..d6b4533 100644 --- a/appl/refind/filefinder.cpp +++ b/appl/refind/filefinder.cpp @@ -21,20 +21,20 @@ * 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); } @@ -78,14 +78,14 @@ QString fileSize(int64_t size){ 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; } @@ -113,73 +113,73 @@ void FileFinder::fillTable(const QString& path, int depth, QTableWidget* table, 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 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::const_iterator it2; QList ::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); } @@ -194,10 +194,10 @@ bool FileFinder::isExcludedDir(const QString& node){ bool rc = false; QList ::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; } @@ -213,18 +213,18 @@ bool FileFinder::isValid(const QFileInfo& file){ 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; } @@ -301,7 +301,7 @@ void FileFinder::setMinSize(const int64_t& minSize){ void FileFinder::setOlderThan(const QDateTime& olderThan){ m_olderThan = olderThan; if (m_olderThan.toMSecsSinceEpoch() > 0) - m_checkDates = true; + m_checkDates = true; } /** @@ -314,14 +314,14 @@ void FileFinder::setPatterns(const QStringList& patterns){ 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); + } } } @@ -333,6 +333,6 @@ void FileFinder::setPatterns(const QStringList& patterns){ void FileFinder::setYoungerThan(const QDateTime& youngerThan){ m_youngerThan = youngerThan; if (youngerThan.toMSecsSinceEpoch() > 0) - m_checkDates = true; + m_checkDates = true; } diff --git a/appl/refind/mainwindow.cpp b/appl/refind/mainwindow.cpp index bdf94df..92aab29 100644 --- a/appl/refind/mainwindow.cpp +++ b/appl/refind/mainwindow.cpp @@ -49,7 +49,8 @@ MainWindow::MainWindow(const QString& startDir, const QString& homeDir, 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")); @@ -180,11 +181,11 @@ QString MainWindow::buildAbsPath(int row, bool withNode, bool uriFormat){ 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){ @@ -285,7 +286,7 @@ void MainWindow::exportFiles(){ 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; @@ -295,7 +296,7 @@ void MainWindow::exportFiles(){ 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")); } } @@ -320,16 +321,16 @@ void MainWindow::exportToStream(QTextStream& stream, int maxRow){ 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; } @@ -373,7 +374,7 @@ void MainWindow::fileDragging(){ 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) @@ -454,7 +455,7 @@ void MainWindow::handleCopyToClipboard(int currentRow, const QString& full){ 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())); } @@ -485,13 +486,13 @@ void MainWindow::handleExternalCommand(ContextHandler* handler, 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; @@ -500,7 +501,7 @@ void MainWindow::handleExternalCommand(ContextHandler* handler, } if (!hasErrors){ QProcess::startDetached(handler->m_program, args, dir, NULL); - setStatusMessage(false, + say(LOG_INFO, tr("started:") + " " + handler->m_program + " " + arguments); } } @@ -553,7 +554,7 @@ void MainWindow::handleTableContextMenu(const QPoint& position){ 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 ::const_iterator it; @@ -685,7 +686,7 @@ QString MainWindow::replaceGlobalPlaceholders(QComboBox* combo, QMap & 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); } @@ -716,7 +717,7 @@ ui->checkBoxTextIgnoreCase->setChecked(false); * 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); @@ -740,7 +741,7 @@ storage.close(); * 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"); @@ -812,7 +813,7 @@ else{ "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(); @@ -839,18 +840,23 @@ if (!name.isEmpty()) } /** - * Writes a text to the status line. + * Issues a message in the status line. * - * @param error true: 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. say(QString("name: %1 no: %2).arg(name).arg(no) + * @return false: level == LOG_ERROR or LOG_WARNING
+ * true: 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; } /** diff --git a/appl/refind/mainwindow.hpp b/appl/refind/mainwindow.hpp index 7391964..d38e53a 100644 --- a/appl/refind/mainwindow.hpp +++ b/appl/refind/mainwindow.hpp @@ -84,7 +84,7 @@ private: QString replaceGlobalPlaceholders(QComboBox* combo, QMap & 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; @@ -100,6 +100,7 @@ private: QAction* m_actionEditor; QAction* m_actionStartShell; ContextHandlerList m_contextHandlers; + ReLogger* m_logger; }; #endif // MAINWINDOW_HPP diff --git a/appl/refind/refind.pro b/appl/refind/refind.pro index 669aac4..619646a 100644 --- a/appl/refind/refind.pro +++ b/appl/refind/refind.pro @@ -18,7 +18,8 @@ INCLUDEPATH = ../.. /usr/include/c++/4.9 SOURCES += main.cpp\ mainwindow.cpp \ ../../base/ReException.cpp \ - ../../base/ReQStringUtil.cpp \ + ../../base/ReQStringUtils.cpp \ + ../../base/ReFileUtils.cpp \ ../../base/ReLogger.cpp \ filefinder.cpp \ textfinder.cpp \ diff --git a/appl/refind/textfinder.cpp b/appl/refind/textfinder.cpp index 6188eb0..2352860 100644 --- a/appl/refind/textfinder.cpp +++ b/appl/refind/textfinder.cpp @@ -17,29 +17,29 @@ * 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); } @@ -48,8 +48,8 @@ TextFinder::TextFinder(const QString& fullName, int64_t length) : */ TextFinder::~TextFinder(){ if (m_ownsRegExpr){ - delete m_regExpr; - m_regExpr = NULL; + delete m_regExpr; + m_regExpr = NULL; } } @@ -64,30 +64,30 @@ TextFinder::~TextFinder(){ 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; } @@ -114,7 +114,7 @@ bool TextFinder::isBinary(){ QByteArray data = m_file.read(64 * 1024); int length = data.length(); const char* ptr = reinterpret_cast (memchr(data.constData(), - '\0', length)); + '\0', length)); bool rc = ptr != NULL; return rc; } @@ -132,16 +132,16 @@ bool TextFinder::isText(const QByteArray& data, bool* trueAscii){ 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; } @@ -158,47 +158,47 @@ bool TextFinder::isUTF8(const QByteArray& data, bool* trueAscii) const{ 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; } /** @@ -224,15 +224,15 @@ void TextFinder::setSearchParameter(const QString& text, bool ignoreCase, 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); } } @@ -245,7 +245,7 @@ void TextFinder::setSearchParameter(const QString& text, bool ignoreCase, QString TextFinder::regExprError(){ QString rc; if (m_regExpr != NULL && !m_regExpr->isValid()) - rc = m_regExpr->errorString(); + rc = m_regExpr->errorString(); return rc; } diff --git a/appl/refind/utils.cpp b/appl/refind/utils.cpp index 9d0ac1d..87ed346 100644 --- a/appl/refind/utils.cpp +++ b/appl/refind/utils.cpp @@ -16,24 +16,24 @@ * 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){ } /** @@ -49,7 +49,7 @@ ContextHandler::IntrinsicType ContextHandler::intrinsicType() const{ * Constructor. */ ContextHandlerList::ContextHandlerList() : - m_list(){ + m_list(){ } /** @@ -65,7 +65,7 @@ ContextHandlerList::~ContextHandlerList(){ * @return the instance itself */ ContextHandlerList::ContextHandlerList(const ContextHandlerList& source) : - m_list(){ + m_list(){ copy(source); } @@ -85,7 +85,7 @@ ContextHandlerList& ContextHandlerList::operator =( */ void ContextHandlerList::addIntrinsics(){ m_list.append( - new ContextHandler(ContextHandler::IT_COPY, QObject::tr("copy"))); + new ContextHandler(ContextHandler::IT_COPY, QObject::tr("copy"))); } /** @@ -94,7 +94,7 @@ void ContextHandlerList::addIntrinsics(){ void ContextHandlerList::clear(){ QList ::const_iterator it; for (it = m_list.begin(); it != m_list.end(); ++it){ - delete *it; + delete *it; } m_list.clear(); } @@ -109,9 +109,9 @@ ContextHandlerList& ContextHandlerList::copy(const ContextHandlerList& source){ clear(); QList ::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; @@ -123,16 +123,16 @@ ContextHandlerList& ContextHandlerList::copy(const ContextHandlerList& source){ * @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); + } } } @@ -141,18 +141,18 @@ ContextHandler* createHandlerIfExists(const QString& file, 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; } @@ -163,53 +163,53 @@ ContextHandler* createHandlerIfExists(const QString& file, * @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 } diff --git a/appl/reidos/FileCommander.cpp b/appl/reidos/FileCommander.cpp index af58f82..77709e3 100644 --- a/appl/reidos/FileCommander.cpp +++ b/appl/reidos/FileCommander.cpp @@ -88,7 +88,7 @@ void FileCommander::buildFs(const QString& url, ReFileSystem& filesystem) 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); } } diff --git a/appl/reidos/idosmain.cpp b/appl/reidos/idosmain.cpp index 4067d3b..b36c481 100644 --- a/appl/reidos/idosmain.cpp +++ b/appl/reidos/idosmain.cpp @@ -69,11 +69,15 @@ void IDosMain::initializeHome(){ /** * Writes a text to the status line. * - * @param error true: the message is an error message + * @param level the type of the message, e.g. LOG_ERROR * @param message the text to set + * @return false: level == LOG_ERROR or LOG_WARNING
+ * true: 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; } /** diff --git a/appl/reidos/idosmain.hpp b/appl/reidos/idosmain.hpp index 37739d4..6fc4ff5 100644 --- a/appl/reidos/idosmain.hpp +++ b/appl/reidos/idosmain.hpp @@ -27,7 +27,7 @@ public: 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(); diff --git a/base/ReFileUtils.cpp b/base/ReFileUtils.cpp index d5e0476..dc49094 100644 --- a/base/ReFileUtils.cpp +++ b/base/ReFileUtils.cpp @@ -121,7 +121,7 @@ bool ReFileUtils::deleteTree(const QString& path, bool withBase, 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; } @@ -269,6 +269,31 @@ QByteArray ReFileUtils::nodeOf(const char* filename) { return rc; } +/** + * Extracts the path of a full filename. + * + * @param filename the filename (with or without path) + * @return "": no path available
+ * "/": filename = "/"
+ * otherwise: the path of filename 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 ".." diff --git a/base/ReFileUtils.hpp b/base/ReFileUtils.hpp index 3b27636..8fa57c4 100644 --- a/base/ReFileUtils.hpp +++ b/base/ReFileUtils.hpp @@ -29,7 +29,7 @@ public: 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); @@ -37,6 +37,7 @@ public: 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); @@ -44,16 +45,16 @@ public: 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; }; diff --git a/base/ReLogger.cpp b/base/ReLogger.cpp index 234bc65..eb18855 100644 --- a/base/ReLogger.cpp +++ b/base/ReLogger.cpp @@ -681,3 +681,4 @@ ReMemoryLogger::ReMemoryLogger() : { addAppender(this); } + diff --git a/base/ReLogger.hpp b/base/ReLogger.hpp index c8b24fe..9c50359 100644 --- a/base/ReLogger.hpp +++ b/base/ReLogger.hpp @@ -16,6 +16,7 @@ */ class ReLogger; class ReConfig; + /** * @brief Logging level: for controlling of the logging. * @@ -30,6 +31,25 @@ enum ReLoggerLevel { 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. say(QString("name: %1 no: %2).arg(name).arg(no) + * @return false: level == LOG_ERROR or LOG_WARNING
+ * true: level >= LOG_INFO + */ + virtual bool say(ReLoggerLevel level, const QString& message) = 0; +}; + class ReAppender { public: ReAppender(const QByteArray& name); diff --git a/base/ReQStringUtils.hpp b/base/ReQStringUtils.hpp index a0eedbb..6f0e1cb 100644 --- a/base/ReQStringUtils.hpp +++ b/base/ReQStringUtils.hpp @@ -20,8 +20,6 @@ public: 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, diff --git a/gui/ReEdit.hpp b/gui/ReEdit.hpp index e10cde4..67cf315 100644 --- a/gui/ReEdit.hpp +++ b/gui/ReEdit.hpp @@ -345,7 +345,8 @@ protected: 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); diff --git a/gui/ReGuiValidator.cpp b/gui/ReGuiValidator.cpp index d09a6e1..608cf83 100644 --- a/gui/ReGuiValidator.cpp +++ b/gui/ReGuiValidator.cpp @@ -125,7 +125,7 @@ QString ReGuiValidator::comboText(QComboBox* combo) { void ReGuiValidator::guiError(QWidget* widget, const QString& message) { if (widget != NULL) widget->setFocus(Qt::OtherFocusReason); - setStatusMessage(true, message); + say(LOG_ERROR, message); m_errors++; } diff --git a/gui/ReGuiValidator.hpp b/gui/ReGuiValidator.hpp index 60465a6..c044b36 100644 --- a/gui/ReGuiValidator.hpp +++ b/gui/ReGuiValidator.hpp @@ -15,19 +15,18 @@ #include #include -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; diff --git a/guiwidget/ReFileTable.cpp b/guiwidget/ReFileTable.cpp index 7b78e3e..c616776 100644 --- a/guiwidget/ReFileTable.cpp +++ b/guiwidget/ReFileTable.cpp @@ -21,7 +21,8 @@ ReFileTable::ReFileTable(QWidget *parent) : 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); @@ -48,10 +49,12 @@ ReFileTable::ReFileTable(QWidget *parent) : 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); } /** @@ -76,16 +79,23 @@ void ReFileTable::fillTable() 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("") : 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); @@ -98,21 +108,78 @@ void ReFileTable::fillTable() } } +/** + * 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 false: level == LOG_ERROR or LOG_WARNING
+ * true: level >= LOG_INFO + */ +bool ReFileTable::say(ReLoggerLevel level, const QString& message) +{ + if (announcer != NULL) + announcer->say(level, message); + return level >= LOG_INFO; +} diff --git a/guiwidget/ReFileTable.hpp b/guiwidget/ReFileTable.hpp index 94e4f64..150749b 100644 --- a/guiwidget/ReFileTable.hpp +++ b/guiwidget/ReFileTable.hpp @@ -12,7 +12,7 @@ // 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 }; @@ -26,12 +26,16 @@ public slots: 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; @@ -41,6 +45,7 @@ public: QTableWidget* tableWidget; ReFileSystem* fileSystem; ReIncludeExcludeMatcher matcher; + ReAnnouncer* announcer; }; #endif // REFILETABLE_HPP diff --git a/guiwidget/reguiwidget.hpp b/guiwidget/reguiwidget.hpp index b5291db..1c927f5 100644 --- a/guiwidget/reguiwidget.hpp +++ b/guiwidget/reguiwidget.hpp @@ -26,6 +26,7 @@ #include "QTableWidget" #include "QHeaderView" #include "QKeyEvent" +#include "QApplication" #include "guiwidget/ReFileTable.hpp" #endif // REGUIWIDGET_HPP diff --git a/os/ReFileSystem.cpp b/os/ReFileSystem.cpp index e601491..bff8b78 100644 --- a/os/ReFileSystem.cpp +++ b/os/ReFileSystem.cpp @@ -279,14 +279,17 @@ ReFileSystem::ErrorCode ReLocalFileSystem::makeDir(const QString& node) { */ 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; } -- 2.39.5