mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-16 18:25:11 -06:00
gnc_list_all_paths returns std::vector instead of GList of EnvPaths
because its consumers are now cpp there's no need to return a GList.
This commit is contained in:
parent
bba49a6d09
commit
89f7e8933b
@ -5160,7 +5160,6 @@ add_about_paths (GtkDialog *dialog)
|
||||
{
|
||||
GtkWidget *page_vbox = gnc_get_dialog_widget_from_id (dialog, "page_vbox");
|
||||
GtkWidget *grid;
|
||||
GList *paths;
|
||||
gint i = 0;
|
||||
|
||||
if (!page_vbox)
|
||||
@ -5170,15 +5169,12 @@ add_about_paths (GtkDialog *dialog)
|
||||
}
|
||||
|
||||
grid = gtk_grid_new ();
|
||||
paths = gnc_list_all_paths ();
|
||||
|
||||
for (GList *path_node = paths; path_node; path_node = g_list_next (path_node))
|
||||
for (const auto& ep : gnc_list_all_paths ())
|
||||
{
|
||||
EnvPaths *ep = (EnvPaths*)path_node->data;
|
||||
|
||||
gchar *env_name = g_strconcat (ep->env_name, ":", NULL);
|
||||
gchar *env_name = g_strconcat (ep.env_name, ":", NULL);
|
||||
GtkWidget *label = gtk_label_new (env_name);
|
||||
const gchar *uri = gnc_uri_create_uri ("file", NULL, 0, NULL, NULL, ep->env_path);
|
||||
const gchar *uri = gnc_uri_create_uri ("file", NULL, 0, NULL, NULL, ep.env_path);
|
||||
gchar *display_uri = gnc_doclink_get_unescaped_just_uri (uri);
|
||||
GtkWidget *widget = gtk_link_button_new_with_label (uri, display_uri);
|
||||
|
||||
@ -5189,7 +5185,7 @@ add_about_paths (GtkDialog *dialog)
|
||||
gtk_widget_set_margin_top (widget, 0);
|
||||
gtk_widget_set_margin_bottom (widget, 0);
|
||||
|
||||
if (ep->modifiable)
|
||||
if (ep.modifiable)
|
||||
{
|
||||
GtkWidget *mod_lab = gtk_label_new (_("(user modifiable)"));
|
||||
gtk_grid_attach (GTK_GRID(grid), mod_lab, 2, i, 1, 1);
|
||||
@ -5205,7 +5201,6 @@ add_about_paths (GtkDialog *dialog)
|
||||
gtk_container_add_with_properties (GTK_CONTAINER(page_vbox), grid,
|
||||
"position", 1, NULL);
|
||||
gtk_widget_show_all (grid);
|
||||
g_list_free_full (paths, g_free);
|
||||
}
|
||||
|
||||
/** Create and display the "about" dialog for gnucash.
|
||||
|
@ -242,17 +242,14 @@ Gnucash::CoreApp::parse_command_line (int argc, char **argv)
|
||||
|
||||
if (m_show_paths)
|
||||
{
|
||||
auto paths { gnc_list_all_paths ()};
|
||||
std::cout << _("GnuCash Paths") << '\n';
|
||||
for (auto n = paths; n; n = n->next)
|
||||
for (const auto& ep : gnc_list_all_paths ())
|
||||
{
|
||||
auto it = static_cast<EnvPaths*>(n->data);
|
||||
std::cout << it->env_name << ": " << it->env_path;
|
||||
if (it->modifiable)
|
||||
std::cout << ep.env_name << ": " << ep.env_path;
|
||||
if (ep.modifiable)
|
||||
std::cout << ' ' << _("(user modifiable)");
|
||||
std::cout << '\n';
|
||||
}
|
||||
g_list_free_full (paths, g_free);
|
||||
exit (0);
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,6 @@
|
||||
#include <boost/locale.hpp>
|
||||
#include <regex>
|
||||
#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:
|
||||
@ -1307,27 +1306,20 @@ gnc_filepath_locate_doc_file (const gchar *name)
|
||||
return result;
|
||||
}
|
||||
|
||||
GList *
|
||||
gnc_list_all_paths (void)
|
||||
std::vector<EnvPaths>
|
||||
gnc_list_all_paths ()
|
||||
{
|
||||
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 {
|
||||
{ "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 },
|
||||
};
|
||||
return std::accumulate (paths.rbegin(), paths.rend(), (GList*) nullptr, accum);
|
||||
}
|
||||
|
||||
static const std::regex
|
||||
|
@ -178,24 +178,6 @@ 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);
|
||||
|
||||
gboolean gnc_filename_is_backup (const char *filename);
|
||||
|
||||
gboolean gnc_filename_is_datafile (const char *filename);
|
||||
@ -217,6 +199,23 @@ gboolean gnc_filename_is_datafile (const char *filename);
|
||||
*/
|
||||
std::ofstream gnc_open_filestream(const char *path);
|
||||
|
||||
#include <vector>
|
||||
|
||||
struct EnvPaths
|
||||
{
|
||||
const gchar *env_name;
|
||||
const gchar *env_path;
|
||||
gboolean modifiable;
|
||||
};
|
||||
|
||||
|
||||
/** Returns a vector of the environment variables used by GnuCash.
|
||||
*
|
||||
* @return a vector of EnvPaths structs, describing the environment
|
||||
* variables used by GnuCash.
|
||||
*/
|
||||
std::vector<EnvPaths> gnc_list_all_paths ();
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* GNC_FILEPATH_UTILS_H */
|
||||
|
Loading…
Reference in New Issue
Block a user