mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
A?adida la informaci?n de descarga de folders y c?mcs
A?adidos los atributos necesarios a la sesi?n relacionados con YACReader
This commit is contained in:
parent
12e697bc0f
commit
6373649672
@ -8,7 +8,8 @@ DEPENDPATH += .
|
||||
INCLUDEPATH += .
|
||||
INCLUDEPATH += ../common \
|
||||
./server \
|
||||
./db
|
||||
./db \
|
||||
../YACReader
|
||||
CONFIG += release
|
||||
CONFIG -= flat
|
||||
QT += sql network
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef __COMIC_H
|
||||
#define __COMIC_H
|
||||
#ifndef __COMICDB_H
|
||||
#define __COMICDB_H
|
||||
|
||||
#include "library_item.h"
|
||||
#include <QSqlDatabase>
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "comiccontroller.h"
|
||||
|
||||
#include "library_window.h"
|
||||
|
||||
extern LibraryWindow * mw;
|
||||
@ -7,25 +8,47 @@ extern LibraryWindow * mw;
|
||||
#include "../static.h"
|
||||
|
||||
#include "comic_db.h"
|
||||
#include "comic.h"
|
||||
|
||||
ComicController::ComicController() {}
|
||||
|
||||
void ComicController::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
response.setHeader("Content-Type", "plain/text; charset=ISO-8859-1");
|
||||
|
||||
|
||||
HttpSession session=Static::sessionStore->getSession(request,response);
|
||||
|
||||
QStringList pathElements = ((QString)request.getPath()).split('/');
|
||||
QString libraryName = pathElements.at(2);
|
||||
qulonglong comicId = pathElements.at(4).toULongLong();
|
||||
|
||||
QMap<QString,QString> libraries = mw->getLibraries();
|
||||
|
||||
|
||||
ComicDB comic = mw->getComicInfo(libraryName, comicId);
|
||||
|
||||
response.writeText(QString("comicid:%1\n").arg(comic.id));
|
||||
response.writeText(QString("hash:%1\n").arg(comic.info.hash));
|
||||
response.writeText(QString("path:%1\n").arg(comic.path));
|
||||
response.writeText(QString("numpages:%1\n").arg(*comic.info.numPages));
|
||||
response.writeText(QString("library:%1\n").arg(libraryName),true);
|
||||
Comic * comicFile = new Comic;
|
||||
if(comicFile->load(libraries.value(libraryName)+comic.path))
|
||||
{
|
||||
session.setCurrentComic(comic.id, comicFile);
|
||||
|
||||
response.setHeader("Content-Type", "plain/text; charset=ISO-8859-1");
|
||||
response.writeText(QString("comicid:%1\n").arg(comic.id));
|
||||
response.writeText(QString("hash:%1\n").arg(comic.info.hash));
|
||||
response.writeText(QString("path:%1\n").arg(comic.path));
|
||||
response.writeText(QString("numpages:%1\n").arg(*comic.info.numPages));
|
||||
response.writeText(QString("library:%1\n").arg(libraryName),true);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete comicFile;
|
||||
response.setStatus(404,"not found");
|
||||
response.write("404 not found",true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//response.write(t.toLatin1(),true);
|
||||
|
||||
}
|
@ -65,6 +65,7 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
t.setVariable(QString("element%1.name").arg(i),folderContent.at(i + (page*10))->name);
|
||||
t.setVariable(QString("element%1.url").arg(i),"/library/"+libraryName+"/folder/"+QString("%1").arg(folderContent.at(i + (page*10))->id));
|
||||
t.setVariable(QString("element%1.downloadurl").arg(i),"/library/"+libraryName+"/folder/"+QString("%1/info").arg(folderContent.at(i + (page*10))->id));
|
||||
i++;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,39 @@
|
||||
#include "folderinfocontroller.h"
|
||||
#include "library_window.h" //get libraries
|
||||
|
||||
#include "folder.h"
|
||||
#include "comic_db.h"
|
||||
|
||||
#include "template.h"
|
||||
#include "../static.h"
|
||||
|
||||
extern LibraryWindow * mw;
|
||||
|
||||
FolderInfoController::FolderInfoController() {}
|
||||
|
||||
void FolderInfoController::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
response.setHeader("Content-Type", "plain/text; charset=ISO-8859-1");
|
||||
|
||||
QString path = request.getPath();
|
||||
QStringList pathElements = path.split('/');
|
||||
QString libraryName = pathElements.at(2);
|
||||
qulonglong parentId = pathElements.at(4).toULongLong();
|
||||
QList<LibraryItem *> folderContent = mw->getFolderContentFromLibrary(libraryName,parentId);
|
||||
QList<LibraryItem *> folderComics = mw->getFolderComicsFromLibrary(libraryName,parentId);
|
||||
|
||||
Folder * currentFolder;
|
||||
for(QList<LibraryItem *>::const_iterator itr = folderContent.constBegin();itr!=folderContent.constEnd();itr++)
|
||||
{
|
||||
currentFolder = (Folder *)(*itr);
|
||||
response.writeText(QString("/library/%1/folder/%2/info\n").arg(libraryName).arg(currentFolder->id));
|
||||
}
|
||||
|
||||
ComicDB * currentComic;
|
||||
for(QList<LibraryItem *>::const_iterator itr = folderComics.constBegin();itr!=folderComics.constEnd();itr++)
|
||||
{
|
||||
currentComic = (ComicDB *)(*itr);
|
||||
response.writeText(QString("/library/%1/comic/%2\n").arg(libraryName).arg(currentComic->id));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
#ifndef FOLDERINFOCONTROLLER_H
|
||||
#define FOLDERINFOCONTROLLER_H
|
||||
|
||||
#include "httprequest.h"
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
class FolderInfoController : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(FolderInfoController);
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
FolderInfoController();
|
||||
|
||||
/** Generates the response */
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
#endif // FOLDERINFOCONTROLLER_H
|
@ -7,6 +7,7 @@
|
||||
#include <QDateTime>
|
||||
#include <QUuid>
|
||||
|
||||
#include "comic.h"
|
||||
|
||||
HttpSession::HttpSession(bool canStore) {
|
||||
if (canStore) {
|
||||
@ -156,3 +157,70 @@ void HttpSession::setLastAccess() {
|
||||
dataPtr->lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//AÑADIDO
|
||||
bool HttpSession::isComicOnDevice(const QString & hash)
|
||||
{
|
||||
if(dataPtr)
|
||||
return dataPtr->yacreaderSessionData.downloadedComics.contains(hash);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
bool HttpSession::isComicDownloaded(const QString & hash)
|
||||
{
|
||||
if(dataPtr)
|
||||
return dataPtr->yacreaderSessionData.downloadedComics.contains(hash);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
qulonglong HttpSession::getCurrentComicId()
|
||||
{
|
||||
if(dataPtr)
|
||||
return dataPtr->yacreaderSessionData.comicId ;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
Comic * HttpSession::getCurrentComic()
|
||||
{
|
||||
if(dataPtr)
|
||||
{
|
||||
return dataPtr->yacreaderSessionData.comic ;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
void HttpSession::dismissCurrentComic()
|
||||
{
|
||||
if(dataPtr)
|
||||
{
|
||||
if(dataPtr->yacreaderSessionData.comic != 0)
|
||||
{
|
||||
delete dataPtr->yacreaderSessionData.comic;
|
||||
}
|
||||
dataPtr->yacreaderSessionData.comicId = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void HttpSession::setComicsOnDevice(const QSet<QString> & set)
|
||||
{
|
||||
if(dataPtr)
|
||||
{
|
||||
dataPtr->yacreaderSessionData.comicsOnDevice = set;
|
||||
}
|
||||
}
|
||||
void HttpSession::setDownloadedComic(const QString & hash)
|
||||
{
|
||||
if(dataPtr)
|
||||
{
|
||||
dataPtr->yacreaderSessionData.downloadedComics.insert(hash);
|
||||
}
|
||||
}
|
||||
void HttpSession::setCurrentComic(qulonglong id, Comic * comic)
|
||||
{
|
||||
if(dataPtr)
|
||||
{
|
||||
dataPtr->yacreaderSessionData.comicId = id;
|
||||
dataPtr->yacreaderSessionData.comic = comic;
|
||||
}
|
||||
}
|
@ -10,7 +10,9 @@
|
||||
#include <QVariant>
|
||||
#include <QReadWriteLock>
|
||||
|
||||
|
||||
#include <QSet>
|
||||
#include <QString>
|
||||
class Comic;
|
||||
/**
|
||||
This class stores data for a single HTTP session.
|
||||
A session can store any number of key/value pairs. This class uses implicit
|
||||
@ -89,8 +91,29 @@ public:
|
||||
*/
|
||||
void setLastAccess();
|
||||
|
||||
//AÑADIDO
|
||||
bool isComicOnDevice(const QString & hash);
|
||||
bool isComicDownloaded(const QString & hash);
|
||||
qulonglong getCurrentComicId();
|
||||
Comic * getCurrentComic();
|
||||
void dismissCurrentComic();
|
||||
|
||||
void setComicsOnDevice(const QSet<QString> & set);
|
||||
void setDownloadedComic(const QString & hash);
|
||||
void setCurrentComic(qulonglong id, Comic * comic);
|
||||
|
||||
private:
|
||||
|
||||
struct YACReaderSessionData {
|
||||
//cómics disponibles en dispositivo
|
||||
QSet<QString> comicsOnDevice;
|
||||
//cómics que han sido descargados o están siendo descargados en esta sesión
|
||||
QSet<QString> downloadedComics;
|
||||
//cómic actual que está siendo descargado
|
||||
qulonglong comicId;
|
||||
Comic * comic;
|
||||
};
|
||||
|
||||
struct HttpSessionData {
|
||||
|
||||
/** Unique ID */
|
||||
@ -108,6 +131,8 @@ private:
|
||||
/** Storage for the key/value pairs; */
|
||||
QMap<QByteArray,QVariant> values;
|
||||
|
||||
YACReaderSessionData yacreaderSessionData;
|
||||
|
||||
};
|
||||
|
||||
/** Pointer to the shared data. */
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "controllers/foldercontroller.h"
|
||||
#include "controllers/covercontroller.h"
|
||||
#include "controllers/comiccontroller.h"
|
||||
#include "controllers/folderinfocontroller.h"
|
||||
|
||||
RequestMapper::RequestMapper(QObject* parent)
|
||||
:HttpRequestHandler(parent) {}
|
||||
@ -35,7 +36,10 @@ void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
|
||||
{
|
||||
FolderController().service(request, response);
|
||||
}
|
||||
|
||||
else if (path.contains("folder") && path.contains("info"))
|
||||
{
|
||||
FolderInfoController().service(request, response);
|
||||
}
|
||||
else if(path.contains("cover") )
|
||||
{
|
||||
CoverController().service(request, response);
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
<ul id="itemContainer">
|
||||
{loop element}
|
||||
<li><a href="{element.url}">{element.name}</a></li>
|
||||
<li><a href="{element.url}">{element.name}</a> - <a href="{element.downloadurl}">Download</a></li>
|
||||
{end element}
|
||||
|
||||
{loop elementcomic}
|
||||
|
Loading…
Reference in New Issue
Block a user