GtefFileSaver: Gtef 2 Reference Manual

## GtefFileSaver GtefFileSaver — Save a GtefBuffer into a file |

## Functions

GtefFileSaver * | gtef_file_saver_new ()
GtefFileSaver * | gtef_file_saver_new_with_target ()
GtefBuffer * | gtef_file_saver_get_buffer ()
GtefFile * | gtef_file_saver_get_file ()
GFile * | gtef_file_saver_get_location ()
void | gtef_file_saver_set_encoding ()
const GtefEncoding * | gtef_file_saver_get_encoding ()
void | gtef_file_saver_set_newline_type ()
GtefNewlineType | gtef_file_saver_get_newline_type ()
void | gtef_file_saver_set_compression_type ()
GtefCompressionType | gtef_file_saver_get_compression_type ()
void | gtef_file_saver_set_flags ()
GtefFileSaverFlags | gtef_file_saver_get_flags ()
void | gtef_file_saver_save_async ()
gboolean | gtef_file_saver_save_finish ()

## Properties

GtkSourceBuffer * | buffer | Read / Write / Construct Only
GtkSourceCompressionType | compression-type | Read / Write / Construct
GtefEncoding * | encoding | Read / Write / Construct
GtefFile * | file | Read / Write / Construct Only
GtefFileSaverFlags | flags | Read / Write / Construct
GFile * | location | Read / Write / Construct Only
GtkSourceNewlineType | newline-type | Read / Write / Construct

## Types and Values

| GtefFileSaver
#define | GTEF_FILE_SAVER_ERROR
enum | GtefFileSaverError
enum | GtefFileSaverFlags

## Object Hierarchy

        GEnum
        ╰── GtefFileSaverError
        GFlags
        ╰── GtefFileSaverFlags
        GObject
        ╰── GtefFileSaver

## Includes

    #include <gtef/gtef.h>

## Description

A GtefFileSaver object permits to save a GtefBuffer into a GFile.

A file saver should be used only for one save operation, including errors handling. If an error occurs, you can reconfigure the saver and relaunch the operation with `gtef_file_saver_save_async()`.

GtefFileSaver is a fork of GtkSourceFileSaver, the code has been a little improved (but no major changes). See the description of GtefFile for more background on why a fork was needed.

## Functions

### gtef_file_saver_new ()

    GtefFileSaver *
    gtef_file_saver_new (GtefBuffer *buffer,
                         GtefFile *file);

Creates a new GtefFileSaver object. The `buffer` will be saved to the GtefFile's location.

This constructor is suitable for a simple "save" operation, when the `file` already contains a non-`NULL` “location”.

#### Parameters

buffer | the GtefBuffer to save. |
file | the GtefFile. |

#### Returns

a new GtefFileSaver object.

Since: 1.0

### gtef_file_saver_new_with_target ()

    GtefFileSaver *
    gtef_file_saver_new_with_target (GtefBuffer *buffer,
                                     GtefFile *file,
                                     GFile *target_location);

Creates a new GtefFileSaver object with a target location. When the file saving is finished successfully, `target_location` is set to the `file` 's “location” property. If an error occurs, the previous valid location is still available in GtefFile.

This constructor adds `GTEF_FILE_SAVER_FLAGS_IGNORE_MODIFICATION_TIME` to the “flags” property.

This constructor is suitable for a "save as" operation, or for saving a new buffer for the first time.

#### Parameters

buffer | the GtefBuffer to save. |
file | the GtefFile. |
target_location | the GFile where to save the buffer to. |

#### Returns

a new GtefFileSaver object.

Since: 1.0

### gtef_file_saver_get_buffer ()

    GtefBuffer *
    gtef_file_saver_get_buffer (GtefFileSaver *saver);

#### Parameters

saver | a GtefFileSaver. |

#### Returns

the GtefBuffer to save.

[transfer none]

Since: 1.0

### gtef_file_saver_get_file ()

    GtefFile *
    gtef_file_saver_get_file (GtefFileSaver *saver);

#### Parameters

saver | a GtefFileSaver. |

#### Returns

the GtefFile.

[transfer none]

Since: 1.0

### gtef_file_saver_get_location ()

    GFile *
    gtef_file_saver_get_location (GtefFileSaver *saver);

#### Parameters

saver | a GtefFileSaver. |

#### Returns

the GFile where to save the buffer to.

[transfer none]

Since: 1.0

### gtef_file_saver_set_encoding ()

    void
    gtef_file_saver_set_encoding (GtefFileSaver *saver,
                                  const GtefEncoding *encoding);

Sets the encoding. If `encoding` is `NULL`, the UTF-8 encoding will be set. By default the encoding is taken from the GtefFile.

#### Parameters

saver | a GtefFileSaver. |
encoding | the new encoding, or `NULL` for UTF-8. | [allow-none]

Since: 1.0

### gtef_file_saver_get_encoding ()

    const GtefEncoding *
    gtef_file_saver_get_encoding (GtefFileSaver *saver);

#### Parameters

saver | a GtefFileSaver. |

#### Returns

the encoding.

Since: 1.0

### gtef_file_saver_set_newline_type ()

    void
    gtef_file_saver_set_newline_type (GtefFileSaver *saver,
                                      GtefNewlineType newline_type);

Sets the newline type. By default the newline type is taken from the GtefFile.

#### Parameters

saver | a GtefFileSaver. |
newline_type | the new newline type. |

Since: 1.0

### gtef_file_saver_get_newline_type ()

    GtefNewlineType
    gtef_file_saver_get_newline_type (GtefFileSaver *saver);

#### Parameters

saver | a GtefFileSaver. |

#### Returns

the newline type.

Since: 1.0

### gtef_file_saver_set_compression_type ()

    void
    gtef_file_saver_set_compression_type (GtefFileSaver *saver,
                                          GtefCompressionType compression_type);

Sets the compression type. By default the compression type is taken from the GtefFile.

#### Parameters

saver | a GtefFileSaver. |
compression_type | the new compression type. |

Since: 1.0

### gtef_file_saver_get_compression_type ()

    GtefCompressionType
    gtef_file_saver_get_compression_type (GtefFileSaver *saver);

#### Parameters

saver | a GtefFileSaver. |

#### Returns

the compression type.

Since: 1.0

### gtef_file_saver_set_flags ()

    void
    gtef_file_saver_set_flags (GtefFileSaver *saver,
                               GtefFileSaverFlags flags);

#### Parameters

saver | a GtefFileSaver. |
flags | the new flags. |

Since: 1.0

### gtef_file_saver_get_flags ()

    GtefFileSaverFlags
    gtef_file_saver_get_flags (GtefFileSaver *saver);

#### Parameters

saver | a GtefFileSaver. |

#### Returns

the flags.

Since: 1.0

### gtef_file_saver_save_async ()

    void
    gtef_file_saver_save_async (GtefFileSaver *saver,
                                gint io_priority,
                                GCancellable *cancellable,
                                GFileProgressCallback progress_callback,
                                gpointer progress_callback_data,
                                GDestroyNotify progress_callback_notify,
                                GAsyncReadyCallback callback,
                                gpointer user_data);

Saves asynchronously the buffer into the file. See the GAsyncResult documentation to know how to use this function.

#### Parameters

saver | a GtefFileSaver. |
io_priority | the I/O priority of the request. E.g. `G_PRIORITY_LOW`, `G_PRIORITY_DEFAULT` or `G_PRIORITY_HIGH`. |
cancellable | optional GCancellable object, `NULL` to ignore. | [nullable]
progress_callback | function to call back with progress information, or `NULL` if progress information is not needed. | [scope notified][nullable]
progress_callback_data | user data to pass to `progress_callback` . | [closure]
progress_callback_notify | function to call on `progress_callback_data` when the `progress_callback` is no longer needed, or `NULL`. | [nullable]
callback | a GAsyncReadyCallback to call when the request is satisfied. | [scope async]
user_data | user data to pass to `callback` . |

Since: 1.0

### gtef_file_saver_save_finish ()

    gboolean
    gtef_file_saver_save_finish (GtefFileSaver *saver,
                                 GAsyncResult *result,
                                 GError **error);

Finishes a file saving started with `gtef_file_saver_save_async()`.

If the file has been saved successfully, the following GtefFile properties will be updated: the location, the encoding, the newline type and the compression type.

gtk_text_buffer_set_modified() is called with `FALSE` if the file has been saved successfully.

#### Parameters

saver | a GtefFileSaver. |
result | a GAsyncResult. |
error | a GError, or `NULL`. |

#### Returns

whether the file was saved successfully.

Since: 1.0

## Types and Values

### GtefFileSaver

    typedef struct _GtefFileSaver GtefFileSaver;

### GTEF_FILE_SAVER_ERROR

    #define GTEF_FILE_SAVER_ERROR gtef_file_saver_error_quark ()

### enum GtefFileSaverError

An error code used with the `GTEF_FILE_SAVER_ERROR` domain.

#### Members

GTEF_FILE_SAVER_ERROR_INVALID_CHARS | The buffer contains invalid characters. |
GTEF_FILE_SAVER_ERROR_EXTERNALLY_MODIFIED | The file is externally modified. |

Since: 1.0

### enum GtefFileSaverFlags

Flags to define the behavior of a GtefFileSaver.

#### Members

GTEF_FILE_SAVER_FLAGS_NONE | No flags. |
GTEF_FILE_SAVER_FLAGS_IGNORE_INVALID_CHARS | Ignore invalid characters. |
GTEF_FILE_SAVER_FLAGS_IGNORE_MODIFICATION_TIME | Save file despite external modifications. |
GTEF_FILE_SAVER_FLAGS_CREATE_BACKUP | Create a backup before saving the file. |

Since: 1.0

## Property Details

### The `“buffer”` property

      “buffer”                   GtkSourceBuffer *

The GtefBuffer to save. The GtefFileSaver object has a weak reference to the buffer.

Flags: Read / Write / Construct Only

Since: 1.0

### The `“compression-type”` property

      “compression-type”         GtkSourceCompressionType

The compression type.

Flags: Read / Write / Construct

Default value: GTK_SOURCE_COMPRESSION_TYPE_NONE

Since: 1.0

### The `“encoding”` property

      “encoding”                 GtefEncoding *

The file's encoding.

Flags: Read / Write / Construct

Since: 1.0

### The `“file”` property

      “file”                     GtefFile *

The GtefFile. The GtefFileSaver object has a weak reference to the file.

Flags: Read / Write / Construct Only

Since: 1.0

### The `“flags”` property

      “flags”                    GtefFileSaverFlags

File saving flags.

Flags: Read / Write / Construct

Since: 1.0

### The `“location”` property

      “location”                 GFile *

The GFile where to save the buffer. By default the location is taken from the GtefFile at construction time.

Flags: Read / Write / Construct Only

Since: 1.0

### The `“newline-type”` property

      “newline-type”             GtkSourceNewlineType

The newline type.

Flags: Read / Write / Construct

Default value: GTK_SOURCE_NEWLINE_TYPE_LF

Since: 1.0

## See Also

GtefFile, GtefFileLoader