Update for new simplified glib::Object::new() API

This commit is contained in:
Sebastian Dröge 2020-12-17 17:26:47 +02:00
parent dfa3812ccc
commit f3b5340875
5 changed files with 9 additions and 35 deletions

View file

@ -167,10 +167,7 @@ mod media_factory {
impl Default for Factory { impl Default for Factory {
// Creates a new instance of our factory // Creates a new instance of our factory
fn default() -> Factory { fn default() -> Factory {
glib::Object::new(Self::static_type(), &[]) glib::Object::new(&[]).expect("Failed to create factory")
.expect("Failed to create factory")
.downcast()
.expect("Created factory is of wrong type")
} }
} }
} }
@ -316,10 +313,7 @@ mod server {
impl Default for Server { impl Default for Server {
// Creates a new instance of our factory // Creates a new instance of our factory
fn default() -> Server { fn default() -> Server {
glib::Object::new(Self::static_type(), &[]) glib::Object::new(&[]).expect("Failed to create server")
.expect("Failed to create server")
.downcast()
.expect("Created server is of wrong type")
} }
} }
} }
@ -385,10 +379,7 @@ mod client {
impl Default for Client { impl Default for Client {
// Creates a new instance of our factory // Creates a new instance of our factory
fn default() -> Client { fn default() -> Client {
glib::Object::new(Self::static_type(), &[]) glib::Object::new(&[]).expect("Failed to create client")
.expect("Failed to create client")
.downcast()
.expect("Created client is of wrong type")
} }
} }
} }

View file

@ -256,10 +256,7 @@ mod fir_filter {
impl FirFilter { impl FirFilter {
// Creates a new instance of our filter with the given name // Creates a new instance of our filter with the given name
pub fn new(name: Option<&str>) -> FirFilter { pub fn new(name: Option<&str>) -> FirFilter {
glib::Object::new(Self::static_type(), &[("name", &name)]) glib::Object::new(&[("name", &name)]).expect("Failed to create fir filter")
.expect("Failed to create fir filter")
.downcast()
.expect("Created fir filter is of wrong type")
} }
// Sets the coefficients by getting access to the private // Sets the coefficients by getting access to the private

View file

@ -1628,13 +1628,8 @@ impl<T: IsA<Pad> + IsA<glib::Object>> PadBuilder<T> {
pub fn new(name: Option<&str>, direction: crate::PadDirection) -> Self { pub fn new(name: Option<&str>, direction: crate::PadDirection) -> Self {
assert_initialized_main_thread!(); assert_initialized_main_thread!();
let pad = glib::Object::new( let pad = glib::Object::new::<T>(&[("name", &name), ("direction", &direction)])
T::static_type(), .expect("Failed to create pad");
&[("name", &name), ("direction", &direction)],
)
.expect("Failed to create pad")
.downcast::<T>()
.unwrap();
// Ghost pads are a bit special // Ghost pads are a bit special
if let Some(pad) = pad.dynamic_cast_ref::<crate::GhostPad>() { if let Some(pad) = pad.dynamic_cast_ref::<crate::GhostPad>() {
@ -1683,7 +1678,7 @@ impl<T: IsA<Pad> + IsA<glib::Object>> PadBuilder<T> {
} }
} }
let pad = glib::Object::new( let pad = glib::Object::with_type(
type_, type_,
&[ &[
("name", &name), ("name", &name),

View file

@ -744,10 +744,7 @@ mod tests {
impl TestElement { impl TestElement {
pub fn new(name: Option<&str>) -> Self { pub fn new(name: Option<&str>) -> Self {
glib::Object::new(TestElement::static_type(), &[("name", &name)]) glib::Object::new(&[("name", &name)]).unwrap()
.unwrap()
.downcast::<Self>()
.unwrap()
} }
} }

View file

@ -141,13 +141,7 @@ mod tests {
impl TestPad { impl TestPad {
pub fn new(name: &str, direction: PadDirection) -> Self { pub fn new(name: &str, direction: PadDirection) -> Self {
glib::Object::new( glib::Object::new(&[("name", &name), ("direction", &direction)]).unwrap()
TestPad::static_type(),
&[("name", &name), ("direction", &direction)],
)
.unwrap()
.downcast::<Self>()
.unwrap()
} }
} }