1 (* Copyright 2001, 2002 b8_bavard, b8_fee_carabine, INRIA *)
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 (** The box with uploads info *)
31 module M
= Gui_messages
33 module O
= Gui_options
34 module C
= Gui_columns
36 let (!!) = Options.(!!)
40 class box columns
() =
42 inherit [GuiTypes.shared_info
] Gpattern.plist `SINGLE
43 (List.map
C.Shared_files_up.string_of_column
!!columns
)
44 true (fun si
-> si
.shared_num
) as pl
45 inherit Gui_uploads_base.box
()
47 val mutable clipboard
= ""
48 val mutable columns
= columns
49 method set_columns l
=
52 (List.map
C.Shared_files_up.string_of_column
!!columns
);
55 method column_menu i
=
57 `I
("Autosize", fun _
-> self#wlist#columns_autosize
());
58 `I
("Sort", self#resort_column i
);
65 match List2.cut i
l with
68 self#set_columns columns
73 `M
("Add Column After", (
74 List.map
(fun (c
,s
) ->
76 let c1, c2
= List2.cut
(i
+1) !!columns
in
77 columns
=:= c1 @ [c
] @ c2
;
78 self#set_columns columns
80 ) Gui_columns.Shared_files_up.column_strings
));
81 `M
("Add Column Before", (
82 List.map
(fun (c
,s
) ->
84 let c1, c2
= List2.cut i
!!columns
in
85 columns
=:= c1 @ [c
] @ c2
;
86 self#set_columns columns
88 ) Gui_columns.Shared_files_up.column_strings
));
91 method box
= wf_upstats#coerce
93 method compare_by_col col si1 si2
=
96 compare si1
.shared_filename si2
.shared_filename
97 | C.Col_shared_requests
->
98 compare si1
.shared_requests si2
.shared_requests
99 | C.Col_shared_upsize
->
100 compare si1
.shared_uploaded si2
.shared_uploaded
101 | C.Col_shared_size
->
102 compare si1
.shared_size si2
.shared_size
104 method compare si1 si2
=
105 let abs = if current_sort
>= 0 then current_sort
else - current_sort
in
107 try List.nth
!!columns
(abs - 1)
108 with _
-> C.Col_shared_file
110 let res = self#compare_by_col
col si1 si2
in
113 method content_by_col si
col =
115 C.Col_shared_file
-> si
.shared_filename
116 | C.Col_shared_requests
-> string_of_int si
.shared_requests
117 | C.Col_shared_upsize
->
118 Gui_misc.size_of_int64 si
.shared_uploaded
119 | C.Col_shared_size
->
120 Gui_misc.size_of_int64 si
.shared_size
123 let strings = List.map
124 (fun col -> P.String
(self#content_by_col si
col))
131 (* fuck the object oriented style: how do I copy something to the
134 let copy_ed2k_links list _
=
135 let buf = Buffer.create
100 in
137 match s
.shared_uids
with
139 match (Uid.to_uid uid
) with
142 let link = Printf.sprintf
"ed2k://|file|%s|%Ld|%s|"
143 (Url.encode
(Filename.basename s
.shared_filename
))
147 Printf.bprintf
buf "%s\n" link;
153 let link = Buffer.contents
buf in
154 !Gui_global.console_message
link;
158 ignore (self#misc#grab_selection `PRIMARY);
159 self#misc#add_selection_target ~target:"string" `PRIMARY;
160 ignore (self#misc#connect#selection_get (fun sel ~info ~time ->
161 lprintf "request selection"; lprint_newline ();
164 ignore (self#event#connect#selection_clear (fun sel ~info ~time ->
165 lprintf "request selection"; lprint_newline ();
170 match self#selection
with
173 [ `I
(("Copy ed2k link to console/clipboard"), copy_ed2k_links list
)
176 method find_file num
= self#find num
178 method h_shared_file_info si
=
180 let _,s_old
= self#find_file si
.shared_num
in
181 s_old
.shared_filename
<- si
.shared_filename
185 method h_shared_file_upload num upsize requests
=
187 let (row
, si
) = self#find_file num
in
188 si
.shared_uploaded
<- upsize
;
189 si
.shared_requests
<- requests
;
190 self#update_row si row
193 lprintf
"Shared file %d not found" num
; lprint_newline
();
196 wf_upstats#add pl#box
;
200 class upstats_box
() =
201 let wl_status = GMisc.label ~text
: "" ~show
: true () in
202 let upstats = new box
O.shared_files_up_columns
() in
204 inherit Gui_uploads_base.upstats_box
() as upsb
206 method wl_status = wl_status
207 method box
= upsb#vbox
208 method upstats_box
= upstats
211 wl_status#set_text
"";
215 Gui_com.send
GuiProto.RefreshUploadStats
217 method h_shared_file_info
=
218 upstats#h_shared_file_info
220 method h_shared_file_upload
=
221 upstats#h_shared_file_upload
223 method set_tb_style tb
=
224 if Options.(!!) Gui_options.mini_toolbars
then
225 (wtool1#misc#hide
(); wtool2#misc#show
()) else
226 (wtool2#misc#hide
(); wtool1#misc#show
());
231 vbox#pack ~expand
: true ~padding
: 2 upstats#box
;
233 Gui_misc.insert_buttons wtool1 wtool2
234 ~text
: (gettext
M.refresh
)
235 ~tooltip
: (gettext
M.refresh
)
236 ~icon
: M.o_xpm_refresh
237 ~callback
: self#refresh
241 Gui_misc.insert_buttons wtool1 wtool2
242 ~text: "Edit Shared Directories"
243 ~tooltip: "Edit Shared Directories"
244 ~icon: M.o_xpm_verify_chunks
246 let module C = Configwin in
248 C.filenames ~f: (fun _ -> ()) "Shared Directories:" []] in
249 match C.simple_edit "Add New Directory" params with
252 | C.Return_cancel -> ()
257 Gui_misc.insert_buttons wtool1 wtool2
258 ~text
: "Add Shared Directory"
259 ~tooltip
: "Add Shared Directory"
260 ~icon
: M.o_xpm_verify_chunks
262 let module C
= Configwin
in
266 C.string ~f
: (fun p
-> prio := int_of_string
(p
)) "Prio:" "0";
267 C.filename ~f
: (fun d
-> dir := d
) "Directory:" ""] in
268 match C.simple_edit
"Add New Directory" ~with_apply
: false
271 if !dir <> "" && !dir <> "/" then
272 Gui_com.send
(Command
(Printf.sprintf
"share %d '%s'" !prio !dir))
274 | C.Return_cancel
-> ()