From 3e08dc3507bab1b715c0e85cbdb0e5121d614027 Mon Sep 17 00:00:00 2001 From: hama Date: Tue, 9 Feb 2016 19:09:13 +0100 Subject: [PATCH] start of recommand --- appl/rebackgui/mainwindow.cpp | 29 ------ appl/rebackgui/mainwindow.hpp | 1 - appl/rebackgui/rebackgui.pro | 4 +- appl/recommand/CommandProcessor.cpp | 25 +++++ appl/recommand/CommandProcessor.hpp | 24 +++++ appl/recommand/main.cpp | 19 ++++ appl/recommand/mainwindow.cpp | 109 ++++++++++++++++++++ appl/recommand/mainwindow.hpp | 40 ++++++++ appl/recommand/mainwindow.ui | 150 ++++++++++++++++++++++++++++ appl/recommand/recommand.hpp | 16 +++ appl/recommand/recommand.pro | 37 +++++++ gui/ReGuiApplication.cpp | 22 +++- gui/ReGuiApplication.hpp | 1 + 13 files changed, 444 insertions(+), 33 deletions(-) create mode 100644 appl/recommand/CommandProcessor.cpp create mode 100644 appl/recommand/CommandProcessor.hpp create mode 100644 appl/recommand/main.cpp create mode 100644 appl/recommand/mainwindow.cpp create mode 100644 appl/recommand/mainwindow.hpp create mode 100644 appl/recommand/mainwindow.ui create mode 100644 appl/recommand/recommand.hpp create mode 100644 appl/recommand/recommand.pro diff --git a/appl/rebackgui/mainwindow.cpp b/appl/rebackgui/mainwindow.cpp index b3bc904..1a2ff3c 100644 --- a/appl/rebackgui/mainwindow.cpp +++ b/appl/rebackgui/mainwindow.cpp @@ -517,35 +517,6 @@ void MainWindow::onUpdate(){ saveState(); } - -/** - * Show a message. - * - * @param level LOG_ERROR or LOG_INFO - * @param message the message to show - * @return false: the message is an error message - */ -bool MainWindow::say(ReLoggerLevel level, const QString& message) -{ - if (level == LOG_ERROR) - error(message); - else - log(message); - setStatusMessage(level, message); - return level >= LOG_INFO; -} - -/** -* Writes a text to the status line. -* -* @param error true: the message is an error message -* @param message the text to set -*/ -void MainWindow::setStatusMessage(bool error, const QString& message){ - RE_UNUSED(error); - m_statusMessage->setText(message); -} - /** * Reads the history of the widget values and other parameters and set it. */ diff --git a/appl/rebackgui/mainwindow.hpp b/appl/rebackgui/mainwindow.hpp index 664e7ae..749ed75 100644 --- a/appl/rebackgui/mainwindow.hpp +++ b/appl/rebackgui/mainwindow.hpp @@ -30,7 +30,6 @@ public: void expandFileList(const QString info); bool log(const QString& message); virtual bool say(ReLoggerLevel level, const QString& message); - void setStatusMessage(bool error, const QString& message); void startStop(bool isStart); void restoreState(); void saveState(); diff --git a/appl/rebackgui/rebackgui.pro b/appl/rebackgui/rebackgui.pro index 8842e0c..ca70619 100644 --- a/appl/rebackgui/rebackgui.pro +++ b/appl/rebackgui/rebackgui.pro @@ -10,7 +10,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = rebackgui TEMPLATE = app -INCLUDEPATH = ../.. /usr/include/c++/4.9 +INCLUDEPATH = ../.. SOURCES += main.cpp\ ../../base/ReException.cpp \ @@ -50,5 +50,5 @@ FORMS += mainwindow.ui \ DISTFILES += \ ReBackGui.html \ - osconnect.pl + osconnect.pl diff --git a/appl/recommand/CommandProcessor.cpp b/appl/recommand/CommandProcessor.cpp new file mode 100644 index 0000000..c43ab27 --- /dev/null +++ b/appl/recommand/CommandProcessor.cpp @@ -0,0 +1,25 @@ +/* + * 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 "recommand.hpp" + +/** + * Constructor. + * + * @param mainWindow the GUI object + */ +CommandProcessor::CommandProcessor(MainWindow* mainWindow) : + m_mainWindow(mainWindow) +{ + +} + +void CommandProcessor::interpret(const QString& text) +{ + +} diff --git a/appl/recommand/CommandProcessor.hpp b/appl/recommand/CommandProcessor.hpp new file mode 100644 index 0000000..223466a --- /dev/null +++ b/appl/recommand/CommandProcessor.hpp @@ -0,0 +1,24 @@ +/* + * 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 COMMANDPROCESSOR_HPP +#define COMMANDPROCESSOR_HPP + +class MainWindow; + +class CommandProcessor +{ +public: + CommandProcessor(MainWindow* mainWindow); +public: + void interpret(const QString& text); +protected: + MainWindow* m_mainWindow; +}; + +#endif // COMMANDPROCESSOR_HPP diff --git a/appl/recommand/main.cpp b/appl/recommand/main.cpp new file mode 100644 index 0000000..344f0aa --- /dev/null +++ b/appl/recommand/main.cpp @@ -0,0 +1,19 @@ +/* + * 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 "recommand.hpp" +#include +char** g_argv; +int main(int argc, char *argv[]){ + g_argv = argv; + QString homeDir = argc > 1 ? argv[1] : ""; + QApplication a(argc, argv); + MainWindow w(homeDir); + w.show(); + return a.exec(); +} diff --git a/appl/recommand/mainwindow.cpp b/appl/recommand/mainwindow.cpp new file mode 100644 index 0000000..68e990e --- /dev/null +++ b/appl/recommand/mainwindow.cpp @@ -0,0 +1,109 @@ +/* + * 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 "recommand.hpp" + +MainWindow::MainWindow(const QString& homeDir, QWidget *parent) : + ReGuiApplication("recommand", homeDir, 2, 100100100, parent), + ReGuiValidator(), + ui(new Ui::MainWindow), + m_processor(NULL) +{ + ui->setupUi(this); + initializeGuiElements(); + connect(ui->pushButtonRun, SIGNAL(clicked()), this, SLOT(onRun())); + connect(ui->pushButtonClear, SIGNAL(clicked()), this, SLOT(onClear())); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + + +/** + * Clears the result field. + */ +void MainWindow::onClear() +{ + ui->textEditResult->clear(); +} + +/** + * Set GUI elements from the queue when the GUI timer is triggered. + */ +void MainWindow::onGuiTimerUpdate() +{ + int count = m_guiQueue.count(); + while(count-- > 0){ + m_mutexGuiQueue.lock(); + ReGuiQueueItem item = m_guiQueue.popFront(); + m_mutexGuiQueue.unlock(); + if (item.m_type == ReGuiQueueItem::Undef) + break; + if (! item.apply()){ + switch (item.m_type){ + case ReGuiQueueItem::ReadyMessage: + say(LOG_INFO, item.m_value); + break; + case ReGuiQueueItem::LogMessage: + say(LOG_INFO, item.m_value); + break; + case ReGuiQueueItem::LogError: + say(LOG_ERROR, item.m_value); + break; + case ReGuiQueueItem::StatusLine: + setStatusMessage(LOG_INFO, item.m_value); + break; + default: + say(LOG_ERROR, "unknown item type: " + QString::number(item.m_type) + + " " + item.m_value); + break; + } + } + } +} + +/** + * Executes the current commands. + */ +void MainWindow::onRun() +{ + +} + +/** + * Writes a message. + * + * @param level mode of the message, e.g. LOG_ERROR + * @param message the message + * @return falselevel is error or warning + */ +bool MainWindow::say(ReLoggerLevel level, const QString& message){ + QString edit = ui->textEditResult->toPlainText(); + QString msg; + switch(level){ + case LOG_WARNING: + msg = "+++ "; + break; + case LOG_ERROR: + msg = "*** "; + break; + default: + break; + } + + if (! edit.endsWith("\n")){ + msg += "\n"; + } + msg += message; + edit += msg; + ui->textEditResult->setText(edit); + return level >= LOG_INFO; +} + diff --git a/appl/recommand/mainwindow.hpp b/appl/recommand/mainwindow.hpp new file mode 100644 index 0000000..056d867 --- /dev/null +++ b/appl/recommand/mainwindow.hpp @@ -0,0 +1,40 @@ +/* + * 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 RECOMMAND_HPP +#include "recommand.hpp" +#endif +#ifndef MAINWINDOW_HPP +#define MAINWINDOW_HPP + +#include + +namespace Ui { +class MainWindow; +} + +class MainWindow : public ReGuiApplication, public ReGuiValidator +{ + Q_OBJECT + +public: + explicit MainWindow(const QString& homeDir, QWidget *parent = 0); + virtual ~MainWindow(); + +public: + virtual void onGuiTimerUpdate(); + void onRun(); + void onClear(); + virtual bool say(ReLoggerLevel level, const QString& message); + +private: + Ui::MainWindow *ui; + CommandProcessor* m_processor; +}; + +#endif // MAINWINDOW_HPP diff --git a/appl/recommand/mainwindow.ui b/appl/recommand/mainwindow.ui new file mode 100644 index 0000000..fe5a83c --- /dev/null +++ b/appl/recommand/mainwindow.ui @@ -0,0 +1,150 @@ + + + MainWindow + + + + 0 + 0 + 977 + 624 + + + + MainWindow + + + + + + + Qt::Vertical + + + + + + + + + Write command, try "help;" + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 125 + 0 + + + + Run + + + + + + + Save + + + + + + + + + + + + + + + + + + Result: + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Clear + + + + + + + + + + + + + + + + + + 0 + 0 + 977 + 26 + + + + + + TopToolBarArea + + + false + + + + + + toolBar + + + TopToolBarArea + + + false + + + + + + + diff --git a/appl/recommand/recommand.hpp b/appl/recommand/recommand.hpp new file mode 100644 index 0000000..7ca2a86 --- /dev/null +++ b/appl/recommand/recommand.hpp @@ -0,0 +1,16 @@ +/* + * 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 RECOMMAND_HPP +#define RECOMMAND_HPP +#include "base/rebase.hpp" +#include "gui/regui.hpp" +#include "CommandProcessor.hpp" +#include "mainwindow.hpp" +#include "ui_mainwindow.h" +#endif // RECOMMAND_HPP diff --git a/appl/recommand/recommand.pro b/appl/recommand/recommand.pro new file mode 100644 index 0000000..21da3bb --- /dev/null +++ b/appl/recommand/recommand.pro @@ -0,0 +1,37 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2016-02-09T13:02:50 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = recommand +TEMPLATE = app +INCLUDEPATH = ../.. + + +SOURCES += main.cpp\ + ../../base/ReException.cpp \ + ../../base/ReConfig.cpp \ + ../../base/ReQStringUtils.cpp \ + ../../base/ReFileUtils.cpp \ + ../../base/ReMatcher.cpp \ + ../../base/ReLogger.cpp \ + ../../base/ReRandomizer.cpp \ + ../../base/ReStringUtils.cpp \ + ../../gui/ReStateStorage.cpp \ + ../../gui/ReGuiApplication.cpp \ + ../../gui/ReGuiValidator.cpp \ + ../../gui/ReGuiQueue.cpp \ + ../../gui/ReGuiUtils.cpp \ + mainwindow.cpp \ + CommandProcessor.cpp + +HEADERS += mainwindow.hpp \ + CommandProcessor.hpp \ + recommand.hpp + +FORMS += mainwindow.ui diff --git a/gui/ReGuiApplication.cpp b/gui/ReGuiApplication.cpp index f80c676..4b38ab0 100644 --- a/gui/ReGuiApplication.cpp +++ b/gui/ReGuiApplication.cpp @@ -40,7 +40,7 @@ ReGuiApplication::ReGuiApplication(const char* applicationName, m_guiQueue(), m_guiTimer(new QTimer(this)), m_statusMessage(new QLabel(tr("Welcome!"))), - m_mutexGuiQueue() + m_mutexGuiQueue() { m_logger.buildStandardAppender(I18N::s2b(m_homeDir) + applicationName, maxLogSize, maxLogFiles); @@ -187,3 +187,23 @@ void ReGuiApplication::externalLog(const QString& message){ m_mutexGuiQueue.unlock(); } +/** +* Writes a text to the status line. +* +* @param level level of the messge: LOG_INFO, LOG_ERROR... +* @param message the text to set +*/ +void ReGuiApplication::setStatusMessage(ReLoggerLevel level, const QString& message){ + switch(level){ + case LOG_ERROR: + m_statusMessage->setText("! " + message); + break; + case LOG_WARNING: + m_statusMessage->setText("+ " + message); + break; + default: + m_statusMessage->setText(message); + break; + } +} + diff --git a/gui/ReGuiApplication.hpp b/gui/ReGuiApplication.hpp index 2b90c39..5532319 100644 --- a/gui/ReGuiApplication.hpp +++ b/gui/ReGuiApplication.hpp @@ -37,6 +37,7 @@ public: ReLogger* logger(); public: static QString buildHomeDir(QString homeDirBase, const QString& node); + void setStatusMessage(ReLoggerLevel level, const QString& message); protected: void initializeGuiElements(); protected slots: -- 2.39.5