How and where to store client information in a GTK 3 application?

I want to make a GTK application, plus sockets and DB. My system is Debian 11, Gnome environment. But before starting building it, I could not answer or find an answer to the question of user authentication with further access to the client part of the application.

For instance, login window appears, user wants to sign up and proceeds to fill the necessary entries. Then, when validation succeeds, main window pops up, but all the changes and activity in the app since then will pertain only to that specific user. And if a user wants to open the app again (I guess, there will be a session time limit, after which login window will appear again - but that is another question, let’s forget it), everything will be restored and displayed as it was since the last time that user was logged in.

I only found, that all those user changes and information should be saved as a cache on client machine, with only little part in DB. Unfortunately, I am new to desktop application development on Gnome and desktop application development in general.

So, how to store that information/client app state, where and just how it works on Gnome specifically?

Please, forgive me for the overall ambiguity of the question.


Welcome to desktop application development, it’s very flexible of what you can do when developing with GTK. Basically almost everything is possible! See for example big applications like Evolution.

There are several possibilities for storing user information:

  • A local file stored in the user’s home directory, for that there are standard directories. GLib has convenience functions to access them, but the directories themselves are documented here.
  • For storing settings, there is GSettings.
  • For security sensitive information, there is libsecret.

Note that thanks to GtkApplication (or GApplication), there is a single process per user per app. GNOME doesn’t support several logins of the same user from different computers/seats for the same home directory (for example with a network file system, NFS etc). So simply reading and writing local files from the home directory, without locks, is what a lot of desktop applications on Linux do.

A simple local file is for example an XML file, JSON, key-value files (.ini-like config files), etc. GLib has some utilities for those. For JSON there is JSON-GLib.

As for the network sockets, look at the GIO library :wink:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.