[tepl] Dumb FileSaver: remove even more things
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tepl] Dumb FileSaver: remove even more things
- Date: Tue, 12 May 2020 15:03:15 +0000 (UTC)
commit 2e6e8ce657de5a77a170e9c4c73092fe566e44cd
Author: Sébastien Wilmet <swilmet gnome org>
Date: Tue May 12 16:54:35 2020 +0200
Dumb FileSaver: remove even more things
docs/reference/tepl-sections.txt | 7 --
tepl/tepl-file-saver.c | 147 ++++++---------------------------------
tepl/tepl-file-saver.h | 51 ++------------
tepl/tepl-tab-saving.c | 3 -
4 files changed, 30 insertions(+), 178 deletions(-)
---
diff --git a/docs/reference/tepl-sections.txt b/docs/reference/tepl-sections.txt
index 8a6860b..79b1ce5 100644
--- a/docs/reference/tepl-sections.txt
+++ b/docs/reference/tepl-sections.txt
@@ -181,8 +181,6 @@ tepl_file_loader_error_quark
<SECTION>
<FILE>file-saver</FILE>
TeplFileSaver
-TEPL_FILE_SAVER_ERROR
-TeplFileSaverError
TeplFileSaverFlags
<SUBSECTION>
tepl_file_saver_new
@@ -192,8 +190,6 @@ tepl_file_saver_get_file
tepl_file_saver_get_location
tepl_file_saver_set_newline_type
tepl_file_saver_get_newline_type
-tepl_file_saver_set_compression_type
-tepl_file_saver_get_compression_type
tepl_file_saver_set_flags
tepl_file_saver_get_flags
tepl_file_saver_save_async
@@ -208,10 +204,7 @@ TEPL_TYPE_FILE_SAVER
TeplFileSaverClass
TeplFileSaverPrivate
tepl_file_saver_get_type
-tepl_file_saver_error_quark
-TEPL_TYPE_FILE_SAVER_ERROR
TEPL_TYPE_FILE_SAVER_FLAGS
-tepl_file_saver_error_get_type
tepl_file_saver_flags_get_type
</SECTION>
diff --git a/tepl/tepl-file-saver.c b/tepl/tepl-file-saver.c
index 7dd51e8..66edb86 100644
--- a/tepl/tepl-file-saver.c
+++ b/tepl/tepl-file-saver.c
@@ -28,7 +28,6 @@ enum
PROP_FILE,
PROP_LOCATION,
PROP_NEWLINE_TYPE,
- PROP_COMPRESSION_TYPE,
PROP_FLAGS,
N_PROPERTIES
};
@@ -50,10 +49,9 @@ struct _TeplFileSaverPrivate
GFile *location;
TeplNewlineType newline_type;
- TeplCompressionType compression_type;
TeplFileSaverFlags flags;
- GTask *task;
+ guint is_saving : 1;
};
typedef struct _TaskData TaskData;
@@ -107,10 +105,6 @@ tepl_file_saver_set_property (GObject *object,
tepl_file_saver_set_newline_type (saver, g_value_get_enum (value));
break;
- case PROP_COMPRESSION_TYPE:
- tepl_file_saver_set_compression_type (saver, g_value_get_enum (value));
- break;
-
case PROP_FLAGS:
tepl_file_saver_set_flags (saver, g_value_get_flags (value));
break;
@@ -147,10 +141,6 @@ tepl_file_saver_get_property (GObject *object,
g_value_set_enum (value, saver->priv->newline_type);
break;
- case PROP_COMPRESSION_TYPE:
- g_value_set_enum (value, saver->priv->compression_type);
- break;
-
case PROP_FLAGS:
g_value_set_flags (value, saver->priv->flags);
break;
@@ -169,14 +159,10 @@ tepl_file_saver_constructed (GObject *object)
if (saver->priv->file != NULL)
{
TeplNewlineType newline_type;
- TeplCompressionType compression_type;
newline_type = tepl_file_get_newline_type (saver->priv->file);
tepl_file_saver_set_newline_type (saver, newline_type);
- compression_type = tepl_file_get_compression_type (saver->priv->file);
- tepl_file_saver_set_compression_type (saver, compression_type);
-
if (saver->priv->location == NULL)
{
saver->priv->location = tepl_file_get_location (saver->priv->file);
@@ -204,7 +190,6 @@ tepl_file_saver_dispose (GObject *object)
g_clear_weak_pointer (&saver->priv->buffer);
g_clear_weak_pointer (&saver->priv->file);
g_clear_object (&saver->priv->location);
- g_clear_object (&saver->priv->task);
G_OBJECT_CLASS (tepl_file_saver_parent_class)->dispose (object);
}
@@ -287,23 +272,6 @@ tepl_file_saver_class_init (TeplFileSaverClass *klass)
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_STRINGS);
- /**
- * TeplFileSaver:compression-type:
- *
- * The compression type.
- *
- * Since: 1.0
- */
- properties[PROP_COMPRESSION_TYPE] =
- g_param_spec_enum ("compression-type",
- "compression-type",
- "",
- TEPL_TYPE_COMPRESSION_TYPE,
- TEPL_COMPRESSION_TYPE_NONE,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT |
- G_PARAM_STATIC_STRINGS);
-
/**
* TeplFileSaver:flags:
*
@@ -330,19 +298,6 @@ tepl_file_saver_init (TeplFileSaver *saver)
saver->priv = tepl_file_saver_get_instance_private (saver);
}
-GQuark
-tepl_file_saver_error_quark (void)
-{
- static GQuark quark = 0;
-
- if (G_UNLIKELY (quark == 0))
- {
- quark = g_quark_from_static_string ("TeplFileSaverError");
- }
-
- return quark;
-}
-
/**
* tepl_file_saver_new:
* @buffer: the #TeplBuffer to save.
@@ -381,9 +336,6 @@ tepl_file_saver_new (TeplBuffer *buffer,
* #TeplFile:location property. If an error occurs, the previous valid
* location is still available in #TeplFile.
*
- * This constructor adds %TEPL_FILE_SAVER_FLAGS_IGNORE_MODIFICATION_TIME to the
- * #TeplFileSaver:flags property.
- *
* This constructor is suitable for a "save as" operation, or for saving a new
* buffer for the first time.
*
@@ -403,7 +355,6 @@ tepl_file_saver_new_with_target (TeplBuffer *buffer,
"buffer", buffer,
"file", file,
"location", target_location,
- "flags", TEPL_FILE_SAVER_FLAGS_IGNORE_MODIFICATION_TIME,
NULL);
}
@@ -419,7 +370,7 @@ tepl_file_saver_get_buffer (TeplFileSaver *saver)
{
g_return_val_if_fail (TEPL_IS_FILE_SAVER (saver), NULL);
- return TEPL_BUFFER (saver->priv->buffer);
+ return saver->priv->buffer;
}
/**
@@ -467,7 +418,7 @@ tepl_file_saver_set_newline_type (TeplFileSaver *saver,
TeplNewlineType newline_type)
{
g_return_if_fail (TEPL_IS_FILE_SAVER (saver));
- g_return_if_fail (saver->priv->task == NULL);
+ g_return_if_fail (!saver->priv->is_saving);
if (saver->priv->newline_type != newline_type)
{
@@ -491,45 +442,6 @@ tepl_file_saver_get_newline_type (TeplFileSaver *saver)
return saver->priv->newline_type;
}
-/**
- * tepl_file_saver_set_compression_type:
- * @saver: a #TeplFileSaver.
- * @compression_type: the new compression type.
- *
- * Sets the compression type. By default the compression type is taken from the
- * #TeplFile.
- *
- * Since: 1.0
- */
-void
-tepl_file_saver_set_compression_type (TeplFileSaver *saver,
- TeplCompressionType compression_type)
-{
- g_return_if_fail (TEPL_IS_FILE_SAVER (saver));
- g_return_if_fail (saver->priv->task == NULL);
-
- if (saver->priv->compression_type != compression_type)
- {
- saver->priv->compression_type = compression_type;
- g_object_notify_by_pspec (G_OBJECT (saver), properties[PROP_COMPRESSION_TYPE]);
- }
-}
-
-/**
- * tepl_file_saver_get_compression_type:
- * @saver: a #TeplFileSaver.
- *
- * Returns: the compression type.
- * Since: 1.0
- */
-TeplCompressionType
-tepl_file_saver_get_compression_type (TeplFileSaver *saver)
-{
- g_return_val_if_fail (TEPL_IS_FILE_SAVER (saver), TEPL_COMPRESSION_TYPE_NONE);
-
- return saver->priv->compression_type;
-}
-
/**
* tepl_file_saver_set_flags:
* @saver: a #TeplFileSaver.
@@ -542,7 +454,7 @@ tepl_file_saver_set_flags (TeplFileSaver *saver,
TeplFileSaverFlags flags)
{
g_return_if_fail (TEPL_IS_FILE_SAVER (saver));
- g_return_if_fail (saver->priv->task == NULL);
+ g_return_if_fail (!saver->priv->is_saving);
if (saver->priv->flags != flags)
{
@@ -572,12 +484,6 @@ tepl_file_saver_get_flags (TeplFileSaver *saver)
* @io_priority: the I/O priority of the request. E.g. %G_PRIORITY_LOW,
* %G_PRIORITY_DEFAULT or %G_PRIORITY_HIGH.
* @cancellable: (nullable): optional #GCancellable object, %NULL to ignore.
- * @progress_callback: (scope notified) (nullable): function to call back with
- * progress information, or %NULL if progress information is not needed.
- * @progress_callback_data: (closure): user data to pass to @progress_callback.
- * @progress_callback_notify: (nullable): function to call on
- * @progress_callback_data when the @progress_callback is no longer needed, or
- * %NULL.
* @callback: (scope async): a #GAsyncReadyCallback to call when the request is
* satisfied.
* @user_data: user data to pass to @callback.
@@ -585,43 +491,41 @@ tepl_file_saver_get_flags (TeplFileSaver *saver)
* Saves asynchronously the buffer into the file. See the #GAsyncResult
* documentation to know how to use this function.
*
- * Since: 1.0
- */
-
-/* The GDestroyNotify is needed, currently the following bug is not fixed:
- * https://gitlab.gnome.org/GNOME/gobject-introspection/issues/25
+ * Since: 5.0
*/
void
-tepl_file_saver_save_async (TeplFileSaver *saver,
- gint io_priority,
- GCancellable *cancellable,
- GFileProgressCallback progress_callback,
- gpointer progress_callback_data,
- GDestroyNotify progress_callback_notify,
- GAsyncReadyCallback callback,
- gpointer user_data)
+tepl_file_saver_save_async (TeplFileSaver *saver,
+ gint io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
+ GTask *task;
TaskData *task_data;
g_return_if_fail (TEPL_IS_FILE_SAVER (saver));
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
- g_return_if_fail (saver->priv->task == NULL);
+ g_return_if_fail (!saver->priv->is_saving);
- saver->priv->task = g_task_new (saver, cancellable, callback, user_data);
- g_task_set_priority (saver->priv->task, io_priority);
+ saver->priv->is_saving = TRUE;
+
+ task = g_task_new (saver, cancellable, callback, user_data);
+ g_task_set_priority (task, io_priority);
task_data = task_data_new ();
- g_task_set_task_data (saver->priv->task, task_data, (GDestroyNotify)task_data_free);
+ g_task_set_task_data (task, task_data, (GDestroyNotify)task_data_free);
if (saver->priv->buffer == NULL ||
saver->priv->file == NULL ||
saver->priv->location == NULL)
{
- g_task_return_boolean (saver->priv->task, FALSE);
+ g_task_return_boolean (task, FALSE);
+ g_object_unref (task);
return;
}
- g_task_return_boolean (saver->priv->task, TRUE);
+ g_task_return_boolean (task, TRUE);
+ g_object_unref (task);
}
/**
@@ -633,8 +537,7 @@ tepl_file_saver_save_async (TeplFileSaver *saver,
* Finishes a file saving started with tepl_file_saver_save_async().
*
* If the file has been saved successfully, the following #TeplFile
- * properties will be updated: the location, the encoding, the newline type and
- * the compression type.
+ * properties will be updated: the location and the newline type.
*
* gtk_text_buffer_set_modified() is called with %FALSE if the file has been
* saved successfully.
@@ -662,9 +565,6 @@ tepl_file_saver_save_finish (TeplFileSaver *saver,
_tepl_file_set_newline_type (saver->priv->file,
saver->priv->newline_type);
-
- _tepl_file_set_compression_type (saver->priv->file,
- saver->priv->compression_type);
}
if (ok && saver->priv->buffer != NULL)
@@ -672,7 +572,6 @@ tepl_file_saver_save_finish (TeplFileSaver *saver,
gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (saver->priv->buffer), FALSE);
}
- g_clear_object (&saver->priv->task);
-
+ saver->priv->is_saving = FALSE;
return ok;
}
diff --git a/tepl/tepl-file-saver.h b/tepl/tepl-file-saver.h
index 19a9e69..aa89ce7 100644
--- a/tepl/tepl-file-saver.h
+++ b/tepl/tepl-file-saver.h
@@ -12,7 +12,6 @@
#error "Only <tepl/tepl.h> can be included directly."
#endif
-#include <gtksourceview/gtksource.h>
#include <tepl/tepl-buffer.h>
#include <tepl/tepl-file.h>
@@ -29,30 +28,9 @@ typedef struct _TeplFileSaver TeplFileSaver;
typedef struct _TeplFileSaverClass TeplFileSaverClass;
typedef struct _TeplFileSaverPrivate TeplFileSaverPrivate;
-#define TEPL_FILE_SAVER_ERROR tepl_file_saver_error_quark ()
-
-/**
- * TeplFileSaverError:
- * @TEPL_FILE_SAVER_ERROR_INVALID_CHARS: The buffer contains invalid
- * characters.
- * @TEPL_FILE_SAVER_ERROR_EXTERNALLY_MODIFIED: The file is externally
- * modified.
- *
- * An error code used with the %TEPL_FILE_SAVER_ERROR domain.
- *
- * Since: 1.0
- */
-typedef enum
-{
- TEPL_FILE_SAVER_ERROR_INVALID_CHARS,
- TEPL_FILE_SAVER_ERROR_EXTERNALLY_MODIFIED
-} TeplFileSaverError;
-
/**
* TeplFileSaverFlags:
* @TEPL_FILE_SAVER_FLAGS_NONE: No flags.
- * @TEPL_FILE_SAVER_FLAGS_IGNORE_INVALID_CHARS: Ignore invalid characters.
- * @TEPL_FILE_SAVER_FLAGS_IGNORE_MODIFICATION_TIME: Save file despite external modifications.
* @TEPL_FILE_SAVER_FLAGS_CREATE_BACKUP: Create a backup before saving the file.
*
* Flags to define the behavior of a #TeplFileSaver.
@@ -61,10 +39,8 @@ typedef enum
*/
typedef enum
{
- TEPL_FILE_SAVER_FLAGS_NONE = 0,
- TEPL_FILE_SAVER_FLAGS_IGNORE_INVALID_CHARS = 1 << 0,
- TEPL_FILE_SAVER_FLAGS_IGNORE_MODIFICATION_TIME = 1 << 1,
- TEPL_FILE_SAVER_FLAGS_CREATE_BACKUP = 1 << 2
+ TEPL_FILE_SAVER_FLAGS_NONE = 0,
+ TEPL_FILE_SAVER_FLAGS_CREATE_BACKUP = 1 << 0
} TeplFileSaverFlags;
struct _TeplFileSaver
@@ -84,9 +60,6 @@ struct _TeplFileSaverClass
_TEPL_EXTERN
GType tepl_file_saver_get_type (void);
-_TEPL_EXTERN
-GQuark tepl_file_saver_error_quark (void);
-
_TEPL_EXTERN
TeplFileSaver * tepl_file_saver_new (TeplBuffer *buffer,
TeplFile *file);
@@ -112,13 +85,6 @@ void tepl_file_saver_set_newline_type (TeplFileSaver
*saver,
_TEPL_EXTERN
TeplNewlineType tepl_file_saver_get_newline_type (TeplFileSaver *saver);
-_TEPL_EXTERN
-void tepl_file_saver_set_compression_type (TeplFileSaver *saver,
- TeplCompressionType compression_type);
-
-_TEPL_EXTERN
-TeplCompressionType tepl_file_saver_get_compression_type (TeplFileSaver *saver);
-
_TEPL_EXTERN
void tepl_file_saver_set_flags (TeplFileSaver *saver,
TeplFileSaverFlags flags);
@@ -127,14 +93,11 @@ _TEPL_EXTERN
TeplFileSaverFlags tepl_file_saver_get_flags (TeplFileSaver *saver);
_TEPL_EXTERN
-void tepl_file_saver_save_async (TeplFileSaver *saver,
- gint io_priority,
- GCancellable *cancellable,
- GFileProgressCallback progress_callback,
- gpointer
progress_callback_data,
- GDestroyNotify
progress_callback_notify,
- GAsyncReadyCallback callback,
- gpointer user_data);
+void tepl_file_saver_save_async (TeplFileSaver *saver,
+ gint io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
_TEPL_EXTERN
gboolean tepl_file_saver_save_finish (TeplFileSaver *saver,
diff --git a/tepl/tepl-tab-saving.c b/tepl/tepl-tab-saving.c
index 125715f..3cce02f 100644
--- a/tepl/tepl-tab-saving.c
+++ b/tepl/tepl-tab-saving.c
@@ -76,9 +76,6 @@ launch_saver (GTask *task)
tepl_file_saver_save_async (saver,
G_PRIORITY_DEFAULT,
NULL,
- NULL,
- NULL,
- NULL,
launch_saver_cb,
task);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]