Skip to content

Commit

Permalink
Merge pull request #181 from nicklan/fix/178
Browse files Browse the repository at this point in the history
Fix/178
  • Loading branch information
elboulangero authored Jun 12, 2018
2 parents 0d05c66 + d443b46 commit 903298b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 30 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ option(WITH_GTK3 "Use Gtk3 as toolkit" ON)
option(WITH_LIBNOTIFY "Enable sending of notifications" ON)
option(ENABLE_NLS "Enable building of translations" ON)
option(BUILD_DOCUMENTATION "Use Doxygen to create the HTML based API documentation" OFF)
# https://github.com/nicklan/pnmixer/issues/178
if (CMAKE_BUILD_TYPE STREQUAL Release)
set(DATA_IN_CWD_default OFF)
else()
set(DATA_IN_CWD_default ON)
endif()
option(DATA_IN_CWD "Whether to also look for data files in the current directory" ${DATA_IN_CWD_default})



## packages required across multiple subdirectories
Expand Down
3 changes: 3 additions & 0 deletions src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
/* libnotify mode */
#cmakedefine WITH_LIBNOTIFY

/* whether to also look for data in the current working directory */
#cmakedefine DATA_IN_CWD

#define PACKAGE_DATA_DIR "@CMAKE_INSTALL_FULL_DATADIR@"

#define PACKAGE_LOCALE_DIR "@CMAKE_INSTALL_FULL_LOCALEDIR@"
Expand Down
74 changes: 44 additions & 30 deletions src/support-ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,37 @@
#include "support-log.h"
#include "support-intl.h"

/**
* Gets the path to a data file.
* May first look in ./data/[path], and then in
* PACKAGE_DATA_DIR/PACKAGE/[path].
*
* @param path of the file
* @return path to the file or NULL on failure. Must be freed.
*/
static gchar *
get_data_file(const char *pathname)
{
gchar *path;

#ifdef DATA_IN_CWD
path = g_build_filename(".", "data", pathname, NULL);
if (g_file_test(path, G_FILE_TEST_EXISTS))
return path;
g_free(path);
#endif

path = g_build_filename(PACKAGE_DATA_DIR, PACKAGE, pathname, NULL);
if (g_file_test(path, G_FILE_TEST_EXISTS))
return path;
g_free(path);

WARN("Could not find data file '%s'", pathname);

return NULL;
}


#ifndef WITH_GTK3
GtkBuilder *
gtk_builder_new_from_file (const gchar *filename)
Expand All @@ -46,56 +77,39 @@ gtk_combo_box_text_remove_all(GtkComboBoxText *combo_box)
}
#endif


/**
* Gets the path to an ui file.
* Looks first in ./data/ui/[file], and then in
* May first look in ./data/ui/[file], and then in
* PACKAGE_DATA_DIR/PACKAGE/ui/[file].
*
* @param filename the name of the ui file
* @return path to the ui file or NULL on failure. Must be freed.
*/
gchar *
get_ui_file(const char *filename)
get_ui_file(const char *uifilename)
{
gchar *path;

path = g_build_filename(".", "data", "ui", filename, NULL);
if (g_file_test(path, G_FILE_TEST_EXISTS))
return path;
g_free(path);
gchar *filename = g_build_filename("ui", uifilename, NULL);
gchar *filepath = get_data_file(filename);

path = g_build_filename(PACKAGE_DATA_DIR, PACKAGE, "ui", filename, NULL);
if (g_file_test(path, G_FILE_TEST_EXISTS))
return path;
g_free(path);

WARN("Could not find ui file '%s'", filename);
return NULL;
g_free(filename);
return filepath;
}

/**
* Gets the path to a pixmap file.
* Looks first in ./data/ui/[file], and then in
* May first look in ./data/pixmaps/[file], and then in
* PACKAGE_DATA_DIR/PACKAGE/ui/[file].
*
* @param filename the pixmap file to find
* @return path to the ui file or NULL on failure. Must be freed.
*/
gchar *
get_pixmap_file(const gchar *filename)
get_pixmap_file(const gchar *pixfilename)
{
gchar *path;

path = g_build_filename(".", "data", "pixmaps", filename, NULL);
if (g_file_test(path, G_FILE_TEST_EXISTS))
return path;
g_free(path);
gchar *filename = g_build_filename("pixmaps", pixfilename, NULL);
gchar *filepath = get_data_file(filename);

path = g_build_filename(PACKAGE_DATA_DIR, PACKAGE, "pixmaps", filename, NULL);
if (g_file_test(path, G_FILE_TEST_EXISTS))
return path;
g_free(path);

WARN("Could not find pixmap file '%s'", filename);
return NULL;
g_free(filename);
return filepath;
}

0 comments on commit 903298b

Please sign in to comment.