[ghex/gtk4-port: 45/91] Help and about; start redoing common callbacks.
- From: Logan Rathbone <larathbone src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ghex/gtk4-port: 45/91] Help and about; start redoing common callbacks.
- Date: Thu, 12 Aug 2021 23:35:10 +0000 (UTC)
commit 67323f15b03026bad6f162271a85a7d35be82bf7
Author: Logan Rathbone <poprocks gmail com>
Date: Wed Jan 20 12:20:24 2021 -0500
Help and about; start redoing common callbacks.
Also some preliminary changes made to the meson config to avoid
duplicitous code and settings.
data/meson.build | 17 ++-
...x.gschema.xml => org.gnome.GHex.gschema.xml.in} | 1 +
meson.build | 4 +
src/Makefile | 3 +-
src/{ui.c => common-ui.c} | 147 ++++++++++++++-------
src/common-ui.h | 44 ++++++
src/configuration.c | 2 -
src/configuration.h | 3 -
src/ghex-application-window.c | 21 ++-
src/preferences.c | 81 +++++++++++-
src/preferences.h | 8 +-
src/ui.h | 93 -------------
12 files changed, 257 insertions(+), 167 deletions(-)
---
diff --git a/data/meson.build b/data/meson.build
index 9135a87a..e9b900ee 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -1,8 +1,3 @@
-install_data(
- 'org.gnome.GHex.gschema.xml',
- install_dir: ghex_schemasdir
-)
-
ghex_desktop = i18n.merge_file(
input: 'org.gnome.GHex.desktop.in',
output: 'org.gnome.GHex.desktop',
@@ -33,6 +28,8 @@ pkg_conf.set('includedir', ghex_includedir)
pkg_conf.set('VERSION', meson.project_version())
+pkg_conf.set_quoted('XML_SHADED_BOX_MAX', shaded_box_max.to_string())
+
configure_file(
input: 'gtkhex-4.pc.in',
output: 'gtkhex-4.pc',
@@ -41,12 +38,20 @@ configure_file(
install: true
)
+configure_file(
+ input: 'org.gnome.GHex.gschema.xml.in',
+ output: 'org.gnome.GHex.gschema.xml',
+ configuration: pkg_conf,
+ install_dir: ghex_schemasdir,
+ install: true
+)
+
ghex_appdata = i18n.merge_file(
input: 'org.gnome.GHex.appdata.xml.in',
output: 'org.gnome.GHex.appdata.xml',
po_dir: ghex_po_dir,
install_dir: ghex_appdatadir,
- install: true,
+ install: true
)
appstream_util_prg = find_program(
diff --git a/data/org.gnome.GHex.gschema.xml b/data/org.gnome.GHex.gschema.xml.in
similarity index 95%
rename from data/org.gnome.GHex.gschema.xml
rename to data/org.gnome.GHex.gschema.xml.in
index 8941643a..32f8a54d 100644
--- a/data/org.gnome.GHex.gschema.xml
+++ b/data/org.gnome.GHex.gschema.xml.in
@@ -25,6 +25,7 @@
<default>'Sans 12'</default>
</key>
<key name="print-shaded-rows" type="u">
+ <range min="0" max=@XML_SHADED_BOX_MAX@>
<default>0</default>
</key>
<key name="show-offsets" type="b">
diff --git a/meson.build b/meson.build
index d734f6f0..cae357c7 100644
--- a/meson.build
+++ b/meson.build
@@ -31,6 +31,8 @@ i18n = import('i18n')
cc = meson.get_compiler('c')
+shaded_box_max = 1000
+
ghex_conf = configuration_data()
ghex_conf.set_quoted('PACKAGE_NAME', meson.project_name())
ghex_conf.set_quoted('PACKAGE_VERSION', meson.project_version())
@@ -43,6 +45,8 @@ ghex_conf.set('VERSION', 'PACKAGE_VERSION')
ghex_conf.set('GETTEXT_PACKAGE', 'PACKAGE_NAME')
ghex_conf.set('LOCALEDIR', 'PACKAGE_LOCALE_DIR')
+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.set10('ENABLE_NLS', true) # Always enabled
diff --git a/src/Makefile b/src/Makefile
index e8f22967..b383dc7c 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -7,11 +7,12 @@ CFLAGS=-Wall -Wextra -Werror=implicit -std=c11 -pedantic \
-Wno-unused-variable -Wno-unused-parameter \
$(GTK_CFLAGS) \
-I../build -I. \
+ -DHAVE_CONFIG_H \
$(DEBUG)
.PHONY: clean compile-resources
-STUB: gtkhex.o hex-document.o ghex-application-window.o hex-dialog.o findreplace.o chartable.o converter.o
resources.o configuration.o preferences.o
+STUB: gtkhex.o hex-document.o ghex-application-window.o hex-dialog.o findreplace.o chartable.o converter.o
resources.o configuration.o preferences.o common-ui.o
compile-resources:
glib-compile-resources ghex.gresource.xml --target=resources.c --generate-source
diff --git a/src/ui.c b/src/common-ui.c
similarity index 87%
rename from src/ui.c
rename to src/common-ui.c
index 42d8eb77..3ce691d4 100644
--- a/src/ui.c
+++ b/src/common-ui.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 -*- */
-/* ui.c - main menus and callbacks; utility functions
+/* common-ui.c - Common UI utility functions
Copyright (C) 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,24 +21,16 @@
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 <config.h>
-#include <string.h>
-#include <unistd.h> /* for F_OK and W_OK */
-
-#include <gtk/gtk.h>
-#include <glib/gi18n.h>
-
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
-#include "ui.h"
-#include "ghex-window.h"
-#include "findreplace.h"
-#include "converter.h"
-#include "print.h"
-#include "chartable.h"
+#include "common-ui.h"
+#if 0
static void ghex_print(GtkHex *gh, gboolean preview);
guint group_type[3] = {
@@ -111,19 +106,21 @@ create_dialog_title(GtkWidget *window, gchar *title)
return;
win = ghex_window_get_active();
-
-#if defined(__GNUC__) && (__GNUC__ > 4)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wformat-nonliteral"
-#endif
- if(win != NULL && win->gh != NULL)
- full_title = g_strdup_printf(title, win->gh->document->path_end);
- else
- full_title = g_strdup_printf(title, "");
-#if defined(__GNUC__) && (__GNUC__ > 4)
-#pragma GCC diagnostic pop
#endif
+//#if defined(__GNUC__) && (__GNUC__ > 4)
+//#pragma GCC diagnostic push
+//#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+//#endif
+// if(win != NULL && win->gh != NULL)
+// full_title = g_strdup_printf(title, win->gh->document->path_end);
+// else
+// full_title = g_strdup_printf(title, "");
+//#if defined(__GNUC__) && (__GNUC__ > 4)
+//#pragma GCC diagnostic pop
+//#endif
+
+#if 0
if(full_title) {
gtk_window_set_title(GTK_WINDOW(window), full_title);
g_free(full_title);
@@ -198,38 +195,88 @@ about_cb (GtkAction *action,
g_free (license_translated);
g_free (copyright);
}
+#endif
void
-help_cb (GtkAction *action,
- GHexWindow *window)
+common_help_cb (GtkWindow *parent)
{
- GError *error = NULL;
-
- gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (window)),
+ gtk_show_uri (parent,
"help:ghex",
- gtk_get_current_event_time (),
- &error);
+ GDK_CURRENT_TIME);
+}
- if (error != NULL) {
- GtkWidget *dialog;
- dialog = gtk_message_dialog_new (NULL,
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_CLOSE,
- _("There was an error displaying help: \n%s"),
- error->message);
- g_signal_connect (G_OBJECT (dialog), "response",
- G_CALLBACK (gtk_widget_destroy),
- NULL);
+void
+common_about_cb (GtkWindow *parent)
+{
+ char *copyright;
+ char *license_translated;
- gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
- gtk_window_present (GTK_WINDOW (dialog));
+ g_return_if_fail (GTK_IS_WINDOW(parent));
- g_error_free (error);
- }
+ const char *authors[] = {
+ "Jaka Mo\304\215nik",
+ "Chema Celorio",
+ "Shivram Upadhyayula",
+ "Rodney Dawes",
+ "Jonathon Jongsma",
+ "Kalev Lember",
+ "Logan Rathbone",
+ NULL
+ };
+
+ const char *documentation_credits[] = {
+ "Jaka Mo\304\215nik",
+ "Sun GNOME Documentation Team",
+ NULL
+ };
+
+ const char *license[] = {
+ N_("This program 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."),
+ N_("This program 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."),
+ N_("You should have received a copy of the GNU General Public License "
+ "along with this program; if not, write to the Free Software Foundation, Inc., "
+ "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA")
+ };
+ license_translated = g_strjoin ("\n\n",
+ _(license[0]),
+ _(license[1]),
+ _(license[2]),
+ NULL);
+
+ /* Translators: these two strings here indicate the copyright time span,
+ e.g. 1998-2018. */
+ copyright = g_strdup_printf (_("Copyright © %Id–%Id The GHex authors"),
+ 1998, 2021);
+
+ gtk_show_about_dialog (parent,
+ "authors", authors,
+ "comments", _("A binary file editor"),
+ "copyright", copyright,
+ "documenters", documentation_credits,
+ "license", license_translated,
+ "logo-icon-name", "org.gnome.GHex",
+ "program-name", "GHex",
+ "title", _("About GHex"),
+ "translator-credits", _("translator-credits"),
+ "version", PACKAGE_VERSION,
+ "website", "https://wiki.gnome.org/Apps/Ghex",
+ "website-label", _("GHex Website"),
+ "wrap-license", TRUE,
+ NULL);
+
+ g_free (license_translated);
+ g_free (copyright);
}
+
+#if 0
void
paste_cb (GtkAction *action,
gpointer user_data)
@@ -436,9 +483,6 @@ export_html_cb (GtkAction *action,
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL,
GTK_STOCK_SAVE,
GTK_RESPONSE_OK,
NULL);
-#if 0
- gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(file_sel), doc->file_name);
-#endif
gtk_window_set_modal(GTK_WINDOW(file_sel), TRUE);
gtk_window_set_position(GTK_WINDOW (file_sel), GTK_WIN_POS_MOUSE);
gtk_widget_show(file_sel);
@@ -915,4 +959,5 @@ remove_view_cb (GtkAction *action,
ghex_window_close(win);
}
+#endif
diff --git a/src/common-ui.h b/src/common-ui.h
new file mode 100644
index 00000000..d90c6c5c
--- /dev/null
+++ b/src/common-ui.h
@@ -0,0 +1,44 @@
+/* vim: colorcolumn=80 ts=4 sw=4
+ */
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* common-ui.h - Common UI utility functions
+
+ Copyright (C) 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>
+*/
+
+#ifndef COMMON_UI_H
+#define COMMON_UI_H
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+
+#include "configuration.h"
+
+G_BEGIN_DECLS
+
+/* various ui convenience functions */
+
+void common_help_cb (GtkWindow *parent);
+void common_about_cb (GtkWindow *parent);
+
+G_END_DECLS
+
+#endif /* COMMON_UI_H */
diff --git a/src/configuration.c b/src/configuration.c
index 3067ee23..c747695b 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -27,8 +27,6 @@
# include <config.h>
#endif /* HAVE_CONFIG_H */
-#include <string.h>
-
#include "configuration.h"
GSettings *settings;
diff --git a/src/configuration.h b/src/configuration.h
index d196d037..46847001 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -28,9 +28,6 @@
#include <gtk/gtk.h>
-#include "preferences.h"
-#include "configuration.h"
-
G_BEGIN_DECLS
/* GSettings keys */
diff --git a/src/ghex-application-window.c b/src/ghex-application-window.c
index 8a873a81..502b3e9b 100644
--- a/src/ghex-application-window.c
+++ b/src/ghex-application-window.c
@@ -11,6 +11,7 @@
#include "chartable.h"
#include "converter.h"
#include "preferences.h"
+#include "common-ui.h"
/* DEFINES */
@@ -985,6 +986,19 @@ toggle_conversions (GtkWidget *widget,
}
+static void
+open_about (GtkWidget *widget,
+ const char *action_name,
+ GVariant *parameter)
+{
+ GHexApplicationWindow *self = GHEX_APPLICATION_WINDOW(widget);
+ GtkWidget *prefs_dialog;
+
+ (void)parameter, (void)action_name; /* unused */
+
+ common_about_cb (GTK_WINDOW(self));
+}
+
static void
open_preferences (GtkWidget *widget,
const char *action_name,
@@ -995,8 +1009,7 @@ open_preferences (GtkWidget *widget,
(void)parameter, (void)action_name; /* unused */
- // TEST
- prefs_dialog = create_preferences_dialog();
+ prefs_dialog = create_preferences_dialog (GTK_WINDOW(self));
gtk_widget_show (prefs_dialog);
}
@@ -1589,6 +1602,10 @@ ghex_application_window_class_init(GHexApplicationWindowClass *klass)
NULL, // GVariant string param_type
open_preferences);
+ gtk_widget_class_install_action (widget_class, "ghex.about",
+ NULL, // GVariant string param_type
+ open_about);
+
gtk_widget_class_install_property_action (widget_class,
"ghex.find", "find-open");
diff --git a/src/preferences.c b/src/preferences.c
index 5ab8ae49..cc85def0 100644
--- a/src/preferences.c
+++ b/src/preferences.c
@@ -24,17 +24,24 @@
Original Author: Jaka Mocnik <jaka gnu org>
*/
+#include "preferences.h"
+
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
-#include "preferences.h"
+/* CONSTANTS */
-/* provides ``settings'' and def_* globals, as well as GHEX_PREF_* defines. */
-#include "configuration.h"
+#ifdef HAVE_CONFIG_H
+# define SHADED_BOX_MAX CONFIG_H_SHADED_BOX_MAX
+#else
+# define SHADED_BOX_MAX 1000
+#endif
#define PREFS_RESOURCE "/org/gnome/ghex/preferences.ui"
+/* MACROS */
+
#define GET_WIDGET(X) \
X = GTK_WIDGET(gtk_builder_get_object (builder, #X)); \
g_assert (GTK_IS_WIDGET (X))
@@ -79,6 +86,8 @@ static GtkWidget *long_chkbtn;
static GtkWidget *shaded_box_chkbtn;
static GtkWidget *shaded_box_spinbtn;
static GtkWidget *shaded_box_box;
+static GtkWidget *close_button;
+static GtkWidget *help_button;
/* PRIVATE DECLARATIONS */
@@ -127,9 +136,30 @@ do_css_stuff(void)
#undef APPLY_PROVIDER_TO
static void
-shaded_box_spinbtn_value_changed_cb (GtkSpinButton *spin_button,
+close_clicked_cb (GtkButton *button,
gpointer user_data)
{
+ (void)user_data; /* unused */
+ g_return_if_fail (GTK_IS_WINDOW (prefs_dialog));
+
+ gtk_window_destroy (GTK_WINDOW(prefs_dialog));
+}
+
+static void
+help_clicked_cb (GtkButton *button,
+ gpointer user_data)
+{
+ (void)user_data; /* unused */
+ g_return_if_fail (GTK_IS_WINDOW (prefs_dialog));
+
+ common_help_cb (GTK_WINDOW(prefs_dialog));
+}
+
+/* wee helper */
+static void
+sync_shaded_box_size_with_spinbtn (void)
+{
+ GtkSpinButton *spin_button = GTK_SPIN_BUTTON(shaded_box_spinbtn);
/* we _want_ implicit conversion here. */
guint tmp = gtk_spin_button_get_value_as_int (spin_button);
@@ -140,6 +170,15 @@ shaded_box_spinbtn_value_changed_cb (GtkSpinButton *spin_button,
}
}
+static void
+shaded_box_spinbtn_value_changed_cb (GtkSpinButton *spin_button,
+ gpointer user_data)
+{
+ (void)spin_button, (void)user_data; /* unused */
+
+ sync_shaded_box_size_with_spinbtn ();
+}
+
static void
shaded_box_chkbtn_toggled_cb (GtkCheckButton *checkbutton,
gpointer user_data)
@@ -152,6 +191,14 @@ shaded_box_chkbtn_toggled_cb (GtkCheckButton *checkbutton,
gtk_widget_set_sensitive (shaded_box_box,
checked ? TRUE : FALSE);
+
+ if (checked) {
+ sync_shaded_box_size_with_spinbtn ();
+ } else if (shaded_box_size) {
+ g_settings_set_uint (settings,
+ GHEX_PREF_BOX_SIZE,
+ 0);
+ }
}
static void
@@ -297,6 +344,14 @@ setup_signals (void)
g_signal_connect (shaded_box_spinbtn, "value-changed",
G_CALLBACK(shaded_box_spinbtn_value_changed_cb), NULL);
+
+ /* close and help */
+
+ g_signal_connect (close_button, "clicked",
+ G_CALLBACK(close_clicked_cb), NULL);
+
+ g_signal_connect (help_button, "clicked",
+ G_CALLBACK(help_clicked_cb), NULL);
}
/* put all of your GET_WIDGET calls other than the main prefs_dialog widget
@@ -359,6 +414,8 @@ grab_widget_values_from_settings (void)
static void
init_widgets (void)
{
+ GET_WIDGET (prefs_dialog);
+
GET_WIDGET (font_button);
GET_WIDGET (data_font_button);
GET_WIDGET (header_font_button);
@@ -369,13 +426,20 @@ init_widgets (void)
GET_WIDGET (shaded_box_chkbtn);
GET_WIDGET (shaded_box_spinbtn);
GET_WIDGET (shaded_box_box);
+ GET_WIDGET (close_button);
+ GET_WIDGET (help_button);
/* Make certain font choosers only allow monospace fonts. */
monospace_only (font_button);
monospace_only (data_font_button);
/* shaded box entry */
- shaded_box_adj = GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, 1000, 1, 10, 0));
+ shaded_box_adj = GTK_ADJUSTMENT(gtk_adjustment_new(1,
+ 1, /* min; no point in having 0 if ineffective */
+ SHADED_BOX_MAX,
+ 1, /* step incr */
+ 10, /* page incr */
+ 0)); /* page size */
gtk_spin_button_set_adjustment (GTK_SPIN_BUTTON(shaded_box_spinbtn),
shaded_box_adj);
}
@@ -383,7 +447,7 @@ init_widgets (void)
/* PUBLIC FUNCTIONS */
GtkWidget *
-create_preferences_dialog (void)
+create_preferences_dialog (GtkWindow *parent)
{
builder = gtk_builder_new_from_resource (PREFS_RESOURCE);
@@ -392,7 +456,10 @@ create_preferences_dialog (void)
grab_widget_values_from_settings ();
setup_signals ();
- GET_WIDGET (prefs_dialog);
+ if (parent) {
+ g_assert (GTK_IS_WINDOW (parent));
+ gtk_window_set_transient_for (GTK_WINDOW(prefs_dialog), parent);
+ }
return prefs_dialog;
}
diff --git a/src/preferences.h b/src/preferences.h
index 913dcac6..47756f5f 100644
--- a/src/preferences.h
+++ b/src/preferences.h
@@ -1,3 +1,5 @@
+/* vim: colorcolumn=80 ts=4 sw=4
+ */
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* preferences.h - Declarations pertaining to preferences
@@ -30,10 +32,12 @@
#include <string.h>
#include <gtkhex.h> /* for GROUP_* enums */
+#include "configuration.h"
+#include "common-ui.h"
+
G_BEGIN_DECLS
-GtkWidget * create_preferences_dialog(void);
-//void set_current_prefs(PropertyUI *pui);
+GtkWidget * create_preferences_dialog (GtkWindow *parent);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]