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

99 lines
4.0 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)
{
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
{
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();
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
{
14 years ago
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);
// }
14 years ago
}
emit transitionFinished(result);
mTransitionDlg->hide();
}