22 |
open GuiTypes2 |
open GuiTypes2 |
23 |
open GuiTypes |
open GuiTypes |
24 |
open CommonTypes |
open CommonTypes |
25 |
|
open GraphTypes |
26 |
|
|
27 |
open GuiTools |
open GuiTools |
28 |
open GuiGlobal |
open GuiGlobal |
56 |
let (uploader_label : GMisc.label option ref) = ref None |
let (uploader_label : GMisc.label option ref) = ref None |
57 |
let nuploading = ref 0 |
let nuploading = ref 0 |
58 |
let show_pending = ref false |
let show_pending = ref false |
|
let uploaders_timerID = ref (GMain.Timeout.add ~ms:2000 ~callback:(fun _ -> true)) |
|
59 |
let (view_context : GPango.context option ref) = ref None |
let (view_context : GPango.context option ref) = ref None |
60 |
|
let uploaders_n_pendings = ref [] |
61 |
|
|
62 |
|
(*************************************************************************) |
63 |
|
(* *) |
64 |
|
(* shared_file_num *) |
65 |
|
(* *) |
66 |
|
(*************************************************************************) |
67 |
|
|
68 |
|
let shared_file_num key = |
69 |
|
try int_of_string key with _ -> raise Not_found |
70 |
|
|
71 |
|
(*************************************************************************) |
72 |
|
(* *) |
73 |
|
(* shared_file_of_key *) |
74 |
|
(* *) |
75 |
|
(*************************************************************************) |
76 |
|
|
77 |
|
let shared_file_of_key key = |
78 |
|
try |
79 |
|
let num = shared_file_num key in |
80 |
|
Hashtbl.find G.shared_files num |
81 |
|
with _ -> raise Not_found |
82 |
|
|
83 |
|
(*************************************************************************) |
84 |
|
(* *) |
85 |
|
(* keys_to_shared_files *) |
86 |
|
(* *) |
87 |
|
(*************************************************************************) |
88 |
|
|
89 |
|
let keys_to_shared_files keys = |
90 |
|
let l = ref [] in |
91 |
|
List.iter (fun k -> |
92 |
|
try |
93 |
|
let s = shared_file_of_key k in |
94 |
|
l := s :: !l |
95 |
|
with _ -> ()) keys; |
96 |
|
!l |
97 |
|
|
98 |
|
(*************************************************************************) |
99 |
|
(* *) |
100 |
|
(* shared_file_key *) |
101 |
|
(* *) |
102 |
|
(*************************************************************************) |
103 |
|
|
104 |
|
let shared_file_key shared_file_num = |
105 |
|
Printf.sprintf "%d" shared_file_num |
106 |
|
|
107 |
|
(*************************************************************************) |
108 |
|
(* *) |
109 |
|
(* uploader_num *) |
110 |
|
(* *) |
111 |
|
(*************************************************************************) |
112 |
|
|
113 |
|
let uploader_num key = |
114 |
|
try int_of_string key with _ -> raise Not_found |
115 |
|
|
116 |
|
(*************************************************************************) |
117 |
|
(* *) |
118 |
|
(* uploader_of_key *) |
119 |
|
(* *) |
120 |
|
(*************************************************************************) |
121 |
|
|
122 |
|
let uploader_of_key key = |
123 |
|
try |
124 |
|
let num = uploader_num key in |
125 |
|
Hashtbl.find G.sources num |
126 |
|
with _ -> raise Not_found |
127 |
|
|
128 |
|
(*************************************************************************) |
129 |
|
(* *) |
130 |
|
(* keys_to_uploaders *) |
131 |
|
(* *) |
132 |
|
(*************************************************************************) |
133 |
|
|
134 |
|
let keys_to_uploaders keys = |
135 |
|
let l = ref [] in |
136 |
|
List.iter (fun k -> |
137 |
|
try |
138 |
|
let s = uploader_of_key k in |
139 |
|
l := s :: !l |
140 |
|
with _ -> ()) keys; |
141 |
|
!l |
142 |
|
|
143 |
|
(*************************************************************************) |
144 |
|
(* *) |
145 |
|
(* uploader_key *) |
146 |
|
(* *) |
147 |
|
(*************************************************************************) |
148 |
|
|
149 |
|
let uploader_key uploader_num = |
150 |
|
Printf.sprintf "%d" uploader_num |
151 |
|
|
152 |
(*************************************************************************) |
(*************************************************************************) |
153 |
(* *) |
(* *) |
159 |
|
|
160 |
module Column = GuiColumns.Shared_files_up |
module Column = GuiColumns.Shared_files_up |
161 |
|
|
162 |
type item = shared_info |
type item = shared_file |
|
type key = int |
|
163 |
|
|
164 |
let columns = O.shared_files_up_columns |
let columns = O.shared_files_up_columns |
165 |
let get_key = (fun si -> si.shared_num) |
let get_key = (fun si -> (shared_file_key si.g_shared_num)) |
166 |
let module_name = "Uploads" |
let module_name = "Uploads" |
167 |
|
|
168 |
end) |
end) |
187 |
(* *) |
(* *) |
188 |
(*************************************************************************) |
(*************************************************************************) |
189 |
|
|
190 |
method from_item row (si : shared_info) = |
method from_item row (si : shared_file) = |
191 |
store#set ~row ~column:shared_network_str (Mi.network_name si.shared_network); |
store#set ~row ~column:shared_network_str (Mi.network_name si.g_shared_network); |
192 |
store#set ~row ~column:shared_network_pixb (Mi.network_pixb si.shared_network ~size:A.SMALL ()); |
store#set ~row ~column:shared_network_pixb (Mi.network_pixb si.g_shared_network ~size:A.SMALL ()); |
193 |
store#set ~row ~column:shared_name (U.utf8_of si.shared_filename); |
store#set ~row ~column:shared_name (U.utf8_of si.g_shared_filename); |
194 |
store#set ~row ~column:shared_name_pixb (Mi.file_type_of_name si.shared_filename ~size:A.SMALL); |
store#set ~row ~column:shared_name_pixb (Mi.file_type_of_name si.g_shared_filename ~size:A.SMALL); |
195 |
store#set ~row ~column:shared_size_str (Mi.size_of_int64 si.shared_size); |
store#set ~row ~column:shared_size_str (Mi.size_of_int64 si.g_shared_size); |
196 |
store#set ~row ~column:shared_uploaded_str (Mi.size_of_int64 si.shared_uploaded); |
store#set ~row ~column:shared_uploaded_str (Mi.size_of_int64 si.g_shared_uploaded); |
197 |
store#set ~row ~column:shared_requests si.shared_requests; |
store#set ~row ~column:shared_requests si.g_shared_requests; |
198 |
store#set ~row ~column:shared_uid (Mi.uid_list_to_string si.shared_uids) |
store#set ~row ~column:shared_uid (Mi.uid_list_to_string si.g_shared_uids) |
199 |
|
|
200 |
(*************************************************************************) |
(*************************************************************************) |
201 |
(* *) |
(* *) |
203 |
(* *) |
(* *) |
204 |
(*************************************************************************) |
(*************************************************************************) |
205 |
|
|
206 |
method from_new_item (row : Gtk.tree_iter) (si : shared_info) (si_new : shared_info) = |
method from_new_item (row : Gtk.tree_iter) (si : shared_file) (si_new : shared_file) = |
207 |
if si.shared_filename <> si_new.shared_filename |
if si.g_shared_filename <> si_new.g_shared_filename |
208 |
then begin |
then begin |
209 |
store#set ~row ~column:shared_name (U.utf8_of si_new.shared_filename); |
store#set ~row ~column:shared_name (U.utf8_of si_new.g_shared_filename); |
210 |
if (Mi.extension_of si.shared_filename) <> (Mi.extension_of si_new.shared_filename) |
if (Mi.extension_of si.g_shared_filename) <> (Mi.extension_of si_new.g_shared_filename) |
211 |
then begin |
then begin |
212 |
store#set ~row ~column:shared_name_pixb (Mi.file_type_of_name si_new.shared_filename ~size:A.SMALL); |
store#set ~row ~column:shared_name_pixb (Mi.file_type_of_name si_new.g_shared_filename ~size:A.SMALL); |
213 |
end |
end |
214 |
end; |
end; |
215 |
if si.shared_size <> si_new.shared_size |
if si.g_shared_size <> si_new.g_shared_size |
216 |
then begin |
then begin |
217 |
store#set ~row ~column:shared_size_str (Mi.size_of_int64 si_new.shared_size); |
store#set ~row ~column:shared_size_str (Mi.size_of_int64 si_new.g_shared_size); |
218 |
end; |
end; |
219 |
if si.shared_uploaded <> si_new.shared_uploaded |
if si.g_shared_uploaded <> si_new.g_shared_uploaded |
220 |
then begin |
then begin |
221 |
store#set ~row ~column:shared_uploaded_str (Mi.size_of_int64 si_new.shared_uploaded); |
store#set ~row ~column:shared_uploaded_str (Mi.size_of_int64 si_new.g_shared_uploaded); |
222 |
end; |
end; |
223 |
if si.shared_requests <> si_new.shared_requests |
if si.g_shared_requests <> si_new.g_shared_requests |
224 |
then begin |
then begin |
225 |
store#set ~row ~column:shared_requests si_new.shared_requests; |
store#set ~row ~column:shared_requests si_new.g_shared_requests; |
226 |
end; |
end; |
227 |
if si.shared_uids <> si_new.shared_uids |
if si.g_shared_uids <> si_new.g_shared_uids |
228 |
then begin |
then begin |
229 |
store#set ~row ~column:shared_uid (Mi.uid_list_to_string si_new.shared_uids) |
store#set ~row ~column:shared_uid (Mi.uid_list_to_string si_new.g_shared_uids) |
230 |
end |
end |
231 |
|
|
232 |
(*************************************************************************) |
(*************************************************************************) |
313 |
(* *) |
(* *) |
314 |
(*************************************************************************) |
(*************************************************************************) |
315 |
|
|
316 |
method sort_items c si1 si2 = |
method sort_items c k1 k2 = |
317 |
match c with |
try |
318 |
Col_shared_file -> compare si1.shared_filename si2.shared_filename |
let si1 = shared_file_of_key k1 in |
319 |
| Col_shared_network -> compare si1.shared_network si2.shared_network |
let si2 = shared_file_of_key k2 in |
320 |
| Col_shared_upsize -> compare si1.shared_uploaded si2.shared_uploaded |
match c with |
321 |
| Col_shared_requests -> compare si1.shared_requests si2.shared_requests |
Col_shared_file -> compare si1.g_shared_filename si2.g_shared_filename |
322 |
| Col_shared_size -> compare si1.shared_size si2.shared_size |
| Col_shared_network -> compare si1.g_shared_network si2.g_shared_network |
323 |
| Col_shared_uid -> compare (Mi.uid_list_to_string si1.shared_uids) (Mi.uid_list_to_string si2.shared_uids) |
| Col_shared_upsize -> compare si1.g_shared_uploaded si2.g_shared_uploaded |
324 |
|
| Col_shared_requests -> compare si1.g_shared_requests si2.g_shared_requests |
325 |
|
| Col_shared_size -> compare si1.g_shared_size si2.g_shared_size |
326 |
|
| Col_shared_uid -> compare (Mi.uid_list_to_string si1.g_shared_uids) (Mi.uid_list_to_string si2.g_shared_uids) |
327 |
|
with _ -> 0 |
328 |
|
|
329 |
(*************************************************************************) |
(*************************************************************************) |
330 |
(* *) |
(* *) |
333 |
(*************************************************************************) |
(*************************************************************************) |
334 |
|
|
335 |
method force_update_icons () = |
method force_update_icons () = |
336 |
List.iter (fun si -> |
List.iter (fun k -> |
337 |
try |
try |
338 |
let (row, _) = self#find_item si.shared_num in |
let si = shared_file_of_key k in |
339 |
store#set ~row ~column:shared_network_pixb (Mi.network_pixb si.shared_network ~size:A.SMALL ()); |
let row = self#find_row k in |
340 |
store#set ~row ~column:shared_name_pixb (Mi.file_type_of_name si.shared_filename ~size:A.SMALL); |
store#set ~row ~column:shared_network_pixb (Mi.network_pixb si.g_shared_network ~size:A.SMALL ()); |
341 |
|
store#set ~row ~column:shared_name_pixb (Mi.file_type_of_name si.g_shared_filename ~size:A.SMALL); |
342 |
with _ -> () |
with _ -> () |
343 |
) (self#all_items ()) |
) (self#all_items ()) |
344 |
|
|
349 |
module Column = GuiColumns.Client |
module Column = GuiColumns.Client |
350 |
|
|
351 |
type item = source_info |
type item = source_info |
|
type key = int |
|
352 |
|
|
353 |
let columns = O.uploaders_columns |
let columns = O.uploaders_columns |
354 |
let get_key = (fun s -> s.source_num) |
let get_key = (fun s -> (uploader_key s.source_num)) |
355 |
let module_name = "Uploaders" |
let module_name = "Uploaders" |
356 |
|
|
357 |
end) |
end) |
601 |
(* *) |
(* *) |
602 |
(*************************************************************************) |
(*************************************************************************) |
603 |
|
|
604 |
method sort_items c s1 s2 = |
method sort_items c k1 k2 = |
605 |
match c with |
try |
606 |
|
let s1 = uploader_of_key k1 in |
607 |
|
let s2 = uploader_of_key k2 in |
608 |
|
match c with |
609 |
Col_client_name -> compare (String.lowercase s1.source_name) (String.lowercase s2.source_name) |
Col_client_name -> compare (String.lowercase s1.source_name) (String.lowercase s2.source_name) |
610 |
| Col_client_state -> compare s1.source_state s2.source_state |
| Col_client_state -> compare s1.source_state s2.source_state |
611 |
| Col_client_kind -> compare s1.source_kind s2.source_kind |
| Col_client_kind -> compare s1.source_kind s2.source_kind |
619 |
| Col_client_download_rate -> compare s1.source_download_rate s2.source_download_rate |
| Col_client_download_rate -> compare s1.source_download_rate s2.source_download_rate |
620 |
| Col_client_upload_rate -> compare s2.source_upload_rate s2.source_upload_rate |
| Col_client_upload_rate -> compare s2.source_upload_rate s2.source_upload_rate |
621 |
| Col_client_upload -> compare s1.source_upload s2.source_upload |
| Col_client_upload -> compare s1.source_upload s2.source_upload |
622 |
|
with _ -> 0 |
623 |
|
|
624 |
(*************************************************************************) |
(*************************************************************************) |
625 |
(* *) |
(* *) |
628 |
(*************************************************************************) |
(*************************************************************************) |
629 |
|
|
630 |
method force_update_icons () = |
method force_update_icons () = |
631 |
List.iter (fun s -> |
List.iter (fun k -> |
632 |
try |
try |
633 |
let (row, _) = self#find_item s.source_num in |
let s = uploader_of_key k in |
634 |
|
let row = self#find_row k in |
635 |
store#set ~row ~column:uploader_network_pixb (Mi.network_pixb s.source_network ~size:A.SMALL ()); |
store#set ~row ~column:uploader_network_pixb (Mi.network_pixb s.source_network ~size:A.SMALL ()); |
636 |
store#set ~row ~column:uploader_name_pixb (Mi.source_type_to_icon s.source_type ~size:A.SMALL); |
store#set ~row ~column:uploader_name_pixb (Mi.source_type_to_icon s.source_type ~size:A.SMALL); |
637 |
with _ -> () |
with _ -> () |
699 |
|
|
700 |
let copy_ed2k_links sel () = |
let copy_ed2k_links sel () = |
701 |
let buf = Buffer.create 100 in |
let buf = Buffer.create 100 in |
702 |
List.iter (fun s -> |
let l = keys_to_shared_files sel in |
703 |
match s.shared_uids with |
List.iter (fun si -> |
704 |
|
match si.g_shared_uids with |
705 |
uid :: _ -> ( |
uid :: _ -> ( |
706 |
match (Uid.to_uid uid) with |
match (Uid.to_uid uid) with |
707 |
Ed2k md4 -> |
Ed2k md4 -> |
708 |
begin |
begin |
709 |
let link = Printf.sprintf "ed2k://|file|%s|%Ld|%s|" |
let link = Printf.sprintf "ed2k://|file|%s|%Ld|%s|" |
710 |
(Url.encode (Filename.basename s.shared_filename)) |
(Url.encode (Filename.basename si.g_shared_filename)) |
711 |
s.shared_size |
si.g_shared_size |
712 |
(Md4.to_string md4) |
(Md4.to_string md4) |
713 |
in |
in |
714 |
Printf.bprintf buf "%s\n" link; |
Printf.bprintf buf "%s\n" link; |
716 |
| _ -> ()) |
| _ -> ()) |
717 |
|
|
718 |
| _ -> () |
| _ -> () |
719 |
) sel; |
) l; |
720 |
let link = Buffer.contents buf in |
let link = Buffer.contents buf in |
721 |
GuiConsole.insert link; |
GuiConsole.insert link; |
722 |
GMain.clipboard#clear (); |
GMain.clipboard#clear (); |
731 |
(* *) |
(* *) |
732 |
(*************************************************************************) |
(*************************************************************************) |
733 |
|
|
734 |
let upload_menu (sel : shared_info list) = |
let upload_menu sel = |
735 |
match sel with |
match sel with |
736 |
[] -> [] |
[] -> [] |
737 |
| _ -> |
| _ -> |
744 |
(* *) |
(* *) |
745 |
(*************************************************************************) |
(*************************************************************************) |
746 |
|
|
747 |
let filter_upload (si : shared_info) = |
let filter_upload k = |
748 |
not (List.memq si.shared_network !G.networks_filtered) |
try |
749 |
|
let si = shared_file_of_key k in |
750 |
|
not (List.memq si.g_shared_network !G.networks_filtered) |
751 |
|
with _ -> true |
752 |
|
|
753 |
(*************************************************************************) |
(*************************************************************************) |
754 |
(* *) |
(* *) |
775 |
(* *) |
(* *) |
776 |
(*************************************************************************) |
(*************************************************************************) |
777 |
|
|
778 |
let add_upload s = |
let hashtbl_update_shared_files si si_new = |
779 |
ignore (uploadstore#add_item s); |
si.g_shared_filename <- si_new.g_shared_filename; |
780 |
update_uploads_label () |
si.g_shared_size <- si_new.g_shared_size; |
781 |
|
si.g_shared_uploaded <- si_new.g_shared_uploaded; |
782 |
let remove_upload s = |
si.g_shared_requests <- si_new.g_shared_requests; |
783 |
uploadstore#remove_item s; |
si.g_shared_uids <- si_new.g_shared_uids; |
784 |
update_uploads_label () |
si.g_shared_last_seen <- si_new.g_shared_last_seen |
785 |
|
|
786 |
|
let add_upload si = |
787 |
|
ignore (uploadstore#add_item si); |
788 |
|
Hashtbl.add G.shared_files si.g_shared_num si; |
789 |
|
update_uploads_label (); |
790 |
|
let si_uid = Mi.to_uid_type si.g_shared_uids in |
791 |
|
GuiGraphBase.add_file si_uid; |
792 |
|
Hashtbl.add G.file_by_uid si_uid (U.utf8_of si.g_shared_filename) |
793 |
|
|
794 |
|
let remove_upload si = |
795 |
|
uploadstore#remove_item (shared_file_key si.g_shared_num); |
796 |
|
Hashtbl.remove G.shared_files si.g_shared_num; |
797 |
|
update_uploads_label (); |
798 |
|
let si_uid = Mi.to_uid_type si.g_shared_uids in |
799 |
|
GuiGraphBase.cancel_file si_uid; |
800 |
|
Hashtbl.remove G.file_by_uid si_uid |
801 |
|
|
802 |
let h_shared_file_info s_new = |
let h_shared_file_info si_new = |
803 |
try |
try |
804 |
let (row ,s) = uploadstore#find_item s_new.shared_num in |
let si = Hashtbl.find G.shared_files si_new.g_shared_num in |
805 |
uploadstore#update_item row s s_new |
let rate = (Int64.to_float si_new.g_shared_uploaded -. Int64.to_float si.g_shared_uploaded) /. |
806 |
with Not_found -> add_upload s_new |
(si_new.g_shared_last_seen -. si.g_shared_last_seen) |
807 |
|
in |
808 |
|
let row = uploadstore#find_row (shared_file_key si_new.g_shared_num) in |
809 |
|
uploadstore#update_item row si si_new; |
810 |
|
hashtbl_update_shared_files si si_new; |
811 |
|
let rate = int_of_float rate in |
812 |
|
GuiGraphBase.save_record rate (GraphFile ((Mi.to_uid_type si.g_shared_uids), GraphUploads)); |
813 |
|
with Not_found -> add_upload si_new |
814 |
|
|
815 |
let h_shared_file_upload shared_num upsize requests = |
let h_shared_file_upload shared_num upsize requests = |
816 |
try |
try |
817 |
let (row, s) = uploadstore#find_item shared_num in |
let si = Hashtbl.find G.shared_files shared_num in |
818 |
let s_new = {s with shared_uploaded = upsize; shared_requests = requests} in |
let row = uploadstore#find_row (shared_file_key shared_num) in |
819 |
uploadstore#update_item row s s_new |
let si_new = {si with |
820 |
|
g_shared_uploaded = upsize; |
821 |
|
g_shared_requests = requests; |
822 |
|
g_shared_last_seen = BasicSocket.current_time () |
823 |
|
} in |
824 |
|
let rate = (Int64.to_float si_new.g_shared_uploaded -. Int64.to_float si.g_shared_uploaded) /. |
825 |
|
(si_new.g_shared_last_seen -. si.g_shared_last_seen) |
826 |
|
in |
827 |
|
let rate = int_of_float rate in |
828 |
|
uploadstore#update_item row si si_new; |
829 |
|
si.g_shared_size <- si_new.g_shared_size; |
830 |
|
si.g_shared_uploaded <- si_new.g_shared_uploaded; |
831 |
|
si.g_shared_requests <- si_new.g_shared_requests; |
832 |
|
si.g_shared_last_seen <- si_new.g_shared_last_seen; |
833 |
|
GuiGraphBase.save_record rate (GraphFile ((Mi.to_uid_type si.g_shared_uids), GraphUploads)) |
834 |
with Not_found -> |
with Not_found -> |
835 |
(if !!verbose then lprintf' "Shared file %d not found\n" shared_num) |
(if !!verbose then lprintf' "Shared file %d not found\n" shared_num) |
836 |
|
|
837 |
let h_shared_file_unshared shared_num = |
let h_shared_file_unshared shared_num = |
838 |
try |
try |
839 |
let (row, s) = uploadstore#find_item shared_num in |
let si = Hashtbl.find G.shared_files shared_num in |
840 |
remove_upload s |
remove_upload si |
841 |
with Not_found -> |
with Not_found -> |
842 |
(if !!verbose then lprintf' "Shared file %d not found" shared_num) |
(if !!verbose then lprintf' "Shared file %d not found" shared_num) |
843 |
|
|
870 |
(*************************************************************************) |
(*************************************************************************) |
871 |
|
|
872 |
let add_to_friends sel () = |
let add_to_friends sel () = |
873 |
|
let l = keys_to_uploaders sel in |
874 |
List.iter (fun s -> |
List.iter (fun s -> |
875 |
GuiCom.send (AddClientFriend s.source_num) |
GuiCom.send (AddClientFriend s.source_num) |
876 |
) sel |
) l |
877 |
|
|
878 |
let browse_files = add_to_friends |
let browse_files = add_to_friends |
879 |
|
|
880 |
let show_details s () = |
let show_details k () = |
881 |
let item = Source (s, 0) in |
try |
882 |
GuiInfoWindow.window item () |
let s = uploader_of_key k in |
883 |
|
let item = Source (s, 0) in |
884 |
|
GuiInfoWindow.window item () |
885 |
|
with _ -> () |
886 |
|
|
887 |
let update_all uploaders = |
let update_all keys = |
888 |
|
let l = keys_to_uploaders keys in |
889 |
List.iter (fun s -> |
List.iter (fun s -> |
890 |
GuiCom.send (GetClient_info s.source_num) |
GuiCom.send (GetClient_info s.source_num) |
891 |
) uploaders; |
) l; |
892 |
GuiCom.send GetUploaders; |
GuiCom.send GetUploaders; |
893 |
GuiCom.send GetPending |
GuiCom.send GetPending |
894 |
|
|
898 |
(* *) |
(* *) |
899 |
(*************************************************************************) |
(*************************************************************************) |
900 |
|
|
901 |
let uploader_menu (sel : source_info list) = |
let uploader_menu sel = |
902 |
match sel with |
match sel with |
903 |
[] -> [] |
[] -> [] |
904 |
| s :: tail -> |
| k :: tail -> |
905 |
(if tail = [] |
(if tail = [] |
906 |
then |
then |
907 |
[ |
[ |
908 |
`I ((!M.dT_me_show_source_details), show_details s) ; |
`I ((!M.dT_me_show_source_details), show_details k) ; |
909 |
] |
] |
910 |
else []) |
else []) |
911 |
@ |
@ |
920 |
(* *) |
(* *) |
921 |
(*************************************************************************) |
(*************************************************************************) |
922 |
|
|
923 |
let filter_uploader (s : source_info) = not ( |
let filter_uploader k = |
924 |
(not !show_pending && not s.source_has_upload) || |
try |
925 |
List.memq s.source_network !G.networks_filtered) |
let s = uploader_of_key k in |
926 |
|
not ((not !show_pending && (s.source_has_upload <> source_has_upload)) || |
927 |
|
List.memq s.source_network !G.networks_filtered) |
928 |
|
with _ -> true |
929 |
|
|
930 |
(*************************************************************************) |
(*************************************************************************) |
931 |
(* *) |
(* *) |
953 |
(* *) |
(* *) |
954 |
(*************************************************************************) |
(*************************************************************************) |
955 |
|
|
956 |
let remove_uploader uploader_num = |
let remove_uploader s = |
957 |
try |
uploaderstore#remove_item (uploader_key s.source_num); |
958 |
let (_, s) = uploaderstore#find_item uploader_num in |
(if s.source_has_upload = source_has_upload then decr nuploading); |
959 |
uploaderstore#remove_item s; |
s.source_has_upload <- source_only |
960 |
(if s.source_has_upload then decr nuploading); |
|
961 |
s.source_has_upload <- false; |
let update_uploaders () = |
962 |
update_uploaders_label () |
let keys = uploaderstore#all_items () in |
963 |
with _ -> () |
let all_uploaders = keys_to_uploaders keys in |
964 |
|
List.iter (fun s -> |
965 |
let update_uploader s_new = |
if not (List.mem_assoc s.source_num !uploaders_n_pendings) |
966 |
try |
then remove_uploader s |
967 |
let (row, s) = uploaderstore#find_item s_new.source_num in |
) all_uploaders; |
968 |
if s_new.source_has_upload && not s.source_has_upload |
List.iter (fun (num, has_upload) -> |
969 |
then begin |
try |
970 |
incr nuploading |
let s = Hashtbl.find G.sources num in |
971 |
end else if (not s_new.source_has_upload) && s.source_has_upload |
let s_new = {s with source_has_upload = has_upload} in |
972 |
then begin |
try |
973 |
decr nuploading |
let row = uploaderstore#find_row (uploader_key num) in |
974 |
end; |
uploaderstore#update_item row s s_new; |
975 |
uploaderstore#update_item row s s_new; |
begin |
976 |
update_uploaders_label () |
if s_new.source_has_upload = source_has_upload && s.source_has_upload <> source_has_upload |
977 |
with _ -> |
then incr nuploading |
978 |
begin |
else if s_new.source_has_upload <> source_has_upload && s.source_has_upload = source_has_upload |
979 |
ignore (uploaderstore#add_item s_new); |
then decr nuploading |
980 |
(if s_new.source_has_upload then incr nuploading); |
end; |
981 |
update_uploaders_label () |
s.source_has_upload <- s_new.source_has_upload |
982 |
end |
with _ -> |
983 |
|
begin |
984 |
|
s.source_has_upload <- s_new.source_has_upload; |
985 |
|
ignore (uploaderstore#add_item s); |
986 |
|
(if s.source_has_upload = source_has_upload then incr nuploading) |
987 |
|
end |
988 |
|
with _ -> |
989 |
|
begin |
990 |
|
GuiCom.send (GetClient_info num) |
991 |
|
end |
992 |
|
) !uploaders_n_pendings; |
993 |
|
uploaders_n_pendings := []; |
994 |
|
update_uploaders_label () |
995 |
|
|
996 |
let h_update_uploader s_new = |
let h_update_uploader s s_new = |
997 |
try |
try |
998 |
let (row, s) = uploaderstore#find_item s_new.source_num in |
let row = uploaderstore#find_row (uploader_key s_new.source_num) in |
999 |
uploaderstore#update_item row s s_new |
uploaderstore#update_item row s s_new |
1000 |
with _ -> () |
with _ -> () |
1001 |
|
|
1002 |
let h_update_uploaders uploaders = |
let h_update_uploaders uploaders = |
|
let all_uploaders = List.filter (fun s -> s.source_has_upload) (uploaderstore#all_items ()) in |
|
|
List.iter (fun s -> |
|
|
if not (List.mem s.source_num uploaders) |
|
|
then remove_uploader s.source_num; |
|
|
) all_uploaders; |
|
1003 |
List.iter (fun uploader_num -> |
List.iter (fun uploader_num -> |
1004 |
try |
uploaders_n_pendings := (uploader_num, source_has_upload) :: !uploaders_n_pendings |
|
let s = Hashtbl.find G.sources uploader_num in |
|
|
let s_new = {s with source_has_upload = true} in |
|
|
update_uploader s_new; |
|
|
s.source_has_upload <- true |
|
|
with Not_found -> |
|
|
GuiCom.send (GetClient_info uploader_num) |
|
1005 |
) uploaders |
) uploaders |
1006 |
|
|
1007 |
let h_update_pending_slots pending_slots = |
let h_update_pending_slots pending_slots = |
|
let all_pendings = List.filter (fun s -> not s.source_has_upload) (uploaderstore#all_items ()) in |
|
|
List.iter (fun s -> |
|
|
if not (List.mem s.source_num pending_slots) |
|
|
then remove_uploader s.source_num |
|
|
) all_pendings; |
|
1008 |
List.iter (fun uploader_num -> |
List.iter (fun uploader_num -> |
1009 |
try |
uploaders_n_pendings := (uploader_num, source_has_slot) :: !uploaders_n_pendings |
|
let s = Hashtbl.find G.sources uploader_num in |
|
|
let s_new = {s with source_has_upload = false} in |
|
|
update_uploader s_new; |
|
|
s.source_has_upload <- false |
|
|
with Not_found -> |
|
|
GuiCom.send (GetClient_info uploader_num) |
|
1010 |
) pending_slots |
) pending_slots |
1011 |
|
|
1012 |
let clean_uploaders_table uploader = |
let clean_uploaders_table uploader = |
1013 |
remove_uploader uploader.source_num |
remove_uploader uploader |
1014 |
|
|
1015 |
(*************************************************************************) |
(*************************************************************************) |
1016 |
(* *) |
(* *) |
1061 |
view_context := None; |
view_context := None; |
1062 |
upload_label := None; |
upload_label := None; |
1063 |
uploader_label := None; |
uploader_label := None; |
|
Timeout.remove (!uploaders_timerID); |
|
1064 |
)); |
)); |
1065 |
let vbox_uploads = |
let vbox_uploads = |
1066 |
GPack.vbox ~homogeneous:false |
GPack.vbox ~homogeneous:false |
1131 |
uploader_label := Some uploaders_label; |
uploader_label := Some uploaders_label; |
1132 |
update_uploads_label (); |
update_uploads_label (); |
1133 |
update_uploaders_label (); |
update_uploaders_label (); |
1134 |
|
vpaned_uploads#coerce |
1135 |
uploaders_timerID := (Timeout.add ~ms:6000 ~callback: |
|
1136 |
(fun _ -> |
|
1137 |
|
|
1138 |
|
let _ = |
1139 |
|
ignore (Timeout.add ~ms:6000 ~callback: |
1140 |
|
(fun _ -> |
1141 |
|
update_uploaders (); |
1142 |
update_all (uploaderstore#all_items ()); |
update_all (uploaderstore#all_items ()); |
1143 |
refresh_uploadstats (); |
refresh_uploadstats (); |
1144 |
true |
true |
1145 |
)); |
)) |
1146 |
|
|
1147 |
|
|
|
vpaned_uploads#coerce |
|