]> gitweb.hamatoma.de Git - reqt/commitdiff
reidos initializations
authorhama <hama@siduction.net>
Tue, 27 Oct 2015 22:59:33 +0000 (23:59 +0100)
committerhama <hama@siduction.net>
Tue, 27 Oct 2015 22:59:33 +0000 (23:59 +0100)
appl/reidos/FileCommander.cpp [new file with mode: 0644]
appl/reidos/FileCommander.hpp [new file with mode: 0644]
appl/reidos/idosmain.cpp
appl/reidos/idosmain.hpp
appl/reidos/main.cpp
appl/reidos/reidos.hpp [new file with mode: 0644]
appl/reidos/reidos.pro
base/ReLogger.cpp
base/ReLogger.hpp
gui/ReGuiValidator.cpp

diff --git a/appl/reidos/FileCommander.cpp b/appl/reidos/FileCommander.cpp
new file mode 100644 (file)
index 0000000..a1bb704
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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 "reidos.hpp"
+
+/**
+ * Constructor.
+ */
+FileCommander::FileCommander(IDosMain* main) :
+       m_main(main),
+       m_topFS(NULL),
+       m_bottomFS(NULL),
+       m_activeFS(NULL),
+       m_inactiveFS(NULL),
+       m_logger(new ReMemoryLogger)
+{
+}
+
+/**
+ * Sets a filesystem to a filesystem given by its url.
+ *
+ * @param url                  the Uniform Resource Locator, e.g. "file:/home/jonny"
+ * @param filesystem   IN/OUT: the filesystem to change
+ */
+void FileCommander::buildFs(const QString& url, ReFileSystem& filesystem)
+{
+       if (url.startsWith("file:", Qt::CaseInsensitive)){
+
+       } else {
+               m_main->setStatusMessage(true, QObject::tr("unknown protocol in url: ") + url);
+       }
+}
+
diff --git a/appl/reidos/FileCommander.hpp b/appl/reidos/FileCommander.hpp
new file mode 100644 (file)
index 0000000..5df917b
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * 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 FILECOMMANDER_HPP
+#define FILECOMMANDER_HPP
+
+class IDosMain;
+
+class FileCommander
+{
+public:
+       FileCommander(IDosMain* m_main);
+public:
+       void buildFs(const QString& url, ReFileSystem& filesystem);
+protected:
+       IDosMain* m_main;
+       ReFileSystem* m_topFS;
+       ReFileSystem* m_bottomFS;
+       ReFileSystem* m_activeFS;
+       ReFileSystem* m_inactiveFS;
+       ReLogger* m_logger;
+};
+
+#endif // FILECOMMANDER_HPP
index e2a4e6e29289867c07d963e13e3d6ced94bb0108..e76926fd0ebc70626a7e916613c6996bff6d0236 100644 (file)
@@ -6,18 +6,88 @@
  * The original sources can be found on https://github.com/republib.
 */
 
-
-#include "idosmain.hpp"
+#include "reidos.hpp"
 #include "ui_idosmain.h"
 
-IDosMain::IDosMain(QWidget *parent) :
+IDosMain::IDosMain(const QString& startDir, const QString& homeDir,
+                       QWidget *parent) :
        QMainWindow(parent),
-       ui(new Ui::IDosMain)
+       ReGuiValidator(),
+       FileCommander(this),
+       ui(new Ui::IDosMain),
+       m_statusMessage(NULL),
+       m_homeDir(homeDir)
+       //m_storageFile(),
 {
        ui->setupUi(this);
+       initializeHome();
+       m_statusMessage = new QLabel(tr("Welcome at reidos"));
 }
 
 IDosMain::~IDosMain()
 {
        delete ui;
 }
+
+void IDosMain::error(const QString& message)
+{
+       m_statusMessage->setText("+++ " + message);
+}
+
+/**
+ * initializeHomeializes the program home directory.
+ */
+void IDosMain::initializeHome(){
+   if (m_homeDir.isEmpty()){
+         m_homeDir = QDir::home().absoluteFilePath(".reidos");
+   }
+
+   QDir home(m_homeDir);
+   if (!home.exists()){
+         if (!home.mkpath(m_homeDir)){
+                m_homeDir = home.tempPath() + "/.redos";
+                home.mkpath(m_homeDir);
+         }
+   }
+   if (!m_homeDir.endsWith("/"))
+         m_homeDir += "/";
+   m_storageFile = m_homeDir + "state.conf";
+   restoreState();
+}
+
+/**
+ * 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 IDosMain::setStatusMessage(bool error, const QString& message){
+       m_statusMessage->setText(error ? "+++ " + message : message);
+}
+
+/**
+ * Reads the history of the widget values and other parameters and set it.
+ */
+void IDosMain::restoreState(){
+       ReStateStorage storage(m_storageFile, m_logger);
+       storage.setForm("main");
+       storage.restore(ui->comboBoxPathTop, "comboBoxPathTop", true);
+       storage.restore(ui->comboBoxPatternTop, "comboBoxPatternTop", false);
+       storage.restore(ui->comboBoxPathBottom, "comboBoxPathBottom", true);
+       storage.restore(ui->comboBoxPatternBottom, "comboBoxPatternBottom", false);
+
+       storage.close();
+}
+
+/**
+ * Stores the history of the widget values and other parameters.
+ */
+void IDosMain::saveState(){
+       ReStateStorage storage(m_storageFile, m_logger);
+       storage.setForm("main");
+       storage.store(ui->comboBoxPathTop, "comboBoxPathTop");
+       storage.store(ui->comboBoxPatternTop, "comboBoxPatternTop");
+       storage.store(ui->comboBoxPathBottom, "comboBoxPathBottom");
+       storage.store(ui->comboBoxPatternBottom, "comboBoxPatternBottom");
+       storage.close();
+}
index 769371ff209cd2d7f343f58998a5837c0c941512..7aa86126c3606aa4064527885efff631204c6e86 100644 (file)
 namespace Ui {
 class IDosMain;
 }
-
-class IDosMain : public QMainWindow
+#include "reidos.hpp"
+class IDosMain : public QMainWindow, public ReGuiValidator, public FileCommander
 {
        Q_OBJECT
 
 public:
-       explicit IDosMain(QWidget *parent = 0);
+       explicit IDosMain(const QString& startDir, const QString& homeDir,
+                       QWidget *parent = 0);
        ~IDosMain();
 
+public:
+       void error(const QString& message);
+       virtual void setStatusMessage(bool error, const QString& message);
+protected:
+       void initializeHome();
+       void restoreState();
+       void saveState();
 private:
        Ui::IDosMain *ui;
+       QLabel* m_statusMessage;
+       QString m_homeDir;
+       QString m_storageFile;
+       ReLogger* m_logger;
 };
 
 #endif // IDOSMAIN_HPP
index 83d2a71c35258277abe06a8e8bff2baffbe8b979..4010211f794f33a1e531e63111f6ce66de02f1a3 100644 (file)
@@ -7,13 +7,15 @@
 */
 
 
-#include "idosmain.hpp"
+#include "reidos.hpp"
 #include <QApplication>
 
 int main(int argc, char *argv[])
 {
        QApplication a(argc, argv);
-       IDosMain w;
+       QString startDir;
+       QString homeDir;
+       IDosMain w(startDir, homeDir);
        w.show();
 
        return a.exec();
diff --git a/appl/reidos/reidos.hpp b/appl/reidos/reidos.hpp
new file mode 100644 (file)
index 0000000..5b03e48
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * 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 REIDOS_HPP
+#define REIDOS_HPP
+#include "QLabel"
+
+
+#include "base/rebase.hpp"
+#include "os/reos.hpp"
+#include "gui/regui.hpp"
+#include "FileCommander.hpp"
+#include "idosmain.hpp"
+
+#endif // REIDOS_HPP
+
index 499926da524bc188b362488997f87ad38126f4f9..34f740030561853663660332bd66bdd3187348b8 100644 (file)
@@ -18,6 +18,7 @@ SOURCES += \
         ../../gui/ReStateStorage.cpp \
         ../../gui/ReSettings.cpp \
         ../../gui/ReFileTree.cpp \
+        ../../gui/ReGuiValidator.cpp \
         ../../base/ReMatcher.cpp \
         ../../base/ReFile.cpp \
         ../../base/ReStringUtils.cpp \
@@ -29,7 +30,8 @@ SOURCES += \
        ../../base/ReFileUtils.cpp \
        ../../base/ReException.cpp \
        idosmain.cpp \
-       main.cpp
+       main.cpp \
+       FileCommander.cpp
 
 HEADERS  +=  ../../base/rebase.hpp \
         ../../gui/regui.hpp \
@@ -40,6 +42,8 @@ HEADERS  +=  ../../base/rebase.hpp \
        ../../base/ReQStringUtils.hpp \
        ../../base/ReException.hpp \
        ../../os/reos.hpp \
-       idosmain.hpp
+       idosmain.hpp \
+       FileCommander.hpp \
+       reidos.hpp
 
 FORMS    += idosmain.ui
index 94c931bc6f7bb26fd2994984cffc4a95e7824d24..955963ff1dabb061b94837f659e1dd5d545fe29e 100644 (file)
@@ -61,8 +61,8 @@ void ReLogger::destroyGlobalLogger() {
  * @param name         identifies the logger. Useful for ReLogger::findLogger()
  */
 ReAppender::ReAppender(const QByteArray& name) :
-           m_name(name),
-           m_level(LOG_INFO) {
+               m_name(name),
+               m_level(LOG_INFO) {
 
 }
 /**
@@ -149,11 +149,11 @@ bool ReAppender::isAutoDelete() const {
  * @param isGlobal  <code>true</code>: the logger becomes the global logger
  */
 ReLogger::ReLogger(bool isGlobal) :
-           // m_appenders(),
-           m_countAppenders(0),
-           m_stdPrefix(),
-           m_mutex(),
-           m_withLocking(false) {
+               // m_appenders(),
+               m_countAppenders(0),
+               m_stdPrefix(),
+               m_mutex(),
+               m_withLocking(false) {
        memset(m_appenders, 0, sizeof m_appenders);
        if (isGlobal) {
                m_globalLogger = this;
@@ -288,7 +288,7 @@ bool ReLogger::log(ReLoggerLevel level, int location, const char* message) {
  * @return                     true: for chaining
  */
 bool ReLogger::log(ReLoggerLevel level, int location,
-    const QByteArray& message) {
+       const QByteArray& message) {
        return log(level, location, message.data());
 }
 
@@ -314,7 +314,7 @@ bool ReLogger::log(ReLoggerLevel level, int location, const ReString& message) {
  * @return                     true: for chaining
  */
 bool ReLogger::logv(ReLoggerLevel level, int location, const char* format,
-    ...) {
+       ...) {
        char buffer[64000];
        va_list ap;
        va_start(ap, format);
@@ -333,7 +333,7 @@ bool ReLogger::logv(ReLoggerLevel level, int location, const char* format,
  * @return                     true: for chaining
  */
 bool ReLogger::logv(ReLoggerLevel level, int location, const QByteArray& format,
-    ...) {
+       ...) {
        char buffer[64000];
        va_list ap;
        va_start(ap, format);
@@ -352,7 +352,7 @@ bool ReLogger::logv(ReLoggerLevel level, int location, const QByteArray& format,
  * @return                     true: for chaining
  */
 bool ReLogger::log(ReLoggerLevel level, int location, const char* format,
-    va_list& varlist) {
+       va_list& varlist) {
        char buffer[64000];
        qvsnprintf(buffer, sizeof buffer, format, varlist);
        return log(level, location, buffer);
@@ -369,8 +369,8 @@ QByteArray ReLogger::buildStdPrefix(ReLoggerLevel level, int location) {
        struct tm* now2 = localtime(&now);
        char buffer[64];
        qsnprintf(buffer, sizeof buffer, "%c%d.%02d.%02d %02d:%02d:%02d (%d): ",
-           getPrefixOfLevel(level), now2->tm_year + 1900, now2->tm_mon + 1,
-           now2->tm_mday, now2->tm_hour, now2->tm_min, now2->tm_sec, location);
+               getPrefixOfLevel(level), now2->tm_year + 1900, now2->tm_mon + 1,
+               now2->tm_mday, now2->tm_hour, now2->tm_min, now2->tm_sec, location);
        return QByteArray(buffer);
 }
 
@@ -418,10 +418,10 @@ ReAppender* ReLogger::findAppender(const char* name) const {
  *                      configuration file
  */
 void ReLogger::buildStandardAppender(ReConfig* config, const char* prefix,
-    const char* defaultLogfilePrefix) {
+       const char* defaultLogfilePrefix) {
        QByteArray sPrefix(prefix);
        QByteArray logFilePrefix = config->asString(sPrefix + "name",
-           defaultLogfilePrefix);
+               defaultLogfilePrefix);
 
        int maxSize = config->asInt(+"maxsize", 10100100);
        int maxCount = config->asInt(sPrefix + "maxfiles", 5);
@@ -445,12 +445,12 @@ void ReLogger::buildStandardAppender(ReConfig* config, const char* prefix,
  * @param maxCount             the maximal count of files. If neccessary the oldest file will be deleted
  */
 void ReLogger::buildStandardAppender(const QByteArray& prefix, int maxSize,
-    int maxCount) {
+       int maxCount) {
        ReStreamAppender* streamAppender = new ReStreamAppender(stderr);
        streamAppender->setAutoDelete(true);
        addAppender((ReAppender*) streamAppender);
        ReFileAppender* fileAppender = new ReFileAppender(prefix, maxSize,
-           maxCount);
+               maxCount);
        fileAppender->setAutoDelete(true);
        addAppender((ReAppender*) fileAppender);
 }
@@ -466,8 +466,8 @@ void ReLogger::buildStandardAppender(const QByteArray& prefix, int maxSize,
  * @brief Constructor.
  */
 ReStreamAppender::ReStreamAppender(FILE* file, const char* appenderName) :
-           ReAppender(QByteArray(appenderName)),
-           m_fp(file) {
+               ReAppender(QByteArray(appenderName)),
+               m_fp(file) {
 }
 
 /**
@@ -486,7 +486,7 @@ ReStreamAppender::~ReStreamAppender() {
  * @param logger    the calling logger
  */
 void ReStreamAppender::log(ReLoggerLevel level, int location,
-    const char* message, ReLogger* logger) {
+       const char* message, ReLogger* logger) {
        const QByteArray& prefix = logger->getStdPrefix(level, location);
        fputs(prefix, m_fp);
        fputs(message, m_fp);
@@ -516,14 +516,14 @@ void ReStreamAppender::log(ReLoggerLevel level, int location,
  * @param appenderName the name of the appender. @see ReLogger::findAppender()
  */
 ReFileAppender::ReFileAppender(const QByteArray& prefix, int maxSize,
-    int maxCount, const char* appenderName) :
-           ReAppender(QByteArray(appenderName)),
-           m_prefix(prefix),
-           m_maxSize(maxSize),
-           m_maxCount(maxCount),
-           m_currentSize(0),
-           m_currentNo(0),
-           m_fp(NULL) {
+       int maxCount, const char* appenderName) :
+               ReAppender(QByteArray(appenderName)),
+               m_prefix(prefix),
+               m_maxSize(maxSize),
+               m_maxCount(maxCount),
+               m_currentSize(0),
+               m_currentNo(0),
+               m_fp(NULL) {
        open();
 }
 
@@ -545,7 +545,7 @@ void ReFileAppender::open() {
                fclose(m_fp);
        char fullName[512];
        qsnprintf(fullName, sizeof fullName, "%s.%03d.log", m_prefix.data(),
-           ++m_currentNo);
+               ++m_currentNo);
        m_fp = fopen(fullName, "a");
        if (m_fp == NULL)
                fprintf(stderr, "cannot open: %s\n", fullName);
@@ -565,7 +565,7 @@ void ReFileAppender::open() {
  */
 #pragma GCC diagnostic ignored "-Wunused-parameter"
 void ReFileAppender::log(ReLoggerLevel level, int location, const char* message,
-    ReLogger* logger) {
+       ReLogger* logger) {
        if (m_fp != NULL) {
                const QByteArray& prefix = logger->getStdPrefix(level, location);
                fputs(prefix, m_fp);
@@ -591,10 +591,10 @@ void ReFileAppender::log(ReLoggerLevel level, int location, const char* message,
  * @param appenderName  NULL or the name of the appender
  */
 ReMemoryAppender::ReMemoryAppender(int maxLines, const char* appenderName) :
-           ReAppender(appenderName),
-           m_lines(),
-           m_maxLines(maxLines),
-           m_addPrefix(true) {
+               ReAppender(appenderName),
+               m_lines(),
+               m_maxLines(maxLines),
+               m_addPrefix(true) {
        m_lines.reserve(maxLines);
 }
 
@@ -614,7 +614,7 @@ ReMemoryAppender::~ReMemoryAppender() {
  */
 #pragma GCC diagnostic ignored "-Wunused-parameter"
 void ReMemoryAppender::log(ReLoggerLevel level, int location,
-    const char* message, ReLogger* logger) {
+       const char* message, ReLogger* logger) {
        if (m_lines.size() >= m_maxLines)
                m_lines.removeFirst();
        if (!m_addPrefix)
@@ -649,7 +649,7 @@ void ReMemoryAppender::clear() {
  * @param appenderName  a name for the appender
  */
 ReDebugAppender::ReDebugAppender(const char* appenderName) :
-           ReAppender(appenderName) {
+               ReAppender(appenderName) {
 }
 /**
  * Destructor.
@@ -666,7 +666,17 @@ ReDebugAppender::~ReDebugAppender() {
  * @param logger    the calling logger
  */
 void ReDebugAppender::log(ReLoggerLevel level, int location,
-    const char* message, ReLogger* logger) {
+       const char* message, ReLogger* logger) {
        QByteArray msg(logger->getStdPrefix(level, location));
        qDebug("%s%s", msg.constData(), message);
 }
+
+/**
+ * Constructor.
+ */
+ReMemoryLogger::ReMemoryLogger() :
+       ReLogger(true),
+       ReMemoryAppender()
+{
+       addAppender(this);
+}
index e3be2af767696c0519b13b8ff90c020898317a2b..c8b24fe07013cece0415c56e7feaa3a4f56e59cd 100644 (file)
@@ -41,7 +41,7 @@ private:
        ReAppender& operator =(const ReAppender& source);
 public:
        virtual void log(ReLoggerLevel level, int location, const char* message,
-           ReLogger* logger) = 0;
+               ReLogger* logger) = 0;
        bool isActive(ReLoggerLevel level);
        void setLevel(ReLoggerLevel level);
        void setAutoDelete(bool onNotOff);
@@ -74,14 +74,14 @@ public:
        bool logv(ReLoggerLevel level, int location, const char* format, ...);
        bool logv(ReLoggerLevel level, int location, const QByteArray& format, ...);
        bool log(ReLoggerLevel level, int location, const char* format,
-           va_list& varlist);
+               va_list& varlist);
        void addAppender(ReAppender* appender);
        ReAppender* findAppender(const char* name) const;
        void buildStandardAppender(ReConfig* config,
-           const char* prefix = "logfile.", const char* defaultLoggerName =
-               "logger");
+               const char* prefix = "logfile.", const char* defaultLoggerName =
+                       "logger");
        void buildStandardAppender(const QByteArray& prefix,
-           int maxSize = 10 * 1024 * 1024, int maxCount = 5);
+               int maxSize = 10 * 1024 * 1024, int maxCount = 5);
        QByteArray buildStdPrefix(ReLoggerLevel level, int location);
        const QByteArray& getStdPrefix(ReLoggerLevel level, int location);
        char getPrefixOfLevel(ReLoggerLevel level) const;
@@ -114,7 +114,7 @@ public:
        virtual ~ReStreamAppender();
 public:
        virtual void log(ReLoggerLevel level, int location, const char* message,
-           ReLogger* logger);
+               ReLogger* logger);
 private:
        // stdout or stderr:
        FILE* m_fp;
@@ -126,12 +126,12 @@ private:
 class ReFileAppender: public ReAppender {
 public:
        ReFileAppender(const QByteArray& name, int maxSize, int maxCount,
-           const char* appenderName = "FileAppender");
+               const char* appenderName = "FileAppender");
        virtual ~ReFileAppender();
 public:
        void open();
        virtual void log(ReLoggerLevel level, int location, const char* message,
-           ReLogger* logger);
+               ReLogger* logger);
 
 private:
        // prefix of the log file name. Will be appended by ".<no>.log"
@@ -154,11 +154,11 @@ private:
 class ReMemoryAppender: public ReAppender {
 public:
        ReMemoryAppender(int maxLines = 1024, const char* appenderName =
-           "MemoryAppender");
+               "MemoryAppender");
        ~ReMemoryAppender();
 public:
        virtual void log(ReLoggerLevel level, int location, const char* message,
-           ReLogger* logger);
+               ReLogger* logger);
        const QList<QByteArray>& getLines() const;
        void clear();
 private:
@@ -178,7 +178,13 @@ public:
        ~ReDebugAppender();
 public:
        virtual void log(ReLoggerLevel level, int location, const char* message,
-           ReLogger* logger);
+               ReLogger* logger);
 };
 
+class ReMemoryLogger : public ReLogger, public ReMemoryAppender {
+public:
+       ReMemoryLogger();
+};
+
+
 #endif // RELOGGER_HPP
index 74306b66e61bd986a4980997e1c2e3c1ab19f3ee..d09a6e11eac6c1a8819540e27b3bf256008ae2f0 100644 (file)
@@ -16,7 +16,7 @@
  * Constructor.
  */
 ReGuiValidator::ReGuiValidator() :
-           m_errors(0) {
+               m_errors(0) {
 }
 
 /**
@@ -61,7 +61,7 @@ QDateTime ReGuiValidator::comboDate(QComboBox* combo) {
  *                      otherwise: or the size resulting from the formula
  */
 int ReGuiValidator::comboInt(QComboBox* combo, int defaultValue,
-    const char* specialString, int specialValue) {
+       const char* specialString, int specialValue) {
        QString value = combo->currentText();
        int rc = defaultValue;
        if (!value.isEmpty()) {
@@ -69,7 +69,7 @@ int ReGuiValidator::comboInt(QComboBox* combo, int defaultValue,
                        rc = specialValue;
                } else {
                        uint nValue = 0;
-                       if (ReQStringUtil::lengthOfUInt(value, 0, 10, &nValue) == 0)
+                       if (ReQStringUtils::lengthOfUInt(value, 0, 10, &nValue) == 0)
                                guiError(combo, QObject::tr("not an integer: ") + value);
                        else {
                                setInHistory(combo, value);