diff --git a/YACReaderLibrary/create_library_dialog.cpp b/YACReaderLibrary/create_library_dialog.cpp index 25fae77d..4a608590 100644 --- a/YACReaderLibrary/create_library_dialog.cpp +++ b/YACReaderLibrary/create_library_dialog.cpp @@ -128,6 +128,14 @@ void CreateLibraryDialog::close() accept->setEnabled(true); QDialog::close(); } + +void CreateLibraryDialog::setDataAndStart(QString name, QString path) +{ + this->path->setText(path); + this->nameEdit->setText(name); + show(); + create(); +} //----------------------------------------------------------------------------- // UpdateLibraryDialog //----------------------------------------------------------------------------- diff --git a/YACReaderLibrary/create_library_dialog.h b/YACReaderLibrary/create_library_dialog.h index f545d4e1..a671fcce 100644 --- a/YACReaderLibrary/create_library_dialog.h +++ b/YACReaderLibrary/create_library_dialog.h @@ -30,6 +30,7 @@ void findPath(); void showCurrentFile(QString file); void close(); + void setDataAndStart(QString name, QString paht); signals: void createLibrary(QString source, QString target, QString name); void cancelCreate(); diff --git a/YACReaderLibrary/db/data_base_management.cpp b/YACReaderLibrary/db/data_base_management.cpp index b8e31492..8d9d1aa2 100644 --- a/YACReaderLibrary/db/data_base_management.cpp +++ b/YACReaderLibrary/db/data_base_management.cpp @@ -494,14 +494,24 @@ QString DataBaseManagement::checkValidDB(const QString & fullPath) version.exec(); if(version.next()) { + db.close(); + QSqlDatabase::removeDatabase(fullPath); return version.record().value("version").toString(); } else + { + db.close(); + QSqlDatabase::removeDatabase(fullPath); return ""; + } } else - return ""; + { + db.close(); + QSqlDatabase::removeDatabase(fullPath); + return ""; + } } int DataBaseManagement::compareVersions(const QString & v1, const QString v2) diff --git a/YACReaderLibrary/library_creator.cpp b/YACReaderLibrary/library_creator.cpp index aaed401d..8a4e1d88 100644 --- a/YACReaderLibrary/library_creator.cpp +++ b/YACReaderLibrary/library_creator.cpp @@ -41,8 +41,13 @@ void LibraryCreator::processLibrary(const QString & source, const QString & targ { _source = source; _target = target; - if(!(QFile(target+"/library.ydb").exists())) //TODO, no sirve sólo con realizar el update, hay que validar la base de datos y determinar si existe "/covers" + //if(!(QFile(target+"/library.ydb").exists())) //TODO, no sirve sólo con realizar el update, hay que validar la base de datos y determinar si existe "/covers" + if(DataBaseManagement::checkValidDB(target+"/library.ydb")=="") + { + //se limpia el directorio ./yacreaderlibrary + delTree(target); _mode = CREATOR; + } else _mode = UPDATER; } diff --git a/YACReaderLibrary/library_window.cpp b/YACReaderLibrary/library_window.cpp index 3be7c61b..aa1e1991 100644 --- a/YACReaderLibrary/library_window.cpp +++ b/YACReaderLibrary/library_window.cpp @@ -600,43 +600,43 @@ void LibraryWindow::createConnections() void LibraryWindow::loadLibrary(const QString & name) { - if(libraries.size()>0) + if(libraries.size()>0) //si hay bibliotecas... { QString path=libraries.value(name)+"/.yacreaderlibrary"; QDir d; //TODO change this by static methods (utils class?? with delTree for example) QString dbVersion; - if(d.exists(path) && (dbVersion = DataBaseManagement::checkValidDB(path+"/library.ydb")) != "") + if(d.exists(path) && (dbVersion = DataBaseManagement::checkValidDB(path+"/library.ydb")) != "") //si existe en disco la biblioteca seleccionada, y es válida.. { int comparation; - if((comparation = DataBaseManagement::compareVersions(dbVersion,VERSION)) == 0) + if((comparation = DataBaseManagement::compareVersions(dbVersion,VERSION)) == 0) //en caso de que la versión se igual que la actual { - index = 0; - sm->clear(); - //foldersView->setModel(NULL); //TODO comprobar pq no sirve con usar simplemente las señales beforeReset y reset - //comicView->setModel(NULL); + index = 0; + sm->clear(); + //foldersView->setModel(NULL); //TODO comprobar pq no sirve con usar simplemente las señales beforeReset y reset + //comicView->setModel(NULL); - dm->setupModelData(path); - foldersView->setModel(dm); - - d.setCurrent(libraries.value(name)); - d.setFilter(QDir::AllDirs | QDir::Files | QDir::Hidden | QDir::NoSymLinks | QDir::NoDotAndDotDot); - if(d.count()<=1) //librería de sólo lectura - { - //QMessageBox::critical(NULL,QString::number(d.count()),QString::number(d.count())); - disableActions(); - importedCovers = true; - } - else //librería normal abierta - { - enableActions(); - importedCovers = false; - } - enableLibraryActions(); + dm->setupModelData(path); + foldersView->setModel(dm); - loadCovers(QModelIndex()); + d.setCurrent(libraries.value(name)); + d.setFilter(QDir::AllDirs | QDir::Files | QDir::Hidden | QDir::NoSymLinks | QDir::NoDotAndDotDot); + if(d.count()<=1) //librería de sólo lectura + { + //QMessageBox::critical(NULL,QString::number(d.count()),QString::number(d.count())); + disableActions(); + importedCovers = true; + } + else //librería normal abierta + { + enableActions(); + importedCovers = false; + } + enableLibraryActions(); - //includeComicsCheckBox->setCheckState(Qt::Unchecked); - foldersFilter->clear(); + loadCovers(QModelIndex()); + + //includeComicsCheckBox->setCheckState(Qt::Unchecked); + foldersFilter->clear(); } else { @@ -675,14 +675,31 @@ void LibraryWindow::loadLibrary(const QString & name) comicFlow->clear(); disableAllActions();//TODO comprobar que se deben deshabilitar - QString currentLibrary = selectedLibrary->currentText(); - if(QMessageBox::question(this,tr("Library not available"),tr("Library ")+currentLibrary+tr(" is no longer available. Do you want to remove it?"),QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes) + //si la librería no existe en disco, se ofrece al usuario la posibiliad de eliminarla + if(!d.exists(path)) { - deleteCurrentLibrary(); + QString currentLibrary = selectedLibrary->currentText(); + if(QMessageBox::question(this,tr("Library not available"),tr("Library ")+currentLibrary+tr(" is no longer available. Do you want to remove it?"),QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes) + { + deleteCurrentLibrary(); + } + } + else//si existe el path, puede ser que la librería sea alguna versión pre-5.0 ó que esté corrupta + { + QString currentLibrary = selectedLibrary->currentText(); + QString path = libraries.value(selectedLibrary->currentText()); + if(QMessageBox::question(this,tr("Old library or corrupted"),tr("Library ")+currentLibrary+tr(" is corrupted or has been created with an older version of YACReaderLibrary. It must be created again. Do you want to create the library now?"),QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes) + { + QDir d(path+"/.yacreaderlibrary"); + delTree(d); + d.rmdir(path+"/.yacreaderlibrary"); + createLibraryDialog->setDataAndStart(currentLibrary,path); + //create(path,path+"/.yacreaderlibrary",currentLibrary); + } } } } - else + else //en caso de que no exista ninguna biblioteca se desactivan los botones pertinentes { disableAllActions(); }