1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.FilterListModel;
26 
27 private import gio.ListModelIF;
28 private import gio.ListModelT;
29 private import glib.ConstructionException;
30 private import gobject.ObjectG;
31 private import gtk.Filter;
32 private import gtk.c.functions;
33 public  import gtk.c.types;
34 
35 
36 /**
37  * `GtkFilterListModel` is a list model that filters the elements of
38  * the underlying model according to a `GtkFilter`.
39  * 
40  * It hides some elements from the other model according to
41  * criteria given by a `GtkFilter`.
42  * 
43  * The model can be set up to do incremental searching, so that
44  * filtering long lists doesn't block the UI. See
45  * [method@Gtk.FilterListModel.set_incremental] for details.
46  */
47 public class FilterListModel : ObjectG, ListModelIF
48 {
49 	/** the main Gtk struct */
50 	protected GtkFilterListModel* gtkFilterListModel;
51 
52 	/** Get the main Gtk struct */
53 	public GtkFilterListModel* getFilterListModelStruct(bool transferOwnership = false)
54 	{
55 		if (transferOwnership)
56 			ownedRef = false;
57 		return gtkFilterListModel;
58 	}
59 
60 	/** the main Gtk struct as a void* */
61 	protected override void* getStruct()
62 	{
63 		return cast(void*)gtkFilterListModel;
64 	}
65 
66 	/**
67 	 * Sets our main struct and passes it to the parent class.
68 	 */
69 	public this (GtkFilterListModel* gtkFilterListModel, bool ownedRef = false)
70 	{
71 		this.gtkFilterListModel = gtkFilterListModel;
72 		super(cast(GObject*)gtkFilterListModel, ownedRef);
73 	}
74 
75 	// add the ListModel capabilities
76 	mixin ListModelT!(GtkFilterListModel);
77 
78 
79 	/** */
80 	public static GType getType()
81 	{
82 		return gtk_filter_list_model_get_type();
83 	}
84 
85 	/**
86 	 * Creates a new `GtkFilterListModel` that will filter @model using the given
87 	 * @filter.
88 	 *
89 	 * Params:
90 	 *     model = the model to sort, or %NULL
91 	 *     filter = filter or %NULL to not filter items
92 	 *
93 	 * Returns: a new `GtkFilterListModel`
94 	 *
95 	 * Throws: ConstructionException GTK+ fails to create the object.
96 	 */
97 	public this(ListModelIF model, Filter filter)
98 	{
99 		auto __p = gtk_filter_list_model_new((model is null) ? null : model.getListModelStruct(), (filter is null) ? null : filter.getFilterStruct());
100 
101 		if(__p is null)
102 		{
103 			throw new ConstructionException("null returned by new");
104 		}
105 
106 		this(cast(GtkFilterListModel*) __p, true);
107 	}
108 
109 	/**
110 	 * Gets the `GtkFilter` currently set on @self.
111 	 *
112 	 * Returns: The filter currently in use
113 	 *     or %NULL if the list isn't filtered
114 	 */
115 	public Filter getFilter()
116 	{
117 		auto __p = gtk_filter_list_model_get_filter(gtkFilterListModel);
118 
119 		if(__p is null)
120 		{
121 			return null;
122 		}
123 
124 		return ObjectG.getDObject!(Filter)(cast(GtkFilter*) __p);
125 	}
126 
127 	/**
128 	 * Returns whether incremental filtering is enabled.
129 	 *
130 	 * See [method@Gtk.FilterListModel.set_incremental].
131 	 *
132 	 * Returns: %TRUE if incremental filtering is enabled
133 	 */
134 	public bool getIncremental()
135 	{
136 		return gtk_filter_list_model_get_incremental(gtkFilterListModel) != 0;
137 	}
138 
139 	/**
140 	 * Gets the model currently filtered or %NULL if none.
141 	 *
142 	 * Returns: The model that gets filtered
143 	 */
144 	public ListModelIF getModel()
145 	{
146 		auto __p = gtk_filter_list_model_get_model(gtkFilterListModel);
147 
148 		if(__p is null)
149 		{
150 			return null;
151 		}
152 
153 		return ObjectG.getDObject!(ListModelIF)(cast(GListModel*) __p);
154 	}
155 
156 	/**
157 	 * Returns the number of items that have not been filtered yet.
158 	 *
159 	 * You can use this value to check if @self is busy filtering by
160 	 * comparing the return value to 0 or you can compute the percentage
161 	 * of the filter remaining by dividing the return value by the total
162 	 * number of items in the underlying model:
163 	 *
164 	 * ```c
165 	 * pending = gtk_filter_list_model_get_pending (self);
166 	 * model = gtk_filter_list_model_get_model (self);
167 	 * percentage = pending / (double) g_list_model_get_n_items (model);
168 	 * ```
169 	 *
170 	 * If no filter operation is ongoing - in particular when
171 	 * [property@Gtk.FilterListModel:incremental] is %FALSE - this
172 	 * function returns 0.
173 	 *
174 	 * Returns: The number of items not yet filtered
175 	 */
176 	public uint getPending()
177 	{
178 		return gtk_filter_list_model_get_pending(gtkFilterListModel);
179 	}
180 
181 	/**
182 	 * Sets the filter used to filter items.
183 	 *
184 	 * Params:
185 	 *     filter = filter to use or %NULL to not filter items
186 	 */
187 	public void setFilter(Filter filter)
188 	{
189 		gtk_filter_list_model_set_filter(gtkFilterListModel, (filter is null) ? null : filter.getFilterStruct());
190 	}
191 
192 	/**
193 	 * Sets the filter model to do an incremental sort.
194 	 *
195 	 * When incremental filtering is enabled, the `GtkFilterListModel` will not
196 	 * run filters immediately, but will instead queue an idle handler that
197 	 * incrementally filters the items and adds them to the list. This of course
198 	 * means that items are not instantly added to the list, but only appear
199 	 * incrementally.
200 	 *
201 	 * When your filter blocks the UI while filtering, you might consider
202 	 * turning this on. Depending on your model and filters, this may become
203 	 * interesting around 10,000 to 100,000 items.
204 	 *
205 	 * By default, incremental filtering is disabled.
206 	 *
207 	 * See [method@Gtk.FilterListModel.get_pending] for progress information
208 	 * about an ongoing incremental filtering operation.
209 	 *
210 	 * Params:
211 	 *     incremental = %TRUE to enable incremental filtering
212 	 */
213 	public void setIncremental(bool incremental)
214 	{
215 		gtk_filter_list_model_set_incremental(gtkFilterListModel, incremental);
216 	}
217 
218 	/**
219 	 * Sets the model to be filtered.
220 	 *
221 	 * Note that GTK makes no effort to ensure that @model conforms to
222 	 * the item type of @self. It assumes that the caller knows what they
223 	 * are doing and have set up an appropriate filter to ensure that item
224 	 * types match.
225 	 *
226 	 * Params:
227 	 *     model = The model to be filtered
228 	 */
229 	public void setModel(ListModelIF model)
230 	{
231 		gtk_filter_list_model_set_model(gtkFilterListModel, (model is null) ? null : model.getListModelStruct());
232 	}
233 }