static guint sxftd_compute_sx(SXFromTransInfo *sxfti) { gchar *name; GDate date; GList *schedule = NULL; getEndTuple end_info; guint sxftd_errno = 0; /* 0 == OK, > 0 means dialog needs to be run again */ SchedXaction *sx = sxfti->sx; /* get the name */ name = gtk_editable_get_chars(GTK_EDITABLE(sxfti->name), 0, -1); xaccSchedXactionSetName(sx, name); g_free(name); gnc_gdate_set_time64( &date, gnc_date_edit_get_date( sxfti->startDateGDE ) ); sxftd_update_schedule(sxfti, &date, &schedule); if (sxftd_errno == 0) { gnc_sx_set_schedule(sx, schedule); xaccSchedXactionSetStartDate( sx, &date ); } end_info = sxftd_get_end_info(sxfti); switch (end_info.type) { case NEVER_END: break; case END_ON_DATE: xaccSchedXactionSetEndDate(sx, &(end_info.end_date)); break; case END_AFTER_N_OCCS: xaccSchedXactionSetNumOccur(sx, end_info.n_occurrences); break; default: sxftd_errno = 2; break; } gnc_sx_set_instance_count( sx, 1 ); /* Set the autocreate, days-in-advance and remind-in-advance values from * options. */ { gboolean autoCreateState, notifyState; gint daysInAdvance; autoCreateState = gnc_prefs_get_bool (GNC_PREFS_GROUP_SXED, GNC_PREF_CREATE_AUTO); notifyState = gnc_prefs_get_bool (GNC_PREFS_GROUP_SXED, GNC_PREF_NOTIFY); xaccSchedXactionSetAutoCreate( sx, autoCreateState, (autoCreateState & notifyState) ); daysInAdvance = gnc_prefs_get_float (GNC_PREFS_GROUP_SXED, GNC_PREF_CREATE_DAYS); xaccSchedXactionSetAdvanceCreation( sx, daysInAdvance ); daysInAdvance = gnc_prefs_get_float (GNC_PREFS_GROUP_SXED, GNC_PREF_REMIND_DAYS); xaccSchedXactionSetAdvanceReminder( sx, daysInAdvance ); } if ( sxftd_add_template_trans( sxfti ) != 0 ) { sxftd_errno = SXFTD_ERRNO_UNBALANCED_XACTION; } return sxftd_errno; }
/** * Update the example calendar; make sure to take into account the end * specification. **/ static void sxftd_update_example_cal( SXFromTransInfo *sxfti ) { struct tm *tmpTm; time64 tmp_tt; GDate date, startDate, nextDate; GList *schedule = NULL; getEndTuple get; get = sxftd_get_end_info( sxfti ); tmp_tt = gnc_date_edit_get_date( sxfti->startDateGDE ); gnc_gdate_set_time64 (&date, tmp_tt); sxftd_update_schedule(sxfti, &date, &schedule); /* go one day before what's in the box so we can get the correct start * date. */ startDate = date; g_date_subtract_days(&date, 1); g_date_clear(&nextDate, 1); recurrenceListNextInstance(schedule, &date, &nextDate); { gchar *name; /* get the name */ name = NULL; name = gtk_editable_get_chars(GTK_EDITABLE(sxfti->name), 0, -1); gnc_dense_cal_store_update_name(sxfti->dense_cal_model, name); g_free(name); } { gchar *schedule_desc; schedule_desc = recurrenceListToCompactString(schedule); gnc_dense_cal_store_update_info(sxfti->dense_cal_model, schedule_desc); g_free(schedule_desc); } /* Set End date sensitivity */ gtk_widget_set_sensitive( GTK_WIDGET(sxfti->endDateGDE), (get.type == END_ON_DATE) ); gtk_widget_set_sensitive( GTK_WIDGET(sxfti->n_occurences), (get.type == END_AFTER_N_OCCS) ); /* Use the day preceding the start date for the store to find the correct real start date */ switch (get.type) { case NEVER_END: gnc_dense_cal_store_update_recurrences_no_end(sxfti->dense_cal_model, &date, schedule); break; case END_ON_DATE: gnc_dense_cal_store_update_recurrences_date_end(sxfti->dense_cal_model, &date, schedule, &get.end_date); break; case END_AFTER_N_OCCS: gnc_dense_cal_store_update_recurrences_count_end(sxfti->dense_cal_model, &date, schedule, get.n_occurrences); break; default: g_warning("unknown get.type [%d]\n", get.type); break; } gnc_dense_cal_set_month( sxfti->example_cal, g_date_get_month( &startDate ) ); gnc_dense_cal_set_year( sxfti->example_cal, g_date_get_year( &startDate ) ); recurrenceListFree(&schedule); }
/** * Update the example calendar; make sure to take into account the end * specification. **/ static void sxftd_update_example_cal( SXFromTransInfo *sxfti ) { struct tm *tmpTm; time_t tmp_tt; GDate date, startDate, nextDate; GList *schedule = NULL; getEndTuple get; get = sxftd_get_end_info( sxfti ); tmp_tt = gnc_date_edit_get_date( sxfti->startDateGDE ); tmpTm = g_new0( struct tm, 1 ); *tmpTm = *localtime( &tmp_tt ); g_date_clear(&date, 1); g_date_set_day( &date, tmpTm->tm_mday ); g_date_set_month( &date, tmpTm->tm_mon + 1 ); g_date_set_year( &date, tmpTm->tm_year + 1900 ); g_free( tmpTm ); sxftd_update_schedule(sxfti, &date, &schedule); /* go one day before what's in the box so we can get the correct start * date. */ startDate = date; g_date_subtract_days(&date, 1); g_date_clear(&nextDate, 1); recurrenceListNextInstance(schedule, &date, &nextDate); { GtkWidget *w; gchar *name; /* get the name */ w = glade_xml_get_widget(sxfti->gxml, SXFTD_NAME_ENTRY); name = gtk_editable_get_chars(GTK_EDITABLE(w), 0, -1); gnc_dense_cal_store_update_name(sxfti->dense_cal_model, name); g_free(name); } { gchar *schedule_desc; schedule_desc = recurrenceListToCompactString(schedule); gnc_dense_cal_store_update_info(sxfti->dense_cal_model, schedule_desc); g_free(schedule_desc); } switch (get.type) { case NEVER_END: gnc_dense_cal_store_update_recurrences_no_end(sxfti->dense_cal_model, &startDate, schedule); break; case END_ON_DATE: gnc_dense_cal_store_update_recurrences_date_end(sxfti->dense_cal_model, &startDate, schedule, &get.end_date); break; case END_AFTER_N_OCCS: gnc_dense_cal_store_update_recurrences_count_end(sxfti->dense_cal_model, &startDate, schedule, get.n_occurrences); break; default: g_warning("unknown get.type [%d]\n", get.type); break; } gnc_dense_cal_set_month( sxfti->example_cal, g_date_get_month( &startDate ) ); gnc_dense_cal_set_year( sxfti->example_cal, g_date_get_year( &startDate ) ); recurrenceListFree(&schedule); }