+ (* Populate the VM combo box. *)
+ method private populate_vmcombo doms =
+ let combo, (model, column) = vmcombo in
+ model#clear ();
+ List.iter (
+ fun { dom_name = name } ->
+ let row = model#append () in
+ model#set ~row ~column name
+ ) doms
+
+ (* When a new domain is selected by the user, eg through vmcombo. *)
+ method private open_domain name =
+ tree#clear ();
+ Slave.discard_command_queue ();
+ Slave.open_domain name (self#when_opened_domain name)
+
+ (* Called back when domain was opened successfully. *)
+ method private when_opened_domain name data =
+ debug "when_opened_domain callback";
+ self#when_opened_common name data
+
+ (* When a set of disk images is selected by the user. *)
+ method open_disk_images images =
+ match images with
+ | [] -> ()
+ | images ->
+ tree#clear ();
+ Slave.discard_command_queue ();
+ Slave.open_images images (self#when_opened_disk_images images)
+
+ (* Called back when disk image(s) were opened successfully. *)
+ method private when_opened_disk_images images data =
+ match images with
+ | [] -> ()
+ | (image, _) :: _ ->
+ debug "when_opened_disk_images callback";
+ self#when_opened_common image data
+
+ (* Called to reopen the handle. *)
+ method reopen () =
+ tree#clear ();
+ Slave.discard_command_queue ();
+ Slave.reopen self#when_reopened
+
+ method private when_reopened data =
+ debug "when_reopened callback";
+ self#when_opened_common "Reopened"(*XXX we lost the original name*) data
+
+ (* Common code for when_opened_domain/when_opened_disk_images. *)
+ method private when_opened_common name data =
+ (* Dump some of the inspection data in debug messages. *)
+ List.iter (fun (dev, t) -> debug "filesystem: %s: %s" dev t)
+ data.insp_all_filesystems;
+ List.iter (
+ fun { insp_root = root; insp_type = typ; insp_distro = distro;
+ insp_major_version = major; insp_minor_version = minor } ->
+ debug "root device %s contains %s %s %d.%d" root typ distro major minor;
+ ) data.insp_oses;
+
+ tree#add_os name data
+
+ (* Public callbacks. *)
+ method throbber_busy () =
+ throbber#set_pixbuf throbber_animation
+
+ method throbber_idle () =
+ throbber#set_pixbuf throbber_static
+
+ method progress (position, total) =
+ if position = 0L && total = 1L then
+ progress_bar#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
+ progress_bar#set_fraction frac
+ )
+
+ (* 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
+ * necessary to turn the exception into an error message.
+ *)
+ method failure exn =
+ let raw_msg = Printexc.to_string exn in
+ debug "failure hook: %s" raw_msg;
+
+ let title, msg = pretty_string_of_exn exn in
+ let icon = GMisc.image () in
+ icon#set_stock `DIALOG_ERROR;
+ icon#set_icon_size `DIALOG;
+ GToolbox.message_box ~title ~icon msg
+
+ (* Do what the user asked on the command line. *)
+ method run_cli_request = function
+ | Cmdline.Empty_window -> ()
+ | Cmdline.Open_images images ->
+ self#open_disk_images images
+ | Cmdline.Open_guest guest ->
+ (* Open libvirt connection, and in the callback open the guest. *)
+ let uri = connect_uri () in
+ Slave.connect uri (self#when_connected_cli_request guest)
+
+ method private when_connected_cli_request guest doms =
+ self#populate_vmcombo doms;
+
+ (* "guest" should match a domain in "doms". Check this and
+ * get the index of it.
+ *)
+ let rec loop i = function
+ | [] ->
+ failwith "guest %s not found (do you need to use --connect?)" guest
+ | d::ds when d = guest -> i
+ | _::ds -> loop (i+1) ds
+ in
+ let i = loop 0 (List.map (fun { dom_name = name } -> name) doms) in
+
+ let combo, _ = vmcombo in
+ combo#set_active i
+
+end