patch #7318
[mldonkey.git] / src / gtk / newgui / gui_installer.ml
blob322c59bda5d5add5a584adf794f0b050f152e971
1 (* Copyright 2001, 2002 b8_bavard, b8_fee_carabine, INRIA *)
2 (*
3 This file is part of mldonkey.
5 mldonkey is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 mldonkey is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with mldonkey; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 open Printf2
21 open Options
22 open GMain
24 (* What we want ?
26 * In which directory should the .ini files be stored ?
27 * Which directories should the temp/ and incoming/ be ?
28 * Which other directories are shared ?
29 * Which connection link is used ?
30 * Security option ?
32 All these replies should be stored in a basic file ~/.mldonkey_install.ini
33 that should also be loaded at startup by mldonkey.
39 let _ = Unix2.safe_mkdir CommonOptions.home_dir
40 let installer_name = Filename.concat CommonOptions.home_dir "installer.ini"
42 let _ =
43 (try Options.load CommonOptions.installer_ini with _ -> ())
45 module Config = struct
46 open Configwin_types
47 open Configwin_ihm
50 let box param_list =
51 let main_box = GPack.vbox () in
52 let f parameter =
53 match parameter with
54 String_param p ->
55 let box = new string_param_box p in
56 let _ = main_box#pack ~expand: false ~padding: 2 box#box in
57 box
58 | Combo_param p ->
59 let box = new combo_param_box p in
60 let _ = main_box#pack ~expand: false ~padding: 2 box#box in
61 box
62 | Text_param p ->
63 let box = new text_param_box p in
64 let _ = main_box#pack ~expand: p.string_expand ~padding: 2 box#box in
65 box
66 | Bool_param p ->
67 let box = new bool_param_box p in
68 let _ = main_box#pack ~expand: false ~padding: 2 box#box in
69 box
70 | Filename_param p ->
71 let box = new filename_param_box p in
72 let _ = main_box#pack ~expand: false ~padding: 2 box#box in
73 box
74 | List_param f ->
75 let box = f () in
76 let _ = main_box#pack ~expand: true ~padding: 2 box#box in
77 box
78 | Custom_param p ->
79 let box = new custom_param_box p in
80 let _ = main_box#pack ~expand: p.custom_expand ~padding: 2 box#box in
81 box
82 | Color_param p ->
83 let box = new color_param_box p in
84 let _ = main_box#pack ~expand: false ~padding: 2 box#box in
85 box
86 | Font_param p ->
87 let box = new font_param_box p in
88 let _ = main_box#pack ~expand: false ~padding: 2 box#box in
89 box
90 | Date_param p ->
91 let box = new date_param_box p in
92 let _ = main_box#pack ~expand: false ~padding: 2 box#box in
93 box
95 let list_param_box = List.map f param_list in
96 let f_apply () =
97 List.iter (fun param_box -> param_box#apply) list_param_box
100 main_box, f_apply
104 class tab (notebook : GPack.notebook) label =
105 let tab_label = GMisc.label ~text: label () in
106 let vbox = GPack.vbox () in
107 let main_hbox = GPack.hbox ~packing:
108 (vbox#pack ~fill: true ~expand: true) () in
109 let main_vbox = GPack.vbox ~packing:
110 (main_hbox#pack ~fill: true ~expand: true) () in
112 let button_hbox = GPack.hbox ~packing:
113 (vbox#pack ~expand: false ~padding: 10) () in
116 let previous_slide = GButton.button ~width: 100 ~label: "Previous" ()
117 ~packing: (button_hbox#pack ~padding: 10) in
119 let cancel = GButton.button ~label: "Cancel" ()
120 ~packing: (button_hbox#pack ~padding: 10) in
122 let next_slide = GButton.button ~width: 100 ~label: "Next" ()
123 ~packing: (button_hbox#pack ~padding: 10) in
125 object(self)
127 method vbox = main_vbox
129 initializer
130 notebook#append_page ~tab_label: tab_label#coerce vbox#coerce ;
131 ignore (next_slide#connect#clicked
132 (fun () -> notebook#next_page ()));
133 ignore (previous_slide#connect#clicked
134 (fun () -> notebook#previous_page ()));
135 ignore (cancel#connect#clicked
136 (fun () -> exit 2));
141 let create_downloads_ini () =
143 let filename = Filename.concat !!CommonOptions.mldonkey_directory "downloads.ini" in
144 let downloads_ini = create_options_file filename in
146 let installed_section = file_section downloads_ini [] "Set by installer" in
148 let shared_directories =
149 define_option installed_section ["shared_directories" ]
150 "Directories where files will be shared"
151 (list_option string_option) []
154 let gui_port =
155 define_option installed_section ["gui_port"] "port for user interaction" int_option 4001
158 let http_port =
159 define_option installed_section ["http_port"] "The port used to connect to your client with a WEB browser" int_option 4080
162 let telnet_port = define_option installed_section ["telnet_port"] "port for user interaction" port_option 4000
165 let http_login =
166 define_option installed_section ["http_login"] "Your login when using a WEB browser" string_option ""
169 let http_password =
170 define_option installed_section ["http_password"] "Your password when using a WEB browser" string_option ""
173 let max_hard_upload_rate = define_option installed_section ["max_hard_upload_rate"]
174 "The maximal upload rate you can tolerate on your link in kBytes/s (0 = no limit)
175 The limit will apply on all your connections (clients and servers) and both
176 control and data messages." int_option 0
179 let max_hard_download_rate = define_option installed_section ["max_hard_download_rate"]
180 "The maximal download rate you can tolerate on your link in kBytes/s (0 = no limit)
181 The limit will apply on all your connections (clients and servers) and both
182 control and data messages." int_option 0
185 let password = define_option installed_section ["password"]
186 "The password to access your client from the GUI (setting it disables
187 the command-line client)" string_option ""
190 let allowed_ips = define_option installed_section ["allowed_ips"]
191 "list of IP address allowed to control the client via telnet/GUI/WEB"
192 (list_option Ip.option) [Ip.of_string "127.0.0.1"]
195 Options.save_with_help downloads_ini;
196 lprintf "%s created successfully" filename; lprint_newline ()
198 let main () =
199 let gui = new Gui_installer_base.window () in
200 let window = gui#window in
201 let notebook = gui#notebook in
202 ignore (window#connect#destroy ~callback:GMain.Main.quit);
204 let directories_tab = new tab notebook "Directories" in
207 let param = Configwin_ihm.filename "MLdonkey directory:" !!CommonOptions.mldonkey_directory
209 let directories_box, directories_apply = Config.box [param] in
210 directories_tab#vbox#pack ~expand: true ~fill: true directories_box#coerce;
212 let connection_tab = new tab notebook "Connection" in
213 let security_tab = new tab notebook "Interfaces" in
215 let save_tab = new tab notebook "Save" in
218 let label = GMisc.label ~text:
219 "Click on the Save button to save this configuration.\n Be careful: it will erase any previous configuration."
220 ~justify:`CENTER
221 ~packing:(save_tab#vbox#pack ~expand: true ~fill: true ~padding: 100) () in
223 let save_button = GButton.button ~height: 30 ~width: 100 ~label: "Save" ()
224 ~packing: (save_tab#vbox#pack ~expand: true ~fill: true ~padding: 10) in
225 ignore (save_button#connect#clicked
226 (fun () ->
227 directories_apply ();
230 Unix2.safe_mkdir !!CommonOptions.mldonkey_directory;
231 create_downloads_ini ();
232 Options.save_with_help CommonOptions.installer_ini;
233 lprintf "%s created successfully\n" installer_name;
235 exit 0));
238 window#show ();
239 GMain.Main.main ()
241 let _ =
242 main ()