mirror of
https://github.com/YACReader/yacreader
synced 2025-07-20 22:14:41 -04:00
Creada provisionalmente clase Comic2 que evita los problemas de gesti?n de memoria
This commit is contained in:
@ -10,24 +10,68 @@ extern LibraryWindow * mw;
|
||||
#include "comic_db.h"
|
||||
#include "comic.h"
|
||||
|
||||
Synchronizer::Synchronizer(Comic2 * c,QString p,QThread * f)
|
||||
:QThread(),comic(c),path(p),from(f)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Synchronizer::run()
|
||||
{
|
||||
connect(comic,SIGNAL(numPages(unsigned int)),this,SLOT(waitedSignal()));
|
||||
loaded = comic->load(path);
|
||||
}
|
||||
|
||||
void Synchronizer::waitedSignal()
|
||||
{
|
||||
if(loaded)
|
||||
{
|
||||
comic->moveToThread(from);
|
||||
quit();
|
||||
}
|
||||
else
|
||||
{
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ComicController::ComicController() {}
|
||||
|
||||
void ComicController::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
|
||||
|
||||
HttpSession session=Static::sessionStore->getSession(request,response);
|
||||
|
||||
QStringList pathElements = ((QString)request.getPath()).split('/');
|
||||
QString libraryName = pathElements.at(2);
|
||||
qulonglong comicId = pathElements.at(4).toULongLong();
|
||||
|
||||
//TODO
|
||||
//if(pathElements.size() == 6)
|
||||
//{
|
||||
// QString action = pathElements.at(5);
|
||||
// if(!action.isEmpty() && (action == "close"))
|
||||
// {
|
||||
// session.dismissCurrentComic();
|
||||
// response.write("",true);
|
||||
// return;
|
||||
// }
|
||||
//}
|
||||
|
||||
QMap<QString,QString> libraries = mw->getLibraries();
|
||||
|
||||
|
||||
ComicDB comic = mw->getComicInfo(libraryName, comicId);
|
||||
|
||||
Comic * comicFile = new Comic;
|
||||
Comic2 * comicFile = new Comic2;
|
||||
//Synchronizer * synchronizer = new Synchronizer(comicFile,libraries.value(libraryName)+comic.path, this->thread());
|
||||
//comicFile->moveToThread(synchronizer);
|
||||
|
||||
|
||||
//synchronizer->start();
|
||||
//QApplication::instance()->exec();
|
||||
//synchronizer->wait(20000);
|
||||
|
||||
if(comicFile->load(libraries.value(libraryName)+comic.path))
|
||||
{
|
||||
session.setCurrentComic(comic.id, comicFile);
|
||||
@ -45,10 +89,6 @@ void ComicController::service(HttpRequest& request, HttpResponse& response)
|
||||
response.setStatus(404,"not found");
|
||||
response.write("404 not found",true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//response.write(t.toLatin1(),true);
|
||||
|
||||
}
|
@ -5,11 +5,14 @@
|
||||
#include "httpresponse.h"
|
||||
#include "httprequesthandler.h"
|
||||
|
||||
#include <QThread>
|
||||
class Comic2;
|
||||
class QString;
|
||||
|
||||
class ComicController : public HttpRequestHandler {
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(ComicController);
|
||||
public:
|
||||
|
||||
/** Constructor */
|
||||
ComicController();
|
||||
|
||||
@ -17,4 +20,21 @@ public:
|
||||
void service(HttpRequest& request, HttpResponse& response);
|
||||
};
|
||||
|
||||
class Synchronizer : public QThread
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
public:
|
||||
Synchronizer(Comic2 * c, QString p, QThread * f);
|
||||
bool loaded;
|
||||
private:
|
||||
Comic2 * comic;
|
||||
QString path;
|
||||
QThread * from;
|
||||
|
||||
void run();
|
||||
public slots:
|
||||
void waitedSignal();
|
||||
};
|
||||
|
||||
#endif // COMICCONTROLLER_H
|
||||
|
@ -16,6 +16,8 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
||||
|
||||
HttpSession session=Static::sessionStore->getSession(request,response);
|
||||
|
||||
|
||||
|
||||
QString y = session.get("xxx").toString();
|
||||
response.writeText(QString("session xxx : %1 <br/>").arg(y));
|
||||
|
||||
@ -29,16 +31,36 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
|
||||
QList<LibraryItem *> folderComics = mw->getFolderComicsFromLibrary(libraryName,parentId);
|
||||
|
||||
qulonglong backId = mw->getParentFromComicFolderId(libraryName,parentId);
|
||||
if(backId == 1 && parentId == 1)
|
||||
t.setVariable(QString("upurl"),"/");
|
||||
else
|
||||
t.setVariable(QString("upurl"),"/library/" + libraryName + "/folder/" +QString("%1").arg(backId));
|
||||
|
||||
|
||||
int page = 0;
|
||||
QByteArray p = request.getParameter("page");
|
||||
if(p.length() != 0)
|
||||
page = p.toInt();
|
||||
|
||||
// /comicIdi/pagei/comicIdj/pagej/....../comicIdn/pagen
|
||||
//QString currentPath = session.get("currentPath").toString();
|
||||
//QStringList pathSize = currentPath.split("/").last().toInt;
|
||||
|
||||
|
||||
if(backId == 1 && parentId == 1)
|
||||
t.setVariable(QString("upurl"),"/?page=0");
|
||||
else
|
||||
t.setVariable(QString("upurl"),"/library/" + libraryName + "/folder/" +QString("%1").arg(backId));//.arg(upPage));
|
||||
|
||||
/*if(currentPath.length()>0)
|
||||
{
|
||||
if(currentPath.contains(QString("%1").arg(parentId))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
session.set("currentPath",currentPath+QString("/%1/%2").arg(parentId).arg(page);
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
//t.loop("element",folderContent.length());
|
||||
|
||||
int elementsPerPage = 10;
|
||||
|
@ -3,37 +3,62 @@
|
||||
#include "../static.h"
|
||||
|
||||
#include "comic.h"
|
||||
#include "comiccontroller.h"
|
||||
#include <QDataStream>
|
||||
#include <QPointer>
|
||||
|
||||
PageController::PageController() {}
|
||||
|
||||
void PageController::service(HttpRequest& request, HttpResponse& response)
|
||||
{
|
||||
|
||||
|
||||
HttpSession session=Static::sessionStore->getSession(request,response);
|
||||
|
||||
QStringList pathElements = ((QString)request.getPath()).split('/');
|
||||
QString libraryName = pathElements.at(2);
|
||||
qulonglong comicId = pathElements.at(4).toULongLong();
|
||||
quint16 page = pathElements.at(6).toUInt();
|
||||
unsigned int page = pathElements.at(6).toUInt();
|
||||
|
||||
Comic * comicFile = session.getCurrentComic();
|
||||
if((comicFile != 0) && comicId == session.getCurrentComicId())
|
||||
Comic2 * comicFile = session.getCurrentComic();
|
||||
if(session.getCurrentComicId() != 0 && !QPointer<Comic2>(comicFile).isNull())
|
||||
{
|
||||
response.setHeader("Content-Type", "image/page");
|
||||
QByteArray pageData = comicFile->getRawPage(page);
|
||||
response.write(pageData);
|
||||
if(comicId == session.getCurrentComicId() && page < comicFile->numPages())
|
||||
{
|
||||
if(comicFile->pageIsLoaded(page))
|
||||
{
|
||||
response.setHeader("Content-Type", "yacreader/page");
|
||||
QByteArray pageData = comicFile->getRawPage(page);
|
||||
QDataStream data(pageData);
|
||||
int i=0;
|
||||
char buffer[65536];
|
||||
while (!data.atEnd()) {
|
||||
int len = data.readRawData(buffer,65536);
|
||||
response.write(QByteArray(buffer,len));
|
||||
}
|
||||
//response.write(pageData);
|
||||
}
|
||||
else
|
||||
{
|
||||
response.setStatus(404,"not found"); //TODO qu<71> mensaje enviar
|
||||
response.write("404 not found",true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(comicId != session.getCurrentComicId())
|
||||
{
|
||||
//delete comicFile;
|
||||
session.dismissCurrentComic();
|
||||
}
|
||||
response.setStatus(404,"not found"); //TODO qu<71> mensaje enviar
|
||||
response.write("404 not found",true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
delete comicFile;
|
||||
response.setStatus(404,"not found");
|
||||
response.write("404 not found",true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//response.write(t.toLatin1(),true);
|
||||
|
||||
}
|
@ -15,6 +15,7 @@ HttpSession::HttpSession(bool canStore) {
|
||||
dataPtr->lastAccess=QDateTime::currentMSecsSinceEpoch();
|
||||
dataPtr->id=QUuid::createUuid().toString().toAscii();
|
||||
dataPtr->yacreaderSessionData.comic = 0;
|
||||
dataPtr->yacreaderSessionData.comicId = 0;
|
||||
#ifdef SUPERVERBOSE
|
||||
qDebug("HttpSession: created new session data with id %s",dataPtr->id.data());
|
||||
#endif
|
||||
@ -180,7 +181,7 @@ qulonglong HttpSession::getCurrentComicId()
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
Comic * HttpSession::getCurrentComic()
|
||||
Comic2* HttpSession::getCurrentComic()
|
||||
{
|
||||
if(dataPtr)
|
||||
{
|
||||
@ -196,6 +197,7 @@ void HttpSession::dismissCurrentComic()
|
||||
if(dataPtr->yacreaderSessionData.comic != 0)
|
||||
{
|
||||
delete dataPtr->yacreaderSessionData.comic;
|
||||
dataPtr->yacreaderSessionData.comic = 0;
|
||||
}
|
||||
dataPtr->yacreaderSessionData.comicId = 0;
|
||||
}
|
||||
@ -215,7 +217,7 @@ void HttpSession::setDownloadedComic(const QString & hash)
|
||||
dataPtr->yacreaderSessionData.downloadedComics.insert(hash);
|
||||
}
|
||||
}
|
||||
void HttpSession::setCurrentComic(qulonglong id, Comic * comic)
|
||||
void HttpSession::setCurrentComic(qulonglong id, Comic2 * comic)
|
||||
{
|
||||
if(dataPtr)
|
||||
{
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
#include <QSet>
|
||||
#include <QString>
|
||||
class Comic;
|
||||
#include "comic.h"
|
||||
|
||||
/**
|
||||
This class stores data for a single HTTP session.
|
||||
@ -96,12 +96,12 @@ public:
|
||||
bool isComicOnDevice(const QString & hash);
|
||||
bool isComicDownloaded(const QString & hash);
|
||||
qulonglong getCurrentComicId();
|
||||
Comic * getCurrentComic();
|
||||
Comic2 * getCurrentComic();
|
||||
void dismissCurrentComic();
|
||||
|
||||
void setComicsOnDevice(const QSet<QString> & set);
|
||||
void setDownloadedComic(const QString & hash);
|
||||
void setCurrentComic(qulonglong id, Comic * comic);
|
||||
void setCurrentComic(qulonglong id, Comic2 * comic);
|
||||
|
||||
private:
|
||||
|
||||
@ -112,7 +112,7 @@ private:
|
||||
QSet<QString> downloadedComics;
|
||||
//c<>mic actual que est<73> siendo descargado
|
||||
qulonglong comicId;
|
||||
Comic * comic;
|
||||
Comic2 * comic;
|
||||
};
|
||||
|
||||
struct HttpSessionData {
|
||||
|
Reference in New Issue
Block a user