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
86/// Trait containing all [`struct@Preset`] methods.
87///
88/// # Implementors
89///
90/// [`Preset`][struct@crate::Preset]
91pub trait PresetExt: IsA<Preset> + 'static {
92 /// Delete the given preset.
93 /// ## `name`
94 /// preset name to remove
95 ///
96 /// # Returns
97 ///
98 /// [`true`] for success, [`false`] if e.g. there is no preset with that `name`
99 #[doc(alias = "gst_preset_delete_preset")]
100 fn delete_preset(&self, name: &str) -> Result<(), glib::error::BoolError> {
101 unsafe {
102 glib::result_from_gboolean!(
103 ffi::gst_preset_delete_preset(
104 self.as_ref().to_glib_none().0,
105 name.to_glib_none().0
106 ),
107 "Failed to delete preset"
108 )
109 }
110 }
111
112 /// Gets the `value` for an existing meta data `tag`. Meta data `tag` names can be
113 /// something like e.g. "comment". Returned values need to be released when done.
114 /// ## `name`
115 /// preset name
116 /// ## `tag`
117 /// meta data item name
118 ///
119 /// # Returns
120 ///
121 /// [`true`] for success, [`false`] if e.g. there is no preset with that `name`
122 /// or no value for the given `tag`
123 ///
124 /// ## `value`
125 /// value
126 #[doc(alias = "gst_preset_get_meta")]
127 #[doc(alias = "get_meta")]
128 fn meta(&self, name: &str, tag: &str) -> Option<glib::GString> {
129 unsafe {
130 let mut value = std::ptr::null_mut();
131 let ret = from_glib(ffi::gst_preset_get_meta(
132 self.as_ref().to_glib_none().0,
133 name.to_glib_none().0,
134 tag.to_glib_none().0,
135 &mut value,
136 ));
137 if ret {
138 Some(from_glib_full(value))
139 } else {
140 None
141 }
142 }
143 }
144
145 /// Get a copy of preset names as a [`None`] terminated string array.
146 ///
147 /// # Returns
148 ///
149 ///
150 /// list with names, use `g_strfreev()` after usage.
151 #[doc(alias = "gst_preset_get_preset_names")]
152 #[doc(alias = "get_preset_names")]
153 fn preset_names(&self) -> Vec<glib::GString> {
154 unsafe {
155 FromGlibPtrContainer::from_glib_full(ffi::gst_preset_get_preset_names(
156 self.as_ref().to_glib_none().0,
157 ))
158 }
159 }
160
161 /// Get a the names of the GObject properties that can be used for presets.
162 ///
163 /// # Returns
164 ///
165 /// an
166 /// array of property names which should be freed with `g_strfreev()` after use.
167 #[doc(alias = "gst_preset_get_property_names")]
168 #[doc(alias = "get_property_names")]
169 fn property_names(&self) -> Vec<glib::GString> {
170 unsafe {
171 FromGlibPtrContainer::from_glib_full(ffi::gst_preset_get_property_names(
172 self.as_ref().to_glib_none().0,
173 ))
174 }
175 }
176
177 /// Check if one can add new presets, change existing ones and remove presets.
178 ///
179 /// # Returns
180 ///
181 /// [`true`] if presets are editable or [`false`] if they are static
182 #[doc(alias = "gst_preset_is_editable")]
183 fn is_editable(&self) -> bool {
184 unsafe { from_glib(ffi::gst_preset_is_editable(self.as_ref().to_glib_none().0)) }
185 }
186
187 /// Load the given preset.
188 /// ## `name`
189 /// preset name to load
190 ///
191 /// # Returns
192 ///
193 /// [`true`] for success, [`false`] if e.g. there is no preset with that `name`
194 #[doc(alias = "gst_preset_load_preset")]
195 fn load_preset(&self, name: &str) -> Result<(), glib::error::BoolError> {
196 unsafe {
197 glib::result_from_gboolean!(
198 ffi::gst_preset_load_preset(self.as_ref().to_glib_none().0, name.to_glib_none().0),
199 "Failed to load preset"
200 )
201 }
202 }
203
204 /// Renames a preset. If there is already a preset by the `new_name` it will be
205 /// overwritten.
206 /// ## `old_name`
207 /// current preset name
208 /// ## `new_name`
209 /// new preset name
210 ///
211 /// # Returns
212 ///
213 /// [`true`] for success, [`false`] if e.g. there is no preset with `old_name`
214 #[doc(alias = "gst_preset_rename_preset")]
215 fn rename_preset(&self, old_name: &str, new_name: &str) -> Result<(), glib::error::BoolError> {
216 unsafe {
217 glib::result_from_gboolean!(
218 ffi::gst_preset_rename_preset(
219 self.as_ref().to_glib_none().0,
220 old_name.to_glib_none().0,
221 new_name.to_glib_none().0
222 ),
223 "Failed to rename preset"
224 )
225 }
226 }
227
228 /// Save the current object settings as a preset under the given name. If there
229 /// is already a preset by this `name` it will be overwritten.
230 /// ## `name`
231 /// preset name to save
232 ///
233 /// # Returns
234 ///
235 /// [`true`] for success, [`false`]
236 #[doc(alias = "gst_preset_save_preset")]
237 fn save_preset(&self, name: &str) -> Result<(), glib::error::BoolError> {
238 unsafe {
239 glib::result_from_gboolean!(
240 ffi::gst_preset_save_preset(self.as_ref().to_glib_none().0, name.to_glib_none().0),
241 "Failed to save preset"
242 )
243 }
244 }
245
246 /// Sets a new `value` for an existing meta data item or adds a new item. Meta
247 /// data `tag` names can be something like e.g. "comment". Supplying [`None`] for the
248 /// `value` will unset an existing value.
249 /// ## `name`
250 /// preset name
251 /// ## `tag`
252 /// meta data item name
253 /// ## `value`
254 /// new value
255 ///
256 /// # Returns
257 ///
258 /// [`true`] for success, [`false`] if e.g. there is no preset with that `name`
259 #[doc(alias = "gst_preset_set_meta")]
260 fn set_meta(
261 &self,
262 name: &str,
263 tag: &str,
264 value: Option<&str>,
265 ) -> Result<(), glib::error::BoolError> {
266 unsafe {
267 glib::result_from_gboolean!(
268 ffi::gst_preset_set_meta(
269 self.as_ref().to_glib_none().0,
270 name.to_glib_none().0,
271 tag.to_glib_none().0,
272 value.to_glib_none().0
273 ),
274 "Failed to set preset meta"
275 )
276 }
277 }
278}
279
280impl<O: IsA<Preset>> PresetExt for O {}