From 3eecf65a8a3f2537a01d2ca21be677611ce8b59f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Tue, 29 Jul 2014 20:11:50 +0200 Subject: [PATCH] added support for opening next/previous comics from iOS remote viewer --- .../server/controllers/comiccontroller.cpp | 34 +++++++++++++++++-- .../controllers/librariescontroller.cpp | 5 +-- YACReaderLibrary/server/requestmapper.cpp | 4 +-- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/YACReaderLibrary/server/controllers/comiccontroller.cpp b/YACReaderLibrary/server/controllers/comiccontroller.cpp index 188e5d52..26bfaed7 100644 --- a/YACReaderLibrary/server/controllers/comiccontroller.cpp +++ b/YACReaderLibrary/server/controllers/comiccontroller.cpp @@ -22,6 +22,8 @@ void ComicController::service(HttpRequest& request, HttpResponse& response) QString libraryName = DBHelper::getLibraryName(pathElements.at(2).toInt()); qulonglong comicId = pathElements.at(4).toULongLong(); + bool remoteComic = path.contains("remote"); + //TODO //if(pathElements.size() == 6) //{ @@ -44,7 +46,8 @@ void ComicController::service(HttpRequest& request, HttpResponse& response) ComicDB comic = DBHelper::getComicInfo(libraryName, comicId); - session.setDownloadedComic(comic.info.hash); + if(!remoteComic) + session.setDownloadedComic(comic.info.hash); 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"); //TODO this field is not used by the client! response.writeText(QString("library:%1\r\n").arg(libraryName)); - response.writeText(comic.toTXT(),true); + response.writeText(QString("libraryId:%1\r\n").arg(pathElements.at(2))); + if(remoteComic) //send previous and next comics id + { + QList 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(iid)); + } + else + { + //ERROR + } + response.writeText(comic.toTXT(),true); + qDeleteAll(siblings); + } } else { diff --git a/YACReaderLibrary/server/controllers/librariescontroller.cpp b/YACReaderLibrary/server/controllers/librariescontroller.cpp index a154b7f8..658674cc 100644 --- a/YACReaderLibrary/server/controllers/librariescontroller.cpp +++ b/YACReaderLibrary/server/controllers/librariescontroller.cpp @@ -17,7 +17,8 @@ void LibrariesController::service(HttpRequest& request, HttpResponse& response) if(postData.length()>0) { QList data = postData.split("\n"); 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 comics = data.at(2).split(":").at(1).split("\t"); foreach(QString hash,comics) { session.setComicOnDevice(hash); @@ -52,7 +53,7 @@ void LibrariesController::service(HttpRequest& request, HttpResponse& response) } else //values by default, only for debug purposes. { - session.setDeviceType("iphone"); + session.setDeviceType("ipad"); session.setDisplayType("@2x"); } diff --git a/YACReaderLibrary/server/requestmapper.cpp b/YACReaderLibrary/server/requestmapper.cpp index 5bbd9199..d010a4c1 100644 --- a/YACReaderLibrary/server/requestmapper.cpp +++ b/YACReaderLibrary/server/requestmapper.cpp @@ -33,7 +33,7 @@ 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 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 cover("/library/.+/cover/[0-9a-f]+.jpg"); //get comic cover (navigation) 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); } - else if(comic.exactMatch(path)) + else if(comic.exactMatch(path) || comicOpen.exactMatch(path)) { ComicController().service(request, response); }