[virt-tools-list] [PATCH 1/2] Add a virt_viewer_app_set_hotkeys() helper function

Hans de Goede hdegoede at redhat.com
Fri Dec 21 09:56:21 UTC 2012


Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 src/remote-viewer.c   | 41 +--------------------------------------
 src/virt-viewer-app.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/virt-viewer-app.h |  1 +
 3 files changed, 55 insertions(+), 40 deletions(-)

diff --git a/src/remote-viewer.c b/src/remote-viewer.c
index 559f29a..b296d67 100644
--- a/src/remote-viewer.c
+++ b/src/remote-viewer.c
@@ -509,46 +509,7 @@ spice_ctrl_notified(SpiceCtrlController *ctrl,
     } else if (g_str_equal(pspec->name, "menu")) {
         spice_ctrl_menu_updated(self);
     } else if (g_str_equal(pspec->name, "hotkeys")) {
-        gchar **hotkey, **hotkeys = g_strsplit(g_value_get_string(&value), ",", -1);
-        if (!hotkeys || g_strv_length(hotkeys) == 0) {
-            g_object_set(app, "enable-accel", FALSE, NULL);
-            goto end;
-        }
-        /* Disable default bindings and replace them with our own */
-        gtk_accel_map_change_entry("<virt-viewer>/view/fullscreen", 0, 0, TRUE);
-        gtk_accel_map_change_entry("<virt-viewer>/view/release-cursor", 0, 0, TRUE);
-        gtk_accel_map_change_entry("<virt-viewer>/file/smartcard-insert", 0, 0, TRUE);
-        gtk_accel_map_change_entry("<virt-viewer>/file/smartcard-remove", 0, 0, TRUE);
-
-        for (hotkey = hotkeys; *hotkey != NULL; hotkey++) {
-            gchar *key = strstr(*hotkey, "=");
-            if (key == NULL) {
-                g_warn_if_reached();
-                continue;
-            }
-            *key = '\0';
-
-            gchar *accel = spice_hotkey_to_gtk_accelerator(key + 1);
-            guint accel_key;
-            GdkModifierType accel_mods;
-            gtk_accelerator_parse(accel, &accel_key, &accel_mods);
-            g_free(accel);
-
-            if (g_str_equal(*hotkey, "toggle-fullscreen")) {
-                gtk_accel_map_change_entry("<virt-viewer>/view/fullscreen", accel_key, accel_mods, TRUE);
-            } else if (g_str_equal(*hotkey, "release-cursor")) {
-                gtk_accel_map_change_entry("<virt-viewer>/view/release-cursor", accel_key, accel_mods, TRUE);
-            } else if (g_str_equal(*hotkey, "smartcard-insert")) {
-                gtk_accel_map_change_entry("<virt-viewer>/file/smartcard-insert", accel_key, accel_mods, TRUE);
-            } else if (g_str_equal(*hotkey, "smartcard-remove")) {
-                gtk_accel_map_change_entry("<virt-viewer>/file/smartcard-remove", accel_key, accel_mods, TRUE);
-            } else {
-                g_warning("Unknown hotkey command %s", *hotkey);
-            }
-        }
-        g_strfreev(hotkeys);
-
-        g_object_set(app, "enable-accel", TRUE, NULL);
+        virt_viewer_app_set_hotkeys(app, g_value_get_string(&value));
     } else {
         gchar *content = g_strdup_value_contents(&value);
 
diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index 6b3ad6d..cdcba67 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -1521,6 +1521,59 @@ virt_viewer_app_set_direct(VirtViewerApp *self, gboolean direct)
 }
 
 void
+virt_viewer_app_set_hotkeys(VirtViewerApp *self, const gchar *hotkeys_str)
+{
+    gchar **hotkey, **hotkeys = NULL;
+
+    g_return_if_fail(VIRT_VIEWER_IS_APP(self));
+
+    if (hotkeys_str)
+        hotkeys = g_strsplit(hotkeys_str, ",", -1);
+
+    if (!hotkeys || g_strv_length(hotkeys) == 0) {
+        g_strfreev(hotkeys);
+        g_object_set(self, "enable-accel", FALSE, NULL);
+        return;
+    }
+
+    /* Disable default bindings and replace them with our own */
+    gtk_accel_map_change_entry("<virt-viewer>/view/fullscreen", 0, 0, TRUE);
+    gtk_accel_map_change_entry("<virt-viewer>/view/release-cursor", 0, 0, TRUE);
+    gtk_accel_map_change_entry("<virt-viewer>/file/smartcard-insert", 0, 0, TRUE);
+    gtk_accel_map_change_entry("<virt-viewer>/file/smartcard-remove", 0, 0, TRUE);
+
+    for (hotkey = hotkeys; *hotkey != NULL; hotkey++) {
+        gchar *key = strstr(*hotkey, "=");
+        if (key == NULL) {
+            g_warn_if_reached();
+            continue;
+        }
+        *key = '\0';
+
+        gchar *accel = spice_hotkey_to_gtk_accelerator(key + 1);
+        guint accel_key;
+        GdkModifierType accel_mods;
+        gtk_accelerator_parse(accel, &accel_key, &accel_mods);
+        g_free(accel);
+
+        if (g_str_equal(*hotkey, "toggle-fullscreen")) {
+            gtk_accel_map_change_entry("<virt-viewer>/view/fullscreen", accel_key, accel_mods, TRUE);
+        } else if (g_str_equal(*hotkey, "release-cursor")) {
+            gtk_accel_map_change_entry("<virt-viewer>/view/release-cursor", accel_key, accel_mods, TRUE);
+        } else if (g_str_equal(*hotkey, "smartcard-insert")) {
+            gtk_accel_map_change_entry("<virt-viewer>/file/smartcard-insert", accel_key, accel_mods, TRUE);
+        } else if (g_str_equal(*hotkey, "smartcard-remove")) {
+            gtk_accel_map_change_entry("<virt-viewer>/file/smartcard-remove", accel_key, accel_mods, TRUE);
+        } else {
+            g_warning("Unknown hotkey command %s", *hotkey);
+        }
+    }
+    g_strfreev(hotkeys);
+
+    g_object_set(self, "enable-accel", TRUE, NULL);
+}
+
+void
 virt_viewer_app_set_attach(VirtViewerApp *self, gboolean attach)
 {
     g_return_if_fail(VIRT_VIEWER_IS_APP(self));
diff --git a/src/virt-viewer-app.h b/src/virt-viewer-app.h
index 2cd3547..663f7a1 100644
--- a/src/virt-viewer-app.h
+++ b/src/virt-viewer-app.h
@@ -76,6 +76,7 @@ int virt_viewer_app_initial_connect(VirtViewerApp *self);
 void virt_viewer_app_start_reconnect_poll(VirtViewerApp *self);
 void virt_viewer_app_set_zoom_level(VirtViewerApp *self, gint zoom_level);
 void virt_viewer_app_set_direct(VirtViewerApp *self, gboolean direct);
+void virt_viewer_app_set_hotkeys(VirtViewerApp *self, const gchar *hotkeys);
 void virt_viewer_app_set_attach(VirtViewerApp *self, gboolean attach);
 gboolean virt_viewer_app_get_attach(VirtViewerApp *self);
 gboolean virt_viewer_app_has_session(VirtViewerApp *self);
-- 
1.8.0.2




More information about the virt-tools-list mailing list