@@ -902,7 +902,9 @@ static void
902
902
gsr_default_associate_handler_file (GNCSplitReg * gsr , Transaction * trans , gboolean have_uri )
903
903
{
904
904
GtkWidget * dialog ;
905
- gint response ;
905
+ gint response ;
906
+ gboolean valid_path_head = FALSE;
907
+ gchar * path_head = gnc_prefs_get_string (GNC_PREFS_GROUP_GENERAL , "assoc-head" );
906
908
907
909
dialog = gtk_file_chooser_dialog_new (_ ("Associate File with Transaction" ),
908
910
GTK_WINDOW (gsr -> window ),
@@ -914,20 +916,34 @@ gsr_default_associate_handler_file (GNCSplitReg *gsr, Transaction *trans, gboole
914
916
915
917
gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog ), FALSE);
916
918
919
+ if ((path_head != NULL ) && (g_strcmp0 (path_head , "" ) != 0 )) // not default entry
920
+ valid_path_head = TRUE;
921
+
917
922
if (have_uri )
918
923
{
919
- GtkWidget * extra_widget ;
920
- gchar * uri_label = g_strconcat (_ ("Existing Association is " ), xaccTransGetAssociation (trans ), NULL );
924
+ gchar * new_uri ;
925
+ gchar * uri_label ;
926
+ gchar * filename ;
921
927
922
- extra_widget = gtk_label_new ( uri_label );
928
+ const gchar * uri = xaccTransGetAssociation ( trans );
923
929
924
- gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog ), extra_widget );
930
+ if (valid_path_head && g_str_has_prefix (uri ,"file:/" ) && !g_str_has_prefix (uri ,"file://" ))
931
+ {
932
+ const gchar * part = uri + strlen ("file:" );
933
+ new_uri = g_strconcat (path_head , part , NULL );
934
+ }
935
+ else
936
+ new_uri = g_strdup (uri );
925
937
926
- gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (dialog ), xaccTransGetAssociation (trans ));
938
+ filename = g_uri_unescape_string (new_uri , NULL );
939
+ uri_label = g_strconcat (_ ("Existing Association is " ), filename , NULL );
940
+ gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog ), gtk_label_new (uri_label ));
941
+ gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (dialog ), new_uri );
927
942
928
943
g_free (uri_label );
944
+ g_free (new_uri );
945
+ g_free (filename );
929
946
}
930
-
931
947
response = gtk_dialog_run (GTK_DIALOG (dialog ));
932
948
933
949
if (response == GTK_RESPONSE_REJECT )
@@ -936,10 +952,22 @@ gsr_default_associate_handler_file (GNCSplitReg *gsr, Transaction *trans, gboole
936
952
if (response == GTK_RESPONSE_ACCEPT )
937
953
{
938
954
gchar * dialog_uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dialog ));
939
- DEBUG ("File URI: %s\n" , dialog_uri );
940
- xaccTransSetAssociation (trans , dialog_uri );
955
+
956
+ PINFO ("Dialog File URI: %s\n" , dialog_uri );
957
+
958
+ if (valid_path_head && g_str_has_prefix (dialog_uri , path_head ))
959
+ {
960
+ gchar * part = dialog_uri + strlen (path_head );
961
+ gchar * new_uri = g_strconcat ("file:" , part , NULL );
962
+ xaccTransSetAssociation (trans , new_uri );
963
+ g_free (new_uri );
964
+ }
965
+ else
966
+ xaccTransSetAssociation (trans , dialog_uri );
967
+
941
968
g_free (dialog_uri );
942
969
}
970
+ g_free (path_head );
943
971
gtk_widget_destroy (dialog );
944
972
}
945
973
@@ -984,9 +1012,9 @@ gsr_default_associate_handler_location (GNCSplitReg *gsr, Transaction *trans, gb
984
1012
// set the default response
985
1013
gtk_dialog_set_default_response (GTK_DIALOG (dialog ), GTK_RESPONSE_ACCEPT );
986
1014
987
- // run the dialog
988
1015
gtk_widget_show_all (dialog );
989
1016
1017
+ // run the dialog
990
1018
response = gtk_dialog_run (GTK_DIALOG (dialog ));
991
1019
992
1020
if (response == GTK_RESPONSE_REJECT )
@@ -1062,6 +1090,8 @@ gsr_default_execassociated_handler (GNCSplitReg *gsr, gpointer data)
1062
1090
Split * split = gnc_split_register_get_current_split (reg );
1063
1091
GtkWidget * dialog ;
1064
1092
const char * uri ;
1093
+ const char * run_uri ;
1094
+ gchar * uri_scheme ;
1065
1095
1066
1096
/* get the current split based on cursor position */
1067
1097
if (split == NULL )
@@ -1082,11 +1112,36 @@ gsr_default_execassociated_handler (GNCSplitReg *gsr, gpointer data)
1082
1112
#endif
1083
1113
1084
1114
uri = xaccTransGetAssociation (trans );
1115
+
1085
1116
if (g_strcmp0 (uri , "" ) == 0 && g_strcmp0 (uri , NULL ) == 0 )
1086
1117
gnc_error_dialog (NULL , "%s" , _ ("This transaction is not associated with a URI." ));
1087
1118
else
1088
- gnc_launch_assoc (uri );
1119
+ {
1120
+ if (g_str_has_prefix (uri ,"file:/" ) && !g_str_has_prefix (uri ,"file://" )) // Check for relative path
1121
+ {
1122
+ gchar * path_head = gnc_prefs_get_string (GNC_PREFS_GROUP_GENERAL , "assoc-head" );
1123
+
1124
+ if ((path_head != NULL ) && (g_strcmp0 (path_head , "" ) != 0 )) // not default entry
1125
+ {
1126
+ const gchar * part = uri + strlen ("file:" );
1127
+ run_uri = g_strconcat (path_head , part , NULL );
1128
+ }
1129
+ else
1130
+ run_uri = g_strdup (uri );
1131
+ }
1132
+ else
1133
+ run_uri = g_strdup (uri );
1089
1134
1135
+ uri_scheme = g_uri_parse_scheme (run_uri );
1136
+
1137
+ if (uri_scheme != NULL ) // make sure we have a scheme entry
1138
+ {
1139
+ gnc_launch_assoc (run_uri );
1140
+ g_free (uri_scheme );
1141
+ }
1142
+ else
1143
+ gnc_error_dialog (NULL , "%s" , _ ("This transaction is not associated with a valid URI." ));
1144
+ }
1090
1145
return ;
1091
1146
}
1092
1147
0 commit comments