mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
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:
parent
f9285bd099
commit
945b24a8f8
@ -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 \
|
||||
|
@ -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);
|
||||
|
@ -129,6 +129,7 @@ public:
|
||||
bool isFavorite(const QModelIndex &index);
|
||||
|
||||
ComicModel::Mode getMode() { return mode; }
|
||||
unsigned long long int getSourceId() { return sourceId; }
|
||||
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
|
47
YACReaderLibrary/library_comic_opener.cpp
Normal file
47
YACReaderLibrary/library_comic_opener.cpp
Normal 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;
|
||||
}
|
18
YACReaderLibrary/library_comic_opener.h
Normal file
18
YACReaderLibrary/library_comic_opener.h
Normal file
@ -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
|
@ -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);
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user