parent
b6604dce59
commit
c4e771c8ad
@ -1,217 +1,219 @@ |
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#include "UBImportDocument.h" |
||||
#include "document/UBDocumentProxy.h" |
||||
|
||||
#include "frameworks/UBFileSystemUtils.h" |
||||
|
||||
#include "core/UBApplication.h" |
||||
#include "core/UBSettings.h" |
||||
#include "core/UBPersistenceManager.h" |
||||
|
||||
#include "globals/UBGlobals.h" |
||||
|
||||
THIRD_PARTY_WARNINGS_DISABLE |
||||
#include "quazip.h" |
||||
#include "quazipfile.h" |
||||
#include "quazipfileinfo.h" |
||||
THIRD_PARTY_WARNINGS_ENABLE |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
UBImportDocument::UBImportDocument(QObject *parent) |
||||
:UBImportAdaptor(parent) |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
UBImportDocument::~UBImportDocument() |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
|
||||
QStringList UBImportDocument::supportedExtentions() |
||||
{ |
||||
return QStringList("ubz"); |
||||
} |
||||
|
||||
|
||||
QString UBImportDocument::importFileFilter() |
||||
{ |
||||
return tr("Open-Sankore (*.ubz)"); |
||||
} |
||||
|
||||
|
||||
QString UBImportDocument::expandFileToDir(const QFile& pZipFile, const QString& pDir) |
||||
{ |
||||
|
||||
QDir rootDir(pDir); |
||||
QuaZip zip(pZipFile.fileName()); |
||||
|
||||
if(!zip.open(QuaZip::mdUnzip)) |
||||
{ |
||||
qWarning() << "Import failed. Cause zip.open(): " << zip.getZipError(); |
||||
return ""; |
||||
} |
||||
|
||||
zip.setFileNameCodec("UTF-8"); |
||||
QuaZipFileInfo info; |
||||
QuaZipFile file(&zip); |
||||
|
||||
// TODO UB 4.x implement a mechanism that can replace an existing
|
||||
// document based on the UID of the document.
|
||||
bool createNewDocument = true; |
||||
QString documentRootFolder; |
||||
|
||||
// first we search the metadata.rdf to check the document properties
|
||||
for(bool more = zip.goToFirstFile(); more; more = zip.goToNextFile()) |
||||
{ |
||||
if(!zip.getCurrentFileInfo(&info)) |
||||
{ |
||||
qWarning() << "Import failed. Cause: getCurrentFileInfo(): " << zip.getZipError(); |
||||
return ""; |
||||
} |
||||
|
||||
QFileInfo currentFileInfo(pDir + "/" + file.getActualFileName()); |
||||
} |
||||
|
||||
if (createNewDocument) |
||||
documentRootFolder = UBPersistenceManager::persistenceManager()->generateUniqueDocumentPath(); |
||||
|
||||
|
||||
QFile out; |
||||
char c; |
||||
for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) |
||||
{ |
||||
if(!zip.getCurrentFileInfo(&info)) |
||||
{ |
||||
//TOD UB 4.3 O display error to user or use crash reporter
|
||||
qWarning() << "Import failed. Cause: getCurrentFileInfo(): " << zip.getZipError(); |
||||
return ""; |
||||
} |
||||
|
||||
if(!file.open(QIODevice::ReadOnly)) |
||||
{ |
||||
qWarning() << "Import failed. Cause: file.open(): " << zip.getZipError(); |
||||
return ""; |
||||
} |
||||
|
||||
if(file.getZipError()!= UNZ_OK) |
||||
{ |
||||
qWarning() << "Import failed. Cause: file.getFileName(): " << zip.getZipError(); |
||||
return ""; |
||||
} |
||||
|
||||
QString newFileName = documentRootFolder + "/" + file.getActualFileName(); |
||||
QFileInfo newFileInfo(newFileName); |
||||
rootDir.mkpath(newFileInfo.absolutePath()); |
||||
|
||||
out.setFileName(newFileName); |
||||
out.open(QIODevice::WriteOnly); |
||||
|
||||
// Slow like hell (on GNU/Linux at least), but it is not my fault.
|
||||
// Not ZIP/UNZIP package's fault either.
|
||||
// The slowest thing here is out.putChar(c).
|
||||
QByteArray outFileContent = file.readAll(); |
||||
if (out.write(outFileContent) == -1) |
||||
{ |
||||
qWarning() << "Import failed. Cause: Unable to write file"; |
||||
out.close(); |
||||
return ""; |
||||
} |
||||
|
||||
while(file.getChar(&c)) |
||||
out.putChar(c); |
||||
|
||||
out.close(); |
||||
|
||||
if(file.getZipError()!=UNZ_OK) |
||||
{ |
||||
qWarning() << "Import failed. Cause: " << zip.getZipError(); |
||||
return ""; |
||||
} |
||||
|
||||
if(!file.atEnd()) |
||||
{ |
||||
qWarning() << "Import failed. Cause: read all but not EOF"; |
||||
return ""; |
||||
} |
||||
|
||||
file.close(); |
||||
|
||||
if(file.getZipError()!=UNZ_OK) |
||||
{ |
||||
qWarning() << "Import failed. Cause: file.close(): " << file.getZipError(); |
||||
return ""; |
||||
} |
||||
|
||||
} |
||||
|
||||
zip.close(); |
||||
|
||||
if(zip.getZipError()!=UNZ_OK) |
||||
{ |
||||
qWarning() << "Import failed. Cause: zip.close(): " << zip.getZipError(); |
||||
return ""; |
||||
} |
||||
|
||||
|
||||
return documentRootFolder; |
||||
} |
||||
|
||||
|
||||
UBDocumentProxy* UBImportDocument::importFile(const QFile& pFile, const QString& pGroup) |
||||
{ |
||||
Q_UNUSED(pGroup); // group is defined in the imported file
|
||||
|
||||
QFileInfo fi(pFile); |
||||
UBApplication::showMessage(tr("Importing file %1...").arg(fi.baseName()), true); |
||||
|
||||
// first unzip the file to the correct place
|
||||
QString path = UBSettings::settings()->uniboardDocumentDirectory(); |
||||
|
||||
QString documentRootFolder = expandFileToDir(pFile, path); |
||||
|
||||
if(!documentRootFolder.length()){ |
||||
UBApplication::showMessage(tr("Import of file %1 failed.").arg(fi.baseName())); |
||||
return 0; |
||||
} |
||||
else{ |
||||
UBDocumentProxy* newDocument = UBPersistenceManager::persistenceManager()->createDocumentFromDir(documentRootFolder); |
||||
UBApplication::showMessage(tr("Import successful.")); |
||||
return newDocument; |
||||
} |
||||
} |
||||
|
||||
|
||||
bool UBImportDocument::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile) |
||||
{ |
||||
QFileInfo fi(pFile); |
||||
UBApplication::showMessage(tr("Importing file %1...").arg(fi.baseName()), true); |
||||
|
||||
QString path = UBFileSystemUtils::createTempDir(); |
||||
|
||||
QString documentRootFolder = expandFileToDir(pFile, path); |
||||
|
||||
UBPersistenceManager::persistenceManager()->addDirectoryContentToDocument(documentRootFolder, pDocument); |
||||
|
||||
UBFileSystemUtils::deleteDir(path); |
||||
|
||||
UBApplication::showMessage(tr("Import successful.")); |
||||
|
||||
return true; |
||||
} |
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#include "UBImportDocument.h" |
||||
#include "document/UBDocumentProxy.h" |
||||
|
||||
#include "frameworks/UBFileSystemUtils.h" |
||||
|
||||
#include "core/UBApplication.h" |
||||
#include "core/UBSettings.h" |
||||
#include "core/UBPersistenceManager.h" |
||||
|
||||
#include "globals/UBGlobals.h" |
||||
|
||||
THIRD_PARTY_WARNINGS_DISABLE |
||||
#include "quazip.h" |
||||
#include "quazipfile.h" |
||||
#include "quazipfileinfo.h" |
||||
THIRD_PARTY_WARNINGS_ENABLE |
||||
|
||||
#include "core/memcheck.h" |
||||
|
||||
UBImportDocument::UBImportDocument(QObject *parent) |
||||
:UBImportAdaptor(parent) |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
UBImportDocument::~UBImportDocument() |
||||
{ |
||||
// NOOP
|
||||
} |
||||
|
||||
|
||||
QStringList UBImportDocument::supportedExtentions() |
||||
{ |
||||
return QStringList("ubz"); |
||||
} |
||||
|
||||
|
||||
QString UBImportDocument::importFileFilter() |
||||
{ |
||||
return tr("Open-Sankore (*.ubz)"); |
||||
} |
||||
|
||||
|
||||
QString UBImportDocument::expandFileToDir(const QFile& pZipFile, const QString& pDir) |
||||
{ |
||||
|
||||
QDir rootDir(pDir); |
||||
QuaZip zip(pZipFile.fileName()); |
||||
|
||||
if(!zip.open(QuaZip::mdUnzip)) |
||||
{ |
||||
qWarning() << "Import failed. Cause zip.open(): " << zip.getZipError(); |
||||
return ""; |
||||
} |
||||
|
||||
zip.setFileNameCodec("UTF-8"); |
||||
QuaZipFileInfo info; |
||||
QuaZipFile file(&zip); |
||||
|
||||
// TODO UB 4.x implement a mechanism that can replace an existing
|
||||
// document based on the UID of the document.
|
||||
bool createNewDocument = true; |
||||
QString documentRootFolder; |
||||
|
||||
// first we search the metadata.rdf to check the document properties
|
||||
for(bool more = zip.goToFirstFile(); more; more = zip.goToNextFile()) |
||||
{ |
||||
if(!zip.getCurrentFileInfo(&info)) |
||||
{ |
||||
qWarning() << "Import failed. Cause: getCurrentFileInfo(): " << zip.getZipError(); |
||||
return ""; |
||||
} |
||||
|
||||
QFileInfo currentFileInfo(pDir + "/" + file.getActualFileName()); |
||||
} |
||||
|
||||
if (createNewDocument) |
||||
documentRootFolder = UBPersistenceManager::persistenceManager()->generateUniqueDocumentPath(); |
||||
|
||||
|
||||
QFile out; |
||||
char c; |
||||
for(bool more=zip.goToFirstFile(); more; more=zip.goToNextFile()) |
||||
{ |
||||
if(!zip.getCurrentFileInfo(&info)) |
||||
{ |
||||
//TOD UB 4.3 O display error to user or use crash reporter
|
||||
qWarning() << "Import failed. Cause: getCurrentFileInfo(): " << zip.getZipError(); |
||||
return ""; |
||||
} |
||||
|
||||
if(!file.open(QIODevice::ReadOnly)) |
||||
{ |
||||
qWarning() << "Import failed. Cause: file.open(): " << zip.getZipError(); |
||||
return ""; |
||||
} |
||||
|
||||
if(file.getZipError()!= UNZ_OK) |
||||
{ |
||||
qWarning() << "Import failed. Cause: file.getFileName(): " << zip.getZipError(); |
||||
return ""; |
||||
} |
||||
|
||||
QString newFileName = documentRootFolder + "/" + file.getActualFileName(); |
||||
QFileInfo newFileInfo(newFileName); |
||||
rootDir.mkpath(newFileInfo.absolutePath()); |
||||
|
||||
out.setFileName(newFileName); |
||||
out.open(QIODevice::WriteOnly); |
||||
|
||||
// Slow like hell (on GNU/Linux at least), but it is not my fault.
|
||||
// Not ZIP/UNZIP package's fault either.
|
||||
// The slowest thing here is out.putChar(c).
|
||||
QByteArray outFileContent = file.readAll(); |
||||
if (out.write(outFileContent) == -1) |
||||
{ |
||||
qWarning() << "Import failed. Cause: Unable to write file"; |
||||
out.close(); |
||||
return ""; |
||||
} |
||||
|
||||
while(file.getChar(&c)) |
||||
out.putChar(c); |
||||
|
||||
out.close(); |
||||
|
||||
if(file.getZipError()!=UNZ_OK) |
||||
{ |
||||
qWarning() << "Import failed. Cause: " << zip.getZipError(); |
||||
return ""; |
||||
} |
||||
|
||||
if(!file.atEnd()) |
||||
{ |
||||
qWarning() << "Import failed. Cause: read all but not EOF"; |
||||
return ""; |
||||
} |
||||
|
||||
file.close(); |
||||
|
||||
if(file.getZipError()!=UNZ_OK) |
||||
{ |
||||
qWarning() << "Import failed. Cause: file.close(): " << file.getZipError(); |
||||
return ""; |
||||
} |
||||
|
||||
} |
||||
|
||||
zip.close(); |
||||
|
||||
if(zip.getZipError()!=UNZ_OK) |
||||
{ |
||||
qWarning() << "Import failed. Cause: zip.close(): " << zip.getZipError(); |
||||
return ""; |
||||
} |
||||
|
||||
|
||||
return documentRootFolder; |
||||
} |
||||
|
||||
|
||||
UBDocumentProxy* UBImportDocument::importFile(const QFile& pFile, const QString& pGroup) |
||||
{ |
||||
Q_UNUSED(pGroup); // group is defined in the imported file
|
||||
|
||||
QFileInfo fi(pFile); |
||||
UBApplication::showMessage(tr("Importing file %1...").arg(fi.baseName()), true); |
||||
|
||||
// first unzip the file to the correct place
|
||||
QString path = UBSettings::settings()->uniboardDocumentDirectory(); |
||||
|
||||
QString documentRootFolder = expandFileToDir(pFile, path); |
||||
|
||||
if(!documentRootFolder.length()){ |
||||
UBApplication::showMessage(tr("Import of file %1 failed.").arg(fi.baseName())); |
||||
return 0; |
||||
} |
||||
else{ |
||||
UBDocumentProxy* newDocument = UBPersistenceManager::persistenceManager()->createDocumentFromDir(documentRootFolder, pGroup); |
||||
|
||||
UBApplication::showMessage(tr("Import successful.")); |
||||
|
||||
return newDocument; |
||||
} |
||||
} |
||||
|
||||
|
||||
bool UBImportDocument::addFileToDocument(UBDocumentProxy* pDocument, const QFile& pFile) |
||||
{ |
||||
QFileInfo fi(pFile); |
||||
UBApplication::showMessage(tr("Importing file %1...").arg(fi.baseName()), true); |
||||
|
||||
QString path = UBFileSystemUtils::createTempDir(); |
||||
|
||||
QString documentRootFolder = expandFileToDir(pFile, path); |
||||
|
||||
UBPersistenceManager::persistenceManager()->addDirectoryContentToDocument(documentRootFolder, pDocument); |
||||
|
||||
UBFileSystemUtils::deleteDir(path); |
||||
|
||||
UBApplication::showMessage(tr("Import successful.")); |
||||
|
||||
return true; |
||||
} |
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,175 +1,175 @@ |
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef UBPERSISTENCEMANAGER_H_ |
||||
#define UBPERSISTENCEMANAGER_H_ |
||||
|
||||
#include <QtCore> |
||||
|
||||
#include "UBSceneCache.h" |
||||
|
||||
struct sTeacherBarInfos |
||||
{ |
||||
QString title; |
||||
QStringList actions; |
||||
QStringList medias; |
||||
QStringList urls; |
||||
QString comments; |
||||
}; |
||||
|
||||
class UBDocument; |
||||
class UBDocumentProxy; |
||||
class UBGraphicsScene; |
||||
|
||||
class UBPersistenceManager : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
private: |
||||
UBPersistenceManager(QObject *pParent = 0); |
||||
static UBPersistenceManager* sSingleton; |
||||
|
||||
public: |
||||
|
||||
virtual ~UBPersistenceManager(); |
||||
|
||||
static const QString imageDirectory; |
||||
static const QString objectDirectory; |
||||
static const QString videoDirectory; |
||||
static const QString audioDirectory; |
||||
static const QString widgetDirectory; |
||||
|
||||
static UBPersistenceManager* persistenceManager(); |
||||
static void destroy(); |
||||
|
||||
virtual UBDocumentProxy* createDocument(const QString& pGroupName = "", const QString& pName = "", bool withEmptyPage = true); |
||||
virtual UBDocumentProxy* createDocumentFromDir(const QString& pDocumentDirectory); |
||||
|
||||
virtual UBDocumentProxy* persistDocumentMetadata(UBDocumentProxy* pDocumentProxy); |
||||
|
||||
virtual UBDocumentProxy* duplicateDocument(UBDocumentProxy* pDocumentProxy); |
||||
|
||||
virtual void deleteDocument(UBDocumentProxy* pDocumentProxy); |
||||
|
||||
virtual void deleteDocumentScenes(UBDocumentProxy* pDocumentProxy, const QList<int>& indexes); |
||||
|
||||
virtual void duplicateDocumentScene(UBDocumentProxy* pDocumentProxy, int index); |
||||
|
||||
virtual void persistDocumentScene(UBDocumentProxy* pDocumentProxy, |
||||
UBGraphicsScene* pScene, const int pSceneIndex); |
||||
virtual void persistTeacherBar(UBDocumentProxy* pDocumentProxy, int page, sTeacherBarInfos infos); |
||||
|
||||
sTeacherBarInfos getTeacherBarInfos(UBDocumentProxy* pDocumentProxy, int page); |
||||
|
||||
virtual UBGraphicsScene* createDocumentSceneAt(UBDocumentProxy* pDocumentProxy, int index); |
||||
|
||||
virtual void insertDocumentSceneAt(UBDocumentProxy* pDocumentProxy, UBGraphicsScene* scene, int index); |
||||
|
||||
virtual void moveSceneToIndex(UBDocumentProxy* pDocumentProxy, int source, int target); |
||||
|
||||
virtual UBGraphicsScene* loadDocumentScene(UBDocumentProxy* pDocumentProxy, int sceneIndex); |
||||
UBGraphicsScene *getDocumentScene(UBDocumentProxy* pDocumentProxy, int sceneIndex) {return mSceneCache.value(pDocumentProxy, sceneIndex);} |
||||
|
||||
QList<QPointer<UBDocumentProxy> > documentProxies; |
||||
|
||||
virtual QStringList allShapes(); |
||||
virtual QStringList allGips(); |
||||
virtual QStringList allSounds(); |
||||
virtual QStringList allImages(const QDir& dir); |
||||
virtual QStringList allVideos(const QDir& dir); |
||||
virtual QStringList allWidgets(const QDir& dir); |
||||
|
||||
virtual QString generateUniqueDocumentPath(); |
||||
|
||||
virtual void addDirectoryContentToDocument(const QString& documentRootFolder, UBDocumentProxy* pDocument); |
||||
|
||||
virtual void upgradeDocumentIfNeeded(UBDocumentProxy* pDocumentProxy); |
||||
|
||||
virtual void upgradeAllDocumentsIfNeeded(); |
||||
|
||||
virtual UBDocumentProxy* documentByUuid(const QUuid& pUuid); |
||||
|
||||
QStringList documentSubDirectories() |
||||
{ |
||||
return mDocumentSubDirectories; |
||||
} |
||||
|
||||
virtual bool isEmpty(UBDocumentProxy* pDocumentProxy); |
||||
virtual void purgeEmptyDocuments(); |
||||
|
||||
virtual QString addVideoFileToDocument(UBDocumentProxy* pDocumentProxy, QString path, QUuid objectUuid); |
||||
virtual QString addVideoFileToDocument(UBDocumentProxy* pDocumentProxy, QUrl sourceUrl, QByteArray pPayload, QUuid objectUuid); |
||||
virtual QString addAudioFileToDocument(UBDocumentProxy* pDocumentProxy, QString path, QUuid objectUuid); |
||||
virtual QString addAudioFileToDocument(UBDocumentProxy* pDocumentProxy, QUrl sourceUrl, QByteArray pPayload, QUuid objectUuid); |
||||
virtual QString addPdfFileToDocument(UBDocumentProxy* pDocumentProxy, QString path, QUuid objectUuid); |
||||
virtual QString addGraphicsWidgteToDocument(UBDocumentProxy *mDocumentProxy, QString path, QUuid objectUuid); |
||||
|
||||
bool mayHaveVideo(UBDocumentProxy* pDocumentProxy); |
||||
bool mayHaveAudio(UBDocumentProxy* pDocumentProxy); |
||||
bool mayHavePDF(UBDocumentProxy* pDocumentProxy); |
||||
bool mayHaveSVGImages(UBDocumentProxy* pDocumentProxy); |
||||
bool mayHaveWidget(UBDocumentProxy* pDocumentProxy); |
||||
|
||||
signals: |
||||
|
||||
void proxyListChanged(); |
||||
|
||||
void documentCreated(UBDocumentProxy* pDocumentProxy); |
||||
void documentMetadataChanged(UBDocumentProxy* pDocumentProxy); |
||||
void documentCommitted(UBDocumentProxy* pDocumentProxy); |
||||
void documentWillBeDeleted(UBDocumentProxy* pDocumentProxy); |
||||
|
||||
void documentSceneCreated(UBDocumentProxy* pDocumentProxy, int pIndex); |
||||
void documentSceneMoved(UBDocumentProxy* pDocumentProxy, int pIndex); |
||||
void documentSceneWillBeDeleted(UBDocumentProxy* pDocumentProxy, int pIndex); |
||||
void documentSceneDeleted(UBDocumentProxy* pDocumentProxy, int pDeletedIndex); |
||||
|
||||
private: |
||||
|
||||
int sceneCount(const UBDocumentProxy* pDocumentProxy); |
||||
|
||||
int sceneCountInDir(const QString& pPath); |
||||
|
||||
QList<QPointer<UBDocumentProxy> > allDocumentProxies(); |
||||
|
||||
void renamePage(UBDocumentProxy* pDocumentProxy, |
||||
const int sourceIndex, const int targetIndex); |
||||
|
||||
void copyPage(UBDocumentProxy* pDocumentProxy, |
||||
const int sourceIndex, const int targetIndex); |
||||
|
||||
void generatePathIfNeeded(UBDocumentProxy* pDocumentProxy); |
||||
|
||||
void checkIfDocumentRepositoryExists(); |
||||
|
||||
UBSceneCache mSceneCache; |
||||
|
||||
QStringList mDocumentSubDirectories; |
||||
|
||||
QMutex mDeletedListMutex; |
||||
|
||||
bool mHasPurgedDocuments; |
||||
|
||||
QList<UBDocumentProxy*> mDocumentCreatedDuringSession; |
||||
|
||||
QString mDocumentRepositoryPath; |
||||
|
||||
private slots: |
||||
void documentRepositoryChanged(const QString& path); |
||||
|
||||
}; |
||||
|
||||
|
||||
#endif /* UBPERSISTENCEMANAGER_H_ */ |
||||
/*
|
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
#ifndef UBPERSISTENCEMANAGER_H_ |
||||
#define UBPERSISTENCEMANAGER_H_ |
||||
|
||||
#include <QtCore> |
||||
|
||||
#include "UBSceneCache.h" |
||||
|
||||
struct sTeacherBarInfos |
||||
{ |
||||
QString title; |
||||
QStringList actions; |
||||
QStringList medias; |
||||
QStringList urls; |
||||
QString comments; |
||||
}; |
||||
|
||||
class UBDocument; |
||||
class UBDocumentProxy; |
||||
class UBGraphicsScene; |
||||
|
||||
class UBPersistenceManager : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
|
||||
private: |
||||
UBPersistenceManager(QObject *pParent = 0); |
||||
static UBPersistenceManager* sSingleton; |
||||
|
||||
public: |
||||
|
||||
virtual ~UBPersistenceManager(); |
||||
|
||||
static const QString imageDirectory; |
||||
static const QString objectDirectory; |
||||
static const QString videoDirectory; |
||||
static const QString audioDirectory; |
||||
static const QString widgetDirectory; |
||||
|
||||
static UBPersistenceManager* persistenceManager(); |
||||
static void destroy(); |
||||
|
||||
virtual UBDocumentProxy* createDocument(const QString& pGroupName = "", const QString& pName = "", bool withEmptyPage = true); |
||||
virtual UBDocumentProxy* createDocumentFromDir(const QString& pDocumentDirectory, const QString& pGroupName = "", const QString& pName = "", bool withEmptyPage = false); |
||||
|
||||
virtual UBDocumentProxy* persistDocumentMetadata(UBDocumentProxy* pDocumentProxy); |
||||
|
||||
virtual UBDocumentProxy* duplicateDocument(UBDocumentProxy* pDocumentProxy); |
||||
|
||||
virtual void deleteDocument(UBDocumentProxy* pDocumentProxy); |
||||
|
||||
virtual void deleteDocumentScenes(UBDocumentProxy* pDocumentProxy, const QList<int>& indexes); |
||||
|
||||
virtual void duplicateDocumentScene(UBDocumentProxy* pDocumentProxy, int index); |
||||
|
||||
virtual void persistDocumentScene(UBDocumentProxy* pDocumentProxy, |
||||
UBGraphicsScene* pScene, const int pSceneIndex); |
||||
virtual void persistTeacherBar(UBDocumentProxy* pDocumentProxy, int page, sTeacherBarInfos infos); |
||||
|
||||
sTeacherBarInfos getTeacherBarInfos(UBDocumentProxy* pDocumentProxy, int page); |
||||
|
||||
virtual UBGraphicsScene* createDocumentSceneAt(UBDocumentProxy* pDocumentProxy, int index); |
||||
|
||||
virtual void insertDocumentSceneAt(UBDocumentProxy* pDocumentProxy, UBGraphicsScene* scene, int index); |
||||
|
||||
virtual void moveSceneToIndex(UBDocumentProxy* pDocumentProxy, int source, int target); |
||||
|
||||
virtual UBGraphicsScene* loadDocumentScene(UBDocumentProxy* pDocumentProxy, int sceneIndex); |
||||
UBGraphicsScene *getDocumentScene(UBDocumentProxy* pDocumentProxy, int sceneIndex) {return mSceneCache.value(pDocumentProxy, sceneIndex);} |
||||
|
||||
QList<QPointer<UBDocumentProxy> > documentProxies; |
||||
|
||||
virtual QStringList allShapes(); |
||||
virtual QStringList allGips(); |
||||
virtual QStringList allSounds(); |
||||
virtual QStringList allImages(const QDir& dir); |
||||
virtual QStringList allVideos(const QDir& dir); |
||||
virtual QStringList allWidgets(const QDir& dir); |
||||
|
||||
virtual QString generateUniqueDocumentPath(); |
||||
|
||||
virtual void addDirectoryContentToDocument(const QString& documentRootFolder, UBDocumentProxy* pDocument); |
||||
|
||||
virtual void upgradeDocumentIfNeeded(UBDocumentProxy* pDocumentProxy); |
||||
|
||||
virtual void upgradeAllDocumentsIfNeeded(); |
||||
|
||||
virtual UBDocumentProxy* documentByUuid(const QUuid& pUuid); |
||||
|
||||
QStringList documentSubDirectories() |
||||
{ |
||||
return mDocumentSubDirectories; |
||||
} |
||||
|
||||
virtual bool isEmpty(UBDocumentProxy* pDocumentProxy); |
||||
virtual void purgeEmptyDocuments(); |
||||
|
||||
virtual QString addVideoFileToDocument(UBDocumentProxy* pDocumentProxy, QString path, QUuid objectUuid); |
||||
virtual QString addVideoFileToDocument(UBDocumentProxy* pDocumentProxy, QUrl sourceUrl, QByteArray pPayload, QUuid objectUuid); |
||||
virtual QString addAudioFileToDocument(UBDocumentProxy* pDocumentProxy, QString path, QUuid objectUuid); |
||||
virtual QString addAudioFileToDocument(UBDocumentProxy* pDocumentProxy, QUrl sourceUrl, QByteArray pPayload, QUuid objectUuid); |
||||
virtual QString addPdfFileToDocument(UBDocumentProxy* pDocumentProxy, QString path, QUuid objectUuid); |
||||
virtual QString addGraphicsWidgteToDocument(UBDocumentProxy *mDocumentProxy, QString path, QUuid objectUuid); |
||||
|
||||
bool mayHaveVideo(UBDocumentProxy* pDocumentProxy); |
||||
bool mayHaveAudio(UBDocumentProxy* pDocumentProxy); |
||||
bool mayHavePDF(UBDocumentProxy* pDocumentProxy); |
||||
bool mayHaveSVGImages(UBDocumentProxy* pDocumentProxy); |
||||
bool mayHaveWidget(UBDocumentProxy* pDocumentProxy); |
||||
|
||||
signals: |
||||
|
||||
void proxyListChanged(); |
||||
|
||||
void documentCreated(UBDocumentProxy* pDocumentProxy); |
||||
void documentMetadataChanged(UBDocumentProxy* pDocumentProxy); |
||||
void documentCommitted(UBDocumentProxy* pDocumentProxy); |
||||
void documentWillBeDeleted(UBDocumentProxy* pDocumentProxy); |
||||
|
||||
void documentSceneCreated(UBDocumentProxy* pDocumentProxy, int pIndex); |
||||
void documentSceneMoved(UBDocumentProxy* pDocumentProxy, int pIndex); |
||||
void documentSceneWillBeDeleted(UBDocumentProxy* pDocumentProxy, int pIndex); |
||||
void documentSceneDeleted(UBDocumentProxy* pDocumentProxy, int pDeletedIndex); |
||||
|
||||
private: |
||||
|
||||
int sceneCount(const UBDocumentProxy* pDocumentProxy); |
||||
|
||||
int sceneCountInDir(const QString& pPath); |
||||
|
||||
QList<QPointer<UBDocumentProxy> > allDocumentProxies(); |
||||
|
||||
void renamePage(UBDocumentProxy* pDocumentProxy, |
||||
const int sourceIndex, const int targetIndex); |
||||
|
||||
void copyPage(UBDocumentProxy* pDocumentProxy, |
||||
const int sourceIndex, const int targetIndex); |
||||
|
||||
void generatePathIfNeeded(UBDocumentProxy* pDocumentProxy); |
||||
|
||||
void checkIfDocumentRepositoryExists(); |
||||
|
||||
UBSceneCache mSceneCache; |
||||
|
||||
QStringList mDocumentSubDirectories; |
||||
|
||||
QMutex mDeletedListMutex; |
||||
|
||||
bool mHasPurgedDocuments; |
||||
|
||||
QList<UBDocumentProxy*> mDocumentCreatedDuringSession; |
||||
|
||||
QString mDocumentRepositoryPath; |
||||
|
||||
private slots: |
||||
void documentRepositoryChanged(const QString& path); |
||||
|
||||
}; |
||||
|
||||
|
||||
#endif /* UBPERSISTENCEMANAGER_H_ */ |
||||
|
Loading…
Reference in new issue