1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// 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 gio_sys;
#[cfg(any(feature = "v2_44", feature = "dox"))]
use glib;
use glib::object::Cast;
use glib::object::IsA;
use glib::translate::*;
use glib::StaticType;
use glib::ToValue;
use std::fmt;
#[cfg(any(feature = "v2_64", feature = "dox"))]
use std::mem;
use ListModel;

glib_wrapper! {
    pub struct ListStore(Object<gio_sys::GListStore, gio_sys::GListStoreClass, ListStoreClass>) @implements ListModel;

    match fn {
        get_type => || gio_sys::g_list_store_get_type(),
    }
}

impl ListStore {
    #[cfg(any(feature = "v2_44", feature = "dox"))]
    pub fn new(item_type: glib::types::Type) -> ListStore {
        unsafe { from_glib_full(gio_sys::g_list_store_new(item_type.to_glib())) }
    }
}

#[derive(Clone, Default)]
pub struct ListStoreBuilder {
    #[cfg(any(feature = "v2_44", feature = "dox"))]
    item_type: Option<glib::types::Type>,
}

impl ListStoreBuilder {
    pub fn new() -> Self {
        Self::default()
    }

    pub fn build(self) -> ListStore {
        let mut properties: Vec<(&str, &dyn ToValue)> = vec![];
        #[cfg(any(feature = "v2_44", feature = "dox"))]
        {
            if let Some(ref item_type) = self.item_type {
                properties.push(("item-type", item_type));
            }
        }
        let ret = glib::Object::new(ListStore::static_type(), &properties)
            .expect("object new")
            .downcast::<ListStore>()
            .expect("downcast");
        ret
    }

    #[cfg(any(feature = "v2_44", feature = "dox"))]
    pub fn item_type(mut self, item_type: glib::types::Type) -> Self {
        self.item_type = Some(item_type);
        self
    }
}

pub const NONE_LIST_STORE: Option<&ListStore> = None;

pub trait ListStoreExt: 'static {
    #[cfg(any(feature = "v2_44", feature = "dox"))]
    fn append<P: IsA<glib::Object>>(&self, item: &P);

    #[cfg(any(feature = "v2_64", feature = "dox"))]
    fn find<P: IsA<glib::Object>>(&self, item: &P) -> Option<u32>;

    //#[cfg(any(feature = "v2_64", feature = "dox"))]
    //fn find_with_equal_func<P: IsA<glib::Object>>(&self, item: &P, equal_func: /*Unimplemented*/FnMut(/*Unimplemented*/Option<Fundamental: Pointer>, /*Unimplemented*/Option<Fundamental: Pointer>) -> bool) -> Option<u32>;

    #[cfg(any(feature = "v2_44", feature = "dox"))]
    fn insert<P: IsA<glib::Object>>(&self, position: u32, item: &P);

    #[cfg(any(feature = "v2_44", feature = "dox"))]
    fn remove(&self, position: u32);

    #[cfg(any(feature = "v2_44", feature = "dox"))]
    fn remove_all(&self);

    #[cfg(any(feature = "v2_44", feature = "dox"))]
    fn splice(&self, position: u32, n_removals: u32, additions: &[glib::Object]);
}

impl<O: IsA<ListStore>> ListStoreExt for O {
    #[cfg(any(feature = "v2_44", feature = "dox"))]
    fn append<P: IsA<glib::Object>>(&self, item: &P) {
        unsafe {
            gio_sys::g_list_store_append(
                self.as_ref().to_glib_none().0,
                item.as_ref().to_glib_none().0,
            );
        }
    }

    #[cfg(any(feature = "v2_64", feature = "dox"))]
    fn find<P: IsA<glib::Object>>(&self, item: &P) -> Option<u32> {
        unsafe {
            let mut position = mem::MaybeUninit::uninit();
            let ret = from_glib(gio_sys::g_list_store_find(
                self.as_ref().to_glib_none().0,
                item.as_ref().to_glib_none().0,
                position.as_mut_ptr(),
            ));
            let position = position.assume_init();
            if ret {
                Some(position)
            } else {
                None
            }
        }
    }

    //#[cfg(any(feature = "v2_64", feature = "dox"))]
    //fn find_with_equal_func<P: IsA<glib::Object>>(&self, item: &P, equal_func: /*Unimplemented*/FnMut(/*Unimplemented*/Option<Fundamental: Pointer>, /*Unimplemented*/Option<Fundamental: Pointer>) -> bool) -> Option<u32> {
    //    unsafe { TODO: call gio_sys:g_list_store_find_with_equal_func() }
    //}

    #[cfg(any(feature = "v2_44", feature = "dox"))]
    fn insert<P: IsA<glib::Object>>(&self, position: u32, item: &P) {
        unsafe {
            gio_sys::g_list_store_insert(
                self.as_ref().to_glib_none().0,
                position,
                item.as_ref().to_glib_none().0,
            );
        }
    }

    #[cfg(any(feature = "v2_44", feature = "dox"))]
    fn remove(&self, position: u32) {
        unsafe {
            gio_sys::g_list_store_remove(self.as_ref().to_glib_none().0, position);
        }
    }

    #[cfg(any(feature = "v2_44", feature = "dox"))]
    fn remove_all(&self) {
        unsafe {
            gio_sys::g_list_store_remove_all(self.as_ref().to_glib_none().0);
        }
    }

    #[cfg(any(feature = "v2_44", feature = "dox"))]
    fn splice(&self, position: u32, n_removals: u32, additions: &[glib::Object]) {
        let n_additions = additions.len() as u32;
        unsafe {
            gio_sys::g_list_store_splice(
                self.as_ref().to_glib_none().0,
                position,
                n_removals,
                additions.to_glib_none().0,
                n_additions,
            );
        }
    }
}

impl fmt::Display for ListStore {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "ListStore")
    }
}