patch #7310
[mldonkey.git] / src / gtk / gui / gui_installer.ml
blob1f49dc9a8279b9deee07e6cf5300e6b1adb45908
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 home_dir = (try Sys.getenv "HOME" with _ -> ".")
41 let config_dir_basename =
42 if Autoconf.windows then "mldonkey" else ".mldonkey"
44 let config_dir = Filename.concat home_dir config_dir_basename
46 let _ = Unix2.safe_mkdir config_dir
48 let installer_name = Filename.concat config_dir "installer.ini"
50 let installer_ini = create_options_file installer_name
52 let mldonkey_directory =
53 define_option installer_ini ["mldonkey_directory"]
54 "The directory where mldonkey's option files are" string_option
55 (Filename.concat home_dir ".mldonkey")
57 let _ =
58 (try Options.load installer_ini with _ -> ())
60 module Config = struct
61 open Configwin_types
62 open Configwin_ihm
65 let box param_list =
66 let main_box = GPack.vbox () in
67 let f parameter =
68 match parameter with
69 String_param p ->
70 let box = new string_param_box p in
71 let _ = main_box#pack ~expand: false ~padding: 2 box#box in
72 box
73 | Combo_param p ->
74 let box = new combo_param_box p in
75 let _ = main_box#pack ~expand: false ~padding: 2 box#box in
76 box
77 | Text_param p ->
78 let box = new text_param_box p in
79 let _ = main_box#pack ~expand: p.string_expand ~padding: 2 box#box in
80 box
81 | Bool_param p ->
82 let box = new bool_param_box p in
83 let _ = main_box#pack ~expand: false ~padding: 2 box#box in
84 box
85 | Filename_param p ->
86 let box = new filename_param_box p in
87 let _ = main_box#pack ~expand: false ~padding: 2 box#box in
88 box
89 | List_param f ->
90 let box = f () in
91 let _ = main_box#pack ~expand: true ~padding: 2 box#box in
92 box
93 | Custom_param p ->
94 let box = new custom_param_box p in
95 let _ = main_box#pack ~expand: p.custom_expand ~padding: 2 box#box in
96 box
97 | Color_param p ->
98 let box = new color_param_box p in
99 let _ = main_box#pack ~expand: false ~padding: 2 box#box in
101 | Font_param p ->
102 let box = new font_param_box p in
103 let _ = main_box#pack ~expand: false ~padding: 2 box#box in
105 | Date_param p ->
106 let box = new date_param_box p in
107 let _ = main_box#pack ~expand: false ~padding: 2 box#box in
110 let list_param_box = List.map f param_list in
111 let f_apply () =
112 List.iter (fun param_box -> param_box#apply) list_param_box
115 main_box, f_apply
119 class tab (notebook : GPack.notebook) label =
120 let tab_label = GMisc.label ~text: label () in
121 let vbox = GPack.vbox () in
122 let main_hbox = GPack.hbox ~packing:
123 (vbox#pack ~fill: true ~expand: true) () in
124 let main_vbox = GPack.vbox ~packing:
125 (main_hbox#pack ~fill: true ~expand: true) () in
127 let button_hbox = GPack.hbox ~packing:
128 (vbox#pack ~expand: false ~padding: 10) () in
131 let previous_slide = GButton.button ~width: 100 ~label: "Previous" ()
132 ~packing: (button_hbox#pack ~padding: 10) in
134 let cancel = GButton.button ~label: "Cancel" ()
135 ~packing: (button_hbox#pack ~padding: 10) in
137 let next_slide = GButton.button ~width: 100 ~label: "Next" ()
138 ~packing: (button_hbox#pack ~padding: 10) in
140 object(self)
142 method vbox = main_vbox
144 initializer
145 notebook#append_page ~tab_label: tab_label#coerce vbox#coerce ;
146 ignore (next_slide#connect#clicked
147 (fun () -> notebook#next_page ()));
148 ignore (previous_slide#connect#clicked
149 (fun () -> notebook#previous_page ()));
150 ignore (cancel#connect#clicked
151 (fun () -> exit 2));
156 let create_downloads_ini () =
158 let filename = Filename.concat !!mldonkey_directory "downloads.ini" in
159 let downloads_ini = create_options_file filename in
161 let shared_directories =
162 define_option downloads_ini ["shared_directories" ]
163 "Directories where files will be shared"
164 (list_option string_option) []
167 let gui_port =
168 define_option downloads_ini ["gui_port"] "port for user interaction" int_option 4001
171 let http_port =
172 define_option downloads_ini ["http_port"] "The port used to connect to your client with a WEB browser" int_option 4080
175 let telnet_port = define_option downloads_ini ["telnet_port"] "port for user interaction" port_option 4000
178 let http_login =
179 define_option downloads_ini ["http_login"] "Your login when using a WEB browser" string_option ""
182 let http_password =
183 define_option downloads_ini ["http_password"] "Your password when using a WEB browser" string_option ""
186 let max_hard_upload_rate = define_option downloads_ini ["max_hard_upload_rate"]
187 "The maximal upload rate you can tolerate on your link in kBytes/s (0 = no limit)
188 The limit will apply on all your connections (clients and servers) and both
189 control and data messages." int_option 0
192 let max_hard_download_rate = define_option downloads_ini ["max_hard_download_rate"]
193 "The maximal download rate you can tolerate on your link in kBytes/s (0 = no limit)
194 The limit will apply on all your connections (clients and servers) and both
195 control and data messages." int_option 0
198 let password = define_option downloads_ini ["password"]
199 "The password to access your client from the GUI (setting it disables
200 the command-line client)" string_option ""
203 let allowed_ips = define_option downloads_ini ["allowed_ips"]
204 "list of IP address allowed to control the client via telnet/GUI/WEB"
205 (list_option Ip.option) [Ip.of_string "127.0.0.1"]
208 Options.save_with_help downloads_ini;
209 lprintf "%s created successfully" filename; lprint_newline ()
211 let main () =
212 let gui = new Gui_installer_base.window () in
213 let window = gui#window in
214 let notebook = gui#notebook in
215 ignore (window#connect#destroy ~callback:GMain.Main.quit);
217 let directories_tab = new tab notebook "Directories" in
220 let param = Configwin_ihm.filename "MLdonkey directory:" !!mldonkey_directory
222 let directories_box, directories_apply = Config.box [param] in
223 directories_tab#vbox#pack ~expand: true ~fill: true directories_box#coerce;
225 let connection_tab = new tab notebook "Connection" in
226 let security_tab = new tab notebook "Interfaces" in
228 let save_tab = new tab notebook "Save" in
231 let label = GMisc.label ~text:
232 "Click on the Save button to save this configuration.\n Be careful: it will erase any previous configuration."
233 ~justify:`CENTER
234 ~packing:(save_tab#vbox#pack ~expand: true ~fill: true ~padding: 100) () in
236 let save_button = GButton.button ~height: 30 ~width: 100 ~label: "Save" ()
237 ~packing: (save_tab#vbox#pack ~expand: true ~fill: true ~padding: 10) in
238 ignore (save_button#connect#clicked
239 (fun () ->
240 directories_apply ();
243 Unix2.safe_mkdir !!mldonkey_directory;
244 create_downloads_ini ();
245 Options.save_with_help installer_ini;
246 lprintf "%s created successfully" installer_name; lprint_newline ();
248 exit 0));
251 window#show ();
252 GMain.Main.main ()
254 let _ =
255 main ()