subsurface/core/settings
jan Iversen ee6b5643b5 core/settings: only sync values that are actually changed
Add a variable reflecting the current_state to all DISK_* macros, in order to
check if the original variable in struct preferences is changed.

Only save to disk if actually changed

[Dirk Hohndel: merged Jan's commit and renamed the variable and adjusted the
               commit message... but fundamentally the commit is still what Jan
               wrote, so he should get the credit]

Signed-off-by: Jan Iversen <jani@apache.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-09-07 14:37:18 -07:00
..
qPref.cpp core/tests: merge Animations and add vars. to qPrefDisplay 2018-08-25 11:49:47 -07:00
qPref.h core/tests: merge Animations and add vars. to qPrefDisplay 2018-08-25 11:49:47 -07:00
qPrefCloudStorage.cpp qPref: use helper function to ensure key/name grouping 2018-09-07 14:37:18 -07:00
qPrefCloudStorage.h Revert "core/tests: add loadFromCloud var to qPrefCloudStorage" 2018-09-06 17:14:48 -07:00
qPrefDisplay.cpp qPref: use helper function to ensure key/name grouping 2018-09-07 14:37:18 -07:00
qPrefDisplay.h core/tests: merge Animations and add vars. to qPrefDisplay 2018-08-25 11:49:47 -07:00
qPrefDiveComputer.cpp qPref: use helper function to ensure key/name grouping 2018-09-07 14:37:18 -07:00
qPrefDiveComputer.h core: make methods in qPref* static 2018-08-15 16:11:39 -07:00
qPrefDivePlanner.cpp qPref: use helper function to ensure key/name grouping 2018-09-07 14:37:18 -07:00
qPrefDivePlanner.h core: make methods in qPref* static 2018-08-15 16:11:39 -07:00
qPrefFacebook.cpp core: make methods in qPrefPrivate static 2018-08-25 11:49:47 -07:00
qPrefFacebook.h core: make methods in qPref* static 2018-08-15 16:11:39 -07:00
qPrefGeneral.cpp qPref: use helper function to ensure key/name grouping 2018-09-07 14:37:18 -07:00
qPrefGeneral.h core/tests: add class var to qPrefGeneral 2018-08-25 11:49:47 -07:00
qPrefGeocoding.cpp qPref: use helper function to ensure key/name grouping 2018-09-07 14:37:18 -07:00
qPrefGeocoding.h core: make methods in qPref* static 2018-08-15 16:11:39 -07:00
qPrefLanguage.cpp qPref: use helper function to ensure key/name grouping 2018-09-07 14:37:18 -07:00
qPrefLanguage.h core: make methods in qPref* static 2018-08-15 16:11:39 -07:00
qPrefLocationService.cpp qPref: use helper function to ensure key/name grouping 2018-09-07 14:37:18 -07:00
qPrefLocationService.h core: make methods in qPref* static 2018-08-15 16:11:39 -07:00
qPrefPartialPressureGas.cpp qPref: use helper function to ensure key/name grouping 2018-09-07 14:37:18 -07:00
qPrefPartialPressureGas.h core: make methods in qPref* static 2018-08-15 16:11:39 -07:00
qPrefPrivate.cpp qPref: use helper function to ensure key/name grouping 2018-09-07 14:37:18 -07:00
qPrefPrivate.h core/settings: only sync values that are actually changed 2018-09-07 14:37:18 -07:00
qPrefProxy.cpp qPref: use helper function to ensure key/name grouping 2018-09-07 14:37:18 -07:00
qPrefProxy.h core: make methods in qPref* static 2018-08-15 16:11:39 -07:00
qPrefTechnicalDetails.cpp qPref: use helper function to ensure key/name grouping 2018-09-07 14:37:18 -07:00
qPrefTechnicalDetails.h core: make methods in qPref* static 2018-08-15 16:11:39 -07:00
qPrefUnit.cpp qPref: use helper function to ensure key/name grouping 2018-09-07 14:37:18 -07:00
qPrefUnit.h core: make methods in qPref* static 2018-08-15 16:11:39 -07:00
qPrefUpdateManager.cpp qPref: use helper function to ensure key/name grouping 2018-09-07 14:37:18 -07:00
qPrefUpdateManager.h core/tests: add uuidString to qPrefUpdateManager 2018-08-25 11:49:47 -07:00
README.md core/settings: add README 2018-08-30 05:36:36 -07:00

Short explanation of how qPref works

System startup:

core/qt-init.cpp init_qt_late()

does

qPref::load();

to load all properties from all qPref* classes

System shutdown:

subsurface-mobile-main.cpp and subsurface-desktop-main.cpp main()

calls

call qPref::sync()

to save all changes to disk, this is needed because part of the program modifies struct preferences instead of calling the set method.

EXCEPTION:

Variables not present in struct preferences (local static variables in the class are not written, see later.

System startup/shutdown common handling:

qPref::load() calls qPref::doSync(false)
qPref::sync() calls qPref::doSync(true)

qPrefDoSync()

qPref::doSync() calls qPref::doSync() for all qPref* classes Meaning qPref knows which classes exist, but not which variables

qPref*::doSync() calls

disk_<variable name>() for each variable

EXCEPTION:

some variables are not in struct preferences, but local static variables which can only be accessed through the set/get functions, therefore there are no need to sync them

	if (!doSync) // meaining load
		load_<variable_name>()

qPref*::disk_*()

qPref*::disk_*() calls qPrefPrivate::propSetValue to save a property, and qPrefPrivate::propValue() to read a property. The function also keeps struct preferences in sync.

qPrefPrivate::propSetValue()

qPrefPrivate::propSetValue() is static and calls QSettings to write property

qPrefPrivate::propValue()

qPrefPrivate::propValue() is static and calls QSettings to read property

macros

the macros are defined in qPrefPrivate.h

the macros are used in qPref*cpp

Reading properties

Reading a property is done through an inline function, and thus no more expensive than accessing the variable directly.

qPref*::<variable_name>()

Setting properties

Setting a property is done through a dedicated set function which are static to simplify the call:

qPref<class>::set_<variable_name>(value)

like:

qPrefDisplay::animation_speed(500);

the set function updates struct preferences (if not a local variable), and saves the property to disk, however save is only done if the variable is changed.

Updating struct preferences

When a program part updates struct preferences directly, changes are NOT saved to disk if the programm crashes, otherwise all variables are saved to disk with the program exists.