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