m_maxDepth(512),
m_baseDir(""),
m_checkDates(false),
- m_countFiles(0),
- m_countDirs(0),
- m_bytes(0),
m_excludedDirs(),
m_textFinder(NULL){
m_youngerThan.setMSecsSinceEpoch(0);
FileFinder::~FileFinder(){
}
-/**
- * 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.
*/
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;
}
/**
/**
* Fills the table with the data of the filtered files of a given directory.
*
- * @param path the directory to inspect
- * @param depth the depth of the directory (relative to base directory)
- * @param table OUT: the table to fill
+ * @param path the directory to inspect
+ * @param depth the depth of the directory (relative to base directory)
+ * @param table OUT: the table to fill
+ * @param statistics OUT: statistic about the found objects
*/
-void FileFinder::fillTable(const QString& path, int depth, QTableWidget* table){
+void FileFinder::fillTable(const QString& path, int depth, QTableWidget* table,
+ Statistics& statistics){
QFileInfoList entries;
QDir dir(path);
table->setSortingEnabled(false);
}
bool isDir = it->isDir();
if (isDir)
- m_countDirs++;
+ statistics.m_dirs++;
else
- m_countFiles++;
+ statistics.m_files++;
table->setItem(m_lines, TC_NODE, new QTableWidgetItem(node));
int ix = node.lastIndexOf('.');
ext = ix <= 0 ? "" : node.mid(ix + 1).toLower();
QTableWidgetItem* item = new QTableWidgetItem(
isDir ? "" : fileSize(it->size()));
if (!isDir)
- m_bytes += it->size();
+ statistics.m_bytes += it->size();
item->setTextAlignment(Qt::AlignRight);
table->setItem(m_lines, TC_SIZE, item);
table->setItem(m_lines, TC_MODIFIED,
for (it = entries.begin(); it != entries.end(); ++it){
QString node = it->fileName();
if (!filtered || !isExcludedDir(node))
- fillTable(path + QDir::separator() + node, depth + 1, table);
+ fillTable(path + QDir::separator() + node, depth + 1, table,
+ statistics);
}
}
table->setRowCount(m_lines);
FileFinder();
~FileFinder();
public:
- int64_t bytes() const;
void clear();
- int countFiles() const;
- int countDirs() const;
- void fillTable(const QString& path, int depth, QTableWidget* table);
+ void fillTable(const QString& path, int depth, QTableWidget* table,
+ Statistics& statistics);
void setBaseDir(const QString& baseDir);
void setFiletypes(const QDir::Filters& filetypes);
void setExcludedDirs(const QStringList& excludedDirs);
int m_maxDepth;
QString m_baseDir;
bool m_checkDates;
- int m_countFiles;
- int m_countDirs;
- int64_t m_bytes;
QStringList m_excludedDirs;
// Only used to hold the search parameters:
TextFinder* m_textFinder;
return rc;
}
+/**
+ * Replaces placeholders valid in header and footer.
+ *
+ * @param text the text to convert
+ * @return <code>text</code> with the esc sequences replaced
+ */
+QString MainWindow::replaceGlobalPlaceholder(const QString& text){
+ int start = 0;
+ QString replacement;
+ QString name;
+ QString rc = text;
+ while (start >= 0){
+ start = rc.indexOf("${", start);
+ if (start < 0)
+ break;
+ int end = rc.indexOf('}', start + 1);
+ if (end < 0)
+ break;
+ name = rc.mid(start + 2, end - start - 2);
+ if (name == "filepatterns")
+ replacement = ui->comboBoxFilePatterns->currentText();
+ else if (name == "base")
+ replacement = m_lastBaseDir.absolutePath();
+ else if (name == "textpattern")
+ replacement = ui->comboBoxTextPattern->currentText();
+ else if (name == "dirs")
+ replacement = QString::number(m_statistics.m_dirs);
+ else if (name == "files")
+ replacement = QString::number(m_statistics.m_files);
+ else if (name == "runtime")
+ replacement = QString::number(m_statistics.m_runtimeSeconds, 'g', 3);
+ else if (name == "bytes")
+ replacement = QString::number(m_statistics.m_bytes);
+ else if (name == "megabytes")
+ replacement = QString::number((double) m_statistics.m_bytes / 1000000);
+ else{
+ QString msg = tr("unknown placeholder: ") + name;
+ guiError(ui->comboBoxFooter, msg);
+ break;
+ }
+ rc = rc.replace("${" + name + "}", replacement);
+ start += replacement.length();
+ }
+ return replaceEscSequences(rc);
+}
+
/**
* Exports the found files into a stream with header and footer.
*
*/
void MainWindow::exportToStream(QTextStream& stream, int maxRow){
if (!ui->comboBoxHeader->currentText().isEmpty()){
- stream << replaceEscSequences(ui->comboBoxHeader->currentText()) << endl;
+ stream << replaceGlobalPlaceholder(ui->comboBoxHeader->currentText())
+ << endl;
}
int count = ui->tabWidget->count();
if (count > 0 && maxRow > 0)
else if (name == "size")
replacement = ui->tableWidget->item(ii, TC_SIZE)->text();
else{
- throw ReQException(tr("unknown placeholder: ") + name);
+ guiError(ui->comboBoxTemplate, tr("unknown placeholder: ") + name);
+ break;
}
line = line.replace("${" + name + "}", replacement);
start += replacement.length();
stream << replaceEscSequences(line) << endl;
}
if (!ui->comboBoxFooter->currentText().isEmpty()){
- stream << replaceEscSequences(ui->comboBoxFooter->currentText()) << endl;
+ stream << replaceGlobalPlaceholder(ui->comboBoxFooter->currentText())
+ << endl;
}
}
}else{
QString value;
QTextStream stream(&value);
+ m_errors = 0;
exportToStream(stream);
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(value);
- setStatusMessage(false, tr("result exported to the clipboard"));
+ if (m_errors == 0)
+ setStatusMessage(false, tr("result exported to the clipboard"));
}
}
if (m_errors == 0){
if (!ui->comboBoxTextPattern->currentText().isEmpty())
finder.setTextFinder(&m_textFinder);
+ m_statistics.clear();
clock_t start = clock();
- finder.fillTable(path, 0, ui->tableWidget);
+ finder.fillTable(path, 0, ui->tableWidget, m_statistics);
+ m_statistics.m_runtimeSeconds = (double) (clock() - start)
+ / CLOCKS_PER_SEC;
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);
+ m_statistics.m_dirs, m_statistics.m_files,
+ m_statistics.m_bytes / 1000000.0, m_statistics.m_runtimeSeconds);
setStatusMessage(false, msg);
}
}
TC_NODE, TC_EXT, TC_SIZE, TC_MODIFIED, TC_TYPE, TC_PATH
};
+struct Statistics {
+ Statistics(){
+ clear();
+ }
+ void clear(){
+ m_dirs = m_files = 0;
+ m_bytes = 0;
+ m_runtimeSeconds = 0;
+ }
+ int m_dirs;
+ int m_files;
+ int64_t m_bytes;
+ double m_runtimeSeconds;
+};
+
class MainWindow: public QMainWindow, public ReGuiValidator {
Q_OBJECT
QString buildAbsPath(int row);
QDir::Filters buildFileTypes();
QString cellAsText(int row, int col);
+ void exportToStream(QTextStream& stream, int maxRow = -1);
void prepareTextFind();
+ QString replaceGlobalPlaceholder(const QString& text);
virtual void setStatusMessage(bool error, const QString& message);
- void exportToStream(QTextStream& stream, int maxRow = -1);
private:
Ui::MainWindow *ui;
QLabel* m_statusMessage;
QDir m_lastBaseDir;
QHeaderView* m_horizontalHeader;
Qt::SortOrder m_lastOrder;
+ Statistics m_statistics;
};
#endif // MAINWINDOW_HPP
<string/>
</property>
</widget>
- <widget class="QWidget" name="">
+ <widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<property name="editable">
<bool>true</bool>
</property>
+ <property name="currentText">
+ <string>=== found: ${dirs} dir(s) and ${files} file(s) with ${megabytes} MB in ${runtime} sec</string>
+ </property>
</widget>
</item>
</layout>