mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Merge branch 'maint-log-paths' into maint #1345
This commit is contained in:
commit
a9ec51bd6d
@ -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);
|
||||
}
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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<EnvPaths*>(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\"."));
|
||||
|
||||
|
@ -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 <std::string> m_gsettings_prefix;
|
||||
|
@ -89,3 +89,8 @@ dialog#GnuCash > box > box > label
|
||||
{
|
||||
font-size: 24px;
|
||||
}
|
||||
dialog#GnuCash grid * {
|
||||
padding-top: 0px;
|
||||
padding-bottom: 0px;
|
||||
min-height: 4px;
|
||||
}
|
||||
|
@ -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:
|
||||
@ -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 ========================== */
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user