This commits allows to load ui files without the need to install virt-viewer. It helps a lot developers testing changes in the ui files and also avoid crashes like [0] when running remote-viewer in tree without any previous installation of virt-viewer. [0]: fidenci@cat ~/src/upstream/virt-viewer $ ./src/remote-viewer (remote-viewer:29951): virt-viewer-ERROR **: failed to find UI description file Trace/breakpoint trap (core dumped) Signed-off-by: Fabiano Fidêncio <fidencio@xxxxxxxxxx> --- src/Makefile.am | 2 +- src/virt-viewer-util.c | 33 ++++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 171a141..ac7177d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -187,7 +187,7 @@ if OS_WIN32 remote_viewer_LDFLAGS += -Wl,--subsystem,windows endif -AM_CPPFLAGS = -DPACKAGE_DATADIR=\""$(pkgdatadir)"\" +AM_CPPFLAGS = -DPACKAGE_DATADIR=\""$(pkgdatadir)"\" -DSOURCE_DIR=\""$(abs_srcdir)"\" VIRT_VIEWER_RES = virt-viewer.rc virt-viewer.manifest ICONDIR = $(top_builddir)/icons diff --git a/src/virt-viewer-util.c b/src/virt-viewer-util.c index 6fe6c04..d82b97f 100644 --- a/src/virt-viewer-util.c +++ b/src/virt-viewer-util.c @@ -65,19 +65,42 @@ virt_viewer_util_try_to_load_ui_from_system_data_dirs(GtkBuilder *builder, const return success; } -static gboolean -virt_viewer_util_try_to_load_ui_from_non_system_data_dirs(GtkBuilder *builder, const gchar *name, GError **error) +static void +virt_viewer_util_check_for_g_file_error_noent(const gchar *path, GError **error) { - gchar *path = g_build_filename(PACKAGE_DATADIR, "ui", name, NULL); - gboolean success = (gtk_builder_add_from_file(builder, path, error) != 0); - if (*error != NULL) { if (!((*error)->domain == G_FILE_ERROR && (*error)->code == G_FILE_ERROR_NOENT)) g_warning("Failed to add ui file '%s': %s", path, (*error)->message); g_clear_error(error); } +} + +static gboolean +virt_viewer_util_try_to_load_ui_from_non_system_data_dirs(GtkBuilder *builder, const gchar *name, GError **error) +{ + gchar *path; + gboolean success; + + /* + * Firstly, try to load the ui file from the $srcdir. + * It allows developers to test changes done in the ui file without + * installing virt-viewer. + */ + path = g_build_filename(SOURCE_DIR, name, NULL); + success = (gtk_builder_add_from_file(builder, path, error) != 0); + virt_viewer_util_check_for_g_file_error_noent(path, error); g_free(path); + if (!success) { + /* + * And only then try to load the ui file from the $pkgdatadir. + */ + path = g_build_filename(PACKAGE_DATADIR, "ui", name, NULL); + success = (gtk_builder_add_from_file(builder, path, error) != 0); + virt_viewer_util_check_for_g_file_error_noent(path, error); + g_free(path); + } + return success; } -- 2.5.0 _______________________________________________ virt-tools-list mailing list virt-tools-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/virt-tools-list