diff --git a/YACReader/main.cpp b/YACReader/main.cpp index 90a79e18..228d1628 100644 --- a/YACReader/main.cpp +++ b/YACReader/main.cpp @@ -118,18 +118,22 @@ int main(int argc, char *argv[]) parser.addPositionalArgument("[File|Directory]", "File or directory to open."); QCommandLineOption comicId("comicId", "", "comicId"); QCommandLineOption libraryId("libraryId", "", "libraryId"); + QCommandLineOption readingListId("readingListId", "", "readingListId"); // hide comicId and libraryId from help #if QT_VERSION >= 0x050800 comicId.setFlags(QCommandLineOption::HiddenFromHelp); libraryId.setFlags(QCommandLineOption::HiddenFromHelp); + readingListId.setFlags(QCommandLineOption::HiddenFromHelp); #else comicId.setHidden(true); libraryId.setHidden(true); + readingListId.setHidden(true); #endif // process parser.addOption(comicId); parser.addOption(libraryId); + parser.addOption(readingListId); parser.process(app); QString destLog = YACReader::getSettingsPath() + "/yacreader.log"; @@ -173,7 +177,15 @@ int main(int argc, char *argv[]) // some arguments need to be parsed after MainWindowViewer creation QStringList arglist = parser.positionalArguments(); if (parser.isSet(comicId) && parser.isSet(libraryId) && arglist.count() >= 1) { - mwv->open(arglist.at(0), parser.value(comicId).toULongLong(), parser.value(libraryId).toULongLong()); + OpenComicSource source; + + if (parser.isSet(readingListId)) { + source = OpenComicSource { OpenComicSource::ReadingList, parser.value(readingListId).toULongLong() }; + } else { + source = OpenComicSource { OpenComicSource::Folder, 33 }; //Folder is not needed to get the comic information, the comid id points to a unique comic + } + + mwv->open(arglist.at(0), parser.value(comicId).toULongLong(), parser.value(libraryId).toULongLong(), source); } else if (arglist.count() >= 1) { mwv->openComicFromPath(arglist.at(0)); } diff --git a/YACReader/main_window_viewer.cpp b/YACReader/main_window_viewer.cpp index 4c893ef0..543b9b1d 100644 --- a/YACReader/main_window_viewer.cpp +++ b/YACReader/main_window_viewer.cpp @@ -851,11 +851,12 @@ void MainWindowViewer::open(QString path, ComicDB &comic, QList &siblin optionsDialog->setFilters(currentComicDB.info.brightness, currentComicDB.info.contrast, currentComicDB.info.gamma); } -void MainWindowViewer::open(QString path, qint64 comicId, qint64 libraryId) +void MainWindowViewer::open(QString path, qint64 comicId, qint64 libraryId, OpenComicSource source) { currentDirectory = path; this->libraryId = libraryId; + this->source = source; enableActions(); @@ -863,7 +864,7 @@ void MainWindowViewer::open(QString path, qint64 comicId, qint64 libraryId) YACReaderLocalClient client; int tries = 1; bool success = false; - while (!(success = client.requestComicInfo(libraryId, currentComicDB, siblingComics)) && tries != 0) + while (!(success = client.requestComicInfo(libraryId, currentComicDB, siblingComics, source)) && tries != 0) tries--; if (success) { @@ -1507,6 +1508,9 @@ void MainWindowViewer::openNextComic() if (currentIndex + 1 > 0 && currentIndex + 1 < siblingComics.count()) { siblingComics[currentIndex] = currentComicDB; //updated currentComicDB = siblingComics.at(currentIndex + 1); + + QMessageBox::warning(nullptr, "", QString(" current dir %1 - path %2").arg(currentDirectory).arg(currentComicDB.path)); + open(currentDirectory + currentComicDB.path, currentComicDB, siblingComics); } diff --git a/YACReader/main_window_viewer.h b/YACReader/main_window_viewer.h index e526a936..2113cd50 100644 --- a/YACReader/main_window_viewer.h +++ b/YACReader/main_window_viewer.h @@ -14,6 +14,7 @@ #endif #include "comic_db.h" +#include "yacreader_global.h" class Comic; class Viewer; @@ -25,6 +26,8 @@ class YACReaderSliderAction; class YACReaderSlider; class EditShortcutsDialog; +namespace YACReader { + class MainWindowViewer : public QMainWindow { Q_OBJECT @@ -32,7 +35,7 @@ class MainWindowViewer : public QMainWindow public slots: void open(); void open(QString path, ComicDB &comic, QList &siblings); - void open(QString path, qint64 comicId, qint64 libraryId); + void open(QString path, qint64 comicId, qint64 libraryId, OpenComicSource source); void openFolder(); void openRecent(); void openLatestComic(); @@ -175,6 +178,7 @@ private: bool isClient; QString startComicPath; quint64 libraryId; + OpenComicSource source; //fullscreen mode in Windows for preventing this bug: QTBUG-41309 https://bugreports.qt.io/browse/QTBUG-41309 Qt::WindowFlags previousWindowFlags; @@ -191,4 +195,7 @@ public: MainWindowViewer(); ~MainWindowViewer() override; }; + +} + #endif diff --git a/YACReader/yacreader_local_client.cpp b/YACReader/yacreader_local_client.cpp index 6556d31b..e3effc32 100644 --- a/YACReader/yacreader_local_client.cpp +++ b/YACReader/yacreader_local_client.cpp @@ -28,7 +28,7 @@ void YACReaderLocalClient::readMessage() } #include -bool YACReaderLocalClient::requestComicInfo(quint64 libraryId, ComicDB &comic, QList &siblings) +bool YACReaderLocalClient::requestComicInfo(quint64 libraryId, ComicDB &comic, QList &siblings, OpenComicSource source) { localSocket->connectToServer(YACREADERLIBRARY_GUID); if (localSocket->isOpen()) { @@ -38,6 +38,7 @@ bool YACReaderLocalClient::requestComicInfo(quint64 libraryId, ComicDB &comic, Q out << (quint32)0; out << (quint8)YACReader::RequestComicInfo; out << libraryId; + out << source; out << comic; out.device()->seek(0); out << (quint32)(block.size() - sizeof(quint32)); diff --git a/YACReader/yacreader_local_client.h b/YACReader/yacreader_local_client.h index f3509e66..1f4f08e7 100644 --- a/YACReader/yacreader_local_client.h +++ b/YACReader/yacreader_local_client.h @@ -1,6 +1,8 @@ #ifndef YACREADER_LOCAL_CLIENT_H #define YACREADER_LOCAL_CLIENT_H +#include "yacreader_global.h" + #include class QLocalSocket; @@ -16,7 +18,7 @@ signals: void finished(); public slots: void readMessage(); - bool requestComicInfo(quint64 libraryId, ComicDB &comic, QList &siblings); + bool requestComicInfo(quint64 libraryId, ComicDB &comic, QList &siblings, YACReader::OpenComicSource source); bool sendComicInfo(quint64 libraryId, ComicDB &comic); bool sendComicInfo(quint64 libraryId, ComicDB &comic, qulonglong nextComicId); diff --git a/YACReaderLibrary/YACReaderLibrary.pro b/YACReaderLibrary/YACReaderLibrary.pro index 9a0e4bf2..ee810eca 100644 --- a/YACReaderLibrary/YACReaderLibrary.pro +++ b/YACReaderLibrary/YACReaderLibrary.pro @@ -78,6 +78,7 @@ HEADERS += comic_flow.h \ db/comic_query_result_processor.h \ db/folder_query_result_processor.h \ db/query_lexer.h \ + library_comic_opener.h \ library_creator.h \ library_window.h \ add_library_dialog.h \ @@ -156,6 +157,7 @@ SOURCES += comic_flow.cpp \ db/comic_query_result_processor.cpp \ db/folder_query_result_processor.cpp \ db/query_lexer.cpp \ + library_comic_opener.cpp \ library_creator.cpp \ library_window.cpp \ main.cpp \ diff --git a/YACReaderLibrary/db/comic_model.cpp b/YACReaderLibrary/db/comic_model.cpp index 842922be..0a925ff6 100644 --- a/YACReaderLibrary/db/comic_model.cpp +++ b/YACReaderLibrary/db/comic_model.cpp @@ -546,6 +546,7 @@ void ComicModel::setupFavoritesModelData(const QString &databasePath) { enableResorting = true; mode = Favorites; + sourceId = -1; beginResetModel(); qDeleteAll(_data); @@ -574,6 +575,7 @@ void ComicModel::setupReadingModelData(const QString &databasePath) { enableResorting = false; mode = Reading; + sourceId = -1; beginResetModel(); qDeleteAll(_data); diff --git a/YACReaderLibrary/db/comic_model.h b/YACReaderLibrary/db/comic_model.h index cbe49d45..55063f3e 100644 --- a/YACReaderLibrary/db/comic_model.h +++ b/YACReaderLibrary/db/comic_model.h @@ -129,6 +129,7 @@ public: bool isFavorite(const QModelIndex &index); ComicModel::Mode getMode() { return mode; } + unsigned long long int getSourceId() { return sourceId; } QHash roleNames() const override; diff --git a/YACReaderLibrary/db_helper.cpp b/YACReaderLibrary/db_helper.cpp index de3a4d56..6fa4edf9 100644 --- a/YACReaderLibrary/db_helper.cpp +++ b/YACReaderLibrary/db_helper.cpp @@ -359,7 +359,7 @@ QList DBHelper::getReadingLists(qulonglong libraryId) return list; } -QList DBHelper::getReadingListFullContent(qulonglong libraryId, qulonglong readingListId) +QList DBHelper::getReadingListFullContent(qulonglong libraryId, qulonglong readingListId, bool getFullComicInfoFields) { QString libraryPath = DBHelper::getLibraries().getPath(libraryId); QList list; @@ -382,26 +382,52 @@ QList DBHelper::getReadingListFullContent(qulonglong libraryId, qulongl foreach (qulonglong id, ids) { QSqlQuery selectQuery(db); - selectQuery.prepare("SELECT c.id,c.parentId,c.fileName,ci.title,ci.currentPage,ci.numPages,ci.hash,ci.read,ci.coverSizeRatio " - "FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) " - "INNER JOIN comic_reading_list crl ON (c.id == crl.comic_id) " - "WHERE crl.reading_list_id = :parentReadingList " - "ORDER BY crl.ordering"); + + QString params; + if (getFullComicInfoFields) { + params = "*"; + } else { + params = "c.id,c.parentId,c.fileName,c.path,ci.title,ci.currentPage,ci.numPages,ci.hash,ci.read,ci.coverSizeRatio"; + } + + selectQuery.prepare("SELECT " + params + " " + "FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) " + "INNER JOIN comic_reading_list crl ON (c.id == crl.comic_id) " + "WHERE crl.reading_list_id = :parentReadingList " + "ORDER BY crl.ordering"); selectQuery.bindValue(":parentReadingList", id); selectQuery.exec(); + auto record = selectQuery.record(); + + int idComicIndex = record.indexOf("id"); + int parentIdIndex = record.indexOf("parentId"); + int fileName = record.indexOf("fileName"); + int path = record.indexOf("path"); + while (selectQuery.next()) { ComicDB comic; - comic.id = selectQuery.value(0).toULongLong(); - comic.parentId = selectQuery.value(1).toULongLong(); - comic.name = selectQuery.value(2).toString(); - comic.info.title = selectQuery.value(3).toString(); - comic.info.currentPage = selectQuery.value(4).toInt(); - comic.info.numPages = selectQuery.value(5).toInt(); - comic.info.hash = selectQuery.value(6).toString(); - comic.info.read = selectQuery.value(7).toBool(); - comic.info.coverSizeRatio = selectQuery.value(8).toFloat(); + if (getFullComicInfoFields) { + comic.id = selectQuery.value(idComicIndex).toULongLong(); + comic.parentId = selectQuery.value(parentIdIndex).toULongLong(); + comic.name = selectQuery.value(fileName).toString(); + comic.path = selectQuery.value(path).toString(); + + comic.info = getComicInfoFromQuery(selectQuery, "comicInfoId"); + } else { + comic.id = selectQuery.value(0).toULongLong(); + comic.parentId = selectQuery.value(1).toULongLong(); + comic.name = selectQuery.value(2).toString(); + comic.path = selectQuery.value(3).toString(); + + comic.info.title = selectQuery.value(4).toString(); + comic.info.currentPage = selectQuery.value(5).toInt(); + comic.info.numPages = selectQuery.value(6).toInt(); + comic.info.hash = selectQuery.value(7).toString(); + comic.info.read = selectQuery.value(8).toBool(); + comic.info.coverSizeRatio = selectQuery.value(9).toFloat(); + } list.append(comic); } @@ -1333,64 +1359,6 @@ QList DBHelper::getSortedComicsFromParent(qulonglong parentId, QSqlData int fileName = record.indexOf("fileName"); int path = record.indexOf("path"); - int hash = record.indexOf("hash"); - int comicInfoId = record.indexOf("comicInfoId"); - int read = record.indexOf("read"); - int edited = record.indexOf("edited"); - - //new 7.0 fields - int hasBeenOpened = record.indexOf("hasBeenOpened"); - int currentPage = record.indexOf("currentPage"); - int bookmark1 = record.indexOf("bookmark1"); - int bookmark2 = record.indexOf("bookmark2"); - int bookmark3 = record.indexOf("bookmark3"); - int brightness = record.indexOf("brightness"); - int contrast = record.indexOf("contrast"); - int gamma = record.indexOf("gamma"); - int rating = record.indexOf("rating"); - //-- - - int title = record.indexOf("title"); - int numPages = record.indexOf("numPages"); - - int coverPage = record.indexOf("coverPage"); - - int number = record.indexOf("number"); - int isBis = record.indexOf("isBis"); - int count = record.indexOf("count"); - - int volume = record.indexOf("volume"); - int storyArc = record.indexOf("storyArc"); - int arcNumber = record.indexOf("arcNumber"); - int arcCount = record.indexOf("arcCount"); - - int genere = record.indexOf("genere"); - - int writer = record.indexOf("writer"); - int penciller = record.indexOf("penciller"); - int inker = record.indexOf("inker"); - int colorist = record.indexOf("colorist"); - int letterer = record.indexOf("letterer"); - int coverArtist = record.indexOf("coverArtist"); - - int date = record.indexOf("date"); - int publisher = record.indexOf("publisher"); - int format = record.indexOf("format"); - int color = record.indexOf("color"); - int ageRating = record.indexOf("ageRating"); - int manga = record.indexOf("manga"); - - int synopsis = record.indexOf("synopsis"); - int characters = record.indexOf("characters"); - int notes = record.indexOf("notes"); - - int comicVineID = record.indexOf("comicVineID"); - - int lastTimeOpened = record.indexOf("lastTimeOpened"); - - int coverSizeRatio = record.indexOf("coverSizeRatio"); - int originalCoverSize = record.indexOf("originalCoverSize"); - ComicDB currentItem; while (selectQuery.next()) { currentItem.id = selectQuery.value(id).toULongLong(); @@ -1398,65 +1366,7 @@ QList DBHelper::getSortedComicsFromParent(qulonglong parentId, QSqlData currentItem.name = selectQuery.value(fileName).toString(); currentItem.path = selectQuery.value(path).toString(); - currentItem.info.hash = selectQuery.value(hash).toString(); - currentItem.info.id = selectQuery.value(comicInfoId).toULongLong(); - currentItem.info.read = selectQuery.value(read).toBool(); - currentItem.info.edited = selectQuery.value(edited).toBool(); - - //new 7.0 fields - currentItem.info.hasBeenOpened = selectQuery.value(hasBeenOpened).toBool(); - currentItem.info.currentPage = selectQuery.value(currentPage).toInt(); - currentItem.info.bookmark1 = selectQuery.value(bookmark1).toInt(); - currentItem.info.bookmark2 = selectQuery.value(bookmark2).toInt(); - currentItem.info.bookmark3 = selectQuery.value(bookmark3).toInt(); - currentItem.info.brightness = selectQuery.value(brightness).toInt(); - currentItem.info.contrast = selectQuery.value(contrast).toInt(); - currentItem.info.gamma = selectQuery.value(gamma).toInt(); - currentItem.info.rating = selectQuery.value(rating).toInt(); - //-- - - currentItem.info.title = selectQuery.value(title); - currentItem.info.numPages = selectQuery.value(numPages); - - currentItem.info.coverPage = selectQuery.value(coverPage); - - currentItem.info.number = selectQuery.value(number); - currentItem.info.isBis = selectQuery.value(isBis); - currentItem.info.count = selectQuery.value(count); - - currentItem.info.volume = selectQuery.value(volume); - currentItem.info.storyArc = selectQuery.value(storyArc); - currentItem.info.arcNumber = selectQuery.value(arcNumber); - currentItem.info.arcCount = selectQuery.value(arcCount); - - currentItem.info.genere = selectQuery.value(genere); - - currentItem.info.writer = selectQuery.value(writer); - currentItem.info.penciller = selectQuery.value(penciller); - currentItem.info.inker = selectQuery.value(inker); - currentItem.info.colorist = selectQuery.value(colorist); - currentItem.info.letterer = selectQuery.value(letterer); - currentItem.info.coverArtist = selectQuery.value(coverArtist); - - currentItem.info.date = selectQuery.value(date); - currentItem.info.publisher = selectQuery.value(publisher); - currentItem.info.format = selectQuery.value(format); - currentItem.info.color = selectQuery.value(color); - currentItem.info.ageRating = selectQuery.value(ageRating); - currentItem.info.manga = selectQuery.value(manga); - - currentItem.info.synopsis = selectQuery.value(synopsis); - currentItem.info.characters = selectQuery.value(characters); - currentItem.info.notes = selectQuery.value(notes); - - currentItem.info.comicVineID = selectQuery.value(comicVineID); - - currentItem.info.lastTimeOpened = selectQuery.value(lastTimeOpened); - - currentItem.info.coverSizeRatio = selectQuery.value(coverSizeRatio); - currentItem.info.originalCoverSize = selectQuery.value(originalCoverSize); - - currentItem.info.existOnDb = true; + currentItem.info = getComicInfoFromQuery(selectQuery, "comicInfoId"); list.append(currentItem); } @@ -1738,9 +1648,20 @@ ComicInfo DBHelper::loadComicInfo(QString hash, QSqlDatabase &db) findComicInfo.bindValue(":hash", hash); findComicInfo.exec(); - QSqlRecord record = findComicInfo.record(); + if (findComicInfo.next()) { + comicInfo = getComicInfoFromQuery(findComicInfo); + } else + comicInfo.existOnDb = false; - int id = record.indexOf("id"); + return comicInfo; +} + +ComicInfo DBHelper::getComicInfoFromQuery(QSqlQuery &query, const QString &idKey) +{ + QSqlRecord record = query.record(); + + int hash = record.indexOf("hash"); + int id = record.indexOf(idKey); int read = record.indexOf("read"); int edited = record.indexOf("edited"); @@ -1797,72 +1718,71 @@ ComicInfo DBHelper::loadComicInfo(QString hash, QSqlDatabase &db) int coverSizeRatio = record.indexOf("coverSizeRatio"); int originalCoverSize = record.indexOf("originalCoverSize"); - if (findComicInfo.next()) { - comicInfo.hash = hash; - comicInfo.id = findComicInfo.value(id).toULongLong(); - comicInfo.read = findComicInfo.value(read).toBool(); - comicInfo.edited = findComicInfo.value(edited).toBool(); + ComicInfo comicInfo; - //new 7.0 fields - comicInfo.hasBeenOpened = findComicInfo.value(hasBeenOpened).toBool(); - comicInfo.currentPage = findComicInfo.value(currentPage).toInt(); - comicInfo.bookmark1 = findComicInfo.value(bookmark1).toInt(); - comicInfo.bookmark2 = findComicInfo.value(bookmark2).toInt(); - comicInfo.bookmark3 = findComicInfo.value(bookmark3).toInt(); - comicInfo.brightness = findComicInfo.value(brightness).toInt(); - comicInfo.contrast = findComicInfo.value(contrast).toInt(); - comicInfo.gamma = findComicInfo.value(gamma).toInt(); - comicInfo.rating = findComicInfo.value(rating).toInt(); - //-- - comicInfo.title = findComicInfo.value(title); - comicInfo.numPages = findComicInfo.value(numPages); + comicInfo.hash = query.value(hash).toString(); + comicInfo.id = query.value(id).toULongLong(); + comicInfo.read = query.value(read).toBool(); + comicInfo.edited = query.value(edited).toBool(); - comicInfo.coverPage = findComicInfo.value(coverPage); + //new 7.0 fields + comicInfo.hasBeenOpened = query.value(hasBeenOpened).toBool(); + comicInfo.currentPage = query.value(currentPage).toInt(); + comicInfo.bookmark1 = query.value(bookmark1).toInt(); + comicInfo.bookmark2 = query.value(bookmark2).toInt(); + comicInfo.bookmark3 = query.value(bookmark3).toInt(); + comicInfo.brightness = query.value(brightness).toInt(); + comicInfo.contrast = query.value(contrast).toInt(); + comicInfo.gamma = query.value(gamma).toInt(); + comicInfo.rating = query.value(rating).toInt(); + //-- + comicInfo.title = query.value(title); + comicInfo.numPages = query.value(numPages); - comicInfo.number = findComicInfo.value(number); - comicInfo.isBis = findComicInfo.value(isBis); - comicInfo.count = findComicInfo.value(count); + comicInfo.coverPage = query.value(coverPage); - comicInfo.volume = findComicInfo.value(volume); - comicInfo.storyArc = findComicInfo.value(storyArc); - comicInfo.arcNumber = findComicInfo.value(arcNumber); - comicInfo.arcCount = findComicInfo.value(arcCount); + comicInfo.number = query.value(number); + comicInfo.isBis = query.value(isBis); + comicInfo.count = query.value(count); - comicInfo.genere = findComicInfo.value(genere); + comicInfo.volume = query.value(volume); + comicInfo.storyArc = query.value(storyArc); + comicInfo.arcNumber = query.value(arcNumber); + comicInfo.arcCount = query.value(arcCount); - comicInfo.writer = findComicInfo.value(writer); - comicInfo.penciller = findComicInfo.value(penciller); - comicInfo.inker = findComicInfo.value(inker); - comicInfo.colorist = findComicInfo.value(colorist); - comicInfo.letterer = findComicInfo.value(letterer); - comicInfo.coverArtist = findComicInfo.value(coverArtist); + comicInfo.genere = query.value(genere); - comicInfo.date = findComicInfo.value(date); - comicInfo.publisher = findComicInfo.value(publisher); - comicInfo.format = findComicInfo.value(format); - comicInfo.color = findComicInfo.value(color); - comicInfo.ageRating = findComicInfo.value(ageRating); + comicInfo.writer = query.value(writer); + comicInfo.penciller = query.value(penciller); + comicInfo.inker = query.value(inker); + comicInfo.colorist = query.value(colorist); + comicInfo.letterer = query.value(letterer); + comicInfo.coverArtist = query.value(coverArtist); - comicInfo.synopsis = findComicInfo.value(synopsis); - comicInfo.characters = findComicInfo.value(characters); - comicInfo.notes = findComicInfo.value(notes); + comicInfo.date = query.value(date); + comicInfo.publisher = query.value(publisher); + comicInfo.format = query.value(format); + comicInfo.color = query.value(color); + comicInfo.ageRating = query.value(ageRating); - comicInfo.comicVineID = findComicInfo.value(comicVineID); + comicInfo.synopsis = query.value(synopsis); + comicInfo.characters = query.value(characters); + comicInfo.notes = query.value(notes); - //new 9.5 fields - comicInfo.lastTimeOpened = findComicInfo.value(lastTimeOpened); + comicInfo.comicVineID = query.value(comicVineID); - comicInfo.coverSizeRatio = findComicInfo.value(coverSizeRatio); - comicInfo.originalCoverSize = findComicInfo.value(originalCoverSize); - //-- + //new 9.5 fields + comicInfo.lastTimeOpened = query.value(lastTimeOpened); - //new 9.8 fields - comicInfo.manga = findComicInfo.value(manga); - //-- + comicInfo.coverSizeRatio = query.value(coverSizeRatio); + comicInfo.originalCoverSize = query.value(originalCoverSize); + //-- - comicInfo.existOnDb = true; - } else - comicInfo.existOnDb = false; + //new 9.8 fields + comicInfo.manga = query.value(manga); + //-- + + comicInfo.existOnDb = true; return comicInfo; } diff --git a/YACReaderLibrary/db_helper.h b/YACReaderLibrary/db_helper.h index 93bedfff..abf69625 100644 --- a/YACReaderLibrary/db_helper.h +++ b/YACReaderLibrary/db_helper.h @@ -37,7 +37,7 @@ public: static QList getFavorites(qulonglong libraryId); static QList getReading(qulonglong libraryId); static QList getReadingLists(qulonglong libraryId); - static QList getReadingListFullContent(qulonglong libraryId, qulonglong readingListId); + static QList getReadingListFullContent(qulonglong libraryId, qulonglong readingListId, bool getFullComicInfoFields = false); //objects management //deletes @@ -96,6 +96,7 @@ public: static ComicDB loadComic(qulonglong id, QSqlDatabase &db); static ComicDB loadComic(QString cname, QString cpath, QString chash, QSqlDatabase &database); static ComicInfo loadComicInfo(QString hash, QSqlDatabase &db); + static ComicInfo getComicInfoFromQuery(QSqlQuery &query, const QString &idKey = "id"); static QList loadSubfoldersNames(qulonglong folderId, QSqlDatabase &db); //queries static bool isFavoriteComic(qulonglong id, QSqlDatabase &db); diff --git a/YACReaderLibrary/library_comic_opener.cpp b/YACReaderLibrary/library_comic_opener.cpp new file mode 100644 index 00000000..36ebf747 --- /dev/null +++ b/YACReaderLibrary/library_comic_opener.cpp @@ -0,0 +1,47 @@ +#include "library_comic_opener.h" + +#include "comic_db.h" + +#include +#include + +bool YACReader::openComic(const ComicDB &comic, + unsigned long long libraryId, + const QString &path, + OpenComicSource source) +{ + bool yacreaderFound = false; + + QString labelParam; + + if (source.source == OpenComicSource::ReadingList) { + labelParam = QString("--readingListId=%1").arg(source.sourceId); + } + +#ifdef Q_OS_MACOS + QStringList possiblePaths { QDir::cleanPath(QCoreApplication::applicationDirPath() + "/../../../") }; + possiblePaths += QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation); + + for (auto &&ypath : possiblePaths) { + QString yacreaderPath = QDir::cleanPath(ypath + "/YACReader.app"); + if (QFileInfo(yacreaderPath).exists()) { + yacreaderFound = true; + QStringList parameters { "-n", yacreaderPath, "--args", path, QString("--comicId=%1").arg(comic.id), QString("--libraryId=%1").arg(libraryId), labelParam }; + QProcess::startDetached("open", parameters); + break; + } + } +#endif + +#ifdef Q_OS_WIN + QStringList parameters { path, QString("--comicId=%1").arg(comic.id), QString("--libraryId=%1").arg(libraryId), labelParam }; + yacreaderFound = QProcess::startDetached(QDir::cleanPath(QCoreApplication::applicationDirPath() + "/YACReader.exe"), parameters); +#endif + +#if defined Q_OS_UNIX && !defined Q_OS_MAC + QStringList parameters { path, QString("--comicId=%1").arg(comic.id), QString("--libraryId=%1").arg(libraryId), labelParam }; + yacreaderFound = QProcess::startDetached(QStringLiteral("YACReader"), parameters); +#endif + + return yacreaderFound; +} diff --git a/YACReaderLibrary/library_comic_opener.h b/YACReaderLibrary/library_comic_opener.h new file mode 100644 index 00000000..b68cb225 --- /dev/null +++ b/YACReaderLibrary/library_comic_opener.h @@ -0,0 +1,18 @@ +#ifndef LIBRARYCOMICOPENER_H +#define LIBRARYCOMICOPENER_H + +#include "yacreader_global.h" + +class ComicDB; +class QString; + +namespace YACReader { + +bool openComic(const ComicDB &comic, + unsigned long long libraryId, + const QString &path, + OpenComicSource source); + +} + +#endif // LIBRARYCOMICOPENER_H diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index 1b7824d1..e2c17ca2 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -86,6 +86,8 @@ #include "whats_new_controller.h" +#include "library_comic_opener.h" + #include "QsLog.h" #ifdef Q_OS_WIN @@ -1825,37 +1827,27 @@ void LibraryWindow::checkEmptyFolder() } } -void LibraryWindow::openComic(const ComicDB &comic) +void LibraryWindow::openComic() { if (!importedCovers) { - //TODO generate IDS for libraries... - quint64 libraryId = libraries.getId(selectedLibrary->currentText()); - bool yacreaderFound = false; + auto libraryId = libraries.getId(selectedLibrary->currentText()); -#ifdef Q_OS_MACOS - QStringList possiblePaths { QDir::cleanPath(QCoreApplication::applicationDirPath() + "/../../../") }; - possiblePaths += QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation); + auto comic = comicsModel->getComic(comicsViewsManager->comicsView->currentIndex()); + auto mode = comicsModel->getMode(); - for (auto &&ypath : possiblePaths) { - QString yacreaderPath = QDir::cleanPath(ypath + "/YACReader.app"); - if (QFileInfo(yacreaderPath).exists()) { - yacreaderFound = true; - QStringList parameters { "-n", yacreaderPath, "--args", currentPath(), QString("--comicId=%1").arg(comic.id), QString("--libraryId=%1").arg(libraryId) }; - QProcess::startDetached("open", parameters); - break; - } + OpenComicSource::Source source; + + if (mode == ComicModel::ReadingList) { + source = OpenComicSource::Source::ReadingList; + } else if (mode == ComicModel::Reading) { + //TODO check where the comic was opened from the last time it was read + source = OpenComicSource::Source::Folder; + } else { + source = OpenComicSource::Source::Folder; } -#endif -#ifdef Q_OS_WIN - QStringList parameters { currentPath(), QString("--comicId=%1").arg(comic.id), QString("--libraryId=%1").arg(libraryId) }; - yacreaderFound = QProcess::startDetached(QDir::cleanPath(QCoreApplication::applicationDirPath() + "/YACReader.exe"), parameters); -#endif + auto yacreaderFound = YACReader::openComic(comic, libraryId, currentPath(), OpenComicSource { source, comicsModel->getSourceId() }); -#if defined Q_OS_UNIX && !defined Q_OS_MAC - QStringList parameters { currentPath(), QString("--comicId=%1").arg(comic.id), QString("--libraryId=%1").arg(libraryId) }; - yacreaderFound = QProcess::startDetached(QStringLiteral("YACReader"), parameters); -#endif if (!yacreaderFound) { #ifdef Q_OS_WIN QMessageBox::critical(this, tr("YACReader not found"), tr("YACReader not found. YACReader should be installed in the same folder as YACReaderLibrary.")); @@ -1866,14 +1858,6 @@ void LibraryWindow::openComic(const ComicDB &comic) } } -void LibraryWindow::openComic() -{ - if (!importedCovers) { - ComicDB comic = comicsModel->getComic(comicsViewsManager->comicsView->currentIndex()); - openComic(comic); - } -} - void LibraryWindow::setCurrentComicsStatusReaded(YACReaderComicReadStatus readStatus) { comicsModel->setComicsRead(getSelectedComics(), readStatus); diff --git a/YACReaderLibrary/library_window.h b/YACReaderLibrary/library_window.h index 8dad315f..969c10a8 100644 --- a/YACReaderLibrary/library_window.h +++ b/YACReaderLibrary/library_window.h @@ -313,7 +313,6 @@ public slots: void selectSubfolder(const QModelIndex &mi, int child); void checkEmptyFolder(); void openComic(); - void openComic(const ComicDB &comic); void createLibrary(); void create(QString source, QString dest, QString name); void showAddLibrary(); diff --git a/YACReaderLibrary/server/controllers/v2/comiccontroller_v2.cpp b/YACReaderLibrary/server/controllers/v2/comiccontroller_v2.cpp index 4a32013f..e962d6b0 100644 --- a/YACReaderLibrary/server/controllers/v2/comiccontroller_v2.cpp +++ b/YACReaderLibrary/server/controllers/v2/comiccontroller_v2.cpp @@ -23,6 +23,7 @@ ComicControllerV2::ComicControllerV2() { } void ComicControllerV2::service(HttpRequest &request, HttpResponse &response) { + QByteArray token = request.getHeader("x-request-id"); YACReaderHttpSession *ySession = Static::yacreaderSessionStore->getYACReaderSessionHttpSession(token); diff --git a/YACReaderLibrary/server/controllers/v2/comiccontroller_v2.h b/YACReaderLibrary/server/controllers/v2/comiccontroller_v2.h index f1a189b9..f22aa631 100644 --- a/YACReaderLibrary/server/controllers/v2/comiccontroller_v2.h +++ b/YACReaderLibrary/server/controllers/v2/comiccontroller_v2.h @@ -5,10 +5,6 @@ #include "httpresponse.h" #include "httprequesthandler.h" -#include -class Comic; -class QString; - class ComicControllerV2 : public stefanfrings::HttpRequestHandler { Q_OBJECT diff --git a/YACReaderLibrary/server/controllers/v2/comiccontrollerinreadinglist_v2.cpp b/YACReaderLibrary/server/controllers/v2/comiccontrollerinreadinglist_v2.cpp new file mode 100644 index 00000000..bbadf8e0 --- /dev/null +++ b/YACReaderLibrary/server/controllers/v2/comiccontrollerinreadinglist_v2.cpp @@ -0,0 +1,101 @@ +#include "comiccontrollerinreadinglist_v2.h" + +#include "db_helper.h" +#include "yacreader_libraries.h" +#include "yacreader_http_session.h" + +#include "template.h" +#include "../static.h" + +#include "comic_db.h" +#include "comic.h" + +#include "qnaturalsorting.h" + +#include "QsLog.h" + +#include + +using stefanfrings::HttpRequest; +using stefanfrings::HttpResponse; + +ComicControllerInReadingListV2::ComicControllerInReadingListV2() { } + +void ComicControllerInReadingListV2::service(HttpRequest &request, HttpResponse &response) +{ + + QByteArray token = request.getHeader("x-request-id"); + YACReaderHttpSession *ySession = Static::yacreaderSessionStore->getYACReaderSessionHttpSession(token); + + if (ySession == nullptr) { + response.setStatus(404, "not found"); + response.write("404 not found", true); + return; + } + + QString path = QUrl::fromPercentEncoding(request.getPath()).toUtf8(); + QStringList pathElements = path.split('/'); + qulonglong libraryId = pathElements.at(3).toLongLong(); + QString libraryName = DBHelper::getLibraryName(libraryId); + qulonglong readingListId = pathElements.at(5).toULongLong(); + qulonglong comicId = pathElements.at(7).toULongLong(); + + YACReaderLibraries libraries = DBHelper::getLibraries(); + + ComicDB comic = DBHelper::getComicInfo(libraryId, comicId); + + Comic *comicFile = FactoryComic::newComic(libraries.getPath(libraryId) + comic.path); + + if (comicFile != nullptr) { + QThread *thread = nullptr; + + thread = new QThread(); + + comicFile->moveToThread(thread); + + connect(comicFile, SIGNAL(errorOpening()), thread, SLOT(quit())); + connect(comicFile, SIGNAL(errorOpening(QString)), thread, SLOT(quit())); + connect(comicFile, SIGNAL(imagesLoaded()), thread, SLOT(quit())); + connect(thread, SIGNAL(started()), comicFile, SLOT(process())); + connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); + + comicFile->load(libraries.getPath(libraryId) + comic.path); + + if (thread != nullptr) + thread->start(); + + QLOG_TRACE() << "remote comic requested"; + ySession->setCurrentRemoteComic(comic.id, comicFile); + + response.setHeader("Content-Type", "text/plain; charset=utf-8"); + //TODO this field is not used by the client! + response.write(QString("library:%1\r\n").arg(libraryName).toUtf8()); + response.write(QString("libraryId:%1\r\n").arg(libraryId).toUtf8()); + + QList siblings = DBHelper::getReadingListFullContent(libraryId, readingListId); + + 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.write(QString("previousComic:%1\r\n").arg(siblings.at(i - 1).id).toUtf8()); + if (i < siblings.length() - 1) + response.write(QString("nextComic:%1\r\n").arg(siblings.at(i + 1).id).toUtf8()); + } else { + //ERROR + } + + response.write(comic.toTXT().toUtf8(), true); + } else { + //delete comicFile; + response.setStatus(404, "not found"); + response.write("404 not found", true); + } + //response.write(t.toLatin1(),true); +} diff --git a/YACReaderLibrary/server/controllers/v2/comiccontrollerinreadinglist_v2.h b/YACReaderLibrary/server/controllers/v2/comiccontrollerinreadinglist_v2.h new file mode 100644 index 00000000..424fcbf7 --- /dev/null +++ b/YACReaderLibrary/server/controllers/v2/comiccontrollerinreadinglist_v2.h @@ -0,0 +1,18 @@ +#ifndef COMICCONTROLLERINREADINGLISTV2_H +#define COMICCONTROLLERINREADINGLISTV2_H + +#include "httprequest.h" +#include "httpresponse.h" +#include "httprequesthandler.h" + +class ComicControllerInReadingListV2 : public stefanfrings::HttpRequestHandler +{ + Q_OBJECT + Q_DISABLE_COPY(ComicControllerInReadingListV2) +public: + ComicControllerInReadingListV2(); + + void service(stefanfrings::HttpRequest &request, stefanfrings::HttpResponse &response) override; +}; + +#endif // COMICCONTROLLERINREADINGLISTV2_H diff --git a/YACReaderLibrary/server/controllers/v2/pagecontroller_v2.cpp b/YACReaderLibrary/server/controllers/v2/pagecontroller_v2.cpp index 2163cde0..a00506f0 100644 --- a/YACReaderLibrary/server/controllers/v2/pagecontroller_v2.cpp +++ b/YACReaderLibrary/server/controllers/v2/pagecontroller_v2.cpp @@ -46,6 +46,12 @@ void PageControllerV2::service(HttpRequest &request, HttpResponse &response) currentComicId = ySession->getCurrentComicId(); } + if (comicFile == nullptr) { + response.setStatus(404, "not found"); + response.write("404 not found", true); + return; + } + if (comicFile->hasBeenAnErrorOpening()) { //delete comicFile; if (remote) diff --git a/YACReaderLibrary/server/requestmapper.cpp b/YACReaderLibrary/server/requestmapper.cpp index d208ab04..ea8af84d 100644 --- a/YACReaderLibrary/server/requestmapper.cpp +++ b/YACReaderLibrary/server/requestmapper.cpp @@ -39,6 +39,7 @@ #include "controllers/v2/readinglistcontentcontroller_v2.h" #include "controllers/v2/readinglistinfocontroller_v2.h" #include "controllers/v2/comicfullinfocontroller_v2.h" +#include "controllers/v2/comiccontrollerinreadinglist_v2.h" #include "db_helper.h" #include "yacreader_libraries.h" @@ -234,6 +235,7 @@ void RequestMapper::serviceV2(HttpRequest &request, HttpResponse &response) QRegExp comicDownloadInfo("/v2/library/.+/comic/[0-9]+/info/?"); //get comic info (full download info) QRegExp comicOpenForDownloading("/v2/library/.+/comic/[0-9]+/?"); //get comic info (full info + opening) QRegExp comicOpenForRemoteReading("/v2/library/.+/comic/[0-9]+/remote/?"); //the server will open for reading the comic + QRegExp comicOpenForRemoteReadingInAReadingList("/v2/library/.+/reading_list/[0-9]+/comic/[0-9]+/remote/?"); //the server will open for reading the comic QRegExp comicFullInfo("/v2/library/.+/comic/[0-9]+/fullinfo/?"); //get comic info QRegExp comicUpdate("/v2/library/.+/comic/[0-9]+/update/?"); //get comic info QRegExp comicClose("/v2/library/.+/comic/[0-9]+/close/?"); //the server will close the comic and free memory @@ -277,8 +279,9 @@ void RequestMapper::serviceV2(HttpRequest &request, HttpResponse &response) CoverControllerV2().service(request, response); } else if (comicDownloadInfo.exactMatch(path)) { ComicDownloadInfoControllerV2().service(request, response); - } else if (comicOpenForDownloading.exactMatch(path) || comicOpenForRemoteReading.exactMatch(path)) //start download or start remote reading - { + } else if (comicOpenForRemoteReadingInAReadingList.exactMatch(path)) { + ComicControllerInReadingListV2().service(request, response); + } else if (comicOpenForDownloading.exactMatch(path) || comicOpenForRemoteReading.exactMatch(path)) { //start download or start remote reading ComicControllerV2().service(request, response); } else if (comicFullInfo.exactMatch(path)) { ComicFullinfoController_v2().service(request, response); diff --git a/YACReaderLibrary/server/server.pri b/YACReaderLibrary/server/server.pri index e0f715b5..9c17a2b3 100644 --- a/YACReaderLibrary/server/server.pri +++ b/YACReaderLibrary/server/server.pri @@ -46,7 +46,8 @@ HEADERS += \ $$PWD/controllers/v2/readinglistcontentcontroller_v2.h \ $$PWD/controllers/v2/comicfullinfocontroller_v2.h \ $$PWD/controllers/v2/readinglistinfocontroller_v2.h \ - $$PWD/controllers/v2/taginfocontroller_v2.h + $$PWD/controllers/v2/taginfocontroller_v2.h \ + $$PWD/controllers/v2/comiccontrollerinreadinglist_v2.h SOURCES += \ @@ -87,7 +88,8 @@ SOURCES += \ $$PWD/controllers/v2/readinglistcontentcontroller_v2.cpp \ $$PWD/controllers/v2/comicfullinfocontroller_v2.cpp \ $$PWD/controllers/v2/readinglistinfocontroller_v2.cpp \ - $$PWD/controllers/v2/taginfocontroller_v2.cpp + $$PWD/controllers/v2/taginfocontroller_v2.cpp \ + $$PWD/controllers/v2/comiccontrollerinreadinglist_v2.cpp include(../../third_party/QtWebApp/httpserver/httpserver.pri) include(../../third_party/QtWebApp/templateengine/templateengine.pri) diff --git a/YACReaderLibrary/yacreader_local_server.cpp b/YACReaderLibrary/yacreader_local_server.cpp index 55891b22..de733747 100644 --- a/YACReaderLibrary/yacreader_local_server.cpp +++ b/YACReaderLibrary/yacreader_local_server.cpp @@ -95,6 +95,7 @@ void YACReaderClientConnectionWorker::run() quint64 libraryId; ComicDB comic; + OpenComicSource source = { OpenComicSource::ReadingList, 0 }; qulonglong nextComicId; int tries = 0; int dataAvailable = 0; @@ -136,22 +137,20 @@ void YACReaderClientConnectionWorker::run() QDataStream dataStream(data); quint8 msgType; dataStream >> msgType; - dataStream >> libraryId; - dataStream >> comic; - - bool nextComicInfoAvailable; - - if (dataStream.atEnd()) { - nextComicInfoAvailable = false; - } else { - nextComicInfoAvailable = true; - dataStream >> nextComicId; - } switch (msgType) { case YACReader::RequestComicInfo: { + dataStream >> libraryId; + dataStream >> source; + dataStream >> comic; + QList siblings; - getComicInfo(libraryId, comic, siblings); + + if (source.source == OpenComicSource::ReadingList) { + getComicInfoFromReadingList(libraryId, source.sourceId, comic, siblings); + } else { + getComicInfo(libraryId, comic, siblings); + } QByteArray block; QDataStream out(&block, QIODevice::WriteOnly); @@ -179,6 +178,18 @@ void YACReaderClientConnectionWorker::run() break; } case YACReader::SendComicInfo: { + bool nextComicInfoAvailable; + + dataStream >> libraryId; + dataStream >> comic; + + if (dataStream.atEnd()) { + nextComicInfoAvailable = false; + } else { + nextComicInfoAvailable = true; + dataStream >> nextComicId; + } + if (nextComicInfoAvailable) { updateComic(libraryId, comic, nextComicId); } else { @@ -208,6 +219,13 @@ void YACReaderClientConnectionWorker::getComicInfo(quint64 libraryId, ComicDB &c siblings = DBHelper::getSiblings(libraryId, comic.parentId); } +void YACReaderClientConnectionWorker::getComicInfoFromReadingList(quint64 libraryId, unsigned long long readingListId, ComicDB &comic, QList &siblings) +{ + QMutexLocker locker(&dbMutex); + comic = DBHelper::getComicInfo(libraryId, comic.id); + siblings = DBHelper::getReadingListFullContent(libraryId, readingListId, true); +} + void YACReaderClientConnectionWorker::updateComic(quint64 libraryId, ComicDB &comic) { QMutexLocker locker(&dbMutex); diff --git a/YACReaderLibrary/yacreader_local_server.h b/YACReaderLibrary/yacreader_local_server.h index 8db3e8de..808a6b4c 100644 --- a/YACReaderLibrary/yacreader_local_server.h +++ b/YACReaderLibrary/yacreader_local_server.h @@ -42,7 +42,8 @@ private: //static int count; void run(); - void getComicInfo(quint64 libraryId, ComicDB &comic, QList &sibling); + void getComicInfo(quint64 libraryId, ComicDB &comic, QList &siblings); + void getComicInfoFromReadingList(quint64 libraryId, unsigned long long readingListId, ComicDB &comic, QList &siblings); void updateComic(quint64 libraryId, ComicDB &comic); void updateComic(quint64 libraryId, ComicDB &comic, qulonglong nextComicId); diff --git a/common/yacreader_global.cpp b/common/yacreader_global.cpp index 8c4d4e13..53d2bf75 100644 --- a/common/yacreader_global.cpp +++ b/common/yacreader_global.cpp @@ -88,3 +88,19 @@ QString YACReader::labelColorToRGBString(LabelColors color) return ""; } + +QDataStream &YACReader::operator<<(QDataStream &stream, const OpenComicSource &source) +{ + stream << (quint8)source.source; + stream << source.sourceId; + return stream; +} + +QDataStream &YACReader::operator>>(QDataStream &stream, OpenComicSource &source) +{ + quint8 sourceRaw; + stream >> sourceRaw; + source.source = (OpenComicSource::Source)sourceRaw; + stream >> source.sourceId; + return stream; +} diff --git a/common/yacreader_global.h b/common/yacreader_global.h index e35dca6e..6b2ba727 100644 --- a/common/yacreader_global.h +++ b/common/yacreader_global.h @@ -2,6 +2,7 @@ #define __YACREADER_GLOBAL_H #include +#include #define VERSION "9.8.0" @@ -54,9 +55,26 @@ enum LabelColors { YDark }; +struct OpenComicSource { + enum Source { + Folder = 0, + ReadingList + }; + + Source source; + qulonglong sourceId; +}; + +QDataStream &operator<<(QDataStream &stream, const OpenComicSource &source); +QDataStream &operator>>(QDataStream &stream, OpenComicSource &source); + QString getSettingsPath(); QString colorToName(LabelColors colors); QString labelColorToRGBString(LabelColors color); } + +Q_DECLARE_METATYPE(YACReader::OpenComicSource::Source) +Q_DECLARE_METATYPE(YACReader::OpenComicSource) + #endif diff --git a/custom_widgets/whats_new_dialog.cpp b/custom_widgets/whats_new_dialog.cpp index c80cceb8..3ce57094 100644 --- a/custom_widgets/whats_new_dialog.cpp +++ b/custom_widgets/whats_new_dialog.cpp @@ -62,7 +62,7 @@ YACReader::WhatsNewDialog::WhatsNewDialog(QWidget *parent) "Server
" " • New `manga` field is sent to YACReader for iOS, so comics tagged as manga will be recognized as such when reading remotely or importing comics.
" "
" - "I hope you enjoy the new update. Please, if you like YACReader consider to become a patron in Patreon or donate some money using Pay-Pal and help keeping the project alive. Remember that there is an iOS version available in the Apple App Store."); + "I hope you enjoy the new update. Please, if you like YACReader consider to become a patron in Patreon or donate some money using Pay-Pal and help keeping the project alive. Remember that there is an iOS version available in the Apple App Store."); QFont textLabelFont("Arial", 15, QFont::Light); text->setFont(textLabelFont); text->setStyleSheet("padding:51px;"