Merge branch 'craig-dev' into dev

Merging of the new settings and metadata saving feature into the main
development branch
preferencesAboutTextFull
Craig Watson 8 years ago
commit 7ca7dd2c87
  1. 2
      src/adaptors/UBMetadataDcSubsetAdaptor.cpp
  2. 3
      src/board/UBBoardController.cpp
  3. 77
      src/core/UBPersistenceManager.cpp
  4. 3
      src/core/UBPersistenceManager.h
  5. 16
      src/core/UBPersistenceWorker.cpp
  6. 5
      src/core/UBPersistenceWorker.h
  7. 5
      src/core/UBSetting.h
  8. 160
      src/core/UBSettings.cpp
  9. 9
      src/core/UBSettings.h
  10. 17
      src/document/UBDocumentController.cpp
  11. 19
      src/document/UBDocumentProxy.cpp
  12. 6
      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))
{ {

@ -1552,7 +1552,7 @@ void UBBoardController::moveSceneToIndex(int source, int target)
UBDocumentContainer::movePageToIndex(source, target); UBDocumentContainer::movePageToIndex(source, target);
selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); selectedDocument()->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime()));
UBMetadataDcSubsetAdaptor::persist(selectedDocument()); UBPersistenceManager::persistenceManager()->persistDocumentMetadata(selectedDocument());
mMovingSceneIndex = source; mMovingSceneIndex = source;
setActiveDocumentScene(target); setActiveDocumentScene(target);
mMovingSceneIndex = -1; mMovingSceneIndex = -1;
@ -1777,6 +1777,7 @@ void UBBoardController::autosaveTimeout()
} }
saveData(sf_showProgress); saveData(sf_showProgress);
UBSettings::settings()->save();
} }
void UBBoardController::appMainModeChanged(UBApplicationController::MainMode md) void UBBoardController::appMainModeChanged(UBApplicationController::MainMode md)

@ -79,14 +79,33 @@ UBPersistenceManager::UBPersistenceManager(QObject *pParent)
mThread = new QThread; mThread = new QThread;
mWorker = new UBPersistenceWorker(); mWorker = new UBPersistenceWorker();
mWorker->moveToThread(mThread); mWorker->moveToThread(mThread);
connect(mWorker, SIGNAL(error(QString)), this, SLOT(errorString(QString))); connect(mWorker, SIGNAL(error(QString)),
connect(mThread, SIGNAL(started()), mWorker, SLOT(process())); this, SLOT(errorString(QString)));
connect(mWorker, SIGNAL(finished()), mThread, SLOT(quit()));
connect(mWorker, SIGNAL(finished()), this, SLOT(onWorkerFinished())); connect(mThread, SIGNAL(started()),
connect(mWorker, SIGNAL(finished()), mWorker, SLOT(deleteLater())); mWorker, SLOT(process()));
connect(mThread, SIGNAL(finished()), mThread, SLOT(deleteLater()));
connect(mWorker,SIGNAL(sceneLoaded(QByteArray,UBDocumentProxy*,int)),this,SLOT(onSceneLoaded(QByteArray,UBDocumentProxy*,int))); connect(mWorker, SIGNAL(finished()),
connect(mWorker,SIGNAL(scenePersisted(UBGraphicsScene*)),this,SLOT(onScenePersisted(UBGraphicsScene*))); mThread, SLOT(quit()));
connect(mWorker, SIGNAL(finished()),
this, SLOT(onWorkerFinished()));
connect(mWorker, SIGNAL(finished()),
mWorker, SLOT(deleteLater()));
connect(mThread, SIGNAL(finished()),
mThread, SLOT(deleteLater()));
connect(mWorker, SIGNAL(sceneLoaded(QByteArray,UBDocumentProxy*,int)),
this, SLOT(onSceneLoaded(QByteArray,UBDocumentProxy*,int)));
connect(mWorker, SIGNAL(scenePersisted(UBGraphicsScene*)),
this, SLOT(onScenePersisted(UBGraphicsScene*)));
connect(mWorker, SIGNAL(metadataPersisted(UBDocumentProxy*)),
this, SLOT(onMetadataPersisted(UBDocumentProxy*)));
mThread->start(); mThread->start();
} }
@ -114,6 +133,11 @@ void UBPersistenceManager::onScenePersisted(UBGraphicsScene* scene)
scene = NULL; scene = NULL;
} }
void UBPersistenceManager::onMetadataPersisted(UBDocumentProxy* proxy)
{
delete proxy;
}
void UBPersistenceManager::onWorkerFinished() void UBPersistenceManager::onWorkerFinished()
{ {
mIsWorkerFinished = true; mIsWorkerFinished = true;
@ -187,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);
@ -352,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));
@ -751,15 +761,16 @@ void UBPersistenceManager::persistDocumentScene(UBDocumentProxy* pDocumentProxy,
mSceneCache.insert(pDocumentProxy, pSceneIndex, pScene); mSceneCache.insert(pDocumentProxy, pSceneIndex, pScene);
if (pDocumentProxy->isModified())
UBMetadataDcSubsetAdaptor::persist(pDocumentProxy);
if (pScene->isModified()) if (pScene->isModified())
{ {
//qDebug() << "Persisting scene";
if (pDocumentProxy->isModified())
persistDocumentMetadata(pDocumentProxy, forceImmediateSaving);
UBThumbnailAdaptor::persistScene(pDocumentProxy, pScene, pSceneIndex); UBThumbnailAdaptor::persistScene(pDocumentProxy, pScene, pSceneIndex);
if(forceImmediateSaving) if(forceImmediateSaving)
UBSvgSubsetAdaptor::persistScene(pDocumentProxy,pScene,pSceneIndex); UBSvgSubsetAdaptor::persistScene(pDocumentProxy,pScene,pSceneIndex);
else{ else {
UBGraphicsScene* copiedScene = pScene->sceneDeepCopy(); UBGraphicsScene* copiedScene = pScene->sceneDeepCopy();
mWorker->saveScene(pDocumentProxy, copiedScene, pSceneIndex); mWorker->saveScene(pDocumentProxy, copiedScene, pSceneIndex);
pScene->setModified(false); pScene->setModified(false);
@ -769,13 +780,17 @@ void UBPersistenceManager::persistDocumentScene(UBDocumentProxy* pDocumentProxy,
} }
UBDocumentProxy* UBPersistenceManager::persistDocumentMetadata(UBDocumentProxy* pDocumentProxy) void UBPersistenceManager::persistDocumentMetadata(UBDocumentProxy* pDocumentProxy, bool forceImmediateSaving)
{ {
UBMetadataDcSubsetAdaptor::persist(pDocumentProxy); if (forceImmediateSaving) {
UBMetadataDcSubsetAdaptor::persist(pDocumentProxy);
emit documentMetadataChanged(pDocumentProxy); emit documentMetadataChanged(pDocumentProxy);
}
return pDocumentProxy; else {
UBDocumentProxy* copy = pDocumentProxy->deepCopy();
mWorker->saveMetadata(copy);
}
} }

@ -64,7 +64,7 @@ class UBPersistenceManager : public QObject
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 = ""); virtual UBDocumentProxy* createDocumentFromDir(const QString& pDocumentDirectory, const QString& pGroupName = "", const QString& pName = "");
virtual UBDocumentProxy* persistDocumentMetadata(UBDocumentProxy* pDocumentProxy); virtual void persistDocumentMetadata(UBDocumentProxy* pDocumentProxy, bool forceImmediateSaving = false);
virtual UBDocumentProxy* duplicateDocument(UBDocumentProxy* pDocumentProxy); virtual UBDocumentProxy* duplicateDocument(UBDocumentProxy* pDocumentProxy);
@ -161,6 +161,7 @@ class UBPersistenceManager : public QObject
void onSceneLoaded(QByteArray,UBDocumentProxy*,int); void onSceneLoaded(QByteArray,UBDocumentProxy*,int);
void onWorkerFinished(); void onWorkerFinished();
void onScenePersisted(UBGraphicsScene* scene); void onScenePersisted(UBGraphicsScene* scene);
void onMetadataPersisted(UBDocumentProxy* proxy);
}; };

@ -25,6 +25,7 @@
#include "UBPersistenceWorker.h" #include "UBPersistenceWorker.h"
#include "adaptors/UBSvgSubsetAdaptor.h" #include "adaptors/UBSvgSubsetAdaptor.h"
#include "adaptors/UBThumbnailAdaptor.h" #include "adaptors/UBThumbnailAdaptor.h"
#include "adaptors/UBMetadataDcSubsetAdaptor.h"
UBPersistenceWorker::UBPersistenceWorker(QObject *parent) : UBPersistenceWorker::UBPersistenceWorker(QObject *parent) :
QObject(parent) QObject(parent)
@ -48,6 +49,13 @@ void UBPersistenceWorker::readScene(UBDocumentProxy* proxy, const int pageIndex)
mSemaphore.release(); mSemaphore.release();
} }
void UBPersistenceWorker::saveMetadata(UBDocumentProxy *proxy)
{
PersistenceInformation entry = {WriteMetadata, proxy, NULL, 0};
saves.append(entry);
mSemaphore.release();
}
void UBPersistenceWorker::applicationWillClose() void UBPersistenceWorker::applicationWillClose()
{ {
qDebug() << "applicaiton Will close signal received"; qDebug() << "applicaiton Will close signal received";
@ -65,9 +73,15 @@ void UBPersistenceWorker::process()
UBSvgSubsetAdaptor::persistScene(info.proxy, info.scene, info.sceneIndex); UBSvgSubsetAdaptor::persistScene(info.proxy, info.scene, info.sceneIndex);
emit scenePersisted(info.scene); emit scenePersisted(info.scene);
} }
else{ else if (info.action == ReadScene){
emit sceneLoaded(UBSvgSubsetAdaptor::loadSceneAsText(info.proxy,info.sceneIndex), info.proxy, info.sceneIndex); emit sceneLoaded(UBSvgSubsetAdaptor::loadSceneAsText(info.proxy,info.sceneIndex), info.proxy, info.sceneIndex);
} }
else if (info.action == WriteMetadata) {
if (info.proxy->isModified()) {
UBMetadataDcSubsetAdaptor::persist(info.proxy);
emit metadataPersisted(info.proxy);
}
}
mSemaphore.acquire(); mSemaphore.acquire();
}while(!mReceivedApplicationClosing); }while(!mReceivedApplicationClosing);
qDebug() << "process will stop"; qDebug() << "process will stop";

@ -32,7 +32,8 @@
typedef enum{ typedef enum{
WriteScene = 0, WriteScene = 0,
ReadScene ReadScene,
WriteMetadata
}ActionType; }ActionType;
typedef struct{ typedef struct{
@ -50,12 +51,14 @@ public:
void saveScene(UBDocumentProxy* proxy, UBGraphicsScene* scene, const int pageIndex); void saveScene(UBDocumentProxy* proxy, UBGraphicsScene* scene, const int pageIndex);
void readScene(UBDocumentProxy* proxy, const int pageIndex); void readScene(UBDocumentProxy* proxy, const int pageIndex);
void saveMetadata(UBDocumentProxy* proxy);
signals: signals:
void finished(); void finished();
void error(QString string); void error(QString string);
void sceneLoaded(QByteArray text,UBDocumentProxy* proxy, const int pageIndex); void sceneLoaded(QByteArray text,UBDocumentProxy* proxy, const int pageIndex);
void scenePersisted(UBGraphicsScene* scene); void scenePersisted(UBGraphicsScene* scene);
void metadataPersisted(UBDocumentProxy* proxy);
public slots: public slots:
void process(); void process();

@ -62,6 +62,11 @@ class UBSetting : public QObject
return mPath; return mPath;
} }
virtual QVariant defaultValue() const
{
return mDefaultValue;
}
public slots: public slots:
void setBool(bool pValue); void setBool(bool pValue);

@ -118,8 +118,10 @@ QString UBSettings::appPingMessage = "__uniboard_ping";
UBSettings* UBSettings::settings() UBSettings* UBSettings::settings()
{ {
if (!sSingleton) if (!sSingleton) {
sSingleton = new UBSettings(qApp); sSingleton = new UBSettings(qApp);
sSingleton->load();
}
return sSingleton; return sSingleton;
} }
@ -146,9 +148,10 @@ QSettings* UBSettings::getAppSettings()
UBSettings::sAppSettings = new QSettings(appSettings, QSettings::IniFormat, 0); UBSettings::sAppSettings = new QSettings(appSettings, QSettings::IniFormat, 0);
UBSettings::sAppSettings->setIniCodec("utf-8"); UBSettings::sAppSettings->setIniCodec("utf-8");
qDebug() << "sAppSettings location: " << appSettings;
} }
qDebug() << "sAppSettings" << sAppSettings;
return UBSettings::sAppSettings; return UBSettings::sAppSettings;
} }
@ -223,13 +226,13 @@ void UBSettings::init()
appPreferredLanguage = new UBSetting(this,"App","PreferredLanguage", ""); appPreferredLanguage = new UBSetting(this,"App","PreferredLanguage", "");
rightLibPaletteBoardModeWidth = new UBSetting(this, "Board", "RightLibPaletteBoardModeWidth", 270); rightLibPaletteBoardModeWidth = new UBSetting(this, "Board", "RightLibPaletteBoardModeWidth", 270);
rightLibPaletteBoardModeIsCollapsed = new UBSetting(this,"Board", "RightLibPaletteBoardModeIsCollapsed",false); rightLibPaletteBoardModeIsCollapsed = new UBSetting(this,"Board", "RightLibPaletteBoardModeIsCollapsed",true);
rightLibPaletteDesktopModeWidth = new UBSetting(this, "Board", "RightLibPaletteDesktopModeWidth", 270); rightLibPaletteDesktopModeWidth = new UBSetting(this, "Board", "RightLibPaletteDesktopModeWidth", 270);
rightLibPaletteDesktopModeIsCollapsed = new UBSetting(this,"Board", "RightLibPaletteDesktopModeIsCollapsed",false); rightLibPaletteDesktopModeIsCollapsed = new UBSetting(this,"Board", "RightLibPaletteDesktopModeIsCollapsed",true);
leftLibPaletteBoardModeWidth = new UBSetting(this, "Board", "LeftLibPaletteBoardModeWidth",270); leftLibPaletteBoardModeWidth = new UBSetting(this, "Board", "LeftLibPaletteBoardModeWidth",270);
leftLibPaletteBoardModeIsCollapsed = new UBSetting(this,"Board","LeftLibPaletteBoardModeIsCollapsed",false); leftLibPaletteBoardModeIsCollapsed = new UBSetting(this,"Board","LeftLibPaletteBoardModeIsCollapsed",true);
leftLibPaletteDesktopModeWidth = new UBSetting(this, "Board", "LeftLibPaletteDesktopModeWidth",270); leftLibPaletteDesktopModeWidth = new UBSetting(this, "Board", "LeftLibPaletteDesktopModeWidth",270);
leftLibPaletteDesktopModeIsCollapsed = new UBSetting(this,"Board","LeftLibPaletteDesktopModeIsCollapsed",false); leftLibPaletteDesktopModeIsCollapsed = new UBSetting(this,"Board","LeftLibPaletteDesktopModeIsCollapsed",true);
appIsInSoftwareUpdateProcess = new UBSetting(this, "App", "IsInSoftwareUpdateProcess", false); appIsInSoftwareUpdateProcess = new UBSetting(this, "App", "IsInSoftwareUpdateProcess", false);
appLastSessionDocumentUUID = new UBSetting(this, "App", "LastSessionDocumentUUID", ""); appLastSessionDocumentUUID = new UBSetting(this, "App", "LastSessionDocumentUUID", "");
@ -265,11 +268,11 @@ void UBSettings::init()
pageDpi = new UBSetting(this, "Board", "pageDpi", 0); pageDpi = new UBSetting(this, "Board", "pageDpi", 0);
QStringList penLightBackgroundColors; QStringList penLightBackgroundColors;
penLightBackgroundColors << "#000000" << "#FF0000" <<"#004080" << "#008000" << "#FFDD00" << "#C87400" << "#800040" << "#008080" << "#5F2D0A"; penLightBackgroundColors << "#000000" << "#FF0000" <<"#004080" << "#008000" << "#FFDD00" << "#C87400" << "#800040" << "#008080" << "#5F2D0A" << "#FFFFFF";
boardPenLightBackgroundColors = new UBColorListSetting(this, "Board", "PenLightBackgroundColors", penLightBackgroundColors, 1.0); boardPenLightBackgroundColors = new UBColorListSetting(this, "Board", "PenLightBackgroundColors", penLightBackgroundColors, 1.0);
QStringList penDarkBackgroundColors; QStringList penDarkBackgroundColors;
penDarkBackgroundColors << "#FFFFFF" << "#FF3400" <<"#66C0FF" << "#81FF5C" << "#FFFF00" << "#B68360" << "#FF497E" << "#8D69FF"; penDarkBackgroundColors << "#FFFFFF" << "#FF3400" <<"#66C0FF" << "#81FF5C" << "#FFFF00" << "#B68360" << "#FF497E" << "#8D69FF" << "#000000";
boardPenDarkBackgroundColors = new UBColorListSetting(this, "Board", "PenDarkBackgroundColors", penDarkBackgroundColors, 1.0); boardPenDarkBackgroundColors = new UBColorListSetting(this, "Board", "PenDarkBackgroundColors", penDarkBackgroundColors, 1.0);
boardMarkerAlpha = new UBSetting(this, "Board", "MarkerAlpha", 0.5); boardMarkerAlpha = new UBSetting(this, "Board", "MarkerAlpha", 0.5);
@ -418,25 +421,82 @@ void UBSettings::init()
useSystemOnScreenKeyboard = new UBSetting(this, "App", "UseSystemOnScreenKeyboard", true); useSystemOnScreenKeyboard = new UBSetting(this, "App", "UseSystemOnScreenKeyboard", true);
cleanNonPersistentSettings(); cleanNonPersistentSettings();
checkNewSettings();
} }
QVariant UBSettings::value ( const QString & key, const QVariant & defaultValue) const /**
* @brief Returns the value for the *key* setting, or *defaultValue* if the key doesn't exist
*
* The value is also added to the local settings queue, to prevent future disk I/O when accessing
* that same setting.
*
* If the value doesn't exist in the application settings (i.e it was not present in the config file),
* it is also added there.
*/
QVariant UBSettings::value ( const QString & key, const QVariant & defaultValue)
{ {
// Check first the settings queue, then the app settings, then the user settings.
// If the key exists in neither of these, then defaultValue is returned.
if (mSettingsQueue.contains(key))
return mSettingsQueue.value(key);
// If the setting doesn't exist in the App settings, add it there
if (!sAppSettings->contains(key) && !(defaultValue == QVariant())) if (!sAppSettings->contains(key) && !(defaultValue == QVariant()))
{
sAppSettings->setValue(key, defaultValue); sAppSettings->setValue(key, defaultValue);
}
return mUserSettings->value(key, sAppSettings->value(key, defaultValue)); QVariant val = mUserSettings->value(key, sAppSettings->value(key, defaultValue));
// If we got here, then the settings queue doesn't contain the value; add it
mSettingsQueue[key] = val;
return val;
} }
void UBSettings::setValue (const QString & key, const QVariant & value) void UBSettings::setValue (const QString & key, const QVariant & value)
{ {
mUserSettings->setValue(key, value); // Save the setting to the queue only; a call to save() is necessary to persist the settings
mSettingsQueue[key] = value;
}
/**
* @brief Save all the queued settings to disk
*/
void UBSettings::save()
{
QHash<QString, QVariant>::const_iterator it = mSettingsQueue.constBegin();
while (it != mSettingsQueue.constEnd()) {
mUserSettings->setValue(it.key(), it.value());
++it;
}
// Force save to file
mUserSettings->sync();
qDebug() << "User settings saved";
} }
/**
* @brief Force load all settings, to cut down on subsequent file access
*/
void UBSettings::load()
{
qDebug() << "Loading all settings";
QStringList keyList = mUserSettings->allKeys() + sAppSettings->allKeys();
keyList.removeDuplicates();
foreach(const QString& key, keyList) {
value(key);
// value() actually handles saving the value to the queue, so
// we don't need to do it here
}
}
int UBSettings::penWidthIndex() int UBSettings::penWidthIndex()
{ {
@ -1264,6 +1324,7 @@ QString UBSettings::replaceWildcard(QString& path)
void UBSettings::closing() void UBSettings::closing()
{ {
save();
cleanNonPersistentSettings(); cleanNonPersistentSettings();
} }
@ -1279,3 +1340,76 @@ void UBSettings::cleanNonPersistentSettings()
youTubeUserEMail->set(QVariant("")); youTubeUserEMail->set(QVariant(""));
} }
} }
/**
* @brief Permanently remove a setting, from local memory and config files
* @param setting The setting to remove
*/
void UBSettings::removeSetting(const QString &setting)
{
if (sAppSettings->contains(setting))
sAppSettings->remove(setting);
if (mUserSettings->contains(setting))
mUserSettings->remove(setting);
if (mSettingsQueue.contains(setting))
mSettingsQueue.remove(setting);
}
void UBSettings::checkNewSettings()
{
/*
* Some settings were modified in new versions and OpenBoard can crash
* if an old settings file is used. This function checks these settings and
* if necessary, resets them to the values initialized in UBSettings::init().
*
* Thus this method can be removed when it is no longer deemed useful.
*/
// OB 1.10 introduced an extra pen color; for simplicity, if the old settings
// are still present (i.e only 4 selected pen colors), we just reset all color settings.
// Having too few colors actually causes OpenBoard to crash, hence these measures.
QList<UBColorListSetting*> colorSettings;
colorSettings << boardPenDarkBackgroundSelectedColors
<< boardPenLightBackgroundSelectedColors
<< boardMarkerDarkBackgroundSelectedColors
<< boardMarkerLightBackgroundSelectedColors;
foreach (UBColorListSetting* setting, colorSettings) {
if (setting->colors().size() < 5)
setting->reset(); // Make sure that there are 5 selected colors
}
colorSettings.clear();
// Next we check whether all the new colors were added; i.e if some default
// colors are not also in the config file, we add them to it.
// This is not nearly as critical as the above issue, but the users (or admins) seemingly
// can't be trusted to delete or modify their own config file when upgrading, so they might
// wonder why they don't have the new colors in their app.
colorSettings << boardPenDarkBackgroundColors
<< boardPenLightBackgroundColors
<< boardMarkerDarkBackgroundColors
<< boardMarkerLightBackgroundColors;
foreach (UBColorListSetting* setting, colorSettings) {
QStringList defaultColors = qvariant_cast<QStringList>(setting->defaultValue());
QStringList currentColors(qvariant_cast<QStringList>(setting->get())); // copy
foreach (QString c, defaultColors) {
if (!currentColors.contains(c))
currentColors.append(QString(c));
}
setting->set(currentColors);
}
// A typo was corrected in version 1.10
removeSetting("Board/useSystemOnScreenKeybard");
}

@ -57,6 +57,8 @@ class UBSettings : public QObject
void InitKeyboardPaletteKeyBtnSizes(); void InitKeyboardPaletteKeyBtnSizes();
void ValidateKeyboardPaletteKeyBtnSize(); void ValidateKeyboardPaletteKeyBtnSize();
void closing(); void closing();
void save();
void load();
int penWidthIndex(); int penWidthIndex();
@ -397,7 +399,7 @@ class UBSettings : public QObject
void setPenPressureSensitive(bool sensitive); void setPenPressureSensitive(bool sensitive);
void setMarkerPressureSensitive(bool sensitive); void setMarkerPressureSensitive(bool sensitive);
QVariant value ( const QString & key, const QVariant & defaultValue = QVariant() ) const; QVariant value ( const QString & key, const QVariant & defaultValue = QVariant() );
void setValue (const QString & key,const QVariant & value); void setValue (const QString & key,const QVariant & value);
void colorChanged() { emit colorContextChanged(); } void colorChanged() { emit colorContextChanged(); }
@ -410,6 +412,8 @@ class UBSettings : public QObject
QSettings* mAppSettings; QSettings* mAppSettings;
QSettings* mUserSettings; QSettings* mUserSettings;
QHash<QString, QVariant> mSettingsQueue;
static const int sDefaultFontPixelSize; static const int sDefaultFontPixelSize;
static const char *sDefaultFontFamily; static const char *sDefaultFontFamily;
@ -421,6 +425,9 @@ class UBSettings : public QObject
static bool checkDirectory(QString& dirPath); static bool checkDirectory(QString& dirPath);
static QString replaceWildcard(QString& path); static QString replaceWildcard(QString& path);
void removeSetting(const QString& setting);
void checkNewSettings();
}; };

@ -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()));
UBMetadataDcSubsetAdaptor::persist(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()));
UBMetadataDcSubsetAdaptor::persist(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)
{ proxyItem->proxy()->setMetaData(UBSettings::documentName, item->text(column));
if (proxyItem->proxy()->metaData(UBSettings::documentName).toString() != 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()));
UBMetadataDcSubsetAdaptor::persist(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()));
UBMetadataDcSubsetAdaptor::persist(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()));
UBMetadataDcSubsetAdaptor::persist(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()));
UBMetadataDcSubsetAdaptor::persist(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()));
UBMetadataDcSubsetAdaptor::persist(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()));
UBMetadataDcSubsetAdaptor::persist(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);
} }
@ -69,6 +72,18 @@ UBDocumentProxy::~UBDocumentProxy()
// NOOP // NOOP
} }
UBDocumentProxy* UBDocumentProxy::deepCopy() const
{
UBDocumentProxy* copy = new UBDocumentProxy();
copy->mPersistencePath = QString(mPersistencePath);
copy->mMetaDatas = QMap<QString, QVariant>(mMetaDatas);
copy->mIsModified = mIsModified;
copy->mPageCount = mPageCount;
return copy;
}
int UBDocumentProxy::pageCount() int UBDocumentProxy::pageCount()
{ {
@ -154,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;
} }

@ -49,13 +49,15 @@ class UBDocumentProxy : public QObject
virtual ~UBDocumentProxy(); virtual ~UBDocumentProxy();
UBDocumentProxy * deepCopy() const;
QString persistencePath() const; QString persistencePath() const;
void setPersistencePath(const QString& pPersistencePath); void setPersistencePath(const QString& pPersistencePath);
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;
@ -86,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