source: appstream-generator/build/girepo/gio/ListModelT.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 8.6 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module gio.ListModelT;
22
23public  import gi.gio;
24public  import gi.giotypes;
25public  import gobject.ObjectG;
26public  import gobject.Signals;
27public  import std.algorithm;
28
29
30/**
31 * #GListModel is an interface that represents a mutable list of
32 * #GObjects. Its main intention is as a model for various widgets in
33 * user interfaces, such as list views, but it can also be used as a
34 * convenient method of returning lists of data, with support for
35 * updates.
36 *
37 * Each object in the list may also report changes in itself via some
38 * mechanism (normally the #GObject::notify signal).  Taken together
39 * with the #GListModel::items-changed signal, this provides for a list
40 * that can change its membership, and in which the members can change
41 * their individual properties.
42 *
43 * A good example would be the list of visible wireless network access
44 * points, where each access point can report dynamic properties such as
45 * signal strength.
46 *
47 * It is important to note that the #GListModel itself does not report
48 * changes to the individual items.  It only reports changes to the list
49 * membership.  If you want to observe changes to the objects themselves
50 * then you need to connect signals to the objects that you are
51 * interested in.
52 *
53 * All items in a #GListModel are of (or derived from) the same type.
54 * g_list_model_get_item_type() returns that type.  The type may be an
55 * interface, in which case all objects in the list must implement it.
56 *
57 * The semantics are close to that of an array:
58 * g_list_model_get_length() returns the number of items in the list and
59 * g_list_model_get_item() returns an item at a (0-based) position. In
60 * order to allow implementations to calculate the list length lazily,
61 * you can also iterate over items: starting from 0, repeatedly call
62 * g_list_model_get_item() until it returns %NULL.
63 *
64 * An implementation may create objects lazily, but must take care to
65 * return the same object for a given position until all references to
66 * it are gone.
67 *
68 * On the other side, a consumer is expected only to hold references on
69 * objects that are currently "user visible", in order to faciliate the
70 * maximum level of laziness in the implementation of the list and to
71 * reduce the required number of signal connections at a given time.
72 *
73 * This interface is intended only to be used from a single thread.  The
74 * thread in which it is appropriate to use it depends on the particular
75 * implementation, but typically it will be from the thread that owns
76 * the [thread-default main context][g-main-context-push-thread-default]
77 * in effect at the time that the model was created.
78 */
79public template ListModelT(TStruct)
80{
81        /** Get the main Gtk struct */
82        public GListModel* getListModelStruct()
83        {
84                return cast(GListModel*)getStruct();
85        }
86
87
88        /**
89         * Get the item at @position. If @position is greater than the number of
90         * items in @list, %NULL is returned.
91         *
92         * %NULL is never returned for an index that is smaller than the length
93         * of the list.  See g_list_model_get_n_items().
94         *
95         * Params:
96         *     position = the position of the item to fetch
97         *
98         * Returns: the item at @position.
99         *
100         * Since: 2.44
101         */
102        public ObjectG getItem(uint position)
103        {
104                auto p = g_list_model_get_item(getListModelStruct(), position);
105               
106                if(p is null)
107                {
108                        return null;
109                }
110               
111                return ObjectG.getDObject!(ObjectG)(cast(GObject*) p, true);
112        }
113
114        /**
115         * Gets the type of the items in @list. All items returned from
116         * g_list_model_get_type() are of that type or a subtype, or are an
117         * implementation of that interface.
118         *
119         * The item type of a #GListModel can not change during the life of the
120         * model.
121         *
122         * Returns: the #GType of the items contained in @list.
123         *
124         * Since: 2.44
125         */
126        public GType getItemType()
127        {
128                return g_list_model_get_item_type(getListModelStruct());
129        }
130
131        /**
132         * Gets the number of items in @list.
133         *
134         * Depending on the model implementation, calling this function may be
135         * less efficient than iterating the list with increasing values for
136         * @position until g_list_model_get_item() returns %NULL.
137         *
138         * Returns: the number of items in @list.
139         *
140         * Since: 2.44
141         */
142        public uint getNItems()
143        {
144                return g_list_model_get_n_items(getListModelStruct());
145        }
146
147        /**
148         * Get the item at @position. If @position is greater than the number of
149         * items in @list, %NULL is returned.
150         *
151         * %NULL is never returned for an index that is smaller than the length
152         * of the list.  See g_list_model_get_n_items().
153         *
154         * Params:
155         *     position = the position of the item to fetch
156         *
157         * Returns: the object at @position.
158         *
159         * Since: 2.44
160         */
161        public ObjectG getObject(uint position)
162        {
163                auto p = g_list_model_get_object(getListModelStruct(), position);
164               
165                if(p is null)
166                {
167                        return null;
168                }
169               
170                return ObjectG.getDObject!(ObjectG)(cast(GObject*) p, true);
171        }
172
173        /**
174         * Emits the #GListModel::items-changed signal on @list.
175         *
176         * This function should only be called by classes implementing
177         * #GListModel. It has to be called after the internal representation
178         * of @list has been updated, because handlers connected to this signal
179         * might query the new state of the list.
180         *
181         * Implementations must only make changes to the model (as visible to
182         * its consumer) in places that will not cause problems for that
183         * consumer.  For models that are driven directly by a write API (such
184         * as #GListStore), changes can be reported in response to uses of that
185         * API.  For models that represent remote data, changes should only be
186         * made from a fresh mainloop dispatch.  It is particularly not
187         * permitted to make changes in response to a call to the #GListModel
188         * consumer API.
189         *
190         * Stated another way: in general, it is assumed that code making a
191         * series of accesses to the model via the API, without returning to the
192         * mainloop, and without calling other code, will continue to view the
193         * same contents of the model.
194         *
195         * Params:
196         *     position = the position at which @list changed
197         *     removed = the number of items removed
198         *     added = the number of items added
199         *
200         * Since: 2.44
201         */
202        public void itemsChanged(uint position, uint removed, uint added)
203        {
204                g_list_model_items_changed(getListModelStruct(), position, removed, added);
205        }
206
207        protected class OnItemsChangedDelegateWrapper
208        {
209                static OnItemsChangedDelegateWrapper[] listeners;
210                void delegate(uint, uint, uint, ListModelIF) dlg;
211                gulong handlerId;
212               
213                this(void delegate(uint, uint, uint, ListModelIF) dlg)
214                {
215                        this.dlg = dlg;
216                        this.listeners ~= this;
217                }
218               
219                void remove(OnItemsChangedDelegateWrapper source)
220                {
221                        foreach(index, wrapper; listeners)
222                        {
223                                if (wrapper.handlerId == source.handlerId)
224                                {
225                                        listeners[index] = null;
226                                        listeners = std.algorithm.remove(listeners, index);
227                                        break;
228                                }
229                        }
230                }
231        }
232
233        /**
234         * This signal is emitted whenever items were added or removed to
235         * @list. At @position, @removed items were removed and @added items
236         * were added in their place.
237         *
238         * Params:
239         *     position = the position at which @list changed
240         *     removed = the number of items removed
241         *     added = the number of items added
242         *
243         * Since: 2.44
244         */
245        gulong addOnItemsChanged(void delegate(uint, uint, uint, ListModelIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
246        {
247                auto wrapper = new OnItemsChangedDelegateWrapper(dlg);
248                wrapper.handlerId = Signals.connectData(
249                        this,
250                        "items-changed",
251                        cast(GCallback)&callBackItemsChanged,
252                        cast(void*)wrapper,
253                        cast(GClosureNotify)&callBackItemsChangedDestroy,
254                        connectFlags);
255                return wrapper.handlerId;
256        }
257       
258        extern(C) static void callBackItemsChanged(GListModel* listmodelStruct, uint position, uint removed, uint added, OnItemsChangedDelegateWrapper wrapper)
259        {
260                wrapper.dlg(position, removed, added, wrapper.outer);
261        }
262       
263        extern(C) static void callBackItemsChangedDestroy(OnItemsChangedDelegateWrapper wrapper, GClosure* closure)
264        {
265                wrapper.remove(wrapper);
266        }
267}
Note: See TracBrowser for help on using the repository browser.