From 63477ec4c94146bae30af05022b5a064667949a8 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 13 Dec 2010 23:08:19 +0000 Subject: [PATCH] Add progress bar. --- filetree.ml | 3 ++- main.ml | 1 + slave.ml | 10 ++++++++++ slave.mli | 9 ++++++++- window.ml | 6 +++++- window.mli | 3 +++ 6 files changed, 29 insertions(+), 3 deletions(-) diff --git a/filetree.ml b/filetree.ml index 0368d53..af871a7 100644 --- a/filetree.ml +++ b/filetree.ml @@ -239,7 +239,8 @@ and add_top_level_os ({ model = model; hash = hash } as t) name os = and add_top_level_vol ({ model = model; hash = hash } as t) name dev = let markup = - sprintf "%s: %s" (markup_escape name) (markup_escape dev) in + sprintf "%s\nfrom %s" + (markup_escape dev) (markup_escape name) in let row = model#append () in make_node t row (Top (Slave.Volume dev)); diff --git a/main.ml b/main.ml index 1fb7ce0..25215ac 100644 --- a/main.ml +++ b/main.ml @@ -38,6 +38,7 @@ let () = Slave.set_failure_hook (Window.failure ws); Slave.set_busy_hook (Window.throbber_busy ws); Slave.set_idle_hook (Window.throbber_idle ws); + Slave.set_progress_hook (Window.progress ws); (* What did the user request on the command line? *) (*Window.run_cli_request ws cli_request;*) diff --git a/slave.ml b/slave.ml index a43cd69..1c56538 100644 --- a/slave.ml +++ b/slave.ml @@ -96,10 +96,12 @@ let no_callback _ = () let failure_hook = ref (fun _ -> ()) let busy_hook = ref (fun _ -> ()) let idle_hook = ref (fun _ -> ()) +let progress_hook = ref (fun _ -> ()) let set_failure_hook cb = failure_hook := cb let set_busy_hook cb = busy_hook := cb let set_idle_hook cb = idle_hook := cb +let set_progress_hook cb = progress_hook := cb (* Execute a function, while holding a mutex. If the function * fails, ensure we release the mutex before rethrowing the @@ -366,6 +368,14 @@ and open_disk_images images cb = *) (* g#set_verbose (verbose ());*) + (* Attach progress bar callback. *) + g#set_progress_callback ( + fun proc_nr serial position total -> + debug "progress callback proc_nr=%d serial=%d posn=%Ld total=%Ld" + proc_nr serial position total; + GtkThread.async !progress_hook (position, total) + ); + List.iter ( function | filename, None -> diff --git a/slave.mli b/slave.mli index d6f9cf7..940de14 100644 --- a/slave.mli +++ b/slave.mli @@ -180,7 +180,9 @@ val exit_thread : unit -> unit and display those in the main thread. {!set_busy_hook} and {!set_idle_hook} are used to implement a - "throbber". *) + "throbber". + + {!set_progress_hook} is used to implement a progress bar. *) val set_failure_hook : exn callback -> unit (** Set the function in the main thread which is called if there is @@ -195,3 +197,8 @@ val set_idle_hook : unit callback -> unit (** Set the function in the main thread which is called whenever the slave thread stops working on a command {i and} has no more commands left in the queue to work on. *) + +val set_progress_hook : (int64 * int64) callback -> unit + (** Set the function in the main thread which is called whenever + the slave thread receives a progress notification message + from libguestfs. *) diff --git a/window.ml b/window.ml index b15c690..c4e17b0 100644 --- a/window.ml +++ b/window.ml @@ -124,6 +124,10 @@ let throbber_busy ws () = let throbber_idle ws () = ws.throbber#set_pixbuf ws.throbber_static +let progress ws (position, total) = + ws.progress_bar#set_fraction + (Int64.to_float position /. Int64.to_float total) + (* This is called in the main thread whenever a command fails in the * slave thread. The command queue has been cleared before this is * called, so our job here is to reset the main window, and if @@ -158,7 +162,7 @@ let rec open_main_window () = let view = make_filetree ~packing:(vbox#pack ~expand:true ~fill:true) () in (* Status bar and progress bar. *) - let hbox = GPack.hbox ~packing:vbox#pack () in + let hbox = GPack.hbox ~spacing:4 ~packing:vbox#pack () in let progress_bar = GRange.progress_bar ~packing:hbox#pack () in let statusbar = GMisc.statusbar ~packing:(hbox#pack ~expand:true) () in let statusbar_context = statusbar#new_context ~name:"Standard" in diff --git a/window.mli b/window.mli index 97aab79..b91ccd9 100644 --- a/window.mli +++ b/window.mli @@ -35,6 +35,9 @@ val throbber_idle : window_state -> unit -> unit thread) which are called whenever the throbber should be animated/busy or idle. *) +val progress : window_state -> int64 * int64 -> unit + (** This called whenever the progress bar should move. *) + (* val run_cli_request : window_state -> Cmdline.cli_request -> unit (** This function performs the {!Cmdline.cli_request} operation. -- 1.8.3.1