This commit is contained in:
Luis Ángel San Martín
2014-09-15 15:07:27 +02:00
92 changed files with 3878 additions and 820 deletions

View File

@ -21,7 +21,8 @@ void ComicController::service(HttpRequest& request, HttpResponse& response)
QString path = QUrl::fromPercentEncoding(request.getPath()).toLatin1();
QStringList pathElements = path.split('/');
QString libraryName = DBHelper::getLibraryName(pathElements.at(2).toInt());
qulonglong libraryId = pathElements.at(2).toLongLong();
QString libraryName = DBHelper::getLibraryName(libraryId);
qulonglong comicId = pathElements.at(4).toULongLong();
bool remoteComic = path.endsWith("remote");
@ -38,20 +39,14 @@ void ComicController::service(HttpRequest& request, HttpResponse& response)
// }
//}
//Aplicar a todos los controladores
//TODO usar LibraryWindow para acceder a informaci<63>n de las bases de datos est<73> mal, hay
//que crear una clase que se encargue de estas cosas
//<2F>Se est<73> accediendo a la UI desde un hilo?
YACReaderLibraries libraries = DBHelper::getLibraries();
ComicDB comic = DBHelper::getComicInfo(libraryName, comicId);
ComicDB comic = DBHelper::getComicInfo(libraryId, comicId);
if(!remoteComic)
session.setDownloadedComic(comic.info.hash);
Comic * comicFile = FactoryComic::newComic(libraries.getPath(libraryName)+comic.path);
Comic * comicFile = FactoryComic::newComic(libraries.getPath(libraryId)+comic.path);
if(comicFile != NULL)
{
@ -64,7 +59,7 @@ void ComicController::service(HttpRequest& request, HttpResponse& response)
connect(thread, SIGNAL(started()), comicFile, SLOT(process()));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
comicFile->load(libraries.getPath(libraryName)+comic.path);
comicFile->load(libraries.getPath(libraryId)+comic.path);
if(thread != NULL)
thread->start();
@ -84,10 +79,10 @@ void ComicController::service(HttpRequest& request, HttpResponse& response)
response.setHeader("Content-Type", "plain/text; charset=ISO-8859-1");
//TODO this field is not used by the client!
response.writeText(QString("library:%1\r\n").arg(libraryName));
response.writeText(QString("libraryId:%1\r\n").arg(pathElements.at(2)));
response.writeText(QString("libraryId:%1\r\n").arg(libraryId));
if(remoteComic) //send previous and next comics id
{
QList<LibraryItem *> siblings = DBHelper::getFolderComicsFromLibrary(libraryName, comic.parentId);
QList<LibraryItem *> siblings = DBHelper::getFolderComicsFromLibrary(libraryId, comic.parentId);
bool found = false;
int i;
for(i = 0; i < siblings.length(); i++)

View File

@ -0,0 +1,24 @@
#include "comicdownloadinfocontroller.h"
#include "db_helper.h"
#include "yacreader_libraries.h"
#include "comic_db.h"
ComicDownloadInfoController::ComicDownloadInfoController() {}
void ComicDownloadInfoController::service(HttpRequest& request, HttpResponse& response)
{
QString path = QUrl::fromPercentEncoding(request.getPath()).toLatin1();
QStringList pathElements = path.split('/');
qulonglong libraryId = pathElements.at(2).toLongLong();
qulonglong comicId = pathElements.at(4).toULongLong();
ComicDB comic = DBHelper::getComicInfo(libraryId, comicId);
//TODO: check if the comic wasn't found;
response.writeText(QString("comicName:%1\r\n").arg(comic.getFileName()));
response.writeText(QString("fileSize:%1\r\n").arg(comic.getFileSize()),true);
}

View File

@ -0,0 +1,19 @@
#ifndef COMICDOWNLOADINFOCONTROLLER_H
#define COMICDOWNLOADINFOCONTROLLER_H
#include "httprequest.h"
#include "httpresponse.h"
#include "httprequesthandler.h"
class ComicDownloadInfoController : public HttpRequestHandler {
Q_OBJECT
Q_DISABLE_COPY(ComicDownloadInfoController);
public:
/** Constructor **/
ComicDownloadInfoController();
/** Generates the response */
void service(HttpRequest& request, HttpResponse& response);
};
#endif // COMICDOWNLOADINFOCONTROLLER_H

View File

@ -43,7 +43,7 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
folderId = qMax<qulonglong>(1,folderId);
QString folderName = DBHelper::getFolderName(libraryName,folderId);
QString folderName = DBHelper::getFolderName(libraryId,folderId);
if(folderName.isEmpty())
{
ErrorController(300).service(request,response);
@ -54,8 +54,8 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
t.setVariable("folder.name",folderName);
else
t.setVariable("folder.name",libraryName);
QList<LibraryItem *> folderContent = DBHelper::getFolderContentFromLibrary(libraryName,folderId);
QList<LibraryItem *> folderComics = DBHelper::getFolderComicsFromLibrary(libraryName,folderId);
QList<LibraryItem *> folderContent = DBHelper::getFolderSubfoldersFromLibrary(libraryId,folderId);
QList<LibraryItem *> folderComics = DBHelper::getFolderComicsFromLibrary(libraryId,folderId);
//response.writeText(libraryName);
@ -152,7 +152,7 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
t.loop("path",foldersPath.count()-1);
for(int i = 1; i < foldersPath.count(); i++){
t.setVariable(QString("path%1.url").arg(i-1),QString("/library/%1/folder/%2").arg(libraryId).arg(foldersPath[i].first));
t.setVariable(QString("path%1.name").arg(i-1),DBHelper::getFolderName(libraryName,foldersPath[i].first));
t.setVariable(QString("path%1.name").arg(i-1),DBHelper::getFolderName(libraryId,foldersPath[i].first));
}
t.loop("element",numFoldersAtCurrentPage);
@ -165,7 +165,7 @@ void FolderController::service(HttpRequest& request, HttpResponse& response)
{
t.setVariable(QString("element%1.class").arg(i),"folder");
QList<LibraryItem *> children = DBHelper::getFolderComicsFromLibrary(libraryName, item->id);
QList<LibraryItem *> children = DBHelper::getFolderComicsFromLibrary(libraryId, item->id);
if(children.length()>0)
{
const ComicDB * comic = static_cast<ComicDB*>(children.at(0));

View File

@ -19,21 +19,30 @@ void FolderInfoController::service(HttpRequest& request, HttpResponse& response)
int libraryId = pathElements.at(2).toInt();
QString libraryName = DBHelper::getLibraryName(libraryId);
qulonglong parentId = pathElements.at(4).toULongLong();
QList<LibraryItem *> folderContent = DBHelper::getFolderContentFromLibrary(libraryName,parentId);
QList<LibraryItem *> folderComics = DBHelper::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(libraryId).arg(currentFolder->id));
}
serviceComics(libraryId, parentId, response);
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(libraryId).arg(currentComic->id));
}
response.writeText("",true);
}
}
void FolderInfoController::serviceComics(const int &library, const qulonglong &folderId, HttpResponse &response)
{
QList<LibraryItem *> folderContent = DBHelper::getFolderSubfoldersFromLibrary(library,folderId);
QList<LibraryItem *> folderComics = DBHelper::getFolderComicsFromLibrary(library,folderId);
ComicDB * currentComic;
for(QList<LibraryItem *>::const_iterator itr = folderComics.constBegin();itr!=folderComics.constEnd();itr++)
{
currentComic = (ComicDB *)(*itr);
response.writeText(QString("/library/%1/comic/%2:%3:%4\r\n").arg(library).arg(currentComic->id).arg(currentComic->getFileName()).arg(currentComic->getFileSize()));
delete currentComic;
}
Folder * currentFolder;
for(QList<LibraryItem *>::const_iterator itr = folderContent.constBegin();itr!=folderContent.constEnd();itr++)
{
currentFolder = (Folder *)(*itr);
serviceComics(library, currentFolder->id, response);
delete currentFolder;
}
}

View File

@ -15,6 +15,9 @@ public:
/** Generates the response */
void service(HttpRequest& request, HttpResponse& response);
private:
void serviceComics(const int &library, const qulonglong & folderId, HttpResponse& response);
};
#endif // FOLDERINFOCONTROLLER_H