Add setting to setup third party readers to work with YACReaderLibrary

This commit is contained in:
Luis Ángel San Martín
2024-10-15 22:11:52 +02:00
parent 5f03fc5f1f
commit 9b6e03bcc4
7 changed files with 52 additions and 4 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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."));
}
}
}

View File

@ -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;

View File

@ -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;