Add Preference path head for Trans. Associations

Add a preference for setting the path head for Transaction Associations
based on a GtkFileChooserButton. An additional button is used to clear
this setting when required.
This commit is contained in:
Robert Fewell 2016-08-16 16:33:56 +01:00 committed by John Ralls
parent 531f0f3c37
commit 47953c9b73
3 changed files with 416 additions and 154 deletions

View File

@ -693,6 +693,143 @@ gnc_prefs_connect_font_button (GtkFontButton *fb)
/****************************************************************************/
/** Callback for a GtkFileChooser widget to store a value in the preferences database.
*
* @internal
*
* @param fc A pointer to the file chooser widget emitting signal.
*/
static void
file_chooser_selected_cb (GtkFileChooser *fc, gpointer user_data)
{
GtkImage *image = g_object_get_data (G_OBJECT(fc), "path_head_error");
const gchar *group = g_object_get_data (G_OBJECT(fc), "group");
const gchar *pref = g_object_get_data (G_OBJECT(fc), "pref");
gchar *folder = gtk_file_chooser_get_uri (fc);
gtk_widget_hide (GTK_WIDGET(image));
if (!gnc_prefs_set_string (group, pref, folder))
PINFO("Failed to save preference at %s, %s with %s", group, pref, folder);
g_free (folder);
}
/** Connect a GtkFileChooserButton widget to its stored value in the preferences database.
*
* @internal
*
* @param fb A pointer to the file chooser button that should be connected.
*
* @param boxname The Hbox name that contains the GtkFileChooserButton and Clear button
*/
static void
gnc_prefs_connect_file_chooser_button (GtkFileChooserButton *fcb, const gchar *boxname)
{
GtkImage *image;
gchar *group, *pref;
gchar *uri;
gboolean folder_set = TRUE;
g_return_if_fail(GTK_FILE_CHOOSER_BUTTON(fcb));
if (boxname == NULL)
gnc_prefs_split_widget_name (gtk_buildable_get_name(GTK_BUILDABLE(fcb)), &group, &pref);
else
gnc_prefs_split_widget_name (boxname, &group, &pref);
uri = gnc_prefs_get_string (group, pref);
PINFO("Uri is %s", uri);
if ((uri != NULL) && (g_strcmp0 (uri, "") != 0)) // default entry
{
gchar *path_head = g_filename_from_uri (uri, NULL, NULL);
// test for current folder present and set chooser to it
if (g_file_test (path_head, G_FILE_TEST_IS_DIR))
gtk_file_chooser_set_current_folder_uri (GTK_FILE_CHOOSER(fcb), uri);
else
folder_set = FALSE;
g_free (path_head);
}
image = g_object_get_data(G_OBJECT(fcb), "path_head_error");
if (folder_set) // If current folder missing, display error and tt message
gtk_widget_hide (GTK_WIDGET(image));
else
{
gchar *uri_u = g_uri_unescape_string (uri, NULL);
gchar *path_head = g_filename_from_uri (uri_u, NULL, NULL);
gchar *ttip = g_strconcat (_("Path does not exist, "), path_head, NULL);
gtk_widget_set_tooltip_text(GTK_WIDGET(image), ttip);
gtk_widget_show (GTK_WIDGET(image));
g_free (ttip);
g_free (uri_u);
g_free (path_head);
}
g_signal_connect (GTK_FILE_CHOOSER(fcb), "selection-changed",
G_CALLBACK(file_chooser_selected_cb), NULL);
g_object_set_data_full (G_OBJECT(fcb),"group", g_strdup (group), (GDestroyNotify) g_free);
g_object_set_data_full (G_OBJECT(fcb),"pref", g_strdup (pref), (GDestroyNotify) g_free);
g_free (group);
g_free (pref);
g_free (uri);
gtk_widget_show_all(GTK_WIDGET(fcb));
}
/** Callback for a 'Clear' button for GtkFileChooserButton widget.
*
* @internal
*
* @param button A pointer to the button widget emitting signal.
*
* @param user_data A Pointer to the GtkFileChooserButton widget.
*/
static void
file_chooser_clear_cb (GtkButton *button, gpointer user_data)
{
GtkFileChooserButton *fcb = GTK_FILE_CHOOSER_BUTTON(user_data);
const gchar *group = g_object_get_data (G_OBJECT(fcb), "group");
const gchar *pref = g_object_get_data (G_OBJECT(fcb), "pref");
GtkImage *image = g_object_get_data (G_OBJECT(fcb), "path_head_error");
GtkWidget *box;
GtkWidget *fcb_new;
gchar *boxname;
/* We need to distroy the GtkFileChooserButton and recreate as there
does not seem to be away of resetting the folder path to NONE */
box = gtk_widget_get_parent (GTK_WIDGET(fcb));
gtk_widget_destroy (GTK_WIDGET(fcb));
if (!gnc_prefs_set_string (group, pref, ""))
PINFO("Failed to Clear preference at %s, %s", group, pref);
fcb_new = gtk_file_chooser_button_new (_("Select a folder"),
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
g_object_set_data (G_OBJECT(fcb_new), "path_head_error", image);
gtk_box_pack_start (GTK_BOX (box), fcb_new, TRUE, TRUE, 0);
gtk_box_reorder_child (GTK_BOX (box),fcb_new, 0);
gtk_widget_show (fcb_new);
boxname = g_strconcat ("pref/", group, "/", pref, NULL);
gnc_prefs_connect_file_chooser_button (GTK_FILE_CHOOSER_BUTTON(fcb_new), boxname);
g_free (boxname);
}
/****************************************************************************/
/** Connect a GtkRadioButton widget to its stored value in the preferences database.
*
* @internal
@ -716,8 +853,8 @@ gnc_prefs_connect_radio_button (GtkRadioButton *button)
gnc_prefs_bind (group, pref, G_OBJECT (button), "active");
g_free(group);
g_free(pref);
g_free (group);
g_free (pref);
}
/****************************************************************************/
@ -974,9 +1111,14 @@ gnc_prefs_connect_one (const gchar *name,
if (GTK_IS_FONT_BUTTON(widget))
{
DEBUG(" %s - entry", name);
DEBUG(" %s - font button", name);
gnc_prefs_connect_font_button(GTK_FONT_BUTTON(widget));
}
else if (GTK_IS_FILE_CHOOSER_BUTTON(widget))
{
DEBUG(" %s - file chooser button", name);
gnc_prefs_connect_file_chooser_button(GTK_FILE_CHOOSER_BUTTON(widget), NULL);
}
else if (GTK_IS_RADIO_BUTTON(widget))
{
DEBUG(" %s - radio button", name);
@ -1027,6 +1169,11 @@ gnc_prefs_connect_one (const gchar *name,
DEBUG(" %s - date_edit", name);
gnc_prefs_connect_date_edit(GNC_DATE_EDIT(widget_child), name );
}
else if (GTK_FILE_CHOOSER_BUTTON(widget_child))
{
DEBUG(" %s - file chooser buuton", name);
gnc_prefs_connect_file_chooser_button(GTK_FILE_CHOOSER_BUTTON(widget_child), name );
}
}
else
{
@ -1052,7 +1199,7 @@ gnc_preferences_dialog_create(void)
{
GtkBuilder *builder;
GtkWidget *dialog, *notebook, *label, *image;
GtkWidget *box, *date, *period, *currency;
GtkWidget *box, *date, *period, *currency, *fcb, *button;
GHashTable *prefs_table;
GDate* gdate = NULL;
gchar buf[128];
@ -1165,6 +1312,19 @@ gnc_preferences_dialog_create(void)
gtk_widget_show (currency);
gtk_box_pack_start(GTK_BOX (box), currency, TRUE, TRUE, 0);
box = GTK_WIDGET(gtk_builder_get_object (builder,
"pref/" GNC_PREFS_GROUP_GENERAL "/assoc-head"));
fcb = gtk_file_chooser_button_new (_("Select a folder"),
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
gtk_box_pack_start (GTK_BOX (box), fcb, TRUE, TRUE, 0);
button = gtk_button_new_with_label (_("Clear"));
gtk_box_pack_start (GTK_BOX (box), button, TRUE, TRUE, 0);
gtk_widget_show (button);
g_signal_connect (GTK_BUTTON(button), "clicked",
G_CALLBACK(file_chooser_clear_cb), fcb);
image = GTK_WIDGET(gtk_builder_get_object (builder, "path_head_error"));
g_object_set_data(G_OBJECT(fcb), "path_head_error", image);
/* Add to the list of interesting widgets */
gnc_prefs_build_widget_table(builder, dialog);

View File

@ -2,6 +2,94 @@
<interface>
<requires lib="gtk+" version="2.24"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkAdjustment" id="auto_decimal_places_adj">
<property name="lower">1</property>
<property name="upper">8</property>
<property name="value">2</property>
<property name="step_increment">1</property>
<property name="page_increment">4</property>
</object>
<object class="GtkAdjustment" id="autosave_interval_minutes_adj">
<property name="upper">99999</property>
<property name="value">3</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="date_backmonth_adj">
<property name="upper">11</property>
<property name="value">6</property>
<property name="step_increment">1</property>
<property name="page_increment">4</property>
</object>
<object class="GtkListStore" id="date_formats">
<columns>
<!-- column-name name -->
<column type="gchararray"/>
<!-- column-name example -->
<column type="gchararray"/>
</columns>
<data>
<row>
<col id="0" translatable="yes">US</col>
<col id="1" translatable="yes">07/31/2013</col>
</row>
<row>
<col id="0" translatable="yes">UK</col>
<col id="1" translatable="yes">31/07/2013</col>
</row>
<row>
<col id="0" translatable="yes">Europe</col>
<col id="1" translatable="yes">31.07.2013</col>
</row>
<row>
<col id="0" translatable="yes">ISO</col>
<col id="1" translatable="yes">2013-07-31</col>
</row>
<row>
<col id="0" translatable="yes">Locale</col>
<col id="1" translatable="yes">(dummy)</col>
</row>
</data>
</object>
<object class="GtkAdjustment" id="key_length_adj">
<property name="lower">1</property>
<property name="upper">999</property>
<property name="value">2</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="max_transactions_adj">
<property name="upper">999999</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="new_search_limit_adj">
<property name="lower">1</property>
<property name="upper">100</property>
<property name="value">1</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="retain_days_adj">
<property name="lower">1</property>
<property name="upper">99999</property>
<property name="value">30</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="save_on_close_adj">
<property name="upper">300</property>
<property name="value">20</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="tab_width_adj">
<property name="lower">1</property>
<property name="upper">100</property>
<property name="value">30</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkDialog" id="GnuCash Preferences">
<property name="can_focus">False</property>
<property name="title" translatable="yes">GnuCash Preferences</property>
@ -1255,7 +1343,7 @@ many months before the current month:</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="n_rows">25</property>
<property name="n_rows">27</property>
<property name="n_columns">4</property>
<child>
<placeholder/>
@ -1311,6 +1399,72 @@ many months before the current month:</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkLabel" id="label50">
<property name="visible">True</property>
@ -1625,8 +1779,8 @@ many months before the current month:</property>
<property name="use_markup">True</property>
</object>
<packing>
<property name="top_attach">23</property>
<property name="bottom_attach">24</property>
<property name="top_attach">25</property>
<property name="bottom_attach">26</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"/>
</packing>
@ -1641,8 +1795,8 @@ many months before the current month:</property>
<property name="mnemonic_widget">pref/dialogs.search/new-search-limit</property>
</object>
<packing>
<property name="top_attach">24</property>
<property name="bottom_attach">25</property>
<property name="top_attach">26</property>
<property name="bottom_attach">27</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"/>
<property name="x_padding">12</property>
@ -1667,8 +1821,8 @@ many months before the current month:</property>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">24</property>
<property name="bottom_attach">25</property>
<property name="top_attach">26</property>
<property name="bottom_attach">27</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"/>
</packing>
@ -1858,48 +2012,6 @@ many months before the current month:</property>
<property name="x_padding">12</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkCheckButton" id="pref/general/save-on-close-expires">
<property name="label" translatable="yes">Enable timeout on "Save changes on closing" question</property>
@ -1919,6 +2031,12 @@ many months before the current month:</property>
<property name="x_padding">12</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkLabel" id="label15">
<property name="visible">True</property>
@ -1985,25 +2103,77 @@ many months before the current month:</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkLabel" id="label19">
<object class="GtkLabel" id="label20">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="top_attach">22</property>
<property name="bottom_attach">23</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"/>
</packing>
</child>
<child>
<object class="GtkLabel" id="label21">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="top_attach">24</property>
<property name="bottom_attach">25</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="pref/general/assoc-head">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_markup">Path head for Transaction Associated files </property>
<property name="tooltip_text" translatable="yes">Path head for Transaction Associated files </property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">23</property>
<property name="bottom_attach">24</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkHBox" id="hbox5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="label19">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Path head for Transaction Association Files</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkImage" id="path_head_error">
<property name="can_focus">False</property>
<property name="stock">gtk-dialog-warning</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="top_attach">23</property>
<property name="bottom_attach">24</property>
</packing>
</child>
</object>
@ -2434,6 +2604,15 @@ many months before the current month:</property>
<property name="y_options"/>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkLabel" id="label47">
<property name="visible">True</property>
@ -2450,6 +2629,12 @@ many months before the current month:</property>
<property name="y_options"/>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkCheckButton" id="pref/general.register/future-after-blank-transaction">
<property name="label" translatable="yes">_Future transactions after blank transaction</property>
@ -3643,92 +3828,4 @@ many months before the current month:</property>
<action-widget response="-7">closebutton2</action-widget>
</action-widgets>
</object>
<object class="GtkAdjustment" id="auto_decimal_places_adj">
<property name="lower">1</property>
<property name="upper">8</property>
<property name="value">2</property>
<property name="step_increment">1</property>
<property name="page_increment">4</property>
</object>
<object class="GtkAdjustment" id="autosave_interval_minutes_adj">
<property name="upper">99999</property>
<property name="value">3</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="date_backmonth_adj">
<property name="upper">11</property>
<property name="value">6</property>
<property name="step_increment">1</property>
<property name="page_increment">4</property>
</object>
<object class="GtkListStore" id="date_formats">
<columns>
<!-- column-name name -->
<column type="gchararray"/>
<!-- column-name example -->
<column type="gchararray"/>
</columns>
<data>
<row>
<col id="0" translatable="yes">US</col>
<col id="1" translatable="yes">07/31/2013</col>
</row>
<row>
<col id="0" translatable="yes">UK</col>
<col id="1" translatable="yes">31/07/2013</col>
</row>
<row>
<col id="0" translatable="yes">Europe</col>
<col id="1" translatable="yes">31.07.2013</col>
</row>
<row>
<col id="0" translatable="yes">ISO</col>
<col id="1" translatable="yes">2013-07-31</col>
</row>
<row>
<col id="0" translatable="yes">Locale</col>
<col id="1" translatable="yes">(dummy)</col>
</row>
</data>
</object>
<object class="GtkAdjustment" id="key_length_adj">
<property name="lower">1</property>
<property name="upper">999</property>
<property name="value">2</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="max_transactions_adj">
<property name="upper">999999</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="new_search_limit_adj">
<property name="lower">1</property>
<property name="upper">100</property>
<property name="value">1</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="retain_days_adj">
<property name="lower">1</property>
<property name="upper">99999</property>
<property name="value">30</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="save_on_close_adj">
<property name="upper">300</property>
<property name="value">20</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="tab_width_adj">
<property name="lower">1</property>
<property name="upper">100</property>
<property name="value">30</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
</interface>

View File

@ -15,6 +15,11 @@
<summary>Character to use as separator between account names</summary>
<description>This setting determines the character that will be used between components of an account name. Possible values are any single non-alphanumeric unicode character, or any of the following strings: "colon" "slash", "backslash", "dash" and "period".</description>
</key>
<key name="assoc-head" type="s">
<default>''</default>
<summary>Transaction Associations head path</summary>
<description>This is the path head for the Transaction file Associations</description>
</key>
<key name="file-compression" type="b">
<default>true</default>
<summary>Compress the data file</summary>