]> gitweb.hamatoma.de Git - reqt/commitdiff
ReSearch: single files work, timer task
authorHamatoma <hamatoma@gmx.de>
Tue, 29 Nov 2016 01:19:42 +0000 (02:19 +0100)
committerHamatoma <hamatoma@gmx.de>
Tue, 29 Nov 2016 01:19:42 +0000 (02:19 +0100)
appl/research/filefilter.cpp
appl/research/filefinder.hpp
appl/research/mainwindow.cpp
appl/research/mainwindow.hpp
appl/research/mainwindow.ui

index 68a8ecc81fa18335510e59510a0550021ef026e2..adccf567a8160eae710a61a81a0068d30cde695d 100644 (file)
@@ -39,13 +39,13 @@ FileFilter::~FileFilter()
  * @param includePattern    regular expression to find lines to filter
  * @param excludePattern    regular expression to prevent lines from filtering
  * @param fromHit           first hit which is visible in the list
- * @param toHit             the filtering stops behind this hit
+ * @param pageSize          the filtering stops behind this hit
  * @param linesAbove        number of lines above the hit which will put into the list
  * @param linesBelow        number of lines below the hit which will put into the list
  */
 void FileFilter::filter(const QString &includePattern,
                         const QString &excludePattern,
-                        int fromHit, int toHit,
+                        int fromHit, int pageSize,
                         int linesAbove, int linesBelow,
                         bool caseSensitive)
 {
@@ -54,7 +54,7 @@ void FileFilter::filter(const QString &includePattern,
     int fileCount = m_table.rowCount();
     m_list.clear();
     m_fromHit = fromHit;
-    m_toHit = toHit;
+    m_toHit = fromHit + pageSize - 1;
     m_linesAbove = linesAbove;
     m_linesBelow = linesBelow;
     delete m_includeExpr;
@@ -66,7 +66,7 @@ void FileFilter::filter(const QString &includePattern,
     m_includeExpr = includePattern.isEmpty() ? NULL : new QRegularExpression(includePattern, option);
     m_excludeExpr = excludePattern.isEmpty() ? NULL : new QRegularExpression(excludePattern, option);
 
-    while (ixFile < fileCount - 1 && hitNo <toHit){
+    while (ixFile < fileCount - 1 && hitNo < m_toHit){
         ++ixFile;
         QString full = m_table.item(ixFile, colPath)->text();
         full += OS_SEPARATOR_STR;
@@ -74,7 +74,9 @@ void FileFilter::filter(const QString &includePattern,
 
         hitNo = filterOneFile(full, hitNo);
     }
-    if (hitNo <= toHit){
+    if (hitNo <= fromHit)
+         m_lastHitPosition.m_hitCount = 0;
+    else if (hitNo < m_toHit){
         m_lastHitPosition.m_hitCount = m_lastHitPosition.m_hitNo;
     }
 }
@@ -108,7 +110,7 @@ int FileFilter::filterOneFile(const QString& filename, int lastHit)
         lastHit = m_lastHitPosition.m_hitNo;
         lineNo = m_lastHitPosition.m_line;
     }
-    while(lastHit <= m_toHit && lineNo < lastIx){
+    while(lastHit < m_toHit && lineNo < lastIx){
         QString line = lines[++lineNo];
         if (m_includeExpr != NULL && ! m_includeExpr->match(line).hasMatch())
             continue;
index 2b45ee2f4d627af5e440bcbd630a03cb85174a44..f30e40af1ca5cd42cb01359ad676142e5e070155 100644 (file)
@@ -11,6 +11,7 @@ public:
     void addToTable(const QString& full, const QString &path,
         const QString &node, const QFileInfo &info);
     void clear();
+    void detachFromTable(const QString &full, const QString &path, const QString &node);
     int foundFiles() const;
     bool handleFile(const QString &full, const QString &path,
         const QString &node, const QFileInfo &info);
@@ -21,7 +22,6 @@ public:
     void setTextToSearch(const QString &text, bool caseSensitive,
         bool isRegularExpression, bool inverseSearch);
 private:
-    void detachFromTable(const QString &full, const QString &path, const QString &node);
     bool searchWithRegExpr(const QString &filename);
     bool searchText(const QString &filename);
 private:
index 581441ee98058fdad13d4b9a04cdcbe4a4cc7353..252dec72d9ac338d42ff515896cc785341f35ce5 100644 (file)
@@ -6,18 +6,22 @@
 #include "QFileDialog"
 
 static const char* VERSION = "2016.11.26";
+static const int s_defaultPageSize = 10;
 
 MainWindow::MainWindow(QApplication& application, const QString& homeDir,
                                           QWidget *parent) :
        ReGuiApplication(application, "rsearch", homeDir, 2, 10100100, "de", parent),
        ReGuiValidator(),
-    ui(new Ui::MainWindow),
-    m_fileFinder(NULL),
-    m_fileCache(new FileCache()),
-    m_test(true),
-    m_lastHitPosition(new HitPosition())
+       ui(new Ui::MainWindow),
+       m_fileFinder(NULL),
+       m_fileCache(new FileCache()),
+       m_test(true),
+    m_lastHitPosition(new HitPosition()),
+    m_currentTask(ttUndef),
+    m_timer(new QTimer(this))
 {
        ReComboBox::setDefaultHistorySize(20);
+    m_timer->setSingleShot(true);
        initializeGui();
 }
 
@@ -27,9 +31,39 @@ MainWindow::MainWindow(QApplication& application, const QString& homeDir,
 MainWindow::~MainWindow()
 {
        delete ui;
-    delete m_fileCache;
-    delete m_fileFinder;
-    delete m_lastHitPosition;
+       delete m_fileCache;
+       delete m_fileFinder;
+       delete m_lastHitPosition;
+}
+
+/**
+ * Adds a single file to the table.
+ *
+ * @param filename  the filename with path
+ * @param yetFound  IN/OUT: number of already found files.<br>
+ *                  Will be incremented if the file exists and was already
+ *                  in the table
+ * @return          <i>1</i>: the file exists<br>
+ *                  <i>0</i>: fhe file does not exist
+ */
+int MainWindow::addSingleFile(bool addNotDetach, const QString& filename, int& alreadyFound)
+{
+    QFileInfo info(filename);
+    int rc = info.exists() ? 1 : 0;
+    if (rc)
+    {
+        QString path = info.absolutePath();
+        QString node = info.baseName();
+        QString full = info.absoluteFilePath();
+        int ignoredFiles = m_fileFinder->ignoredFiles();
+        if (addNotDetach)
+            m_fileFinder->addToTable(full, path, node, info);
+        else
+            m_fileFinder->detachFromTable(full, path, node);
+        if (m_fileFinder->ignoredFiles() - ignoredFiles > 0)
+            ++alreadyFound;
+    }
+    return rc;
 }
 
 /**
@@ -41,14 +75,14 @@ MainWindow::~MainWindow()
  * @param defaultValue  the value if the source value is invalid
  */
 int MainWindow::comboboxToInt(QComboBox& combobox, int defaultValue){
-    QString text = combobox.currentText();
-    uint rc = 0;
-    if (ReQStringUtils::lengthOfUInt(text, 0, 10, &rc) != text.length()){
-        say(LOG_ERROR, tr("not an integer: %1 using instead: %2").arg(text).arg(defaultValue));
-        combobox.setCurrentText(QString::number(defaultValue));
-        rc = (uint) defaultValue;
-    }
-    return (int) rc;
+       QString text = combobox.currentText();
+       uint rc = 0;
+       if (ReQStringUtils::lengthOfUInt(text, 0, 10, &rc) != text.length()){
+               say(LOG_ERROR, tr("not an integer: %1 using instead: %2").arg(text).arg(defaultValue));
+               combobox.setCurrentText(QString::number(defaultValue));
+               rc = (uint) defaultValue;
+       }
+       return (int) rc;
 }
 
 /**
@@ -62,45 +96,47 @@ void MainWindow::initializeGui(){
        connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(onAbout()));
        connect(ui->comboBoxBaseDirectory, SIGNAL(textEdited(const QString&, const QString&)),
                        this, SLOT(textEdited(const QString&, const QString&)));
-    connect(ui->pushButtonSelectBase, SIGNAL(clicked()), this, SLOT(onSelectBaseDirectory()));
-    connect(ui->pushButtonAdd, SIGNAL(clicked()), this, SLOT(onAdd()));
-    connect(ui->pushButtonClear, SIGNAL(clicked()), this, SLOT(onClear()));
-    connect(ui->pushButtonFilter, SIGNAL(clicked()), this, SLOT(onFilter()));
-    connect(ui->pushButtonDetach, SIGNAL(clicked()), this, SLOT(onDetach()));
-    connect(ui->pushButtonPrevious, SIGNAL(clicked()), this, SLOT(onPrevious()));
-    connect(ui->pushButtonNext, SIGNAL(clicked()), this, SLOT(onNext()));
-
-    connect(ui->comboBoxExcludingPattern, SIGNAL(textEdited(QString,QString)),
-            this, SLOT(clearLastHitPosition(const QString&, const QString&)));
-    connect(ui->comboBoxIncludingPattern, SIGNAL(textEdited(QString,QString)),
-            this, SLOT(clearLastHitPosition(const QString&, const QString&)));
-    connect(ui->comboBoxLinesAbove, SIGNAL(textEdited(QString,QString)),
-            this, SLOT(clearLastHitPosition(const QString&, const QString&)));
+       connect(ui->pushButtonSelectBase, SIGNAL(clicked()), this, SLOT(onSelectBaseDirectory()));
+       connect(ui->pushButtonAdd, SIGNAL(clicked()), this, SLOT(onAdd()));
+       connect(ui->pushButtonClear, SIGNAL(clicked()), this, SLOT(onClear()));
+       connect(ui->pushButtonFilter, SIGNAL(clicked()), this, SLOT(onFilter()));
+       connect(ui->pushButtonDetach, SIGNAL(clicked()), this, SLOT(onDetach()));
+       connect(ui->pushButtonPrevious, SIGNAL(clicked()), this, SLOT(onPrevious()));
+       connect(ui->pushButtonNext, SIGNAL(clicked()), this, SLOT(onNext()));
+
+       connect(ui->comboBoxExcludingPattern, SIGNAL(textEdited(QString,QString)),
+                       this, SLOT(clearLastHitPosition(const QString&, const QString&)));
+       connect(ui->comboBoxIncludingPattern, SIGNAL(textEdited(QString,QString)),
+                       this, SLOT(clearLastHitPosition(const QString&, const QString&)));
+       connect(ui->comboBoxLinesAbove, SIGNAL(textEdited(QString,QString)),
+                       this, SLOT(clearLastHitPosition(const QString&, const QString&)));
     connect(ui->comboBoxLinesBelow, SIGNAL(textEdited(QString,QString)),
             this, SLOT(clearLastHitPosition(const QString&, const QString&)));
-    delete m_fileFinder;
-    m_fileFinder = new FileFinder(*ui->tableWidget, *m_fileCache);
+    connect(ui->comboBoxFromHit, SIGNAL(textEdited(QString,QString)),
+            this, SLOT(onFromHitChanged(const QString&, const QString&)));
 
-    ui->tableWidget->setColumnWidth(colNode, 200);
-    ui->tableWidget->setColumnWidth(colSize, 125);
-    ui->tableWidget->setColumnWidth(colDate, 175);
-    switchFilter(true);
-    if (m_test){
-        ui->comboBoxBaseDirectory->setCurrentText("/home/mhm/labor");
-        ui->comboBoxFilePatterns->setCurrentText("big*.txt");
-        ui->comboBoxIncludingPattern->setCurrentText("47");
-        onAdd();
-    }
+    connect(m_timer, SIGNAL(timeout()), this, SLOT(onTimerTask()));
+
+       delete m_fileFinder;
+       m_fileFinder = new FileFinder(*ui->tableWidget, *m_fileCache);
+
+       ui->tableWidget->setColumnWidth(colNode, 200);
+       ui->tableWidget->setColumnWidth(colSize, 125);
+       ui->tableWidget->setColumnWidth(colDate, 175);
+       switchFilter(true);
+       if (m_test){
+        ui->comboBoxBaseDirectory->setCurrentText("/home/mhm");
+       }
 }
 
 /**
  * Writes the known number of hits into the label.
  */
 void MainWindow::logHits(){
-    if (m_lastHitPosition->m_hitCount >= 0)
-        ui->labelHits->setText(tr("%1 hit(s)").arg(m_lastHitPosition->m_hitCount));
-    else
-        ui->labelHits->setText(tr(">= %1 hit(s)").arg(m_lastHitPosition->m_maxHitNo));
+       if (m_lastHitPosition->m_hitCount >= 0)
+               ui->labelHits->setText(tr("%1 hit(s)").arg(m_lastHitPosition->m_hitCount));
+       else
+               ui->labelHits->setText(tr(">= %1 hit(s)").arg(m_lastHitPosition->m_maxHitNo));
 }
 
 /**
@@ -108,10 +144,11 @@ void MainWindow::logHits(){
  */
 void MainWindow::clearLastHitPosition(const QString&, const QString&)
 {
-    m_lastHitPosition->m_filename.clear();
-    m_lastHitPosition->m_hitCount = -1;
-    m_lastHitPosition->m_hitNo = -1;
-    m_lastHitPosition->m_maxHitNo = 0;
+       m_lastHitPosition->m_filename.clear();
+       m_lastHitPosition->m_hitCount = -1;
+       m_lastHitPosition->m_hitNo = -1;
+       m_lastHitPosition->m_maxHitNo = 0;
+       switchFilter(true);
 }
 
 /**
@@ -136,7 +173,23 @@ void MainWindow::onAboutToQuit()
  */
 void MainWindow::onAdd()
 {
-    searchFiles(true);
+    switchFilter(true);
+    switchAdd(true);
+    m_currentTask = ttAdd;
+    m_timer->start(5);
+}
+
+/**
+ * Handles the click of the "Add" button.
+ */
+void MainWindow::onAddTimer()
+{
+    if (ui->tabWidgetFileSearch->currentIndex() < 2){
+        searchFiles(true);
+    } else {
+        searchSingleFile(true);
+    }
+    switchAdd(false);
 }
 
 /**
@@ -144,7 +197,23 @@ void MainWindow::onAdd()
  */
 void MainWindow::onDetach()
 {
-    searchFiles(false);
+    switchAdd(true);
+    switchFilter(true);
+    m_currentTask = ttDetach;
+    m_timer->start(5);
+}
+
+/**
+ * Handles the click of the "Detach" button.
+ */
+void MainWindow::onDetachTimer()
+{
+    if (ui->tabWidgetFileSearch->currentIndex() < 2){
+        searchFiles(false);
+    } else {
+        searchSingleFile(false);
+    }
+    switchAdd(false);
 }
 
 /**
@@ -152,8 +221,9 @@ void MainWindow::onDetach()
  */
 void MainWindow::onClear()
 {
+    switchFilter(true);
     m_fileFinder->clear();
-    ui->labelFileCount->setText("");
+       ui->labelFileCount->setText("");
 }
 
 /**
@@ -161,17 +231,25 @@ void MainWindow::onClear()
  */
 void MainWindow::onFilter()
 {
-    FileFilter filter(*ui->tableWidget, *ui->listWidgetHits, *m_fileCache,
-                      *m_lastHitPosition);
-    int from = comboboxToInt(*ui->comboBoxFromHit, 0);
-    int to = comboboxToInt(*ui->comboBoxToHit, from + 100);
-    int above = comboboxToInt(*ui->comboBoxLinesAbove, 0);
-    int below = comboboxToInt(*ui->comboBoxLinesBelow, 0);
-
-    filter.filter(ui->comboBoxIncludingPattern->currentText(),
-                  ui->comboBoxExcludingPattern->currentText(),
-                  from, to, above, below, false);
+    qint64 start = QDateTime::currentMSecsSinceEpoch();
+       FileFilter filter(*ui->tableWidget, *ui->listWidgetHits, *m_fileCache,
+                                         *m_lastHitPosition);
+       int from = comboboxToInt(*ui->comboBoxFromHit, 0);
+       int pageSize = comboboxToInt(*ui->comboBoxPageSize, s_defaultPageSize);
+       int above = comboboxToInt(*ui->comboBoxLinesAbove, 0);
+       int below = comboboxToInt(*ui->comboBoxLinesBelow, 0);
+    ui->pushButtonFilter->setEnabled(false);
+       filter.filter(ui->comboBoxIncludingPattern->currentText(),
+                                 ui->comboBoxExcludingPattern->currentText(),
+                  from, pageSize, above, below, false);
     switchFilter(false);
+    int found = pageSize;
+    if (m_lastHitPosition->m_hitCount >= 0
+            && m_lastHitPosition->m_hitCount - from < pageSize)
+        found = m_lastHitPosition->m_hitCount - from + 1;
+    qint64 duration = QDateTime::currentMSecsSinceEpoch() - start;
+    say(LOG_INFO, tr("Found: %1 hit(s) in %2").arg(found)
+        .arg(ReQStringUtils::readableDuration(duration)));
 }
 
 /**
@@ -181,6 +259,18 @@ void MainWindow::onGuiTimerUpdate()
 {
 }
 
+/**
+ * Handles the event "changed text" of the field <i>comboBoxFromHit</i>.
+ *
+ * @param oldValue  value before editing
+ * @param newValue  value after editing
+ */
+void MainWindow::onFromHitChanged(const QString& oldValue, const QString& newValue)
+{
+    ReUseParameter(oldValue);
+    ReUseParameter(newValue);
+    ui->pushButtonFilter->setEnabled(true);
+}
 
 /**
  * The language has been changed.
@@ -195,26 +285,33 @@ void MainWindow::onLanguageChange()
  */
 void MainWindow::onNext()
 {
-    int first = comboInt(ui->comboBoxFromHit, 1);
-    int last = comboInt(ui->comboBoxToHit, first + 100);
-    int pageSize = last - first + 1;
-    first = first + pageSize;
-    ui->comboBoxFromHit->setCurrentText(QString::number(first));
-    ui->comboBoxToHit->setCurrentText(QString::number(first + pageSize - 1));
-    onFilter();
+       int first = comboInt(ui->comboBoxFromHit, 1);
+       int pageSize = comboInt(ui->comboBoxPageSize, s_defaultPageSize);
+    if (m_lastHitPosition->m_hitCount >= 0
+            && first + pageSize > m_lastHitPosition->m_hitCount)
+               first = max(1, m_lastHitPosition->m_hitCount - 1);
+       else
+               first += pageSize;
+       ui->comboBoxFromHit->setCurrentText(QString::number(first));
+       if (first != m_lastHitPosition->m_hitNo)
+               onFilter();
+    if (m_lastHitPosition->m_hitCount >= 0
+            && first + pageSize > m_lastHitPosition->m_hitCount)
+        ui->pushButtonNext->setEnabled(false);
 }
 /**
  * Shows the previous page of filtered lines.
  */
 void MainWindow::onPrevious()
 {
-    int first = comboInt(ui->comboBoxFromHit, 1);
-    int last = comboInt(ui->comboBoxToHit, first + 100);
-    int pageSize = last - first + 1;
-    first = max(1, first - pageSize);
-    ui->comboBoxFromHit->setCurrentText(QString::number(first));
-    ui->comboBoxToHit->setCurrentText(QString::number(first + pageSize - 1));
-    onFilter();
+       int first = comboInt(ui->comboBoxFromHit, 1);
+       int pageSize = comboInt(ui->comboBoxPageSize, s_defaultPageSize);
+       first = max(1, first - pageSize);
+       ui->comboBoxFromHit->setCurrentText(QString::number(first));
+       onFilter();
+    bool enabled = m_lastHitPosition->m_hitCount < 0
+            || first < m_lastHitPosition->m_hitCount;
+    ui->pushButtonNext->setEnabled(enabled);
 }
 
 /**
@@ -222,11 +319,31 @@ void MainWindow::onPrevious()
  */
 void MainWindow::onSelectBaseDirectory(){
 QString dir = QFileDialog::getExistingDirectory(this, tr("Select Directory"),
-    ui->comboBoxBaseDirectory->currentText(), QFileDialog::ShowDirsOnly);
+       ui->comboBoxBaseDirectory->currentText(), QFileDialog::ShowDirsOnly);
 if (!dir.isEmpty())
    ui->comboBoxBaseDirectory->setCurrentText(ReFileUtils::nativePath(dir));
 }
 
+/**
+ * Does the timer task.
+ */
+void MainWindow::onTimerTask()
+{
+    switch(m_currentTask)
+    {
+    case ttAdd:
+        onAddTimer();
+        break;
+    case ttDetach:
+        onDetachTimer();
+        break;
+    case ttClear:
+        break;
+    default:
+        break;
+    }
+}
+
 /**
  * Writes a message.
  *
@@ -247,32 +364,84 @@ bool MainWindow::say(ReLoggerLevel level, const QString& message){
  */
 void MainWindow::searchFiles(bool addNotDetach)
 {
-    QString base = ui->comboBoxBaseDirectory->currentText();
-    if (base.isEmpty()){
-        say(LOG_ERROR, tr("missing a base directory"));
-    } else {
-        QDateTime olderThan = comboDate(ui->comboBoxOlder);
-        QDateTime youngerThan = comboDate(ui->comboBoxYounger);
-        m_fileFinder->setOlderThan(olderThan.toMSecsSinceEpoch() <= 0
-                ? NULL : new QDateTime(olderThan));
-        m_fileFinder->setYoungerThan(olderThan.toMSecsSinceEpoch() <= 0
-                ? NULL : new QDateTime(youngerThan));
-        m_fileFinder->setTextToSearch(ui->comboBoxTextPattern->currentText(),
-                ui->checkBoxCaseSensitiv->isChecked(),
-                ui->checkBoxRegularExpr->isChecked(),
-                ui->checkBoxInverse->isChecked());
-        m_fileFinder->setAddNotDetach(addNotDetach);
-        m_fileFinder->search(base, ui->comboBoxFilePatterns->currentText(),
-             atoi(ui->lineEditMinDepth->text().toLocal8Bit().data()),
-             atoi(ui->lineEditMaxDepth->text().toLocal8Bit().data()));
-        int files = ui->tableWidget->rowCount();
-        ui->labelFileCount->setText(QString::number(files)
-                                    + " " + tr("file(s)"));
-        say(LOG_INFO, tr("files: %1 already found: %2 processed directories: %3")
-            .arg(m_fileFinder->foundFiles())
-            .arg(m_fileFinder->ignoredFiles())
-            .arg(m_fileFinder->processedDirs()));
+       QString base = ui->comboBoxBaseDirectory->currentText();
+       if (base.isEmpty()){
+               say(LOG_ERROR, tr("missing a base directory"));
+       } else {
+               QDateTime olderThan = comboDate(ui->comboBoxOlder);
+               QDateTime youngerThan = comboDate(ui->comboBoxYounger);
+               m_fileFinder->setOlderThan(olderThan.toMSecsSinceEpoch() <= 0
+                               ? NULL : new QDateTime(olderThan));
+               m_fileFinder->setYoungerThan(olderThan.toMSecsSinceEpoch() <= 0
+                               ? NULL : new QDateTime(youngerThan));
+               m_fileFinder->setTextToSearch(ui->comboBoxTextPattern->currentText(),
+                               ui->checkBoxCaseSensitiv->isChecked(),
+                               ui->checkBoxRegularExpr->isChecked(),
+                               ui->checkBoxInverse->isChecked());
+               m_fileFinder->setAddNotDetach(addNotDetach);
+               m_fileFinder->search(base, ui->comboBoxFilePatterns->currentText(),
+                        atoi(ui->lineEditMinDepth->text().toLocal8Bit().data()),
+                        atoi(ui->lineEditMaxDepth->text().toLocal8Bit().data()));
+               int files = ui->tableWidget->rowCount();
+               ui->labelFileCount->setText(QString::number(files)
+                                                                       + " " + tr("file(s)"));
+               say(LOG_INFO, tr("files: %1 already found: %2 processed directories: %3")
+                       .arg(m_fileFinder->foundFiles())
+                       .arg(m_fileFinder->ignoredFiles())
+                       .arg(m_fileFinder->processedDirs()));
+       }
+}
+
+/**
+ * Common operation of onAdd() and onDetach().
+ *
+ * @param addNotDetach  <i>true</i>: add the found files<br>
+ *                      <i>false</i>: detach the found files
+ */
+void MainWindow::searchSingleFile(bool addNotDetach)
+{
+    int ix = ui->comboBoxSeparator->currentIndex();
+    QString separator;
+    if (ix >= 0)
+        separator = ui->comboBoxSeparator->currentText();
+    QStringList lines = ui->plainTextFilenames->toPlainText()
+            .split('\n', QString::SkipEmptyParts);
+    QRegExp separatorExpr(separator);
+
+    int found = 0;
+    int allFiles = 0;
+    int ignored = 0;
+    for (int no = 0; no < lines.size(); no++){
+        QString line = lines[no].trimmed();
+        if (separator.isEmpty()){
+            found += addSingleFile(addNotDetach, line, ignored);
+            ++ allFiles;
+        } else {
+            QStringList files = line.split(separatorExpr, QString::SkipEmptyParts);
+            allFiles += files.size();
+            for (int ix2 = 0; ix2 < files.size(); ix2++)
+                found += addSingleFile(addNotDetach, files[ix2], ignored);
+        }
     }
+    say(LOG_INFO, tr("Listed: %1 exists: %2 already found: %3").arg(allFiles)
+        .arg(found).arg(ignored));
+}
+
+/**
+ * Switches the add button and related.
+ *
+ * @param hide  <i>true</i>: hide the buttons
+ *              <i>false</i>: show the buttons
+ */
+void MainWindow::switchAdd(bool hide)
+{
+    ui->pushButtonAdd->setEnabled(! hide);
+    ui->pushButtonDetach->setEnabled(! hide);
+    ui->pushButtonClear->setEnabled(! hide);
+    if (hide)
+        say(LOG_INFO, tr("I am working..."));
+    ui->pushButtonAdd->update();
+    ui->groupBox->update();
 }
 
 /**
@@ -281,18 +450,15 @@ void MainWindow::searchFiles(bool addNotDetach)
  * @param first     <i>true</i>: a new resultset is expected.
  */
 void MainWindow::switchFilter(bool first){
-    ui->pushButtonFilter->setEnabled(first);
-    ui->pushButtonPrevious->setEnabled(! first);
-    ui->pushButtonNext->setEnabled(! first);
-    if (first){
-        int start = comboInt(ui->comboBoxFromHit, 1);
-        int pageSize = comboInt(ui->comboBoxToHit, start + 50) - start + 1;
-        ui->comboBoxFromHit->setCurrentText("1");
-        ui->comboBoxToHit->setCurrentText(QString::number(pageSize));
-        ui->labelHits->setText("");
-    } else {
-        logHits();
-    }
+       ui->pushButtonFilter->setEnabled(first);
+       ui->pushButtonPrevious->setEnabled(! first);
+       ui->pushButtonNext->setEnabled(! first);
+       if (first){
+               ui->comboBoxFromHit->setCurrentText("1");
+               ui->labelHits->setText("");
+       } else {
+               logHits();
+       }
 }
 
 /**
@@ -303,6 +469,6 @@ void MainWindow::switchFilter(bool first){
 void MainWindow::textEdited(const QString& oldString, const QString& newString)
 {
        ReUseParameter(oldString);
-       ReUseParameter(newString);
+    ReUseParameter(newString);
 }
 
index 623d46faa84b2b078441fe28d96ef3668fbe40c1..ec9c81f58aec3481381dbfe0a2dcc5091450f9fa 100644 (file)
@@ -19,6 +19,10 @@ class MainWindow;
 class MainWindow :  public ReGuiApplication, public ReGuiValidator
 {
        Q_OBJECT
+public:
+    enum TimerTask {
+        ttUndef, ttAdd, ttDetach, ttClear
+    };
 
 public:
        explicit MainWindow(QApplication& application, const QString& homeDir,
@@ -28,13 +32,18 @@ public:
        virtual bool say(ReLoggerLevel level, const QString& message);
 
 private:
+    int addSingleFile(bool addNotDetach, const QString &filename, int &alreadyFound);
     int comboboxToInt(QComboBox &combobox, int defaultValue);
     void initializeGui();
     void logHits();
+    void onAddTimer();
     virtual void onAboutToQuit();
+    void onDetachTimer();
     virtual void onGuiTimerUpdate();
     virtual void onLanguageChange();
     void searchFiles(bool addNotDetach);
+    void searchSingleFile(bool addNotDetach);
+    void switchAdd(bool hide);
     void switchFilter(bool first);
 private slots:
     void clearLastHitPosition(const QString &, const QString &);
@@ -43,9 +52,11 @@ private slots:
     void onClear();
     void onDetach();
     void onFilter();
+    void onFromHitChanged(const QString &oldValue, const QString &newValue);
     void onNext();
     void onPrevious();
     void onSelectBaseDirectory();
+    void onTimerTask();
     void textEdited(const QString& oldString, const QString& newString);
 private:
    Ui::MainWindow *ui;
@@ -53,5 +64,7 @@ private:
    FileCache* m_fileCache;
    bool m_test;
    HitPosition* m_lastHitPosition;
+   TimerTask m_currentTask;
+   QTimer* m_timer;
 };
 #endif // MAINWINDOW_H
index e6aa7816707a6eb9b0889458dbf081362b8fca42..f13990e465124c9e783dd40f60fbd6f50ecba4e7 100644 (file)
    </rect>
   </property>
   <property name="windowTitle">
-   <string>MainWindow</string>
+   <string>ReSearch</string>
   </property>
   <widget class="QWidget" name="centralWidget">
    <layout class="QVBoxLayout" name="verticalLayout_4">
     <item>
      <widget class="QTabWidget" name="tabWidget">
       <property name="currentIndex">
-       <number>1</number>
+       <number>0</number>
       </property>
       <widget class="QWidget" name="tabFiles">
        <attribute name="title">
@@ -321,90 +321,119 @@ If the checkbox &quot;inverse search&quot; is checked a file is found only if th
                <attribute name="title">
                 <string>Single files</string>
                </attribute>
-              </widget>
-             </widget>
-            </item>
-            <item>
-             <widget class="QGroupBox" name="groupBox">
-              <property name="maximumSize">
-               <size>
-                <width>16777215</width>
-                <height>175</height>
-               </size>
-              </property>
-              <property name="title">
-               <string>Activity</string>
-              </property>
-              <widget class="QLabel" name="labelFileCount">
-               <property name="geometry">
-                <rect>
-                 <x>0</x>
-                 <y>150</y>
-                 <width>131</width>
-                 <height>20</height>
-                </rect>
-               </property>
-               <property name="text">
-                <string notr="true"/>
-               </property>
-              </widget>
-              <widget class="QWidget" name="layoutWidget">
-               <property name="geometry">
-                <rect>
-                 <x>19</x>
-                 <y>27</y>
-                 <width>87</width>
-                 <height>113</height>
-                </rect>
-               </property>
-               <layout class="QVBoxLayout" name="verticalLayout_5">
-                <item>
-                 <widget class="QPushButton" name="pushButtonAdd">
-                  <property name="toolTip">
-                   <string>Adds the described files into the table below</string>
-                  </property>
+               <layout class="QFormLayout" name="formLayout">
+                <item row="0" column="0">
+                 <widget class="QLabel" name="label_14">
                   <property name="text">
-                   <string>&amp;Add</string>
+                   <string>List of files:</string>
                   </property>
                  </widget>
                 </item>
-                <item>
-                 <widget class="QPushButton" name="pushButtonDetach">
+                <item row="0" column="1">
+                 <widget class="QPlainTextEdit" name="plainTextFilenames">
                   <property name="toolTip">
-                   <string>Removes the found files from the table below</string>
-                  </property>
-                  <property name="text">
-                   <string>&amp;Detach</string>
+                   <string>One ore more filenames (with path) separated by the separator described below</string>
                   </property>
                  </widget>
                 </item>
-                <item>
-                 <spacer name="verticalSpacer">
-                  <property name="orientation">
-                   <enum>Qt::Vertical</enum>
-                  </property>
-                  <property name="sizeHint" stdset="0">
-                   <size>
-                    <width>20</width>
-                    <height>40</height>
-                   </size>
+                <item row="1" column="0">
+                 <widget class="QLabel" name="label_15">
+                  <property name="text">
+                   <string>Separator:</string>
                   </property>
-                 </spacer>
+                 </widget>
                 </item>
-                <item>
-                 <widget class="QPushButton" name="pushButtonClear">
+                <item row="1" column="1">
+                 <widget class="QComboBox" name="comboBoxSeparator">
                   <property name="toolTip">
-                   <string>Clears the table below</string>
+                   <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Regular expression for the separator between filenames.&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Note&lt;/span&gt;: The newline is always a separator.&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Examples&lt;/span&gt;: (type without &amp;quot;)&lt;/p&gt;&lt;p&gt;&amp;quot;\s+&amp;quot; : whitespaces (blanks, tabulators)&lt;/p&gt;&lt;p&gt;&amp;quot;,\s*&amp;quot;: a comma with or without whitespaces&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
                   </property>
-                  <property name="text">
-                   <string>&amp;Clear</string>
+                  <property name="editable">
+                   <bool>true</bool>
+                  </property>
+                  <property name="currentText">
+                   <string notr="true">'\n' (newline)</string>
                   </property>
+                  <item>
+                   <property name="text">
+                    <string>'\n' (newline)</string>
+                   </property>
+                  </item>
                  </widget>
                 </item>
                </layout>
               </widget>
              </widget>
             </item>
+            <item>
+             <widget class="QGroupBox" name="groupBox">
+              <property name="maximumSize">
+               <size>
+                <width>16777215</width>
+                <height>175</height>
+               </size>
+              </property>
+              <property name="title">
+               <string>Activity</string>
+              </property>
+              <layout class="QVBoxLayout" name="verticalLayout_7">
+               <item>
+                <layout class="QVBoxLayout" name="verticalLayout_5">
+                 <item>
+                  <widget class="QPushButton" name="pushButtonAdd">
+                   <property name="toolTip">
+                    <string>Adds the described files into the table below</string>
+                   </property>
+                   <property name="text">
+                    <string>&amp;Add</string>
+                   </property>
+                  </widget>
+                 </item>
+                 <item>
+                  <widget class="QPushButton" name="pushButtonDetach">
+                   <property name="toolTip">
+                    <string>Removes the found files from the table below</string>
+                   </property>
+                   <property name="text">
+                    <string>&amp;Detach</string>
+                   </property>
+                  </widget>
+                 </item>
+                 <item>
+                  <spacer name="verticalSpacer">
+                   <property name="orientation">
+                    <enum>Qt::Vertical</enum>
+                   </property>
+                   <property name="sizeHint" stdset="0">
+                    <size>
+                     <width>20</width>
+                     <height>40</height>
+                    </size>
+                   </property>
+                  </spacer>
+                 </item>
+                 <item>
+                  <widget class="QPushButton" name="pushButtonClear">
+                   <property name="toolTip">
+                    <string>Clears the table below</string>
+                   </property>
+                   <property name="text">
+                    <string>&amp;Clear</string>
+                   </property>
+                  </widget>
+                 </item>
+                </layout>
+               </item>
+               <item>
+                <widget class="QLabel" name="labelFileCount">
+                 <property name="text">
+                  <string notr="true"/>
+                 </property>
+                </widget>
+               </item>
+              </layout>
+             </widget>
+            </item>
            </layout>
           </item>
           <item>
@@ -482,6 +511,13 @@ If the checkbox &quot;inverse search&quot; is checked a file is found only if th
               </item>
               <item row="0" column="1">
                <widget class="ReComboBox" name="comboBoxIncludingPattern">
+                <property name="toolTip">
+                 <string>Regular expression defining a hit.
+&lt;b&gt;Examples&lt;/b&gt;
+&lt;b&gt;or expression&lt;/b&gt;: &quot;cat|dog&quot; find the lines &quot;&lt;bcat&lt;/b&gt;s are wanted&quot; and &quot;Missing a &lt;b&gt;dog&lt;/b&gt;&quot;
+&lt;b&gt;Begin of the line&lt;/b&gt;: &quot;^1234&quot; finds the line &quot;&lt;b&gt;1234&lt;/b&gt; houses&quot; but not the line &quot;count: &lt;b&gt;1234&lt;/b&gt;&quot;
+&lt;b&gt;Word boundaries&lt;/b&gt;: &quot;\bcat\b&quot; finds the line &quot;a &lt;b&gt;cat&lt;/b&gt; and a dog&quot; but not the line &quot;Look at the &lt;b&gt;cat&lt;/b&gt;s&quot;</string>
+                </property>
                 <property name="editable">
                  <bool>true</bool>
                 </property>
@@ -496,6 +532,9 @@ If the checkbox &quot;inverse search&quot; is checked a file is found only if th
               </item>
               <item row="1" column="1">
                <widget class="ReComboBox" name="comboBoxExcludingPattern">
+                <property name="toolTip">
+                 <string>Regulare expression to prevend from being a hit</string>
+                </property>
                 <property name="editable">
                  <bool>true</bool>
                 </property>
@@ -512,7 +551,7 @@ If the checkbox &quot;inverse search&quot; is checked a file is found only if th
                <rect>
                 <x>11</x>
                 <y>11</y>
-                <width>298</width>
+                <width>321</width>
                 <height>38</height>
                </rect>
               </property>
@@ -570,6 +609,12 @@ If the checkbox &quot;inverse search&quot; is checked a file is found only if th
           </item>
           <item>
            <layout class="QHBoxLayout" name="horizontalLayout_5">
+            <property name="leftMargin">
+             <number>10</number>
+            </property>
+            <property name="rightMargin">
+             <number>10</number>
+            </property>
             <item>
              <widget class="QPushButton" name="pushButtonFilter">
               <property name="text">
@@ -670,18 +715,21 @@ If the checkbox &quot;inverse search&quot; is checked a file is found only if th
             <item>
              <widget class="QLabel" name="label_11">
               <property name="text">
-               <string>To hit:</string>
+               <string>Pagesize:</string>
               </property>
              </widget>
             </item>
             <item>
-             <widget class="ReComboBox" name="comboBoxToHit">
+             <widget class="ReComboBox" name="comboBoxPageSize">
               <property name="maximumSize">
                <size>
                 <width>100</width>
                 <height>16777215</height>
                </size>
               </property>
+              <property name="toolTip">
+               <string>Maximal number of hits in the list below</string>
+              </property>
               <property name="editable">
                <bool>true</bool>
               </property>