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@aoeu.ca>


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@15510 57a11ea4-9604-0410-9ed3-97b8803252fd
zzzoldfeatures/module-cleanup
Joshua Sled 20 years ago
parent 4ec231f487
commit 068540a938

@ -407,22 +407,31 @@ 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);
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)
{
instances->sx_instance_list = gnc_g_list_map(all_sxes, (GncGMapFunc)_gnc_sx_gen_instances, range_end);
}
else
{
GList *all_sxes = gnc_book_get_schedxactions(gnc_get_current_book())->sx_list;
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 @@ gnc_sx_get_instances(GDate *range_end)
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 @@ _gnc_sx_instance_find_by_sx(GncSxInstances *in_list_instances, SchedXaction *sx_
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 @@ _gnc_sx_instance_event_handler(QofEntity *ent, QofEventId event_type, gpointer u
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 @@ _gnc_sx_instance_event_handler(QofEntity *ent, QofEventId event_type, gpointer u
{
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); } */
}

@ -53,6 +53,7 @@ typedef struct _GncSxInstanceModel
/* public */
GDate range_end;
gboolean include_disabled;
GList *sx_instance_list; /* <GncSxInstances*> */
} GncSxInstanceModel;
@ -114,7 +115,7 @@ GType gnc_sx_instance_model_get_type(void);
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

@ -26,7 +26,7 @@ test_basic()
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 @@ test_empty()
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 @@ test_once()
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 @@ test_state_changes()
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);

@ -1,4 +1,4 @@
-*- rst -*-
-*- mode: rst; buffer-file-coding-system: utf-8 -*-
Scheduled Transactions
===============================================================
@ -8,14 +8,14 @@ Overview
- 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 @@ TODO
- [ ] add instances
- [ ] remove instances
- [ ] make "weird"
- [ ] ± disabled flag
- [x] ensure state consistency model is upheld
- [ ] check variables-unbound logic
- [ ] verify summary counts

@ -42,7 +42,7 @@ test()
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");

@ -337,7 +337,7 @@ gnc_plugin_page_sx_list_create_widget (GncPluginPage *plugin_page)
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));
}
{

Loading…
Cancel
Save