Extract opening a comic from YACReaderLibrary to its own file

And send a new param `--readingListId` to tell YACReader that the comic is opened from a reading list.
This commit is contained in:
Luis Ángel San Martín
2021-05-27 18:48:52 +02:00
parent f9285bd099
commit 945b24a8f8
7 changed files with 86 additions and 33 deletions

View File

@ -0,0 +1,47 @@
#include "library_comic_opener.h"
#include "comic_db.h"
#include <QtCore>
#include <QtWidgets>
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;
}