]> gitweb.hamatoma.de Git - reqt/commitdiff
reimgconvert: refactoring
authorhama <hama@siduction.net>
Wed, 20 Jan 2016 11:32:58 +0000 (12:32 +0100)
committerhama <hama@siduction.net>
Wed, 20 Jan 2016 11:58:07 +0000 (12:58 +0100)
* guiQueue moved to new class ReGuiApplication
* recursive conversion, finding other files works
* common home directory .reappl

16 files changed:
appl/reimgconvert/converter.cpp
appl/reimgconvert/converter.hpp
appl/reimgconvert/mainwindow.cpp
appl/reimgconvert/mainwindow.hpp
appl/reimgconvert/mainwindow.ui
appl/reimgconvert/reimgconvert.pro
base/ReFileUtils.cpp
base/ReQStringUtils.cpp
base/rebase.hpp
gui/ReGuiApplication.cpp [new file with mode: 0644]
gui/ReGuiApplication.hpp [new file with mode: 0644]
gui/ReGuiQueue.hpp
gui/ReStateStorage.cpp
gui/ReStateStorage.hpp
gui/regui.hpp
remodules.hpp

index 26d446e97362cb18b5462d7a10c342338f0c4b35..1a6ce1e0f9323fc7ade7215c391654eaa12f050f 100644 (file)
 #include <QRegularExpression>
 #include <QPixmap>
 
+enum {
+       LOC_CONSTRUCTOR_1       = LOC_FIRST_OF(LOC_REIMGCONVERTER_CONVERTER), // 20401
+};
+
 /** @file
  *
  * @section intro_sec Introduction
@@ -92,7 +96,7 @@
 
 bool Converter::m_shouldStop = false;
 QStringList Converter::m_files;
-uint64_t Converter::m_totalBytes = 0;
+qint64 Converter::m_totalBytes = 0;
 int Converter::m_totalFiles = 0;
 bool Converter::m_searchReady = false;
 QMutex Converter::m_mutex;
@@ -211,7 +215,7 @@ void addArg(QStringList& args, const char* prefix, int value){
  * @param heightNew the new height of the image
  * @param quality   0 or quality in % (only for JPEG targets)
  */
-void TaskConverter::callExternProgram(const QString& source, const QString& target, int width,
+void TaskConverter::callExternalProgram(const QString& source, const QString& target, int width,
    int height, int widthNew, int heightNew, int quality){
    QStringList args;
    // convert -size 100x200 source.png -resize 50x100 target.jpg";
@@ -255,15 +259,16 @@ void TaskConverter::convertOneFile(const QString& source, const QString& target,
                   handleSimple(width, height, widthNew, heightNew);
           else
                   handleUserDefined(width, height, widthNew, heightNew);
-          QString node = ReFileUtils::nodeOf(source);
+          QString relPath = source.mid(m_sourceDir.length());
          log(
-                node + " " + info + " " + ReQStringUtils::readableSize(size)
+                relPath + " " + ReQStringUtils::readableSize(size)
                        + QString(" -> %1x%2 ").arg(widthNew).arg(heightNew));
-         callExternProgram(source, target, width, height, widthNew, heightNew, m_quality);
+         callExternalProgram(source, target, width, height, widthNew, heightNew, m_quality);
          struct stat info;
          if (stat(I18N::s2b(target).constData(), &info) == 0){
                  sizeTarget = info.st_size;
-                m_mainWindow->logAppendLast(ReQStringUtils::readableSize(sizeTarget)
+                m_mainWindow->externalAppend(ReGuiQueueItem::ListAppendToCurrent,
+                                       NULL, ReQStringUtils::readableSize(sizeTarget)
                                                                          + " " + ReQStringUtils::readableDuration(
                                                                                  clock() - start));
          }
@@ -413,15 +418,15 @@ bool TaskConverter::readPropertiesByIdentify(const QString& name, int& width, in
 void TaskConverter::run(){
    QString msg;
    clock_t start = clock();
-   uint64_t preSize = 0;
-   uint64_t postSize = 0;
-   uint64_t lengthTarget = 0;
+   qint64 preSize = 0;
+   qint64 postSize = 0;
+   qint64 lengthTarget = 0;
    int no = 0;
    QString info;
    QString node;
    QString targetDir;
    try{
-          while (! m_shouldStop && ! m_searchReady){
+          while (! m_shouldStop){
                   m_mutex.lock();
                   if (m_files.size() == 0)
                           info.clear();
@@ -431,7 +436,10 @@ void TaskConverter::run(){
                   }
                   m_mutex.unlock();
                   if (info.isEmpty()){
-                          QThread::sleep(50);
+                          if (m_searchReady)
+                                  break;
+                          else
+                                  QThread::sleep(50);
                   } else {
                           int ix = info.indexOf('\t');
                           node = info.mid(ix + 1);
@@ -455,15 +463,17 @@ void TaskConverter::run(){
                                   preSize += length;
                                   postSize += lengthTarget;
                                   int percentFiles = int(no * 100 / max(1, m_totalFiles));
-                                  int percentSize = int(preSize * 100 / max(1, m_totalBytes));
-                                  m_mainWindow->setStatusMessage(LOG_INFO,
-                                                               tr("%1 file(s) of %2 (%3 %), %4 -> %5 (%6 %)")
-                                                                       .arg(no).arg(m_totalFiles)
-                                                                       .arg(percentFiles + percentSize / 2)
-                                                                          .arg(ReQStringUtils::readableSize(preSize))
-                                                                          .arg(ReQStringUtils::readableSize(postSize))
-                                                                         .arg(postSize * 100.0 / max(1, preSize), 0,
-                                                                                  'f', 2));
+                                  int percentSize = int(preSize * 100 / max(1, min(preSize, m_totalBytes)));
+                                  int percent = preSize > m_totalBytes ? percentFiles
+                                                                                                               : (2 * percentFiles + percentSize) / 3;
+                                  info = tr("%1 file(s) of %2 (%3 %), %4 -> %5 (%6 %)")
+                                                  .arg(no).arg(m_totalFiles)
+                                                  .arg(percent)
+                                                         .arg(ReQStringUtils::readableSize(preSize))
+                                                         .arg(ReQStringUtils::readableSize(postSize))
+                                                        .arg(postSize * 100.0 / max(1LL, preSize), 0,
+                                                                 'f', 1);
+                                  m_mainWindow->externalStatusMessage(LOG_INFO, info);
 
                                }
                   }
@@ -474,13 +484,14 @@ void TaskConverter::run(){
                 QObject::tr("Execution stopped because of error(s): ")
                        + exc.message());
    }
-   preSize = max(1, preSize);
-   msg = QObject::tr("%1 file(s) converted, %2 -> %3 (%4 %), duration: %5").arg(no)
+   preSize = max(1LL, preSize);
+   msg = QObject::tr("%1 of %2 file(s) converted, %3 -> %4 (%5 %), duration: %6")
+                  .arg(no).arg(m_totalFiles)
                   .arg(ReQStringUtils::readableSize(preSize))
                        .arg(ReQStringUtils::readableSize(postSize))
-                  .arg(postSize * 100.0 / preSize, 0, 'f', 2)
+                  .arg(postSize * 100.0 / preSize, 0, 'f', 1)
                   .arg(ReQStringUtils::readableDuration(clock() - start));
-   m_mainWindow->finishTask(msg);
+   m_mainWindow->externalTaskFinished(msg);
 }
 
 /**
@@ -505,13 +516,14 @@ TaskSearch::TaskSearch(const QString& directory,
  *
  * @param dir  the directory to inspect
  */
-void TaskSearch::searchOneDirectory(const QString& dir){
+void TaskSearch::processOneDirectory(const QString& dir){
        QDirIterator it(dir);
        QRegExp regExpr(m_sourcePattern, Qt::CaseInsensitive, QRegExp::Wildcard);
        QString relPath;
        QString info;
-       if (dir.length() > m_sourceDir.length())
-               relPath = m_sourceDir.mid(m_sourceDir.length());
+       if (dir.length() > m_sourceDir.length()){
+               relPath = dir.mid(m_sourceDir.length() + 1) + OS_SEPARATOR_STR;
+       }
        while (it.hasNext()){
           if (m_shouldStop){
                  break;
@@ -521,19 +533,22 @@ void TaskSearch::searchOneDirectory(const QString& dir){
                   info = relPath + "\t" + it.fileName();
                   m_mutex.lock();
                   m_files.append(info);
+                  m_totalFiles++;
+                  m_totalBytes += it.fileInfo().size();
                   m_mutex.unlock();
           }
        }
        if (m_recursive && ! m_shouldStop){
                QDirIterator it2(dir);
+               QString node;
                while (it2.hasNext()){
                        if (m_shouldStop){
                           break;
                        }
                   it2.next();
 
-                  if (it2.fileInfo().isDir()){
-                          searchOneDirectory(it2.filePath());
+                  if (it2.fileInfo().isDir() && (node = it2.fileName()) != "." && node != ".."){
+                          processOneDirectory(it2.filePath());
                   }
                }
        }
@@ -544,7 +559,9 @@ void TaskSearch::searchOneDirectory(const QString& dir){
  */
 void TaskSearch::run(){
        m_searchReady = false;
-       searchOneDirectory(m_sourceDir);
+       m_totalBytes = 0;
+       m_totalFiles = 0;
+       processOneDirectory(m_sourceDir);
        m_searchReady = true;
 }
 
@@ -575,8 +592,9 @@ void TaskShowOther::processOneDirectory(const QString& dir){
        QRegExp regExpr(m_sourcePattern, Qt::CaseInsensitive, QRegExp::Wildcard);
        QString relPath;
        QString info;
-       if (dir.length() > m_sourceDir.length())
-               relPath = m_sourceDir.mid(m_sourceDir.length());
+       if (dir.length() > m_sourceDir.length()){
+               relPath = dir.mid(m_sourceDir.length() + 1) + OS_SEPARATOR_STR;
+       }
        while (it.hasNext()){
           if (m_shouldStop){
                  break;
@@ -585,18 +603,19 @@ void TaskShowOther::processOneDirectory(const QString& dir){
           if (! it.fileInfo().isDir() && regExpr.indexIn(it.fileName()) < 0){
                   info = relPath + it.fileName();
                   m_totalFiles++;
-                  m_mainWindow->remoteLog(info);
+                  m_mainWindow->externalLog(info);
           }
        }
        if (m_recursive && ! m_shouldStop){
                QDirIterator it2(dir);
+               QString node;
                while (it2.hasNext()){
                        if (m_shouldStop){
                           break;
                        }
                   it2.next();
 
-                  if (it2.fileInfo().isDir()){
+                  if (it2.fileInfo().isDir() && (node = it2.fileName()) != "." && node != ".."){
                           processOneDirectory(it2.filePath());
                   }
                }
@@ -611,6 +630,6 @@ void TaskShowOther::run(){
        m_totalFiles = 0;
        processOneDirectory(m_sourceDir);
        m_searchReady = true;
-       m_mainWindow->finishTask(tr("Found: %1 file(s)").arg(m_totalFiles));
+       m_mainWindow->externalTaskFinished(tr("Found: %1 file(s)").arg(m_totalFiles));
 }
 
index 891374aad1ab3cfaae12cc396cbcbcdfc9763dbe..a0c4522ab6bacd2cf4c1c61b62933458ee439de8 100644 (file)
@@ -74,7 +74,7 @@ protected:
        virtual void run();
 protected:
        bool buildArgs();
-       void callExternProgram(const QString& source, const QString& target, int width,
+       void callExternalProgram(const QString& source, const QString& target, int width,
           int height, int widthNew, int heightNew, int quality);
        void converterTask();
        void convertOneFile(const QString& source, const QString& target,
@@ -109,7 +109,7 @@ public:
 protected:
        virtual void run();
 protected:
-   void searchOneDirectory(const QString& dir);
+   void processOneDirectory(const QString& dir);
 private:
    QString m_sourcePattern;
    bool m_recursive;
index 5a6fef5e1edb4517432929ef7c1f15c9411bbc8e..52c5d364f93b68d16f9c93e283dab07a6ef9392d 100644 (file)
@@ -15,7 +15,7 @@
 #include "ui_mainwindow.h"
 #include "aboutdialog.hpp"
 
-const QString VERSION("2016.01.15");
+const QString VERSION("2016.01.20");
 
 /** @class MainWindow mainwindow.hpp "mainwindow.hpp"
  *
@@ -32,17 +32,15 @@ const QString VERSION("2016.01.15");
  * @param parent        NULL or the parent (who destroys the objects at the end)
  */
 MainWindow::MainWindow(const QString& homeDir, QWidget *parent) :
-                       ReHomeApplication("reimgconvert", homeDir, 2, 100100100, parent),
+                       ReGuiApplication("reimgconvert", homeDir, 2, 100100100, parent),
                        ui(new Ui::MainWindow),
                        m_taskConvert(NULL),
                        m_taskSearch(NULL),
-                       m_taskShowOther(NULL),
-                       m_logger(),
-                       m_guiQueue(),
-                       m_guiTimer(new QTimer(this)){
+                       m_taskShowOther(NULL)
+{
        ui->setupUi(this);
+       initializeGuiElements();
    startStop(false);
-   m_statusMessage = new QLabel(tr("Welcome at reimgconvert"));
    statusBar()->addWidget(m_statusMessage);
    connect(ui->actionStart, SIGNAL(triggered()), this,
          SLOT(onConvert()));
@@ -65,10 +63,8 @@ MainWindow::MainWindow(const QString& homeDir, QWidget *parent) :
    connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about()));
    connect(ui->comboBoxTemplate, SIGNAL(currentIndexChanged(const QString&)),
                        this, SLOT(onTemplateChangeIndex(const QString&)));
-   connect(m_guiTimer, SIGNAL(timeout()), this, SLOT(guiTimerUpdate()));
    connect(ui->pushButtonShowOtherFiles, SIGNAL(clicked()), this, SLOT(onShowOtherFiles()));
    restoreState();
-   m_guiTimer->start(100);
 }
 
 /**
@@ -116,27 +112,15 @@ bool MainWindow::error(const QString& message){
 }
 
 /**
- * Finishs a task with sending a ready message.
- *
- * Note: the method is called from a non-main thread.
- *
- * @param message      the message to show
- */
-void MainWindow::finishTask(const QString& message){
-       Converter::m_mutex.lock();
-       m_guiQueue.pushBack(ReGuiQueueItem(ReGuiQueueItem::ReadyMessage, NULL, message));
-       Converter::m_mutex.unlock();
-}
-/**
- * Callback method of the GUI timer.
+ * Reads the <code>m_guiQueue</code> and put the info into the GUI elements.
  */
 void MainWindow::guiTimerUpdate()
 {
        int count = m_guiQueue.count();
        while(count-- > 0){
-               Converter::m_mutex.lock();
+               m_mutexGuiQueue.lock();
                ReGuiQueueItem item = m_guiQueue.popFront();
-               Converter::m_mutex.unlock();
+               m_mutexGuiQueue.unlock();
                if (item.m_type == ReGuiQueueItem::Undef)
                        break;
                if (! item.apply()){
@@ -152,12 +136,11 @@ void MainWindow::guiTimerUpdate()
                                say(LOG_INFO, item.m_value);
                                break;
                        case ReGuiQueueItem::StatusLine:
-                               setStatusMessage(false, item.m_value);
+                               externalStatusMessage(false, item.m_value);
                                break;
                        case ReGuiQueueItem::ListAppendToCurrent:
                        {
-                               QListWidgetItem* item2 = reinterpret_cast<QListWidget*>(
-                                                       item.m_widget)->currentItem();
+                               QListWidgetItem* item2 = ui->listWidget->currentItem();
                                item2->setText(item2->text() + " " + item.m_value);
                                break;
                        }
@@ -182,22 +165,6 @@ bool MainWindow::log(const QString& message){
    return true;
 }
 
-/**
- * @brief Logs a message
- *
- * Note: used by non main threads
- *
- * @param message   the message to log
- * @return          <code>true</code>
- */
-bool MainWindow::logAppendLast(const QString& message){
-       Converter::m_mutex.lock();
-       m_guiQueue.pushBack(ReGuiQueueItem(ReGuiQueueItem::ListAppendToCurrent,
-                                                                          ui->listWidget, message));
-       Converter::m_mutex.unlock();
-   return true;
-}
-
 /**
  * @brief Handles the button click on "convert".
  */
@@ -221,7 +188,7 @@ void MainWindow::onConvert(){
           delete m_taskSearch;
           m_taskSearch = new TaskSearch(ui->comboBoxSourceDir->currentText(),
                                ui->comboBoxSourcePattern->currentText(),
-                               ui->checkBoxCopyOtherFiles->isChecked(), this);
+                               ui->checkBoxRecursive->isChecked(), this);
           m_taskSearch->start();
 
           delete m_taskConvert;
@@ -257,7 +224,7 @@ void MainWindow::onShowOtherFiles(){
        delete m_taskShowOther;
        m_taskShowOther = new TaskShowOther(ui->comboBoxSourceDir->currentText(),
                         ui->comboBoxSourcePattern->currentText(),
-                        ui->checkBoxCopyOtherFiles->isChecked(), this);
+                        ui->checkBoxRecursive->isChecked(), this);
        m_taskShowOther->start();
 }
 /**
@@ -295,20 +262,6 @@ void MainWindow::onTemplateChangeIndex(const QString & text){
    int height = match.captured(2).toInt();
    setMaxDimensions(width, height);
 }
-
-/**
- * Writes a text to the log.
- *
- * Note: this method is called from a non-main thread
- *
- * @param message   the text to set
- */
-void MainWindow::remoteLog(const QString& message){
-       Converter::m_mutex.lock();
-       m_guiQueue.pushBack(ReGuiQueueItem(ReGuiQueueItem::ListEnd,
-                                                                          ui->listWidget, message));
-       Converter::m_mutex.unlock();
-}
 /**
  * Reads the history of the widget values and other parameters and set it.
  */
@@ -406,27 +359,13 @@ void MainWindow::selectTarget(){
          ui->comboBoxTargetDir->setCurrentText(dir);
 }
 
-/**
- * Writes a text to the status line.
- *
- * Note: this method is called from a non-main thread
- *
- * @param message   the text to set
- */
-void MainWindow::setRemoteStatus(const QString& message){
-       Converter::m_mutex.lock();
-       m_guiQueue.pushBack(ReGuiQueueItem(ReGuiQueueItem::StatusLine,
-                                                                          NULL, message));
-       Converter::m_mutex.unlock();
-}
-
 /**
  * Writes a text to the status line.
  *
  * @param error     <code>true</code>: the message is an error message
  * @param message   the text to set
  */
-void MainWindow::setStatusMessage(bool error, const QString& message){
+void MainWindow::externalStatusMessage(bool error, const QString& message){
        RE_UNUSED(error);
    m_statusMessage->setText(message);
 }
index 148371aba7ced841c66a12e7c72420db4b849c91..5ee1406dc5c9b7ab701c6e8127c300449ace3057 100644 (file)
@@ -23,7 +23,7 @@ namespace Ui {
 class MainWindow;
 }
 
-class MainWindow: public ReHomeApplication,
+class MainWindow: public ReGuiApplication,
    public ReGuiValidator,
    public ConvertLogger {
    Q_OBJECT
@@ -35,12 +35,8 @@ public:
 public:
        virtual void aboutToQuit();
    bool error(const QString& message);
-   void finishTask(const QString& message);
    bool log(const QString& message);
-   bool logAppendLast(const QString& message);
-   void remoteLog(const QString& message);
-   void setRemoteStatus(const QString& message);
-   void setStatusMessage(bool error, const QString& message);
+   void externalStatusMessage(bool error, const QString& message);
 public:
    virtual bool say(ReLoggerLevel level, const QString& message);
 private:
@@ -64,10 +60,6 @@ private:
    TaskConverter* m_taskConvert;
    TaskSearch* m_taskSearch;
    TaskShowOther* m_taskShowOther;
-   QLabel* m_statusMessage;
-   ReLogger m_logger;
-   ReGuiQueue m_guiQueue;
-   QTimer* m_guiTimer;
 };
 
 #endif // MAINWINDOW_HPP
index dcd95ab87e898fd4ac40450bae16f04490c1503f..403db30e2715178da20235efc45c445b72f6818b 100644 (file)
@@ -42,7 +42,7 @@
        <attribute name="title">
         <string>Dimensions (quick)</string>
        </attribute>
-       <widget class="QWidget" name="">
+       <widget class="QWidget" name="layoutWidget">
         <property name="geometry">
          <rect>
           <x>11</x>
          </item>
         </layout>
        </widget>
-       <widget class="QWidget" name="">
+       <widget class="QWidget" name="layoutWidget">
         <property name="geometry">
          <rect>
           <x>13</x>
       </item>
       <item>
        <widget class="QCheckBox" name="checkBoxCopyOtherFiles">
+        <property name="enabled">
+         <bool>false</bool>
+        </property>
         <property name="minimumSize">
          <size>
           <width>125</width>
index 4aa94bfeaf0ccef463477042f5bd6050044bd381..6be8c710dec942b5c38404a63b2708bcf74bfe52 100644 (file)
@@ -11,7 +11,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
 TARGET = reimgconvert
 TEMPLATE = app
 
-INCLUDEPATH = ../.. /usr/include/c++/4.9
+INCLUDEPATH += ../..
 
 SOURCES += main.cpp\
         ../../base/ReException.cpp \
@@ -21,6 +21,7 @@ SOURCES += main.cpp\
         ../../gui/ReStateStorage.cpp \
         ../../gui/ReGuiValidator.cpp \
         ../../gui/ReGuiQueue.cpp \
+        ../../gui/ReGuiApplication.cpp \
         mainwindow.cpp \
         converter.cpp \
         aboutdialog.cpp
@@ -30,6 +31,7 @@ HEADERS  += mainwindow.hpp \
         ../../base/ReQStringUtils.hpp \
         ../../gui/ReStateStorage.hpp \
         ../../gui/ReGuiValidator.hpp \
+        ../../gui/ReGuiApplication.hpp \
         ../../gui/regui.hpp \
         converter.hpp \
         aboutdialog.hpp
@@ -47,4 +49,4 @@ CODECFORSRC = UTF-8
 OTHER_FILES +=
 
 DISTFILES += \
-    ReImgConvert.html
+       ReImgConvert.html
index 8c3c37524159a8988df4d254040b48654b1ed32c..ac2e535f8ac8d2b89a73f4878ac649d42d8e8749 100644 (file)
@@ -12,7 +12,7 @@
 #include "base/rebase.hpp"
 
 enum {
-       LOC_DELETE_TREE_1 = LOC_FIRST_OF(LOC_FILE), // 11801
+       LOC_DELETE_TREE_1 = LOC_FIRST_OF(LOC_FILE_UTILS), // 11801
        LOC_DELETE_TREE_2,              // 11802
        LOC_DELETE_TREE_3,              // 11803
        LOC_SET_TIMES_1,                // 11804
index 2458f1f547bf78f77585ea08f95e053bcc20ce00..721479f0e5acc4bdc33e946de5120decc05223c0 100644 (file)
@@ -483,7 +483,6 @@ void ReQStringUtils::skipExpected(const ReString& text, QChar expected,
 QString ReQStringUtils::readableDuration(clock_t duration){
        QString rc;
        char buffer[128];
-       int cl_per_sec = CLOCKS_PER_SEC;
        double duration2 = (double) duration / CLOCKS_PER_SEC;
        if (duration2 < 60.0){
                rc = QString::number(duration2, 'f', 3) + " sec";
index 74f75173b42b17c969eaa4a4eddc91d71f3879e5..bbdb20372ec68ae0cf8eb1a1704cf990c59aec1a 100644 (file)
@@ -126,6 +126,14 @@ inline
 int min(int a, int b) {
        return a < b ? a : b;
 }
+inline
+int max(qint64 a, qint64 b) {
+       return a > b ? a : b;
+}
+inline
+int min(qint64 a, qint64 b) {
+       return a < b ? a : b;
+}
 inline double max(double a, double b) {
        return a > b ? a : b;
 }
diff --git a/gui/ReGuiApplication.cpp b/gui/ReGuiApplication.cpp
new file mode 100644 (file)
index 0000000..306758d
--- /dev/null
@@ -0,0 +1,143 @@
+/*
+ * ReStateStorage.cpp
+ *
+ * (Un)License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * More info: http://unlicense.org
+ * The latest sources: https://github.com/republib
+ */
+#include "base/rebase.hpp"
+#include "gui/regui.hpp"
+#include <QCoreApplication>
+
+enum {
+       LOC_CONSTRUCTOR_1       = LOC_FIRST_OF(LOC_GUI_APPLICATION), // 12401
+       LOC_QUIT_1,                     // 12402
+};
+
+/**
+ * Constructor.
+ *
+ * @param applicationName      the name of the application. Defines the node
+ *                                                     of the home directory
+ * @param homeDirBase          "": the user's home directory will be used<br>
+ *                                                     otherwise: the home directory will created in this
+ *                                                     directory
+ * @param maxLogFiles          max. count of (rotating) log files
+ * @param maxLogSize           max. size of the (rotating) log files
+ */
+ReGuiApplication::ReGuiApplication(const char* applicationName,
+                                                                                  const QString& homeDirBase,
+                                                                                  int maxLogFiles, int maxLogSize,
+                                                                        QWidget *parent = NULL) :
+       QMainWindow(parent),
+       m_applicationName(applicationName),
+       m_homeDir(buildHomeDir(homeDirBase, ".reappl")),
+       m_logger(),
+       m_storageFile(),
+       m_guiQueue(),
+       m_guiTimer(new QTimer(this)),
+       m_statusMessage(new QLabel(tr("Welcome!"))),
+       m_mutexGuiQueue()
+{
+       m_logger.buildStandardAppender(I18N::s2b(m_homeDir) + applicationName,
+                                                                  maxLogSize, maxLogFiles);
+       m_storageFile = m_homeDir + applicationName + ".state.conf";
+       m_logger.log(LOG_INFO, LOC_CONSTRUCTOR_1, "start");
+}
+
+/**
+ * Callback method at the application's end.
+ */
+void ReGuiApplication::aboutToQuit()
+{
+       m_logger.log(LOG_INFO, LOC_QUIT_1, "end");
+}
+
+/**
+ * Build the home directory path name.
+ *
+ * @param homeDirBase          "": the user's home directory will be used<br>
+ *                                                     otherwise: the home directory will created in this
+ *                                                     directory
+ * @param node
+ * @return
+ */
+QString ReGuiApplication::buildHomeDir(QString homeDirBase, const QString& node){
+       QString homeDir;
+       if (homeDirBase.isEmpty()){
+                         homeDir = QDir::home().absoluteFilePath(node);
+       } else if (ReFileUtils::isRootDir(homeDirBase.toLatin1().constData())){
+               homeDir = homeDirBase + node;
+       }
+       ReQStringUtils::chomp(homeDir, OS_SEPARATOR);
+       QDir home(homeDir);
+       if (!home.exists()){
+        if (!home.mkpath(homeDir)){
+               homeDir = home.tempPath() + node;
+               home.mkpath(homeDir);
+        }
+       }
+       ReQStringUtils::ensureLastChar(homeDir, OS_SEPARATOR);
+       return homeDir;
+}
+/**
+ * Finishs a task with sending a ready message.
+ *
+ * Note: the method is called from a non-main thread.
+ *
+ * @param message      the message to show
+ */
+void ReGuiApplication::externalTaskFinished(const QString& message){
+       m_mutexGuiQueue.lock();
+       m_guiQueue.pushBack(ReGuiQueueItem(ReGuiQueueItem::ReadyMessage, NULL, message));
+       m_mutexGuiQueue.unlock();
+}
+
+/**
+ * Initializes the GUI elements of this class.
+ *
+ * Should be called after initializing the formular (<code>ui->setupUi()</code>).
+ */
+void ReGuiApplication::initializeGuiElements(){
+       QCoreApplication* app = QCoreApplication::instance();
+       QObject::connect(app, SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit()));
+       connect(m_guiTimer, SIGNAL(timeout()), this, SLOT(guiTimerUpdate()));
+       m_guiTimer->start(100);
+}
+
+/**
+ * @brief Logs a message
+ *
+ * Note: used by a non main thread.
+ *
+ * @param type         the type of the queue entry
+ * @param widget       NULL or the target widget
+ * @param info         the info for the target widget
+ * @return          <code>true</code>
+ */
+bool ReGuiApplication::externalAppend(ReGuiQueueItem::WidgetType type, QWidget* widget,
+                                                                const QString& info){
+       m_mutexGuiQueue.lock();
+       m_guiQueue.pushBack(ReGuiQueueItem(type, widget, info));
+       m_mutexGuiQueue.unlock();
+       return true;
+}
+
+
+/**
+ * Writes a text to the log.
+ *
+ * Note: this method is called from a non-main thread
+ *
+ * @param message   the text to set
+ */
+void ReGuiApplication::externalLog(const QString& message){
+       m_mutexGuiQueue.lock();
+       m_guiQueue.pushBack(ReGuiQueueItem(ReGuiQueueItem::LogMessage, NULL,
+                                                                       message));
+       m_mutexGuiQueue.unlock();
+}
+
diff --git a/gui/ReGuiApplication.hpp b/gui/ReGuiApplication.hpp
new file mode 100644 (file)
index 0000000..97b27a8
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * ReStateStorage.hpp
+ *
+ * (Un)License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * More info: http://unlicense.org
+ * The latest sources: https://github.com/republib
+ */
+
+#ifndef REGUIAPPLICATION_HPP_
+#define REGUIAPPLICATION_HPP_
+
+#include <QMainWindow>
+
+/**
+ * An abstract base class for applications which stores their data in a home directory.
+ */
+class ReGuiApplication : public QMainWindow{
+public:
+       ReGuiApplication(const char* applicationName,
+                                                const QString& homeDir, int maxLogFiles, int maxLogSize,
+                                         QWidget *parent);
+public slots:
+       /**
+        * Callback method called when the application is closed.
+        */
+       void aboutToQuit();
+public:
+       static QString buildHomeDir(QString homeDirBase, const QString& node);
+       bool externalAppend(ReGuiQueueItem::WidgetType type, QWidget* widget, const QString& info);
+       void externalLog(const QString& message);
+       void externalTaskFinished(const QString& message);
+protected:
+       void initializeGuiElements();
+protected slots:
+       /**
+        * Reads the <code>m_guiQueue</code>.
+        */
+       virtual void guiTimerUpdate() = 0;
+protected:
+       QByteArray m_applicationName;
+       QString m_homeDir;
+       ReLogger m_logger;
+       QString m_storageFile;
+       ReGuiQueue m_guiQueue;
+       QTimer* m_guiTimer;
+       QLabel* m_statusMessage;
+       QMutex m_mutexGuiQueue;
+
+};
+
+#endif /* REGUIAPPLICATION_HPP_ */
index 23fa19d84c6fda4cbe5f7197ae9410cbd888aa75..0b5775ef60eac9e46cc26e746daecaa4bc6498c7 100644 (file)
@@ -16,7 +16,7 @@ class ReGuiQueueItem {
 public:
        enum WidgetType {
                Undef, LabelText, NewTableRow, ListEnd, ListAppendToCurrent,
-               LogMessage, ReadyMessage, StatusLine,
+               LogMessage, LogError, ReadyMessage, StatusLine,
                UserDefined1, UserDefined2
        };
 
index e21b7e80672cac9daf9179e64b7b585c2741c487..8ea323d59d4af8a628d4236fa9ac49a41e737d27 100644 (file)
@@ -355,64 +355,3 @@ void ReStateStorage::store(const QMainWindow* window) {
        }
 }
 
-/**
- * Constructor.
- *
- * @param applicationName      the name of the application. Defines the node
- *                                                     of the home directory
- * @param homeDirBase          "": the user's home directory will be used<br>
- *                                                     otherwise: the home directory will created in this
- *                                                     directory
- * @param maxLogFiles          max. count of (rotating) log files
- * @param maxLogSize           max. size of the (rotating) log files
- */
-ReHomeApplication::ReHomeApplication(const char* applicationName,
-                                                                                  const QString& homeDirBase,
-                                                                                  int maxLogFiles, int maxLogSize,
-                                                                        QWidget *parent = NULL) :
-       QMainWindow(parent),
-       m_applicationName(applicationName),
-       m_homeDir(buildHomeDir(homeDirBase, "." + m_applicationName)),
-       m_logger(),
-       m_storageFile()
-{
-       m_logger.buildStandardAppender(I18N::s2b(m_homeDir) + "logger.",
-                                                                  maxLogSize, maxLogFiles);
-       m_storageFile = m_homeDir + OS_SEPARATOR_STR + "status.conf";
-       m_storageFile = m_homeDir + "state.conf";
-       QCoreApplication* app = QCoreApplication::instance();
-       QObject::connect(app, SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit()));
-}
-
-void ReHomeApplication::aboutToQuit()
-{
-       m_logger.log(LOG_INFO, 999, "exit");
-}
-
-/**
- * Build the home directory path name.
- *
- * @param homeDirBase          "": the user's home directory will be used<br>
- *                                                     otherwise: the home directory will created in this
- *                                                     directory
- * @param node
- * @return
- */
-QString ReHomeApplication::buildHomeDir(QString homeDirBase, const QString& node){
-       QString homeDir;
-       if (homeDirBase.isEmpty()){
-                         homeDir = QDir::home().absoluteFilePath(node);
-       } else if (ReFileUtils::isRootDir(homeDirBase.toLatin1().constData())){
-               homeDir = homeDirBase + node;
-       }
-       ReQStringUtils::chomp(homeDir, OS_SEPARATOR);
-       QDir home(homeDir);
-       if (!home.exists()){
-        if (!home.mkpath(homeDir)){
-               homeDir = home.tempPath() + node;
-               home.mkpath(homeDir);
-        }
-       }
-       ReQStringUtils::ensureLastChar(homeDir, OS_SEPARATOR);
-       return homeDir;
-}
index 075fec20868f21614ee57b4c436e9949cc043b96..b44de8b338de2300592267071e91b8bfa9c9fe4d 100644 (file)
@@ -55,26 +55,4 @@ private:
        ReLogger* m_logger;
 };
 
-/**
- * An abstract base class for applications which stores their data in a home directory.
- */
-class ReHomeApplication : public QMainWindow{
-public:
-       ReHomeApplication(const char* applicationName,
-                                                const QString& homeDir, int maxLogFiles, int maxLogSize,
-                                         QWidget *parent);
-public slots:
-       /**
-        * Callback method called when the application is closed.
-        */
-       void aboutToQuit();
-public:
-       static QString buildHomeDir(QString homeDirBase, const QString& node);
-protected:
-       QByteArray m_applicationName;
-       QString m_homeDir;
-       ReLogger m_logger;
-       QString m_storageFile;
-};
-
 #endif /* GUI_RESTATESTORAGE_HPP_ */
index ec911b2c20d8b152efa981924fdf6765df1e0ebf..e092a32f8221449943dcf4218b91f8308c3b8262 100644 (file)
 #include <QTableWidget>
 #include "gui/ReGuiQueue.hpp"
 #include "gui/ReStateStorage.hpp"
+#include "gui/ReGuiApplication.hpp"
 #include "gui/ReGuiValidator.hpp"
 #include "gui/ReEdit.hpp"
 #include "gui/ReSettings.hpp"
 #include "gui/ReFileTree.hpp"
+
 /**
  * Tests whether a point is inside the rectangle (including border).
  * @param rect  rectangle to test
index 1633b4bf8233e7259618aa729cbf05a70f7f3d53..19e6c2b2e0661b16cdd585965c4ac9a3deedf843 100644 (file)
@@ -29,16 +29,19 @@ enum {
        LOC_MFPARSER, // 115
        LOC_TRAVERSER,
        LOC_SETTINGS,
-       LOC_FILE,
+       LOC_FILE_UTILS,
        LOC_FILETREE,
        LOC_STATESTORAGE,       // 120
        LOC_FILESYSTEM,
        LOC_RANDOMIZER,
        LOC_CRYPTFILESYSTEM,
+       LOC_GUI_APPLICATION,
 
        // Applications:
        LOC_RECFORM_CPPPARSER = 201,
        LOC_RECFORM_CPPFORMATTER = 202,
+       LOC_REIMGCONVERTER_ = 203,
+       LOC_REIMGCONVERTER_CONVERTER = 204,
 };
 #define LOC_FIRST_OF(moduleNo) (moduleNo*100+1)
 class RplModules {