Save metadata.rdf less often

The documents' metadata.rdf file is now persisted only when a scene in
the document is also persisted; as well as when the document is modified
(trashed / path changed) in the the Documents pane.

Code was cleaned-up a bit too (added a forgotten return value, etc)
preferencesAboutTextFull
Craig Watson 9 years ago
parent 59207cbbf2
commit 11b9bf74fb
  1. 2
      src/adaptors/UBMetadataDcSubsetAdaptor.cpp
  2. 19
      src/core/UBPersistenceManager.cpp
  3. 15
      src/document/UBDocumentController.cpp
  4. 11
      src/document/UBDocumentProxy.cpp
  5. 4
      src/document/UBDocumentProxy.h

@ -86,7 +86,7 @@ void UBMetadataDcSubsetAdaptor::persist(UBDocumentProxy* proxy)
return; return;
} }
QString fileName = proxy->persistencePath() + "/" + metadataFilename; QString fileName = proxy->persistencePath() + "/" + metadataFilename;
qWarning() << "Persisting document path is" << fileName; qWarning() << "Persisting document; path is" << fileName;
QFile file(fileName); QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
{ {

@ -211,13 +211,6 @@ QList<QPointer<UBDocumentProxy> > UBPersistenceManager::allDocumentProxies()
{ {
UBDocumentProxy* proxy = new UBDocumentProxy(fullPath); // deleted in UBPersistenceManager::destructor UBDocumentProxy* proxy = new UBDocumentProxy(fullPath); // deleted in UBPersistenceManager::destructor
QMap<QString, QVariant> metadatas = UBMetadataDcSubsetAdaptor::load(fullPath);
foreach(QString key, metadatas.keys())
{
proxy->setMetaData(key, metadatas.value(key));
}
proxy->setPageCount(sceneCount(proxy)); proxy->setPageCount(sceneCount(proxy));
proxies << QPointer<UBDocumentProxy>(proxy); proxies << QPointer<UBDocumentProxy>(proxy);
@ -376,13 +369,6 @@ UBDocumentProxy* UBPersistenceManager::createDocumentFromDir(const QString& pDoc
doc->setMetaData(UBSettings::documentName, pName); doc->setMetaData(UBSettings::documentName, pName);
} }
QMap<QString, QVariant> metadatas = UBMetadataDcSubsetAdaptor::load(pDocumentDirectory);
foreach(QString key, metadatas.keys())
{
doc->setMetaData(key, metadatas.value(key));
}
doc->setUuid(QUuid::createUuid()); doc->setUuid(QUuid::createUuid());
doc->setPageCount(sceneCount(doc)); doc->setPageCount(sceneCount(doc));
@ -775,11 +761,12 @@ void UBPersistenceManager::persistDocumentScene(UBDocumentProxy* pDocumentProxy,
mSceneCache.insert(pDocumentProxy, pSceneIndex, pScene); mSceneCache.insert(pDocumentProxy, pSceneIndex, pScene);
if (pScene->isModified())
{
//qDebug() << "Persisting scene";
if (pDocumentProxy->isModified()) if (pDocumentProxy->isModified())
persistDocumentMetadata(pDocumentProxy, forceImmediateSaving); persistDocumentMetadata(pDocumentProxy, forceImmediateSaving);
if (pScene->isModified())
{
UBThumbnailAdaptor::persistScene(pDocumentProxy, pScene, pSceneIndex); UBThumbnailAdaptor::persistScene(pDocumentProxy, pScene, pSceneIndex);
if(forceImmediateSaving) if(forceImmediateSaving)
UBSvgSubsetAdaptor::persistScene(pDocumentProxy,pScene,pSceneIndex); UBSvgSubsetAdaptor::persistScene(pDocumentProxy,pScene,pSceneIndex);

@ -517,7 +517,6 @@ void UBDocumentController::duplicateSelectedItem()
duplicatePages(selectedSceneIndexes); duplicatePages(selectedSceneIndexes);
emit documentThumbnailsUpdated(this); emit documentThumbnailsUpdated(this);
selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(selectedDocument());
mDocumentUI->thumbnailWidget->selectItemAt(selectedSceneIndexes.last() + selectedSceneIndexes.size()); mDocumentUI->thumbnailWidget->selectItemAt(selectedSceneIndexes.last() + selectedSceneIndexes.size());
} }
} }
@ -534,7 +533,6 @@ void UBDocumentController::duplicateSelectedItem()
UBDocumentProxy* duplicatedDoc = UBPersistenceManager::persistenceManager()->duplicateDocument(source); UBDocumentProxy* duplicatedDoc = UBPersistenceManager::persistenceManager()->duplicateDocument(source);
duplicatedDoc->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); duplicatedDoc->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(duplicatedDoc);
selectDocument(duplicatedDoc, false); selectDocument(duplicatedDoc, false);
@ -995,13 +993,7 @@ void UBDocumentController::itemChanged(QTreeWidgetItem * item, int column)
, this, SLOT(updateDocumentInTree(UBDocumentProxy*))); , this, SLOT(updateDocumentInTree(UBDocumentProxy*)));
if (proxyItem) if (proxyItem)
{
if (proxyItem->proxy()->metaData(UBSettings::documentName).toString() != item->text(column))
{
proxyItem->proxy()->setMetaData(UBSettings::documentName, item->text(column)); proxyItem->proxy()->setMetaData(UBSettings::documentName, item->text(column));
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(proxyItem->proxy());
}
}
else else
{ {
// it is a group // it is a group
@ -1017,7 +1009,6 @@ void UBDocumentController::itemChanged(QTreeWidgetItem * item, int column)
if (0 != (item->flags() & Qt::ItemIsEditable)) if (0 != (item->flags() & Qt::ItemIsEditable))
{ {
childItem->proxy()->setMetaData(UBSettings::documentGroupName, item->text(column)); childItem->proxy()->setMetaData(UBSettings::documentGroupName, item->text(column));
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(childItem->proxy());
} }
} }
} }
@ -1104,7 +1095,6 @@ void UBDocumentController::addFolderOfImages()
else else
{ {
document->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); document->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(document);
reloadThumbnails(); reloadThumbnails();
} }
} }
@ -1150,7 +1140,6 @@ bool UBDocumentController::addFileToDocument(UBDocumentProxy* document)
if (success) if (success)
{ {
document->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); document->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(document);
} }
else else
{ {
@ -1169,7 +1158,6 @@ void UBDocumentController::moveSceneToIndex(UBDocumentProxy* proxy, int source,
if (UBDocumentContainer::movePageToIndex(source, target)) if (UBDocumentContainer::movePageToIndex(source, target))
{ {
proxy->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); proxy->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(proxy);
mDocumentUI->thumbnailWidget->hightlightItem(target); mDocumentUI->thumbnailWidget->hightlightItem(target);
} }
@ -1497,7 +1485,6 @@ void UBDocumentController::addToDocument()
mDocumentUI->thumbnailWidget->selectItemAt(newActiveSceneIndex, false); mDocumentUI->thumbnailWidget->selectItemAt(newActiveSceneIndex, false);
selectDocument(mBoardController->selectedDocument()); selectDocument(mBoardController->selectedDocument());
mBoardController->selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); mBoardController->selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(mBoardController->selectedDocument());
UBApplication::applicationController->showBoard(); UBApplication::applicationController->showBoard();
} }
@ -1678,7 +1665,6 @@ void UBDocumentController::addImages()
else else
{ {
document->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); document->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(document);
reloadThumbnails(); reloadThumbnails();
} }
} }
@ -1791,7 +1777,6 @@ void UBDocumentController::deletePages(QList<QGraphicsItem *> itemsToDelete)
UBDocumentContainer::deletePages(sceneIndexes); UBDocumentContainer::deletePages(sceneIndexes);
proxy->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); proxy->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBPersistenceManager::persistenceManager()->persistDocumentMetadata(proxy);
int minIndex = proxy->pageCount() - 1; int minIndex = proxy->pageCount() - 1;
foreach (int i, sceneIndexes) foreach (int i, sceneIndexes)

@ -33,9 +33,10 @@
#include "core/UBPersistenceManager.h" #include "core/UBPersistenceManager.h"
#include "core/UBSettings.h" #include "core/UBSettings.h"
#include "core/UBDocumentManager.h" #include "core/UBDocumentManager.h"
#include "core/memcheck.h" #include "core/memcheck.h"
#include "adaptors/UBMetadataDcSubsetAdaptor.h"
UBDocumentProxy::UBDocumentProxy() UBDocumentProxy::UBDocumentProxy()
: mPageCount(0) : mPageCount(0)
{ {
@ -48,6 +49,8 @@ UBDocumentProxy::UBDocumentProxy(const QString& pPersistancePath)
{ {
init(); init();
setPersistencePath(pPersistancePath); setPersistencePath(pPersistancePath);
mMetaDatas = UBMetadataDcSubsetAdaptor::load(pPersistancePath);
} }
@ -74,9 +77,11 @@ UBDocumentProxy* UBDocumentProxy::deepCopy() const
UBDocumentProxy* copy = new UBDocumentProxy(); UBDocumentProxy* copy = new UBDocumentProxy();
copy->mPersistencePath = QString(mPersistencePath); copy->mPersistencePath = QString(mPersistencePath);
copy->mMetaDatas = QHash<QString, QVariant>(mMetaDatas); copy->mMetaDatas = QMap<QString, QVariant>(mMetaDatas);
copy->mIsModified = mIsModified; copy->mIsModified = mIsModified;
copy->mPageCount = mPageCount; copy->mPageCount = mPageCount;
return copy;
} }
@ -164,7 +169,7 @@ QVariant UBDocumentProxy::metaData(const QString& pKey) const
} }
} }
QHash<QString, QVariant> UBDocumentProxy::metaDatas() const QMap<QString, QVariant> UBDocumentProxy::metaDatas() const
{ {
return mMetaDatas; return mMetaDatas;
} }

@ -57,7 +57,7 @@ class UBDocumentProxy : public QObject
void setMetaData(const QString& pKey , const QVariant& pValue); void setMetaData(const QString& pKey , const QVariant& pValue);
QVariant metaData(const QString& pKey) const; QVariant metaData(const QString& pKey) const;
QHash<QString, QVariant> metaDatas() const; QMap<QString, QVariant> metaDatas() const;
QString name() const; QString name() const;
QString groupName() const; QString groupName() const;
@ -88,7 +88,7 @@ class UBDocumentProxy : public QObject
QString mPersistencePath; QString mPersistencePath;
QHash<QString, QVariant> mMetaDatas; QMap<QString, QVariant> mMetaDatas;
bool mIsModified; bool mIsModified;

Loading…
Cancel
Save