From: hama Date: Mon, 14 Sep 2015 22:20:52 +0000 (+0200) Subject: ReFileSystem X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=f655f301a4ebf4d3250d2dabfee7606cba09dc2f;p=reqt ReFileSystem --- diff --git a/appl/reide/mainwindow.cpp b/appl/reide/mainwindow.cpp index 0d8aca2..9ec5186 100644 --- a/appl/reide/mainwindow.cpp +++ b/appl/reide/mainwindow.cpp @@ -20,7 +20,8 @@ MainWindow::MainWindow(const char* workspace, const char* project, m_logger(logger), m_perspectives(this), m_timerRuns(false), - m_timer(this){ + m_timer(this), + m_delayedStorage(NULL){ setLayout(new QVBoxLayout); if (workspace == NULL) workspace = QDir::homePath().toUtf8(); @@ -52,6 +53,7 @@ MainWindow::MainWindow(const char* workspace, const char* project, m_perspectives.addPerspective(mainPerspective); m_perspectives.change(mainPerspective->name()); m_perspectives.addPerspective(new ProjectPerspective(proj, this)); + m_delayedStorage = new ReDelayedStorage(m_workspace->historyFile()) } /** @@ -61,13 +63,10 @@ MainWindow::MainWindow(const char* workspace, const char* project, */ void MainWindow::geometryChanged(int value){ ReUseParameter(value); - if (! m_timer.isActive()){ - m_timer.start(5000); - } + m_delayedStorage->storeWindow(this); } void MainWindow::timeout(){ - ReSettings } /** diff --git a/appl/reide/mainwindow.hpp b/appl/reide/mainwindow.hpp index 2254719..3a3c43a 100644 --- a/appl/reide/mainwindow.hpp +++ b/appl/reide/mainwindow.hpp @@ -34,12 +34,15 @@ public: public slots: void open(); void geometryChanged(int value); +protected slots: + void timeout(); private: Workspace* m_workspace; ReLogger* m_logger; PerspectiveList m_perspectives; bool m_timerRuns; QTimer m_timer; + ReDelayedStorage* m_delayedStorage; }; #endif // MAINWINDOW_HPP diff --git a/appl/reide/reide.pro b/appl/reide/reide.pro index b169124..2c28034 100644 --- a/appl/reide/reide.pro +++ b/appl/reide/reide.pro @@ -10,7 +10,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = ReEditor TEMPLATE = app - +PRECOMPILED_HEADER = base/rebase.hpp INCLUDEPATH += ../.. SOURCES += \ @@ -43,6 +43,8 @@ HEADERS += mainwindow.hpp \ ../../base/rebase.hpp \ ../../gui/regui.hpp \ ../../gui/ReEdit.hpp \ + ../../gui/ReStateStorage.hpp \ + ../../gui/ReSettings.hpp \ ../../base/ReStringUtils.hpp \ ../../base/ReQStringUtils.hpp \ ../../base/ReException.hpp \ diff --git a/appl/reidos/idosmain.cpp b/appl/reidos/idosmain.cpp new file mode 100644 index 0000000..e2a4e6e --- /dev/null +++ b/appl/reidos/idosmain.cpp @@ -0,0 +1,23 @@ +/* + * 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 "idosmain.hpp" +#include "ui_idosmain.h" + +IDosMain::IDosMain(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::IDosMain) +{ + ui->setupUi(this); +} + +IDosMain::~IDosMain() +{ + delete ui; +} diff --git a/appl/reidos/idosmain.hpp b/appl/reidos/idosmain.hpp new file mode 100644 index 0000000..769371f --- /dev/null +++ b/appl/reidos/idosmain.hpp @@ -0,0 +1,31 @@ +/* + * 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 IDOSMAIN_HPP +#define IDOSMAIN_HPP + +#include + +namespace Ui { +class IDosMain; +} + +class IDosMain : public QMainWindow +{ + Q_OBJECT + +public: + explicit IDosMain(QWidget *parent = 0); + ~IDosMain(); + +private: + Ui::IDosMain *ui; +}; + +#endif // IDOSMAIN_HPP diff --git a/appl/reidos/idosmain.ui b/appl/reidos/idosmain.ui new file mode 100644 index 0000000..6054c6c --- /dev/null +++ b/appl/reidos/idosmain.ui @@ -0,0 +1,186 @@ + + + IDosMain + + + + 0 + 0 + 787 + 590 + + + + IDosMain + + + + + + + Qt::Vertical + + + + + + + + + true + + + + + + + ... + + + + + + + ... + + + + + + + ... + + + + + + + + + true + + + + Type + + + + + Size + + + + + Modified + + + + + Attributes + + + + + Name + + + + + + + + + + + + + + true + + + + + + + ... + + + + + + + ... + + + + + + + ... + + + + + + + + + true + + + + Type + + + + + Size + + + + + Modified + + + + + Attributes + + + + + Name + + + + + + + + + + + + + + 0 + 0 + 787 + 35 + + + + + + TopToolBarArea + + + false + + + + + + + + diff --git a/appl/reidos/main.cpp b/appl/reidos/main.cpp new file mode 100644 index 0000000..83d2a71 --- /dev/null +++ b/appl/reidos/main.cpp @@ -0,0 +1,20 @@ +/* + * 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 "idosmain.hpp" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + IDosMain w; + w.show(); + + return a.exec(); +} diff --git a/appl/reidos/reidos.pro b/appl/reidos/reidos.pro new file mode 100644 index 0000000..15e7855 --- /dev/null +++ b/appl/reidos/reidos.pro @@ -0,0 +1,41 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2015-09-14T18:00:57 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = reidos +TEMPLATE = app + +INCLUDEPATH += . ../.. + +SOURCES += main.cpp\ + ../../gui/ReEdit.cpp \ + ../../gui/ReStateStorage.cpp \ + ../../gui/ReSettings.cpp \ + ../../gui/ReFileTree.cpp \ + ../../base/ReFile.cpp \ + ../../os/ReFileSystem.cpp \ + ../../base/ReLogger.cpp \ + ../../base/ReQStringUtils.cpp \ + ../../base/ReFileUtils.cpp \ + ../../base/ReException.cpp \ + idosmain.cpp \ + main.cpp + +HEADERS += ../../base/rebase.hpp \ + ../../gui/regui.hpp \ + ../../gui/ReEdit.hpp \ + ../../gui/ReStateStorage.hpp \ + ../../gui/ReSettings.hpp \ + ../../base/ReStringUtils.hpp \ + ../../base/ReQStringUtils.hpp \ + ../../base/ReException.hpp \ + ../../os/reos.hpp \ + idosmain.hpp + +FORMS += idosmain.ui diff --git a/base/rebase.hpp b/base/rebase.hpp index d79125f..4894bf1 100644 --- a/base/rebase.hpp +++ b/base/rebase.hpp @@ -38,6 +38,12 @@ #include #include #include +#include +#include +#include +#include +#include + typedef unsigned char uint8_t; #if !defined __linux__ typedef qint64 int64_t; diff --git a/gui/ReSettings.cpp b/gui/ReSettings.cpp index db352a6..c8a10e1 100644 --- a/gui/ReSettings.cpp +++ b/gui/ReSettings.cpp @@ -206,6 +206,15 @@ void ReSettings::changeValue(const char* name, const QString& value) { property->m_value = value; } +/** + * Returns the name of the history file. + * @return the full name of the history file + */ +const QString& ReSettings::fileHistory() const +{ + return m_fileHistory; +} + /** * Returns a history item as a list. * @@ -396,30 +405,23 @@ void ReSettings::writeSettings() { * * @param delay time between first change of setting and storage in seconds */ -ReDelayedStorage::ReDelayedStorage(const QString& file, int delay) : +ReDelayedStorage::ReDelayedStorage(const QString& file, ReLogger* logger, + int delay) : m_timer(NULL), m_list(), m_delay(delay), - m_file(file){ + m_file(file), + m_logger(logger){ m_timer.setSingleShot(true); - QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(timeout())); + connect(&m_timer, SIGNAL(timeout()), this, SLOT(timeout())); } /** - * Tests whether a given widget is in the internal list. - * - * @param widget the widget to search - * @return true: the widget is in the list + * Destructor. */ -bool ReDelayedStorage::contains(const QWidget* widget){ - QList::const_iterator; - bool rc = false; - for (it = m_list.cbegin(); ! rc && it != m_list.cend(); ++it){ - ObjInfo* info = *it; - if (info->m_widget == widget) - rc = true; - } - return rc; +ReDelayedStorage::~ReDelayedStorage() +{ + } /** @@ -429,7 +431,7 @@ bool ReDelayedStorage::contains(const QWidget* widget){ * @return -1: not found
* otherwise: the index in m_list */ -QWidget*ReDelayedStorage::indexOf(const QWidget* widget) +int ReDelayedStorage::indexOf(const QWidget* widget) const { int rc = -1; for (int ix = 0; rc < 0 && ix < m_list.size(); ix++) @@ -443,16 +445,16 @@ QWidget*ReDelayedStorage::indexOf(const QWidget* widget) * * @param window the window to store */ -void ReDelayedStorage::storeWindow(QMainWindow* window) +void ReDelayedStorage::storeWindow(const QMainWindow* window) { int ix = indexOf(window); if (ix < 0){ ObjInfo* info = new ObjInfo; info->m_type = OT_WINDOW; - info->m_widget = widget; + info->m_widget = window; m_list.append(info); if (! m_timer.isActive()){ - timer.start(m_delay*1000); + m_timer.start(m_delay*1000); } } } @@ -462,7 +464,7 @@ void ReDelayedStorage::storeWindow(QMainWindow* window) */ void ReDelayedStorage::timeout() { - ReStateStorage storage(m_file); + ReStateStorage storage(m_file, m_logger); storage.initForRead(); for (int ix = 0; ix < m_list.size(); ix++){ ObjInfo* info = m_list.at(ix); diff --git a/gui/ReSettings.hpp b/gui/ReSettings.hpp index 9e1efa0..526e50d 100644 --- a/gui/ReSettings.hpp +++ b/gui/ReSettings.hpp @@ -11,7 +11,10 @@ #ifndef STORAGE_HPP #define STORAGE_HPP -#include +#ifndef REBASE_HPP +#include "base/rebase.hpp" +#endif + enum RePropertyType { PT_UNDEF, PT_INT, @@ -35,8 +38,9 @@ public: RePropertyType m_type; const char* m_limits; }; - -class ReDelayedStorage{ +class ReLogger; +class QMainWindow; +class ReDelayedStorage : protected QObject{ Q_OBJECT enum ObjType { OT_UNDEF, @@ -47,18 +51,20 @@ class ReDelayedStorage{ const QWidget* m_widget; } ObjInfo; public: - ReDelayedStorage(const QString& file, int delay = 5); + ReDelayedStorage(const QString& file, ReLogger* m_logger, int delay = 5); + virtual ~ReDelayedStorage(); public: void storeWindow(const QMainWindow* window); public: void timeout(); private: - int indexOf(const QWidget* widget); + int indexOf(const QWidget* widget) const; private: QTimer m_timer; QList m_list; int m_delay; QString m_file; + ReLogger* m_logger; }; class ReSettings { @@ -72,6 +78,7 @@ public: int maxEntries); bool boolValue(const char* name); void changeValue(const char* name, const QString& value); + const QString& fileHistory() const; QStringList& historyAsList(const char* key, QStringList& list, const char* form = NULL); void insertProperty(ReProperty* property); @@ -83,6 +90,7 @@ public: QString topOfHistory(const char* key, const QString& defaultValue = ""); void writeSettings(); + protected: QString m_prefix; QString m_path; diff --git a/os/ReFileSystem.cpp b/os/ReFileSystem.cpp new file mode 100644 index 0000000..2d9e14b --- /dev/null +++ b/os/ReFileSystem.cpp @@ -0,0 +1,100 @@ +/* + * ReTraverser.cpp + * + * License: Public Domain + * You can use and modify this file without any restriction. + * Do what you want. + * No warranties and disclaimer of any damages. + * You also can use this license: http://www.wtfpl.net + * The latest sources: https://github.com/republib + */ + +#include "base/rebase.hpp" +#include "os/reos.hpp" + + +/** + * Constructor. + * + * @param name the name of the filesystem + */ +ReFileSystem::ReFileSystem(const QString& name) : + m_name(name), m_writeable(false) +{ + +} + +/** + * Destructor. + */ +ReFileSystem::~ReFileSystem() +{ + +} + +bool ReFileSystem::getWriteable() const +{ + return m_writeable; +} + +void ReFileSystem::setWriteable(bool writeable) +{ + m_writeable = writeable; +} + +/** + * Constructor. + */ +ReLinuxFS::ReLinuxFS(const QString& basePath) : + m_path(basePath), + m_currentPath(basePath), + m_dir(basePath) +{ + +} + +/** + * Changes the current directory of the filesystem. + * + * @param path the new current directory + * @return 0: success
+ * EC_PATH_NOT_FOUND directory does not exist
+ * EC_NOT_ACCESSIBLE parent not readable + */ +ReFileSystem::ErrorCode ReLinuxFS::setDirectory(const QString& path) +{ + ErrorCode rc = m_dir.setCurrent(path) ? EC_SUCCESS : EC_PATH_NOT_FOUND; + m_currentPath = m_dir.absolutePath(); + return rc; +} + +/** + * Returns the name of the current directory. + * + * @return the name of the current directory + */ +const QString&ReLinuxFS::directory() const +{ + return m_currentDir; +} + +/** + * Returns a list of the file infos of the current directory. + * + * @param patterns only files matching these patterns will be in the result. + * Can contain wildcard '*' (for any string) + * @return a list of the files matching the patterns + */ +QList ReLinuxFS::listInfos(const QString& pattern) +{ + QList rc; + m_dir.setNameFilters(patterns); + QFileInfoList list = m_dir.entryInfoList(); + QFileInfoList::const_iterator it; + for (it = list.cbegin(); it != list.cend(); it++){ + const QFileInfo& info = *it; + ReFileMetaData* meta = new ReFileMetaData(info.fileName()); + + } +} + diff --git a/os/ReFileSystem.hpp b/os/ReFileSystem.hpp new file mode 100644 index 0000000..4f7a51e --- /dev/null +++ b/os/ReFileSystem.hpp @@ -0,0 +1,81 @@ +/* + * ReFileSystem.hpp + * + * License: Public Domain + * You can use and modify this file without any restriction. + * Do what you want. + * No warranties and disclaimer of any damages. + * You also can use this license: http://www.wtfpl.net + * The latest sources: https://github.com/republib + */ + +#ifndef OS_REFILESYSTEM_HPP_ +#define OS_REFILESYSTEM_HPP_ + +class ReFileMetaData { +public: + FileMetaData(const QString& node); + virtual ~FileMetaData(); +public: + QString m_node; + QDateTime m_modified; + QDateTime m_created; + int16_t m_owner; + int16_t m_group; + mode_t m_mode; +}; + +class ReFileSystem { + enum ErrorCode { + EC_SUCCESS, + EC_PATH_NOT_FOUND, + EC_NOT_ACCESSIBLE, + }; + +public: + ReFileSystem(const QString& name); + virtual ~ReFileSystem(); +public: + /** Changes the current directory of the filesystem. + * @param path the new current directory + * @return 0: success
+ * EC_PATH_NOT_FOUND directory does not exist
+ * EC_NOT_ACCESSIBLE parent not readable + */ + virtual ErrorCode setDirectory(const QString& path) = 0; + /** Returns the name of the current directory. + * @return the name of the current directory + */ + virtual const QString& directory() const = 0; + /** Returns a list of the file infos of the current directory. + * @param patterns only files matching these patterns will be in the result + * Can contain wildcard '*' (for any string) + * @return a list of the files matching the patterns + */ + virtual QList listInfos(const QStringList& patterns) = 0; +public: + bool getWriteable() const; + void setWriteable(bool writeable); + +protected: + QString m_name; + QString m_directory; + bool m_writeable; +}; + +class ReLinuxFS : public ReFileSystem { +public: + ReLinuxFS(const QString& basePath); + virtual ~ReLinuxFS(); + // ReFileSystem interface +public: + ErrorCode setDirectory(const QString& path); + const QString& directory() const; + QList listInfos(const QStringList& patterns); +protected: + QString m_basePath; + QString m_currentPath; + QDir m_dir; +}; + +#endif /* OS_REFILESYSTEM_HPP_ */ diff --git a/os/reos.hpp b/os/reos.hpp index 5cbb396..f4b0fe6 100644 --- a/os/reos.hpp +++ b/os/reos.hpp @@ -44,5 +44,6 @@ inline bool operator >(const ReFileTime_t& time1, const ReFileTime_t& time2) { #include "os/ReDirTools.hpp" #include "net/renet.hpp" #include "os/ReRemoteDir.hpp" +#include "os/ReFileSystem.hpp" #endif /* OS_REOS_HPP_ */