[ghex/support-block-devices-part-deux: 3/4] hex-doc/appwin: Dynamic loading of `direct` backend for block devices




commit b6d41e1bd5746dbc1df2b6908695e157ddd1c2a8
Author: Logan Rathbone <poprocks gmail com>
Date:   Wed Jun 8 03:12:20 2022 -0400

    hex-doc/appwin: Dynamic loading of `direct` backend for block devices

 src/ghex-application-window.c | 14 ++++++++++++++
 src/hex-document.c            | 23 +++++++++++++++++++++++
 src/hex-document.h            |  1 +
 3 files changed, 38 insertions(+)
---
diff --git a/src/ghex-application-window.c b/src/ghex-application-window.c
index afc18de..65e591a 100644
--- a/src/ghex-application-window.c
+++ b/src/ghex-application-window.c
@@ -2159,7 +2159,21 @@ ghex_application_window_open_file (GHexApplicationWindow *self, GFile *file)
        }
 
        if (doc)
+       {
+               GFileType type;
+
+               type = g_file_query_file_type (file, G_FILE_QUERY_INFO_NONE, NULL);
+               if (type == G_FILE_TYPE_SPECIAL)
+               {
+                       HexBuffer *buf;
+
+                       g_debug ("%s: attempting to set buffer to `direct`", __func__);
+                       buf = hex_buffer_util_new ("direct", file);
+                       hex_document_set_buffer (doc, buf);
+               }
+
                gh = HEX_WIDGET(hex_widget_new (doc));
+       }
 
        /* Display a fairly generic error message if we can't even get this far. */
        if (! gh)
diff --git a/src/hex-document.c b/src/hex-document.c
index 7376a6c..f42840a 100644
--- a/src/hex-document.c
+++ b/src/hex-document.c
@@ -1825,3 +1825,26 @@ hex_document_get_file (HexDocument *doc)
 {
        return doc->file;
 }
+
+/**
+ * hex_document_set_buffer:
+ * @doc: a [class@Hex.Document] object
+ * @buf: [iface@Hex.Buffer]
+ *
+ * Set the [iface@Hex.Buffer] connected with the #HexDocument.
+ *
+ * Returns: %TRUE if the operation was successful; %FALSE otherwise.
+ *
+ * Since: 4.2
+ */
+gboolean
+hex_document_set_buffer (HexDocument *doc, HexBuffer *buf)
+{
+       g_return_val_if_fail (HEX_IS_DOCUMENT (doc), FALSE);
+       g_return_val_if_fail (HEX_IS_BUFFER (buf), FALSE);
+
+       g_clear_object (&doc->buffer);
+       doc->buffer = buf;
+
+       return TRUE;
+}
diff --git a/src/hex-document.h b/src/hex-document.h
index ef3c13a..6168294 100644
--- a/src/hex-document.h
+++ b/src/hex-document.h
@@ -230,6 +230,7 @@ GFile *             hex_document_get_file (HexDocument *doc);
 gboolean       hex_document_set_file (HexDocument *doc, GFile *file);
 HexChangeData *        hex_document_get_undo_data (HexDocument *doc);
 HexBuffer *    hex_document_get_buffer (HexDocument *doc);
+gboolean       hex_document_set_buffer (HexDocument *doc, HexBuffer *buf);
 
 /* HexDocumentFindData functions */
 


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