From: hama Date: Sat, 11 Apr 2015 00:31:48 +0000 (+0200) Subject: refind: design, filter conditions X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=50f7aa686318a674bae991bacf94df1812d24f79;p=reqt refind: design, filter conditions --- diff --git a/appl/refind/filefinder.cpp b/appl/refind/filefinder.cpp index eb3e733..91b609e 100644 --- a/appl/refind/filefinder.cpp +++ b/appl/refind/filefinder.cpp @@ -20,26 +20,57 @@ FileFinder::FileFinder() : m_minDepth(0), m_maxDepth(512), m_baseDir(""), - m_checkDates(false){ + m_checkDates(false), + m_countDirs(0), + m_countFiles(0), + m_bytes(0){ m_youngerThan.setMSecsSinceEpoch(0); m_olderThan.setMSecsSinceEpoch(0); } /** - * Resets the data. + * Returns the sum of sizes of the found files. + * @return the sum of the sizes + */ +int64_t FileFinder::bytes() const{ + return m_bytes; +} + +/** + * Resets the data. */ void FileFinder::clear(){ - m_lines = 0; - m_patterns.clear(); - m_minSize = 0; - m_maxSize = -1; - m_youngerThan.setMSecsSinceEpoch(0); - m_olderThan.setMSecsSinceEpoch(0); - m_fileTypes = 0; - m_minDepth = 0; - m_maxDepth = 512; - // m_baseDir; - m_checkDates = false; + m_lines = 0; + m_patterns.clear(); + m_minSize = 0; + m_maxSize = -1; + m_youngerThan.setMSecsSinceEpoch(0); + m_olderThan.setMSecsSinceEpoch(0); + m_fileTypes = 0; + m_minDepth = 0; + m_maxDepth = 512; + // m_baseDir; + m_checkDates = false; + m_countDirs = m_countFiles = 0; + m_bytes = 0; +} + +/** + * Returns the number of the found directories. + * + * @return the number of directories in the result table + */ +int FileFinder::countDirs() const{ + return m_countDirs; +} + +/** + * Returns the number of the found files. + * + * @return the number of files in the result table + */ +int FileFinder::countFiles() const{ + return m_countFiles; } /** @@ -50,7 +81,22 @@ void FileFinder::clear(){ */ QString fileSize(int64_t size){ QString rc; - rc.sprintf("%.6f MB", (double) size / 1000000.0); + rc.sprintf("%.6f", (double) size / 1000000.0); + return rc; +} +/** + * Returns the type of the file. + * @param info the file info + * @return a string describing the text + */ +QString typeOf(QFileInfo& info){ + QString rc; + if (info.isDir()) + rc = QObject::tr("dir"); + else if (info.isSymLink()) + rc = QObject::tr("link"); + else + rc = QObject::tr("file"); return rc; } @@ -65,32 +111,50 @@ void FileFinder::fillTable(const QString& path, int depth, QTableWidget* table){ QDir dir(path); QFileInfoList entries; if (m_patterns.count() == 0) - entries = dir.entryInfoList(m_fileTypes, QDir::NoSort); + entries = dir.entryInfoList(m_fileTypes | QDir::NoDotAndDotDot, + QDir::NoSort); else entries = dir.entryInfoList(m_patterns, m_fileTypes, QDir::NoSort); QList ::iterator it; QString relativePath = path.mid(1 + m_baseDir.length()); + QString node, ext; for (it = entries.begin(); it != entries.end(); ++it){ + node = it->fileName(); + if (node == "." || node == "..") + continue; if (depth >= m_minDepth && isValid(*it)){ if (m_lines >= table->rowCount()){ table->setRowCount(m_lines + 500); } - table->setItem(m_lines, TC_NODE, new QTableWidgetItem(it->fileName())); + bool isDir = it->isDir(); + if (isDir) + m_countDirs++; + else + m_countFiles++; + 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(it->isDir() ? "dir" : fileSize(it->size())); + QTableWidgetItem* item = new QTableWidgetItem( + isDir ? "" : fileSize(it->size())); + if (!isDir) + m_bytes += it->size(); item->setTextAlignment(Qt::AlignRight); - table->setItem(m_lines, TC_SIZE,item); + table->setItem(m_lines, TC_SIZE, item); table->setItem(m_lines, TC_MODIFIED, new QTableWidgetItem( - it->lastModified().toString("yyyy.MM.dd hh:mm:ss"))); + it->lastModified().toString("yyyy.MM.dd/hh:mm:ss"))); m_lines++; } } - if (depth <= m_maxDepth){ + if (depth < m_maxDepth){ entries = dir.entryInfoList( QDir::NoSymLinks | QDir::NoDotAndDotDot | QDir::AllDirs, QDir::NoSort); for (it = entries.begin(); it != entries.end(); ++it){ - fillTable(path + QDir::separator() + it->fileName(), depth + 1, table); + QString node = it->fileName(); + fillTable(path + QDir::separator() + node, depth + 1, table); } } table->setRowCount(m_lines); @@ -106,10 +170,11 @@ bool FileFinder::isValid(const QFileInfo& file){ int64_t size = file.size(); bool rc = size >= m_minSize && (m_maxSize < 0 || size <= m_maxSize); bool checkYounger; - if (rc && ((checkYounger = m_youngerThan.toMSecsSinceEpoch() > 0) - || m_olderThan.toMSecsSinceEpoch() > 0)){ + if (rc + && ((checkYounger = m_youngerThan.toMSecsSinceEpoch() > 0) + || m_olderThan.toMSecsSinceEpoch() > 0)){ QDateTime date = file.lastModified(); - rc = ! checkYounger || date >= m_youngerThan; + rc = !checkYounger || date >= m_youngerThan; if (rc) rc = m_olderThan.toMSecsSinceEpoch() == 0 || date <= m_olderThan; } @@ -179,7 +244,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; } /** @@ -199,6 +264,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/filefinder.hpp b/appl/refind/filefinder.hpp index 6421c12..20a558e 100644 --- a/appl/refind/filefinder.hpp +++ b/appl/refind/filefinder.hpp @@ -17,8 +17,11 @@ class FileFinder { public: FileFinder(); public: - void fillTable(const QString& path, int depth, QTableWidget* table); + int64_t bytes() const; void clear(); + int countFiles() const; + int countDirs() const; + void fillTable(const QString& path, int depth, QTableWidget* table); void setBaseDir(const QString& baseDir); void setFiletypes(const QDir::Filters& filetypes); void setMaxDepth(int maxDepth); @@ -28,7 +31,6 @@ public: void setMaxSize(const int64_t& maxSize); void setMinSize(const int64_t& minSize); void setYoungerThan(const QDateTime& youngerThan); - private: bool isValid(const QFileInfo& file); private: @@ -43,6 +45,9 @@ private: int m_maxDepth; QString m_baseDir; bool m_checkDates; + int m_countFiles; + int m_countDirs; + int64_t m_bytes; }; #endif // FILEFINDER_HPP diff --git a/appl/refind/main.cpp b/appl/refind/main.cpp index 5117378..1feb89c 100644 --- a/appl/refind/main.cpp +++ b/appl/refind/main.cpp @@ -9,15 +9,13 @@ * The latest sources: https://github.com/republib */ - #include "mainwindow.hpp" #include -int main(int argc, char *argv[]) -{ - QApplication a(argc, argv); - MainWindow w; - w.show(); +int main(int argc, char *argv[]){ + QApplication a(argc, argv); + MainWindow w; + w.show(); - return a.exec(); + return a.exec(); } diff --git a/appl/refind/mainwindow.cpp b/appl/refind/mainwindow.cpp index 12f4d3c..d6ebe3c 100644 --- a/appl/refind/mainwindow.cpp +++ b/appl/refind/mainwindow.cpp @@ -9,7 +9,6 @@ * The latest sources: https://github.com/republib */ - #include #include "base/rebase.hpp" #include "mainwindow.hpp" @@ -22,30 +21,31 @@ * @param parent NULL or the parent widget */ MainWindow::MainWindow(QWidget *parent) : - QMainWindow(parent), - ui(new Ui::MainWindow), - m_statusMessage(NULL), - m_stdLabelBackgroundRole(NULL), - m_errors(0) -{ - ui->setupUi(this); - m_statusMessage = new QLabel(tr("Willkommen bei refind")); - ui->comboBoxDirectory->setCurrentText(QDir::currentPath()); - statusBar()->addWidget(m_statusMessage); - connect(ui->pushButtonSearch, SIGNAL(clicked()), this, SLOT(search())); - connect(ui->pushButtonUp, SIGNAL(clicked()), this, SLOT(up())); - ui->tableWidget->setColumnWidth(TC_NODE, 200); - ui->tableWidget->setColumnWidth(TC_SIZE, 125); - ui->tableWidget->setColumnWidth(TC_MODIFIED, 175); - ui->tableWidget->horizontalHeader()->setStretchLastSection(true); + QMainWindow(parent), + ui(new Ui::MainWindow), + m_statusMessage(NULL), + m_stdLabelBackgroundRole(NULL), + m_errors(0){ + ui->setupUi(this); + m_statusMessage = new QLabel(tr("Willkommen bei refind")); + ui->comboBoxDirectory->setCurrentText(QDir::currentPath()); + statusBar()->addWidget(m_statusMessage); + connect(ui->pushButtonSearch, SIGNAL(clicked()), this, SLOT(search())); + connect(ui->pushButtonSearch2, SIGNAL(clicked()), this, SLOT(search())); + connect(ui->pushButtonUp, SIGNAL(clicked()), this, SLOT(up())); + ui->tableWidget->setColumnWidth(TC_NODE, 200); + ui->tableWidget->setColumnWidth(TC_EXT, 40); + ui->tableWidget->setColumnWidth(TC_SIZE, 125); + ui->tableWidget->setColumnWidth(TC_MODIFIED, 175); + ui->tableWidget->setColumnWidth(TC_TYPE, 50); + ui->tableWidget->horizontalHeader()->setStretchLastSection(true); } /** * @brief Destructor. */ -MainWindow::~MainWindow() -{ - delete ui; +MainWindow::~MainWindow(){ + delete ui; } /** * Returns the date given as formula in a combobox. @@ -55,23 +55,46 @@ MainWindow::~MainWindow() * @return the date resulting from the formula or begin of the epoch (error case) */ QDateTime MainWindow::comboDate(QComboBox* combo){ - QDateTime rc; - QString value = combo->currentText(); - if (value.isEmpty()) - rc.setMSecsSinceEpoch(0); - else { - ReDateTimeParser parser(value); - if (parser.isValid()){ - rc.setMSecsSinceEpoch(QDateTime().addSecs(-parser.asInt64()).currentMSecsSinceEpoch()); - setInHistory(combo, value); - combo->setCurrentText(rc.toString("yyyy.MM.dd hh:mm")); - } else{ - guiError(combo, parser.errorMessage()); - rc.setMSecsSinceEpoch(0); - } - } - return rc; + QDateTime rc; + QString value = combo->currentText(); + if (value.isEmpty()) + rc.setMSecsSinceEpoch(0); + else{ + ReDateTimeParser parser(value); + if (parser.isValid()){ + rc = parser.asDateTime(); + setInHistory(combo, value); + combo->setCurrentText(rc.toString("yyyy.MM.dd/hh:mm")); + }else{ + guiError(combo, parser.errorMessage()); + rc.setMSecsSinceEpoch(0); + } + } + return rc; +} +/** + * Returns an integer given in a combobox. + * + * @param combo the combobox with the integer + * @param defaultValue the value if the combobox is empty or invalid + * @return defaultValue: empty or invalid input
+ * otherwise: or the size resulting from the formula + */ +int MainWindow::comboInt(QComboBox* combo, int defaultValue){ + QString value = combo->currentText(); + int rc = defaultValue; + if (!value.isEmpty()){ + uint nValue = 0; + if (ReQStringUtil::lengthOfUInt(value, 0, 10, &nValue) == 0) + guiError(combo, QObject::tr("not an integer: ") + value); + else{ + setInHistory(combo, value); + rc = (int) nValue; + } + } + return rc; } + /** * Returns the size (in bytes) given as formula in a combobox. * @@ -81,17 +104,18 @@ QDateTime MainWindow::comboDate(QComboBox* combo){ * otherwise: or the size resulting from the formula */ int64_t MainWindow::comboSize(QComboBox* combo){ - QString value = combo->currentText(); - int64_t rc = -1; - if (! value.isEmpty()){ - ReSizeParser parser(value); - int64_t rc = parser.asInt64(-1); - if (rc >= 0) - setInHistory(combo, value); - else - guiError(combo, parser.errorMessage()); - } - return rc; + QString value = combo->currentText(); + int64_t rc = -1; + if (!value.isEmpty()){ + ReSizeParser parser(value); + rc = parser.asInt64(-1); + if (rc >= 0){ + setInHistory(combo, value); + combo->setCurrentText(QString("").sprintf("%lld", rc)); + }else + guiError(combo, parser.errorMessage()); + } + return rc; } /** @@ -101,38 +125,48 @@ int64_t MainWindow::comboSize(QComboBox* combo){ * @param message the error message */ void MainWindow::guiError(QWidget* widget, const QString& message){ - widget->setFocus(Qt::OtherFocusReason); - setStatusMessage(true, message); - m_errors++; + widget->setFocus(Qt::OtherFocusReason); + setStatusMessage(true, message); + m_errors++; } QString MainWindow::comboText(QComboBox* combo){ - QString rc = combo->currentText(); - setInHistory(combo, rc); - return rc; + QString rc = combo->currentText(); + setInHistory(combo, rc); + return rc; } - /** * Handles the "search" button. */ void MainWindow::search(){ - m_errors = 0; - QString path = ui->comboBoxDirectory->currentText(); - FileFinder finder; - finder.setBaseDir(path); - finder.setMaxSize(comboSize(ui->comboBoxMaxSize)); - finder.setMinSize(comboSize(ui->comboBoxMinSize)); - finder.setOlderThan(comboDate(ui->comboBoxOlder)); - finder.setYoungerThan(comboDate(ui->comboBoxYounger)); - QStringList patterns; - QString value = ui->comboBoxFilePatterns->currentText(); - if (! value.isEmpty()) - patterns = value.split(";"); - finder.setPatterns(patterns); - if (m_errors == 0) - finder.fillTable(path, 0, ui->tableWidget); - } + m_errors = 0; + QString path = ui->comboBoxDirectory->currentText(); + FileFinder finder; + finder.setBaseDir(path); + finder.setMaxSize(comboSize(ui->comboBoxMaxSize)); + finder.setMinSize(comboSize(ui->comboBoxMinSize)); + finder.setOlderThan(comboDate(ui->comboBoxOlder)); + finder.setYoungerThan(comboDate(ui->comboBoxYounger)); + finder.setMinDepth(comboInt(ui->comboBoxMinDepth, 0)); + finder.setMaxDepth(comboInt(ui->comboBoxMaxDepth, -1)); + QStringList patterns; + QString value = ui->comboBoxFilePatterns->currentText(); + if (!value.isEmpty()) + patterns = value.split(";"); + finder.setPatterns(patterns); + if (m_errors == 0){ + clock_t start = clock(); + finder.fillTable(path, 0, ui->tableWidget); + QString msg; + msg.sprintf( + QObject::tr( + "Found: %d dir(s) and %d file(s) with %.6f MByte. Duration of the search: %.3f sec").toUtf8(), + finder.countDirs(), finder.countFiles(), finder.bytes() / 1000000.0, + (double) (clock() - start) / CLOCKS_PER_SEC); + setStatusMessage(false, msg); + } +} /** * @brief Sets a text in a combobox uses as history. @@ -144,22 +178,22 @@ void MainWindow::search(){ * @param value the text to set */ void MainWindow::setInHistory(QComboBox* combo, const QString& value){ - if (value.isEmpty()){ - // nothing to do - } else if (combo->count() == 0) - combo->addItem(value); - else { - if (value != combo->itemText(0)){ - combo->insertItem(0, value); - } - for (int ii = 1; ii < combo->count(); ii++){ - if (value == combo->itemText(ii)){ - combo->removeItem(ii); - } - } - if (combo->count() > 20) - combo->removeItem(20); - } + if (value.isEmpty()){ + // nothing to do + }else if (combo->count() == 0) + combo->addItem(value); + else{ + if (value != combo->itemText(0)){ + combo->insertItem(0, value); + } + for (int ii = 1; ii < combo->count(); ii++){ + if (value == combo->itemText(ii)){ + combo->removeItem(ii); + } + } + if (combo->count() > 20) + combo->removeItem(20); + } } /** @@ -169,21 +203,23 @@ void MainWindow::setInHistory(QComboBox* combo, const QString& value){ * @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); + if (m_stdLabelBackgroundRole == NULL) + m_stdLabelBackgroundRole = new QPalette::ColorRole( + m_statusMessage->backgroundRole()); + m_statusMessage->setBackgroundRole( + error ? QPalette::HighlightedText : *m_stdLabelBackgroundRole); + m_statusMessage->setText(message); } /** * @brief Handles the "up" button: go to the parent directory. */ void MainWindow::up(){ - QString path = ui->comboBoxDirectory->currentText(); - int ix = path.lastIndexOf(QDir::separator()); - if (ix >= 0){ - path = path.mid(0, ix); - ui->comboBoxDirectory->setEditText(path); - setInHistory(ui->comboBoxDirectory, path); - } + QString path = ui->comboBoxDirectory->currentText(); + int ix = path.lastIndexOf(QDir::separator()); + if (ix >= 0){ + path = path.mid(0, ix); + ui->comboBoxDirectory->setEditText(path); + setInHistory(ui->comboBoxDirectory, path); + } } diff --git a/appl/refind/mainwindow.hpp b/appl/refind/mainwindow.hpp index c509944..99def87 100644 --- a/appl/refind/mainwindow.hpp +++ b/appl/refind/mainwindow.hpp @@ -9,7 +9,6 @@ * The latest sources: https://github.com/republib */ - #ifndef MAINWINDOW_HPP #define MAINWINDOW_HPP @@ -17,38 +16,37 @@ #include #include - namespace Ui { class MainWindow; } enum TableColumns { - TC_NODE, TC_SIZE, TC_MODIFIED, TC_PATH + TC_NODE, TC_EXT, TC_SIZE, TC_MODIFIED, TC_TYPE, TC_PATH }; -class MainWindow : public QMainWindow -{ +class MainWindow: public QMainWindow { - Q_OBJECT + Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0); - ~MainWindow(); + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); private slots: - void search(); - void up(); + void search(); + void up(); private: - QDateTime comboDate(QComboBox* combo); - int64_t comboSize(QComboBox* combo); - QString comboText(QComboBox* combo); - void guiError(QWidget* widget, const QString& message); - void setInHistory(QComboBox* combo, const QString& value); - void setStatusMessage(bool error, const QString& message); + QDateTime comboDate(QComboBox* combo); + int comboInt(QComboBox* combo, int defaultValue); + int64_t comboSize(QComboBox* combo); + QString comboText(QComboBox* combo); + void guiError(QWidget* widget, const QString& message); + void setInHistory(QComboBox* combo, const QString& value); + void setStatusMessage(bool error, const QString& message); private: - Ui::MainWindow *ui; - QLabel* m_statusMessage; - QPalette::ColorRole* m_stdLabelBackgroundRole; - int m_errors; + Ui::MainWindow *ui; + QLabel* m_statusMessage; + QPalette::ColorRole* m_stdLabelBackgroundRole; + int m_errors; }; #endif // MAINWINDOW_HPP diff --git a/appl/refind/mainwindow.ui b/appl/refind/mainwindow.ui index 0c7a9a3..0727c6b 100644 --- a/appl/refind/mainwindow.ui +++ b/appl/refind/mainwindow.ui @@ -6,7 +6,7 @@ 0 0 - 1134 + 888 579 @@ -28,11 +28,11 @@ 16777215 - 130 + 150 - 0 + 1 @@ -40,72 +40,124 @@ - - - - - Search - - - Ctrl+F + + + + + + 100 + 16777215 + - - - - - - true + + Directory: - - + + - + + + + 75 + 0 + + - 50 + 100 16777215 - Up + Dirs + + + true - + + + + 75 + 0 + + - 50 + 100 16777215 - ... + Links + + + true + + + + + + + + 75 + 0 + + + + + 100 + 16777215 + + + + Hidden + + + + + + + + 75 + 0 + + + + + 100 + 16777215 + + + + Specials + + + + Qt::Horizontal + + + + 40 + 20 + + + + - - - - - 200 - 16777215 - - - - Directory: - - - - + - 300 + 275 0 @@ -114,8 +166,8 @@ - - + + 200 @@ -123,19 +175,15 @@ - File Patterns: + Text Pattern: - - - - ignore case - - + + - + 200 @@ -143,90 +191,180 @@ - Text Pattern: + File Patterns: - + true - - - - Exclude Patterns: - - - - - - - true - - - - - + + - + + + + 157 + 0 + + + + + 200 + 16777215 + + - Dirs + Regular expr. - + + + + 150 + 0 + + + + + 200 + 16777215 + + - Files + Binary files - - - Links + + + Qt::Horizontal - + + + 40 + 20 + + + + + + + + + Search + + + Ctrl+F + + + + + - + + + + 50 + 0 + + + + + 75 + 16777215 + + - Hidden + Up - + + + + 50 + 0 + + + + + 50 + 16777215 + + - Specials + ... + + + + true + + + + + + + + 125 + 16777215 + + + + ignore case + + + + + + + Files + + + true + + + - Size, Date, Depth + Size, Date, Depth, Excluded Dirs - 0 + 10 0 - 412 - 94 + 812 + 113 - - + + 10 + + + 10 + + + 150 @@ -234,12 +372,18 @@ - Max Size + Min. Size: - - + + + + + 175 + 0 + + 200 @@ -251,24 +395,30 @@ - - + + - 150 + 200 16777215 - Min. Size: + Younger than: - - - + + + 200 + 0 + + + + + 16777215 16777215 @@ -277,21 +427,41 @@ - - + + + + Min. Depth: + + + + + + + true + + + + + - 200 + 150 16777215 - Older than: + Max Size: - - + + + + + 175 + 0 + + 200 @@ -303,60 +473,67 @@ - - + + 200 16777215 - - true + + Older than: - - + + 200 16777215 - - Younger than: + + true - - + + - Min. Depth + Max. Depth: - - + + true - - + + - Max. Depth + Excluded Dirs: - - + + true + + + + Search + + + @@ -374,7 +551,12 @@ - Size + Ext + + + + + Size (MByte) AlignRight|AlignVCenter @@ -385,6 +567,11 @@ Modified + + + Type + + Path @@ -393,55 +580,7 @@ - - - - - Files: - - - - - - - - 100 - 16777215 - - - - - - - - Size: - - - - - - - - 100 - 16777215 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + @@ -452,7 +591,7 @@ 0 0 - 1134 + 888 23 @@ -530,6 +669,31 @@ + + tabWidget + comboBoxDirectory + pushButtonUp + pushButtonDirectory + comboBoxFilePatterns + checkBox_2 + checkBox + checkBox_4 + checkBox_3 + checkBox_5 + comboBoxTextPattern + checkBoxTextIgnoreCase + checkBoxRegExpr + checkBoxBinaryFiles + pushButtonSearch + tableWidget + comboBoxMinSize + comboBoxMaxSize + comboBoxYounger + comboBoxOlder + comboBoxMinDepth + comboBoxMaxDepth + comboBoxExcludedDirs + diff --git a/base/ReQStringUtil.cpp b/base/ReQStringUtil.cpp index 2f85a64..7082523 100644 --- a/base/ReQStringUtil.cpp +++ b/base/ReQStringUtil.cpp @@ -103,15 +103,15 @@ int ReQStringUtil::lengthOfUInt(const ReString& text, int start, int radix, * otherwise: the length is incremented */ void ReQStringUtil::skipExpected(const ReString& text, QChar expected, - int& index, int& length){ - if (length == 0){ - // error state, do nothing - } else if (index >= text.length() || text[index] != expected){ - length = 0; - } else { - index++; - length++; - } + int& index, int& length){ + if (length == 0){ + // error state, do nothing + }else if (index >= text.length() || text[index] != expected){ + length = 0; + }else{ + index++; + length++; + } } /** @@ -126,59 +126,59 @@ void ReQStringUtil::skipExpected(const ReString& text, QChar expected, * @return 0: no date found
* otherwise: the length of the date in the string */ -int ReQStringUtil::lengthOfDate(const ReString& text, int start, QDate* value) -{ - uint day = 0; - uint month = 0; - uint year = 0; - int length = lengthOfUInt(text, start, 10, &year); - switch(length){ - case 1: - case 2: - day = year; - year = 0; - break; - case 4: - break; - default: - length = 0; - break; - } - int length2; - start += length; - skipExpected(text, '.', start, length); - if (length > 0){ - length2 = lengthOfUInt(text, start, 10, &month); - if (length2 < 1 || length2 > 2) - length = 0; - else { - start += length2; - length += length2; - } - } - skipExpected(text, '.', start, length); - if (year > 0){ - length2 = lengthOfUInt(text, start, 10, &day); - if (length2 < 1 || length2 > 2) - length = 0; - else { - start += length2; - length += length2; - } - } else{ - length2 = lengthOfUInt(text, start, 10, &year); - if (length2 != 4) - length = 0; - else { - start += length2; - length += length2; - } - } - if (day < 1 || day > 31 || month < 1 || month > 12 || year < 1970 || year > 2100) - length = 0; - if (length != 0 && value != NULL) - *value = QDate(year, month, day); - return length; +int ReQStringUtil::lengthOfDate(const ReString& text, int start, QDate* value){ + uint day = 0; + uint month = 0; + uint year = 0; + int length = lengthOfUInt(text, start, 10, &year); + switch (length) { + case 1: + case 2: + day = year; + year = 0; + break; + case 4: + break; + default: + length = 0; + break; + } + int length2; + start += length; + skipExpected(text, '.', start, length); + if (length > 0){ + length2 = lengthOfUInt(text, start, 10, &month); + if (length2 < 1 || length2 > 2) + length = 0; + else{ + start += length2; + length += length2; + } + } + skipExpected(text, '.', start, length); + if (year > 0){ + length2 = lengthOfUInt(text, start, 10, &day); + if (length2 < 1 || length2 > 2) + length = 0; + else{ + start += length2; + length += length2; + } + }else{ + length2 = lengthOfUInt(text, start, 10, &year); + if (length2 != 4) + length = 0; + else{ + start += length2; + length += length2; + } + } + if (day < 1 || day > 31 || month < 1 || month > 12 || year < 1970 + || year > 2100) + length = 0; + if (length != 0 && value != NULL) + *value = QDate(year, month, day); + return length; } /** @@ -196,35 +196,34 @@ int ReQStringUtil::lengthOfDate(const ReString& text, int start, QDate* value) * otherwise: the length of the date in the string */ int ReQStringUtil::lengthOfDateTime(const ReString& text, int start, - bool allowDateOnly, bool allowTimeOnly, QDateTime* value) -{ - QDate date; - QTime time; - int length = lengthOfDate(text, start, &date); - if (length == 0){ - if (allowTimeOnly){ - date = QDate::currentDate(); - length = lengthOfTime(text, start, &time); - } - } else { - if (start + length + 1 + 3 <= text.length()) { - start += length; - int length2 = 0; - if (! text[start].isDigit()){ - QTime time2; - length2 = lengthOfTime(text, start + 1, &time2); - if (length2 == 0 && ! allowDateOnly) - length = 0; - else if (length2 > 0){ - length += 1 + length2; - time = time2; - } + bool allowDateOnly, bool allowTimeOnly, QDateTime* value){ + QDate date; + QTime time; + int length = lengthOfDate(text, start, &date); + if (length == 0){ + if (allowTimeOnly){ + date = QDate::currentDate(); + length = lengthOfTime(text, start, &time); + } + }else{ + if (start + length + 1 + 3 <= text.length()){ + start += length; + int length2 = 0; + if (!text[start].isDigit()){ + QTime time2; + length2 = lengthOfTime(text, start + 1, &time2); + if (length2 == 0 && !allowDateOnly) + length = 0; + else if (length2 > 0){ + length += 1 + length2; + time = time2; } - } - } - if (length > 0 && value != NULL) - *value = QDateTime(date, time); - return length; + } + } + } + if (length > 0 && value != NULL) + *value = QDateTime(date, time); + return length; } /** * Returns the length of a time in a string. @@ -238,38 +237,37 @@ int ReQStringUtil::lengthOfDateTime(const ReString& text, int start, * @return 0: no date found
* otherwise: the length of the date in the string */ -int ReQStringUtil::lengthOfTime(const ReString& text, int start, QTime* value) -{ - uint hour = 0; - uint minute = 0; - uint sec = 0; - int length = lengthOfUInt(text, start, 10, &hour); - if (length > 0 && hour > 23) - length = 0; - if (length > 0){ - start += length; - } - int length2; - skipExpected(text, ':', start, length); - if (length > 0){ - length2 = lengthOfUInt(text, start, 10, &minute); - if (length2 < 1 || length2 > 2 || minute >= 60) - length = 0; - else - start += length2, length += length2; - } - if (length > 0 && start < text.length() && text[start] == ':'){ - length++; - start++; - length2 = lengthOfUInt(text, start, 10, &sec); - if (length2 < 1 || length2 > 2 || sec >= 60) - length = 0; - else - start += length2, length += length2; - } - if (length != 0 && value != NULL) - *value = QTime(hour, minute, sec); - return length; +int ReQStringUtil::lengthOfTime(const ReString& text, int start, QTime* value){ + uint hour = 0; + uint minute = 0; + uint sec = 0; + int length = lengthOfUInt(text, start, 10, &hour); + if (length > 0 && hour > 23) + length = 0; + if (length > 0){ + start += length; + } + int length2; + skipExpected(text, ':', start, length); + if (length > 0){ + length2 = lengthOfUInt(text, start, 10, &minute); + if (length2 < 1 || length2 > 2 || minute >= 60) + length = 0; + else + start += length2, length += length2; + } + if (length > 0 && start < text.length() && text[start] == ':'){ + length++; + start++; + length2 = lengthOfUInt(text, start, 10, &sec); + if (length2 < 1 || length2 > 2 || sec >= 60) + length = 0; + else + start += length2, length += length2; + } + if (length != 0 && value != NULL) + *value = QTime(hour, minute, sec); + return length; } /** @@ -362,11 +360,10 @@ char*ReQStringUtil::utf8(const ReString& source, char buffer[], return buffer; } -class ReParserException : public ReException { +class ReParserException: public ReException { public: ReParserException(const QString& message) : - ReException(), - m_message(message){ + ReException(), m_message(message){ } public: QString m_message; @@ -378,11 +375,12 @@ public: * @param unitList description of the allowed units with its factor
* example: "kibyte:1024;kbyte:1000;mibyte:1048576;mbyte:1000000" */ -ReUnitParser::ReUnitParser(const QString& expr, const char* unitList, bool parseAtOnce) : +ReUnitParser::ReUnitParser(const QString& expr, const char* unitList, + bool parseAtOnce) : m_result(0), m_expr(expr), m_message(), m_unitList(unitList){ - normalize(); - if (parseAtOnce) - parse(); + normalize(); + if (parseAtOnce) + parse(); } /** @@ -439,18 +437,18 @@ bool ReUnitParser::isValid() const{ * @brief Normalizes the internal stored unit expression. */ void ReUnitParser::normalize(){ - // Remove the blanks: - for (int ii = m_expr.length() - 1; ii >= 0; ii--){ - if (m_expr[ii].isSpace()) - m_expr.remove(ii, 1); - } - // Replace the '-' operator by '+' as operator and '-' as sign: - // 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.insert(ii, '+'); - } - } + // Remove the blanks: + for (int ii = m_expr.length() - 1; ii >= 0; ii--){ + if (m_expr[ii].isSpace()) + m_expr.remove(ii, 1); + } + // Replace the '-' operator by '+' as operator and '-' as sign: + // 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.insert(ii, '+'); + } + } } /** @@ -468,7 +466,8 @@ void ReUnitParser::parse(){ for (it2 = factors.begin(); it2 != factors.end(); ++it2){ QStringList powerOperands = it2->split("^"); if (powerOperands.count() > 2) - throw ReParserException(QObject::tr("more than 2 power operators, e.g. '2^3^4'")); + throw ReParserException( + 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("-"); @@ -479,7 +478,8 @@ void ReUnitParser::parse(){ uint64_t fac = value; uint64_t exponent = valueOf(*++it3); if (qLn(value) * qLn(exponent) >= qLn(qPow(2.0, 64))) - throw ReParserException(QObject::tr("number overflow while power operation")); + throw ReParserException( + QObject::tr("number overflow while power operation")); for (int ii = 1; ii < (int) exponent; ii++) value = value * fac; } @@ -510,30 +510,35 @@ uint64_t ReUnitParser::valueOf(const QString& value) const{ if (ix == 0) throw ReParserException(QObject::tr("number expected: ") + value); QString unit = value.mid(ix); - if (! unit.isEmpty()){ + if (!unit.isEmpty()){ QStringList units = QString(m_unitList).split(";"); QStringList::const_iterator it; bool found = false; for (it = units.begin(); it != units.end(); ++it){ QStringList pair = it->split(":"); if (pair.count() == 0) - throw ReParserException(QObject::tr("missing ':' in unit definition, e.g. 'k:1000': ") + *it); + throw ReParserException( + 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); + throw ReParserException( + QObject::tr("too many ':' in unit definition: ") + *it); bool ok = false; QString unit2 = *pair.begin(); QString factor = *++pair.begin(); uint64_t nFactor = factor.toLongLong(&ok); - if (! ok) + if (!ok) throw ReParserException(QObject::tr("not a number: ") + factor); - if (unit2.startsWith(unit)){ + if (unit2.startsWith(unit, Qt::CaseInsensitive)){ rc *= nFactor; found = true; break; } } - if (! found) - throw ReParserException(QObject::tr("unknown unit, allowed: ") + QString(m_unitList)); + if (!found) + throw ReParserException( + QObject::tr("unknown unit '$1'. Allowed: ").arg(unit) + + QString(m_unitList)); } return rc; } @@ -544,10 +549,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. @@ -555,8 +560,9 @@ 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){ - parseDateTime(expr); + ReUnitParser("", "minutes:60;hours:3600;days:86400;weeks:604800", + false){ + parseDateTime(expr); } /** @@ -564,9 +570,8 @@ ReDateTimeParser::ReDateTimeParser(const QString& expr) : * * @return the parse result. If invalid input the result is the begin of the epoche */ -QDateTime ReDateTimeParser::asDateTime() const -{ - return m_dateTime; +QDateTime ReDateTimeParser::asDateTime() const{ + return m_dateTime; } /** @@ -579,40 +584,41 @@ QDateTime ReDateTimeParser::asDateTime() const * othewise: the calculated date/time */ QDateTime ReDateTimeParser::parseDateTime(const QString& expr){ - m_expr = expr; - normalize(); - QDateTime rc = QDateTime::currentDateTime(); - int64_t relativeSeconds = 0; - if (m_expr.isEmpty()) - m_message = QObject::tr("empty string is not a date/time"); - else { - QDateTime dateTime; - int length2 = 0; - bool checkSum = true; - if (m_expr.startsWith("now", Qt::CaseInsensitive)){ - m_expr.remove(0, 3); - } else if ( (length2 = ReQStringUtil::lengthOfDateTime(m_expr, 0, true, - true, &dateTime)) > 0){ - rc = dateTime; - m_expr.remove(0, length2); - } else { - checkSum = false; + m_expr = expr; + normalize(); + QDateTime rc = QDateTime::currentDateTime(); + int64_t relativeSeconds = 0; + if (m_expr.isEmpty()) + m_message = QObject::tr("empty string is not a date/time"); + else{ + QDateTime dateTime; + int length2 = 0; + bool checkSum = true; + if (m_expr.startsWith("now", Qt::CaseInsensitive)){ + m_expr.remove(0, 3); + }else if ((length2 = ReQStringUtil::lengthOfDateTime(m_expr, 0, true, + true, &dateTime)) > 0){ + rc = dateTime; + m_expr.remove(0, length2); + }else{ + checkSum = false; + parse(); + // meaning is "older than x seconds" + relativeSeconds = m_result = -m_result; + } + if (checkSum){ + if (m_expr.startsWith("+")){ + m_expr.remove(0, 1); + } + if (!m_expr.isEmpty()){ parse(); - // meaning is "older than x seconds" - relativeSeconds = m_result = - m_result; - } - if (checkSum){ - if (m_expr.startsWith("+")){ - m_expr.remove(0, 1); - } - if (! m_expr.isEmpty()){ - parse(); - relativeSeconds = m_result; - } - } - } - rc.setMSecsSinceEpoch(isValid() ? rc.toMSecsSinceEpoch() + 1000 * relativeSeconds : 0); - m_dateTime = rc; - return rc; + relativeSeconds = m_result; + } + } + } + rc.setMSecsSinceEpoch( + isValid() ? rc.toMSecsSinceEpoch() + 1000 * relativeSeconds : 0); + m_dateTime = rc; + return rc; }