новые иконки в 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

81 lines
3.4 KiB

14 years ago
#include "UniboardSankoreTransition.h"
#include "core/UBSettings.h"
#include "frameworks/UBDesktopServices.h"
#include "frameworks/UBFileSystemUtils.h"
#include "core/UBApplication.h"
14 years ago
UniboardSankoreTransition::UniboardSankoreTransition(QObject *parent) :
QObject(parent)
{
mUniboardSourceDirectory = UBFileSystemUtils::normalizeFilePath(UBDesktopServices::storageLocation(QDesktopServices::DataLocation));
mUniboardSourceDirectory.replace("Sankore/Sankore 3.1", "Mnemis/Uniboard");
14 years ago
}
UniboardSankoreTransition::~UniboardSankoreTransition()
14 years ago
{
delete mTransitionDlg;
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()){
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);
14 years ago
QString uniboardDocumentDirectory = mUniboardSourceDirectory + "/document";
14 years ago
QFileInfoList fileInfoList = UBFileSystemUtils::allElementsInDirectory(uniboardDocumentDirectory);
QFileInfoList::iterator fileInfo;
QString sankoreDocumentDirectory = UBSettings::uniboardDocumentDirectory();
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);
}
}
if (!result){
qWarning() << "The transaction has failed";
14 years ago
rollbackDocumentsTransition(fileInfoList);
UBFileSystemUtils::deleteDir(backupDestinationPath);
14 years ago
}
else {
UBFileSystemUtils::deleteDir(mUniboardSourceDirectory);
}
emit transitionFinished(result);
mTransitionDlg->hide();
14 years ago
}