comp.lang.ada
 help / color / mirror / Atom feed
From: DrPi <314@drpi.fr>
Subject: Re: GtkAda question
Date: Sat, 17 Apr 2021 21:58:55 +0200	[thread overview]
Message-ID: <607b3dff$0$3693$426a74cc@news.free.fr> (raw)
In-Reply-To: <s57k0k$ba9$1@gioia.aioe.org>

Le 14/04/2021 à 22:40, Dmitry A. Kazakov a écrit :
> On 2021-04-14 21:27, DrPi wrote:
>> Le 14/04/2021 à 00:00, Gautier write-only address a écrit :
>>> If I search for "Glib.Key_File" on the Web, the first hit is:
>>> https://developer.gnome.org/glib/stable/glib-Key-value-file-parser.html
>>> So perhaps you want to parse and write ".ini-like config files" as 
>>> mentioned there?
>> That's it.
>> To be more precise, I need to save and retrieve few data like window 
>> position and size.
> 
> I [mis]use Gtk_Recent_Manager for the purpose.
> 
> See the package Gtk.Recent_Manager_Keys. It has
> 
>    function Restore
>             (  Key     : UTF8_String;
>                Default : UTF8_String;
>                Manager : Gtk_Recent_Manager := Get_Default
>             )  return UTF8_String;
> 
>    procedure Store
>              (  Key     : UTF8_String;
>                 Value   : UTF8_String;
>                 Manager : Gtk_Recent_Manager := Get_Default
>              );
> 
> This is basically all what you need.
> 
> On top of that you set something like:
> 
>    function Restore (Key : String; Default : GInt) return GInt is
>    begin
>       return GInt'Value (Restore (Key, GInt'Image (Default)));
>    exception
>       when others =>
>          return GInt (Default);
>    end Restore;
> 
> Then you restore the window geometry simply as:
> 
>    Window.Resize (Restore ("width", 200), Restore ("height", 100));
>    Window.Move (Restore ("x", 0), Restore ("y", 0));
> 
> [You would add some sanity checks, of course]
> 
> The advantage is that the recent manager is sort of standard in GTK, it 
> is maintained by GTK on per user basis. All GTK applications share the 
> same *.xbel file.
> 
> The rest is disadvantages. The file is in XML, you can find your keys 
> there. E.g. stored x position of max_home_automation looks like this:
> 
>   <bookmark href="x" added="2021-04-10T09:30:03Z" 
> modified="2021-04-10T11:10:10Z" visited="2021-04-10T09:30:05Z">
>     <title>1677</title>
>     <desc>stored value for x</desc>
>     <info>
>       <metadata owner="http://freedesktop.org">
>         <mime:mime-type type="application/octet-stream"/>
>         <bookmark:applications>
>           <bookmark:application name="max_home_automation.exe" 
> exec="&apos; max_home_automation.exe%u&apos;" 
> modified="2021-04-10T11:10:10Z" count="114"/>
>         </bookmark:applications>
>       </metadata>
>     </info>
>   </bookmark>
> 
> Quite a lot of junk to store one puny value. As all GTK it is kind of 
> buggy, you may experience data losses. But otherwise it is simple for 
> keeping geometry and other settings there.
> 
Thanks for the explanations.

  reply	other threads:[~2021-04-17 19:58 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-12 21:45 GtkAda question DrPi
2021-04-13  9:53 ` Blady
2021-04-13 11:07   ` DrPi
2021-04-13 11:55     ` Dmitry A. Kazakov
2021-04-13 21:36       ` DrPi
2021-04-14  6:11         ` Dmitry A. Kazakov
2021-04-14 10:21           ` Emmanuel Briot
2021-04-14 19:28             ` DrPi
2021-04-14 20:23           ` DrPi
2021-04-14 21:05             ` Dmitry A. Kazakov
2021-04-17 19:56               ` DrPi
2021-04-13 22:00 ` Gautier write-only address
2021-04-14 19:27   ` DrPi
2021-04-14 20:40     ` Dmitry A. Kazakov
2021-04-17 19:58       ` DrPi [this message]
2021-04-18  9:34 ` DrPi
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox