project.rs 12.9 KB
Newer Older
1 2 3 4
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

5
use ges_sys;
6
use glib;
7
use glib::object::Cast;
8
use glib::object::IsA;
9
use glib::signal::connect_raw;
10
use glib::signal::SignalHandlerId;
11
use glib::translate::*;
12
use glib::GString;
13
use glib_sys;
14 15 16 17 18
use gst_pbutils;
use libc;
use std::boxed::Box as Box_;
use std::mem::transmute;
use std::ptr;
19 20
use Asset;
use Timeline;
21 22

glib_wrapper! {
23
    pub struct Project(Object<ges_sys::GESProject, ges_sys::GESProjectClass, ProjectClass>) @extends Asset;
24 25

    match fn {
26
        get_type => || ges_sys::ges_project_get_type(),
27 28 29 30
    }
}

impl Project {
31
    pub fn new(uri: Option<&str>) -> Project {
32
        assert_initialized_main_thread!();
33
        unsafe { from_glib_full(ges_sys::ges_project_new(uri.to_glib_none().0)) }
34 35 36
    }
}

37 38
pub const NONE_PROJECT: Option<&Project> = None;

39
pub trait ProjectExt: 'static {
40 41
    fn add_asset<P: IsA<Asset>>(&self, asset: &P) -> bool;

42 43 44 45
    fn add_encoding_profile<P: IsA<gst_pbutils::EncodingProfile>>(
        &self,
        profile: &P,
    ) -> Result<(), glib::error::BoolError>;
46

47
    fn create_asset(&self, id: Option<&str>, extractable_type: glib::types::Type) -> bool;
48

49 50 51 52
    fn create_asset_sync(
        &self,
        id: Option<&str>,
        extractable_type: glib::types::Type,
Guillaume Gomez's avatar
Guillaume Gomez committed
53
    ) -> Result<Option<Asset>, glib::Error>;
54 55 56 57 58

    fn get_asset(&self, id: &str, extractable_type: glib::types::Type) -> Option<Asset>;

    fn get_loading_assets(&self) -> Vec<Asset>;

59
    fn get_uri(&self) -> Option<GString>;
60 61 62 63 64

    fn list_assets(&self, filter: glib::types::Type) -> Vec<Asset>;

    fn list_encoding_profiles(&self) -> Vec<gst_pbutils::EncodingProfile>;

Guillaume Gomez's avatar
Guillaume Gomez committed
65
    fn load<P: IsA<Timeline>>(&self, timeline: &P) -> Result<(), glib::Error>;
66

67
    fn remove_asset<P: IsA<Asset>>(&self, asset: &P) -> Result<(), glib::error::BoolError>;
68

69 70 71 72 73 74
    fn save<P: IsA<Timeline>, Q: IsA<Asset>>(
        &self,
        timeline: &P,
        uri: &str,
        formatter_asset: Option<&Q>,
        overwrite: bool,
Guillaume Gomez's avatar
Guillaume Gomez committed
75
    ) -> Result<(), glib::Error>;
76 77 78 79 80 81 82

    fn connect_asset_added<F: Fn(&Self, &Asset) + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_asset_loading<F: Fn(&Self, &Asset) + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_asset_removed<F: Fn(&Self, &Asset) + 'static>(&self, f: F) -> SignalHandlerId;

Guillaume Gomez's avatar
Guillaume Gomez committed
83
    fn connect_error_loading_asset<F: Fn(&Self, &glib::Error, &str, glib::types::Type) + 'static>(
84 85 86
        &self,
        f: F,
    ) -> SignalHandlerId;
87 88 89

    fn connect_loaded<F: Fn(&Self, &Timeline) + 'static>(&self, f: F) -> SignalHandlerId;

Guillaume Gomez's avatar
Guillaume Gomez committed
90
    fn connect_missing_uri<F: Fn(&Self, &glib::Error, &Asset) -> Option<GString> + 'static>(
91 92 93
        &self,
        f: F,
    ) -> SignalHandlerId;
94 95
}

96
impl<O: IsA<Project>> ProjectExt for O {
97 98
    fn add_asset<P: IsA<Asset>>(&self, asset: &P) -> bool {
        unsafe {
99 100 101 102
            from_glib(ges_sys::ges_project_add_asset(
                self.as_ref().to_glib_none().0,
                asset.as_ref().to_glib_none().0,
            ))
103 104 105
        }
    }

106 107 108 109
    fn add_encoding_profile<P: IsA<gst_pbutils::EncodingProfile>>(
        &self,
        profile: &P,
    ) -> Result<(), glib::error::BoolError> {
110
        unsafe {
111 112 113 114 115 116 117
            glib_result_from_gboolean!(
                ges_sys::ges_project_add_encoding_profile(
                    self.as_ref().to_glib_none().0,
                    profile.as_ref().to_glib_none().0
                ),
                "Failed to add profile"
            )
118 119 120
        }
    }

121
    fn create_asset(&self, id: Option<&str>, extractable_type: glib::types::Type) -> bool {
122
        unsafe {
123 124 125 126 127
            from_glib(ges_sys::ges_project_create_asset(
                self.as_ref().to_glib_none().0,
                id.to_glib_none().0,
                extractable_type.to_glib(),
            ))
128 129 130
        }
    }

131 132 133 134
    fn create_asset_sync(
        &self,
        id: Option<&str>,
        extractable_type: glib::types::Type,
Guillaume Gomez's avatar
Guillaume Gomez committed
135
    ) -> Result<Option<Asset>, glib::Error> {
136 137
        unsafe {
            let mut error = ptr::null_mut();
138 139 140 141 142 143 144 145 146 147 148
            let ret = ges_sys::ges_project_create_asset_sync(
                self.as_ref().to_glib_none().0,
                id.to_glib_none().0,
                extractable_type.to_glib(),
                &mut error,
            );
            if error.is_null() {
                Ok(from_glib_full(ret))
            } else {
                Err(from_glib_full(error))
            }
149 150 151 152 153
        }
    }

    fn get_asset(&self, id: &str, extractable_type: glib::types::Type) -> Option<Asset> {
        unsafe {
154 155 156 157 158
            from_glib_full(ges_sys::ges_project_get_asset(
                self.as_ref().to_glib_none().0,
                id.to_glib_none().0,
                extractable_type.to_glib(),
            ))
159 160 161 162 163
        }
    }

    fn get_loading_assets(&self) -> Vec<Asset> {
        unsafe {
164 165 166
            FromGlibPtrContainer::from_glib_full(ges_sys::ges_project_get_loading_assets(
                self.as_ref().to_glib_none().0,
            ))
167 168 169
        }
    }

170
    fn get_uri(&self) -> Option<GString> {
171
        unsafe { from_glib_full(ges_sys::ges_project_get_uri(self.as_ref().to_glib_none().0)) }
172 173 174 175
    }

    fn list_assets(&self, filter: glib::types::Type) -> Vec<Asset> {
        unsafe {
176 177 178 179
            FromGlibPtrContainer::from_glib_full(ges_sys::ges_project_list_assets(
                self.as_ref().to_glib_none().0,
                filter.to_glib(),
            ))
180 181 182 183 184
        }
    }

    fn list_encoding_profiles(&self) -> Vec<gst_pbutils::EncodingProfile> {
        unsafe {
185 186 187
            FromGlibPtrContainer::from_glib_none(ges_sys::ges_project_list_encoding_profiles(
                self.as_ref().to_glib_none().0,
            ))
188 189 190
        }
    }

Guillaume Gomez's avatar
Guillaume Gomez committed
191
    fn load<P: IsA<Timeline>>(&self, timeline: &P) -> Result<(), glib::Error> {
192 193
        unsafe {
            let mut error = ptr::null_mut();
194 195 196 197 198 199 200 201 202 203
            let _ = ges_sys::ges_project_load(
                self.as_ref().to_glib_none().0,
                timeline.as_ref().to_glib_none().0,
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
204 205 206
        }
    }

207
    fn remove_asset<P: IsA<Asset>>(&self, asset: &P) -> Result<(), glib::error::BoolError> {
208
        unsafe {
209 210 211 212 213 214 215
            glib_result_from_gboolean!(
                ges_sys::ges_project_remove_asset(
                    self.as_ref().to_glib_none().0,
                    asset.as_ref().to_glib_none().0
                ),
                "Failed to remove asset"
            )
216 217 218
        }
    }

219 220 221 222 223 224
    fn save<P: IsA<Timeline>, Q: IsA<Asset>>(
        &self,
        timeline: &P,
        uri: &str,
        formatter_asset: Option<&Q>,
        overwrite: bool,
Guillaume Gomez's avatar
Guillaume Gomez committed
225
    ) -> Result<(), glib::Error> {
226 227
        unsafe {
            let mut error = ptr::null_mut();
228 229 230 231 232 233 234 235 236 237 238 239 240
            let _ = ges_sys::ges_project_save(
                self.as_ref().to_glib_none().0,
                timeline.as_ref().to_glib_none().0,
                uri.to_glib_none().0,
                formatter_asset.map(|p| p.as_ref()).to_glib_none().0,
                overwrite.to_glib(),
                &mut error,
            );
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
241 242 243 244
        }
    }

    fn connect_asset_added<F: Fn(&Self, &Asset) + 'static>(&self, f: F) -> SignalHandlerId {
245 246 247 248 249 250
        unsafe extern "C" fn asset_added_trampoline<P, F: Fn(&P, &Asset) + 'static>(
            this: *mut ges_sys::GESProject,
            asset: *mut ges_sys::GESAsset,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Project>,
Sebastian Dröge's avatar
Sebastian Dröge committed
251 252
        {
            let f: &F = &*(f as *const F);
253 254 255 256
            f(
                &Project::from_glib_borrow(this).unsafe_cast(),
                &from_glib_borrow(asset),
            )
Sebastian Dröge's avatar
Sebastian Dröge committed
257
        }
258
        unsafe {
Sebastian Dröge's avatar
Sebastian Dröge committed
259
            let f: Box_<F> = Box_::new(f);
260 261 262 263 264 265
            connect_raw(
                self.as_ptr() as *mut _,
                b"asset-added\0".as_ptr() as *const _,
                Some(transmute(asset_added_trampoline::<Self, F> as usize)),
                Box_::into_raw(f),
            )
266 267 268 269
        }
    }

    fn connect_asset_loading<F: Fn(&Self, &Asset) + 'static>(&self, f: F) -> SignalHandlerId {
270 271 272 273 274 275
        unsafe extern "C" fn asset_loading_trampoline<P, F: Fn(&P, &Asset) + 'static>(
            this: *mut ges_sys::GESProject,
            asset: *mut ges_sys::GESAsset,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Project>,
Sebastian Dröge's avatar
Sebastian Dröge committed
276 277
        {
            let f: &F = &*(f as *const F);
278 279 280 281
            f(
                &Project::from_glib_borrow(this).unsafe_cast(),
                &from_glib_borrow(asset),
            )
Sebastian Dröge's avatar
Sebastian Dröge committed
282
        }
283
        unsafe {
Sebastian Dröge's avatar
Sebastian Dröge committed
284
            let f: Box_<F> = Box_::new(f);
285 286 287 288 289 290
            connect_raw(
                self.as_ptr() as *mut _,
                b"asset-loading\0".as_ptr() as *const _,
                Some(transmute(asset_loading_trampoline::<Self, F> as usize)),
                Box_::into_raw(f),
            )
291 292 293 294
        }
    }

    fn connect_asset_removed<F: Fn(&Self, &Asset) + 'static>(&self, f: F) -> SignalHandlerId {
295 296 297 298 299 300
        unsafe extern "C" fn asset_removed_trampoline<P, F: Fn(&P, &Asset) + 'static>(
            this: *mut ges_sys::GESProject,
            asset: *mut ges_sys::GESAsset,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Project>,
Sebastian Dröge's avatar
Sebastian Dröge committed
301 302
        {
            let f: &F = &*(f as *const F);
303 304 305 306
            f(
                &Project::from_glib_borrow(this).unsafe_cast(),
                &from_glib_borrow(asset),
            )
Sebastian Dröge's avatar
Sebastian Dröge committed
307
        }
308
        unsafe {
Sebastian Dröge's avatar
Sebastian Dröge committed
309
            let f: Box_<F> = Box_::new(f);
310 311 312 313 314 315
            connect_raw(
                self.as_ptr() as *mut _,
                b"asset-removed\0".as_ptr() as *const _,
                Some(transmute(asset_removed_trampoline::<Self, F> as usize)),
                Box_::into_raw(f),
            )
316 317 318
        }
    }

Guillaume Gomez's avatar
Guillaume Gomez committed
319 320 321
    fn connect_error_loading_asset<
        F: Fn(&Self, &glib::Error, &str, glib::types::Type) + 'static,
    >(
322 323 324 325 326
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn error_loading_asset_trampoline<
            P,
Guillaume Gomez's avatar
Guillaume Gomez committed
327
            F: Fn(&P, &glib::Error, &str, glib::types::Type) + 'static,
328 329 330 331 332 333 334 335
        >(
            this: *mut ges_sys::GESProject,
            error: *mut glib_sys::GError,
            id: *mut libc::c_char,
            extractable_type: glib_sys::GType,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Project>,
Sebastian Dröge's avatar
Sebastian Dröge committed
336 337
        {
            let f: &F = &*(f as *const F);
338 339 340 341 342 343
            f(
                &Project::from_glib_borrow(this).unsafe_cast(),
                &from_glib_borrow(error),
                &GString::from_glib_borrow(id),
                from_glib(extractable_type),
            )
Sebastian Dröge's avatar
Sebastian Dröge committed
344
        }
345
        unsafe {
Sebastian Dröge's avatar
Sebastian Dröge committed
346
            let f: Box_<F> = Box_::new(f);
347 348 349 350 351 352 353 354
            connect_raw(
                self.as_ptr() as *mut _,
                b"error-loading-asset\0".as_ptr() as *const _,
                Some(transmute(
                    error_loading_asset_trampoline::<Self, F> as usize,
                )),
                Box_::into_raw(f),
            )
355 356 357 358
        }
    }

    fn connect_loaded<F: Fn(&Self, &Timeline) + 'static>(&self, f: F) -> SignalHandlerId {
359 360 361 362 363 364
        unsafe extern "C" fn loaded_trampoline<P, F: Fn(&P, &Timeline) + 'static>(
            this: *mut ges_sys::GESProject,
            timeline: *mut ges_sys::GESTimeline,
            f: glib_sys::gpointer,
        ) where
            P: IsA<Project>,
Sebastian Dröge's avatar
Sebastian Dröge committed
365 366
        {
            let f: &F = &*(f as *const F);
367 368 369 370
            f(
                &Project::from_glib_borrow(this).unsafe_cast(),
                &from_glib_borrow(timeline),
            )
Sebastian Dröge's avatar
Sebastian Dröge committed
371
        }
372
        unsafe {
Sebastian Dröge's avatar
Sebastian Dröge committed
373
            let f: Box_<F> = Box_::new(f);
374 375 376 377 378 379
            connect_raw(
                self.as_ptr() as *mut _,
                b"loaded\0".as_ptr() as *const _,
                Some(transmute(loaded_trampoline::<Self, F> as usize)),
                Box_::into_raw(f),
            )
380 381 382
        }
    }

Guillaume Gomez's avatar
Guillaume Gomez committed
383
    fn connect_missing_uri<F: Fn(&Self, &glib::Error, &Asset) -> Option<GString> + 'static>(
384 385 386 387 388
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn missing_uri_trampoline<
            P,
Guillaume Gomez's avatar
Guillaume Gomez committed
389
            F: Fn(&P, &glib::Error, &Asset) -> Option<GString> + 'static,
390 391 392 393 394 395 396 397
        >(
            this: *mut ges_sys::GESProject,
            error: *mut glib_sys::GError,
            wrong_asset: *mut ges_sys::GESAsset,
            f: glib_sys::gpointer,
        ) -> *mut libc::c_char
        where
            P: IsA<Project>,
Sebastian Dröge's avatar
Sebastian Dröge committed
398 399
        {
            let f: &F = &*(f as *const F);
400 401 402 403 404 405
            f(
                &Project::from_glib_borrow(this).unsafe_cast(),
                &from_glib_borrow(error),
                &from_glib_borrow(wrong_asset),
            )
            .to_glib_full()
Sebastian Dröge's avatar
Sebastian Dröge committed
406
        }
407
        unsafe {
Sebastian Dröge's avatar
Sebastian Dröge committed
408
            let f: Box_<F> = Box_::new(f);
409 410 411 412 413 414
            connect_raw(
                self.as_ptr() as *mut _,
                b"missing-uri\0".as_ptr() as *const _,
                Some(transmute(missing_uri_trampoline::<Self, F> as usize)),
                Box_::into_raw(f),
            )
415 416 417
        }
    }
}