From 298cc147ee0015df2128f9efe0402004e9820b9c Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 29 Jul 2011 14:43:49 +0100 Subject: [PATCH] Implement open disk and connect to URI menu options. --- .depend | 10 ++++++++-- Makefile.am | 6 ++++++ main.ml | 4 ++++ menu_open_disk.ml | 41 +++++++++++++++++++++++++++++++++++++++++ menu_open_disk.mli | 23 +++++++++++++++++++++++ menu_open_uri.ml | 38 ++++++++++++++++++++++++++++++++++++++ menu_open_uri.mli | 21 +++++++++++++++++++++ window.ml | 7 ++++++- window.mli | 7 ++++++- 9 files changed, 153 insertions(+), 4 deletions(-) create mode 100644 menu_open_disk.ml create mode 100644 menu_open_disk.mli create mode 100644 menu_open_uri.ml create mode 100644 menu_open_uri.mli diff --git a/.depend b/.depend index f90ce09..94b28dd 100644 --- a/.depend +++ b/.depend @@ -13,8 +13,14 @@ filetree.cmx: utils.cmx slave_types.cmx slave.cmx filetree_markup.cmx deviceSet. filetree_markup.cmi: slave_types.cmi filetree_markup.cmo: utils.cmi slave_types.cmi filetree_markup.cmi filetree_markup.cmx: utils.cmx slave_types.cmx filetree_markup.cmi -main.cmo: window.cmi utils.cmi slave.cmi op_view_file.cmi op_inspection_dialog.cmi op_file_information.cmi op_download_file.cmi op_download_dir_tarball.cmi op_download_dir_find0.cmi op_download_as_reg.cmi op_disk_usage.cmi op_copy_regvalue.cmi op_checksum_file.cmi config.cmi cmdline.cmi -main.cmx: window.cmx utils.cmx slave.cmx op_view_file.cmx op_inspection_dialog.cmx op_file_information.cmx op_download_file.cmx op_download_dir_tarball.cmx op_download_dir_find0.cmx op_download_as_reg.cmx op_disk_usage.cmx op_copy_regvalue.cmx op_checksum_file.cmx config.cmx cmdline.cmx +main.cmo: window.cmi utils.cmi slave.cmi op_view_file.cmi op_inspection_dialog.cmi op_file_information.cmi op_download_file.cmi op_download_dir_tarball.cmi op_download_dir_find0.cmi op_download_as_reg.cmi op_disk_usage.cmi op_copy_regvalue.cmi op_checksum_file.cmi menu_open_uri.cmi menu_open_disk.cmi config.cmi cmdline.cmi +main.cmx: window.cmx utils.cmx slave.cmx op_view_file.cmx op_inspection_dialog.cmx op_file_information.cmx op_download_file.cmx op_download_dir_tarball.cmx op_download_dir_find0.cmx op_download_as_reg.cmx op_disk_usage.cmx op_copy_regvalue.cmx op_checksum_file.cmx menu_open_uri.cmx menu_open_disk.cmx config.cmx cmdline.cmx +menu_open_disk.cmi: window.cmi +menu_open_disk.cmo: utils.cmi menu_open_disk.cmi +menu_open_disk.cmx: utils.cmx menu_open_disk.cmi +menu_open_uri.cmi: window.cmi +menu_open_uri.cmo: utils.cmi menu_open_uri.cmi +menu_open_uri.cmx: utils.cmx menu_open_uri.cmi op_checksum_file.cmi: filetree.cmi op_checksum_file.cmo: utils.cmi slave.cmi op_checksum_file.cmi op_checksum_file.cmx: utils.cmx slave.cmx op_checksum_file.cmi diff --git a/Makefile.am b/Makefile.am index f77a4b7..8a0be7c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -48,6 +48,10 @@ SOURCES = \ filetree_markup.mli \ filetree_markup.ml \ main.ml \ + menu_open_disk.mli \ + menu_open_disk.ml \ + menu_open_uri.mli \ + menu_open_uri.ml \ op_checksum_file.mli \ op_checksum_file.ml \ op_copy_regvalue.mli \ @@ -102,6 +106,8 @@ OBJECTS = \ op_file_information.cmo \ op_inspection_dialog.cmo \ op_view_file.cmo \ + menu_open_uri.cmo \ + menu_open_disk.cmo \ window.cmo \ main.cmo diff --git a/main.ml b/main.ml index 92327c3..c6c60c5 100644 --- a/main.ml +++ b/main.ml @@ -77,6 +77,10 @@ let () = ~callback:(w#connect_to (Some "xen:///"))); ignore (w#connect_none_signal ~callback:(w#connect_to None)); + ignore (w#connect_uri_signal + ~callback:(Menu_open_uri.open_uri_dialog w)); + ignore (w#open_disk_signal + ~callback:(Menu_open_disk.open_disk_dialog w)); ignore (w#reopen_signal ~callback:w#reopen); ignore ( w#inspection_signal diff --git a/menu_open_disk.ml b/menu_open_disk.ml new file mode 100644 index 0000000..31cbb9f --- /dev/null +++ b/menu_open_disk.ml @@ -0,0 +1,41 @@ +(* Guestfs Browser. + * Copyright (C) 2011 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 + +open Printf + +let open_disk_dialog w () = + debug "open disk dialog"; + let title = "Open disk image directly" in + + let d = GWindow.file_chooser_dialog ~action:`OPEN ~title ~modal:true () in + d#add_button_stock `CANCEL `CANCEL; + d#add_select_button_stock `OPEN `OPEN; + + match d#run () with + | `DELETE_EVENT | `CANCEL -> + d#destroy () + | `OPEN -> + match d#filename with + | None -> () + | Some localfile -> + d#destroy (); + + (* Open the disk image. *) + w#open_disk_images [localfile, None] diff --git a/menu_open_disk.mli b/menu_open_disk.mli new file mode 100644 index 0000000..24dd768 --- /dev/null +++ b/menu_open_disk.mli @@ -0,0 +1,23 @@ +(* Guestfs Browser. + * Copyright (C) 2011 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. + *) + +(** Connect -> Open disk image dialog. + + Currently this is limited to opening a single disk. *) + +val open_disk_dialog : Window.window -> unit -> unit diff --git a/menu_open_uri.ml b/menu_open_uri.ml new file mode 100644 index 0000000..c987fca --- /dev/null +++ b/menu_open_uri.ml @@ -0,0 +1,38 @@ +(* Guestfs Browser. + * Copyright (C) 2011 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 + +open Printf + +let open_uri_dialog w () = + debug "open URI dialog"; + let title = "Open libvirt URI" in + + let msg = "Note that guestfs-browser needs access to the disk images. +Therefore remote URIs will usually not work." in + let uri = GToolbox.input_string ~title ~text:"qemu:///system" msg in + + match uri with + | None -> () + | Some "" -> (* assume default URI *) + debug "open URI: connect to NULL"; + w#connect_to None () + | Some uri -> + debug "open URI: connect to non-NULL URI %s" uri; + w#connect_to (Some uri) () diff --git a/menu_open_uri.mli b/menu_open_uri.mli new file mode 100644 index 0000000..012fcbc --- /dev/null +++ b/menu_open_uri.mli @@ -0,0 +1,21 @@ +(* Guestfs Browser. + * Copyright (C) 2011 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. + *) + +(** Connect -> Connect to a libvirt URI dialog. *) + +val open_uri_dialog : Window.window -> unit -> unit diff --git a/window.ml b/window.ml index 7f35b04..ac6c34c 100644 --- a/window.ml +++ b/window.ml @@ -118,6 +118,7 @@ class window = let connect_xen_signal = new GUtil.signal () in let connect_none_signal = new GUtil.signal () in let connect_uri_signal = new GUtil.signal () in + let open_disk_signal = new GUtil.signal () in let reopen_signal = new GUtil.signal () in let inspection_signal = new GUtil.signal () in @@ -126,6 +127,7 @@ object (self) connect_xen_signal#disconnect; connect_none_signal#disconnect; connect_uri_signal#disconnect; + open_disk_signal#disconnect; reopen_signal#disconnect; inspection_signal#disconnect] @@ -133,6 +135,7 @@ object (self) method connect_xen_signal = connect_xen_signal#connect ~after method connect_none_signal = connect_none_signal#connect ~after method connect_uri_signal = connect_uri_signal#connect ~after + method open_disk_signal = open_disk_signal#connect ~after method reopen_signal = reopen_signal#connect ~after method inspection_signal = inspection_signal#connect ~after @@ -159,6 +162,8 @@ object (self) ~callback:connect_none_signal#call); ignore (connect_menu.connect_uri_item#connect#activate ~callback:connect_uri_signal#call); + ignore (connect_menu.open_disk_item#connect#activate + ~callback:open_disk_signal#call); ignore (connect_menu.reopen_item#connect#activate ~callback:reopen_signal#call); ignore (guest_menu.guest_inspection_item#connect#activate @@ -227,7 +232,7 @@ object (self) self#when_opened_common name data (* When a set of disk images is selected by the user. *) - method private open_disk_images images = + method open_disk_images images = match images with | [] -> () | images -> diff --git a/window.mli b/window.mli index 39994dc..530acbc 100644 --- a/window.mli +++ b/window.mli @@ -24,11 +24,12 @@ object ('a) method after : 'a method disconnect : GtkSignal.id -> unit - (** Signals that can be emitted by window. *) + (** Signals that can be emitted by window menu items. *) method connect_kvm_signal : callback:(unit -> unit) -> GtkSignal.id method connect_xen_signal : callback:(unit -> unit) -> GtkSignal.id method connect_none_signal : callback:(unit -> unit) -> GtkSignal.id method connect_uri_signal : callback:(unit -> unit) -> GtkSignal.id + method open_disk_signal : callback:(unit -> unit) -> GtkSignal.id method reopen_signal : callback:(unit -> unit) -> GtkSignal.id method inspection_signal : callback:(unit -> unit) -> GtkSignal.id @@ -57,6 +58,10 @@ object ('a) method connect_to : string option -> unit -> unit (** Connect to the given libvirt URI. *) + method open_disk_images : (string * string option) list -> unit + (** Open disk image(s) directly. The second part of each pair + is the optional disk format. *) + method reopen : unit -> unit (** Reopen the libguestfs handle and current guest. *) -- 1.8.3.1