--- /dev/null
+/*
+ * 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);
+ }
+}
+
--- /dev/null
+/*
+ * 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
* 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();
+}
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
*/
-#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();
--- /dev/null
+/*
+ * 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
+
../../gui/ReStateStorage.cpp \
../../gui/ReSettings.cpp \
../../gui/ReFileTree.cpp \
+ ../../gui/ReGuiValidator.cpp \
../../base/ReMatcher.cpp \
../../base/ReFile.cpp \
../../base/ReStringUtils.cpp \
../../base/ReFileUtils.cpp \
../../base/ReException.cpp \
idosmain.cpp \
- main.cpp
+ main.cpp \
+ FileCommander.cpp
HEADERS += ../../base/rebase.hpp \
../../gui/regui.hpp \
../../base/ReQStringUtils.hpp \
../../base/ReException.hpp \
../../os/reos.hpp \
- idosmain.hpp
+ idosmain.hpp \
+ FileCommander.hpp \
+ reidos.hpp
FORMS += idosmain.ui
* @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) {
}
/**
* @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;
* @return true: for chaining
*/
bool ReLogger::log(ReLoggerLevel level, int location,
- const QByteArray& message) {
+ const QByteArray& message) {
return log(level, location, message.data());
}
* @return true: for chaining
*/
bool ReLogger::logv(ReLoggerLevel level, int location, const char* format,
- ...) {
+ ...) {
char buffer[64000];
va_list ap;
va_start(ap, 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);
* @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);
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);
}
* 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);
* @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);
}
* @brief Constructor.
*/
ReStreamAppender::ReStreamAppender(FILE* file, const char* appenderName) :
- ReAppender(QByteArray(appenderName)),
- m_fp(file) {
+ ReAppender(QByteArray(appenderName)),
+ m_fp(file) {
}
/**
* @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);
* @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();
}
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);
*/
#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);
* @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);
}
*/
#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)
* @param appenderName a name for the appender
*/
ReDebugAppender::ReDebugAppender(const char* appenderName) :
- ReAppender(appenderName) {
+ ReAppender(appenderName) {
}
/**
* Destructor.
* @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);
+}
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);
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;
virtual ~ReStreamAppender();
public:
virtual void log(ReLoggerLevel level, int location, const char* message,
- ReLogger* logger);
+ ReLogger* logger);
private:
// stdout or stderr:
FILE* m_fp;
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"
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:
~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
* Constructor.
*/
ReGuiValidator::ReGuiValidator() :
- m_errors(0) {
+ m_errors(0) {
}
/**
* 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()) {
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);