Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Add missing functions for PixbufAnimation #158

Merged
merged 5 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Gir.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ generate = [
]

manual = [
"GdkPixbuf.PixbufAnimation",
"GdkPixbuf.PixbufAnimationIter",
"Gio.AsyncReadyCallback",
"Gio.Cancellable",
Expand Down Expand Up @@ -95,6 +94,14 @@ status = "generate"
# manual complex param
ignore = true

[[object]]
name = "GdkPixbuf.PixbufAnimation"
status = "generate"
[[object.function]]
name = "get_iter"
# TimeVal misses memory management functions
ignore = true

[[object]]
name = "GdkPixbuf.PixbufFormat"
status = "generate"
Expand Down
2 changes: 1 addition & 1 deletion gir-files
Submodule gir-files updated 2 files
+1 −1 GLib-2.0.gir
+1 −0 fix.sh
138 changes: 0 additions & 138 deletions src/animation.rs

This file was deleted.

5 changes: 5 additions & 0 deletions src/auto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
mod pixbuf;
pub use self::pixbuf::{Pixbuf, PixbufClass};

mod pixbuf_animation;
pub use self::pixbuf_animation::PixbufAnimationExt;
pub use self::pixbuf_animation::{PixbufAnimation, PixbufAnimationClass, NONE_PIXBUF_ANIMATION};

mod pixbuf_loader;
pub use self::pixbuf_loader::PixbufLoaderExt;
pub use self::pixbuf_loader::{PixbufLoader, PixbufLoaderClass, NONE_PIXBUF_LOADER};
Expand All @@ -24,5 +28,6 @@ pub use self::enums::PixbufRotation;

#[doc(hidden)]
pub mod traits {
pub use super::PixbufAnimationExt;
pub use super::PixbufLoaderExt;
}
176 changes: 176 additions & 0 deletions src/auto/pixbuf_animation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
// 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

use gdk_pixbuf_sys;
use gio;
use gio_sys;
use glib;
use glib::object::IsA;
use glib::translate::*;
use glib_sys;
use gobject_sys;
use std;
use std::boxed::Box as Box_;
use std::fmt;
use std::pin::Pin;
use std::ptr;
use Pixbuf;

glib_wrapper! {
pub struct PixbufAnimation(Object<gdk_pixbuf_sys::GdkPixbufAnimation, PixbufAnimationClass>);

match fn {
get_type => || gdk_pixbuf_sys::gdk_pixbuf_animation_get_type(),
}
}

impl PixbufAnimation {
pub fn from_file<P: AsRef<std::path::Path>>(
filename: P,
) -> Result<PixbufAnimation, glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let ret = gdk_pixbuf_sys::gdk_pixbuf_animation_new_from_file(
filename.as_ref().to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}

pub fn from_resource(resource_path: &str) -> Result<PixbufAnimation, glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let ret = gdk_pixbuf_sys::gdk_pixbuf_animation_new_from_resource(
resource_path.to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}

pub fn from_stream<P: IsA<gio::InputStream>, Q: IsA<gio::Cancellable>>(
stream: &P,
cancellable: Option<&Q>,
) -> Result<PixbufAnimation, glib::Error> {
unsafe {
let mut error = ptr::null_mut();
let ret = gdk_pixbuf_sys::gdk_pixbuf_animation_new_from_stream(
stream.as_ref().to_glib_none().0,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
&mut error,
);
if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
}
}
}

pub fn new_from_stream_async<
P: IsA<gio::InputStream>,
Q: IsA<gio::Cancellable>,
R: FnOnce(Result<PixbufAnimation, glib::Error>) + Send + 'static,
>(
stream: &P,
cancellable: Option<&Q>,
callback: R,
) {
let user_data: Box_<R> = Box_::new(callback);
unsafe extern "C" fn new_from_stream_async_trampoline<
R: FnOnce(Result<PixbufAnimation, glib::Error>) + Send + 'static,
>(
_source_object: *mut gobject_sys::GObject,
res: *mut gio_sys::GAsyncResult,
user_data: glib_sys::gpointer,
) {
let mut error = ptr::null_mut();
let ret = gdk_pixbuf_sys::gdk_pixbuf_animation_new_from_stream_finish(res, &mut error);
let result = if error.is_null() {
Ok(from_glib_full(ret))
} else {
Err(from_glib_full(error))
};
let callback: Box_<R> = Box_::from_raw(user_data as *mut _);
callback(result);
}
let callback = new_from_stream_async_trampoline::<R>;
unsafe {
gdk_pixbuf_sys::gdk_pixbuf_animation_new_from_stream_async(
stream.as_ref().to_glib_none().0,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
Some(callback),
Box_::into_raw(user_data) as *mut _,
);
}
}

pub fn new_from_stream_async_future<P: IsA<gio::InputStream> + Clone + 'static>(
stream: &P,
) -> Pin<Box_<dyn std::future::Future<Output = Result<PixbufAnimation, glib::Error>> + 'static>>
{
let stream = stream.clone();
Box_::pin(gio::GioFuture::new(&(), move |_obj, send| {
let cancellable = gio::Cancellable::new();
Self::new_from_stream_async(&stream, Some(&cancellable), move |res| {
send.resolve(res);
});

cancellable
}))
}
}

pub const NONE_PIXBUF_ANIMATION: Option<&PixbufAnimation> = None;

pub trait PixbufAnimationExt: 'static {
fn get_height(&self) -> i32;

fn get_static_image(&self) -> Option<Pixbuf>;

fn get_width(&self) -> i32;

fn is_static_image(&self) -> bool;
}

impl<O: IsA<PixbufAnimation>> PixbufAnimationExt for O {
fn get_height(&self) -> i32 {
unsafe { gdk_pixbuf_sys::gdk_pixbuf_animation_get_height(self.as_ref().to_glib_none().0) }
}

fn get_static_image(&self) -> Option<Pixbuf> {
unsafe {
from_glib_none(gdk_pixbuf_sys::gdk_pixbuf_animation_get_static_image(
self.as_ref().to_glib_none().0,
))
}
}

fn get_width(&self) -> i32 {
unsafe { gdk_pixbuf_sys::gdk_pixbuf_animation_get_width(self.as_ref().to_glib_none().0) }
}

fn is_static_image(&self) -> bool {
unsafe {
from_glib(gdk_pixbuf_sys::gdk_pixbuf_animation_is_static_image(
self.as_ref().to_glib_none().0,
))
}
}
}

impl fmt::Display for PixbufAnimation {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "PixbufAnimation")
}
}
4 changes: 2 additions & 2 deletions src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 60cbef0)
from gir-files (https://github.com/gtk-rs/gir-files @ 8a626fd)
Generated by gir (https://github.com/gtk-rs/gir @ ad40c01)
from gir-files (https://github.com/gtk-rs/gir-files @ cb01ad7)
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ extern crate libc;

mod auto;

mod animation;
mod pixbuf;
mod pixbuf_animation;
mod pixbuf_animation_iter;
pub mod prelude;

pub use auto::*;

pub use self::animation::{PixbufAnimation, PixbufAnimationExt, PixbufAnimationIter};
pub use self::pixbuf_animation_iter::PixbufAnimationIter;
Loading