mirror of
https://github.com/YACReader/yacreader
synced 2025-07-18 21:14:33 -04:00
Add support for setting custom covers on folders
This commit is contained in:
@ -370,8 +370,12 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const
|
||||
if (role == FolderModel::IdRole)
|
||||
return item->id;
|
||||
|
||||
if (role == FolderModel::CoverPathRole)
|
||||
return getCoverUrlPathForComicHash(item->data(FirstChildHash).toString());
|
||||
if (role == FolderModel::CoverPathRole) {
|
||||
if (item->data(FolderModel::CustomImage).toString().isEmpty())
|
||||
return getCoverUrlPathForComicHash(item->data(FirstChildHash).toString());
|
||||
else
|
||||
return getCoverUrlPathForFolderId(item->id);
|
||||
}
|
||||
|
||||
if (role == FolderModel::NumChildrenRole)
|
||||
return item->data(NumChildren);
|
||||
@ -675,6 +679,50 @@ void FolderModel::updateTreeType(YACReader::FileType type)
|
||||
QSqlDatabase::removeDatabase(connectionName);
|
||||
}
|
||||
|
||||
void FolderModel::setCustomFolderCover(const QModelIndex &index, const QString &path)
|
||||
{
|
||||
QString connectionName = "";
|
||||
{
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||
db.transaction();
|
||||
|
||||
auto item = static_cast<FolderItem *>(index.internalPointer());
|
||||
item->setData(FolderModel::CustomImage, path);
|
||||
|
||||
Folder f = DBHelper::loadFolder(item->id, db);
|
||||
f.customImage = path;
|
||||
DBHelper::update(f, db);
|
||||
|
||||
db.commit();
|
||||
connectionName = db.connectionName();
|
||||
}
|
||||
QSqlDatabase::removeDatabase(connectionName);
|
||||
|
||||
emit dataChanged(index, index);
|
||||
}
|
||||
|
||||
void FolderModel::resetFolderCover(const QModelIndex &index)
|
||||
{
|
||||
QString connectionName = "";
|
||||
{
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
|
||||
db.transaction();
|
||||
|
||||
auto item = static_cast<FolderItem *>(index.internalPointer());
|
||||
item->setData(FolderModel::CustomImage, "");
|
||||
|
||||
Folder f = DBHelper::loadFolder(item->id, db);
|
||||
f.customImage = "";
|
||||
DBHelper::update(f, db);
|
||||
|
||||
db.commit();
|
||||
connectionName = db.connectionName();
|
||||
}
|
||||
QSqlDatabase::removeDatabase(connectionName);
|
||||
|
||||
emit dataChanged(index, index);
|
||||
}
|
||||
|
||||
QStringList FolderModel::getSubfoldersNames(const QModelIndex &mi)
|
||||
{
|
||||
QStringList result;
|
||||
@ -858,6 +906,12 @@ QUrl FolderModel::getCoverUrlPathForComicHash(const QString &hash) const
|
||||
return QUrl::fromLocalFile(coverPath);
|
||||
}
|
||||
|
||||
QUrl FolderModel::getCoverUrlPathForFolderId(qulonglong folderId) const
|
||||
{
|
||||
auto coverPath = LibraryPaths::customFolderCoverPathFromDataPath(_databasePath, QString::number(folderId));
|
||||
return QUrl::fromLocalFile(coverPath);
|
||||
}
|
||||
|
||||
void FolderModel::setShowRecent(bool showRecent)
|
||||
{
|
||||
if (this->showRecent == showRecent)
|
||||
|
@ -70,6 +70,8 @@ public:
|
||||
void updateFolderFinishedStatus(const QModelIndexList &list, bool status);
|
||||
void updateFolderType(const QModelIndexList &list, YACReader::FileType type);
|
||||
void updateTreeType(YACReader::FileType type);
|
||||
void setCustomFolderCover(const QModelIndex &index, const QString &path);
|
||||
void resetFolderCover(const QModelIndex &index);
|
||||
|
||||
QStringList getSubfoldersNames(const QModelIndex &mi);
|
||||
FolderModel *getSubfoldersModel(const QModelIndex &mi); // it creates a model that contains just the direct subfolders
|
||||
@ -81,6 +83,7 @@ public:
|
||||
QModelIndex addFolderAtParent(const QString &folderName, const QModelIndex &parent);
|
||||
|
||||
Q_INVOKABLE QUrl getCoverUrlPathForComicHash(const QString &hash) const;
|
||||
Q_INVOKABLE QUrl getCoverUrlPathForFolderId(qulonglong folderId) const;
|
||||
|
||||
void setShowRecent(bool showRecent);
|
||||
void setRecentRange(int days);
|
||||
|
Reference in New Issue
Block a user