From 1c9f2133f653079637c8e28b9a18461f78f590e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Tue, 26 Nov 2024 17:44:24 +0100 Subject: [PATCH] Add a small dialog to show some info about a library --- CHANGELOG.md | 1 + YACReaderLibrary/db_helper.cpp | 36 +++++++++++++++++++++ YACReaderLibrary/db_helper.h | 3 ++ YACReaderLibrary/library_window.cpp | 24 ++++++++++++++ YACReaderLibrary/library_window.h | 1 + YACReaderLibrary/library_window_actions.cpp | 10 +++++- YACReaderLibrary/library_window_actions.h | 3 ++ YACReaderLibrary/yacreader_libraries.cpp | 12 +++++++ YACReaderLibrary/yacreader_libraries.h | 2 ++ shortcuts_management/shortcuts_manager.h | 1 + 10 files changed, 92 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5daa8403..97214fd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ Version counting is based on semantic versioning (Major.Feature.Patch) * Fix crash when current folders is empty after an update. * Enable dropping content on the FolderContentView. * Fix `open containing folder...` shortcut for comics. +* Add a dialog to show information about a library, it includes the number of folders and comics and the number of read comics. ### YACReaderLibraryServer * New command --system-info to print information about the execution environment and available resources (including what image formats are supported and what libraries are used by the app). diff --git a/YACReaderLibrary/db_helper.cpp b/YACReaderLibrary/db_helper.cpp index 04c1add9..32040272 100644 --- a/YACReaderLibrary/db_helper.cpp +++ b/YACReaderLibrary/db_helper.cpp @@ -2022,3 +2022,39 @@ bool DBHelper::isFavoriteComic(qulonglong id, QSqlDatabase &db) return false; } + +QString DBHelper::getLibraryInfo(QUuid id) +{ + QString info; + QString libraryPath = DBHelper::getLibraries().getPath(id); + + info = "Library path:
" + libraryPath + "

"; + + QString connectionName = ""; + QList list; + { + QSqlDatabase db = DataBaseManagement::loadDatabase(libraryPath + "/.yacreaderlibrary"); + connectionName = db.connectionName(); + + // num folders + auto foldersQuery = db.exec("SELECT COUNT(*) FROM folder WHERE id <> 1"); + foldersQuery.next(); + + info += "Number of folders:
" + foldersQuery.value(0).toString() + "

"; + + // num comics + auto comicsQuery = db.exec("SELECT COUNT(*) FROM comic"); + comicsQuery.next(); + + info += "Number of comics:
" + comicsQuery.value(0).toString() + "

"; + + // num read comics + auto readComicsQuery = db.exec("SELECT count(*) FROM comic c INNER JOIN comic_info ci ON c.comicInfoId = ci.id WHERE ci.read = 1"); + readComicsQuery.next(); + + info += "Number of read comics:
" + readComicsQuery.value(0).toString() + "

"; + } + QSqlDatabase::removeDatabase(connectionName); + + return info; +} diff --git a/YACReaderLibrary/db_helper.h b/YACReaderLibrary/db_helper.h index 699bc59a..d298bc42 100644 --- a/YACReaderLibrary/db_helper.h +++ b/YACReaderLibrary/db_helper.h @@ -104,6 +104,9 @@ public: static QList loadSubfoldersNames(qulonglong folderId, QSqlDatabase &db); // queries static bool isFavoriteComic(qulonglong id, QSqlDatabase &db); + + // library + static QString getLibraryInfo(QUuid id); }; #endif diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index 756facb5..e71d36b1 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -619,6 +619,9 @@ void LibraryWindow::createMenus() selectedLibrary->addAction(actions.exportLibraryAction); selectedLibrary->addAction(actions.importLibraryAction); + YACReader::addSperator(selectedLibrary); + + selectedLibrary->addAction(actions.showLibraryInfo); // MacOSX app menus #ifdef Q_OS_MACOS @@ -648,6 +651,10 @@ void LibraryWindow::createMenus() libraryMenu->addAction(actions.exportLibraryAction); libraryMenu->addAction(actions.importLibraryAction); + libraryMenu->addSeparator(); + + libraryMenu->addAction(actions.showLibraryInfo); + // folder QMenu *folderMenu = new QMenu(tr("Folder")); folderMenu->addAction(actions.openContainingFolderAction); @@ -1894,6 +1901,23 @@ void LibraryWindow::rescanLibraryForXMLInfo() xmlInfoLibraryScanner->scanLibrary(path, path + "/.yacreaderlibrary"); } +void LibraryWindow::showLibraryInfo() +{ + auto id = libraries.getUuid(selectedLibrary->currentText()); + auto info = DBHelper::getLibraryInfo(id); + + // TODO: use something nicer than a QMessageBox + QMessageBox msgBox; + msgBox.setWindowTitle(tr("Library info")); + msgBox.setText(info); + QSpacerItem *horizontalSpacer = new QSpacerItem(420, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); + QGridLayout *layout = (QGridLayout *)msgBox.layout(); + layout->addItem(horizontalSpacer, layout->rowCount(), 0, 1, layout->columnCount()); + msgBox.setStandardButtons(QMessageBox::Close); + msgBox.setDefaultButton(QMessageBox::Close); + msgBox.exec(); +} + void LibraryWindow::rescanCurrentFolderForXMLInfo() { rescanFolderForXMLInfo(getCurrentFolderIndex()); diff --git a/YACReaderLibrary/library_window.h b/YACReaderLibrary/library_window.h index c6255649..72c71e1a 100644 --- a/YACReaderLibrary/library_window.h +++ b/YACReaderLibrary/library_window.h @@ -251,6 +251,7 @@ public slots: void removeLibrary(); void renameLibrary(); void rescanLibraryForXMLInfo(); + void showLibraryInfo(); void rescanCurrentFolderForXMLInfo(); void rescanFolderForXMLInfo(QModelIndex modelIndex); void rename(QString newName); diff --git a/YACReaderLibrary/library_window_actions.cpp b/YACReaderLibrary/library_window_actions.cpp index b8e2cccf..1f596677 100644 --- a/YACReaderLibrary/library_window_actions.cpp +++ b/YACReaderLibrary/library_window_actions.cpp @@ -101,6 +101,11 @@ void LibraryWindowActions::createActions(LibraryWindow *window, QSettings *setti rescanLibraryForXMLInfoAction->setData(RESCAN_LIBRARY_XML_INFO_ACTION_YL); rescanLibraryForXMLInfoAction->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(RESCAN_LIBRARY_XML_INFO_ACTION_YL)); + showLibraryInfo = new QAction(tr("Show library info"), window); + showLibraryInfo->setToolTip(tr("Show information about the current library")); + showLibraryInfo->setData(SHOW_LIBRARY_INFO_ACTION_YL); + showLibraryInfo->setShortcut(ShortcutsManager::getShortcutsManager().getShortcut(SHOW_LIBRARY_INFO_ACTION_YL)); + openComicAction = new QAction(tr("Open current comic"), window); openComicAction->setToolTip(tr("Open current comic on YACReader")); openComicAction->setData(OPEN_COMIC_ACTION_YL); @@ -559,6 +564,8 @@ void LibraryWindowActions::createConnections( // connect(deleteLibraryAction,SIGNAL(triggered()),window,SLOT(deleteLibrary())); QObject::connect(removeLibraryAction, &QAction::triggered, window, &LibraryWindow::removeLibrary); QObject::connect(rescanLibraryForXMLInfoAction, &QAction::triggered, window, &LibraryWindow::rescanLibraryForXMLInfo); + QObject::connect(showLibraryInfo, &QAction::triggered, window, &LibraryWindow::showLibraryInfo); + QObject::connect(openComicAction, &QAction::triggered, window, QOverload<>::of(&LibraryWindow::openComic)); QObject::connect(helpAboutAction, &QAction::triggered, had, &QWidget::show); QObject::connect(addFolderAction, &QAction::triggered, window, &LibraryWindow::addFolderToCurrentIndex); @@ -659,7 +666,8 @@ void LibraryWindowActions::setUpShortcutsManagement(EditShortcutsDialog *editSho << updateLibraryAction << renameLibraryAction << removeLibraryAction - << rescanLibraryForXMLInfoAction); + << rescanLibraryForXMLInfoAction + << showLibraryInfo); allActions << tmpList; diff --git a/YACReaderLibrary/library_window_actions.h b/YACReaderLibrary/library_window_actions.h index 6dab5add..e2efb18b 100644 --- a/YACReaderLibrary/library_window_actions.h +++ b/YACReaderLibrary/library_window_actions.h @@ -39,6 +39,9 @@ public: QAction *removeLibraryAction; QAction *helpAboutAction; QAction *renameLibraryAction; + + QAction *showLibraryInfo; + #ifndef Q_OS_MACOS QAction *toggleFullScreenAction; #endif diff --git a/YACReaderLibrary/yacreader_libraries.cpp b/YACReaderLibrary/yacreader_libraries.cpp index d21387f7..4e3f13f6 100644 --- a/YACReaderLibrary/yacreader_libraries.cpp +++ b/YACReaderLibrary/yacreader_libraries.cpp @@ -54,6 +54,12 @@ QString YACReaderLibraries::getPath(int id) return library != libraries.cend() ? library->getPath() : ""; } +QString YACReaderLibraries::getPath(const QUuid &id) +{ + auto library = std::find_if(libraries.cbegin(), libraries.cend(), [id](const YACReaderLibrary &library) { return library.getId() == id; }); + return library != libraries.cend() ? library->getPath() : ""; +} + QString YACReaderLibraries::getDBPath(int id) { return getPath(id) + "/.yacreaderlibrary"; @@ -101,6 +107,12 @@ int YACReaderLibraries::getId(const QString &name) return library != libraries.cend() ? library->getLegacyId() : -1; } +QUuid YACReaderLibraries::getUuid(const QString &name) +{ + auto library = std::find_if(libraries.cbegin(), libraries.cend(), [name](const YACReaderLibrary &library) { return library.getName() == name; }); + return library != libraries.cend() ? library->getId() : QUuid(); +} + int YACReaderLibraries::getIdFromUuid(const QUuid &uuid) { auto library = std::find_if(libraries.cbegin(), libraries.cend(), [uuid](const YACReaderLibrary &library) { return library.getId() == uuid; }); diff --git a/YACReaderLibrary/yacreader_libraries.h b/YACReaderLibrary/yacreader_libraries.h index 0d0bee0a..e7e8c86d 100644 --- a/YACReaderLibrary/yacreader_libraries.h +++ b/YACReaderLibrary/yacreader_libraries.h @@ -15,6 +15,7 @@ public: QList getNames(); QString getPath(const QString &name); QString getPath(int id); + QString getPath(const QUuid &id); QString getDBPath(int id); QString getName(int id); bool isEmpty(); @@ -23,6 +24,7 @@ public: void remove(const QString &name); void rename(const QString &oldName, const QString &newName); int getId(const QString &name); + QUuid getUuid(const QString &name); int getIdFromUuid(const QUuid &uuid); YACReaderLibraries &operator=(const YACReaderLibraries &source); QList getLibraries() const; diff --git a/shortcuts_management/shortcuts_manager.h b/shortcuts_management/shortcuts_manager.h index ccf712cc..f511567e 100644 --- a/shortcuts_management/shortcuts_manager.h +++ b/shortcuts_management/shortcuts_manager.h @@ -46,6 +46,7 @@ public: #define RENAME_LIBRARY_ACTION_YL "RENAME_LIBRARY_ACTION_YL" #define REMOVE_LIBRARY_ACTION_YL "REMOVE_LIBRARY_ACTION_YL" #define RESCAN_LIBRARY_XML_INFO_ACTION_YL "RESCAN_LIBRARY_XML_INFO_ACTION_YL" +#define SHOW_LIBRARY_INFO_ACTION_YL "SHOW_LIBRARY_INFO_ACTION_YL" #define OPEN_COMIC_ACTION_YL "OPEN_COMIC_ACTION_YL" #define SET_AS_READ_ACTION_YL "SET_AS_READ_ACTION_YL" #define SET_AS_NON_READ_ACTION_YL "SET_AS_NON_READ_ACTION_YL"