[virt-tools-list] [PATCH 1/2] Add a menu entry for USB device selection

Hans de Goede hdegoede at redhat.com
Wed Feb 1 13:28:23 UTC 2012


Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 configure.ac                    |    2 +-
 src/virt-viewer-app.c           |    9 +++++++++
 src/virt-viewer-app.h           |    3 +++
 src/virt-viewer-session-spice.c |   39 +++++++++++++++++++++++++++++++++++----
 src/virt-viewer-session.c       |   13 +++++++++++++
 src/virt-viewer-session.h       |    4 ++++
 src/virt-viewer-window.c        |    9 +++++++++
 src/virt-viewer.xml             |   10 ++++++++++
 8 files changed, 84 insertions(+), 5 deletions(-)

diff --git a/configure.ac b/configure.ac
index a54f41b..ca4ff4c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,7 +16,7 @@ LIBVIRT_REQUIRED="0.6.0"
 GTK2_REQUIRED="2.12.0"
 GTK3_REQUIRED="3.0"
 GTK_VNC_REQUIRED="0.4.3"
-SPICE_GTK_REQUIRED="0.8"
+SPICE_GTK_REQUIRED="0.9"
 
 AC_PROG_CC
 AM_PROG_CC_C_O
diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index 5cdc186..d97ffa2 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -1609,6 +1609,15 @@ virt_viewer_app_get_windows(VirtViewerApp *self)
 	return self->priv->windows;
 }
 
+void virt_viewer_app_usb_device_selection(VirtViewerApp   *self,
+					  GtkWindow       *parent)
+{
+	g_return_if_fail(VIRT_VIEWER_IS_APP(self));
+	g_return_if_fail(self->priv->session != NULL);
+
+	virt_viewer_session_usb_device_selection(self->priv->session, parent);
+}
+
 /*
  * Local variables:
  *  c-indent-level: 8
diff --git a/src/virt-viewer-app.h b/src/virt-viewer-app.h
index 7280873..3170dae 100644
--- a/src/virt-viewer-app.h
+++ b/src/virt-viewer-app.h
@@ -91,6 +91,9 @@ void virt_viewer_app_show_status(VirtViewerApp *self, const gchar *fmt, ...);
 void virt_viewer_app_show_display(VirtViewerApp *self);
 GHashTable* virt_viewer_app_get_windows(VirtViewerApp *self);
 
+void virt_viewer_app_usb_device_selection(VirtViewerApp   *self,
+					  GtkWindow       *parent);
+
 G_END_DECLS
 
 #endif /* VIRT_VIEWER_APP_H */
diff --git a/src/virt-viewer-session-spice.c b/src/virt-viewer-session-spice.c
index dccfbbc..9832a4b 100644
--- a/src/virt-viewer-session-spice.c
+++ b/src/virt-viewer-session-spice.c
@@ -26,6 +26,7 @@
 #include <glib/gi18n.h>
 
 #include <spice-option.h>
+#include <usb-device-widget.h>
 #include "virt-viewer-util.h"
 #include "virt-viewer-session-spice.h"
 #include "virt-viewer-display-spice.h"
@@ -53,6 +54,7 @@ static gboolean virt_viewer_session_spice_open_fd(VirtViewerSession *session, in
 static gboolean virt_viewer_session_spice_open_host(VirtViewerSession *session, char *host, char *port);
 static gboolean virt_viewer_session_spice_open_uri(VirtViewerSession *session, char *uri);
 static gboolean virt_viewer_session_spice_channel_open_fd(VirtViewerSession *session, VirtViewerSessionChannel *channel, int fd);
+static void virt_viewer_session_spice_usb_device_selection(VirtViewerSession *session, GtkWindow *parent);
 static void virt_viewer_session_spice_channel_new(SpiceSession *s,
 						  SpiceChannel *channel,
 						  VirtViewerSession *session);
@@ -118,6 +120,7 @@ virt_viewer_session_spice_class_init(VirtViewerSessionSpiceClass *klass)
 	dclass->open_host = virt_viewer_session_spice_open_host;
 	dclass->open_uri = virt_viewer_session_spice_open_uri;
 	dclass->channel_open_fd = virt_viewer_session_spice_channel_open_fd;
+	dclass->usb_device_selection = virt_viewer_session_spice_usb_device_selection;
 
 	g_type_class_add_private(klass, sizeof(VirtViewerSessionSpicePrivate));
 
@@ -138,9 +141,9 @@ virt_viewer_session_spice_init(VirtViewerSessionSpice *self G_GNUC_UNUSED)
 }
 
 static void
-usb_auto_connect_failed(SpiceUsbDeviceManager *manager G_GNUC_UNUSED,
-			SpiceUsbDevice *device G_GNUC_UNUSED,
-			GError *error, VirtViewerSessionSpice *self)
+usb_connect_failed(GObject *object G_GNUC_UNUSED,
+		   SpiceUsbDevice *device G_GNUC_UNUSED,
+		   GError *error, VirtViewerSessionSpice *self)
 {
 	if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
 		return;
@@ -170,7 +173,7 @@ create_spice_session(VirtViewerSessionSpice *self)
 	manager = spice_usb_device_manager_get(self->priv->session, NULL);
 	if (manager)
 		g_signal_connect(manager, "auto-connect-failed",
-				 G_CALLBACK(usb_auto_connect_failed), self);
+				 G_CALLBACK(usb_connect_failed), self);
 
 	g_object_bind_property(self, "auto-usbredir",
 			       self->priv->gtk_session, "auto-usbredir",
@@ -307,6 +310,34 @@ virt_viewer_session_spice_main_channel_event(SpiceChannel *channel G_GNUC_UNUSED
 	g_free(password);
 }
 
+static void
+virt_viewer_session_spice_usb_device_selection(VirtViewerSession *session,
+					       GtkWindow *parent)
+{
+	VirtViewerSessionSpice *self = VIRT_VIEWER_SESSION_SPICE(session);
+	VirtViewerSessionSpicePrivate *priv = self->priv;
+	GtkWidget *dialog, *area, *usb_device_widget;
+
+	/* Create the widgets */
+	dialog = gtk_dialog_new_with_buttons(
+		    _("Select USB devices for redirection"), parent,
+		    GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+		    GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+		    NULL);
+	gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
+	area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+
+	usb_device_widget = spice_usb_device_widget_new(priv->session,
+							"%s %s");
+	g_signal_connect(usb_device_widget, "connect-failed",
+			 G_CALLBACK(usb_connect_failed), self);
+	gtk_box_pack_start(GTK_BOX(area), usb_device_widget, TRUE, TRUE, 5);
+
+	/* show and run */
+	gtk_widget_show_all(dialog);
+	gtk_dialog_run(GTK_DIALOG(dialog));
+	gtk_widget_destroy(dialog);
+}
 
 static void
 virt_viewer_session_spice_channel_new(SpiceSession *s,
diff --git a/src/virt-viewer-session.c b/src/virt-viewer-session.c
index e115fff..8fb4646 100644
--- a/src/virt-viewer-session.c
+++ b/src/virt-viewer-session.c
@@ -352,6 +352,19 @@ gboolean virt_viewer_session_get_auto_usbredir(VirtViewerSession *self)
 	return self->priv->auto_usbredir;
 }
 
+void virt_viewer_session_usb_device_selection(VirtViewerSession   *self,
+					      GtkWindow           *parent)
+{
+	VirtViewerSessionClass *klass;
+
+	g_return_if_fail(VIRT_VIEWER_IS_SESSION(self));
+
+	klass = VIRT_VIEWER_SESSION_GET_CLASS(self);
+	g_return_if_fail(klass->usb_device_selection != NULL);
+
+	klass->usb_device_selection(self, parent);
+}
+
 /*
  * Local variables:
  *  c-indent-level: 8
diff --git a/src/virt-viewer-session.h b/src/virt-viewer-session.h
index 80ef372..565ff31 100644
--- a/src/virt-viewer-session.h
+++ b/src/virt-viewer-session.h
@@ -70,6 +70,7 @@ struct _VirtViewerSessionClass {
 	gboolean (* open_host) (VirtViewerSession* session, char *host, char *port);
 	gboolean (* open_uri) (VirtViewerSession* session, char *uri);
 	gboolean (* channel_open_fd) (VirtViewerSession* session, VirtViewerSessionChannel *channel, int fd);
+	void (* usb_device_selection) (VirtViewerSession* session, GtkWindow *parent);
 
 	/* signals */
 	void (*session_connected)(VirtViewerSession *session);
@@ -112,6 +113,9 @@ gboolean virt_viewer_session_open_uri(VirtViewerSession *session, gchar *uri);
 void virt_viewer_session_set_auto_usbredir(VirtViewerSession* session, gboolean auto_usbredir);
 gboolean virt_viewer_session_get_auto_usbredir(VirtViewerSession* session);
 
+void virt_viewer_session_usb_device_selection(VirtViewerSession   *self,
+					      GtkWindow           *parent);
+
 G_END_DECLS
 
 #endif /* _VIRT_VIEWER_SESSION_H */
diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
index d80b456..555bdae 100644
--- a/src/virt-viewer-window.c
+++ b/src/virt-viewer-window.c
@@ -51,6 +51,7 @@ void virt_viewer_window_menu_view_fullscreen(GtkWidget *menu, VirtViewerWindow *
 void virt_viewer_window_menu_view_resize(GtkWidget *menu, VirtViewerWindow *self);
 void virt_viewer_window_menu_send(GtkWidget *menu, VirtViewerWindow *self);
 void virt_viewer_window_menu_file_screenshot(GtkWidget *menu, VirtViewerWindow *self);
+void virt_viewer_window_menu_file_usb_device_selection(GtkWidget *menu, VirtViewerWindow *self);
 
 /* Internal methods */
 static void virt_viewer_window_enable_modifiers(VirtViewerWindow *self);
@@ -726,6 +727,14 @@ virt_viewer_window_menu_file_screenshot(GtkWidget *menu G_GNUC_UNUSED,
 }
 
 G_MODULE_EXPORT void
+virt_viewer_window_menu_file_usb_device_selection(GtkWidget *menu G_GNUC_UNUSED,
+						  VirtViewerWindow *self)
+{
+	virt_viewer_app_usb_device_selection(self->priv->app,
+					     GTK_WINDOW(self->priv->window));
+}
+
+G_MODULE_EXPORT void
 virt_viewer_window_menu_help_about(GtkWidget *menu G_GNUC_UNUSED,
 				   VirtViewerWindow *self)
 {
diff --git a/src/virt-viewer.xml b/src/virt-viewer.xml
index b701c2c..d9c1334 100644
--- a/src/virt-viewer.xml
+++ b/src/virt-viewer.xml
@@ -36,6 +36,16 @@
                       </object>
                     </child>
                     <child>
+                      <object class="GtkMenuItem" id="menu-file-usb-device-selection">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="use_action_appearance">False</property>
+                        <property name="label" translatable="yes">USB device selection</property>
+                        <property name="use_underline">True</property>
+                        <signal name="activate" handler="virt_viewer_window_menu_file_usb_device_selection" swapped="no"/>
+                      </object>
+                    </child>
+                    <child>
                       <object class="GtkSeparatorMenuItem" id="separatormenuitem1">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-- 
1.7.7.6




More information about the virt-tools-list mailing list