page zero issue after importing documents using the Importer program

preferencesAboutTextFull
Claudio Valerio 11 years ago
parent d452b2dd28
commit f8a21c1b3c
  1. 2
      src/adaptors/UBImportDocument.cpp
  2. 66
      src/core/UBPersistenceManager.cpp
  3. 10
      src/core/UBPersistenceManager.h
  4. 1
      src/document/UBDocumentController.cpp

@ -179,7 +179,7 @@ UBDocumentProxy* UBImportDocument::importFile(const QFile& pFile, const QString&
return NULL;
}
UBDocumentProxy* newDocument = UBPersistenceManager::persistenceManager()->createDocumentFromDir(documentRootFolder, pGroup, "", false, false);
UBDocumentProxy* newDocument = UBPersistenceManager::persistenceManager()->createDocumentFromDir(documentRootFolder, pGroup, "");
UBApplication::showMessage(tr("Import successful."));
return newDocument;
}

@ -65,7 +65,7 @@ UBPersistenceManager::UBPersistenceManager(QObject *pParent)
mDocumentSubDirectories << audioDirectory;
documentProxies = allDocumentProxies();
emit proxyListChanged();
}
UBPersistenceManager* UBPersistenceManager::persistenceManager()
@ -102,6 +102,13 @@ QList<QPointer<UBDocumentProxy> > UBPersistenceManager::allDocumentProxies()
rootDir.mkpath(rootDir.path());
QStringList dirList = rootDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Time | QDir::Reversed);
foreach(QString path, dirList)
{
shiftPagesToStartWithTheZeroOne(rootDir.path() + "/" + path);
}
QFileSystemWatcher* watcher = new QFileSystemWatcher(this);
watcher->addPath(mDocumentRepositoryPath);
@ -109,8 +116,7 @@ QList<QPointer<UBDocumentProxy> > UBPersistenceManager::allDocumentProxies()
QList<QPointer<UBDocumentProxy> > proxies;
foreach(QString path, rootDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot,
QDir::Time | QDir::Reversed))
foreach(QString path, dirList)
{
QString fullPath = rootDir.path() + "/" + path;
@ -257,8 +263,6 @@ UBDocumentProxy* UBPersistenceManager::createDocument(const QString& pGroupName,
documentProxies.insert(0, QPointer<UBDocumentProxy>(doc));
emit proxyListChanged();
emit documentCreated(doc);
mDocumentCreatedDuringSession << doc;
@ -266,7 +270,7 @@ UBDocumentProxy* UBPersistenceManager::createDocument(const QString& pGroupName,
return doc;
}
UBDocumentProxy* UBPersistenceManager::createDocumentFromDir(const QString& pDocumentDirectory, const QString& pGroupName, const QString& pName, bool withEmptyPage, bool addTitlePage)
UBDocumentProxy* UBPersistenceManager::createDocumentFromDir(const QString& pDocumentDirectory, const QString& pGroupName, const QString& pName)
{
checkIfDocumentRepositoryExists();
@ -281,8 +285,6 @@ UBDocumentProxy* UBPersistenceManager::createDocumentFromDir(const QString& pDoc
{
doc->setMetaData(UBSettings::documentName, pName);
}
if(withEmptyPage) createDocumentSceneAt(doc, 0);
if(addTitlePage) persistDocumentScene(doc, mSceneCache.createScene(doc, 0, false), 0);
QMap<QString, QVariant> metadatas = UBMetadataDcSubsetAdaptor::load(pDocumentDirectory);
@ -303,7 +305,6 @@ UBDocumentProxy* UBPersistenceManager::createDocumentFromDir(const QString& pDoc
documentProxies << QPointer<UBDocumentProxy>(doc);
emit proxyListChanged();
emit documentCreated(doc);
@ -326,8 +327,6 @@ void UBPersistenceManager::deleteDocument(UBDocumentProxy* pDocumentProxy)
pDocumentProxy->deleteLater();
emit proxyListChanged();
}
@ -363,8 +362,6 @@ UBDocumentProxy* UBPersistenceManager::duplicateDocument(UBDocumentProxy* pDocum
documentProxies << QPointer<UBDocumentProxy>(copy);
emit proxyListChanged();
emit documentCreated(copy);
return copy;
@ -652,7 +649,6 @@ void UBPersistenceManager::copyPage(UBDocumentProxy* pDocumentProxy, const int s
int UBPersistenceManager::sceneCount(const UBDocumentProxy* proxy)
{
const QString pPath = proxy->persistencePath();
int pageIndex = 0;
bool moreToProcess = true;
@ -739,31 +735,6 @@ bool UBPersistenceManager::addDirectoryContentToDocument(const QString& document
}
void UBPersistenceManager::upgradeDocumentIfNeeded(UBDocumentProxy* pDocumentProxy)
{
int pageCount = pDocumentProxy->pageCount();
for(int index = 0 ; index < pageCount; index++)
{
UBSvgSubsetAdaptor::upgradeScene(pDocumentProxy, index);
}
pDocumentProxy->setMetaData(UBSettings::documentVersion, UBSettings::currentFileVersion);
UBMetadataDcSubsetAdaptor::persist(pDocumentProxy);
}
void UBPersistenceManager::upgradeAllDocumentsIfNeeded()
{
foreach(QPointer<UBDocumentProxy> proxy, documentProxies)
{
upgradeDocumentIfNeeded(proxy);
}
}
UBDocumentProxy* UBPersistenceManager::documentByUuid(const QUuid& pUuid)
{
for(int i = 0 ; i < documentProxies.length(); i++)
@ -935,3 +906,20 @@ void UBPersistenceManager::checkIfDocumentRepositoryExists()
UBApplication::quit();
}
}
void UBPersistenceManager::shiftPagesToStartWithTheZeroOne(QString persistencePath)
{
if(!QFile(persistencePath + "/page000.svg").exists() && QFile(persistencePath + "/page001.svg").exists()){
int i = 1;
while(QFile(persistencePath + UBFileSystemUtils::digitFileFormat("/page%1.svg",i)).exists()){
QFile svg(persistencePath + UBFileSystemUtils::digitFileFormat("/page%1.svg", i));
svg.rename(persistencePath + UBFileSystemUtils::digitFileFormat("/page%1.svg", i-1));
QFile thumb(persistencePath + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", i));
thumb.rename(persistencePath + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", i-1));
i+=1;
}
}
}

@ -50,12 +50,13 @@ class UBPersistenceManager : public QObject
static const QString audioDirectory;
static const QString widgetDirectory;
static const QString teacherGuideDirectory;
static void shiftPagesToStartWithTheZeroOne(QString persistencePath);
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, bool addTitlePage = false);
virtual UBDocumentProxy* createDocumentFromDir(const QString& pDocumentDirectory, const QString& pGroupName = "", const QString& pName = "");
virtual UBDocumentProxy* persistDocumentMetadata(UBDocumentProxy* pDocumentProxy);
@ -92,10 +93,6 @@ class UBPersistenceManager : public QObject
bool addDirectoryContentToDocument(const QString& documentRootFolder, UBDocumentProxy* pDocument);
virtual void upgradeDocumentIfNeeded(UBDocumentProxy* pDocumentProxy);
virtual void upgradeAllDocumentsIfNeeded();
virtual UBDocumentProxy* documentByUuid(const QUuid& pUuid);
QStringList documentSubDirectories()
@ -110,9 +107,6 @@ class UBPersistenceManager : public QObject
bool addFileToDocument(UBDocumentProxy* pDocumentProxy, QString path, const QString& subdir, QUuid objectUuid, QString& destinationPath, QByteArray* data = NULL);
signals:
void proxyListChanged();
void documentCreated(UBDocumentProxy* pDocumentProxy);
void documentMetadataChanged(UBDocumentProxy* pDocumentProxy);
void documentWillBeDeleted(UBDocumentProxy* pDocumentProxy);

@ -818,6 +818,7 @@ void UBDocumentController::loadDocumentProxies()
{
QString docGroup = proxy->metaData(UBSettings::documentGroupName).toString();
bool isEmptyGroupName = false;
bool isInTrash = false;

Loading…
Cancel
Save