mirror of
https://github.com/Gnucash/gnucash.git
synced 2024-11-25 18:30:23 -06:00
Bug #514210: Allow multiple rows to be selected and remapped on QIF Import
account mapping pages. Also includes many whitespace adjustments. BP git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@17156 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
d0ddccaa01
commit
23b3f81410
@ -1,5 +1,5 @@
|
||||
/********************************************************************\
|
||||
* dialog-account-picker.c -- window for picking a Gnucash account *
|
||||
* dialog-account-picker.c -- window for picking a Gnucash account *
|
||||
* from the QIF importer. *
|
||||
* Copyright (C) 2000-2001 Bill Gribble <grib@billgribble.com> *
|
||||
* Copyright (c) 2006 David Hampton <hampton@employees.org> *
|
||||
@ -46,14 +46,14 @@ struct _accountpickerdialog {
|
||||
GtkWidget * dialog;
|
||||
GtkTreeView * treeview;
|
||||
QIFImportWindow * qif_wind;
|
||||
SCM map_entry;
|
||||
SCM map_entry;
|
||||
gchar * selected_name;
|
||||
};
|
||||
|
||||
static void
|
||||
acct_tree_add_accts(SCM accts,
|
||||
GtkTreeStore *store,
|
||||
GtkTreeIter *parent,
|
||||
GtkTreeStore *store,
|
||||
GtkTreeIter *parent,
|
||||
const char *base_name,
|
||||
const char *selected_name,
|
||||
GtkTreeRowReference **reference)
|
||||
@ -64,7 +64,7 @@ acct_tree_add_accts(SCM accts,
|
||||
gboolean leafnode;
|
||||
SCM current;
|
||||
gboolean checked;
|
||||
|
||||
|
||||
while(!SCM_NULLP(accts)) {
|
||||
current = SCM_CAR(accts);
|
||||
|
||||
@ -79,33 +79,33 @@ acct_tree_add_accts(SCM accts,
|
||||
else
|
||||
compname = "";
|
||||
|
||||
if(!SCM_NULLP(SCM_CADDR(current))) {
|
||||
if (!SCM_NULLP(SCM_CADDR(current))) {
|
||||
leafnode = FALSE;
|
||||
}
|
||||
else {
|
||||
leafnode = TRUE;
|
||||
}
|
||||
|
||||
/* compute full name */
|
||||
if(base_name && *base_name) {
|
||||
/* compute full name */
|
||||
if (base_name && *base_name) {
|
||||
acctname = g_strjoin(gnc_get_account_separator_string(),
|
||||
base_name, compname, (char *)NULL);
|
||||
base_name, compname, (char *)NULL);
|
||||
}
|
||||
else {
|
||||
acctname = g_strdup(compname);
|
||||
}
|
||||
|
||||
checked = (SCM_CADR (current) == SCM_BOOL_T);
|
||||
checked = (SCM_CADR(current) == SCM_BOOL_T);
|
||||
|
||||
gtk_tree_store_append(store, &iter, parent);
|
||||
gtk_tree_store_set(store, &iter,
|
||||
ACCOUNT_COL_NAME, compname,
|
||||
ACCOUNT_COL_FULLNAME, acctname,
|
||||
ACCOUNT_COL_CHECK, checked,
|
||||
-1);
|
||||
ACCOUNT_COL_NAME, compname,
|
||||
ACCOUNT_COL_FULLNAME, acctname,
|
||||
ACCOUNT_COL_CHECK, checked,
|
||||
-1);
|
||||
|
||||
if (reference && !*reference &&
|
||||
selected_name && (g_utf8_collate(selected_name, acctname) == 0)) {
|
||||
selected_name && (g_utf8_collate(selected_name, acctname) == 0)) {
|
||||
GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
|
||||
*reference = gtk_tree_row_reference_new(GTK_TREE_MODEL(store), path);
|
||||
gtk_tree_path_free(path);
|
||||
@ -113,12 +113,12 @@ acct_tree_add_accts(SCM accts,
|
||||
|
||||
if(!leafnode) {
|
||||
acct_tree_add_accts(SCM_CADDR(current), store, &iter, acctname,
|
||||
selected_name, reference);
|
||||
selected_name, reference);
|
||||
}
|
||||
|
||||
g_free(acctname);
|
||||
|
||||
accts = SCM_CDR(accts);
|
||||
accts = SCM_CDR(accts);
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,8 +126,8 @@ static void
|
||||
build_acct_tree(QIFAccountPickerDialog * picker, QIFImportWindow * import)
|
||||
{
|
||||
SCM get_accts = scm_c_eval_string("qif-import:get-all-accts");
|
||||
SCM acct_tree = scm_call_1(get_accts,
|
||||
gnc_ui_qif_import_druid_get_mappings(import));
|
||||
SCM acct_tree = scm_call_1(get_accts,
|
||||
gnc_ui_qif_import_druid_get_mappings(import));
|
||||
GtkTreeStore *store;
|
||||
GtkTreePath *path;
|
||||
GtkTreeSelection* selection;
|
||||
@ -137,7 +137,7 @@ build_acct_tree(QIFAccountPickerDialog * picker, QIFImportWindow * import)
|
||||
gtk_tree_store_clear(store);
|
||||
|
||||
acct_tree_add_accts(acct_tree, store, NULL, NULL,
|
||||
picker->selected_name, &reference);
|
||||
picker->selected_name, &reference);
|
||||
|
||||
if (reference) {
|
||||
selection = gtk_tree_view_get_selection(picker->treeview);
|
||||
@ -160,11 +160,11 @@ gnc_ui_qif_account_picker_new_cb(GtkButton * w, gpointer user_data)
|
||||
char * fullname;
|
||||
GtkWidget *dlg, *entry;
|
||||
|
||||
dlg = gtk_message_dialog_new (GTK_WINDOW(wind->dialog),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_QUESTION,
|
||||
GTK_BUTTONS_OK_CANCEL,
|
||||
"%s", _("Enter a name for the account"));
|
||||
dlg = gtk_message_dialog_new(GTK_WINDOW(wind->dialog),
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_QUESTION,
|
||||
GTK_BUTTONS_OK_CANCEL,
|
||||
"%s", _("Enter a name for the account"));
|
||||
|
||||
entry = gtk_entry_new();
|
||||
gtk_entry_set_max_length(GTK_ENTRY(entry), 250);
|
||||
@ -176,7 +176,7 @@ gnc_ui_qif_account_picker_new_cb(GtkButton * w, gpointer user_data)
|
||||
name = gtk_entry_get_text(GTK_ENTRY(entry));
|
||||
if(wind->selected_name && (strlen(wind->selected_name) > 0)) {
|
||||
fullname = g_strjoin(gnc_get_account_separator_string(),
|
||||
wind->selected_name, name, (char *)NULL);
|
||||
wind->selected_name, name, (char *)NULL);
|
||||
}
|
||||
else {
|
||||
fullname = g_strdup(name);
|
||||
@ -192,8 +192,8 @@ gnc_ui_qif_account_picker_new_cb(GtkButton * w, gpointer user_data)
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_ui_qif_account_picker_changed_cb (GtkTreeSelection *selection,
|
||||
gpointer user_data)
|
||||
gnc_ui_qif_account_picker_changed_cb(GtkTreeSelection *selection,
|
||||
gpointer user_data)
|
||||
{
|
||||
QIFAccountPickerDialog * wind = user_data;
|
||||
SCM name_setter = scm_c_eval_string("qif-map-entry:set-gnc-name!");
|
||||
@ -202,22 +202,26 @@ gnc_ui_qif_account_picker_changed_cb (GtkTreeSelection *selection,
|
||||
|
||||
g_free(wind->selected_name);
|
||||
if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
|
||||
gtk_tree_model_get(model, &iter, ACCOUNT_COL_FULLNAME, &wind->selected_name, -1);
|
||||
scm_call_2(name_setter, wind->map_entry, scm_makfrom0str(wind->selected_name));
|
||||
gtk_tree_model_get(model, &iter,
|
||||
ACCOUNT_COL_FULLNAME, &wind->selected_name,
|
||||
-1);
|
||||
scm_call_2(name_setter, wind->map_entry,
|
||||
scm_makfrom0str(wind->selected_name));
|
||||
} else {
|
||||
wind->selected_name = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_ui_qif_account_picker_row_activated_cb (GtkTreeView *view, GtkTreePath *path,
|
||||
GtkTreeViewColumn *column,
|
||||
gpointer user_data)
|
||||
gnc_ui_qif_account_picker_row_activated_cb(GtkTreeView *view,
|
||||
GtkTreePath *path,
|
||||
GtkTreeViewColumn *column,
|
||||
gpointer user_data)
|
||||
{
|
||||
QIFAccountPickerDialog *wind = user_data;
|
||||
g_return_if_fail (wind);
|
||||
g_return_if_fail(wind);
|
||||
|
||||
gtk_dialog_response (GTK_DIALOG (wind->dialog), GTK_RESPONSE_OK);
|
||||
gtk_dialog_response(GTK_DIALOG(wind->dialog), GTK_RESPONSE_OK);
|
||||
}
|
||||
|
||||
static int
|
||||
@ -232,21 +236,22 @@ gnc_ui_qif_account_picker_map_cb(GtkWidget * w, gpointer user_data)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************
|
||||
* qif_account_picker_dialog
|
||||
* select an account from the ones that the engine knows about, plus
|
||||
* the ones that will be created newly by the QIF import. this is
|
||||
* sort of like fileBox... it returns a string for the account name or
|
||||
* NULL on cancel. It's modal.
|
||||
*
|
||||
* Select an account from the ones that the engine knows about,
|
||||
* plus those that will be created by the QIF import. Returns
|
||||
* a new Scheme map entry, or SCM_BOOL_F on cancel. Modal.
|
||||
****************************************************************/
|
||||
|
||||
SCM
|
||||
qif_account_picker_dialog(QIFImportWindow * qif_wind, SCM map_entry)
|
||||
{
|
||||
{
|
||||
QIFAccountPickerDialog * wind;
|
||||
SCM save_entry = scm_c_eval_string("qif-map-entry:clone");
|
||||
SCM clone_entry = scm_c_eval_string("qif-map-entry:clone");
|
||||
SCM init_pick = scm_c_eval_string("qif-map-entry:gnc-name");
|
||||
SCM saved_entry = scm_call_1(save_entry, map_entry);
|
||||
SCM new_entry = scm_call_1(clone_entry, map_entry);
|
||||
int response;
|
||||
const gchar * scmname;
|
||||
GladeXML *xml;
|
||||
@ -254,19 +259,20 @@ qif_account_picker_dialog(QIFImportWindow * qif_wind, SCM map_entry)
|
||||
|
||||
wind = g_new0(QIFAccountPickerDialog, 1);
|
||||
|
||||
xml = gnc_glade_xml_new ("qif.glade", "QIF Import Account Picker");
|
||||
xml = gnc_glade_xml_new("qif.glade", "QIF Import Account Picker");
|
||||
|
||||
glade_xml_signal_connect_data
|
||||
(xml, "gnc_ui_qif_account_picker_new_cb",
|
||||
G_CALLBACK (gnc_ui_qif_account_picker_new_cb), wind);
|
||||
glade_xml_signal_connect_data(xml,
|
||||
"gnc_ui_qif_account_picker_new_cb",
|
||||
G_CALLBACK(gnc_ui_qif_account_picker_new_cb),
|
||||
wind);
|
||||
|
||||
wind->dialog = glade_xml_get_widget (xml, "QIF Import Account Picker");
|
||||
wind->treeview = GTK_TREE_VIEW(glade_xml_get_widget (xml, "account_tree"));
|
||||
wind->dialog = glade_xml_get_widget(xml, "QIF Import Account Picker");
|
||||
wind->treeview = GTK_TREE_VIEW(glade_xml_get_widget(xml, "account_tree"));
|
||||
wind->qif_wind = qif_wind;
|
||||
|
||||
wind->map_entry = map_entry;
|
||||
|
||||
scmname = SCM_STRING_CHARS(scm_call_1(init_pick, map_entry));
|
||||
wind->map_entry = new_entry;
|
||||
|
||||
scmname = SCM_STRING_CHARS(scm_call_1(init_pick, new_entry));
|
||||
wind->selected_name = g_strdup(scmname);
|
||||
|
||||
scm_gc_protect_object(wind->map_entry);
|
||||
@ -278,40 +284,44 @@ qif_account_picker_dialog(QIFImportWindow * qif_wind, SCM map_entry)
|
||||
GtkTreeSelection *selection;
|
||||
|
||||
store = gtk_tree_store_new(NUM_ACCOUNT_COLS, G_TYPE_STRING, G_TYPE_STRING,
|
||||
G_TYPE_BOOLEAN);
|
||||
G_TYPE_BOOLEAN);
|
||||
gtk_tree_view_set_model(wind->treeview, GTK_TREE_MODEL(store));
|
||||
g_object_unref(store);
|
||||
|
||||
renderer = gtk_cell_renderer_text_new();
|
||||
column = gtk_tree_view_column_new_with_attributes(_("Account"), renderer,
|
||||
"text", ACCOUNT_COL_NAME,
|
||||
NULL);
|
||||
column = gtk_tree_view_column_new_with_attributes(_("Account"),
|
||||
renderer,
|
||||
"text",
|
||||
ACCOUNT_COL_NAME,
|
||||
NULL);
|
||||
g_object_set(column, "expand", TRUE, NULL);
|
||||
gtk_tree_view_append_column(wind->treeview, column);
|
||||
|
||||
renderer = gtk_cell_renderer_toggle_new();
|
||||
g_object_set(renderer, "activatable", FALSE, NULL);
|
||||
column = gtk_tree_view_column_new_with_attributes(_("New?"), renderer,
|
||||
"active", ACCOUNT_COL_CHECK,
|
||||
NULL);
|
||||
column = gtk_tree_view_column_new_with_attributes(_("New?"),
|
||||
renderer,
|
||||
"active",
|
||||
ACCOUNT_COL_CHECK,
|
||||
NULL);
|
||||
gtk_tree_view_append_column(wind->treeview, column);
|
||||
|
||||
selection = gtk_tree_view_get_selection(wind->treeview);
|
||||
g_signal_connect(selection, "changed",
|
||||
G_CALLBACK(gnc_ui_qif_account_picker_changed_cb), wind);
|
||||
G_CALLBACK(gnc_ui_qif_account_picker_changed_cb), wind);
|
||||
g_signal_connect(wind->treeview, "row-activated",
|
||||
G_CALLBACK(gnc_ui_qif_account_picker_row_activated_cb),
|
||||
wind);
|
||||
G_CALLBACK(gnc_ui_qif_account_picker_row_activated_cb),
|
||||
wind);
|
||||
}
|
||||
|
||||
g_signal_connect_after(wind->dialog, "map",
|
||||
G_CALLBACK(gnc_ui_qif_account_picker_map_cb),
|
||||
wind);
|
||||
|
||||
button = glade_xml_get_widget (xml, "newbutton");
|
||||
G_CALLBACK(gnc_ui_qif_account_picker_map_cb),
|
||||
wind);
|
||||
|
||||
button = glade_xml_get_widget(xml, "newbutton");
|
||||
gtk_button_set_use_stock(GTK_BUTTON(button), TRUE);
|
||||
|
||||
/* this is to get the checkmarks set up right.. it will get called
|
||||
/* this is to get the checkmarks set up right.. it will get called
|
||||
* again after the window is mapped. */
|
||||
build_acct_tree(wind, wind->qif_wind);
|
||||
|
||||
@ -324,10 +334,8 @@ qif_account_picker_dialog(QIFImportWindow * qif_wind, SCM map_entry)
|
||||
g_free(wind->selected_name);
|
||||
g_free(wind);
|
||||
|
||||
if (response == GTK_RESPONSE_OK) {
|
||||
return map_entry;
|
||||
}
|
||||
else {
|
||||
return saved_entry;
|
||||
}
|
||||
if (response == GTK_RESPONSE_OK)
|
||||
return new_entry;
|
||||
|
||||
return SCM_BOOL_F;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user