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