r15510 - gnucash/trunk/src - SX instance model event handling for enabled SXes:

Josh Sled jsled at cvs.gnucash.org
Mon Feb 5 19:14:11 EST 2007


Author: jsled
Date: 2007-02-05 19:14:10 -0500 (Mon, 05 Feb 2007)
New Revision: 15510
Trac: http://svn.gnucash.org/trac/changeset/15510

Modified:
   gnucash/trunk/src/app-utils/gnc-sx-instance-model.c
   gnucash/trunk/src/app-utils/gnc-sx-instance-model.h
   gnucash/trunk/src/app-utils/test/test-sx.c
   gnucash/trunk/src/doc/sx.rst
   gnucash/trunk/src/gnome-utils/test/test-sx.c
   gnucash/trunk/src/gnome/gnc-plugin-page-sx-list.c
Log:
SX instance model event handling for enabled SXes:
- SX instance models properly handle SX update/add/remove events
  with/without enabled transactions.
- New SX editors now show non-enabled transactions
Patch from Peter McAlpine <peter at aoeu.ca>


Modified: gnucash/trunk/src/app-utils/gnc-sx-instance-model.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-sx-instance-model.c	2007-02-05 23:59:39 UTC (rev 15509)
+++ gnucash/trunk/src/app-utils/gnc-sx-instance-model.c	2007-02-06 00:14:10 UTC (rev 15510)
@@ -407,22 +407,31 @@
      GDate *now = g_date_new();
      g_date_clear(now, 1);
      g_date_set_time_t(now, time(NULL));
-     return gnc_sx_get_instances(now);
+     return gnc_sx_get_instances(now, FALSE);
 }
 
 GncSxInstanceModel*
-gnc_sx_get_instances(GDate *range_end)
+gnc_sx_get_instances(GDate *range_end, gboolean include_disabled)
 {
-     GList *enabled_sxes = NULL;
+     GList *all_sxes = gnc_book_get_schedxactions(gnc_get_current_book())->sx_list;
      GncSxInstanceModel *instances;
 
      g_assert(range_end != NULL);
      g_assert(g_date_valid(range_end));
 
+     instances = gnc_sx_instance_model_new();
+     instances->include_disabled = include_disabled;
+     instances->range_end = *range_end;
+
+     if (include_disabled) 
      {
-          GList *all_sxes = gnc_book_get_schedxactions(gnc_get_current_book())->sx_list;
+          instances->sx_instance_list = gnc_g_list_map(all_sxes, (GncGMapFunc)_gnc_sx_gen_instances, range_end);
+     } 
+     else 
+     {
           GList *sx_iter = g_list_first(all_sxes);
-          
+          GList *enabled_sxes = NULL;
+
           for (; sx_iter != NULL; sx_iter = sx_iter->next)
           {
                SchedXaction *sx = (SchedXaction*)sx_iter->data;
@@ -431,14 +440,10 @@
                     enabled_sxes = g_list_append(enabled_sxes, sx);
                }
           }
+          instances->sx_instance_list = gnc_g_list_map(enabled_sxes, (GncGMapFunc)_gnc_sx_gen_instances, range_end);
+          g_list_free(enabled_sxes);
      }
 
-     instances = gnc_sx_instance_model_new();
-     instances->range_end = *range_end;
-     instances->sx_instance_list = gnc_g_list_map(enabled_sxes, (GncGMapFunc)_gnc_sx_gen_instances, range_end);
-
-     g_list_free(enabled_sxes);
-
      return instances;
 }
 static GncSxInstanceModel*
@@ -599,7 +604,6 @@
      return -1;
 }
 
-// @fixme: this needs to ignore non-enabled SXes
 static void
 _gnc_sx_instance_event_handler(QofEntity *ent, QofEventId event_type, gpointer user_data, gpointer evt_data)
 {
@@ -621,9 +625,33 @@
           sx = GNC_SX(ent);
           // only send `updated` if it's actually in the model
           sx_is_in_model = (g_list_find_custom(instances->sx_instance_list, sx, (GCompareFunc)_gnc_sx_instance_find_by_sx) != NULL);
-          if (sx_is_in_model && event_type & QOF_EVENT_MODIFY)
+          if (event_type & QOF_EVENT_MODIFY)
           {
-               g_signal_emit_by_name(instances, "updated", (gpointer)sx);
+               if (sx_is_in_model)
+               {
+                    if (instances->include_disabled || xaccSchedXactionGetEnabled(sx))
+                    {
+                         g_signal_emit_by_name(instances, "updated", (gpointer)sx);
+                    }
+                    else
+                    {
+                         /* the sx was enabled but is now disabled */
+                         g_signal_emit_by_name(instances, "removing", (gpointer)sx);
+                    }
+               }
+               else
+               {
+                    /* determine if this is a legitimate SX or just a "one-off" / being created */
+                    GList *all_sxes = gnc_book_get_schedxactions(gnc_get_current_book())->sx_list;
+                    if (g_list_find(all_sxes, sx) && (!instances->include_disabled && xaccSchedXactionGetEnabled(sx)))
+                    {
+                         /* it's moved from disabled to enabled, add the instances */
+                         instances->sx_instance_list
+                              = g_list_append(instances->sx_instance_list,
+                                              _gnc_sx_gen_instances((gpointer)sx, (gpointer)&instances->range_end));
+                         g_signal_emit_by_name(instances, "added", (gpointer)sx);
+                    }
+               }
           }
           /* else { unsupported event type; ignore } */
      }
@@ -641,19 +669,21 @@
                {
                     g_signal_emit_by_name(instances, "removing", (gpointer)sx);
                }
-               else
+               else if (instances->include_disabled)
                {
-                    // @@ fixme:
-                    printf("err\n");
+                   PWARN("Could not remove instances that do not exist in the model");
                }
           }
           else if (event_type & GNC_EVENT_ITEM_ADDED)
           {
-               /* generate instances, add to instance list, emit update. */
-               instances->sx_instance_list
-                    = g_list_append(instances->sx_instance_list,
-                                    _gnc_sx_gen_instances((gpointer)sx, (gpointer)&instances->range_end));
-               g_signal_emit_by_name(instances, "added", (gpointer)sx);
+               if (instances->include_disabled || xaccSchedXactionGetEnabled(sx))
+               {
+                    /* generate instances, add to instance list, emit update. */
+                    instances->sx_instance_list
+                         = g_list_append(instances->sx_instance_list,
+                                         _gnc_sx_gen_instances((gpointer)sx, (gpointer)&instances->range_end));
+                    g_signal_emit_by_name(instances, "added", (gpointer)sx);
+               }
           }
           /* else { printf("unsupported event type [%d]\n", event_type); } */
      }

Modified: gnucash/trunk/src/app-utils/gnc-sx-instance-model.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-sx-instance-model.h	2007-02-05 23:59:39 UTC (rev 15509)
+++ gnucash/trunk/src/app-utils/gnc-sx-instance-model.h	2007-02-06 00:14:10 UTC (rev 15510)
@@ -53,6 +53,7 @@
 
      /* public */
      GDate range_end;
+     gboolean include_disabled;
      GList *sx_instance_list; /* <GncSxInstances*> */
 } GncSxInstanceModel;
 
@@ -114,7 +115,7 @@
 
 GncSxInstanceModel* gnc_sx_get_current_instances(void);
 
-GncSxInstanceModel* gnc_sx_get_instances(GDate *range_end);
+GncSxInstanceModel* gnc_sx_get_instances(GDate *range_end, gboolean include_disabled);
 
 /**
  * Regenerates and updates the GncSxInstances* for the given SX.  Model

Modified: gnucash/trunk/src/app-utils/test/test-sx.c
===================================================================
--- gnucash/trunk/src/app-utils/test/test-sx.c	2007-02-05 23:59:39 UTC (rev 15509)
+++ gnucash/trunk/src/app-utils/test/test-sx.c	2007-02-06 00:14:10 UTC (rev 15510)
@@ -26,7 +26,7 @@
      g_date_clear(range_end_tomorrow, 1);
      g_date_set_time_t(range_end_tomorrow, time(NULL));
      g_date_add_days(range_end_tomorrow, 1);
-     model = gnc_sx_get_instances(range_end_tomorrow);
+     model = gnc_sx_get_instances(range_end_tomorrow, TRUE);
 
      {
           GncSxInstances *insts;
@@ -55,7 +55,7 @@
      GncSxInstanceModel *model;
 
      end = g_date_new_dmy(31, 12, way_in_the_future_year);
-     model = gnc_sx_get_instances(end);
+     model = gnc_sx_get_instances(end, TRUE);
      do_test(g_list_length(model->sx_instance_list) == 0, "no instances");
      g_object_unref(G_OBJECT(model));
      success("empty");
@@ -85,7 +85,7 @@
 
      lonely = add_once_sx("once", when);
 
-     model = gnc_sx_get_instances(end);
+     model = gnc_sx_get_instances(end, TRUE);
 
      do_test(g_list_length(model->sx_instance_list) == 1, "1 instances");
      instances = (GncSxInstances*)model->sx_instance_list->data;
@@ -122,7 +122,7 @@
      g_date_add_days(end, 3);
 
      foo = add_daily_sx("foo", start, NULL, NULL);
-     model = gnc_sx_get_instances(end);
+     model = gnc_sx_get_instances(end, TRUE);
 
      do_test(g_list_length(model->sx_instance_list) == 1, "one sx");
      insts = (GncSxInstances*)g_list_nth_data(model->sx_instance_list, 0);

Modified: gnucash/trunk/src/doc/sx.rst
===================================================================
--- gnucash/trunk/src/doc/sx.rst	2007-02-05 23:59:39 UTC (rev 15509)
+++ gnucash/trunk/src/doc/sx.rst	2007-02-06 00:14:10 UTC (rev 15510)
@@ -1,4 +1,4 @@
--*- rst -*-
+-*- mode: rst; buffer-file-coding-system: utf-8 -*-
 
 Scheduled Transactions
 ===============================================================
@@ -8,14 +8,14 @@
 
 - SX List
   - CRUD operations on SXes
-  - Show Next "year"s worth of SX instances
-    - gnc_sx_get_instances({now + 1yr})
+  - Show Next "year"s worth of enabled and disabled SX instances
+    - gnc_sx_get_instances({now + 1yr}, TRUE)
 
 - SX Editor
 
 - SinceLastRun
-  - Last .. present (+ create-in-advance, reminder) instances
-    - gnc_sx_get_instances(now)
+  - Last .. present (+ create-in-advance, reminder) enabled instances
+    - gnc_sx_get_instances(now, FALSE)
 
 TODO
 ----------
@@ -45,6 +45,7 @@
       - [ ] add instances
       - [ ] remove instances
       - [ ] make "weird"
+    - [ ] ± disabled flag
   - [x] ensure state consistency model is upheld
   - [ ] check variables-unbound logic
   - [ ] verify summary counts

Modified: gnucash/trunk/src/gnome/gnc-plugin-page-sx-list.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-plugin-page-sx-list.c	2007-02-05 23:59:39 UTC (rev 15509)
+++ gnucash/trunk/src/gnome/gnc-plugin-page-sx-list.c	2007-02-06 00:14:10 UTC (rev 15510)
@@ -337,7 +337,7 @@
           g_date_clear(&end, 1);
           g_date_set_time_t(&end, time(NULL));
           g_date_add_years(&end, 1);
-          priv->instances = GNC_SX_INSTANCE_MODEL(gnc_sx_get_instances(&end));
+          priv->instances = GNC_SX_INSTANCE_MODEL(gnc_sx_get_instances(&end, TRUE));
      }
 
      {

Modified: gnucash/trunk/src/gnome-utils/test/test-sx.c
===================================================================
--- gnucash/trunk/src/gnome-utils/test/test-sx.c	2007-02-05 23:59:39 UTC (rev 15509)
+++ gnucash/trunk/src/gnome-utils/test/test-sx.c	2007-02-06 00:14:10 UTC (rev 15510)
@@ -42,7 +42,7 @@
      
      foo = add_daily_sx("foo", start, NULL, NULL);
 
-     model = gnc_sx_get_instances(end);
+     model = gnc_sx_get_instances(end, TRUE);
      setup_default_handlers(model);
 
      do_test(g_list_length(model->sx_instance_list) == 1, "1 instances");



More information about the gnucash-changes mailing list