Adapt to subclassing changes

This commit is contained in:
Elias Projahn 2021-01-25 15:23:20 +01:00
parent 801a130ef8
commit 911d0b070c
2 changed files with 50 additions and 58 deletions

View file

@ -16,6 +16,7 @@ gtk-macros = "0.2.0"
gstreamer = "0.16.4" gstreamer = "0.16.4"
gstreamer-player = "0.16.3" gstreamer-player = "0.16.3"
isahc = "0.9.12" isahc = "0.9.12"
once_cell = "1.5.2"
rand = "0.7.3" rand = "0.7.3"
secret-service = "1.1.1" secret-service = "1.1.1"
serde = { version = "1.0.117", features = ["derive"] } serde = { version = "1.0.117", features = ["derive"] }

View file

@ -3,6 +3,7 @@ use glib::subclass;
use glib::subclass::prelude::*; use glib::subclass::prelude::*;
use gio::prelude::*; use gio::prelude::*;
use gio::subclass::prelude::*; use gio::subclass::prelude::*;
use once_cell::sync::Lazy;
use std::cell::Cell; use std::cell::Cell;
glib::wrapper! { glib::wrapper! {
@ -32,49 +33,44 @@ mod indexed_list_model {
length: Cell<u32>, length: Cell<u32>,
} }
static PROPERTIES: [subclass::Property; 1] = [
subclass::Property("length", |length| {
glib::ParamSpec::uint(
length,
"Length",
"Length",
0,
std::u32::MAX,
0,
glib::ParamFlags::READWRITE,
)
}),
];
impl ObjectSubclass for IndexedListModel { impl ObjectSubclass for IndexedListModel {
const NAME: &'static str = "IndexedListModel"; const NAME: &'static str = "IndexedListModel";
type Type = super::IndexedListModel; type Type = super::IndexedListModel;
type ParentType = glib::Object; type ParentType = glib::Object;
type Interfaces = (gio::ListModel,);
type Instance = subclass::simple::InstanceStruct<Self>; type Instance = subclass::simple::InstanceStruct<Self>;
type Class = subclass::simple::ClassStruct<Self>; type Class = subclass::simple::ClassStruct<Self>;
glib::object_subclass!(); glib::object_subclass!();
fn type_init(type_: &mut subclass::InitializingType<Self>) {
type_.add_interface::<gio::ListModel>();
}
fn class_init(klass: &mut Self::Class) {
klass.install_properties(&PROPERTIES);
}
fn new() -> Self { fn new() -> Self {
Self { length: Cell::new(0) } Self { length: Cell::new(0) }
} }
} }
impl ObjectImpl for IndexedListModel { impl ObjectImpl for IndexedListModel {
fn set_property(&self, _obj: &Self::Type, id: usize, value: &glib::Value) { fn properties() -> &'static [glib::ParamSpec] {
let prop = &PROPERTIES[id]; static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
vec![
glib::ParamSpec::uint(
"length",
"Length",
"Length",
0,
std::u32::MAX,
0,
glib::ParamFlags::READWRITE,
),
]
});
match *prop { PROPERTIES.as_ref()
subclass::Property("length", ..) => { }
fn set_property(&self, _obj: &Self::Type, id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
match pspec.get_name() {
"length" => {
let length = value.get().unwrap().unwrap(); let length = value.get().unwrap().unwrap();
self.length.set(length); self.length.set(length);
} }
@ -82,11 +78,9 @@ mod indexed_list_model {
} }
} }
fn get_property(&self, _obj: &Self::Type, id: usize) -> glib::Value { fn get_property(&self, _obj: &Self::Type, id: usize, pspec: &glib::ParamSpec) -> glib::Value {
let prop = &PROPERTIES[id]; match pspec.get_name() {
"length" => self.length.get().to_value(),
match *prop {
subclass::Property("length", ..) => self.length.get().to_value(),
_ => unimplemented!(), _ => unimplemented!(),
} }
} }
@ -131,45 +125,44 @@ mod item_index {
value: Cell<u32>, value: Cell<u32>,
} }
static PROPERTIES: [subclass::Property; 1] = [
subclass::Property("value", |value| {
glib::ParamSpec::uint(
value,
"Value",
"Value",
0,
std::u32::MAX,
0,
glib::ParamFlags::READWRITE,
)
}),
];
impl ObjectSubclass for ItemIndex { impl ObjectSubclass for ItemIndex {
const NAME: &'static str = "ItemIndex"; const NAME: &'static str = "ItemIndex";
type Type = super::ItemIndex; type Type = super::ItemIndex;
type ParentType = glib::Object; type ParentType = glib::Object;
type Interfaces = ();
type Instance = subclass::simple::InstanceStruct<Self>; type Instance = subclass::simple::InstanceStruct<Self>;
type Class = subclass::simple::ClassStruct<Self>; type Class = subclass::simple::ClassStruct<Self>;
glib::object_subclass!(); glib::object_subclass!();
fn class_init(klass: &mut Self::Class) {
klass.install_properties(&PROPERTIES);
}
fn new() -> Self { fn new() -> Self {
Self { value: Cell::new(0) } Self { value: Cell::new(0) }
} }
} }
impl ObjectImpl for ItemIndex { impl ObjectImpl for ItemIndex {
fn set_property(&self, _obj: &Self::Type, id: usize, value: &glib::Value) { fn properties() -> &'static [glib::ParamSpec] {
let prop = &PROPERTIES[id]; static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
vec![
glib::ParamSpec::uint(
"value",
"Value",
"Value",
0,
std::u32::MAX,
0,
glib::ParamFlags::READWRITE,
),
]
});
match *prop { PROPERTIES.as_ref()
subclass::Property("value", ..) => { }
fn set_property(&self, _obj: &Self::Type, id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
match pspec.get_name() {
"value" => {
let value = value.get().unwrap().unwrap(); let value = value.get().unwrap().unwrap();
self.value.set(value); self.value.set(value);
} }
@ -177,11 +170,9 @@ mod item_index {
} }
} }
fn get_property(&self, _obj: &Self::Type, id: usize) -> glib::Value { fn get_property(&self, _obj: &Self::Type, id: usize, pspec: &glib::ParamSpec) -> glib::Value {
let prop = &PROPERTIES[id]; match pspec.get_name() {
"value" => self.value.get().to_value(),
match *prop {
subclass::Property("value", ..) => self.value.get().to_value(),
_ => unimplemented!(), _ => unimplemented!(),
} }
} }