Skip to content

Commit

Permalink
Implement multiple-ofx import with reconcile
Browse files Browse the repository at this point in the history
I had to rebase against master which included the reconcile after import and there were a few conflicts.
So this is the new version. It includes all the recommendations made in the original PR but the code now includes the reconcile part.
  • Loading branch information
jean committed May 15, 2020
1 parent 8283263 commit 55d7385
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 137 deletions.
112 changes: 82 additions & 30 deletions gnucash/gnome-utils/gnc-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,15 @@ static QofLogModule log_module = GNC_MOD_GUI;
static GNCShutdownCB shutdown_cb = NULL;
static gint save_in_progress = 0;


/********************************************************************\
* gnc_file_dialog *
* Pops up a file selection dialog (either a "Save As" or an *
* "Open"), and returns the name of the file the user selected. *
* (This function does not return until the user selects a file *
* or presses "Cancel" or the window manager destroy button) *
* *
* Args: title - the title of the window *
* filters - list of GtkFileFilters to use, will be *
freed automatically *
* default_dir - start the chooser in this directory *
* type - what type of dialog (open, save, etc.) *
* Return: containing the name of the file the user selected *
\********************************************************************/

char *
gnc_file_dialog (GtkWindow *parent,
const char * title,
GList * filters,
const char * starting_dir,
GNCFileDialogType type
)
// gnc_file_dialog_int is used both by gnc_file_dialog and gnc_file_dialog_multi
static GSList *
gnc_file_dialog_int (GtkWindow *parent,
const char * title,
GList * filters,
const char * starting_dir,
GNCFileDialogType type,
gboolean multi
)
{
GtkWidget *file_box;
const char *internal_name;
Expand All @@ -91,6 +77,7 @@ gnc_file_dialog (GtkWindow *parent,
const gchar *ok_icon = NULL;
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
gint response;
GSList* file_name_list = NULL;

ENTER(" ");

Expand Down Expand Up @@ -130,6 +117,9 @@ gnc_file_dialog (GtkWindow *parent,
action,
_("_Cancel"), GTK_RESPONSE_CANCEL,
NULL);
if (multi)
gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (file_box), TRUE);

if (ok_icon)
gnc_gtk_dialog_add_button(file_box, okbutton, ok_icon, GTK_RESPONSE_ACCEPT);
else
Expand Down Expand Up @@ -174,23 +164,85 @@ gnc_file_dialog (GtkWindow *parent,

if (response == GTK_RESPONSE_ACCEPT)
{
/* look for constructs like postgres://foo */
internal_name = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER (file_box));
if (internal_name != NULL)
if (multi)
{
if (strstr (internal_name, "file://") == internal_name)
file_name_list = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER (file_box));
}
else
{
/* look for constructs like postgres://foo */
internal_name = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER (file_box));
if (internal_name != NULL)
{
/* nope, a local file name */
internal_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (file_box));
if (strstr (internal_name, "file://") == internal_name)
{
/* nope, a local file name */
internal_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (file_box));
}
file_name = g_strdup(internal_name);
}
file_name = g_strdup(internal_name);
file_name_list = g_slist_append (file_name_list, file_name);
}
}
gtk_widget_destroy(GTK_WIDGET(file_box));
LEAVE("%s", file_name ? file_name : "(null)");
return file_name_list;
}

/********************************************************************\
* gnc_file_dialog *
* Pops up a file selection dialog (either a "Save As" or an *
* "Open"), and returns the name of the file the user selected. *
* (This function does not return until the user selects a file *
* or presses "Cancel" or the window manager destroy button) *
* *
* Args: title - the title of the window *
* filters - list of GtkFileFilters to use, will be *
* freed automatically *
* default_dir - start the chooser in this directory *
* type - what type of dialog (open, save, etc.) *
* Return: containing the name of the file the user selected *
\********************************************************************/
char *
gnc_file_dialog (GtkWindow *parent,
const char * title,
GList * filters,
const char * starting_dir,
GNCFileDialogType type
)
{
gchar* file_name = NULL;
GSList* ret = gnc_file_dialog_int (parent, title, filters, starting_dir, type, FALSE);
if (ret)
file_name = g_strdup (ret->data);
g_slist_free_full (ret, g_free);
return file_name;
}

/********************************************************************\
* gnc_file_dialog_multi *
* Pops up a file selection dialog (either a "Save As" or an *
* "Open"), and returns the name of the files the user selected. *
* Similar to gnc_file_dialog with allowing multi-file selection *
* *
* Args: title - the title of the window *
* filters - list of GtkFileFilters to use, will be *
* freed automatically *
* default_dir - start the chooser in this directory *
* type - what type of dialog (open, save, etc.) *
* Return: GList containing the names of the selected files *
\********************************************************************/

GSList *
gnc_file_dialog_multi (GtkWindow *parent,
const char * title,
GList * filters,
const char * starting_dir,
GNCFileDialogType type
)
{
return gnc_file_dialog_int (parent, title, filters, starting_dir, type, TRUE);
}

gboolean
show_session_error (GtkWindow *parent,
Expand Down
6 changes: 6 additions & 0 deletions gnucash/gnome-utils/gnc-file.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ char * gnc_file_dialog (GtkWindow *parent,
const char * starting_dir,
GNCFileDialogType type);

GSList * gnc_file_dialog_multi (GtkWindow *parent,
const char * title,
GList * filters,
const char * starting_dir,
GNCFileDialogType type);

gboolean gnc_file_open_file (GtkWindow *parent,
const char *filename,
gboolean open_readonly);
Expand Down
10 changes: 9 additions & 1 deletion gnucash/gnome/window-reconcile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1800,7 +1800,6 @@ recnWindowWithBalance (GtkWidget *parent, Account *account, gnc_numeric new_endi
gnc_register_gui_component (WINDOW_RECONCILE_CM_CLASS,
refresh_handler, close_handler,
recnData);
// This window should close if we close the session.
gnc_gui_component_set_session (recnData->component_id, gnc_get_current_session());

recn_set_watches (recnData);
Expand Down Expand Up @@ -2118,6 +2117,15 @@ gnc_ui_reconcile_window_raise(RecnWindow * recnData)
gtk_window_present(GTK_WINDOW(recnData->window));
}

GtkWidget*
gnc_ui_reconcile_window_get_widget(RecnWindow * recnData)
{
if (recnData == NULL || recnData->window == NULL)
return NULL;
return recnData->window;
}



/********************************************************************\
* recn_destroy_cb *
Expand Down
2 changes: 1 addition & 1 deletion gnucash/gnome/window-reconcile.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ RecnWindow *recnWindowWithBalance (GtkWidget *parent, Account *account,
time64 statement_date);

void gnc_ui_reconcile_window_raise(RecnWindow * recnData);

GtkWidget* gnc_ui_reconcile_window_get_widget(RecnWindow * recnData);
#endif /* WINDOW_RECONCILE_H */
15 changes: 15 additions & 0 deletions gnucash/gtkbuilder/dialog-import.glade
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,21 @@
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="reconcile_after_close_button">
<property name="label" translatable="yes">Reconcile after match</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
Expand Down
22 changes: 21 additions & 1 deletion gnucash/import-export/import-main-matcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ struct _main_matcher_info
GtkTreeViewColumn *account_column;
GtkWidget *show_account_column;
GtkWidget *show_matched_info;
GtkWidget *reconcile_after_close;
gboolean add_toggled; // flag to indicate that add has been toggled to stop selection
gint id;
};
Expand Down Expand Up @@ -196,6 +197,8 @@ gboolean gnc_gen_trans_list_empty(GNCImportMainMatcher *info)
void gnc_gen_trans_list_show_all(GNCImportMainMatcher *info)
{
gtk_widget_show_all (GTK_WIDGET (info->main_widget));
// By default, do not show this check box.
gnc_gen_trans_list_show_reconcile_after_close (info, FALSE, FALSE);
}

void
Expand Down Expand Up @@ -985,6 +988,9 @@ GNCImportMainMatcher *gnc_gen_trans_list_new (GtkWidget *parent,
g_signal_connect (G_OBJECT(info->show_matched_info), "toggled",
G_CALLBACK(show_matched_info_toggled_cb), info);

// Create the checkbox, but do not show it by default.
info->reconcile_after_close = GTK_WIDGET(gtk_builder_get_object (builder, "reconcile_after_close_button"));

show_update = gnc_import_Settings_get_action_update_enabled (info->user_settings);
gnc_gen_trans_init_view (info, all_from_same_account, show_update);
heading_label = GTK_WIDGET(gtk_builder_get_object (builder, "heading_label"));
Expand All @@ -1006,7 +1012,7 @@ GNCImportMainMatcher *gnc_gen_trans_list_new (GtkWidget *parent,
gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, info);

g_object_unref (G_OBJECT(builder));

// Register this UI, it needs to be closed when the session is closed.
info->id = gnc_register_gui_component (IMPORT_MAIN_MATCHER_CM_CLASS,
NULL, /* no refresh handler */
Expand Down Expand Up @@ -1069,6 +1075,8 @@ GNCImportMainMatcher * gnc_gen_trans_assist_new (GtkWidget *parent,
g_signal_connect (G_OBJECT(info->show_matched_info), "toggled",
G_CALLBACK(show_matched_info_toggled_cb), info);

info->reconcile_after_close = GTK_WIDGET(gtk_builder_get_object (builder, "reconcile_when_close_button"));

show_update = gnc_import_Settings_get_action_update_enabled (info->user_settings);
gnc_gen_trans_init_view (info, all_from_same_account, show_update);
heading_label = GTK_WIDGET(gtk_builder_get_object (builder, "heading_label"));
Expand Down Expand Up @@ -1448,6 +1456,18 @@ void gnc_gen_trans_list_add_trans (GNCImportMainMatcher *gui, Transaction *trans
return;
}/* end gnc_import_add_trans() */

void gnc_gen_trans_list_show_reconcile_after_close(GNCImportMainMatcher *info, gboolean reconcile_after_close, gboolean active)
{
gtk_widget_set_visible (info->reconcile_after_close,reconcile_after_close);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (info->reconcile_after_close), active);
}

GtkWidget*
gnc_gen_trans_list_get_reconcile_widget(GNCImportMainMatcher *info)
{
return info->reconcile_after_close;
}

void gnc_gen_trans_list_add_trans_with_ref_id (GNCImportMainMatcher *gui, Transaction *trans, guint32 ref_id)
{
GNCImportTransInfo * transaction_info = NULL;
Expand Down
3 changes: 3 additions & 0 deletions gnucash/import-export/import-main-matcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,8 @@ gboolean gnc_gen_trans_list_empty(GNCImportMainMatcher *info);
*/
void gnc_gen_trans_list_show_all(GNCImportMainMatcher *info);

void gnc_gen_trans_list_show_reconcile_after_close(GNCImportMainMatcher *info, gboolean reconcile_after_close, gboolean active);
GtkWidget* gnc_gen_trans_list_get_reconcile_widget(GNCImportMainMatcher *info);

#endif
/**@}*/
Loading

0 comments on commit 55d7385

Please sign in to comment.