[gtksourceview/wip/loader-saver: 18/28] Make load_async() and save_async() introspection-friendly
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/loader-saver: 18/28] Make load_async() and save_async() introspection-friendly
- Date: Sun, 6 Jul 2014 16:41:40 +0000 (UTC)
commit f72f1cfabf9ecbaf3057673d7be5d2b905530e07
Author: Sébastien Wilmet <swilmet gnome org>
Date: Wed Jun 11 00:36:45 2014 +0200
Make load_async() and save_async() introspection-friendly
gtksourceview/gtksourcefileloader.c | 25 ++++++++++++++++++++++---
gtksourceview/gtksourcefileloader.h | 1 +
gtksourceview/gtksourcefilesaver.c | 25 ++++++++++++++++++++++---
gtksourceview/gtksourcefilesaver.h | 1 +
tests/test-file-loader.c | 4 +---
tests/test-file-saver.c | 4 +---
6 files changed, 48 insertions(+), 12 deletions(-)
---
diff --git a/gtksourceview/gtksourcefileloader.c b/gtksourceview/gtksourcefileloader.c
index 4a41e99..8759283 100644
--- a/gtksourceview/gtksourcefileloader.c
+++ b/gtksourceview/gtksourcefileloader.c
@@ -87,6 +87,7 @@ struct _GtkSourceFileLoaderPrivate
goffset total_size;
GFileProgressCallback progress_cb;
gpointer progress_cb_data;
+ GDestroyNotify progress_cb_notify;
gchar chunk_buffer[READ_CHUNK_SIZE];
gssize chunk_bytes_read;
@@ -192,6 +193,15 @@ reset (GtkSourceFileLoader *loader)
g_clear_object (&loader->priv->input_stream);
g_clear_object (&loader->priv->output_stream);
g_clear_object (&loader->priv->info);
+
+ if (loader->priv->progress_cb_notify != NULL)
+ {
+ loader->priv->progress_cb_notify (loader->priv->progress_cb_data);
+ loader->priv->progress_cb_notify = NULL;
+ }
+
+ loader->priv->progress_cb = NULL;
+ loader->priv->progress_cb_data = NULL;
}
static void
@@ -813,10 +823,13 @@ gtk_source_file_loader_get_input_stream (GtkSourceFileLoader *loader)
* @loader: a #GtkSourceFileLoader.
* @io_priority: the I/O priority of the request. E.g. %G_PRIORITY_LOW,
* %G_PRIORITY_DEFAULT or %G_PRIORITY_HIGH.
- * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
- * @progress_callback: (allow-none): function to call back with progress
- * information, or %NULL if progress information is not needed.
+ * @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.
@@ -827,12 +840,17 @@ gtk_source_file_loader_get_input_stream (GtkSourceFileLoader *loader)
*
* Since: 3.14
*/
+
+/* The GDestroyNotify is needed, currently the following bug is not fixed:
+ * https://bugzilla.gnome.org/show_bug.cgi?id=616044
+ */
void
gtk_source_file_loader_load_async (GtkSourceFileLoader *loader,
gint io_priority,
GCancellable *cancellable,
GFileProgressCallback progress_callback,
gpointer progress_callback_data,
+ GDestroyNotify progress_callback_notify,
GAsyncReadyCallback callback,
gpointer user_data)
{
@@ -861,6 +879,7 @@ gtk_source_file_loader_load_async (GtkSourceFileLoader *loader,
loader->priv->progress_cb = progress_callback;
loader->priv->progress_cb_data = progress_callback_data;
+ loader->priv->progress_cb_notify = progress_callback_notify;
DEBUG ({
g_print ("Start loading\n");
diff --git a/gtksourceview/gtksourcefileloader.h b/gtksourceview/gtksourcefileloader.h
index 5526e70..cdf5f0c 100644
--- a/gtksourceview/gtksourcefileloader.h
+++ b/gtksourceview/gtksourcefileloader.h
@@ -98,6 +98,7 @@ void gtk_source_file_loader_load_async (GtkSourceFileLoader
*loader,
GCancellable *cancellable,
GFileProgressCallback progress_callback,
gpointer
progress_callback_data,
+ GDestroyNotify
progress_callback_notify,
GAsyncReadyCallback callback,
gpointer user_data);
diff --git a/gtksourceview/gtksourcefilesaver.c b/gtksourceview/gtksourcefilesaver.c
index 6f9df78..6e1e5ab 100644
--- a/gtksourceview/gtksourcefilesaver.c
+++ b/gtksourceview/gtksourcefilesaver.c
@@ -93,6 +93,7 @@ struct _GtkSourceFileSaverPrivate
goffset total_size;
GFileProgressCallback progress_cb;
gpointer progress_cb_data;
+ GDestroyNotify progress_cb_notify;
gchar chunk_buffer[WRITE_CHUNK_SIZE];
gssize chunk_bytes_read;
@@ -211,6 +212,15 @@ reset (GtkSourceFileSaver *saver)
g_clear_object (&saver->priv->input_stream);
g_clear_object (&saver->priv->info);
g_clear_error (&saver->priv->error);
+
+ if (saver->priv->progress_cb_notify != NULL)
+ {
+ saver->priv->progress_cb_notify (saver->priv->progress_cb_data);
+ saver->priv->progress_cb_notify = NULL;
+ }
+
+ saver->priv->progress_cb = NULL;
+ saver->priv->progress_cb_data = NULL;
}
static void
@@ -1132,10 +1142,13 @@ gtk_source_file_saver_get_flags (GtkSourceFileSaver *saver)
* @saver: a #GtkSourceFileSaver.
* @io_priority: the I/O priority of the request. E.g. %G_PRIORITY_LOW,
* %G_PRIORITY_DEFAULT or %G_PRIORITY_HIGH.
- * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore.
- * @progress_callback: (allow-none): function to call back with progress
- * information, or %NULL if progress information is not needed.
+ * @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.
@@ -1145,12 +1158,17 @@ gtk_source_file_saver_get_flags (GtkSourceFileSaver *saver)
*
* Since: 3.14
*/
+
+/* The GDestroyNotify is needed, currently the following bug is not fixed:
+ * https://bugzilla.gnome.org/show_bug.cgi?id=616044
+ */
void
gtk_source_file_saver_save_async (GtkSourceFileSaver *saver,
gint io_priority,
GCancellable *cancellable,
GFileProgressCallback progress_callback,
gpointer progress_callback_data,
+ GDestroyNotify progress_callback_notify,
GAsyncReadyCallback callback,
gpointer user_data)
{
@@ -1180,6 +1198,7 @@ gtk_source_file_saver_save_async (GtkSourceFileSaver *saver,
saver->priv->progress_cb = progress_callback;
saver->priv->progress_cb_data = progress_callback_data;
+ saver->priv->progress_cb_notify = progress_callback_notify;
check_invalid_chars = (saver->priv->flags & GTK_SOURCE_FILE_SAVER_FLAGS_IGNORE_INVALID_CHARS) == 0;
diff --git a/gtksourceview/gtksourcefilesaver.h b/gtksourceview/gtksourcefilesaver.h
index 00b59e0..351aaf8 100644
--- a/gtksourceview/gtksourcefilesaver.h
+++ b/gtksourceview/gtksourcefilesaver.h
@@ -127,6 +127,7 @@ void gtk_source_file_saver_save_async (GtkSourceFileSaver
*saver,
GCancellable *cancellable,
GFileProgressCallback progress_callback,
gpointer
progress_callback_data,
+ GDestroyNotify
progress_callback_notify,
GAsyncReadyCallback callback,
gpointer user_data);
diff --git a/tests/test-file-loader.c b/tests/test-file-loader.c
index 3a14d59..5cd5d34 100644
--- a/tests/test-file-loader.c
+++ b/tests/test-file-loader.c
@@ -112,9 +112,7 @@ test_loader (const gchar *filename,
gtk_source_file_loader_load_async (loader,
G_PRIORITY_DEFAULT,
- NULL,
- NULL,
- NULL,
+ NULL, NULL, NULL, NULL,
(GAsyncReadyCallback) load_file_cb,
data);
diff --git a/tests/test-file-saver.c b/tests/test-file-saver.c
index 06f09f8..889a262 100644
--- a/tests/test-file-saver.c
+++ b/tests/test-file-saver.c
@@ -118,9 +118,7 @@ save_file (SaverTestData *data)
gtk_source_file_saver_save_async (data->saver,
G_PRIORITY_DEFAULT,
- NULL,
- NULL,
- NULL,
+ NULL, NULL, NULL, NULL,
(GAsyncReadyCallback) save_file_cb,
data);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]