[tepl] FileLoader: add a mode to simulate a long file loading
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tepl] FileLoader: add a mode to simulate a long file loading
- Date: Mon, 25 May 2020 08:56:08 +0000 (UTC)
commit 0df68a32df14e672a148add964530361460d06ad
Author: Sébastien Wilmet <swilmet gnome org>
Date: Mon May 25 10:42:05 2020 +0200
FileLoader: add a mode to simulate a long file loading
tepl/tepl-file-loader.c | 41 +++++++++++++++++++++++++++++++++++++----
1 file changed, 37 insertions(+), 4 deletions(-)
---
diff --git a/tepl/tepl-file-loader.c b/tepl/tepl-file-loader.c
index 2beb2c4..055e449 100644
--- a/tepl/tepl-file-loader.c
+++ b/tepl/tepl-file-loader.c
@@ -29,6 +29,11 @@
* gtk_text_buffer_set_modified() is called with %FALSE.
*/
+/* To simulate for example loading a big remote file with a slow network
+ * connection.
+ */
+#define SIMULATE_LONG_FILE_LOADING FALSE
+
struct _TeplFileLoaderPrivate
{
/* Weak ref to the TeplBuffer. A strong ref could create a reference
@@ -356,6 +361,31 @@ out:
g_free (content);
}
+static void
+start_load_contents (GTask *task)
+{
+ TeplFileLoader *loader = g_task_get_source_object (task);
+
+ g_file_load_contents_async (loader->priv->location,
+ g_task_get_cancellable (task),
+ load_contents_cb,
+ task);
+}
+
+#if SIMULATE_LONG_FILE_LOADING
+static gboolean
+simulate_long_file_loading_timeout_cb (gpointer user_data)
+{
+ GTask *task = G_TASK (user_data);
+
+ g_message ("%s()", G_STRFUNC);
+
+ start_load_contents (task);
+
+ return G_SOURCE_REMOVE;
+}
+#endif
+
/**
* tepl_file_loader_load_async:
* @loader: a #TeplFileLoader.
@@ -403,10 +433,13 @@ tepl_file_loader_load_async (TeplFileLoader *loader,
gtk_text_buffer_set_text (GTK_TEXT_BUFFER (loader->priv->buffer), "", -1);
gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (loader->priv->buffer), FALSE);
- g_file_load_contents_async (loader->priv->location,
- cancellable,
- load_contents_cb,
- task);
+#if SIMULATE_LONG_FILE_LOADING
+ g_timeout_add_seconds (5,
+ simulate_long_file_loading_timeout_cb,
+ task);
+#else
+ start_load_contents (task);
+#endif
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]