diff --git a/CHANGELOG.md b/CHANGELOG.md index 84c8bdaf..ab514d5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Version counting is based on semantic versioning (Major.Feature.Patch) * Fix headers in the table view getting stuck in a non moveable state. * Add option to set the type of a library. It will convert all the content to desired type (comic, manga, etc) and it will set that type as the default one for that library. Available in the library context menu. * Added more info to Help -> System info. +* New setting to open comics in third party reader apps, it works by entering a command that will launch the app, e.g. "/path/to/the/app {comic_file_path}". You can use `{comic_file_path}` as a placeholder where `YACReaderLibrary` will place thet path to the comic file. ### YACReaderLibraryServer * New command --system-info to print information about the execution environment and available resources (including what image formats are supported and what libraries are used by the app). diff --git a/YACReaderLibrary/library_comic_opener.cpp b/YACReaderLibrary/library_comic_opener.cpp index 638cf9a1..44c8ac28 100644 --- a/YACReaderLibrary/library_comic_opener.cpp +++ b/YACReaderLibrary/library_comic_opener.cpp @@ -46,3 +46,16 @@ bool YACReader::openComic(const ComicDB &comic, return yacreaderFound; } + +bool YACReader::openComicInThirdPartyApp(const QString &command, const QString &path) +{ + QString mutableCommand = command; + QString fullCommand; + if (mutableCommand.contains("{comic_file_path}")) { + fullCommand = mutableCommand.replace("{comic_file_path}", "\"" + path + "\""); + } else { + fullCommand = mutableCommand + " \"" + path + "\""; + } + + return QProcess::startDetached(fullCommand); +} diff --git a/YACReaderLibrary/library_comic_opener.h b/YACReaderLibrary/library_comic_opener.h index b68cb225..5fb6d28d 100644 --- a/YACReaderLibrary/library_comic_opener.h +++ b/YACReaderLibrary/library_comic_opener.h @@ -13,6 +13,9 @@ bool openComic(const ComicDB &comic, const QString &path, OpenComicSource source); +bool openComicInThirdPartyApp(const QString &command, + const QString &path); + } #endif // LIBRARYCOMICOPENER_H diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index 4e6db6f2..756facb5 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -1674,14 +1674,23 @@ void LibraryWindow::openComic(const ComicDB &comic, const ComicModel::Mode mode) source = OpenComicSource::Source::Folder; } - auto yacreaderFound = YACReader::openComic(comic, libraryId, currentPath(), OpenComicSource { source, comicsModel->getSourceId() }); + auto thirdPartyReaderCommand = settings->value(THIRD_PARTY_READER_COMMAND, "").toString(); + if (thirdPartyReaderCommand.isEmpty()) { + auto yacreaderFound = YACReader::openComic(comic, libraryId, currentPath(), OpenComicSource { source, comicsModel->getSourceId() }); - if (!yacreaderFound) { + 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.")); + QMessageBox::critical(this, tr("YACReader not found"), tr("YACReader not found. YACReader should be installed in the same folder as YACReaderLibrary.")); #else - QMessageBox::critical(this, tr("YACReader not found"), tr("YACReader not found. There might be a problem with your YACReader installation.")); + QMessageBox::critical(this, tr("YACReader not found"), tr("YACReader not found. There might be a problem with your YACReader installation.")); #endif + } + } else { + auto exec = YACReader::openComicInThirdPartyApp(thirdPartyReaderCommand, QDir::cleanPath(currentPath() + comic.path)); + + if (!exec) { + QMessageBox::critical(this, tr("Error"), tr("Error opening comic with third party reader.")); + } } } diff --git a/YACReaderLibrary/options_dialog.cpp b/YACReaderLibrary/options_dialog.cpp index 24eabb44..32a7df27 100644 --- a/YACReaderLibrary/options_dialog.cpp +++ b/YACReaderLibrary/options_dialog.cpp @@ -85,6 +85,14 @@ void OptionsDialog::restoreOptions(QSettings *settings) updateLibrariesTimeEdit->setTime(settings->value(UPDATE_LIBRARIES_AT_CERTAIN_TIME_TIME, "00:00").toTime()); compareModifiedDateWhenUpdatingLibrariesCheck->setChecked(settings->value(COMPARE_MODIFIED_DATE_ON_LIBRARY_UPDATES, false).toBool()); + + thirdPartyReaderEdit->setText(settings->value(THIRD_PARTY_READER_COMMAND, "").toString()); +} + +void OptionsDialog::saveOptions() +{ + settings->setValue(THIRD_PARTY_READER_COMMAND, thirdPartyReaderEdit->text()); + YACReaderOptionsDialog::saveOptions(); } void OptionsDialog::useBackgroundImageCheckClicked(bool checked) @@ -198,12 +206,23 @@ QWidget *OptionsDialog::createGeneralTab() connect(recentIntervalSlider, &QAbstractSlider::valueChanged, this, &OptionsDialog::numDaysToConsiderRecentChanged); + auto thirdPartyReaderBox = new QGroupBox(tr("Third party reader")); + thirdPartyReaderEdit = new QLineEdit(); + thirdPartyReaderEdit->setPlaceholderText(tr("Write {comic_file_path} where the path should go in the command")); + auto clearButton = new QPushButton(tr("Clear")); + auto thirdPartyReaderLayout = new QHBoxLayout(); + thirdPartyReaderLayout->addWidget(thirdPartyReaderEdit, 1); + thirdPartyReaderLayout->addWidget(clearButton); + thirdPartyReaderBox->setLayout(thirdPartyReaderLayout); + connect(clearButton, &QPushButton::clicked, thirdPartyReaderEdit, &QLineEdit::clear); + auto generalLayout = new QVBoxLayout(); generalLayout->addWidget(trayIconBox); generalLayout->addWidget(shortcutsBox); generalLayout->addWidget(apiKeyBox); generalLayout->addWidget(comicInfoXMLBox); generalLayout->addWidget(recentlyAddedBox); + generalLayout->addWidget(thirdPartyReaderBox); generalLayout->addStretch(); auto generalW = new QWidget; diff --git a/YACReaderLibrary/options_dialog.h b/YACReaderLibrary/options_dialog.h index ff8aae65..54b9254f 100644 --- a/YACReaderLibrary/options_dialog.h +++ b/YACReaderLibrary/options_dialog.h @@ -18,6 +18,7 @@ public: public slots: void editApiKey(); void restoreOptions(QSettings *settings) override; + void saveOptions() override; private slots: void useBackgroundImageCheckClicked(bool checked); @@ -35,6 +36,7 @@ private: QCheckBox *comicInfoXMLCheckbox; QSlider *recentIntervalSlider; QLabel *numDaysLabel; + QLineEdit *thirdPartyReaderEdit; // Libraries tab QCheckBox *updateLibrariesAtStartupCheck; diff --git a/common/yacreader_global_gui.h b/common/yacreader_global_gui.h index 4a940281..d9fb58ad 100644 --- a/common/yacreader_global_gui.h +++ b/common/yacreader_global_gui.h @@ -74,6 +74,7 @@ #define DISPLAY_CONTINUE_READING_IN_GRID_VIEW "DISPLAY_CONTINUE_READING_IN_GRID_VIEW" #define DISPLAY_RECENTLY_INDICATOR "DISPLAY_RECENTLY_INDICATOR" #define NUM_DAYS_TO_CONSIDER_RECENT "NUM_DAYS_TO_CONSIDER_RECENT" +#define THIRD_PARTY_READER_COMMAND "THIRD_PARTY_READER_COMMAND" namespace YACReader {