Qsettings#828
Conversation
+ tests for them.
Our config file lies in such a 'weird' place that the normal mechanisms of telling QSettings about it don't work. I need to give it the exact filename when construting the QSettings instance. Since the whole point of this exercise is to get rid of the m_pConfig pointer and have a settings object easily available anywhere in mixxx I need to create this wrapper which saves the location of the config file at the start of mixxx. This way MixxxSettings instances can be created anywhere in mixxx with quick access to any setting.
This is for testing as a start. We can check that each new option appears and it will also make it easier to track progress of option settings correctly ported to the new class.
|
As this is will lead to a huge change in mixxx i'm nut sure if you want to have it in master right now. |
|
There is no capital on Windows filsystem. You should use another name. |
|
What is the original benefit of changing to QSettings? Which pending issues are solved by it? QSettings is basically a wrapper around the native config systems of our target OSs. Please note that QSettings is reentrant but not thread-safe. Our current config system is not thread-safe as well, even though it is uses from multiple threads. https://bugs.launchpad.net/mixxx/+bug/1428500 The spreading m_config can be easily fixed by tuning it into a singleton. We have to be careful consider when is the right time to switch over to a new config system, since we have to provide a migration path. IMHO we should switch to QT 5 first since the config path handling has changed between QT5 and QT4. There is also the pending user config dir bug: |
There was a problem hiding this comment.
setFallbacksEnabled is non const, we should use the pointer notation.
A reference should be always const.
There was a problem hiding this comment.
That will be solved when we use Qt5 where I can move QSettings.
tl;dr Less and better maintainable code. longer The current config-system is a pain to use. Accessing values is just plain strange. Compare the two access methods. // Old
m_pConfig->getValueString(ConfigKey("[Controls]", "Tooltips", "1").toInt()
// new
settings.value("Controls/Tooltips", true).toBool();I find the second easier to grasp and use. It relies on QVariant instead of QString as a backend to save settings which is more appropriate for this stuff. We sometimes go through weirds hops in our code an rely on automatic type conversion a lot to get the correct result. Finally it is super hard to get access to the config object in a class that does not already hold a pointer to it. You have to figure out a dependency chain to your target class and pass the pointer along the whole way. We also have to manually save the settings (QSettings does this automatically). We have to be scared that we get mismatched files when we write from different threads. QSettings would fix all of these issues.
Yes QSettings is by itself not thread-safe. But it does not need to be, neither does it need to be a singleton. The idea is that you create a QSettings object when ever you need one and destroy it afterwards, thus we don't need to pass the object around and it will ALWAYS live in just one thread.
`
Nope. It is a very generic interface to it. By default it allows to use target specific config but it can be customized to use the same formats on every platform as well as location. Which is what I have done here and also the reason why I had to create the
I setup QSettings in a way that we can use the same config-file names as before on all platforms. The filename differs right now to track changes while we port all settings to QSettings. The change can be done here
We bypass 'QSystem' completely in this PR anyway. The benefit we will get is a proper class to handle user settings inside of mixxx. It results in an easier to use settings interface and less code to maintain.
Sure you can switch to QT5 first. That would actually be nice, because I can make some of this code nicer with movable Qt-types.
Using QSettings would actually make solving this bug easier. |
Apparently Windows still hasn't come across case sensitive file-systems.
This isn't set globally but only ever for the settings I currently create.
This was a big pain to attempt to deal with for #649. |
There was a problem hiding this comment.
This is a proof of concept. No setting has been switched so far. It should only show how qsettings can be used to replace the old system and still be backwards compatible.
|
I have two concerns here:
|
Well these are two issues here.
I personally don't think we can get around the user-config being a shared state. There sure might be
I would still like that the configuration file is human readable. As this made it easier in the past to |
protocol buffers have a human-readable text format that is well-defined and parseable. It's a good choice for a configuration language. |
|
protobuf has human readable format, see http://stackoverflow.com/questions/18873924/what-does-the-protobuf-text-format-look-like |
|
I have just debugged though the code and it looks like the proposed way of simplifying, comes with a lot of extra CPU load.
Some time ago I had the idea to merge Configs and control Objects, time has passed and we have no persistand ControlObjects. These are able to accessed from everywhere. but limited to a double type. I am sure this will carry us a while ;-) |
|
By the way: Can we merge #501 for 2.1.0 it fixes a race condition and other issues and does not prevent any changes that are proposed here. |
|
I came across this post about a thread-safe configuration with compile time checks today. http://jguegant.github.io/blogs/tech/thread-safe-multi-type-map.html |
|
Any consensus on a way forward here? I'd like to get back to #649, but I don't know what the best way to overcome the obstacle of reading a configuration value there in a class that doesn't already do that. |
|
@Be-ing I'm not going to finish this PR. It also looks like @rryan want's to refactor the internals of mixxx a lot with manager classes. A settings manager will likely fit into this scheme. http://mixxx.org/wiki/doku.php/mixxx_init_refactor |
|
Cool, I'll get back to work on #649 after that's complete. |
This adds read and write functions for Qt QSettings object and a small wrapper class to use QSettings with mixxx.
I haven't touched any of the config options so far. This should show as a proof-of-concept how we can switch to QSettings and get rid of the
m_pConfigpointer that we pass around everywhere. If we want to switch I would suggest merging this PR and then creating a PR for each config-option that has been ported to the new interface. To keep track of the porting progress the QSettings object currently saves it's progress in a file calledMixxx.cfginstead ofmixxx.cfg(notice the capital M).Once we have gotten every access to a config option switch the
mixxx.cfgfile should be empty when we run mixxx with an empty settings-folder (do anrm -r ~/.mixxxbefore starting mixxx).A nice side effect of using QSettings is that all options in the settings-file are sorted by group. So every settings associated with the library for example will be at exactly the same place in the file and not spread across it.