modified comics and folders information served to remote devices (YACReader for iOS 2.0)

This commit is contained in:
Luis Ángel San Martín 2014-09-03 12:42:52 +02:00
parent 26c94ccccd
commit df36159956
13 changed files with 133 additions and 66 deletions

View File

@ -31,9 +31,9 @@ YACReaderLibraries DBHelper::getLibraries()
libraries.load();
return libraries;
}
QList<LibraryItem *> DBHelper::getFolderContentFromLibrary(const QString & libraryName, qulonglong folderId)
QList<LibraryItem *> DBHelper::getFolderSubfoldersFromLibrary(qulonglong libraryId, qulonglong folderId)
{
QString libraryPath = DBHelper::getLibraries().getPath(libraryName);
QString libraryPath = DBHelper::getLibraries().getPath(libraryId);
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
QList<LibraryItem *> list = DBHelper::getFoldersFromParent(folderId,db,false);
@ -42,9 +42,9 @@ QList<LibraryItem *> DBHelper::getFolderContentFromLibrary(const QString & libra
QSqlDatabase::removeDatabase(libraryPath);
return list;
}
QList<LibraryItem *> DBHelper::getFolderComicsFromLibrary(const QString & libraryName, qulonglong folderId)
QList<LibraryItem *> DBHelper::getFolderComicsFromLibrary(qulonglong libraryId, qulonglong folderId)
{
QString libraryPath = DBHelper::getLibraries().getPath(libraryName);
QString libraryPath = DBHelper::getLibraries().getPath(libraryId);
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
QList<LibraryItem *> list = DBHelper::getComicsFromParent(folderId,db,false);
@ -53,9 +53,9 @@ QList<LibraryItem *> DBHelper::getFolderComicsFromLibrary(const QString & librar
QSqlDatabase::removeDatabase(libraryPath);
return list;
}
qulonglong DBHelper::getParentFromComicFolderId(const QString & libraryName, qulonglong id)
qulonglong DBHelper::getParentFromComicFolderId(qulonglong libraryId, qulonglong id)
{
QString libraryPath = DBHelper::getLibraries().getPath(libraryName);
QString libraryPath = DBHelper::getLibraries().getPath(libraryId);
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
Folder f = DBHelper::loadFolder(id,db);
@ -64,9 +64,9 @@ qulonglong DBHelper::getParentFromComicFolderId(const QString & libraryName, qul
QSqlDatabase::removeDatabase(libraryPath);
return f.parentId;
}
ComicDB DBHelper::getComicInfo(const QString & libraryName, qulonglong id)
ComicDB DBHelper::getComicInfo(qulonglong libraryId, qulonglong id)
{
QString libraryPath = DBHelper::getLibraries().getPath(libraryName);
QString libraryPath = DBHelper::getLibraries().getPath(libraryId);
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
ComicDB comic = DBHelper::loadComic(id,db);
@ -76,9 +76,9 @@ ComicDB DBHelper::getComicInfo(const QString & libraryName, qulonglong id)
return comic;
}
QList<ComicDB> DBHelper::getSiblings(const QString & libraryName, qulonglong parentId)
QList<ComicDB> DBHelper::getSiblings(qulonglong libraryId, qulonglong parentId)
{
QString libraryPath = DBHelper::getLibraries().getPath(libraryName);
QString libraryPath = DBHelper::getLibraries().getPath(libraryId);
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
QList<ComicDB> comics = DBHelper::getSortedComicsFromParent(parentId,db);
@ -87,9 +87,9 @@ QList<ComicDB> DBHelper::getSiblings(const QString & libraryName, qulonglong par
return comics;
}
QString DBHelper::getFolderName(const QString & libraryName, qulonglong id)
QString DBHelper::getFolderName(qulonglong libraryId, qulonglong id)
{
QString libraryPath = DBHelper::getLibraries().getPath(libraryName);
QString libraryPath = DBHelper::getLibraries().getPath(libraryId);
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
QString name="";
@ -153,9 +153,9 @@ void DBHelper::update(ComicDB * comic, QSqlDatabase & db)
//do nothing
}
void DBHelper::update(const QString & libraryName, ComicInfo & comicInfo)
void DBHelper::update(qulonglong libraryId, ComicInfo & comicInfo)
{
QString libraryPath = DBHelper::getLibraries().getPath(libraryName);
QString libraryPath = DBHelper::getLibraries().getPath(libraryId);
QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath+"/.yacreaderlibrary");
DBHelper::update(&comicInfo,db);

View File

@ -19,12 +19,12 @@ class DBHelper
public:
//server
static YACReaderLibraries getLibraries();
static QList<LibraryItem *> getFolderContentFromLibrary(const QString & libraryName, qulonglong folderId);
static QList<LibraryItem *> getFolderComicsFromLibrary(const QString & libraryName, qulonglong folderId);
static qulonglong getParentFromComicFolderId(const QString & libraryName, qulonglong id);
static ComicDB getComicInfo(const QString & libraryName, qulonglong id);
static QList<ComicDB> getSiblings(const QString & libraryName, qulonglong parentId);
static QString getFolderName(const QString & libraryName, qulonglong id);
static QList<LibraryItem *> getFolderSubfoldersFromLibrary(qulonglong libraryId, qulonglong folderId);
static QList<LibraryItem *> getFolderComicsFromLibrary(qulonglong libraryId, qulonglong folderId);
static qulonglong getParentFromComicFolderId(qulonglong libraryId, qulonglong id);
static ComicDB getComicInfo(qulonglong libraryId, qulonglong id);
static QList<ComicDB> getSiblings(qulonglong libraryId, qulonglong parentId);
static QString getFolderName(qulonglong libraryId, qulonglong id);
static QList<QString> getLibrariesNames();
static QString getLibraryName(int id);
@ -37,13 +37,13 @@ public:
static qulonglong insert(Folder * folder, QSqlDatabase & db);
static qulonglong insert(ComicDB * comic, QSqlDatabase & db);
//updates
static void update(const QString & libraryName, ComicInfo & comicInfo);
static void update(qulonglong libraryId, ComicInfo & comicInfo);
static void update(ComicDB * comics, QSqlDatabase & db);
static void update(ComicInfo * comicInfo, QSqlDatabase & db);
static void updateRead(ComicInfo * comicInfo, QSqlDatabase & db);
static void update(const Folder & folder, QSqlDatabase & db);
static void updateProgress(qulonglong libraryId,const ComicInfo & comicInfo); //TODO change libraryName by libraryId in all methods.
//queries
static void updateProgress(qulonglong libraryId,const ComicInfo & comicInfo);
static QList<LibraryItem *> getFoldersFromParent(qulonglong parentId, QSqlDatabase & db, bool sort = true);
static QList<ComicDB> getSortedComicsFromParent(qulonglong parentId, QSqlDatabase & db);
static QList<LibraryItem *> getComicsFromParent(qulonglong parentId, QSqlDatabase & db, bool sort = true);

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ón de las bases de datos está mal, hay
//que crear una clase que se encargue de estas cosas
//¿Se está 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));
}
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));
}
serviceComics(libraryId, parentId, response);
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

View File

@ -20,6 +20,7 @@
#include "controllers/pagecontroller.h"
#include "controllers/updatecomiccontroller.h"
#include "controllers/errorcontroller.h"
#include "controllers/comicdownloadinfocontroller.h"
#include "db_helper.h"
#include "yacreader_libraries.h"
@ -95,7 +96,8 @@ void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
QRegExp folder("/library/.+/folder/[0-9]+/?");//get comic content
QRegExp folderInfo("/library/.+/folder/[0-9]+/info/?"); //get folder info
QRegExp comic("/library/.+/comic/[0-9]+/?"); //get comic info
QRegExp comicDownloadInfo("/library/.+/comic/[0-9]+/?"); //get comic info (basic/download info)
QRegExp comicFullInfo("/library/.+/comic/[0-9]+/info/?"); //get comic info (full info)
QRegExp comicOpen("/library/.+/comic/[0-9]+/remote/?"); //the server will open for reading the comic
QRegExp comicUpdate("/library/.+/comic/[0-9]+/update/?"); //get comic info
QRegExp comicClose("/library/.+/comic/[0-9]+/close/?"); //the server will close the comic and free memory
@ -138,8 +140,12 @@ void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
else if(cover.exactMatch(path))
{
CoverController().service(request, response);
}
else if(comic.exactMatch(path) || comicOpen.exactMatch(path))
}
else if(comicDownloadInfo.exactMatch(path))
{
ComicDownloadInfoController().service(request, response);
}
else if(comicFullInfo.exactMatch(path) || comicOpen.exactMatch(path))//start download or start remote reading
{
ComicController().service(request, response);
}

View File

@ -13,7 +13,8 @@ HEADERS += \
$$PWD/controllers/pagecontroller.h \
$$PWD/controllers/sessionmanager.h \
$$PWD/controllers/covercontroller.h \
server/controllers/updatecomiccontroller.h
server/controllers/updatecomiccontroller.h \
server/controllers/comicdownloadinfocontroller.h
SOURCES += \
$$PWD/static.cpp \
@ -27,7 +28,8 @@ SOURCES += \
$$PWD/controllers/pagecontroller.cpp \
$$PWD/controllers/sessionmanager.cpp \
$$PWD/controllers/covercontroller.cpp \
server/controllers/updatecomiccontroller.cpp
server/controllers/updatecomiccontroller.cpp \
server/controllers/comicdownloadinfocontroller.cpp
include(lib/bfLogging/bfLogging.pri)
include(lib/bfHttpServer/bfHttpServer.pri)

View File

@ -206,13 +206,13 @@ void YACReaderClientConnectionWorker::run()
void YACReaderClientConnectionWorker::getComicInfo(quint64 libraryId, ComicDB & comic, QList<ComicDB> & siblings)
{
QMutexLocker locker(&dbMutex);
comic = DBHelper::getComicInfo(DBHelper::getLibrariesNames().at(libraryId), comic.id);
siblings = DBHelper::getSiblings(DBHelper::getLibrariesNames().at(libraryId), comic.parentId);
comic = DBHelper::getComicInfo(libraryId, comic.id);
siblings = DBHelper::getSiblings(libraryId, comic.parentId);
}
void YACReaderClientConnectionWorker::updateComic(quint64 libraryId, ComicDB & comic)
{
QMutexLocker locker(&dbMutex);
DBHelper::update(DBHelper::getLibrariesNames().at(libraryId), comic.info);
DBHelper::update(libraryId, comic.info);
emit comicUpdated(libraryId, comic);
}

View File

@ -31,7 +31,7 @@ QString ComicDB::toTXT()
txt.append(QString("currentPage:%1\r\n").arg(info.currentPage));
txt.append(QString("contrast:%1\r\n").arg(info.contrast));
//Información general
//Informaci<EFBFBD>n general
if(!info.coverPage.isNull())
txt.append(QString("coverPage:%1\r\n").arg(info.coverPage.toString()));
@ -80,7 +80,7 @@ QString ComicDB::toTXT()
if(!info.coverArtist.isNull())
txt.append(QString("coverArtist:%1\r\n").arg(info.coverArtist.toString()));
//Publicación
//Publicaci<EFBFBD>n
if(!info.date.isNull())
txt.append(QString("date:%1\r\n").arg(info.date.toString()));
@ -127,7 +127,13 @@ QString ComicDB::getParentFolderName() const
if(paths.length()<2)
return "";
else
return paths[paths.length()-2];
return paths[paths.length()-2];
}
qulonglong ComicDB::getFileSize() const
{
//the size is encoded in the hash after the SHA-1
return info.hash.right(info.hash.length()-40).toLongLong();
}
//-----------------------------------------------------------------------------

View File

@ -139,6 +139,9 @@ public:
//returns parent folder name
QString getParentFolderName() const;
//return the size of the file in bytes
qulonglong getFileSize() const;
QString toTXT();
ComicInfo info;