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
// Copyright (C) 2018 Thibault Saunier <tsaunier@igalia.com>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use ges_sys;
use glib;
use glib::object::IsA;
use glib::translate::*;
use std::ptr;
use TimelineElement;

pub trait TimelineElementExtManual: 'static {
    fn get_child_property(&self, name: &str) -> Option<glib::Value>;
    fn set_child_property(
        &self,
        name: &str,
        value: &dyn glib::ToValue,
    ) -> Result<(), glib::BoolError>;
}

impl<O: IsA<TimelineElement>> TimelineElementExtManual for O {
    fn get_child_property(&self, name: &str) -> Option<glib::Value> {
        unsafe {
            let found: bool = from_glib(ges_sys::ges_timeline_element_lookup_child(
                self.as_ref().to_glib_none().0,
                name.to_glib_none().0,
                ptr::null_mut(),
                ptr::null_mut(),
            ));
            if !found {
                return None;
            }

            let mut value = glib::Value::uninitialized();
            ges_sys::ges_timeline_element_get_child_property(
                self.as_ref().to_glib_none().0,
                name.to_glib_none().0,
                value.to_glib_none_mut().0,
            );
            Some(value)
        }
    }

    fn set_child_property(
        &self,
        name: &str,
        value: &dyn glib::ToValue,
    ) -> Result<(), glib::BoolError> {
        unsafe {
            let found: bool = from_glib(ges_sys::ges_timeline_element_lookup_child(
                self.as_ref().to_glib_none().0,
                name.to_glib_none().0,
                ptr::null_mut(),
                ptr::null_mut(),
            ));
            if !found {
                return Err(glib_bool_error!("Child property not found"));
            }

            let value = value.to_value();
            ges_sys::ges_timeline_element_set_child_property(
                self.as_ref().to_glib_none().0,
                name.to_glib_none().0,
                value.to_glib_none().0,
            );

            Ok(())
        }
    }
}