mirror of
https://github.com/YACReader/yacreader
synced 2025-05-25 18:00:46 -04:00
More migrations to LibraryPaths
This commit is contained in:
parent
7f08ad0776
commit
181884a85f
@ -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<int>() << CoverPathRole);
|
// this doesn't work in QML -> emit dataChanged(index(itemIndex, 0), index(itemIndex, 0), QVector<int>() << CoverPathRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ????
|
|
||||||
QUrl ComicModel::getCoverUrlPathForComicHash(const QString &hash) const
|
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<qulonglong> &comicIds)
|
void ComicModel::addComicsToFavorites(const QList<qulonglong> &comicIds)
|
||||||
|
@ -852,7 +852,8 @@ QModelIndex FolderModel::addFolderAtParent(const QString &folderName, const QMod
|
|||||||
|
|
||||||
QUrl FolderModel::getCoverUrlPathForComicHash(const QString &hash) const
|
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)
|
void FolderModel::setShowRecent(bool showRecent)
|
||||||
|
@ -154,7 +154,7 @@ void LibraryCreator::run()
|
|||||||
_currentPathFolders.clear();
|
_currentPathFolders.clear();
|
||||||
// se crean los directorios .yacreaderlibrary y .yacreaderlibrary/covers
|
// se crean los directorios .yacreaderlibrary y .yacreaderlibrary/covers
|
||||||
QDir dir;
|
QDir dir;
|
||||||
dir.mkpath(_target + "/covers");
|
dir.mkpath(LibraryPaths::libraryCoversPathFromLibraryDataPath(_target));
|
||||||
|
|
||||||
// se crea la base de datos .yacreaderlibrary/library.ydb
|
// se crea la base de datos .yacreaderlibrary/library.ydb
|
||||||
{
|
{
|
||||||
@ -269,7 +269,8 @@ void LibraryCreator::cancel()
|
|||||||
|
|
||||||
void LibraryCreator::cleanup(QSqlDatabase &db, const QString &target)
|
void LibraryCreator::cleanup(QSqlDatabase &db, const QString &target)
|
||||||
{
|
{
|
||||||
QDir coversDir(target + "/covers/");
|
auto coversPath = LibraryPaths::libraryCoversPathFromLibraryDataPath(target);
|
||||||
|
QDir coversDir(coversPath);
|
||||||
if (!coversDir.exists()) {
|
if (!coversDir.exists()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -285,10 +286,8 @@ void LibraryCreator::cleanup(QSqlDatabase &db, const QString &target)
|
|||||||
|
|
||||||
while (infoToDeleteQuery.next()) {
|
while (infoToDeleteQuery.next()) {
|
||||||
QString hash = infoToDeleteQuery.value(1).toString();
|
QString hash = infoToDeleteQuery.value(1).toString();
|
||||||
QString cover = hash + ".jpg";
|
QString coverPath = LibraryPaths::coverPathFromLibraryDataPath(target, hash);
|
||||||
|
QFile::remove(coverPath);
|
||||||
auto fullPath = coversDir.absoluteFilePath(cover);
|
|
||||||
QFile::remove(fullPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSqlQuery deleteQuery(db);
|
QSqlQuery deleteQuery(db);
|
||||||
@ -358,7 +357,7 @@ void LibraryCreator::create(QDir dir)
|
|||||||
|
|
||||||
bool LibraryCreator::checkCover(const QString &hash)
|
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)
|
QString pseudoHash(const QFileInfo &fileInfo)
|
||||||
@ -383,14 +382,15 @@ void LibraryCreator::insertComic(const QString &relativePath, const QFileInfo &f
|
|||||||
QPair<int, int> originalCoverSize = { 0, 0 };
|
QPair<int, int> originalCoverSize = { 0, 0 };
|
||||||
bool exists = checkCover(hash);
|
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)) {
|
if (!(comic.hasCover() && exists)) {
|
||||||
ie.extract();
|
ie.extract();
|
||||||
numPages = ie.getNumPages();
|
numPages = ie.getNumPages();
|
||||||
originalCoverSize = ie.getOriginalCoverSize();
|
originalCoverSize = ie.getOriginalCoverSize();
|
||||||
if (numPages > 0) {
|
if (numPages > 0) {
|
||||||
emit comicAdded(relativePath, _target + "/covers/" + hash + ".jpg");
|
emit comicAdded(relativePath, coverPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,9 +127,24 @@ struct LibraryPaths {
|
|||||||
return QDir(libraryDataPath(libraryPath)).filePath("covers");
|
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
|
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
|
static QString coverPathWithFileName(const QString &libraryPath, const QString &fileName) // libraryPath + /.yacreaderlibrary/covers/hash + fileName
|
||||||
|
Loading…
Reference in New Issue
Block a user