diff options
author | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2017-07-03 12:40:55 +0200 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2017-07-03 12:40:55 +0200 |
commit | 48d334acbeb665aae9c2f9f4867ff0afe836e7d3 (patch) | |
tree | 6ca13a6fbf4ef00eee73b5c76e2c9e1cbaa20293 | |
parent | f6b224b1cb6a7004a46c3606413db63f5101b816 (diff) | |
download | uca-48d334acbeb665aae9c2f9f4867ff0afe836e7d3.tar.gz uca-48d334acbeb665aae9c2f9f4867ff0afe836e7d3.tar.bz2 uca-48d334acbeb665aae9c2f9f4867ff0afe836e7d3.tar.xz uca-48d334acbeb665aae9c2f9f4867ff0afe836e7d3.zip |
gui: use glib-resources to bake in UI
-rw-r--r-- | bin/gui/CMakeLists.txt | 53 | ||||
-rw-r--r-- | bin/gui/config.h.in | 1 | ||||
-rw-r--r-- | bin/gui/uca-camera-control.c | 37 | ||||
-rw-r--r-- | bin/gui/uca-camera-control.glade (renamed from bin/gui/control.glade) | 0 | ||||
-rw-r--r-- | bin/gui/uca-camera-control.gresource.xml | 6 |
5 files changed, 65 insertions, 32 deletions
diff --git a/bin/gui/CMakeLists.txt b/bin/gui/CMakeLists.txt index e722ab0..a8869dd 100644 --- a/bin/gui/CMakeLists.txt +++ b/bin/gui/CMakeLists.txt @@ -1,44 +1,55 @@ cmake_minimum_required(VERSION 2.6) -#{{{ Variables -set(CMAKE_INSTALL_GLADEDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/libuca") -#}}} -#{{{ Configure find_package(PkgConfig) +find_program(GLIB_COMPILE_RESOURCES glib-compile-resources REQUIRED) pkg_check_modules(GTK2 gtk+-2.0>=2.22) pkg_check_modules(GTHREAD2 gthread-2.0) -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in - ${CMAKE_CURRENT_BINARY_DIR}/config.h) - -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/control.glade - ${CMAKE_CURRENT_BINARY_DIR}) -#}}} -#{{{ Target if (GTK2_FOUND) + set(GRESOURCES_XML "${CMAKE_CURRENT_SOURCE_DIR}/uca-camera-control.gresource.xml") + set(GRESOURCES_H "${CMAKE_CURRENT_BINARY_DIR}/resources.h") + set(GRESOURCES_C "${CMAKE_CURRENT_BINARY_DIR}/resources.c") + + add_custom_command( + OUTPUT ${GRESOURCES_H} + COMMAND ${GLIB_COMPILE_RESOURCES} + --target ${GRESOURCES_H} + --generate-header ${GRESOURCES_XML} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/uca-camera-control.glade" ${GRESOURCES_XML} + ) + + add_custom_command( + OUTPUT ${GRESOURCES_C} + COMMAND ${GLIB_COMPILE_RESOURCES} + --target ${GRESOURCES_C} + --generate-source ${GRESOURCES_XML} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/uca-camera-control.glade" ${GRESOURCES_XML} + ) + include_directories(${GTK2_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}) - set(BINARY "uca-camera-control") - add_executable(${BINARY} + add_executable(uca-camera-control uca-camera-control.c egg-property-cell-renderer.c egg-property-tree-view.c - egg-histogram-view.c) + egg-histogram-view.c + ${GRESOURCES_C} + ) + + add_custom_target(resources DEPENDS ${GRESOURCES_C} ${GRESOURCES_H}) + add_dependencies(uca-camera-control resources) - target_link_libraries(${BINARY} + target_link_libraries(uca-camera-control m uca ${GTK2_LIBRARIES} ${GTHREAD2_LIBRARIES}) - install(TARGETS ${BINARY} + install(TARGETS uca-camera-control RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT executables) - - install(FILES control.glade - DESTINATION ${CMAKE_INSTALL_GLADEDIR} - COMPONENT executables) endif() -#}}} diff --git a/bin/gui/config.h.in b/bin/gui/config.h.in deleted file mode 100644 index 7d4d5a0..0000000 --- a/bin/gui/config.h.in +++ /dev/null @@ -1 +0,0 @@ -#define CONTROL_GLADE_PATH "${CMAKE_INSTALL_GLADEDIR}/control.glade" diff --git a/bin/gui/uca-camera-control.c b/bin/gui/uca-camera-control.c index f59460d..375de2f 100644 --- a/bin/gui/uca-camera-control.c +++ b/bin/gui/uca-camera-control.c @@ -23,12 +23,12 @@ #include <cairo.h> #include <string.h> -#include "config.h" #include "uca-camera.h" #include "uca-plugin-manager.h" #include "uca-ring-buffer.h" #include "egg-property-tree-view.h" #include "egg-histogram-view.h" +#include "resources.h" typedef enum { IDLE, @@ -1548,6 +1548,29 @@ create_choice_window (GtkBuilder *builder) g_list_free (camera_types); } +static gboolean +builder_add_from_resource (GtkBuilder *builder, const gchar *resource_path, GError **error) +{ + GBytes *data; + const gchar *buffer; + gsize length; + gboolean ret; + + g_assert (error && *error == NULL); + data = g_resources_lookup_data (resource_path, 0, error); + + if (data == NULL) + return FALSE; + + length = 0; + buffer = g_bytes_get_data (data, &length); + g_assert (buffer != NULL); + + ret = gtk_builder_add_from_string (builder, buffer, length, error) > 0; + g_bytes_unref (data); + return ret; +} + int main (int argc, char *argv[]) { @@ -1578,15 +1601,9 @@ main (int argc, char *argv[]) builder = gtk_builder_new (); - if (!gtk_builder_add_from_file (builder, CONTROL_GLADE_PATH, &error)) { - g_warning ("Cannot load UI: `%s'. Trying in current working directory.", error->message); - g_error_free (error); - error = NULL; - - if (!gtk_builder_add_from_file (builder, "control.glade", &error)) { - g_warning ("Cannot load UI: `%s'.", error->message); - return 1; - } + if (!builder_add_from_resource (builder, "/edu/kit/ipe/uca-camera-control/uca-camera-control.glade", &error)) { + g_warning ("Could not load UI: %s", error->message); + return 1; } plugin_manager = uca_plugin_manager_new (); diff --git a/bin/gui/control.glade b/bin/gui/uca-camera-control.glade index 967fdf0..967fdf0 100644 --- a/bin/gui/control.glade +++ b/bin/gui/uca-camera-control.glade diff --git a/bin/gui/uca-camera-control.gresource.xml b/bin/gui/uca-camera-control.gresource.xml new file mode 100644 index 0000000..5c84a0d --- /dev/null +++ b/bin/gui/uca-camera-control.gresource.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<gresources> + <gresource prefix="/edu/kit/ipe/uca-camera-control"> + <file compressed="true">uca-camera-control.glade</file> + </gresource> +</gresources> |