From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!news-out.netnews.com!newsin.alt.net!fdcspool2.netnews.com!news-out.netnews.com!news.alt.net!fdc3.netnews.com!sewer!alphared!news.uzoreto.com!news.muarf.org!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!212.27.60.64.MISMATCH!cleanfeed3-b.proxad.net!nnrp1-1.free.fr!not-for-mail Subject: Re: GtkAda question Newsgroups: comp.lang.ada References: <6074bf6b$0$3702$426a74cc@news.free.fr> <60774222$0$6471$426a74cc@news.free.fr> From: DrPi <314@drpi.fr> Date: Sat, 17 Apr 2021 21:58:55 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Message-ID: <607b3dff$0$3693$426a74cc@news.free.fr> Organization: Guest of ProXad - France NNTP-Posting-Date: 17 Apr 2021 21:58:55 CEST NNTP-Posting-Host: 82.65.30.55 X-Trace: 1618689535 news-1.free.fr 3693 82.65.30.55:58145 X-Complaints-To: abuse@proxad.net Xref: reader02.eternal-september.org comp.lang.ada:61805 List-Id: 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: > >   modified="2021-04-10T11:10:10Z" visited="2021-04-10T09:30:05Z"> >    1677 >    stored value for x >    >      >        >        >          exec="' max_home_automation.exe%u'" > modified="2021-04-10T11:10:10Z" count="114"/> >        >      >    >   > > 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.