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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// 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
#![allow(deprecated)]

use crate::{ffi, Asset, Extractable, Timeline};
use glib::{prelude::*, translate::*};

glib::wrapper! {
    /// Base class for timeline data serialization and deserialization.
    ///
    /// This is an Abstract Base Class, you cannot instantiate it.
    ///
    /// # Implements
    ///
    /// [`FormatterExt`][trait@crate::prelude::FormatterExt], [`trait@glib::ObjectExt`], [`ExtractableExt`][trait@crate::prelude::ExtractableExt]
    #[doc(alias = "GESFormatter")]
    pub struct Formatter(Object<ffi::GESFormatter, ffi::GESFormatterClass>) @implements Extractable;

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

impl Formatter {
    pub const NONE: Option<&'static Formatter> = None;

    /// Checks if there is a [`Formatter`][crate::Formatter] available which can load a [`Timeline`][crate::Timeline]
    /// from the given URI.
    /// ## `uri`
    /// a `gchar` * pointing to the URI
    ///
    /// # Returns
    ///
    /// TRUE if there is a [`Formatter`][crate::Formatter] that can support the given uri
    /// or FALSE if not.
    #[doc(alias = "ges_formatter_can_load_uri")]
    pub fn can_load_uri(uri: &str) -> Result<(), glib::Error> {
        assert_initialized_main_thread!();
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::ges_formatter_can_load_uri(uri.to_glib_none().0, &mut error);
            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Returns TRUE if there is a [`Formatter`][crate::Formatter] available which can save a
    /// [`Timeline`][crate::Timeline] to the given URI.
    /// ## `uri`
    /// a `gchar` * pointing to a URI
    ///
    /// # Returns
    ///
    /// TRUE if the given `uri` is supported, else FALSE.
    #[doc(alias = "ges_formatter_can_save_uri")]
    pub fn can_save_uri(uri: &str) -> Result<(), glib::Error> {
        assert_initialized_main_thread!();
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::ges_formatter_can_save_uri(uri.to_glib_none().0, &mut error);
            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Get the default [`Asset`][crate::Asset] to use as formatter. It will return
    /// the asset for the [`Formatter`][crate::Formatter] that has the highest `rank`
    ///
    /// # Returns
    ///
    /// The [`Asset`][crate::Asset] for the formatter with highest `rank`
    #[doc(alias = "ges_formatter_get_default")]
    #[doc(alias = "get_default")]
    #[allow(clippy::should_implement_trait)]
    pub fn default() -> Asset {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(ffi::ges_formatter_get_default()) }
    }
}

mod sealed {
    pub trait Sealed {}
    impl<T: super::IsA<super::Formatter>> Sealed for T {}
}

/// Trait containing all [`struct@Formatter`] methods.
///
/// # Implementors
///
/// [`BaseXmlFormatter`][struct@crate::BaseXmlFormatter], [`CommandLineFormatter`][struct@crate::CommandLineFormatter], [`Formatter`][struct@crate::Formatter]
pub trait FormatterExt: IsA<Formatter> + sealed::Sealed + 'static {
    /// Load data from the given URI into timeline.
    ///
    /// # Deprecated since 1.18
    ///
    /// Use [`TimelineExt::load_from_uri()`][crate::prelude::TimelineExt::load_from_uri()]
    /// ## `timeline`
    /// a [`Timeline`][crate::Timeline]
    /// ## `uri`
    /// a `gchar` * pointing to a URI
    ///
    /// # Returns
    ///
    /// TRUE if the timeline data was successfully loaded from the URI,
    /// else FALSE.
    #[cfg_attr(feature = "v1_18", deprecated = "Since 1.18")]
    #[allow(deprecated)]
    #[doc(alias = "ges_formatter_load_from_uri")]
    fn load_from_uri(&self, timeline: &impl IsA<Timeline>, uri: &str) -> Result<(), glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::ges_formatter_load_from_uri(
                self.as_ref().to_glib_none().0,
                timeline.as_ref().to_glib_none().0,
                uri.to_glib_none().0,
                &mut error,
            );
            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    /// Save data from timeline to the given URI.
    ///
    /// # Deprecated since 1.18
    ///
    /// Use [`TimelineExt::save_to_uri()`][crate::prelude::TimelineExt::save_to_uri()]
    /// ## `timeline`
    /// a [`Timeline`][crate::Timeline]
    /// ## `uri`
    /// a `gchar` * pointing to a URI
    /// ## `overwrite`
    /// [`true`] to overwrite file if it exists
    ///
    /// # Returns
    ///
    /// TRUE if the timeline data was successfully saved to the URI
    /// else FALSE.
    #[cfg_attr(feature = "v1_18", deprecated = "Since 1.18")]
    #[allow(deprecated)]
    #[doc(alias = "ges_formatter_save_to_uri")]
    fn save_to_uri(
        &self,
        timeline: &impl IsA<Timeline>,
        uri: &str,
        overwrite: bool,
    ) -> Result<(), glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::ges_formatter_save_to_uri(
                self.as_ref().to_glib_none().0,
                timeline.as_ref().to_glib_none().0,
                uri.to_glib_none().0,
                overwrite.into_glib(),
                &mut error,
            );
            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }
}

impl<O: IsA<Formatter>> FormatterExt for O {}