From: hama Date: Thu, 29 Oct 2015 23:20:04 +0000 (+0100) Subject: dayly work X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=1ceb6223c5b370a99d0b043e8db042ac61f6bd28;p=reqt dayly work --- diff --git a/appl/reidos/FileCommander.cpp b/appl/reidos/FileCommander.cpp index 9132c6c..af58f82 100644 --- a/appl/reidos/FileCommander.cpp +++ b/appl/reidos/FileCommander.cpp @@ -16,11 +16,14 @@ FileCommander::FileCommander(IDosMain* main) : m_main(main), m_topFS(NULL), m_bottomFS(NULL), - m_activeFS(NULL), - m_inactiveFS(NULL), + m_topMatcher(), + m_bottomMatcher(), m_logger(new ReMemoryLogger()), - m_topIsActive(true) + m_topIsActive(true), + m_dateFormat("yyyy.MM.dd hh:mm:ss") { + m_topFS = new ReLocalFileSystem(QDir::homePath(), m_logger); + m_bottomFS = new ReLocalFileSystem(QDir::homePath(), m_logger); } /** @@ -31,9 +34,10 @@ FileCommander::FileCommander(IDosMain* main) : */ bool FileCommander::changeDirectory(const QString& path){ bool rc = false; - QString current = m_activeFS->directory(); - if (m_activeFS->setDirectory(path) == ReFileSystem::EC_SUCCESS){ - rc = current != m_activeFS->directory(); + ReFileSystem* current = m_topIsActive ? m_topFS : m_bottomFS; + QString currentDir = current->directory(); + if (current->setDirectory(path) == ReFileSystem::EC_SUCCESS){ + rc = currentDir != current->directory(); } return rc; } @@ -49,9 +53,27 @@ void FileCommander::fillTable(QTableWidget* table) ReFileSystem* fs = m_topIsActive ? m_topFS : m_bottomFS; fs->listInfos(m_topIsActive ? m_topMatcher : m_bottomMatcher, list); ReFileMetaDataList::const_iterator it; - table->setCount(list.length()); - for (it = list.cbegin(); it != list.cend(); ++list){ - table-> + table->setRowCount(list.length()); + int row = 0; + for (it = list.cbegin(); it != list.cend(); ++it){ + // TC_EXT, TC_SIZE, TC_MODIFIED, TC_NODE + QString modified = it->m_modified.toString(m_dateFormat); + QString size = QString::number(it->m_size); + QString ext = ReFileUtils::extensionOf(it->m_node); + if (table->item(row, 0) == NULL){ + table->setItem(row, TC_NODE, new QTableWidgetItem(it->m_node)); + table->setItem(row, TC_MODIFIED, new QTableWidgetItem(modified)); + table->setItem(row, TC_EXT, new QTableWidgetItem(ext)); + QTableWidgetItem* item = new QTableWidgetItem(size); + item->setTextAlignment(Qt::AlignRight); + table->setItem(row, TC_SIZE, item); + } else { + table->item(row, TC_NODE)->setText(it->m_node); + table->item(row, TC_MODIFIED)->setText(modified); + table->item(row, TC_EXT)->setText(ext); + table->item(row, TC_SIZE)->setText(size); + } + row++; } } diff --git a/appl/reidos/FileCommander.hpp b/appl/reidos/FileCommander.hpp index 87c949e..92af7dc 100644 --- a/appl/reidos/FileCommander.hpp +++ b/appl/reidos/FileCommander.hpp @@ -14,8 +14,9 @@ class IDosMain; class FileCommander { +public: enum TableColumns { - TC_EXT, TC_SIZE, TC_MODIFIED, TC_NODE, + TC_MODIFIED, TC_SIZE, TC_EXT, TC_NODE, }; public: FileCommander(IDosMain* m_main); @@ -28,8 +29,10 @@ protected: ReFileSystem* m_topFS; ReFileSystem* m_bottomFS; ReIncludeExcludeMatcher m_topMatcher; + ReIncludeExcludeMatcher m_bottomMatcher; ReLogger* m_logger; bool m_topIsActive; + QString m_dateFormat; }; #endif // FILECOMMANDER_HPP diff --git a/appl/reidos/idosmain.cpp b/appl/reidos/idosmain.cpp index a487c71..e2e64f4 100644 --- a/appl/reidos/idosmain.cpp +++ b/appl/reidos/idosmain.cpp @@ -32,6 +32,13 @@ IDosMain::IDosMain(const QString& startDir, const QString& homeDir, ui->tableWidgetBottom->setColumnWidth(TC_EXT, 40); ui->tableWidgetBottom->setColumnWidth(TC_SIZE, 125); ui->tableWidgetBottom->setColumnWidth(TC_MODIFIED, 175); + QString dir(ui->comboBoxPathTop->currentText()); + if (dir.isEmpty()) + dir = startDir; + if (dir.isEmpty()) + dir = QDir::homePath(); + changeDirectory(dir); + fillTable(ui->tableWidgetTop); } /** diff --git a/appl/reidos/idosmain.hpp b/appl/reidos/idosmain.hpp index feb3426..adc14c0 100644 --- a/appl/reidos/idosmain.hpp +++ b/appl/reidos/idosmain.hpp @@ -32,8 +32,7 @@ protected: void initializeHome(); void restoreState(); void saveState(); -protected: -signals: +protected slots: void keyPress(QKeyEvent* event); private: diff --git a/appl/reidos/reidos.hpp b/appl/reidos/reidos.hpp index 5b03e48..89cdf3b 100644 --- a/appl/reidos/reidos.hpp +++ b/appl/reidos/reidos.hpp @@ -10,7 +10,8 @@ #ifndef REIDOS_HPP #define REIDOS_HPP #include "QLabel" - +#include "QTableWidget" +#include "QKeyEvent" #include "base/rebase.hpp" #include "os/reos.hpp" diff --git a/base/ReMatcher.cpp b/base/ReMatcher.cpp index 7d46812..7506aa4 100644 --- a/base/ReMatcher.cpp +++ b/base/ReMatcher.cpp @@ -112,6 +112,16 @@ void ReMatcher::setPattern(const QString& pattern, bool anchored) { } } } + +bool ReMatcher::anchored() const +{ + return m_anchored; +} + +void ReMatcher::setAnchored(bool anchored) +{ + m_anchored = anchored; +} /** * Returns the current pattern. * @@ -195,14 +205,25 @@ const QStringList& ReListMatcher::allMatchingList() { return *m_allMatchingList; } +/** + * Returns the anchor flag of the pattern matching. + * + * @return true: the character case is relevant + */ +bool ReListMatcher::anchored() const { + return m_list.length() <= 0 ? true : m_list.at(0)->anchored(); +} + /** * Returns the case sensitivity of the pattern matching. * * @return true: the character case is relevant */ Qt::CaseSensitivity ReListMatcher::caseSensivitiy() const { - return m_list.at(0)->caseSensivitiy(); + return m_list.length() <= 0 ? Qt::CaseSensitive + : m_list.at(0)->caseSensivitiy(); } + /** * Frees the resources. */ @@ -297,6 +318,25 @@ void ReListMatcher::setPatterns(const QStringList& patterns, } } +/** + * Constructor. + * + * @param patterns a comma delimited pattern list, exclude patterns + * marked with the prefix '-'. Example: "*.c,*.h,-test*' + * @param caseSensitivity caseSensitive or caseInsensitive + * @param anchored true: the pattern starts at the strings + * start
+ * false: the pattern can start anywhere in + * the string + */ +ReIncludeExcludeMatcher::ReIncludeExcludeMatcher(const QString& patterns, + Qt::CaseSensitivity caseSensivity, bool anchored) : + m_includes(ReQStringUtils::m_emptyList, caseSensivity, anchored), + m_excludes(ReQStringUtils::m_emptyList, caseSensivity, anchored) +{ + setPatterns(patterns); +} + /** * Constructor. * @@ -383,3 +423,35 @@ void ReIncludeExcludeMatcher::setCaseSensivitiy( m_excludes.setCaseSensivitiy(caseSensivitiy); } +/** + * Sets the patterns from a string. + * + * @param patterns a pattern list, delimited by separator + * @param separator separates the patterns + * @param excludeMarker if a pattern starts with this character, the pattern + * is a excluding pattern + */ +void ReIncludeExcludeMatcher::setPatterns(const QString& patterns, + QChar separator, QChar excludeMarker){ + QStringList includes; + QStringList excludes; + int start = 0; + int ix; + while( (ix = patterns.indexOf(separator, start)) >= 0){ + int length = ix - start; + if (length > 0){ + if (patterns.at(start) == excludeMarker){ + if (length > 1) + excludes.append(patterns.mid(start, length - 1)); + } else { + includes.append(patterns.mid(start, length)); + } + } + start = ix + 1; + } + m_includes.setPatterns(includes, m_includes.caseSensivitiy(), + m_includes.anchored()); + m_excludes.setPatterns(excludes, m_excludes.caseSensivitiy(), + m_excludes.anchored()); +} + diff --git a/base/ReMatcher.hpp b/base/ReMatcher.hpp index c26e87f..4c73658 100644 --- a/base/ReMatcher.hpp +++ b/base/ReMatcher.hpp @@ -23,12 +23,13 @@ public: Qt::CaseSensitive, bool anchored = false); public: bool allMatching() const; + bool anchored() const; Qt::CaseSensitivity caseSensivitiy() const; bool matches(const QString& text); const QString& pattern() const; + void setAnchored(bool anchored); void setCaseSensivitiy(const Qt::CaseSensitivity& caseSensivitiy); void setPattern(const QString& pattern, bool anchored = false); - protected: QString m_pattern; QStringList m_needles; @@ -59,6 +60,7 @@ public: Qt::CaseSensitivity caseSensivity = Qt::CaseSensitive, bool anchored = false); public: + bool anchored() const; static const ReListMatcher& allMatcher(); static const QStringList& allMatchingList(); protected: @@ -79,6 +81,9 @@ protected: */ class ReIncludeExcludeMatcher { public: + ReIncludeExcludeMatcher(const QString& pattern = ReQStringUtils::m_empty, + Qt::CaseSensitivity caseSensitivty = Qt::CaseSensitive, + bool anchored = false); ReIncludeExcludeMatcher(const QStringList& includes, const QStringList& excludes, Qt::CaseSensitivity caseSensitivty = Qt::CaseSensitive, bool anchored = false); @@ -88,6 +93,8 @@ public: const ReListMatcher& includes() const; const ReListMatcher& excludes() const; void setCaseSensivitiy(const Qt::CaseSensitivity& caseSensivitiy); + void setPatterns(const QString& patterns, QChar separator = ',', + QChar excludeMarker = '-'); public: static const ReIncludeExcludeMatcher& allMatcher(); private: diff --git a/base/ReQStringUtils.cpp b/base/ReQStringUtils.cpp index 9d816f5..d3b1ae0 100644 --- a/base/ReQStringUtils.cpp +++ b/base/ReQStringUtils.cpp @@ -10,7 +10,8 @@ */ #include "base/rebase.hpp" -QStringList ReQStringUtils::m_emptyList; +const QStringList ReQStringUtils::m_emptyList; +const QString ReQStringUtils::m_empty; /** @file * @brief Missed operation for QStrings. @@ -78,7 +79,7 @@ QString& ReQStringUtils::ensureLastChar(QString& value, QChar lastChar) { * otherwise: the length of the integer */ int ReQStringUtils::lengthOfUInt64(const ReString& text, int start, int radix, - quint64* pValue) { + quint64* pValue) { int inputLength = text.size(); int64_t value = 0; int ix = start; @@ -113,7 +114,7 @@ int ReQStringUtils::lengthOfUInt64(const ReString& text, int start, int radix, } } else { throw ReException("ReQStringUtil::lengthOfInt(): wrong radix: %d", - radix); + radix); } if (pValue != NULL) *pValue = value; @@ -131,7 +132,7 @@ int ReQStringUtils::lengthOfUInt64(const ReString& text, int start, int radix, * otherwise: the length of the integer */ int ReQStringUtils::lengthOfUInt(const ReString& text, int start, int radix, - uint* pValue) { + uint* pValue) { quint64 value; int rc = lengthOfUInt64(text, start, radix, &value); if (pValue != NULL) @@ -152,7 +153,7 @@ int ReQStringUtils::lengthOfUInt(const ReString& text, int start, int radix, * otherwise: the length of the date in the string */ int ReQStringUtils::lengthOfDate(const ReString& text, int start, - QDate* value) { + QDate* value) { uint day = 0; uint month = 0; uint year = 0; @@ -200,7 +201,7 @@ int ReQStringUtils::lengthOfDate(const ReString& text, int start, } } if (day < 1 || day > 31 || month < 1 || month > 12 || year < 1970 - || year > 2100) + || year > 2100) length = 0; if (length != 0 && value != NULL) *value = QDate(year, month, day); @@ -222,7 +223,7 @@ int ReQStringUtils::lengthOfDate(const ReString& text, int start, * otherwise: the length of the date in the string */ int ReQStringUtils::lengthOfDateTime(const ReString& text, int start, - bool allowDateOnly, bool allowTimeOnly, QDateTime* value) { + bool allowDateOnly, bool allowTimeOnly, QDateTime* value) { QDate date; QTime time; int length = lengthOfDate(text, start, &date); @@ -264,7 +265,7 @@ int ReQStringUtils::lengthOfDateTime(const ReString& text, int start, * otherwise: the length of the date in the string */ int ReQStringUtils::lengthOfTime(const ReString& text, int start, - QTime* value) { + QTime* value) { uint hour = 0; uint minute = 0; uint sec = 0; @@ -308,7 +309,7 @@ int ReQStringUtils::lengthOfTime(const ReString& text, int start, * otherwise: the length of the floating point number */ int ReQStringUtils::lengthOfReal(const ReString& text, int start, - qreal* pValue) { + qreal* pValue) { int inputLength = text.size(); qreal value = 0.0; int cc; @@ -379,7 +380,7 @@ int ReQStringUtils::lengthOfReal(const ReString& text, int start, * false: unknown name found (not replaced) */ bool ReQStringUtils::replacePlaceholders(QString& text, - const QMap& placeholders, QString* error) { + const QMap& placeholders, QString* error) { int start = 0; bool rc = true; QString name; @@ -418,7 +419,7 @@ bool ReQStringUtils::replacePlaceholders(QString& text, * otherwise: the length is incremented */ void ReQStringUtils::skipExpected(const ReString& text, QChar expected, - int& index, int& length) { + int& index, int& length) { if (length == 0) { // error state, do nothing } else if (index >= text.length() || text[index] != expected) { @@ -441,7 +442,7 @@ void ReQStringUtils::skipExpected(const ReString& text, QChar expected, * @return buffer */ char*ReQStringUtils::utf8(const ReString& source, char buffer[], - size_t bufferSize) { + size_t bufferSize) { QByteArray val = source.toUtf8(); if (val.length() < (int) bufferSize) bufferSize = val.length() + 1; @@ -453,8 +454,8 @@ char*ReQStringUtils::utf8(const ReString& source, char buffer[], class ReParserException: public ReException { public: ReParserException(const QString& message) : - ReException(), - m_message(message) { + ReException(), + m_message(message) { } public: QString m_message; @@ -467,11 +468,11 @@ public: * example: "kibyte:1024;kbyte:1000;mibyte:1048576;mbyte:1000000" */ ReUnitParser::ReUnitParser(const QString& expr, const char* unitList, - bool parseAtOnce) : - m_result(0), - m_expr(expr), - m_message(), - m_unitList(unitList) { + bool parseAtOnce) : + m_result(0), + m_expr(expr), + m_message(), + m_unitList(unitList) { normalize(); if (parseAtOnce) parse(); @@ -540,7 +541,7 @@ void ReUnitParser::normalize() { // This makes the syntax easier to parse: only one sum operator ('+'). for (int ii = m_expr.length() - 1; ii > 0; ii--) { if (m_expr[ii] == '-' && m_expr[ii - 1] != '+' - && m_expr[ii - 1] != '*') { + && m_expr[ii - 1] != '*') { m_expr.insert(ii, '+'); } } @@ -562,8 +563,8 @@ void ReUnitParser::parse() { QStringList powerOperands = it2->split("^"); if (powerOperands.count() > 2) throw ReParserException( - QObject::tr( - "more than 2 power operators, e.g. '2^3^4'")); + QObject::tr( + "more than 2 power operators, e.g. '2^3^4'")); QStringList::const_iterator it3 = powerOperands.begin(); QString op = *it3; bool isNeg = op.startsWith("-"); @@ -575,8 +576,8 @@ void ReUnitParser::parse() { uint64_t exponent = valueOf(*++it3); if (qLn(value) * qLn(exponent) >= qLn(qPow(2.0, 64))) throw ReParserException( - QObject::tr( - "number overflow while power operation")); + QObject::tr( + "number overflow while power operation")); for (int ii = 1; ii < (int) exponent; ii++) value = value * fac; } @@ -615,12 +616,12 @@ uint64_t ReUnitParser::valueOf(const QString& value) const { QStringList pair = it->split(":"); if (pair.count() == 0) throw ReParserException( - QObject::tr( - "missing ':' in unit definition, e.g. 'k:1000': ") - + *it); + QObject::tr( + "missing ':' in unit definition, e.g. 'k:1000': ") + + *it); if (pair.count() > 2) throw ReParserException( - QObject::tr("too many ':' in unit definition: ") + *it); + QObject::tr("too many ':' in unit definition: ") + *it); bool ok = false; QString unit2 = *pair.begin(); QString factor = *++pair.begin(); @@ -635,8 +636,8 @@ uint64_t ReUnitParser::valueOf(const QString& value) const { } if (!found) throw ReParserException( - QObject::tr("unknown unit '$1'. Allowed: ").arg(unit) - + QString(m_unitList)); + QObject::tr("unknown unit '$1'. Allowed: ").arg(unit) + + QString(m_unitList)); } return rc; } @@ -647,10 +648,10 @@ uint64_t ReUnitParser::valueOf(const QString& value) const { * @param expr an expression, e.g. "10*1024kByte+5MiByte" */ ReSizeParser::ReSizeParser(const QString& expr) : - ReUnitParser(expr, "byte:1;kbyte:1000;kibyte:1024;" - "mbyte:1000000;mibyte:1048576;" - "gbyte:1000000000;gibyte:1073741824;" - "tbyte:1000000000000;tibyte:1099511627776") { + ReUnitParser(expr, "byte:1;kbyte:1000;kibyte:1024;" + "mbyte:1000000;mibyte:1048576;" + "gbyte:1000000000;gibyte:1073741824;" + "tbyte:1000000000000;tibyte:1099511627776") { } /** * Constructor. @@ -658,7 +659,7 @@ ReSizeParser::ReSizeParser(const QString& expr) : * @param expr an expression, e.g. "3*3days-5min+3weeks" */ ReDateTimeParser::ReDateTimeParser(const QString& expr) : - ReUnitParser("", "minutes:60;hours:3600;days:86400;weeks:604800", false) { + ReUnitParser("", "minutes:60;hours:3600;days:86400;weeks:604800", false) { parseDateTime(expr); } @@ -694,7 +695,7 @@ QDateTime ReDateTimeParser::parseDateTime(const QString& expr) { if (m_expr.startsWith("now", Qt::CaseInsensitive)) { m_expr.remove(0, 3); } else if ((length2 = ReQStringUtils::lengthOfDateTime(m_expr, 0, true, - true, &dateTime)) > 0) { + true, &dateTime)) > 0) { rc = dateTime; m_expr.remove(0, length2); } else { @@ -714,7 +715,7 @@ QDateTime ReDateTimeParser::parseDateTime(const QString& expr) { } } rc.setMSecsSinceEpoch( - isValid() ? rc.toMSecsSinceEpoch() + 1000 * relativeSeconds : 0); + isValid() ? rc.toMSecsSinceEpoch() + 1000 * relativeSeconds : 0); m_dateTime = rc; return rc; } diff --git a/base/ReQStringUtils.hpp b/base/ReQStringUtils.hpp index b883cb3..a0eedbb 100644 --- a/base/ReQStringUtils.hpp +++ b/base/ReQStringUtils.hpp @@ -23,18 +23,18 @@ public: static QString extensionOf(const QString& filename); static QByteArray extensionOf(const char* filename); static int lengthOfDate(const ReString& text, int start = 0, QDate* value = - NULL); + NULL); static int lengthOfDateTime(const ReString& text, int start = 0, - bool allowDateOnly = true, bool allowTimeOnly = true, QDateTime* value = - NULL); + bool allowDateOnly = true, bool allowTimeOnly = true, QDateTime* value = + NULL); static int lengthOfReal(const ReString& text, int start = 0, qreal* value = - NULL); + NULL); static int lengthOfTime(const ReString& text, int start = 0, QTime* value = - NULL); + NULL); static int lengthOfUInt64(const ReString& text, int start = 0, int radix = - 10, uint64_t* value = NULL); + 10, uint64_t* value = NULL); static int lengthOfUInt(const ReString& text, int start, int radix, - uint* pValue); + uint* pValue); static bool match(const QString& heap, const QStringList& needles); /** * Returns the path with native path separators. @@ -50,9 +50,9 @@ public: #endif } static bool replacePlaceholders(QString& text, - const QMap& placeholders, QString* error); + const QMap& placeholders, QString* error); static void skipExpected(const ReString& text, QChar expected, int& index, - int& length); + int& length); /** * @brief Returns the value of a hexadecimal digit. * @@ -62,12 +62,13 @@ public: */ inline static int valueOfHexDigit(int digit) { return digit >= '0' && digit <= '9' ? digit - '0' : - digit >= 'A' && digit <= 'F' ? digit - 'A' + 10 : - digit >= 'a' && digit <= 'f' ? digit - 'a' + 10 : -1; + digit >= 'A' && digit <= 'F' ? digit - 'A' + 10 : + digit >= 'a' && digit <= 'f' ? digit - 'a' + 10 : -1; } static char* utf8(const ReString& source, char buffer[], size_t bufferSize); public: - static QStringList m_emptyList; + static const QStringList m_emptyList; + static const QString m_empty; }; /** @@ -81,7 +82,7 @@ public: class ReUnitParser { public: ReUnitParser(const QString& expr, const char* unitList, bool parseAtOnce = - true); + true); public: bool isValid() const; const QString& errorMessage() const; diff --git a/os/ReFileSystem.cpp b/os/ReFileSystem.cpp index 9edc0b2..e601491 100644 --- a/os/ReFileSystem.cpp +++ b/os/ReFileSystem.cpp @@ -231,13 +231,15 @@ int ReLocalFileSystem::listInfos(const ReIncludeExcludeMatcher& matcher, struct stat info; for (it = nodes.cbegin(); it != nodes.cend(); it++) { QString node = *it; - full.resize(pathLength); - full.append(node.toUtf8()); - if (stat(full.constData(), &info) == 0) { - list.append( - ReFileMetaData(node, QDateTime::fromTime_t(info.st_mtime), - QDateTime::fromTime_t(info.st_ctime), info.st_uid, - info.st_gid, info.st_mode, info.st_size)); + if (node != "." && node != ".."){ + full.resize(pathLength); + full.append(node.toUtf8()); + if (stat(full.constData(), &info) == 0) { + list.append( + ReFileMetaData(node, QDateTime::fromTime_t(info.st_mtime), + QDateTime::fromTime_t(info.st_ctime), info.st_uid, + info.st_gid, info.st_mode, info.st_size)); + } } } return list.size();