From ae990d82afd6ef11c0712439811ccc147a5a8731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Sat, 29 Oct 2022 11:07:57 +0200 Subject: [PATCH] Add a new action to scan the xml info from a folder --- YACReaderLibrary/library_window.cpp | 39 +++++++++++++++++++++++- YACReaderLibrary/library_window.h | 3 ++ shortcuts_management/shortcuts_manager.h | 1 + 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index 8a905c94..2ce6ab4e 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -394,7 +394,8 @@ void LibraryWindow::setUpShortcutsManagement() << setFolderAsUnreadAction << setFolderAsMangaAction << setFolderAsNormalAction - << updateCurrentFolderAction); + << updateCurrentFolderAction + << rescanXMLFromCurrentFolderAction); allActions << tmpList; editShortcutsDialog->addActionsGroup("Lists", QIcon(":/images/shortcuts_group_folders.svg"), // TODO change icon @@ -795,6 +796,10 @@ void LibraryWindow::createActions() updateCurrentFolderAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(UPDATE_CURRENT_FOLDER_ACTION_YL)); updateCurrentFolderAction->setIcon(QIcon(":/images/menus_icons/update_current_folder.svg")); + rescanXMLFromCurrentFolderAction = new QAction(tr("Scan legacy XML metadata"), this); + rescanXMLFromCurrentFolderAction->setData(SCAN_XML_FROM_CURRENT_FOLDER_ACTION_YL); + rescanXMLFromCurrentFolderAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SCAN_XML_FROM_CURRENT_FOLDER_ACTION_YL)); + addReadingListAction = new QAction(tr("Add new reading list"), this); addReadingListAction->setData(ADD_READING_LIST_ACTION_YL); addReadingListAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(ADD_READING_LIST_ACTION_YL)); @@ -840,6 +845,7 @@ void LibraryWindow::createActions() this->addAction(setFolderAsMangaAction); this->addAction(setFolderAsNormalAction); this->addAction(deleteMetadataAction); + this->addAction(rescanXMLFromCurrentFolderAction); #ifndef Q_OS_MAC this->addAction(toggleFullScreenAction); #endif @@ -905,6 +911,7 @@ void LibraryWindow::disableFoldersActions(bool disabled) openContainingFolderAction->setDisabled(disabled); updateFolderAction->setDisabled(disabled); + rescanXMLFromCurrentFolderAction->setDisabled(disabled); } void LibraryWindow::disableAllActions() @@ -1055,6 +1062,8 @@ void LibraryWindow::createMenus() folderMenu->addAction(openContainingFolderAction); folderMenu->addAction(updateFolderAction); folderMenu->addSeparator(); + folderMenu->addAction(rescanXMLFromCurrentFolderAction); + folderMenu->addSeparator(); folderMenu->addAction(setFolderAsNotCompletedAction); folderMenu->addAction(setFolderAsCompletedAction); folderMenu->addSeparator(); @@ -1235,6 +1244,8 @@ void LibraryWindow::createConnections() connect(updateCurrentFolderAction, &QAction::triggered, this, &LibraryWindow::updateCurrentFolder); connect(updateFolderAction, &QAction::triggered, this, &LibraryWindow::updateCurrentFolder); + connect(rescanXMLFromCurrentFolderAction, &QAction::triggered, this, &LibraryWindow::rescanCurrentFolderForXMLInfo); + // lists connect(addReadingListAction, &QAction::triggered, this, &LibraryWindow::addNewReadingList); connect(deleteReadingListAction, &QAction::triggered, this, &LibraryWindow::deleteSelectedReadingList); @@ -1808,6 +1819,8 @@ void LibraryWindow::showGridFoldersContextMenu(QPoint point, Folder folder) auto updateFolderAction = new QAction(tr("Update folder"), this); updateFolderAction->setIcon(QIcon(":/images/menus_icons/update_current_folder.svg")); + auto rescanLibraryForXMLInfoAction = new QAction(tr("Rescan library for XML info"), this); + auto setFolderAsNotCompletedAction = new QAction(); setFolderAsNotCompletedAction->setText(tr("Set as uncompleted")); @@ -1829,6 +1842,8 @@ void LibraryWindow::showGridFoldersContextMenu(QPoint point, Folder folder) menu.addAction(openContainingFolderAction); menu.addAction(updateFolderAction); menu.addSeparator(); + menu.addAction(rescanLibraryForXMLInfoAction); + menu.addSeparator(); if (folder.isCompleted()) menu.addAction(setFolderAsNotCompletedAction); else @@ -1852,6 +1867,9 @@ void LibraryWindow::showGridFoldersContextMenu(QPoint point, Folder folder) connect(updateFolderAction, &QAction::triggered, this, [=]() { updateFolder(foldersModel->getIndexFromFolder(folder)); }); + connect(rescanLibraryForXMLInfoAction, &QAction::triggered, this, [=]() { + rescanFolderForXMLInfo(foldersModel->getIndexFromFolder(folder)); + }); connect(setFolderAsNotCompletedAction, &QAction::triggered, this, [=]() { foldersModel->updateFolderCompletedStatus(QModelIndexList() << foldersModel->getIndexFromFolder(folder), false); subfolderModel->updateFolderCompletedStatus(QModelIndexList() << subfolderModel->getIndexFromFolder(folder), false); @@ -2237,6 +2255,23 @@ void LibraryWindow::rescanLibraryForXMLInfo() xmlInfoLibraryScanner->scanLibrary(path, path + "/.yacreaderlibrary"); } +void LibraryWindow::rescanCurrentFolderForXMLInfo() +{ + rescanFolderForXMLInfo(getCurrentFolderIndex()); +} + +void LibraryWindow::rescanFolderForXMLInfo(QModelIndex modelIndex) +{ + importWidget->setXMLScanLook(); + showImportingWidget(); + + QString currentLibrary = selectedLibrary->currentText(); + QString path = libraries.getPath(currentLibrary); + _lastAdded = currentLibrary; + + xmlInfoLibraryScanner->scanFolder(path, path + "/.yacreaderlibrary", QDir::cleanPath(currentPath() + foldersModel->getFolderPath(modelIndex)), modelIndex); +} + void LibraryWindow::cancelCreating() { stopLibraryCreator(); @@ -2821,6 +2856,8 @@ void LibraryWindow::showFoldersContextMenu(const QPoint &point) menu.addAction(openContainingFolderAction); menu.addAction(updateFolderAction); menu.addSeparator(); //------------------------------- + menu.addAction(rescanXMLFromCurrentFolderAction); + menu.addSeparator(); //------------------------------- if (isCompleted) menu.addAction(setFolderAsNotCompletedAction); else diff --git a/YACReaderLibrary/library_window.h b/YACReaderLibrary/library_window.h index e94bb79e..fc12dad1 100644 --- a/YACReaderLibrary/library_window.h +++ b/YACReaderLibrary/library_window.h @@ -230,6 +230,7 @@ public: QAction *updateFolderAction; QAction *updateCurrentFolderAction; + QAction *rescanXMLFromCurrentFolderAction; // reading lists actions QAction *addReadingListAction; @@ -346,6 +347,8 @@ public slots: void removeLibrary(); void renameLibrary(); void rescanLibraryForXMLInfo(); + void rescanCurrentFolderForXMLInfo(); + void rescanFolderForXMLInfo(QModelIndex modelIndex); void rename(QString newName); void cancelCreating(); void stopLibraryCreator(); diff --git a/shortcuts_management/shortcuts_manager.h b/shortcuts_management/shortcuts_manager.h index 25acf21e..58fca9a8 100644 --- a/shortcuts_management/shortcuts_manager.h +++ b/shortcuts_management/shortcuts_manager.h @@ -82,6 +82,7 @@ public: #define SHOW_EDIT_SHORTCUTS_ACTION_YL "SHOW_EDIT_SHORTCUTS_ACTION_YL" #define QUIT_ACTION_YL "QUIT_ACTION_YL" #define UPDATE_CURRENT_FOLDER_ACTION_YL "UPDATE_CURRENT_FOLDER_ACTION_YL" +#define SCAN_XML_FROM_CURRENT_FOLDER_ACTION_YL "SCAN_XML_FROM_CURRENT_FOLDER_ACTION_YL" #define ADD_FOLDER_ACTION_YL "ADD_FOLDER_ACTION_YL" #define REMOVE_FOLDER_ACTION_YL "REMOVE_FOLDER_ACTION_YL" #define ADD_READING_LIST_ACTION_YL "ADD_READING_LIST_ACTION_YL"