[Gnucash-changes] r13198 - gnucash/trunk/src - Move the accounting
period preference functions from window-main-summarybar
Chris Shoemaker
chris at cvs.gnucash.org
Sat Feb 11 00:00:03 EST 2006
Author: chris
Date: 2006-02-11 00:00:02 -0500 (Sat, 11 Feb 2006)
New Revision: 13198
Trac: http://svn.gnucash.org/trac/changeset/13198
Modified:
gnucash/trunk/src/app-utils/gnc-accounting-period.c
gnucash/trunk/src/app-utils/gnc-accounting-period.h
gnucash/trunk/src/gnome-utils/gnc-tree-view-account.c
gnucash/trunk/src/gnome-utils/window-main-summarybar.c
gnucash/trunk/src/gnome-utils/window-main-summarybar.h
Log:
Move the accounting period preference functions from window-main-summarybar
to gnc-accounting-period.
Modified: gnucash/trunk/src/app-utils/gnc-accounting-period.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-accounting-period.c 2006-02-11 03:54:24 UTC (rev 13197)
+++ gnucash/trunk/src/app-utils/gnc-accounting-period.c 2006-02-11 05:00:02 UTC (rev 13198)
@@ -42,9 +42,114 @@
*/
#include "config.h"
+#include <string.h>
#include "gnc-accounting-period.h"
#include "gnc-gdate-utils.h"
+#include "gnc-date.h"
+#include "gnc-gconf-utils.h"
+#include "qof.h"
+#include "gnc-ui-util.h"
+/* TODO: This should probably be changed eventually. */
+#define GCONF_SECTION "window/pages/account_tree/summary"
+#define KEY_START_CHOICE "start_choice"
+#define KEY_START_DATE "start_date"
+#define KEY_START_PERIOD "start_period"
+#define KEY_END_CHOICE "end_choice"
+#define KEY_END_DATE "end_date"
+#define KEY_END_PERIOD "end_period"
+
+static time_t
+lookup_start_date_option(const gchar *section,
+ const gchar *key_choice,
+ const gchar *key_absolute,
+ const gchar *key_relative,
+ GDate *fy_end)
+{
+ const gchar *choice;
+ time_t time;
+ int which;
+
+ choice = gnc_gconf_get_string(section, key_choice, NULL);
+ if (choice && strcmp(choice, "absolute") == 0) {
+ time = gnc_gconf_get_int(section, key_absolute, NULL);
+ } else {
+ which = gnc_gconf_get_int(section, key_relative, NULL);
+ time = gnc_accounting_period_start_timet(which, fy_end, NULL);
+ }
+ /* we will need the balance of the last transaction before the start
+ date, so subtract 1 from start date */
+ /* CAS: we don't actually do what this comment says. I think that's
+ because a bug in the engine has been fixed. */
+ return time;
+}
+
+
+static time_t
+lookup_end_date_option(const gchar *section,
+ const gchar *key_choice,
+ const gchar *key_absolute,
+ const gchar *key_relative,
+ GDate *fy_end)
+{
+ const gchar *choice;
+ time_t time;
+ int which;
+
+ choice = gnc_gconf_get_string(section, key_choice, NULL);
+ if (choice && strcmp(choice, "absolute") == 0) {
+ time = gnc_gconf_get_int(section, key_absolute, NULL);
+ time = gnc_timet_get_day_end(time);
+ } else {
+ which = gnc_gconf_get_int(section, key_relative, NULL);
+ time = gnc_accounting_period_end_timet(which, fy_end, NULL);
+ }
+ if (time == 0)
+ time = -1;
+ return time;
+}
+
+static GDate *
+get_fy_end(void)
+{
+ QofBook *book;
+ KvpFrame *book_frame;
+ gint64 month, day;
+
+ book = gnc_get_current_book();
+ book_frame = qof_book_get_slots(book);
+ month = kvp_frame_get_gint64(book_frame, "/book/fyear_end/month");
+ day = kvp_frame_get_gint64(book_frame, "/book/fyear_end/day");
+ if (g_date_valid_dmy(day, month, 2005 /* not leap year */))
+ return g_date_new_dmy(day, month, G_DATE_BAD_YEAR);
+ return NULL;
+}
+
+time_t
+gnc_accounting_period_fiscal_start(void)
+{
+ time_t t;
+ GDate *fy_end = get_fy_end();
+ t = lookup_start_date_option(GCONF_SECTION, KEY_START_CHOICE,
+ KEY_START_DATE, KEY_START_PERIOD, fy_end);
+ if (fy_end)
+ g_date_free(fy_end);
+ return t;
+}
+
+time_t
+gnc_accounting_period_fiscal_end(void)
+{
+ time_t t;
+ GDate *fy_end = get_fy_end();
+
+ t = lookup_end_date_option(GCONF_SECTION, KEY_END_CHOICE,
+ KEY_END_DATE, KEY_END_PERIOD, fy_end);
+ if (fy_end)
+ g_date_free(fy_end);
+ return t;
+}
+
GDate *
gnc_accounting_period_start_gdate (GncAccountingPeriod which,
const GDate *fy_end,
Modified: gnucash/trunk/src/app-utils/gnc-accounting-period.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-accounting-period.h 2006-02-11 03:54:24 UTC (rev 13197)
+++ gnucash/trunk/src/app-utils/gnc-accounting-period.h 2006-02-11 05:00:02 UTC (rev 13198)
@@ -165,6 +165,14 @@
time_t gnc_accounting_period_end_timet (GncAccountingPeriod which,
const GDate *fy_end,
const GDate *contains);
+
+
+/* Convenience routines that take care of getting the fiscal
+ accounting period from the preferences and returning the start and
+ end times. */
+time_t gnc_accounting_period_fiscal_start(void);
+time_t gnc_accounting_period_fiscal_end(void);
+
/** @} */
#endif /* GNC_ACCOUNTING_PERIOD_H */
Modified: gnucash/trunk/src/gnome-utils/gnc-tree-view-account.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-view-account.c 2006-02-11 03:54:24 UTC (rev 13197)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-view-account.c 2006-02-11 05:00:02 UTC (rev 13198)
@@ -32,6 +32,7 @@
#include "gkeyfile.h"
#endif
+#include "gnc-accounting-period.h"
#include "gnc-tree-view.h"
#include "gnc-tree-model-account.h"
#include "gnc-tree-model-account-types.h"
@@ -353,8 +354,8 @@
g_return_if_fail(GTK_TREE_MODEL_SORT(s_model));
acct = gnc_tree_view_account_get_account_from_iter(s_model, iter);
- t1 = gnc_main_window_summary_get_start();
- t2 = gnc_main_window_summary_get_end();
+ t1 = gnc_accounting_period_fiscal_start();
+ t2 = gnc_accounting_period_fiscal_end();
if (t2 > t1) {
gnc_numeric b1, b2, b3;
Modified: gnucash/trunk/src/gnome-utils/window-main-summarybar.c
===================================================================
--- gnucash/trunk/src/gnome-utils/window-main-summarybar.c 2006-02-11 03:54:24 UTC (rev 13197)
+++ gnucash/trunk/src/gnome-utils/window-main-summarybar.c 2006-02-11 05:00:02 UTC (rev 13198)
@@ -35,7 +35,6 @@
#include "gnc-euro.h"
#include "gnc-gconf-utils.h"
#include "gnc-ui-util.h"
-#include "qof.h"
#include "window-main-summarybar.h"
typedef struct {
@@ -51,12 +50,6 @@
#define GCONF_SECTION "window/pages/account_tree/summary"
#define KEY_GRAND_TOTAL "grand_total"
#define KEY_NON_CURRENCY "non_currency"
-#define KEY_START_CHOICE "start_choice"
-#define KEY_START_DATE "start_date"
-#define KEY_START_PERIOD "start_period"
-#define KEY_END_CHOICE "end_choice"
-#define KEY_END_DATE "end_date"
-#define KEY_END_PERIOD "end_period"
/**
* An accumulator for a given currency.
@@ -337,97 +330,6 @@
N_COLUMNS,
};
-static time_t
-lookup_start_date_option(const gchar *section,
- const gchar *key_choice,
- const gchar *key_absolute,
- const gchar *key_relative,
- GDate *fy_end)
-{
- const gchar *choice;
- time_t time;
- int which;
-
- choice = gnc_gconf_get_string(section, key_choice, NULL);
- if (choice && strcmp(choice, "absolute") == 0) {
- time = gnc_gconf_get_int(section, key_absolute, NULL);
- } else {
- which = gnc_gconf_get_int(section, key_relative, NULL);
- time = gnc_accounting_period_start_timet(which, fy_end, NULL);
- }
- /* we will need the balance of the last transaction before the start
- date, so subtract 1 from start date */
- /* CAS: we don't actually do what this comment says. I think that's
- because a bug in the engine has been fixed. */
- return time;
-}
-
-
-static time_t
-lookup_end_date_option(const gchar *section,
- const gchar *key_choice,
- const gchar *key_absolute,
- const gchar *key_relative,
- GDate *fy_end)
-{
- const gchar *choice;
- time_t time;
- int which;
-
- choice = gnc_gconf_get_string(section, key_choice, NULL);
- if (choice && strcmp(choice, "absolute") == 0) {
- time = gnc_gconf_get_int(section, key_absolute, NULL);
- time = gnc_timet_get_day_end(time);
- } else {
- which = gnc_gconf_get_int(section, key_relative, NULL);
- time = gnc_accounting_period_end_timet(which, fy_end, NULL);
- }
- if (time == 0)
- time = -1;
- return time;
-}
-
-static GDate *
-get_fy_end(void)
-{
- QofBook *book;
- KvpFrame *book_frame;
- gint64 month, day;
-
- book = gnc_get_current_book();
- book_frame = qof_book_get_slots(book);
- month = kvp_frame_get_gint64(book_frame, "/book/fyear_end/month");
- day = kvp_frame_get_gint64(book_frame, "/book/fyear_end/day");
- if (g_date_valid_dmy(day, month, 2005 /* not leap year */))
- return g_date_new_dmy(day, month, G_DATE_BAD_YEAR);
- return NULL;
-}
-
-time_t
-gnc_main_window_summary_get_start(void)
-{
- time_t t;
- GDate *fy_end = get_fy_end();
- t = lookup_start_date_option(GCONF_SECTION, KEY_START_CHOICE,
- KEY_START_DATE, KEY_START_PERIOD, fy_end);
- if (fy_end)
- g_date_free(fy_end);
- return t;
-}
-
-time_t
-gnc_main_window_summary_get_end(void)
-{
- time_t t;
- GDate *fy_end = get_fy_end();
-
- t = lookup_end_date_option(GCONF_SECTION, KEY_END_CHOICE,
- KEY_END_DATE, KEY_END_PERIOD, fy_end);
- if (fy_end)
- g_date_free(fy_end);
- return t;
-}
-
/* The gnc_main_window_summary_refresh() subroutine redraws summary
* information. The statusbar includes two fields, titled 'profits'
* and 'assets'. The total assets equal the sum of all of the
@@ -463,8 +365,8 @@
gnc_gconf_get_bool(GCONF_SECTION, KEY_GRAND_TOTAL, NULL);
options.non_currency =
gnc_gconf_get_bool(GCONF_SECTION, KEY_NON_CURRENCY, NULL);
- options.start_date = gnc_main_window_summary_get_start();
- options.end_date = gnc_main_window_summary_get_end();
+ options.start_date = gnc_accounting_period_fiscal_start();
+ options.end_date = gnc_accounting_period_fiscal_end();
currency_list = NULL;
Modified: gnucash/trunk/src/gnome-utils/window-main-summarybar.h
===================================================================
--- gnucash/trunk/src/gnome-utils/window-main-summarybar.h 2006-02-11 03:54:24 UTC (rev 13197)
+++ gnucash/trunk/src/gnome-utils/window-main-summarybar.h 2006-02-11 05:00:02 UTC (rev 13198)
@@ -25,7 +25,5 @@
#define WINDOW_MAIN_SUMMARYBAR_H
GtkWidget * gnc_main_window_summary_new(void);
-time_t gnc_main_window_summary_get_start(void);
-time_t gnc_main_window_summary_get_end(void);
#endif
More information about the gnucash-changes
mailing list