page zero issue after importing documents using the Importer program

preferencesAboutTextFull
Claudio Valerio 12 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; return NULL;
} }
UBDocumentProxy* newDocument = UBPersistenceManager::persistenceManager()->createDocumentFromDir(documentRootFolder, pGroup, "", false, false); UBDocumentProxy* newDocument = UBPersistenceManager::persistenceManager()->createDocumentFromDir(documentRootFolder, pGroup, "");
UBApplication::showMessage(tr("Import successful.")); UBApplication::showMessage(tr("Import successful."));
return newDocument; return newDocument;
} }

@ -65,7 +65,7 @@ UBPersistenceManager::UBPersistenceManager(QObject *pParent)
mDocumentSubDirectories << audioDirectory; mDocumentSubDirectories << audioDirectory;
documentProxies = allDocumentProxies(); documentProxies = allDocumentProxies();
emit proxyListChanged();
} }
UBPersistenceManager* UBPersistenceManager::persistenceManager() UBPersistenceManager* UBPersistenceManager::persistenceManager()
@ -102,6 +102,13 @@ QList<QPointer<UBDocumentProxy> > UBPersistenceManager::allDocumentProxies()
rootDir.mkpath(rootDir.path()); 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); QFileSystemWatcher* watcher = new QFileSystemWatcher(this);
watcher->addPath(mDocumentRepositoryPath); watcher->addPath(mDocumentRepositoryPath);
@ -109,8 +116,7 @@ QList<QPointer<UBDocumentProxy> > UBPersistenceManager::allDocumentProxies()
QList<QPointer<UBDocumentProxy> > proxies; QList<QPointer<UBDocumentProxy> > proxies;
foreach(QString path, rootDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, foreach(QString path, dirList)
QDir::Time | QDir::Reversed))
{ {
QString fullPath = rootDir.path() + "/" + path; QString fullPath = rootDir.path() + "/" + path;
@ -257,8 +263,6 @@ UBDocumentProxy* UBPersistenceManager::createDocument(const QString& pGroupName,
documentProxies.insert(0, QPointer<UBDocumentProxy>(doc)); documentProxies.insert(0, QPointer<UBDocumentProxy>(doc));
emit proxyListChanged();
emit documentCreated(doc); emit documentCreated(doc);
mDocumentCreatedDuringSession << doc; mDocumentCreatedDuringSession << doc;
@ -266,7 +270,7 @@ UBDocumentProxy* UBPersistenceManager::createDocument(const QString& pGroupName,
return doc; 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(); checkIfDocumentRepositoryExists();
@ -281,8 +285,6 @@ UBDocumentProxy* UBPersistenceManager::createDocumentFromDir(const QString& pDoc
{ {
doc->setMetaData(UBSettings::documentName, pName); 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); QMap<QString, QVariant> metadatas = UBMetadataDcSubsetAdaptor::load(pDocumentDirectory);
@ -303,7 +305,6 @@ UBDocumentProxy* UBPersistenceManager::createDocumentFromDir(const QString& pDoc
documentProxies << QPointer<UBDocumentProxy>(doc); documentProxies << QPointer<UBDocumentProxy>(doc);
emit proxyListChanged();
emit documentCreated(doc); emit documentCreated(doc);
@ -326,8 +327,6 @@ void UBPersistenceManager::deleteDocument(UBDocumentProxy* pDocumentProxy)
pDocumentProxy->deleteLater(); pDocumentProxy->deleteLater();
emit proxyListChanged();
} }
@ -363,8 +362,6 @@ UBDocumentProxy* UBPersistenceManager::duplicateDocument(UBDocumentProxy* pDocum
documentProxies << QPointer<UBDocumentProxy>(copy); documentProxies << QPointer<UBDocumentProxy>(copy);
emit proxyListChanged();
emit documentCreated(copy); emit documentCreated(copy);
return copy; return copy;
@ -652,7 +649,6 @@ void UBPersistenceManager::copyPage(UBDocumentProxy* pDocumentProxy, const int s
int UBPersistenceManager::sceneCount(const UBDocumentProxy* proxy) int UBPersistenceManager::sceneCount(const UBDocumentProxy* proxy)
{ {
const QString pPath = proxy->persistencePath(); const QString pPath = proxy->persistencePath();
int pageIndex = 0; int pageIndex = 0;
bool moreToProcess = true; 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) UBDocumentProxy* UBPersistenceManager::documentByUuid(const QUuid& pUuid)
{ {
for(int i = 0 ; i < documentProxies.length(); i++) for(int i = 0 ; i < documentProxies.length(); i++)
@ -935,3 +906,20 @@ void UBPersistenceManager::checkIfDocumentRepositoryExists()
UBApplication::quit(); 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 audioDirectory;
static const QString widgetDirectory; static const QString widgetDirectory;
static const QString teacherGuideDirectory; static const QString teacherGuideDirectory;
static void shiftPagesToStartWithTheZeroOne(QString persistencePath);
static UBPersistenceManager* persistenceManager(); static UBPersistenceManager* persistenceManager();
static void destroy(); static void destroy();
virtual UBDocumentProxy* createDocument(const QString& pGroupName = "", const QString& pName = "", bool withEmptyPage = true); 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); virtual UBDocumentProxy* persistDocumentMetadata(UBDocumentProxy* pDocumentProxy);
@ -92,10 +93,6 @@ class UBPersistenceManager : public QObject
bool addDirectoryContentToDocument(const QString& documentRootFolder, UBDocumentProxy* pDocument); bool addDirectoryContentToDocument(const QString& documentRootFolder, UBDocumentProxy* pDocument);
virtual void upgradeDocumentIfNeeded(UBDocumentProxy* pDocumentProxy);
virtual void upgradeAllDocumentsIfNeeded();
virtual UBDocumentProxy* documentByUuid(const QUuid& pUuid); virtual UBDocumentProxy* documentByUuid(const QUuid& pUuid);
QStringList documentSubDirectories() 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); bool addFileToDocument(UBDocumentProxy* pDocumentProxy, QString path, const QString& subdir, QUuid objectUuid, QString& destinationPath, QByteArray* data = NULL);
signals: signals:
void proxyListChanged();
void documentCreated(UBDocumentProxy* pDocumentProxy); void documentCreated(UBDocumentProxy* pDocumentProxy);
void documentMetadataChanged(UBDocumentProxy* pDocumentProxy); void documentMetadataChanged(UBDocumentProxy* pDocumentProxy);
void documentWillBeDeleted(UBDocumentProxy* pDocumentProxy); void documentWillBeDeleted(UBDocumentProxy* pDocumentProxy);

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

Loading…
Cancel
Save