1 module webkit2.FaviconDatabase; 2 3 private import cairo.Surface; 4 private import gio.AsyncResultIF; 5 private import gio.Cancellable; 6 private import glib.ErrorG; 7 private import glib.GException; 8 private import glib.Str; 9 private import gobject.ObjectG; 10 private import gobject.Signals; 11 private import std.algorithm; 12 private import webkit2.c.functions; 13 public import webkit2.c.types; 14 15 16 /** 17 * #WebKitFaviconDatabase provides access to the icons associated with 18 * web sites. 19 * 20 * WebKit will automatically look for available icons in <link> 21 * elements on opened pages as well as an existing favicon.ico and 22 * load the images found into a memory cache if possible. That cache 23 * is frozen to an on-disk database for persistence. 24 * 25 * If #WebKitSettings:enable-private-browsing is %TRUE, new icons 26 * won't be added to the on-disk database and no existing icons will 27 * be deleted from it. Nevertheless, WebKit will still store them in 28 * the in-memory cache during the current execution. 29 */ 30 public class FaviconDatabase : ObjectG 31 { 32 /** the main Gtk struct */ 33 protected WebKitFaviconDatabase* webKitFaviconDatabase; 34 35 /** Get the main Gtk struct */ 36 public WebKitFaviconDatabase* getFaviconDatabaseStruct(bool transferOwnership = false) 37 { 38 if (transferOwnership) 39 ownedRef = false; 40 return webKitFaviconDatabase; 41 } 42 43 /** the main Gtk struct as a void* */ 44 protected override void* getStruct() 45 { 46 return cast(void*)webKitFaviconDatabase; 47 } 48 49 /** 50 * Sets our main struct and passes it to the parent class. 51 */ 52 public this (WebKitFaviconDatabase* webKitFaviconDatabase, bool ownedRef = false) 53 { 54 this.webKitFaviconDatabase = webKitFaviconDatabase; 55 super(cast(GObject*)webKitFaviconDatabase, ownedRef); 56 } 57 58 59 /** */ 60 public static GType getType() 61 { 62 return webkit_favicon_database_get_type(); 63 } 64 65 /** 66 * Clears all icons from the database. 67 */ 68 public void clear() 69 { 70 webkit_favicon_database_clear(webKitFaviconDatabase); 71 } 72 73 /** 74 * Asynchronously obtains a #cairo_surface_t of the favicon for the 75 * given page URI. It returns the cached icon if it's in the database 76 * asynchronously waiting for the icon to be read from the database. 77 * 78 * This is an asynchronous method. When the operation is finished, callback will 79 * be invoked. You can then call webkit_favicon_database_get_favicon_finish() 80 * to get the result of the operation. 81 * 82 * You must call webkit_web_context_set_favicon_database_directory() for 83 * the #WebKitWebContext associated with this #WebKitFaviconDatabase 84 * before attempting to use this function; otherwise, 85 * webkit_favicon_database_get_favicon_finish() will return 86 * %WEBKIT_FAVICON_DATABASE_ERROR_NOT_INITIALIZED. 87 * 88 * Params: 89 * pageUri = URI of the page for which we want to retrieve the favicon 90 * cancellable = A #GCancellable or %NULL. 91 * callback = A #GAsyncReadyCallback to call when the request is 92 * satisfied or %NULL if you don't care about the result. 93 * userData = The data to pass to @callback. 94 */ 95 public void getFavicon(string pageUri, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 96 { 97 webkit_favicon_database_get_favicon(webKitFaviconDatabase, Str.toStringz(pageUri), (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 98 } 99 100 /** 101 * Finishes an operation started with webkit_favicon_database_get_favicon(). 102 * 103 * Params: 104 * result = A #GAsyncResult obtained from the #GAsyncReadyCallback passed to webkit_favicon_database_get_favicon() 105 * 106 * Returns: a new reference to a #cairo_surface_t, or 107 * %NULL in case of error. 108 * 109 * Throws: GException on failure. 110 */ 111 public Surface getFaviconFinish(AsyncResultIF result) 112 { 113 GError* err = null; 114 115 auto __p = webkit_favicon_database_get_favicon_finish(webKitFaviconDatabase, (result is null) ? null : result.getAsyncResultStruct(), &err); 116 117 if (err !is null) 118 { 119 throw new GException( new ErrorG(err) ); 120 } 121 122 if(__p is null) 123 { 124 return null; 125 } 126 127 return new Surface(cast(cairo_surface_t*) __p); 128 } 129 130 /** 131 * Obtains the URI of the favicon for the given @page_uri. 132 * 133 * Params: 134 * pageUri = URI of the page containing the icon 135 * 136 * Returns: a newly allocated URI for the favicon, or %NULL if the 137 * database doesn't have a favicon for @page_uri. 138 */ 139 public string getFaviconUri(string pageUri) 140 { 141 auto retStr = webkit_favicon_database_get_favicon_uri(webKitFaviconDatabase, Str.toStringz(pageUri)); 142 143 scope(exit) Str.freeString(retStr); 144 return Str.toString(retStr); 145 } 146 147 /** 148 * This signal is emitted when the favicon URI of @page_uri has 149 * been changed to @favicon_uri in the database. You can connect 150 * to this signal and call webkit_favicon_database_get_favicon() 151 * to get the favicon. If you are interested in the favicon of a 152 * #WebKitWebView it's easier to use the #WebKitWebView:favicon 153 * property. See webkit_web_view_get_favicon() for more details. 154 * 155 * Params: 156 * pageUri = the URI of the Web page containing the icon 157 * faviconUri = the URI of the favicon 158 */ 159 gulong addOnFaviconChanged(void delegate(string, string, FaviconDatabase) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 160 { 161 return Signals.connect(this, "favicon-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 162 } 163 }