* @param dialog the option dialog
*/
TableKeyPressEater::TableKeyPressEater(DialogOptions* dialog) :
- QObject(dialog),
- m_dialog(dialog)
-{
+ QObject(dialog), m_dialog(dialog){
}
-
/**
* Event handler for the up/down keys of the table widget.
*
* @param event the current event
* @return
*/
-bool TableKeyPressEater::eventFilter(QObject *obj, QEvent *event)
-{
- if (event->type() == QEvent::KeyPress){
- QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
- int key = keyEvent->key();
- if (key == Qt::Key_Up || key == Qt::Key_Down)
- m_dialog->handleKey(key);
- }
- // standard event processing
- return QObject::eventFilter(obj, event);
+bool TableKeyPressEater::eventFilter(QObject *obj, QEvent *event){
+ if (event->type() == QEvent::KeyPress){
+ QKeyEvent *keyEvent = static_cast <QKeyEvent*>(event);
+ int key = keyEvent->key();
+ if (key == Qt::Key_Up || key == Qt::Key_Down)
+ m_dialog->handleKey(key);
+ }
+ // standard event processing
+ return QObject::eventFilter(obj, event);
}
/**
* Constructor.
SLOT(selectProgram()));
connect(ui->pushButtonUp, SIGNAL(clicked()), this, SLOT(up()));
connect(ui->tableWidget, SIGNAL(cellClicked(int,int)), this, SLOT(cellEntered(int,int)));
- connect(ui->tableWidget, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
- connect(ui->tableWidget, SIGNAL(currentItemChanged()), this, SLOT(currentItemChanged()));
+ connect(ui->tableWidget, SIGNAL(selectionChanged()), this,
+ SLOT(selectionChanged()));
+ connect(ui->tableWidget, SIGNAL(currentItemChanged()), this,
+ SLOT(currentItemChanged()));
ui->tableWidget->installEventFilter(new TableKeyPressEater(this));
for (int ix = 0; ix < ui->comboBoxFileType->count(); ix++)
}
void DialogOptions::currentItemChanged(QTableWidgetItem * current,
- QTableWidgetItem * previous){
- QString text = current->text() + " " + previous->text();
+ QTableWidgetItem * previous){
+ QString text = current->text() + " " + previous->text();
}
/**
QList < QString > dirMode;
for (int row = 0; row < count; row++){
ContextHandler* handler = m_contextHandlers.list().at(row);
- ui->tableWidget->setItem(row, COL_TITLE,
- new QTableWidgetItem(handler->m_text));
- ui->tableWidget->setItem(row, COL_PROGRAM,
- new QTableWidgetItem(handler->m_program));
- ui->tableWidget->setItem(row, COL_ARGUMENTS,
- new QTableWidgetItem(handler->m_arguments));
- value = ui->comboBoxFileType->itemText(handler->m_fileType - 1);
- ui->tableWidget->setItem(row, COL_FILE_TYPE, new QTableWidgetItem(value));
- value = ui->comboBoxDirMode->itemText(handler->m_directoryMode - 1);
- ui->tableWidget->setItem(row, COL_CURRENT_DIR,
- new QTableWidgetItem(value));
+ if (handler->intrinsicType() == ContextHandler::IT_UNDEF){
+ ui->tableWidget->setItem(row, COL_TITLE,
+ new QTableWidgetItem(handler->m_text));
+ ui->tableWidget->setItem(row, COL_PROGRAM,
+ new QTableWidgetItem(handler->m_program));
+ ui->tableWidget->setItem(row, COL_ARGUMENTS,
+ new QTableWidgetItem(handler->m_arguments));
+ value = ui->comboBoxFileType->itemText(handler->m_fileType - 1);
+ ui->tableWidget->setItem(row, COL_FILE_TYPE,
+ new QTableWidgetItem(value));
+ value = ui->comboBoxDirMode->itemText(handler->m_directoryMode - 1);
+ ui->tableWidget->setItem(row, COL_CURRENT_DIR,
+ new QTableWidgetItem(value));
+ }
}
}
*
* @param key the key (up or down)
*/
-void DialogOptions::handleKey(int key)
-{
- if (key == Qt::Key_Down){
- if (m_selectedRow < ui->tableWidget->rowCount() - 1)
- m_selectedRow++;
- } else if (key == Qt::Key_Up){
- if (m_selectedRow > 0)
- m_selectedRow--;
- }
+void DialogOptions::handleKey(int key){
+ if (key == Qt::Key_Down){
+ if (m_selectedRow < ui->tableWidget->rowCount() - 1)
+ m_selectedRow++;
+ }else if (key == Qt::Key_Up){
+ if (m_selectedRow > 0)
+ m_selectedRow--;
+ }
}
/**
QString file = QFileDialog::getOpenFileName(NULL, tr("Select Program File"),
ui->comboBoxProgram->currentText());
if (!file.isEmpty())
- ui->comboBoxProgram->setCurrentText(file);
+ ui->comboBoxProgram->setCurrentText(file);
}
-void DialogOptions::selectionChanged()
-{
- QList<QTableWidgetSelectionRange> selections = ui->tableWidget->selectedRanges();
- QList<QTableWidgetSelectionRange>::const_iterator it = selections.begin();
- if (it != selections.end()){
- int row = (*it).topRow();
- if (row != m_selectedRow)
- selectRow(row);
- }
+void DialogOptions::selectionChanged(){
+ QList < QTableWidgetSelectionRange > selections =
+ ui->tableWidget->selectedRanges();
+ QList <QTableWidgetSelectionRange>::const_iterator it = selections.begin();
+ if (it != selections.end()){
+ int row = (*it).topRow();
+ if (row != m_selectedRow)
+ selectRow(row);
+ }
}
/**
* Handles the event "pushed button up".
#include <QMouseEvent>
#include <QDrag>
#include <QMimeData>
+#include <QPainter>
#include <QProcess>
#include <QMessageBox>
ui->comboBoxDirectory->setCurrentText(startDir);
if (ui->comboBoxDirectory->currentText().isEmpty())
ui->comboBoxDirectory->setCurrentText(QDir::currentPath());
+ ui->tableWidget->setMainWindow(this);
statusBar()->addWidget(m_statusMessage);
connect(ui->actionSearch, SIGNAL(triggered()), this, SLOT(search()));
connect(ui->pushButtonSearch, SIGNAL(clicked()), this, SLOT(search()));
delete ui;
}
-void MainWindow::mousePressEvent(QMouseEvent* event){
- if (event->button() == Qt::LeftButton
- && ui->tableWidget->geometry().contains(event->pos())){
-
- QDrag *drag = new QDrag(this);
- QMimeData *mimeData = new QMimeData;
-
- mimeData->setText("test text");
- drag->setMimeData(mimeData);
-#if 0
- const QPixmap image = iconShader.pixmap(QSize(16,16));
- drag->drawPixmap(0, 0, 16, 16, image);
- drag->drawText(QRect(20, 0, 170, 20), tr("copy or move") );
-
- drag->setPixmap(iconPixmap);
-#endif
- Qt::DropAction dropAction = drag->exec();
- }
-}
/**
* initializeHomeializes the program home directory.
*/
/**
* Gets the absolute path of the file in the given row.
*
- * @param row the row number
- * @return the absolute path of the file given by the row
+ * @param row the row number
+ * @param withNode true: the node will be appended to the result
+ * @return the absolute path of the file given by the row
*/
-QString MainWindow::buildAbsPath(int row){
+QString MainWindow::buildAbsPath(int row, bool withNode){
QString rc(m_lastBaseDir.absolutePath());
QString value = cellAsText(row, TC_PATH);
- if (!value.isEmpty())
- rc += "/" + value + "/";
+ if (!value.isEmpty()){
+ ReQStringUtil::ensureLastChar(rc, '/');
+ rc += value;
+ }
+ if (withNode){
+ ReQStringUtil::ensureLastChar(rc, '/');
+ rc += cellAsText(row, TC_NODE);
+ }
return rc;
}
handlePlaceholder(ui->comboBoxHeader);
}
+/**
+ * Processes the dragging operation of the selected files in the table widget.
+ */
+void MainWindow::fileDragging(){
+
+ QDrag *drag = new QDrag(this);
+ QMimeData *mimeData = new QMimeData;
+ QList < QUrl > urls;
+ QList < QTableWidgetSelectionRange > ranges =
+ ui->tableWidget->selectedRanges();
+ QList <QTableWidgetSelectionRange>::iterator it;
+ int files = 0;
+ int dirs = 0;
+ bool isDir = false;
+ for (it = ranges.begin(); it != ranges.end(); ++it){
+ for (int row = (*it).topRow(); row <= (*it).bottomRow(); row++){
+ isDir = cellAsText(row, TC_SIZE).isEmpty();
+ QUrl url(buildAbsPath(row, true));
+ urls.append(url);
+ if (isDir)
+ dirs++;
+ else
+ files++;
+ }
+ }
+ if (urls.size() > 0){
+ mimeData->setUrls(urls);
+ drag->setMimeData(mimeData);
+ QPixmap image(200, 30);
+ QPainter painter(&image);
+ QString msg;
+ if (urls.size() == 1)
+ msg = tr("copy ") + ReQStringUtil::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)
+ msg = tr("copy %1 file(s)").arg(files);
+ else
+ msg = tr("copy %1 dirs(s)").arg(dirs);
+
+ painter.fillRect(image.rect(), Qt::white);
+ painter.drawText(10, 20, msg);
+ drag->setPixmap(image);
+
+ Qt::DropAction dropAction = drag->exec(Qt::CopyAction);
+ }
+
+}
+
/**
* Prepares the context menu of the result table.
*
*/
void MainWindow::prepareContextMenu(){
ui->tableWidget->setContextMenuPolicy(Qt::CustomContextMenu);
- connect(ui->tableWidget,
- SIGNAL(customContextMenuRequested(const QPoint&)),
- SLOT(handleTableContextMenu(const QPoint&)));
+connect(ui->tableWidget,
+ SIGNAL(customContextMenuRequested(const QPoint&)),
+ SLOT(handleTableContextMenu(const QPoint&)));
}
/**
* Prepares the text search.
*/
void MainWindow::prepareTextFind(){
- m_textFinder.setSearchParameter(ui->comboBoxTextPattern->currentText(),
- ui->checkBoxTextIgnoreCase->isChecked(), ui->checkBoxRegExpr->isChecked(),
- !ui->checkBoxBinaryFiles->isChecked());
- QString error = m_textFinder.regExprError();
- if (!error.isEmpty()){
- guiError(ui->comboBoxTextPattern, error);
- }
+m_textFinder.setSearchParameter(ui->comboBoxTextPattern->currentText(),
+ ui->checkBoxTextIgnoreCase->isChecked(), ui->checkBoxRegExpr->isChecked(),
+ !ui->checkBoxBinaryFiles->isChecked());
+QString error = m_textFinder.regExprError();
+if (!error.isEmpty()){
+ guiError(ui->comboBoxTextPattern, error);
+}
}
/**
* Shows a preview of the result export.
*/
void MainWindow::preview(){
- QString value;
- QTextStream stream(&value);
- exportToStream(stream, 1);
- QMessageBox msgBox;
- msgBox.setText(value);
- msgBox.setInformativeText(tr("Preview of the Export"));
- msgBox.setStandardButtons(QMessageBox::Cancel);
- msgBox.setDefaultButton(QMessageBox::Save);
- msgBox.exec();
+QString value;
+QTextStream stream(&value);
+exportToStream(stream, 1);
+QMessageBox msgBox;
+msgBox.setText(value);
+msgBox.setInformativeText(tr("Preview of the Export"));
+msgBox.setStandardButtons(QMessageBox::Cancel);
+msgBox.setDefaultButton(QMessageBox::Save);
+msgBox.exec();
}
void MainWindow::buildGlobalPlaceholders(QMap <QString, QString>& hash){
- hash.insert("filepatterns", ui->comboBoxFilePatterns->currentText());
- hash.insert("base", m_lastBaseDir.absolutePath());
- hash.insert("textpattern", ui->comboBoxTextPattern->currentText());
- hash.insert("dirs", QString::number(m_statistics.m_dirs));
- hash.insert("files", QString::number(m_statistics.m_files));
- hash.insert("runtime",
- QString::number(m_statistics.m_runtimeSeconds, 'g', 3));
- hash.insert("bytes", QString::number(m_statistics.m_bytes));
- hash.insert("megabytes",
- QString::number((double) m_statistics.m_bytes / 1000000));
- hash.insert("datetime",
- QDateTime::currentDateTime().toLocalTime().toString(
- "yyyy.MM.dd/hh:mm:ss"));
+hash.insert("filepatterns", ui->comboBoxFilePatterns->currentText());
+hash.insert("base", m_lastBaseDir.absolutePath());
+hash.insert("textpattern", ui->comboBoxTextPattern->currentText());
+hash.insert("dirs", QString::number(m_statistics.m_dirs));
+hash.insert("files", QString::number(m_statistics.m_files));
+hash.insert("runtime", QString::number(m_statistics.m_runtimeSeconds, 'g', 3));
+hash.insert("bytes", QString::number(m_statistics.m_bytes));
+hash.insert("megabytes",
+ QString::number((double) m_statistics.m_bytes / 1000000));
+hash.insert("datetime",
+ QDateTime::currentDateTime().toLocalTime().toString("yyyy.MM.dd/hh:mm:ss"));
}
/**
* Replaces placeholders valid in header and footer.
* @return <code>text</code> with the esc sequences replaced
*/
QString MainWindow::replaceGlobalPlaceholders(QComboBox* combo,
- QMap <QString, QString>& placeholders){
- QString rc = combo->currentText();
- QString error;
- if (!ReQStringUtil::replacePlaceholders(rc, placeholders, &error))
- guiError(combo, error);
- return replaceEscSequences(rc);
+QMap <QString, QString>& placeholders){
+QString rc = combo->currentText();
+QString error;
+if (!ReQStringUtil::replacePlaceholders(rc, placeholders, &error))
+ guiError(combo, error);
+return replaceEscSequences(rc);
}
/**
* Most of the filter parameters will be set to the default.
*/
void MainWindow::resetParameters(){
- ui->comboBoxFilePatterns->setCurrentText("");
- ui->comboBoxMaxDepth->setCurrentText("");
- ui->comboBoxMaxSize->setCurrentText("");
- ui->comboBoxMinDepth->setCurrentText("");
- ui->comboBoxMinSize->setCurrentText("");
- ui->comboBoxOlder->setCurrentText("");
- ui->comboBoxYounger->setCurrentText("");
- ui->comboBoxTextPattern->setCurrentText("");
- ui->checkBoxBinaryFiles->setChecked(false);
- ui->checkBoxDirs->setChecked(true);
- ui->checkBoxFiles->setChecked(true);
- ui->checkBoxHidden->setChecked(false);
- ui->checkBoxLinks->setChecked(true);
- ui->checkBoxReadable->setChecked(true);
- ui->checkBoxRegExpr->setChecked(false);
- ui->checkBoxTextIgnoreCase->setChecked(false);
- ui->checkBoxWritable->setChecked(true);
- ui->checkBoxExecutable->setChecked(true);
+ui->comboBoxFilePatterns->setCurrentText("");
+ui->comboBoxMaxDepth->setCurrentText("");
+ui->comboBoxMaxSize->setCurrentText("");
+ui->comboBoxMinDepth->setCurrentText("");
+ui->comboBoxMinSize->setCurrentText("");
+ui->comboBoxOlder->setCurrentText("");
+ui->comboBoxYounger->setCurrentText("");
+ui->comboBoxTextPattern->setCurrentText("");
+ui->checkBoxBinaryFiles->setChecked(false);
+ui->checkBoxDirs->setChecked(true);
+ui->checkBoxFiles->setChecked(true);
+ui->checkBoxHidden->setChecked(false);
+ui->checkBoxLinks->setChecked(true);
+ui->checkBoxReadable->setChecked(true);
+ui->checkBoxRegExpr->setChecked(false);
+ui->checkBoxTextIgnoreCase->setChecked(false);
+ui->checkBoxWritable->setChecked(true);
+ui->checkBoxExecutable->setChecked(true);
}
/**
* Handles the push of the button "select directory".
*/
void MainWindow::restoreState(){
- ReStateStorage storage(m_storageFile);
- storage.setForm("main");
- storage.restore(ui->comboBoxDirectory, "comboBoxDirectory", true);
- storage.restore(ui->comboBoxExcludedDirs, "comboBoxExcludedDirs", true);
- storage.restore(ui->comboBoxExportFile, "comboBoxExportFile", true);
- storage.restore(ui->comboBoxFilePatterns, "comboBoxFilePatterns");
- storage.restore(ui->comboBoxFooter, "comboBoxFooter", true);
- storage.restore(ui->comboBoxHeader, "comboBoxHeader", true);
- storage.restore(ui->comboBoxMaxDepth, "comboBoxMaxDepth");
- storage.restore(ui->comboBoxMaxSize, "comboBoxMaxSize");
- storage.restore(ui->comboBoxMinDepth, "comboBoxMinDepth");
- storage.restore(ui->comboBoxMinSize, "comboBoxMinSize");
- storage.restore(ui->comboBoxOlder, "comboBoxOlder");
- storage.restore(ui->comboBoxTemplate, "comboBoxTemplate", true);
- storage.restore(ui->comboBoxTextPattern, "comboBoxTextPattern");
- storage.restore(ui->comboBoxYounger, "comboBoxYounger");
- m_contextHandlers.restore(storage);
- storage.close();
+ReStateStorage storage(m_storageFile);
+storage.setForm("main");
+storage.restore(ui->comboBoxDirectory, "comboBoxDirectory", true);
+storage.restore(ui->comboBoxExcludedDirs, "comboBoxExcludedDirs", true);
+storage.restore(ui->comboBoxExportFile, "comboBoxExportFile", true);
+storage.restore(ui->comboBoxFilePatterns, "comboBoxFilePatterns");
+storage.restore(ui->comboBoxFooter, "comboBoxFooter", true);
+storage.restore(ui->comboBoxHeader, "comboBoxHeader", true);
+storage.restore(ui->comboBoxMaxDepth, "comboBoxMaxDepth");
+storage.restore(ui->comboBoxMaxSize, "comboBoxMaxSize");
+storage.restore(ui->comboBoxMinDepth, "comboBoxMinDepth");
+storage.restore(ui->comboBoxMinSize, "comboBoxMinSize");
+storage.restore(ui->comboBoxOlder, "comboBoxOlder");
+storage.restore(ui->comboBoxTemplate, "comboBoxTemplate", true);
+storage.restore(ui->comboBoxTextPattern, "comboBoxTextPattern");
+storage.restore(ui->comboBoxYounger, "comboBoxYounger");
+m_contextHandlers.restore(storage);
+storage.close();
}
/**
* Handles the push of the button "select directory".
*/
void MainWindow::saveState(){
- ReStateStorage storage(m_storageFile);
- storage.setForm("main");
- storage.store(ui->comboBoxDirectory, "comboBoxDirectory");
- storage.store(ui->comboBoxExcludedDirs, "comboBoxExcludedDirs");
- storage.store(ui->comboBoxExportFile, "comboBoxExportFile");
- storage.store(ui->comboBoxFilePatterns, "comboBoxFilePatterns");
- storage.store(ui->comboBoxFooter, "comboBoxFooter");
- storage.store(ui->comboBoxHeader, "comboBoxHeader");
- storage.store(ui->comboBoxMaxDepth, "comboBoxMaxDepth");
- storage.store(ui->comboBoxMaxSize, "comboBoxMaxSize");
- storage.store(ui->comboBoxMinDepth, "comboBoxMinDepth");
- storage.store(ui->comboBoxMinSize, "comboBoxMinSize");
- storage.store(ui->comboBoxOlder, "comboBoxOlder");
- storage.store(ui->comboBoxTemplate, "comboBoxTemplate");
- storage.store(ui->comboBoxTextPattern, "comboBoxTextPattern");
- storage.store(ui->comboBoxYounger, "comboBoxYounger");
- m_contextHandlers.save(storage);
- storage.close();
+ReStateStorage storage(m_storageFile);
+storage.setForm("main");
+storage.store(ui->comboBoxDirectory, "comboBoxDirectory");
+storage.store(ui->comboBoxExcludedDirs, "comboBoxExcludedDirs");
+storage.store(ui->comboBoxExportFile, "comboBoxExportFile");
+storage.store(ui->comboBoxFilePatterns, "comboBoxFilePatterns");
+storage.store(ui->comboBoxFooter, "comboBoxFooter");
+storage.store(ui->comboBoxHeader, "comboBoxHeader");
+storage.store(ui->comboBoxMaxDepth, "comboBoxMaxDepth");
+storage.store(ui->comboBoxMaxSize, "comboBoxMaxSize");
+storage.store(ui->comboBoxMinDepth, "comboBoxMinDepth");
+storage.store(ui->comboBoxMinSize, "comboBoxMinSize");
+storage.store(ui->comboBoxOlder, "comboBoxOlder");
+storage.store(ui->comboBoxTemplate, "comboBoxTemplate");
+storage.store(ui->comboBoxTextPattern, "comboBoxTextPattern");
+storage.store(ui->comboBoxYounger, "comboBoxYounger");
+m_contextHandlers.save(storage);
+storage.close();
}
/**
* Handles the "search" button.
*/
void MainWindow::search(){
- m_errors = 0;
- QApplication::setOverrideCursor (QCursor(Qt::WaitCursor));QString
- path = ui->comboBoxDirectory->currentText();
- QFileInfo dir(path);
- if (!dir.exists())
- guiError(ui->comboBoxDirectory, tr("directory not found: ") + path);
- else if (!dir.isDir())
- guiError(ui->comboBoxDirectory, tr("not a directory: ") + path);
- else{
- m_lastBaseDir.cd(path);
- 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));
- finder.setFiletypes(buildFileTypes());
- QStringList patterns;
- QString value = ui->comboBoxFilePatterns->currentText();
- if (!value.isEmpty())
- patterns = value.split(",");
- finder.setPatterns(patterns);
- value = ui->comboBoxExcludedDirs->currentText();
- if (value.indexOf('/') >= 0 || value.indexOf('\\') >= 0)
- guiError(ui->comboBoxExcludedDirs, tr("no path delimiter allowed"));
- else if (value.indexOf('*') >= 0)
- guiError(ui->comboBoxExcludedDirs,
- tr("no patterns allowed. Do not use '*"));
- else if (!value.isEmpty())
- patterns = value.split(",");
- finder.setExcludedDirs(patterns);
- prepareTextFind();
- 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, 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(),
- m_statistics.m_dirs, m_statistics.m_files,
- m_statistics.m_bytes / 1000000.0, m_statistics.m_runtimeSeconds);
- setStatusMessage(false, msg);
- }
+m_errors = 0;
+QApplication::setOverrideCursor (QCursor(Qt::WaitCursor));QString
+path = ui->comboBoxDirectory->currentText();
+QFileInfo dir(path);
+if (!dir.exists())
+ guiError(ui->comboBoxDirectory, tr("directory not found: ") + path);
+else if (!dir.isDir())
+ guiError(ui->comboBoxDirectory, tr("not a directory: ") + path);
+else{
+ m_lastBaseDir.cd(path);
+ 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));
+ finder.setFiletypes(buildFileTypes());
+ QStringList patterns;
+ QString value = ui->comboBoxFilePatterns->currentText();
+ if (!value.isEmpty())
+ patterns = value.split(",");
+ finder.setPatterns(patterns);
+ value = ui->comboBoxExcludedDirs->currentText();
+ if (value.indexOf('/') >= 0 || value.indexOf('\\') >= 0)
+ guiError(ui->comboBoxExcludedDirs, tr("no path delimiter allowed"));
+ else if (value.indexOf('*') >= 0)
+ guiError(ui->comboBoxExcludedDirs,
+ tr("no patterns allowed. Do not use '*"));
+ else if (!value.isEmpty())
+ patterns = value.split(",");
+ finder.setExcludedDirs(patterns);
+ prepareTextFind();
+ 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, 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(),
+ m_statistics.m_dirs, m_statistics.m_files,
+ m_statistics.m_bytes / 1000000.0, m_statistics.m_runtimeSeconds);
+ setStatusMessage(false, msg);
}
- QApplication::restoreOverrideCursor();
+}
+QApplication::restoreOverrideCursor();
}
/**
* Handles the push of the button "select directory".
*/
void MainWindow::selectDirectory(){
- QString dir = QFileDialog::getExistingDirectory(this, tr("Select Directory"),
- ui->comboBoxDirectory->currentText(), QFileDialog::ShowDirsOnly);
- if (!dir.isEmpty())
- ui->comboBoxDirectory->setCurrentText(dir);
+QString dir = QFileDialog::getExistingDirectory(this, tr("Select Directory"),
+ ui->comboBoxDirectory->currentText(), QFileDialog::ShowDirsOnly);
+if (!dir.isEmpty())
+ ui->comboBoxDirectory->setCurrentText(dir);
}
/**
* Calls the file selection dialog.
*/
void MainWindow::selectExportFile(){
- QString name = QFileDialog::getSaveFileName(this, tr("Select Export File"),
- ui->comboBoxExportFile->currentText());
- if (!name.isEmpty())
- ui->comboBoxExportFile->setCurrentText(name);
+QString name = QFileDialog::getSaveFileName(this, tr("Select Export File"),
+ ui->comboBoxExportFile->currentText());
+if (!name.isEmpty())
+ ui->comboBoxExportFile->setCurrentText(name);
}
* @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();
- QDir dir(path);
+QString path = ui->comboBoxDirectory->currentText();
+QDir dir(path);
+if (dir.exists()){
+ dir.cdUp();
if (dir.exists()){
- dir.cdUp();
- if (dir.exists()){
- path = dir.absolutePath();
- ui->comboBoxDirectory->setEditText(path);
- setInHistory(ui->comboBoxDirectory, path);
- }
+ path = dir.absolutePath();
+ ui->comboBoxDirectory->setEditText(path);
+ setInHistory(ui->comboBoxDirectory, path);
}
}
+}
#include "base/rebase.hpp"
#include "utils.hpp"
+/**
+ * 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){
+}
+
/**
* Constructor.
*/
m_program(),
m_arguments(),
m_directoryMode(DM_TO_PARENT),
- m_fileType(FT_FILE){
+ m_fileType(FT_FILE),
+ m_intrinsicType(IT_UNDEF){
+}
+
+/**
+ * Returns the intrinsic type.
+ *
+ * @return the intrinsic type
+ */
+ContextHandler::IntrinsicType ContextHandler::intrinsicType() const{
+ return m_intrinsicType;
}
/**
return copy(source);
}
+/**
+ * Adds the intrinsic context menu actions.
+ */
+void ContextHandlerList::addIntrinsics(){
+ m_list.append(
+ new ContextHandler(ContextHandler::IT_COPY, QObject::tr("copy")));
+}
+
/**
* Frees the resources.
*/
QList <ContextHandler*>::const_iterator it;
for (it = source.m_list.begin(); it != source.m_list.end(); ++it){
ContextHandler* handler = *it;
- m_list.append(handler);
+ if (handler->intrinsicType() == ContextHandler::IT_UNDEF)
+ m_list.append(handler);
}
+ addIntrinsics();
return *this;
}
QString value;
for (int ix = 0; ix < m_list.size(); ix++){
ContextHandler* handler = m_list.at(ix);
- 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);
+ 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* createHandlerIfExists(const QString& file,
- ContextHandler::FileType fileType = ContextHandler::FT_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}";
+ ContextHandler::FileType fileType = ContextHandler::FT_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}";
#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;
- }
- return handler;
+ handler->m_fileType = fileType;
+ handler->m_directoryMode =
+ fileType == ContextHandler::FT_FILE ?
+ ContextHandler::DM_TO_PARENT : ContextHandler::DM_TO_FILE;
+ }
+ return 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
}
+ addIntrinsics();
}
/**