Merge branch 'Bug796896' of https://github.com/Bob-IT/gnucash into maint

This commit is contained in:
Geert Janssens 2018-11-28 14:21:16 +01:00
commit de6c173ef4
10 changed files with 262 additions and 312 deletions

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.0 -->
<!-- Generated with glade 3.20.4 -->
<interface>
<requires lib="gtk+" version="3.10"/>
<object class="GtkAdjustment" id="num_hrows_adj">
@ -279,7 +279,6 @@ Enter file name and location for the Import...
</child>
</object>
<packing>
<property name="page_type">progress</property>
<property name="title" translatable="yes">Import Account Preview, first 10 rows only</property>
<property name="complete">True</property>
<property name="has_padding">False</property>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.2 -->
<!-- Generated with glade 3.20.4 -->
<interface>
<requires lib="gtk+" version="3.10"/>
<object class="GtkAdjustment" id="end_row_adj">
@ -66,6 +66,7 @@ Click on 'Forward' to proceed or 'Cancel' to Abort Import.</property>
</object>
<packing>
<property name="page_type">intro</property>
<property name="title" translatable="yes">Price Import Assistant</property>
<property name="complete">True</property>
<property name="has_padding">False</property>
</packing>
@ -453,6 +454,7 @@ Select location and file name for the Import, then click 'OK'...
<property name="label" translatable="yes">Double-click anywhere on the table below to insert a column break</property>
<property name="use_markup">True</property>
<property name="wrap">True</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">1</property>
@ -480,6 +482,7 @@ Select location and file name for the Import, then click 'OK'...
<property name="label" translatable="yes">Right-click anywhere in a column to modify it (widen, narrow, merge)</property>
<property name="use_markup">True</property>
<property name="wrap">True</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">1</property>
@ -920,48 +923,13 @@ For example
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkViewport" id="viewport2">
<object class="GtkTreeView" id="treeview">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkBox" id="vbox8">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkTreeView" id="ctreeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="headers_visible">False</property>
<property name="enable_grid_lines">both</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkTreeView" id="treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="enable_grid_lines">both</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="enable_grid_lines">both</property>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
</object>
</child>
@ -1042,7 +1010,7 @@ For example
</child>
</object>
<packing>
<property name="page_type">intro</property>
<property name="title" translatable="yes">Import Preview</property>
<property name="complete">True</property>
<property name="has_padding">False</property>
</packing>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.20.2 -->
<!-- Generated with glade 3.20.4 -->
<interface>
<requires lib="gtk+" version="3.10"/>
<object class="GtkListStore" id="account_match_store">
@ -57,6 +57,7 @@ Lastly, for repeated imports the preview page has buttons to Load and Save the s
</object>
<packing>
<property name="page_type">intro</property>
<property name="title" translatable="yes">Transaction Import Assistant</property>
<property name="complete">True</property>
<property name="has_padding">False</property>
</packing>
@ -453,6 +454,7 @@ Select location and file name for the Import, then click 'OK'...
<property name="label" translatable="yes">Double-click anywhere on the table below to insert a column break</property>
<property name="use_markup">True</property>
<property name="wrap">True</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">1</property>
@ -480,6 +482,7 @@ Select location and file name for the Import, then click 'OK'...
<property name="label" translatable="yes">Right-click anywhere in a column to modify it (widen, narrow, merge)</property>
<property name="use_markup">True</property>
<property name="wrap">True</property>
<property name="xalign">0</property>
</object>
<packing>
<property name="left_attach">1</property>
@ -854,48 +857,13 @@ For example
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkViewport" id="viewport2">
<object class="GtkTreeView" id="treeview">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkBox" id="vbox8">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkTreeView" id="ctreeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="headers_visible">False</property>
<property name="enable_grid_lines">both</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection1"/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkTreeView" id="treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="enable_grid_lines">both</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection2"/>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="enable_grid_lines">both</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection2"/>
</child>
</object>
</child>
@ -982,7 +950,7 @@ For example
</child>
</object>
<packing>
<property name="page_type">intro</property>
<property name="title" translatable="yes">Import Preview</property>
<property name="complete">True</property>
<property name="has_padding">False</property>
</packing>
@ -1098,7 +1066,7 @@ For example
</child>
</object>
<packing>
<property name="title" translatable="yes">Match Import accounts with GnuCash accounts</property>
<property name="title" translatable="yes">Match Import and GnuCash accounts</property>
<property name="has_padding">False</property>
</packing>
</child>

View File

@ -73,7 +73,7 @@ void csv_export_show_range_cb (GtkRadioButton *button, gpointer user_data);
void csv_export_start_date_cb (GtkWidget *radio, gpointer user_data);
void csv_export_end_date_cb (GtkWidget *radio, gpointer user_data);
void csv_export_file_chooser_confirm_cb (GtkWidget *button, CsvExportInfo *info);
void csv_export_file_chooser_selection_changed_cb (GtkFileChooser *chooser, CsvExportInfo *info);
static const gchar *finish_tree_string = N_(
/* Translators: %s is the file name string. */
@ -121,55 +121,43 @@ static const gchar *start_trans_simple_string = N_(
/**************************************************
* csv_export_file_chooser_confirm_cb
* csv_export_file_chooser_selection_changed_cb
*
* call back for ok button in file chooser widget
* call back for GtkFileChooser widget
**************************************************/
void
csv_export_file_chooser_confirm_cb (GtkWidget *button, CsvExportInfo *info)
csv_export_file_chooser_selection_changed_cb (GtkFileChooser *chooser, CsvExportInfo *info)
{
GtkAssistant *assistant = GTK_ASSISTANT(info->window);
gint num = gtk_assistant_get_current_page (assistant);
GtkWidget *page = gtk_assistant_get_nth_page (assistant, num);
gchar *file_name;
gtk_assistant_set_page_complete (assistant, page, FALSE);
file_name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(info->file_chooser));
if (file_name)
{
if (g_file_test (file_name, G_FILE_TEST_EXISTS))
{
const char *format = _("The file %s already exists. "
"Are you sure you want to overwrite it?");
/* if user says cancel, we should break out */
if (!gnc_verify_dialog (GTK_WINDOW (assistant), FALSE, format, file_name))
return;
}
info->file_name = g_strdup (file_name);
gtk_assistant_set_page_complete (assistant, page, TRUE);
}
if (file_name)
/* Test for a valid filename and not a directory */
if (file_name && !g_file_test (file_name, G_FILE_TEST_IS_DIR))
{
gchar *filepath = gnc_uri_get_path (file_name);
gchar *filedir = g_path_get_dirname (filepath);
g_free (info->file_name);
info->file_name = g_strdup (file_name);
g_free (info->starting_dir);
info->starting_dir = g_strdup (filedir);
g_free (filedir);
g_free (filepath);
gtk_assistant_set_page_complete (assistant, page, TRUE);
}
g_free (file_name);
DEBUG("file_name selected is %s", info->file_name);
DEBUG("starting directory is %s", info->starting_dir);
/* Step to next page if page is complete */
if(gtk_assistant_get_page_complete (assistant, page))
gtk_assistant_set_current_page (assistant, num + 1);
}
@ -268,7 +256,6 @@ csv_export_custom_entry_cb (GtkWidget *widget, gpointer user_data)
info->separator_str = strdup (custom_str);
if (info->use_custom == TRUE && gtk_entry_get_text_length (GTK_ENTRY(info->custom_entry)) == 0)
gtk_assistant_set_page_complete (assistant, page, FALSE);
else
gtk_assistant_set_page_complete (assistant, page, TRUE);
@ -701,6 +688,16 @@ csv_export_assistant_finish_page_prepare (GtkAssistant *assistant,
gtk_label_set_text (GTK_LABEL(info->finish_label), text);
g_free (text);
/* Test if the filename exists */
if (g_file_test (info->file_name, G_FILE_TEST_EXISTS))
{
const char *format = _("The file %s already exists. "
"Are you sure you want to overwrite it?");
/* if user says cancel, we should go back a page */
if (!gnc_verify_dialog (GTK_WINDOW (assistant), FALSE, format, info->file_name))
gtk_assistant_previous_page (assistant);
}
/* Enable the Assistant Buttons */
gtk_assistant_set_page_complete (assistant, page, TRUE);
}
@ -921,15 +918,9 @@ csv_export_assistant_create (CsvExportInfo *info)
/* File chooser Page */
info->file_page = GTK_WIDGET(gtk_builder_get_object(builder, "file_page"));
info->file_chooser = gtk_file_chooser_widget_new (GTK_FILE_CHOOSER_ACTION_SAVE);
button = gtk_button_new_with_mnemonic (_("_OK"));
gtk_widget_set_size_request (button, 100, -1);
gtk_widget_show (button);
h_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_set_homogeneous (GTK_BOX (h_box), TRUE);
gtk_box_pack_start(GTK_BOX(h_box), button, FALSE, FALSE, 0);
gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER(info->file_chooser), h_box);
g_signal_connect (G_OBJECT(button), "clicked",
G_CALLBACK(csv_export_file_chooser_confirm_cb), info);
g_signal_connect (G_OBJECT(info->file_chooser), "selection-changed",
G_CALLBACK(csv_export_file_chooser_selection_changed_cb), info);
box = GTK_WIDGET(gtk_builder_get_object (builder, "file_page"));
gtk_box_pack_start (GTK_BOX (box), info->file_chooser, TRUE, TRUE, 6);

View File

@ -62,7 +62,7 @@ void csv_import_assistant_summary_page_prepare (GtkAssistant *assistant, gpointe
void csv_import_sep_cb (GtkWidget *radio, gpointer user_data );
void csv_import_hrows_cb (GtkWidget *spin, gpointer user_data );
void csv_import_file_chooser_confirm_cb (GtkWidget *button, CsvImportInfo *info);
void csv_import_file_chooser_selection_changed_cb (GtkFileChooser *chooser, CsvImportInfo *info);
static gchar *gnc_input_dialog (GtkWidget *parent, const gchar *title, const gchar *msg, const gchar *default_input);
@ -136,25 +136,22 @@ void create_regex (GString *regex_str, const gchar *sep)
/*************************************************************************/
/**************************************************
* csv_file_chooser_confirm_cb
* csv_import_file_chooser_selection_changed_cb
*
* call back for ok button in file chooser widget
* call back for file chooser widget
**************************************************/
void
csv_import_file_chooser_confirm_cb (GtkWidget *button, CsvImportInfo *info)
csv_import_file_chooser_selection_changed_cb (GtkFileChooser *chooser, CsvImportInfo *info)
{
GtkAssistant *assistant = GTK_ASSISTANT(info->window);
gint num = gtk_assistant_get_current_page (assistant);
GtkWidget *page = gtk_assistant_get_nth_page (assistant, num);
GtkAssistant *assistant = GTK_ASSISTANT(info->assistant);
gchar *file_name;
csv_import_result res;
gtk_assistant_set_page_complete (assistant, page, FALSE);
gtk_assistant_set_page_complete (assistant, info->file_page, FALSE);
gtk_assistant_set_page_complete (assistant, info->account_page, FALSE);
file_name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(info->file_chooser));
if (file_name)
if (file_name && !g_file_test (file_name, G_FILE_TEST_IS_DIR))
{
gchar *filepath = gnc_uri_get_path (file_name);
gchar *filedir = g_path_get_dirname (filepath);
@ -164,25 +161,12 @@ csv_import_file_chooser_confirm_cb (GtkWidget *button, CsvImportInfo *info)
info->file_name = g_strdup (file_name);
// generate preview
gtk_list_store_clear (info->store);
res = csv_import_read_file (info->file_name, info->regexp->str, info->store, 1 );
if (res == RESULT_OPEN_FAILED)
gnc_error_dialog (GTK_WINDOW (info->window), _("The input file can not be opened."));
else if (res == RESULT_OK)
gtk_assistant_set_page_complete (assistant, page, TRUE);
else if (res == MATCH_FOUND)
gtk_assistant_set_page_complete (assistant, page, TRUE);
gtk_assistant_set_page_complete (assistant, info->file_page, TRUE);
}
g_free (file_name);
DEBUG("file_name selected is %s", info->file_name);
DEBUG("starting directory is %s", info->starting_dir);
/* Step to next page if page is complete */
if(gtk_assistant_get_page_complete (assistant, page))
gtk_assistant_set_current_page (assistant, num + 1);
}
@ -227,6 +211,24 @@ void csv_import_hrows_cb (GtkWidget *spin, gpointer user_data)
}
/*******************************************************
* csv_import_assistant_enable_account_forward
*
* enaable forward button on account_page if store has rows
*******************************************************/
static void csv_import_assistant_enable_account_forward (CsvImportInfo *info)
{
GtkAssistant *assistant = GTK_ASSISTANT(info->assistant);
gboolean store_has_rows = TRUE;
/* if the store is empty, disable forward button */
if (gtk_tree_model_iter_n_children (GTK_TREE_MODEL(info->store), NULL) == 0)
store_has_rows = FALSE;
gtk_assistant_set_page_complete (assistant, info->account_page, store_has_rows);
}
/*******************************************************
* csv_import_sep_cb
*
@ -257,7 +259,10 @@ void csv_import_sep_cb (GtkWidget *radio, gpointer user_data)
if (g_strcmp0 (name, "radio_custom") == 0)
{
temp = gnc_input_dialog (0, _("Adjust regular expression used for import"), _("This regular expression is used to parse the import file. Modify according to your needs.\n"), info->regexp->str);
temp = gnc_input_dialog (GTK_WIDGET (info->assistant),
_("Adjust regular expression used for import"),
_("This regular expression is used to parse the import file. Modify according to your needs.\n"),
info->regexp->str);
if (temp)
{
g_string_assign (info->regexp, temp);
@ -269,10 +274,13 @@ void csv_import_sep_cb (GtkWidget *radio, gpointer user_data)
gtk_list_store_clear (info->store);
gtk_widget_set_sensitive (info->header_row_spin, TRUE);
if (csv_import_read_file (info->file_name, info->regexp->str, info->store, 11) == MATCH_FOUND)
if (csv_import_read_file (GTK_WINDOW (info->assistant), info->file_name, info->regexp->str, info->store, 11) == MATCH_FOUND)
gtk_spin_button_set_value (GTK_SPIN_BUTTON(info->header_row_spin), 1); // set header spin to 1
else
gtk_spin_button_set_value (GTK_SPIN_BUTTON(info->header_row_spin), 0); //reset header spin to 0
/* if the store has rows, enable forward button */
csv_import_assistant_enable_account_forward (info);
}
@ -385,15 +393,13 @@ csv_import_assistant_file_page_prepare (GtkAssistant *assistant,
gpointer user_data)
{
CsvImportInfo *info = user_data;
gint num = gtk_assistant_get_current_page (assistant);
GtkWidget *page = gtk_assistant_get_nth_page (assistant, num);
/* Set the default directory */
if (info->starting_dir)
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(info->file_chooser), info->starting_dir);
/* Disable the Forward Assistant Button */
gtk_assistant_set_page_complete (assistant, page, FALSE);
gtk_assistant_set_page_complete (assistant, info->file_page, FALSE);
}
@ -402,15 +408,36 @@ csv_import_assistant_account_page_prepare (GtkAssistant *assistant,
gpointer user_data)
{
CsvImportInfo *info = user_data;
csv_import_result res;
/* Disable the Forward Assistant Button */
gtk_assistant_set_page_complete (assistant, info->account_page, FALSE);
/* test read one line */
gtk_list_store_clear (info->store);
res = csv_import_read_file (GTK_WINDOW (info->assistant), info->file_name, info->regexp->str, info->store, 1 );
if (res == RESULT_OPEN_FAILED)
{
gnc_error_dialog (GTK_WINDOW (info->assistant), _("The input file can not be opened."));
gtk_assistant_previous_page (assistant);
}
else if (res == RESULT_OK)
gtk_assistant_set_page_complete (assistant, info->account_page, TRUE);
else if (res == MATCH_FOUND)
gtk_assistant_set_page_complete (assistant, info->account_page, TRUE);
// generate preview
gtk_list_store_clear (info->store);
gtk_widget_set_sensitive (info->header_row_spin, TRUE);
if (csv_import_read_file (info->file_name, info->regexp->str, info->store, 11 ) == MATCH_FOUND)
if (csv_import_read_file (GTK_WINDOW (info->assistant), info->file_name, info->regexp->str, info->store, 11 ) == MATCH_FOUND)
gtk_spin_button_set_value (GTK_SPIN_BUTTON(info->header_row_spin), 1); // set header spin to 1
else
gtk_spin_button_set_value (GTK_SPIN_BUTTON(info->header_row_spin), 0); //reset header spin to 0
/* if the store has rows, enable forward button */
csv_import_assistant_enable_account_forward (info);
}
@ -419,21 +446,16 @@ csv_import_assistant_finish_page_prepare (GtkAssistant *assistant,
gpointer user_data)
{
CsvImportInfo *info = user_data;
gint num = gtk_assistant_get_current_page (assistant);
GtkWidget *page = gtk_assistant_get_nth_page (assistant, num);
gchar *text;
/* Set Finish page text */
/* Before creating accounts, if this is a new book, tell user they can
* specify book options, since they affect how transactions are created */
if (info->new_book)
{
text = g_strdup_printf (gettext (new_book_finish_tree_string), info->file_name);
}
else
{
text = g_strdup_printf (gettext (finish_tree_string), info->file_name);
}
gtk_label_set_text (GTK_LABEL(info->finish_label), text);
g_free (text);
@ -441,7 +463,7 @@ csv_import_assistant_finish_page_prepare (GtkAssistant *assistant,
gnc_set_default_directory (GNC_PREFS_GROUP, info->starting_dir);
/* Enable the Assistant Buttons */
gtk_assistant_set_page_complete (assistant, page, TRUE);
gtk_assistant_set_page_complete (assistant, info->finish_label, TRUE);
}
@ -455,7 +477,7 @@ csv_import_assistant_summary_page_prepare (GtkAssistant *assistant,
/* Before creating accounts, if this is a new book, let user specify
* book options, since they affect how transactions are created */
if (info->new_book)
info->new_book = gnc_new_book_option_display (info->window);
info->new_book = gnc_new_book_option_display (info->assistant);
if (g_strcmp0 (info->error, "") != 0)
{
@ -544,7 +566,7 @@ csv_import_assistant_finish (GtkAssistant *assistant, gpointer user_data)
CsvImportInfo *info = user_data;
gtk_list_store_clear (info->store);
csv_import_read_file (info->file_name, info->regexp->str, info->store, 0 );
csv_import_read_file (GTK_WINDOW (info->assistant), info->file_name, info->regexp->str, info->store, 0 );
csv_account_import (info);
}
@ -557,8 +579,8 @@ csv_import_close_handler (gpointer user_data)
g_free (info->file_name);
g_string_free (info->regexp, TRUE);
gnc_save_window_size (GNC_PREFS_GROUP, GTK_WINDOW(info->window));
gtk_widget_destroy (info->window);
gnc_save_window_size (GNC_PREFS_GROUP, GTK_WINDOW(info->assistant));
gtk_widget_destroy (info->assistant);
}
/*******************************************************
@ -568,8 +590,6 @@ static GtkWidget *
csv_import_assistant_create (CsvImportInfo *info)
{
GtkBuilder *builder;
GtkWidget *window;
GtkWidget *box, *h_box;
GtkWidget *button;
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
@ -578,54 +598,44 @@ csv_import_assistant_create (CsvImportInfo *info)
builder = gtk_builder_new();
gnc_builder_add_from_file (builder, "assistant-csv-account-import.glade", "num_hrows_adj");
gnc_builder_add_from_file (builder, "assistant-csv-account-import.glade", "csv_account_import_assistant");
window = GTK_WIDGET(gtk_builder_get_object (builder, "csv_account_import_assistant"));
info->window = window;
info->assistant = GTK_WIDGET(gtk_builder_get_object (builder, "csv_account_import_assistant"));
// Set the style context for this dialog so it can be easily manipulated with css
gnc_widget_set_style_context (GTK_WIDGET(window), "GncAssistAccountImport");
gnc_widget_set_style_context (GTK_WIDGET(info->assistant), "GncAssistAccountImport");
/* Load default settings */
load_settings (info);
/* Enable buttons on all page. */
gtk_assistant_set_page_complete (GTK_ASSISTANT(window),
gtk_assistant_set_page_complete (GTK_ASSISTANT(info->assistant),
GTK_WIDGET(gtk_builder_get_object(builder, "start_page")),
TRUE);
gtk_assistant_set_page_complete (GTK_ASSISTANT(window),
gtk_assistant_set_page_complete (GTK_ASSISTANT(info->assistant),
GTK_WIDGET(gtk_builder_get_object(builder, "file_page")),
FALSE);
gtk_assistant_set_page_complete (GTK_ASSISTANT(window),
gtk_assistant_set_page_complete (GTK_ASSISTANT(info->assistant),
GTK_WIDGET(gtk_builder_get_object(builder, "import_tree_page")),
TRUE);
gtk_assistant_set_page_complete (GTK_ASSISTANT(window),
gtk_assistant_set_page_complete (GTK_ASSISTANT(info->assistant),
GTK_WIDGET(gtk_builder_get_object(builder, "end_page")),
FALSE);
gtk_assistant_set_page_complete (GTK_ASSISTANT(window),
gtk_assistant_set_page_complete (GTK_ASSISTANT(info->assistant),
GTK_WIDGET(gtk_builder_get_object(builder, "summary_page")),
TRUE);
/* Start Page */
/* File chooser Page */
info->file_page = GTK_WIDGET(gtk_builder_get_object(builder, "file_page"));
info->file_chooser = gtk_file_chooser_widget_new (GTK_FILE_CHOOSER_ACTION_OPEN);
g_signal_connect (G_OBJECT(info->file_chooser), "file-activated",
G_CALLBACK(csv_import_file_chooser_confirm_cb), info);
button = gtk_button_new_with_mnemonic (_("_OK"));
gtk_widget_set_size_request (button, 100, -1);
gtk_widget_show (button);
h_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_set_homogeneous (GTK_BOX (h_box), TRUE);
gtk_widget_set_hexpand (GTK_WIDGET(h_box), TRUE);
gtk_box_pack_start (GTK_BOX(h_box), button, FALSE, FALSE, 0);
gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER(info->file_chooser), h_box);
g_signal_connect (G_OBJECT(button), "clicked",
G_CALLBACK(csv_import_file_chooser_confirm_cb), info);
g_signal_connect (G_OBJECT(info->file_chooser), "selection-changed",
G_CALLBACK(csv_import_file_chooser_selection_changed_cb), info);
box = GTK_WIDGET(gtk_builder_get_object(builder, "file_page"));
gtk_box_pack_start (GTK_BOX(box), info->file_chooser, TRUE, TRUE, 6);
gtk_box_pack_start (GTK_BOX(info->file_page), info->file_chooser, TRUE, TRUE, 6);
gtk_widget_show (info->file_chooser);
/* Account Tree Page */
info->account_page = GTK_WIDGET(gtk_builder_get_object(builder, "import_tree_page"));
info->header_row_spin = GTK_WIDGET(gtk_builder_get_object (builder, "num_hrows"));
info->tree_view = GTK_WIDGET(gtk_builder_get_object (builder, "treeview"));
@ -665,15 +675,15 @@ csv_import_assistant_create (CsvImportInfo *info)
info->summary_label = GTK_WIDGET(gtk_builder_get_object (builder, "summary_label"));
info->summary_error_view = GTK_WIDGET(gtk_builder_get_object (builder, "summary_error_view"));
g_signal_connect (G_OBJECT(window), "destroy",
g_signal_connect (G_OBJECT(info->assistant), "destroy",
G_CALLBACK(csv_import_assistant_destroy_cb), info);
gnc_restore_window_size (GNC_PREFS_GROUP,
GTK_WINDOW(info->window), gnc_ui_get_main_window(NULL));
GTK_WINDOW(info->assistant), gnc_ui_get_main_window(NULL));
gtk_builder_connect_signals (builder, info);
g_object_unref (G_OBJECT(builder));
return window;
return info->assistant;
}
@ -701,7 +711,7 @@ gnc_file_csv_account_import(void)
NULL, csv_import_close_handler,
info);
gtk_widget_show_all (info->window);
gtk_widget_show_all (info->assistant);
gnc_window_adjust_for_screen (GTK_WINDOW(info->window));
gnc_window_adjust_for_screen (GTK_WINDOW(info->assistant));
}

View File

@ -39,7 +39,6 @@ enum tree_import_model_columns
typedef struct
{
GtkWidget *window;
GtkWidget *assistant;
GtkWidget *file_chooser;
@ -51,6 +50,9 @@ typedef struct
GtkWidget *summary_label;
GtkWidget *summary_error_view;
GtkWidget *file_page;
GtkWidget *account_page;
gchar *starting_dir;
gchar *file_name;
gchar *error;

View File

@ -93,7 +93,7 @@ public:
void assist_finish ();
void assist_compmgr_close ();
void file_confirm_cb ();
void file_selection_changed_cb ();
void preview_settings_delete ();
void preview_settings_save ();
@ -190,7 +190,7 @@ extern "C"
void csv_price_imp_assist_prepare_cb (GtkAssistant *assistant, GtkWidget *page, CsvImpPriceAssist* info);
void csv_price_imp_assist_close_cb (GtkAssistant *gtkassistant, CsvImpPriceAssist* info);
void csv_price_imp_assist_finish_cb (GtkAssistant *gtkassistant, CsvImpPriceAssist* info);
void csv_price_imp_file_confirm_cb (GtkWidget *button, CsvImpPriceAssist *info);
void csv_price_imp_file_selection_changed_cb (GtkFileChooser *chooser, CsvImpPriceAssist *info);
void csv_price_imp_preview_del_settings_cb (GtkWidget *button, CsvImpPriceAssist *info);
void csv_price_imp_preview_save_settings_cb (GtkWidget *button, CsvImpPriceAssist *info);
void csv_price_imp_preview_settings_sel_changed_cb (GtkComboBox *combo, CsvImpPriceAssist *info);
@ -228,9 +228,9 @@ csv_price_imp_assist_finish_cb (GtkAssistant *assistant, CsvImpPriceAssist* info
info->assist_finish ();
}
void csv_price_imp_file_confirm_cb (GtkWidget *button, CsvImpPriceAssist *info)
void csv_price_imp_file_selection_changed_cb (GtkFileChooser *chooser, CsvImpPriceAssist *info)
{
info->file_confirm_cb();
info->file_selection_changed_cb();
}
void csv_price_imp_preview_del_settings_cb (GtkWidget *button, CsvImpPriceAssist *info)
@ -500,18 +500,9 @@ CsvImpPriceAssist::CsvImpPriceAssist ()
/* File chooser Page */
file_page = GTK_WIDGET(gtk_builder_get_object (builder, "file_page"));
file_chooser = gtk_file_chooser_widget_new (GTK_FILE_CHOOSER_ACTION_OPEN);
g_signal_connect (G_OBJECT(file_chooser), "file-activated",
G_CALLBACK(csv_price_imp_file_confirm_cb), this);
auto button = gtk_button_new_with_mnemonic (_("_OK"));
gtk_widget_set_size_request (button, 100, -1);
gtk_widget_show (button);
auto h_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_set_homogeneous (GTK_BOX (h_box), TRUE);
gtk_widget_set_hexpand (GTK_WIDGET(h_box), TRUE);
gtk_box_pack_start (GTK_BOX(h_box), button, FALSE, FALSE, 0);
gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER(file_chooser), h_box);
g_signal_connect (G_OBJECT(button), "clicked",
G_CALLBACK(csv_price_imp_file_confirm_cb), this);
g_signal_connect (G_OBJECT(file_chooser), "selection-changed",
G_CALLBACK(csv_price_imp_file_selection_changed_cb), this);
auto box = GTK_WIDGET(gtk_builder_get_object (builder, "file_page"));
gtk_box_pack_start (GTK_BOX(box), file_chooser, TRUE, TRUE, 6);
@ -676,15 +667,17 @@ CsvImpPriceAssist::~CsvImpPriceAssist ()
* Code related to the file chooser page
**************************************************/
/* csv_price_imp_file_confirm_cb
/* csv_price_imp_file_selection_changed_cb
*
* call back for ok button in file chooser widget
* call back for file chooser widget
*/
void
CsvImpPriceAssist::file_confirm_cb ()
CsvImpPriceAssist::file_selection_changed_cb ()
{
gtk_assistant_set_page_complete (csv_imp_asst, file_page, false);
auto file_name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(file_chooser));
if (!file_name)
if (!file_name || g_file_test (file_name, G_FILE_TEST_IS_DIR))
return;
auto filepath = gnc_uri_get_path (file_name);
@ -700,36 +693,7 @@ CsvImpPriceAssist::file_confirm_cb ()
g_free (file_name);
g_free (starting_dir);
/* Load the file into parse_data. */
price_imp = std::unique_ptr<GncPriceImport>(new GncPriceImport);
/* Assume data is CSV. User can later override to Fixed Width if needed */
try
{
price_imp->file_format (GncImpFileFormat::CSV);
price_imp->load_file (m_file_name);
price_imp->tokenize (true);
}
catch (std::ifstream::failure& e)
{
/* File loading failed ... */
gnc_error_dialog (GTK_WINDOW(csv_imp_asst), "%s", e.what());
return;
}
catch (std::range_error &e)
{
/* Parsing failed ... */
gnc_error_dialog (GTK_WINDOW(csv_imp_asst), "%s", _(e.what()));
return;
}
/* Get settings store and populate */
preview_populate_settings_combo();
gtk_combo_box_set_active (settings_combo, 0);
// set over_write to false as default
price_imp->over_write (false);
auto num = gtk_assistant_get_current_page (csv_imp_asst);
gtk_assistant_set_current_page (csv_imp_asst, num + 1);
gtk_assistant_set_page_complete (csv_imp_asst, file_page, true);
}
@ -1742,6 +1706,10 @@ void CsvImpPriceAssist::preview_validate_settings ()
void
CsvImpPriceAssist::assist_file_page_prepare ()
{
/* Disable the Forward Assistant Button */
gtk_assistant_set_page_complete (csv_imp_asst, file_page, false);
gtk_assistant_set_page_complete (csv_imp_asst, preview_page, false);
/* Set the default directory */
auto starting_dir = gnc_get_default_directory (GNC_PREFS_GROUP);
if (starting_dir)
@ -1754,11 +1722,51 @@ CsvImpPriceAssist::assist_file_page_prepare ()
void
CsvImpPriceAssist::assist_preview_page_prepare ()
{
/* Disable the Forward Assistant Button */
gtk_assistant_set_page_complete (csv_imp_asst, preview_page, false);
auto go_back = false;
/* Load the data into the treeview. */
preview_refresh_table ();
/* Load the file into parse_data, reset it if altrady loaded. */
if (price_imp)
price_imp.reset();
/* Load the file into parse_data. */
price_imp = std::unique_ptr<GncPriceImport>(new GncPriceImport);
/* Assume data is CSV. User can later override to Fixed Width if needed */
try
{
price_imp->file_format (GncImpFileFormat::CSV);
price_imp->load_file (m_file_name);
price_imp->tokenize (true);
}
catch (std::ifstream::failure& e)
{
/* File loading failed ... */
gnc_error_dialog (GTK_WINDOW(csv_imp_asst), "%s", e.what());
go_back = true;
}
catch (std::range_error &e)
{
/* Parsing failed ... */
gnc_error_dialog (GTK_WINDOW(csv_imp_asst), "%s", _(e.what()));
go_back = true;
}
if (go_back)
gtk_assistant_previous_page (csv_imp_asst);
else
{
/* Get settings store and populate */
preview_populate_settings_combo();
gtk_combo_box_set_active (settings_combo, 0);
// set over_write to false as default
price_imp->over_write (false);
/* Disable the Forward Assistant Button */
gtk_assistant_set_page_complete (csv_imp_asst, preview_page, false);
/* Load the data into the treeview. */
g_idle_add ((GSourceFunc)csv_imp_preview_queue_rebuild_table, this);
}
}
void

View File

@ -159,7 +159,7 @@ public:
void assist_finish ();
void assist_compmgr_close ();
void file_confirm_cb ();
void file_selection_changed_cb ();
void preview_settings_delete ();
void preview_settings_save ();
@ -269,7 +269,7 @@ extern "C"
void csv_tximp_assist_prepare_cb (GtkAssistant *assistant, GtkWidget *page, CsvImpTransAssist* info);
void csv_tximp_assist_close_cb (GtkAssistant *gtkassistant, CsvImpTransAssist* info);
void csv_tximp_assist_finish_cb (GtkAssistant *gtkassistant, CsvImpTransAssist* info);
void csv_tximp_file_confirm_cb (GtkWidget *button, CsvImpTransAssist *info);
void csv_tximp_file_selection_changed_cb (GtkFileChooser *chooser, CsvImpTransAssist *info);
void csv_tximp_preview_del_settings_cb (GtkWidget *button, CsvImpTransAssist *info);
void csv_tximp_preview_save_settings_cb (GtkWidget *button, CsvImpTransAssist *info);
void csv_tximp_preview_settings_sel_changed_cb (GtkComboBox *combo, CsvImpTransAssist *info);
@ -310,9 +310,9 @@ csv_tximp_assist_finish_cb (GtkAssistant *assistant, CsvImpTransAssist* info)
}
void csv_tximp_file_confirm_cb (GtkWidget *button, CsvImpTransAssist *info)
void csv_tximp_file_selection_changed_cb (GtkFileChooser *chooser, CsvImpTransAssist *info)
{
info->file_confirm_cb();
info->file_selection_changed_cb();
}
void csv_tximp_preview_del_settings_cb (GtkWidget *button, CsvImpTransAssist *info)
@ -479,18 +479,8 @@ CsvImpTransAssist::CsvImpTransAssist ()
/* File chooser Page */
file_page = GTK_WIDGET(gtk_builder_get_object (builder, "file_page"));
file_chooser = gtk_file_chooser_widget_new (GTK_FILE_CHOOSER_ACTION_OPEN);
g_signal_connect (G_OBJECT(file_chooser), "file-activated",
G_CALLBACK(csv_tximp_file_confirm_cb), this);
auto button = gtk_button_new_with_mnemonic (_("_OK"));
gtk_widget_set_size_request (button, 100, -1);
gtk_widget_show (button);
auto h_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_set_homogeneous (GTK_BOX (h_box), TRUE);
gtk_widget_set_hexpand (GTK_WIDGET(h_box), TRUE);
gtk_box_pack_start (GTK_BOX(h_box), button, FALSE, FALSE, 0);
gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER(file_chooser), h_box);
g_signal_connect (G_OBJECT(button), "clicked",
G_CALLBACK(csv_tximp_file_confirm_cb), this);
g_signal_connect (G_OBJECT(file_chooser), "selection-changed",
G_CALLBACK(csv_tximp_file_selection_changed_cb), this);
auto box = GTK_WIDGET(gtk_builder_get_object (builder, "file_page"));
gtk_box_pack_start (GTK_BOX(box), file_chooser, TRUE, TRUE, 6);
@ -681,17 +671,17 @@ CsvImpTransAssist::~CsvImpTransAssist ()
* Code related to the file chooser page
**************************************************/
/* csv_tximp_file_confirm_cb
/* csv_tximp_file_selection_changed_cb
*
* call back for ok button in file chooser widget
*/
void
CsvImpTransAssist::file_confirm_cb ()
CsvImpTransAssist::file_selection_changed_cb ()
{
gtk_assistant_set_page_complete (csv_imp_asst, account_match_page, false);
gtk_assistant_set_page_complete (csv_imp_asst, file_page, false);
auto file_name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(file_chooser));
if (!file_name)
if (!file_name || g_file_test (file_name, G_FILE_TEST_IS_DIR))
return;
auto filepath = gnc_uri_get_path (file_name);
@ -707,37 +697,7 @@ CsvImpTransAssist::file_confirm_cb ()
g_free (file_name);
g_free (starting_dir);
/* Load the file into parse_data. */
tx_imp = std::unique_ptr<GncTxImport>(new GncTxImport);
/* Assume data is CSV. User can later override to Fixed Width if needed */
try
{
tx_imp->file_format (GncImpFileFormat::CSV);
tx_imp->load_file (m_file_name);
tx_imp->tokenize (true);
}
catch (std::ifstream::failure& e)
{
/* File loading failed ... */
gnc_error_dialog (GTK_WINDOW (csv_imp_asst), "%s", e.what());
return;
}
catch (std::range_error &e)
{
/* Parsing failed ... */
gnc_error_dialog (GTK_WINDOW (csv_imp_asst), "%s", _(e.what()));
return;
}
preview_refresh ();
/* Get settings store and populate */
preview_populate_settings_combo();
gtk_combo_box_set_active (settings_combo, 0);
gtk_assistant_set_page_complete (csv_imp_asst, account_match_page, true);
auto num = gtk_assistant_get_current_page (csv_imp_asst);
gtk_assistant_set_current_page (csv_imp_asst, num + 1);
gtk_assistant_set_page_complete (csv_imp_asst, file_page, true);
}
@ -1696,9 +1656,11 @@ void CsvImpTransAssist::preview_validate_settings ()
/* Show or hide the account match page based on whether there are
* accounts in the user data according to the importer configuration
* only if there are no errors
*/
gtk_widget_set_visible (GTK_WIDGET(account_match_page),
!tx_imp->accounts().empty());
if (error_msg.empty())
gtk_widget_set_visible (GTK_WIDGET(account_match_page),
!tx_imp->accounts().empty());
}
@ -1884,13 +1846,52 @@ CsvImpTransAssist::assist_file_page_prepare ()
void
CsvImpTransAssist::assist_preview_page_prepare ()
{
tx_imp->req_mapped_accts (false);
auto go_back = false;
/* Load the file into parse_data, reset it if altrady loaded. */
if (tx_imp)
tx_imp.reset();
tx_imp = std::unique_ptr<GncTxImport>(new GncTxImport);
/* Disable the Forward Assistant Button */
gtk_assistant_set_page_complete (csv_imp_asst, preview_page, false);
/* Assume data is CSV. User can later override to Fixed Width if needed */
try
{
tx_imp->file_format (GncImpFileFormat::CSV);
tx_imp->load_file (m_file_name);
tx_imp->tokenize (true);
}
catch (std::ifstream::failure& e)
{
/* File loading failed ... */
gnc_error_dialog (GTK_WINDOW (csv_imp_asst), "%s", e.what());
go_back = true;
}
catch (std::range_error &e)
{
/* Parsing failed ... */
gnc_error_dialog (GTK_WINDOW (csv_imp_asst), "%s", _(e.what()));
go_back = true;
}
/* Load the data into the treeview. */
preview_refresh_table ();
if (go_back)
gtk_assistant_previous_page (csv_imp_asst);
else
{
preview_refresh ();
/* Get settings store and populate */
preview_populate_settings_combo();
gtk_combo_box_set_active (settings_combo, 0);
tx_imp->req_mapped_accts (false);
/* Disable the Forward Assistant Button */
gtk_assistant_set_page_complete (csv_imp_asst, preview_page, false);
/* Load the data into the treeview. */
g_idle_add ((GSourceFunc)csv_imp_preview_queue_rebuild_table, this);
}
}
void
@ -1915,7 +1916,7 @@ CsvImpTransAssist::assist_account_match_page_prepare ()
gtk_widget_set_sensitive (account_match_btn, true);
/* Enable the Forward Assistant Button */
gtk_assistant_set_page_complete (csv_imp_asst, account_match_page,
gtk_assistant_set_page_complete (csv_imp_asst, account_match_page,
csv_tximp_acct_match_check_all (store));
}

View File

@ -78,7 +78,8 @@ fill_model_with_match(GMatchInfo *match_info,
* Parse the file for a correctly formatted file
*******************************************************/
csv_import_result
csv_import_read_file (const gchar *filename, const gchar *parser_regexp,
csv_import_read_file (GtkWindow *win, const gchar *filename,
const gchar *parser_regexp,
GtkListStore *store, guint max_rows)
{
gchar *locale_cont, *contents;

View File

@ -42,7 +42,9 @@ enum _csv_import_result
typedef enum _csv_import_result csv_import_result;
csv_import_result
csv_import_read_file (const gchar *filename, const gchar *parser_regexp, GtkListStore *store, guint max_rows );
csv_import_read_file (GtkWindow *win, const gchar *filename,
const gchar *parser_regexp,
GtkListStore *store, guint max_rows );
void csv_account_import (CsvImportInfo *info);