mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
Run the library upgrade in background.
This commit is contained in:
parent
d7c633cf3f
commit
049081960f
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
|
#include <thread>
|
||||||
|
#include <future>
|
||||||
|
|
||||||
#include "data_base_management.h"
|
#include "data_base_management.h"
|
||||||
#include "yacreader_global.h"
|
#include "yacreader_global.h"
|
||||||
@ -1113,6 +1115,15 @@ void LibraryWindow::createConnections()
|
|||||||
|
|
||||||
//save covers
|
//save covers
|
||||||
connect(saveCoversToAction,SIGNAL(triggered()),this,SLOT(saveSelectedCoversTo()));
|
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)
|
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..
|
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);
|
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);
|
foldersModel->setupModelData(path);
|
||||||
foldersModelProxy->setSourceModel(foldersModel);
|
foldersModelProxy->setSourceModel(foldersModel);
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
#include "yacreader_navigation_controller.h"
|
#include "yacreader_navigation_controller.h"
|
||||||
|
|
||||||
|
#include <future>
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
#include "yacreader_macosx_toolbar.h"
|
#include "yacreader_macosx_toolbar.h"
|
||||||
#endif
|
#endif
|
||||||
@ -284,6 +286,9 @@ protected:
|
|||||||
public:
|
public:
|
||||||
LibraryWindow();
|
LibraryWindow();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void libraryUpgraded(const QString & libraryName);
|
||||||
|
void errorUpgradingLibrary(const QString & path);
|
||||||
public slots:
|
public slots:
|
||||||
void loadLibrary(const QString & path);
|
void loadLibrary(const QString & path);
|
||||||
void selectSubfolder(const QModelIndex & mi, int child);
|
void selectSubfolder(const QModelIndex & mi, int child);
|
||||||
@ -376,12 +381,15 @@ public slots:
|
|||||||
void setToolbarTitle(const QModelIndex & modelIndex);
|
void setToolbarTitle(const QModelIndex & modelIndex);
|
||||||
void saveSelectedCoversTo();
|
void saveSelectedCoversTo();
|
||||||
void checkMaxNumLibraries();
|
void checkMaxNumLibraries();
|
||||||
|
void showErrorUpgradingLibrary(const QString & path);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//fullscreen mode in Windows for preventing this bug: QTBUG-41309 https://bugreports.qt.io/browse/QTBUG-41309
|
//fullscreen mode in Windows for preventing this bug: QTBUG-41309 https://bugreports.qt.io/browse/QTBUG-41309
|
||||||
Qt::WindowFlags previousWindowFlags;
|
Qt::WindowFlags previousWindowFlags;
|
||||||
QPoint previousPos;
|
QPoint previousPos;
|
||||||
QSize previousSize;
|
QSize previousSize;
|
||||||
|
|
||||||
|
std::future<void> upgradeLibraryFuture;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user