usb-device-manager: Splitout device add / remove function

Split the device add / remove functions into a gudev specific part and
a generic part. This is a preparation patch for adding support libusb's
new hotplug API.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
usb-device-manager: Add support for libusb hotplug API

For now this makes the usb-code even more of a #ifdef party (albeit only
slightly so). But it does give us (theoretical, untested) usb support on
Mac OS X, and once the libusb Windows backend also gets hotplug support, we
can bump the required libusb version to a new enough one, and drop both the
windows gudev emulation as well as the gudev code-paths.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
gi: Make sure usb-device-widget.c is introspected

If it's not, annotation we add to inline gtk-doc comments won't
be taken into account in the .gir file.
gi: Add (allow none) to optional const char * params

Without that annotation, it will not be possible to pass NULL to
these methods when using a gi-based binding.
gst: Chain up dispose impl to parent class
doc: Fix typo in code comment
smartcard: Handle VCARD_EMUL_INIT_ALREADY_INITED

When initializing a software smartcard, vcard_emul_init() can
report success, error, or indicate that initialization has already
been done. In this last case, we would assume that an error occurred
instead of behaving as if the initialization succeeded.

vcard_emul_init() can end up being called multiple time if the
smartcard channel gets destroyed and recreated during the lifetime
of the application

Fixes rhbz#815639
smartcard: Only init manager once

The SpiceSmartcardManager is a singleton, so it does not make
a lot of sense to try to init it multiple times. This commit adds
a GOnce to ensure the manager is only init'ed once.
session: copy "ca" property in copy ctor

This fixes the GSpice-WARNING **: no cert loaded, when doing a seamless
migration (when using the "ca" property).
usb-widget: fix gtk2 Python bindings

The Python bindings generator failed to bind the USB widget, because of
the object/class declaration. The declaration was circumventing the
deprecated errors when compiling with GTK_DISABLE_DEPRECATED. We used
to need that because of broken gtk+ headers, but it is no longer
necessary since 15bd7ceba1434b5d710bfd16078044f30693467b.
usb-device-manager: fix compilation error when usbredir is disabled
Only use GOBJECT_INTROSPECTION_CHECK when available

Current el6 systems don't have gobject-introspection packages,
so the GOBJECT_INTROSPECTION_CHECK m4 macro is not available
on such systems. This makes it difficult to run autogen.sh
on these systems.
This commit uses m4_ifdef to check if this macro is available
before trying to use it, and makes sure introspection is
disabled when GOBJECT_INTROSPECTION_CHECK could not be found.
This allows to compile spice-gtk from git on el6 systems
with:
./autogen.sh --with-gtk=2.0 --disable-gtk-doc --disable-vala
             --disable-controller --disable-werror
glib-compat: g_slist_free_full: pass the right ptr to destroy (rhbz#997893)

The destroy function passed to g_slist_free_full should be passed the elements
data pointer, not the element itself.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Use g_slist_foreach_full glib implementation

For the compat case (glib < 2.28), we were using our own implementation
instead of directly reusing glib code.
win usb: request for driver uninstall only for driver that were installed

Currently when spice_usb_device_manager_remove_dev() is called,
for windows clients a request to uninstall the driver is sent to usbclerk.

This cause problems when 2 instances (A and B) of the client are running:
- Both A and B get notified about a new USB device when it's plugged in
- A is requested to usbredir the USB device.
- A requests usbclerk to install WinUSB driver for that device.
- usbclerk starts installing the driver
- Windows sends to both A and B - device removal events, which may cause
  B to call spice_usb_device_manager_remove_dev.
- usbclerk completes installing the driver and reply to A
- B requests usbclerk to remove the WinUSB driver for that device.

To prevent that, spice-gtk now requests usbclerk to remove the driver
only if it was the instance that requested the driver to be installed.
This is done with the help of a new device SPICE_USB_DEVICE_STATE_INSTALLED
state.

rhbz#919166
win-usb-dev: ignore devices with addr 1 for LIBUSBX_API_VERSION

Starting libusbx version 1.0.13 (commit 8cd30bb7066f785ee78cf6c3dccafdbc4b957b50)
windows device enumeration changed and root hubs address number is 1 intead
of 0xff.

This patch uses LIBUSBX_API_VERSION which was introduced after 1.0.13 release
(commit 9d368fc4774344d81ab02840f3a8478301bfb6fa).
gtk: remove dead code
Revert "channel-main: Convert text line-endings if necessary (rhbz#752350)"

This implementation assumes that the toolkit doesn't do any conversion
on its own. This is actually not the case, gtk+ converts line endings
already on windows.  It would be pretty ugly to do conversions back and
forth at different levels. So the channel implementation shouldn't
try to do conversion, and implementation must be done at higher level,
where the actual system clipboard implementation is known (at
gtk-session for instance)

Since this code hasn't been officially released, let's revert it and
implement a better crlf conversion handling in gtk-session in the
following commits.

This reverts commit e45a446a9981ad4adaeff9c885962a8c6140333e.
util: add unix2dos and dos2unix

Convert line endings from/to LF/CRLF.
gtk: handle clipboard CRLF conversion

gtk+ internal text/utf8 is using LF conversion, on all platforms.
Even though the toolkit may only handle a single line ending type, we
may want to avoid the conversion for Spice use cases, gtk+ could learn a
new native utf8 target type, see also:
https://bugzilla.gnome.org/show_bug.cgi?id=706657

In the meantime, the only thing we need to convert, is to/from crlf
guest (from/to lf). This is what this change is about.

It has been tested successfully with the various guest/client OS
combinations.