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);
}
/**
*/
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;
}
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++;
}
}
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);
ReFileSystem* m_topFS;
ReFileSystem* m_bottomFS;
ReIncludeExcludeMatcher m_topMatcher;
+ ReIncludeExcludeMatcher m_bottomMatcher;
ReLogger* m_logger;
bool m_topIsActive;
+ QString m_dateFormat;
};
#endif // FILECOMMANDER_HPP
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);
}
/**
void initializeHome();
void restoreState();
void saveState();
-protected:
-signals:
+protected slots:
void keyPress(QKeyEvent* event);
private:
#ifndef REIDOS_HPP
#define REIDOS_HPP
#include "QLabel"
-
+#include "QTableWidget"
+#include "QKeyEvent"
#include "base/rebase.hpp"
#include "os/reos.hpp"
}
}
}
+
+bool ReMatcher::anchored() const
+{
+ return m_anchored;
+}
+
+void ReMatcher::setAnchored(bool anchored)
+{
+ m_anchored = anchored;
+}
/**
* Returns the current pattern.
*
return *m_allMatchingList;
}
+/**
+ * Returns the anchor flag of the pattern matching.
+ *
+ * @return <code>true</code>: 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 <code>true</code>: 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.
*/
}
}
+/**
+ * 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 <code>true<code>: the pattern starts at the strings
+ * start<br>
+ * <code>false<code>: 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.
*
m_excludes.setCaseSensivitiy(caseSensivitiy);
}
+/**
+ * Sets the patterns from a string.
+ *
+ * @param patterns a pattern list, delimited by <code>separator</code>
+ * @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());
+}
+
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;
Qt::CaseSensitivity caseSensivity = Qt::CaseSensitive, bool anchored =
false);
public:
+ bool anchored() const;
static const ReListMatcher& allMatcher();
static const QStringList& allMatchingList();
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);
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:
*/
#include "base/rebase.hpp"
-QStringList ReQStringUtils::m_emptyList;
+const QStringList ReQStringUtils::m_emptyList;
+const QString ReQStringUtils::m_empty;
/** @file
* @brief Missed operation for <code>QString</code>s.
* 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;
}
} else {
throw ReException("ReQStringUtil::lengthOfInt(): wrong radix: %d",
- radix);
+ radix);
}
if (pValue != NULL)
*pValue = value;
* 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)
* 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;
}
}
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);
* 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);
* 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;
* 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;
* <code>false</code>: unknown name found (not replaced)
*/
bool ReQStringUtils::replacePlaceholders(QString& text,
- const QMap<QString, QString>& placeholders, QString* error) {
+ const QMap<QString, QString>& placeholders, QString* error) {
int start = 0;
bool rc = true;
QString name;
* 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) {
* @return <code>buffer</code>
*/
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;
class ReParserException: public ReException {
public:
ReParserException(const QString& message) :
- ReException(),
- m_message(message) {
+ ReException(),
+ m_message(message) {
}
public:
QString m_message;
* 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();
// 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, '+');
}
}
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("-");
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;
}
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();
}
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;
}
* @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.
* @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);
}
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 {
}
}
rc.setMSecsSinceEpoch(
- isValid() ? rc.toMSecsSinceEpoch() + 1000 * relativeSeconds : 0);
+ isValid() ? rc.toMSecsSinceEpoch() + 1000 * relativeSeconds : 0);
m_dateTime = rc;
return rc;
}
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.
#endif
}
static bool replacePlaceholders(QString& text,
- const QMap<QString, QString>& placeholders, QString* error);
+ const QMap<QString, QString>& 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.
*
*/
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;
};
/**
class ReUnitParser {
public:
ReUnitParser(const QString& expr, const char* unitList, bool parseAtOnce =
- true);
+ true);
public:
bool isValid() const;
const QString& errorMessage() const;
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();