[gssdp/gssdp_1.0] sniffer: Modify ui file search order
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gssdp/gssdp_1.0] sniffer: Modify ui file search order
- Date: Fri, 26 Oct 2018 18:58:52 +0000 (UTC)
commit 90f42ba3267f6ed130bf9a818f02d04e9d01d45e
Author: Jens Georg <mail jensge org>
Date: Fri Oct 26 20:57:00 2018 +0200
sniffer: Modify ui file search order
Search order is as follows:
- Current dir
- Next to the executable
- Install path
Also change the way to look for the file. Just use
gtk_builder_add_from_file and have it fail when the path does not exist
tools/gssdp-device-sniffer.c | 32 +++++++++++++++-----------------
1 file changed, 15 insertions(+), 17 deletions(-)
---
diff --git a/tools/gssdp-device-sniffer.c b/tools/gssdp-device-sniffer.c
index 96442d6..0a16bc5 100644
--- a/tools/gssdp-device-sniffer.c
+++ b/tools/gssdp-device-sniffer.c
@@ -581,7 +581,6 @@ init_ui (gint *argc, gchar **argv[])
{
GtkWidget *main_window;
gint window_width, window_height;
- const gchar *ui_path = NULL;
GError *error = NULL;
GOptionContext *context;
double w, h;
@@ -596,25 +595,24 @@ init_ui (gint *argc, gchar **argv[])
return FALSE;
}
- /* Try to fetch the ui file from the CWD first */
- ui_path = UI_FILE;
- if (!g_file_test (ui_path, G_FILE_TEST_EXISTS)) {
- /* Then Try to fetch it from the system path */
- ui_path = UI_DIR "/" UI_FILE;
+ builder = gtk_builder_new();
- if (!g_file_test (ui_path, G_FILE_TEST_EXISTS))
- ui_path = NULL;
- }
-
- if (ui_path == NULL) {
- g_critical ("Unable to load the GUI file %s", UI_FILE);
- return FALSE;
+ /* Try to fetch the ui file from the CWD first */
+ if (gtk_builder_add_from_file (builder, UI_FILE, NULL) == 0) {
+ /* Apparently not. let's check next to the executable */
+ char *path = g_strconcat (g_path_get_dirname (*argv[0]), G_DIR_SEPARATOR_S, UI_FILE, NULL);
+ if (gtk_builder_add_from_file (builder, path, NULL) == 0) {
+ g_clear_pointer (&path, g_free);
+ /* Also not... Check the install path */
+ if (gtk_builder_add_from_file (builder, UI_DIR G_DIR_SEPARATOR_S UI_FILE, NULL) == 0) {
+ g_critical ("Unable to load the GUI file %s", UI_FILE);
+
+ return FALSE;
+ }
+ }
+ g_clear_pointer (&path, g_free);
}
- builder = gtk_builder_new();
- if (gtk_builder_add_from_file(builder, ui_path, NULL) == 0)
- return FALSE;
-
main_window = GTK_WIDGET(gtk_builder_get_object (builder, "main-window"));
g_assert (main_window != NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]