]> gitweb.hamatoma.de Git - reqt/commitdiff
Refind: works with separate file finder thread
authorhama <hama@siduction.net>
Sun, 20 Dec 2015 17:42:41 +0000 (18:42 +0100)
committerhama <hama@siduction.net>
Sun, 20 Dec 2015 17:42:41 +0000 (18:42 +0100)
* GUI manipulation only in main thread
* layout changed: 4 lines in the header
* stop after maximal hits
* clear file table + append results to existing results
* new layout for export

13 files changed:
appl/refind/dialogfileplaceholder.ui
appl/refind/filefinder.cpp
appl/refind/filefinder.hpp
appl/refind/mainwindow.cpp
appl/refind/mainwindow.hpp
appl/refind/mainwindow.ui
appl/refind/refind.pro
appl/refind/utils.cpp
appl/refind/utils.hpp
base/rebase.hpp
gui/ReGuiQueue.cpp [new file with mode: 0644]
gui/ReGuiQueue.hpp [new file with mode: 0644]
gui/regui.hpp

index f274a2aca220b9a316fe47fa377215c2e6f3308b..1facfacc1d3398ad0a2fec783d47e8ffca201b34 100644 (file)
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>800</width>
-    <height>429</height>
+    <height>500</height>
    </rect>
   </property>
   <property name="windowTitle">
      </item>
      <item row="2" column="1">
       <property name="text">
-       <string notr="true">doc</string>
+       <string notr="true">/home/bob/doc</string>
       </property>
      </item>
      <item row="2" column="2">
       <property name="text">
-       <string>relative path</string>
+       <string>path without node</string>
       </property>
      </item>
      <item row="3" column="0">
index 2869c343fe0809a536ca2955005f0da8f0da7f38..259a2b0f0b91e72e95336a8b0f4079fb6e24d18a 100644 (file)
@@ -21,7 +21,6 @@
  * Constructor.
  */
 FileFinder::FileFinder() :
-                       m_lines(0),
                        m_patterns(),
                        m_antiPatterns(),
                        m_minSize(0),
@@ -37,15 +36,26 @@ FileFinder::FileFinder() :
                        m_textFinder(NULL),
                        m_table(NULL),
                        m_statistics(),
-                       m_announcer(NULL),
-                       m_observer(NULL){
-    m_youngerThan.setMSecsSinceEpoch(0);
-    m_olderThan.setMSecsSinceEpoch(0);
+                       m_guiQueue(NULL),
+                       m_maxHits(0){
+       m_youngerThan.setMSecsSinceEpoch(0);
+       m_olderThan.setMSecsSinceEpoch(0);
 }
 
+/**
+ * Destructor.
+ */
 FileFinder::~FileFinder(){
 }
 
+/**
+ * Resets the instance.
+ */
+void FileFinder::clear()
+{
+       m_statistics.clear();
+}
+
 /**
  * Returns a string representation of the filesize.
  *
@@ -54,7 +64,7 @@ FileFinder::~FileFinder(){
  */
 QString fileSize(int64_t size){
    QString rc;
-   rc.sprintf("%.6f", (double) size / 1000000.0);
+   rc.sprintf("%12.6f", (double) size / 1000000.0);
    return rc;
 }
 /**
@@ -114,6 +124,7 @@ void FileFinder::fillTable(const QString& path, int depth){
    QList<QRegExp*>::const_iterator it2;
    QList <QFileInfo>::const_iterator it;
    clock_t nextUpdate = clock() + CLOCKS_PER_SEC;
+   QString row, size, type, modified;
    for (it = entries.begin(); it != entries.end(); ++it){
          node = it->fileName();
          if (node == "." || node == "..")
@@ -128,42 +139,42 @@ void FileFinder::fillTable(const QString& path, int depth){
          if (ignore)
                  continue;
          if (depth >= m_minDepth && isValid(*it)){
-                if (m_lines >= m_table->rowCount()){
-                       m_table->setRowCount(m_lines + 500);
-                }
                 bool isDir = it->isDir();
                 if (isDir)
                        m_statistics.m_dirs++;
                 else
                        m_statistics.m_files++;
-                m_table->setItem(m_lines, TC_NODE, new QTableWidgetItem(node));
+                row.clear();
+                // TC_NODE, TC_EXT, TC_SIZE, TC_MODIFIED, TC_TYPE, TC_PATH
                 int ix = node.lastIndexOf('.');
                 ext = ix <= 0 ? "" : node.mid(ix + 1).toLower();
-                m_table->setItem(m_lines, TC_EXT, new QTableWidgetItem(ext));
-                m_table->setItem(m_lines, TC_TYPE, new QTableWidgetItem(typeOf(*it)));
-                m_table->setItem(m_lines, TC_PATH, new QTableWidgetItem(path));
-                QTableWidgetItem* item = new QTableWidgetItem(
-                       isDir ? "" : fileSize(it->size()));
+                type = typeOf(*it);
+                if (isDir)
+                        size.clear();
+                else
+                        size = fileSize(it->size());
+                modified = it->lastModified().toString("yyyy.MM.dd/hh:mm:ss");
+                row.reserve(6 + node.length() + ext.length() + size.length()
+                                        + modified.length() + type.length() + path.length());
+                row.append('\t').append(node).append('\t').append(ext);
+                row.append('\t').append(size).append('\t').append(modified);
+                row.append('\t').append(type).append('\t').append(path);
                 if (!isDir)
                        m_statistics.m_bytes += it->size();
-                item->setTextAlignment(Qt::AlignRight);
-                m_table->setItem(m_lines, TC_SIZE, item);
-                m_table->setItem(m_lines, TC_MODIFIED,
-                       new QTableWidgetItem(
-                          it->lastModified().toString("yyyy.MM.dd/hh:mm:ss")));
-    }
-    clock_t now = clock();
-    if (now > nextUpdate){
-      m_table->setRowCount(m_lines);
-      if (m_announcer != NULL)
-          m_announcer->say(LOG_INFO, path);
-      nextUpdate = now + CLOCKS_PER_SEC;
-    }
+                m_guiQueue->pushBack(ReGuiQueueItem(ReGuiQueueItem::NewTableRow, m_table, row));
+                if (m_maxHits-- < 0)
+                        break;
+       }
+       clock_t now = clock();
+       if (now > nextUpdate){
+         m_guiQueue->pushBack(ReGuiQueueItem(ReGuiQueueItem::LogMessage, NULL, path));
+         nextUpdate = now + CLOCKS_PER_SEC;
+       }
    }
    for (it2 = antiPatterns.begin(); it2 != antiPatterns.end(); ++it2){
           delete *it2;
    }
-   if (depth < m_maxDepth || m_maxDepth < 0){
+   if (depth < m_maxDepth || m_maxDepth < 0 && m_maxHits > 0){
          entries = dir.entryInfoList(
                 QDir::NoSymLinks | QDir::NoDotAndDotDot | QDir::AllDirs, QDir::NoSort);
          bool filtered = m_excludedDirs.length() > 0;
@@ -173,7 +184,6 @@ void FileFinder::fillTable(const QString& path, int depth){
                        fillTable(path + QDir::separator() + node, depth + 1);
          }
    }
-   m_table->setRowCount(m_lines);
 }
 /**
  * Runs a file search in a second thread.
@@ -187,29 +197,20 @@ void FileFinder::run()
  * Fills the table with the data of the filtered files of a given directory.
  */
 void FileFinder::search(){
-       if (! m_append){
-               m_statistics.clear();
-               m_lines = 0;
-       }
        clock_t start = clock();
-       m_table->setSortingEnabled(false);
-    QString path = ReFileUtils::nativePath(m_baseDir);
-    path = ReQStringUtils::chomp(path, OS_SEPARATOR);
-    fillTable(path, 0);
+       m_statistics.clear();
+       QString path = ReFileUtils::nativePath(m_baseDir);
+       path = ReQStringUtils::chomp(path, OS_SEPARATOR);
+       fillTable(path, 0);
        m_statistics.m_runtimeSeconds = (double) (clock() - start)
           / CLOCKS_PER_SEC;
-       if (m_announcer != NULL){
-               QString msg;
-               msg.sprintf(
-                       I18N::s2b(QObject::tr(
-                         "Found: %d dir(s) and %d file(s) with %.6f MByte. Duration of the search: %.3f sec")),
-                  m_statistics.m_dirs, m_statistics.m_files,
-                  m_statistics.m_bytes / 1000000.0, m_statistics.m_runtimeSeconds);
-               m_announcer->say(LOG_INFO, msg);
-       }
-       m_table->setSortingEnabled(true);
-       if (m_observer != NULL)
-               m_observer->notify("ready");
+       QString msg;
+       msg.sprintf(
+                               I18N::s2b(QObject::tr(
+                                                         "Found: %d dir(s) and %d file(s) with %.6f MByte. Duration of the search: %.3f sec")),
+                               m_statistics.m_dirs, m_statistics.m_files,
+                               m_statistics.m_bytes / 1000000.0, m_statistics.m_runtimeSeconds);
+       m_guiQueue->pushBack(ReGuiQueueItem(ReGuiQueueItem::ReadyMessage, NULL, msg));
 }
 
 /**
@@ -257,20 +258,26 @@ bool FileFinder::isValid(const QFileInfo& file){
    return rc;
 }
 
-void FileFinder::setAppend(bool append)
+/**
+ * Sets the maximal hit count.
+ *
+ * @param maxHits      the maximal hit count
+ */
+void FileFinder::setMaxHits(int maxHits)
 {
-       m_append = append;
+       m_maxHits = maxHits;
 }
 
 /**
- * Sets the announcer for the summary message at the end.
+ * Sets the gui queue for exchanging data to the main tread.
  *
- * @param announcer    the announcer
+ * @param guiQueue     the gui queue
  */
-void FileFinder::setAnnouncer(ReAnnouncer* announcer)
+void FileFinder::setGuiQueue(ReGuiQueue* guiQueue)
 {
-       m_announcer = announcer;
+       m_guiQueue = guiQueue;
 }
+
 /**
  * Sets the base directory.
  *
index 82926335e464f37d3be36cf9492e946f137c2c9a..0916cfea5557ab30923afa1f6b36aefef1292204 100644 (file)
@@ -22,6 +22,7 @@ public:
    FileFinder();
    ~FileFinder();
 public:
+   void clear();
    void fillTable(const QString& path, int depth);
    void run();
    void search();
@@ -30,7 +31,9 @@ public:
    void setBaseDir(const QString& baseDir);
    void setFiletypes(const QDir::Filters& filetypes);
    void setExcludedDirs(const QStringList& excludedDirs);
+   void setGuiQueue(ReGuiQueue* guiQueue);
    void setMaxDepth(int maxDepth);
+   void setMaxHits(int maxHits);
    void setMaxSize(const int64_t& maxSize);
    void setMinDepth(int minDepth);
    void setMinSize(const int64_t& minSize);
@@ -45,7 +48,6 @@ private:
    bool isExcludedDir(const QString& node);
    bool isValid(const QFileInfo& file);
 private:
-   int m_lines;
    QStringList m_patterns;
    QStringList m_antiPatterns;
    int64_t m_minSize;
@@ -62,9 +64,9 @@ private:
    TextFinder* m_textFinder;
    QTableWidget* m_table;
    Statistics m_statistics;
-   ReAnnouncer* m_announcer;
    ReObserver* m_observer;
-   bool m_append;
+   ReGuiQueue* m_guiQueue;
+   int m_maxHits;
 };
 
 #endif // FILEFINDER_HPP
index b911aa541c1a3edb128ef0c32cff6049e58587eb..cd47be3a0bceeecd8c01d25308b5cd68e598b099 100644 (file)
@@ -54,7 +54,9 @@ MainWindow::MainWindow(const QString& startDir, const QString& homeDir,
                        m_storageFile(),
                        m_contextHandlers(),
                        m_logger(new ReMemoryLogger()),
-                       m_finder(NULL){
+                       m_finder(NULL),
+                       m_guiQueue(),
+                       m_guiTimer(new QTimer(this)){
    ui->setupUi(this);
    initializeHome();
    m_statusMessage = new QLabel(tr("Welcome at refind"));
@@ -103,12 +105,16 @@ MainWindow::MainWindow(const QString& startDir, const QString& homeDir,
    m_horizontalHeader = ui->tableWidget->horizontalHeader();
    connect(m_horizontalHeader, SIGNAL(sectionClicked ( int ) ),
                        this, SLOT(headerClicked ( int ) ));
+   connect(m_guiTimer, SIGNAL(timeout()), this, SLOT(guiTimerUpdate()));
    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, 75);
    prepareContextMenu();
+   m_guiTimer->start(100);
+   bool active = m_guiTimer->isActive();
+   active = ! active;
 }
 
 /**
@@ -432,6 +438,37 @@ void MainWindow::fullNameToClipboard(){
    }
 }
 
+/**
+ * Callback method of the GUI timer.
+ */
+void MainWindow::guiTimerUpdate()
+{
+       int count = m_guiQueue.count();
+       while(count-- > 0){
+               ReGuiQueueItem item = m_guiQueue.popFront();
+               if (item.m_type == ReGuiQueueItem::Undef)
+                       break;
+               if (! item.apply()){
+                       switch (item.m_type){
+                       case ReGuiQueueItem::ReadyMessage:
+                               say(LOG_INFO, item.m_value);
+                               m_statistics = m_finder->statistics();
+                               ui->pushButtonSearch->setEnabled(true);
+                               ui->pushButtonSearch2->setEnabled(true);
+                               break;
+                       case ReGuiQueueItem::LogMessage:
+                               say(LOG_INFO, item.m_value);
+                               break;
+                       default:
+                               say(LOG_ERROR, "unknown item type: " + QString::number(item.m_type)
+                                       + " " + item.m_value);
+                               break;
+                       }
+
+               }
+       }
+}
+
 /**
  * Handle the "copy to clipboard" entry from the context menu.
  *
@@ -636,11 +673,6 @@ void MainWindow::headerPlaceholder(){
  */
 ReObserver::ReturnCode MainWindow::notify(const char* message)
 {
-       if (strcmp(message, "ready") == 0){
-               ui->pushButtonSearch->setEnabled(true);
-               ui->pushButtonSearch2->setEnabled(true);
-        m_statistics = m_finder->statistics();
-       }
        return ReObserver::SUCCESS;
 }
 
@@ -684,11 +716,11 @@ msgBox.exec();
 }
 
 inline QString addEsc(const QString& text){
-    QString rc = text;
+       QString rc = text;
 #if defined WIN32
-    rc.replace("\\", "\\\\");
+       rc.replace("\\", "\\\\");
 #endif
-    return rc;
+       return rc;
 }
 
 /**
@@ -698,17 +730,17 @@ inline QString addEsc(const QString& text){
  */
 void MainWindow::buildGlobalPlaceholders(QMap <QString, QString>& hash){
 
-hash.insert("filepatterns", addEsc(ui->comboBoxFilePatterns->currentText()));
-hash.insert("base", m_lastBaseDir.absolutePath());
-hash.insert("textpattern", addEsc(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", addEsc(ui->comboBoxFilePatterns->currentText()));
+       hash.insert("base", m_lastBaseDir.absolutePath());
+       hash.insert("textpattern", addEsc(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 the placeholders valid in header and footer.
@@ -801,8 +833,12 @@ storage.close();
  * @param finder       OUT: the finder to populate
  */
 void MainWindow::populateFinder(FileFinder& finder){
+       if (! ui->checkBoxAppend->isChecked()){
+               ui->tableWidget->setRowCount(0);
+               m_statistics.clear();
+       }
        finder.setObserver(this);
-    finder.setAnnouncer(this);
+       finder.setGuiQueue(&this->m_guiQueue);
        finder.setBaseDir(comboText(ui->comboBoxDirectory));
        finder.setTable(ui->tableWidget);
        m_lastBaseDir.cd(comboText(ui->comboBoxDirectory));
@@ -812,8 +848,8 @@ void MainWindow::populateFinder(FileFinder& finder){
        finder.setYoungerThan(comboDate(ui->comboBoxYounger));
        finder.setMinDepth(comboInt(ui->comboBoxMinDepth, 0));
        finder.setMaxDepth(comboInt(ui->comboBoxMaxDepth, -1));
+       finder.setMaxHits(comboInt(ui->comboBoxMaxHits, 0x7fffffff));
        finder.setFiletypes(buildFileTypes());
-       finder.setAppend(ui->checkBoxAppend->isChecked());
        QStringList patterns;
        QString value = comboText(ui->comboBoxFilePatterns);
        if (!value.isEmpty())
@@ -848,6 +884,8 @@ void MainWindow::search(){
           guiError(ui->comboBoxDirectory, tr("not a directory: ") + path);
        else{
                QApplication::setOverrideCursor (QCursor(Qt::WaitCursor));
+               ui->pushButtonSearch->setEnabled(false);
+               ui->pushButtonSearch->setEnabled(false);
                if (m_finder == NULL)
                        m_finder = new FileFinder;
                populateFinder(*m_finder);
@@ -907,7 +945,7 @@ QDir dir(path);
 if (dir.exists()){
    dir.cdUp();
    if (dir.exists()){
-      path = ReFileUtils::nativePath(dir.absolutePath());
+         path = ReFileUtils::nativePath(dir.absolutePath());
          ui->comboBoxDirectory->setEditText(path);
          setInHistory(ui->comboBoxDirectory, path);
    }
index d7bb21188b98357ef0a82c97fa25d0af36dbeadb..db260f75a4b3a53db7fc1dc0dac8b35015b99b31 100644 (file)
@@ -36,7 +36,7 @@ enum TableColumns {
 };
 class FileFinder;
 
-class MainWindow: public QMainWindow, public ReGuiValidator, public ReObserver {
+class MainWindow: public QMainWindow, public ReGuiValidator, protected ReObserver{
 
    Q_OBJECT
 
@@ -60,6 +60,7 @@ private slots:
    void filePlaceholder();
    void footerPlaceholder();
    void fullNameToClipboard();
+   void guiTimerUpdate();
    void handleTableContextMenu(const QPoint& position);
    void headerClicked(int col);
    void headerPlaceholder();
@@ -107,6 +108,8 @@ private:
    ContextHandlerList m_contextHandlers;
    ReLogger* m_logger;
    FileFinder* m_finder;
+   ReGuiQueue m_guiQueue;
+   QTimer* m_guiTimer;
 };
 
 #endif // MAINWINDOW_HPP
index e66609762e6f5b78183f7d6cc5388b81ba0e709c..588902498852ffa1d057a7810fdfae5013cf8e26 100644 (file)
@@ -31,7 +31,7 @@
         <property name="maximumSize">
          <size>
           <width>16777215</width>
-          <height>150</height>
+          <height>175</height>
          </size>
         </property>
         <property name="currentIndex">
          <layout class="QHBoxLayout" name="horizontalLayout_4">
           <item>
            <layout class="QGridLayout" name="gridLayout" columnstretch="0,0,0,0,0,0,0">
+            <item row="3" column="0" colspan="2">
+             <widget class="QPushButton" name="pushButtonSearch">
+              <property name="toolTip">
+               <string>Execute the search</string>
+              </property>
+              <property name="text">
+               <string>&amp;Run search</string>
+              </property>
+              <property name="icon">
+               <iconset>
+                <normaloff>:/main/icons/action_go.gif</normaloff>
+                <normalon>:/main/icons/action_go.png</normalon>:/main/icons/action_go.gif</iconset>
+              </property>
+              <property name="shortcut">
+               <string>Ctrl+F</string>
+              </property>
+              <property name="autoDefault">
+               <bool>true</bool>
+              </property>
+              <property name="default">
+               <bool>true</bool>
+              </property>
+             </widget>
+            </item>
             <item row="0" column="0">
              <widget class="QLabel" name="label">
               <property name="maximumSize">
@@ -57,7 +81,7 @@
               </property>
              </widget>
             </item>
-            <item row="2" column="5" colspan="2">
+            <item row="1" column="5" colspan="2">
              <layout class="QHBoxLayout" name="horizontalLayout">
               <item>
                <widget class="QCheckBox" name="checkBoxDirs">
                 </property>
                </spacer>
               </item>
-              <item>
-               <widget class="QPushButton" name="pushButtonClear">
-                <property name="toolTip">
-                 <string>Clears the file table</string>
-                </property>
-                <property name="text">
-                 <string>C&amp;lear</string>
-                </property>
-                <property name="shortcut">
-                 <string notr="true"/>
-                </property>
-                <property name="checkable">
-                 <bool>false</bool>
-                </property>
-               </widget>
-              </item>
-              <item>
-               <widget class="QCheckBox" name="checkBoxAppend">
-                <property name="toolTip">
-                 <string>Adds the result of the next search to the table</string>
-                </property>
-                <property name="text">
-                 <string>Append</string>
-                </property>
-               </widget>
-              </item>
              </layout>
             </item>
-            <item row="3" column="1">
+            <item row="2" column="1">
              <widget class="QComboBox" name="comboBoxTextPattern">
               <property name="minimumSize">
                <size>
               </property>
              </widget>
             </item>
-            <item row="3" column="0">
+            <item row="2" column="0">
              <widget class="QLabel" name="label_3">
               <property name="maximumSize">
                <size>
               </property>
              </widget>
             </item>
-            <item row="1" column="5">
-             <layout class="QVBoxLayout" name="verticalLayout_4"/>
-            </item>
-            <item row="2" column="0">
+            <item row="1" column="0">
              <widget class="QLabel" name="label_2">
               <property name="maximumSize">
                <size>
               </property>
              </widget>
             </item>
-            <item row="2" column="1">
+            <item row="1" column="1">
              <widget class="QComboBox" name="comboBoxFilePatterns">
               <property name="toolTip">
                <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;A comma (',') separated list of filename patterns. A prefix of '-'  means inversion: if a filename matches it will not be found.&lt;/p&gt;&lt;p&gt;Example: *.txt,*.odt&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
               </property>
              </widget>
             </item>
-            <item row="3" column="5" colspan="2">
+            <item row="2" column="5" colspan="2">
              <layout class="QHBoxLayout" name="horizontalLayout_5">
               <item>
                <widget class="QCheckBox" name="checkBoxRegExpr">
               </item>
              </layout>
             </item>
-            <item row="0" column="6">
-             <widget class="QPushButton" name="pushButtonSearch">
-              <property name="toolTip">
-               <string>Execute the search</string>
+            <item row="2" column="2">
+             <widget class="QCheckBox" name="checkBoxTextIgnoreCase">
+              <property name="maximumSize">
+               <size>
+                <width>125</width>
+                <height>16777215</height>
+               </size>
               </property>
               <property name="text">
-               <string>&amp;Run search</string>
-              </property>
-              <property name="icon">
-               <iconset>
-                <normaloff>:/main/icons/action_go.gif</normaloff>
-                <normalon>:/main/icons/action_go.png</normalon>:/main/icons/action_go.gif</iconset>
-              </property>
-              <property name="shortcut">
-               <string>Ctrl+F</string>
-              </property>
-              <property name="autoDefault">
-               <bool>true</bool>
-              </property>
-              <property name="default">
-               <bool>true</bool>
+               <string>Ignore case</string>
               </property>
              </widget>
             </item>
               </item>
              </layout>
             </item>
+            <item row="1" column="2">
+             <widget class="QCheckBox" name="checkBoxFiles">
+              <property name="text">
+               <string>Files</string>
+              </property>
+              <property name="checked">
+               <bool>true</bool>
+              </property>
+             </widget>
+            </item>
             <item row="0" column="1" colspan="2">
              <widget class="QComboBox" name="comboBoxDirectory">
               <property name="toolTip">
               </property>
              </widget>
             </item>
+            <item row="3" column="5">
+             <layout class="QFormLayout" name="formLayout">
+              <item row="0" column="0">
+               <widget class="QLabel" name="label_16">
+                <property name="text">
+                 <string>Stop after:</string>
+                </property>
+               </widget>
+              </item>
+              <item row="0" column="1">
+               <widget class="QComboBox" name="comboBoxMaxHits">
+                <property name="editable">
+                 <bool>true</bool>
+                </property>
+                <property name="currentText">
+                 <string notr="true"/>
+                </property>
+               </widget>
+              </item>
+             </layout>
+            </item>
             <item row="3" column="2">
-             <widget class="QCheckBox" name="checkBoxTextIgnoreCase">
-              <property name="maximumSize">
-               <size>
-                <width>125</width>
-                <height>16777215</height>
-               </size>
+             <widget class="QCheckBox" name="checkBoxAppend">
+              <property name="toolTip">
+               <string>Adds the result of the next search to the table</string>
               </property>
               <property name="text">
-               <string>ignore case</string>
+               <string>Append</string>
               </property>
              </widget>
             </item>
-            <item row="2" column="2">
-             <widget class="QCheckBox" name="checkBoxFiles">
+            <item row="3" column="6">
+             <widget class="QPushButton" name="pushButtonClear">
+              <property name="toolTip">
+               <string>Clears the file table</string>
+              </property>
               <property name="text">
-               <string>Files</string>
+               <string>C&amp;lear</string>
               </property>
-              <property name="checked">
-               <bool>true</bool>
+              <property name="shortcut">
+               <string notr="true"/>
+              </property>
+              <property name="checkable">
+               <bool>false</bool>
               </property>
              </widget>
             </item>
               </property>
              </widget>
             </item>
+            <item row="0" column="2">
+             <widget class="QLabel" name="label_6">
+              <property name="maximumSize">
+               <size>
+                <width>200</width>
+                <height>16777215</height>
+               </size>
+              </property>
+              <property name="text">
+               <string>Younger than:</string>
+              </property>
+             </widget>
+            </item>
             <item row="0" column="0">
              <widget class="QLabel" name="label_4">
               <property name="maximumSize">
               </property>
              </widget>
             </item>
-            <item row="0" column="2">
-             <widget class="QLabel" name="label_6">
+            <item row="1" column="2">
+             <widget class="QLabel" name="label_7">
               <property name="maximumSize">
                <size>
                 <width>200</width>
                </size>
               </property>
               <property name="text">
-               <string>Younger than:</string>
+               <string>Older than:</string>
+              </property>
+             </widget>
+            </item>
+            <item row="1" column="4">
+             <widget class="QLabel" name="label_12">
+              <property name="text">
+               <string>Max. Depth:</string>
+              </property>
+             </widget>
+            </item>
+            <item row="2" column="1" colspan="3">
+             <widget class="QComboBox" name="comboBoxExcludedDirs">
+              <property name="toolTip">
+               <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;a comma (',') separated list of directory names not entered for the search.&lt;/p&gt;&lt;p&gt;Example: .git,.cache&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+              </property>
+              <property name="editable">
+               <bool>true</bool>
+              </property>
+             </widget>
+            </item>
+            <item row="0" column="4">
+             <widget class="QLabel" name="label_11">
+              <property name="text">
+               <string>Min. Depth:</string>
               </property>
              </widget>
             </item>
-            <item row="2" column="4" colspan="2">
+            <item row="2" column="0">
+             <widget class="QLabel" name="label_13">
+              <property name="text">
+               <string>Excluded Dirs:</string>
+              </property>
+             </widget>
+            </item>
+            <item row="3" column="1" colspan="4">
              <widget class="QPushButton" name="pushButtonSearch2">
               <property name="text">
                <string>&amp;Run search</string>
               </property>
              </widget>
             </item>
-            <item row="1" column="2">
-             <widget class="QLabel" name="label_7">
+           </layout>
+          </item>
+         </layout>
+        </widget>
+        <widget class="QWidget" name="tabExport">
+         <attribute name="title">
+          <string>&amp;Export</string>
+         </attribute>
+         <layout class="QVBoxLayout" name="verticalLayout_5">
+          <item>
+           <layout class="QGridLayout" name="gridLayout_3">
+            <item row="2" column="1" colspan="3">
+             <widget class="QComboBox" name="comboBoxHeader">
+              <property name="minimumSize">
+               <size>
+                <width>300</width>
+                <height>0</height>
+               </size>
+              </property>
               <property name="maximumSize">
                <size>
-                <width>200</width>
+                <width>16777215</width>
+                <height>16777215</height>
+               </size>
+              </property>
+              <property name="toolTip">
+               <string>Text at the top of the export file</string>
+              </property>
+              <property name="editable">
+               <bool>true</bool>
+              </property>
+             </widget>
+            </item>
+            <item row="4" column="0">
+             <widget class="QPushButton" name="pushButtonExport">
+              <property name="toolTip">
+               <string>Exports file attributes (specified in the template line)  of each found files  found file in a textfile or clipboard</string>
+              </property>
+              <property name="text">
+               <string>&amp;Export</string>
+              </property>
+              <property name="icon">
+               <iconset resource="refind.qrc">
+                <normaloff>:/main/icons/database_save.png</normaloff>:/main/icons/database_save.png</iconset>
+              </property>
+              <property name="shortcut">
+               <string>Alt+E</string>
+              </property>
+             </widget>
+            </item>
+            <item row="3" column="4">
+             <widget class="QPushButton" name="pushButtonFooterPlaceholder">
+              <property name="maximumSize">
+               <size>
+                <width>50</width>
                 <height>16777215</height>
                </size>
               </property>
+              <property name="toolTip">
+               <string>Select a placeholder for the footer</string>
+              </property>
               <property name="text">
-               <string>Older than:</string>
+               <string>...</string>
               </property>
              </widget>
             </item>
-            <item row="2" column="1" colspan="3">
-             <widget class="QComboBox" name="comboBoxExcludedDirs">
+            <item row="3" column="1" colspan="3">
+             <widget class="QComboBox" name="comboBoxFooter">
               <property name="toolTip">
-               <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;a comma (',') separated list of directory names not entered for the search.&lt;/p&gt;&lt;p&gt;Example: .git,.cache&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+               <string>Text at the end of the export file</string>
               </property>
               <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>
-            <item row="0" column="4">
-             <widget class="QLabel" name="label_11">
+            <item row="3" column="0">
+             <widget class="QLabel" name="label_15">
               <property name="text">
-               <string>Min. Depth:</string>
+               <string>File footer:</string>
               </property>
              </widget>
             </item>
-            <item row="1" column="4">
-             <widget class="QLabel" name="label_12">
+            <item row="2" column="4">
+             <widget class="QPushButton" name="pushButtonHeaderPlaceholder">
+              <property name="maximumSize">
+               <size>
+                <width>50</width>
+                <height>16777215</height>
+               </size>
+              </property>
+              <property name="toolTip">
+               <string>Select a placeholder for the header</string>
+              </property>
               <property name="text">
-               <string>Max. Depth:</string>
+               <string>...</string>
               </property>
              </widget>
             </item>
             <item row="2" column="0">
-             <widget class="QLabel" name="label_13">
+             <widget class="QLabel" name="label_10">
               <property name="text">
-               <string>Excluded Dirs:</string>
+               <string>File header:</string>
+              </property>
+             </widget>
+            </item>
+            <item row="0" column="4">
+             <widget class="QPushButton" name="pushButtonFilePlaceholder">
+              <property name="maximumSize">
+               <size>
+                <width>50</width>
+                <height>16777215</height>
+               </size>
+              </property>
+              <property name="toolTip">
+               <string>Select a placeholder for the template</string>
+              </property>
+              <property name="text">
+               <string>...</string>
+              </property>
+             </widget>
+            </item>
+            <item row="0" column="0">
+             <widget class="QLabel" name="label_8">
+              <property name="text">
+               <string>Line template:</string>
+              </property>
+             </widget>
+            </item>
+            <item row="0" column="1" colspan="3">
+             <widget class="QComboBox" name="comboBoxTemplate">
+              <property name="toolTip">
+               <string>Template of a line for each file</string>
+              </property>
+              <property name="editable">
+               <bool>true</bool>
+              </property>
+              <property name="currentText">
+               <string notr="true">${full};${size};${modified}</string>
               </property>
              </widget>
             </item>
+            <item row="4" column="4">
+             <widget class="QPushButton" name="pushButtonPreview">
+              <property name="text">
+               <string>&amp;Preview</string>
+              </property>
+              <property name="icon">
+               <iconset resource="refind.qrc">
+                <normaloff>:/main/icons/eye.png</normaloff>:/main/icons/eye.png</iconset>
+              </property>
+             </widget>
+            </item>
+            <item row="4" column="1" colspan="3">
+             <layout class="QHBoxLayout" name="horizontalLayout_7" stretch="0,0,1,0">
+              <item>
+               <widget class="QRadioButton" name="radioButtonClipboard">
+                <property name="text">
+                 <string>Clipboard</string>
+                </property>
+                <property name="checked">
+                 <bool>true</bool>
+                </property>
+               </widget>
+              </item>
+              <item>
+               <widget class="QRadioButton" name="radioButtonFile">
+                <property name="text">
+                 <string>&amp;File:</string>
+                </property>
+                <property name="checked">
+                 <bool>false</bool>
+                </property>
+               </widget>
+              </item>
+              <item>
+               <widget class="QComboBox" name="comboBoxExportFile">
+                <property name="toolTip">
+                 <string>Name of the export file</string>
+                </property>
+                <property name="editable">
+                 <bool>true</bool>
+                </property>
+                <property name="currentText">
+                 <string>refind.result.txt</string>
+                </property>
+               </widget>
+              </item>
+              <item>
+               <widget class="QPushButton" name="pushButtonExportFile">
+                <property name="maximumSize">
+                 <size>
+                  <width>50</width>
+                  <height>16777215</height>
+                 </size>
+                </property>
+                <property name="toolTip">
+                 <string>Select the export file</string>
+                </property>
+                <property name="text">
+                 <string>...</string>
+                </property>
+               </widget>
+              </item>
+             </layout>
+            </item>
            </layout>
           </item>
          </layout>
         </widget>
-        <widget class="QWidget" name="tabExport">
-         <attribute name="title">
-          <string>&amp;Export</string>
-         </attribute>
-         <widget class="QLabel" name="label_14">
-          <property name="geometry">
-           <rect>
-            <x>515</x>
-            <y>106</y>
-            <width>85</width>
-            <height>29</height>
-           </rect>
-          </property>
-          <property name="text">
-           <string/>
-          </property>
-         </widget>
-         <widget class="QWidget" name="layoutWidget">
-          <property name="geometry">
-           <rect>
-            <x>10</x>
-            <y>11</y>
-            <width>981</width>
-            <height>116</height>
-           </rect>
-          </property>
-          <layout class="QGridLayout" name="gridLayout_3">
-           <item row="1" column="0">
-            <widget class="QLabel" name="label_9">
-             <property name="text">
-              <string>Export file:</string>
-             </property>
-            </widget>
-           </item>
-           <item row="0" column="1">
-            <layout class="QHBoxLayout" name="horizontalLayout_7">
-             <item>
-              <widget class="QComboBox" name="comboBoxTemplate">
-               <property name="toolTip">
-                <string>Template of a line for each file</string>
-               </property>
-               <property name="editable">
-                <bool>true</bool>
-               </property>
-               <property name="currentText">
-                <string notr="true">${full};${size};${modified}</string>
-               </property>
-              </widget>
-             </item>
-             <item>
-              <widget class="QPushButton" name="pushButtonFilePlaceholder">
-               <property name="maximumSize">
-                <size>
-                 <width>50</width>
-                 <height>16777215</height>
-                </size>
-               </property>
-               <property name="toolTip">
-                <string>Select a placeholder for the template</string>
-               </property>
-               <property name="text">
-                <string>...</string>
-               </property>
-              </widget>
-             </item>
-            </layout>
-           </item>
-           <item row="2" column="1">
-            <layout class="QHBoxLayout" name="horizontalLayout_8">
-             <item>
-              <widget class="QRadioButton" name="radioButtonFile">
-               <property name="text">
-                <string>&amp;File</string>
-               </property>
-               <property name="checked">
-                <bool>false</bool>
-               </property>
-              </widget>
-             </item>
-             <item>
-              <widget class="QRadioButton" name="radioButtonClipboard">
-               <property name="text">
-                <string>Clipboard</string>
-               </property>
-               <property name="checked">
-                <bool>true</bool>
-               </property>
-              </widget>
-             </item>
-             <item>
-              <spacer name="horizontalSpacer">
-               <property name="orientation">
-                <enum>Qt::Horizontal</enum>
-               </property>
-               <property name="sizeHint" stdset="0">
-                <size>
-                 <width>40</width>
-                 <height>20</height>
-                </size>
-               </property>
-              </spacer>
-             </item>
-             <item>
-              <widget class="QPushButton" name="pushButtonPreview">
-               <property name="text">
-                <string>&amp;Preview</string>
-               </property>
-               <property name="icon">
-                <iconset resource="refind.qrc">
-                 <normaloff>:/main/icons/eye.png</normaloff>:/main/icons/eye.png</iconset>
-               </property>
-              </widget>
-             </item>
-            </layout>
-           </item>
-           <item row="1" column="1">
-            <layout class="QHBoxLayout" name="horizontalLayout_6">
-             <item>
-              <widget class="QComboBox" name="comboBoxExportFile">
-               <property name="toolTip">
-                <string>Name of the export file</string>
-               </property>
-               <property name="editable">
-                <bool>true</bool>
-               </property>
-               <property name="currentText">
-                <string>refind.result.txt</string>
-               </property>
-              </widget>
-             </item>
-             <item>
-              <widget class="QPushButton" name="pushButtonExportFile">
-               <property name="maximumSize">
-                <size>
-                 <width>50</width>
-                 <height>16777215</height>
-                </size>
-               </property>
-               <property name="toolTip">
-                <string>Select the export file</string>
-               </property>
-               <property name="text">
-                <string>...</string>
-               </property>
-              </widget>
-             </item>
-            </layout>
-           </item>
-           <item row="2" column="3">
-            <widget class="QPushButton" name="pushButtonExport">
-             <property name="toolTip">
-              <string>Exports file attributes (specified in the template line)  of each found files  found file in a textfile or clipboard</string>
-             </property>
-             <property name="text">
-              <string>&amp;Export</string>
-             </property>
-             <property name="icon">
-              <iconset resource="refind.qrc">
-               <normaloff>:/main/icons/database_save.png</normaloff>:/main/icons/database_save.png</iconset>
-             </property>
-             <property name="shortcut">
-              <string>Alt+E</string>
-             </property>
-            </widget>
-           </item>
-           <item row="1" column="2">
-            <widget class="QLabel" name="label_15">
-             <property name="text">
-              <string>File footer:</string>
-             </property>
-            </widget>
-           </item>
-           <item row="0" column="0">
-            <widget class="QLabel" name="label_8">
-             <property name="text">
-              <string>Line template:</string>
-             </property>
-            </widget>
-           </item>
-           <item row="0" column="2">
-            <widget class="QLabel" name="label_10">
-             <property name="text">
-              <string>File header:</string>
-             </property>
-            </widget>
-           </item>
-           <item row="0" column="3">
-            <widget class="QComboBox" name="comboBoxHeader">
-             <property name="minimumSize">
-              <size>
-               <width>300</width>
-               <height>0</height>
-              </size>
-             </property>
-             <property name="maximumSize">
-              <size>
-               <width>16777215</width>
-               <height>16777215</height>
-              </size>
-             </property>
-             <property name="toolTip">
-              <string>Text at the top of the export file</string>
-             </property>
-             <property name="editable">
-              <bool>true</bool>
-             </property>
-            </widget>
-           </item>
-           <item row="1" column="3">
-            <widget class="QComboBox" name="comboBoxFooter">
-             <property name="toolTip">
-              <string>Text at the end of the export file</string>
-             </property>
-             <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>
-           <item row="0" column="4">
-            <widget class="QPushButton" name="pushButtonHeaderPlaceholder">
-             <property name="maximumSize">
-              <size>
-               <width>50</width>
-               <height>16777215</height>
-              </size>
-             </property>
-             <property name="toolTip">
-              <string>Select a placeholder for the header</string>
-             </property>
-             <property name="text">
-              <string>...</string>
-             </property>
-            </widget>
-           </item>
-           <item row="1" column="4">
-            <widget class="QPushButton" name="pushButtonFooterPlaceholder">
-             <property name="maximumSize">
-              <size>
-               <width>50</width>
-               <height>16777215</height>
-              </size>
-             </property>
-             <property name="toolTip">
-              <string>Select a placeholder for the footer</string>
-             </property>
-             <property name="text">
-              <string>...</string>
-             </property>
-            </widget>
-           </item>
-          </layout>
-         </widget>
-        </widget>
        </widget>
       </item>
       <item>
   <tabstop>comboBoxDirectory</tabstop>
   <tabstop>pushButtonUp</tabstop>
   <tabstop>pushButtonDirectory</tabstop>
-  <tabstop>pushButtonSearch</tabstop>
   <tabstop>comboBoxFilePatterns</tabstop>
   <tabstop>checkBoxFiles</tabstop>
   <tabstop>checkBoxDirs</tabstop>
   <tabstop>comboBoxMinDepth</tabstop>
   <tabstop>comboBoxMaxDepth</tabstop>
   <tabstop>comboBoxExcludedDirs</tabstop>
-  <tabstop>pushButtonSearch2</tabstop>
-  <tabstop>comboBoxTemplate</tabstop>
-  <tabstop>pushButtonFilePlaceholder</tabstop>
-  <tabstop>comboBoxHeader</tabstop>
-  <tabstop>pushButtonHeaderPlaceholder</tabstop>
-  <tabstop>comboBoxExportFile</tabstop>
-  <tabstop>pushButtonExportFile</tabstop>
-  <tabstop>comboBoxFooter</tabstop>
-  <tabstop>pushButtonFooterPlaceholder</tabstop>
-  <tabstop>radioButtonFile</tabstop>
-  <tabstop>radioButtonClipboard</tabstop>
-  <tabstop>pushButtonExport</tabstop>
-  <tabstop>tabWidget</tabstop>
   <tabstop>tableWidget</tabstop>
  </tabstops>
  <resources>
index 619646a2c6b618ba1f56dd60672ef4509b053a6a..16dcfadda9a1317e2d557568d0e6ba9e7817666d 100644 (file)
@@ -30,7 +30,8 @@ SOURCES += main.cpp\
         dialogfileplaceholder.cpp \
         utils.cpp \
         dialogoptions.cpp \
-        filetablewidget.cpp
+        filetablewidget.cpp \
+    ../../gui/ReGuiQueue.cpp
 
 
 HEADERS  += mainwindow.hpp \
@@ -46,7 +47,8 @@ HEADERS  += mainwindow.hpp \
         dialogfileplaceholder.hpp \
         utils.hpp \
         dialogoptions.hpp \
-        filetablewidget.hpp
+        filetablewidget.hpp \
+    ../../gui/ReGuiQueue.hpp
 
 
 FORMS    += mainwindow.ui \
index da9e65aade90b52fa22044ee718c4340ded889b5..c0c6cb13489f90c41f03e3b4d59ae006b352b50e 100644 (file)
@@ -231,3 +231,16 @@ void Statistics::clear(){
    m_bytes = 0;
    m_runtimeSeconds = 0;
 }
+
+/**
+ * Adds the result of another instance to the instance.
+ *
+ * @param source       instance to add
+ */
+void Statistics::add(Statistics& source)
+{
+       m_dirs += source.m_dirs;
+       m_bytes += source.m_bytes;
+       m_files += source.m_bytes;
+       m_runtimeSeconds += source.m_runtimeSeconds;
+}
index 5b162911a5957013a32583b60d252742b2cd0c8f..d6be1f185cf02a218502c555405666e820b45913 100644 (file)
@@ -22,14 +22,14 @@ enum {
 class ContextHandler {
 public:
    enum IntrinsicType {
-      IT_UNDEF, IT_COPY
+         IT_UNDEF, IT_COPY
    };
 
    enum DirMode {
-      DM_UNDEF, DM_TO_PARENT, DM_TO_FILE
+         DM_UNDEF, DM_TO_PARENT, DM_TO_FILE
    };
    enum FileType {
-      FT_UNDEF, FT_FILE, FT_DIR, FT_ALL
+         FT_UNDEF, FT_FILE, FT_DIR, FT_ALL
    };
 public:
    ContextHandler();
@@ -56,7 +56,7 @@ public:
    void clear();
    ContextHandlerList&copy(const ContextHandlerList& source);
    QList <ContextHandler*>& list(){
-      return m_list;
+         return m_list;
    }
    void save(ReStateStorage& storage);
    void restore(ReStateStorage& storage);
@@ -69,6 +69,7 @@ public:
    Statistics();
 public:
    void clear();
+   void add(Statistics& source);
 public:
    int m_dirs;
    int m_files;
index 18db3d35c3e5d72441bbd6c5b420f738e98fd996..8c7577c615fa4eb43e9fa6f8e2482af4a61f4c35 100644 (file)
@@ -47,6 +47,7 @@
 #include <QComboBox>
 #include <QComboBox>
 #include <QProcess>
+#include <QMutex>
 
 typedef unsigned char uint8_t;
 #if !defined __linux__
@@ -65,8 +66,9 @@ typedef QString ReString;
 #define OS_SEPARATOR_STR "/"
 #define OS_2nd_SEPARATOR '\\'
 #define OS_2nd_SEPARATOR_STR "\\"
-#define _mkdir(path) mkdir(path, -1)
 #define _memicmp memicmp
+#define _mkdir(path) mkdir(path, -1)
+#define _rmdir rmdir
 #else
 #define _strcasecmp _stricmp
 #define OS_SEPARATOR '\\'
@@ -147,7 +149,7 @@ inline int hexToInt(char hex, int defaultValue = -1){
  * @param value the value to round
  */
 inline int roundInt(double value) {
-    return (int) value < 0.0 ? ceil(value - 0.5) : floor(value + 0.5);
+       return (int) value < 0.0 ? ceil(value - 0.5) : floor(value + 0.5);
 }
 /** An observer can be informed about state changes.
  * Pure abstract class.
diff --git a/gui/ReGuiQueue.cpp b/gui/ReGuiQueue.cpp
new file mode 100644 (file)
index 0000000..8c61576
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+*/
+
+#include "base/rebase.hpp"
+#include "gui/regui.hpp"
+
+/**
+ * Constructor.
+ */
+ReGuiQueue::ReGuiQueue() :
+       m_locker()
+{
+}
+
+/**
+ * Adds an entry at the end of the the queue.
+ *
+ * This method can be used by all threads.
+ *
+ * @param item the item to add
+ */
+void ReGuiQueue::pushBack(const ReGuiQueueItem& item)
+{
+       m_locker.lock();
+       append(item);
+       m_locker.unlock();
+}
+
+/**
+ * Returns the number of elements.
+ *
+ * This method should be called only by the master thread.
+ *
+ * @return     the number of elements
+ */
+int ReGuiQueue::count() const
+{
+       // no locking is necessary: removing is done only by the same thread
+       return size();
+}
+
+/**
+ * Returns the first element and delete it from the queue.
+ *
+ * This method should be called only by the master thread.
+ *
+ * @return the first elements
+ */
+ReGuiQueueItem ReGuiQueue::popFront()
+{
+       m_locker.lock();
+       ReGuiQueueItem rc = takeFirst();
+       m_locker.unlock();
+       return rc;
+}
+
+/**
+ * Takes the info from the instance and put it into the widget.
+ *
+ * This method should only used by the master thread.
+ *
+ * @return     <code>true</code>: the info could be put into the widget<br>
+ *                     <code>false</code>: nothing is done
+ */
+bool ReGuiQueueItem::apply() const
+{
+       bool rc = m_widget != NULL;
+       if (rc){
+               switch(m_type){
+               case LabelText:
+                       reinterpret_cast<QLabel*>(m_widget)->setText(m_value);
+                       break;
+               case NewTableRow:
+               {
+                       QChar separator = m_value.at(0);
+                       QStringList list = m_value.mid(1).split(separator);
+                       QTableWidget* table = reinterpret_cast<QTableWidget*>(m_widget);
+                       int rowCount = table->rowCount();
+                       table->setRowCount(rowCount + 1);
+                       int cols = min(list.size(), table->columnCount());
+                       for (int ix = 0; ix < cols; ix++){
+                               table->setItem(rowCount, ix, new QTableWidgetItem(list.at(ix)));
+                       }
+                       break;
+               }
+               default:
+                       rc = false;
+                       break;
+               }
+       }
+       return rc;
+}
diff --git a/gui/ReGuiQueue.hpp b/gui/ReGuiQueue.hpp
new file mode 100644 (file)
index 0000000..4ae6587
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Licence:
+ * You can use and modify this file without any restriction.
+ * There is no warranty.
+ * You also can use the licence from http://www.wtfpl.net/.
+ * The original sources can be found on https://github.com/republib.
+*/
+
+#ifndef REGUIQUEUE_HPP
+#define REGUIQUEUE_HPP
+
+class ReGuiQueueItem {
+public:
+       enum WidgetType {
+               Undef, LabelText, NewTableRow, LogMessage, ReadyMessage,
+               UserDefined1, UserDefined2
+       };
+
+public:
+       /** Constructor.
+        */
+       ReGuiQueueItem():
+               m_type(Undef),
+               m_widget(NULL),
+               m_value(){
+       }
+
+       /** Constructor.
+        * @param type          widget type
+        * @param widget        NULL or the widget
+        * @param value         the value to set
+        */
+       ReGuiQueueItem(WidgetType type, QWidget* widget, const QString value) :
+               m_type(type),
+               m_widget(widget),
+               m_value(value){
+       }
+       /** Copy constructor.
+        * @param source        the source to copy
+        */
+       ReGuiQueueItem(const ReGuiQueueItem& source) :
+               m_type(source.m_type),
+               m_widget(source.m_widget),
+               m_value(source.m_value){
+       }
+       /** Assign operator.
+        * @param source        the source to copy
+        * @return                      the instance
+        */
+       ReGuiQueueItem& operator = (const ReGuiQueueItem& source){
+               m_type = source.m_type;
+               m_widget = source.m_widget;
+               m_value = source.m_value;
+               return *this;
+       }
+public:
+       bool apply() const;
+public:
+       WidgetType m_type;
+       QWidget* m_widget;
+       QString m_value;
+};
+
+/**
+ * Queue for exchange gui data for the main thread.
+ *
+ * Qt allows manipulating GUI elements only in the main thread.
+ * This queue allows the exchange of information from other threads.
+ */
+class ReGuiQueue : protected QVector<ReGuiQueueItem>
+{
+public:
+       ReGuiQueue();
+public:
+       int count() const;
+       ReGuiQueueItem popFront();
+       void pushBack(const ReGuiQueueItem& item);
+protected:
+       QMutex m_locker;
+};
+
+#endif // REGUIQUEUE_HPP
index 134bd06026054b0bd68e26e6a2b15d1256757de8..b459c51b5f21579c11544107f8e9f2b6f8a4ec23 100644 (file)
@@ -13,6 +13,9 @@
 #define REGUI_HPP
 
 #include <QPushButton>
+#include <QLabel>
+#include <QTableWidget>
+#include "gui/ReGuiQueue.hpp"
 #include "gui/ReStateStorage.hpp"
 #include "gui/ReGuiValidator.hpp"
 #include "gui/ReEdit.hpp"