diff options
author | Jens Georg <mail@jensge.org> | 2018-10-26 20:57:00 +0200 |
---|---|---|
committer | Jens Georg <mail@jensge.org> | 2018-10-26 20:58:26 +0200 |
commit | 90f42ba3267f6ed130bf9a818f02d04e9d01d45e (patch) | |
tree | cda9fe4fe4dd5f30db97bebd7b143fc69795bfed | |
parent | 6f30a0c030c06bdadc1e46b018073e55c85e2e6b (diff) | |
download | gssdp-90f42ba3267f6ed130bf9a818f02d04e9d01d45e.tar.gz |
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
-rw-r--r-- | tools/gssdp-device-sniffer.c | 32 |
1 files 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); |