mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Work on moving entity tables into sessions.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@5475 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
981bb4fbec
commit
48ac2e2dcb
@ -119,8 +119,11 @@ struct uiFreqTypeTuple uiFreqTypeStrs[] = {
|
||||
/**
|
||||
* Struct passed around as user-data when parsing the FreqSpec.
|
||||
**/
|
||||
typedef struct _freqSpecParseData {
|
||||
typedef struct
|
||||
{
|
||||
FreqSpec *fs; /* FreqSpec we're parsing into. */
|
||||
GNCSession *session; /* Session we're loading into. */
|
||||
|
||||
/* fields used in the union of unions... :) */
|
||||
GDate once_day; /* once */
|
||||
gint64 interval; /* all [except once] */
|
||||
@ -143,8 +146,6 @@ fspd_init( fsParseData *fspd )
|
||||
g_date_clear( &fspd->once_day, 1 );
|
||||
}
|
||||
|
||||
FreqSpec *dom_tree_to_freqSpec(xmlNodePtr node);
|
||||
|
||||
xmlNodePtr
|
||||
gnc_freqSpec_dom_tree_create( FreqSpec *fs )
|
||||
{
|
||||
@ -396,7 +397,7 @@ fs_subelement_handler( xmlNodePtr node, gpointer data )
|
||||
fsParseData *fspd = data;
|
||||
FreqSpec *fs;
|
||||
gboolean successful;
|
||||
fs = dom_tree_to_freqSpec( node );
|
||||
fs = dom_tree_to_freqSpec( node, fspd->session );
|
||||
if ( fs == NULL )
|
||||
return FALSE;
|
||||
fspd->list = g_list_append( fspd->list, fs );
|
||||
@ -556,6 +557,7 @@ gnc_freqSpec_end_handler(gpointer data_for_children,
|
||||
sixtp_gdv2 *globaldata = (sixtp_gdv2*)global_data;
|
||||
|
||||
fspd_init( &fspd );
|
||||
fspd.session = globaldata->session;
|
||||
|
||||
/* this won't actually get invoked [FreqSpecs aren't top-level
|
||||
elements]; see dom_tree_to_freqSpec(), below. */
|
||||
@ -567,7 +569,7 @@ gnc_freqSpec_end_handler(gpointer data_for_children,
|
||||
|
||||
g_return_val_if_fail( tree, FALSE );
|
||||
|
||||
fspd.fs = xaccFreqSpecMalloc();
|
||||
fspd.fs = xaccFreqSpecMalloc(globaldata->session);
|
||||
successful = dom_tree_generic_parse( tree, fs_dom_handlers, &fspd );
|
||||
if (!successful) {
|
||||
xmlElemDump( stdout, NULL, tree );
|
||||
@ -586,14 +588,14 @@ gnc_freqSpec_sixtp_parser_create(void)
|
||||
}
|
||||
|
||||
FreqSpec*
|
||||
dom_tree_to_freqSpec(xmlNodePtr node)
|
||||
dom_tree_to_freqSpec(xmlNodePtr node, GNCSession *session)
|
||||
{
|
||||
gboolean successful;
|
||||
fsParseData fspd;
|
||||
|
||||
fspd_init( &fspd );
|
||||
|
||||
fspd.fs = xaccFreqSpecMalloc();
|
||||
fspd.fs = xaccFreqSpecMalloc(session);
|
||||
successful = dom_tree_generic_parse( node, fs_dom_handlers, &fspd );
|
||||
if ( !successful ) {
|
||||
xaccFreqSpecFree( fspd.fs );
|
||||
|
@ -358,7 +358,7 @@ sx_freqspec_handler( xmlNodePtr node, gpointer sx_pdata )
|
||||
|
||||
g_return_val_if_fail( node, FALSE );
|
||||
|
||||
fs = dom_tree_to_freqSpec( xmlGetLastChild( node ) );
|
||||
fs = dom_tree_to_freqSpec( xmlGetLastChild( node ), pdata->session );
|
||||
xaccSchedXactionSetFreqSpec( sx, fs );
|
||||
|
||||
return TRUE;
|
||||
|
@ -43,7 +43,7 @@ GUID* dom_tree_to_guid(xmlNodePtr node);
|
||||
gnc_commodity* dom_tree_to_commodity_ref(xmlNodePtr node, GNCSession *session);
|
||||
gnc_commodity *dom_tree_to_commodity_ref_no_engine(xmlNodePtr node);
|
||||
|
||||
FreqSpec* dom_tree_to_freqSpec( xmlNodePtr node );
|
||||
FreqSpec* dom_tree_to_freqSpec( xmlNodePtr node, GNCSession *session );
|
||||
|
||||
Timespec* dom_tree_to_timespec(xmlNodePtr node);
|
||||
GDate* dom_tree_to_gdate(xmlNodePtr node);
|
||||
|
@ -133,7 +133,7 @@ void subSpecsListMapDelete( gpointer data, gpointer user_data );
|
||||
|
||||
|
||||
/** Local Prototypes *****/
|
||||
static void xaccFreqSpecInit( FreqSpec *fs );
|
||||
|
||||
|
||||
static const char *
|
||||
get_wday_name(guint day)
|
||||
@ -173,21 +173,29 @@ get_abbrev_month_name(guint month)
|
||||
**/
|
||||
|
||||
static void
|
||||
xaccFreqSpecInit( FreqSpec *fs )
|
||||
xaccFreqSpecInit( FreqSpec *fs, GNCSession *session )
|
||||
{
|
||||
g_return_if_fail( fs );
|
||||
g_return_if_fail (session);
|
||||
|
||||
xaccGUIDNew( &fs->guid );
|
||||
xaccStoreEntity( fs, &fs->guid, GNC_ID_FREQSPEC );
|
||||
|
||||
fs->type = INVALID;
|
||||
fs->uift = UIFREQ_ONCE;
|
||||
|
||||
memset( &(fs->s), 0, sizeof(fs->s) );
|
||||
}
|
||||
|
||||
FreqSpec*
|
||||
xaccFreqSpecMalloc(void)
|
||||
xaccFreqSpecMalloc(GNCSession *session)
|
||||
{
|
||||
FreqSpec *fs = g_new0(FreqSpec, 1);
|
||||
xaccFreqSpecInit( fs );
|
||||
FreqSpec *fs;
|
||||
|
||||
g_return_val_if_fail (session, NULL);
|
||||
|
||||
fs = g_new0(FreqSpec, 1);
|
||||
xaccFreqSpecInit( fs, session );
|
||||
/* FIXME:event */
|
||||
gnc_engine_generate_event( &fs->guid, GNC_EVENT_CREATE );
|
||||
return fs;
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <glib.h>
|
||||
|
||||
#include "GNCId.h"
|
||||
#include "gnc-engine.h"
|
||||
|
||||
/**
|
||||
* Frequency specification.
|
||||
@ -84,7 +85,7 @@ typedef struct gncp_freq_spec FreqSpec;
|
||||
/**
|
||||
* Allocates memory for a FreqSpec and initializes it.
|
||||
**/
|
||||
FreqSpec* xaccFreqSpecMalloc(void);
|
||||
FreqSpec* xaccFreqSpecMalloc(GNCSession *session);
|
||||
|
||||
/**
|
||||
* destroys any private data belonging to the FreqSpec.
|
||||
|
@ -53,7 +53,7 @@ xaccSchedXactionInit( SchedXaction *sx, GNCSession *session)
|
||||
AccountGroup *ag;
|
||||
char *name;
|
||||
|
||||
sx->freq = xaccFreqSpecMalloc();
|
||||
sx->freq = xaccFreqSpecMalloc(session);
|
||||
|
||||
book = gnc_session_get_book (session);
|
||||
|
||||
|
@ -9,11 +9,16 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <glib.h>
|
||||
#include <guile/gh.h>
|
||||
|
||||
#include "test-stuff.h"
|
||||
#include "FreqSpec.h"
|
||||
#include "GNCIdP.h"
|
||||
#include "gnc-engine.h"
|
||||
#include "gnc-module.h"
|
||||
#include "gnc-session.h"
|
||||
|
||||
static GNCSession *session;
|
||||
|
||||
static void
|
||||
test_once (void)
|
||||
@ -22,7 +27,7 @@ test_once (void)
|
||||
guint32 i, start_julian;
|
||||
GDate date1, date2, next_date;
|
||||
|
||||
fs = xaccFreqSpecMalloc();
|
||||
fs = xaccFreqSpecMalloc(session);
|
||||
|
||||
for( start_julian = 1; start_julian < 1000; ++start_julian ) {
|
||||
g_date_set_julian( &date1, start_julian );
|
||||
@ -48,7 +53,7 @@ test_daily (void)
|
||||
FreqSpec *fs;
|
||||
GDate date1, date2, next_date;
|
||||
|
||||
fs = xaccFreqSpecMalloc();
|
||||
fs = xaccFreqSpecMalloc(session);
|
||||
|
||||
g_date_set_dmy( &date1, 1, 1, 2000 );
|
||||
|
||||
@ -96,7 +101,7 @@ test_weekly (void)
|
||||
FreqSpec *fs;
|
||||
GDate date1, date2, next_date;
|
||||
|
||||
fs = xaccFreqSpecMalloc();
|
||||
fs = xaccFreqSpecMalloc(session);
|
||||
|
||||
/* Use this to test any specific cases which fail,
|
||||
* for easy access in the debugger. */
|
||||
@ -156,7 +161,7 @@ test_monthly (void)
|
||||
FreqSpec *fs;
|
||||
GDate date0, date1, date2, next_date;
|
||||
|
||||
fs = xaccFreqSpecMalloc();
|
||||
fs = xaccFreqSpecMalloc(session);
|
||||
|
||||
/* Use this to test any specific cases which fail,
|
||||
* for easy access in the debugger. */
|
||||
@ -229,7 +234,7 @@ test_month_relative (void)
|
||||
FreqSpec *fs;
|
||||
GDate date0, date1, date2, next_date;
|
||||
|
||||
fs = xaccFreqSpecMalloc();
|
||||
fs = xaccFreqSpecMalloc(session);
|
||||
|
||||
/* Use this to test any specific cases which fail,
|
||||
* for easy access in the debugger. */
|
||||
@ -344,7 +349,7 @@ test_composite (void)
|
||||
FreqSpec *fs, *fs2;
|
||||
GDate date0, date1, date2, next_date;
|
||||
|
||||
fs = xaccFreqSpecMalloc();
|
||||
fs = xaccFreqSpecMalloc(session);
|
||||
|
||||
/* Use this to test any specific cases which fail,
|
||||
* for easy access in the debugger. */
|
||||
@ -366,17 +371,17 @@ test_composite (void)
|
||||
|
||||
xaccFreqSpecSetComposite( fs );
|
||||
|
||||
fs2 = xaccFreqSpecMalloc();
|
||||
fs2 = xaccFreqSpecMalloc(session);
|
||||
g_date_set_dmy( &date0, 29, 3, 2001 ); /* Wednesday */
|
||||
xaccFreqSpecSetWeekly( fs2, &date0, 2 );
|
||||
xaccFreqSpecCompositeAdd( fs, fs2 );
|
||||
|
||||
fs2 = xaccFreqSpecMalloc();
|
||||
fs2 = xaccFreqSpecMalloc(session);
|
||||
g_date_set_dmy( &date0, 3, 4, 2001 ); /* Tuesday */
|
||||
xaccFreqSpecSetWeekly( fs2, &date0, 2 );
|
||||
xaccFreqSpecCompositeAdd( fs, fs2 );
|
||||
|
||||
fs2 = xaccFreqSpecMalloc();
|
||||
fs2 = xaccFreqSpecMalloc(session);
|
||||
g_date_set_dmy( &date0, 7, 4, 2001 ); /* Saturday */
|
||||
xaccFreqSpecSetWeekly( fs2, &date0, 2 );
|
||||
xaccFreqSpecCompositeAdd( fs, fs2 );
|
||||
@ -387,12 +392,14 @@ test_composite (void)
|
||||
g_date_set_dmy( &date0, 26, 3, 2001 );
|
||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||
g_date_set_dmy( &date2, 29, 3, 2001 );
|
||||
do_test( g_date_compare( &date1, &date2 ) == 0, "first date in sequence" );
|
||||
do_test( g_date_compare( &date1, &date2 ) == 0,
|
||||
"first date in sequence" );
|
||||
|
||||
g_date_set_dmy( &date0, 27, 3, 2001 );
|
||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||
g_date_set_dmy( &date2, 29, 3, 2001 );
|
||||
do_test( g_date_compare( &date1, &date2 ) == 0, "first date in sequence" );
|
||||
do_test( g_date_compare( &date1, &date2 ) == 0,
|
||||
"first date in sequence" );
|
||||
|
||||
g_date_set_dmy( &date0, 28, 3, 2001 );
|
||||
xaccFreqSpecGetNextInstance( fs, &date0, &date1 );
|
||||
@ -517,16 +524,18 @@ test_composite (void)
|
||||
xaccFreqSpecFree(fs);
|
||||
}
|
||||
|
||||
int
|
||||
main( int argc, char* argv[] )
|
||||
static void
|
||||
guile_main( int argc, char* argv[] )
|
||||
{
|
||||
gnc_module_load("gnucash/engine", 0);
|
||||
|
||||
g_log_set_always_fatal( G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING );
|
||||
|
||||
#if 0
|
||||
set_success_print(TRUE);
|
||||
#endif
|
||||
|
||||
gnc_engine_init (argc, argv);
|
||||
session = gnc_session_new ();
|
||||
|
||||
test_once();
|
||||
|
||||
@ -540,6 +549,16 @@ main( int argc, char* argv[] )
|
||||
|
||||
test_composite();
|
||||
|
||||
gnc_session_destroy (session);
|
||||
|
||||
print_test_results();
|
||||
return get_rv();
|
||||
exit (get_rv());
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
gh_enter (argc, argv, guile_main);
|
||||
return 0;
|
||||
}
|
||||
|
@ -21,16 +21,17 @@
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
#include <math.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <glib.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "FreqSpec.h"
|
||||
#include "dialog-utils.h"
|
||||
#include "gnc-engine-util.h"
|
||||
#include "gnc-frequency.h"
|
||||
#include "dialog-utils.h"
|
||||
#include "FreqSpec.h"
|
||||
#include "gnc-ui-util.h"
|
||||
|
||||
static short module = MOD_SX;
|
||||
|
||||
@ -611,7 +612,7 @@ gnc_frequency_save_state( GNCFrequency *gf, FreqSpec *fs, GDate *outStartDate )
|
||||
for ( i=1; i<6; i++ ) {
|
||||
*gd2 = *gd;
|
||||
g_date_add_days( gd2, i );
|
||||
tmpFS = xaccFreqSpecMalloc();
|
||||
tmpFS = xaccFreqSpecMalloc(gnc_get_current_session ());
|
||||
xaccFreqSpecSetWeekly( tmpFS, gd2, tmpInt );
|
||||
xaccFreqSpecCompositeAdd( fs, tmpFS );
|
||||
}
|
||||
@ -638,7 +639,8 @@ gnc_frequency_save_state( GNCFrequency *gf, FreqSpec *fs, GDate *outStartDate )
|
||||
o = glade_xml_get_widget( gf->gxml, str );
|
||||
if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(o) ) ) {
|
||||
|
||||
tmpFS = xaccFreqSpecMalloc();
|
||||
tmpFS = xaccFreqSpecMalloc
|
||||
(gnc_get_current_session ());
|
||||
xaccFreqSpecSetUIType( tmpFS, uift );
|
||||
/* struct-copy is expected to work, here */
|
||||
/* [wish we didn't have to know about the GDate implementation...] */
|
||||
@ -670,7 +672,7 @@ gnc_frequency_save_state( GNCFrequency *gf, FreqSpec *fs, GDate *outStartDate )
|
||||
|
||||
o = glade_xml_get_widget( gf->gxml, "semimonthly_first" );
|
||||
day = gnc_option_menu_get_active( GTK_WIDGET(o) )+1;
|
||||
tmpFS = xaccFreqSpecMalloc();
|
||||
tmpFS = xaccFreqSpecMalloc(gnc_get_current_session ());
|
||||
tmpTm = g_new0( struct tm, 1 );
|
||||
g_date_to_struct_tm( gd, tmpTm );
|
||||
if ( day >= tmpTm->tm_mday ) {
|
||||
@ -687,7 +689,7 @@ gnc_frequency_save_state( GNCFrequency *gf, FreqSpec *fs, GDate *outStartDate )
|
||||
|
||||
o = glade_xml_get_widget( gf->gxml, "semimonthly_second" );
|
||||
day = gnc_option_menu_get_active( GTK_WIDGET(o) )+1;
|
||||
tmpFS = xaccFreqSpecMalloc();
|
||||
tmpFS = xaccFreqSpecMalloc(gnc_get_current_session ());
|
||||
tmpTimeT = gnome_date_edit_get_date( gf->startDate );
|
||||
gd = g_date_new();
|
||||
g_date_set_time( gd, tmpTimeT );
|
||||
@ -799,7 +801,8 @@ static void
|
||||
update_cal( GNCFrequency *gf, GtkCalendar *cal )
|
||||
{
|
||||
FreqSpec *fs;
|
||||
fs = xaccFreqSpecMalloc();
|
||||
|
||||
fs = xaccFreqSpecMalloc(gnc_get_current_session ());
|
||||
gnc_frequency_save_state( gf, fs, NULL );
|
||||
mark_calendar( cal, fs );
|
||||
xaccFreqSpecFree( fs );
|
||||
|
@ -250,7 +250,7 @@ sxftd_compute_sx(SXFromTransInfo *sxfti)
|
||||
|
||||
g_date_set_time(&date, trans_t);
|
||||
|
||||
fs = xaccFreqSpecMalloc();
|
||||
fs = xaccFreqSpecMalloc(gnc_get_current_session ());
|
||||
|
||||
/* get the frequency */
|
||||
|
||||
@ -274,7 +274,7 @@ sxftd_compute_sx(SXFromTransInfo *sxfti)
|
||||
case FREQ_WEEKLY:
|
||||
g_date_add_days(&date, 7);
|
||||
|
||||
tmpfs = xaccFreqSpecMalloc();
|
||||
tmpfs = xaccFreqSpecMalloc(gnc_get_current_session ());
|
||||
xaccFreqSpecSetComposite(fs);
|
||||
xaccFreqSpecSetWeekly(tmpfs, &date, 1);
|
||||
xaccFreqSpecSetUIType(fs, UIFREQ_WEEKLY);
|
||||
|
Loading…
Reference in New Issue
Block a user