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 gdk.ContentProvider; 26 27 private import gdk.ContentFormats; 28 private import gdk.c.functions; 29 public import gdk.c.types; 30 private import gio.AsyncResultIF; 31 private import gio.Cancellable; 32 private import gio.OutputStream; 33 private import glib.Bytes; 34 private import glib.ConstructionException; 35 private import glib.ErrorG; 36 private import glib.GException; 37 private import glib.Str; 38 private import gobject.ObjectG; 39 private import gobject.Signals; 40 private import gobject.Value; 41 private import std.algorithm; 42 43 44 /** 45 * A `GdkContentProvider` is used to provide content for the clipboard or 46 * for drag-and-drop operations in a number of formats. 47 * 48 * To create a `GdkContentProvider`, use [ctor@Gdk.ContentProvider.new_for_value] 49 * or [ctor@Gdk.ContentProvider.new_for_bytes]. 50 * 51 * GDK knows how to handle common text and image formats out-of-the-box. See 52 * [class@Gdk.ContentSerializer] and [class@Gdk.ContentDeserializer] if you want 53 * to add support for application-specific data formats. 54 */ 55 public class ContentProvider : ObjectG 56 { 57 /** the main Gtk struct */ 58 protected GdkContentProvider* gdkContentProvider; 59 60 /** Get the main Gtk struct */ 61 public GdkContentProvider* getContentProviderStruct(bool transferOwnership = false) 62 { 63 if (transferOwnership) 64 ownedRef = false; 65 return gdkContentProvider; 66 } 67 68 /** the main Gtk struct as a void* */ 69 protected override void* getStruct() 70 { 71 return cast(void*)gdkContentProvider; 72 } 73 74 /** 75 * Sets our main struct and passes it to the parent class. 76 */ 77 public this (GdkContentProvider* gdkContentProvider, bool ownedRef = false) 78 { 79 this.gdkContentProvider = gdkContentProvider; 80 super(cast(GObject*)gdkContentProvider, ownedRef); 81 } 82 83 84 /** */ 85 public static GType getType() 86 { 87 return gdk_content_provider_get_type(); 88 } 89 90 /** 91 * Create a content provider that provides the given @bytes as data for 92 * the given @mime_type. 93 * 94 * Params: 95 * mimeType = the mime type 96 * bytes = a `GBytes` with the data for @mime_type 97 * 98 * Returns: a new `GdkContentProvider` 99 * 100 * Throws: ConstructionException GTK+ fails to create the object. 101 */ 102 public this(string mimeType, Bytes bytes) 103 { 104 auto __p = gdk_content_provider_new_for_bytes(Str.toStringz(mimeType), (bytes is null) ? null : bytes.getBytesStruct()); 105 106 if(__p is null) 107 { 108 throw new ConstructionException("null returned by new_for_bytes"); 109 } 110 111 this(cast(GdkContentProvider*) __p, true); 112 } 113 114 /** 115 * Create a content provider that provides the given @value. 116 * 117 * Params: 118 * value = a `GValue` 119 * 120 * Returns: a new `GdkContentProvider` 121 * 122 * Throws: ConstructionException GTK+ fails to create the object. 123 */ 124 public this(Value value) 125 { 126 auto __p = gdk_content_provider_new_for_value((value is null) ? null : value.getValueStruct()); 127 128 if(__p is null) 129 { 130 throw new ConstructionException("null returned by new_for_value"); 131 } 132 133 this(cast(GdkContentProvider*) __p, true); 134 } 135 136 /** 137 * Creates a content provider that represents all the given @providers. 138 * 139 * Whenever data needs to be written, the union provider will try the given 140 * @providers in the given order and the first one supporting a format will 141 * be chosen to provide it. 142 * 143 * This allows an easy way to support providing data in different formats. 144 * For example, an image may be provided by its file and by the image 145 * contents with a call such as 146 * ```c 147 * gdk_content_provider_new_union ((GdkContentProvider *[2]) { 148 * gdk_content_provider_new_typed (G_TYPE_FILE, file), 149 * gdk_content_provider_new_typed (G_TYPE_TEXTURE, texture) 150 * }, 2); 151 * ``` 152 * 153 * Params: 154 * providers = The #GdkContentProviders to present the union of 155 * 156 * Returns: a new `GdkContentProvider` 157 * 158 * Throws: ConstructionException GTK+ fails to create the object. 159 */ 160 public this(ContentProvider[] providers) 161 { 162 GdkContentProvider*[] providersArray = new GdkContentProvider*[providers.length]; 163 for ( int i = 0; i < providers.length; i++ ) 164 { 165 providersArray[i] = providers[i].getContentProviderStruct(); 166 } 167 168 auto __p = gdk_content_provider_new_union(providersArray.ptr, cast(size_t)providers.length); 169 170 if(__p is null) 171 { 172 throw new ConstructionException("null returned by new_union"); 173 } 174 175 this(cast(GdkContentProvider*) __p, true); 176 } 177 178 /** 179 * Emits the ::content-changed signal. 180 */ 181 public void contentChanged() 182 { 183 gdk_content_provider_content_changed(gdkContentProvider); 184 } 185 186 /** 187 * Gets the contents of @provider stored in @value. 188 * 189 * The @value will have been initialized to the `GType` the value should be 190 * provided in. This given `GType` does not need to be listed in the formats 191 * returned by [method@Gdk.ContentProvider.ref_formats]. However, if the 192 * given `GType` is not supported, this operation can fail and 193 * #G_IO_ERROR_NOT_SUPPORTED will be reported. 194 * 195 * Params: 196 * value = the `GValue` to fill 197 * 198 * Returns: %TRUE if the value was set successfully. Otherwise 199 * @error will be set to describe the failure. 200 * 201 * Throws: GException on failure. 202 */ 203 public bool getValue(Value value) 204 { 205 GError* err = null; 206 207 auto __p = gdk_content_provider_get_value(gdkContentProvider, (value is null) ? null : value.getValueStruct(), &err) != 0; 208 209 if (err !is null) 210 { 211 throw new GException( new ErrorG(err) ); 212 } 213 214 return __p; 215 } 216 217 /** 218 * Gets the formats that the provider can provide its current contents in. 219 * 220 * Returns: The formats of the provider 221 */ 222 public ContentFormats refFormats() 223 { 224 auto __p = gdk_content_provider_ref_formats(gdkContentProvider); 225 226 if(__p is null) 227 { 228 return null; 229 } 230 231 return ObjectG.getDObject!(ContentFormats)(cast(GdkContentFormats*) __p, true); 232 } 233 234 /** 235 * Gets the formats that the provider suggests other applications to store 236 * the data in. 237 * 238 * An example of such an application would be a clipboard manager. 239 * 240 * This can be assumed to be a subset of [method@Gdk.ContentProvider.ref_formats]. 241 * 242 * Returns: The storable formats of the provider 243 */ 244 public ContentFormats refStorableFormats() 245 { 246 auto __p = gdk_content_provider_ref_storable_formats(gdkContentProvider); 247 248 if(__p is null) 249 { 250 return null; 251 } 252 253 return ObjectG.getDObject!(ContentFormats)(cast(GdkContentFormats*) __p, true); 254 } 255 256 /** 257 * Asynchronously writes the contents of @provider to @stream in the given 258 * @mime_type. 259 * 260 * When the operation is finished @callback will be called. You must then call 261 * [method@Gdk.ContentProvider.write_mime_type_finish] to get the result 262 * of the operation. 263 * 264 * The given mime type does not need to be listed in the formats returned by 265 * [method@Gdk.ContentProvider.ref_formats]. However, if the given `GType` is 266 * not supported, #G_IO_ERROR_NOT_SUPPORTED will be reported. 267 * 268 * The given @stream will not be closed. 269 * 270 * Params: 271 * mimeType = the mime type to provide the data in 272 * stream = the `GOutputStream` to write to 273 * ioPriority = I/O priority of the request. 274 * cancellable = optional `GCancellable` object, %NULL to ignore. 275 * callback = callback to call when the request is satisfied 276 * userData = the data to pass to callback function 277 */ 278 public void writeMimeTypeAsync(string mimeType, OutputStream stream, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 279 { 280 gdk_content_provider_write_mime_type_async(gdkContentProvider, Str.toStringz(mimeType), (stream is null) ? null : stream.getOutputStreamStruct(), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 281 } 282 283 /** 284 * Finishes an asynchronous write operation. 285 * 286 * See [method@Gdk.ContentProvider.write_mime_type_async]. 287 * 288 * Params: 289 * result = a `GAsyncResult` 290 * 291 * Returns: %TRUE if the operation was completed successfully. Otherwise 292 * @error will be set to describe the failure. 293 * 294 * Throws: GException on failure. 295 */ 296 public bool writeMimeTypeFinish(AsyncResultIF result) 297 { 298 GError* err = null; 299 300 auto __p = gdk_content_provider_write_mime_type_finish(gdkContentProvider, (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 301 302 if (err !is null) 303 { 304 throw new GException( new ErrorG(err) ); 305 } 306 307 return __p; 308 } 309 310 /** 311 * Emitted whenever the content provided by this provider has changed. 312 */ 313 gulong addOnContentChanged(void delegate(ContentProvider) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 314 { 315 return Signals.connect(this, "content-changed", dlg, connectFlags ^ ConnectFlags.SWAPPED); 316 } 317 }