first of all, not sure if it’s the best place for ask for help/recomenations, if not, please point me to the correct place, and close if needed.
well, my topic, I created for sailfish an application to see the status of flights, based on data from airlabs. And since I liked it a lot, I started some time ago to clone it using gtk + rust, to learn both, the app is a pretty simple app, search a flight, save it into some kind of history/recents, show the data of the flight. (for more context, if you are interessed, this is the version I’ve got: Jaume / flight-tracker-gnome · GitLab )
now I’ve got some basic stuff working, it’s requesting the data of the flights, having the history, saving the data. But the way I’m handling it is every screen/sub-template, loads the flights handler, to know what it has, and retrives the data from that, Maybe this is the best way to handle it, but I’m not sure about that.
then the questions:
what is the best way to handle some shared DB? in the full application? Originally I tried to get a way to access the application class, but I didn’t found any way.
to get updated the ui of some other part of the application, the only way is with signals to the parent, etc? and then update the data of the other child elements?
I had more questions, but right now the two more importants are this two, thanks a lot!
For persistent storage, you can use things like GSettings or have some DB on disk.
For access across your app, you can pull from those anywhere, or you can have something like a model in the application like you said. You can access the application class anywhere with Gio.Application.get_default.
In Python I often use GSettings for persistent storage, and a separate module for a model for app access.
to get updated the ui of some other part of the application, the only way is with signals to the parent, etc? and then update the data of the other child elements?
I’d recommend updating as much of your UI as possible “automatically”, so that means using widgets that work nicely with Gio.ListModel: Gtk.ListView/Gtk.GridView, Gtk.ListBox.bind_model, etc. Then there’s also property bindings and expression bindings which link your data with your UI.
There’s also two main ways of explicit communication: signals and actions. You connect to a signal if you want your UI to react to a change, while you use actions if you want to explicitly do something. A benefit of actions is that they are available everywhere in the widget hierarchy below the widget that has the actions.
I hope this helps you get started, feel free to ask further questions
hey, thanks, Now I found the get_default_application binding in rust, with that I think I can refactor it a little bit, to make it easy.
The GSettings I’m already using but for storing the api-key of airlabs (Which btw, what is the best way to store a secret in gnome?) and also the window configuration. (I did the tutorial of a todo-list in rust)
The listModel I already use to list the flights, but I didn’t binded it directly to my data. Maybe now I can rethink it, and improve it.