MCPcopy Create free account
hub / github.com/YACReader/yacreader / loadLibrary

Method loadLibrary

YACReaderLibrary/library_window.cpp:848–992  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

846}
847
848void LibraryWindow::loadLibrary(const QString &name)
849{
850 if (!libraries.isEmpty()) // si hay bibliotecas...
851 {
852 historyController->clear();
853
854 showRootWidget();
855 QString rootPath = libraries.getPath(name);
856 QString path = LibraryPaths::libraryDataPath(rootPath);
857 QString customFolderCoversPath = LibraryPaths::libraryCustomFoldersCoverPath(rootPath);
858 QString databasePath = LibraryPaths::libraryDatabasePath(rootPath);
859 QDir d; // TODO change this by static methods (utils class?? with delTree for example)
860 QString dbVersion;
861 if (d.exists(path) && d.exists(databasePath) && (dbVersion = DataBaseManagement::checkValidDB(databasePath)) != "") // si existe en disco la biblioteca seleccionada, y es válida..
862 {
863 // this folde was added in 9.16, it needs to exist before the user starts importing custom covers for folders
864 d.mkdir(customFolderCoversPath);
865
866 int comparation = DataBaseManagement::compareVersions(dbVersion, DB_VERSION);
867
868 if (comparation < 0) {
869 int ret = QMessageBox::question(this, tr("Update needed"), tr("This library was created with a previous version of YACReaderLibrary. It needs to be updated. Update now?"), QMessageBox::Yes, QMessageBox::No);
870 if (ret == QMessageBox::Yes) {
871 importWidget->setUpgradeLook();
872 showImportingWidget();
873
874 upgradeLibraryFuture = std::async(std::launch::async, [this, name, path, rootPath] {
875 bool updated = DataBaseManagement::updateToCurrentVersion(rootPath);
876
877 if (!updated)
878 emit errorUpgradingLibrary(path);
879
880 emit libraryUpgraded(name);
881 });
882
883 return;
884 } else {
885 contentViewsManager->comicsView->setModel(NULL);
886 foldersView->setModel(NULL);
887 listsView->setModel(NULL);
888 actions.disableAllActions(); // TODO comprobar que se deben deshabilitar
889 // será possible renombrar y borrar estas bibliotecas
890 actions.renameLibraryAction->setEnabled(true);
891 actions.removeLibraryAction->setEnabled(true);
892 }
893 }
894
895 if (comparation == 0) // en caso de que la versión se igual que la actual
896 {
897 foldersModel->setupModelData(path);
898 foldersModelProxy->setSourceModel(foldersModel);
899 foldersView->setModel(foldersModelProxy);
900 foldersView->setCurrentIndex(QModelIndex()); // why is this necesary?? by default it seems that returns an arbitrary index.
901
902 listsModel->setupReadingListsData(path);
903 listsModelProxy->setSourceModel(listsModel);
904 listsView->setModel(listsModelProxy);
905

Callers

nothing calls this directly

Calls 15

isEmptyMethod · 0.80
getPathMethod · 0.80
setUpgradeLookMethod · 0.80
disableAllActionsMethod · 0.80
setupModelDataMethod · 0.80
setupReadingListsDataMethod · 0.80
disableFoldersActionsMethod · 0.80
setFilterMethod · 0.80
currentTextMethod · 0.80
setDataAndStartMethod · 0.80
QModelIndexClass · 0.50

Tested by

no test coverage detected