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 gio.FileIOStream; 26 27 private import gio.AsyncResultIF; 28 private import gio.Cancellable; 29 private import gio.FileInfo; 30 private import gio.IOStream; 31 private import gio.SeekableIF; 32 private import gio.SeekableT; 33 private import gio.c.functions; 34 public import gio.c.types; 35 private import glib.ErrorG; 36 private import glib.GException; 37 private import glib.Str; 38 private import gobject.ObjectG; 39 public import gtkc.giotypes; 40 41 42 /** 43 * GFileIOStream provides io streams that both read and write to the same 44 * file handle. 45 * 46 * GFileIOStream implements #GSeekable, which allows the io 47 * stream to jump to arbitrary positions in the file and to truncate 48 * the file, provided the filesystem of the file supports these 49 * operations. 50 * 51 * To find the position of a file io stream, use 52 * g_seekable_tell(). 53 * 54 * To find out if a file io stream supports seeking, use g_seekable_can_seek(). 55 * To position a file io stream, use g_seekable_seek(). 56 * To find out if a file io stream supports truncating, use 57 * g_seekable_can_truncate(). To truncate a file io 58 * stream, use g_seekable_truncate(). 59 * 60 * The default implementation of all the #GFileIOStream operations 61 * and the implementation of #GSeekable just call into the same operations 62 * on the output stream. 63 * 64 * Since: 2.22 65 */ 66 public class FileIOStream : IOStream, SeekableIF 67 { 68 /** the main Gtk struct */ 69 protected GFileIOStream* gFileIOStream; 70 71 /** Get the main Gtk struct */ 72 public GFileIOStream* getFileIOStreamStruct(bool transferOwnership = false) 73 { 74 if (transferOwnership) 75 ownedRef = false; 76 return gFileIOStream; 77 } 78 79 /** the main Gtk struct as a void* */ 80 protected override void* getStruct() 81 { 82 return cast(void*)gFileIOStream; 83 } 84 85 /** 86 * Sets our main struct and passes it to the parent class. 87 */ 88 public this (GFileIOStream* gFileIOStream, bool ownedRef = false) 89 { 90 this.gFileIOStream = gFileIOStream; 91 super(cast(GIOStream*)gFileIOStream, ownedRef); 92 } 93 94 // add the Seekable capabilities 95 mixin SeekableT!(GFileIOStream); 96 97 98 /** */ 99 public static GType getType() 100 { 101 return g_file_io_stream_get_type(); 102 } 103 104 /** 105 * Gets the entity tag for the file when it has been written. 106 * This must be called after the stream has been written 107 * and closed, as the etag can change while writing. 108 * 109 * Returns: the entity tag for the stream. 110 * 111 * Since: 2.22 112 */ 113 public string getEtag() 114 { 115 auto retStr = g_file_io_stream_get_etag(gFileIOStream); 116 117 scope(exit) Str.freeString(retStr); 118 return Str.toString(retStr); 119 } 120 121 /** 122 * Queries a file io stream for the given @attributes. 123 * This function blocks while querying the stream. For the asynchronous 124 * version of this function, see g_file_io_stream_query_info_async(). 125 * While the stream is blocked, the stream will set the pending flag 126 * internally, and any other operations on the stream will fail with 127 * %G_IO_ERROR_PENDING. 128 * 129 * Can fail if the stream was already closed (with @error being set to 130 * %G_IO_ERROR_CLOSED), the stream has pending operations (with @error being 131 * set to %G_IO_ERROR_PENDING), or if querying info is not supported for 132 * the stream's interface (with @error being set to %G_IO_ERROR_NOT_SUPPORTED). I 133 * all cases of failure, %NULL will be returned. 134 * 135 * If @cancellable is not %NULL, then the operation can be cancelled by 136 * triggering the cancellable object from another thread. If the operation 137 * was cancelled, the error %G_IO_ERROR_CANCELLED will be set, and %NULL will 138 * be returned. 139 * 140 * Params: 141 * attributes = a file attribute query string. 142 * cancellable = optional #GCancellable object, %NULL to ignore. 143 * 144 * Returns: a #GFileInfo for the @stream, or %NULL on error. 145 * 146 * Since: 2.22 147 * 148 * Throws: GException on failure. 149 */ 150 public FileInfo queryInfo(string attributes, Cancellable cancellable) 151 { 152 GError* err = null; 153 154 auto __p = g_file_io_stream_query_info(gFileIOStream, Str.toStringz(attributes), (cancellable is null) ? null : cancellable.getCancellableStruct(), &err); 155 156 if (err !is null) 157 { 158 throw new GException( new ErrorG(err) ); 159 } 160 161 if(__p is null) 162 { 163 return null; 164 } 165 166 return ObjectG.getDObject!(FileInfo)(cast(GFileInfo*) __p, true); 167 } 168 169 /** 170 * Asynchronously queries the @stream for a #GFileInfo. When completed, 171 * @callback will be called with a #GAsyncResult which can be used to 172 * finish the operation with g_file_io_stream_query_info_finish(). 173 * 174 * For the synchronous version of this function, see 175 * g_file_io_stream_query_info(). 176 * 177 * Params: 178 * attributes = a file attribute query string. 179 * ioPriority = the [I/O priority][gio-GIOScheduler] of the request 180 * cancellable = optional #GCancellable object, %NULL to ignore. 181 * callback = callback to call when the request is satisfied 182 * userData = the data to pass to callback function 183 * 184 * Since: 2.22 185 */ 186 public void queryInfoAsync(string attributes, int ioPriority, Cancellable cancellable, GAsyncReadyCallback callback, void* userData) 187 { 188 g_file_io_stream_query_info_async(gFileIOStream, Str.toStringz(attributes), ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), callback, userData); 189 } 190 191 /** 192 * Finalizes the asynchronous query started 193 * by g_file_io_stream_query_info_async(). 194 * 195 * Params: 196 * result = a #GAsyncResult. 197 * 198 * Returns: A #GFileInfo for the finished query. 199 * 200 * Since: 2.22 201 * 202 * Throws: GException on failure. 203 */ 204 public FileInfo queryInfoFinish(AsyncResultIF result) 205 { 206 GError* err = null; 207 208 auto __p = g_file_io_stream_query_info_finish(gFileIOStream, (result is null) ? null : result.getAsyncResultStruct(), &err); 209 210 if (err !is null) 211 { 212 throw new GException( new ErrorG(err) ); 213 } 214 215 if(__p is null) 216 { 217 return null; 218 } 219 220 return ObjectG.getDObject!(FileInfo)(cast(GFileInfo*) __p, true); 221 } 222 }