(* Guestfs Browser. * Copyright (C) 2010 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 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 (* 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 ()); (* 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 window#show (); window#add_accel_group accel_group; (* display_state which is threaded through all the other callbacks, * allowing callbacks to update the window. *) { 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; (* Run the main display thread. When this returns, the application * has been closed. *) GtkThread.main (); Slave.exit_thread ()