1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT

use crate::Asset;
use glib::object::IsA;
use glib::translate::*;

glib::wrapper! {
    /// A [`crate::glib::object::Object`] that implements the [`crate::Extractable`] interface can be
    /// extracted from a [`crate::Asset`] using [`crate::prelude::AssetExt::extract()`].
    ///
    /// Each extractable type will have its own way of interpreting the
    /// [`crate::Asset:id`] of an asset (or, if it is associated with a specific
    /// subclass of [`crate::Asset`], the asset subclass may handle the
    /// interpretation of the [`crate::Asset:id`]). By default, the requested asset
    /// [`crate::Asset:id`] will be ignored by a [`crate::Extractable`] and will be set to
    /// the type name of the extractable instead. Also by default, when the
    /// requested asset is extracted, the returned object will simply be a
    /// newly created default object of that extractable type. You should check
    /// the documentation for each extractable type to see if they differ from
    /// the default.
    ///
    /// After the object is extracted, it will have a reference to the asset it
    /// came from, which you can retrieve using [`Self::get_asset()`].
    ///
    /// # Implements
    ///
    /// [`trait@crate::prelude::ExtractableExt`], [`trait@glib::object::ObjectExt`]
    pub struct Extractable(Interface<ffi::GESExtractable, ffi::GESExtractableInterface>);

    match fn {
        type_ => || ffi::ges_extractable_get_type(),
    }
}

pub const NONE_EXTRACTABLE: Option<&Extractable> = None;

/// Trait containing all `Extractable` methods.
///
/// # Implementors
///
/// [`struct@crate::BaseEffect`], [`struct@crate::BaseTransitionClip`], [`struct@crate::Clip`], [`struct@crate::Container`], [`struct@crate::Effect`], [`struct@crate::Extractable`], [`struct@crate::Group`], [`struct@crate::Layer`], [`struct@crate::OperationClip`], [`struct@crate::TimelineElement`], [`struct@crate::Timeline`], [`struct@crate::TrackElement`], [`struct@crate::TransitionClip`], [`struct@crate::UriClip`]
pub trait ExtractableExt: 'static {
    /// Get the asset that has been set on the extractable object.
    ///
    /// # Returns
    ///
    /// The asset set on `self`, or [`None`]
    /// if no asset has been set.
    #[doc(alias = "ges_extractable_get_asset")]
    #[doc(alias = "get_asset")]
    fn asset(&self) -> Option<Asset>;

    /// Gets the [`crate::Asset:id`] of some associated asset. It may be the case
    /// that the object has no set asset, or even that such an asset does not
    /// yet exist in the GES cache. Instead, this will return the asset
    /// [`crate::Asset:id`] that is _compatible_ with the current state of the object,
    /// as determined by the [`crate::Extractable`] implementer. If it was indeed
    /// extracted from an asset, this should return the same as its
    /// corresponding asset [`crate::Asset:id`].
    ///
    /// # Returns
    ///
    /// The [`crate::Asset:id`] of some associated [`crate::Asset`]
    /// that is compatible with `self`'s current state.
    #[doc(alias = "ges_extractable_get_id")]
    #[doc(alias = "get_id")]
    fn id(&self) -> Option<glib::GString>;

    /// Sets the asset for this extractable object.
    ///
    /// When an object is extracted from an asset using [`crate::prelude::AssetExt::extract()`] its
    /// asset will be automatically set. Note that many classes that implement
    /// [`crate::Extractable`] will automatically create their objects using assets
    /// when you call their `new` methods. However, you can use this method to
    /// associate an object with a compatible asset if it was created by other
    /// means and does not yet have an asset. Or, for some implementations of
    /// [`crate::Extractable`], you can use this to change the asset of the given
    /// extractable object, which will lead to a change in its state to
    /// match the new asset [`crate::Asset:id`].
    /// ## `asset`
    /// The asset to set
    ///
    /// # Returns
    ///
    /// [`true`] if `asset` could be successfully set on `self`.
    #[doc(alias = "ges_extractable_set_asset")]
    fn set_asset<P: IsA<Asset>>(&self, asset: &P) -> Result<(), glib::error::BoolError>;
}

impl<O: IsA<Extractable>> ExtractableExt for O {
    fn asset(&self) -> Option<Asset> {
        unsafe {
            from_glib_none(ffi::ges_extractable_get_asset(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn id(&self) -> Option<glib::GString> {
        unsafe { from_glib_full(ffi::ges_extractable_get_id(self.as_ref().to_glib_none().0)) }
    }

    fn set_asset<P: IsA<Asset>>(&self, asset: &P) -> Result<(), glib::error::BoolError> {
        unsafe {
            glib::result_from_gboolean!(
                ffi::ges_extractable_set_asset(
                    self.as_ref().to_glib_none().0,
                    asset.as_ref().to_glib_none().0
                ),
                "Failed to set asset"
            )
        }
    }
}