1 (* virt-manager-like graphical management tool.
2 (C) Copyright 2007 Richard W.M. Jones, Red Hat Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 let title = "Virtual Control"
24 let utf8_copyright = "\194\169"
28 let gtk_major, gtk_minor, gtk_micro = GMain.Main.version in
29 sprintf "%d.%d.%d" gtk_major gtk_minor gtk_micro in
30 let virt_version = string_of_int (fst (Libvirt.get_version ())) in
31 let title = "About " ^ title in
32 let icon = GMisc.image () in
33 icon#set_stock `DIALOG_INFO;
34 icon#set_icon_size `DIALOG;
38 ("Virtual control (virt-ctrl) by\n" ^
39 "Richard W.M. Jones (rjones@redhat.com).\n\n" ^
40 "Copyright " ^ utf8_copyright ^ " 2007 Red Hat Inc.\n\n" ^
41 "Libvirt version: " ^ virt_version ^ "\n" ^
42 "Gtk toolkit version: " ^ gtk_version)
44 (* Catch any exception and throw up a dialog. *)
46 (* A nicer exception printing function. *)
47 let string_of_exn = function
48 | Libvirt.Virterror err ->
49 "Virtualisation error: " ^ (Libvirt.Virterror.to_string err)
51 | exn -> Printexc.to_string exn
53 GtkSignal.user_handler :=
55 let label = string_of_exn exn in
56 let title = "Error" in
57 let icon = GMisc.image () in
58 icon#set_stock `DIALOG_ERROR;
59 icon#set_icon_size `DIALOG;
60 GToolbox.message_box ~title ~icon label
62 let make ~open_connection
63 ~start_domain ~pause_domain ~resume_domain ~shutdown_domain =
64 (* Create the main window. *)
65 let window = GWindow.window ~width:800 ~height:600 ~title () in
66 let vbox = GPack.vbox ~packing:window#add () in
69 let menubar = GMenu.menu_bar ~packing:vbox#pack () in
70 let factory = new GMenu.factory menubar in
71 let accel_group = factory#accel_group in
72 let file_menu = factory#add_submenu "File" in
73 let help_menu = factory#add_submenu "Help" in
76 let factory = new GMenu.factory file_menu ~accel_group in
77 let open_item = factory#add_item "Open connection ..."
79 ignore (factory#add_separator ());
80 let quit_item = factory#add_item "Quit" ~key:GdkKeysyms._Q in
82 ignore (open_item#connect#activate ~callback:open_connection);
85 let factory = new GMenu.factory help_menu ~accel_group in
86 let help_item = factory#add_item "Help" in
87 let help_about_item = factory#add_item "About ..." in
89 ignore (help_about_item#connect#activate ~callback:help_about);
92 let toolbar = GButton.toolbar ~packing:vbox#pack () in
94 GButton.tool_button ~label:"Connect ..." ~stock:`CONNECT
95 ~packing:toolbar#insert () in
97 GButton.tool_button ~label:"Start" ~stock:`ADD
98 ~packing:toolbar#insert () in
100 GButton.tool_button ~label:"Pause" ~stock:`MEDIA_PAUSE
101 ~packing:toolbar#insert () in
103 GButton.tool_button ~label:"Resume" ~stock:`MEDIA_PLAY
104 ~packing:toolbar#insert () in
105 let shutdown_button =
106 GButton.tool_button ~label:"Shutdown" ~stock:`STOP
107 ~packing:toolbar#insert () in
108 ignore (connect_button#connect#clicked ~callback:open_connection);
111 let (tree, model, columns, initial_state) =
112 Vc_connections.make_treeview
113 ~packing:(vbox#pack ~expand:true ~fill:true) () in
115 ignore (start_button#connect#clicked
116 ~callback:(start_domain tree model columns));
117 ignore (pause_button#connect#clicked
118 ~callback:(pause_domain tree model columns));
119 ignore (resume_button#connect#clicked
120 ~callback:(resume_domain tree model columns));
121 ignore (shutdown_button#connect#clicked
122 ~callback:(shutdown_domain tree model columns));
124 (* Make a timeout function which is called once per second. *)
125 let state = ref initial_state in
127 state := Vc_connections.repopulate tree model columns !state;
130 let timeout_id = GMain.Timeout.add ~ms:1000 ~callback in
134 GMain.Timeout.remove timeout_id;
139 ignore (window#connect#destroy ~callback:GMain.quit);
140 ignore (window#event#connect#delete ~callback:quit);
141 ignore (quit_item#connect#activate
142 ~callback:(fun () -> ignore (quit ()); ()));
144 window#add_accel_group accel_group;
146 (* Display the window. *)