From 263f007d5c5246f72ea16805becc188bf1299735 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sun, 5 Jun 2022 12:00:58 +0800 Subject: [PATCH 1/4] [gnc-filepath-utils] new: gnc_list_all_paths --- libgnucash/core-utils/gnc-filepath-utils.cpp | 23 ++++++++++++++++++++ libgnucash/core-utils/gnc-filepath-utils.h | 18 +++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/libgnucash/core-utils/gnc-filepath-utils.cpp b/libgnucash/core-utils/gnc-filepath-utils.cpp index 34f482d4ca..e16d908835 100644 --- a/libgnucash/core-utils/gnc-filepath-utils.cpp +++ b/libgnucash/core-utils/gnc-filepath-utils.cpp @@ -69,6 +69,7 @@ extern "C" { #include #include #include +#include /* 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: @@ -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 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 ========================== */ diff --git a/libgnucash/core-utils/gnc-filepath-utils.h b/libgnucash/core-utils/gnc-filepath-utils.h index f88cd32050..57e1ddf777 100644 --- a/libgnucash/core-utils/gnc-filepath-utils.h +++ b/libgnucash/core-utils/gnc-filepath-utils.h @@ -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 */ From 46ac60bda1986b1639a0edbe59af435d1d271058 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sat, 18 Jun 2022 16:36:13 +0800 Subject: [PATCH 2/4] [gnc-gtk-utils] new: gnc_get_dialog_widget_from_id --- gnucash/gnome-utils/gnc-gtk-utils.c | 35 +++++++++++++++++++++++++++++ gnucash/gnome-utils/gnc-gtk-utils.h | 2 ++ 2 files changed, 37 insertions(+) diff --git a/gnucash/gnome-utils/gnc-gtk-utils.c b/gnucash/gnome-utils/gnc-gtk-utils.c index 2dca606f59..9b69141866 100644 --- a/gnucash/gnome-utils/gnc-gtk-utils.c +++ b/gnucash/gnome-utils/gnc-gtk-utils.c @@ -297,3 +297,38 @@ gnc_style_context_get_border_color (GtkStyleContext *context, *color = *c; gdk_rgba_free (c); } + +static gpointer +find_widget_func (GtkWidget *widget, const gchar *id) +{ + const gchar *name = gtk_buildable_get_name (GTK_BUILDABLE(widget)); + GtkWidget *ret = NULL; + + if (g_strcmp0 (name, id) == 0) + return widget; + + if (GTK_IS_CONTAINER(widget)) + { + GList *container_list = gtk_container_get_children (GTK_CONTAINER(widget)); + for (GList *n = container_list; !ret && n; n = n->next) + ret = find_widget_func (n->data, id); + g_list_free (container_list); + } + + return ret; +} + +/** Find the Widget defined by 'id' in the dialog + * + * @param dialog The dialog to search for 'id'. + * + * @param id The widget name to find in the dialog. + * + * @returns The widget defined by id in the dialog or NULL. + */ +GtkWidget * +gnc_get_dialog_widget_from_id (GtkDialog *dialog, const gchar *id) +{ + GtkWidget *content_area = gtk_dialog_get_content_area (dialog); + return find_widget_func (content_area, id); +} diff --git a/gnucash/gnome-utils/gnc-gtk-utils.h b/gnucash/gnome-utils/gnc-gtk-utils.h index 6651f76f0c..b227eec0c8 100644 --- a/gnucash/gnome-utils/gnc-gtk-utils.h +++ b/gnucash/gnome-utils/gnc-gtk-utils.h @@ -53,6 +53,8 @@ void gnc_style_context_get_border_color (GtkStyleContext *context, GtkStateFlags state, GdkRGBA *color); +GtkWidget *gnc_get_dialog_widget_from_id (GtkDialog *dialog, const gchar *id); + /** @} */ #endif /* GNC_GTK_UTILS_H */ From 1a263040ab17e17e8b7343ee6ef75fae57ece9f6 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sun, 5 Jun 2022 12:01:05 +0800 Subject: [PATCH 3/4] [gnc-main-window] About window shows gnc_list_all_paths() --- gnucash/gnome-utils/gnc-main-window.c | 67 +++++++++++++++++++++++++++ gnucash/gnucash.css | 5 ++ 2 files changed, 72 insertions(+) diff --git a/gnucash/gnome-utils/gnc-main-window.c b/gnucash/gnome-utils/gnc-main-window.c index 249de04909..89fe6fc8dc 100644 --- a/gnucash/gnome-utils/gnc-main-window.c +++ b/gnucash/gnome-utils/gnc-main-window.c @@ -51,6 +51,7 @@ #include "engine-helpers.h" #include "file-utils.h" #include "gnc-component-manager.h" +#include "dialog-doclink-utils.h" #include "gnc-engine.h" #include "gnc-features.h" #include "gnc-file.h" @@ -59,6 +60,7 @@ #include "gnc-gnome-utils.h" #include "gnc-gobject-utils.h" #include "gnc-gui-query.h" +#include "gnc-gtk-utils.h" #include "gnc-hooks.h" #include "gnc-icons.h" #include "gnc-session.h" @@ -4702,6 +4704,67 @@ url_signal_cb (GtkAboutDialog *dialog, gchar *uri, gpointer data) return TRUE; } +static gboolean +link_button_cb (GtkLinkButton *button, gpointer user_data) +{ + const gchar *uri = gtk_link_button_get_uri (button); + gnc_launch_doclink (GTK_WINDOW(user_data), uri); + return TRUE; +} + +static void +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) + { + PWARN("Unable to find AboutDialog 'page_vbox' Widget"); + return; + } + + grid = gtk_grid_new (); + paths = gnc_list_all_paths (); + + for (GList *path_node = paths; path_node; path_node = g_list_next (path_node)) + { + EnvPaths *ep = (EnvPaths*)path_node->data; + + 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); + gchar *display_uri = gnc_doclink_get_unescaped_just_uri (uri); + GtkWidget *widget = gtk_link_button_new_with_label (uri, display_uri); + + gtk_grid_attach (GTK_GRID(grid), label, 0, i, 1, 1); + gtk_widget_set_halign (label, GTK_ALIGN_END); + gtk_grid_attach (GTK_GRID(grid), widget, 1, i, 1, 1); + gtk_widget_set_halign (widget, GTK_ALIGN_START); + gtk_widget_set_margin_top (widget, 0); + gtk_widget_set_margin_bottom (widget, 0); + + if (ep->modifiable) + { + GtkWidget *mod_lab = gtk_label_new (_("(user modifiable)")); + gtk_grid_attach (GTK_GRID(grid), mod_lab, 2, i, 1, 1); + gtk_widget_show (mod_lab); + } + g_signal_connect (widget, "activate-link", + G_CALLBACK(link_button_cb), dialog); + i++; + + g_free (display_uri); + g_free (env_name); + } + 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. * * @param action The GtkAction for the "about" menu item. @@ -4759,6 +4822,10 @@ gnc_main_window_cmd_help_about (GtkAction *action, GncMainWindow *window) g_object_unref (logo); g_signal_connect (dialog, "activate-link", G_CALLBACK (url_signal_cb), NULL); + + // Add enviroment paths + add_about_paths (dialog); + /* Set dialog to resize. */ gtk_window_set_resizable(GTK_WINDOW (dialog), TRUE); diff --git a/gnucash/gnucash.css b/gnucash/gnucash.css index 92e8dca840..af46af8415 100644 --- a/gnucash/gnucash.css +++ b/gnucash/gnucash.css @@ -89,3 +89,8 @@ dialog#GnuCash > box > box > label { font-size: 24px; } +dialog#GnuCash grid * { + padding-top: 0px; + padding-bottom: 0px; + min-height: 4px; +} From f5f303714c5f8303828d913da708824ec721f7dd Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Mon, 6 Jun 2022 15:42:36 +0800 Subject: [PATCH 4/4] [gnucash-core-app] "--paths" returns gnc_list_all_paths() --- gnucash/gnucash-core-app.cpp | 18 ++++++++++++++++++ gnucash/gnucash-core-app.hpp | 1 + 2 files changed, 19 insertions(+) diff --git a/gnucash/gnucash-core-app.cpp b/gnucash/gnucash-core-app.cpp index 3bbcc5f751..54c6d32e28 100644 --- a/gnucash/gnucash-core-app.cpp +++ b/gnucash/gnucash-core-app.cpp @@ -249,6 +249,22 @@ Gnucash::CoreApp::parse_command_line (int argc, char **argv) exit(1); } + if (m_show_paths) + { + auto paths { gnc_list_all_paths ()}; + std::cout << _("GnuCash Paths") << '\n'; + for (auto n = paths; n; n = n->next) + { + auto it = static_cast(n->data); + std::cout << it->env_name << ": " << it->env_path; + if (it->modifiable) + std::cout << ' ' << _("(user modifiable)"); + std::cout << '\n'; + } + g_list_free_full (paths, g_free); + exit (0); + } + if (m_show_version) { bl::format rel_fmt (bl::translate ("GnuCash {1}")); @@ -289,6 +305,8 @@ Gnucash::CoreApp::add_common_program_options (void) _("Enable extra/development/debugging features.")) ("log", bpo::value (&m_log_flags), _("Log level overrides, of the form \"modulename={debug,info,warn,crit,error}\"\nExamples: \"--log qof=debug\" or \"--log gnc.backend.file.sx=info\"\nThis can be invoked multiple times.")) + ("paths", bpo::bool_switch(&m_show_paths), + _("Show paths")) ("logto", bpo::value (&m_log_to_filename), _("File to log into; defaults to \"/tmp/gnucash.trace\"; can be \"stderr\" or \"stdout\".")); diff --git a/gnucash/gnucash-core-app.hpp b/gnucash/gnucash-core-app.hpp index 9ff91af336..b7b1bf40dc 100644 --- a/gnucash/gnucash-core-app.hpp +++ b/gnucash/gnucash-core-app.hpp @@ -62,6 +62,7 @@ private: /* Command-line option variables */ bool m_show_help = false; bool m_show_version = false; + bool m_show_paths = false; bool m_debug = false; bool m_extra = false; boost::optional m_gsettings_prefix;