1 // Take a look at the license at the top of the repository in the LICENSE file.
2 
3 use crate::PixbufAnimation;
4 use crate::PixbufAnimationIter;
5 use glib::object::IsA;
6 use glib::translate::*;
7 
8 use std::ptr;
9 use std::time::SystemTime;
10 
11 pub trait PixbufAnimationExtManual {
12     #[doc(alias = "gdk_pixbuf_animation_get_iter")]
13     #[doc(alias = "get_iter")]
iter(&self, start_time: Option<SystemTime>) -> PixbufAnimationIter14     fn iter(&self, start_time: Option<SystemTime>) -> PixbufAnimationIter;
15 }
16 
17 impl<T: IsA<PixbufAnimation>> PixbufAnimationExtManual for T {
iter(&self, start_time: Option<SystemTime>) -> PixbufAnimationIter18     fn iter(&self, start_time: Option<SystemTime>) -> PixbufAnimationIter {
19         let start_time = start_time.map(|s| {
20             let diff = s
21                 .duration_since(SystemTime::UNIX_EPOCH)
22                 .expect("failed to convert time");
23             glib::ffi::GTimeVal {
24                 tv_sec: diff.as_secs() as _,
25                 tv_usec: diff.subsec_micros() as _,
26             }
27         });
28 
29         unsafe {
30             from_glib_full(ffi::gdk_pixbuf_animation_get_iter(
31                 self.as_ref().to_glib_none().0,
32                 start_time
33                     .as_ref()
34                     .map(|t| t as *const glib::ffi::GTimeVal)
35                     .unwrap_or(ptr::null()),
36             ))
37         }
38     }
39 }
40