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

Christophe Fergeau cfergeau at redhat.com
Wed Dec 19 16:23:51 UTC 2012


Bleh, this conflicts with this unreviewed patch of mine /o\
https://www.redhat.com/archives/virt-tools-list/2012-December/msg00172.html

Luckily this is easy enough to fix :)

Christophe

On Wed, Dec 19, 2012 at 03:59:27PM +0100, Hans de Goede wrote:
> Signed-off-by: Hans de Goede <hdegoede at redhat.com>
> ---
>  src/remote-viewer.c   | 36 +-----------------------------------
>  src/virt-viewer-app.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
>  src/virt-viewer-app.h |  1 +
>  3 files changed, 49 insertions(+), 35 deletions(-)
> 
> diff --git a/src/remote-viewer.c b/src/remote-viewer.c
> index 31812d6..b296d67 100644
> --- a/src/remote-viewer.c
> +++ b/src/remote-viewer.c
> @@ -509,41 +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;
> -        }
> -
> -        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..4e56d40 100644
> --- a/src/virt-viewer-app.c
> +++ b/src/virt-viewer-app.c
> @@ -1521,6 +1521,53 @@ 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;
> +    }
> +
> +    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
> 
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list at redhat.com
> https://www.redhat.com/mailman/listinfo/virt-tools-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20121219/561ac9e5/attachment.sig>


More information about the virt-tools-list mailing list