r15366 - gnucash/branches/sx-cleanup/src - Move upcoming instance model summarization from since-last-run to instance model itself. Simplify app opening/menu-item "since-last-run" handling behavior.

Josh Sled jsled at cvs.gnucash.org
Sat Jan 13 19:10:36 EST 2007


Author: jsled
Date: 2007-01-13 19:10:35 -0500 (Sat, 13 Jan 2007)
New Revision: 15366
Trac: http://svn.gnucash.org/trac/changeset/15366

Modified:
   gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.c
   gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.h
   gnucash/branches/sx-cleanup/src/doc/sx.rst
   gnucash/branches/sx-cleanup/src/gnome/dialog-sx-since-last-run.c
   gnucash/branches/sx-cleanup/src/gnome/dialog-sx-since-last-run.h
   gnucash/branches/sx-cleanup/src/gnome/gnc-plugin-basic-commands.c
Log:
Move upcoming instance model summarization from since-last-run to instance model itself.  Simplify app opening/menu-item "since-last-run" handling behavior.


Modified: gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.c
===================================================================
--- gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.c	2007-01-14 00:09:22 UTC (rev 15365)
+++ gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.c	2007-01-14 00:10:35 UTC (rev 15366)
@@ -401,6 +401,15 @@
 }
 
 GncSxInstanceModel*
+gnc_sx_get_current_instances(void)
+{
+     GDate *now = g_date_new();
+     g_date_clear(now, 1);
+     g_date_set_time_t(now, time(NULL));
+     return gnc_sx_get_instances(now);
+}
+
+GncSxInstanceModel*
 gnc_sx_get_instances(GDate *range_end)
 {
      GncSxInstanceModel *instances;
@@ -1199,3 +1208,66 @@
      }
      return rtn;
 }
+
+void
+gnc_sx_instance_model_summarize(GncSxInstanceModel *model, GncSxSummary *summary)
+{
+     GList *sx_iter, *inst_iter;
+
+     g_return_if_fail(model != NULL);
+     g_return_if_fail(summary != NULL);
+
+     summary->need_dialog = FALSE;
+     summary->num_instances = 0;
+     summary->num_to_create_instances = 0;
+     summary->num_auto_create_instances = 0;
+     summary->num_auto_create_no_notify_instances = 0;
+
+     for (sx_iter = model->sx_instance_list; sx_iter != NULL; sx_iter = sx_iter->next)
+     {
+          GncSxInstances *instances = (GncSxInstances*)sx_iter->data;
+          gboolean sx_is_auto_create = FALSE, sx_notify = FALSE;
+          xaccSchedXactionGetAutoCreate(instances->sx, &sx_is_auto_create, &sx_notify);
+          for (inst_iter = instances->list; inst_iter != NULL; inst_iter = inst_iter->next)
+          {
+               GncSxInstance *inst = (GncSxInstance*)inst_iter->data;
+               summary->num_instances++;
+
+               if (inst->state == SX_INSTANCE_STATE_TO_CREATE)
+               {
+                    if (sx_is_auto_create)
+                    {
+                         if (!sx_notify)
+                         {
+                              summary->num_auto_create_no_notify_instances++;
+                         }
+                         else
+                         {
+                              summary->num_auto_create_instances++;
+                         }
+                    }
+                    else
+                    {
+                         summary->num_to_create_instances++;
+                    }
+               }
+          }
+     }
+
+     // if all the instances are 'auto-create, no-notify', then we don't need
+     // the dialog.
+     summary->need_dialog
+          = (summary->num_instances != 0
+             && summary->num_auto_create_no_notify_instances != summary->num_instances);
+     
+}
+
+void
+gnc_sx_summary_print(GncSxSummary *summary)
+{
+     printf("num_instances: %d\n", summary->num_instances);
+     printf("num_to_create: %d\n", summary->num_to_create_instances);
+     printf("num_auto_create_instances: %d\n", summary->num_auto_create_instances);
+     printf("num_auto_create_no_notify_instances: %d\n", summary->num_auto_create_no_notify_instances);
+     printf("need dialog? %s\n", summary->need_dialog ? "true" : "false");
+}

Modified: gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.h
===================================================================
--- gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.h	2007-01-14 00:09:22 UTC (rev 15365)
+++ gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.h	2007-01-14 00:10:35 UTC (rev 15366)
@@ -112,6 +112,8 @@
 
 GType gnc_sx_instance_model_get_type(void);
 
+GncSxInstanceModel* gnc_sx_get_current_instances(void);
+
 GncSxInstanceModel* gnc_sx_get_instances(GDate *range_end);
 
 /**
@@ -155,6 +157,24 @@
                                          GList **created_transaction_guids,
                                          GList **creation_errors);
 
+typedef struct _GncSxSummary
+{
+     gboolean need_dialog; /**< If the dialog needs to be displayed. **/
+
+     gint num_instances; /**< The number of total instances (in any state). **/
+     gint num_to_create_instances; /**< The number of (not-auto-create) to-create instances. **/
+     gint num_auto_create_instances;  /**< The total number of auto-create instances. **/
+     gint num_auto_create_no_notify_instances; /**< The number of automatically-created instances that do no request notification. **/
+} GncSxSummary;
+
+/**
+ * @param summary Caller-provided, populated with a summarization of the
+ * state of the model.  Specifically, used to determine if there are SLR SXes
+ * that need either auto-creation or user-interaction.
+ **/
+void gnc_sx_instance_model_summarize(GncSxInstanceModel *model, GncSxSummary *summary);
+void gnc_sx_summary_print(GncSxSummary *summary);
+
 /* @@fixme names. */
 void sxsl_get_sx_vars(SchedXaction *sx, GHashTable *var_hash);
 int parse_vars_from_formula(const char *formula, GHashTable *var_hash, gnc_numeric *result);

Modified: gnucash/branches/sx-cleanup/src/doc/sx.rst
===================================================================
--- gnucash/branches/sx-cleanup/src/doc/sx.rst	2007-01-14 00:09:22 UTC (rev 15365)
+++ gnucash/branches/sx-cleanup/src/doc/sx.rst	2007-01-14 00:10:35 UTC (rev 15366)
@@ -68,7 +68,7 @@
   - [x] move "effect_change" up to app-utils/, test.
   - [x] move state-change up to app-utils
   - [x] move variable-setting up to app-utils
-  - [ ] move summarization up to app-utils
+  - [x] move summarization up to app-utils
   - [x] add reminders, postponed to SxInstanceModel
   - [x] add mutation support to sx instance model
     - [x] state machine

Modified: gnucash/branches/sx-cleanup/src/gnome/dialog-sx-since-last-run.c
===================================================================
--- gnucash/branches/sx-cleanup/src/gnome/dialog-sx-since-last-run.c	2007-01-14 00:09:22 UTC (rev 15365)
+++ gnucash/branches/sx-cleanup/src/gnome/dialog-sx-since-last-run.c	2007-01-14 00:10:35 UTC (rev 15366)
@@ -81,6 +81,7 @@
 static void gnc_sx_slr_tree_model_adapter_dispose(GObject *obj);
 static void gnc_sx_slr_tree_model_adapter_finalize(GObject *obj);
 
+GncSxInstanceModel* gnc_sx_slr_tree_model_adapter_get_instance_model(GncSxSlrTreeModelAdapter *slr_model);
 GncSxInstances* gnc_sx_slr_tree_model_adapter_get_sx_instances(GncSxSlrTreeModelAdapter *model, GtkTreeIter *iter);
 static GncSxInstances* _gnc_sx_slr_tree_model_adapter_get_sx_instances(GncSxSlrTreeModelAdapter *model, GtkTreeIter *iter, gboolean check_depth);
 /** @return null if the iter is not actually an GncSxInstance. **/
@@ -89,8 +90,6 @@
 /** @return false if the iter is not actaully an GncSxInstance's variable. **/
 gboolean gnc_sx_slr_model_get_instance_and_variable(GncSxSlrTreeModelAdapter *model, GtkTreeIter *iter, GncSxInstance **instance_loc, GncSxVariable **var_loc);
 
-void gnc_sx_slr_model_summarize(GncSxSlrTreeModelAdapter *model, GncSxSlrSummary *summary);
-
 void gnc_sx_slr_model_change_instance_state(GncSxSlrTreeModelAdapter *model, GncSxInstance *instance, GncSxInstanceState new_state);
 void gnc_sx_slr_model_change_variable(GncSxSlrTreeModelAdapter *model, GncSxInstance *instance, GncSxVariable *variable, gnc_numeric *new_value);
 void gnc_sx_slr_model_effect_change(GncSxSlrTreeModelAdapter *model, gboolean auto_create_only, GList **created_transaction_guids, GList **creation_errors);
@@ -498,6 +497,12 @@
      }
 }
 
+GncSxInstanceModel*
+gnc_sx_slr_tree_model_adapter_get_instance_model(GncSxSlrTreeModelAdapter *slr_model)
+{
+     return slr_model->instances;
+}
+
 GncSxInstances*
 gnc_sx_slr_tree_model_adapter_get_sx_instances(GncSxSlrTreeModelAdapter *model, GtkTreeIter *iter)
 {
@@ -715,99 +720,23 @@
      return rtn;
 }
 
-GncSxSlrTreeModelAdapter*
-gnc_sx_get_slr_model()
-{
-     GDate now;
-     GncSxInstanceModel *instance_model;
-     GncSxSlrTreeModelAdapter *slr_model;
-     g_date_clear(&now, 1);
-     g_date_set_time_t(&now, time(NULL));
-     instance_model = gnc_sx_get_instances(&now);
-     slr_model = gnc_sx_slr_tree_model_adapter_new(instance_model);
-     g_object_unref(G_OBJECT(instance_model));
-     return slr_model;
-}
-
 void
-gnc_sx_slr_model_summarize(GncSxSlrTreeModelAdapter *model, GncSxSlrSummary *summary)
-{
-     GList *sx_iter, *inst_iter;
-
-     g_return_if_fail(model != NULL);
-     g_return_if_fail(summary != NULL);
-
-     summary->need_dialog = FALSE;
-     summary->num_instances = 0;
-     summary->num_to_create_instances = 0;
-     summary->num_auto_create_instances = 0;
-     summary->num_auto_create_no_notify_instances = 0;
-
-     for (sx_iter = model->instances->sx_instance_list; sx_iter != NULL; sx_iter = sx_iter->next)
-     {
-          GncSxInstances *instances = (GncSxInstances*)sx_iter->data;
-          gboolean sx_is_auto_create = FALSE, sx_notify = FALSE;
-          xaccSchedXactionGetAutoCreate(instances->sx, &sx_is_auto_create, &sx_notify);
-          for (inst_iter = instances->list; inst_iter != NULL; inst_iter = inst_iter->next)
-          {
-               GncSxInstance *inst = (GncSxInstance*)inst_iter->data;
-               summary->num_instances++;
-
-               if (inst->state == SX_INSTANCE_STATE_TO_CREATE)
-               {
-                    if (sx_is_auto_create)
-                    {
-                         if (!sx_notify)
-                         {
-                              summary->num_auto_create_no_notify_instances++;
-                         }
-                         else
-                         {
-                              summary->num_auto_create_instances++;
-                         }
-                    }
-                    else
-                    {
-                         summary->num_to_create_instances++;
-                    }
-               }
-          }
-     }
-
-     // if all the instances are 'auto-create, no-notify', then we don't need
-     // the dialog.
-     summary->need_dialog
-          = (summary->num_instances != 0
-             && summary->num_auto_create_no_notify_instances != summary->num_instances);
-}
-
-static void
-_print_summary(GncSxSlrSummary *summary)
-{
-     printf("num_instances: %d\n", summary->num_instances);
-     printf("num_to_create: %d\n", summary->num_to_create_instances);
-     printf("num_auto_create_instances: %d\n", summary->num_auto_create_instances);
-     printf("num_auto_create_no_notify_instances: %d\n", summary->num_auto_create_no_notify_instances);
-     printf("need dialog? %s\n", summary->need_dialog ? "true" : "false");
-}
-
-void
 gnc_sx_sxsincelast_book_opened(void)
 {
-     GncSxSlrTreeModelAdapter *slr_model;
-     GncSxSlrSummary summary;
+     GncSxInstanceModel *inst_model;
+     GncSxSummary summary;
 
      if (!gnc_gconf_get_bool(GCONF_SECTION, "show_at_file_open", NULL))
           return;
 
-     slr_model = gnc_sx_get_slr_model();
-     gnc_sx_slr_model_summarize(slr_model, &summary);
-     _print_summary(&summary);
-     gnc_sx_slr_model_effect_change(slr_model, TRUE, NULL, NULL);
+     inst_model = gnc_sx_get_current_instances();
+     gnc_sx_instance_model_summarize(inst_model, &summary);
+     gnc_sx_summary_print(&summary);
+     gnc_sx_instance_model_effect_change(inst_model, TRUE, NULL, NULL);
 
      if (summary.need_dialog)
      {
-          gnc_ui_sx_since_last_run_dialog(slr_model);
+          gnc_ui_sx_since_last_run_dialog(inst_model);
      }
      else
      {
@@ -822,19 +751,18 @@
                       "(%d transactions automatically created)",
                       summary.num_auto_create_no_notify_instances),
                      summary.num_auto_create_no_notify_instances);
-               gnc_sx_slr_model_effect_change(slr_model, TRUE, NULL, NULL);
           }
      }
-     g_object_unref(G_OBJECT(slr_model));
+     g_object_unref(G_OBJECT(inst_model));
 }
 
 void
 gnc_ui_sxsincelast_dialog_create(void)
 {
-     GncSxSlrTreeModelAdapter *slr_model = gnc_sx_get_slr_model();
-     gnc_sx_slr_model_effect_change(slr_model, TRUE, NULL, NULL);
-     gnc_ui_sx_since_last_run_dialog(slr_model);
-     g_object_unref(G_OBJECT(slr_model));
+     GncSxInstanceModel *model = gnc_sx_get_current_instances();
+     gnc_sx_instance_model_effect_change(model, TRUE, NULL, NULL);
+     gnc_ui_sx_since_last_run_dialog(model);
+     g_object_unref(G_OBJECT(model));
 }
 
 static void
@@ -912,7 +840,7 @@
 }
 
 GncSxSinceLastRunDialog*
-gnc_ui_sx_since_last_run_dialog(GncSxSlrTreeModelAdapter *slr_model)
+gnc_ui_sx_since_last_run_dialog(GncSxInstanceModel *sx_instances)
 {
      GncSxSinceLastRunDialog *dialog;
      GladeXML *glade;
@@ -921,8 +849,8 @@
      glade = gnc_glade_xml_new("sched-xact.glade", "since-last-run-dialog");
      dialog->dialog = glade_xml_get_widget(glade, "since-last-run-dialog");
 
-     dialog->editing_model = slr_model;
-     g_object_ref(G_OBJECT(dialog->editing_model));
+     dialog->editing_model = gnc_sx_slr_tree_model_adapter_new(sx_instances);
+     g_object_ref_sink(G_OBJECT(dialog->editing_model));
      
      {
           GtkPaned *paned;

Modified: gnucash/branches/sx-cleanup/src/gnome/dialog-sx-since-last-run.h
===================================================================
--- gnucash/branches/sx-cleanup/src/gnome/dialog-sx-since-last-run.h	2007-01-14 00:09:22 UTC (rev 15365)
+++ gnucash/branches/sx-cleanup/src/gnome/dialog-sx-since-last-run.h	2007-01-14 00:10:35 UTC (rev 15366)
@@ -27,31 +27,13 @@
 
 #include <gtk/gtk.h>
 
-#include "SchedXaction.h"
+#include "gnc-sx-instance-model.h"
 #include "gnc-plugin-page-sx-list.h"
 
 typedef struct _GncSxSlrTreeModelAdapter GncSxSlrTreeModelAdapter;
 typedef struct _GncSxSinceLastRunDialog GncSxSinceLastRunDialog;
-typedef struct _GncSxSlrSummary
-{
-     gboolean need_dialog; /**< If the dialog needs to be displayed. **/
 
-     gint num_instances; /**< The number of total instances (all states). **/
-     gint num_to_create_instances; /**< The number of (not-auto-create) to-create instances. **/
-     gint num_auto_create_instances;  /**< The total number of auto-create instances. **/
-     gint num_auto_create_no_notify_instances; /**< The number of automatically-created instances that do no request notification. **/
-} GncSxSlrSummary;
-
-GncSxSlrTreeModelAdapter* gnc_sx_get_slr_model(void);
-
 /**
- * @param summary Caller-provided, populated with a summarization of the
- * state of the model.  Specifically, used to determine if there are SLR SXes
- * that need either auto-creation or user-interaction.
- **/
-void gnc_sx_slr_model_summarize(GncSxSlrTreeModelAdapter *model, GncSxSlrSummary *summary);
-
-/**
  * This encapsulates the "run when file opened" application logic.  As such,
  * it should probably move to a non-ui file.
  **/
@@ -60,11 +42,11 @@
 /**
  * Create the since-last-run dialog.
  **/
-GncSxSinceLastRunDialog*  gnc_ui_sx_since_last_run_dialog(GncSxSlrTreeModelAdapter *model);
+GncSxSinceLastRunDialog*  gnc_ui_sx_since_last_run_dialog(GncSxInstanceModel *sx_instances);
 
 // eliminate...
 void gnc_ui_sxsincelast_dialog_create(void);
 
-void gnc_sx_slr_model_effect_change(GncSxSlrTreeModelAdapter *model, gboolean auto_create_only, GList **created_transaction_guids, GList **creation_errors);
+//void gnc_sx_slr_model_effect_change(GncSxSlrTreeModelAdapter *model, gboolean auto_create_only, GList **created_transaction_guids, GList **creation_errors);
 
 #endif

Modified: gnucash/branches/sx-cleanup/src/gnome/gnc-plugin-basic-commands.c
===================================================================
--- gnucash/branches/sx-cleanup/src/gnome/gnc-plugin-basic-commands.c	2007-01-14 00:09:22 UTC (rev 15365)
+++ gnucash/branches/sx-cleanup/src/gnome/gnc-plugin-basic-commands.c	2007-01-14 00:10:35 UTC (rev 15366)
@@ -444,21 +444,21 @@
 gnc_main_window_cmd_actions_since_last_run (GtkAction *action, GncMainWindowActionData *data)
 {
   GncMainWindow *window;
-  GncSxSlrTreeModelAdapter *slr_model;
-  GncSxSlrSummary summary;
+  GncSxInstanceModel *sx_instances;
+  GncSxSummary summary;
   const char *nothing_to_do_msg =
     _( "There are no Scheduled Transactions to be entered at this time." );
 	
   g_return_if_fail (data != NULL);
 
   window = data->window;
-
-  slr_model = gnc_sx_get_slr_model();
-  gnc_sx_slr_model_summarize(slr_model, &summary);
-  gnc_sx_slr_model_effect_change(slr_model, TRUE, NULL, NULL);
+  
+  sx_instances = gnc_sx_get_current_instances();
+  gnc_sx_instance_model_summarize(sx_instances, &summary);
+  gnc_sx_instance_model_effect_change(sx_instances, TRUE, NULL, NULL);
   if (summary.need_dialog)
   {
-    gnc_ui_sx_since_last_run_dialog(slr_model);
+    gnc_ui_sx_since_last_run_dialog(sx_instances);
   }
   else
   {
@@ -479,7 +479,7 @@
                       summary.num_auto_create_no_notify_instances);
     }
   }
-  g_object_unref(G_OBJECT(slr_model));
+  g_object_unref(G_OBJECT(sx_instances));
 }
 
 static void



More information about the gnucash-changes mailing list