[ghex/gtk4-port: 50/91] Get to build with meson.




commit 3373656b647a2301c418b5c86a9b771a78d74b46
Author: Logan Rathbone <poprocks gmail com>
Date:   Fri Jan 22 16:09:08 2021 -0500

    Get to build with meson.
    
    I'd say we're at about pre-alpha at this point for 4.0.
    
    Once a few of the glaring showstopper bugs are fixed, and a
    low-hanging-fruit cleanup of some files is done, I should be in a
    position to submit an MR as a proposed alpha for ghex4.

 meson.build                   |   9 +--
 src/STUB.c                    |  80 +++++++++++++++++++++++--
 src/common-ui.c               |   4 +-
 src/ghex-application-window.c |  39 +++++--------
 src/ghex-application-window.h |  10 ++++
 src/gtkhex.c                  |   8 ++-
 src/main.c                    | 133 ++++++++++++++----------------------------
 src/meson.build               |  19 +++---
 8 files changed, 167 insertions(+), 135 deletions(-)
---
diff --git a/meson.build b/meson.build
index cae357c7..171f3762 100644
--- a/meson.build
+++ b/meson.build
@@ -49,6 +49,11 @@ ghex_conf.set('CONFIG_H_SHADED_BOX_MAX', shaded_box_max)
 
 ghex_conf.set_quoted('LIBGTKHEX_RELEASE_STRING', 'gtkhex-@0@.0'.format(libghex_version_major))
 
+ghex_conf.set('DEBUG', get_option('debug'))
+
+# Always enable; it's generated by Meson anyway.
+ghex_conf.set('HAVE_CONFIG_H', true)
+
 ghex_conf.set10('ENABLE_NLS', true) # Always enabled
 
 check_headers = [
@@ -81,10 +86,6 @@ foreach f : check_functions
   endif
 endforeach
 
-# FIXME - REMOVE
-atk_dep = dependency('atk', version: '>= 1.0.0')
-gail_dep = dependency('gail-3.0', version: '>= 1.0.0')
-
 gio_dep = dependency('gio-2.0', version: '>= 2.66.0')
 gtk_dep = dependency('gtk4', version: '>= 4.0.0')
 
diff --git a/src/STUB.c b/src/STUB.c
index 2aeb23fd..53a4a55b 100644
--- a/src/STUB.c
+++ b/src/STUB.c
@@ -1,9 +1,68 @@
-/* vim: colorcolumn=80 tw=4 sw=4
+/* vim: colorcolumn=80 ts=4 sw=4
  */
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* main.c - genesis of a GHex application
+
+   Copyright © 1998 - 2004 Free Software Foundation
+   Copyright © 2021 Logan Rathbone
+
+   GHex is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   GHex is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GHex; see the file COPYING.
+   If not, write to the Free Software Foundation, Inc.,
+   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+   Original Author: Jaka Mocnik <jaka gnu org>
+*/
+
+#include <config.h>
 
-#include <gtkhex.h>
 #include "ghex-application-window.h"
-#include "configuration.h"
+
+/* FIXME - TEST ON WIN32.
+ * This is one of the few functions in this file that has been ripped verbatim
+ * from the old main.c. It might work. Maybe.
+ */
+#ifdef G_OS_WIN32
+static char *
+ghex_win32_locale_dir (void)
+{
+    gchar *install_dir;
+    gchar *locale_dir = NULL;
+    gchar *utf8_locale_dir;
+
+    install_dir = g_win32_get_package_installation_directory_of_module (NULL);
+
+    if (install_dir) {
+        utf8_locale_dir = g_build_filename (install_dir, "share", "locale", NULL);
+        locale_dir = g_win32_locale_filename_from_utf8 (utf8_locale_dir);
+
+        g_free (install_dir);
+        g_free (utf8_locale_dir);
+    }
+
+    return locale_dir;
+}
+#endif
+
+static char *
+ghex_locale_dir (void)
+{
+#ifdef G_OS_WIN32
+    return ghex_win32_locale_dir ();
+#else
+    return g_strdup (LOCALEDIR);
+#endif
+}
 
 static void
 activate (GtkApplication *app,
@@ -23,12 +82,25 @@ int
 main (int argc, char *argv[])
 {
        GtkApplication *app;
+       char *locale_dir;
        int status;
 
+       /* boilerplate i18n stuff */
+       setlocale (LC_ALL, "");
+       locale_dir = ghex_locale_dir ();
+       bindtextdomain (GETTEXT_PACKAGE, locale_dir);
+       g_free (locale_dir);
+
+       bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+       textdomain (GETTEXT_PACKAGE);
+       /* </i18n> */
+
        ghex_init_configuration ();
 
-       app = gtk_application_new("org.gtk.example", G_APPLICATION_FLAGS_NONE);
+       /* FIXME - don't know if NON_UNIQUE is correct for this context. */
+       app = gtk_application_new("org.gnome.GHex", G_APPLICATION_NON_UNIQUE);
        g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
+       g_application_register (G_APPLICATION (application), NULL, NULL);
 
        status = g_application_run (G_APPLICATION(app), argc, argv);
 
diff --git a/src/common-ui.c b/src/common-ui.c
index 00ad5ca5..d6fa90f6 100644
--- a/src/common-ui.c
+++ b/src/common-ui.c
@@ -24,9 +24,7 @@
    Original Author: Jaka Mocnik <jaka gnu org>
 */
 
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
+#include <config.h>            /* Not optional for this. */
 
 #include "common-ui.h"
 
diff --git a/src/ghex-application-window.c b/src/ghex-application-window.c
index 7c439bde..426b833c 100644
--- a/src/ghex-application-window.c
+++ b/src/ghex-application-window.c
@@ -1,18 +1,8 @@
 /* vim: ts=4 sw=4 colorcolumn=80
  */
-#include <glib/gi18n.h>
-#include <gtkhex.h>
 
 #include "ghex-application-window.h"
 
-#include "configuration.h"
-#include "hex-dialog.h"
-#include "findreplace.h"
-#include "chartable.h"
-#include "converter.h"
-#include "preferences.h"
-#include "common-ui.h"
-
 /* DEFINES */
 
 /* FIXME/TODO - this was an option before. Not sure I see the point in
@@ -277,7 +267,7 @@ pango_font_description_to_css (PangoFontDescription *desc)
        }
        if (set & PANGO_FONT_MASK_SIZE)
        {
-               g_string_append_printf (s, "font-size: %dpt",
+               g_string_append_printf (s, "font-size: %dpt; ",
                                pango_font_description_get_size (desc) / PANGO_SCALE);
        }
 
@@ -480,16 +470,16 @@ file_save (GHexApplicationWindow *self)
        doc = gtk_hex_get_document (self->gh);
        g_return_if_fail (HEX_IS_DOCUMENT (doc));
 
-       if (hex_document_write (doc))
-       {
+       if (hex_document_write (doc)) {
                /* we're happy... */
                g_debug ("%s: File saved successfully.", __func__);
        }
-       else
-       {
-               g_debug("%s: NOT IMPLEMENTED - show following message in GUI:",
-                               __func__);
-               g_debug(_("Error saving file!"));
+       else {
+               display_error_dialog (GTK_WINDOW(self),
+                               _("There was an error saving the file."
+                               "\n\n"
+                               "You permissions of the file may have been changed "
+                               "by another program, or the file may have become corrupted."));
        }
 }
 
@@ -675,6 +665,11 @@ close_doc_confirmation_dialog (GHexApplicationWindow *self)
        gtk_widget_show (dialog);
 }
 
+/* FIXME / TODO - I could see this function being useful, but right now it is
+ * not used by anything, so I'm disabling it to silence warnings about unused
+ * functions.
+ */
+#if 0
 static void
 enable_all_actions (GHexApplicationWindow *self, gboolean enable)
 {
@@ -706,6 +701,7 @@ enable_all_actions (GHexApplicationWindow *self, gboolean enable)
                ++i;
        }
 }
+#endif
 
 /* Kinda like enable_all_actions, but only for ghex-specific ones. */
 static void
@@ -1082,15 +1078,12 @@ save_as_response_cb (GtkNativeDialog *dialog,
                if (! change_ok) {
                        g_error ("%s: There was a fatal error changing the name of the "
                                        "file path. This should NOT happen and may be indicative "
-                                       "of a bug or programer error. Please file a bug report.");
+                                       "of a bug or programer error. Please file a bug report.",
+                                       __func__);
                }
                gtk_file_name = g_filename_to_utf8 (doc->file_name,
                                -1, NULL, NULL, NULL);
 
-               g_debug("%s: NOT IMPLEMENTED - show following message in GUI:",
-                               __func__);
-               g_debug(_("Saved buffer to file %s"), gtk_file_name);
-
                g_free(gtk_file_name);
        }
        else
diff --git a/src/ghex-application-window.h b/src/ghex-application-window.h
index ca7d26af..c0a50771 100644
--- a/src/ghex-application-window.h
+++ b/src/ghex-application-window.h
@@ -5,6 +5,16 @@
 #define GHEX_APPLICATION_WINDOW_H
 
 #include <gtk/gtk.h>
+#include <gtkhex.h>
+#include <glib/gi18n.h>
+
+#include "configuration.h"
+#include "hex-dialog.h"
+#include "findreplace.h"
+#include "chartable.h"
+#include "converter.h"
+#include "preferences.h"
+#include "common-ui.h"
 
 #define GHEX_TYPE_APPLICATION_WINDOW (ghex_application_window_get_type ())
 G_DECLARE_FINAL_TYPE (GHexApplicationWindow, ghex_application_window,
diff --git a/src/gtkhex.c b/src/gtkhex.c
index e3f2e964..37a07d88 100644
--- a/src/gtkhex.c
+++ b/src/gtkhex.c
@@ -41,6 +41,8 @@
 
 #ifdef ENABLE_DEBUG
 #define TEST_DEBUG_FUNCTION_START g_debug ("%s: start", __func__);
+#else
+#define TEST_DEBUG_FUNCTION_START /* */
 #endif
 
 #define NOT_IMPLEMENTED \
@@ -1486,8 +1488,8 @@ scroll_cb (GtkEventControllerScroll *controller,
        double old_value, new_value;
 
        TEST_DEBUG_FUNCTION_START
-       g_return_if_fail (GTK_IS_HEX(gh));
-//     g_return_if_fail (GTK_IS_WIDGET(widget));
+
+       g_return_val_if_fail (GTK_IS_HEX(gh), FALSE);
 
        old_value = gtk_adjustment_get_value(gh->adj);
        new_value = old_value + dy;
@@ -1772,7 +1774,7 @@ ascii_pressed_cb (GtkGestureClick *gesture,
        /* Middle-click press. */
        else if (button == GDK_BUTTON_MIDDLE)
        {
-               g_debug("%s: MIDDLE CLICK - NOT IMPLEMENTED.");
+               g_debug("%s: MIDDLE CLICK - NOT IMPLEMENTED.", __func__);
 #if 0
                GtkHexClass *klass = GTK_HEX_CLASS(GTK_WIDGET_GET_CLASS(gh));
                gchar *text;
diff --git a/src/main.c b/src/main.c
index 9288c5ee..b6314940 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,7 +1,10 @@
+/* vim: colorcolumn=80 ts=4 sw=4
+ */
 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
 /* main.c - genesis of a GHex application
 
-   Copyright (C) 1998 - 2004 Free Software Foundation
+   Copyright © 1998 - 2004 Free Software Foundation
+   Copyright © 2021 Logan Rathbone
 
    GHex is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -18,28 +21,21 @@
    If not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
-   Author: Jaka Mocnik <jaka gnu org>
+   Original Author: Jaka Mocnik <jaka gnu org>
 */
 
+#include <locale.h>
 #include <config.h>
-#include <glib/gi18n.h>
 
-#include "configuration.h"
-#include "ghex-window.h"
-
-/* Command line options */
-static gchar *geometry = NULL;
-static gchar **args_remaining = NULL;
-
-static GOptionEntry options[] = {
-        { "geometry", 'g', 0, G_OPTION_ARG_STRING, &geometry, N_("X geometry specification (see \"X\" man 
page)."), N_("GEOMETRY") },
-        { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &args_remaining, NULL, N_("FILES") },
-        { NULL }
-};
+#include "ghex-application-window.h"
 
+/* FIXME - TEST ON WIN32.
+ * This is one of the few functions in this file that has been ripped verbatim
+ * from the old main.c. It might work. Maybe.
+ */
 #ifdef G_OS_WIN32
-static gchar *
-_ghex_win32_locale_dir (void)
+static char *
+ghex_win32_locale_dir (void)
 {
     gchar *install_dir;
     gchar *locale_dir = NULL;
@@ -59,98 +55,57 @@ _ghex_win32_locale_dir (void)
 }
 #endif
 
-static gchar *
+static char *
 ghex_locale_dir (void)
 {
 #ifdef G_OS_WIN32
-    return _ghex_win32_locale_dir ();
+    return ghex_win32_locale_dir ();
 #else
     return g_strdup (LOCALEDIR);
 #endif
 }
 
 static void
-ghex_activate (GApplication *application,
-               gpointer      unused)
+activate (GtkApplication *app,
+       gpointer user_data)
 {
-    GList *windows = gtk_application_get_windows (GTK_APPLICATION (application));
-    gtk_window_present (GTK_WINDOW (windows->data));
+       GtkWidget *window;
+
+       (void)user_data;        /* unused */
+
+       window = ghex_application_window_new (app);
+
+       gtk_window_set_application (GTK_WINDOW(window), app);
+       gtk_window_present (GTK_WINDOW(window));
 }
 
 int
-main(int argc, char **argv)
+main (int argc, char *argv[])
 {
-       GtkWidget *win;
-       GError *error = NULL;
-       GtkApplication *application;
-       gchar *locale_dir;
-       gint retval;
+       GtkApplication *app;
+       char *locale_dir;
+       int status;
 
+       /* boilerplate i18n stuff */
+       setlocale (LC_ALL, "");
        locale_dir = ghex_locale_dir ();
        bindtextdomain (GETTEXT_PACKAGE, locale_dir);
        g_free (locale_dir);
 
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
        textdomain (GETTEXT_PACKAGE);
+       /* </i18n> */
+
+       ghex_init_configuration ();
+
+       /* FIXME - don't know if NON_UNIQUE is correct for this context. */
+       app = gtk_application_new("org.gnome.GHex", G_APPLICATION_NON_UNIQUE);
+       g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
+       g_application_register (G_APPLICATION (app), NULL, NULL);
+
+       status = g_application_run (G_APPLICATION(app), argc, argv);
+
+       g_object_unref(app);
 
-       /* Initialize GTK+ program */
-       if (!gtk_init_with_args (&argc, &argv,
-                                _("- GTK+ binary editor"),
-                                options,
-                                GETTEXT_PACKAGE,
-                                &error)) {
-               g_printerr (_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
-                           error->message, argv[0]);
-               g_error_free (error);
-               return 1;
-       }
-
-       /* Set default window icon */
-       gtk_window_set_default_icon_name ("org.gnome.GHex");
-
-       /* load preferences */
-       ghex_init_configuration();
-
-       /* accessibility setup */
-       setup_factory();
-
-       application = gtk_application_new ("org.gnome.GHex",
-                                          G_APPLICATION_NON_UNIQUE);
-       g_signal_connect (application, "activate",
-                         G_CALLBACK (ghex_activate), NULL);
-
-       g_application_register (G_APPLICATION (application), NULL, NULL);
-
-       if (args_remaining != NULL) {
-               gchar **filename;
-               for (filename = args_remaining; *filename != NULL; filename++) {
-                       if (g_file_test (*filename, G_FILE_TEST_EXISTS)) {
-                               win = ghex_window_new_from_file (application, *filename);
-                               if(win != NULL) {
-                                       if(geometry) {
-                                               if(!gtk_window_parse_geometry(GTK_WINDOW(win), geometry))
-                                                       g_warning(_("Invalid geometry string \"%s\"\n"), 
geometry);
-                                               geometry = NULL;
-                                       }
-                                       gtk_widget_show(win);
-                               }
-                       }
-               }
-       }
-
-       if(ghex_window_get_list() == NULL) {
-               win = ghex_window_new (application);
-               if(geometry) {
-                       if(!gtk_window_parse_geometry(GTK_WINDOW(win), geometry))
-                               g_warning(_("Invalid geometry string \"%s\"\n"), geometry);
-                       geometry = NULL;
-               }
-               gtk_widget_show(win);
-       }
-       else win = GTK_WIDGET(ghex_window_get_list()->data);
-
-       retval = g_application_run (G_APPLICATION (application), argc, argv);
-       g_object_unref (application);
-
-       return retval;
+       return status;
 }
diff --git a/src/meson.build b/src/meson.build
index c61260a0..45950341 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -9,9 +9,7 @@ libghex_headers = [
 ]
 
 libghex_deps = [
-  atk_dep,
   gtk_dep,
-  gail_dep
 ]
 
 libghex_c_args = [
@@ -46,31 +44,34 @@ libghex_dep = declare_dependency(
   sources: libghex_headers
 )
 
+# for i in `ls *.{c,h}`; do echo "  '${i}',"; done
 ghex_sources = [
   'chartable.c',
   'chartable.h',
+  'common-ui.c',
+  'common-ui.h',
   'configuration.c',
   'configuration.h',
   'converter.c',
   'converter.h',
   'findreplace.c',
   'findreplace.h',
-  'ghex-window.c',
-  'ghex-window.h',
+  'ghex-application-window.c',
+  'ghex-application-window.h',
+  'gtkhex.c',
+  'gtkhex.h',
   'hex-dialog.c',
   'hex-dialog.h',
-  'hex-document-ui.c',
+  'hex-document.c',
+  'hex-document.h',
   'main.c',
   'preferences.c',
   'preferences.h',
   'print.c',
-  'print.h',
-  'common-ui.c',
-  'common-ui.h'
+  'print.h'
 ]
 
 ghex_deps = [
-  atk_dep,
   gio_dep,
   gtk_dep
 ]


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