← Back to team overview

ubuntu-phone team mailing list archive

Re: Preferred Settings API for Ubuntu apps

 

On 31.07.2014 19:45, Sam Bull wrote:
> On ĵaŭ, 2014-07-31 at 17:44 +0200, Christian Dywan wrote:
>> From my point of view once you start dealing with objects you'll want
>> U1db* and for instance save your object as a document.
>>
>> Do you have a specific example?
> My app is a dictionary, and it contains translations for many languages.
> I want to only display relevant languages to the user. For this, I use
> an Object as a simple key/value store, with the key being the language
> and the value a boolean as to whether it should be shown or not.
>
> I'd prefer the keys to not be hardcoded, as I load all the data
> (including the list of languages) from downloaded data, so if a new
> language were to be added to the list, then the app would check at the
> beginning and see it missing from the saved Object and add a value for
> it.
>
> Essentially, all I want is a simple Python dictionary.
>
> Although, having just explained all this, I've just realised a possibly
> better solution would be to simply store an array of enabled languages,
> and check if a language is in the array. Though, this would still be
> better if the values were hashed, are there sets in Javascript, and
> could they be saved?
You can do [ "en", "fr" ] or { "en": "English", "fr": "French" } however
they are object types in Javascript thus not allowed as settings values.


QSettings has support for arrays in the C++ API
http://qt-project.org/doc/qt-4.8/qsettings.html#beginWriteArray

It should be possible to extend the backend so that it detects arrays
and stores them as such.



As a short-term solution you could use a string instead like "en,fr".

ciao,
    Christian

Attachment: signature.asc
Description: OpenPGP digital signature


Follow ups

References