gstreamer/auto/preset.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::ffi;
7use glib::{prelude::*, translate::*};
8
9glib::wrapper! {
10 /// This interface offers methods to query and manipulate parameter preset sets.
11 /// A preset is a bunch of property settings, together with meta data and a name.
12 /// The name of a preset serves as key for subsequent method calls to manipulate
13 /// single presets.
14 /// All instances of one type will share the list of presets. The list is created
15 /// on demand, if presets are not used, the list is not created.
16 ///
17 /// The interface comes with a default implementation that serves most plugins.
18 /// Wrapper plugins will override most methods to implement support for the
19 /// native preset format of those wrapped plugins.
20 /// One method that is useful to be overridden is [`PresetExt::property_names()`][crate::prelude::PresetExt::property_names()].
21 /// With that one can control which properties are saved and in which order.
22 /// When implementing support for read-only presets, one should set the vmethods
23 /// for [`PresetExt::save_preset()`][crate::prelude::PresetExt::save_preset()] and [`PresetExt::delete_preset()`][crate::prelude::PresetExt::delete_preset()] to [`None`].
24 /// Applications can use [`PresetExt::is_editable()`][crate::prelude::PresetExt::is_editable()] to check for that.
25 ///
26 /// The default implementation supports presets located in a system directory,
27 /// application specific directory and in the users home directory. When getting
28 /// a list of presets individual presets are read and overlaid in 1) system,
29 /// 2) application and 3) user order. Whenever an earlier entry is newer, the
30 /// later entries will be updated. Since 1.8 you can also provide extra paths
31 /// where to find presets through the GST_PRESET_PATH environment variable.
32 /// Presets found in those paths will be considered as "app presets".
33 ///
34 /// # Implements
35 ///
36 /// [`PresetExt`][trait@crate::prelude::PresetExt]
37 #[doc(alias = "GstPreset")]
38 pub struct Preset(Interface<ffi::GstPreset, ffi::GstPresetInterface>);
39
40 match fn {
41 type_ => || ffi::gst_preset_get_type(),
42 }
43}
44
45impl Preset {
46 pub const NONE: Option<&'static Preset> = None;
47
48 /// Gets the directory for application specific presets if set by the
49 /// application.
50 ///
51 /// # Returns
52 ///
53 /// the directory or [`None`], don't free or modify
54 /// the string
55 #[doc(alias = "gst_preset_get_app_dir")]
56 #[doc(alias = "get_app_dir")]
57 pub fn app_dir() -> Option<std::path::PathBuf> {
58 assert_initialized_main_thread!();
59 unsafe { from_glib_none(ffi::gst_preset_get_app_dir()) }
60 }
61
62 /// Sets an extra directory as an absolute path that should be considered when
63 /// looking for presets. Any presets in the application dir will shadow the
64 /// system presets.
65 /// ## `app_dir`
66 /// the application specific preset dir
67 ///
68 /// # Returns
69 ///
70 /// [`true`] for success, [`false`] if the dir already has been set
71 #[doc(alias = "gst_preset_set_app_dir")]
72 pub fn set_app_dir(app_dir: impl AsRef<std::path::Path>) -> Result<(), glib::error::BoolError> {
73 assert_initialized_main_thread!();
74 unsafe {
75 glib::result_from_gboolean!(
76 ffi::gst_preset_set_app_dir(app_dir.as_ref().to_glib_none().0),
77 "Failed to set app preset directory"
78 )
79 }
80 }
81}
82
83unsafe impl Send for Preset {}
84unsafe impl Sync for Preset {}
85
86mod sealed {
87 pub trait Sealed {}
88 impl<T: super::IsA<super::Preset>> Sealed for T {}
89}
90
91/// Trait containing all [`struct@Preset`] methods.
92///
93/// # Implementors
94///
95/// [`Preset`][struct@crate::Preset]
96pub trait PresetExt: IsA<Preset> + sealed::Sealed + 'static {
97 /// Delete the given preset.
98 /// ## `name`
99 /// preset name to remove
100 ///
101 /// # Returns
102 ///
103 /// [`true`] for success, [`false`] if e.g. there is no preset with that `name`
104 #[doc(alias = "gst_preset_delete_preset")]
105 fn delete_preset(&self, name: &str) -> Result<(), glib::error::BoolError> {
106 unsafe {
107 glib::result_from_gboolean!(
108 ffi::gst_preset_delete_preset(
109 self.as_ref().to_glib_none().0,
110 name.to_glib_none().0
111 ),
112 "Failed to delete preset"
113 )
114 }
115 }
116
117 /// Gets the `value` for an existing meta data `tag`. Meta data `tag` names can be
118 /// something like e.g. "comment". Returned values need to be released when done.
119 /// ## `name`
120 /// preset name
121 /// ## `tag`
122 /// meta data item name
123 ///
124 /// # Returns
125 ///
126 /// [`true`] for success, [`false`] if e.g. there is no preset with that `name`
127 /// or no value for the given `tag`
128 ///
129 /// ## `value`
130 /// value
131 #[doc(alias = "gst_preset_get_meta")]
132 #[doc(alias = "get_meta")]
133 fn meta(&self, name: &str, tag: &str) -> Option<glib::GString> {
134 unsafe {
135 let mut value = std::ptr::null_mut();
136 let ret = from_glib(ffi::gst_preset_get_meta(
137 self.as_ref().to_glib_none().0,
138 name.to_glib_none().0,
139 tag.to_glib_none().0,
140 &mut value,
141 ));
142 if ret {
143 Some(from_glib_full(value))
144 } else {
145 None
146 }
147 }
148 }
149
150 /// Get a copy of preset names as a [`None`] terminated string array.
151 ///
152 /// # Returns
153 ///
154 ///
155 /// list with names, use `g_strfreev()` after usage.
156 #[doc(alias = "gst_preset_get_preset_names")]
157 #[doc(alias = "get_preset_names")]
158 fn preset_names(&self) -> Vec<glib::GString> {
159 unsafe {
160 FromGlibPtrContainer::from_glib_full(ffi::gst_preset_get_preset_names(
161 self.as_ref().to_glib_none().0,
162 ))
163 }
164 }
165
166 /// Get a the names of the GObject properties that can be used for presets.
167 ///
168 /// # Returns
169 ///
170 /// an
171 /// array of property names which should be freed with `g_strfreev()` after use.
172 #[doc(alias = "gst_preset_get_property_names")]
173 #[doc(alias = "get_property_names")]
174 fn property_names(&self) -> Vec<glib::GString> {
175 unsafe {
176 FromGlibPtrContainer::from_glib_full(ffi::gst_preset_get_property_names(
177 self.as_ref().to_glib_none().0,
178 ))
179 }
180 }
181
182 /// Check if one can add new presets, change existing ones and remove presets.
183 ///
184 /// # Returns
185 ///
186 /// [`true`] if presets are editable or [`false`] if they are static
187 #[doc(alias = "gst_preset_is_editable")]
188 fn is_editable(&self) -> bool {
189 unsafe { from_glib(ffi::gst_preset_is_editable(self.as_ref().to_glib_none().0)) }
190 }
191
192 /// Load the given preset.
193 /// ## `name`
194 /// preset name to load
195 ///
196 /// # Returns
197 ///
198 /// [`true`] for success, [`false`] if e.g. there is no preset with that `name`
199 #[doc(alias = "gst_preset_load_preset")]
200 fn load_preset(&self, name: &str) -> Result<(), glib::error::BoolError> {
201 unsafe {
202 glib::result_from_gboolean!(
203 ffi::gst_preset_load_preset(self.as_ref().to_glib_none().0, name.to_glib_none().0),
204 "Failed to load preset"
205 )
206 }
207 }
208
209 /// Renames a preset. If there is already a preset by the `new_name` it will be
210 /// overwritten.
211 /// ## `old_name`
212 /// current preset name
213 /// ## `new_name`
214 /// new preset name
215 ///
216 /// # Returns
217 ///
218 /// [`true`] for success, [`false`] if e.g. there is no preset with `old_name`
219 #[doc(alias = "gst_preset_rename_preset")]
220 fn rename_preset(&self, old_name: &str, new_name: &str) -> Result<(), glib::error::BoolError> {
221 unsafe {
222 glib::result_from_gboolean!(
223 ffi::gst_preset_rename_preset(
224 self.as_ref().to_glib_none().0,
225 old_name.to_glib_none().0,
226 new_name.to_glib_none().0
227 ),
228 "Failed to rename preset"
229 )
230 }
231 }
232
233 /// Save the current object settings as a preset under the given name. If there
234 /// is already a preset by this `name` it will be overwritten.
235 /// ## `name`
236 /// preset name to save
237 ///
238 /// # Returns
239 ///
240 /// [`true`] for success, [`false`]
241 #[doc(alias = "gst_preset_save_preset")]
242 fn save_preset(&self, name: &str) -> Result<(), glib::error::BoolError> {
243 unsafe {
244 glib::result_from_gboolean!(
245 ffi::gst_preset_save_preset(self.as_ref().to_glib_none().0, name.to_glib_none().0),
246 "Failed to save preset"
247 )
248 }
249 }
250
251 /// Sets a new `value` for an existing meta data item or adds a new item. Meta
252 /// data `tag` names can be something like e.g. "comment". Supplying [`None`] for the
253 /// `value` will unset an existing value.
254 /// ## `name`
255 /// preset name
256 /// ## `tag`
257 /// meta data item name
258 /// ## `value`
259 /// new value
260 ///
261 /// # Returns
262 ///
263 /// [`true`] for success, [`false`] if e.g. there is no preset with that `name`
264 #[doc(alias = "gst_preset_set_meta")]
265 fn set_meta(
266 &self,
267 name: &str,
268 tag: &str,
269 value: Option<&str>,
270 ) -> Result<(), glib::error::BoolError> {
271 unsafe {
272 glib::result_from_gboolean!(
273 ffi::gst_preset_set_meta(
274 self.as_ref().to_glib_none().0,
275 name.to_glib_none().0,
276 tag.to_glib_none().0,
277 value.to_glib_none().0
278 ),
279 "Failed to set preset meta"
280 )
281 }
282 }
283}
284
285impl<O: IsA<Preset>> PresetExt for O {}