+
+ (* Refresh button.
+ * http://stackoverflow.com/questions/2188659/stock-icons-not-shown-on-buttons
+ *)
+ let refresh_button =
+ let image = GMisc.image ~stock:`REFRESH () in
+ let b = GButton.button ~packing:hbox#pack () in
+ b#set_image (image :> GObj.widget);
+ b in
+
+ (* Throbber. *)
+ let static = Throbber.static () in
+ (*let animation = Throbber.animation () in*)
+ let throbber =
+ (* Workaround for http://caml.inria.fr/mantis/view.php?id=4732 *)
+ let from = Obj.magic 3448763 (* `END *) in
+ GMisc.image ~pixbuf:static ~packing:(hbox#pack ~from) () in
+
+ vmcombo, refresh_button, throbber, static
+
+and make_filetree ~packing () =
+ (* Create the filetree inside a scrolled window. *)
+ let sw =
+ GBin.scrolled_window ~packing ~hpolicy:`AUTOMATIC ~vpolicy:`ALWAYS () in
+ let tree = new Filetree.tree ~packing:sw#add () in
+
+ (* Wire up the loosely-coupled external components of the filetree.
+ * See the note about signals in {!Filetree.tree} documentation.
+ *)
+ ignore (tree#op_checksum_file
+ ~callback:(Op_checksum_file.checksum_file tree));
+ ignore (tree#op_copy_regvalue
+ ~callback:(Op_copy_regvalue.copy_regvalue tree));
+ ignore (tree#op_disk_usage
+ ~callback:(Op_disk_usage.disk_usage tree));
+ ignore (tree#op_download_as_reg
+ ~callback:(Op_download_as_reg.download_as_reg tree));
+ ignore (tree#op_download_dir_find0
+ ~callback:(Op_download_dir_find0.download_dir_find0 tree));
+ ignore (tree#op_download_dir_tarball
+ ~callback:(Op_download_dir_tarball.download_dir_tarball tree));
+ ignore (tree#op_download_file
+ ~callback:(Op_download_file.download_file tree));
+ ignore (tree#op_file_information
+ ~callback:(Op_file_information.file_information tree));
+ ignore (tree#op_inspection_dialog
+ ~callback:(Op_inspection_dialog.inspection_dialog tree));
+ ignore (tree#op_view_file
+ ~callback:(Op_view_file.view_file tree));
+
+ tree
+
+class window =
+ (* I prototyped the basic window layout using Glade, but have
+ * implemented it by hand to give us more flexibility.
+ *)
+ let title = "Guest Filesystem Browser" in
+ let window = GWindow.window ~width:700 ~height:700 ~title () in
+ let vbox = GPack.vbox ~packing:window#add () in
+
+ (* Menus. *)
+ let connect_kvm_item, connect_xen_item, connect_none_item, _, _ =
+ make_menubar window vbox ~packing:vbox#pack () in
+
+ (* Top toolbar. *)
+ let vmcombo, refresh_button, throbber, throbber_static =
+ make_toolbar ~packing:vbox#pack () in
+
+ (* Main part of display is the file tree. *)
+ let view = make_filetree ~packing:(vbox#pack ~expand:true ~fill:true) () in
+
+ (* Status bar and progress bar. *)
+ 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
+
+object (self)
+ initializer
+ ignore (statusbar_context#push title);
+ window#show ();
+
+ (* Connect up the callback for menu entries etc. These require the
+ * window_state struct in callbacks.
+ *)
+
+ (* Connect to different hypervisors. *)
+ ignore (connect_kvm_item#connect#activate
+ ~callback:(fun () -> self#connect_to (Some "qemu:///system")));
+ ignore (connect_xen_item#connect#activate
+ ~callback:(fun () -> self#connect_to (Some "xen:///")));
+ ignore (connect_none_item#connect#activate
+ ~callback:(fun () -> self#connect_to None));
+
+ (* VM combo box when changed by the user.
+ * The refresh button acts like changing the VM combo too.
+ *)
+ let combo, (model, column) = vmcombo in
+ ignore (
+ combo#connect#changed
+ ~callback:(
+ fun () ->
+ match combo#active_iter with
+ | None -> () (* nothing selected *)
+ | Some row -> self#open_domain (model#get ~row ~column)
+ )
+ );
+ ignore (
+ refresh_button#connect#clicked
+ ~callback:(
+ fun () ->
+ match combo#active_iter with
+ | None -> () (* nothing selected *)
+ | Some row -> self#open_domain (model#get ~row ~column)
+ )
+ )
+
+ (* Set the statusbar text. *)
+ method set_statusbar msg =
+ statusbar_context#pop ();
+ ignore (statusbar_context#push msg)
+
+ (* Clear the filetree. *)
+ method private clear_view () =
+ view#clear ()
+
+ (* Callback from Connect -> ... menu items. *)
+ method private connect_to uri =
+ self#clear_view ();
+ Slave.discard_command_queue ();
+ Slave.connect uri (self#when_connected uri)
+
+ (* Called back when connected to a new hypervisor. *)
+ method private when_connected uri doms =
+ self#populate_vmcombo doms
+
+ (* Populate the VM combo box. *)
+ method private populate_vmcombo doms =