Fix typos, add more info in README
[gwiad.git] / gwiad / src / gwiad-config-settings.adb
blob75c6caa40335f06a150910c8d4b81498f57a81e6
1 ------------------------------------------------------------------------------
2 -- Gwiad --
3 -- --
4 -- Copyright (C) 2007 --
5 -- Olivier Ramonat --
6 -- --
7 -- This library is free software; you can redistribute it and/or modify --
8 -- it under the terms of the GNU General Public License as published by --
9 -- the Free Software Foundation; either version 2 of the License, or (at --
10 -- your option) any later version. --
11 -- --
12 -- This library is distributed in the hope that it will be useful, but --
13 -- WITHOUT ANY WARRANTY; without even the implied warranty of --
14 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
15 -- General Public License for more details. --
16 -- --
17 -- You should have received a copy of the GNU General Public License --
18 -- along with this library; if not, write to the Free Software Foundation, --
19 -- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. --
20 ------------------------------------------------------------------------------
22 with Ada.Text_IO;
23 with Ada.Exceptions;
25 with Morzhol.Iniparser;
26 with Gwiad.Config;
28 package body Gwiad.Config.Settings is
30 use Ada;
32 Config_Filename : constant String := "gwiad.ini";
34 type Attributes is (Auth_Username, Auth_Password,
35 Web_Default_Directory, Web_Default_Page);
37 package Conf is new Morzhol.Iniparser (Parameter_Name => Attributes);
39 -------------------
40 -- Auth_Password --
41 -------------------
43 function Auth_Password return String is
44 begin
45 return Conf.Get_Value (Auth_Password);
46 end Auth_Password;
48 -------------------
49 -- Auth_Username --
50 -------------------
52 function Auth_Username return String is
53 begin
54 return Conf.Get_Value (Auth_Username);
55 end Auth_Username;
57 ---------------------------
58 -- Web_Default_Directory --
59 ---------------------------
61 function Web_Default_Directory return String is
62 begin
63 return Conf.Get_Value (Web_Default_Directory);
64 end Web_Default_Directory;
66 ----------------------
67 -- Web_Default_Page --
68 ----------------------
70 function Web_Default_Page return String is
71 begin
72 return Conf.Get_Value (Web_Default_Page);
73 end Web_Default_Page;
75 begin -- Gwiad.Config.Settings
76 -- Sets default option and reads configuration file
78 Conf.Set_Value (Auth_Username, Gwiad.Config.Auth_Username);
79 Conf.Set_Value (Auth_Password, Gwiad.Config.Auth_Password);
80 Conf.Set_Value (Web_Default_Directory, Gwiad.Config.Web_Default_Directory);
81 Conf.Set_Value (Web_Default_Page, Gwiad.Config.Web_Default_Page);
83 -- Now read the config file if any
85 Conf.IO.Open (Config_Filename);
86 Conf.IO.Close;
88 exception
89 when Conf.IO.Uncomplete_Config =>
90 Conf.IO.Close;
91 when UP : Conf.IO.Unknown_Parameter =>
92 Text_IO.Put_Line (Exceptions.Exception_Message (UP));
93 Conf.IO.Close;
94 when Text_IO.Name_Error =>
95 null;
96 end Gwiad.Config.Settings;