* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)
+open Printf
+
+open Utils
+
type file_menu = {
quit_item : GMenu.menu_item;
}
class window =
let title = "Resize a virtual machine - virt-resize-ui" in
object (self)
+ val mutable tabs = None
+ val mutable statusbar_context = None
+ val mutable progress_bar : GRange.progress_bar option = None
+
+ method source_tab = (Option.get tabs).source_tab
+
+ method set_statusbar msg =
+ Option.may (
+ fun c ->
+ c#pop ();
+ ignore (c#push msg)
+ ) statusbar_context
+
+ method progress (position, total) =
+ Option.may (
+ fun pb ->
+ if position = 0L && total = 1L then
+ pb#pulse ()
+ else (
+ let frac = Int64.to_float position /. Int64.to_float total in
+ if frac < 0. || frac > 1. then
+ eprintf "warning: progress bar out of range: %Ld / %Ld (%g)\n"
+ position total frac;
+ let frac = if frac < 0. then 0. else if frac > 1. then 1. else frac in
+ pb#set_fraction frac
+ )
+ ) progress_bar
+
initializer
(* Window. *)
let window = GWindow.window ~width:700 ~height:700 ~title () in
let about = factory#add_item "About virt-resize-ui ..." in
{ about_item = about } in
+ ignore help_menu;
+
(* Tabbed notebook for main part of the display. *)
- let tabs =
+ tabs <- (
let nb = GPack.notebook ~packing:(vbox#pack ~expand:true ~fill:true) () in
let src = Source_tab.tab () in
(GMisc.label ~text:"Expand logical volumes" () :> GObj.widget) in
ignore (nb#append_page ~tab_label (lvs :> GObj.widget));
- { source_tab = src; destination_tab = dest;
- partitions_tab = parts; logvols_tab = lvs } in
+ Some { source_tab = src; destination_tab = dest;
+ partitions_tab = parts; logvols_tab = lvs });
+
+ (* Status bar and progress bar. *)
+ let hbox = GPack.hbox ~spacing:4 ~packing:vbox#pack () in
+ progress_bar <- Some (GRange.progress_bar ~packing:hbox#pack ());
+ let statusbar = GMisc.statusbar ~packing:(hbox#pack ~expand:true) () in
+ statusbar_context <- Some (statusbar#new_context ~name:"Standard");
+ ignore ((Option.get statusbar_context)#push title);
(* Buttons. *)
let buttons =
{ prev_button = prev; next_button = next; go_button = go;
exit_button = ex } in
- ignore help_menu;
- ignore tabs;
-
(* Quit button. *)
let quit _ = GMain.quit (); false in
ignore (window#connect#destroy ~callback:GMain.quit);