[SailfishDevel] Update changes LocalStorage location?

Thomas Perl th.perl at gmail.com
Sat Feb 1 15:00:32 UTC 2014


On 2014-01-31 23:59, Mikael Hermansson wrote:
> now can we instead be constructive and discuss what IS correct places 
> to store data?
> Now question is does those changes follow some Linux directory standards?

Yes, the directory "standard" that is followed is the XDG Base Directory 

Harbour FAQ has an entry how we use this in Sailfish OS and extend it 
(by mandating using $APPNAME as subfolder in the XDG directories) to 
make sure we can have per-application data directories (we need this for 
various reasons down the road, one is figuring out how much data an app 
is storing and showing that to the user, another is clearing that data 
when the app is uninstalled or clearing caches when space runs low, 
automatic integration into the backup application, etc...):

"Where should I store application configuration, application data and 
cache files?"

If you are using Qt 5, see here:

If you are using GLib, see here:

If you are using something else (e.g. wayland-egl directly or SDL2), we 
have a drop-in library for you that implements Harbour-conformant 

> I have an AppInfo class that I use in my apps and share in QML

Yes, you can actually just use:

for data: QStandardPaths::writableLocation(QStandardPaths::DataLocation)
for cache: QStandardPaths::writableLocation(QStandardPaths::CacheLocation)
for config: 

With the new libsailfishapp, QCoreApplication::applicationName() will 
always contain your $APPNAME, which is nice for C++ applications, but 
even more important, it now also works for QML-only (i.e. "sailfish-qml" 
launcher-based) apps.

The meaning and difference of data, cache and config can be found in 
Harbour FAQ:

I.e. the config folder is something that when erased should only remove 
preferences/settings (e.g. view options, sorting options, etc..), but 
not user data. The data folder can contain user data (erasing the data 
folder would remove user data). And the cache directory would store 
derived data that can be re-generated (e.g. from the data folder of by 
fetching something from the web).

For a simple game, the usage would be as follows:
  - config: Sound on/off preferences, input settings, etc...
  - data: Highscores, user progress and user-generated levels
  - cache: Image thumbnail previews of user-generated levels

If the config is cleared, the user will still keep their highscore and 
user-generated levels. If the cache is cleared, the user will also keep 
their data, but the next startup might be slower, as the application 
might have to re-generate thumbnail previews of user-generated levels.

> And when I use SQL Db:s in QML I do:
> db=LocalStorage.openDatabaseSync("harbour-uradio","1.0","StorageDatabase",100000);
> Correct?

Yes, in LocalStorage, you can even have different databases with 
different names. Local Storage uses QQmlEngine's offlineStoragePath to 
figure out where to store such files:

HTH :)

More information about the Devel mailing list