|
|
@ -2,28 +2,25 @@ |
|
|
|
#include "core/UBSettings.h" |
|
|
|
#include "core/UBSettings.h" |
|
|
|
#include "frameworks/UBDesktopServices.h" |
|
|
|
#include "frameworks/UBDesktopServices.h" |
|
|
|
#include "frameworks/UBFileSystemUtils.h" |
|
|
|
#include "frameworks/UBFileSystemUtils.h" |
|
|
|
|
|
|
|
#include "core/UBApplication.h" |
|
|
|
|
|
|
|
#include "core/UBPersistenceManager.h" |
|
|
|
|
|
|
|
|
|
|
|
UniboardSankoreTransition::UniboardSankoreTransition(QObject *parent) : |
|
|
|
UniboardSankoreTransition::UniboardSankoreTransition(QObject *parent) : |
|
|
|
QObject(parent) |
|
|
|
QObject(parent) |
|
|
|
{ |
|
|
|
{ |
|
|
|
mUniboardSourceDirectory = UBDesktopServices::storageLocation(QDesktopServices::DataLocation); |
|
|
|
mUniboardSourceDirectory = UBFileSystemUtils::normalizeFilePath(UBDesktopServices::storageLocation(QDesktopServices::DataLocation)); |
|
|
|
mUniboardSourceDirectory.replace("Sankore", "Mnemis/Uniboard"); |
|
|
|
#if defined(Q_WS_MACX) |
|
|
|
|
|
|
|
mUniboardSourceDirectory.replace("Sankore/Sankore 3.1", "Uniboard"); |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
mUniboardSourceDirectory.replace("Sankore/Sankore 3.1", "Mnemis/Uniboard"); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
connect(this, SIGNAL(docAdded(UBDocumentProxy*)), UBPersistenceManager::persistenceManager(), SIGNAL(documentCreated(UBDocumentProxy*))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
UniboardSankoreTransition::~UniboardSankoreTransition() |
|
|
|
bool UniboardSankoreTransition::backupUniboardDirectory() |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
bool result = false; |
|
|
|
delete mTransitionDlg; |
|
|
|
QString destinationDirectory = UBDesktopServices::storageLocation(QDesktopServices::DesktopLocation); |
|
|
|
|
|
|
|
if(QFileInfo(destinationDirectory).exists() && QFileInfo(mUniboardSourceDirectory).exists()){ |
|
|
|
|
|
|
|
if(!destinationDirectory.endsWith("/")) destinationDirectory += "/"; |
|
|
|
|
|
|
|
result = UBFileSystemUtils::copyDir(mUniboardSourceDirectory, destinationDirectory + QFileInfo(mUniboardSourceDirectory).fileName() + "BackupData/"); |
|
|
|
|
|
|
|
if(result) documentTransition(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UniboardSankoreTransition::rollbackDocumentsTransition(QFileInfoList& fileInfoList) |
|
|
|
void UniboardSankoreTransition::rollbackDocumentsTransition(QFileInfoList& fileInfoList) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QFileInfoList::iterator fileInfo; |
|
|
|
QFileInfoList::iterator fileInfo; |
|
|
@ -41,26 +38,61 @@ void UniboardSankoreTransition::rollbackDocumentsTransition(QFileInfoList& fileI |
|
|
|
|
|
|
|
|
|
|
|
void UniboardSankoreTransition::documentTransition() |
|
|
|
void UniboardSankoreTransition::documentTransition() |
|
|
|
{ |
|
|
|
{ |
|
|
|
QString uniboardDocumentDirectory = mUniboardSourceDirectory + "/document"; |
|
|
|
if (QFileInfo(mUniboardSourceDirectory).exists()){ |
|
|
|
QString sankoreDocumentDirectory = UBSettings::uniboardDocumentDirectory(); |
|
|
|
QString uniboardDocumentDirectory = mUniboardSourceDirectory + "/document"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QFileInfoList fileInfoList = UBFileSystemUtils::allElementsInDirectory(uniboardDocumentDirectory); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString backupDirectoryPath = UBFileSystemUtils::normalizeFilePath(UBDesktopServices::storageLocation(QDesktopServices::DesktopLocation)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mTransitionDlg = new UBUpdateDlg(0, fileInfoList.count(), backupDirectoryPath); |
|
|
|
|
|
|
|
connect(mTransitionDlg, SIGNAL(updateFiles()), this, SLOT(startDocumentTransition())); |
|
|
|
|
|
|
|
connect(this, SIGNAL(transitionFinished(bool)), mTransitionDlg, SLOT(onFilesUpdated(bool))); |
|
|
|
|
|
|
|
mTransitionDlg->show(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UniboardSankoreTransition::startDocumentTransition() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
bool result = false; |
|
|
|
|
|
|
|
QString backupDestinationPath = mTransitionDlg->backupPath() + "/UniboardBackup"; |
|
|
|
|
|
|
|
result = UBFileSystemUtils::copyDir(mUniboardSourceDirectory, backupDestinationPath); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString uniboardDocumentDirectory = mUniboardSourceDirectory + "/document"; |
|
|
|
QFileInfoList fileInfoList = UBFileSystemUtils::allElementsInDirectory(uniboardDocumentDirectory); |
|
|
|
QFileInfoList fileInfoList = UBFileSystemUtils::allElementsInDirectory(uniboardDocumentDirectory); |
|
|
|
|
|
|
|
|
|
|
|
QFileInfoList::iterator fileInfo; |
|
|
|
QFileInfoList::iterator fileInfo; |
|
|
|
bool result = true; |
|
|
|
QString sankoreDocumentDirectory = UBSettings::uniboardDocumentDirectory(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QStringList qslNewDocs; |
|
|
|
|
|
|
|
|
|
|
|
for (fileInfo = fileInfoList.begin(); fileInfo != fileInfoList.end() && result; fileInfo += 1) { |
|
|
|
for (fileInfo = fileInfoList.begin(); fileInfo != fileInfoList.end() && result; fileInfo += 1) { |
|
|
|
if (fileInfo->isDir() && fileInfo->fileName().startsWith("Uniboard Document ")){ |
|
|
|
if (fileInfo->isDir() && fileInfo->fileName().startsWith("Uniboard Document ")){ |
|
|
|
QString sankoreDocumentName = fileInfo->fileName(); |
|
|
|
QString sankoreDocumentName = fileInfo->fileName(); |
|
|
|
sankoreDocumentName.replace("Uniboard","Sankore"); |
|
|
|
sankoreDocumentName.replace("Uniboard","Sankore"); |
|
|
|
result = UBFileSystemUtils::copyDir(fileInfo->filePath(),sankoreDocumentDirectory + "/" + sankoreDocumentName); |
|
|
|
result = UBFileSystemUtils::copyDir(fileInfo->filePath(),sankoreDocumentDirectory + "/" + sankoreDocumentName); |
|
|
|
|
|
|
|
qslNewDocs << sankoreDocumentName; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!result){ |
|
|
|
if (!result){ |
|
|
|
qWarning() << "The transaction has failed during the copy of the " + fileInfo->filePath() + " document."; |
|
|
|
qWarning() << "The transaction has failed"; |
|
|
|
rollbackDocumentsTransition(fileInfoList); |
|
|
|
rollbackDocumentsTransition(fileInfoList); |
|
|
|
|
|
|
|
UBFileSystemUtils::deleteDir(backupDestinationPath); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
UBFileSystemUtils::deleteDir(mUniboardSourceDirectory); |
|
|
|
UBFileSystemUtils::deleteDir(mUniboardSourceDirectory); |
|
|
|
|
|
|
|
// Notify the application that new documents have been added
|
|
|
|
|
|
|
|
// foreach(QString qstr, qslNewDocs)
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// UBDocumentProxy* pDoc = new UBDocumentProxy();
|
|
|
|
|
|
|
|
// pDoc->setMetaData(UBSettings::documentName, qstr);
|
|
|
|
|
|
|
|
// emit docAdded(pDoc);
|
|
|
|
|
|
|
|
// }
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
emit transitionFinished(result); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mTransitionDlg->hide(); |
|
|
|
} |
|
|
|
} |