Use the new session object in the all the controllers that need yacreader session information.

This commit is contained in:
Luis Ángel San Martín 2016-06-22 20:14:37 +02:00
parent b3aca9b542
commit d2e3b51089
5 changed files with 38 additions and 27 deletions

View File

@ -2,6 +2,7 @@
#include "db_helper.h"
#include "yacreader_libraries.h"
#include "yacreader_http_session.h"
#include "template.h"
#include "../static.h"
@ -18,6 +19,7 @@ ComicController::ComicController() {}
void ComicController::service(HttpRequest& request, HttpResponse& response)
{
HttpSession session=Static::sessionStore->getSession(request,response,false);
YACReaderHttpSession *ySession = Static::yacreaderSessionStore.value(session.getId());
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
QStringList pathElements = path.split('/');
@ -44,7 +46,7 @@ void ComicController::service(HttpRequest& request, HttpResponse& response)
ComicDB comic = DBHelper::getComicInfo(libraryId, comicId);
if(!remoteComic)
session.setDownloadedComic(comic.info.hash);
ySession->setDownloadedComic(comic.info.hash);
Comic * comicFile = FactoryComic::newComic(libraries.getPath(libraryId)+comic.path);
@ -70,13 +72,13 @@ void ComicController::service(HttpRequest& request, HttpResponse& response)
if(remoteComic)
{
QLOG_TRACE() << "remote comic requested";
session.setCurrentRemoteComic(comic.id, comicFile);
ySession->setCurrentRemoteComic(comic.id, comicFile);
}
else
{
QLOG_TRACE() << "comic requested";
session.setCurrentComic(comic.id, comicFile);
ySession->setCurrentComic(comic.id, comicFile);
}
response.setHeader("Content-Type", "text/plain; charset=utf-8");

View File

@ -1,6 +1,7 @@
#include "covercontroller.h"
#include "db_helper.h" //get libraries
#include "yacreader_libraries.h"
#include "yacreader_http_session.h"
#include "template.h"
#include "../static.h"
@ -9,8 +10,8 @@ CoverController::CoverController() {}
void CoverController::service(HttpRequest& request, HttpResponse& response)
{
HttpSession session=Static::sessionStore->getSession(request,response,false);
YACReaderHttpSession *ySession = Static::yacreaderSessionStore.value(session.getId());
response.setHeader("Content-Type", "image/jpeg");
response.setHeader("Connection","close");
@ -47,7 +48,7 @@ void CoverController::service(HttpRequest& request, HttpResponse& response)
if (!img.isNull()) {
int width = 80, height = 120;
if(session.getDisplayType()=="@2x")
if(ySession->getDisplayType()=="@2x")
{
width = 160;
height = 240;
@ -66,7 +67,7 @@ void CoverController::service(HttpRequest& request, HttpResponse& response)
if(folderCover)
{
if(session.getDisplayType()=="@2x")
if(ySession->getDisplayType()=="@2x")
p.drawImage(0,0,QImage(":/images/f_overlayed_retina.png"));
else
p.drawImage(0,0,QImage(":/images/f_overlayed.png"));

View File

@ -11,6 +11,8 @@
#include "qnaturalsorting.h"
#include "yacreader_http_session.h"
#include "QsLog.h"
struct LibraryItemSorter
@ -26,6 +28,7 @@ FolderController::FolderController() {}
void FolderController::service(HttpRequest& request, HttpResponse& response)
{
HttpSession session=Static::sessionStore->getSession(request,response,false);
YACReaderHttpSession *ySession = Static::yacreaderSessionStore.value(session.getId());
response.setHeader("Content-Type", "text/html; charset=utf-8");
response.setHeader("Connection","close");
@ -33,7 +36,7 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
//QString y = session.get("xxx").toString();
//response.writeText(QString("session xxx : %1 <br/>").arg(y));
Template t=Static::templateLoader->getTemplate("folder_"+session.getDeviceType(),request.getHeader("Accept-Language"));
Template t = Static::templateLoader->getTemplate("folder_"+ySession->getDeviceType(),request.getHeader("Accept-Language"));
t.enableWarnings();
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
QStringList pathElements = path.split('/');
@ -85,17 +88,17 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
if(folderId == 1)
{
session.clearNavigationPath();
session.pushNavigationItem(QPair<qulonglong,quint32>(folderId,page));
ySession->clearNavigationPath();
ySession->pushNavigationItem(QPair<qulonglong,quint32>(folderId,page));
t.setVariable(QString("upurl"),"/");
}
else
{
if(fromUp)
session.popNavigationItem();
ySession->popNavigationItem();
else //drill down or direct access
{
QStack<QPair<qulonglong, quint32> > path = session.getNavigationPath();
QStack<QPair<qulonglong, quint32> > path = ySession->getNavigationPath();
bool found=false;
for(QStack<QPair<qulonglong, quint32> >::const_iterator itr = path.begin(); itr!=path.end(); itr++)
if(itr->first == folderId)
@ -106,16 +109,16 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
if(found)
{
while(session.topNavigationItem().first != folderId)
session.popNavigationItem();
while(ySession->topNavigationItem().first != folderId)
ySession->popNavigationItem();
session.updateTopItem(QPair<qulonglong,quint32>(folderId,page));
ySession->updateTopItem(QPair<qulonglong,quint32>(folderId,page));
}
else
session.pushNavigationItem(QPair<qulonglong,quint32>(folderId,page));
ySession->pushNavigationItem(QPair<qulonglong,quint32>(folderId,page));
}
QStack<QPair<qulonglong, quint32> > path = session.getNavigationPath();
QStack<QPair<qulonglong, quint32> > path = ySession->getNavigationPath();
if(path.count()>1)
{
QPair<qulonglong, quint32> parentItem = path.at(path.count()-2);
@ -146,7 +149,7 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
int numFoldersAtCurrentPage = qMax(0,qMin(numFolders - indexCurrentPage, elementsPerPage));
//PATH
QStack<QPair<qulonglong,quint32> > foldersPath = session.getNavigationPath();
QStack<QPair<qulonglong,quint32> > foldersPath = ySession->getNavigationPath();
t.setVariable(QString("library.name"),libraryName);
t.setVariable(QString("library.url"),QString("/library/%1/folder/1").arg(libraryId));
t.loop("path",foldersPath.count()-1);
@ -195,9 +198,9 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
const ComicDB * comic = (ComicDB *)item;
t.setVariable(QString("element%1.browse").arg(i),"");
//t.setVariable(QString("element%1.downloadurl").arg(i),"/library/"+libraryName+"/comic/"+QString("%1").arg(comic->id));
if(!session.isComicOnDevice(comic->info.hash) && !session.isComicDownloaded(comic->info.hash))
if(!ySession->isComicOnDevice(comic->info.hash) && !ySession->isComicDownloaded(comic->info.hash))
t.setVariable(QString("element%1.download").arg(i),QString("<a onclick=\"this.innerHTML='IMPORTING';this.className='importedButton';\" class =\"importButton\" href=\"%1\">IMPORT</a>").arg("/library/"+QString::number(libraryId)+"/comic/"+QString("%1").arg(comic->id)));
else if (session.isComicOnDevice(comic->info.hash))
else if (ySession->isComicOnDevice(comic->info.hash))
t.setVariable(QString("element%1.download").arg(i),QString("<div class=\"importedButton\">IMPORTED</div>"));
else
t.setVariable(QString("element%1.download").arg(i),QString("<div class=\"importedButton\">IMPORTING</div>"));

View File

@ -1,6 +1,7 @@
#include "librariescontroller.h"
#include "db_helper.h" //get libraries
#include "yacreader_libraries.h"
#include "yacreader_http_session.h"
#include "template.h"
#include "../static.h"
@ -12,13 +13,14 @@ LibrariesController::LibrariesController() {}
void LibrariesController::service(HttpRequest& request, HttpResponse& response)
{
HttpSession session=Static::sessionStore->getSession(request,response,false);
YACReaderHttpSession *ySession = Static::yacreaderSessionStore.value(session.getId());
response.setHeader("Content-Type", "text/html; charset=utf-8");
response.setHeader("Connection","close");
session.clearNavigationPath();
ySession->clearNavigationPath();
Template t=Static::templateLoader->getTemplate("libraries_"+session.getDeviceType(),request.getHeader("Accept-Language"));
Template t=Static::templateLoader->getTemplate("libraries_"+ySession->getDeviceType(),request.getHeader("Accept-Language"));
t.enableWarnings();
YACReaderLibraries libraries = DBHelper::getLibraries();

View File

@ -4,6 +4,8 @@
#include "comic.h"
#include "comiccontroller.h"
#include "yacreader_http_session.h"
#include <QDataStream>
#include <QPointer>
@ -16,6 +18,7 @@ PageController::PageController() {}
void PageController::service(HttpRequest& request, HttpResponse& response)
{
HttpSession session=Static::sessionStore->getSession(request,response,false);
YACReaderHttpSession *ySession = Static::yacreaderSessionStore.value(session.getId());
QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8();
bool remote = path.endsWith("remote");
@ -35,14 +38,14 @@ void PageController::service(HttpRequest& request, HttpResponse& response)
if(remote)
{
QLOG_TRACE() << "se recupera comic remoto para servir páginas";
comicFile = session.getCurrentRemoteComic();
currentComicId = session.getCurrentRemoteComicId();
comicFile = ySession->getCurrentRemoteComic();
currentComicId = ySession->getCurrentRemoteComicId();
}
else
{
QLOG_TRACE() << "se recupera comic para servir páginas";
comicFile = session.getCurrentComic();
currentComicId = session.getCurrentComicId();
comicFile = ySession->getCurrentComic();
currentComicId = ySession->getCurrentComicId();
}
if(currentComicId != 0 && !QPointer<Comic>(comicFile).isNull())
@ -77,9 +80,9 @@ void PageController::service(HttpRequest& request, HttpResponse& response)
{
//delete comicFile;
if(remote)
session.dismissCurrentRemoteComic();
ySession->dismissCurrentRemoteComic();
else
session.dismissCurrentComic();
ySession->dismissCurrentComic();
}
response.setStatus(404,"not found"); //TODO qué mensaje enviar
response.write("404 not found",true);