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 *)
32 module M
= Gui_messages
34 module O
= Gui_options
35 module C
= Gui_columns
37 let (!!) = Options.(!!)
39 class box columns
() =
41 inherit [GuiTypes.shared_info
] Gpattern.plist `SINGLE
42 (List.map
C.Shared_files_up.string_of_column
!!columns
)
43 true (fun si
-> si
.shared_num
) as pl
45 (* inherit Gui_uploads_base.box () *)
47 val mutable clipboard
= ""
48 val mutable columns
= columns
50 method set_list_bg bg font
=
51 let wlist = self#
wlist in
52 let style = wlist#misc#
style#copy
in
53 style#set_base
[ (`NORMAL
, bg
)];
55 wlist#misc#set_style
style;
56 wlist#columns_autosize
()
58 method set_columns l
=
61 (List.map
C.Shared_files_up.string_of_column
!!columns
);
63 self#set_list_bg
(`NAME
!!O.color_list_bg
) (Gdk.Font.load_fontset
!!O.font_list
)
65 method column_menu i
=
67 `I
(M.mAutosize
, fun _
-> self#
wlist#columns_autosize
());
68 `I
(M.mSort
, self#resort_column i
);
75 match List2.cut i
l with
78 self#set_columns columns
83 `M
(M.mAdd_column_after
, (
84 List.map
(fun (c
,s
,_
) ->
86 let c1, c2
= List2.cut
(i
+1) !!columns
in
87 columns
=:= c1 @ [c
] @ c2
;
88 self#set_columns columns
90 ) Gui_columns.Shared_files_up.column_strings
));
91 `M
(M.mAdd_column_before
, (
92 List.map
(fun (c
,s
,_
) ->
94 let c1, c2
= List2.cut i
!!columns
in
95 columns
=:= c1 @ [c
] @ c2
;
96 self#set_columns columns
98 ) Gui_columns.Shared_files_up.column_strings
));
101 (* method box = wf_upstats#coerce *)
103 method compare_by_col col si1 si2
=
106 compare si1
.shared_filename si2
.shared_filename
107 | C.Col_shared_requests
->
108 compare si1
.shared_requests si2
.shared_requests
109 | C.Col_shared_upsize
->
110 compare si1
.shared_uploaded si2
.shared_uploaded
111 | C.Col_shared_size
->
112 compare si1
.shared_size si2
.shared_size
114 method compare si1 si2
=
115 let abs = if current_sort
>= 0 then current_sort
else - current_sort
in
117 try List.nth
!!columns
(abs - 1)
118 with _
-> C.Col_shared_file
120 let res = self#compare_by_col
col si1 si2
in
123 method content_by_col si
col =
125 C.Col_shared_file
-> si
.shared_filename
126 | C.Col_shared_requests
-> string_of_int si
.shared_requests
127 | C.Col_shared_upsize
->
128 Gui_misc.size_of_int64 si
.shared_uploaded
129 | C.Col_shared_size
->
130 Gui_misc.size_of_int64 si
.shared_size
133 let strings = List.map
134 (fun col -> P.String
(self#content_by_col si
col))
141 (* fuck the object oriented style: how do I copy something to the
144 let copy_ed2k_links list _
=
145 let buf = Buffer.create
100 in
147 match s
.shared_uids
with
149 match (Uid.to_uid uid
) with
152 let link = Printf.sprintf
"ed2k://|file|%s|%Ld|%s|"
153 (Url.encode
(Filename.basename s
.shared_filename
))
157 Printf.bprintf
buf "%s\n" link;
163 let link = Buffer.contents
buf in
164 !Gui_global.console_message
link;
168 ignore (self#misc#grab_selection `PRIMARY);
169 self#misc#add_selection_target ~target:"string" `PRIMARY;
170 ignore (self#misc#connect#selection_get (fun sel ~info ~time ->
171 lprintf "request selection"; lprint_newline ();
174 ignore (self#event#connect#selection_clear (fun sel ~info ~time ->
175 lprintf "request selection"; lprint_newline ();
180 match self#selection
with
183 [ `I
((M.uT_me_copy_ed2k
), copy_ed2k_links list
)
186 method find_file num
= self#find num
188 method h_shared_file_info si
=
190 let _,s_old
= self#find_file si
.shared_num
in
191 s_old
.shared_filename
<- si
.shared_filename
195 method h_shared_file_upload num upsize requests
=
197 let (row
, si
) = self#find_file num
in
198 si
.shared_uploaded
<- upsize
;
199 si
.shared_requests
<- requests
;
200 self#update_row si row
203 lprintf
"Shared file %d not found" num
; lprint_newline
();
206 wf_upstats#add pl#box;
211 let refresh_timerID =
212 ref (Timeout.add ~ms
:2000
213 ~callback
:(fun _ -> true))
215 class upstats_box
() =
216 let wl_status = GMisc.label ~text
: "" ~show
: true () in
217 let upstats = new box
O.shared_files_up_columns
() in
218 let uploaders = new Gui_friends.box_list
false in
220 inherit Gui_uploads_base.upstats_box
() as upsb
222 method wl_status = wl_status
223 method box
= upsb#vbox
224 method box_upstats
= upstats
225 method box_uploaders
= uploaders
227 method set_list_bg bg font
=
228 upstats#set_list_bg bg font
;
229 uploaders#set_list_bg bg font
232 wl_status#set_text
"";
236 method h_update_client c
=
237 uploaders#update_client c
239 method h_update_client_state
(num
, state
) =
240 uploaders#update_client_state
(num
, state
)
242 method h_update_client_type
(num
, friend_kind
) =
243 uploaders#update_client_type
(num
, friend_kind
)
245 method clean_table clients
=
246 uploaders#clean_table clients
248 method h_update_uploaders
l =
249 uploaders#update_uploaders
l
251 method h_update_pending_slots
l =
252 uploaders#update_pending_slots
l
255 Gui_com.send
GuiProto.RefreshUploadStats
257 method h_shared_file_info
=
258 upstats#h_shared_file_info
260 method h_shared_file_upload
=
261 upstats#h_shared_file_upload
263 method c_update_icons b
=
264 uploaders#update_icons b
266 method set_tb_style tb
=
267 uploaders#set_tb_style tb
;
268 if Options.(!!) Gui_options.mini_toolbars
then
269 (wtool1#misc#hide
(); wtool2#misc#show
()) else
270 (wtool2#misc#hide
(); wtool1#misc#show
());
274 (* we add a timer to refresh automatically the shared files rows
275 when the uploads tab is visible. This will relief the
276 user to do it : IMHO it is annoying. *)
277 method is_visible b
=
281 (Timeout.add ~ms
:6000
286 Timeout.remove
(!refresh_timerID)
290 vpaned#add1
upstats#box
;
291 hbox_uploaders#add
uploaders#coerce
;
293 let style = evbox1#misc#
style#copy
in
294 style#set_bg
[ (`NORMAL
, (`NAME
"#494949"))];
295 evbox1#misc#set_style
style;
296 let style = label_shared_files#misc#
style#copy
in
297 style#set_fg
[ (`NORMAL
, `WHITE
)];
298 label_shared_files#misc#set_style
style;
300 Gui_misc.insert_buttons wtool1 wtool2
301 ~text
: (M.uT_lb_add_shared_directory
)
302 ~tooltip
: (M.uT_ti_add_shared_directory
)
303 ~icon
: M.o_xpm_add_shared_directory
305 let module C
= Configwin
in
309 C.string ~f
: (fun p
-> prio := int_of_string
(p
)) (M.uT_lb_priority
) "0";
310 C.filename ~f
: (fun d
-> dir := d
) (M.uT_lb_directory
) ""]
312 match C.simple_edit
(M.uT_wt_add_new_directory
)
316 if !dir <> "" && !dir <> "/" then
317 Gui_com.send
(Command
(Printf.sprintf
"share %d '%s'" !prio !dir))
319 | C.Return_cancel
-> ()