added support for opening next/previous comics from iOS remote viewer

This commit is contained in:
Luis Ángel San Martín
2014-07-29 20:11:50 +02:00
parent f916498510
commit 093b2b0cb1
3 changed files with 37 additions and 6 deletions

View File

@ -22,6 +22,8 @@ void ComicController::service(HttpRequest& request, HttpResponse& response)
QString libraryName = DBHelper::getLibraryName(pathElements.at(2).toInt()); QString libraryName = DBHelper::getLibraryName(pathElements.at(2).toInt());
qulonglong comicId = pathElements.at(4).toULongLong(); qulonglong comicId = pathElements.at(4).toULongLong();
bool remoteComic = path.contains("remote");
//TODO //TODO
//if(pathElements.size() == 6) //if(pathElements.size() == 6)
//{ //{
@ -44,6 +46,7 @@ void ComicController::service(HttpRequest& request, HttpResponse& response)
ComicDB comic = DBHelper::getComicInfo(libraryName, comicId); ComicDB comic = DBHelper::getComicInfo(libraryName, comicId);
if(!remoteComic)
session.setDownloadedComic(comic.info.hash); session.setDownloadedComic(comic.info.hash);
Comic * comicFile = FactoryComic::newComic(libraries.getPath(libraryName)+comic.path); Comic * comicFile = FactoryComic::newComic(libraries.getPath(libraryName)+comic.path);
@ -69,7 +72,34 @@ void ComicController::service(HttpRequest& request, HttpResponse& response)
response.setHeader("Content-Type", "plain/text; charset=ISO-8859-1"); response.setHeader("Content-Type", "plain/text; charset=ISO-8859-1");
//TODO this field is not used by the client! //TODO this field is not used by the client!
response.writeText(QString("library:%1\r\n").arg(libraryName)); response.writeText(QString("library:%1\r\n").arg(libraryName));
response.writeText(QString("libraryId:%1\r\n").arg(pathElements.at(2)));
if(remoteComic) //send previous and next comics id
{
QList<LibraryItem *> siblings = DBHelper::getFolderComicsFromLibrary(libraryName, comic.parentId);
bool found = false;
int i;
for(i = 0; i < siblings.length(); i++)
{
if (siblings.at(i)->id == comic.id)
{
found = true;
break;
}
}
if(found)
{
if(i>0)
response.writeText(QString("previousComic:%1\r\n").arg(siblings.at(i-1)->id));
if(i<siblings.length()-1)
response.writeText(QString("nextComic:%1\r\n").arg(siblings.at(i+1)->id));
}
else
{
//ERROR
}
response.writeText(comic.toTXT(),true); response.writeText(comic.toTXT(),true);
qDeleteAll(siblings);
}
} }
else else
{ {

View File

@ -17,7 +17,8 @@ void LibrariesController::service(HttpRequest& request, HttpResponse& response)
if(postData.length()>0) { if(postData.length()>0) {
QList<QString> data = postData.split("\n"); QList<QString> data = postData.split("\n");
if(data.length() > 2) { if(data.length() > 2) {
//ONLY COMICS ARE UPDATED, DEVICE CHARACTERISTICS ARE INMUTABLE session.setDeviceType(data.at(0).split(":").at(1));
session.setDisplayType(data.at(1).split(":").at(1));
QList<QString> comics = data.at(2).split(":").at(1).split("\t"); QList<QString> comics = data.at(2).split(":").at(1).split("\t");
foreach(QString hash,comics) { foreach(QString hash,comics) {
session.setComicOnDevice(hash); session.setComicOnDevice(hash);
@ -52,7 +53,7 @@ void LibrariesController::service(HttpRequest& request, HttpResponse& response)
} }
else //values by default, only for debug purposes. else //values by default, only for debug purposes.
{ {
session.setDeviceType("iphone"); session.setDeviceType("ipad");
session.setDisplayType("@2x"); session.setDisplayType("@2x");
} }

View File

@ -33,7 +33,7 @@ void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
QRegExp folder("/library/.+/folder/[0-9]+/?");//get comic content QRegExp folder("/library/.+/folder/[0-9]+/?");//get comic content
QRegExp folderInfo("/library/.+/folder/[0-9]+/info/?"); //get folder info QRegExp folderInfo("/library/.+/folder/[0-9]+/info/?"); //get folder info
QRegExp comic("/library/.+/comic/[0-9]+/?"); //get comic info QRegExp comic("/library/.+/comic/[0-9]+/?"); //get comic info
QRegExp comicOpen("/library/.+/comic/[0-9]+/open/?"); //the server will open for reading the comic QRegExp comicOpen("/library/.+/comic/[0-9]+/remote/?"); //the server will open for reading the comic
QRegExp comicClose("/library/.+/comic/[0-9]+/close/?"); //the server will close the comic and free memory QRegExp comicClose("/library/.+/comic/[0-9]+/close/?"); //the server will close the comic and free memory
QRegExp cover("/library/.+/cover/[0-9a-f]+.jpg"); //get comic cover (navigation) QRegExp cover("/library/.+/cover/[0-9a-f]+.jpg"); //get comic cover (navigation)
QRegExp comicPage("/library/.+/comic/[0-9]+/page/[0-9]+/?"); //get comic page QRegExp comicPage("/library/.+/comic/[0-9]+/page/[0-9]+/?"); //get comic page
@ -69,7 +69,7 @@ void RequestMapper::service(HttpRequest& request, HttpResponse& response) {
{ {
CoverController().service(request, response); CoverController().service(request, response);
} }
else if(comic.exactMatch(path)) else if(comic.exactMatch(path) || comicOpen.exactMatch(path))
{ {
ComicController().service(request, response); ComicController().service(request, response);
} }