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.SortListModel;
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.Sorter;
32 private import gtk.c.functions;
33 public  import gtk.c.types;
34 
35 
36 /**
37  * `GtkSortListModel` is a list model that sorts the elements of
38  * the underlying model according to a `GtkSorter`.
39  * 
40  * The model can be set up to do incremental sorting, so that
41  * sorting long lists doesn't block the UI. See
42  * [method@Gtk.SortListModel.set_incremental] for details.
43  * 
44  * `GtkSortListModel` is a generic model and because of that it
45  * cannot take advantage of any external knowledge when sorting.
46  * If you run into performance issues with `GtkSortListModel`,
47  * it is strongly recommended that you write your own sorting list
48  * model.
49  */
50 public class SortListModel : ObjectG, ListModelIF
51 {
52 	/** the main Gtk struct */
53 	protected GtkSortListModel* gtkSortListModel;
54 
55 	/** Get the main Gtk struct */
56 	public GtkSortListModel* getSortListModelStruct(bool transferOwnership = false)
57 	{
58 		if (transferOwnership)
59 			ownedRef = false;
60 		return gtkSortListModel;
61 	}
62 
63 	/** the main Gtk struct as a void* */
64 	protected override void* getStruct()
65 	{
66 		return cast(void*)gtkSortListModel;
67 	}
68 
69 	/**
70 	 * Sets our main struct and passes it to the parent class.
71 	 */
72 	public this (GtkSortListModel* gtkSortListModel, bool ownedRef = false)
73 	{
74 		this.gtkSortListModel = gtkSortListModel;
75 		super(cast(GObject*)gtkSortListModel, ownedRef);
76 	}
77 
78 	// add the ListModel capabilities
79 	mixin ListModelT!(GtkSortListModel);
80 
81 
82 	/** */
83 	public static GType getType()
84 	{
85 		return gtk_sort_list_model_get_type();
86 	}
87 
88 	/**
89 	 * Creates a new sort list model that uses the @sorter to sort @model.
90 	 *
91 	 * Params:
92 	 *     model = the model to sort, or %NULL
93 	 *     sorter = the `GtkSorter` to sort @model with, or %NULL
94 	 *
95 	 * Returns: a new `GtkSortListModel`
96 	 *
97 	 * Throws: ConstructionException GTK+ fails to create the object.
98 	 */
99 	public this(ListModelIF model, Sorter sorter)
100 	{
101 		auto __p = gtk_sort_list_model_new((model is null) ? null : model.getListModelStruct(), (sorter is null) ? null : sorter.getSorterStruct());
102 
103 		if(__p is null)
104 		{
105 			throw new ConstructionException("null returned by new");
106 		}
107 
108 		this(cast(GtkSortListModel*) __p, true);
109 	}
110 
111 	/**
112 	 * Returns whether incremental sorting is enabled.
113 	 *
114 	 * See [method@Gtk.SortListModel.set_incremental].
115 	 *
116 	 * Returns: %TRUE if incremental sorting is enabled
117 	 */
118 	public bool getIncremental()
119 	{
120 		return gtk_sort_list_model_get_incremental(gtkSortListModel) != 0;
121 	}
122 
123 	/**
124 	 * Gets the model currently sorted or %NULL if none.
125 	 *
126 	 * Returns: The model that gets sorted
127 	 */
128 	public ListModelIF getModel()
129 	{
130 		auto __p = gtk_sort_list_model_get_model(gtkSortListModel);
131 
132 		if(__p is null)
133 		{
134 			return null;
135 		}
136 
137 		return ObjectG.getDObject!(ListModelIF)(cast(GListModel*) __p);
138 	}
139 
140 	/**
141 	 * Estimates progress of an ongoing sorting operation.
142 	 *
143 	 * The estimate is the number of items that would still need to be
144 	 * sorted to finish the sorting operation if this was a linear
145 	 * algorithm. So this number is not related to how many items are
146 	 * already correctly sorted.
147 	 *
148 	 * If you want to estimate the progress, you can use code like this:
149 	 * ```c
150 	 * pending = gtk_sort_list_model_get_pending (self);
151 	 * model = gtk_sort_list_model_get_model (self);
152 	 * progress = 1.0 - pending / (double) MAX (1, g_list_model_get_n_items (model));
153 	 * ```
154 	 *
155 	 * If no sort operation is ongoing - in particular when
156 	 * [property@Gtk.SortListModel:incremental] is %FALSE - this
157 	 * function returns 0.
158 	 *
159 	 * Returns: a progress estimate of remaining items to sort
160 	 */
161 	public uint getPending()
162 	{
163 		return gtk_sort_list_model_get_pending(gtkSortListModel);
164 	}
165 
166 	/**
167 	 * Gets the sorter that is used to sort @self.
168 	 *
169 	 * Returns: the sorter of #self
170 	 */
171 	public Sorter getSorter()
172 	{
173 		auto __p = gtk_sort_list_model_get_sorter(gtkSortListModel);
174 
175 		if(__p is null)
176 		{
177 			return null;
178 		}
179 
180 		return ObjectG.getDObject!(Sorter)(cast(GtkSorter*) __p);
181 	}
182 
183 	/**
184 	 * Sets the sort model to do an incremental sort.
185 	 *
186 	 * When incremental sorting is enabled, the `GtkSortListModel` will not do
187 	 * a complete sort immediately, but will instead queue an idle handler that
188 	 * incrementally sorts the items towards their correct position. This of
189 	 * course means that items do not instantly appear in the right place. It
190 	 * also means that the total sorting time is a lot slower.
191 	 *
192 	 * When your filter blocks the UI while sorting, you might consider
193 	 * turning this on. Depending on your model and sorters, this may become
194 	 * interesting around 10,000 to 100,000 items.
195 	 *
196 	 * By default, incremental sorting is disabled.
197 	 *
198 	 * See [method@Gtk.SortListModel.get_pending] for progress information
199 	 * about an ongoing incremental sorting operation.
200 	 *
201 	 * Params:
202 	 *     incremental = %TRUE to sort incrementally
203 	 */
204 	public void setIncremental(bool incremental)
205 	{
206 		gtk_sort_list_model_set_incremental(gtkSortListModel, incremental);
207 	}
208 
209 	/**
210 	 * Sets the model to be sorted.
211 	 *
212 	 * The @model's item type must conform to the item type of @self.
213 	 *
214 	 * Params:
215 	 *     model = The model to be sorted
216 	 */
217 	public void setModel(ListModelIF model)
218 	{
219 		gtk_sort_list_model_set_model(gtkSortListModel, (model is null) ? null : model.getListModelStruct());
220 	}
221 
222 	/**
223 	 * Sets a new sorter on @self.
224 	 *
225 	 * Params:
226 	 *     sorter = the `GtkSorter` to sort @model with
227 	 */
228 	public void setSorter(Sorter sorter)
229 	{
230 		gtk_sort_list_model_set_sorter(gtkSortListModel, (sorter is null) ? null : sorter.getSorterStruct());
231 	}
232 }