r17751 - gnucash/trunk/src - Revert r17730 and re-apply r17725, "Bug #106401: Add SX weekend occurence to be shifted to weekdays"

Christian Stimming cstim at cvs.gnucash.org
Sat Dec 6 16:54:16 EST 2008


Author: cstim
Date: 2008-12-06 16:54:16 -0500 (Sat, 06 Dec 2008)
New Revision: 17751
Trac: http://svn.gnucash.org/trac/changeset/17751

Modified:
   gnucash/trunk/src/backend/file/gnc-freqspec-xml-v2.c
   gnucash/trunk/src/backend/file/gnc-recurrence-xml-v2.c
   gnucash/trunk/src/gnome-utils/gnc-frequency.c
   gnucash/trunk/src/gnome/glade/sched-xact.glade
Log:
Revert r17730 and re-apply r17725, "Bug #106401: Add SX weekend occurence to be shifted to weekdays"

This time, the XML element handler for the "weekend adjustment" is optional
so that old files without that element are read without error.

Patch (well, kind of) by Simon Arlott.

Modified: gnucash/trunk/src/backend/file/gnc-freqspec-xml-v2.c
===================================================================
--- gnucash/trunk/src/backend/file/gnc-freqspec-xml-v2.c	2008-12-06 21:54:08 UTC (rev 17750)
+++ gnucash/trunk/src/backend/file/gnc-freqspec-xml-v2.c	2008-12-06 21:54:16 UTC (rev 17751)
@@ -245,6 +245,20 @@
 
 static
 gboolean
+fs_weekend_adj_handler( xmlNodePtr node, gpointer data )
+{
+        fsParseData *fspd = data;
+        gboolean        ret;
+        gint64          foo;
+        ret = dom_tree_to_integer( node, &foo );
+        if ( !ret )
+                return ret;
+        fspd->weekend_adj = foo;
+        return TRUE;
+}
+
+static
+gboolean
 fs_subelement_handler( xmlNodePtr node, gpointer data )
 {
         fsParseData *fspd = data;
@@ -273,13 +287,14 @@
 }
 
 struct dom_tree_handler fs_union_dom_handlers[] = {
-        { "fs:date",       fs_date_handler,       0, 0 },
-        { "fs:interval",   fs_interval_handler,   0, 0 },
-        { "fs:offset",     fs_offset_handler,     0, 0 },
-        { "fs:day",        fs_day_handler,        0, 0 },
-        { "fs:weekday",    fs_weekday_handler,    0, 0 },
-        { "fs:occurrence", fs_occurrence_handler, 0, 0 },
-        { "gnc:freqspec",  fs_subelement_handler, 0, 0 },
+        { "fs:date",        fs_date_handler,        0, 0 },
+        { "fs:interval",    fs_interval_handler,    0, 0 },
+        { "fs:offset",      fs_offset_handler,      0, 0 },
+        { "fs:day",         fs_day_handler,         0, 0 },
+        { "fs:weekday",     fs_weekday_handler,     0, 0 },
+        { "fs:occurrence",  fs_occurrence_handler,  0, 0 },
+        { "fs:weekend_adj", fs_weekend_adj_handler, 0, 0 },
+        { "gnc:freqspec",   fs_subelement_handler,  0, 0 },
         { NULL, NULL, 0, 0 },
 };
 

Modified: gnucash/trunk/src/backend/file/gnc-recurrence-xml-v2.c
===================================================================
--- gnucash/trunk/src/backend/file/gnc-recurrence-xml-v2.c	2008-12-06 21:54:08 UTC (rev 17750)
+++ gnucash/trunk/src/backend/file/gnc-recurrence-xml-v2.c	2008-12-06 21:54:16 UTC (rev 17751)
@@ -47,6 +47,7 @@
 #define recurrence_mult          "recurrence:mult"
 #define recurrence_period_type   "recurrence:period_type"
 #define recurrence_start         "recurrence:start"
+#define recurrence_weekend_adj   "recurrence:weekend_adj"
 
 //TODO: I think three of these functions rightly belong in Recurrence.c.
 
@@ -83,10 +84,25 @@
     return dom_tree_to_guint16(node, &((Recurrence *)r)->mult);
 }
 
+static gboolean
+recurrence_weekend_adj_handler(xmlNodePtr node, gpointer d)
+{
+    WeekendAdjust wadj;
+    char *nodeTxt;
+
+    nodeTxt = dom_tree_to_text(node);
+    g_return_val_if_fail(nodeTxt, FALSE);
+    wadj= recurrenceWeekendAdjustFromString(nodeTxt);
+    ((Recurrence *) d)->wadj = wadj;
+    g_free(nodeTxt);
+    return (wadj != -1);
+}
+
 static struct dom_tree_handler recurrence_dom_handlers[] = {
     { recurrence_mult, recurrence_mult_handler, 1, 0 },
     { recurrence_period_type, recurrence_period_type_handler, 1, 0 },
     { recurrence_start, recurrence_start_date_handler, 1, 0 },
+    { recurrence_weekend_adj, recurrence_weekend_adj_handler, 0, 0 },
     { NULL, NULL, 0, 0 }
 };
 
@@ -113,6 +129,7 @@
     xmlNodePtr n;
     PeriodType pt;
     GDate d;
+    WeekendAdjust wadj;
 
     n = xmlNewNode(NULL, tag);
     xmlSetProp(n, "version", recurrence_version_string );
@@ -123,5 +140,8 @@
                                     recurrencePeriodTypeToString(pt)));
     d = recurrenceGetDate(r);
     xmlAddChild(n, gdate_to_dom_tree(recurrence_start, &d));
+    wadj = recurrenceGetWeekendAdjust(r);
+    xmlAddChild(n, text_to_dom_tree(recurrence_weekend_adj,
+                                    recurrenceWeekendAdjustToString(wadj)));
     return n;
 }

Modified: gnucash/trunk/src/gnome/glade/sched-xact.glade
===================================================================
--- gnucash/trunk/src/gnome/glade/sched-xact.glade	2008-12-06 21:54:08 UTC (rev 17750)
+++ gnucash/trunk/src/gnome/glade/sched-xact.glade	2008-12-06 21:54:16 UTC (rev 17751)
@@ -1892,6 +1892,47 @@
 			      <property name="fill">True</property>
 			    </packing>
 			  </child>
+
+			  <child>
+			    <widget class="GtkLabel" id="label847751">
+			      <property name="visible">True</property>
+			      <property name="label" translatable="yes">except on weekends:</property>
+			      <property name="use_underline">False</property>
+			      <property name="use_markup">False</property>
+			      <property name="justify">GTK_JUSTIFY_RIGHT</property>
+			      <property name="wrap">False</property>
+			      <property name="selectable">False</property>
+			      <property name="xalign">1</property>
+			      <property name="yalign">0.5</property>
+			      <property name="xpad">0</property>
+			      <property name="ypad">0</property>
+			      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+			      <property name="width_chars">-1</property>
+			      <property name="single_line_mode">False</property>
+			      <property name="angle">0</property>
+			    </widget>
+			    <packing>
+			      <property name="padding">2</property>
+			      <property name="expand">False</property>
+			      <property name="fill">True</property>
+			    </packing>
+			  </child>
+
+			  <child>
+			    <widget class="GtkComboBox" id="semimonthly_first_weekend">
+			      <property name="visible">True</property>
+			      <property name="items" translatable="yes">No change
+Use previous weekday
+Use next weekday</property>
+			      <property name="add_tearoffs">False</property>
+			      <property name="focus_on_click">True</property>
+			    </widget>
+			    <packing>
+			      <property name="padding">0</property>
+			      <property name="expand">False</property>
+			      <property name="fill">False</property>
+			    </packing>
+			  </child>
 			</widget>
 			<packing>
 			  <property name="padding">3</property>
@@ -1982,6 +2023,47 @@
 			      <property name="fill">False</property>
 			    </packing>
 			  </child>
+
+			  <child>
+			    <widget class="GtkLabel" id="label847752">
+			      <property name="visible">True</property>
+			      <property name="label" translatable="yes">except on weekends:</property>
+			      <property name="use_underline">False</property>
+			      <property name="use_markup">False</property>
+			      <property name="justify">GTK_JUSTIFY_RIGHT</property>
+			      <property name="wrap">False</property>
+			      <property name="selectable">False</property>
+			      <property name="xalign">1</property>
+			      <property name="yalign">0.5</property>
+			      <property name="xpad">0</property>
+			      <property name="ypad">0</property>
+			      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+			      <property name="width_chars">-1</property>
+			      <property name="single_line_mode">False</property>
+			      <property name="angle">0</property>
+			    </widget>
+			    <packing>
+			      <property name="padding">2</property>
+			      <property name="expand">False</property>
+			      <property name="fill">True</property>
+			    </packing>
+			  </child>
+
+			  <child>
+			    <widget class="GtkComboBox" id="semimonthly_second_weekend">
+			      <property name="visible">True</property>
+			      <property name="items" translatable="yes">No change
+Use previous weekday
+Use next weekday</property>
+			      <property name="add_tearoffs">False</property>
+			      <property name="focus_on_click">True</property>
+			    </widget>
+			    <packing>
+			      <property name="padding">0</property>
+			      <property name="expand">False</property>
+			      <property name="fill">False</property>
+			    </packing>
+			  </child>
 			</widget>
 			<packing>
 			  <property name="padding">3</property>
@@ -2202,16 +2284,57 @@
 			      <property name="fill">False</property>
 			    </packing>
 			  </child>
+
+			  <child>
+			    <widget class="GtkLabel" id="label847750">
+			      <property name="visible">True</property>
+			      <property name="label" translatable="yes">except on weekends:</property>
+			      <property name="use_underline">False</property>
+			      <property name="use_markup">False</property>
+			      <property name="justify">GTK_JUSTIFY_RIGHT</property>
+			      <property name="wrap">False</property>
+			      <property name="selectable">False</property>
+			      <property name="xalign">1</property>
+			      <property name="yalign">0.5</property>
+			      <property name="xpad">0</property>
+			      <property name="ypad">0</property>
+			      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+			      <property name="width_chars">-1</property>
+			      <property name="single_line_mode">False</property>
+			      <property name="angle">0</property>
+			    </widget>
+			    <packing>
+			      <property name="padding">2</property>
+			      <property name="expand">False</property>
+			      <property name="fill">True</property>
+			    </packing>
+			  </child>
+
+			  <child>
+			    <widget class="GtkComboBox" id="monthly_weekend">
+			      <property name="visible">True</property>
+			      <property name="items" translatable="yes">No change
+Use previous weekday
+Use next weekday</property>
+			      <property name="add_tearoffs">False</property>
+			      <property name="focus_on_click">True</property>
+			    </widget>
+			    <packing>
+			      <property name="padding">0</property>
+			      <property name="expand">False</property>
+			      <property name="fill">False</property>
+			    </packing>
+			  </child>
 			</widget>
 			<packing>
-			  <property name="padding">5</property>
+			  <property name="padding">3</property>
 			  <property name="expand">False</property>
 			  <property name="fill">True</property>
 			</packing>
 		      </child>
 		    </widget>
 		    <packing>
-		      <property name="padding">5</property>
+		      <property name="padding">3</property>
 		      <property name="expand">True</property>
 		      <property name="fill">True</property>
 		    </packing>

Modified: gnucash/trunk/src/gnome-utils/gnc-frequency.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-frequency.c	2008-12-06 21:54:08 UTC (rev 17750)
+++ gnucash/trunk/src/gnome-utils/gnc-frequency.c	2008-12-06 21:54:16 UTC (rev 17751)
@@ -412,8 +412,12 @@
 
              dom_combobox = glade_xml_get_widget(gf->gxml, "semimonthly_first");
              gtk_combo_box_set_active(GTK_COMBO_BOX(dom_combobox), _get_monthly_combobox_index(first));
+             dom_combobox = glade_xml_get_widget(gf->gxml, "semimonthly_first_weekend");
+             gtk_combo_box_set_active(GTK_COMBO_BOX(dom_combobox), recurrenceGetWeekendAdjust(first));
              dom_combobox = glade_xml_get_widget(gf->gxml, "semimonthly_second");
              gtk_combo_box_set_active(GTK_COMBO_BOX(dom_combobox), _get_monthly_combobox_index(second));
+             dom_combobox = glade_xml_get_widget(gf->gxml, "semimonthly_second_weekend");
+             gtk_combo_box_set_active(GTK_COMBO_BOX(dom_combobox), recurrenceGetWeekendAdjust(second));
 
              gtk_notebook_set_current_page(gf->nb, PAGE_SEMI_MONTHLY);
              gtk_combo_box_set_active(gf->freqComboBox, PAGE_SEMI_MONTHLY);
@@ -464,7 +468,7 @@
          case PERIOD_YEAR:
          case PERIOD_LAST_WEEKDAY: {
              guint multiplier;
-             GtkWidget *multipler_spin, *day_of_month;
+             GtkWidget *multipler_spin, *day_of_month, *weekend_mode;
              
              multipler_spin = glade_xml_get_widget(gf->gxml, "monthly_spin");
              multiplier = recurrenceGetMultiplier(r);
@@ -474,6 +478,8 @@
 
              day_of_month = glade_xml_get_widget(gf->gxml, "monthly_day");
              gtk_combo_box_set_active(GTK_COMBO_BOX(day_of_month), _get_monthly_combobox_index(r));
+             weekend_mode = glade_xml_get_widget(gf->gxml, "monthly_weekend");
+             gtk_combo_box_set_active(GTK_COMBO_BOX(weekend_mode), recurrenceGetWeekendAdjust(r));
 
              gtk_notebook_set_current_page(gf->nb, PAGE_MONTHLY);
              gtk_combo_box_set_active(gf->freqComboBox, PAGE_MONTHLY);
@@ -507,7 +513,8 @@
     Recurrence *r;
     GtkWidget *day_of_month_combo = glade_xml_get_widget(gf->gxml, combo_name);
     int day_of_month_index = gtk_combo_box_get_active(GTK_COMBO_BOX(day_of_month_combo));
-    int weekend_adjust = WEEKEND_ADJ_NONE;
+    GtkWidget *weekend_adjust_combo = glade_xml_get_widget(gf->gxml, combo_weekend_name);
+    int weekend_adjust = gtk_combo_box_get_active(GTK_COMBO_BOX(weekend_adjust_combo));
         
     r = g_new0(Recurrence, 1);
     if (day_of_month_index > LAST_DAY_OF_MONTH_OPTION_INDEX)



More information about the gnucash-changes mailing list