Skip to content

Commit

Permalink
[gnc-filepath-utils] new: gnc_list_all_paths
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherlam committed Jul 10, 2022
1 parent aa43c19 commit 263f007
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
23 changes: 23 additions & 0 deletions libgnucash/core-utils/gnc-filepath-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ extern "C" {
#include <boost/filesystem.hpp>
#include <boost/locale.hpp>
#include <iostream>
#include <numeric>

/* Below cvt and bfs_locale should be used with boost::filesystem::path (bfs)
* objects created alter in this source file. The rationale is as follows:
Expand Down Expand Up @@ -1306,5 +1307,27 @@ gnc_filepath_locate_doc_file (const gchar *name)
return result;
}

GList *
gnc_list_all_paths (void)
{
if (gnc_userdata_home.empty())
gnc_filepath_init ();

std::vector<EnvPaths> paths
{ { "GNC_USERDATA_DIR", gnc_userdata_home_str.c_str(), true},
{ "GNC_USERCONFIG_DIR", gnc_userconfig_home_str.c_str(), true },
{ "GNC_BIN", g_getenv ("GNC_BIN"), false },
{ "GNC_LIB", g_getenv ("GNC_LIB"), false },
{ "GNC_CONF", g_getenv ("GNC_CONF"), false },
{ "GNC_DATA", g_getenv ("GNC_DATA"), false },
};
auto accum = [](const auto& a, const auto& b)
{
EnvPaths *ep = g_new0 (EnvPaths, 1);
*ep = b;
return g_list_prepend (a, ep);
};
return std::accumulate (paths.rbegin(), paths.rend(), (GList*) nullptr, accum);
}

/* =============================== END OF FILE ========================== */
18 changes: 18 additions & 0 deletions libgnucash/core-utils/gnc-filepath-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,22 @@ gchar *gnc_filepath_locate_ui_file (const gchar *name);
*/
gchar *gnc_filepath_locate_doc_file (const gchar *name);

typedef struct
{
const gchar *env_name;
const gchar *env_path;
gboolean modifiable;
} EnvPaths;


/** Returns a GList* of the environment variables used by GnuCash.
*
* @return a GList* of EnvPaths structs, describing the environment
* variables used by GnuCash.
*
* @note It is the caller's responsibility to free the GList with
* g_list_free_full (paths, g_free)
*/
GList *gnc_list_all_paths (void);

#endif /* GNC_FILEPATH_UTILS_H */

0 comments on commit 263f007

Please sign in to comment.