r15634 - gnucash/trunk/src - Fix "has in-editor sx changed" processing for Recurrences. Fix Cancel checking/behavior. Remove previous never-run "bug fix" as it was actually a bug. :p

Josh Sled jsled at cvs.gnucash.org
Mon Feb 19 17:52:45 EST 2007


Author: jsled
Date: 2007-02-19 17:52:44 -0500 (Mon, 19 Feb 2007)
New Revision: 15634
Trac: http://svn.gnucash.org/trac/changeset/15634

Modified:
   gnucash/trunk/src/doc/sx.rst
   gnucash/trunk/src/engine/Recurrence.c
   gnucash/trunk/src/engine/Recurrence.h
   gnucash/trunk/src/gnome/dialog-sx-editor.c
Log:
Fix "has in-editor sx changed" processing for Recurrences.  Fix Cancel checking/behavior.  Remove previous never-run "bug fix" as it was actually a bug. :p


Modified: gnucash/trunk/src/doc/sx.rst
===================================================================
--- gnucash/trunk/src/doc/sx.rst	2007-02-19 22:22:17 UTC (rev 15633)
+++ gnucash/trunk/src/doc/sx.rst	2007-02-19 22:52:44 UTC (rev 15634)
@@ -133,7 +133,7 @@
       - [x] remove > monthly pages (-> monthly)
     - [x] clean up, reformat source
   - dialog-sx-editor
-    - [ ] gnc_sxed_check_changed
+    - [x] gnc_sxed_check_changed
     - [x] gnc_sxed_check_consistent
     - [x] gnc_sxed_update_cal
     - [x] gnc_sxed_save_sx

Modified: gnucash/trunk/src/engine/Recurrence.c
===================================================================
--- gnucash/trunk/src/engine/Recurrence.c	2007-02-19 22:22:17 UTC (rev 15633)
+++ gnucash/trunk/src/engine/Recurrence.c	2007-02-19 22:52:44 UTC (rev 15634)
@@ -664,3 +664,11 @@
 
     return recurrenceCmp(most_freq_a, most_freq_b);
 }
+
+void
+recurrenceListFree(GList **recurrences)
+{
+    g_list_foreach(*recurrences, (GFunc)g_free, NULL);
+    g_list_free(*recurrences);
+    *recurrences = NULL;
+}

Modified: gnucash/trunk/src/engine/Recurrence.h
===================================================================
--- gnucash/trunk/src/engine/Recurrence.h	2007-02-19 22:22:17 UTC (rev 15633)
+++ gnucash/trunk/src/engine/Recurrence.h	2007-02-19 22:52:44 UTC (rev 15634)
@@ -170,4 +170,6 @@
 int recurrenceCmp(Recurrence *a, Recurrence *b);
 int recurrenceListCmp(GList *a, GList *b);
 
+void recurrenceListFree(GList **recurrence);
+
 #endif  /* RECURRENCE_H */

Modified: gnucash/trunk/src/gnome/dialog-sx-editor.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-sx-editor.c	2007-02-19 22:22:17 UTC (rev 15633)
+++ gnucash/trunk/src/gnome/dialog-sx-editor.c	2007-02-19 22:52:44 UTC (rev 15634)
@@ -222,11 +222,13 @@
     return TRUE;
 }
 
-static
-void
+static void
 editor_cancel_button_clicked( GtkButton *b, GncSxEditorDialog *sxed )
 {
     /* close */
+    if (!sxed_confirmed_cancel(sxed))
+        return;
+
     gnc_close_gui_component_by_data( DIALOG_SCHEDXACTION_EDITOR_CM_CLASS,
                                      sxed );
 }
@@ -270,8 +272,7 @@
  * @return TRUE if this is a 'new' SX, or if the SX has changed from it's
  *   previous configuration.
  **/
-static
-gboolean
+static gboolean
 gnc_sxed_check_changed( GncSxEditorDialog *sxed )
 {
     if ( sxed->newsxP )
@@ -398,35 +399,28 @@
         }
     }
 
-    /* FS, startdate */
     {
-        FreqSpec *dlgFS, *sxFS;
-        GDate dlgStartDate, sxStartDate;
-        GString *dlgFSstr, *sxFSstr;
-        gboolean fsStrCmpResult;
+        GList *dialog_schedule = NULL;
+        GDate dialog_start_date, sx_start_date;
+        gchar *dialog_schedule_str, *sx_schedule_str;
+        gboolean schedules_are_the_same, start_dates_are_the_same;
 
-        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 */
+        g_date_clear(&dialog_start_date, 1);
+        gnc_frequency_save_to_recurrence(sxed->gncfreq, &dialog_schedule, &dialog_start_date);
+        dialog_schedule_str = recurrenceListToString(dialog_schedule);
+        recurrenceListFree(&dialog_schedule);
 
-        fsStrCmpResult = /* lame version of comparison */
-            (strcmp( dlgFSstr->str, sxFSstr->str) != 0);
-        g_string_free( dlgFSstr, TRUE );
-        g_string_free( sxFSstr, TRUE );
-        xaccFreqSpecFree( dlgFS );
+        sx_start_date = *xaccSchedXactionGetStartDate(sxed->sx);
+        sx_schedule_str = recurrenceListToString(gnc_sx_get_schedule(sxed->sx));
 
-        if ( (g_date_compare(&dlgStartDate, &sxStartDate) != 0)
-             ||  fsStrCmpResult ) {
+        schedules_are_the_same = (strcmp(dialog_schedule_str, sx_schedule_str) == 0);
+        g_free(dialog_schedule_str);
+        g_free(sx_schedule_str);
+
+        start_dates_are_the_same = (g_date_compare(&dialog_start_date, &sx_start_date) == 0);
+
+        if (!schedules_are_the_same || !start_dates_are_the_same)
             return TRUE;
-        }
     }
 
     /* template transactions */
@@ -798,7 +792,7 @@
 
     /* deal with time. */
     {
-        GDate startDate, endDate, nextDate, now;
+        GDate startDate, endDate, nextDate;
 
         if ( !gtk_toggle_button_get_active(sxed->optEndDate)
              && !gtk_toggle_button_get_active(sxed->optEndCount)
@@ -839,9 +833,6 @@
 
         }
 
-        g_date_clear(&now, 1);
-        g_date_set_time_t(&now, time(NULL));
-
         g_date_clear( &endDate, 1 );
         if ( gtk_toggle_button_get_active(sxed->optEndDate) ) {
             g_date_set_time_t( &endDate,
@@ -855,12 +846,11 @@
         {
             g_date_subtract_days(&startDate, 1);
             recurrenceListNextInstance(schedule, &startDate, &nextDate);
-            g_list_free(schedule);
         }
+        recurrenceListFree(&schedule);
 
         if (!g_date_valid(&nextDate)
-            || (g_date_valid(&endDate) && (g_date_compare(&nextDate, &endDate) > 0))
-            || (g_date_compare(&nextDate, &now) < 0))
+            || (g_date_valid(&endDate) && (g_date_compare(&nextDate, &endDate) > 0)))
         {
             const char *invalid_sx_check_msg =
                 _("You have attempted to create a Scheduled "
@@ -977,11 +967,16 @@
 
         str = g_string_new( "" );
         xaccFreqSpecGetFreqStr( fs, str );
-        g_debug("fs: %s", str->str);
+        g_debug("freq spec: %s", str->str);
+        g_string_free(str, TRUE);
 
         gnc_frequency_save_to_recurrence(sxed->gncfreq, &schedule, &gdate);
         gnc_sx_set_schedule(sxed->sx, schedule);
-        g_debug("recurrences parsed [%s]", recurrenceListToString(schedule));
+        {
+            gchar *recurrence_str = recurrenceListToCompactString(schedule);
+            g_debug("recurrences parsed [%s]", recurrence_str);
+            g_free(recurrence_str);
+        }
 
         /* now that we have it, set the start date */
         xaccSchedXactionSetStartDate( sxed->sx, &gdate );
@@ -1261,9 +1256,6 @@
     GtkBox *b;
 
     b = GTK_BOX(glade_xml_get_widget( sxed->gxml, "gncfreq_hbox" ));
-    /*sxed->gncfreq =
-      GNC_FREQUENCY( gnc_frequency_new( xaccSchedXactionGetFreqSpec(sxed->sx),
-      xaccSchedXactionGetStartDate(sxed->sx) ) );*/
     sxed->gncfreq =
         GNC_FREQUENCY(gnc_frequency_new_from_recurrence(gnc_sx_get_schedule(sxed->sx),
                                                         xaccSchedXactionGetStartDate(sxed->sx)));
@@ -1596,8 +1588,7 @@
     }
 
 cleanup:
-    g_list_foreach(recurrences, (GFunc)g_free, NULL);
-    g_list_free(recurrences);
+    recurrenceListFree(&recurrences);
 }
 
 static void



More information about the gnucash-changes mailing list