2 * Copyright (C) 2011 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 quit_item : GMenu.menu_item;
28 about_item : GMenu.menu_item;
32 source_tab : Source_tab.tab;
33 destination_tab : Destination_tab.tab;
34 partitions_tab : Partitions_tab.tab;
35 logvols_tab : Logvols_tab.tab;
39 prev_button : GButton.button;
40 next_button : GButton.button;
41 go_button : GButton.button;
42 exit_button : GButton.button;
46 let title = "Resize a virtual machine - virt-resize-ui" in
48 val mutable tabs = None
49 val mutable statusbar_context = None
50 val mutable progress_bar : GRange.progress_bar option = None
52 method source_tab = (Option.get tabs).source_tab
54 method set_statusbar msg =
61 method progress (position, total) =
64 if position = 0L && total = 1L then
67 let frac = Int64.to_float position /. Int64.to_float total in
68 if frac < 0. || frac > 1. then
69 eprintf "warning: progress bar out of range: %Ld / %Ld (%g)\n"
71 let frac = if frac < 0. then 0. else if frac > 1. then 1. else frac in
78 let window = GWindow.window ~width:700 ~height:700 ~title () in
79 let vbox = GPack.vbox ~packing:window#add () in
82 let menubar = GMenu.menu_bar ~packing:vbox#pack () in
83 let factory = new GMenu.factory menubar in
84 let accel_group = factory#accel_group in
87 let menu = factory#add_submenu "_File" in
88 let factory = new GMenu.factory menu ~accel_group in
89 let quit = factory#add_item "E_xit" ~key:GdkKeysyms._Q in
90 { quit_item = quit } in
93 let menu = factory#add_submenu "_Help" in
94 let factory = new GMenu.factory menu ~accel_group in
95 let about = factory#add_item "About virt-resize-ui ..." in
96 { about_item = about } in
100 (* Tabbed notebook for main part of the display. *)
102 let nb = GPack.notebook ~packing:(vbox#pack ~expand:true ~fill:true) () in
104 let src = Source_tab.tab () in
105 let tab_label = (GMisc.label ~text:"Source" () :> GObj.widget) in
106 ignore (nb#append_page ~tab_label (src :> GObj.widget));
108 let dest = Destination_tab.tab () in
109 let tab_label = (GMisc.label ~text:"Destination" () :> GObj.widget) in
110 ignore (nb#append_page ~tab_label (dest :> GObj.widget));
112 let parts = Partitions_tab.tab () in
114 (GMisc.label ~text:"Resize partitions" () :> GObj.widget) in
115 ignore (nb#append_page ~tab_label (parts :> GObj.widget));
117 let lvs = Logvols_tab.tab () in
119 (GMisc.label ~text:"Expand logical volumes" () :> GObj.widget) in
120 ignore (nb#append_page ~tab_label (lvs :> GObj.widget));
122 Some { source_tab = src; destination_tab = dest;
123 partitions_tab = parts; logvols_tab = lvs });
125 (* Status bar and progress bar. *)
126 let hbox = GPack.hbox ~spacing:4 ~packing:vbox#pack () in
127 progress_bar <- Some (GRange.progress_bar ~packing:hbox#pack ());
128 let statusbar = GMisc.statusbar ~packing:(hbox#pack ~expand:true) () in
129 statusbar_context <- Some (statusbar#new_context ~name:"Standard");
130 ignore ((Option.get statusbar_context)#push title);
134 let bbox = GPack.button_box `HORIZONTAL ~packing:vbox#pack () in
135 bbox#set_border_width 8;
137 let ex = GButton.button ~stock:`QUIT ~packing:bbox#pack () in
138 ex#misc#set_sensitive true;
139 let prev = GButton.button ~stock:`GO_BACK ~packing:bbox#pack () in
140 prev#misc#set_sensitive false;
141 let next = GButton.button ~stock:`GO_FORWARD ~packing:bbox#pack () in
142 next#misc#set_sensitive true;
143 let go = GButton.button ~stock:`APPLY ~packing:bbox#pack () in
144 go#misc#set_sensitive false;
145 { prev_button = prev; next_button = next; go_button = go;
146 exit_button = ex } in
149 let quit _ = GMain.quit (); false in
150 ignore (window#connect#destroy ~callback:GMain.quit);
151 ignore (window#event#connect#delete ~callback:quit);
152 ignore (file_menu.quit_item#connect#activate
153 ~callback:(fun () -> ignore (quit ()); ()));
154 ignore (buttons.exit_button#connect#clicked
155 ~callback:(fun () -> ignore (quit ()); ()));
158 window#add_accel_group accel_group;