Version 0.0.1
[guestfs-browser.git] / main.ml
diff --git a/main.ml b/main.ml
index a823aa5..9a72113 100644 (file)
--- a/main.ml
+++ b/main.ml
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *)
 
-open Utils
-
-(* Display state. *)
-type display_state = {
-  window : GWindow.window;
-  throbber_busy : unit -> unit;
-  throbber_idle : unit -> unit;
-}
-
-let open_main_window () =
-  let title = "Guest Filesystem Browser" in
-  let window = GWindow.window ~width:800 ~height:600 ~title () in
-  let vbox = GPack.vbox ~packing:window#add () in
-
-  (* Do the menus. *)
-  let menubar = GMenu.menu_bar ~packing:vbox#pack () in
-  let factory = new GMenu.factory menubar in
-  let accel_group = factory#accel_group in
-  let connect_menu = factory#add_submenu "_Connect" in
-
-  let factory = new GMenu.factory connect_menu ~accel_group in
-  let quit_item = factory#add_item "E_xit" ~key:GdkKeysyms._Q in
+open Printf
 
-  (* Quit. *)
-  let quit _ = GMain.quit (); false in
-  ignore (window#connect#destroy ~callback:GMain.quit);
-  ignore (window#event#connect#delete ~callback:quit);
-  ignore (quit_item#connect#activate
-            ~callback:(fun () -> ignore (quit ()); ()));
-
-  (* Top status area. *)
-  let hbox = GPack.hbox ~border_width:4 ~packing:vbox#pack () in
-  ignore (GMisc.label ~text:"Guest: " ~packing:hbox#pack ());
+open Utils
 
-  (* Throbber, http://faq.pygtk.org/index.py?req=show&file=faq23.037.htp *)
-  let static = Throbber.static () in
-  (*let animation = Throbber.animation () in*)
-  let throbber =
-    GMisc.image ~pixbuf:static ~packing:(hbox#pack ~from:`END) () in
-  let throbber_busy () =
-    (*throbber#set_pixbuf animation*)
-    (* Workaround because no binding for GdkPixbufAnimation: *)
-    let file = Filename.dirname Sys.argv.(0) // "Throbber.gif" in
-    throbber#set_file file
-  and throbber_idle () =
-    throbber#set_pixbuf static
-  in
+module G = Guestfs
 
-  window#show ();
-  window#add_accel_group accel_group;
+(* Main. *)
+let () =
+  let cli_request = Cmdline.command_line () in
 
-  (* display_state which is threaded through all the other callbacks,
-   * allowing callbacks to update the window.
+  (* If we're in verbose mode, print some debug information which
+   * could be useful in bug reports.
    *)
-  { window = window;
-    throbber_busy = throbber_busy; throbber_idle = throbber_idle }
-
-let () =
-  let ds = open_main_window () in
-  Slave.set_failure_hook (failure ds);
-  Slave.set_busy_hook ds.throbber_busy;
-  Slave.set_idle_hook ds.throbber_idle;
+  if verbose () then (
+    debug "%s %s" Config.package Config.version;
+    let v = fst (Libvirt.get_version ()) in
+    debug "libvirt %d.%d.%d"
+      (v / 1_000_000) ((v / 1_000) mod 1_000) (v mod 1_000);
+    let g = G.create () in
+    let v = G.version g in
+    debug "libguestfs %Ld.%Ld.%Ld%s"
+      v.G.major v.G.minor v.G.release v.G.extra;
+    G.close g;
+  );
+
+  let ds = Window.open_main_window () in
+  Slave.set_failure_hook (Window.failure ds);
+  Slave.set_busy_hook ds.Window.throbber_busy;
+  Slave.set_idle_hook ds.Window.throbber_idle;
+
+  (* What did the user request on the command line? *)
+  Window.run_cli_request ds cli_request;
 
   (* Run the main display thread.  When this returns, the application
    * has been closed.