[ghex] GUI/settings: support quadwords grouping



commit 6a0606f6f212a498ce8fcc858d8d5ac8d39169c6
Author: Logan Rathbone <poprocks gmail com>
Date:   Thu Dec 16 20:11:08 2021 -0500

    GUI/settings: support quadwords grouping
    
    Closes #33
    
    Also: fixed minor issue in hex-buffer-malloc which caused a compiler
    warning and could cause a crash if an invalid GFile is passed.

 data/org.gnome.GHex.gschema.xml.in |  1 +
 src/ghex-application-window.c      |  3 +--
 src/ghex-application-window.ui.in  | 11 ++++++++---
 src/gtkhex.h                       |  8 ++++----
 src/hex-buffer-malloc.c            |  4 ++--
 src/preferences.c                  | 14 ++++++++++----
 src/preferences.ui                 | 12 +++++++++---
 7 files changed, 35 insertions(+), 18 deletions(-)
---
diff --git a/data/org.gnome.GHex.gschema.xml.in b/data/org.gnome.GHex.gschema.xml.in
index fc2d2dc..b042230 100644
--- a/data/org.gnome.GHex.gschema.xml.in
+++ b/data/org.gnome.GHex.gschema.xml.in
@@ -9,6 +9,7 @@
                <value nick="bytes" value="1"/>
                <value nick="words" value="2"/>
                <value nick="longwords" value="4"/>
+               <value nick="quadwords" value="8"/>
        </enum>
        <enum id="@app_id@.DarkMode">
                <value nick="off" value="0"/>
diff --git a/src/ghex-application-window.c b/src/ghex-application-window.c
index b767e21..51c1113 100644
--- a/src/ghex-application-window.c
+++ b/src/ghex-application-window.c
@@ -1542,8 +1542,7 @@ ghex_application_window_init (GHexApplicationWindow *self)
         * class-init, so we end up with the 'win' namespace when we do it from
         * here. Be aware of that.
         */
-       action = g_settings_create_action (settings,
-                       GHEX_PREF_GROUP);
+       action = g_settings_create_action (settings, GHEX_PREF_GROUP);
        g_action_map_add_action (G_ACTION_MAP(self), action);
 
        /* Setup notebook signals */
diff --git a/src/ghex-application-window.ui.in b/src/ghex-application-window.ui.in
index 5b921d0..a8923f4 100644
--- a/src/ghex-application-window.ui.in
+++ b/src/ghex-application-window.ui.in
@@ -97,21 +97,26 @@
                        <submenu>
                                <attribute name="label" translatable="yes">G_roup Data As</attribute>
                                <item>
-                                       <attribute name="label" translatable="yes">_Bytes</attribute>
+                                       <attribute name="label" translatable="yes">_Bytes (8-bit)</attribute>
                                        <!-- use 'win' prefix for these because that's what gets set 
automatically by g_settings_create_action in _init -->
                                        <attribute name="action">win.group-data-by</attribute>
                                        <attribute name="target">bytes</attribute>
                                </item>
                                <item>
-                                       <attribute name="label" translatable="yes">_Words</attribute>
+                                       <attribute name="label" translatable="yes">_Words (16-bit)</attribute>
                                        <attribute name="action">win.group-data-by</attribute>
                                        <attribute name="target">words</attribute>
                                </item>
                                <item>
-                                       <attribute name="label" translatable="yes">_Longwords</attribute>
+                                       <attribute name="label" translatable="yes">_Longwords 
(32-bit)</attribute>
                                        <attribute name="action">win.group-data-by</attribute>
                                        <attribute name="target">longwords</attribute>
                                </item>
+                               <item>
+                                       <attribute name="label" translatable="yes">_Quadwords 
(64-bit)</attribute>
+                                       <attribute name="action">win.group-data-by</attribute>
+                                       <attribute name="target">quadwords</attribute>
+                               </item>
                        </submenu>
                </section>
 
diff --git a/src/gtkhex.h b/src/gtkhex.h
index 8aabab0..f12e7bf 100644
--- a/src/gtkhex.h
+++ b/src/gtkhex.h
@@ -43,10 +43,10 @@ G_BEGIN_DECLS
 
 typedef enum
 {
-       GTK_HEX_GROUP_BYTE              1,
-       GTK_HEX_GROUP_WORD              2,
-       GTK_HEX_GROUP_LONG              4,
-       GTK_HEX_GROUP_QUAD              8
+       GTK_HEX_GROUP_BYTE =            1,
+       GTK_HEX_GROUP_WORD =            2,
+       GTK_HEX_GROUP_LONG =            4,
+       GTK_HEX_GROUP_QUAD =            8
 } GtkHexGroupType;
 
 /* GOBJECT DECLARATION */
diff --git a/src/hex-buffer-malloc.c b/src/hex-buffer-malloc.c
index 9f023bb..261bcfe 100644
--- a/src/hex-buffer-malloc.c
+++ b/src/hex-buffer-malloc.c
@@ -211,7 +211,7 @@ static gboolean
 hex_buffer_malloc_read (HexBuffer *buf)
 {
        HexBufferMalloc *self = HEX_BUFFER_MALLOC (buf);
-       char *path;
+       char *path = NULL;
        FILE *file = NULL;
        size_t fread_ret;
        gboolean retval = FALSE;
@@ -252,7 +252,7 @@ hex_buffer_malloc_write_to_file (HexBuffer *buf, GFile *file)
 {
        HexBufferMalloc *self = HEX_BUFFER_MALLOC (buf);
        char *path = NULL;
-       FILE *fp;
+       FILE *fp = NULL;
        gboolean ret = FALSE;
        int exp_len;
 
diff --git a/src/preferences.c b/src/preferences.c
index 00980c5..9d94ea8 100644
--- a/src/preferences.c
+++ b/src/preferences.c
@@ -76,6 +76,7 @@ static GtkWidget *show_offsets_chkbtn;
 static GtkWidget *bytes_chkbtn;
 static GtkWidget *words_chkbtn;
 static GtkWidget *long_chkbtn;
+static GtkWidget *quad_chkbtn;
 static GtkWidget *shaded_box_chkbtn;
 static GtkWidget *shaded_box_spinbtn;
 static GtkWidget *shaded_box_box;
@@ -96,7 +97,6 @@ do_css_stuff(void)
        GET_WIDGET (font_frame);
        GET_WIDGET (group_type_frame);
        GET_WIDGET (print_font_frame);
-
        
        /* overall padding for content area: */
        box_provider = gtk_css_provider_new ();
@@ -202,9 +202,6 @@ group_type_set_cb (GtkCheckButton *checkbutton,
         */
        if (gtk_check_button_get_active (checkbutton))
        {
-               g_debug ("%s: active. - group_type: %d",
-                               __func__, group_type);
-
                g_settings_set_enum (settings,
                                GHEX_PREF_GROUP,
                                group_type);
@@ -361,6 +358,9 @@ setup_signals (void)
        g_signal_connect (long_chkbtn, "toggled",
                        G_CALLBACK(group_type_set_cb), GINT_TO_POINTER(GTK_HEX_GROUP_LONG));
 
+       g_signal_connect (quad_chkbtn, "toggled",
+                       G_CALLBACK(group_type_set_cb), GINT_TO_POINTER(GTK_HEX_GROUP_QUAD));
+
        /* show offsets checkbutton */
 
        g_signal_connect (show_offsets_chkbtn, "toggled",
@@ -441,6 +441,11 @@ grab_widget_values_from_settings (void)
                                        TRUE);
                        break;
 
+               case GTK_HEX_GROUP_QUAD:
+                       gtk_check_button_set_active (GTK_CHECK_BUTTON(quad_chkbtn),
+                                       TRUE);
+                       break;
+
                default:
                        g_warning ("group_type option invalid; falling back to BYTES.");
                        gtk_check_button_set_active (GTK_CHECK_BUTTON(bytes_chkbtn),
@@ -470,6 +475,7 @@ init_widgets (void)
        GET_WIDGET (bytes_chkbtn);
        GET_WIDGET (words_chkbtn);
        GET_WIDGET (long_chkbtn);
+       GET_WIDGET (quad_chkbtn);
        GET_WIDGET (shaded_box_chkbtn);
        GET_WIDGET (shaded_box_spinbtn);
        GET_WIDGET (shaded_box_box);
diff --git a/src/preferences.ui b/src/preferences.ui
index 86b2b21..48359e0 100644
--- a/src/preferences.ui
+++ b/src/preferences.ui
@@ -105,19 +105,25 @@
                                                                                                              
  <property name="orientation">vertical</property>
                                                                                                              
  <child>
                                                                                                              
          <object class="GtkCheckButton" id="bytes_chkbtn">
-                                                                                                             
                  <property name="label" translatable="yes">Bytes</property>
+                                                                                                             
                  <property name="label" translatable="yes">Bytes (8-bit)</property>
                                                                                                              
                          <!-- note: don't put group="bytes_checkbtn" here. -->
                                                                                                              
          </object>
                                                                                                              
  </child>
                                                                                                              
  <child>
                                                                                                              
          <object class="GtkCheckButton" id="words_chkbtn">
-                                                                                                             
                  <property name="label" translatable="yes">Words</property>
+                                                                                                             
                  <property name="label" translatable="yes">Words (16-bit)</property>
                                                                                                              
                  <property name="group">bytes_chkbtn</property>
                                                                                                              
          </object>
                                                                                                              
  </child>
                                                                                                              
  <child>
                                                                                                              
          <object class="GtkCheckButton" id="long_chkbtn">
-                                                                                                             
                  <property name="label" translatable="yes">Longwords</property>
+                                                                                                             
                  <property name="label" translatable="yes">Longwords (32-bit)</property>
+                                                                                                             
                  <property name="group">bytes_chkbtn</property>
+                                                                                                             
          </object>
+                                                                                                             
  </child>
+                                                                                                             
  <child>
+                                                                                                             
          <object class="GtkCheckButton" id="quad_chkbtn">
+                                                                                                             
                  <property name="label" translatable="yes">Quadwords (64-bit)</property>
                                                                                                              
                  <property name="group">bytes_chkbtn</property>
                                                                                                              
          </object>
                                                                                                              
  </child>


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