diff --git a/gnucash/import-export/csv-exp/assistant-csv-export.c b/gnucash/import-export/csv-exp/assistant-csv-export.c index fdb2c8186b..8a8d3aa4b7 100644 --- a/gnucash/import-export/csv-exp/assistant-csv-export.c +++ b/gnucash/import-export/csv-exp/assistant-csv-export.c @@ -475,7 +475,7 @@ get_filter_times (CsvExportInfo *info) if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(info->csvd.start_date_today))) info->csvd.start_time = gnc_time64_get_today_start(); else - info->csvd.start_time = 0; + info->csvd.start_time = info->csvd.earliest_time; } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(info->csvd.end_date_choose))) @@ -489,7 +489,7 @@ get_filter_times (CsvExportInfo *info) if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(info->csvd.end_date_today))) info->csvd.end_time = gnc_time64_get_today_end(); else - info->csvd.end_time = gnc_time (NULL); + info->csvd.end_time = info->csvd.latest_time; } } @@ -508,6 +508,15 @@ csv_export_show_range_cb (GtkRadioButton *button, gpointer user_data) g_return_if_fail (GTK_IS_RADIO_BUTTON(button)); active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(button)); + + if (!active) + { + info->csvd.start_time = info->csvd.earliest_time; + info->csvd.end_time = info->csvd.latest_time; + } + else + get_filter_times (info); + gtk_widget_set_sensitive (info->csvd.table, active); } @@ -581,22 +590,19 @@ csv_export_end_date_cb (GtkWidget *radio, gpointer user_data) /******************************************************************* - * get_earliest_in_book + * get_earliest_and_latest_in_book * - * Find the earliest date occurring in the book. Do this by making - * a query and sorting by date. Since the truncated sort returns - * only the *last* search results, sort in decreasing order. + * Find the earliest and latest dates occurring in the book. *******************************************************************/ -static time64 -get_earliest_in_book (QofBook *book) +static void +get_earliest_and_latest_in_book (CsvExportInfo *info, QofBook *book) { QofQuery *q; GSList *p1, *p2; GList *res; - time64 earliest; + time64 etime, ltime; q = qof_query_create_for (GNC_ID_SPLIT); - qof_query_set_max_results (q, 1); qof_query_set_book (q, book); /* Sort by transaction date */ @@ -605,24 +611,24 @@ get_earliest_in_book (QofBook *book) p2 = g_slist_prepend (NULL, QUERY_DEFAULT_SORT); qof_query_set_sort_order (q, p1, p2, NULL); - /* Reverse the sort order */ - qof_query_set_sort_increasing (q, FALSE, FALSE, FALSE); - - /* Run the query, find the earliest transaction date */ + /* Run the query, find the earliest and latest transaction dates */ res = qof_query_run (q); if (res) { - earliest = xaccQueryGetEarliestDateFound (q); + etime = xaccQueryGetEarliestDateFound (q); + ltime = xaccQueryGetLatestDateFound (q); } else { /* If no results, we don't want to bomb totally */ - earliest = gnc_time (0); + etime = gnc_time (0); + ltime = gnc_time (NULL); } + info->csvd.earliest_time = gnc_time64_get_day_start (etime); + info->csvd.latest_time = gnc_time64_get_day_end (ltime); qof_query_destroy (q); - return earliest; } @@ -824,7 +830,6 @@ csv_export_assistant_create (CsvExportInfo *info) GtkWidget *h_box; GtkWidget *button; GtkWidget *table, *hbox; - time64 start_time, end_time; builder = gtk_builder_new(); gnc_builder_add_from_file (builder , "assistant-csv-export.glade", "csv_export_assistant"); @@ -890,12 +895,11 @@ csv_export_assistant_create (CsvExportInfo *info) /* Set the date info */ button = GTK_WIDGET(gtk_builder_get_object (builder, "show_range")); - /* Earliest and Latest in Book */ - start_time = get_earliest_in_book (gnc_get_current_book()); - end_time = gnc_time (NULL); + /* Get the Earliest and Latest dates in Book */ + get_earliest_and_latest_in_book (info, gnc_get_current_book()); - info->csvd.start_time = start_time; - info->csvd.end_time = end_time; + info->csvd.start_time = info->csvd.earliest_time; + info->csvd.end_time = info->csvd.latest_time; gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(button), FALSE); table = GTK_WIDGET(gtk_builder_get_object (builder, "select_range_table")); @@ -912,7 +916,7 @@ csv_export_assistant_create (CsvExportInfo *info) hbox = GTK_WIDGET(gtk_builder_get_object (builder, "start_date_hbox")); gtk_box_pack_start (GTK_BOX(hbox), info->csvd.start_date, TRUE, TRUE, 0); gtk_widget_show (info->csvd.start_date); - gnc_date_edit_set_time (GNC_DATE_EDIT(info->csvd.start_date), start_time); + gnc_date_edit_set_time (GNC_DATE_EDIT(info->csvd.start_date), info->csvd.start_time); g_signal_connect (G_OBJECT(info->csvd.start_date), "date-changed", G_CALLBACK(csv_export_date_changed_cb), info); @@ -921,7 +925,7 @@ csv_export_assistant_create (CsvExportInfo *info) hbox = GTK_WIDGET(gtk_builder_get_object (builder, "end_date_hbox")); gtk_box_pack_start (GTK_BOX(hbox), info->csvd.end_date, TRUE, TRUE, 0); gtk_widget_show (info->csvd.end_date); - gnc_date_edit_set_time (GNC_DATE_EDIT(info->csvd.end_date), end_time); + gnc_date_edit_set_time (GNC_DATE_EDIT(info->csvd.end_date), info->csvd.end_time); g_signal_connect (G_OBJECT (info->csvd.end_date), "date-changed", G_CALLBACK (csv_export_date_changed_cb), info); diff --git a/gnucash/import-export/csv-exp/assistant-csv-export.h b/gnucash/import-export/csv-exp/assistant-csv-export.h index 78ea0ff5c4..b0cf99cbe7 100644 --- a/gnucash/import-export/csv-exp/assistant-csv-export.h +++ b/gnucash/import-export/csv-exp/assistant-csv-export.h @@ -50,6 +50,8 @@ typedef struct time64 start_time; time64 end_time; + time64 earliest_time; + time64 latest_time; } CsvExportDate; typedef struct