# -*- coding: utf-8 -*-
# This file has been autogenerated by the pywayland scanner

# Copyright © 2008-2011 Kristian Høgsberg
# Copyright © 2010-2011 Intel Corporation
# Copyright © 2012-2013 Collabora, Ltd.
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice (including the
# next paragraph) shall be included in all copies or substantial
# portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from pywayland.interface import Interface


class DataSource(Interface):
    """Offer to transfer data

    The :class:`DataSource` object is the source side of a
    :class:`~pywayland.protocol.wayland.dataoffer.DataOffer`. It is created by
    the source client in a data transfer and provides a way to describe the
    offered data and a way to respond to requests to transfer the data.
    """
    name = "wl_data_source"
    version = 1


@DataSource.request("s", [None])
def offer(self, mime_type):
    """Add an offered mime type

    This request adds a mime type to the set of mime types advertised to
    targets.  Can be called several times to offer multiple types.

    :param mime_type:
    :type mime_type: `string`
    """
    self._marshal(0, mime_type)


@DataSource.request("", [])
def destroy(self):
    """Destroy the data source

    Destroy the data source.
    """
    self._marshal(1)
    self._destroy()


@DataSource.event("?s", [None])
def target(self, mime_type):
    """A target accepts an offered mime type

    Sent when a target accepts pointer_focus or motion events.  If a target
    does not accept any of the offered types, type is NULL.

    Used for feedback during drag-and-drop.

    :param mime_type:
    :type mime_type: `string` or `None`
    """
    self._post_event(0, mime_type)


@DataSource.event("sh", [None, None])
def send(self, mime_type, fd):
    """Send the data

    Request for data from the client.  Send the data as the specified mime type
    over the passed file descriptor, then close it.

    :param mime_type:
    :type mime_type: `string`
    :param fd:
    :type fd: `fd`
    """
    self._post_event(1, mime_type, fd)


@DataSource.event("", [])
def cancelled(self):
    """Selection was cancelled

    This data source has been replaced by another data source. The client
    should clean up and destroy this data source.
    """
    self._post_event(2)


DataSource._gen_c()
