diff --git a/YACReaderLibrary/db/comic_model.cpp b/YACReaderLibrary/db/comic_model.cpp index 6c29a686..b0a40129 100644 --- a/YACReaderLibrary/db/comic_model.cpp +++ b/YACReaderLibrary/db/comic_model.cpp @@ -1228,10 +1228,10 @@ void ComicModel::notifyCoverChange(const ComicDB &comic) // this doesn't work in QML -> emit dataChanged(index(itemIndex, 0), index(itemIndex, 0), QVector() << CoverPathRole); } -// ???? QUrl ComicModel::getCoverUrlPathForComicHash(const QString &hash) const { - return QUrl::fromLocalFile(_databasePath + "/covers/" + hash + ".jpg"); + auto coverPath = LibraryPaths::coverPathFromLibraryDataPath(_databasePath, hash); + return QUrl::fromLocalFile(coverPath); } void ComicModel::addComicsToFavorites(const QList &comicIds) diff --git a/YACReaderLibrary/db/folder_model.cpp b/YACReaderLibrary/db/folder_model.cpp index ca746621..54d63bf2 100644 --- a/YACReaderLibrary/db/folder_model.cpp +++ b/YACReaderLibrary/db/folder_model.cpp @@ -852,7 +852,8 @@ QModelIndex FolderModel::addFolderAtParent(const QString &folderName, const QMod QUrl FolderModel::getCoverUrlPathForComicHash(const QString &hash) const { - return QUrl::fromLocalFile(_databasePath + "/covers/" + hash + ".jpg"); + auto coverPath = LibraryPaths::coverPathFromLibraryDataPath(_databasePath, hash); + return QUrl::fromLocalFile(coverPath); } void FolderModel::setShowRecent(bool showRecent) diff --git a/YACReaderLibrary/library_creator.cpp b/YACReaderLibrary/library_creator.cpp index 1cd66ce1..eaa035b3 100644 --- a/YACReaderLibrary/library_creator.cpp +++ b/YACReaderLibrary/library_creator.cpp @@ -154,7 +154,7 @@ void LibraryCreator::run() _currentPathFolders.clear(); // se crean los directorios .yacreaderlibrary y .yacreaderlibrary/covers QDir dir; - dir.mkpath(_target + "/covers"); + dir.mkpath(LibraryPaths::libraryCoversPathFromLibraryDataPath(_target)); // se crea la base de datos .yacreaderlibrary/library.ydb { @@ -269,7 +269,8 @@ void LibraryCreator::cancel() void LibraryCreator::cleanup(QSqlDatabase &db, const QString &target) { - QDir coversDir(target + "/covers/"); + auto coversPath = LibraryPaths::libraryCoversPathFromLibraryDataPath(target); + QDir coversDir(coversPath); if (!coversDir.exists()) { return; } @@ -285,10 +286,8 @@ void LibraryCreator::cleanup(QSqlDatabase &db, const QString &target) while (infoToDeleteQuery.next()) { QString hash = infoToDeleteQuery.value(1).toString(); - QString cover = hash + ".jpg"; - - auto fullPath = coversDir.absoluteFilePath(cover); - QFile::remove(fullPath); + QString coverPath = LibraryPaths::coverPathFromLibraryDataPath(target, hash); + QFile::remove(coverPath); } QSqlQuery deleteQuery(db); @@ -358,7 +357,7 @@ void LibraryCreator::create(QDir dir) bool LibraryCreator::checkCover(const QString &hash) { - return QFile::exists(_target + "/covers/" + hash + ".jpg"); + return QFile::exists(LibraryPaths::coverPathFromLibraryDataPath(_target, hash)); } QString pseudoHash(const QFileInfo &fileInfo) @@ -383,14 +382,15 @@ void LibraryCreator::insertComic(const QString &relativePath, const QFileInfo &f QPair originalCoverSize = { 0, 0 }; bool exists = checkCover(hash); - YACReader::InitialComicInfoExtractor ie(QDir::cleanPath(fileInfo.absoluteFilePath()), _target + "/covers/" + hash + ".jpg", comic.info.coverPage.toInt(), settings->value(IMPORT_COMIC_INFO_XML_METADATA, false).toBool()); + auto coverPath = LibraryPaths::coverPathFromLibraryDataPath(_target, hash); + YACReader::InitialComicInfoExtractor ie(QDir::cleanPath(fileInfo.absoluteFilePath()), coverPath, comic.info.coverPage.toInt(), settings->value(IMPORT_COMIC_INFO_XML_METADATA, false).toBool()); if (!(comic.hasCover() && exists)) { ie.extract(); numPages = ie.getNumPages(); originalCoverSize = ie.getOriginalCoverSize(); if (numPages > 0) { - emit comicAdded(relativePath, _target + "/covers/" + hash + ".jpg"); + emit comicAdded(relativePath, coverPath); } } diff --git a/common/yacreader_global.h b/common/yacreader_global.h index d4f06ef6..9fb68539 100644 --- a/common/yacreader_global.h +++ b/common/yacreader_global.h @@ -127,9 +127,24 @@ struct LibraryPaths { return QDir(libraryDataPath(libraryPath)).filePath("covers"); } + static QString libraryCoversPathFromLibraryDataPath(const QString &libraryDataPath) // libraryDataPath + /covers + { + return QDir(libraryDataPath).filePath("covers"); + } + static QString coverPath(const QString &libraryPath, const QString &hash) // libraryPath + /.yacreaderlibrary/covers/hash + .jpg { - return QDir(libraryCoversFolderPath(libraryPath)).filePath(hash + ".jpg"); + return QDir(libraryCoversFolderPath(libraryPath)).filePath(coverFileName(hash)); + } + + static QString coverPathFromLibraryDataPath(const QString &libraryDataPath, const QString &hash) // libraryDataPath + /covers/hash + .jpg + { + return QDir(libraryCoversPathFromLibraryDataPath(libraryDataPath)).filePath(coverFileName(hash)); + } + + static QString coverFileName(const QString &hash) // hash + .jpg + { + return hash + ".jpg"; } static QString coverPathWithFileName(const QString &libraryPath, const QString &fileName) // libraryPath + /.yacreaderlibrary/covers/hash + fileName