Run the library upgrade in background.

This commit is contained in:
Luis Ángel San Martín 2018-03-12 21:22:00 +01:00
parent d7c633cf3f
commit 049081960f
2 changed files with 51 additions and 22 deletions

View File

@ -22,6 +22,8 @@
#include <iterator>
#include <typeinfo>
#include <thread>
#include <future>
#include "data_base_management.h"
#include "yacreader_global.h"
@ -1113,6 +1115,15 @@ void LibraryWindow::createConnections()
//save covers
connect(saveCoversToAction,SIGNAL(triggered()),this,SLOT(saveSelectedCoversTo()));
//upgrade library
connect(this, SIGNAL(libraryUpgraded(QString)), this, SLOT(loadLibrary(QString)), Qt::QueuedConnection);
connect(this, SIGNAL(errorUpgradingLibrary(QString)), this, SLOT(showErrorUpgradingLibrary(QString)), Qt::QueuedConnection);
}
void LibraryWindow::showErrorUpgradingLibrary(const QString & path)
{
QMessageBox::critical(this,tr("Upgrade failed"), tr("There were errors during library upgrade in: ") + path+"/library.ydb");
}
void LibraryWindow::loadLibrary(const QString & name)
@ -1128,29 +1139,39 @@ void LibraryWindow::loadLibrary(const QString & name)
if(d.exists(path) && d.exists(path+"/library.ydb") && (dbVersion = DataBaseManagement::checkValidDB(path+"/library.ydb")) != "") //si existe en disco la biblioteca seleccionada, y es válida..
{
int comparation = DataBaseManagement::compareVersions(dbVersion,VERSION);
bool updated = false;
if(comparation < 0)
{
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);
if(ret == QMessageBox::Yes)
{
updated = DataBaseManagement::updateToCurrentVersion(path+"/library.ydb");
if(!updated)
QMessageBox::critical(this,tr("Update failed"), tr("The current library can't be udpated. Check for write write permissions on: ") + path+"/library.ydb");
}
else
{
comicsViewsManager->comicsView->setModel(NULL);
foldersView->setModel(NULL);
listsView->setModel(NULL);
disableAllActions();//TODO comprobar que se deben deshabilitar
//será possible renombrar y borrar estas bibliotecas
renameLibraryAction->setEnabled(true);
removeLibraryAction->setEnabled(true);
}
}
if(comparation == 0 || updated) //en caso de que la versión se igual que la actual
if(comparation < 0)
{
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);
if(ret == QMessageBox::Yes)
{
importWidget->setUpgradeLook();
showImportingWidget();
upgradeLibraryFuture = std::async(std::launch::async, [this, name, path] {
bool updated = DataBaseManagement::updateToCurrentVersion(path);
if(!updated)
emit errorUpgradingLibrary(path);
emit libraryUpgraded(name);
});
return;
}
else
{
comicsViewsManager->comicsView->setModel(NULL);
foldersView->setModel(NULL);
listsView->setModel(NULL);
disableAllActions();//TODO comprobar que se deben deshabilitar
//será possible renombrar y borrar estas bibliotecas
renameLibraryAction->setEnabled(true);
removeLibraryAction->setEnabled(true);
}
}
if(comparation == 0) //en caso de que la versión se igual que la actual
{
foldersModel->setupModelData(path);
foldersModelProxy->setSourceModel(foldersModel);

View File

@ -10,6 +10,8 @@
#include "yacreader_navigation_controller.h"
#include <future>
#ifdef Q_OS_MAC
#include "yacreader_macosx_toolbar.h"
#endif
@ -284,6 +286,9 @@ protected:
public:
LibraryWindow();
signals:
void libraryUpgraded(const QString & libraryName);
void errorUpgradingLibrary(const QString & path);
public slots:
void loadLibrary(const QString & path);
void selectSubfolder(const QModelIndex & mi, int child);
@ -376,12 +381,15 @@ public slots:
void setToolbarTitle(const QModelIndex & modelIndex);
void saveSelectedCoversTo();
void checkMaxNumLibraries();
void showErrorUpgradingLibrary(const QString & path);
private:
//fullscreen mode in Windows for preventing this bug: QTBUG-41309 https://bugreports.qt.io/browse/QTBUG-41309
Qt::WindowFlags previousWindowFlags;
QPoint previousPos;
QSize previousSize;
std::future<void> upgradeLibraryFuture;
};
#endif