/[mldonkey]/mldonkey/src/gtk2/gui/guiDownloads.ml
ViewVC logotype

Diff of /mldonkey/src/gtk2/gui/guiDownloads.ml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by spiralvoice, Fri May 13 21:15:47 2005 UTC revision 1.6 by spiralvoice, Mon Oct 31 18:34:01 2005 UTC
# Line 22  Line 22 
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 GuiColumns  open GuiColumns
# Line 84  let dummy_source = Line 85  let dummy_source =
85       source_upload_rate = 0.;       source_upload_rate = 0.;
86       source_download_rate = 0.;       source_download_rate = 0.;
87       source_upload = None;       source_upload = None;
88       source_has_upload = false;       source_has_upload = source_only;
89       source_availability = [];       source_availability = [];
90       source_files_requested = [];       source_files_requested = [];
91    }    }
92    
93  (*************************************************************************)  (*************************************************************************)
94  (*                                                                       *)  (*                                                                       *)
95    (*                         is_file                                       *)
96    (*                                                                       *)
97    (*************************************************************************)
98    
99    let is_file key = not (String.contains key ':')
100    
101    (*************************************************************************)
102    (*                                                                       *)
103    (*                         is_source                                     *)
104    (*                                                                       *)
105    (*************************************************************************)
106    
107    let is_source key = (snd (String2.cut_at key ':') <> "")
108    
109    (*************************************************************************)
110    (*                                                                       *)
111    (*                         file_num                                      *)
112    (*                                                                       *)
113    (*************************************************************************)
114    
115    let file_num key =
116      if is_file key || is_source key
117      then begin
118        let t = fst (String2.cut_at key ':') in
119        int_of_string t
120      end else raise Not_found
121    
122    (*************************************************************************)
123    (*                                                                       *)
124    (*                         source_num                                    *)
125    (*                                                                       *)
126    (*************************************************************************)
127    
128    let source_num key =
129      if is_source key
130      then begin
131        let t = snd (String2.cut_at key ':') in
132        int_of_string t
133      end else raise Not_found
134    
135    (*************************************************************************)
136    (*                                                                       *)
137    (*                         file_of_key                                   *)
138    (*                                                                       *)
139    (*************************************************************************)
140    
141    let file_of_key key =
142      try
143        let num = file_num key in
144        Hashtbl.find G.files num
145      with _ -> raise Not_found
146    
147    (*************************************************************************)
148    (*                                                                       *)
149    (*                         source_of_key                                 *)
150    (*                                                                       *)
151    (*************************************************************************)
152    
153    let source_of_key key =
154      try
155        let num = source_num key in
156        Hashtbl.find G.sources num
157      with _ -> raise Not_found
158    
159    (*************************************************************************)
160    (*                                                                       *)
161    (*                         keys_to_files                                 *)
162    (*                                                                       *)
163    (*************************************************************************)
164    
165    let keys_to_files keys =
166      let l = ref [] in
167      List.iter (fun k ->
168        try
169          if (is_file k) then
170            let f = file_of_key k in
171            if not (List.memq f !l) then
172              l := f :: !l
173        with _ -> ()) keys;
174      !l
175    
176    (*************************************************************************)
177    (*                                                                       *)
178    (*                         keys_to_sources                               *)
179    (*                                                                       *)
180    (*************************************************************************)
181    
182    let keys_to_sources keys =
183      let l = ref [] in
184      List.iter (fun k ->
185        try
186          let s = source_of_key k in
187          if not (List.memq s !l)
188            then l := s :: !l
189        with _ -> ()) keys;
190      !l
191    
192    (*************************************************************************)
193    (*                                                                       *)
194    (*                         file_key                                      *)
195    (*                                                                       *)
196    (*************************************************************************)
197    
198    let file_key file_num =
199      Printf.sprintf "%d" file_num
200    
201    (*************************************************************************)
202    (*                                                                       *)
203    (*                         source_key                                    *)
204    (*                                                                       *)
205    (*************************************************************************)
206    
207    let source_key file_num source_num =
208      Printf.sprintf "%d:%d" file_num source_num
209    
210    (*************************************************************************)
211    (*                                                                       *)
212    (*                         dummy_source_key                              *)
213    (*                                                                       *)
214    (*************************************************************************)
215    
216    let dummy_source_key file_num =
217      source_key file_num dummy_source.source_num
218    
219    (*************************************************************************)
220    (*                                                                       *)
221  (*                         Templates                                     *)  (*                         Templates                                     *)
222  (*                                                                       *)  (*                                                                       *)
223  (*************************************************************************)  (*************************************************************************)
# Line 98  let dummy_source = Line 225  let dummy_source =
225  let get_key =  let get_key =
226    (fun i ->    (fun i ->
227       match i with       match i with
228           File f -> File_num f.file_num           File f -> (Printf.sprintf "%d" f.g_file_num)
229         | Source (s, file_num) -> Source_num (s.source_num, file_num)         | Source (s, file_num) -> (Printf.sprintf "%d:%d" file_num s.source_num)
230    )    )
231    
232  module Downloads = GuiTemplates.Gview(struct  module Downloads = GuiTemplates.Gview(struct
# Line 107  module Downloads = GuiTemplates.Gview(st Line 234  module Downloads = GuiTemplates.Gview(st
234    module Column = GuiColumns.File    module Column = GuiColumns.File
235    
236    type item = item_info    type item = item_info
   type key  = item_index  
237    
238    let columns = O.downloads_columns    let columns = O.downloads_columns
239    let get_key = get_key    let get_key = get_key
# Line 151  class g_download () = Line 277  class g_download () =
277        match i with        match i with
278            File f ->            File f ->
279              begin              begin
280                store#set ~row ~column:download_network (Mi.network_name f.file_network);                store#set ~row ~column:download_network (Mi.network_name f.g_file_network);
281                store#set ~row ~column:download_network_pixb (Mi.network_pixb f.file_network ~size:A.SMALL ());                store#set ~row ~column:download_network_pixb (Mi.network_pixb f.g_file_network ~size:A.SMALL ());
282                store#set ~row ~column:download_name (U.utf8_of f.file_name);                store#set ~row ~column:download_name (U.utf8_of f.g_file_name);
283                store#set ~row ~column:download_name_pixb (Mi.file_type_of_name f.file_name ~size:A.SMALL);                store#set ~row ~column:download_name_pixb (Mi.file_type_of_name f.g_file_name ~size:A.SMALL);
284                store#set ~row ~column:download_uid (Mi.uid_list_to_string f.file_uids);                store#set ~row ~column:download_uid (Mi.uid_list_to_string f.g_file_uids);
285                store#set ~row ~column:download_size (Mi.size_of_int64 f.file_size);                store#set ~row ~column:download_size (Mi.size_of_int64 f.g_file_size);
286                store#set ~row ~column:download_downloaded (Mi.size_of_int64 f.file_downloaded);                store#set ~row ~column:download_downloaded (Mi.size_of_int64 f.g_file_downloaded);
287                store#set ~row ~column:download_percent (Mi.get_percent_of f.file_downloaded f.file_size);                store#set ~row ~column:download_percent (Mi.get_percent_of f.g_file_downloaded f.g_file_size);
288                store#set ~row ~column:download_sources (Printf.sprintf "(%d / %d)" f.file_active_sources f.file_all_sources);                store#set ~row ~column:download_sources (Printf.sprintf "(%d / %d)" f.g_file_active_sources f.g_file_all_sources);
289                store#set ~row ~column:download_state (Mi.string_of_file_state f.file_state f.file_download_rate);                store#set ~row ~column:download_state (Mi.string_of_file_state f.g_file_state f.g_file_download_rate);
290                let availability = Mi.main_availability_of f.file_network f.file_availability in                let availability = Mi.main_availability_of f.g_file_network f.g_file_availability in
291                store#set ~row ~column:download_availability (Mi.string_of_availability availability f.file_chunks);                store#set ~row ~column:download_availability (Mi.string_of_availability availability f.g_file_chunks);
292                store#set ~row ~column:download_availability_pixb (Mi.availability_bar availability f.file_chunks true);                store#set ~row ~column:download_availability_pixb (Mi.availability_bar availability f.g_file_chunks true);
293                store#set ~row ~column:download_download_rate (Mi.rate_to_string f.file_download_rate);                store#set ~row ~column:download_download_rate (Mi.rate_to_string f.g_file_download_rate);
294                store#set ~row ~column:download_format (Mi.format_to_string f.file_format);                store#set ~row ~column:download_format (Mi.format_to_string f.g_file_format);
295                store#set ~row ~column:download_age (Mi.time_to_string f.file_age);                store#set ~row ~column:download_age (Mi.time_to_string f.g_file_age);
296                store#set ~row ~column:download_last_seen (Mi.time_to_string f.file_last_seen);                store#set ~row ~column:download_last_seen (Mi.time_to_string f.g_file_last_seen);
297                store#set ~row ~column:download_eta_inst (Mi.calc_eta_inst f.file_size f.file_downloaded f.file_download_rate);                store#set ~row ~column:download_eta_inst (Mi.calc_eta_inst f.g_file_size f.g_file_downloaded f.g_file_download_rate);
298                store#set ~row ~column:download_eta_average (Mi.calc_eta_average f.file_size f.file_downloaded f.file_age);                store#set ~row ~column:download_eta_average (Mi.calc_eta_average f.g_file_size f.g_file_downloaded f.g_file_age);
299                store#set ~row ~column:download_priority (Mi.priority_to_string f.file_priority);                store#set ~row ~column:download_priority (Mi.priority_to_string f.g_file_priority);
300                store#set ~row ~column:download_comment (U.utf8_of f.file_comment)                store#set ~row ~column:download_comment (U.utf8_of f.g_file_comment)
301              end              end
302          | Source (s, file_num) ->          | Source (s, file_num) ->
303              try              try
304                let (_, i) = self#find_item (File_num file_num) in                let f = Hashtbl.find G.files file_num in
               let f = match i with File f -> f | _ -> raise Exit in  
305                if s.source_num = (-1)                if s.source_num = (-1)
306                  then begin                  then begin
307                    store#set ~row ~column:download_name s.source_name;                    store#set ~row ~column:download_name s.source_name;
# Line 194  class g_download () = Line 319  class g_download () =
319                    store#set ~row ~column:download_downloaded (Mi.size_of_int64 s.source_downloaded);                    store#set ~row ~column:download_downloaded (Mi.size_of_int64 s.source_downloaded);
320                    store#set ~row ~column:download_percent s.source_software;                    store#set ~row ~column:download_percent s.source_software;
321                    store#set ~row ~column:download_state (Mi.string_of_state s.source_state file_num);                    store#set ~row ~column:download_state (Mi.string_of_state s.source_state file_num);
322                    store#set ~row ~column:download_availability (Mi.string_of_availability availability f.file_chunks);                    store#set ~row ~column:download_availability (Mi.string_of_availability availability f.g_file_chunks);
323                    store#set ~row ~column:download_availability_pixb (Mi.availability_bar availability f.file_chunks false);                    store#set ~row ~column:download_availability_pixb (Mi.availability_bar availability f.g_file_chunks false);
324                    store#set ~row ~column:download_download_rate (Mi.rate_to_string s.source_download_rate);                    store#set ~row ~column:download_download_rate (Mi.rate_to_string s.source_download_rate);
325                  end                  end
326              with _ -> ()              with _ -> ()
# Line 210  class g_download () = Line 335  class g_download () =
335        match (i, i_new) with        match (i, i_new) with
336            (File f, File f_new) ->            (File f, File f_new) ->
337              begin              begin
338                if f.file_comment <> f_new.file_comment                if f.g_file_comment <> f_new.g_file_comment
339                  then begin                  then begin
340                    store#set ~row ~column:download_comment (U.utf8_of f_new.file_comment)                    store#set ~row ~column:download_comment (U.utf8_of f_new.g_file_comment)
341                  end;                  end;
342                if f.file_name <> f_new.file_name                if f.g_file_name <> f_new.g_file_name
343                  then begin                  then begin
344                    store#set ~row ~column:download_name (U.utf8_of f_new.file_name);                    store#set ~row ~column:download_name (U.utf8_of f_new.g_file_name);
345                    if (Mi.extension_of f.file_name) <> (Mi.extension_of f_new.file_name)                    if (Mi.extension_of f.g_file_name) <> (Mi.extension_of f_new.g_file_name)
346                      then begin                      then begin
347                        store#set ~row ~column:download_name_pixb (Mi.file_type_of_name f_new.file_name ~size:A.SMALL);                        store#set ~row ~column:download_name_pixb (Mi.file_type_of_name f_new.g_file_name ~size:A.SMALL);
348                      end                      end
349                  end;                  end;
350                if f.file_uids <> f_new.file_uids                if f.g_file_uids <> f_new.g_file_uids
351                  then begin                  then begin
352                    store#set ~row ~column:download_uid (Mi.uid_list_to_string f.file_uids);                    store#set ~row ~column:download_uid (Mi.uid_list_to_string f.g_file_uids);
353                  end;                  end;
354                if (f.file_size, f.file_downloaded, f.file_download_rate, f.file_age) <>                if (f.g_file_size, f.g_file_downloaded, f.g_file_download_rate, f.g_file_age) <>
355                   (f_new.file_size, f_new.file_downloaded, f_new.file_download_rate, f_new.file_age)                   (f_new.g_file_size, f_new.g_file_downloaded, f_new.g_file_download_rate, f_new.g_file_age)
356                  then begin                  then begin
357                    store#set ~row ~column:download_downloaded (Mi.size_of_int64 f_new.file_downloaded);                    store#set ~row ~column:download_downloaded (Mi.size_of_int64 f_new.g_file_downloaded);
358                    store#set ~row ~column:download_percent (Mi.get_percent_of f_new.file_downloaded f_new.file_size);                    store#set ~row ~column:download_percent (Mi.get_percent_of f_new.g_file_downloaded f_new.g_file_size);
359                    store#set ~row ~column:download_size (Mi.size_of_int64 f_new.file_size);                    store#set ~row ~column:download_size (Mi.size_of_int64 f_new.g_file_size);
360                    store#set ~row ~column:download_age (Mi.time_to_string f_new.file_age);                    store#set ~row ~column:download_age (Mi.time_to_string f_new.g_file_age);
361                    store#set ~row ~column:download_download_rate (Mi.rate_to_string f_new.file_download_rate);                    store#set ~row ~column:download_download_rate (Mi.rate_to_string f_new.g_file_download_rate);
362                    store#set ~row ~column:download_eta_inst (Mi.calc_eta_inst f_new.file_size f_new.file_downloaded                    store#set ~row ~column:download_eta_inst (Mi.calc_eta_inst f_new.g_file_size f_new.g_file_downloaded
363                                                                               f_new.file_download_rate);                                                                               f_new.g_file_download_rate);
364                    store#set ~row ~column:download_eta_average (Mi.calc_eta_average f_new.file_size                    store#set ~row ~column:download_eta_average (Mi.calc_eta_average f_new.g_file_size
365                                                                                     f_new.file_downloaded f_new.file_age);                                                                                     f_new.g_file_downloaded f_new.g_file_age);
366                  end;                  end;
367                if (f.file_state, f.file_download_rate) <> (f_new.file_state, f_new.file_download_rate)                if (f.g_file_state, f.g_file_download_rate) <> (f_new.g_file_state, f_new.g_file_download_rate)
368                  then begin                  then begin
369                    store#set ~row ~column:download_state (Mi.string_of_file_state f_new.file_state f_new.file_download_rate);                    store#set ~row ~column:download_state (Mi.string_of_file_state f_new.g_file_state f_new.g_file_download_rate);
370                  end;                  end;
371                let availability = Mi.main_availability_of f.file_network f.file_availability in                let availability = Mi.main_availability_of f.g_file_network f.g_file_availability in
372                let availability_new = Mi.main_availability_of f_new.file_network f_new.file_availability in                let availability_new = Mi.main_availability_of f_new.g_file_network f_new.g_file_availability in
373                if (availability, f.file_chunks) <> (availability_new, f_new.file_chunks)                if (availability, f.g_file_chunks) <> (availability_new, f_new.g_file_chunks)
374                  then begin                  then begin
375                    store#set ~row ~column:download_availability (Mi.string_of_availability availability_new f_new.file_chunks);                    store#set ~row ~column:download_availability (Mi.string_of_availability availability_new f_new.g_file_chunks);
376                    store#set ~row ~column:download_availability_pixb (Mi.availability_bar availability_new f_new.file_chunks true);                    store#set ~row ~column:download_availability_pixb (Mi.availability_bar availability_new f_new.g_file_chunks true);
377                  end;                  end;
378                if f.file_format <> f_new.file_format                if f.g_file_format <> f_new.g_file_format
379                  then begin                  then begin
380                    store#set ~row ~column:download_format (Mi.format_to_string f_new.file_format);                    store#set ~row ~column:download_format (Mi.format_to_string f_new.g_file_format);
381                  end;                  end;
382                if f.file_last_seen <> f_new.file_last_seen                if f.g_file_last_seen <> f_new.g_file_last_seen
383                  then begin                  then begin
384                    store#set ~row ~column:download_last_seen (Mi.time_to_string f_new.file_last_seen);                    store#set ~row ~column:download_last_seen (Mi.time_to_string f_new.g_file_last_seen);
385                  end;                  end;
386                if f.file_priority <> f_new.file_priority                if f.g_file_priority <> f_new.g_file_priority
387                  then begin                  then begin
388                    store#set ~row ~column:download_priority (Mi.priority_to_string f_new.file_priority);                    store#set ~row ~column:download_priority (Mi.priority_to_string f_new.g_file_priority);
389                  end;                  end;
390                if (f.file_active_sources, f.file_all_sources) <> (f_new.file_active_sources, f_new.file_all_sources)                if (f.g_file_active_sources, f.g_file_all_sources) <> (f_new.g_file_active_sources, f_new.g_file_all_sources)
391                  then begin                  then begin
392                    store#set ~row ~column:download_sources (Printf.sprintf "(%d / %d)" f_new.file_active_sources f_new.file_all_sources);                    store#set ~row ~column:download_sources (Printf.sprintf "(%d / %d)" f_new.g_file_active_sources f_new.g_file_all_sources);
393                  end                  end
394              end              end
395    
396          | (Source (s, file_num), Source (s_new, file_num_new)) when file_num = file_num_new ->          | (Source (s, file_num), Source (s_new, file_num_new)) when file_num = file_num_new ->
397             (try             (try
398                let (_, i) = self#find_item (File_num file_num) in                let f = Hashtbl.find G.files file_num in
               let f = match i with File f -> f | _ -> raise Exit in  
399                if s.source_num <> (-1)                if s.source_num <> (-1)
400                  then begin                  then begin
401                    if s.source_name <> s_new.source_name                    if s.source_name <> s_new.source_name
# Line 306  class g_download () = Line 430  class g_download () =
430                    in                    in
431                    if availability <> new_availability                    if availability <> new_availability
432                      then begin                      then begin
433                        store#set ~row ~column:download_availability (Mi.string_of_availability new_availability f.file_chunks);                        store#set ~row ~column:download_availability (Mi.string_of_availability new_availability f.g_file_chunks);
434                        store#set ~row ~column:download_availability_pixb (Mi.availability_bar new_availability f.file_chunks false)                        store#set ~row ~column:download_availability_pixb (Mi.availability_bar new_availability f.g_file_chunks false)
435                      end;                      end;
436                    if s_new.source_download_rate <> s.source_download_rate                    if s_new.source_download_rate <> s.source_download_rate
437                      then begin                      then begin
# Line 337  class g_download () = Line 461  class g_download () =
461                let renderer = GTree.cell_renderer_text [`XALIGN 0.] in                let renderer = GTree.cell_renderer_text [`XALIGN 0.] in
462                col#pack ~expand:false renderer;                col#pack ~expand:false renderer;
463                col#set_cell_data_func renderer                col#set_cell_data_func renderer
464                 (fun model row ->                  (fun model row ->
465                    match !view_context with                     match !view_context with
466                        Some context when col#width > 0 ->                         Some context when col#width > 0 ->
467                          begin                           begin
468                            let width =                             let width =
469                              if !!O.gtk_look_use_icons                               if !!O.gtk_look_use_icons
470                                then (col#width - 4 - !!O.gtk_look_lists_icon_size) - 4 * !G.char_width                                 then (col#width - 4 - !!O.gtk_look_lists_icon_size) - 4 * !G.char_width
471                                else col#width - 4 * !G.char_width                                 else col#width - 4 * !G.char_width
472                            in                             in
473                            let name = model#get ~row ~column:download_name in                             let name = model#get ~row ~column:download_name in
474                            let s = GuiTools.fit_string_to_pixels name ~context ~pixels:width in                             let s = GuiTools.fit_string_to_pixels name ~context ~pixels:width in
475                            renderer#set_properties [ `TEXT s ];                             renderer#set_properties [ `TEXT s ];
476                            let item = self#get_item row in                             let key = self#find_model_key row in
477                            begin                             if (is_file key) then begin
478                              match item with                               renderer#set_properties [ `EDITABLE true ];
479                                  File f ->                               ignore (renderer#connect#edited ~callback:
480                                    renderer#set_properties [ `EDITABLE true ];                                 (fun path name ->
481                                    ignore (renderer#connect#edited ~callback:                                    try
482                                      (fun path name ->                                      let iter = self#get_iter path in
483                                         try                                      let k = self#find_model_key iter in
484                                           let iter = self#get_iter path in                                      if (is_file k) then begin
485                                           let item = self#get_item iter in                                        let file = file_of_key k in
486                                           match item with                                        (match file.g_file_state with
487                                               File ff ->                                             FileDownloaded  -> GuiCom.send (SaveFile (file.g_file_num, name))
488                                                 let child_row = self#convert_iter_to_child_iter iter in                                           | _  ->  GuiCom.send (RenameFile (file.g_file_num, name)));
489                                                 store#set ~row:child_row ~column:download_name ff.file_name;                                        let store_iter = self#convert_iter_to_child_iter iter in
490                                                 (match ff.file_state with                                        store#set ~row:store_iter ~column:download_name file.g_file_name
491                                                     FileDownloaded  -> GuiCom.send (SaveFile (ff.file_num, name))                                      end
492                                                   | _  ->  GuiCom.send (RenameFile (ff.file_num, name)))                                    with _ -> ()
                                            | _ -> ()  
   
                                        with _ -> ()  
493                                    ))                                    ))
494    
495                                | _ -> renderer#set_properties [ `EDITABLE false ]                               end else renderer#set_properties [ `EDITABLE false ]
496                             end
                           end  
                         end  
497    
498                        | _ -> renderer#set_properties [ `TEXT "" ]                        | _ -> renderer#set_properties [ `TEXT "" ]
499                )                  )
500             end              end
501    
502          | Col_file_size ->          | Col_file_size ->
503              begin              begin
# Line 529  class g_download () = Line 648  class g_download () =
648  (*                                                                       *)  (*                                                                       *)
649  (*************************************************************************)  (*************************************************************************)
650    
651      method sort_items c i1 i2 =      method sort_items c k1 k2 =
652        match (i1, i2) with        match (is_file k1, is_file k2) with
653            (File f1, File f2) ->            (true, true) ->
654               begin               begin try
655                   let f1 = file_of_key k1 in
656                   let f2 = file_of_key k2 in
657                 match c with                 match c with
658                     Col_file_name -> compare (String.lowercase f1.file_name) (String.lowercase f2.file_name)                     Col_file_name -> compare (String.lowercase f1.g_file_name) (String.lowercase f2.g_file_name)
659                   | Col_file_size -> compare f1.file_size f2.file_size                   | Col_file_size -> compare f1.g_file_size f2.g_file_size
660                   | Col_file_downloaded -> compare f1.file_downloaded f2.file_downloaded                   | Col_file_downloaded -> compare f1.g_file_downloaded f2.g_file_downloaded
661                   | Col_file_percent -> compare (float_of_string (Mi.get_percent_of f1.file_downloaded f1.file_size))                   | Col_file_percent -> compare (float_of_string (Mi.get_percent_of f1.g_file_downloaded f1.g_file_size))
662                                                 (float_of_string (Mi.get_percent_of f2.file_downloaded f2.file_size))                                                 (float_of_string (Mi.get_percent_of f2.g_file_downloaded f2.g_file_size))
663                   | Col_file_rate -> compare f1.file_download_rate f2.file_download_rate                   | Col_file_rate -> compare f1.g_file_download_rate f2.g_file_download_rate
664                   | Col_file_state -> compare (Mi.string_of_file_state f1.file_state f1.file_download_rate)                   | Col_file_state -> compare (Mi.string_of_file_state f1.g_file_state f1.g_file_download_rate)
665                                               (Mi.string_of_file_state f2.file_state f2.file_download_rate)                                               (Mi.string_of_file_state f2.g_file_state f2.g_file_download_rate)
666                   | Col_file_availability ->                   | Col_file_availability ->
667                       begin                       begin
668                         let av1 = Mi.main_availability_of f1.file_network f1.file_availability in                         let av1 = Mi.main_availability_of f1.g_file_network f1.g_file_availability in
669                         let av2 = Mi.main_availability_of f2.file_network f2.file_availability in                         let av2 = Mi.main_availability_of f2.g_file_network f2.g_file_availability in
670                         if !!O.gtk_look_graphical_availability                         if !!O.gtk_look_graphical_availability
671                           then begin                           then begin
672                             Mi.sort_availability_bar (av1, f1.file_chunks) (av2, f2.file_chunks) true                             Mi.sort_availability_bar (av1, f1.g_file_chunks) (av2, f2.g_file_chunks) true
673                           end else begin                           end else begin
674                             let s1 = Mi.string_of_availability av1 f1.file_chunks in                             let s1 = Mi.string_of_availability av1 f1.g_file_chunks in
675                             let s2 = Mi.string_of_availability av2 f2.file_chunks in                             let s2 = Mi.string_of_availability av2 f2.g_file_chunks in
676                             compare (float_of_string s1) (float_of_string s2)                             compare (float_of_string s1) (float_of_string s2)
677                           end                           end
678                       end                       end
679                   | Col_file_uid -> compare (Mi.uid_list_to_string f1.file_uids) (Mi.uid_list_to_string f2.file_uids)                   | Col_file_uid -> compare (Mi.uid_list_to_string f1.g_file_uids) (Mi.uid_list_to_string f2.g_file_uids)
680                   | Col_file_format -> compare f1.file_format f2.file_format                   | Col_file_format -> compare f1.g_file_format f2.g_file_format
681                   | Col_file_network -> compare f1.file_network f2.file_network                   | Col_file_network -> compare f1.g_file_network f2.g_file_network
682                   | Col_file_age -> compare f1.file_age f2.file_age                   | Col_file_age -> compare f1.g_file_age f2.g_file_age
683                   | Col_file_last_seen -> compare f1.file_last_seen f2.file_last_seen                   | Col_file_last_seen -> compare f1.g_file_last_seen f2.g_file_last_seen
684                   | Col_file_eta -> compare (Mi.calc_eta_inst f1.file_size f1.file_downloaded f1.file_download_rate)                   | Col_file_eta -> compare (Mi.calc_eta_inst f1.g_file_size f1.g_file_downloaded f1.g_file_download_rate)
685                                             (Mi.calc_eta_inst f2.file_size f2.file_downloaded f2.file_download_rate)                                             (Mi.calc_eta_inst f2.g_file_size f2.g_file_downloaded f2.g_file_download_rate)
686                   | Col_file_priority -> compare f1.file_priority f2.file_priority                   | Col_file_priority -> compare f1.g_file_priority f2.g_file_priority
687                   | Col_file_comment -> compare f1.file_comment f2.file_comment                   | Col_file_comment -> compare f1.g_file_comment f2.g_file_comment
688                   | Col_file_sources ->                   | Col_file_sources ->
689                       begin                       begin
690                         let i = compare f1.file_active_sources f2.file_active_sources in                         let i = compare f1.g_file_active_sources f2.g_file_active_sources in
691                         if i = 0                         if i = 0
692                           then compare f1.file_all_sources f2.file_all_sources                           then compare f1.g_file_all_sources f2.g_file_all_sources
693                           else i                           else i
694                       end                       end
695               end               with _ -> 0 end
696    
697          | (Source (s1, file_num_a), Source (s2, file_num_b)) when file_num_a = file_num_b ->          | (false, false) when (try file_num k1 = file_num k2 with _ -> false) ->
698               begin               begin try
699                   let s1 = source_of_key k1 in
700                   let s2 = source_of_key k2 in
701                   let file_num = file_num k1 in
702                 match c with                 match c with
703                     Col_file_name -> compare (String.lowercase s1.source_name)                     Col_file_name -> compare (String.lowercase s1.source_name)
704                                              (String.lowercase s2.source_name)                                              (String.lowercase s2.source_name)
705                   | Col_file_downloaded -> compare s1.source_downloaded s2.source_downloaded                   | Col_file_downloaded -> compare s1.source_downloaded s2.source_downloaded
706                   | Col_file_percent -> compare s1.source_software s2.source_software                   | Col_file_percent -> compare s1.source_software s2.source_software
707                   | Col_file_state -> compare (Mi.string_of_state s1.source_state file_num_a)                   | Col_file_state -> compare (Mi.string_of_state s1.source_state file_num)
708                                               (Mi.string_of_state s2.source_state file_num_a)                                               (Mi.string_of_state s2.source_state file_num)
709                   | Col_file_availability ->                   | Col_file_availability ->
710                       begin                       begin
711                         try                         try
712                           let (_, i1) = self#find_item (File_num file_num_a) in                           let f = Hashtbl.find G.files file_num in
713                           let (_ ,i2) = self#find_item (File_num file_num_b) in                           let av_s1 = try List.assoc file_num s1.source_availability with _ -> "" in
714                           let f1 = match i1 with File f -> f | _ -> raise Exit in                           let av_s2 = try List.assoc file_num s2.source_availability with _ -> "" in
                          let f2 = match i2 with File f -> f | _ -> raise Exit in  
                          let av_s1 = try List.assoc file_num_a s1.source_availability with _ -> "" in  
                          let av_s2 = try List.assoc file_num_a s2.source_availability with _ -> "" in  
715                           if !!O.gtk_look_graphical_availability                           if !!O.gtk_look_graphical_availability
716                             then begin                             then begin
717                               Mi.sort_availability_bar (av_s1, f1.file_chunks) (av_s2, f2.file_chunks) false                               Mi.sort_availability_bar (av_s1, f.g_file_chunks) (av_s2, f.g_file_chunks) false
718                             end else begin                             end else begin
719                               let av1 = Mi.string_of_availability av_s1 f1.file_chunks in                               let av1 = Mi.string_of_availability av_s1 f.g_file_chunks in
720                               let av2 = Mi.string_of_availability av_s2 f2.file_chunks in                               let av2 = Mi.string_of_availability av_s2 f.g_file_chunks in
721                               compare (float_of_string av1) (float_of_string av2)                               compare (float_of_string av1) (float_of_string av2)
722                             end                             end
723                         with _ -> 0                         with _ -> 0
# Line 604  class g_download () = Line 725  class g_download () =
725                   | Col_file_network -> compare s1.source_network s2.source_network                   | Col_file_network -> compare s1.source_network s2.source_network
726                   | Col_file_rate -> compare s1.source_download_rate s2.source_download_rate                   | Col_file_rate -> compare s1.source_download_rate s2.source_download_rate
727                   | _ -> 0                   | _ -> 0
728               end               with _ -> 0 end
729    
730          | _ -> 0          | _ -> 0
731    
# Line 615  class g_download () = Line 736  class g_download () =
736  (*************************************************************************)  (*************************************************************************)
737    
738      method force_update_icons () =      method force_update_icons () =
739        List.iter (fun i ->        List.iter (fun k ->
740          try          try
741            let (row, i_) = self#find_item (get_key i) in            let row = self#find_row k in
742            match i with            if (is_file k) then begin
743                File f ->              let f = file_of_key k in
744                   begin              store#set ~row ~column:download_network_pixb (Mi.network_pixb f.g_file_network ~size:A.SMALL ());
745                     store#set ~row ~column:download_network_pixb (Mi.network_pixb f.file_network ~size:A.SMALL ());              store#set ~row ~column:download_name_pixb (Mi.file_type_of_name f.g_file_name ~size:A.SMALL);
746                     store#set ~row ~column:download_name_pixb (Mi.file_type_of_name f.file_name ~size:A.SMALL);            end else begin
747                   end              let s = source_of_key k in
748              | Source (s, file_num) ->              store#set ~row ~column:download_network_pixb (Mi.network_pixb s.source_network ~size:A.SMALL ());
749                  begin              store#set ~row ~column:download_name_pixb (Mi.source_type_to_icon s.source_type ~size:A.SMALL);
750                    store#set ~row ~column:download_network_pixb (Mi.network_pixb s.source_network ~size:A.SMALL ());            end
                   store#set ~row ~column:download_name_pixb (Mi.source_type_to_icon s.source_type ~size:A.SMALL);  
                 end  
751          with _ -> ()          with _ -> ()
752        ) (self#all_items ())        ) (self#all_items ())
753    
# Line 639  class g_download () = Line 758  class g_download () =
758  (*************************************************************************)  (*************************************************************************)
759    
760      method force_update_avail_bars () =      method force_update_avail_bars () =
761        List.iter (fun i ->        List.iter (fun k ->
762          try          try
763            let (row, _) = self#find_item (get_key i) in            let row = self#find_row k in
764            if !!O.gtk_look_graphical_availability            if !!O.gtk_look_graphical_availability
765              then match i with              then if (is_file k) then begin
766                       File f ->                 let f = file_of_key k in
767                         begin                 let availability = Mi.main_availability_of f.g_file_network f.g_file_availability in
768                           let availability = Mi.main_availability_of f.file_network f.file_availability in                 store#set ~row ~column:download_availability_pixb (Mi.availability_bar availability f.g_file_chunks true);
769                           store#set ~row ~column:download_availability_pixb (Mi.availability_bar availability f.file_chunks true);              end else begin
770                         end                 let f = file_of_key k in
771                     | Source (s, file_num) ->                 let s = source_of_key k in
772                         begin                 let availability =
773                           let (_, i') = self#find_item (File_num file_num) in                   try
774                           let f = match i' with File f -> f | _ -> raise Exit in                     List.assoc (file_num k) s.source_availability
775                           let availability =                   with _ -> ""
776                             try                 in
777                               List.assoc file_num s.source_availability                 store#set ~row ~column:download_availability_pixb (Mi.availability_bar availability f.g_file_chunks false);
778                             with _ -> ""              end else store#set ~row ~column:download_availability_pixb None
                          in  
                          store#set ~row ~column:download_availability_pixb (Mi.availability_bar availability f.file_chunks false);  
                        end  
   
             else store#set ~row ~column:download_availability_pixb None  
779          with _ -> ()          with _ -> ()
780        ) (self#all_items ())        ) (self#all_items ())
781    
# Line 684  let on_entry_return entry = Line 798  let on_entry_return entry =
798            entry#set_text ""            entry#set_text ""
799          end          end
800    
801  let preview f () = GuiCom.send (Preview f.file_num)  let preview k () = try GuiCom.send (Preview (file_num k)) with _ -> ()
802    
803  let show_details item () = GuiInfoWindow.window item ()  let show_details k () =
804      try
805        let item =
806          if is_file k
807          then File (file_of_key k)
808          else Source ((source_of_key k), file_num k)
809        in GuiInfoWindow.window item ()
810      with _ -> ()
811    
812  let pause_resume sel () =  let pause_resume sel () =
813    List.iter (fun item ->    List.iter (fun k ->
814      match item with      if is_file k
815          File f ->      then try
816             GuiCom.send (SwitchDownload (f.file_num,        let f = file_of_key k in
817                match f.file_state with        let state =
818                  FilePaused | FileAborted _ -> true          match f.g_file_state with
819                | _ -> false              FilePaused | FileAborted _ -> true
820             ))            | _ -> false
821        | _ -> ()        in
822          GuiCom.send (SwitchDownload (f.g_file_num, state))
823        with _ -> ()
824    ) sel    ) sel
825    
826  let retry_connect sel () =  let retry_connect sel () =
827    List.iter (fun item ->    List.iter (fun k ->
828      match item with      if is_file k
829          File f ->      then try
830             GuiCom.send (ConnectAll f.file_num)        GuiCom.send (ConnectAll (file_num k))
831        | _ -> ()      with _ -> ()
832    ) sel    ) sel
833    
834  let cancel sel () =  let cancel sel () =
835    let warning_message = !M.dT_lb_ask_cancel_download_files in    let warning_message = !M.dT_lb_ask_cancel_download_files in
836    let l = ref [] in    let l = ref [] in
837    List.iter (fun item ->    List.iter (fun k ->
838      match item with      if is_file k
839          File f ->      then try
840            l := f.file_name :: !l        let f = file_of_key k in
841        | _ -> ()        l := f.g_file_name :: !l
842        with _ -> ()
843    ) sel;    ) sel;
844    let on_ok () =    let on_ok () =
845      List.iter (fun item ->      List.iter (fun k ->
846        match item with      if is_file k
847            File f ->      then try
848              (* Printf.printf "ASK to Cancel file : %d\n" f.file_num;        GuiCom.send (RemoveDownload_query (file_num k))
849              flush stdout; *)      with _ -> ()
             GuiCom.send (RemoveDownload_query f.file_num)  
         | _ -> ()  
850      ) sel      ) sel
851    in    in
852    GuiTools.warning_box ~warning_message ~text:!l ~on_ok ()    GuiTools.warning_box ~warning_message ~text:!l ~on_ok ()
853    
854  let verify_chunks sel () =  let verify_chunks sel () =
855    List.iter (fun item ->    List.iter (fun k ->
856      match item with      if is_file k
857          File f ->      then try
858             GuiCom.send (VerifyAllChunks f.file_num)        GuiCom.send (VerifyAllChunks (file_num k))
859        | _ -> ()      with _ -> ()
860    ) sel    ) sel
861    
862  let set_priority sel prio () =  let set_priority sel prio () =
863    List.iter (fun item ->    List.iter (fun k ->
864      match item with      if is_file k
865          File f ->      then try
866             GuiCom.send (SetFilePriority (f.file_num, prio))        GuiCom.send (SetFilePriority (file_num k, prio))
867        | _ -> ()      with _ -> ()
868    ) sel    ) sel
869    
870  let preference label v box_type opt_list =  let preference label v box_type opt_list =
# Line 766  let preference label v box_type opt_list Line 888  let preference label v box_type opt_list
888    }    }
889    
890  let edit_mp3_tags f () =  let edit_mp3_tags f () =
891    match f.file_format with    match f.g_file_format with
892        MP3 (tag,_) ->        MP3 (tag,_) ->
893          begin          begin
894            let module C = ConfigWindow in            let module C = ConfigWindow in
# Line 787  let edit_mp3_tags f () = Line 909  let edit_mp3_tags f () =
909              tag.P.comment <- comment.C.pref_new_value;              tag.P.comment <- comment.C.pref_new_value;
910              tag.P.tracknum <- int_of_float (C.safe_int tracknum.C.pref_new_value);              tag.P.tracknum <- int_of_float (C.safe_int tracknum.C.pref_new_value);
911              tag.P.genre <- Mp3_misc.genre_of_string genre.C.pref_new_value;              tag.P.genre <- Mp3_misc.genre_of_string genre.C.pref_new_value;
912              GuiCom.send (ModifyMp3Tags (f.file_num, tag))              GuiCom.send (ModifyMp3Tags (f.g_file_num, tag))
913            in            in
914            C.simple_panel            C.simple_panel
915                ~prefs:[title;artist;album;year;comment;tracknum;genre]                ~prefs:[title;artist;album;year;comment;tracknum;genre]
# Line 795  let edit_mp3_tags f () = Line 917  let edit_mp3_tags f () =
917                ~icon:(A.get_icon ~icon:M.icon_menu_search_mp3 ~size:A.SMALL ())                ~icon:(A.get_icon ~icon:M.icon_menu_search_mp3 ~size:A.SMALL ())
918                ~on_ok ()                ~on_ok ()
919          end          end
   
920      | _ -> ()      | _ -> ()
921    
 let save_all () =  
   List.iter (fun i ->  
     match i with  
         File f ->  
           (match f.file_state with  
               FileDownloaded ->  
                 GuiCom.send (SaveFile (f.file_num, f.file_name))  
             | _ -> ())  
922    
923        | _ -> ()  let get_format sel () =
924      List.iter (fun k ->
925        if is_file k then try
926          GuiCom.send (QueryFormat (file_num k))
927        with _ -> ()
928      ) sel
929    
930    let save_all () =
931      List.iter (fun k ->
932        if is_file k
933        then try
934          let f = file_of_key k in
935          match f.g_file_state with
936              FileDownloaded -> GuiCom.send (SaveFile (f.g_file_num, f.g_file_name))
937            | _ -> ()
938        with _ -> ()
939    ) (downloadstore#all_items ())    ) (downloadstore#all_items ())
940    
 (*  
 let save_as f () =  
   let file_opt = GToolbox.input_string ~title:(!M.dT_wt_save_as)  
     ~text:(U.utf8_of f.file_name)  
     (!M.dT_lb_save_as)  
   in  
   match file_opt with  
     None -> ()  
   | Some name ->  
       match f.file_state with  
            FileDownloaded  -> GuiCom.send (SaveFile (f.file_num, name))  
         | _  ->  GuiCom.send (RenameFile (f.file_num, name))  
 *)  
   
941  let add_to_friends sel () =  let add_to_friends sel () =
942    List.iter (fun item ->    List.iter (fun k ->
943      match item with      if is_source k then try
944          Source (s, _) ->        GuiCom.send (AddClientFriend (source_num k))
945             GuiCom.send (AddClientFriend s.source_num)      with _ -> ()
       | _ -> ()  
946    ) sel    ) sel
947    
948  let browse_files = add_to_friends  let browse_files = add_to_friends
# Line 849  let ask_for_sources () = Line 961  let ask_for_sources () =
961        GuiCom.send (InterestedInSources true)        GuiCom.send (InterestedInSources true)
962      end      end
963    
964  let get_format sel () =  let update_downloading_files () =
965    List.iter (fun item ->    let keys = downloadstore#all_items () in
966      match item with    let files = keys_to_files keys in
967          File f ->    List.iter (fun f ->
968             GuiCom.send (QueryFormat f.file_num)      GuiCom.send (GetFile_info f.g_file_num)
969        | _ -> ()    ) files
   ) sel  
970    
971  (*************************************************************************)  (*************************************************************************)
972  (*                                                                       *)  (*                                                                       *)
# Line 866  let get_format sel () = Line 977  let get_format sel () =
977  let download_menu sel =  let download_menu sel =
978      match sel with      match sel with
979          [] -> []          [] -> []
980        | (File f) :: tail ->        | k :: tail when (is_file k) ->
981            (if tail = []            (if tail = []
982               then               then
983                 [                 [
984                  `I ((!M.dT_me_show_file_details), show_details (File f)) ;                  `I ((!M.dT_me_show_file_details), show_details k) ;
985                  `I ((!M.dT_me_preview), preview f) ;                  `I ((!M.dT_me_preview), preview k) ;
986                  `S ;                  `S ;
987                 ]                 ]
988               else  [])               else  [])
# Line 890  let download_menu sel = Line 1001  let download_menu sel =
1001                       ]) ::                       ]) ::
1002                  `S ::                  `S ::
1003                  `I ((!M.dT_me_get_format), get_format sel) ::                  `I ((!M.dT_me_get_format), get_format sel) ::
1004               (match (f.file_state, f.file_format) with               (try let f = file_of_key k in
1005                  match (f.g_file_state, f.g_file_format) with
1006                    (FileDownloaded, MP3 _) ->                    (FileDownloaded, MP3 _) ->
1007                 [                 [
1008                  `I ((!M.dT_me_edit_mp3), edit_mp3_tags f)                  `I ((!M.dT_me_edit_mp3), edit_mp3_tags f)
1009                 ]                 ]
1010                  | _ ->                  | _ ->
1011                 [])                 [] with _ -> [])
1012               @               @
1013                  `I ((!M.dT_me_save_all), save_all) :: [] (*                  `I ((!M.dT_me_save_all), save_all) :: [] (*
1014                  (if tail = [] then                  (if tail = [] then
# Line 905  let download_menu sel = Line 1017  let download_menu sel =
1017                 ]                 ]
1018              else  []) *)              else  []) *)
1019    
1020        | (Source (s, file_num)) :: tail ->        | k :: tail when (is_source k) ->
1021            if s.source_num = (-1)            if (source_num k) = (-1)
1022              then []              then []
1023              else              else
1024                (if tail = []                (if tail = []
1025                   then                   then
1026                     [                     [
1027                      `I ((!M.dT_me_show_source_details), show_details (Source (s, file_num))) ;                      `I ((!M.dT_me_show_source_details), show_details k) ;
1028                     ]                     ]
1029                   else  [])                   else  [])
1030                @                @
# Line 920  let download_menu sel = Line 1032  let download_menu sel =
1032                      `I (!M.dT_me_browse_files, browse_files sel);                      `I (!M.dT_me_browse_files, browse_files sel);
1033                      `I (!M.dT_me_add_to_friends, add_to_friends sel)                      `I (!M.dT_me_add_to_friends, add_to_friends sel)
1034                     ]                     ]
1035          | _ -> []
1036    
1037  (*************************************************************************)  (*************************************************************************)
1038  (*                                                                       *)  (*                                                                       *)
# Line 927  let download_menu sel = Line 1040  let download_menu sel =
1040  (*                                                                       *)  (*                                                                       *)
1041  (*************************************************************************)  (*************************************************************************)
1042    
1043  let filter_download i =  let filter_download k =
1044    match i with    if is_file k
1045        File f -> not (List.memq f.file_network !G.networks_filtered)    then begin
1046      | Source (s, _) -> not (List.memq s.source_network !G.networks_filtered)(*  &&      try
1047                         s.source_state <> NewHost &&        let f = file_of_key k in
1048                         (s.source_name <> "" && s.source_software <> "unk") *)        not (List.memq f.g_file_network !G.networks_filtered)
1049        with _ -> true
1050      end else begin
1051        try
1052          let s = source_of_key k in
1053          not (List.memq s.source_network !G.networks_filtered)
1054    (*    && s.source_state <> NewHost && (s.source_name <> "" && s.source_software <> "unk") *)
1055        with _ -> true
1056      end
1057    
1058  (*************************************************************************)  (*************************************************************************)
1059  (*                                                                       *)  (*                                                                       *)
# Line 953  let clean_avail_bars () = Line 1074  let clean_avail_bars () =
1074    if !!O.gtk_look_graphical_availability    if !!O.gtk_look_graphical_availability
1075      then begin      then begin
1076        let list = ref [] in        let list = ref [] in
1077        List.iter (fun i ->        List.iter (fun k ->
1078          match i with          if is_file k
1079              File f ->            then begin
1080                begin              try
1081                  let availability = Mi.main_availability_of f.file_network f.file_availability in                let f = file_of_key k in
1082                  let key = (availability, f.file_chunks, true) in                let availability = Mi.main_availability_of f.g_file_network f.g_file_availability in
1083                  if not (List.mem key !list)                let key = (availability, f.g_file_chunks, true) in
1084                    then begin list := key :: !list end;                if not (List.mem key !list)
1085                  match f.file_sources with                  then begin list := key :: !list end;
1086                      None -> ()                match f.g_file_sources with
1087                    | Some sources ->                    None -> ()
1088                        List.iter (fun source_num ->                  | Some sources ->
1089                          let s = Hashtbl.find G.sources source_num in                      List.iter (fun source_num ->
1090                          List.iter (fun (_, avail) ->                        let s = Hashtbl.find G.sources source_num in
1091                            let key = (avail, f.file_chunks, false) in                        List.iter (fun (_, avail) ->
1092                            if not (List.mem key !list)                          let key = (avail, f.g_file_chunks, false) in
1093                              then list := key :: !list                          if not (List.mem key !list)
1094                          ) s.source_availability;                            then list := key :: !list
1095                        ) sources                        ) s.source_availability;
1096                end                      ) sources
1097               with _ -> ()
1098            | _ -> ()            end
   
1099        ) (downloadstore#all_items ());        ) (downloadstore#all_items ());
1100        A.clean_avail_bars !list        A.clean_avail_bars !list
1101      end      end
# Line 1007  let reset_downloads_filter () = Line 1127  let reset_downloads_filter () =
1127  (*                                                                       *)  (*                                                                       *)
1128  (*************************************************************************)  (*************************************************************************)
1129    
1130    let all_files_razorback2_stats () =
1131      let l = List.filter (fun k -> is_file k) (downloadstore#all_items ()) in
1132      List.iter (fun k ->
1133        try
1134          let file = file_of_key k in
1135          GuiHtml.get_razorback2_stats file
1136        with _ -> ()
1137      ) l
1138    
1139    let hashtbl_update f f_new =
1140      f.g_file_comment <- f_new.g_file_comment;
1141      f.g_file_name <- f_new.g_file_name;
1142      f.g_file_names <- f_new.g_file_names;
1143      f.g_file_size <- f_new.g_file_size;
1144      f.g_file_downloaded <- f_new.g_file_downloaded;
1145      f.g_file_active_sources <- f_new.g_file_active_sources;
1146      f.g_file_all_sources <- f_new.g_file_all_sources;
1147      f.g_file_state <- f_new.g_file_state;
1148      f.g_file_chunks <- f_new.g_file_chunks;
1149      f.g_file_availability <- f_new.g_file_availability;
1150      f.g_file_sources <- f_new.g_file_sources;
1151      f.g_file_download_rate <- f_new.g_file_download_rate;
1152      f.g_file_format <- f_new.g_file_format;
1153      f.g_file_chunks_age <- f_new.g_file_chunks_age;
1154      f.g_file_age <- f_new.g_file_age;
1155      f.g_file_last_seen <- f_new.g_file_last_seen;
1156      f.g_file_priority <- f_new.g_file_priority;
1157      f.g_file_uids <- f_new.g_file_uids
1158    
1159  let remove_dummy_source file_num =  let remove_dummy_source file_num =
1160    downloadstore#remove_item (Source (dummy_source, file_num))    downloadstore#remove_item (dummy_source_key file_num)
1161    
1162  let add_dummy_source parent file_num =  let add_dummy_source parent file_num =
1163    try    try
1164      let _ = downloadstore#find_item (Source_num ((-1), file_num)) in      let _ = downloadstore#find_row (dummy_source_key file_num) in
1165      ()      ()
1166    with _ ->    with _ ->
1167      ignore (downloadstore#add_item (Source (dummy_source, file_num)) ~parent ())      ignore (downloadstore#add_item (Source (dummy_source, file_num)) ~parent ())
1168    
1169  let h_cancelled file_num =  let h_cancelled file_num =
1170    try    try
1171      let (_, i) = downloadstore#find_item (File_num file_num) in      let fi = Hashtbl.find G.files file_num in
1172      match i with      downloadstore#remove_item (file_key file_num);
1173          File f ->      Hashtbl.remove G.files file_num;
1174            begin      decr G.ndownloads;
1175              downloadstore#remove_item (File f);      (if fi.g_file_state = FileDownloaded
1176              decr G.ndownloads;         then decr G.ndownloaded);
1177              (if f.file_state = FileDownloaded      GuiStatusBar.update_downloadedfiles ();
1178                 then decr G.ndownloaded);      let file_uid = Mi.to_uid_type fi.g_file_uids in
1179              GuiStatusBar.update_downloadedfiles ()      GuiGraphBase.cancel_file file_uid;
1180            end      Hashtbl.remove G.file_by_uid file_uid;
       | _ -> ()  
1181    with _ -> ()    with _ -> ()
1182    
1183  let h_paused f =  let h_paused f =
1184      let file_uid = Mi.to_uid_type f.g_file_uids in
1185    try    try
1186      let (row, i) = downloadstore#find_item (File_num f.file_num) in      let fi = Hashtbl.find G.files f.g_file_num in
1187      match i with      let row = downloadstore#find_row (file_key f.g_file_num) in
1188          File fi ->      (if f.g_file_state = FileDownloaded && f.g_file_state <> fi.g_file_state
1189            begin         then incr G.ndownloaded);
1190              (if f.file_state = FileDownloaded && f.file_state <> fi.file_state      let f_new = {f with g_file_sources = fi.g_file_sources} in
1191                 then incr G.ndownloaded);      downloadstore#update_item row (File fi) (File f_new);
1192              let f_new = {f with file_sources = fi.file_sources} in      hashtbl_update fi f_new;
1193              downloadstore#update_item row (File fi) (File f_new)      let rate = int_of_float f.g_file_download_rate in
1194            end      GuiGraphBase.save_record rate (GraphFile (file_uid, GraphDownloads));
1195          | _ -> ()      if f.g_file_name <> fi.g_file_name
1196          then Hashtbl.replace G.file_by_uid (file_uid) (U.utf8_of f.g_file_name);
1197    with _ ->    with _ ->
1198      begin      begin
1199        let parent = downloadstore#add_item (File f) () in        let parent = downloadstore#add_item (File f) () in
1200        incr G.ndownloads;        incr G.ndownloads;
1201        (if f.file_state = FileDownloaded        (if f.g_file_state = FileDownloaded
1202           then incr G.ndownloaded);           then incr G.ndownloaded);
1203        GuiStatusBar.update_downloadedfiles ();        GuiStatusBar.update_downloadedfiles ();
1204        add_dummy_source parent f.file_num        add_dummy_source parent f.g_file_num;
1205          Hashtbl.add G.files f.g_file_num f;
1206          GuiGraphBase.add_file file_uid;
1207          Hashtbl.add G.file_by_uid file_uid (U.utf8_of f.g_file_name);
1208          if !!O.gtk_misc_display_razorback_stats
1209            then begin
1210              try GuiHtml.get_razorback2_stats f with _ -> ()
1211            end
1212      end      end
1213    
1214  let h_downloading = h_paused  let h_downloading = h_paused
# Line 1062  let h_removed = h_cancelled Line 1219  let h_removed = h_cancelled
1219    
1220    
1221  let file_info f =  let file_info f =
1222    match f.file_state with    match f.g_file_state with
1223        FileNew -> assert false        FileNew -> assert false
1224      | FileCancelled ->      | FileCancelled ->
1225          h_cancelled f.file_num          h_cancelled f.g_file_num
1226      | FileDownloaded ->      | FileDownloaded ->
1227          h_downloaded f          h_downloaded f
1228      | FileShared ->      | FileShared ->
1229          h_removed f.file_num          h_removed f.g_file_num
1230      | FilePaused | FileQueued | FileAborted _ ->      | FilePaused | FileQueued | FileAborted _ ->
1231          h_paused f          h_paused f
1232      | FileDownloading ->      | FileDownloading ->
1233          h_downloading f          h_downloading f
1234    
1235  let file_downloaded (num, downloaded, rate, last_seen) =  let file_downloaded (file_num, downloaded, rate, last_seen) =
1236    try    try
1237      let (row, i) = downloadstore#find_item (File_num num) in      let f = Hashtbl.find G.files file_num in
1238      match i with      let row = downloadstore#find_row (file_key file_num) in
1239          File f ->      let f_new = {f with g_file_downloaded = downloaded;
1240            begin                          g_file_download_rate = rate;
1241              let f_new = {f with file_downloaded = downloaded;                          g_file_last_seen = last_seen}
1242                                  file_download_rate = rate;      in
1243                                  file_last_seen = last_seen}      downloadstore#update_item row (File f) (File f_new);
1244              in      f.g_file_downloaded <- f_new.g_file_downloaded;
1245              downloadstore#update_item row (File f) (File f_new)      f.g_file_download_rate <- f_new.g_file_download_rate;
1246            end      f.g_file_last_seen <- f_new.g_file_last_seen;
1247        | _ -> ()      let rate = int_of_float f.g_file_download_rate in
1248        GuiGraphBase.save_record rate (GraphFile ((Mi.to_uid_type f.g_file_uids), GraphDownloads));
1249    with _ -> ()    with _ -> ()
1250    
1251  (* File_add_source and File_update_availability could be merged now that we use  (* File_add_source and File_update_availability could be merged now that we use
# Line 1095  let file_downloaded (num, downloaded, ra Line 1253  let file_downloaded (num, downloaded, ra
1253   *)   *)
1254  let h_add_source s file_num =  let h_add_source s file_num =
1255    try    try
1256      let (row, i) = downloadstore#find_item (File_num file_num) in      let f = Hashtbl.find G.files file_num in
1257      match i with      let parent = downloadstore#find_row (file_key file_num) in
1258          File f ->      match f.g_file_sources with
1259            None ->
1260            begin            begin
1261              match f.file_sources with              f.g_file_sources <- Some [s.source_num];
1262                  None ->              ignore (downloadstore#add_item (Source (s, file_num)) ~parent ());
1263                    begin              remove_dummy_source file_num
1264                      f.file_sources <- Some [s.source_num];            end
1265                      ignore (downloadstore#add_item (Source (s, file_num)) ~parent:row ());        | Some sources ->
1266                      remove_dummy_source file_num            begin
1267                    end              if List.mem s.source_num sources
1268                | Some sources ->                then raise Exit
1269                    begin                else begin
1270                      if List.mem s.source_num sources                  f.g_file_sources <- Some (s.source_num :: sources);
1271                        then raise Exit                  ignore (downloadstore#add_item (Source (s, file_num)) ~parent ());
1272                        else begin                end
                         f.file_sources <- Some (s.source_num :: sources);  
                         ignore (downloadstore#add_item (Source (s, file_num)) ~parent:row ());  
                       end  
                   end  
1273            end            end
       | _ -> ()  
1274    with _ -> ()    with _ -> ()
1275    
1276  let h_remove_source s file_num =  let h_remove_source s file_num =
1277    try    try
1278      let (row, i) = downloadstore#find_item (File_num file_num) in      let f = Hashtbl.find G.files file_num in
1279      match i with      let parent = downloadstore#find_row (file_key file_num) in
1280          File f ->      let _ =
1281            begin        match f.g_file_sources with
1282              let _ =            None -> add_dummy_source parent file_num
1283                match f.file_sources with          | Some sources ->
1284                    None -> add_dummy_source row file_num              begin
1285                  | Some sources ->                f.g_file_sources <- Some (List.filter (fun num -> num <> s.source_num) sources)
1286                      begin              end
1287                        f.file_sources <- Some (List.filter (fun num -> num <> s.source_num) sources)      in
1288                      end      (match f.g_file_sources with
1289              in           Some [] ->
1290              (match f.file_sources with             begin
1291                  Some [] ->               f.g_file_sources <- None;
1292                    begin               add_dummy_source parent file_num;
1293                      f.file_sources <- None;             end
1294                      add_dummy_source row file_num;         | _ -> ());
1295                    end      downloadstore#remove_item (source_key file_num s.source_num);
               | _ -> ());  
             downloadstore#remove_item (Source (s, file_num));  
           end  
       | _ -> ()  
1296    with _ -> ()    with _ -> ()
1297    
1298  let h_update_source s_new =  let h_update_source s s_new =
1299    List.iter (fun file_num ->    List.iter (fun file_num ->
1300      try      try
1301        let (row, i) = downloadstore#find_item (Source_num (s_new.source_num, file_num)) in        let row = downloadstore#find_row (source_key file_num s_new.source_num) in
1302        match i with        downloadstore#update_item row (Source (s, file_num)) (Source (s_new, file_num))
           Source (s, num) ->  
             downloadstore#update_item row (Source (s, num)) (Source (s_new, num))  
         | _ -> ()  
1303      with _ -> ()      with _ -> ()
1304    ) s_new.source_files_requested;    ) s_new.source_files_requested;
1305    match s_new.source_state with    match s_new.source_state with
# Line 1161  let h_update_source s_new = Line 1308  let h_update_source s_new =
1308            then downloaders := s_new.source_num :: !downloaders            then downloaders := s_new.source_num :: !downloaders
1309      | _ -> ()      | _ -> ()
1310    
1311  let h_update_source_availability s_new file_num =  let h_update_source_availability s s_new file_num =
1312     try     try
1313       let (row, i) = downloadstore#find_item (Source_num (s_new.source_num, file_num)) in       let row = downloadstore#find_row (source_key file_num s_new.source_num) in
1314       match i with       downloadstore#update_item row (Source (s, file_num)) (Source (s_new, file_num))
          Source (s, num) ->  
            downloadstore#update_item row (Source (s, num)) (Source (s_new, num))  
        | _ -> ()  
1315     with _ -> ()     with _ -> ()
1316    
1317  let clean_sources_table s_old =  let clean_sources_table s_old =
# Line 1184  let clean_sources_table s_old = Line 1328  let clean_sources_table s_old =
1328  open GMain  open GMain
1329    
1330  let downloads_box gui =  let downloads_box gui =
1331      update_downloaders ();
1332      update_downloading_files ();
1333    let vbox = GPack.vbox ~homogeneous:false ~border_width:6 () in    let vbox = GPack.vbox ~homogeneous:false ~border_width:6 () in
1334    ignore (vbox#connect#destroy ~callback:    ignore (vbox#connect#destroy ~callback:
1335      (fun _ ->      (fun _ ->
# Line 1210  let downloads_box gui = Line 1356  let downloads_box gui =
1356      Downloads.treeview ~mode:`MULTIPLE      Downloads.treeview ~mode:`MULTIPLE
1357        ~packing:(vbox#pack ~expand:true ~fill:true) ()        ~packing:(vbox#pack ~expand:true ~fill:true) ()
1358    in    in
1359    let on_expand_item path (i : GuiTypes2.item_info) =    if !!O.gtk_misc_display_razorback_stats
1360        then begin
1361          let hbox_razorback_stats =
1362            GPack.hbox ~homogeneous:false ~border_width:6
1363              ~spacing:12
1364              ~packing:(vbox#pack ~expand:false ~fill:true) ()
1365          in
1366          let razorback_history =
1367            GMisc.image ~packing:(hbox_razorback_stats#pack ~expand:false ~fill:true) ()
1368          in
1369          let vbox_razorback_stats =
1370            GPack.vbox ~homogeneous:false ~border_width:6
1371              ~spacing:12
1372              ~packing:(hbox_razorback_stats#pack ~expand:false ~fill:true) ()
1373          in
1374          let label_rating =
1375            GMisc.label ~xalign:0. ~yalign:0.
1376            ~packing:(vbox_razorback_stats#pack ~expand:false ~fill:true) ()
1377          in
1378          let label_availability =
1379            GMisc.label ~xalign:0. ~yalign:0.
1380            ~packing:(vbox_razorback_stats#pack ~expand:false ~fill:true) ()
1381          in
1382          let label_completed =
1383            GMisc.label ~xalign:0. ~yalign:0.
1384            ~packing:(vbox_razorback_stats#pack ~expand:false ~fill:true) ()
1385          in
1386          let on_select_files keys =
1387            match keys with
1388                [] -> ()
1389              | k :: _ when (is_file k) ->
1390                  begin
1391                    try
1392                      let file = file_of_key k in
1393                      match file.g_file_razorback_stats with
1394                          None -> ()
1395                        | Some stats ->
1396                            begin
1397                              try
1398                                let filename = stats.razorback_file_history in
1399                                Printf2.lprintf_nl2 "image: %s" filename;
1400                                let pixb = GdkPixbuf.from_file filename in
1401                                razorback_history#set_pixbuf pixb;
1402                                label_rating#set_label (Printf.sprintf "Rating: %s" stats.razorback_file_rating);
1403                                label_availability#set_label (Printf.sprintf "Available: %d" stats.razorback_file_avalaibility);
1404                                label_completed#set_label (Printf.sprintf "Completed: %d" stats.razorback_file_completed);
1405                              with _ -> GuiHtml.get_razorback2_stats file
1406                            end
1407                    with _ -> ()
1408                  end
1409              | _ -> ()
1410          in
1411          downloadview#set_on_select on_select_files
1412        end;
1413      let on_expand_item path k =
1414      ask_for_sources ();      ask_for_sources ();
1415      false      false
1416    in    in
1417    let on_expanded_item path (i : GuiTypes2.item_info) =    let on_expanded_item path k =
1418      expanded_rows := List.length downloadview#expanded_paths;      expanded_rows := List.length downloadview#expanded_paths;
1419      ( if !!verbose then lprintf' "rows expanded %d\n" !expanded_rows)      (if !!verbose then lprintf' "rows expanded %d\n" !expanded_rows)
1420    in    in
1421    let on_collapsed_item path (i : GuiTypes2.item_info) =    let on_collapsed_item path k =
1422      expanded_rows := List.length downloadview#expanded_paths;      expanded_rows := List.length downloadview#expanded_paths;
1423      ( if !!verbose then lprintf' "rows expanded %d\n" !expanded_rows)      (if !!verbose then lprintf' "rows expanded %d\n" !expanded_rows)
1424    in    in
1425    view_context := Some downloadview#view#misc#pango_context;    view_context := Some downloadview#view#misc#pango_context;
1426    downloadview#set_model downloadstore#gmodel;    downloadview#set_model downloadstore#gmodel;
# Line 1233  let downloads_box gui = Line 1433  let downloads_box gui =
1433      (fun _ ->      (fun _ ->
1434        ( if !!verbose then lprintf' "Update downloaders\n");        ( if !!verbose then lprintf' "Update downloaders\n");
1435        update_downloaders ();        update_downloaders ();
1436          update_downloading_files ();
1437        true);        true);
1438    ignore (entry#event#connect#key_press ~callback:    ignore (entry#event#connect#key_press ~callback:
1439      (fun ev ->      (fun ev ->
# Line 1247  let _ = Line 1448  let _ =
1448    ignore (Timeout.add ~ms:1800000 ~callback:    ignore (Timeout.add ~ms:1800000 ~callback:
1449      (fun _ ->      (fun _ ->
1450        clean_avail_bars ();        clean_avail_bars ();
1451          if !!O.gtk_misc_display_razorback_stats
1452            then all_files_razorback2_stats ();
1453        true        true
1454    ));    ));
1455    ignore (Timeout.add ~ms:30000 ~callback:    ignore (Timeout.add ~ms:30000 ~callback:

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26