[virt-tools-list] [virt-viewer v2 3/3] util: allow loading an in-tree ui file
Fabiano Fidêncio
fidencio at redhat.com
Thu Feb 25 13:03:40 UTC 2016
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 abortions like [0] when running remote-viewer from the
source tree and without having any previous installation.
[0]:
fidenci at 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 at redhat.com>
---
src/Makefile.am | 2 +-
src/virt-viewer-util.c | 35 +++++++++++++++++++++++++++++++----
2 files changed, 32 insertions(+), 5 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 d6dbbe4..705eb36 100644
--- a/src/virt-viewer-util.c
+++ b/src/virt-viewer-util.c
@@ -67,11 +67,10 @@ virt_viewer_util_try_to_load_ui_from_system_data_dirs(GtkBuilder *builder,
}
static gboolean
-virt_viewer_util_try_to_load_ui_from_non_system_data_dirs(GtkBuilder *builder,
- const gchar *name,
- GError **error)
+virt_viewer_util_add_to_builder_from_file(GtkBuilder *builder,
+ const gchar *path,
+ GError **error)
{
- gchar *path = g_build_filename(PACKAGE_DATADIR, "ui", name, NULL);
GError *local_error = NULL;
gboolean ret = (gtk_builder_add_from_file(builder, path, &local_error) != 0);
@@ -84,8 +83,36 @@ virt_viewer_util_try_to_load_ui_from_non_system_data_dirs(GtkBuilder *builder,
g_warning("Failed to add ui file '%s': %s", path, local_error->message);
g_clear_error(&local_error);
}
+
+ return ret;
+}
+
+static gboolean
+virt_viewer_util_try_to_load_ui_from_non_system_data_dirs(GtkBuilder *builder,
+ const gchar *name,
+ GError **error)
+{
+ gboolean ret;
+ gchar *path;
+
+ /*
+ * 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);
+ ret = virt_viewer_util_add_to_builder_from_file(builder, path, error);
g_free(path);
+ if (!ret) {
+ /*
+ * And only then try to load the ui file from the $pkgdatadir.
+ */
+ path = g_build_filename(PACKAGE_DATADIR, "ui", name, NULL),
+ ret = virt_viewer_util_add_to_builder_from_file(builder, path, error);
+ g_free(path);
+ }
+
return ret;
}
--
2.5.0
More information about the virt-tools-list
mailing list