[go: up one dir, main page]

gtk4/auto/
media_file.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// DO NOT EDIT
4
5use crate::{ffi, MediaStream};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    #[doc(alias = "GtkMediaFile")]
15    pub struct MediaFile(Object<ffi::GtkMediaFile, ffi::GtkMediaFileClass>) @extends MediaStream, @implements gdk::Paintable;
16
17    match fn {
18        type_ => || ffi::gtk_media_file_get_type(),
19    }
20}
21
22impl MediaFile {
23    pub const NONE: Option<&'static MediaFile> = None;
24
25    #[doc(alias = "gtk_media_file_new")]
26    pub fn new() -> MediaFile {
27        assert_initialized_main_thread!();
28        unsafe { from_glib_full(ffi::gtk_media_file_new()) }
29    }
30
31    #[doc(alias = "gtk_media_file_new_for_file")]
32    #[doc(alias = "new_for_file")]
33    pub fn for_file(file: &impl IsA<gio::File>) -> MediaFile {
34        assert_initialized_main_thread!();
35        unsafe {
36            from_glib_full(ffi::gtk_media_file_new_for_file(
37                file.as_ref().to_glib_none().0,
38            ))
39        }
40    }
41
42    #[doc(alias = "gtk_media_file_new_for_filename")]
43    #[doc(alias = "new_for_filename")]
44    pub fn for_filename(filename: impl AsRef<std::path::Path>) -> MediaFile {
45        assert_initialized_main_thread!();
46        unsafe {
47            from_glib_full(ffi::gtk_media_file_new_for_filename(
48                filename.as_ref().to_glib_none().0,
49            ))
50        }
51    }
52
53    #[doc(alias = "gtk_media_file_new_for_input_stream")]
54    #[doc(alias = "new_for_input_stream")]
55    pub fn for_input_stream(stream: &impl IsA<gio::InputStream>) -> MediaFile {
56        assert_initialized_main_thread!();
57        unsafe {
58            from_glib_full(ffi::gtk_media_file_new_for_input_stream(
59                stream.as_ref().to_glib_none().0,
60            ))
61        }
62    }
63
64    #[doc(alias = "gtk_media_file_new_for_resource")]
65    #[doc(alias = "new_for_resource")]
66    pub fn for_resource(resource_path: &str) -> MediaFile {
67        assert_initialized_main_thread!();
68        unsafe {
69            from_glib_full(ffi::gtk_media_file_new_for_resource(
70                resource_path.to_glib_none().0,
71            ))
72        }
73    }
74}
75
76impl Default for MediaFile {
77    fn default() -> Self {
78        Self::new()
79    }
80}
81
82pub trait MediaFileExt: IsA<MediaFile> + 'static {
83    #[doc(alias = "gtk_media_file_clear")]
84    fn clear(&self) {
85        unsafe {
86            ffi::gtk_media_file_clear(self.as_ref().to_glib_none().0);
87        }
88    }
89
90    #[doc(alias = "gtk_media_file_get_file")]
91    #[doc(alias = "get_file")]
92    fn file(&self) -> Option<gio::File> {
93        unsafe { from_glib_none(ffi::gtk_media_file_get_file(self.as_ref().to_glib_none().0)) }
94    }
95
96    #[doc(alias = "gtk_media_file_get_input_stream")]
97    #[doc(alias = "get_input_stream")]
98    #[doc(alias = "input-stream")]
99    fn input_stream(&self) -> Option<gio::InputStream> {
100        unsafe {
101            from_glib_none(ffi::gtk_media_file_get_input_stream(
102                self.as_ref().to_glib_none().0,
103            ))
104        }
105    }
106
107    #[doc(alias = "gtk_media_file_set_file")]
108    #[doc(alias = "file")]
109    fn set_file(&self, file: Option<&impl IsA<gio::File>>) {
110        unsafe {
111            ffi::gtk_media_file_set_file(
112                self.as_ref().to_glib_none().0,
113                file.map(|p| p.as_ref()).to_glib_none().0,
114            );
115        }
116    }
117
118    #[doc(alias = "gtk_media_file_set_filename")]
119    fn set_filename(&self, filename: Option<impl AsRef<std::path::Path>>) {
120        unsafe {
121            ffi::gtk_media_file_set_filename(
122                self.as_ref().to_glib_none().0,
123                filename.as_ref().map(|p| p.as_ref()).to_glib_none().0,
124            );
125        }
126    }
127
128    #[doc(alias = "gtk_media_file_set_input_stream")]
129    #[doc(alias = "input-stream")]
130    fn set_input_stream(&self, stream: Option<&impl IsA<gio::InputStream>>) {
131        unsafe {
132            ffi::gtk_media_file_set_input_stream(
133                self.as_ref().to_glib_none().0,
134                stream.map(|p| p.as_ref()).to_glib_none().0,
135            );
136        }
137    }
138
139    #[doc(alias = "gtk_media_file_set_resource")]
140    fn set_resource(&self, resource_path: Option<&str>) {
141        unsafe {
142            ffi::gtk_media_file_set_resource(
143                self.as_ref().to_glib_none().0,
144                resource_path.to_glib_none().0,
145            );
146        }
147    }
148
149    #[doc(alias = "file")]
150    fn connect_file_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
151        unsafe extern "C" fn notify_file_trampoline<P: IsA<MediaFile>, F: Fn(&P) + 'static>(
152            this: *mut ffi::GtkMediaFile,
153            _param_spec: glib::ffi::gpointer,
154            f: glib::ffi::gpointer,
155        ) {
156            let f: &F = &*(f as *const F);
157            f(MediaFile::from_glib_borrow(this).unsafe_cast_ref())
158        }
159        unsafe {
160            let f: Box_<F> = Box_::new(f);
161            connect_raw(
162                self.as_ptr() as *mut _,
163                c"notify::file".as_ptr() as *const _,
164                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
165                    notify_file_trampoline::<Self, F> as *const (),
166                )),
167                Box_::into_raw(f),
168            )
169        }
170    }
171
172    #[doc(alias = "input-stream")]
173    fn connect_input_stream_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
174        unsafe extern "C" fn notify_input_stream_trampoline<
175            P: IsA<MediaFile>,
176            F: Fn(&P) + 'static,
177        >(
178            this: *mut ffi::GtkMediaFile,
179            _param_spec: glib::ffi::gpointer,
180            f: glib::ffi::gpointer,
181        ) {
182            let f: &F = &*(f as *const F);
183            f(MediaFile::from_glib_borrow(this).unsafe_cast_ref())
184        }
185        unsafe {
186            let f: Box_<F> = Box_::new(f);
187            connect_raw(
188                self.as_ptr() as *mut _,
189                c"notify::input-stream".as_ptr() as *const _,
190                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
191                    notify_input_stream_trampoline::<Self, F> as *const (),
192                )),
193                Box_::into_raw(f),
194            )
195        }
196    }
197}
198
199impl<O: IsA<MediaFile>> MediaFileExt for O {}