mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -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/comic_query_result_processor.h \
|
||||||
db/folder_query_result_processor.h \
|
db/folder_query_result_processor.h \
|
||||||
db/query_lexer.h \
|
db/query_lexer.h \
|
||||||
|
library_comic_opener.h \
|
||||||
library_creator.h \
|
library_creator.h \
|
||||||
library_window.h \
|
library_window.h \
|
||||||
add_library_dialog.h \
|
add_library_dialog.h \
|
||||||
@ -156,6 +157,7 @@ SOURCES += comic_flow.cpp \
|
|||||||
db/comic_query_result_processor.cpp \
|
db/comic_query_result_processor.cpp \
|
||||||
db/folder_query_result_processor.cpp \
|
db/folder_query_result_processor.cpp \
|
||||||
db/query_lexer.cpp \
|
db/query_lexer.cpp \
|
||||||
|
library_comic_opener.cpp \
|
||||||
library_creator.cpp \
|
library_creator.cpp \
|
||||||
library_window.cpp \
|
library_window.cpp \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
|
@ -546,6 +546,7 @@ void ComicModel::setupFavoritesModelData(const QString &databasePath)
|
|||||||
{
|
{
|
||||||
enableResorting = true;
|
enableResorting = true;
|
||||||
mode = Favorites;
|
mode = Favorites;
|
||||||
|
sourceId = -1;
|
||||||
|
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
qDeleteAll(_data);
|
qDeleteAll(_data);
|
||||||
@ -574,6 +575,7 @@ void ComicModel::setupReadingModelData(const QString &databasePath)
|
|||||||
{
|
{
|
||||||
enableResorting = false;
|
enableResorting = false;
|
||||||
mode = Reading;
|
mode = Reading;
|
||||||
|
sourceId = -1;
|
||||||
|
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
qDeleteAll(_data);
|
qDeleteAll(_data);
|
||||||
|
@ -129,6 +129,7 @@ public:
|
|||||||
bool isFavorite(const QModelIndex &index);
|
bool isFavorite(const QModelIndex &index);
|
||||||
|
|
||||||
ComicModel::Mode getMode() { return mode; }
|
ComicModel::Mode getMode() { return mode; }
|
||||||
|
unsigned long long int getSourceId() { return sourceId; }
|
||||||
|
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
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 "whats_new_controller.h"
|
||||||
|
|
||||||
|
#include "library_comic_opener.h"
|
||||||
|
|
||||||
#include "QsLog.h"
|
#include "QsLog.h"
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
@ -1825,37 +1827,27 @@ void LibraryWindow::checkEmptyFolder()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibraryWindow::openComic(const ComicDB &comic)
|
void LibraryWindow::openComic()
|
||||||
{
|
{
|
||||||
if (!importedCovers) {
|
if (!importedCovers) {
|
||||||
//TODO generate IDS for libraries...
|
auto libraryId = libraries.getId(selectedLibrary->currentText());
|
||||||
quint64 libraryId = libraries.getId(selectedLibrary->currentText());
|
|
||||||
bool yacreaderFound = false;
|
|
||||||
|
|
||||||
#ifdef Q_OS_MACOS
|
auto comic = comicsModel->getComic(comicsViewsManager->comicsView->currentIndex());
|
||||||
QStringList possiblePaths { QDir::cleanPath(QCoreApplication::applicationDirPath() + "/../../../") };
|
auto mode = comicsModel->getMode();
|
||||||
possiblePaths += QStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation);
|
|
||||||
|
|
||||||
for (auto &&ypath : possiblePaths) {
|
OpenComicSource::Source source;
|
||||||
QString yacreaderPath = QDir::cleanPath(ypath + "/YACReader.app");
|
|
||||||
if (QFileInfo(yacreaderPath).exists()) {
|
if (mode == ComicModel::ReadingList) {
|
||||||
yacreaderFound = true;
|
source = OpenComicSource::Source::ReadingList;
|
||||||
QStringList parameters { "-n", yacreaderPath, "--args", currentPath(), QString("--comicId=%1").arg(comic.id), QString("--libraryId=%1").arg(libraryId) };
|
} else if (mode == ComicModel::Reading) {
|
||||||
QProcess::startDetached("open", parameters);
|
//TODO check where the comic was opened from the last time it was read
|
||||||
break;
|
source = OpenComicSource::Source::Folder;
|
||||||
}
|
} else {
|
||||||
|
source = OpenComicSource::Source::Folder;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
auto yacreaderFound = YACReader::openComic(comic, libraryId, currentPath(), OpenComicSource { source, comicsModel->getSourceId() });
|
||||||
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
|
|
||||||
|
|
||||||
#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) {
|
if (!yacreaderFound) {
|
||||||
#ifdef Q_OS_WIN
|
#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."));
|
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)
|
void LibraryWindow::setCurrentComicsStatusReaded(YACReaderComicReadStatus readStatus)
|
||||||
{
|
{
|
||||||
comicsModel->setComicsRead(getSelectedComics(), readStatus);
|
comicsModel->setComicsRead(getSelectedComics(), readStatus);
|
||||||
|
@ -313,7 +313,6 @@ public slots:
|
|||||||
void selectSubfolder(const QModelIndex &mi, int child);
|
void selectSubfolder(const QModelIndex &mi, int child);
|
||||||
void checkEmptyFolder();
|
void checkEmptyFolder();
|
||||||
void openComic();
|
void openComic();
|
||||||
void openComic(const ComicDB &comic);
|
|
||||||
void createLibrary();
|
void createLibrary();
|
||||||
void create(QString source, QString dest, QString name);
|
void create(QString source, QString dest, QString name);
|
||||||
void showAddLibrary();
|
void showAddLibrary();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user