GnuCash c935c2f+
Loading...
Searching...
No Matches
Macros | Functions
assistant-csv-export.c File Reference

CSV Export Assistant. More...

#include <config.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include "gnc-ui.h"
#include "gnc-uri-utils.h"
#include "gnc-component-manager.h"
#include "gnc-date-edit.h"
#include "gnc-prefs.h"
#include "gnc-tree-view-account.h"
#include "dialog-utils.h"
#include "Query.h"
#include "Transaction.h"
#include "assistant-csv-export.h"
#include "csv-tree-export.h"
#include "csv-transactions-export.h"

Go to the source code of this file.

Macros

#define GNC_PREFS_GROUP   "dialogs.export.csv"
 
#define GNC_PREF_PANED_POS   "paned-position"
 
#define ASSISTANT_CSV_EXPORT_CM_CLASS   "assistant-csv-export"
 

Functions

void csv_export_assistant_prepare (GtkAssistant *assistant, GtkWidget *page, gpointer user_data)
 
void csv_export_assistant_finish (GtkAssistant *gtkassistant, gpointer user_data)
 
void csv_export_assistant_cancel (GtkAssistant *gtkassistant, gpointer user_data)
 
void csv_export_assistant_close (GtkAssistant *gtkassistant, gpointer user_data)
 
void csv_export_assistant_start_page_prepare (GtkAssistant *assistant, gpointer user_data)
 
void csv_export_assistant_account_page_prepare (GtkAssistant *gtkassistant, gpointer user_data)
 
void csv_export_assistant_file_page_prepare (GtkAssistant *assistant, gpointer user_data)
 
void csv_export_assistant_finish_page_prepare (GtkAssistant *assistant, gpointer user_data)
 
void csv_export_assistant_summary_page_prepare (GtkAssistant *assistant, gpointer user_data)
 
void csv_export_quote_cb (GtkToggleButton *button, gpointer user_data)
 
void csv_export_simple_cb (GtkToggleButton *button, gpointer user_data)
 
void csv_export_sep_cb (GtkWidget *radio, gpointer user_data)
 
void csv_export_custom_entry_cb (GtkWidget *widget, gpointer user_data)
 
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_file_activated_cb (GtkFileChooser *chooser, CsvExportInfo *info)
 
void csv_export_file_chooser_selection_changed_cb (GtkFileChooser *chooser, CsvExportInfo *info)
 
void gnc_file_csv_export (CsvExportType export_type)
 The gnc_file_csv_export() will let the user export the account tree or transactions to a delimited file.
 
void gnc_file_csv_export_register (CsvExportType export_type, Query *q, Account *acc)
 The gnc_file_csv_export_register() will let the user export the active register transactions to a delimited file.
 

Detailed Description

CSV Export Assistant.

Author
Copyright (c) 2012 Robert Fewell

Definition in file assistant-csv-export.c.

Macro Definition Documentation

◆ ASSISTANT_CSV_EXPORT_CM_CLASS

#define ASSISTANT_CSV_EXPORT_CM_CLASS   "assistant-csv-export"

Definition at line 49 of file assistant-csv-export.c.

◆ GNC_PREF_PANED_POS

#define GNC_PREF_PANED_POS   "paned-position"

Definition at line 48 of file assistant-csv-export.c.

◆ GNC_PREFS_GROUP

#define GNC_PREFS_GROUP   "dialogs.export.csv"

Definition at line 47 of file assistant-csv-export.c.

Function Documentation

◆ csv_export_assistant_account_page_prepare()

void csv_export_assistant_account_page_prepare ( GtkAssistant *  gtkassistant,
gpointer  user_data 
)

Definition at line 683 of file assistant-csv-export.c.

685{
686 CsvExportInfo *info = user_data;
687
688 /* Enable the "Next" Assistant Button if we have accounts */
689 if (g_list_length(info->csva.account_list) > 0)
690 gtk_assistant_set_page_complete (assistant, info->account_page, TRUE);
691 else
692 gtk_assistant_set_page_complete (assistant, info->account_page, FALSE);
693}

◆ csv_export_assistant_cancel()

void csv_export_assistant_cancel ( GtkAssistant *  gtkassistant,
gpointer  user_data 
)

Definition at line 807 of file assistant-csv-export.c.

808{
809 CsvExportInfo *info = user_data;
810 gnc_close_gui_component_by_data (ASSISTANT_CSV_EXPORT_CM_CLASS, info);
811}

◆ csv_export_assistant_close()

void csv_export_assistant_close ( GtkAssistant *  gtkassistant,
gpointer  user_data 
)

Definition at line 814 of file assistant-csv-export.c.

815{
816 CsvExportInfo *info = user_data;
817 gnc_close_gui_component_by_data (ASSISTANT_CSV_EXPORT_CM_CLASS, info);
818}

◆ csv_export_assistant_file_page_prepare()

void csv_export_assistant_file_page_prepare ( GtkAssistant *  assistant,
gpointer  user_data 
)

Definition at line 697 of file assistant-csv-export.c.

699{
700 CsvExportInfo *info = user_data;
701
702 /* Set the default directory */
703 if (info->starting_dir)
704 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(info->file_chooser), info->starting_dir);
705 gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER(info->file_chooser), "");
706
707 /* Disable the "Next" Assistant Button */
708 gtk_assistant_set_page_complete (assistant, info->file_page, FALSE);
709}

◆ csv_export_assistant_finish()

void csv_export_assistant_finish ( GtkAssistant *  gtkassistant,
gpointer  user_data 
)

Definition at line 821 of file assistant-csv-export.c.

822{
823 CsvExportInfo *info = user_data;
824
825 if (info->export_type == XML_EXPORT_TREE)
826 csv_tree_export (info);
827 else
828 csv_transactions_export (info);
829}

◆ csv_export_assistant_finish_page_prepare()

void csv_export_assistant_finish_page_prepare ( GtkAssistant *  assistant,
gpointer  user_data 
)

Definition at line 713 of file assistant-csv-export.c.

715{
716 CsvExportInfo *info = user_data;
717 gchar *text;
718
719 /* Set Finish page text */
720 if (info->export_type == XML_EXPORT_TREE)
721 text = g_strdup_printf (gettext (finish_tree_string), info->file_name);
722 else
723 {
724 if ((info->export_type == XML_EXPORT_REGISTER) &&
725 (g_list_length (info->csva.account_list) == 0))
726 text = g_strdup_printf (gettext (finish_trans_search_gl_string), info->file_name);
727 else
728 text = g_strdup_printf (gettext (finish_trans_string),
729 info->file_name,
730 g_list_length (info->csva.account_list));
731 }
732 gtk_label_set_text (GTK_LABEL(info->finish_label), text);
733 g_free (text);
734
735 /* Test if the filename exists */
736 if (g_file_test (info->file_name, G_FILE_TEST_EXISTS))
737 {
738 const char *format = _("The file %s already exists. "
739 "Are you sure you want to overwrite it?");
740
741 /* if user says cancel, we should go back a page */
742 if (!gnc_verify_dialog (GTK_WINDOW (assistant), FALSE, format, info->file_name))
743 gtk_assistant_previous_page (assistant);
744 }
745 /* Enable the Assistant Buttons */
746 gtk_assistant_set_page_complete (assistant, info->finish_label, TRUE);
747}

◆ csv_export_assistant_prepare()

void csv_export_assistant_prepare ( GtkAssistant *  assistant,
GtkWidget *  page,
gpointer  user_data 
)

Definition at line 774 of file assistant-csv-export.c.

776{
777 CsvExportInfo *info = user_data;
778
779 if (page == info->start_page)
780 csv_export_assistant_start_page_prepare (assistant, user_data);
781 else if (page == info->account_page)
782 csv_export_assistant_account_page_prepare (assistant, user_data);
783 else if (page == info->file_page)
784 csv_export_assistant_file_page_prepare (assistant, user_data);
785 else if (page == info->finish_label)
786 csv_export_assistant_finish_page_prepare (assistant, user_data);
787 else if (page == info->summary_label)
788 csv_export_assistant_summary_page_prepare (assistant, user_data);
789 else
790 g_assert_not_reached();
791}

◆ csv_export_assistant_start_page_prepare()

void csv_export_assistant_start_page_prepare ( GtkAssistant *  assistant,
gpointer  user_data 
)

Definition at line 663 of file assistant-csv-export.c.

665{
666 CsvExportInfo *info = user_data;
667 gchar *msg = NULL;
668
669 if (info->export_type == XML_EXPORT_TREE)
670 msg = g_strdup (_(start_tree_string));
671 else
672 msg = g_strdup_printf (_(start_trans_common_string), _(start_trans_multi_string));
673
674 gtk_label_set_text (GTK_LABEL(info->start_label), msg);
675 g_free (msg);
676
677 /* Enable the Assistant Buttons */
678 gtk_assistant_set_page_complete (assistant, info->start_page, TRUE);
679}

◆ csv_export_assistant_summary_page_prepare()

void csv_export_assistant_summary_page_prepare ( GtkAssistant *  assistant,
gpointer  user_data 
)

Definition at line 751 of file assistant-csv-export.c.

753{
754 CsvExportInfo *info = user_data;
755 gchar *text, *mtext;
756 gnc_set_default_directory (GNC_PREFS_GROUP, info->starting_dir);
757
758 if (info->failed)
759 text = _("There was a problem with the export, this could be due to lack of space, "
760 "permissions or unable to access folder. Check the trace file for further logging!\n"
761 "You may need to enable debugging.\n");
762 else
763 text = _("File exported successfully!\n");
764
765 mtext = g_strdup_printf ("<span size=\"medium\"><b>%s</b></span>", text);
766
767 gtk_label_set_markup (GTK_LABEL(info->summary_label), mtext);
768
769 g_free (mtext);
770}

◆ csv_export_custom_entry_cb()

void csv_export_custom_entry_cb ( GtkWidget *  widget,
gpointer  user_data 
)

Definition at line 283 of file assistant-csv-export.c.

284{
285 CsvExportInfo *info = user_data;
286 GtkAssistant *assistant = GTK_ASSISTANT(info->assistant);
287 const gchar *custom_str;
288
289 custom_str = gtk_entry_get_text (GTK_ENTRY(info->custom_entry));
290 info->separator_str = strdup (custom_str);
291
292 if (info->use_custom == TRUE && gtk_entry_get_text_length (GTK_ENTRY(info->custom_entry)) == 0)
293 gtk_assistant_set_page_complete (assistant, info->start_page, FALSE);
294 else
295 gtk_assistant_set_page_complete (assistant, info->start_page, TRUE);
296}

◆ csv_export_end_date_cb()

void csv_export_end_date_cb ( GtkWidget *  radio,
gpointer  user_data 
)

Definition at line 592 of file assistant-csv-export.c.

593{
594 CsvExportInfo *info = user_data;
595 const gchar *name;
596 gboolean active;
597
598 g_return_if_fail (GTK_IS_RADIO_BUTTON(radio));
599
600 if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(radio)))
601 {
602 LEAVE("1st callback of pair. Defer to 2nd callback.");
603 return;
604 }
605
606 name = gtk_buildable_get_name (GTK_BUILDABLE(radio));
607 active = (g_strcmp0 (name, "end_date_choose") == 0 ? 1 : 0 );
608 gtk_widget_set_sensitive (info->csvd.end_date, active);
609 get_filter_times (info);
610}
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition qoflog.h:282

◆ csv_export_file_chooser_file_activated_cb()

void csv_export_file_chooser_file_activated_cb ( GtkFileChooser *  chooser,
CsvExportInfo info 
)

Definition at line 166 of file assistant-csv-export.c.

168{
169 GtkAssistant *assistant = GTK_ASSISTANT(info->assistant);
170 gtk_assistant_set_page_complete (assistant, info->file_page, FALSE);
171
172 /* Test for a valid filename and not a directory */
173 if (csv_export_assistant_check_filename (chooser, info))
174 {
175 gtk_assistant_set_page_complete (assistant, info->file_page, TRUE);
176 gtk_assistant_next_page (assistant);
177 }
178}

◆ csv_export_file_chooser_selection_changed_cb()

void csv_export_file_chooser_selection_changed_cb ( GtkFileChooser *  chooser,
CsvExportInfo info 
)

Definition at line 187 of file assistant-csv-export.c.

189{
190 GtkAssistant *assistant = GTK_ASSISTANT(info->assistant);
191
192 /* Enable the "Next" button based on a valid filename */
193 gtk_assistant_set_page_complete (assistant, info->file_page,
194 csv_export_assistant_check_filename (chooser, info));
195}

◆ csv_export_quote_cb()

void csv_export_quote_cb ( GtkToggleButton *  button,
gpointer  user_data 
)

Definition at line 245 of file assistant-csv-export.c.

246{
247 CsvExportInfo *info = user_data;
248
249 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(button)))
250 info->use_quotes = TRUE;
251 else
252 info->use_quotes = FALSE;
253}

◆ csv_export_sep_cb()

void csv_export_sep_cb ( GtkWidget *  radio,
gpointer  user_data 
)

Definition at line 204 of file assistant-csv-export.c.

205{
206 CsvExportInfo *info = user_data;
207 GtkAssistant *assistant = GTK_ASSISTANT(info->assistant);
208 const gchar *name;
209
210 if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(radio)))
211 {
212 LEAVE("1st callback of pair. Defer to 2nd callback.");
213 return;
214 }
215
216 name = gtk_buildable_get_name (GTK_BUILDABLE(radio));
217
218 gtk_widget_set_sensitive (info->custom_entry, FALSE);
219 info->use_custom = FALSE;
220 gtk_assistant_set_page_complete (assistant, info->start_page, TRUE);
221
222 if (g_strcmp0 (name, "comma_radio") == 0)
223 info->separator_str = ",";
224 if (g_strcmp0 (name, "colon_radio") == 0)
225 info->separator_str = ":";
226 if (g_strcmp0 (name, "semicolon_radio") == 0)
227 info->separator_str = ";";
228
229 if (g_strcmp0 (name, "custom_radio") == 0)
230 {
231 gtk_widget_set_sensitive (info->custom_entry, TRUE);
232 info->use_custom = TRUE;
233 if (gtk_entry_get_text_length (GTK_ENTRY(info->custom_entry)) == 0)
234 gtk_assistant_set_page_complete (assistant, info->start_page, FALSE);
235 }
236}

◆ csv_export_show_range_cb()

void csv_export_show_range_cb ( GtkRadioButton *  button,
gpointer  user_data 
)

Definition at line 524 of file assistant-csv-export.c.

525{
526 CsvExportInfo *info = user_data;
527 gboolean active;
528
529 g_return_if_fail (GTK_IS_RADIO_BUTTON(button));
530
531 active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(button));
532
533 if (!active)
534 {
535 info->csvd.start_time = info->csvd.earliest_time;
536 info->csvd.end_time = info->csvd.latest_time;
537 }
538 else
539 get_filter_times (info);
540
541 gtk_widget_set_sensitive (info->csvd.table, active);
542}

◆ csv_export_simple_cb()

void csv_export_simple_cb ( GtkToggleButton *  button,
gpointer  user_data 
)

Definition at line 261 of file assistant-csv-export.c.

262{
263 CsvExportInfo *info = user_data;
264
265 info->simple_layout = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(button));
266
267 gchar *msg = NULL;
268 if (info->simple_layout)
269 msg = g_strdup_printf (_(start_trans_common_string), _(start_trans_simple_string));
270 else
271 msg = g_strdup_printf (_(start_trans_common_string), _(start_trans_multi_string));
272
273 gtk_label_set_text (GTK_LABEL(info->start_label), msg);
274 g_free (msg);
275}

◆ csv_export_start_date_cb()

void csv_export_start_date_cb ( GtkWidget *  radio,
gpointer  user_data 
)

Definition at line 565 of file assistant-csv-export.c.

566{
567 CsvExportInfo *info = user_data;
568 const gchar *name;
569 gboolean active;
570
571 g_return_if_fail (GTK_IS_RADIO_BUTTON(radio));
572
573 if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(radio)))
574 {
575 LEAVE("1st callback of pair. Defer to 2nd callback.");
576 return;
577 }
578
579 name = gtk_buildable_get_name (GTK_BUILDABLE(radio));
580 active = (g_strcmp0 (name, "start_date_choose") == 0 ? 1 : 0 );
581 gtk_widget_set_sensitive (info->csvd.start_date, active);
582 get_filter_times (info);
583}

◆ gnc_file_csv_export()

void gnc_file_csv_export ( CsvExportType  export_type)

The gnc_file_csv_export() will let the user export the account tree or transactions to a delimited file.

Definition at line 1032 of file assistant-csv-export.c.

1033{
1034 gnc_file_csv_export_internal (export_type, NULL, NULL);
1035}

◆ gnc_file_csv_export_register()

void gnc_file_csv_export_register ( CsvExportType  export_type,
Query q,
Account acc 
)

The gnc_file_csv_export_register() will let the user export the active register transactions to a delimited file.

Definition at line 1047 of file assistant-csv-export.c.

1048{
1049 gnc_file_csv_export_internal (export_type, q, acc);
1050}