Add actions for setting folders as manga/normal

This commit is contained in:
Luis Ángel San Martín 2021-01-16 18:31:48 +01:00
parent d402999991
commit 6461a4014e
7 changed files with 128 additions and 3 deletions

View File

@ -127,6 +127,9 @@ QVariant FolderModel::data(const QModelIndex &index, int role) const
if (role == FolderModel::FinishedRole)
return item->data(FolderModel::Finished);
if (role == FolderModel::MangaRole)
return item->data(FolderModel::Manga);
if (role == FolderModel::IdRole)
return item->id;
@ -246,6 +249,7 @@ void FolderModel::setupModelData(QSqlQuery &sqlquery, FolderItem *parent)
int path = record.indexOf("path");
int finished = record.indexOf("finished");
int completed = record.indexOf("completed");
int manga = record.indexOf("manga");
int id = record.indexOf("id");
int parentId = record.indexOf("parentId");
@ -256,6 +260,7 @@ void FolderModel::setupModelData(QSqlQuery &sqlquery, FolderItem *parent)
data << sqlquery.value(path).toString();
data << sqlquery.value(finished).toBool();
data << sqlquery.value(completed).toBool();
data << sqlquery.value(manga).toBool();
auto item = new FolderItem(data);
item->id = sqlquery.value(id).toULongLong();
@ -278,6 +283,7 @@ void FolderModel::updateFolderModelData(QSqlQuery &sqlquery, FolderItem *parent)
int path = record.indexOf("path");
int finished = record.indexOf("finished");
int completed = record.indexOf("completed");
int manga = record.indexOf("manga");
int id = record.indexOf("id");
int parentId = record.indexOf("parentId");
@ -288,6 +294,7 @@ void FolderModel::updateFolderModelData(QSqlQuery &sqlquery, FolderItem *parent)
data << sqlquery.value(path).toString();
data << sqlquery.value(finished).toBool();
data << sqlquery.value(completed).toBool();
data << sqlquery.value(manga).toBool();
auto item = new FolderItem(data);
item->id = sqlquery.value(id).toULongLong();
@ -356,6 +363,36 @@ void FolderModel::updateFolderFinishedStatus(const QModelIndexList &list, bool s
emit dataChanged(index(list.first().row(), FolderModel::Name), index(list.last().row(), FolderModel::Completed));
}
void FolderModel::updateFolderManga(const QModelIndexList &list, bool manga)
{
QString connectionName = "";
{
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
db.transaction();
foreach (QModelIndex mi, list) {
auto item = static_cast<FolderItem *>(mi.internalPointer());
std::function<void(FolderItem *, bool)> setManga;
setManga = [&setManga](FolderItem *item, bool manga) -> void {
item->setData(FolderModel::Manga, manga);
for (auto child : item->children()) {
setManga(child, manga);
}
};
setManga(item, manga);
DBHelper::updateFolderTreeManga(item->id, db, manga);
}
db.commit();
connectionName = db.connectionName();
}
QSqlDatabase::removeDatabase(connectionName);
emit dataChanged(index(list.first().row(), FolderModel::Name), index(list.last().row(), FolderModel::Manga));
}
QStringList FolderModel::getSubfoldersNames(const QModelIndex &mi)
{
QStringList result;
@ -461,7 +498,8 @@ QModelIndex FolderModel::addFolderAtParent(const QString &folderName, const QMod
Folder newFolder;
newFolder.name = folderName;
newFolder.parentId = parentItem->id;
newFolder.path = parentItem->data(1).toString() + "/" + folderName;
newFolder.path = parentItem->data(Columns::Path).toString() + "/" + folderName;
newFolder.setManga(parentItem->data(Columns::Manga).toBool());
QString connectionName = "";
{
QSqlDatabase db = DataBaseManagement::loadDatabase(_databasePath);
@ -478,6 +516,7 @@ QModelIndex FolderModel::addFolderAtParent(const QString &folderName, const QMod
data << newFolder.path;
data << false; //finished
data << true; //completed
data << newFolder.isManga();
auto item = new FolderItem(data);
item->id = newFolder.id;

View File

@ -67,6 +67,7 @@ public:
void updateFolderCompletedStatus(const QModelIndexList &list, bool status);
void updateFolderFinishedStatus(const QModelIndexList &list, bool status);
void updateFolderManga(const QModelIndexList &list, bool manga);
QStringList getSubfoldersNames(const QModelIndex &mi);
@ -78,13 +79,15 @@ public:
Name = 0,
Path = 1,
Finished = 2,
Completed = 3
Completed = 3,
Manga = 4
}; //id INTEGER PRIMARY KEY, parentId INTEGER NOT NULL, name TEXT NOT NULL, path TEXT NOT NULL
enum Roles {
FinishedRole = Qt::UserRole + 1,
CompletedRole,
IdRole
IdRole,
MangaRole
};
public slots:

View File

@ -1518,6 +1518,37 @@ QList<Label> DBHelper::getLabels(qulonglong libraryId)
return labels;
}
void DBHelper::updateFolderTreeManga(qulonglong id, QSqlDatabase &db, bool manga)
{
QSqlQuery updateFolderQuery(db);
updateFolderQuery.prepare("UPDATE folder "
"SET manga = :manga "
"WHERE id = :id");
updateFolderQuery.bindValue(":manga", manga ? 1 : 0);
updateFolderQuery.bindValue(":id", id);
updateFolderQuery.exec();
QSqlQuery updateComicInfo(db);
updateComicInfo.prepare("UPDATE comic_info "
"SET manga = :manga "
"FROM comic c INNER JOIN comic_info ci ON (c.comicInfoId = ci.id) "
"WHERE c.parentId = :parentId");
updateComicInfo.bindValue(":manga", manga ? 1 : 0);
updateComicInfo.bindValue(":parentId", id);
updateComicInfo.exec();
QSqlQuery getSubFoldersQuery(db);
getSubFoldersQuery.prepare("SELECT id FROM folder WHERE parentId = :parentId AND id <> 1"); //do not select the root folder
getSubFoldersQuery.bindValue(":parentId", id);
getSubFoldersQuery.exec();
int childFolderIdPos = getSubFoldersQuery.record().indexOf("id");
while (getSubFoldersQuery.next()) {
updateFolderTreeManga(getSubFoldersQuery.value(childFolderIdPos).toULongLong(), db, manga);
}
}
//loads
Folder DBHelper::loadFolder(qulonglong id, QSqlDatabase &db)
{

View File

@ -86,6 +86,8 @@ public:
static QList<LibraryItem *> getComicsFromParent(qulonglong parentId, QSqlDatabase &db, bool sort = true);
static QList<Label> getLabels(qulonglong libraryId);
static void updateFolderTreeManga(qulonglong id, QSqlDatabase &db, bool manga);
//load
static Folder loadFolder(qulonglong id, QSqlDatabase &db);
static Folder loadFolder(const QString &folderName, qulonglong parentId, QSqlDatabase &db);

View File

@ -348,6 +348,8 @@ void LibraryWindow::setUpShortcutsManagement()
<< setFolderAsCompletedAction
<< setFolderAsReadAction
<< setFolderAsUnreadAction
<< setFolderAsMangaAction
<< setFolderAsNormalAction
<< updateCurrentFolderAction);
allActions << tmpList;
@ -616,6 +618,8 @@ void LibraryWindow::createActions()
toggleComicsViewAction->setIcon(icoViewsButton);
//socialAction = new QAction(this);
//----
openContainingFolderAction = new QAction(this);
openContainingFolderAction->setText(tr("Open folder..."));
openContainingFolderAction->setData(OPEN_CONTAINING_FOLDER_ACTION_YL);
@ -642,6 +646,18 @@ void LibraryWindow::createActions()
setFolderAsUnreadAction->setData(SET_FOLDER_AS_UNREAD_ACTION_YL);
setFolderAsUnreadAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_FOLDER_AS_UNREAD_ACTION_YL));
setFolderAsMangaAction = new QAction(this);
setFolderAsMangaAction->setText(tr("Set as manga"));
setFolderAsMangaAction->setData(SET_FOLDER_AS_MANGA_ACTION_YL);
setFolderAsMangaAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_FOLDER_AS_MANGA_ACTION_YL));
setFolderAsNormalAction = new QAction(this);
setFolderAsNormalAction->setText(tr("Set as comic"));
setFolderAsNormalAction->setData(SET_FOLDER_AS_NORMAL_ACTION_YL);
setFolderAsNormalAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SET_FOLDER_AS_NORMAL_ACTION_YL));
//----
openContainingFolderComicAction = new QAction(this);
openContainingFolderComicAction->setText(tr("Open containing folder..."));
openContainingFolderComicAction->setData(OPEN_CONTAINING_FOLDER_COMIC_ACTION_YL);
@ -747,6 +763,8 @@ void LibraryWindow::createActions()
this->addAction(setFolderAsNotCompletedAction);
this->addAction(setFolderAsReadAction);
this->addAction(setFolderAsUnreadAction);
this->addAction(setFolderAsMangaAction);
this->addAction(setFolderAsNormalAction);
#ifndef Q_OS_MAC
this->addAction(toggleFullScreenAction);
#endif
@ -912,6 +930,10 @@ void LibraryWindow::createMenus()
foldersView->addAction(setFolderAsReadAction);
foldersView->addAction(setFolderAsUnreadAction);
YACReader::addSperator(foldersView);
foldersView->addAction(setFolderAsMangaAction);
foldersView->addAction(setFolderAsNormalAction);
selectedLibrary->addAction(updateLibraryAction);
selectedLibrary->addAction(renameLibraryAction);
@ -957,6 +979,9 @@ void LibraryWindow::createMenus()
folderMenu->addSeparator();
folderMenu->addAction(setFolderAsReadAction);
folderMenu->addAction(setFolderAsUnreadAction);
folderMenu->addSperator();
foldersView->addAction(setFolderAsMangaAction);
foldersView->addAction(setFolderAsNormalAction);
//comic
QMenu *comicMenu = new QMenu(tr("Comic"));
@ -1089,6 +1114,9 @@ void LibraryWindow::createConnections()
connect(setFolderAsReadAction, SIGNAL(triggered()), this, SLOT(setFolderAsRead()));
connect(setFolderAsUnreadAction, SIGNAL(triggered()), this, SLOT(setFolderAsUnread()));
connect(openContainingFolderAction, SIGNAL(triggered()), this, SLOT(openContainingFolder()));
connect(setFolderAsMangaAction, &QAction::triggered, this, &LibraryWindow::setFolderAsManga);
connect(setFolderAsNormalAction, &QAction::triggered, this, &LibraryWindow::setFolderAsNormal);
connect(resetComicRatingAction, SIGNAL(triggered()), this, SLOT(resetComicRating()));
//connect(dm,SIGNAL(directoryLoaded(QString)),foldersView,SLOT(expandAll()));
@ -2310,6 +2338,16 @@ void LibraryWindow::setFolderAsUnread()
foldersModel->updateFolderFinishedStatus(QModelIndexList() << foldersModelProxy->mapToSource(foldersView->currentIndex()), false);
}
void LibraryWindow::setFolderAsManga()
{
foldersModel->updateFolderManga(QModelIndexList() << foldersModelProxy->mapToSource(foldersView->currentIndex()), true);
}
void LibraryWindow::setFolderAsNormal()
{
foldersModel->updateFolderManga(QModelIndexList() << foldersModelProxy->mapToSource(foldersView->currentIndex()), false);
}
void LibraryWindow::exportLibrary(QString destPath)
{
QString currentLibrary = selectedLibrary->currentText();
@ -2543,6 +2581,7 @@ void LibraryWindow::showFoldersContextMenu(const QPoint &point)
bool isCompleted = sourceMI.data(FolderModel::CompletedRole).toBool();
bool isRead = sourceMI.data(FolderModel::FinishedRole).toBool();
bool isManga = sourceMI.data(FolderModel::MangaRole).toBool();
QMenu menu;
//QMenu * folderMenu = new QMenu(tr("Folder"));
@ -2558,6 +2597,11 @@ void LibraryWindow::showFoldersContextMenu(const QPoint &point)
menu.addAction(setFolderAsUnreadAction);
else
menu.addAction(setFolderAsReadAction);
menu.addSeparator(); //-------------------------------
if (isManga)
menu.addAction(setFolderAsNormalAction);
else
menu.addAction(setFolderAsMangaAction);
menu.exec(foldersView->mapToGlobal(point));
}

View File

@ -189,6 +189,8 @@ public:
//--
QAction *setFolderAsReadAction;
QAction *setFolderAsUnreadAction;
QAction *setFolderAsMangaAction;
QAction *setFolderAsNormalAction;
QAction *openContainingFolderComicAction;
QAction *setAsReadAction;
@ -321,6 +323,8 @@ public slots:
void setFolderAsCompleted();
void setFolderAsRead();
void setFolderAsUnread();
void setFolderAsManga();
void setFolderAsNormal();
void openContainingFolderComic();
void deleteCurrentLibrary();
void removeLibrary();

View File

@ -64,6 +64,8 @@ public:
#define SET_FOLDER_AS_COMPLETED_ACTION_YL "SET_FOLDER_AS_COMPLETED_ACTION_YL"
#define SET_FOLDER_AS_READ_ACTION_YL "SET_FOLDER_AS_READ_ACTION_YL"
#define SET_FOLDER_AS_UNREAD_ACTION_YL "SET_FOLDER_AS_UNREAD_ACTION_YL"
#define SET_FOLDER_AS_MANGA_ACTION_YL "SET_FOLDER_AS_MANGA_ACTION_YL"
#define SET_FOLDER_AS_NORMAL_ACTION_YL "SET_FOLDER_AS_NORMAL_ACTION_YL"
#define OPEN_CONTAINING_FOLDER_COMIC_ACTION_YL "OPEN_CONTAINING_FOLDER_COMIC_ACTION_YL"
#define RESET_COMIC_RATING_ACTION_YL "RESET_COMIC_RATING_ACTION_YL"
#define SELECT_ALL_COMICS_ACTION_YL "SELECT_ALL_COMICS_ACTION_YL"