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 gsv.SourceFileSaver; 26 27 private import gio.AsyncResultIF; 28 private import gio.Cancellable; 29 private import gio.File; 30 private import gio.FileIF; 31 private import glib.ConstructionException; 32 private import glib.ErrorG; 33 private import glib.GException; 34 private import gobject.ObjectG; 35 private import gsv.SourceBuffer; 36 private import gsv.SourceEncoding; 37 private import gsv.SourceFile; 38 private import gsvc.gsv; 39 public import gsvc.gsvtypes; 40 41 42 public class SourceFileSaver : ObjectG 43 { 44 /** the main Gtk struct */ 45 protected GtkSourceFileSaver* gtkSourceFileSaver; 46 47 /** Get the main Gtk struct */ 48 public GtkSourceFileSaver* getSourceFileSaverStruct() 49 { 50 return gtkSourceFileSaver; 51 } 52 53 /** the main Gtk struct as a void* */ 54 protected override void* getStruct() 55 { 56 return cast(void*)gtkSourceFileSaver; 57 } 58 59 protected override void setStruct(GObject* obj) 60 { 61 gtkSourceFileSaver = cast(GtkSourceFileSaver*)obj; 62 super.setStruct(obj); 63 } 64 65 /** 66 * Sets our main struct and passes it to the parent class. 67 */ 68 public this (GtkSourceFileSaver* gtkSourceFileSaver, bool ownedRef = false) 69 { 70 this.gtkSourceFileSaver = gtkSourceFileSaver; 71 super(cast(GObject*)gtkSourceFileSaver, ownedRef); 72 } 73 74 /** 75 */ 76 77 public static GType getType() 78 { 79 return gtk_source_file_saver_get_type(); 80 } 81 82 /** 83 * Creates a new #GtkSourceFileSaver object. The @buffer will be saved to the 84 * #GtkSourceFile's location. 85 * 86 * This constructor is suitable for a simple "save" operation, when the @file 87 * already contains a non-%NULL #GtkSourceFile:location. 88 * 89 * Params: 90 * buffer = the #GtkSourceBuffer to save. 91 * file = the #GtkSourceFile. 92 * 93 * Return: a new #GtkSourceFileSaver object. 94 * 95 * Since: 3.14 96 * 97 * Throws: ConstructionException GTK+ fails to create the object. 98 */ 99 public this(SourceBuffer buffer, SourceFile file) 100 { 101 auto p = gtk_source_file_saver_new((buffer is null) ? null : buffer.getSourceBufferStruct(), (file is null) ? null : file.getSourceFileStruct()); 102 103 if(p is null) 104 { 105 throw new ConstructionException("null returned by new"); 106 } 107 108 this(cast(GtkSourceFileSaver*) p, true); 109 } 110 111 /** 112 * Creates a new #GtkSourceFileSaver object with a target location. When the 113 * file saving is finished successfully, @target_location is set to the @file's 114 * #GtkSourceFile:location property. If an error occurs, the previous valid 115 * location is still available in #GtkSourceFile. 116 * 117 * This constructor is suitable for a "save as" operation, or for saving a new 118 * buffer for the first time. 119 * 120 * Params: 121 * buffer = the #GtkSourceBuffer to save. 122 * file = the #GtkSourceFile. 123 * targetLocation = the #GFile where to save the buffer to. 124 * 125 * Return: a new #GtkSourceFileSaver object. 126 * 127 * Since: 3.14 128 * 129 * Throws: ConstructionException GTK+ fails to create the object. 130 */ 131 public this(SourceBuffer buffer, SourceFile file, FileIF targetLocation) 132 { 133 auto p = gtk_source_file_saver_new_with_target((buffer is null) ? null : buffer.getSourceBufferStruct(), (file is null) ? null : file.getSourceFileStruct(), (targetLocation is null) ? null : targetLocation.getFileStruct()); 134 135 if(p is null) 136 { 137 throw new ConstructionException("null returned by new_with_target"); 138 } 139 140 this(cast(GtkSourceFileSaver*) p, true); 141 } 142 143 /** 144 * Return: the #GtkSourceBuffer to save. 145 * 146 * Since: 3.14 147 */ 148 public SourceBuffer getBuffer() 149 { 150 auto p = gtk_source_file_saver_get_buffer(gtkSourceFileSaver); 151 152 if(p is null) 153 { 154 return null; 155 } 156 157 return ObjectG.getDObject!(SourceBuffer)(cast(GtkSourceBuffer*) p); 158 } 159 160 /** 161 * Return: the compression type. 162 * 163 * Since: 3.14 164 */ 165 public GtkSourceCompressionType getCompressionType() 166 { 167 return gtk_source_file_saver_get_compression_type(gtkSourceFileSaver); 168 } 169 170 /** 171 * Return: the encoding. 172 * 173 * Since: 3.14 174 */ 175 public SourceEncoding getEncoding() 176 { 177 auto p = gtk_source_file_saver_get_encoding(gtkSourceFileSaver); 178 179 if(p is null) 180 { 181 return null; 182 } 183 184 return ObjectG.getDObject!(SourceEncoding)(cast(GtkSourceEncoding*) p); 185 } 186 187 /** 188 * Return: the #GtkSourceFile. 189 * 190 * Since: 3.14 191 */ 192 public SourceFile getFile() 193 { 194 auto p = gtk_source_file_saver_get_file(gtkSourceFileSaver); 195 196 if(p is null) 197 { 198 return null; 199 } 200 201 return ObjectG.getDObject!(SourceFile)(cast(GtkSourceFile*) p); 202 } 203 204 /** 205 * Return: the flags. 206 * 207 * Since: 3.14 208 */ 209 public GtkSourceFileSaverFlags getFlags() 210 { 211 return gtk_source_file_saver_get_flags(gtkSourceFileSaver); 212 } 213 214 /** 215 * Return: the #GFile where to save the buffer to. 216 * 217 * Since: 3.14 218 */ 219 public FileIF getLocation() 220 { 221 auto p = gtk_source_file_saver_get_location(gtkSourceFileSaver); 222 223 if(p is null) 224 { 225 return null; 226 } 227 228 return ObjectG.getDObject!(File, FileIF)(cast(GFile*) p); 229 } 230 231 /** 232 * Return: the newline type. 233 * 234 * Since: 3.14 235 */ 236 public GtkSourceNewlineType getNewlineType() 237 { 238 return gtk_source_file_saver_get_newline_type(gtkSourceFileSaver); 239 } 240 241 /** 242 * Saves asynchronously the buffer into the file. See the #GAsyncResult 243 * documentation to know how to use this function. 244 * 245 * Params: 246 * ioPriority = the I/O priority of the request. E.g. %G_PRIORITY_LOW, 247 * %G_PRIORITY_DEFAULT or %G_PRIORITY_HIGH. 248 * cancellable = optional #GCancellable object, %NULL to ignore. 249 * progressCallback = function to call back with 250 * progress information, or %NULL if progress information is not needed. 251 * progressCallbackData = user data to pass to @progress_callback. 252 * progressCallbackNotify = function to call on 253 * @progress_callback_data when the @progress_callback is no longer needed, or 254 * %NULL. 255 * callback = a #GAsyncReadyCallback to call when the request is 256 * satisfied. 257 * userData = user data to pass to @callback. 258 * 259 * Since: 3.14 260 */ 261 public void saveAsync(int ioPriority, Cancellable cancellable, GFileProgressCallback progressCallback, void* progressCallbackData, GDestroyNotify progressCallbackNotify, GAsyncReadyCallback callback, void* userData) 262 { 263 gtk_source_file_saver_save_async(gtkSourceFileSaver, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), progressCallback, progressCallbackData, progressCallbackNotify, callback, userData); 264 } 265 266 /** 267 * Finishes a file saving started with gtk_source_file_saver_save_async(). 268 * 269 * If the file has been saved successfully, the following #GtkSourceFile 270 * properties will be updated: the location, the encoding, the newline type and 271 * the compression type. 272 * 273 * Params: 274 * result = a #GAsyncResult. 275 * 276 * Return: whether the file was saved successfully. 277 * 278 * Since: 3.14 279 * 280 * Throws: GException on failure. 281 */ 282 public bool saveFinish(AsyncResultIF result) 283 { 284 GError* err = null; 285 286 auto p = gtk_source_file_saver_save_finish(gtkSourceFileSaver, (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 287 288 if (err !is null) 289 { 290 throw new GException( new ErrorG(err) ); 291 } 292 293 return p; 294 } 295 296 /** 297 * Sets the compression type. By default the compression type is taken from the 298 * #GtkSourceFile. 299 * 300 * Params: 301 * compressionType = the new compression type. 302 * 303 * Since: 3.14 304 */ 305 public void setCompressionType(GtkSourceCompressionType compressionType) 306 { 307 gtk_source_file_saver_set_compression_type(gtkSourceFileSaver, compressionType); 308 } 309 310 /** 311 * Sets the encoding. If @encoding is %NULL, the UTF-8 encoding will be set. 312 * By default the encoding is taken from the #GtkSourceFile. 313 * 314 * Params: 315 * encoding = the new encoding, or %NULL for UTF-8. 316 * 317 * Since: 3.14 318 */ 319 public void setEncoding(SourceEncoding encoding) 320 { 321 gtk_source_file_saver_set_encoding(gtkSourceFileSaver, (encoding is null) ? null : encoding.getSourceEncodingStruct()); 322 } 323 324 public void setFlags(GtkSourceFileSaverFlags flags) 325 { 326 gtk_source_file_saver_set_flags(gtkSourceFileSaver, flags); 327 } 328 329 /** 330 * Sets the newline type. By default the newline type is taken from the 331 * #GtkSourceFile. 332 * 333 * Params: 334 * newlineType = the new newline type. 335 * 336 * Since: 3.14 337 */ 338 public void setNewlineType(GtkSourceNewlineType newlineType) 339 { 340 gtk_source_file_saver_set_newline_type(gtkSourceFileSaver, newlineType); 341 } 342 }