Added uniboard sankore document directory transition

preferencesAboutTextFull
Claudio Valerio 14 years ago
parent 2d4d6bbc85
commit acac135700
  1. 6
      src/core/UBApplication.cpp
  2. 3
      src/core/UBApplication.h
  3. 2
      src/frameworks/UBDesktopServices_mac.cpp
  4. 51
      src/transition/UniboardSankoreTransition.cpp
  5. 9
      src/transition/UniboardSankoreTransition.h

@ -45,7 +45,6 @@
#include "ui_mainWindow.h" #include "ui_mainWindow.h"
#include "transition/UniboardSankoreTransition.h"
QPointer<QUndoStack> UBApplication::undoStack; QPointer<QUndoStack> UBApplication::undoStack;
@ -54,6 +53,7 @@ UBBoardController* UBApplication::boardController = 0;
UBWebController* UBApplication::webController = 0; UBWebController* UBApplication::webController = 0;
UBDocumentController* UBApplication::documentController = 0; UBDocumentController* UBApplication::documentController = 0;
UBSoftwareUpdateController* UBApplication::softwareUpdateController = 0; UBSoftwareUpdateController* UBApplication::softwareUpdateController = 0;
UniboardSankoreTransition* UBApplication::mUniboardSankoreTransition = 0;
UBMainWindow* UBApplication::mainWindow = 0; UBMainWindow* UBApplication::mainWindow = 0;
@ -299,8 +299,8 @@ int UBApplication::exec(const QString& pFileToImport)
UBLibraryController::preloadFirstOnlineLibrary(); UBLibraryController::preloadFirstOnlineLibrary();
UniboardSankoreTransition* transition = new UniboardSankoreTransition(); mUniboardSankoreTransition = new UniboardSankoreTransition();
transition->backupUniboardDirectory(); mUniboardSankoreTransition->documentTransition();
return QApplication::exec(); return QApplication::exec();
} }

@ -12,12 +12,14 @@
#include "qtsingleapplication.h" #include "qtsingleapplication.h"
#include "transition/UniboardSankoreTransition.h"
namespace Ui namespace Ui
{ {
class MainWindow; class MainWindow;
} }
class UBBoardController; class UBBoardController;
class UBWebController; class UBWebController;
class UBControlView; class UBControlView;
@ -49,6 +51,7 @@ class UBApplication : public QtSingleApplication
static UBWebController* webController; static UBWebController* webController;
static UBDocumentController* documentController; static UBDocumentController* documentController;
static UBSoftwareUpdateController* softwareUpdateController; static UBSoftwareUpdateController* softwareUpdateController;
static UniboardSankoreTransition* mUniboardSankoreTransition;
static UBMainWindow* mainWindow; static UBMainWindow* mainWindow;

@ -82,7 +82,7 @@ QString UBDesktopServices::storageLocation(StandardLocation type)
QString path = getFullPath(ref); QString path = getFullPath(ref);
if (QDesktopServices::DataLocation == type || QDesktopServices::CacheLocation == type) if (QDesktopServices::DataLocation == type || QDesktopServices::CacheLocation == type)
path += "/Sankore"; path += "/Sankore/Sankore 3.1";
return path; return path;
} }

@ -2,28 +2,19 @@
#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"
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"); mUniboardSourceDirectory.replace("Sankore/Sankore 3.1", "Mnemis/Uniboard");
} }
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,13 +32,32 @@ 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();
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();
@ -57,10 +67,15 @@ void UniboardSankoreTransition::documentTransition()
} }
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);
} }
emit transitionFinished(result);
mTransitionDlg->hide();
} }

@ -3,24 +3,29 @@
#include <QObject> #include <QObject>
#include <QFileInfo> #include <QFileInfo>
#include "gui/UBUpdateDlg.h"
class UniboardSankoreTransition : public QObject class UniboardSankoreTransition : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit UniboardSankoreTransition(QObject *parent = 0); explicit UniboardSankoreTransition(QObject *parent = 0);
bool backupUniboardDirectory(); ~UniboardSankoreTransition();
void documentTransition(); void documentTransition();
private: private:
void rollbackDocumentsTransition(QFileInfoList& fileInfoList); void rollbackDocumentsTransition(QFileInfoList& fileInfoList);
UBUpdateDlg* mTransitionDlg;
protected: protected:
QString mUniboardSourceDirectory; QString mUniboardSourceDirectory;
signals: signals:
void transitionFinished(bool result);
public slots: private slots:
void startDocumentTransition();
}; };

Loading…
Cancel
Save