From 4eea0597ed91f51203aad958fdca95bea5cff123 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Thu, 5 May 2011 15:21:41 +0200 Subject: [PATCH] Added new files --- Sankore_3.1.pro | 6 ++ src/core/UBApplication.cpp | 5 ++ src/frameworks/UBFileSystemUtils.cpp | 5 +- src/transition/UniboardSankoreTransition.cpp | 66 ++++++++++++++++++++ src/transition/UniboardSankoreTransition.h | 27 ++++++++ thirdparty/xpdf/xpdf-3.02/xpdf/Makefile | 2 +- 6 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 src/transition/UniboardSankoreTransition.cpp create mode 100644 src/transition/UniboardSankoreTransition.h diff --git a/Sankore_3.1.pro b/Sankore_3.1.pro index 853344b3..80055fe3 100644 --- a/Sankore_3.1.pro +++ b/Sankore_3.1.pro @@ -346,3 +346,9 @@ INSTALLS = UB_ETC \ UB_THIRDPARTY_INTERACTIVE OTHER_FILES += + +HEADERS += \ + src/transition/UniboardSankoreTransition.h + +SOURCES += \ + src/transition/UniboardSankoreTransition.cpp diff --git a/src/core/UBApplication.cpp b/src/core/UBApplication.cpp index 623ed36b..efd5a46f 100644 --- a/src/core/UBApplication.cpp +++ b/src/core/UBApplication.cpp @@ -45,6 +45,8 @@ #include "ui_mainWindow.h" +#include "transition/UniboardSankoreTransition.h" + QPointer UBApplication::undoStack; UBApplicationController* UBApplication::applicationController = 0; @@ -297,6 +299,9 @@ int UBApplication::exec(const QString& pFileToImport) UBLibraryController::preloadFirstOnlineLibrary(); + UniboardSankoreTransition* transition = new UniboardSankoreTransition(); + transition->backupUniboardDirectory(); + return QApplication::exec(); } diff --git a/src/frameworks/UBFileSystemUtils.cpp b/src/frameworks/UBFileSystemUtils.cpp index d811d2bb..b50935c5 100644 --- a/src/frameworks/UBFileSystemUtils.cpp +++ b/src/frameworks/UBFileSystemUtils.cpp @@ -154,8 +154,7 @@ QStringList UBFileSystemUtils::allFiles(const QString& pDirPath) QFileInfoList UBFileSystemUtils::allElementsInDirectory(const QString& pDirPath) { QDir dir = QDir(pDirPath); - dir.setFilter(QDir::Files | QDir::Dirs | - QDir::NoDotAndDotDot | QDir::NoSymLinks); + dir.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks); dir.setSorting(QDir::DirsFirst); return QFileInfoList(dir.entryInfoList()); @@ -164,8 +163,6 @@ QFileInfoList UBFileSystemUtils::allElementsInDirectory(const QString& pDirPath) bool UBFileSystemUtils::deleteDir(const QString& pDirPath) { - //qDebug() << "UBFileSystemUtils::deleteDir.start" << pDirPath; - if (pDirPath == "" || pDirPath == "." || pDirPath == "..") return false; diff --git a/src/transition/UniboardSankoreTransition.cpp b/src/transition/UniboardSankoreTransition.cpp new file mode 100644 index 00000000..7b19206f --- /dev/null +++ b/src/transition/UniboardSankoreTransition.cpp @@ -0,0 +1,66 @@ +#include "UniboardSankoreTransition.h" +#include "core/UBSettings.h" +#include "frameworks/UBDesktopServices.h" +#include "frameworks/UBFileSystemUtils.h" + +UniboardSankoreTransition::UniboardSankoreTransition(QObject *parent) : + QObject(parent) +{ + mUniboardSourceDirectory = UBDesktopServices::storageLocation(QDesktopServices::DataLocation); + mUniboardSourceDirectory.replace("Sankore/Sankore 3.1", "Mnemis/Uniboard"); +} + +bool UniboardSankoreTransition::backupUniboardDirectory() +{ + bool result = false; + 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) +{ + 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() +{ + QString uniboardDocumentDirectory = mUniboardSourceDirectory + "/document"; + QString sankoreDocumentDirectory = UBSettings::uniboardDocumentDirectory(); + + QFileInfoList fileInfoList = UBFileSystemUtils::allElementsInDirectory(uniboardDocumentDirectory); + + QFileInfoList::iterator fileInfo; + bool result = true; + 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 during the copy of the " + fileInfo->filePath() + " document."; + rollbackDocumentsTransition(fileInfoList); + } + else { + UBFileSystemUtils::deleteDir(mUniboardSourceDirectory); + } +} \ No newline at end of file diff --git a/src/transition/UniboardSankoreTransition.h b/src/transition/UniboardSankoreTransition.h new file mode 100644 index 00000000..2ff7eed8 --- /dev/null +++ b/src/transition/UniboardSankoreTransition.h @@ -0,0 +1,27 @@ +#ifndef UNIBOARDSANKORETRANSITION_H +#define UNIBOARDSANKORETRANSITION_H + +#include +#include + +class UniboardSankoreTransition : public QObject +{ + Q_OBJECT +public: + explicit UniboardSankoreTransition(QObject *parent = 0); + bool backupUniboardDirectory(); + void documentTransition(); + +private: + void rollbackDocumentsTransition(QFileInfoList& fileInfoList); + +protected: + QString mUniboardSourceDirectory; + +signals: + +public slots: + +}; + +#endif // UNIBOARDSANKORETRANSITION_H diff --git a/thirdparty/xpdf/xpdf-3.02/xpdf/Makefile b/thirdparty/xpdf/xpdf-3.02/xpdf/Makefile index 054b0178..8fc95fb4 100644 --- a/thirdparty/xpdf/xpdf-3.02/xpdf/Makefile +++ b/thirdparty/xpdf/xpdf-3.02/xpdf/Makefile @@ -26,7 +26,7 @@ LDFLAGS = T1LIBS = FTLIBS = -XLIBS = -lX11 +XLIBS = -lXt -lXext -lSM -lICE -lX11 SPLASHLIBS = -L$(SPLASHLIBDIR) -lsplash