новые иконки в OpenBoard
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OpenBoard/src/transition/UniboardSankoreTransition.cpp

102 lines
4.2 KiB

14 years ago
#include "UniboardSankoreTransition.h"
#include "core/UBSettings.h"
#include "frameworks/UBDesktopServices.h"
#include "frameworks/UBFileSystemUtils.h"
#include "core/UBApplication.h"
#include "core/UBPersistenceManager.h"
14 years ago
UniboardSankoreTransition::UniboardSankoreTransition(QObject *parent) :
QObject(parent)
, mTransitionDlg(NULL)
14 years ago
{
// mOldSankoreDirectory = UBFileSystemUtils::normalizeFilePath(UBDesktopServices::storageLocation(QDesktopServices::DataLocation));
// mUniboardSourceDirectory = UBFileSystemUtils::normalizeFilePath(UBDesktopServices::storageLocation(QDesktopServices::DataLocation));
//#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*)));
14 years ago
}
UniboardSankoreTransition::~UniboardSankoreTransition()
14 years ago
{
if(NULL != mTransitionDlg)
{
delete mTransitionDlg;
mTransitionDlg = NULL;
}
14 years ago
}
void UniboardSankoreTransition::rollbackDocumentsTransition(QFileInfoList& fileInfoList)
{
QFileInfoList::iterator fileInfo;
for (fileInfo = fileInfoList.begin(); fileInfo != fileInfoList.end(); fileInfo += 1) {
if (fileInfo->isDir() && fileInfo->fileName().startsWith("Uniboard Document ")){
QString sankoreDocumentName = fileInfo->fileName();
sankoreDocumentName.replace("Uniboard","Sankore");
QString sankoreDocumentDirectoryPath = UBSettings::uniboardDocumentDirectory() + "/" + sankoreDocumentName;
if (QFileInfo(sankoreDocumentDirectoryPath).exists()){
UBFileSystemUtils::deleteDir(sankoreDocumentDirectoryPath);
}
}
}
}
void UniboardSankoreTransition::documentTransition()
{
if (QFileInfo(mUniboardSourceDirectory).exists() || QFileInfo(mOldSankoreDirectory).exists()){
QString uniboardDocumentDirectory = mUniboardSourceDirectory + "/document";
QFileInfoList fileInfoList = UBFileSystemUtils::allElementsInDirectory(uniboardDocumentDirectory);
fileInfoList << UBFileSystemUtils::allElementsInDirectory(mOldSankoreDirectory + "/document");
QString backupDirectoryPath = UBFileSystemUtils::normalizeFilePath(UBDesktopServices::storageLocation(QDesktopServices::DesktopLocation));
if (fileInfoList.count() != 0){
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);
14 years ago
QString uniboardDocumentDirectory = mUniboardSourceDirectory + "/document";
14 years ago
QFileInfoList fileInfoList = UBFileSystemUtils::allElementsInDirectory(uniboardDocumentDirectory);
QFileInfoList::iterator fileInfo;
QString sankoreDocumentDirectory = UBSettings::uniboardDocumentDirectory();
QStringList qslNewDocs;
14 years ago
for (fileInfo = fileInfoList.begin(); fileInfo != fileInfoList.end() && result; fileInfo += 1) {
if (fileInfo->isDir() && fileInfo->fileName().startsWith("Uniboard Document ")){
QString sankoreDocumentName = fileInfo->fileName();
sankoreDocumentName.replace("Uniboard","Sankore");
result = UBFileSystemUtils::copyDir(fileInfo->filePath(),sankoreDocumentDirectory + "/" + sankoreDocumentName);
qslNewDocs << sankoreDocumentName;
14 years ago
}
}
if (!result){
qWarning() << "The transaction has failed";
14 years ago
rollbackDocumentsTransition(fileInfoList);
UBFileSystemUtils::deleteDir(backupDestinationPath);
14 years ago
}
else{
UBFileSystemUtils::deleteDir(mOldSankoreDirectory);
14 years ago
UBFileSystemUtils::deleteDir(mUniboardSourceDirectory);
}
emit transitionFinished(result);
mTransitionDlg->hide();
}