Use GResources for the UI file and the LICENSE

- The About dialog now displays the licence.
 - The main UI file is now integrated into the binary.

The project needed some of its ugly CMake code back.
This commit is contained in:
Přemysl Eric Janouch 2021-11-01 10:53:03 +01:00
parent 082f1aa41c
commit 3465557a5b
Signed by: p
GPG Key ID: A0420B94F92B9493
4 changed files with 59 additions and 3 deletions

View File

@ -143,6 +143,7 @@ set (logdiag_TESTS
diagram) diagram)
set (logdiag_SOURCES set (logdiag_SOURCES
${PROJECT_BINARY_DIR}/gresource.c
src/ld-window-main.c src/ld-window-main.c
src/logdiag.c) src/logdiag.c)
set (logdiag_HEADERS set (logdiag_HEADERS
@ -175,6 +176,48 @@ endfunction ()
glib_genmarshal (${PROJECT_SOURCE_DIR}/liblogdiag/ld-marshal.list ld_marshal) glib_genmarshal (${PROJECT_SOURCE_DIR}/liblogdiag/ld-marshal.list ld_marshal)
# Generate resources
function (glib_compile_resources xml target)
find_program (GLIB_COMPILE_RESOURCES_EXECUTABLE glib-compile-resources)
if (NOT GLIB_COMPILE_RESOURCES_EXECUTABLE)
message (FATAL_ERROR "glib-compile-resources not found")
endif ()
# glib-compile-resources reads paths relative to its working directory
get_filename_component (_xml_path "${xml}" PATH)
# On Windows, the final Makefile may contain:
# cd e:\abc && ...
# That won't actually change the directory. We have to do:
# cd e:\abc && e: && ...
set (_prefix)
if (WIN32 AND "${_xml_path}" MATCHES "^.:[/\\\\]")
string (SUBSTRING "${_xml_path}" 0 2 _xml_drive)
set (_prefix ${_xml_drive} &&)
endif ()
# VERBATIM would cause problems, so it is not used here
add_custom_command (OUTPUT ${target}
COMMAND ${_prefix} ${GLIB_COMPILE_RESOURCES_EXECUTABLE}
--generate-source --target ${target} "${xml}" DEPENDS "${xml}"
WORKING_DIRECTORY "${_xml_path}" COMMENT "Compiling resources")
# This refuses to accept drive changes, but it also needn't succeed
execute_process (COMMAND ${GLIB_COMPILE_RESOURCES_EXECUTABLE}
--generate-dependencies "${xml}"
WORKING_DIRECTORY "${_xml_path}" OUTPUT_VARIABLE _deps)
string (REPLACE "\n" ";" _deps "${_deps}")
foreach (_dep ${_deps})
set_property (SOURCE "${target}"
APPEND PROPERTY OBJECT_DEPENDS "${_xml_path}/${_dep}")
endforeach ()
configure_file ("${xml}" glib-compile-resources.stamp COPYONLY)
endfunction ()
glib_compile_resources (${PROJECT_SOURCE_DIR}/share/logdiag.gresource.xml
${PROJECT_BINARY_DIR}/gresource.c)
# Generate a configure file # Generate a configure file
add_definitions (-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_36) add_definitions (-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_36)
add_definitions (-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_36) add_definitions (-DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_36)
@ -349,7 +392,7 @@ else ()
endif () endif ()
install (DIRECTORY docs/user-guide DESTINATION share/doc/${PROJECT_NAME}) install (DIRECTORY docs/user-guide DESTINATION share/doc/${PROJECT_NAME})
install (DIRECTORY share/gui share/library DESTINATION share/${PROJECT_NAME}) install (DIRECTORY share/library DESTINATION share/${PROJECT_NAME})
install (FILES ${GSETTINGS_SCHEMAS} DESTINATION share/glib-2.0/schemas) install (FILES ${GSETTINGS_SCHEMAS} DESTINATION share/glib-2.0/schemas)
install (CODE " # DESTDIR is not in use on Windows (WIN32 is only native here!) install (CODE " # DESTDIR is not in use on Windows (WIN32 is only native here!)
if (WIN32 OR \"\$ENV{DESTDIR}\" STREQUAL \"\") if (WIN32 OR \"\$ENV{DESTDIR}\" STREQUAL \"\")

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/logdiag">
<file>logdiag.ui</file>
<file alias="LICENSE">../LICENSE</file>
</gresource>
</gresources>

View File

@ -274,8 +274,8 @@ ld_window_main_init (LdWindowMain *self)
priv->action_group, 0); priv->action_group, 0);
error = NULL; error = NULL;
gtk_ui_manager_add_ui_from_file gtk_ui_manager_add_ui_from_resource
(priv->ui_manager, PROJECT_SHARE_DIR "gui/window-main.ui", &error); (priv->ui_manager, "/logdiag/logdiag.ui", &error);
if (error) if (error)
{ {
g_message ("building UI failed: %s", error->message); g_message ("building UI failed: %s", error->message);
@ -1153,6 +1153,10 @@ static void
on_action_about (GtkAction *action, LdWindowMain *self) on_action_about (GtkAction *action, LdWindowMain *self)
{ {
GtkWidget *about_dialog; GtkWidget *about_dialog;
GBytes *license;
license = g_resources_lookup_data ("/logdiag/LICENSE",
G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
about_dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG, about_dialog = g_object_new (GTK_TYPE_ABOUT_DIALOG,
"program-name", PROJECT_NAME, "program-name", PROJECT_NAME,
@ -1160,9 +1164,11 @@ on_action_about (GtkAction *action, LdWindowMain *self)
"version", PROJECT_VERSION, "version", PROJECT_VERSION,
"translator-credits", _("translator-credits"), "translator-credits", _("translator-credits"),
"copyright", "Copyright 2010 - 2021 Přemysl Eric Janouch", "copyright", "Copyright 2010 - 2021 Přemysl Eric Janouch",
"license", g_bytes_get_data (license, NULL),
"website", PROJECT_URL, "website", PROJECT_URL,
NULL); NULL);
g_bytes_unref (license);
g_signal_connect (about_dialog, "activate-link", g_signal_connect (about_dialog, "activate-link",
G_CALLBACK (on_action_about_activate_link), self); G_CALLBACK (on_action_about_activate_link), self);