Use signals to loosely couple modules.
[guestfs-browser.git] / main.ml
diff --git a/main.ml b/main.ml
index 82e4603..c908bbc 100644 (file)
--- a/main.ml
+++ b/main.ml
@@ -33,15 +33,53 @@ let () =
     debug "libvirt %s" (libvirt_version_string ());
   );
 
-  let ws = Window.open_main_window () in
-  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_status_hook (Window.set_statusbar ws);
-  Slave.set_progress_hook (Window.progress ws);
+  (* Create the main window. *)
+  let w = new Window.window in
+
+  (* Wire up hooks that carry messages from the slave thread
+   * to the main thread.
+   *)
+  Slave.set_failure_hook w#failure;
+  Slave.set_busy_hook w#throbber_busy;
+  Slave.set_idle_hook w#throbber_idle;
+  Slave.set_status_hook w#set_statusbar;
+  Slave.set_progress_hook w#progress;
+
+  (* Wire up the loosely-coupled external components of the filetree.
+   * See the note about signals in {!Filetree.tree} documentation.
+   *)
+  let tree = w#tree in
+  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));
+
+  (* Connect menu entry signals to the functions that implement them. *)
+  ignore (w#connect_kvm_signal
+            ~callback:(w#connect_to (Some "qemu:///system")));
+  ignore (w#connect_xen_signal
+            ~callback:(w#connect_to (Some "xen:///")));
+  ignore (w#connect_none_signal
+            ~callback:(w#connect_to None));
 
   (* What did the user request on the command line? *)
-  Window.run_cli_request ws cli_request;
+  w#run_cli_request cli_request;
 
   (* Run the main display thread.  When this returns, the application
    * has been closed.