[ghex] HexBufferMalloc: add async API; GtkNotebook bugfix.



commit 091eb69b89b4362a938c7f8ce4d571719263585f
Author: Logan Rathbone <poprocks gmail com>
Date:   Fri Dec 17 22:25:39 2021 -0500

    HexBufferMalloc: add async API; GtkNotebook bugfix.

 src/findreplace.c             |  2 --
 src/ghex-application-window.c | 11 +++++------
 src/hex-buffer-malloc.c       | 43 +++++++++++++++++++++++++++++++++++++++++++
 src/hex-buffer-mmap.c         |  9 ---------
 4 files changed, 48 insertions(+), 17 deletions(-)
---
diff --git a/src/findreplace.c b/src/findreplace.c
index c75e793..5858939 100644
--- a/src/findreplace.c
+++ b/src/findreplace.c
@@ -199,8 +199,6 @@ find_common (FindDialog *self, enum FindDirection direction,
        g_return_if_fail (HEX_IS_DOCUMENT (f_priv->f_doc));
 
        parent = GTK_WINDOW(gtk_widget_get_native (widget));
-       if (! GTK_IS_WINDOW(parent))
-               parent = NULL;
 
        doc = gtk_hex_get_document (priv->gh);
        cursor_pos = gtk_hex_get_cursor (priv->gh);
diff --git a/src/ghex-application-window.c b/src/ghex-application-window.c
index 5b4075e..987f71b 100644
--- a/src/ghex-application-window.c
+++ b/src/ghex-application-window.c
@@ -738,10 +738,9 @@ tab_close_request_cb (GHexNotebookTab *tab,
 }
 
 static void
-notebook_switch_page_cb (GtkNotebook *notebook,
-               GtkWidget   *page,
-               guint        page_num,
-               gpointer     user_data)
+notebook_page_changed_cb (GtkNotebook *notebook,
+               GParamSpec *pspec,
+               gpointer    user_data)
 {
        GHexApplicationWindow *self = GHEX_APPLICATION_WINDOW(user_data);
        HexDocument *doc;
@@ -1582,8 +1581,8 @@ ghex_application_window_init (GHexApplicationWindow *self)
 
        /* Setup notebook signals */
 
-       g_signal_connect (self->hex_notebook, "switch-page",
-                       G_CALLBACK(notebook_switch_page_cb), self);
+       g_signal_connect (self->hex_notebook, "notify::page",
+                       G_CALLBACK(notebook_page_changed_cb), self);
 
        g_signal_connect (self->hex_notebook, "page-added",
                        G_CALLBACK(notebook_page_added_cb), self);
diff --git a/src/hex-buffer-malloc.c b/src/hex-buffer-malloc.c
index 261bcfe..c586b47 100644
--- a/src/hex-buffer-malloc.c
+++ b/src/hex-buffer-malloc.c
@@ -247,6 +247,47 @@ out:
        return retval;
 }
 
+
+static gboolean
+hex_buffer_malloc_read_finish (HexBuffer *buf,
+               GAsyncResult *result,
+               GError **error)
+{
+       HexBufferMalloc *self = HEX_BUFFER_MALLOC (buf);
+
+       g_return_val_if_fail (g_task_is_valid (result, G_OBJECT(self)), FALSE);
+
+       return g_task_propagate_boolean (G_TASK(result), error);
+}
+
+static void
+hex_buffer_malloc_thread (GTask *task,
+               gpointer source_object,
+               gpointer task_data,
+               GCancellable *cancellable)
+{
+       HexBufferMalloc *self = HEX_BUFFER_MALLOC (source_object);
+       gboolean success;
+
+       success = hex_buffer_malloc_read (HEX_BUFFER(self));
+
+       g_task_return_boolean (task, success);
+}
+
+static void
+hex_buffer_malloc_read_async (HexBuffer *buf,
+               GCancellable *cancellable,
+               GAsyncReadyCallback callback,
+               gpointer user_data)
+{
+       HexBufferMalloc *self = HEX_BUFFER_MALLOC (buf);
+       GTask *task;
+
+       task = g_task_new (self, cancellable, callback, user_data);
+       g_task_run_in_thread (task, hex_buffer_malloc_thread);
+       g_object_unref (task);  /* _run_in_thread takes a ref */
+}
+
 static gboolean
 hex_buffer_malloc_write_to_file (HexBuffer *buf, GFile *file)
 {
@@ -362,6 +403,8 @@ hex_buffer_malloc_iface_init (HexBufferInterface *iface)
        iface->set_data = hex_buffer_malloc_set_data;
        iface->set_file = hex_buffer_malloc_set_file;
        iface->read = hex_buffer_malloc_read;
+       iface->read_async = hex_buffer_malloc_read_async;
+       iface->read_finish = hex_buffer_malloc_read_finish;
        iface->write_to_file = hex_buffer_malloc_write_to_file;
        iface->get_payload_size = hex_buffer_malloc_get_payload_size;
 }
diff --git a/src/hex-buffer-mmap.c b/src/hex-buffer-mmap.c
index 8cac6df..b633e67 100644
--- a/src/hex-buffer-mmap.c
+++ b/src/hex-buffer-mmap.c
@@ -591,7 +591,6 @@ hex_buffer_mmap_thread (GTask *task,
                g_task_return_error (task, self->error);
 }
 
-
 static void
 hex_buffer_mmap_read_async (HexBuffer *buf,
                GCancellable *cancellable,
@@ -606,14 +605,6 @@ hex_buffer_mmap_read_async (HexBuffer *buf,
        g_object_unref (task);  /* _run_in_thread takes a ref */
 }
 
-
-
-
-
-
-
-
-
 static gboolean hex_buffer_mmap_set_data (HexBuffer *buf,
                size_t offset,
                size_t len,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]