20 |
open Options |
open Options |
21 |
open GuiTypes2 |
open GuiTypes2 |
22 |
open CommonTypes |
open CommonTypes |
23 |
|
open GraphTypes |
24 |
|
|
25 |
open GMain |
open GMain |
26 |
open GtkBase |
open GtkBase |
48 |
|
|
49 |
let chmod_config () = |
let chmod_config () = |
50 |
let base_config = |
let base_config = |
51 |
(Filename.concat CommonOptions.home_dir "mlgui.ini") |
(Filename.concat M.gui_config_dir "mlgui.ini") |
52 |
in |
in |
53 |
let save_config = |
let save_config = |
54 |
base_config ^ ".old" |
base_config ^ ".old" |
81 |
|
|
82 |
let value_reader gui t = |
let value_reader gui t = |
83 |
try |
try |
84 |
|
|
85 |
begin |
begin |
86 |
if !!verbose then lprintf' "MESSAGE RECEIVED: %s\n" |
if !!verbose then lprintf' "MESSAGE RECEIVED: %s\n" |
87 |
(string_of_to_gui t); |
(string_of_to_gui t); |
88 |
end; |
end; |
89 |
|
|
|
|
|
90 |
match t with |
match t with |
91 |
|
|
92 |
(* The first message received from the core *) |
(* The first message received from the core *) |
134 |
begin |
begin |
135 |
GuiStatusBar.update_updown s.tcp_upload_rate s.tcp_download_rate; |
GuiStatusBar.update_updown s.tcp_upload_rate s.tcp_download_rate; |
136 |
GuiStatusBar.update_sharedfiles s.nshared_files s.upload_counter; |
GuiStatusBar.update_sharedfiles s.nshared_files s.upload_counter; |
137 |
|
GuiGraphBase.save_record s.tcp_download_rate GraphDownloads; |
138 |
|
GuiGraphBase.save_record s.tcp_upload_rate GraphUploads; |
139 |
if !G.is_docked |
if !G.is_docked |
140 |
then begin |
then begin |
141 |
let up = float_of_int s.tcp_upload_rate /. 1024. in |
let up = float_of_int s.tcp_upload_rate /. 1024. in |
169 |
else s.source_files_requested |
else s.source_files_requested |
170 |
in |
in |
171 |
let s_new = {s with source_files_requested = files_requested} in |
let s_new = {s with source_files_requested = files_requested} in |
172 |
GuiDownloads.h_add_source s_new file_num; |
GuiDownloads.h_add_source s_new file_num;(* seen *) |
173 |
Hashtbl.replace G.sources source_num s_new |
s.source_files_requested <- s_new.source_files_requested;(* seen *) |
174 |
with _ -> |
with _ -> |
175 |
GuiCom.send (GuiProto.GetClient_info source_num) |
GuiCom.send (GuiProto.GetClient_info source_num) |
176 |
end |
end |
181 |
let s = Hashtbl.find G.sources source_num in |
let s = Hashtbl.find G.sources source_num in |
182 |
let files_requested = List.filter (fun num -> num <> file_num) s.source_files_requested in |
let files_requested = List.filter (fun num -> num <> file_num) s.source_files_requested in |
183 |
let s_new = {s with source_files_requested = files_requested} in |
let s_new = {s with source_files_requested = files_requested} in |
184 |
GuiDownloads.h_remove_source s_new file_num; |
GuiDownloads.h_remove_source s_new file_num;(* seen *) |
185 |
Hashtbl.replace G.sources source_num s_new |
s.source_files_requested <- s_new.source_files_requested;(* seen *) |
186 |
with _ -> |
with _ -> |
187 |
GuiCom.send (GuiProto.GetClient_info source_num) |
GuiCom.send (GuiProto.GetClient_info source_num) |
188 |
end |
end |
202 |
{s with source_availability = (file_num, avail) :: avails} |
{s with source_availability = (file_num, avail) :: avails} |
203 |
with _ -> {s with source_availability = (file_num, avail) :: s.source_availability} |
with _ -> {s with source_availability = (file_num, avail) :: s.source_availability} |
204 |
in |
in |
205 |
GuiDownloads.h_update_source_availability s_new file_num; |
GuiDownloads.h_update_source_availability s s_new file_num;(* seen *) |
206 |
Hashtbl.replace G.sources source_num s_new |
s.source_availability <- s_new.source_availability(* seen *) |
207 |
with _ -> |
with _ -> |
208 |
GuiCom.send (GuiProto.GetClient_info source_num) |
GuiCom.send (GuiProto.GetClient_info source_num) |
209 |
end |
end |
216 |
gui.init.downloads <- false |
gui.init.downloads <- false |
217 |
end |
end |
218 |
); |
); |
219 |
GuiDownloads.file_info |
let file = Mi.file_info_to_g_file_info f in |
220 |
{f with file_age = (BasicSocket.last_time () - f.file_age); |
GuiDownloads.file_info file |
|
file_last_seen = (BasicSocket.last_time () - f.file_last_seen); |
|
|
} |
|
221 |
end |
end |
222 |
|
|
223 |
| Server_info s -> |
| Server_info s -> |
269 |
GuiServers.h_server_update_users user.user_server user.user_num; |
GuiServers.h_server_update_users user.user_server user.user_num; |
270 |
GuiRooms.update_user_info user |
GuiRooms.update_user_info user |
271 |
end |
end |
272 |
|
|
273 |
| Room_add_user (num, user_num) -> |
| Room_add_user (num, user_num) -> |
274 |
GuiRooms.add_room_user num user_num |
GuiRooms.add_room_user num user_num |
275 |
|
|
276 |
| Room_remove_user (num, user_num) -> |
| Room_remove_user (num, user_num) -> |
277 |
GuiRooms.remove_room_user num user_num |
GuiRooms.remove_room_user num user_num |
278 |
|
|
317 |
try |
try |
318 |
let s = Hashtbl.find G.sources source_num in |
let s = Hashtbl.find G.sources source_num in |
319 |
let s_new = {s with source_state = state} in |
let s_new = {s with source_state = state} in |
320 |
GuiDownloads.h_update_source s_new ; |
GuiDownloads.h_update_source s s_new;(* seen *) |
321 |
GuiUploads.h_update_uploader s_new; |
GuiUploads.h_update_uploader s s_new;(* seen *) |
322 |
GuiFriends.h_update_friend s_new; |
GuiFriends.h_update_friend s s_new;(* seen *) |
323 |
Hashtbl.replace G.sources s.source_num s_new |
s.source_state <- state(* seen *) |
324 |
with _ -> |
with _ -> |
325 |
begin |
begin |
326 |
GuiCom.send (GuiProto.GetClient_info source_num) |
GuiCom.send (GuiProto.GetClient_info source_num) |
332 |
try |
try |
333 |
let s = Hashtbl.find G.sources source_num in |
let s = Hashtbl.find G.sources source_num in |
334 |
let s_new = {s with source_type = friend_kind} in |
let s_new = {s with source_type = friend_kind} in |
335 |
GuiDownloads.h_update_source s_new ; |
GuiDownloads.h_update_source s s_new;(* seen *) |
336 |
GuiUploads.h_update_uploader s_new; |
GuiUploads.h_update_uploader s s_new;(* seen *) |
337 |
GuiFriends.h_update_friend s_new; |
GuiFriends.h_update_friend s s_new;(* seen *) |
338 |
Hashtbl.replace G.sources s.source_num s_new |
s.source_type <- friend_kind;(* seen *) |
339 |
with _ -> |
with _ -> |
340 |
begin |
begin |
341 |
GuiCom.send (GuiProto.GetClient_info source_num) |
GuiCom.send (GuiProto.GetClient_info source_num) |
346 |
GuiResults.result_info r |
GuiResults.result_info r |
347 |
|
|
348 |
| Client_file (source_num , dirname, file_num) -> |
| Client_file (source_num , dirname, file_num) -> |
349 |
GuiFriends.add_friend_files (source_num , dirname, file_num) |
GuiFriends.add_friend_files (source_num , dirname, file_num)(* seen *) |
350 |
|
|
351 |
| Client_info client -> |
| Client_info client -> |
352 |
begin |
begin |
357 |
end |
end |
358 |
); |
); |
359 |
let source = Mi.client_to_source client in |
let source = Mi.client_to_source client in |
360 |
let s_new = |
try |
361 |
try |
let s = Hashtbl.find G.sources source.source_num in |
362 |
let s = Hashtbl.find G.sources source.source_num in |
let s_new = |
363 |
{ source with |
{ source with |
364 |
source_files = s.source_files; |
source_files = s.source_files; |
365 |
source_has_upload = s.source_has_upload; |
source_has_upload = s.source_has_upload; |
368 |
source_upload_rate = Mi.source_upload_rate source s; |
source_upload_rate = Mi.source_upload_rate source s; |
369 |
source_download_rate = Mi.source_download_rate source s; |
source_download_rate = Mi.source_download_rate source s; |
370 |
} |
} |
371 |
with _ -> source |
in |
372 |
in |
GuiDownloads.h_update_source s s_new;(* seen *) |
373 |
GuiDownloads.h_update_source s_new; |
GuiUploads.h_update_uploader s s_new;(* seen *) |
374 |
GuiUploads.h_update_uploader s_new; |
GuiFriends.h_update_friend s s_new;(* seen *) |
375 |
GuiFriends.h_update_friend s_new; |
G.hashtbl_update_sources s s_new;(* seen *) |
376 |
Hashtbl.replace G.sources s_new.source_num s_new |
with _ -> |
377 |
|
begin |
378 |
|
GuiFriends.h_update_friend source source;(* seen *) |
379 |
|
Hashtbl.add G.sources source.source_num source(* seen *) |
380 |
|
end |
381 |
end |
end |
382 |
|
|
383 |
| Room_message (_, PrivateMessage(num, mes) ) |
| Room_message (_, PrivateMessage(num, mes) ) |
402 |
|
|
403 |
| (DownloadedFiles _|DownloadFiles _|ConnectedServers _) -> assert false |
| (DownloadedFiles _|DownloadFiles _|ConnectedServers _) -> assert false |
404 |
|
|
|
| Shared_file_info s -> |
|
|
begin |
|
|
(if gui.init.uploads |
|
|
then begin |
|
|
gui.set_splash_screen M.icon_menu_uploads (Mi.remove_ !M.mW_lb_uploads); |
|
|
gui.init.uploads <- false |
|
|
end |
|
|
); |
|
|
GuiUploads. h_shared_file_info s |
|
|
end |
|
|
|
|
405 |
| CleanTables (clients, servers) -> |
| CleanTables (clients, servers) -> |
406 |
begin |
begin |
407 |
let all_sources = Hashtbl2.to_list G.sources in |
let all_sources = Hashtbl2.to_list G.sources in |
424 |
GuiServers.clean_servers_table servers; |
GuiServers.clean_servers_table servers; |
425 |
end |
end |
426 |
|
|
427 |
|
| Shared_file_info s -> |
428 |
|
begin |
429 |
|
(if gui.init.uploads |
430 |
|
then begin |
431 |
|
gui.set_splash_screen M.icon_menu_uploads (Mi.remove_ !M.mW_lb_uploads); |
432 |
|
gui.init.uploads <- false |
433 |
|
end |
434 |
|
); |
435 |
|
GuiUploads.h_shared_file_info (Mi.shared_info_to_shared_file s) |
436 |
|
end |
437 |
|
|
438 |
| Shared_file_upload (num, size, requests) -> |
| Shared_file_upload (num, size, requests) -> |
439 |
GuiUploads.h_shared_file_upload num size requests |
GuiUploads.h_shared_file_upload num size requests |
440 |
|
|
785 |
true |
true |
786 |
); |
); |
787 |
GMain.main (); |
GMain.main (); |
788 |
|
|
789 |
); |
); |
790 |
window#show () |
window#show () |
791 |
|
|
807 |
G.get_metrics_from_gtk_font_list (); |
G.get_metrics_from_gtk_font_list (); |
808 |
|
|
809 |
let quit () = |
let quit () = |
810 |
chmod_config (); |
chmod_config (); |
811 |
(if !G.is_docked then G.tray.destroy_tray ()); |
(if !G.is_docked then G.tray.destroy_tray ()); |
812 |
CommonGlobals.exit_properly 0 |
CommonGlobals.exit_properly 0 |
813 |
in |
in |
817 |
|
|
818 |
ignore (w#event#connect#delete ~callback: |
ignore (w#event#connect#delete ~callback: |
819 |
(fun _ -> |
(fun _ -> |
820 |
w#misc#hide (); |
if Autoconf.system = "windows" |
821 |
let icon = A.get_icon ~icon:M.icon_type_source_normal ~size:A.MEDIUM () in |
then begin |
822 |
G.tray.create_tray icon "MLDonkey"; |
w#misc#hide (); |
823 |
true |
let icon = A.get_icon ~icon:M.icon_type_source_normal ~size:A.MEDIUM () in |
824 |
|
G.tray.create_tray icon "MLDonkey"; |
825 |
|
end else begin |
826 |
|
quit () |
827 |
|
end; |
828 |
|
true |
829 |
)); |
)); |
830 |
|
|
831 |
let main_menu = core_menu gui quit in |
let main_menu = core_menu gui quit in |
832 |
GuiStatusBar.menuitem#set_submenu (main_menu); |
GuiStatusBar.menuitem#set_submenu (main_menu); |
833 |
|
|
834 |
G.console_message := (fun s -> GuiConsole.insert s); |
G.console_message := (fun s -> GuiConsole.insert s); |
835 |
G.get_files := (fun list -> |
if Autoconf.system <> "windows" |
836 |
let l = ref [] in |
then begin |
837 |
List.iter (fun file_num -> |
let icon = A.get_icon ~icon:M.icon_type_source_normal ~size:A.MEDIUM () in |
838 |
try |
G.tray.create_tray icon "MLDonkey"; |
839 |
let (_, i) = GuiDownloads.downloadstore#find_item (File_num file_num) in |
end; |
840 |
match i with |
let win_hidden = ref false in |
|
File f -> l := f :: !l |
|
|
| _ -> () |
|
|
with _ -> () |
|
|
) list; |
|
|
!l |
|
|
); |
|
|
|
|
841 |
!G.set_systray_callback (fun ev -> |
!G.set_systray_callback (fun ev -> |
842 |
match ev with |
match ev with |
843 |
DOUBLE_CLICKED -> |
DOUBLE_CLICKED -> |
844 |
begin |
if Autoconf.system = "windows" |
845 |
|
then begin |
846 |
(if !!verbose then lprintf' "tray double clicked\n"); |
(if !!verbose then lprintf' "tray double clicked\n"); |
847 |
G.tray.destroy_tray (); |
G.tray.destroy_tray (); |
848 |
w#misc#show (); |
w#misc#show (); |
849 |
w#maximize (); |
w#maximize (); |
850 |
end |
end |
851 |
| RBUTTON_CLICKED -> |
| RBUTTON_CLICKED -> |
852 |
begin |
begin |
853 |
(if !!verbose then lprintf' "tray right clicked\n"); |
(if !!verbose then lprintf' "tray right clicked\n"); |
861 |
win#show () |
win#show () |
862 |
end |
end |
863 |
end |
end |
864 |
| _ -> () |
| LBUTTON_CLICKED -> |
865 |
|
if Autoconf.system <> "windows" |
866 |
|
then begin |
867 |
|
(if !!verbose then lprintf' "tray left clicked\n"); |
868 |
|
if !win_hidden |
869 |
|
then begin |
870 |
|
w#misc#show (); |
871 |
|
win_hidden := false |
872 |
|
end else begin |
873 |
|
w#misc#hide (); |
874 |
|
win_hidden := true |
875 |
|
end |
876 |
|
end |
877 |
); |
); |
878 |
|
|
879 |
CommonGlobals.do_at_exit (fun _ -> |
CommonGlobals.do_at_exit (fun _ -> |