diff -ur src/gtk2/gui/guiDownloads.ml src/gtk2/gui/guiDownloads.ml --- src/gtk2/gui/guiDownloads.ml 2005-11-13 10:41:02.000000000 +0100 +++ src/gtk2/gui/guiDownloads.ml 2005-11-13 12:25:01.136841336 +0100 @@ -983,6 +983,13 @@ GuiCom.send (GetFile_info f.g_file_num) ) files + +let razorback2_stats k () = + try + let file = file_of_key k in + GuiHtml.get_razorback2_stats file + with _ -> () + (*************************************************************************) (* *) (* Download Menu *) @@ -998,6 +1005,7 @@ [ `I ((!M.dT_me_show_file_details), show_details k) ; `I ((!M.dT_me_preview), preview k) ; + `I ((!M.dT_me_razorback2_stats), razorback2_stats k); `S ; ] else []) @@ -1142,15 +1150,6 @@ (* *) (*************************************************************************) -let all_files_razorback2_stats () = - let l = List.filter (fun k -> is_file k) (downloadstore#all_items ()) in - List.iter (fun k -> - try - let file = file_of_key k in - GuiHtml.get_razorback2_stats file - with _ -> () - ) l - let hashtbl_update f f_new = f.g_file_comment <- f_new.g_file_comment; f.g_file_name <- f_new.g_file_name; @@ -1221,10 +1220,6 @@ Hashtbl.add G.files f.g_file_num f; GuiGraphBase.add_file file_uid; Hashtbl.add G.file_by_uid file_uid (U.utf8_of f.g_file_name); - if !!O.gtk_misc_display_razorback_stats - then begin - try GuiHtml.get_razorback2_stats f with _ -> () - end; add_dummy_source f.g_file_num; end @@ -1372,60 +1367,61 @@ Downloads.treeview ~mode:`MULTIPLE ~packing:(vbox#pack ~expand:true ~fill:true) () in - if !!O.gtk_misc_display_razorback_stats - then begin - let hbox_razorback_stats = - GPack.hbox ~homogeneous:false ~border_width:6 - ~spacing:12 - ~packing:(vbox#pack ~expand:false ~fill:true) () - in - let razorback_history = - GMisc.image ~packing:(hbox_razorback_stats#pack ~expand:false ~fill:true) () - in - let vbox_razorback_stats = - GPack.vbox ~homogeneous:false ~border_width:6 - ~spacing:12 - ~packing:(hbox_razorback_stats#pack ~expand:false ~fill:true) () - in - let label_rating = - GMisc.label ~xalign:0. ~yalign:0. - ~packing:(vbox_razorback_stats#pack ~expand:false ~fill:true) () - in - let label_availability = - GMisc.label ~xalign:0. ~yalign:0. - ~packing:(vbox_razorback_stats#pack ~expand:false ~fill:true) () - in - let label_completed = - GMisc.label ~xalign:0. ~yalign:0. - ~packing:(vbox_razorback_stats#pack ~expand:false ~fill:true) () - in - let on_select_files keys = - match keys with - [] -> () - | k :: _ when (is_file k) -> - begin - try - let file = file_of_key k in - match file.g_file_razorback_stats with - None -> () - | Some stats -> - begin - try - let filename = stats.razorback_file_history in - Printf2.lprintf_nl2 "image: %s" filename; - let pixb = GdkPixbuf.from_file filename in - razorback_history#set_pixbuf pixb; - label_rating#set_label (Printf.sprintf "Rating: %s" stats.razorback_file_rating); - label_availability#set_label (Printf.sprintf "Available: %d" stats.razorback_file_avalaibility); - label_completed#set_label (Printf.sprintf "Completed: %d" stats.razorback_file_completed); - with _ -> GuiHtml.get_razorback2_stats file - end - with _ -> () - end - | _ -> () - in - downloadview#set_on_select on_select_files - end; + let hbox_razorback_stats = + GPack.hbox ~homogeneous:false ~border_width:6 + ~spacing:12 + ~packing:(vbox#pack ~expand:false ~fill:true) () + in + let razorback_history = + GMisc.image ~packing:(hbox_razorback_stats#pack ~expand:false ~fill:true) () + in + let vbox_razorback_stats = + GPack.vbox ~homogeneous:false ~border_width:6 + ~spacing:12 + ~packing:(hbox_razorback_stats#pack ~expand:false ~fill:true) () + in + let label_rating = + GMisc.label ~xalign:0. ~yalign:0. + ~packing:(vbox_razorback_stats#pack ~expand:false ~fill:true) () + in + let label_availability = + GMisc.label ~xalign:0. ~yalign:0. + ~packing:(vbox_razorback_stats#pack ~expand:false ~fill:true) () + in + let label_completed = + GMisc.label ~xalign:0. ~yalign:0. + ~packing:(vbox_razorback_stats#pack ~expand:false ~fill:true) () + in + let on_select_files keys = + match keys with + k :: _ when (is_file k) -> + begin + try + let file = file_of_key k in + match file.g_file_razorback_stats with + None -> + begin + let pixb = A.get_icon ~icon:M.icon_mime_unknown ~size:A.LARGE () in + razorback_history#set_pixbuf pixb; + label_rating#set_label "Razorback Stats not available" + end + | Some stats -> + begin + try + let filename = stats.razorback_file_history in + Printf2.lprintf_nl2 "image: %s" filename; + let pixb = GdkPixbuf.from_file filename in + razorback_history#set_pixbuf pixb; + label_rating#set_label (Printf.sprintf "Rating: %s" stats.razorback_file_rating); + label_availability#set_label (Printf.sprintf "Available: %d" stats.razorback_file_avalaibility); + label_completed#set_label (Printf.sprintf "Completed: %d" stats.razorback_file_completed); + GuiHtml.get_razorback2_stats file + with _ -> () + end + with _ -> () + end + | _ -> () + in let on_expand_item path k = ask_for_sources (); false @@ -1444,6 +1440,7 @@ downloadview#set_on_expand on_expand_item; downloadview#set_on_expanded on_expanded_item; downloadview#set_on_collapsed on_collapsed_item; + downloadview#set_on_select on_select_files; update_downloaders (); downloaders_timerID := Timeout.add ~ms:6000 ~callback: (fun _ -> @@ -1467,8 +1464,6 @@ ignore (Timeout.add ~ms:1800000 ~callback: (fun _ -> clean_avail_bars (); - if !!O.gtk_misc_display_razorback_stats - then all_files_razorback2_stats (); true )); ignore (Timeout.add ~ms:30000 ~callback: diff -ur src/gtk2/gui/guiHtml.ml src/gtk2/gui/guiHtml.ml --- src/gtk2/gui/guiHtml.ml 2005-10-31 19:34:02.000000000 +0100 +++ src/gtk2/gui/guiHtml.ml 2005-11-13 12:29:20.300442480 +0100 @@ -130,7 +130,8 @@ try (try Sys.remove filename with _ -> lprintf_nl2 "cannot remove file %s" filename); File.from_string filename ___s; - stats.razorback_file_history <- filename + stats.razorback_file_history <- filename; + stats.razorback_file_last_time <- BasicSocket.current_time (); with _ -> (lprintf_nl2 "failed in H.wget_string")) (fun n m -> lprintf_nl2 "progress: %d / %d" n m) end ) sl; @@ -191,20 +192,35 @@ in iter dl -let get_razorback2_stats file = +let get_razorback2_stats file = () +(* try let md4 = uids_to_md4 file.g_file_uids in - let stats = { - razorback_file_history = ""; - razorback_file_rating = ""; - razorback_file_avalaibility = 0; - razorback_file_completed = 0; - } in - file.g_file_razorback_stats <- Some stats; - let referer = "http://stats.razorback2.com/" in - let url = Printf.sprintf "%sed2khistory?ed2k=%s" referer md4 in - get url (parse_razorback_stats stats md4 referer) + let stats = + match file.g_file_razorback_stats with + None -> + begin + let s ={ + razorback_file_history = ""; + razorback_file_rating = ""; + razorback_file_avalaibility = 0; + razorback_file_completed = 0; + razorback_file_last_time = 0.; + } in + file.g_file_razorback_stats <- Some s; + s + end + | Some s -> s + in + let last_time = BasicSocket.current_time () -. stats.razorback_file_last_time in + if last_time > 3600000. (* 60 min *) + then begin + let referer = "http://stats.razorback2.com/" in + let url = Printf.sprintf "%sed2khistory?ed2k=%s" referer md4 in + get url (parse_razorback_stats stats md4 referer) + end with _ -> () +*) (* Element: ! diff -ur src/gtk2/gui/guiMessages.ml src/gtk2/gui/guiMessages.ml --- src/gtk2/gui/guiMessages.ml 2005-11-13 10:41:02.000000000 +0100 +++ src/gtk2/gui/guiMessages.ml 2005-11-13 12:13:53.510335992 +0100 @@ -235,6 +235,7 @@ let dT_me_save = ref "" let dT_me_browse_files = ref "" let dT_me_add_to_friends = ref "" +let dT_me_razorback2_stats = ref "" let dT_lb_link = ref "" let dT_me_show_file_details = ref "" let dT_me_show_source_details = ref "" @@ -701,6 +702,7 @@ dT_me_show_file_details := _s "Show file details"; dT_me_show_source_details := _s "Show source details"; dT_wt_show_source_details := _s "Source details"; + dT_me_razorback2_stats := _s "Get Razorback Stats"; (* Friends Tab *) diff -ur src/gtk2/gui/guiOptions.ml src/gtk2/gui/guiOptions.ml --- src/gtk2/gui/guiOptions.ml 2005-11-01 11:46:55.000000000 +0100 +++ src/gtk2/gui/guiOptions.ml 2005-11-13 11:33:30.000000000 +0100 @@ -352,12 +352,6 @@ (* {Misc} *) -let gtk_misc_display_razorback_stats = define_option current_section - ["gtk_misc_display_razorback_stats"] - ~desc:"Display razorback statistics" - "Check to display file information from http://stats.razorback2.com in the downloads page" - bool_option true - let gtk_misc_relative_availability = define_option current_section ["gtk_misc_relative_availability"] ~desc:"Use relative % availability" diff -ur src/gtk2/gui/guiTypes2.ml src/gtk2/gui/guiTypes2.ml --- src/gtk2/gui/guiTypes2.ml 2005-11-13 10:41:02.000000000 +0100 +++ src/gtk2/gui/guiTypes2.ml 2005-11-13 11:35:58.000000000 +0100 @@ -218,6 +218,7 @@ mutable razorback_file_rating : string; mutable razorback_file_avalaibility : int; mutable razorback_file_completed : int; + mutable razorback_file_last_time : float; } type g_file_info = {