Change register sheet associations tooltip to use

dialog-assoc-utils functions
This commit is contained in:
Robert Fewell 2020-05-18 16:17:42 +01:00
parent f31749f490
commit 1b8cad0086
3 changed files with 29 additions and 39 deletions

View File

@ -118,6 +118,18 @@ gnc_assoc_get_use_uri (const gchar *path_head, const gchar *uri, gchar *uri_sche
return use_str;
}
gchar *
gnc_assoc_get_unescaped_just_uri (const gchar *uri)
{
gchar *path_head = gnc_assoc_get_path_head ();
gchar *uri_scheme = gnc_uri_get_scheme (uri);
gchar *ret_uri = gnc_assoc_get_unescape_uri (path_head, uri, uri_scheme);
g_free (path_head);
g_free (uri_scheme);
return ret_uri;
}
gchar *
gnc_assoc_convert_trans_associate_uri (gpointer trans, gboolean book_ro)
{

View File

@ -89,6 +89,20 @@ gchar * gnc_assoc_convert_trans_associate_uri (gpointer trans, gboolean book_ro)
*/
gchar * gnc_assoc_get_unescape_uri (const gchar *path_head, const gchar *uri, gchar *uri_scheme);
/** Return an unescaped uri for display use just based on the uri.
*
* The function allocates memory for the uri. The calling function should
* free this memory with g_free when the unescaped uri is no longer needed.
* Return an unesacped uri for displaying and if OS is windows change the
* '/' to '\' to look like a traditional windows path
*
* @param uri The association
*
* @return The unescaped uri used for display purposes.
*/
gchar * gnc_assoc_get_unescaped_just_uri (const gchar *uri);
/** Presents a dialog when the path head is changed.
*
* When the path head is changed a dialog is raised that allows for

View File

@ -27,6 +27,7 @@
#include "datecell.h"
#include "dialog-utils.h"
#include "dialog-assoc-utils.h"
#include "gnc-engine.h"
#include "gnc-prefs.h"
#include "gnc-ui.h"
@ -559,45 +560,8 @@ gnc_split_register_get_associate_tooltip (VirtualLocation virt_loc,
uri = xaccTransGetAssociation (trans);
// Check for uri is empty or NULL
if (uri && *uri != '\0')
{
gchar* scheme = gnc_uri_get_scheme (uri);
gchar* file_path = NULL;
if (!scheme) // relative path
{
gchar* path_head = gnc_prefs_get_string (GNC_PREFS_GROUP_GENERAL,
"assoc-head");
if (path_head && *path_head != '\0') // not default entry
file_path = gnc_file_path_absolute (gnc_uri_get_path (path_head), uri);
else
file_path = gnc_file_path_absolute (NULL, uri);
g_free (path_head);
}
if (gnc_uri_is_file_scheme (scheme)) // absolute path
file_path = gnc_uri_get_path (uri);
#ifdef G_OS_WIN32 // make path look like a traditional windows path
if (file_path)
file_path = g_strdelimit (file_path, "/", '\\');
#endif
g_free (scheme);
if (!file_path)
return g_uri_unescape_string (uri, NULL);
else
{
gchar* file_uri_u = g_uri_unescape_string (file_path, NULL);
const gchar* filename = gnc_uri_get_path (file_uri_u);
g_free (file_uri_u);
g_free (file_path);
return g_strdup (filename);
}
}
if (uri && *uri)
return gnc_assoc_get_unescaped_just_uri (uri);
else
return NULL;
}