diff --git a/ChangeLog b/ChangeLog index 1f8b3fcc87..9112782d8e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,34 @@ +2002-07-01 Joshua Sled + + * src/gnome-utils/gnc-dense-cal.c (gnc_dense_cal_mark_remove): + Unrealistic marks [such as '-1'] are now ignored instead of + hitting assertion. + + * src/gnome/dialog-scheduledxaction.c: Dead code removal; naming + clarifications. + (gnc_sxed_check_consistent): Added. + (gnc_sxed_check_changed): Added; used when the cancel button is + pressed. SX editor now queries the user if the SX has changed. + (gnc_sxed_save_sx): Added; seperated from consistency-check. + (_gnc_sxed_get_widgets): Added; many glade_xml_get_widget(...)s + removed from code. + (free_var_numeric): Added; we now cleanup the temporary variable + table correctly after doing balance checking. + (schedXact_editor_create_ledger): RegWidget toolbar shouldn't + expand; fixed. + (putSchedXactionInDialog): Fixed assertion-failure/abort when a + previously-unscheduled SX is scheduled. + + * src/engine/SchedXaction.c (xaccSchedXactionGetNextInstance), + (xaccSchedXactionGetInstanceAfter): Fixed bug in + number-of-occurance instance-state processing. + + * src/register/ledger-core/gnc-regwidget.c: + * src/gnome/dialog-schedxaction.c: + * src/gnome/dialog-sxsincelast.c: + * src/engine/SchedXaction.[ch]: + * src/engine/FreqSpec.[ch]: Dead code removal/cleanup. + 2002-07-01 Derek Atkins * gnc-html: convert URLType from enum to char* diff --git a/src/engine/FreqSpec.c b/src/engine/FreqSpec.c index e0991b5e67..0b380d70eb 100644 --- a/src/engine/FreqSpec.c +++ b/src/engine/FreqSpec.c @@ -263,16 +263,6 @@ xaccFreqSpecSetUIType( FreqSpec *fs, UIFreqType newUIFreqType ) fs->uift = newUIFreqType; } -/* -void -xaccFreqSpecSetTypes( FreqSpec *fs, FreqType newFT, UIFreqType newUIFT ) -{ - g_return_if_fail( fs ); - xaccFreqSpecSetType( fs, newFT ); - xaccFreqSpecSetUIType( fs, newUIFT ); -} -*/ - static inline guint32 min( guint32 a, guint32 b ) { return a > b ? b : a; diff --git a/src/engine/FreqSpec.h b/src/engine/FreqSpec.h index f2520c16c2..fab54f3d3a 100644 --- a/src/engine/FreqSpec.h +++ b/src/engine/FreqSpec.h @@ -108,6 +108,7 @@ FreqType xaccFreqSpecGetType( FreqSpec *fs ); * Sets the type of a FreqSpec. * Setting the type re-initializes any spec-data; this means * destroying any sub-types in the case of COMPOSITE. + * * THESE FUNCTIONS HAVE NOT BEEN MAINTAINED THROUGH BEN'S CHANGES. * They need to be checked. **/ @@ -116,9 +117,6 @@ FreqType xaccFreqSpecGetType( FreqSpec *fs ); UIFreqType xaccFreqSpecGetUIType( FreqSpec *fs ); void xaccFreqSpecSetUIType( FreqSpec *fs, UIFreqType newUIFreqType ); -/* Convenience function; calls the two above. */ -/* void xaccFreqSpecSetTypes( FreqSpec *fs, FreqType newType, UIFreqType newUIType ); */ - /** * Sets the type to once-off, and initialises the * date it occurs on. @@ -182,7 +180,7 @@ int xaccFreqSpecGetDaily( FreqSpec *fs, int *outRepeat ); int xaccFreqSpecGetWeekly( FreqSpec *fs, int *outRepeat, int *outDayOfWeek ); int xaccFreqSpecGetMonthly( FreqSpec *fs, int *outRepeat, int *outDayOfMonth, int *outMonthOffset ); -// FIXME: add month-relative +/* FIXME: add month-relative */ /** * Returns the list of FreqSpecs in a COMPOSITE FreqSpec. @@ -199,17 +197,6 @@ GList* xaccFreqSpecCompositeGet( FreqSpec *fs ); **/ void xaccFreqSpecCompositeAdd( FreqSpec *fs, FreqSpec *fsToAdd ); -/** - * Returns the next date which the FreqSpec specifies given the - * previous occurance. Like the relaxed validity check, this doesn't - * take multipliers into account; it just returns the next possible - * occurance after the given day. - * bstanley I think this should be private. - **/ -/* -time_t xaccFreqSpecGetInstanceAfter( FreqSpec *fs, time_t after ); -*/ - /** * Returns the next instance of the FreqSpec after a given input date. * Note that if the given date happens to be a repeat date, @@ -219,23 +206,4 @@ void xaccFreqSpecGetNextInstance( FreqSpec *fs, const GDate* in_date, GDate* out_date ); -/** - * Returns either NULL [valid] or a descriptive string [reason not - * valid] for the given query date. This is "relaxed", in that it - * doesn't care about the frequency multiplier [e.g., For - * WEEKLY[2]:Wed, all Wednesdays are valid; for MONTHLY[12]:16, the - * 16th day of every month is valid. - **/ -/* -char* xaccFreqSpecIsValidDateRelaxed( FreqSpec *fs, time_t query ); -*/ - -/** - * A strict validity check. Given a previous and query date, returns - * NULL if the query date is valid, or a text reason if not. - **/ -/* -char* xaccFreqSpecIsValidDate( FreqSpec *fs, time_t previous, time_t query ); -*/ - #endif /* XACC_FREQSPEC_H */ diff --git a/src/engine/SchedXaction.c b/src/engine/SchedXaction.c index 9881f7bf2c..cc2e63937c 100644 --- a/src/engine/SchedXaction.c +++ b/src/engine/SchedXaction.c @@ -201,7 +201,6 @@ xaccSchedXactionSetFreqSpec( SchedXaction *sx, FreqSpec *fs ) { g_return_if_fail( fs ); - DEBUG("Called xaccSchedXactionSetFreqSpec"); xaccFreqSpecFree( sx->freq ); sx->freq = fs; sx->dirty = TRUE; @@ -427,7 +426,6 @@ xaccSchedXactionSetAdvanceReminder( SchedXaction *sx, gint reminderDays ) } -/* FIXME: there is a bug in this, I think */ GDate xaccSchedXactionGetNextInstance( SchedXaction *sx, void *stateData ) { @@ -474,10 +472,8 @@ xaccSchedXactionGetNextInstance( SchedXaction *sx, void *stateData ) g_date_clear( &next_occur, 1 ); } } else if ( xaccSchedXactionHasOccurDef( sx ) && stateData ) { - /* FIXME: does this work? */ - gint remaining; - remaining = xaccSchedXactionGetRemOccur( sx ); - if ( remaining == 0 ) { + temporalStateData *tsd = (temporalStateData*)stateData; + if ( tsd->num_occur_rem == 0 ) { PINFO( "no more occurances remain" ); g_date_clear( &next_occur, 1 ); } @@ -500,16 +496,11 @@ xaccSchedXactionGetInstanceAfter( SchedXaction *sx, end_date = xaccSchedXactionGetEndDate( sx ); if ( g_date_compare( &next_occur, end_date ) > 0 ) { - PINFO( "next_occur past end_date" ); g_date_clear( &next_occur, 1 ); } } else if ( xaccSchedXactionHasOccurDef( sx ) && stateData ) { - /* gint remaining = xaccSchedXactionGetRemOccur( sx ); */ - gint *remaining = (gint*)stateData; - DEBUG( "stateData [remaining]: %d", *remaining ); - if ( (*remaining - 1) < 0 ) { - PINFO( "next_occur is outside " - "reminaing-instances window." ); + temporalStateData *tsd = (temporalStateData*)stateData; + if ( tsd->num_occur_rem == 0 ) { g_date_clear( &next_occur, 1 ); } } @@ -644,19 +635,7 @@ xaccSchedXactionSetTemplateTrans(SchedXaction *sx, GList *t_t_list, void* xaccSchedXactionCreateSequenceState( SchedXaction *sx ) { - //void *toRet = NULL; - return gnc_sx_create_temporal_state_snapshot( sx ); - /* - if ( xaccSchedXactionHasOccurDef( sx ) ) { - toRet = g_new0( gint, 1 ); - *(gint*)toRet = xaccSchedXactionGetRemOccur( sx ); - DEBUG( "Returning state data [remaining]: %d", *(gint*)toRet ); - } else { - DEBUG( "Returning null state data" ); - } - */ - //return toRet; } void @@ -667,28 +646,16 @@ xaccSchedXactionIncrSequenceState( SchedXaction *sx, temporalStateData *tsd = (temporalStateData*)stateData; tsd->num_occur_rem -= 1; } -#if 0 /* change to temporal_state */ - if ( xaccSchedXactionHasOccurDef( sx ) ) { - gint *remaining; - remaining = (gint*)stateData; - *remaining = *remaining - 1; - } -#endif /* 0 */ } void xaccSchedXactionDestroySequenceState( void *stateData ) { gnc_sx_destroy_temporal_state_snapshot( stateData ); -#if 0 /* change to temporal_state */ - if ( xaccSchedXactionHasOccurDef( sx ) ) { - g_free( (gint*)stateData ); - } -#endif /* 0 */ } -void -*gnc_sx_create_temporal_state_snapshot( SchedXaction *sx ) +void* +gnc_sx_create_temporal_state_snapshot( SchedXaction *sx ) { temporalStateData *toRet = g_new0( temporalStateData, 1 ); toRet->last_date = sx->last_date; diff --git a/src/gnome-utils/gnc-dense-cal.c b/src/gnome-utils/gnc-dense-cal.c index 72b0bc39d5..4524e7e6a7 100644 --- a/src/gnome-utils/gnc-dense-cal.c +++ b/src/gnome-utils/gnc-dense-cal.c @@ -1410,9 +1410,11 @@ gnc_dense_cal_mark( GncDenseCal *dcal, d = dateArray[i]; doc = gdc_get_doc_offset( dcal, d ); if ( doc < 0 ) { +#if 0 /* Silently ignore. */ printf( "This is TheErrorThatShouldBeAppropriately" "Handeled @ %d for \"%s\" with %d\n", i, name, doc ); +#endif /* 0 */ continue; } l = g_list_alloc(); @@ -1432,6 +1434,11 @@ gnc_dense_cal_mark_remove( GncDenseCal *dcal, guint markToRemove ) gint doc; gdc_mark_data *gdcmd; + /* Ignore non-realistic marks */ + if ( markToRemove == -1 ) { + return; + } + gdcmd = NULL; for ( l = dcal->markData; l; l=l->next ) { gdcmd = (gdc_mark_data*)l->data; diff --git a/src/gnome-utils/gnc-frequency.c b/src/gnome-utils/gnc-frequency.c index f1b0791155..018937b0c0 100644 --- a/src/gnome-utils/gnc-frequency.c +++ b/src/gnome-utils/gnc-frequency.c @@ -53,8 +53,6 @@ static void update_appropriate_cal( GNCFrequency *gf ); static void gnc_frequency_class_init( GNCFrequencyClass *klass ); -static void free_resources( GtkObject *o, gpointer d ); - static void freq_option_value_changed( GtkMenuShell *b, gpointer d ); static void start_date_changed( GnomeDateEdit *gde, gpointer d ); static void spin_changed_helper( GtkAdjustment *adj, gpointer d ); @@ -209,10 +207,6 @@ gnc_frequency_init( GNCFrequency *gf ) gf->vb = vb; gtk_container_add( GTK_CONTAINER(&gf->widget), GTK_WIDGET(gf->vb) ); - /* connect to the destroy signal for cleanup */ - gtk_signal_connect( GTK_OBJECT(gf->vb), "destroy", - GTK_SIGNAL_FUNC(free_resources), gf ); - /* intially fix the calendars. */ for ( j=0; cals[j] != NULL; j++ ) { o = glade_xml_get_widget( gf->gxml, cals[j] ); @@ -636,30 +630,30 @@ gnc_frequency_save_state( GNCFrequency *gf, FreqSpec *fs, GDate *outStartDate ) case UIFREQ_DAILY_MF: xaccFreqSpecSetComposite( fs ); xaccFreqSpecSetUIType( fs, uift ); - gd2 = g_date_new(); o = glade_xml_get_widget( gf->gxml, "dailymf_spin" ); tmpInt = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(o) ); /* Okay. Assume that the calendar is upgraded to */ /* support selecting weeks, returning the Sunday selected. */ /* Normalize to sunday. */ - tmpTm = g_new0( struct tm, 1 ); - g_date_to_struct_tm( gd, tmpTm ); - /* month-day += (week-day - current-week-day ) % 7 */ - /* week-day <- 0 */ - tmpTm->tm_mday -= ( tmpTm->tm_wday ) % 7; - g_date_set_time( gd, mktime( tmpTm ) ); + { + tmpTm = g_new0( struct tm, 1 ); + g_date_to_struct_tm( gd, tmpTm ); + /* month-day += (week-day - current-week-day ) % 7 */ + /* week-day <- 0 */ + tmpTm->tm_mday -= ( tmpTm->tm_wday ) % 7; + g_date_set_time( gd, mktime( tmpTm ) ); + g_free( tmpTm ); + } /* 1 == "mon", 5 == "fri" */ for ( i=1; i<6; i++ ) { - *gd2 = *gd; - g_date_add_days( gd2, i ); + g_date_add_days( gd, 1 ); tmpFS = xaccFreqSpecMalloc(gnc_get_current_book ()); - xaccFreqSpecSetWeekly( tmpFS, gd2, tmpInt ); + xaccFreqSpecSetWeekly( tmpFS, gd, tmpInt ); xaccFreqSpecCompositeAdd( fs, tmpFS ); } + g_date_free( gd ); - g_date_free( gd2 ); - g_free( tmpTm ); break; case UIFREQ_WEEKLY: xaccFreqSpecSetComposite( fs ); @@ -897,17 +891,6 @@ update_appropriate_cal( GNCFrequency *gf ) update_cal( gf, GTK_CALENDAR(o) ); } -static void -free_resources( GtkObject *o, gpointer d ) -{ -#if 0 - GNCFrequency *gf = (GNCFrequency*)d; - // FIXME: destroy an appropriate widget - gtk_widget_destroy( glade_xml_get_widget( gf->gxml, - "GNCFrequency widget" ) ); -#endif // 0 -} - static void spin_changed_helper( GtkAdjustment *adj, gpointer d ) { diff --git a/src/gnome/dialog-scheduledxaction.c b/src/gnome/dialog-scheduledxaction.c index fc1de52b16..76339aba39 100644 --- a/src/gnome/dialog-scheduledxaction.c +++ b/src/gnome/dialog-scheduledxaction.c @@ -59,9 +59,12 @@ static short module = MOD_SX; #define DIALOG_SCHEDXACTION_EDITOR_CM_CLASS "dialog-scheduledtransaction-editor" #define SX_LIST_GLADE_NAME "Scheduled Transaction List" +#define SX_LIST "sched_xact_list" #define SX_LIST_UPCOMING_FRAME "upcoming_cal_frame" #define SX_EDITOR_GLADE_NAME "Scheduled Transaction Editor" #define SX_OPT_STR "Scheduled Transactions" + +#define SXED_NAME_ENTRY "sxe_name" #define AUTOCREATE_OPT "autocreate_opt" #define NOTIFY_OPT "notify_opt" #define ADVANCE_OPT "advance_opt" @@ -80,14 +83,6 @@ static short module = MOD_SX; /** Datatypes ***********************************************************/ -/* FIXME: this is stolen from window-register.c */ -typedef enum -{ - DELETE_TRANS, - DELETE_SPLITS, - DELETE_CANCEL -} DeleteType; - typedef enum _EndTypeEnum { END_NEVER, END_DATE, @@ -108,13 +103,29 @@ struct _SchedXactionEditorDialog GtkWidget *dialog; SchedXactionDialog *sxd; SchedXaction *sx; - /* FIXME: what does "new" mean? */ - int new; + /* If this is a new scheduled transaction or not. */ + int newsxP; + /* The various widgets in the dialog */ GNCLedgerDisplay *ledger; GnucashRegister *reg; GNCFrequency *gncfreq; + GtkEditable *nameEntry; + + GtkToggleButton *autocreateOpt; + GtkToggleButton *notifyOpt; + GtkToggleButton *advanceOpt; + GtkSpinButton *advanceSpin; + GtkToggleButton *remindOpt; + GtkSpinButton *remindSpin; + + GtkToggleButton *optEndDate; + GtkToggleButton *optEndNone; + GtkToggleButton *optEndCount; + GnomeNumberEntry *endCountEntry; + GnomeNumberEntry *endRemainEntry; + GnomeDateEdit *endDateEntry; char *sxGUIDstr; @@ -129,7 +140,6 @@ static void generate_instances( SchedXaction *sx, GDate *end, GList **instanceList ); static void schedXact_populate( SchedXactionDialog * ); -static void schedXact_editor_init( SchedXactionEditorDialog * ); static void schedXact_editor_create_freq_sel( SchedXactionEditorDialog *sxed ); static void schedXact_editor_create_ledger( SchedXactionEditorDialog *sxed ); static void schedXact_editor_populate( SchedXactionEditorDialog * ); @@ -139,31 +149,22 @@ static void edit_button_clicked( GtkButton *b, gpointer d ); static void delete_button_clicked( GtkButton *b, gpointer d ); static void close_button_clicked( GtkButton *b, gpointer d ); +static void _gnc_sxed_get_widgets( SchedXactionEditorDialog *sxed ); + static void endgroup_rb_toggled( GtkButton *b, gpointer d ); static void set_endgroup_toggle_states( SchedXactionEditorDialog *sxed, EndType t ); static void advance_toggle( GtkButton *b, SchedXactionEditorDialog *sxed ); +static gboolean gnc_sxed_check_consistent( SchedXactionEditorDialog *sxed ); +static gboolean gnc_sxed_check_changed( SchedXactionEditorDialog *sxed ); + +static void gnc_sxed_save_sx( SchedXactionEditorDialog *sxed ); /* ledger standard-handlers */ static gncUIWidget sxe_ledger_get_parent( GNCLedgerDisplay *ld ); -/* ledger callbacks */ -#if 0 -static void sxe_register_record_cb( GnucashRegister *reg, gpointer d ); -static void sxe_register_redraw_all_cb( GnucashRegister *reg, gpointer d ); -#endif - static void sxed_reg_recordCB( GtkWidget *w, gpointer d ); static void sxed_reg_cancelCB( GtkWidget *w, gpointer d ); -#if 0 /* removed 2002.05.29 to get rid of compilation warnings after - * gncRegWidget addition. */ -static void sxed_reg_deleteCB( GtkWidget *w, gpointer d ); -static void sxed_reg_duplicateCB( GtkWidget *w, gpointer d ); -static void sxed_reg_expand_trans_checkCB( GtkWidget *w, gpointer d ); -static void sxed_reg_new_transCB( GtkWidget *w, gpointer d ); -static void sxed_reg_jumpCB( GtkWidget *w, gpointer d ); -static void sxed_reg_xferCB( GtkWidget *w, gpointer d ); -#endif /* 0 -- removed 2002.05.29 */ static void gnc_sxed_reg_check_close(SchedXactionEditorDialog *sxed); @@ -187,16 +188,8 @@ sxed_close_handler ( gpointer user_data ) { SchedXactionEditorDialog *sxed = user_data; - DEBUG( "sxed_close_handler" ); - gnc_sxed_reg_check_close( sxed ); - - /*gnc_ledger_display_close( sxed->ledger );*/ - /*sxed->ledger = NULL;*/ - - g_free (sxed->sxGUIDstr); - sxed->sxGUIDstr = NULL; - + /* Real dialog cleanup occurs in "destroy" callback. */ gnome_dialog_close( GNOME_DIALOG( sxed->dialog ) ); } @@ -207,16 +200,26 @@ close_button_clicked( GtkButton *b, gpointer d ) sxd_close_handler( d ); } -static void +static +void editor_cancel_button_clicked( GtkButton *b, SchedXactionEditorDialog *sxed ) { SplitRegister *reg; reg = gnc_ledger_display_get_split_register( sxed->ledger ); + /* check for changes */ + if ( gnc_sxed_check_changed( sxed ) ) { + const char *sx_changed_msg = + _( "This SX has changed; are you " + "sure you want to cancel?" ); + if ( !gnc_verify_dialog_parented( GTK_WIDGET(sxed->dialog), + FALSE, sx_changed_msg ) ) { + return; + } + } /* cancel ledger changes */ gnc_split_register_cancel_cursor_trans_changes( reg ); - /* FIXME: cancel other changes */ - + /* close */ gnc_close_gui_component_by_data (DIALOG_SCHEDXACTION_EDITOR_CM_CLASS, sxed); @@ -231,14 +234,6 @@ editor_help_button_clicked(GtkButton *b, SchedXactionEditorDialog *sxed) return; } -#if 0 -static void -local_print_helper( gpointer key, gpointer value, gpointer ud ) -{ - printf( "var: \"%s\"\n", (char*)key ); -} -#endif - static void set_var_to_random_value( gpointer key, gpointer value, gpointer ud ) { @@ -246,29 +241,229 @@ set_var_to_random_value( gpointer key, gpointer value, gpointer ud ) val = g_new0( gnc_numeric, 1 ); *val = double_to_gnc_numeric( rand() + 2, 1, - GNC_NUMERIC_RND_MASK | GNC_RND_FLOOR ); + GNC_NUMERIC_RND_MASK + | GNC_RND_FLOOR ); if ( value != NULL ) { g_free( value ); } g_hash_table_insert( ud, key, val ); } +static +void +free_var_numeric( gpointer key, gpointer val, gpointer ud ) +{ + g_free( (gnc_numeric*)val ); +} + static void editor_ok_button_clicked( GtkButton *b, SchedXactionEditorDialog *sxed ) { GNCBook *book; - GtkWidget *w, *optEndDate, *optNoEnd, *optNumOccur; GList *sxList; - FreqSpec *fs; - GDate *gdate; - gboolean ttHasVars; - /* FIXMEs: Do checks on validity and such, interrupting the user if + if ( !gnc_sxed_check_consistent( sxed ) ) + return; + + gnc_sxed_save_sx( sxed ); + + /* add to list */ + putSchedXactionInDialog( sxed->sx, sxed->sxd ); + if ( sxed->newsxP ) { + book = gnc_get_current_book (); + sxList = gnc_book_get_schedxactions( book ); + sxList = g_list_append( sxList, sxed->sx ); + gnc_book_set_schedxactions( book, sxList ); + sxed->sx = NULL; + } + + /* cleanup */ + gnc_close_gui_component_by_data (DIALOG_SCHEDXACTION_EDITOR_CM_CLASS, + sxed); +} + +/** + * Checks to see if the SX has been modified from it's previously-saved + * state. + * @return TRUE if this is a 'new' SX, or if the SX has changed from it's + * previous configuration. + **/ +static +gboolean +gnc_sxed_check_changed( SchedXactionEditorDialog *sxed ) +{ + if ( sxed->newsxP ) + return TRUE; + + /* name */ + { + char *name; + + name = gtk_editable_get_chars( GTK_EDITABLE(sxed->nameEntry), 0, -1 ); + if ( strlen(name) == 0 ) { + return TRUE; + + } + if ( (xaccSchedXactionGetName(sxed->sx) == NULL) + || (strcmp( xaccSchedXactionGetName(sxed->sx), + name ) != 0) ) { + return TRUE; + } + } + + /* end options */ + { + /* dialog says... no end */ + if ( gtk_toggle_button_get_active( sxed->optEndNone ) ) { + if ( xaccSchedXactionHasEndDate(sxed->sx) + || xaccSchedXactionHasOccurDef(sxed->sx) ) { + return TRUE; + } + } + + /* dialog says... end date */ + if ( gtk_toggle_button_get_active( sxed->optEndDate ) ) { + GDate sxEndDate, dlgEndDate; + + if ( ! xaccSchedXactionHasEndDate( sxed->sx ) ) { + return TRUE; + } + sxEndDate = *xaccSchedXactionGetEndDate( sxed->sx ); + g_date_set_time( &dlgEndDate, + gnome_date_edit_get_date( sxed-> + endDateEntry ) ); + + if ( g_date_compare( &sxEndDate, &dlgEndDate ) != 0 ) { + return TRUE; + } + } + + /* dialog says... num occur */ + if ( gtk_toggle_button_get_active( sxed->optEndCount ) ) { + gint sxNumOccur, sxNumRem, dlgNumOccur, dlgNumRem; + + if ( ! xaccSchedXactionGetNumOccur( sxed->sx ) ) { + return TRUE; + } + + dlgNumOccur = (gint)gnome_number_entry_get_number( sxed-> + endCountEntry ); + dlgNumRem = (gint)gnome_number_entry_get_number( sxed-> + endRemainEntry ); + + sxNumOccur = xaccSchedXactionGetNumOccur( sxed->sx ); + sxNumRem = xaccSchedXactionGetRemOccur( sxed->sx ); + + if ( (dlgNumOccur != sxNumOccur) + || (dlgNumRem != sxNumRem) ) { + return TRUE; + } + } + } + + /* SX options [autocreate, notify, reminder, advance] */ + { + gboolean dlgAutoCreate, dlgNotify, sxAutoCreate, sxNotify; + gint dlgAdvance, sxAdvance; + gint dlgRemind, sxRemind; + + dlgAutoCreate = + gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(sxed-> + autocreateOpt) ); + dlgNotify = + gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(sxed-> + notifyOpt) ); + + xaccSchedXactionGetAutoCreate( sxed->sx, &sxAutoCreate, &sxNotify ); + if ( ! ((dlgAutoCreate == sxAutoCreate) + && (dlgNotify == sxNotify)) ) { + return TRUE; + } + + dlgAdvance = 0; + if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(sxed->advanceOpt) ) ) { + dlgAdvance = + gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(sxed-> + advanceSpin) ); + } + sxAdvance = xaccSchedXactionGetAdvanceCreation( sxed->sx ); + if ( dlgAdvance != sxAdvance ) { + return TRUE; + } + + dlgRemind = 0; + if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(sxed->remindOpt) ) ) { + dlgRemind = + gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(sxed->remindSpin) ); + } + sxRemind = xaccSchedXactionGetAdvanceReminder( sxed->sx ); + if ( dlgRemind != sxRemind ) { + return TRUE; + } + } + + /* FS, startdate */ + { + FreqSpec *dlgFS, *sxFS; + GDate dlgStartDate, sxStartDate; + GString *dlgFSstr, *sxFSstr; + gboolean fsStrCmpResult; + + dlgFS = xaccFreqSpecMalloc( gnc_get_current_book() ); + /* save gncFreq data */ + gnc_frequency_save_state( sxed->gncfreq, dlgFS, &dlgStartDate ); + dlgFSstr = g_string_sized_new( 16 ); + xaccFreqSpecGetFreqStr( dlgFS, dlgFSstr ); + /* get SX startdate/fs data */ + sxStartDate = *xaccSchedXactionGetStartDate( sxed->sx ); + sxFS = xaccSchedXactionGetFreqSpec( sxed->sx ); + sxFSstr = g_string_sized_new( 16 ); + xaccFreqSpecGetFreqStr( sxFS, sxFSstr ); + /* compare */ + + fsStrCmpResult = /* lame version of comparison */ + (strcmp( dlgFSstr->str, sxFSstr->str) != 0); + g_string_free( dlgFSstr, TRUE ); + g_string_free( sxFSstr, TRUE ); + xaccFreqSpecFree( dlgFS ); + + if ( (g_date_compare(&dlgStartDate, &sxStartDate) != 0) + || fsStrCmpResult ) { + return TRUE; + } + } + + /* template transactions */ + { + SplitRegister *sr = + gnc_ledger_display_get_split_register( sxed->ledger ); + + if ( gnc_split_register_changed( sr ) ) { + return TRUE; + } + } + return FALSE; +} + + +/** + * Checks to make sure that the SX is in a reasonable state to save. + * @return true if checks out okay, false otherwise. + **/ +static +gboolean +gnc_sxed_check_consistent( SchedXactionEditorDialog *sxed ) +{ + gboolean ttHasVars; + FreqSpec *fs; + + /* FIXMEs... + * Do checks on validity and such, interrupting the user if * things aren't right. - * . We should do all validity checks before we change anything - * about the SX; for clarity as well as consistency. * + * . the 'will ever be valid' check should take num-occur vals into + * account. * . balancing the SX if contain numeric-only formula data. * . agreement with create-automagically/notification controls * X SX name is unique @@ -280,11 +475,8 @@ editor_ok_button_clicked( GtkButton *b, SchedXactionEditorDialog *sxed ) * [X more generically, creating a "not scheduled" SX is probably not * right... ] */ - ttHasVars = FALSE; - gnc_split_register_save ( gnc_ledger_display_get_split_register(sxed->ledger), - FALSE ); - /* numeric-formulas-get-balanced determination */ + ttHasVars = FALSE; { static const int NUM_ITERS_WITH_VARS = 5; static const int NUM_ITERS_NO_VARS = 1; @@ -309,6 +501,12 @@ editor_ok_button_clicked( GtkButton *b, SchedXactionEditorDialog *sxed ) * . true: all good * . false: indicate to user, allow decision. */ + + /* FIXME: This _really_ shouldn't require a modification of the + * SX just to get the var names... */ + gnc_split_register_save ( gnc_ledger_display_get_split_register(sxed->ledger), + FALSE ); + /* numeric-formulas-get-balanced determination */ sxsl_get_sx_vars( sxed->sx, vars ); ttHasVars = (g_hash_table_size( vars ) != 0); @@ -345,7 +543,7 @@ editor_ok_button_clicked( GtkButton *b, SchedXactionEditorDialog *sxed ) PERR( "Couldn't parse credit formula for " "\"%s\" on second pass", xaccSchedXactionGetName( sxed->sx ) ); - return; + return FALSE; } creditSum = gnc_numeric_add_fixed( creditSum, tmp ); tmp = gnc_numeric_zero(); @@ -361,7 +559,7 @@ editor_ok_button_clicked( GtkButton *b, SchedXactionEditorDialog *sxed ) PERR( "Couldn't parse debit formula for " "\"%s\" on second pass", xaccSchedXactionGetName( sxed->sx ) ); - return; + return FALSE; } debitSum = gnc_numeric_add_fixed( debitSum, tmp ); tmp = gnc_numeric_zero(); @@ -383,6 +581,7 @@ editor_ok_button_clicked( GtkButton *b, SchedXactionEditorDialog *sxed ) } #endif /* DEBUG */ } + g_hash_table_foreach( vars, free_var_numeric, (gpointer)vars ); g_hash_table_destroy( vars ); if ( unbalanceable @@ -392,26 +591,24 @@ editor_ok_button_clicked( GtkButton *b, SchedXactionEditorDialog *sxed ) "appears unbalancable, " "should it still be " "created?") ) ) { - return; + return FALSE; } } /* read out data back into SchedXaction object. */ - /* FIXME: this is getting too deep; split out. */ { char *name; - GList *sxList; gboolean nameExists, nameHasChanged; + GList *sxList; - w = glade_xml_get_widget( sxed->gxml, "sxe_name" ); - name = gtk_entry_get_text( GTK_ENTRY(w) ); + name = gtk_editable_get_chars( GTK_EDITABLE(sxed->nameEntry), 0, -1 ); if ( strlen(name) == 0 ) { const char *sx_has_no_name_msg = _( "Please name the Scheduled Transaction." ); gnc_error_dialog_parented( GTK_WINDOW(sxed->dialog), sx_has_no_name_msg ); - return; + return FALSE; } @@ -419,8 +616,9 @@ editor_ok_button_clicked( GtkButton *b, SchedXactionEditorDialog *sxed ) nameHasChanged = (xaccSchedXactionGetName(sxed->sx) == NULL) || (strcmp( xaccSchedXactionGetName(sxed->sx), name ) != 0); - sxList = gnc_book_get_schedxactions( gnc_get_current_book() ); - for ( ; nameHasChanged && !nameExists && sxList ; + for ( sxList = + gnc_book_get_schedxactions( gnc_get_current_book() ); + nameHasChanged && !nameExists && sxList ; sxList = sxList->next ) { char *existingName; existingName = @@ -428,148 +626,217 @@ editor_ok_button_clicked( GtkButton *b, SchedXactionEditorDialog *sxed ) data ); nameExists |= ( g_strcasecmp(name, existingName) == 0 ); } + g_free( name ); if ( nameHasChanged && nameExists ) { const char *sx_has_existing_name_msg = - _( "A Scheduled Transaction with this name \"%s\" already exists.\n" - "Are you sure you want to name this one the same?" ); + _( "A Scheduled Transaction with this " + "name \"%s\" already exists.\n" + "Are you sure you want to name " + "this one the same?" ); if ( ! gnc_verify_dialog_parented( sxed->dialog, FALSE, sx_has_existing_name_msg, name) ) { - /* They don't; so don't. */ - return; + return FALSE; } } - xaccSchedXactionSetName( sxed->sx, name ); - } - - gdate = g_date_new(); - optEndDate = glade_xml_get_widget( sxed->gxml, "rb_enddate" ); - optNoEnd = glade_xml_get_widget( sxed->gxml, "rb_noend" ); - optNumOccur = glade_xml_get_widget( sxed->gxml, "rb_num_occur" ); - if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(optEndDate)) ) { - /* get the end date data */ - w = glade_xml_get_widget( sxed->gxml, END_DATE_DATEENTRY ); - g_date_set_time( gdate, gnome_date_edit_get_date( GNOME_DATE_EDIT(w) ) ); - xaccSchedXactionSetEndDate( sxed->sx, gdate ); - /* set the num occurances data */ - xaccSchedXactionSetNumOccur( sxed->sx, 0 ); - } else if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(optNumOccur) ) ) { - gint num; - /* get the occurances data */ - w = glade_xml_get_widget( sxed->gxml, END_GNOME_NUMENTRY ); - num = (gint)gnome_number_entry_get_number( GNOME_NUMBER_ENTRY(w) ); - xaccSchedXactionSetNumOccur( sxed->sx, num ); - - w = glade_xml_get_widget( sxed->gxml, REMAIN_GNOME_NUMENTRY ); - num = (gint)gnome_number_entry_get_number( GNOME_NUMBER_ENTRY(w) ); - xaccSchedXactionSetRemOccur( sxed->sx, num ); - - g_date_clear( gdate, 1 ); - xaccSchedXactionSetEndDate( sxed->sx, gdate ); - } else if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(optNoEnd) ) ) { - xaccSchedXactionSetNumOccur( sxed->sx, 0 ); - g_date_clear( gdate, 1 ); - xaccSchedXactionSetEndDate( sxed->sx, gdate ); - } else { - PERR( "No valid end specified\n" ); } { gboolean autocreateState, notifyState; - w = glade_xml_get_widget( sxed->gxml, "autocreate_opt" ); - autocreateState = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(w) ); - w = glade_xml_get_widget( sxed->gxml, "notify_opt" ); - notifyState = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(w) ); + autocreateState = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(sxed->autocreateOpt) ); + notifyState = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(sxed->notifyOpt) ); if ( ttHasVars && autocreateState ) { - gnc_info_dialog( _("You attempted to create a \"Create " - "Automatically\" " - "Scheduled Transaction which has Variables, " - "which is not allowed.\nPlease remove the " - "Create Automatically flag and try again.") ); - return; + /* FIXME: Wow... that's a mouthful. Reword. */ + gnc_warning_dialog_parented( sxed->dialog, + _("You attempted to create a \"Create " + "Automatically\" " + "Scheduled Transaction which has Variables, " + "which is not allowed.\nPlease remove the " + "Create Automatically flag and try again.") ); + return FALSE; } - /* "Notify" only makes sense if AutoCreate is actived; - * enforce that here. */ - xaccSchedXactionSetAutoCreate( sxed->sx, - autocreateState, - (autocreateState & notifyState) ); - } - - { - int daysInAdvance; - - daysInAdvance = 0; - w = glade_xml_get_widget( sxed->gxml, "advance_opt" ); - if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(w) ) ) { - w = glade_xml_get_widget( sxed->gxml, "advance_days" ); - daysInAdvance = - gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(w) ); - } - xaccSchedXactionSetAdvanceCreation( sxed->sx, daysInAdvance ); - - daysInAdvance = 0; - w = glade_xml_get_widget( sxed->gxml, "remind_opt" ); - if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(w) ) ) { - w = glade_xml_get_widget( sxed->gxml, "remind_days" ); - daysInAdvance = - gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(w) ); - } - xaccSchedXactionSetAdvanceReminder( sxed->sx, daysInAdvance ); } - /* get the frequency spec data */ - fs = xaccSchedXactionGetFreqSpec( sxed->sx ); - gnc_frequency_save_state( sxed->gncfreq, fs, gdate ); - - /* now that we have it, set the start date */ - xaccSchedXactionSetStartDate( sxed->sx, gdate ); - g_date_free( gdate ); - - /* Now, see if the user is attempting to create a SX that can't exist - * [will never run]. */ + /* deal with time. */ { - gboolean isInvalid; - gdate = g_date_new(); - *gdate = xaccSchedXactionGetNextInstance( sxed->sx, NULL ); - isInvalid = !g_date_valid( gdate ); - g_date_free( gdate ); - if ( isInvalid ) { - char *invalid_sx_check_msg = + GDate startDate, endDate, nextDate; + + if ( !gtk_toggle_button_get_active(sxed->optEndDate) + && !gtk_toggle_button_get_active(sxed->optEndCount) + && !gtk_toggle_button_get_active(sxed->optEndNone) ) { + const char *sx_end_spec_msg = + _( "Please provide a valid end selection." ); + gnc_error_dialog( sx_end_spec_msg ); + return FALSE; + } + + if ( gtk_toggle_button_get_active(sxed->optEndCount)) { + gint occur, rem; + + occur = (gint)gnome_number_entry_get_number( sxed->endCountEntry ); + xaccSchedXactionSetNumOccur( sxed->sx, occur ); + + rem = (gint)gnome_number_entry_get_number( sxed->endRemainEntry ); + xaccSchedXactionSetRemOccur( sxed->sx, rem ); + + if ( occur == 0 ) { + const char *sx_occur_count_zero_msg = + _( "There must be some number of occurances." ); + gnc_error_dialog_parented( GTK_WINDOW(sxed->dialog), + sx_occur_count_zero_msg ); + return FALSE; + } + + if ( rem > occur ) { + const char *sx_occur_counts_wrong_msg = + _( "The number of remaining occurances " + "(%d) is greater than the number of " + "total occurances (%d)." ); + gnc_error_dialog_parented( GTK_WINDOW(sxed->dialog), + sx_occur_counts_wrong_msg, + rem, occur ); + return FALSE; + } + + } + + g_date_clear( &endDate, 1 ); + if ( gtk_toggle_button_get_active(sxed->optEndDate) ) { + g_date_set_time( &endDate, + gnome_date_edit_get_date( sxed-> + endDateEntry ) ); + } + + /* Now, see if the user is attempting to create a SX that can't exist + * [will never run]. */ + + /* get the frequency spec data */ + fs = xaccFreqSpecMalloc( gnc_get_current_book() ); + gnc_frequency_save_state( sxed->gncfreq, fs, &startDate ); + /* Replicate just a smidgen of the code in the SX + * ...GetNextInstance routine */ + g_date_subtract_days( &startDate, 1 ); + xaccFreqSpecGetNextInstance( fs, &startDate, &nextDate ); + xaccFreqSpecFree( fs ); + + if ( !g_date_valid( &nextDate ) + || (g_date_valid( &endDate ) + && (g_date_compare( &nextDate, &endDate ) > 0)) ) { + const char *invalid_sx_check_msg = _( "You have attempted to create a Scheduled " "Transaction which will never run.\nDo you " "really want to do this?" ); if ( ! gnc_verify_dialog_parented( sxed->dialog, FALSE, invalid_sx_check_msg) ) { - return; + return FALSE; } } } + return TRUE; +} - /* add to list */ - putSchedXactionInDialog( sxed->sx, sxed->sxd ); - if ( sxed->new ) { - book = gnc_get_current_book (); - sxList = gnc_book_get_schedxactions( book ); - sxList = g_list_append( sxList, sxed->sx ); - gnc_book_set_schedxactions( book, sxList ); - sxed->sx = NULL; +/** + * Saves the contents of the SX. This assumes that gnc_sxed_check_consistent + * has returned true. + **/ +static +void +gnc_sxed_save_sx( SchedXactionEditorDialog *sxed ) +{ + /* name */ + { + char *name; + + name = gtk_editable_get_chars( sxed->nameEntry, 0, -1 ); + xaccSchedXactionSetName( sxed->sx, name ); + g_free( name ); + } + + /* date */ + { + GDate gdate; + + if ( gtk_toggle_button_get_active(sxed->optEndDate) ) { + /* get the end date data */ + g_date_set_time( &gdate, gnome_date_edit_get_date( sxed->endDateEntry ) ); + xaccSchedXactionSetEndDate( sxed->sx, &gdate ); + /* set the num occurances data */ + xaccSchedXactionSetNumOccur( sxed->sx, 0 ); + } else if ( gtk_toggle_button_get_active(sxed->optEndCount) ) { + gint num; + /* get the occurances data */ + num = (gint)gnome_number_entry_get_number( sxed->endCountEntry ); + xaccSchedXactionSetNumOccur( sxed->sx, num ); + num = (gint)gnome_number_entry_get_number( sxed->endRemainEntry ); + xaccSchedXactionSetRemOccur( sxed->sx, num ); + + g_date_clear( &gdate, 1 ); + xaccSchedXactionSetEndDate( sxed->sx, &gdate ); + } else if ( gtk_toggle_button_get_active( sxed->optEndNone ) ) { + xaccSchedXactionSetNumOccur( sxed->sx, 0 ); + g_date_clear( &gdate, 1 ); + xaccSchedXactionSetEndDate( sxed->sx, &gdate ); + } else { + PERR( "No valid end specified\n" ); + } + } + + /* Auto-create/notification states */ + { + gboolean autocreateState, notifyState; + + autocreateState = gtk_toggle_button_get_active( sxed->autocreateOpt ); + notifyState = gtk_toggle_button_get_active( sxed->notifyOpt ); + /* "Notify" only makes sense if AutoCreate is actived; + * enforce that here. */ + xaccSchedXactionSetAutoCreate( sxed->sx, + autocreateState, + (autocreateState & notifyState) ); + } + + /* days in advance */ + { + int daysInAdvance; + + daysInAdvance = 0; + if ( gtk_toggle_button_get_active( sxed->advanceOpt ) ) { + daysInAdvance = + gtk_spin_button_get_value_as_int( sxed->advanceSpin ); + } + xaccSchedXactionSetAdvanceCreation( sxed->sx, daysInAdvance ); + + daysInAdvance = 0; + if ( gtk_toggle_button_get_active( sxed->remindOpt ) ) { + daysInAdvance = + gtk_spin_button_get_value_as_int( sxed->remindSpin ); + } + xaccSchedXactionSetAdvanceReminder( sxed->sx, daysInAdvance ); + } + + /* start date and freq spec */ + { + FreqSpec *fs; + GDate gdate; + + fs = xaccSchedXactionGetFreqSpec( sxed->sx ); + gnc_frequency_save_state( sxed->gncfreq, fs, &gdate ); + + /* now that we have it, set the start date */ + xaccSchedXactionSetStartDate( sxed->sx, &gdate ); } - /* cleanup */ - gnc_close_gui_component_by_data (DIALOG_SCHEDXACTION_EDITOR_CM_CLASS, - sxed); } static void autocreate_toggled( GtkObject *o, SchedXactionEditorDialog *sxed ) { - GtkWidget *notifyCheck; - - notifyCheck = glade_xml_get_widget( sxed->gxml, "notify_opt" ); - gtk_widget_set_sensitive( notifyCheck, + if ( !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(o)) ) { + gtk_toggle_button_set_active( sxed->notifyOpt, FALSE ); + } + gtk_widget_set_sensitive( GTK_WIDGET(sxed->notifyOpt), gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(o) ) ); } @@ -614,17 +881,21 @@ scheduledxaction_editor_dialog_destroy(GtkObject *object, gpointer data) if (sxed == NULL) return; -#if 0 - if ( sxed->ledger ) { - sxed_close_handler( sxed ); - return; - } -#endif /* 0 */ gnc_unregister_gui_component_by_data - (DIALOG_SCHEDXACTION_EDITOR_CM_CLASS, sxed); + (DIALOG_SCHEDXACTION_EDITOR_CM_CLASS, sxed); + if ( sxed->newsxP ) { + xaccSchedXactionFree( sxed->sx ); + } sxed->sx = NULL; + /* FIXME: + * . what do we need to do to clean up the reg widget? + * . what about the rest of the dialog? + */ + g_free (sxed->sxGUIDstr); + sxed->sxGUIDstr = NULL; + g_free (sxed); } @@ -652,6 +923,7 @@ gnc_ui_scheduled_xaction_dialog_create(void) sxd->gxml = gnc_glade_xml_new( "sched-xact.glade", SX_LIST_GLADE_NAME ); sxd->dialog = glade_xml_get_widget( sxd->gxml, SX_LIST_GLADE_NAME ); + sxd->sxData = g_hash_table_new( NULL, NULL ); sxdo = GTK_OBJECT(sxd->dialog); @@ -753,7 +1025,7 @@ schedXact_populate( SchedXactionDialog *sxd ) g_list_foreach( sxList, putSchedXactionInDialog, sxd ); sx_clist = GTK_CLIST( glade_xml_get_widget( sxd->gxml, - "sched_xact_list" ) ); + SX_LIST ) ); for ( i=0; i<3; i++ ) { gtk_clist_set_column_auto_resize( sx_clist, i, TRUE ); } @@ -761,29 +1033,54 @@ schedXact_populate( SchedXactionDialog *sxd ) GTK_SIGNAL_FUNC(row_select_handler), sxd ); } -#if 0 -static void -sxed_check_close( SchedXactionEditorDialog *sxed ) -{ - SplitRegister *reg; - - reg = gnc_ledger_display_get_split_register( sxed->ledger ); - - /* Check for SX changes... how? */ - - /* Check the ledger for changes. */ - gnc_sxed_reg_check_close( sxed ); -} -#endif - static gboolean sxed_delete_event( GtkWidget *widget, GdkEvent *evt, gpointer ud ) { - DEBUG( "delete-event" ); sxed_close_handler( (SchedXactionEditorDialog*)ud ); return TRUE; } +static +void +_gnc_sxed_get_widgets( SchedXactionEditorDialog *sxed ) +{ + GtkWidget *w; + + w = glade_xml_get_widget( sxed->gxml, SXED_NAME_ENTRY ); + sxed->nameEntry = GTK_EDITABLE(w); + w = glade_xml_get_widget( sxed->gxml, AUTOCREATE_OPT ); + sxed->autocreateOpt = GTK_TOGGLE_BUTTON(w); + w = glade_xml_get_widget( sxed->gxml, NOTIFY_OPT ); + sxed->notifyOpt = GTK_TOGGLE_BUTTON(w); + w = glade_xml_get_widget( sxed->gxml, ADVANCE_OPT ); + sxed->advanceOpt = GTK_TOGGLE_BUTTON(w); + w = glade_xml_get_widget( sxed->gxml, ADVANCE_DAYS_SPIN ); + sxed->advanceSpin = GTK_SPIN_BUTTON(w); + w = glade_xml_get_widget( sxed->gxml, REMIND_OPT ); + sxed->remindOpt = GTK_TOGGLE_BUTTON(w); + w = glade_xml_get_widget( sxed->gxml, REMIND_DAYS_SPIN ); + sxed->remindSpin = GTK_SPIN_BUTTON(w); + + w = glade_xml_get_widget( sxed->gxml, "rb_enddate" ); + sxed->optEndDate = GTK_TOGGLE_BUTTON(w); + + w = glade_xml_get_widget( sxed->gxml, "rb_noend" ); + sxed->optEndNone = GTK_TOGGLE_BUTTON(w); + + w = glade_xml_get_widget( sxed->gxml, "rb_num_occur" ); + sxed->optEndCount = GTK_TOGGLE_BUTTON(w); + + w = glade_xml_get_widget( sxed->gxml, END_GNOME_NUMENTRY ); + sxed->endCountEntry = GNOME_NUMBER_ENTRY(w); + + w = glade_xml_get_widget( sxed->gxml, REMAIN_GNOME_NUMENTRY ); + sxed->endRemainEntry = GNOME_NUMBER_ENTRY(w); + + w = glade_xml_get_widget( sxed->gxml, END_DATE_DATEENTRY ); + sxed->endDateEntry = GNOME_DATE_EDIT(w); + +} + SchedXactionEditorDialog * gnc_ui_scheduled_xaction_editor_dialog_create( SchedXactionDialog *sxd, SchedXaction *sx, @@ -792,7 +1089,7 @@ gnc_ui_scheduled_xaction_editor_dialog_create( SchedXactionDialog *sxd, SchedXactionEditorDialog *sxed; GtkWidget *button; int i; - GList *alreadyExists = NULL; + GList *dlgExists = NULL; static struct widgetSignalCallback { char *name; @@ -809,31 +1106,35 @@ gnc_ui_scheduled_xaction_editor_dialog_create( SchedXactionDialog *sxd, { "rb_num_occur", "toggled", endgroup_rb_toggled, GINT_TO_POINTER(NUM_OCCUR_OPTION) }, { "autocreate_opt", "toggled", autocreate_toggled, NULL }, - { "advance_opt", "toggled", advance_toggle, (gpointer)"advance_days" }, - { "remind_opt", "toggled", advance_toggle, (gpointer)"remind_days" }, + { "advance_opt", "toggled", advance_toggle, (gpointer)ADVANCE_DAYS_SPIN }, + { "remind_opt", "toggled", advance_toggle, (gpointer)REMIND_DAYS_SPIN }, { NULL, NULL, NULL, NULL } }; - alreadyExists = gnc_find_gui_components( DIALOG_SCHEDXACTION_EDITOR_CM_CLASS, - editor_component_sx_equality, - sx ); - if ( alreadyExists ) { - sxed = (SchedXactionEditorDialog*)alreadyExists->data; + dlgExists = gnc_find_gui_components( DIALOG_SCHEDXACTION_EDITOR_CM_CLASS, + editor_component_sx_equality, + sx ); + if ( dlgExists != NULL ) { + sxed = (SchedXactionEditorDialog*)dlgExists->data; gtk_window_present( GTK_WINDOW(sxed->dialog) ); - g_list_free( alreadyExists ); + g_list_free( dlgExists ); return sxed; } sxed = g_new0( SchedXactionEditorDialog, 1 ); - sxed->gxml = gnc_glade_xml_new( "sched-xact.glade", SX_EDITOR_GLADE_NAME ); sxed->dialog = glade_xml_get_widget( sxed->gxml, SX_EDITOR_GLADE_NAME ); sxed->sxd = sxd; sxed->sx = sx; - sxed->new = newP; + sxed->newsxP = newP; + + /* NOTE: this must occur before processing the widget list, above, so + * the gpointers stored with the advance_ and remind_opts are + * correct. */ + _gnc_sxed_get_widgets( sxed ); gnc_register_gui_component( DIALOG_SCHEDXACTION_EDITOR_CM_CLASS, NULL, /* no refresh handler */ @@ -861,44 +1162,27 @@ gnc_ui_scheduled_xaction_editor_dialog_create( SchedXactionDialog *sxd, } /* FIXME: For some reason the Glade-specified sensitivity settings - are not being honored. */ - button = glade_xml_get_widget( sxed->gxml, "notify_opt" ); - gtk_widget_set_sensitive( button, FALSE ); - button = glade_xml_get_widget( sxed->gxml, "advance_days" ); - gtk_widget_set_sensitive( button, FALSE ); - button = glade_xml_get_widget( sxed->gxml, "remind_days" ); - gtk_widget_set_sensitive( button, FALSE ); + * are not being honored. */ + gtk_widget_set_sensitive( GTK_WIDGET(sxed->notifyOpt), FALSE ); + gtk_widget_set_sensitive( GTK_WIDGET(sxed->advanceSpin), FALSE ); + gtk_widget_set_sensitive( GTK_WIDGET(sxed->remindSpin), FALSE ); + gtk_widget_set_sensitive( GTK_WIDGET(sxed->endCountEntry), FALSE ); + gtk_widget_set_sensitive( GTK_WIDGET(sxed->endRemainEntry), FALSE ); + /* Allow grow, allow shrink, auto-shrink */ + gtk_window_set_policy (GTK_WINDOW(sxed->dialog), TRUE, TRUE, FALSE); /* create the frequency-selection macrowidget */ schedXact_editor_create_freq_sel( sxed ); /* create the template-transaction ledger window */ schedXact_editor_create_ledger( sxed ); - /* initialize */ - schedXact_editor_init( sxed ); /* populate */ schedXact_editor_populate( sxed ); gtk_widget_show_all(sxed->dialog); - return sxed; } -static -void -schedXact_editor_init( SchedXactionEditorDialog *sxed ) -{ - GtkWidget *w; - w = glade_xml_get_widget( sxed->gxml, END_GNOME_NUMENTRY ); - gtk_widget_set_sensitive( w, FALSE ); - w = glade_xml_get_widget( sxed->gxml, REMAIN_GNOME_NUMENTRY ); - gtk_widget_set_sensitive( w, FALSE ); - - /* Allow grow, allow shrink, auto-shrink */ - gtk_window_set_policy (GTK_WINDOW(sxed->dialog), TRUE, TRUE, FALSE); -} - - static void schedXact_editor_create_freq_sel( SchedXactionEditorDialog *sxed ) @@ -956,7 +1240,7 @@ schedXact_editor_create_ledger( SchedXactionEditorDialog *sxed ) GTK_WINDOW(sxed->dialog) ); gtk_box_pack_start( GTK_BOX(vbox), gnc_regWidget_get_toolbar( GNC_REGWIDGET(regWidget) ), - TRUE, TRUE, 2 ); + FALSE, TRUE, 2 ); { GtkWidget *popup, *tmpMenu, *tmpMI; /* Fixup the popup menu with the menus that would normally be in the @@ -983,39 +1267,6 @@ schedXact_editor_create_ledger( SchedXactionEditorDialog *sxed ) } gtk_box_pack_start( GTK_BOX(vbox), regWidget, TRUE, TRUE, 2 ); -#if 0 - gnc_ledger_display_set_handlers( sxed->ledger, - sxe_ledger_destroy, - sxe_ledger_get_parent ); - gnc_ledger_display_set_user_data( sxed->ledger, (gpointer)sxed ); - - - /* Watch the order of operations, here... */ - gnucash_register_set_initial_rows( numLedgerLines ); - regWidget = gnucash_register_new( splitreg->table ); - gnc_table_init_gui( regWidget, splitreg ); - sxed->reg = GNUCASH_REGISTER(regWidget); - GNUCASH_SHEET(sxed->reg->sheet)->window = GTK_WIDGET(sxed->dialog); - - popup = schedXaction_editor_create_reg_popup( sxed ); - gnucash_register_attach_popup( sxed->reg, popup, sxed ); - - toolbar = schedXaction_editor_create_reg_tool_bar( sxed ); - /*gtk_container_set_border_width( GTK_CONTAINER(toolbar), 2 );*/ - - gtk_box_pack_start( GTK_BOX(vbox), toolbar, FALSE, FALSE, 2 ); - gtk_box_pack_end( GTK_BOX(vbox), regWidget, TRUE, TRUE, 2 ); -#endif /* 0 */ - -#if 0 - gtk_signal_connect( GTK_OBJECT(sxed->dialog), "activate_cursor", - GTK_SIGNAL_FUNC(sxe_register_record_cb), sxed ); - gtk_signal_connect( GTK_OBJECT(sxed->dialog), "redraw_all", - GTK_SIGNAL_FUNC(sxe_register_redraw_all_cb), sxed ); - -#endif /* 0 */ - - /* configure... */ /* don't use double-line */ gnc_split_register_config(splitreg, @@ -1033,7 +1284,6 @@ static void schedXact_editor_populate( SchedXactionEditorDialog *sxed ) { - GtkEntry *nameEntry; char *name; time_t tmpDate; SplitRegister *splitReg; @@ -1044,40 +1294,34 @@ schedXact_editor_populate( SchedXactionEditorDialog *sxed ) gint daysInAdvance; gboolean autoCreateState, notifyState; - nameEntry = GTK_ENTRY(glade_xml_get_widget( sxed->gxml, "sxe_name" )); name = xaccSchedXactionGetName(sxed->sx); if ( name != NULL ) { - gtk_entry_set_text( nameEntry, name ); + gtk_entry_set_text( GTK_ENTRY(sxed->nameEntry), name ); } gd = xaccSchedXactionGetEndDate( sxed->sx ); if ( g_date_valid( gd ) ) { - w = glade_xml_get_widget( sxed->gxml, "rb_enddate" ); - gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(w), TRUE ); + gtk_toggle_button_set_active( sxed->optEndDate, TRUE ); /* fill in date data. */ - w = glade_xml_get_widget( sxed->gxml, END_DATE_DATEENTRY ); tmpTm = g_new0( struct tm, 1 ); g_date_to_struct_tm( gd, tmpTm ); tmpDate = mktime( tmpTm ); g_free( tmpTm ); - gnome_date_edit_set_time( GNOME_DATE_EDIT(w), tmpDate ); + gnome_date_edit_set_time( sxed->endDateEntry, tmpDate ); set_endgroup_toggle_states( sxed, END_DATE ); } else if ( xaccSchedXactionHasOccurDef( sxed->sx ) ) { gint numOccur = xaccSchedXactionGetNumOccur( sxed->sx ); gint numRemain = xaccSchedXactionGetRemOccur( sxed->sx ); - w = glade_xml_get_widget( sxed->gxml, "rb_num_occur" ); - gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(w), TRUE ); + gtk_toggle_button_set_active( sxed->optEndCount, TRUE ); - w = glade_xml_get_widget( sxed->gxml, END_GNOME_NUMENTRY ); - w = gnome_number_entry_gtk_entry( GNOME_NUMBER_ENTRY(w) ); + w = gnome_number_entry_gtk_entry( sxed->endCountEntry ); tmpgStr = g_string_sized_new(5); g_string_sprintf( tmpgStr, "%d", numOccur ); gtk_entry_set_text( GTK_ENTRY(w), tmpgStr->str ); g_string_free( tmpgStr, TRUE ); - w = glade_xml_get_widget( sxed->gxml, REMAIN_GNOME_NUMENTRY );; - w = gnome_number_entry_gtk_entry( GNOME_NUMBER_ENTRY(w) ); + w = gnome_number_entry_gtk_entry( sxed->endRemainEntry ); tmpgStr = g_string_sized_new(5); g_string_sprintf( tmpgStr, "%d", numRemain ); gtk_entry_set_text( GTK_ENTRY(w), tmpgStr->str ); @@ -1085,13 +1329,12 @@ schedXact_editor_populate( SchedXactionEditorDialog *sxed ) set_endgroup_toggle_states( sxed, END_OCCUR ); } else { - w = glade_xml_get_widget( sxed->gxml, "rb_noend" ); - gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(w), TRUE ); + gtk_toggle_button_set_active( sxed->optEndNone, TRUE ); set_endgroup_toggle_states( sxed, END_NEVER ); } /* Do auto-create/notify setup */ - if ( sxed->new ) { + if ( sxed->newsxP ) { autoCreateState = gnc_lookup_boolean_option( SX_OPT_STR, "Auto-Create new Scheduled " @@ -1105,17 +1348,15 @@ schedXact_editor_populate( SchedXactionEditorDialog *sxed ) &autoCreateState, ¬ifyState ); } - w = glade_xml_get_widget( sxed->gxml, "autocreate_opt" ); - gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(w), autoCreateState ); + gtk_toggle_button_set_active( sxed->autocreateOpt, autoCreateState ); if ( ! autoCreateState ) { notifyState = FALSE; } - w = glade_xml_get_widget( sxed->gxml, "notify_opt" ); - gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(w), notifyState ); + gtk_toggle_button_set_active( sxed->notifyOpt, notifyState ); /* Do days-in-advance-to-create widget[s] setup. */ - if ( sxed->new ) { + if ( sxed->newsxP ) { daysInAdvance = (int)gnc_lookup_number_option( SX_OPT_STR, "Default number of days in " @@ -1125,15 +1366,13 @@ schedXact_editor_populate( SchedXactionEditorDialog *sxed ) xaccSchedXactionGetAdvanceCreation( sxed->sx ); } if ( daysInAdvance != 0 ) { - w = glade_xml_get_widget( sxed->gxml, "advance_opt" ); - gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(w), TRUE ); - w = glade_xml_get_widget( sxed->gxml, "advance_days" ); - gtk_spin_button_set_value( GTK_SPIN_BUTTON(w), + gtk_toggle_button_set_active( sxed->advanceOpt, TRUE ); + gtk_spin_button_set_value( sxed->advanceSpin, (gfloat)daysInAdvance ); } /* Do days-in-advance-to-remind widget[s] setup. */ - if ( sxed->new ) { + if ( sxed->newsxP ) { daysInAdvance = (int)gnc_lookup_number_option( SX_OPT_STR, "Default number of days in " @@ -1143,10 +1382,8 @@ schedXact_editor_populate( SchedXactionEditorDialog *sxed ) xaccSchedXactionGetAdvanceReminder( sxed->sx ); } if ( daysInAdvance != 0 ) { - w = glade_xml_get_widget( sxed->gxml, "remind_opt" ); - gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(w), TRUE ); - w= glade_xml_get_widget( sxed->gxml, "remind_days" ); - gtk_spin_button_set_value( GTK_SPIN_BUTTON(w), + gtk_toggle_button_set_active( sxed->remindOpt, TRUE ); + gtk_spin_button_set_value( sxed->remindSpin, (gfloat)daysInAdvance ); } @@ -1168,16 +1405,9 @@ static void set_endgroup_toggle_states( SchedXactionEditorDialog *sxed, EndType type ) { - GtkWidget *dateCtl, *occurCtl; - - dateCtl = glade_xml_get_widget( sxed->gxml, END_DATE_DATEENTRY ); - gtk_widget_set_sensitive( GTK_WIDGET(dateCtl), (type == END_DATE) ); - - occurCtl = glade_xml_get_widget( sxed->gxml, END_GNOME_NUMENTRY ); - gtk_widget_set_sensitive( GTK_WIDGET(occurCtl), (type == END_OCCUR) ); - - occurCtl = glade_xml_get_widget( sxed->gxml, REMAIN_GNOME_NUMENTRY ); - gtk_widget_set_sensitive( GTK_WIDGET(occurCtl), (type == END_OCCUR) ); + gtk_widget_set_sensitive( GTK_WIDGET(sxed->endDateEntry), (type == END_DATE) ); + gtk_widget_set_sensitive( GTK_WIDGET(sxed->endCountEntry), (type == END_OCCUR) ); + gtk_widget_set_sensitive( GTK_WIDGET(sxed->endRemainEntry), (type == END_OCCUR) ); } static @@ -1214,7 +1444,7 @@ edit_button_clicked( GtkButton *b, gpointer d ) SchedXactionEditorDialog *sxed; sxd = (SchedXactionDialog*)d; - cl = GTK_CLIST(glade_xml_get_widget( sxd->gxml, "sched_xact_list" )); + cl = GTK_CLIST(glade_xml_get_widget( sxd->gxml, SX_LIST )); for( sel = cl->selection; sel; sel = g_list_next(sel) ) { row = (int)sel->data; /* get the clist row for this listitem */ @@ -1242,7 +1472,7 @@ delete_button_clicked( GtkButton *b, gpointer d ) sxd = (SchedXactionDialog*)d; - cl = GTK_CLIST(glade_xml_get_widget( sxd->gxml, "sched_xact_list" )); + cl = GTK_CLIST(glade_xml_get_widget( sxd->gxml, SX_LIST )); sel = cl->selection; if ( !sel ) { @@ -1310,10 +1540,8 @@ delete_button_clicked( GtkButton *b, gpointer d ) sx = (SchedXaction*)gtk_clist_get_row_data( cl, (int)sel->data ); sxList = g_list_remove( sxList, (gpointer)sx ); foundP = g_hash_table_lookup_extended( sxd->sxData, sx, - &unused, &tag ); + &unused, (gpointer*)&tag ); g_assert( foundP ); - /* FIXME: this should allow the possibility that an - * unscheduled transaction will have no mark tag. */ if ( tag != -1 ) { gnc_dense_cal_mark_remove( sxd->gdcal, tag ); } @@ -1484,7 +1712,7 @@ putSchedXactionInDialog( gpointer data, gpointer user_data ) text[1] = freqStr->str; text[2] = nextDate->str; - clist = GTK_CLIST( glade_xml_get_widget( sxd->gxml, "sched_xact_list" ) ); + clist = GTK_CLIST( glade_xml_get_widget( sxd->gxml, SX_LIST ) ); gtk_clist_freeze( clist ); row = gtk_clist_find_row_from_data( clist, sx ); if ( row != -1 ) { @@ -1492,7 +1720,8 @@ putSchedXactionInDialog( gpointer data, gpointer user_data ) gboolean foundP = g_hash_table_lookup_extended( sxd->sxData, (gpointer)sx, - &unused, &oldMarkTag ); + &unused, + (gpointer*)&oldMarkTag ); g_assert( foundP ); } if ( row == -1 ) { @@ -1501,7 +1730,9 @@ putSchedXactionInDialog( gpointer data, gpointer user_data ) gtk_clist_set_row_data( clist, row, sx ); } else { /* old item being replaced. */ - gnc_dense_cal_mark_remove( sxd->gdcal, oldMarkTag ); + if ( oldMarkTag != -1 ) { + gnc_dense_cal_mark_remove( sxd->gdcal, oldMarkTag ); + } for ( i=0; i<3; i++ ) { gtk_clist_set_text( clist, row, i, text[i] ); } @@ -1509,7 +1740,6 @@ putSchedXactionInDialog( gpointer data, gpointer user_data ) gtk_clist_thaw( clist ); g_hash_table_insert( sxd->sxData, (gpointer)sx, (gpointer)gdcMarkTag ); - /* FIXME: leaky? -- shouldn't be with 'TRUE' below */ g_string_free( freqStr, TRUE ); g_string_free( nextDate, TRUE ); } @@ -1524,38 +1754,6 @@ sxe_ledger_get_parent( GNCLedgerDisplay *ld ) return sxed->dialog; } -#if 0 -static -void -sxe_register_record_cb( GnucashRegister *reg, gpointer d ) -{ - SchedXactionEditorDialog *sxed = (SchedXactionEditorDialog*)d; - SplitRegister *splitreg; - Transaction *t; - - DEBUG( "FIXME: sxe_register_record_cb called\n" ); - - splitreg = gnc_ledger_display_get_split_register( sxed->ledger ); - t = gnc_split_register_get_current_trans( splitreg ); - if ( ! gnc_split_register_save( splitreg, TRUE ) ) - return; - - /* clipped "if (t) - * gnc_reg_incl_date( splitreg, trans_get_date(trans) )" */ - - gnc_split_register_redraw( splitreg ); -} -#endif - -#if 0 -static -void -sxe_register_redraw_all_cb( GnucashRegister *reg, gpointer d ) -{ - DEBUG( "FIXME: sxe_register_redraw_all_cb called\n" ); -} -#endif - static void sxed_reg_recordCB( GtkWidget *w, gpointer d ) @@ -1593,166 +1791,6 @@ refactor_transaction_delete_toggle_cb(GtkToggleButton *button, gpointer data) gtk_editable_insert_text(GTK_EDITABLE(text), s, strlen(s), &pos); } -/* FIXME */ -#if 0 /* removed 2002.05.29 by jsled to remove compilation warnings after - * gncRegWidget addition. */ -static DeleteType -refactor_transaction_delete_query(GtkWindow *parent) -{ - GtkWidget *dialog; - GtkWidget *dvbox; - GtkWidget *frame; - GtkWidget *vbox; - GtkWidget *trans_button; - GtkWidget *splits_button; - GtkWidget *text; - GSList *group; - gint pos = 0; - gint result; - - const char *usual = _("This selection will delete the whole " - "transaction. This is what you usually want."); - const char *warn = _("Warning: Just deleting all the splits will " - "make your account unbalanced. You probably " - "shouldn't do this unless you're going to " - "immediately add another split to bring the " - "transaction back into balance."); - - DeleteType return_value; - - dialog = gnome_dialog_new(_("Delete Transaction"), - GNOME_STOCK_BUTTON_OK, - GNOME_STOCK_BUTTON_CANCEL, - NULL); - - gnome_dialog_set_default(GNOME_DIALOG(dialog), 0); - gnome_dialog_close_hides(GNOME_DIALOG(dialog), TRUE); - gnome_dialog_set_parent(GNOME_DIALOG(dialog), parent); - - dvbox = GNOME_DIALOG(dialog)->vbox; - - frame = gtk_frame_new(NULL); - gtk_container_border_width(GTK_CONTAINER(frame), 5); - - vbox = gtk_vbox_new(TRUE, 3); - gtk_container_border_width(GTK_CONTAINER(vbox), 5); - gtk_container_add(GTK_CONTAINER(frame), vbox); - - text = gtk_text_new(NULL, NULL); - - trans_button = - gtk_radio_button_new_with_label(NULL, - _("Delete the whole transaction")); - gtk_object_set_user_data(GTK_OBJECT(trans_button), text); - gtk_box_pack_start(GTK_BOX(vbox), trans_button, TRUE, TRUE, 0); - - gtk_signal_connect(GTK_OBJECT(trans_button), "toggled", - GTK_SIGNAL_FUNC(refactor_transaction_delete_toggle_cb), - (gpointer) usual); - - group = gtk_radio_button_group(GTK_RADIO_BUTTON(trans_button)); - splits_button = gtk_radio_button_new_with_label(group, - _("Delete all the splits")); - gtk_object_set_user_data(GTK_OBJECT(splits_button), text); - gtk_box_pack_start(GTK_BOX(vbox), splits_button, TRUE, TRUE, 0); - - gtk_signal_connect(GTK_OBJECT(splits_button), "toggled", - GTK_SIGNAL_FUNC(refactor_transaction_delete_toggle_cb), - (gpointer) warn); - - gtk_box_pack_start(GTK_BOX(dvbox), frame, TRUE, TRUE, 0); - - gtk_editable_insert_text(GTK_EDITABLE(text), usual, strlen(warn), &pos); - gtk_text_set_line_wrap(GTK_TEXT(text), TRUE); - gtk_text_set_word_wrap(GTK_TEXT(text), TRUE); - gtk_text_set_editable(GTK_TEXT(text), FALSE); - gtk_box_pack_start(GTK_BOX(dvbox), text, FALSE, FALSE, 0); - - gtk_widget_show_all(dvbox); - - result = gnome_dialog_run_and_close(GNOME_DIALOG(dialog)); - - if (result != 0) - return_value = DELETE_CANCEL; - else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(trans_button))) - return_value = DELETE_TRANS; - else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(splits_button))) - return_value = DELETE_SPLITS; - else - return_value = DELETE_CANCEL; - - gtk_widget_destroy(dialog); - - return return_value; -} - -static -void -sxed_reg_duplicateCB( GtkWidget *w, gpointer d ) -{ - gnc_split_register_duplicate_current ( - gnc_ledger_display_get_split_register ( - ((SchedXactionEditorDialog*)d)->ledger)); -} - -static -void -sxed_reg_expand_trans_checkCB( GtkWidget *w, gpointer d ) -{ - SchedXactionEditorDialog *sxed = d; - - gnc_split_register_expand_current_trans - (gnc_ledger_display_get_split_register (sxed->ledger), - GTK_CHECK_MENU_ITEM (w)->active ); -} - -static -void -refactor_jump_to_blank( GNCLedgerDisplay *ledger, - GnucashRegister *gncReg ) -{ - SplitRegister *reg = gnc_ledger_display_get_split_register (ledger); - VirtualCellLocation vcell_loc; - Split *blank; - - blank = gnc_split_register_get_blank_split (reg); - if (blank == NULL) - return; - - if (gnc_split_register_get_split_virt_loc (reg, blank, &vcell_loc)) - gnucash_register_goto_virt_cell (gncReg, vcell_loc); -} - -static -void -sxed_reg_new_transCB( GtkWidget *w, gpointer d ) -{ - SchedXactionEditorDialog *sxed = d; - SplitRegister *reg; - - reg = gnc_ledger_display_get_split_register (sxed->ledger); - - if (gnc_split_register_save (reg, TRUE)) - gnc_split_register_redraw (reg); - - refactor_jump_to_blank( sxed->ledger, sxed->reg ); -} - -static -void -sxed_reg_jumpCB( GtkWidget *w, gpointer d ) -{ - /* FIXME This one gets funky because of the accounts stored in - * the kvp-frames */ -} - -static -void -sxed_reg_xferCB( GtkWidget *w, gpointer d ) -{ - /* FIXME: should use a "templatized" xfer dlg. */ -} -#endif /* 0 -- removed 2002.05.29 ... */ /********************************************************************\ * gnc_register_check_close * diff --git a/src/gnome/dialog-sxsincelast.c b/src/gnome/dialog-sxsincelast.c index 4f0645c58b..e95cad2333 100644 --- a/src/gnome/dialog-sxsincelast.c +++ b/src/gnome/dialog-sxsincelast.c @@ -894,12 +894,6 @@ sxsincelast_init( sxSinceLastData *sxsld ) sxsincelast_close_handler, sxsld->sincelast_window ); -#if 0 /* FIXME: need to be fixed because 'show-test' removal, b0rk them all. */ - gtk_signal_connect( GTK_OBJECT(sxsld->sincelast_window), "map", - GTK_SIGNAL_FUNC( show_test ), sxsld ); - gtk_signal_connect( GTK_OBJECT(sxsld->sincelast_window), "realize", - GTK_SIGNAL_FUNC( show_test ), sxsld ); -#endif /* 0 */ gtk_signal_connect( GTK_OBJECT(sxsld->sincelast_window), "destroy", GTK_SIGNAL_FUNC( sxsincelast_destroy ), sxsld ); @@ -1171,11 +1165,6 @@ add_to_create_list_to_gui( GList *toCreateList, sxSinceLastData *sxsld ) /* FIXME: Simulate a 'next' button press to get the right "first * thing" hilighted */ -#if 0 - if ( sxsld->tcl_row > 0 ) { - gtk_clist_select_row( clist, 0, 0 ); - } -#endif /* 0 */ } static void @@ -1295,6 +1284,7 @@ processSelectedReminderList( GList *goodList, sxSinceLastData *sxsld ) gboolean autoCreateOpt, notifyOpt; tct = NULL; + act = NULL; for ( ; goodList ; goodList = goodList->next ) { rit = (reminderInstanceTuple*)goodList->data; @@ -1625,10 +1615,6 @@ create_each_transaction_helper( Transaction *t, void *d ) /* FIXME: when we copy the trans_onto_trans, we don't want to copy the Split's kvp_frames... */ -#if 0 - DEBUG( "I'm seeing Transaction \"%s\"", xaccTransGetDescription( t ) ); -#endif /* 0 */ - createUD = (createData*)d; tci = createUD->tci; @@ -1657,10 +1643,6 @@ create_each_transaction_helper( Transaction *t, void *d ) will, but I'd rather not have to count on it. --jsled */ split_kvpf = xaccSplitGetSlots( (Split*)osList->data ); -#if 0 - DEBUG( "\tProcessing Split \"%s\"", xaccSplitGetMemo( split ) ); - DEBUG( "\tkvp_frame: %s\n", kvp_frame_to_string( split_kvpf ) ); -#endif /* 0 */ /* from-transaction of splits */ /* This needs to be before the value setting [below] so the @@ -2295,72 +2277,6 @@ processed_valid_reminders_listP( sxSinceLastData *sxsld ) badRecentRun = NULL; } } -#if 0 - /* ================================================== */ - - if ( xaccSchedXactionGetName( rt->sx ) != rtName ) { - if ( rtName != NULL ) { - /* Deal with previous sequence. */ - overallOkFlag &= - inform_or_add( reminderListPtr, - prevRT, okFlag, - badList, &goodList ); - } - - /* Reset loop state vars */ - okFlag = prevState = TRUE; - rtName = xaccSchedXactionGetName( rt->sx ); - - /* Cleanup */ - if ( badList != NULL ) { - g_list_free( badList ); - } - if ( badRecentRun != NULL ) { - g_list_free( badRecentRun ); - } - badList = badRecentRun = NULL; - } - - /* If we haven't seen an inconsistency, then we're still ok. - * "inconsistency": we can go from [isSelected ==] TRUE to - * FALSE, but not back again [w/in a SX sequence, which we - * are [by the outer loop]]. */ - if ( prevState ) { - prevState = rt->isSelected; - if ( ! rt->isSelected ) { - badRecentRun = - g_list_append( badRecentRun, rt ); - } - } else { - if ( rt->isSelected ) { - okFlag = FALSE; - if ( g_list_length( badRecentRun ) > 0 ) { - badList = - g_list_concat( badList, - badRecentRun ); - badRecentRun = NULL; - } - } else { - badRecentRun = - g_list_append( badRecentRun, rt ); - } - - } - - reminderListPtr = reminderListPtr->next; - } - - /* Deal with final sequence. */ - if ( rtName != NULL ) { - overallOkFlag &= inform_or_add( sxsld->reminderList, - rt, okFlag, - badList, &goodList ); - } - - /* cleanup */ - g_list_free( badList ); - g_list_free( badRecentRun ); -#endif /* 0 */ /* Handle implications of above logic. */ if ( !overallOkFlag ) { @@ -2493,14 +2409,6 @@ create_autoCreate_ledger( sxSinceLastData *sxsld ) gtk_box_pack_start( GTK_BOX(vbox), toolbar, FALSE, FALSE, 2 ); gtk_box_pack_end( GTK_BOX(vbox), GTK_WIDGET(sxsld->ac_regWidget), TRUE, TRUE, 2 ); -#if 0 - gtk_signal_connect( GTK_OBJECT(sxed->dialog), "activate_cursor", - GTK_SIGNAL_FUNC(sxe_register_record_cb), sxed ); - gtk_signal_connect( GTK_OBJECT(sxed->dialog), "redraw_all", - GTK_SIGNAL_FUNC(sxe_register_redraw_all_cb), sxed ); - -#endif /* 0 */ - /* FIXME: we should do all the happy-fun register stuff... button bar * controls ... popups ... */ @@ -2548,13 +2456,6 @@ create_created_ledger( sxSinceLastData *sxsld ) gtk_box_pack_start( GTK_BOX(vbox), toolbar, FALSE, FALSE, 2 ); gtk_box_pack_end( GTK_BOX(vbox), GTK_WIDGET(sxsld->created_regWidget), TRUE, TRUE, 2 ); -#if 0 - gtk_signal_connect( GTK_OBJECT(sxed->dialog), "activate_cursor", - GTK_SIGNAL_FUNC(sxe_register_record_cb), sxed ); - gtk_signal_connect( GTK_OBJECT(sxed->dialog), "redraw_all", - GTK_SIGNAL_FUNC(sxe_register_redraw_all_cb), sxed ); - -#endif /* 0 */ /* FIXME: we should do all the happy-fun register stuff... button bar * controls ... popups ... */ diff --git a/src/register/ledger-core/gnc-regwidget.c b/src/register/ledger-core/gnc-regwidget.c index b77791cd3b..19105dc380 100644 --- a/src/register/ledger-core/gnc-regwidget.c +++ b/src/register/ledger-core/gnc-regwidget.c @@ -150,11 +150,11 @@ gnc_regWidget_new( GNCLedgerDisplay *ld, GtkWindow *win ) GNCRegWidget *rw; rw = GNC_REGWIDGET( gtk_type_new( gnc_regWidget_get_type() ) ); /* IMPORTANT: If we set this to anything other than GTK_RESIZE_QUEUE, we - * enter into a very bad back-and-forth between the sheet and the druid [in - * certain conditions and circumstances not detailed here], causing in - * either a single instance of the druid resizing or infinite instances of - * the druid resizing without bound. Contact jsled@asynchronous.org for - * details. -- 2002.04.15 + * enter into a very bad back-and-forth between the sheet and a containing + * GnomeDruid [in certain conditions and circumstances not detailed here], + * resulting in either a single instance of the Druid resizing or infinite + * instances of the Druid resizing without bound. Contact + * jsled@asynchronous.org for details. -- 2002.04.15 */ gtk_container_set_resize_mode( GTK_CONTAINER( rw ), GTK_RESIZE_QUEUE ); gnc_regWidget_init2( rw, ld, win ); @@ -211,11 +211,6 @@ gnc_regWidget_new( GNCLedgerDisplay *ld, GtkWindow *win ) #include "messages.h" #include "table-allgui.h" -#if 0 -static int last_width = 0; -static int last_stock_width = 0; -#endif - /** PROTOTYPES ******************************************************/ static void gnc_register_redraw_all_cb (GnucashRegister *g_reg, gpointer data); static void gnc_register_redraw_help_cb (GnucashRegister *g_reg, @@ -609,16 +604,13 @@ gnc_register_jump_to_blank (GNCRegWidget *rw) static void expand_ent_cb (GNCRegWidget *rw, gpointer data) { -#if 0 - GtkWidget *widget = data; -#endif gboolean expand; SplitRegister *reg; reg = gnc_ledger_display_get_split_register (rw->ledger); #if 0 - /* jsled: this isn't true. */ + /* this isn't true. --jsled */ expand = GTK_TOGGLE_BUTTON (widget)->active; #else expand = TRUE; @@ -627,7 +619,7 @@ expand_ent_cb (GNCRegWidget *rw, gpointer data) gnc_split_register_expand_current_trans (reg, expand); } -/* jsled: default handler */ +/* default handler --jsled */ static void new_trans_cb (GNCRegWidget *rw, gpointer data) { @@ -1082,12 +1074,6 @@ gnc_register_record (GNCRegWidget *rw) if (!gnc_split_register_save (reg, TRUE)) return; -#if 0 - if (trans != NULL) - gnc_register_include_date (rw, xaccTransGetDate(trans)); -#endif /* 0 */ - - /*gnc_split_register_redraw (reg);*/ gnc_ledger_display_refresh( rw->ledger ); } @@ -1177,11 +1163,8 @@ static gboolean gnc_register_delete_cb(GtkWidget *widget, GdkEvent *event, gpointer data) { GNCRegWidget *rw = data; - DEBUG( "gnc_reg[widget]_delete_cb in" ); gnc_register_check_close (rw); - gnc_ledger_display_close (rw->ledger); - DEBUG("gnc_reg[widget]_delete_cb out [true]"); return FALSE; /* let the user handle correctly. */ } @@ -1192,13 +1175,9 @@ gnc_register_destroy_cb(GtkWidget *widget, gpointer data) GNCRegWidget *rw = GNC_REGWIDGET(widget); SCM id; - DEBUG( "Got gnc_regwidget_destroy cb" ); gnc_ledger_display_close (rw->ledger); - id = rw->toolbar_change_callback_id; gnc_unregister_option_change_callback_id(id); - - DEBUG ("destroyed GNCRegWidget"); } /* jsled: what to do? */ @@ -1389,36 +1368,6 @@ gnc_regWidget_init2( GNCRegWidget *rw, GNCLedgerDisplay *ledger, GtkWindow *win } #endif /* 0 */ - /* jsled: FIXME: prefix && loading/saving window state - * Some argument can be made that this is the caller's responsibility. - */ -#if 0 - { - int *width; - char *prefix; - - switch (reg->type) - { - case STOCK_REGISTER: - case PORTFOLIO_LEDGER: - case CURRENCY_REGISTER: - prefix = "reg_stock_win"; - width = &last_stock_width; - break; - - default: - prefix = "reg_win"; - width = &last_width; - break; - } - - if (*width == 0) - gnc_get_window_size (prefix, width, NULL); - - gtk_window_set_default_size (GTK_WINDOW(win), *width, 0); - } -#endif /* 0 */ - gtk_widget_show_all (GTK_WIDGET(rw)); gnc_split_register_show_present_divider (reg, TRUE); @@ -1505,38 +1454,6 @@ gnc_register_redraw_help_cb (GnucashRegister *g_reg, gpointer data) g_free (help); } -#if 0 -/* jsled: window-manip. */ -static void -gnc_reg_save_size (RegWindow *regData) -{ - SplitRegister *reg; - int *width; - char *prefix; - - reg = gnc_ledger_display_get_split_register (regData->ledger); - - switch (reg->type) - { - case STOCK_REGISTER: - case PORTFOLIO_LEDGER: - case CURRENCY_REGISTER: - prefix = "reg_stock_win"; - width = &last_stock_width; - break; - default: - prefix = "reg_win"; - width = &last_width; - break; - } - - gdk_window_get_geometry (regData->window->window, NULL, NULL, - width, NULL, NULL); - - gnc_save_window_size (prefix, *width, 0); -} -#endif /* 0 */ - /********************************************************************\ * regDestroy() \********************************************************************/ @@ -1546,25 +1463,16 @@ regDestroy (GNCLedgerDisplay *ledger) { GNCRegWidget *rw = gnc_ledger_display_get_user_data (ledger); - DEBUG("regDestroy"); - if (rw) { SplitRegister *reg; - /* jsled: FIXME */ -#if 0 - gnc_reg_save_size (rw); -#endif /* 0 */ - reg = gnc_ledger_display_get_split_register (ledger); if (reg && reg->table) gnc_table_save_state (reg->table); } - - DEBUG("regDestroy out"); gnc_ledger_display_set_user_data (ledger, NULL); } @@ -1666,39 +1574,6 @@ pasteTransCB (GtkWidget *w, gpointer data) (gnc_ledger_display_get_split_register (rw->ledger)); } - -#if 0 -static gboolean -gnc_register_include_date(RegWindow *regData, time_t date) -{ - RegDateWindow *regDateData; - time_t start, end; - gboolean changed = FALSE; - - regDateData = regData->date_window; - - start = gnc_date_edit_get_date(GNC_DATE_EDIT(regDateData->start_date)); - end = gnc_date_edit_get_date(GNC_DATE_EDIT(regDateData->end_date)); - - if (date < start) - { - gnc_date_edit_set_time(GNC_DATE_EDIT(regDateData->start_date), date); - changed = TRUE; - } - - if (date > end) - { - gnc_date_edit_set_time(GNC_DATE_EDIT(regDateData->end_date), date); - changed = TRUE; - } - - if (changed) - gnc_register_set_date_range(regData); - - return changed; -} -#endif /* 0 */ - /********************************************************************\ * recordCB * * * diff --git a/src/register/ledger-core/gnc-regwidget.h b/src/register/ledger-core/gnc-regwidget.h index 248e222f73..8bafb4f311 100644 --- a/src/register/ledger-core/gnc-regwidget.h +++ b/src/register/ledger-core/gnc-regwidget.h @@ -41,8 +41,9 @@ struct _GNCRegWidget { /* The "parent" widget */ GtkVBox vbox; - /* Top level window */ - /* jsled: used by the jump cbs; can we get by w/o knowing this? inv. layering */ + /* Top level/containing window */ + /* jsled: used by the jump cbs; can we get by w/o knowing this? investigate + * layering */ GtkWidget * window; gint width; gint height;