diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2015-03-25 00:06:33 +0100 |
---|---|---|
committer | Marc-André Lureau <marcandre.lureau@redhat.com> | 2015-03-25 11:57:51 +0100 |
commit | f047ffdd174ad076f981a96d40099cec3a2e302d (patch) | |
tree | 96bd1b134b53e4f2c17286ada22bcdd60c94ae0b | |
parent | 9acea56987506f1d47d5bc933e824dc5b2f7654e (diff) |
smartcard: add reader and cards on channel up
The smartcard manager reports reader/card events on insertion and
removal. If a smartcard channel is created after those events, the
channel state will not be in sync with the current reader/card state.
Sync the state when the channel is up.
Fixes:
https://bugzilla.redhat.com/show_bug.cgi?id=1205171
-rw-r--r-- | gtk/channel-smartcard.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/gtk/channel-smartcard.c b/gtk/channel-smartcard.c index cc3ae3b..0ab7213 100644 --- a/gtk/channel-smartcard.c +++ b/gtk/channel-smartcard.c @@ -400,6 +400,10 @@ static void reader_added_cb(SpiceSmartcardManager *manager, VReader *reader, SpiceSmartcardChannel *channel = SPICE_SMARTCARD_CHANNEL(user_data); const char *reader_name = vreader_get_name(reader); + if (vreader_get_id(reader) != -1 || + g_list_find(channel->priv->pending_reader_additions, reader)) + return; + channel->priv->pending_reader_additions = g_list_append(channel->priv->pending_reader_additions, reader); @@ -452,6 +456,8 @@ static void spice_smartcard_channel_up_cb(GObject *source_object, gpointer user_data) { SpiceChannel *channel = SPICE_CHANNEL(user_data); + SpiceSmartcardManager *manager = spice_smartcard_manager_get(); + GList *l, *list = NULL; GError *error = NULL; g_return_if_fail(channel != NULL); @@ -459,9 +465,25 @@ static void spice_smartcard_channel_up_cb(GObject *source_object, spice_smartcard_manager_init_finish(SPICE_SESSION(source_object), res, &error); - if (error) + if (error) { g_warning("%s", error->message); + goto end; + } + + list = spice_smartcard_manager_get_readers(manager); + for (l = list; l != NULL; l = l->next) { + VReader *reader = l->data; + gboolean has_card = vreader_card_is_present(reader) == VREADER_OK; + + reader_added_cb(manager, reader, channel); + if (has_card) + card_inserted_cb(manager, reader, channel); + + g_boxed_free(SPICE_TYPE_SMARTCARD_READER, reader); + } +end: + g_list_free(list); g_clear_error(&error); } |