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