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  * 	- gdk.Screen
49  * 	- gtk.RecentInfo
50  * 	- glib.ErrorG
51  * 	- glib.GException
52  * 	- glib.ListG
53  * structWrap:
54  * 	- GList* -> ListG
55  * 	- GdkScreen* -> Screen
56  * 	- GtkRecentInfo* -> RecentInfo
57  * 	- GtkRecentManager* -> RecentManager
58  * module aliases:
59  * local aliases:
60  * overrides:
61  */
62 
63 module gtk.RecentManager;
64 
65 public  import gtkc.gtktypes;
66 
67 private import gtkc.gtk;
68 private import glib.ConstructionException;
69 private import gobject.ObjectG;
70 
71 private import gobject.Signals;
72 public  import gtkc.gdktypes;
73 
74 private import glib.Str;
75 private import gdk.Screen;
76 private import gtk.RecentInfo;
77 private import glib.ErrorG;
78 private import glib.GException;
79 private import glib.ListG;
80 
81 
82 
83 private import gobject.ObjectG;
84 
85 /**
86  * Description
87  * GtkRecentManager provides a facility for adding, removing and
88  * looking up recently used files. Each recently used file is
89  * identified by its URI, and has meta-data associated to it, like
90  * the names and command lines of the applications that have
91  * registered it, the number of time each application has registered
92  * the same file, the mime type of the file and whether the file
93  * should be displayed only by the applications that have
94  * registered it.
95  * The GtkRecentManager acts like a database of all the recently
96  * used files. You can create new GtkRecentManager objects, but
97  * it is more efficient to use the standard recent manager for
98  * the GdkScreen so that informations about the recently used
99  * files is shared with other people using them. In case the
100  * default screen is being used, adding a new recently used
101  * file is as simple as:
102  * $(DDOC_COMMENT example)
103  * While looking up a recently used file is as simple as:
104  * $(DDOC_COMMENT example)
105  * Recently used files are supported since GTK+ 2.10.
106  */
107 public class RecentManager : ObjectG
108 {
109 	
110 	/** the main Gtk struct */
111 	protected GtkRecentManager* gtkRecentManager;
112 	
113 	
114 	public GtkRecentManager* getRecentManagerStruct()
115 	{
116 		return gtkRecentManager;
117 	}
118 	
119 	
120 	/** the main Gtk struct as a void* */
121 	protected override void* getStruct()
122 	{
123 		return cast(void*)gtkRecentManager;
124 	}
125 	
126 	/**
127 	 * Sets our main struct and passes it to the parent class
128 	 */
129 	public this (GtkRecentManager* gtkRecentManager)
130 	{
131 		super(cast(GObject*)gtkRecentManager);
132 		this.gtkRecentManager = gtkRecentManager;
133 	}
134 	
135 	protected override void setStruct(GObject* obj)
136 	{
137 		super.setStruct(obj);
138 		gtkRecentManager = cast(GtkRecentManager*)obj;
139 	}
140 	
141 	/**
142 	 */
143 	int[string] connectedSignals;
144 	
145 	void delegate(RecentManager)[] onChangedListeners;
146 	/**
147 	 * Emitted when the current recently used resources manager changes its
148 	 * contents.
149 	 * Since 2.10
150 	 */
151 	void addOnChanged(void delegate(RecentManager) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
152 	{
153 		if ( !("changed" in connectedSignals) )
154 		{
155 			Signals.connectData(
156 			getStruct(),
157 			"changed",
158 			cast(GCallback)&callBackChanged,
159 			cast(void*)this,
160 			null,
161 			connectFlags);
162 			connectedSignals["changed"] = 1;
163 		}
164 		onChangedListeners ~= dlg;
165 	}
166 	extern(C) static void callBackChanged(GtkRecentManager* recentManagerStruct, RecentManager _recentManager)
167 	{
168 		foreach ( void delegate(RecentManager) dlg ; _recentManager.onChangedListeners )
169 		{
170 			dlg(_recentManager);
171 		}
172 	}
173 	
174 	
175 	/**
176 	 * Creates a new recent manager object. Recent manager objects are used to
177 	 * handle the list of recently used resources. A GtkRecentManager object
178 	 * monitors the recently used resources list, and emits the "changed" signal
179 	 * each time something inside the list changes.
180 	 * GtkRecentManager objects are expensive: be sure to create them only when
181 	 * needed. You should use gtk_recent_manager_get_default() instead.
182 	 * Since 2.10
183 	 * Throws: ConstructionException GTK+ fails to create the object.
184 	 */
185 	public this ()
186 	{
187 		// GtkRecentManager * gtk_recent_manager_new (void);
188 		auto p = gtk_recent_manager_new();
189 		if(p is null)
190 		{
191 			throw new ConstructionException("null returned by gtk_recent_manager_new()");
192 		}
193 		this(cast(GtkRecentManager*) p);
194 	}
195 	
196 	/**
197 	 * Gets a unique instance of GtkRecentManager, that you can share
198 	 * in your application without caring about memory management. The
199 	 * returned instance will be freed when you application terminates.
200 	 * Since 2.10
201 	 * Returns: A unique GtkRecentManager. Do not ref or unref it. [transfer none]
202 	 */
203 	public static RecentManager getDefault()
204 	{
205 		// GtkRecentManager * gtk_recent_manager_get_default (void);
206 		auto p = gtk_recent_manager_get_default();
207 		
208 		if(p is null)
209 		{
210 			return null;
211 		}
212 		
213 		return ObjectG.getDObject!(RecentManager)(cast(GtkRecentManager*) p);
214 	}
215 	
216 	/**
217 	 * Warning
218 	 * gtk_recent_manager_get_for_screen has been deprecated since version 2.12 and should not be used in newly-written code. This function has been deprecated and should
219 	 *  not be used in newly written code. Calling this function is
220 	 *  equivalent to calling gtk_recent_manager_get_default().
221 	 * Gets the recent manager object associated with screen; if this
222 	 * function has not previously been called for the given screen,
223 	 * a new recent manager object will be created and associated with
224 	 * the screen. Recent manager objects are fairly expensive to create,
225 	 * so using this function is usually a better choice than calling
226 	 * gtk_recent_manager_new() and setting the screen yourself; by using
227 	 * this function a single recent manager object will be shared between
228 	 * users.
229 	 * Since 2.10
230 	 * Params:
231 	 * screen = a GdkScreen
232 	 * Returns: A unique GtkRecentManager associated with the given screen. This recent manager is associated to the with the screen and can be used as long as the screen is open. Do not ref or unref it.
233 	 */
234 	public static RecentManager getForScreen(Screen screen)
235 	{
236 		// GtkRecentManager * gtk_recent_manager_get_for_screen (GdkScreen *screen);
237 		auto p = gtk_recent_manager_get_for_screen((screen is null) ? null : screen.getScreenStruct());
238 		
239 		if(p is null)
240 		{
241 			return null;
242 		}
243 		
244 		return ObjectG.getDObject!(RecentManager)(cast(GtkRecentManager*) p);
245 	}
246 	
247 	/**
248 	 * Warning
249 	 * gtk_recent_manager_set_screen has been deprecated since version 2.12 and should not be used in newly-written code. This function has been deprecated and should
250 	 *  not be used in newly written code. Calling this function has
251 	 *  no effect.
252 	 * Sets the screen for a recent manager; the screen is used to
253 	 * track the user's currently configured recently used documents
254 	 * storage.
255 	 * Since 2.10
256 	 * Params:
257 	 * screen = a GdkScreen
258 	 */
259 	public void setScreen(Screen screen)
260 	{
261 		// void gtk_recent_manager_set_screen (GtkRecentManager *manager,  GdkScreen *screen);
262 		gtk_recent_manager_set_screen(gtkRecentManager, (screen is null) ? null : screen.getScreenStruct());
263 	}
264 	
265 	/**
266 	 * Adds a new resource, pointed by uri, into the recently used
267 	 * resources list.
268 	 * This function automatically retrieves some of the needed
269 	 * metadata and setting other metadata to common default values; it
270 	 * then feeds the data to gtk_recent_manager_add_full().
271 	 * See gtk_recent_manager_add_full() if you want to explicitly
272 	 * define the metadata for the resource pointed by uri.
273 	 * Since 2.10
274 	 * Params:
275 	 * uri = a valid URI
276 	 * Returns: TRUE if the new item was successfully added to the recently used resources list
277 	 */
278 	public int addItem(string uri)
279 	{
280 		// gboolean gtk_recent_manager_add_item (GtkRecentManager *manager,  const gchar *uri);
281 		return gtk_recent_manager_add_item(gtkRecentManager, Str.toStringz(uri));
282 	}
283 	
284 	/**
285 	 * Adds a new resource, pointed by uri, into the recently used
286 	 * resources list, using the metadata specified inside the GtkRecentData
287 	 * structure passed in recent_data.
288 	 * The passed URI will be used to identify this resource inside the
289 	 * list.
290 	 * In order to register the new recently used resource, metadata about
291 	 * the resource must be passed as well as the URI; the metadata is
292 	 * stored in a GtkRecentData structure, which must contain the MIME
293 	 * type of the resource pointed by the URI; the name of the application
294 	 * that is registering the item, and a command line to be used when
295 	 * launching the item.
296 	 * Optionally, a GtkRecentData structure might contain a UTF-8 string
297 	 * to be used when viewing the item instead of the last component of the
298 	 * URI; a short description of the item; whether the item should be
299 	 * considered private - that is, should be displayed only by the
300 	 * applications that have registered it.
301 	 * Since 2.10
302 	 * Params:
303 	 * uri = a valid URI
304 	 * recentData = metadata of the resource
305 	 * Returns: TRUE if the new item was successfully added to the recently used resources list, FALSE otherwise.
306 	 */
307 	public int addFull(string uri, GtkRecentData* recentData)
308 	{
309 		// gboolean gtk_recent_manager_add_full (GtkRecentManager *manager,  const gchar *uri,  const GtkRecentData *recent_data);
310 		return gtk_recent_manager_add_full(gtkRecentManager, Str.toStringz(uri), recentData);
311 	}
312 	
313 	/**
314 	 * Removes a resource pointed by uri from the recently used resources
315 	 * list handled by a recent manager.
316 	 * Since 2.10
317 	 * Params:
318 	 * uri = the URI of the item you wish to remove
319 	 * Returns: TRUE if the item pointed by uri has been successfully removed by the recently used resources list, and FALSE otherwise.
320 	 * Throws: GException on failure.
321 	 */
322 	public int removeItem(string uri)
323 	{
324 		// gboolean gtk_recent_manager_remove_item (GtkRecentManager *manager,  const gchar *uri,  GError **error);
325 		GError* err = null;
326 		
327 		auto p = gtk_recent_manager_remove_item(gtkRecentManager, Str.toStringz(uri), &err);
328 		
329 		if (err !is null)
330 		{
331 			throw new GException( new ErrorG(err) );
332 		}
333 		
334 		return p;
335 	}
336 	
337 	/**
338 	 * Searches for a URI inside the recently used resources list, and
339 	 * returns a structure containing informations about the resource
340 	 * like its MIME type, or its display name.
341 	 * Since 2.10
342 	 * Params:
343 	 * uri = a URI
344 	 * 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().
345 	 * Throws: GException on failure.
346 	 */
347 	public RecentInfo lookupItem(string uri)
348 	{
349 		// GtkRecentInfo * gtk_recent_manager_lookup_item (GtkRecentManager *manager,  const gchar *uri,  GError **error);
350 		GError* err = null;
351 		
352 		auto p = gtk_recent_manager_lookup_item(gtkRecentManager, Str.toStringz(uri), &err);
353 		
354 		if (err !is null)
355 		{
356 			throw new GException( new ErrorG(err) );
357 		}
358 		
359 		
360 		if(p is null)
361 		{
362 			return null;
363 		}
364 		
365 		return ObjectG.getDObject!(RecentInfo)(cast(GtkRecentInfo*) p);
366 	}
367 	
368 	/**
369 	 * Checks whether there is a recently used resource registered
370 	 * with uri inside the recent manager.
371 	 * Since 2.10
372 	 * Params:
373 	 * uri = a URI
374 	 * Returns: TRUE if the resource was found, FALSE otherwise.
375 	 */
376 	public int hasItem(string uri)
377 	{
378 		// gboolean gtk_recent_manager_has_item (GtkRecentManager *manager,  const gchar *uri);
379 		return gtk_recent_manager_has_item(gtkRecentManager, Str.toStringz(uri));
380 	}
381 	
382 	/**
383 	 * Changes the location of a recently used resource from uri to new_uri.
384 	 * Please note that this function will not affect the resource pointed
385 	 * by the URIs, but only the URI used in the recently used resources list.
386 	 * Since 2.10
387 	 * Params:
388 	 * uri = the URI of a recently used resource
389 	 * newUri = the new URI of the recently used resource, or NULL to
390 	 * remove the item pointed by uri in the list. [allow-none]
391 	 * Returns: TRUE on success.
392 	 * Throws: GException on failure.
393 	 */
394 	public int moveItem(string uri, string newUri)
395 	{
396 		// gboolean gtk_recent_manager_move_item (GtkRecentManager *manager,  const gchar *uri,  const gchar *new_uri,  GError **error);
397 		GError* err = null;
398 		
399 		auto p = gtk_recent_manager_move_item(gtkRecentManager, Str.toStringz(uri), Str.toStringz(newUri), &err);
400 		
401 		if (err !is null)
402 		{
403 			throw new GException( new ErrorG(err) );
404 		}
405 		
406 		return p;
407 	}
408 	
409 	/**
410 	 * Warning
411 	 * gtk_recent_manager_get_limit has been deprecated since version 2.22 and should not be used in newly-written code. The length of the list should be managed by the
412 	 *  view (implementing GtkRecentChooser), and not by the model (the
413 	 *  GtkRecentManager). See "limit".
414 	 * Gets the maximum number of items that the gtk_recent_manager_get_items()
415 	 * function should return.
416 	 * Since 2.10
417 	 * Returns: the number of items to return, or -1 for every item.
418 	 */
419 	public int getLimit()
420 	{
421 		// gint gtk_recent_manager_get_limit (GtkRecentManager *manager);
422 		return gtk_recent_manager_get_limit(gtkRecentManager);
423 	}
424 	
425 	/**
426 	 * Warning
427 	 * gtk_recent_manager_set_limit has been deprecated since version 2.22 and should not be used in newly-written code. The length of the list should be managed by the
428 	 *  view (implementing GtkRecentChooser), and not by the model (the
429 	 *  GtkRecentManager). See "limit".
430 	 * Sets the maximum number of item that the gtk_recent_manager_get_items()
431 	 * function should return. If limit is set to -1, then return all the
432 	 * items.
433 	 * Since 2.10
434 	 * Params:
435 	 * limit = the maximum number of items to return, or -1.
436 	 */
437 	public void setLimit(int limit)
438 	{
439 		// void gtk_recent_manager_set_limit (GtkRecentManager *manager,  gint limit);
440 		gtk_recent_manager_set_limit(gtkRecentManager, limit);
441 	}
442 	
443 	/**
444 	 * Gets the list of recently used resources.
445 	 * Since 2.10
446 	 * 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]
447 	 */
448 	public ListG getItems()
449 	{
450 		// GList * gtk_recent_manager_get_items (GtkRecentManager *manager);
451 		auto p = gtk_recent_manager_get_items(gtkRecentManager);
452 		
453 		if(p is null)
454 		{
455 			return null;
456 		}
457 		
458 		return ObjectG.getDObject!(ListG)(cast(GList*) p);
459 	}
460 	
461 	/**
462 	 * Purges every item from the recently used resources list.
463 	 * Since 2.10
464 	 * Returns: the number of items that have been removed from the recently used resources list.
465 	 * Throws: GException on failure.
466 	 */
467 	public int purgeItems()
468 	{
469 		// gint gtk_recent_manager_purge_items (GtkRecentManager *manager,  GError **error);
470 		GError* err = null;
471 		
472 		auto p = gtk_recent_manager_purge_items(gtkRecentManager, &err);
473 		
474 		if (err !is null)
475 		{
476 			throw new GException( new ErrorG(err) );
477 		}
478 		
479 		return p;
480 	}
481 }