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  * Conversion parameters:
26  * inFile  = GtkRecentManager.html
27  * outPack = gtk
28  * outFile = RecentManager
29  * strct   = GtkRecentManager
30  * realStrct=
31  * ctorStrct=
32  * clss    = RecentManager
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- gtk_recent_manager_
41  * omit structs:
42  * omit prefixes:
43  * 	- gtk_recent_info_
44  * omit code:
45  * omit signals:
46  * imports:
47  * 	- glib.Str
48  * 	- glib.ErrorG
49  * 	- glib.GException
50  * 	- glib.ListG
51  * 	- gtk.RecentInfo
52  * structWrap:
53  * 	- GList* -> ListG
54  * 	- GtkRecentInfo* -> RecentInfo
55  * 	- GtkRecentManager* -> RecentManager
56  * module aliases:
57  * local aliases:
58  * overrides:
59  */
60 
61 module gtk.RecentManager;
62 
63 public  import gtkc.gtktypes;
64 
65 private import gtkc.gtk;
66 private import glib.ConstructionException;
67 private import gobject.ObjectG;
68 
69 private import gobject.Signals;
70 public  import gtkc.gdktypes;
71 private import glib.Str;
72 private import glib.ErrorG;
73 private import glib.GException;
74 private import glib.ListG;
75 private import gtk.RecentInfo;
76 
77 
78 private import gobject.ObjectG;
79 
80 /**
81  * GtkRecentManager provides a facility for adding, removing and
82  * looking up recently used files. Each recently used file is
83  * identified by its URI, and has meta-data associated to it, like
84  * the names and command lines of the applications that have
85  * registered it, the number of time each application has registered
86  * the same file, the mime type of the file and whether the file
87  * should be displayed only by the applications that have
88  * registered it.
89  *
90  * Note
91  *
92  * The recently used files list is per user.
93  *
94  * The GtkRecentManager acts like a database of all the recently
95  * used files. You can create new GtkRecentManager objects, but
96  * it is more efficient to use the default manager created by GTK+.
97  *
98  * Adding a new recently used file is as simple as:
99  *
100  * $(DDOC_COMMENT example)
101  *
102  * The GtkRecentManager will try to gather all the needed information
103  * from the file itself through GIO.
104  *
105  * Looking up the meta-data associated with a recently used file
106  * given its URI requires calling gtk_recent_manager_lookup_item():
107  *
108  * $(DDOC_COMMENT example)
109  *
110  * In order to retrieve the list of recently used files, you can use
111  * gtk_recent_manager_get_items(), which returns a list of GtkRecentInfo
112  * structures.
113  *
114  * A GtkRecentManager is the model used to populate the contents of
115  * one, or more GtkRecentChooser implementations.
116  *
117  * Note
118  *
119  * The maximum age of the recently used files list is
120  * controllable through the "gtk-recent-files-max-age"
121  * property.
122  *
123  * Recently used files are supported since GTK+ 2.10.
124  */
125 public class RecentManager : ObjectG
126 {
127 	
128 	/** the main Gtk struct */
129 	protected GtkRecentManager* gtkRecentManager;
130 	
131 	
132 	/** Get the main Gtk struct */
133 	public GtkRecentManager* getRecentManagerStruct()
134 	{
135 		return gtkRecentManager;
136 	}
137 	
138 	
139 	/** the main Gtk struct as a void* */
140 	protected override void* getStruct()
141 	{
142 		return cast(void*)gtkRecentManager;
143 	}
144 	
145 	/**
146 	 * Sets our main struct and passes it to the parent class
147 	 */
148 	public this (GtkRecentManager* gtkRecentManager)
149 	{
150 		super(cast(GObject*)gtkRecentManager);
151 		this.gtkRecentManager = gtkRecentManager;
152 	}
153 	
154 	protected override void setStruct(GObject* obj)
155 	{
156 		super.setStruct(obj);
157 		gtkRecentManager = cast(GtkRecentManager*)obj;
158 	}
159 	
160 	/**
161 	 */
162 	int[string] connectedSignals;
163 	
164 	void delegate(RecentManager)[] onChangedListeners;
165 	/**
166 	 * Emitted when the current recently used resources manager changes its
167 	 * contents, either by calling gtk_recent_manager_add_item() or by another
168 	 * application.
169 	 * Since 2.10
170 	 * See Also
171 	 * GBookmarkFile, GtkSettings, GtkRecentChooser
172 	 */
173 	void addOnChanged(void delegate(RecentManager) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
174 	{
175 		if ( !("changed" in connectedSignals) )
176 		{
177 			Signals.connectData(
178 			getStruct(),
179 			"changed",
180 			cast(GCallback)&callBackChanged,
181 			cast(void*)this,
182 			null,
183 			connectFlags);
184 			connectedSignals["changed"] = 1;
185 		}
186 		onChangedListeners ~= dlg;
187 	}
188 	extern(C) static void callBackChanged(GtkRecentManager* recentManagerStruct, RecentManager _recentManager)
189 	{
190 		foreach ( void delegate(RecentManager) dlg ; _recentManager.onChangedListeners )
191 		{
192 			dlg(_recentManager);
193 		}
194 	}
195 	
196 	
197 	/**
198 	 * Creates a new recent manager object. Recent manager objects are used to
199 	 * handle the list of recently used resources. A GtkRecentManager object
200 	 * monitors the recently used resources list, and emits the "changed" signal
201 	 * each time something inside the list changes.
202 	 * GtkRecentManager objects are expensive: be sure to create them only when
203 	 * needed. You should use gtk_recent_manager_get_default() instead.
204 	 * Since 2.10
205 	 * Throws: ConstructionException GTK+ fails to create the object.
206 	 */
207 	public this ()
208 	{
209 		// GtkRecentManager * gtk_recent_manager_new (void);
210 		auto p = gtk_recent_manager_new();
211 		if(p is null)
212 		{
213 			throw new ConstructionException("null returned by gtk_recent_manager_new()");
214 		}
215 		this(cast(GtkRecentManager*) p);
216 	}
217 	
218 	/**
219 	 * Gets a unique instance of GtkRecentManager, that you can share
220 	 * in your application without caring about memory management.
221 	 * Since 2.10
222 	 * Returns: A unique GtkRecentManager. Do not ref or unref it. [transfer none]
223 	 */
224 	public static RecentManager getDefault()
225 	{
226 		// GtkRecentManager * gtk_recent_manager_get_default (void);
227 		auto p = gtk_recent_manager_get_default();
228 		
229 		if(p is null)
230 		{
231 			return null;
232 		}
233 		
234 		return ObjectG.getDObject!(RecentManager)(cast(GtkRecentManager*) p);
235 	}
236 	
237 	/**
238 	 * Adds a new resource, pointed by uri, into the recently used
239 	 * resources list.
240 	 * This function automatically retrieves some of the needed
241 	 * metadata and setting other metadata to common default values; it
242 	 * then feeds the data to gtk_recent_manager_add_full().
243 	 * See gtk_recent_manager_add_full() if you want to explicitly
244 	 * define the metadata for the resource pointed by uri.
245 	 * Since 2.10
246 	 * Params:
247 	 * uri = a valid URI
248 	 * Returns: TRUE if the new item was successfully added to the recently used resources list
249 	 */
250 	public int addItem(string uri)
251 	{
252 		// gboolean gtk_recent_manager_add_item (GtkRecentManager *manager,  const gchar *uri);
253 		return gtk_recent_manager_add_item(gtkRecentManager, Str.toStringz(uri));
254 	}
255 	
256 	/**
257 	 * Adds a new resource, pointed by uri, into the recently used
258 	 * resources list, using the metadata specified inside the GtkRecentData
259 	 * structure passed in recent_data.
260 	 * The passed URI will be used to identify this resource inside the
261 	 * list.
262 	 * In order to register the new recently used resource, metadata about
263 	 * the resource must be passed as well as the URI; the metadata is
264 	 * stored in a GtkRecentData structure, which must contain the MIME
265 	 * type of the resource pointed by the URI; the name of the application
266 	 * that is registering the item, and a command line to be used when
267 	 * launching the item.
268 	 * Optionally, a GtkRecentData structure might contain a UTF-8 string
269 	 * to be used when viewing the item instead of the last component of the
270 	 * URI; a short description of the item; whether the item should be
271 	 * considered private - that is, should be displayed only by the
272 	 * applications that have registered it.
273 	 * Since 2.10
274 	 * Params:
275 	 * uri = a valid URI
276 	 * recentData = metadata of the resource
277 	 * Returns: TRUE if the new item was successfully added to the recently used resources list, FALSE otherwise.
278 	 */
279 	public int addFull(string uri, GtkRecentData* recentData)
280 	{
281 		// gboolean gtk_recent_manager_add_full (GtkRecentManager *manager,  const gchar *uri,  const GtkRecentData *recent_data);
282 		return gtk_recent_manager_add_full(gtkRecentManager, Str.toStringz(uri), recentData);
283 	}
284 	
285 	/**
286 	 * Removes a resource pointed by uri from the recently used resources
287 	 * list handled by a recent manager.
288 	 * Since 2.10
289 	 * Params:
290 	 * uri = the URI of the item you wish to remove
291 	 * Returns: TRUE if the item pointed by uri has been successfully removed by the recently used resources list, and FALSE otherwise.
292 	 * Throws: GException on failure.
293 	 */
294 	public int removeItem(string uri)
295 	{
296 		// gboolean gtk_recent_manager_remove_item (GtkRecentManager *manager,  const gchar *uri,  GError **error);
297 		GError* err = null;
298 		
299 		auto p = gtk_recent_manager_remove_item(gtkRecentManager, Str.toStringz(uri), &err);
300 		
301 		if (err !is null)
302 		{
303 			throw new GException( new ErrorG(err) );
304 		}
305 		
306 		return p;
307 	}
308 	
309 	/**
310 	 * Searches for a URI inside the recently used resources list, and
311 	 * returns a structure containing informations about the resource
312 	 * like its MIME type, or its display name.
313 	 * Since 2.10
314 	 * Params:
315 	 * uri = a URI
316 	 * Returns: a GtkRecentInfo structure containing information about the resource pointed by uri, or NULL if the URI was not registered in the recently used resources list. Free with gtk_recent_info_unref().
317 	 * Throws: GException on failure.
318 	 */
319 	public RecentInfo lookupItem(string uri)
320 	{
321 		// GtkRecentInfo * gtk_recent_manager_lookup_item (GtkRecentManager *manager,  const gchar *uri,  GError **error);
322 		GError* err = null;
323 		
324 		auto p = gtk_recent_manager_lookup_item(gtkRecentManager, Str.toStringz(uri), &err);
325 		
326 		if (err !is null)
327 		{
328 			throw new GException( new ErrorG(err) );
329 		}
330 		
331 		
332 		if(p is null)
333 		{
334 			return null;
335 		}
336 		
337 		return ObjectG.getDObject!(RecentInfo)(cast(GtkRecentInfo*) p);
338 	}
339 	
340 	/**
341 	 * Checks whether there is a recently used resource registered
342 	 * with uri inside the recent manager.
343 	 * Since 2.10
344 	 * Params:
345 	 * uri = a URI
346 	 * Returns: TRUE if the resource was found, FALSE otherwise.
347 	 */
348 	public int hasItem(string uri)
349 	{
350 		// gboolean gtk_recent_manager_has_item (GtkRecentManager *manager,  const gchar *uri);
351 		return gtk_recent_manager_has_item(gtkRecentManager, Str.toStringz(uri));
352 	}
353 	
354 	/**
355 	 * Changes the location of a recently used resource from uri to new_uri.
356 	 * Please note that this function will not affect the resource pointed
357 	 * by the URIs, but only the URI used in the recently used resources list.
358 	 * Since 2.10
359 	 * Params:
360 	 * uri = the URI of a recently used resource
361 	 * newUri = the new URI of the recently used resource, or NULL to
362 	 * remove the item pointed by uri in the list. [allow-none]
363 	 * Returns: TRUE on success.
364 	 * Throws: GException on failure.
365 	 */
366 	public int moveItem(string uri, string newUri)
367 	{
368 		// gboolean gtk_recent_manager_move_item (GtkRecentManager *manager,  const gchar *uri,  const gchar *new_uri,  GError **error);
369 		GError* err = null;
370 		
371 		auto p = gtk_recent_manager_move_item(gtkRecentManager, Str.toStringz(uri), Str.toStringz(newUri), &err);
372 		
373 		if (err !is null)
374 		{
375 			throw new GException( new ErrorG(err) );
376 		}
377 		
378 		return p;
379 	}
380 	
381 	/**
382 	 * Gets the list of recently used resources.
383 	 * Since 2.10
384 	 * Returns: a list of newly allocated GtkRecentInfo objects. Use gtk_recent_info_unref() on each item inside the list, and then free the list itself using g_list_free(). [element-type GtkRecentInfo][transfer full]
385 	 */
386 	public ListG getItems()
387 	{
388 		// GList * gtk_recent_manager_get_items (GtkRecentManager *manager);
389 		auto p = gtk_recent_manager_get_items(gtkRecentManager);
390 		
391 		if(p is null)
392 		{
393 			return null;
394 		}
395 		
396 		return ObjectG.getDObject!(ListG)(cast(GList*) p);
397 	}
398 	
399 	/**
400 	 * Purges every item from the recently used resources list.
401 	 * Since 2.10
402 	 * Returns: the number of items that have been removed from the recently used resources list.
403 	 * Throws: GException on failure.
404 	 */
405 	public int purgeItems()
406 	{
407 		// gint gtk_recent_manager_purge_items (GtkRecentManager *manager,  GError **error);
408 		GError* err = null;
409 		
410 		auto p = gtk_recent_manager_purge_items(gtkRecentManager, &err);
411 		
412 		if (err !is null)
413 		{
414 			throw new GException( new ErrorG(err) );
415 		}
416 		
417 		return p;
418 	}
419 }