From e67d34a51110482c70d1a57911f85a0ec1480ba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Tue, 21 Jun 2016 21:56:52 +0200 Subject: [PATCH] Added a new class for storing specific YACReader's http session data. --- YACReaderLibrary/server/server.pri | 6 +- .../server/yacreader_http_session.cpp | 165 ++++++++++++++++++ .../server/yacreader_http_session.h | 71 ++++++++ 3 files changed, 240 insertions(+), 2 deletions(-) create mode 100644 YACReaderLibrary/server/yacreader_http_session.cpp create mode 100644 YACReaderLibrary/server/yacreader_http_session.h diff --git a/YACReaderLibrary/server/server.pri b/YACReaderLibrary/server/server.pri index b47413c6..4dc0e3ca 100644 --- a/YACReaderLibrary/server/server.pri +++ b/YACReaderLibrary/server/server.pri @@ -19,7 +19,8 @@ HEADERS += \ #v2 $$PWD/controllers/versioncontroller.h \ $$PWD/controllers/foldercontentcontroller.h \ - $$PWD/controllers/tagscontroller.h + $$PWD/controllers/tagscontroller.h \ + $$PWD/yacreader_http_session.h SOURCES += \ $$PWD/static.cpp \ @@ -39,7 +40,8 @@ SOURCES += \ #v2 $$PWD/controllers/versioncontroller.cpp \ $$PWD/controllers/foldercontentcontroller.cpp \ - $$PWD/controllers/tagscontroller.cpp + $$PWD/controllers/tagscontroller.cpp \ + $$PWD/yacreader_http_session.cpp include(lib/logging/logging.pri) include(lib/httpserver/httpserver.pri) diff --git a/YACReaderLibrary/server/yacreader_http_session.cpp b/YACReaderLibrary/server/yacreader_http_session.cpp new file mode 100644 index 00000000..7a9c533e --- /dev/null +++ b/YACReaderLibrary/server/yacreader_http_session.cpp @@ -0,0 +1,165 @@ +#include "yacreader_http_session.h" + +YACReaderHttpSession::YACReaderHttpSession(QObject *parent) + : QObject(parent), comic(nullptr), remoteComic(nullptr), comicId(0), remoteComicId(0) +{ + +} + +bool YACReaderHttpSession::isComicOnDevice(const QString & hash) +{ + return comicsOnDevice.contains(hash); +} + +bool YACReaderHttpSession::isComicDownloaded(const QString & hash) +{ + return downloadedComics.contains(hash); +} + +void YACReaderHttpSession::setComicOnDevice(const QString & hash) +{ + comicsOnDevice.insert(hash); +} + +void YACReaderHttpSession::setComicsOnDevice(const QSet & set) +{ + comicsOnDevice = set; +} + +void YACReaderHttpSession::setDownloadedComic(const QString & hash) +{ + downloadedComics.insert(hash); +} + +QSet YACReaderHttpSession::getComicsOnDevice() +{ + return comicsOnDevice ; +} + +QSet YACReaderHttpSession::getDownloadedComics() +{ + return downloadedComics ; +} + +void YACReaderHttpSession::clearComics() +{ + comicsOnDevice.clear(); + downloadedComics.clear(); +} +//current comic (import) +qulonglong YACReaderHttpSession::getCurrentComicId() +{ + return comicId; +} + +Comic* YACReaderHttpSession::getCurrentComic() +{ + comic; +} + +void YACReaderHttpSession::dismissCurrentComic() +{ + if(comic != nullptr) + { + comic->deleteLater(); + comic = nullptr; + } +} + +void YACReaderHttpSession::setCurrentComic(qulonglong id, Comic * comic) +{ + dismissCurrentComic(); + comicId = id; + comic = comic; +} + +//current comic (read) +qulonglong YACReaderHttpSession::getCurrentRemoteComicId() +{ + return remoteComicId ; +} + +Comic* YACReaderHttpSession::getCurrentRemoteComic() +{ + return remoteComic ; +} + +void YACReaderHttpSession::dismissCurrentRemoteComic() +{ + if(remoteComic != nullptr) + { + remoteComic->deleteLater(); + remoteComic = nullptr; + } +} + +void YACReaderHttpSession::setCurrentRemoteComic(qulonglong id, Comic * comic) +{ + dismissCurrentRemoteComic(); + remoteComicId = id; + remoteComic = comic; +} + +QString YACReaderHttpSession::getDeviceType() +{ + return device; +} + +QString YACReaderHttpSession::getDisplayType() +{ + return display; +} + +void YACReaderHttpSession::setDeviceType(const QString & device) +{ + //comicsOnDevice.clear(); //TODO crear un m�todo clear que limpie la sesi�n completamente + //downloadedComics.clear(); + device = device; +} + +void YACReaderHttpSession::setDisplayType(const QString & display) +{ + display = display; +} + +void YACReaderHttpSession::clearNavigationPath() +{ + navigationPath.clear(); +} + +QPair YACReaderHttpSession::popNavigationItem() +{ + if(navigationPath.isEmpty() == false) + return navigationPath.pop(); + return QPair(); +} + +QPair YACReaderHttpSession::topNavigationItem() +{ + if(navigationPath.isEmpty() == false) + return navigationPath.top(); + return QPair(); +} + +void YACReaderHttpSession::pushNavigationItem(const QPair &item) +{ + navigationPath.push(item); +} + +void YACReaderHttpSession::updateTopItem(const QPair &item) +{ + if(navigationPath.isEmpty() == false) + { + navigationPath.pop(); + navigationPath.push(item); + } + else + { + navigationPath.push(item); + } +} + +QStack > YACReaderHttpSession::getNavigationPath() +{ + return navigationPath; +} diff --git a/YACReaderLibrary/server/yacreader_http_session.h b/YACReaderLibrary/server/yacreader_http_session.h new file mode 100644 index 00000000..cc6a3131 --- /dev/null +++ b/YACReaderLibrary/server/yacreader_http_session.h @@ -0,0 +1,71 @@ +#ifndef YACREADERHTTPSESSION_H +#define YACREADERHTTPSESSION_H + +#include + +#include "comic.h" + + + +class YACReaderHttpSession : public QObject +{ + Q_OBJECT +public: + explicit YACReaderHttpSession(QObject *parent = 0); + + void setComicsOnDevice(const QSet & set); + void setComicOnDevice(const QString & hash); + void setDownloadedComic(const QString & hash); + bool isComicOnDevice(const QString & hash); + bool isComicDownloaded(const QString & hash); + QSet getComicsOnDevice(); + QSet getDownloadedComics(); + void clearComics(); + + //current comic (import) + qulonglong getCurrentComicId(); + Comic * getCurrentComic(); + void dismissCurrentComic(); + void setCurrentComic(qulonglong id, Comic * comic); + + //current comic (read) + qulonglong getCurrentRemoteComicId(); + Comic * getCurrentRemoteComic(); + void dismissCurrentRemoteComic(); + void setCurrentRemoteComic(qulonglong id, Comic * comic); + + //device identification + QString getDeviceType(); + QString getDisplayType(); + void setDeviceType(const QString & device); + void setDisplayType(const QString & display); + + void clearNavigationPath(); + QPair popNavigationItem(); + QPair topNavigationItem(); + void pushNavigationItem(const QPair & item); + void updateTopItem(const QPair & item); + + //TODO replace QPair by a custom class for storing folderId, page and folderName(save some DB accesses) + QStack > getNavigationPath(); + +signals: + +public slots: + +private: + QSet comicsOnDevice; + QSet downloadedComics; + + QString device; + QString display; + + qulonglong comicId; + qulonglong remoteComicId; + Comic * comic; + Comic * remoteComic; + + QStack > navigationPath; /* folder_id, page_number */ +}; + +#endif // YACREADERHTTPSESSION_H