[Spice-devel] [PATCH spice-gtk 3/4] usb-device-manager: Add a auto-connect-failed signal

Hans de Goede hdegoede at redhat.com
Wed Aug 31 06:21:58 PDT 2011


And use it in spicy to inform users of auto redirect failures (usually due
to insufficient rights on the /dev/bus/usb device nodes).

Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 gtk/spice-marshal.txt    |    1 +
 gtk/spicy.c              |   24 ++++++++++++++++++++++++
 gtk/usb-device-manager.c |   24 ++++++++++++++++++++++++
 gtk/usb-device-manager.h |    2 ++
 4 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/gtk/spice-marshal.txt b/gtk/spice-marshal.txt
index 55467e1..9c76054 100644
--- a/gtk/spice-marshal.txt
+++ b/gtk/spice-marshal.txt
@@ -11,3 +11,4 @@ VOID:UINT,UINT,POINTER,UINT
 BOOLEAN:UINT,POINTER,UINT
 BOOLEAN:UINT,UINT
 VOID:OBJECT,OBJECT
+VOID:BOXED,BOXED
diff --git a/gtk/spicy.c b/gtk/spicy.c
index 761e056..362ba04 100644
--- a/gtk/spicy.c
+++ b/gtk/spicy.c
@@ -1533,12 +1533,30 @@ signal_handler(int signum)
     g_main_loop_quit(mainloop);
 }
 
+static void auto_connect_failed(SpiceUsbDeviceManager *manager,
+                                SpiceUsbDevice        *device,
+                                GError                *error,
+                                gpointer               data)
+{
+    GtkWidget *dialog;
+
+    dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR,
+                                    GTK_BUTTONS_CLOSE,
+                                    "USB redirection error");
+    gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
+        "Unable to auto redirect %s: %s",
+        spice_usb_device_get_description(device), error->message);
+    gtk_dialog_run(GTK_DIALOG(dialog));
+    gtk_widget_destroy(dialog);
+}
+
 int main(int argc, char *argv[])
 {
     GError *error = NULL;
     GOptionContext *context;
     spice_connection *conn;
     gchar *conf_file, *conf;
+    SpiceUsbDeviceManager *manager;
 
     g_thread_init(NULL);
     bindtextdomain(GETTEXT_PACKAGE, SPICE_GTK_LOCALEDIR);
@@ -1599,6 +1617,12 @@ int main(int argc, char *argv[])
         g_signal_connect(rrscreen, "changed", G_CALLBACK(on_screen_changed), NULL);
     on_screen_changed(rrscreen, NULL);
 
+    manager = spice_usb_device_manager_get(NULL, NULL);
+    if (manager) {
+        g_signal_connect(manager, "auto-connect-failed",
+                         G_CALLBACK(auto_connect_failed), NULL);
+    }
+
     conn = connection_new();
     spice_set_session_option(conn->session);
     spice_cmdline_session_setup(conn->session);
diff --git a/gtk/usb-device-manager.c b/gtk/usb-device-manager.c
index 4e13ae1..ea439ee 100644
--- a/gtk/usb-device-manager.c
+++ b/gtk/usb-device-manager.c
@@ -46,6 +46,7 @@ enum
 {
     DEVICE_ADDED,
     DEVICE_REMOVED,
+    AUTO_CONNECT_FAILED,
     LAST_SIGNAL,
 };
 
@@ -280,6 +281,28 @@ static void spice_usb_device_manager_class_init(SpiceUsbDeviceManagerClass *klas
                      1,
                      SPICE_TYPE_USB_DEVICE);
 
+    /**
+     * SpiceUsbDeviceManager::auto-connect-failed:
+     * @manager: the #SpiceUsbDeviceManager that emitted the signal
+     * @device: #SpiceUsbDevice boxed object corresponding to device which failed to auto connect
+     * @error: #GError describing the reason why the autoconnect failed
+     *
+     * The #SpiceUsbDeviceManager::device-removed signal is emitted whenever
+     * the auto-connect property is true, and a newly plugged in device could
+     * not be auto-connected.
+     **/
+    signals[AUTO_CONNECT_FAILED] =
+        g_signal_new("auto-connect-failed",
+                     G_OBJECT_CLASS_TYPE(gobject_class),
+                     G_SIGNAL_RUN_FIRST,
+                     G_STRUCT_OFFSET(SpiceUsbDeviceManagerClass, auto_connect_failed),
+                     NULL, NULL,
+                     g_cclosure_user_marshal_VOID__BOXED_BOXED,
+                     G_TYPE_NONE,
+                     2,
+                     SPICE_TYPE_USB_DEVICE,
+                     G_TYPE_ERROR);
+
     g_type_class_add_private(klass, sizeof(SpiceUsbDeviceManagerPrivate));
 }
 
@@ -323,6 +346,7 @@ static void spice_usb_device_manager_dev_added(GUsbDeviceList *devlist,
         if (err) {
             g_warning("Could not auto-redirect %s: %s",
                       spice_usb_device_get_description(device), err->message);
+            g_signal_emit(manager, signals[AUTO_CONNECT_FAILED], 0, device, err);
             g_error_free(err);
         }
     }
diff --git a/gtk/usb-device-manager.h b/gtk/usb-device-manager.h
index d72e5dd..f18e457 100644
--- a/gtk/usb-device-manager.h
+++ b/gtk/usb-device-manager.h
@@ -59,6 +59,8 @@ struct _SpiceUsbDeviceManagerClass
                           SpiceUsbDevice *device);
     void (*device_removed) (SpiceUsbDeviceManager *manager,
                             SpiceUsbDevice *device);
+    void (*auto_connect_failed) (SpiceUsbDeviceManager *manager,
+                                 SpiceUsbDevice *device, GError *error);
     /*
      * If adding fields to this struct, remove corresponding
      * amount of padding to avoid changing overall struct size
-- 
1.7.6.1



More information about the Spice-devel mailing list