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

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

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;

View File

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