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