r14948 - gnucash/branches/sx-cleanup/src - Break all new classes out into individual files, mostly from gnc-plugin-page-sx-list.[ch] and gnc-dense-cal.[ch].
Joshua Sled
jsled at cvs.gnucash.org
Mon Oct 9 19:05:42 EDT 2006
Author: jsled
Date: 2006-10-09 19:05:38 -0400 (Mon, 09 Oct 2006)
New Revision: 14948
Trac: http://svn.gnucash.org/trac/changeset/14948
Added:
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/gnome-utils/gnc-dense-cal-model.c
gnucash/branches/sx-cleanup/src/gnome-utils/gnc-dense-cal-model.h
gnucash/branches/sx-cleanup/src/gnome-utils/gnc-dense-cal-store.c
gnucash/branches/sx-cleanup/src/gnome-utils/gnc-dense-cal-store.h
gnucash/branches/sx-cleanup/src/gnome-utils/gnc-sx-instance-dense-cal-adapter.c
gnucash/branches/sx-cleanup/src/gnome-utils/gnc-sx-instance-dense-cal-adapter.h
gnucash/branches/sx-cleanup/src/gnome/gnc-sx-list-tree-model-adapter.c
gnucash/branches/sx-cleanup/src/gnome/gnc-sx-list-tree-model-adapter.h
Modified:
gnucash/branches/sx-cleanup/src/app-utils/Makefile.am
gnucash/branches/sx-cleanup/src/core-utils/gnc-glib-utils.c
gnucash/branches/sx-cleanup/src/core-utils/gnc-glib-utils.h
gnucash/branches/sx-cleanup/src/gnome-utils/Makefile.am
gnucash/branches/sx-cleanup/src/gnome-utils/gnc-dense-cal.c
gnucash/branches/sx-cleanup/src/gnome-utils/gnc-dense-cal.h
gnucash/branches/sx-cleanup/src/gnome/Makefile.am
gnucash/branches/sx-cleanup/src/gnome/dialog-sx-editor.c
gnucash/branches/sx-cleanup/src/gnome/dialog-sx-editor.h
gnucash/branches/sx-cleanup/src/gnome/dialog-sx-from-trans.c
gnucash/branches/sx-cleanup/src/gnome/dialog-sx-since-last-run.c
gnucash/branches/sx-cleanup/src/gnome/gnc-plugin-page-sx-list.c
gnucash/branches/sx-cleanup/src/gnome/gnc-plugin-page-sx-list.h
Log:
Break all new classes out into individual files, mostly from gnc-plugin-page-sx-list.[ch] and gnc-dense-cal.[ch].
Modified: gnucash/branches/sx-cleanup/src/app-utils/Makefile.am
===================================================================
--- gnucash/branches/sx-cleanup/src/app-utils/Makefile.am 2006-10-09 19:47:15 UTC (rev 14947)
+++ gnucash/branches/sx-cleanup/src/app-utils/Makefile.am 2006-10-09 23:05:38 UTC (rev 14948)
@@ -34,6 +34,7 @@
gnc-exp-parser.c \
gnc-gettext-util.c \
gnc-helpers.c \
+ gnc-sx-instance-model.c \
gncmod-app-utils.c \
gnc-ui-util.c \
guile-util.c \
@@ -59,6 +60,7 @@
gnc-exp-parser.h \
gnc-gettext-util.h \
gnc-helpers.h \
+ gnc-sx-instance-model.h \
gnc-ui-common.h \
gnc-ui-util.h \
guile-util.h \
Added: gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.c
===================================================================
--- gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.c 2006-10-09 19:47:15 UTC (rev 14947)
+++ gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.c 2006-10-09 23:05:38 UTC (rev 14948)
@@ -0,0 +1,530 @@
+/*
+ * gnc-sx-instance-model.c
+ *
+ * Copyright (C) 2006 Josh Sled <jsled at asynchronous.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation Voice: +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
+ * Boston, MA 02110-1301, USA gnu at gnu.org
+ */
+
+#include "config.h"
+#include <glib.h>
+#include <glib-object.h>
+
+#include "Account.h"
+#include "SchedXaction.h"
+#include "Split.h"
+#include "SX-book.h"
+#include "Transaction.h"
+#include "gnc-book.h"
+#include "gnc-commodity.h"
+#include "gnc-event.h"
+#include "gnc-exp-parser.h"
+#include "gnc-glib-utils.h"
+#include "gnc-sx-instance-model.h"
+#include "gnc-ui-util.h"
+#include "qof.h"
+
+static void gnc_sx_instance_model_class_init (GncSxInstanceModelClass *klass);
+static void gnc_sx_instance_model_init(GTypeInstance *instance, gpointer klass);
+static GncSxInstanceModel* gnc_sx_instance_model_new(void);
+
+static GncSxInstance* gnc_sx_instance_new(GncSxInstances *parent, GncSxInstanceState state, GDate *date, void *temporal_state, gint sequence_num);
+
+static void sxsl_get_sx_vars(SchedXaction *sx, GHashTable *var_hash);
+static gint _get_vars_helper(Transaction *txn, void *var_hash_data);
+static int parse_vars_from_formula(const char *formula, GHashTable *varHash, gnc_numeric *result);
+
+static GncSxVariable* gnc_sx_variable_new(gchar *name);
+
+static void _gnc_sx_instance_event_handler(QofEntity *ent, QofEventId event_type, gpointer user_data, gpointer evt_data);
+
+/* ------------------------------------------------------------ */
+
+static void
+_sx_var_to_raw_numeric(gchar *name, GncSxVariable *var, GHashTable *parser_var_hash)
+{
+ g_hash_table_insert(parser_var_hash, name, &var->value);
+}
+
+static void
+_var_numeric_to_sx_var(gchar *name, gnc_numeric *num, GHashTable *sx_var_hash)
+{
+ gpointer p_var;
+ if (!g_hash_table_lookup_extended(sx_var_hash, name, NULL, &p_var))
+ {
+ p_var = (gpointer)gnc_sx_variable_new(name);
+ g_hash_table_insert(sx_var_hash, name, p_var);
+ }
+ ((GncSxVariable*)p_var)->value = *num;
+}
+
+static void
+_wipe_parsed_sx_var(gchar *key, GncSxVariable *var, gpointer unused_user_data)
+{
+ var->value = gnc_numeric_error(GNC_ERROR_ARG);
+}
+
+/**
+ * @return caller-owned.
+ **/
+GHashTable*
+gnc_sx_instance_get_variables_for_parser(GHashTable *instance_var_hash)
+{
+ GHashTable *parser_vars;
+ parser_vars = g_hash_table_new(g_str_hash, g_str_equal);
+ g_hash_table_foreach(instance_var_hash, (GHFunc)_sx_var_to_raw_numeric, parser_vars);
+ return parser_vars;
+}
+
+static int
+parse_vars_from_formula(const char *formula,
+ GHashTable *var_hash,
+ gnc_numeric *result)
+{
+ gnc_numeric num;
+ char *errLoc;
+ int toRet = 0;
+ GHashTable *parser_vars;
+
+ // convert var_hash -> variables for the parser.
+ parser_vars = gnc_sx_instance_get_variables_for_parser(var_hash);
+
+ if (!gnc_exp_parser_parse_separate_vars(formula, &num, &errLoc, parser_vars))
+ {
+ toRet = -1;
+ }
+
+ // convert back.
+ g_hash_table_foreach(parser_vars, (GHFunc)_var_numeric_to_sx_var, var_hash);
+ g_hash_table_destroy(parser_vars);
+
+ if (result != NULL)
+ {
+ *result = num;
+ }
+
+ return toRet;
+}
+
+static GncSxVariable*
+gnc_sx_variable_new(gchar *name)
+{
+ GncSxVariable *var = g_new0(GncSxVariable, 1);
+ var->name = name;
+ var->value = gnc_numeric_error(GNC_ERROR_ARG);
+ var->editable = TRUE;
+ return var;
+}
+
+static gint
+_get_vars_helper(Transaction *txn, void *var_hash_data)
+{
+ GHashTable *var_hash = (GHashTable*)var_hash_data;
+ GList *split_list;
+ kvp_frame *kvpf;
+ kvp_value *kvp_val;
+ Split *s;
+ char *str;
+ gnc_commodity *first_cmdty = NULL;
+
+ split_list = xaccTransGetSplitList(txn);
+ if (split_list == NULL)
+ {
+ return 1;
+ }
+
+ for ( ; split_list; split_list = split_list->next)
+ {
+ gnc_commodity *split_cmdty = NULL;
+ GUID *acct_guid;
+ Account *acct;
+
+ s = (Split*)split_list->data;
+ kvpf = xaccSplitGetSlots(s);
+ kvp_val = kvp_frame_get_slot_path(kvpf,
+ GNC_SX_ID,
+ GNC_SX_ACCOUNT,
+ NULL);
+ acct_guid = kvp_value_get_guid(kvp_val);
+ acct = xaccAccountLookup(acct_guid, gnc_get_current_book());
+ split_cmdty = xaccAccountGetCommodity(acct);
+ if (first_cmdty == NULL)
+ {
+ first_cmdty = split_cmdty;
+ }
+
+ if (! gnc_commodity_equal(split_cmdty, first_cmdty))
+ {
+ GncSxVariable *var;
+ GString *var_name;
+
+ var_name = g_string_sized_new(16);
+ g_string_printf(var_name, "%s -> %s",
+ gnc_commodity_get_mnemonic(split_cmdty),
+ gnc_commodity_get_mnemonic(first_cmdty));
+ var = gnc_sx_variable_new(g_strdup(var_name->str));
+ g_hash_table_insert(var_hash, var->name, var);
+ g_string_free(var_name, TRUE);
+ }
+
+ // existing... ------------------------------------------
+ kvp_val = kvp_frame_get_slot_path(kvpf,
+ GNC_SX_ID,
+ GNC_SX_CREDIT_FORMULA,
+ NULL);
+ if (kvp_val != NULL)
+ {
+ str = kvp_value_get_string(kvp_val);
+ if (str && strlen(str) != 0)
+ {
+ parse_vars_from_formula(str, var_hash, NULL);
+ }
+ }
+
+ kvp_val = kvp_frame_get_slot_path(kvpf,
+ GNC_SX_ID,
+ GNC_SX_DEBIT_FORMULA,
+ NULL);
+ if (kvp_val != NULL)
+ {
+ str = kvp_value_get_string(kvp_val);
+ if (str && strlen(str) != 0)
+ {
+ parse_vars_from_formula(str, var_hash, NULL);
+ }
+ }
+ }
+
+ return 0;
+}
+
+Account*
+gnc_sx_get_template_transaction_account(SchedXaction *sx)
+{
+ AccountGroup *template_group;
+ Account *sx_template_acct;
+ const char *sx_guid_str;
+
+ template_group = gnc_book_get_template_group(gnc_get_current_book());
+ sx_guid_str = guid_to_string(xaccSchedXactionGetGUID(sx));
+ /* Get account named after guid string. */
+ sx_template_acct = xaccGetAccountFromName(template_group, sx_guid_str);
+ return sx_template_acct;
+}
+
+static void
+sxsl_get_sx_vars(SchedXaction *sx, GHashTable *var_hash)
+{
+ Account *sx_template_acct;
+ sx_template_acct = gnc_sx_get_template_transaction_account(sx);
+ xaccAccountForEachTransaction(sx_template_acct, _get_vars_helper, var_hash);
+}
+
+static void
+_clone_sx_var_hash_entry(gpointer key, gpointer value, gpointer user_data)
+{
+ GHashTable *to = (GHashTable*)user_data;
+ GncSxVariable *to_copy = (GncSxVariable*)value;
+ GncSxVariable *var = gnc_sx_variable_new(to_copy->name);
+ var->value = to_copy->value;
+ var->editable = to_copy->editable;
+ g_hash_table_insert(to, key, var);
+}
+
+static GncSxInstance*
+gnc_sx_instance_new(GncSxInstances *parent, GncSxInstanceState state, GDate *date, void *temporal_state, gint sequence_num)
+{
+ GncSxInstance *rtn = g_new0(GncSxInstance, 1);
+ rtn->parent = parent;
+ rtn->orig_state = state;
+ rtn->state = state;
+ g_date_clear(&rtn->date, 1);
+ rtn->date = *date;
+ rtn->temporal_state = gnc_sx_clone_temporal_state(temporal_state);
+
+ if (! parent->variable_names_parsed)
+ {
+ parent->variable_names = g_hash_table_new(g_str_hash, g_str_equal);
+ sxsl_get_sx_vars(parent->sx, parent->variable_names);
+ g_hash_table_foreach(parent->variable_names, (GHFunc)_wipe_parsed_sx_var, NULL);
+ parent->variable_names_parsed = TRUE;
+
+ // @@fixme: add sequence_num as `i`, non-editable
+ }
+
+ rtn->variable_bindings = g_hash_table_new(g_str_hash, g_str_equal);
+ g_hash_table_foreach(parent->variable_names, _clone_sx_var_hash_entry, rtn->variable_bindings);
+ return rtn;
+}
+
+static void
+_build_list_from_hash_elts(gpointer key, gpointer value, gpointer user_data)
+{
+ GList **list = (GList**)user_data;
+ *list = g_list_append(*list, value);
+}
+
+GList *
+gnc_sx_instance_get_variables(GncSxInstance *inst)
+{
+ GList *vars = NULL;
+ g_hash_table_foreach(inst->variable_bindings, _build_list_from_hash_elts, &vars);
+
+ // @@fixme sort by name
+ return vars;
+}
+
+static GncSxInstances*
+_gnc_sx_gen_instances(gpointer *data, gpointer user_data)
+{
+ GncSxInstances *instances = g_new0(GncSxInstances, 1);
+ SchedXaction *sx = (SchedXaction*)data;
+ GDate *range_end = (GDate*)user_data;
+ GDate creation_end, remind_end;
+ GDate cur_date;
+ void *sequence_ctx;
+
+ instances->sx = sx;
+
+ creation_end = *range_end;
+ g_date_add_days(&creation_end, xaccSchedXactionGetAdvanceCreation(sx));
+ remind_end = creation_end;
+ g_date_add_days(&remind_end, xaccSchedXactionGetAdvanceReminder(sx));
+
+ /* postponed */
+ {
+ GList *postponed = gnc_sx_get_defer_instances(sx);
+ for ( ; postponed != NULL; postponed = postponed->next)
+ {
+ GDate inst_date;
+ int seq_num;
+ GncSxInstance *inst;
+
+ g_date_clear(&inst_date, 1);
+ inst_date = xaccSchedXactionGetNextInstance(sx, postponed->data);
+ seq_num = gnc_sx_get_instance_count(sx, postponed->data);
+ inst = gnc_sx_instance_new(instances, SX_INSTANCE_STATE_POSTPONED, &inst_date, postponed->data, seq_num);
+ //inst->temporal_state = postponed->data;
+ instances->list = g_list_append(instances->list, inst);
+ }
+ }
+
+ /* to-create */
+ g_date_clear(&cur_date, 1);
+ sequence_ctx = gnc_sx_create_temporal_state(sx);
+ cur_date = xaccSchedXactionGetInstanceAfter(sx, &cur_date, sequence_ctx);
+ instances->next_instance_date = cur_date;
+ while (g_date_valid(&cur_date) && g_date_compare(&cur_date, &creation_end) <= 0)
+ {
+ GncSxInstance *inst;
+ int seq_num;
+ seq_num = gnc_sx_get_instance_count(sx, sequence_ctx);
+ inst = gnc_sx_instance_new(instances, SX_INSTANCE_STATE_TO_CREATE, &cur_date, sequence_ctx, seq_num);
+ instances->list = g_list_append(instances->list, inst);
+ gnc_sx_incr_temporal_state(sx, sequence_ctx);
+ cur_date = xaccSchedXactionGetInstanceAfter(sx, &cur_date, sequence_ctx);
+ }
+
+ /* reminders */
+ while (g_date_valid(&cur_date) && g_date_compare(&cur_date, &remind_end) <= 0)
+ {
+ GncSxInstance *inst;
+ int seq_num;
+ seq_num = gnc_sx_get_instance_count(sx, sequence_ctx);
+ inst = gnc_sx_instance_new(instances, SX_INSTANCE_STATE_REMINDER, &cur_date, sequence_ctx, seq_num);
+ instances->list = g_list_append(instances->list, inst);
+ gnc_sx_incr_temporal_state(sx, sequence_ctx);
+ cur_date = xaccSchedXactionGetInstanceAfter(sx, &cur_date, sequence_ctx);
+ }
+
+ return instances;
+}
+
+GncSxInstanceModel*
+gnc_sx_get_instances(GDate *range_end)
+{
+ GncSxInstanceModel *instances;
+ GList *sxes;
+
+ g_assert(range_end != NULL);
+ g_assert(g_date_valid(range_end));
+
+ instances = gnc_sx_instance_model_new();
+ instances->range_end = *range_end;
+ sxes = gnc_book_get_schedxactions(gnc_get_current_book())->sx_list;
+ instances->sx_instance_list = gnc_g_list_map(sxes, (GncGMapFunc)_gnc_sx_gen_instances, range_end);
+
+ return instances;
+}
+
+static GncSxInstanceModel*
+gnc_sx_instance_model_new(void)
+{
+ return GNC_SX_INSTANCE_MODEL(g_object_new(GNC_TYPE_SX_INSTANCE_MODEL, NULL));
+}
+
+GType
+gnc_sx_instance_model_get_type(void)
+{
+ static GType type = 0;
+ if (type == 0) {
+ static const GTypeInfo info = {
+ sizeof (GncSxInstanceModelClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ (GClassInitFunc)gnc_sx_instance_model_class_init, /* class_init */
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (GncSxInstanceModel),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc)gnc_sx_instance_model_init /* instance_init */
+ };
+ type = g_type_register_static (G_TYPE_OBJECT,
+ "GncSxInstanceModelType",
+ &info, 0);
+ }
+ return type;
+}
+
+static void
+gnc_sx_instance_model_dispose (GObject *object)
+{
+ printf("dispose\n");
+}
+
+static void
+gnc_sx_instance_model_finalize (GObject *object)
+{
+ printf("finalize\n");
+}
+
+static void
+gnc_sx_instance_model_class_init (GncSxInstanceModelClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+ object_class->dispose = gnc_sx_instance_model_dispose;
+ object_class->finalize = gnc_sx_instance_model_finalize;
+
+ klass->removing_signal_id =
+ g_signal_new("removing",
+ GNC_TYPE_SX_INSTANCE_MODEL,
+ G_SIGNAL_RUN_FIRST,
+ 0, /* class offset */
+ NULL, /* accumulator */
+ NULL, /* accum data */
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_POINTER);
+
+ klass->updated_signal_id =
+ g_signal_new("updated",
+ GNC_TYPE_SX_INSTANCE_MODEL,
+ G_SIGNAL_RUN_FIRST,
+ 0, /* class offset */
+ NULL, /* accumulator */
+ NULL, /* accum data */
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0, NULL);
+
+ klass->added_signal_id =
+ g_signal_new("added",
+ GNC_TYPE_SX_INSTANCE_MODEL,
+ G_SIGNAL_RUN_FIRST,
+ 0, /* class offset */
+ NULL, /* accumulator */
+ NULL, /* accum data */
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_POINTER);
+}
+
+static void
+gnc_sx_instance_model_init(GTypeInstance *instance, gpointer klass)
+{
+ GncSxInstanceModel *inst = (GncSxInstanceModel*)instance;
+
+ g_date_clear(&inst->range_end, 1);
+ inst->sx_instance_list = NULL;
+ inst->qof_event_handler_id = qof_event_register_handler(_gnc_sx_instance_event_handler, inst);
+}
+
+static void
+_gnc_sx_instance_event_handler(QofEntity *ent, QofEventId event_type, gpointer user_data, gpointer evt_data)
+{
+ GncSxInstanceModel *instances = GNC_SX_INSTANCE_MODEL(user_data);
+
+ /* selection rules {
+ // (gnc_collection_get_schedxaction_list(book), GNC_EVENT_ITEM_ADDED)
+ // (gnc_collection_get_schedxaction_list(book), GNC_EVENT_ITEM_REMOVED)
+ // (GNC_IS_SX(ent), QOF_EVENT_MODIFIED)
+ // } */
+ if (!(GNC_IS_SX(ent) || GNC_IS_SXES(ent)))
+ return;
+
+ if (GNC_IS_SX(ent))
+ {
+ SchedXaction *sx;
+ sx = GNC_SX(ent);
+ if (event_type & QOF_EVENT_MODIFY)
+ {
+ /* @re-generate instance, update*/
+ }
+ /* else { unsupported event type; ignore } */
+ }
+ else if (GNC_IS_SXES(ent))
+ {
+ SchedXactions *sxes = GNC_SXES(ent);
+ SchedXaction *sx = GNC_SX(evt_data);
+
+ sxes = NULL;
+ if (event_type & GNC_EVENT_ITEM_REMOVED)
+ {
+ gpointer sx_instance_to_remove = NULL;
+ GList *list;
+
+ /* find, remove, update */
+ for (list = instances->sx_instance_list; list != NULL; list = list->next)
+ {
+ if (sx == ((GncSxInstances*)list->data)->sx)
+ {
+ sx_instance_to_remove = list->data;
+ break;
+ }
+ }
+ if (sx_instance_to_remove != NULL)
+ {
+ g_signal_emit_by_name(instances, "removing", GUINT_TO_POINTER(GPOINTER_TO_UINT(((GncSxInstances*)sx_instance_to_remove)->sx)));
+ instances->sx_instance_list = g_list_remove(instances->sx_instance_list, sx_instance_to_remove);
+ g_signal_emit_by_name(instances, "updated"); // @@fixme remove
+ }
+ else { printf("err\n"); }
+ }
+ 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", GUINT_TO_POINTER(GPOINTER_TO_UINT(sx)));
+ g_signal_emit_by_name(instances, "updated"); // @fixme remove
+ }
+ /* else { printf("unsupported event type [%d]\n", event_type); } */
+ }
+}
Added: gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.h
===================================================================
--- gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.h 2006-10-09 19:47:15 UTC (rev 14947)
+++ gnucash/branches/sx-cleanup/src/app-utils/gnc-sx-instance-model.h 2006-10-09 23:05:38 UTC (rev 14948)
@@ -0,0 +1,121 @@
+/*
+ * gnc-sx-instance-model.h
+ *
+ * Copyright (C) 2006 Josh Sled <jsled at asynchronous.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation Voice: +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
+ * Boston, MA 02110-1301, USA gnu at gnu.org
+ */
+
+#ifndef _GNC_SX_INSTANCE_MODEL_H
+#define _GNC_SX_INSTANCE_MODEL_H
+
+#include "config.h"
+#include <glib.h>
+#include <glib-object.h>
+#include "SchedXaction.h"
+
+G_BEGIN_DECLS
+
+#define GNC_TYPE_SX_INSTANCE_MODEL (gnc_sx_instance_model_get_type ())
+#define GNC_SX_INSTANCE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_SX_INSTANCE_MODEL, GncSxInstanceModel))
+#define GNC_SX_INSTANCE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_SX_INSTANCE_MODEL, GncSxInstanceModelClass))
+#define GNC_IS_SX_INSTANCE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_SX_INSTANCE_MODEL))
+#define GNC_IS_SX_INSTANCE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_SX_INSTANCE_MODEL))
+#define GNC_SX_INSTANCE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_TYPE_SX_INSTANCE_MODEL, GncSxInstanceModelClass))
+
+typedef struct _GncSxInstanceModel
+{
+ GObject parent;
+
+ /* private */
+ gint qof_event_handler_id;
+
+ /* signals */
+ /* void (*added)(GncSxInstance *sx); // gpointer user_data */
+ /* void (*removed)(GncSxInstance *sx); // gpointer user_data */
+ /* void (*changed)(GncSxInstance *inst); // gpointer user_data */
+
+ /* public */
+ GDate range_end;
+ GList *sx_instance_list; /* <GncSxInstances*> */
+} GncSxInstanceModel;
+
+typedef struct _GncSxInstanceModelClass
+{
+ GObjectClass parent;
+
+ guint removing_signal_id;
+ guint updated_signal_id;
+ guint added_signal_id;
+} GncSxInstanceModelClass;
+
+typedef struct _GncSxInstances
+{
+ SchedXaction *sx;
+ GHashTable /** <name:char*,GncSxVariable*> **/ *variable_names;
+ gboolean variable_names_parsed;
+
+ GDate next_instance_date;
+
+ /** GList<GncSxInstance*> **/
+ GList *list; // @fixme: s/list/?/
+} GncSxInstances;
+
+typedef enum
+{
+ SX_INSTANCE_STATE_IGNORED,
+ SX_INSTANCE_STATE_POSTPONED,
+ SX_INSTANCE_STATE_TO_CREATE,
+ SX_INSTANCE_STATE_REMINDER,
+ SX_INSTANCE_STATE_CREATED,
+ SX_INSTANCE_STATE_MAX_STATE
+} GncSxInstanceState;
+
+typedef struct _GncSxVariable
+{
+ gchar *name;
+ gnc_numeric value; /**< only numeric values are supported. **/
+ gboolean editable;
+} GncSxVariable;
+
+typedef struct _GncSxInstance
+{
+ GncSxInstances *parent; /**< the parent instances collection. **/
+ void *temporal_state; /**< the sx creation temporal state. **/
+ GncSxInstanceState orig_state; /**< the original state at generation time. **/
+ GncSxInstanceState state; /**< the current state of the instance (during editing) **/
+ GDate date; /**< the instance date. **/
+ GHashTable *variable_bindings; /**< variable bindings. **/
+} GncSxInstance;
+
+GType gnc_sx_instance_model_get_type(void);
+
+GncSxInstanceModel* gnc_sx_get_instances(GDate *range_end);
+
+/** @return GList<GncSxVariable*> **/
+GList *gnc_sx_instance_get_variables(GncSxInstance *inst);
+
+Account* gnc_sx_get_template_transaction_account(SchedXaction *sx);
+
+/**
+ * @return caller-owned.
+ **/
+GHashTable* gnc_sx_instance_get_variables_for_parser(GHashTable *instance_var_hash);
+
+G_END_DECLS
+
+#endif // _GNC_SX_INSTANCE_MODEL_H
Modified: gnucash/branches/sx-cleanup/src/core-utils/gnc-glib-utils.c
===================================================================
--- gnucash/branches/sx-cleanup/src/core-utils/gnc-glib-utils.c 2006-10-09 19:47:15 UTC (rev 14947)
+++ gnucash/branches/sx-cleanup/src/core-utils/gnc-glib-utils.c 2006-10-09 23:05:38 UTC (rev 14948)
@@ -27,7 +27,7 @@
#include "gnc-glib-utils.h"
-int
+int
safe_utf8_collate (const char * da, const char * db)
{
if (da && !(*da))
@@ -65,3 +65,14 @@
memmove(end, end+1, len); /* shuffle the remainder one byte */
} while (!g_utf8_validate(str, -1, (const gchar **)&end));
}
+
+GList*
+gnc_g_list_map(GList* list, GncGMapFunc fn, gpointer user_data)
+{
+ GList *rtn = NULL;
+ for (; list != NULL; list = list->next)
+ {
+ rtn = g_list_append(rtn, (*fn)(list->data, user_data));
+ }
+ return rtn;
+}
Modified: gnucash/branches/sx-cleanup/src/core-utils/gnc-glib-utils.h
===================================================================
--- gnucash/branches/sx-cleanup/src/core-utils/gnc-glib-utils.h 2006-10-09 19:47:15 UTC (rev 14947)
+++ gnucash/branches/sx-cleanup/src/core-utils/gnc-glib-utils.h 2006-10-09 23:05:38 UTC (rev 14948)
@@ -75,6 +75,13 @@
void gnc_utf8_strip_invalid (gchar *str);
+typedef gpointer (*GncGMapFunc)(gpointer data, gpointer user_data);
+
+/**
+ * @return Caller-owned GList* of results of apply `fn` to `list` in order.
+ **/
+GList* gnc_g_list_map(GList* list, GncGMapFunc fn, gpointer user_data);
+
/** @} */
#endif /* GNC_GLIB_UTILS_H */
Modified: gnucash/branches/sx-cleanup/src/gnome/Makefile.am
===================================================================
--- gnucash/branches/sx-cleanup/src/gnome/Makefile.am 2006-10-09 19:47:15 UTC (rev 14947)
+++ gnucash/branches/sx-cleanup/src/gnome/Makefile.am 2006-10-09 23:05:38 UTC (rev 14948)
@@ -60,6 +60,7 @@
gnc-plugin-page-sx-list.c \
gnc-plugin-page-register.c \
gnc-split-reg.c \
+ gnc-sx-list-tree-model-adapter.c \
lot-viewer.c \
reconcile-list.c \
top-level.c \
@@ -98,6 +99,7 @@
gnc-plugin-page-sx-list.h \
gnc-plugin-page-register.h \
gnc-split-reg.h \
+ gnc-sx-list-tree-model-adapter.h \
gw-gnc.h \
lot-viewer.h \
reconcile-list.h \
Modified: gnucash/branches/sx-cleanup/src/gnome/dialog-sx-editor.c
===================================================================
--- gnucash/branches/sx-cleanup/src/gnome/dialog-sx-editor.c 2006-10-09 19:47:15 UTC (rev 14947)
+++ gnucash/branches/sx-cleanup/src/gnome/dialog-sx-editor.c 2006-10-09 23:05:38 UTC (rev 14948)
@@ -41,6 +41,7 @@
#include "gnc-date.h"
#include "gnc-date-edit.h"
#include "gnc-dense-cal.h"
+#include "gnc-dense-cal-store.h"
#include "gnc-embedded-window.h"
#include "gnc-engine.h"
#include "gnc-frequency.h"
@@ -117,7 +118,7 @@
GNCLedgerDisplay *ledger;
GNCFrequency *gncfreq;
- GncDenseCalTransientModel *dense_cal_model;
+ GncDenseCalStore *dense_cal_model;
GncDenseCal *example_cal;
GtkEditable *nameEntry;
@@ -1264,7 +1265,7 @@
gtk_container_add( GTK_CONTAINER(b), GTK_WIDGET(sxed->gncfreq) );
b = GTK_BOX(glade_xml_get_widget( sxed->gxml, "example_cal_hbox" ));
- sxed->dense_cal_model = gnc_dense_cal_transient_model_new(EX_CAL_NUM_MONTHS*31);
+ sxed->dense_cal_model = gnc_dense_cal_store_new(EX_CAL_NUM_MONTHS*31);
sxed->example_cal = GNC_DENSE_CAL(gnc_dense_cal_new_with_model(GNC_DENSE_CAL_MODEL(sxed->dense_cal_model)));
g_assert(sxed->example_cal);
gnc_dense_cal_set_num_months( sxed->example_cal, EX_CAL_NUM_MONTHS );
@@ -1554,7 +1555,7 @@
if (!g_date_valid(&start_date))
{
/* Nothing to do. */
- gnc_dense_cal_transient_model_clear(sxed->dense_cal_model);
+ gnc_dense_cal_store_clear(sxed->dense_cal_model);
xaccFreqSpecFree(fs);
return;
}
@@ -1567,17 +1568,17 @@
{
GDate end_date;
g_date_set_time_t(&end_date, gnc_date_edit_get_date(sxed->endDateEntry));
- gnc_dense_cal_transient_model_update_date_end(sxed->dense_cal_model, &start_date, fs, &end_date);
+ gnc_dense_cal_store_update_date_end(sxed->dense_cal_model, &start_date, fs, &end_date);
}
else if (gtk_toggle_button_get_active(sxed->optEndNone))
{
- gnc_dense_cal_transient_model_update_no_end(sxed->dense_cal_model, &start_date, fs);
+ gnc_dense_cal_store_update_no_end(sxed->dense_cal_model, &start_date, fs);
}
else if (gtk_toggle_button_get_active(sxed->optEndCount))
{
gint num_remain
= gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(sxed->endRemainSpin));
- gnc_dense_cal_transient_model_update_count_end(sxed->dense_cal_model, &start_date, fs, num_remain);
+ gnc_dense_cal_store_update_count_end(sxed->dense_cal_model, &start_date, fs, num_remain);
}
else
{
Modified: gnucash/branches/sx-cleanup/src/gnome/dialog-sx-editor.h
===================================================================
--- gnucash/branches/sx-cleanup/src/gnome/dialog-sx-editor.h 2006-10-09 19:47:15 UTC (rev 14947)
+++ gnucash/branches/sx-cleanup/src/gnome/dialog-sx-editor.h 2006-10-09 23:05:38 UTC (rev 14948)
@@ -33,13 +33,10 @@
#define KEY_CREATE_DAYS "create_days"
#define KEY_REMIND_DAYS "remind_days"
-struct _GncSxEditorDialog;
-
typedef struct _GncSxEditorDialog GncSxEditorDialog;
-GncSxEditorDialog *
-gnc_ui_scheduled_xaction_editor_dialog_create(SchedXaction *sx,
- gboolean newSX);
+GncSxEditorDialog* gnc_ui_scheduled_xaction_editor_dialog_create(SchedXaction *sx,
+ gboolean newSX);
void gnc_ui_scheduled_xaction_editor_dialog_destroy(GncSxEditorDialog *sxd);
Modified: gnucash/branches/sx-cleanup/src/gnome/dialog-sx-from-trans.c
===================================================================
--- gnucash/branches/sx-cleanup/src/gnome/dialog-sx-from-trans.c 2006-10-09 19:47:15 UTC (rev 14947)
+++ gnucash/branches/sx-cleanup/src/gnome/dialog-sx-from-trans.c 2006-10-09 23:05:38 UTC (rev 14948)
@@ -24,24 +24,24 @@
#include "config.h"
-#include <gtk/gtk.h>
-#include <glib/gi18n.h>
-#include "glib-compat.h"
-
-#include "gnc-engine.h"
-#include "SX-book.h"
-#include "SX-ttinfo.h"
-#include "SchedXaction.h"
-#include "gnc-component-manager.h"
#include "dialog-sx-editor.h"
#include "dialog-sx-from-trans.h"
#include "dialog-utils.h"
+#include "glib-compat.h"
+#include "gnc-component-manager.h"
#include "gnc-date-edit.h"
-#include "qof.h"
+#include "gnc-dense-cal-store.h"
+#include "gnc-dense-cal.h"
+#include "gnc-engine.h"
#include "gnc-gconf-utils.h"
+#include "gnc-ui-util.h"
#include "gnc-ui.h"
-#include "gnc-ui-util.h"
-#include "gnc-dense-cal.h"
+#include "qof.h"
+#include "SchedXaction.h"
+#include "SX-book.h"
+#include "SX-ttinfo.h"
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
#define SX_GLADE_FILE "sched-xact.glade"
#define SXFTD_DIALOG_GLADE_NAME "sx_from_real_trans"
@@ -92,7 +92,7 @@
Transaction *trans;
SchedXaction *sx;
- GncDenseCalTransientModel *dense_cal_model;
+ GncDenseCalStore *dense_cal_model;
GncDenseCal *example_cal;
GNCDateEdit *startDateGDE, *endDateGDE;
@@ -101,7 +101,7 @@
typedef struct
{
- gdctm_end_type type;
+ gdcs_end_type type;
GDate end_date;
guint n_occurrences;
} getEndTuple;
@@ -365,7 +365,7 @@
int num_marks = SXFTD_EXCAL_NUM_MONTHS * 31;
w = GTK_WIDGET(glade_xml_get_widget( sxfti->gxml, SXFTD_EX_CAL_FRAME ));
- sxfti->dense_cal_model = gnc_dense_cal_transient_model_new(num_marks);
+ sxfti->dense_cal_model = gnc_dense_cal_store_new(num_marks);
sxfti->example_cal = GNC_DENSE_CAL(gnc_dense_cal_new_with_model(GNC_DENSE_CAL_MODEL(sxfti->dense_cal_model)));
g_assert( sxfti->example_cal );
@@ -705,13 +705,13 @@
switch (get.type)
{
case NEVER_END:
- gnc_dense_cal_transient_model_update_no_end(sxfti->dense_cal_model, &startDate, fs);
+ gnc_dense_cal_store_update_no_end(sxfti->dense_cal_model, &startDate, fs);
break;
case END_ON_DATE:
- gnc_dense_cal_transient_model_update_date_end(sxfti->dense_cal_model, &startDate, fs, &get.end_date);
+ gnc_dense_cal_store_update_date_end(sxfti->dense_cal_model, &startDate, fs, &get.end_date);
break;
case END_AFTER_N_OCCS:
- gnc_dense_cal_transient_model_update_count_end(sxfti->dense_cal_model, &startDate, fs, get.n_occurrences);
+ gnc_dense_cal_store_update_count_end(sxfti->dense_cal_model, &startDate, fs, get.n_occurrences);
break;
default:
printf("unknown get.type [%d]\n", get.type);
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 2006-10-09 19:47:15 UTC (rev 14947)
+++ gnucash/branches/sx-cleanup/src/gnome/dialog-sx-since-last-run.c 2006-10-09 23:05:38 UTC (rev 14948)
@@ -27,7 +27,8 @@
#include "dialog-utils.h"
#include "gnc-exp-parser.h"
-#include "gnc-plugin-page-sx-list.h"
+// #include "gnc-plugin-page-sx-list.h"
+#include "gnc-sx-instance-model.h"
#include "dialog-sx-since-last-run.h"
#include "gnc-ui-util.h"
@@ -53,7 +54,6 @@
struct _GncSxSinceLastRunDialog
{
GtkWidget *dialog;
- //GncSxInstanceModel *instances;
GncSxSlrTreeModelAdapter *editing_model;
GtkTreeView *instance_view;
GtkToggleButton *review_created_txns_toggle;
Modified: gnucash/branches/sx-cleanup/src/gnome/gnc-plugin-page-sx-list.c
===================================================================
--- gnucash/branches/sx-cleanup/src/gnome/gnc-plugin-page-sx-list.c 2006-10-09 19:47:15 UTC (rev 14947)
+++ gnucash/branches/sx-cleanup/src/gnome/gnc-plugin-page-sx-list.c 2006-10-09 23:05:38 UTC (rev 14948)
@@ -49,8 +49,12 @@
#include "gnc-commodity.h"
#include "gnc-event.h"
#include "gnc-dense-cal.h"
+#include "gnc-glib-utils.h"
#include "gnc-icons.h"
#include "gnc-plugin-page-sx-list.h"
+#include "gnc-sx-instance-model.h"
+#include "gnc-sx-instance-dense-cal-adapter.h"
+#include "gnc-sx-list-tree-model-adapter.h"
#include "gnc-ui-util.h"
#include "gnc-main-window.h"
#include "dialog-utils.h"
@@ -86,106 +90,6 @@
static GObjectClass *parent_class = NULL;
-/* ------------------------------------------------------------ */
-
-GType gnc_sx_instance_model_get_type(void);
-static void gnc_sx_instance_model_class_init (GncSxInstanceModelClass *klass);
-static void gnc_sx_instance_model_init(GTypeInstance *instance, gpointer klass);
-static GncSxInstanceModel* gnc_sx_instance_model_new(void);
-
-static GncSxInstance* gnc_sx_instance_new(GncSxInstances *parent, GncSxInstanceState state, GDate *date, void *temporal_state, gint sequence_num);
-
-static void sxsl_get_sx_vars(SchedXaction *sx, GHashTable *var_hash);
-static gint _get_vars_helper(Transaction *txn, void *var_hash_data);
-static int parse_vars_from_formula(const char *formula, GHashTable *varHash, gnc_numeric *result);
-
-static GncSxVariable* gnc_sx_variable_new(gchar *name);
-
-static void _gnc_sx_instance_event_handler(QofEntity *ent, QofEventId event_type, gpointer user_data, gpointer evt_data);
-
-#define GNC_TYPE_SX_INSTANCE_MODEL (gnc_sx_instance_model_get_type ())
-#define GNC_SX_INSTANCE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_SX_INSTANCE_MODEL, GncSxInstanceModel))
-#define GNC_SX_INSTANCE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_SX_INSTANCE_MODEL, GncSxInstanceModelClass))
-#define GNC_IS_SX_INSTANCE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_SX_INSTANCE_MODEL))
-#define GNC_IS_SX_INSTANCE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_SX_INSTANCE_MODEL))
-#define GNC_SX_INSTANCE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_TYPE_SX_INSTANCE_MODEL, GncSxInstanceModelClass))
-
-GncSxInstanceModel* gnc_sx_get_instances(GDate *range_end);
-
-/* ------------------------------------------------------------ */
-
-typedef struct _GncSxInstanceDenseCalAdapterClass
-{
- GObjectClass parent;
-} GncSxInstanceDenseCalAdapterClass;
-
-struct _GncSxInstanceDenseCalAdapter
-{
- GObject parent;
-
- GncSxInstanceModel *instances;
-};
-
-GncSxInstanceDenseCalAdapter* gnc_sx_instance_dense_cal_adapter_new(GncSxInstanceModel *instances);
-GType gnc_sx_instance_dense_cal_adapter_get_type(void);
-static GList* gsidca_get_contained(GncDenseCalModel *model);
-static gchar* gsidca_get_name(GncDenseCalModel *model, guint tag);
-static gchar* gsidca_get_info(GncDenseCalModel *model, guint tag);
-static gint gsidca_get_instance_count(GncDenseCalModel *model, guint tag);
-static void gsidca_get_instance(GncDenseCalModel *model, guint tag, gint instance_index, GDate *date);
-
-#define GNC_TYPE_SX_INSTANCE_DENSE_CAL_ADAPTER (gnc_sx_instance_dense_cal_adapter_get_type ())
-#define GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_SX_INSTANCE_DENSE_CAL_ADAPTER, GncSxInstanceDenseCalAdapter))
-#define GNC_SX_INSTANCE_DENSE_CAL_ADAPTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_SX_INSTANCE_DENSE_CAL_ADAPTER, GncSxInstanceDenseCalAdapterClass))
-#define GNC_IS_SX_INSTANCE_DENSE_CAL_ADAPTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_SX_INSTANCE_DENSE_CAL_ADAPTER))
-#define GNC_IS_SX_INSTANCE_DENSE_CAL_ADAPTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_SX_INSTANCE_DENSE_CAL_ADAPTER))
-#define GNC_SX_INSTANCE_DENSE_CAL_ADAPTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_TYPE_SX_INSTANCE_DENSE_CAL_ADAPTER, GncSxInstanceDenseCalAdapterClass))
-
-/* ------------------------------------------------------------ */
-
-struct _GncSxListTreeModelAdapter
-{
- GObject parent;
-
- /* protected */
- GncSxInstanceModel *instances;
- GtkTreeStore *real;
-};
-
-typedef struct _GncSxListTreeModelAdapterClass
-{
- GObjectClass parent;
-} GncSxListTreeModelAdapterClass;
-
-GType gnc_sx_list_tree_model_adapter_get_type(void);
-static void gnc_sx_list_tree_model_adapter_class_init(GncSxListTreeModelAdapterClass *klass);
-static void gnc_sx_list_tree_model_adapter_interface_init(gpointer g_iface, gpointer iface_data);
-static void gnc_sx_list_tree_model_adapter_init(GTypeInstance *instance, gpointer klass);
-GncSxListTreeModelAdapter* gnc_sx_list_tree_model_adapter_new(GncSxInstanceModel *instances);
-
-GncSxInstances* gnc_sx_list_tree_model_adapter_get_sx_instances(GncSxListTreeModelAdapter *model, GtkTreeIter *iter);
-
-#define GNC_TYPE_SX_LIST_TREE_MODEL_ADAPTER (gnc_sx_list_tree_model_adapter_get_type ())
-#define GNC_SX_LIST_TREE_MODEL_ADAPTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_SX_LIST_TREE_MODEL_ADAPTER, GncSxListTreeModelAdapter))
-#define GNC_SX_LIST_TREE_MODEL_ADAPTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_SX_LIST_TREE_MODEL_ADAPTER, GncSxListTreeModelAdapterClass))
-#define GNC_IS_SX_LIST_TREE_MODEL_ADAPTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_SX_LIST_TREE_MODEL_ADAPTER))
-#define GNC_IS_SX_LIST_TREE_MODEL_ADAPTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_SX_LIST_TREE_MODEL_ADAPTER))
-#define GNC_SX_LIST_TREE_MODEL_ADAPTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_TYPE_SX_LIST_TREE_MODEL_ADAPTER, GncSxListTreeModelAdapterClass))
-
-/* ------------------------------------------------------------ */
-
-typedef gpointer (*GMapFunc)(gpointer data, gpointer user_data);
-static GList*
-g_list_map(GList* list, GMapFunc fn, gpointer user_data)
-{
- GList *rtn = NULL;
- for (; list != NULL; list = list->next)
- {
- rtn = g_list_append(rtn, (*fn)(list->data, user_data));
- }
- return rtn;
-}
-
/************************************************************
* Prototypes *
************************************************************/
@@ -542,8 +446,6 @@
LEAVE(" ");
}
-
-
/**
* Create a new sx list page based on the information saved during a previous
* instantiation of gnucash.
@@ -634,7 +536,7 @@
return;
}
- to_edit = g_list_map(selected_paths, (GMapFunc)_sx_for_path, model);
+ to_edit = gnc_g_list_map(selected_paths, (GncGMapFunc)_sx_for_path, model);
g_list_foreach(to_edit, (GFunc)_edit_sx, NULL);
g_list_free(to_edit);
g_list_foreach(selected_paths, (GFunc)gtk_tree_path_free, NULL);
@@ -684,7 +586,7 @@
return;
}
- to_delete = g_list_map(selected_paths, (GMapFunc)_sx_for_path, model);
+ to_delete = gnc_g_list_map(selected_paths, (GncGMapFunc)_sx_for_path, model);
{
GList *list;
for (list = to_delete; list != NULL; list = list->next)
@@ -773,969 +675,5 @@
#endif /* 0 - compare/sort fns */
-/* ------------------------------------------------------------ */
-
-static void
-_sx_var_to_raw_numeric(gchar *name, GncSxVariable *var, GHashTable *parser_var_hash)
-{
- g_hash_table_insert(parser_var_hash, name, &var->value);
-}
-
-static void
-_var_numeric_to_sx_var(gchar *name, gnc_numeric *num, GHashTable *sx_var_hash)
-{
- gpointer p_var;
- if (!g_hash_table_lookup_extended(sx_var_hash, name, NULL, &p_var))
- {
- p_var = (gpointer)gnc_sx_variable_new(name);
- g_hash_table_insert(sx_var_hash, name, p_var);
- }
- ((GncSxVariable*)p_var)->value = *num;
-}
-
-static void
-_wipe_parsed_sx_var(gchar *key, GncSxVariable *var, gpointer unused_user_data)
-{
- var->value = gnc_numeric_error(GNC_ERROR_ARG);
-}
-
-/**
- * @return caller-owned.
- **/
-GHashTable*
-gnc_sx_instance_get_variables_for_parser(GHashTable *instance_var_hash)
-{
- GHashTable *parser_vars;
- parser_vars = g_hash_table_new(g_str_hash, g_str_equal);
- g_hash_table_foreach(instance_var_hash, (GHFunc)_sx_var_to_raw_numeric, parser_vars);
- return parser_vars;
-}
-
-static int
-parse_vars_from_formula(const char *formula,
- GHashTable *var_hash,
- gnc_numeric *result)
-{
- gnc_numeric num;
- char *errLoc;
- int toRet = 0;
- GHashTable *parser_vars;
-
- // convert var_hash -> variables for the parser.
- parser_vars = gnc_sx_instance_get_variables_for_parser(var_hash);
-
- if (!gnc_exp_parser_parse_separate_vars(formula, &num, &errLoc, parser_vars))
- {
- toRet = -1;
- }
-
- // convert back.
- g_hash_table_foreach(parser_vars, (GHFunc)_var_numeric_to_sx_var, var_hash);
- g_hash_table_destroy(parser_vars);
-
- if (result != NULL)
- {
- *result = num;
- }
-
- return toRet;
-}
-
-static GncSxVariable*
-gnc_sx_variable_new(gchar *name)
-{
- GncSxVariable *var = g_new0(GncSxVariable, 1);
- var->name = name;
- var->value = gnc_numeric_error(GNC_ERROR_ARG);
- var->editable = TRUE;
- return var;
-}
-
-static gint
-_get_vars_helper(Transaction *txn, void *var_hash_data)
-{
- GHashTable *var_hash = (GHashTable*)var_hash_data;
- GList *split_list;
- kvp_frame *kvpf;
- kvp_value *kvp_val;
- Split *s;
- char *str;
- gnc_commodity *first_cmdty = NULL;
-
- split_list = xaccTransGetSplitList(txn);
- if (split_list == NULL)
- {
- return 1;
- }
-
- for ( ; split_list; split_list = split_list->next)
- {
- gnc_commodity *split_cmdty = NULL;
- GUID *acct_guid;
- Account *acct;
-
- s = (Split*)split_list->data;
- kvpf = xaccSplitGetSlots(s);
- kvp_val = kvp_frame_get_slot_path(kvpf,
- GNC_SX_ID,
- GNC_SX_ACCOUNT,
- NULL);
- acct_guid = kvp_value_get_guid(kvp_val);
- acct = xaccAccountLookup(acct_guid, gnc_get_current_book());
- split_cmdty = xaccAccountGetCommodity(acct);
- if (first_cmdty == NULL)
- {
- first_cmdty = split_cmdty;
- }
-
- if (! gnc_commodity_equal(split_cmdty, first_cmdty))
- {
- GncSxVariable *var;
- GString *var_name;
-
- var_name = g_string_sized_new(16);
- g_string_printf(var_name, "%s -> %s",
- gnc_commodity_get_mnemonic(split_cmdty),
- gnc_commodity_get_mnemonic(first_cmdty));
- var = gnc_sx_variable_new(g_strdup(var_name->str));
- g_hash_table_insert(var_hash, var->name, var);
- g_string_free(var_name, TRUE);
- }
-
- // existing... ------------------------------------------
- kvp_val = kvp_frame_get_slot_path(kvpf,
- GNC_SX_ID,
- GNC_SX_CREDIT_FORMULA,
- NULL);
- if (kvp_val != NULL)
- {
- str = kvp_value_get_string(kvp_val);
- if (str && strlen(str) != 0)
- {
- parse_vars_from_formula(str, var_hash, NULL);
- }
- }
-
- kvp_val = kvp_frame_get_slot_path(kvpf,
- GNC_SX_ID,
- GNC_SX_DEBIT_FORMULA,
- NULL);
- if (kvp_val != NULL)
- {
- str = kvp_value_get_string(kvp_val);
- if (str && strlen(str) != 0)
- {
- parse_vars_from_formula(str, var_hash, NULL);
- }
- }
- }
-
- return 0;
-}
-
-Account*
-gnc_sx_get_template_transaction_account(SchedXaction *sx)
-{
- AccountGroup *template_group;
- Account *sx_template_acct;
- const char *sx_guid_str;
-
- template_group = gnc_book_get_template_group(gnc_get_current_book());
- sx_guid_str = guid_to_string(xaccSchedXactionGetGUID(sx));
- /* Get account named after guid string. */
- sx_template_acct = xaccGetAccountFromName(template_group, sx_guid_str);
- return sx_template_acct;
-}
-
-static void
-sxsl_get_sx_vars(SchedXaction *sx, GHashTable *var_hash)
-{
- Account *sx_template_acct;
- sx_template_acct = gnc_sx_get_template_transaction_account(sx);
- xaccAccountForEachTransaction(sx_template_acct, _get_vars_helper, var_hash);
-}
-
-static void
-_clone_sx_var_hash_entry(gpointer key, gpointer value, gpointer user_data)
-{
- GHashTable *to = (GHashTable*)user_data;
- GncSxVariable *to_copy = (GncSxVariable*)value;
- GncSxVariable *var = gnc_sx_variable_new(to_copy->name);
- var->value = to_copy->value;
- var->editable = to_copy->editable;
- g_hash_table_insert(to, key, var);
-}
-
-static GncSxInstance*
-gnc_sx_instance_new(GncSxInstances *parent, GncSxInstanceState state, GDate *date, void *temporal_state, gint sequence_num)
-{
- GncSxInstance *rtn = g_new0(GncSxInstance, 1);
- rtn->parent = parent;
- rtn->orig_state = state;
- rtn->state = state;
- g_date_clear(&rtn->date, 1);
- rtn->date = *date;
- rtn->temporal_state = gnc_sx_clone_temporal_state(temporal_state);
-
- if (! parent->variable_names_parsed)
- {
- parent->variable_names = g_hash_table_new(g_str_hash, g_str_equal);
- sxsl_get_sx_vars(parent->sx, parent->variable_names);
- g_hash_table_foreach(parent->variable_names, (GHFunc)_wipe_parsed_sx_var, NULL);
- parent->variable_names_parsed = TRUE;
-
- // @@fixme: add sequence_num as `i`, non-editable
- }
-
- rtn->variable_bindings = g_hash_table_new(g_str_hash, g_str_equal);
- g_hash_table_foreach(parent->variable_names, _clone_sx_var_hash_entry, rtn->variable_bindings);
- return rtn;
-}
-
-static void
-_build_list_from_hash_elts(gpointer key, gpointer value, gpointer user_data)
-{
- GList **list = (GList**)user_data;
- *list = g_list_append(*list, value);
-}
-
-GList *
-gnc_sx_instance_get_variables(GncSxInstance *inst)
-{
- GList *vars = NULL;
- g_hash_table_foreach(inst->variable_bindings, _build_list_from_hash_elts, &vars);
-
- // @@fixme sort by name
- return vars;
-}
-
-static GncSxInstances*
-_gnc_sx_gen_instances(gpointer *data, gpointer user_data)
-{
- GncSxInstances *instances = g_new0(GncSxInstances, 1);
- SchedXaction *sx = (SchedXaction*)data;
- GDate *range_end = (GDate*)user_data;
- GDate creation_end, remind_end;
- GDate cur_date;
- void *sequence_ctx;
-
- instances->sx = sx;
-
- creation_end = *range_end;
- g_date_add_days(&creation_end, xaccSchedXactionGetAdvanceCreation(sx));
- remind_end = creation_end;
- g_date_add_days(&remind_end, xaccSchedXactionGetAdvanceReminder(sx));
-
- /* postponed */
- {
- GList *postponed = gnc_sx_get_defer_instances(sx);
- for ( ; postponed != NULL; postponed = postponed->next)
- {
- GDate inst_date;
- int seq_num;
- GncSxInstance *inst;
-
- g_date_clear(&inst_date, 1);
- inst_date = xaccSchedXactionGetNextInstance(sx, postponed->data);
- seq_num = gnc_sx_get_instance_count(sx, postponed->data);
- inst = gnc_sx_instance_new(instances, SX_INSTANCE_STATE_POSTPONED, &inst_date, postponed->data, seq_num);
- //inst->temporal_state = postponed->data;
- instances->list = g_list_append(instances->list, inst);
- }
- }
-
- /* to-create */
- g_date_clear(&cur_date, 1);
- sequence_ctx = gnc_sx_create_temporal_state(sx);
- cur_date = xaccSchedXactionGetInstanceAfter(sx, &cur_date, sequence_ctx);
- instances->next_instance_date = cur_date;
- while (g_date_valid(&cur_date) && g_date_compare(&cur_date, &creation_end) <= 0)
- {
- GncSxInstance *inst;
- int seq_num;
- seq_num = gnc_sx_get_instance_count(sx, sequence_ctx);
- inst = gnc_sx_instance_new(instances, SX_INSTANCE_STATE_TO_CREATE, &cur_date, sequence_ctx, seq_num);
- instances->list = g_list_append(instances->list, inst);
- gnc_sx_incr_temporal_state(sx, sequence_ctx);
- cur_date = xaccSchedXactionGetInstanceAfter(sx, &cur_date, sequence_ctx);
- }
-
- /* reminders */
- while (g_date_valid(&cur_date) && g_date_compare(&cur_date, &remind_end) <= 0)
- {
- GncSxInstance *inst;
- int seq_num;
- seq_num = gnc_sx_get_instance_count(sx, sequence_ctx);
- inst = gnc_sx_instance_new(instances, SX_INSTANCE_STATE_REMINDER, &cur_date, sequence_ctx, seq_num);
- instances->list = g_list_append(instances->list, inst);
- gnc_sx_incr_temporal_state(sx, sequence_ctx);
- cur_date = xaccSchedXactionGetInstanceAfter(sx, &cur_date, sequence_ctx);
- }
-
- return instances;
-}
-
-GncSxInstanceModel*
-gnc_sx_get_instances(GDate *range_end)
-{
- GncSxInstanceModel *instances;
- GList *sxes;
-
- g_assert(range_end != NULL);
- g_assert(g_date_valid(range_end));
-
- instances = gnc_sx_instance_model_new();
- instances->range_end = *range_end;
- sxes = gnc_book_get_schedxactions(gnc_get_current_book())->sx_list;
- instances->sx_instance_list = g_list_map(sxes, (GMapFunc)_gnc_sx_gen_instances, (gpointer)range_end);
-
- return instances;
-}
-
-static GncSxInstanceModel*
-gnc_sx_instance_model_new(void)
-{
- return GNC_SX_INSTANCE_MODEL(g_object_new(GNC_TYPE_SX_INSTANCE_MODEL, NULL));
-}
-
-GType
-gnc_sx_instance_model_get_type(void)
-{
- static GType type = 0;
- if (type == 0) {
- static const GTypeInfo info = {
- sizeof (GncSxInstanceModelClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc)gnc_sx_instance_model_class_init, /* class_init */
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GncSxInstanceModel),
- 0, /* n_preallocs */
- (GInstanceInitFunc)gnc_sx_instance_model_init /* instance_init */
- };
- type = g_type_register_static (G_TYPE_OBJECT,
- "GncSxInstanceModelType",
- &info, 0);
- }
- return type;
-}
-
-static void
-gnc_sx_instance_model_dispose (GObject *object)
-{
- printf("dispose\n");
-}
-
-static void
-gnc_sx_instance_model_finalize (GObject *object)
-{
- printf("finalize\n");
-}
-
-static void
-gnc_sx_instance_model_class_init (GncSxInstanceModelClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS(klass);
- object_class->dispose = gnc_sx_instance_model_dispose;
- object_class->finalize = gnc_sx_instance_model_finalize;
-
- klass->removing_signal_id =
- g_signal_new("removing",
- GNC_TYPE_SX_INSTANCE_MODEL,
- G_SIGNAL_RUN_FIRST,
- 0, /* class offset */
- NULL, /* accumulator */
- NULL, /* accum data */
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE,
- 1,
- G_TYPE_POINTER);
-
- klass->updated_signal_id =
- g_signal_new("updated",
- GNC_TYPE_SX_INSTANCE_MODEL,
- G_SIGNAL_RUN_FIRST,
- 0, /* class offset */
- NULL, /* accumulator */
- NULL, /* accum data */
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE,
- 0, NULL);
-
- klass->added_signal_id =
- g_signal_new("added",
- GNC_TYPE_SX_INSTANCE_MODEL,
- G_SIGNAL_RUN_FIRST,
- 0, /* class offset */
- NULL, /* accumulator */
- NULL, /* accum data */
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE,
- 1,
- G_TYPE_POINTER);
-}
-
-static void
-gnc_sx_instance_model_init(GTypeInstance *instance, gpointer klass)
-{
- GncSxInstanceModel *inst = (GncSxInstanceModel*)instance;
-
- g_date_clear(&inst->range_end, 1);
- inst->sx_instance_list = NULL;
- inst->qof_event_handler_id = qof_event_register_handler(_gnc_sx_instance_event_handler, inst);
-}
-
-static void
-_gnc_sx_instance_event_handler(QofEntity *ent, QofEventId event_type, gpointer user_data, gpointer evt_data)
-{
- GncSxInstanceModel *instances = GNC_SX_INSTANCE_MODEL(user_data);
-
- /* selection rules {
- // (gnc_collection_get_schedxaction_list(book), GNC_EVENT_ITEM_ADDED)
- // (gnc_collection_get_schedxaction_list(book), GNC_EVENT_ITEM_REMOVED)
- // (GNC_IS_SX(ent), QOF_EVENT_MODIFIED)
- // } */
- if (!(GNC_IS_SX(ent) || GNC_IS_SXES(ent)))
- return;
-
- if (GNC_IS_SX(ent))
- {
- SchedXaction *sx;
- sx = GNC_SX(ent);
- if (event_type & QOF_EVENT_MODIFY)
- {
- /* @re-generate instance, update*/
- }
- /* else { unsupported event type; ignore } */
- }
- else if (GNC_IS_SXES(ent))
- {
- SchedXactions *sxes = GNC_SXES(ent);
- SchedXaction *sx = GNC_SX(evt_data);
-
- sxes = NULL;
- if (event_type & GNC_EVENT_ITEM_REMOVED)
- {
- gpointer sx_instance_to_remove = NULL;
- GList *list;
-
- /* find, remove, update */
- for (list = instances->sx_instance_list; list != NULL; list = list->next)
- {
- if (sx == ((GncSxInstances*)list->data)->sx)
- {
- sx_instance_to_remove = list->data;
- break;
- }
- }
- if (sx_instance_to_remove != NULL)
- {
- g_signal_emit_by_name(instances, "removing", GUINT_TO_POINTER(GPOINTER_TO_UINT(((GncSxInstances*)sx_instance_to_remove)->sx)));
- instances->sx_instance_list = g_list_remove(instances->sx_instance_list, sx_instance_to_remove);
- g_signal_emit_by_name(instances, "updated"); // @@fixme remove
- }
- else { printf("err\n"); }
- }
- 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", GUINT_TO_POINTER(GPOINTER_TO_UINT(sx)));
- g_signal_emit_by_name(instances, "updated"); // @fixme remove
- }
- /* else { printf("unsupported event type [%d]\n", event_type); } */
- }
-}
-
-/* ------------------------------------------------------------ */
-
-static void
-gnc_sx_instance_dense_cal_adapter_class_init(GncSxInstanceDenseCalAdapterClass *klass)
-{
- ; /* nop */
-}
-
-static void
-gnc_sx_instance_dense_cal_adapter_init(GTypeInstance *instance, gpointer klass)
-{
- /*GncSxInstanceDenseCalAdapter *adapter = GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(instance);*/
- ; /* nop */
-}
-
-static void
-gnc_sx_instance_dense_cal_adapter_interface_init(gpointer g_iface, gpointer iface_data)
-{
- GncDenseCalModelIface *iface = (GncDenseCalModelIface*)g_iface;
- iface->get_contained = gsidca_get_contained;
- iface->get_name = gsidca_get_name;
- iface->get_info = gsidca_get_info;
- iface->get_instance_count = gsidca_get_instance_count;
- iface->get_instance = gsidca_get_instance;
-}
-
-static void
-gsidca_instances_added_cb(GncSxInstanceModel *model, gpointer instance_added, gpointer user_data)
-{
- GncSxInstanceDenseCalAdapter *adapter = GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(user_data);
- g_signal_emit_by_name(adapter, "added", GPOINTER_TO_UINT(instance_added));
-}
-
-static void
-gsidca_instances_updated_cb(GncSxInstanceModel *model, gpointer user_data)
-{
- GncSxInstanceDenseCalAdapter *adapter = GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(user_data);
- // @@fixme figure out which; emit appropriate signal.
- GList *exposed_tags;
- printf("instances updated\n");
- for (exposed_tags = gsidca_get_contained(GNC_DENSE_CAL_MODEL(adapter)); exposed_tags != NULL; exposed_tags = exposed_tags->next)
- {
- g_signal_emit_by_name(adapter, "update", GPOINTER_TO_UINT(exposed_tags->data));
- }
-}
-
-static void
-gsidca_instances_removing_cb(GncSxInstanceModel *model, gpointer instance_to_be_removed, gpointer user_data)
-{
- GncSxInstanceDenseCalAdapter *adapter = GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(user_data);
- printf("removing instance...\n");
- g_signal_emit_by_name(adapter, "removing", GPOINTER_TO_UINT(instance_to_be_removed));
-}
-
-GncSxInstanceDenseCalAdapter*
-gnc_sx_instance_dense_cal_adapter_new(GncSxInstanceModel *instances)
-{
- GncSxInstanceDenseCalAdapter *adapter = g_object_new(GNC_TYPE_SX_INSTANCE_DENSE_CAL_ADAPTER, NULL);
- adapter->instances = instances;
- g_signal_connect(instances, "added", (GCallback)gsidca_instances_added_cb, adapter);
- g_signal_connect(instances, "updated", (GCallback)gsidca_instances_updated_cb, adapter);
- g_signal_connect(instances, "removing", (GCallback)gsidca_instances_removing_cb, adapter);
- return adapter;
-}
-
-GType
-gnc_sx_instance_dense_cal_adapter_get_type(void)
-{
- static GType type = 0;
- if (type == 0)
- {
- static const GTypeInfo info = {
- sizeof (GncSxInstanceDenseCalAdapterClass),
- NULL, /* base init */
- NULL, /* base finalize */
- (GClassInitFunc)gnc_sx_instance_dense_cal_adapter_class_init,
- NULL, /* class finalize */
- NULL, /* class data */
- sizeof(GncSxInstanceDenseCalAdapter),
- 0, /* n_preallocs */
- (GInstanceInitFunc)gnc_sx_instance_dense_cal_adapter_init
- };
- static const GInterfaceInfo iDenseCalModelInfo = {
- (GInterfaceInitFunc)gnc_sx_instance_dense_cal_adapter_interface_init,
- NULL, /* interface finalize */
- NULL, /* interface data */
- };
-
- type = g_type_register_static (G_TYPE_OBJECT,
- "GncSxInstanceDenseCalAdapterType",
- &info, 0);
- g_type_add_interface_static(type,
- GNC_TYPE_DENSE_CAL_MODEL,
- &iDenseCalModelInfo);
- }
- return type;
-}
-
-static gint
-gsidca_find_sx_with_tag(gconstpointer list_data,
- gconstpointer find_data)
-{
- GncSxInstances *sx_instances = (GncSxInstances*)list_data;
- return (GUINT_TO_POINTER(GPOINTER_TO_UINT(sx_instances->sx)) == find_data ? 0 : 1);
-}
-
-static GList*
-gsidca_get_contained(GncDenseCalModel *model)
-{
- GncSxInstanceDenseCalAdapter *adapter = GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(model);
- //"removing return g_list_map(instances->sxes, sx_to_tag, null);
- GList *list = NULL, *sxes;
- for (sxes = adapter->instances->sx_instance_list; sxes != NULL; sxes = sxes->next)
- {
- GncSxInstances *sx_instances = (GncSxInstances*)sxes->data;
- list = g_list_append(list, GUINT_TO_POINTER(GPOINTER_TO_UINT(sx_instances->sx)));
- }
- return list;
-}
-
-static gchar*
-gsidca_get_name(GncDenseCalModel *model, guint tag)
-{
- GncSxInstanceDenseCalAdapter *adapter = GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(model);
- GncSxInstances *insts
- = (GncSxInstances*)g_list_find_custom(adapter->instances->sx_instance_list, GUINT_TO_POINTER(tag), gsidca_find_sx_with_tag)->data;
- if (insts == NULL)
- return NULL;
- return xaccSchedXactionGetName(insts->sx);
-}
-
-static gchar*
-gsidca_get_info(GncDenseCalModel *model, guint tag)
-{
- GncSxInstanceDenseCalAdapter *adapter = GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(model);
- // g_list_find(instances->sxes, {sx_to_tag, tag}).get_freq_spec().get_freq_str();
- FreqSpec *spec;
- GString *info;
- gchar *info_str;
- GncSxInstances *insts
- = (GncSxInstances*)g_list_find_custom(adapter->instances->sx_instance_list, GUINT_TO_POINTER(tag), gsidca_find_sx_with_tag)->data;
- if (insts == NULL)
- return NULL;
- spec = xaccSchedXactionGetFreqSpec(insts->sx);
- info = g_string_sized_new(16);
- xaccFreqSpecGetFreqStr(spec, info);
- info_str = info->str; // @fixme leaked... :/
- g_string_free(info, FALSE);
- return info_str;
-}
-
-static gint
-gsidca_get_instance_count(GncDenseCalModel *model, guint tag)
-{
- GncSxInstanceDenseCalAdapter *adapter = GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(model);
- // g_list_find(instances->sxes, {sx_to_tag, tag}).length();
- GncSxInstances *insts
- = (GncSxInstances*)g_list_find_custom(adapter->instances->sx_instance_list, GUINT_TO_POINTER(tag), gsidca_find_sx_with_tag)->data;
- if (insts == NULL)
- return 0;
- return g_list_length(insts->list);
-}
-
-static void
-gsidca_get_instance(GncDenseCalModel *model, guint tag, gint instance_index, GDate *date)
-{
- GncSxInstanceDenseCalAdapter *adapter = GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(model);
- GncSxInstance *inst;
- GncSxInstances *insts
- = (GncSxInstances*)g_list_find_custom(adapter->instances->sx_instance_list, GUINT_TO_POINTER(tag), gsidca_find_sx_with_tag)->data;
- if (insts == NULL)
- return;
- inst = (GncSxInstance*)g_list_nth_data(insts->list, instance_index);
- g_date_valid(&inst->date);
- *date = inst->date;
- g_date_valid(date);
-}
-
-/* ------------------------------------------------------------ */
-
-GType
-gnc_sx_list_tree_model_adapter_get_type(void)
-{
- static GType type = 0;
- if (type == 0) {
- static const GTypeInfo info = {
- sizeof (GncSxListTreeModelAdapterClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc)gnc_sx_list_tree_model_adapter_class_init, /* class_init */
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GncSxListTreeModelAdapter),
- 0, /* n_preallocs */
- (GInstanceInitFunc)gnc_sx_list_tree_model_adapter_init /* instance_init */
- };
- static const GInterfaceInfo itreeModel_info = {
- (GInterfaceInitFunc) gnc_sx_list_tree_model_adapter_interface_init, /* interface_init */
- NULL, /* interface_finalize */
- NULL /* interface_data */
- };
-
- type = g_type_register_static (G_TYPE_OBJECT,
- "GncSxListTreeModelAdapterType",
- &info, 0);
- g_type_add_interface_static(type,
- GTK_TYPE_TREE_MODEL,
- &itreeModel_info);
- }
- return type;
-}
-
-static void
-gnc_sx_list_tree_model_adapter_class_init(GncSxListTreeModelAdapterClass *klass)
-{
- ; /* nop */
-}
-
-static GtkTreeModelFlags
-gsltma_get_flags(GtkTreeModel *tree_model)
-{
- return gtk_tree_model_get_flags(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real));
-}
-
-static gint
-gsltma_get_n_columns(GtkTreeModel *tree_model)
-{
- return gtk_tree_model_get_n_columns(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real));
-}
-
-static GType
-gsltma_get_column_type(GtkTreeModel *tree_model, gint index)
-{
- return gtk_tree_model_get_column_type(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), index);
-}
-
-static gboolean
-gsltma_get_iter(GtkTreeModel *tree_model,
- GtkTreeIter *iter,
- GtkTreePath *path)
-{
- return gtk_tree_model_get_iter(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), iter, path);
-}
-
-static GtkTreePath*
-gsltma_get_path(GtkTreeModel *tree_model,
- GtkTreeIter *iter)
-{
- return gtk_tree_model_get_path(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), iter);
-}
-
-static void
-gsltma_get_value(GtkTreeModel *tree_model,
- GtkTreeIter *iter,
- gint column,
- GValue *value)
-{
- gtk_tree_model_get_value(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), iter, column, value);
-}
-
-static gboolean
-gsltma_iter_next(GtkTreeModel *tree_model,
- GtkTreeIter *iter)
-{
- return gtk_tree_model_iter_next(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), iter);
-}
-
-static gboolean
-gsltma_iter_children(GtkTreeModel *tree_model,
- GtkTreeIter *iter,
- GtkTreeIter *parent)
-{
- return gtk_tree_model_iter_children(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), iter, parent);
-}
-
-static gboolean
-gsltma_iter_has_child(GtkTreeModel *tree_model,
- GtkTreeIter *iter)
-{
- return gtk_tree_model_iter_has_child(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), iter);
-}
-
-static gint
-gsltma_iter_n_children(GtkTreeModel *tree_model,
- GtkTreeIter *iter)
-{
- return gtk_tree_model_iter_n_children(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), iter);
-}
-
-static gboolean
-gsltma_iter_nth_child(GtkTreeModel *tree_model,
- GtkTreeIter *iter,
- GtkTreeIter *parent,
- gint n)
-{
- return gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), iter, parent, n);
-}
-
-static gboolean
-gsltma_iter_parent(GtkTreeModel *tree_model,
- GtkTreeIter *iter,
- GtkTreeIter *child)
-{
- return gtk_tree_model_iter_parent(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), iter, child);
-}
-
-static void
-gsltma_ref_node(GtkTreeModel *tree_model,
- GtkTreeIter *iter)
-{
- gtk_tree_model_ref_node(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), iter);
-}
-
-static void
-gsltma_unref_node(GtkTreeModel *tree_model,
- GtkTreeIter *iter)
-{
- gtk_tree_model_unref_node(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), iter);
-}
-
-static void
-gnc_sx_list_tree_model_adapter_interface_init(gpointer g_iface, gpointer iface_data)
-{
- GtkTreeModelIface *tree_model = (GtkTreeModelIface*)g_iface;
- tree_model->get_flags = gsltma_get_flags;
- tree_model->get_n_columns = gsltma_get_n_columns;
- tree_model->get_column_type = gsltma_get_column_type;
- tree_model->get_iter = gsltma_get_iter;
- tree_model->get_path = gsltma_get_path;
- tree_model->get_value = gsltma_get_value;
- tree_model->iter_next = gsltma_iter_next;
- tree_model->iter_children = gsltma_iter_children;
- tree_model->iter_has_child = gsltma_iter_has_child;
- tree_model->iter_n_children = gsltma_iter_n_children;
- tree_model->iter_nth_child = gsltma_iter_nth_child;
- tree_model->iter_parent = gsltma_iter_parent;
- tree_model->ref_node = gsltma_ref_node;
- tree_model->unref_node = gsltma_unref_node;
-}
-
-static void
-gsltma_proxy_row_changed(GtkTreeModel *treemodel,
- GtkTreePath *arg1,
- GtkTreeIter *arg2,
- gpointer user_data)
-{
- g_signal_emit_by_name(user_data, "row-changed", arg1, arg2);
-}
-
-static void
-gsltma_proxy_row_deleted(GtkTreeModel *treemodel,
- GtkTreePath *arg1,
- gpointer user_data)
-{
- g_signal_emit_by_name(user_data, "row-deleted", arg1);
-}
-
-static void
-gsltma_proxy_row_has_child_toggled(GtkTreeModel *treemodel,
- GtkTreePath *arg1,
- GtkTreeIter *arg2,
- gpointer user_data)
-{
- g_signal_emit_by_name(user_data, "row-has-child-toggled", arg1, arg2);
-}
-
-static void
-gsltma_proxy_row_inserted(GtkTreeModel *treemodel,
- GtkTreePath *arg1,
- GtkTreeIter *arg2,
- gpointer user_data)
-{
- g_signal_emit_by_name(user_data, "row-inserted", arg1, arg2);
-}
-
-static void
-gsltma_proxy_rows_reordered(GtkTreeModel *treemodel,
- GtkTreePath *arg1,
- GtkTreeIter *arg2,
- gpointer arg3,
- gpointer user_data)
-{
- g_signal_emit_by_name(user_data, "rows-reordered", arg1, arg2, arg3);
-}
-
-static void
-gnc_sx_list_tree_model_adapter_init(GTypeInstance *instance, gpointer klass)
-{
- GncSxListTreeModelAdapter *adapter = GNC_SX_LIST_TREE_MODEL_ADAPTER(instance);
- adapter->real = gtk_tree_store_new(4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
-
- g_signal_connect(adapter->real, "row-changed", G_CALLBACK(gsltma_proxy_row_changed), adapter);
- g_signal_connect(adapter->real, "row-deleted", G_CALLBACK(gsltma_proxy_row_deleted), adapter);
- g_signal_connect(adapter->real, "row-has-child-toggled", G_CALLBACK(gsltma_proxy_row_has_child_toggled), adapter);
- g_signal_connect(adapter->real, "row-inserted", G_CALLBACK(gsltma_proxy_row_inserted), adapter);
- g_signal_connect(adapter->real, "rows-reordered", G_CALLBACK(gsltma_proxy_rows_reordered), adapter);
-}
-
-static void
-gsltma_populate_tree_store(GncSxListTreeModelAdapter *model)
-{
- GtkTreeIter iter;
- GList *list;
-
- for (list = model->instances->sx_instance_list; list != NULL; list = list->next)
- {
- GncSxInstances *instances = (GncSxInstances*)list->data;
- FreqSpec *fs;
- GString *frequency_str;
- char last_occur_date_buf[MAX_DATE_LENGTH+1];
- char next_occur_date_buf[MAX_DATE_LENGTH+1];
-
- frequency_str = g_string_sized_new(32);
- fs = xaccSchedXactionGetFreqSpec(instances->sx);
- xaccFreqSpecGetFreqStr(fs, frequency_str);
-
- {
- GDate *last_occur = xaccSchedXactionGetLastOccurDate(instances->sx);
- if (last_occur == NULL || !g_date_valid(last_occur))
- {
- g_stpcpy(last_occur_date_buf, "never");
- }
- else
- {
- qof_print_gdate(last_occur_date_buf,
- MAX_DATE_LENGTH,
- last_occur);
- }
- }
-
- qof_print_gdate(next_occur_date_buf, MAX_DATE_LENGTH, &instances->next_instance_date);
-
- gtk_tree_store_append(model->real, &iter, NULL);
- gtk_tree_store_set(model->real, &iter,
- 0, xaccSchedXactionGetName(instances->sx),
- 1, frequency_str->str,
- 2, last_occur_date_buf,
- 3, next_occur_date_buf,
- -1);
- g_string_free(frequency_str, TRUE);
- }
-}
-
-static void
-gsltma_updated_cb(GncSxInstanceModel *instances, gpointer user_data)
-{
- GncSxListTreeModelAdapter *model = GNC_SX_LIST_TREE_MODEL_ADAPTER(user_data);
- printf("update\n");
- gtk_tree_store_clear(model->real);
- gsltma_populate_tree_store(model);
-}
-
-GncSxListTreeModelAdapter*
-gnc_sx_list_tree_model_adapter_new(GncSxInstanceModel *instances)
-{
- GncSxListTreeModelAdapter *rtn;
-
- rtn = GNC_SX_LIST_TREE_MODEL_ADAPTER(g_object_new(GNC_TYPE_SX_LIST_TREE_MODEL_ADAPTER, NULL));
- rtn->instances = instances;
-
- gsltma_populate_tree_store(rtn);
-
- g_signal_connect(G_OBJECT(rtn->instances), "updated", (GCallback)gsltma_updated_cb, (gpointer)rtn);
-
- return rtn;
-}
-
-GncSxInstances*
-gnc_sx_list_tree_model_adapter_get_sx_instances(GncSxListTreeModelAdapter *model, GtkTreeIter *iter)
-{
- GtkTreePath *path;
- gint *indices;
- gint index;
-
- path = gtk_tree_model_get_path(GTK_TREE_MODEL(model), iter);
- if (gtk_tree_path_get_depth(path) > 1)
- {
- gtk_tree_path_free(path);
- return NULL;
- }
- indices = gtk_tree_path_get_indices(path);
- index = indices[0];
-
- gtk_tree_path_free(path);
- return (GncSxInstances*)g_list_nth_data(model->instances->sx_instance_list, index);
-}
-
/** @} */
/** @} */
Modified: gnucash/branches/sx-cleanup/src/gnome/gnc-plugin-page-sx-list.h
===================================================================
--- gnucash/branches/sx-cleanup/src/gnome/gnc-plugin-page-sx-list.h 2006-10-09 19:47:15 UTC (rev 14947)
+++ gnucash/branches/sx-cleanup/src/gnome/gnc-plugin-page-sx-list.h 2006-10-09 23:05:38 UTC (rev 14948)
@@ -51,7 +51,6 @@
#define GNC_PLUGIN_PAGE_SX_LIST_NAME "GncPluginPageSxList"
-
/* typedefs & structures */
typedef struct
{
@@ -76,92 +75,6 @@
**/
GncPluginPage *gnc_plugin_page_sx_list_new(void);
-
-/** ------------------------------------------------------------ **/
-typedef struct _GncSxInstanceDenseCalAdapter GncSxInstanceDenseCalAdapter;
-typedef struct _GncSxInstanceModel GncSxInstanceModel;
-typedef struct _GncSxListTreeModelAdapter GncSxListTreeModelAdapter;
-
-struct _GncSxInstanceModel
-{
- GObject parent;
-
- /* private */
- gint qof_event_handler_id;
-
- /* signals */
- /* void (*added)(GncSxInstance *sx); // gpointer user_data */
- /* void (*removed)(GncSxInstance *sx); // gpointer user_data */
- /* void (*changed)(GncSxInstance *inst); // gpointer user_data */
-
- /* public */
- GDate range_end;
- GList *sx_instance_list; /* <GncSxInstances*> */
-};
-
-typedef struct _GncSxInstanceModelClass
-{
- GObjectClass parent;
-
- guint removing_signal_id;
- guint updated_signal_id;
- guint added_signal_id;
-} GncSxInstanceModelClass;
-
-typedef struct _GncSxInstances
-{
- SchedXaction *sx;
- GHashTable /** <name:char*,GncSxVariable*> **/ *variable_names;
- gboolean variable_names_parsed;
-
- GDate next_instance_date;
-
- /** GList<GncSxInstance*> **/
- GList *list; // @fixme: s/list/?/
-} GncSxInstances;
-
-typedef enum
-{
- SX_INSTANCE_STATE_IGNORED,
- SX_INSTANCE_STATE_POSTPONED,
- SX_INSTANCE_STATE_TO_CREATE,
- SX_INSTANCE_STATE_REMINDER,
- SX_INSTANCE_STATE_CREATED,
- SX_INSTANCE_STATE_MAX_STATE
-} GncSxInstanceState;
-
-typedef struct _GncSxVariable
-{
- gchar *name;
- gnc_numeric value; /**< only numeric values are supported. **/
- gboolean editable;
-} GncSxVariable;
-
-typedef struct _GncSxInstance
-{
- GncSxInstances *parent; /**< the parent instances collection. **/
- void *temporal_state; /**< the sx creation temporal state. **/
- GncSxInstanceState orig_state; /**< the original state at generation time. **/
- GncSxInstanceState state; /**< the current state of the instance (during editing) **/
- GDate date; /**< the instance date. **/
- GHashTable *variable_bindings; /**< variable bindings. **/
-} GncSxInstance;
-
-GncSxInstanceModel* gnc_sx_get_instances(GDate *range_end);
-
-/** @return GList<GncSxVariable*> **/
-GList *gnc_sx_instance_get_variables(GncSxInstance *inst);
-
-Account* gnc_sx_get_template_transaction_account(SchedXaction *sx);
-
-/**
- * @return caller-owned.
- **/
-GHashTable* gnc_sx_instance_get_variables_for_parser(GHashTable *instance_var_hash);
-
-
-/** ------------------------------------------------------------ **/
-
G_END_DECLS
#endif /* __GNC_PLUGIN_PAGE_SX_LIST_H */
Added: gnucash/branches/sx-cleanup/src/gnome/gnc-sx-list-tree-model-adapter.c
===================================================================
--- gnucash/branches/sx-cleanup/src/gnome/gnc-sx-list-tree-model-adapter.c 2006-10-09 19:47:15 UTC (rev 14947)
+++ gnucash/branches/sx-cleanup/src/gnome/gnc-sx-list-tree-model-adapter.c 2006-10-09 23:05:38 UTC (rev 14948)
@@ -0,0 +1,353 @@
+/*
+ * gnc-sx-list-tree-model-adapter.c
+ *
+ * Copyright (C) 2006 Josh Sled <jsled at asynchronous.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation Voice: +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
+ * Boston, MA 02110-1301, USA gnu at gnu.org
+ */
+
+#include "config.h"
+#include <glib.h>
+#include <glib-object.h>
+#include "gnc-sx-instance-model.h"
+#include "gnc-sx-list-tree-model-adapter.h"
+#include <gtk/gtk.h>
+
+struct _GncSxListTreeModelAdapter
+{
+ GObject parent;
+
+ /* protected */
+ GncSxInstanceModel *instances;
+ GtkTreeStore *real;
+};
+
+struct _GncSxListTreeModelAdapterClass
+{
+ GObjectClass parent;
+};
+
+static void gnc_sx_list_tree_model_adapter_class_init(GncSxListTreeModelAdapterClass *klass);
+static void gnc_sx_list_tree_model_adapter_interface_init(gpointer g_iface, gpointer iface_data);
+static void gnc_sx_list_tree_model_adapter_init(GTypeInstance *instance, gpointer klass);
+
+GType
+gnc_sx_list_tree_model_adapter_get_type(void)
+{
+ static GType type = 0;
+ if (type == 0) {
+ static const GTypeInfo info = {
+ sizeof (GncSxListTreeModelAdapterClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ (GClassInitFunc)gnc_sx_list_tree_model_adapter_class_init, /* class_init */
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (GncSxListTreeModelAdapter),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc)gnc_sx_list_tree_model_adapter_init /* instance_init */
+ };
+ static const GInterfaceInfo itreeModel_info = {
+ (GInterfaceInitFunc) gnc_sx_list_tree_model_adapter_interface_init, /* interface_init */
+ NULL, /* interface_finalize */
+ NULL /* interface_data */
+ };
+
+ type = g_type_register_static (G_TYPE_OBJECT,
+ "GncSxListTreeModelAdapterType",
+ &info, 0);
+ g_type_add_interface_static(type,
+ GTK_TYPE_TREE_MODEL,
+ &itreeModel_info);
+ }
+ return type;
+}
+
+static void
+gnc_sx_list_tree_model_adapter_class_init(GncSxListTreeModelAdapterClass *klass)
+{
+ ; /* nop */
+}
+
+static GtkTreeModelFlags
+gsltma_get_flags(GtkTreeModel *tree_model)
+{
+ return gtk_tree_model_get_flags(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real));
+}
+
+static gint
+gsltma_get_n_columns(GtkTreeModel *tree_model)
+{
+ return gtk_tree_model_get_n_columns(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real));
+}
+
+static GType
+gsltma_get_column_type(GtkTreeModel *tree_model, gint index)
+{
+ return gtk_tree_model_get_column_type(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), index);
+}
+
+static gboolean
+gsltma_get_iter(GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ GtkTreePath *path)
+{
+ return gtk_tree_model_get_iter(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), iter, path);
+}
+
+static GtkTreePath*
+gsltma_get_path(GtkTreeModel *tree_model,
+ GtkTreeIter *iter)
+{
+ return gtk_tree_model_get_path(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), iter);
+}
+
+static void
+gsltma_get_value(GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ gint column,
+ GValue *value)
+{
+ gtk_tree_model_get_value(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), iter, column, value);
+}
+
+static gboolean
+gsltma_iter_next(GtkTreeModel *tree_model,
+ GtkTreeIter *iter)
+{
+ return gtk_tree_model_iter_next(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), iter);
+}
+
+static gboolean
+gsltma_iter_children(GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ GtkTreeIter *parent)
+{
+ return gtk_tree_model_iter_children(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), iter, parent);
+}
+
+static gboolean
+gsltma_iter_has_child(GtkTreeModel *tree_model,
+ GtkTreeIter *iter)
+{
+ return gtk_tree_model_iter_has_child(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), iter);
+}
+
+static gint
+gsltma_iter_n_children(GtkTreeModel *tree_model,
+ GtkTreeIter *iter)
+{
+ return gtk_tree_model_iter_n_children(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), iter);
+}
+
+static gboolean
+gsltma_iter_nth_child(GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ GtkTreeIter *parent,
+ gint n)
+{
+ return gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), iter, parent, n);
+}
+
+static gboolean
+gsltma_iter_parent(GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ GtkTreeIter *child)
+{
+ return gtk_tree_model_iter_parent(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), iter, child);
+}
+
+static void
+gsltma_ref_node(GtkTreeModel *tree_model,
+ GtkTreeIter *iter)
+{
+ gtk_tree_model_ref_node(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), iter);
+}
+
+static void
+gsltma_unref_node(GtkTreeModel *tree_model,
+ GtkTreeIter *iter)
+{
+ gtk_tree_model_unref_node(GTK_TREE_MODEL(GNC_SX_LIST_TREE_MODEL_ADAPTER(tree_model)->real), iter);
+}
+
+static void
+gnc_sx_list_tree_model_adapter_interface_init(gpointer g_iface, gpointer iface_data)
+{
+ GtkTreeModelIface *tree_model = (GtkTreeModelIface*)g_iface;
+ tree_model->get_flags = gsltma_get_flags;
+ tree_model->get_n_columns = gsltma_get_n_columns;
+ tree_model->get_column_type = gsltma_get_column_type;
+ tree_model->get_iter = gsltma_get_iter;
+ tree_model->get_path = gsltma_get_path;
+ tree_model->get_value = gsltma_get_value;
+ tree_model->iter_next = gsltma_iter_next;
+ tree_model->iter_children = gsltma_iter_children;
+ tree_model->iter_has_child = gsltma_iter_has_child;
+ tree_model->iter_n_children = gsltma_iter_n_children;
+ tree_model->iter_nth_child = gsltma_iter_nth_child;
+ tree_model->iter_parent = gsltma_iter_parent;
+ tree_model->ref_node = gsltma_ref_node;
+ tree_model->unref_node = gsltma_unref_node;
+}
+
+static void
+gsltma_proxy_row_changed(GtkTreeModel *treemodel,
+ GtkTreePath *arg1,
+ GtkTreeIter *arg2,
+ gpointer user_data)
+{
+ g_signal_emit_by_name(user_data, "row-changed", arg1, arg2);
+}
+
+static void
+gsltma_proxy_row_deleted(GtkTreeModel *treemodel,
+ GtkTreePath *arg1,
+ gpointer user_data)
+{
+ g_signal_emit_by_name(user_data, "row-deleted", arg1);
+}
+
+static void
+gsltma_proxy_row_has_child_toggled(GtkTreeModel *treemodel,
+ GtkTreePath *arg1,
+ GtkTreeIter *arg2,
+ gpointer user_data)
+{
+ g_signal_emit_by_name(user_data, "row-has-child-toggled", arg1, arg2);
+}
+
+static void
+gsltma_proxy_row_inserted(GtkTreeModel *treemodel,
+ GtkTreePath *arg1,
+ GtkTreeIter *arg2,
+ gpointer user_data)
+{
+ g_signal_emit_by_name(user_data, "row-inserted", arg1, arg2);
+}
+
+static void
+gsltma_proxy_rows_reordered(GtkTreeModel *treemodel,
+ GtkTreePath *arg1,
+ GtkTreeIter *arg2,
+ gpointer arg3,
+ gpointer user_data)
+{
+ g_signal_emit_by_name(user_data, "rows-reordered", arg1, arg2, arg3);
+}
+
+static void
+gnc_sx_list_tree_model_adapter_init(GTypeInstance *instance, gpointer klass)
+{
+ GncSxListTreeModelAdapter *adapter = GNC_SX_LIST_TREE_MODEL_ADAPTER(instance);
+ adapter->real = gtk_tree_store_new(4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
+
+ g_signal_connect(adapter->real, "row-changed", G_CALLBACK(gsltma_proxy_row_changed), adapter);
+ g_signal_connect(adapter->real, "row-deleted", G_CALLBACK(gsltma_proxy_row_deleted), adapter);
+ g_signal_connect(adapter->real, "row-has-child-toggled", G_CALLBACK(gsltma_proxy_row_has_child_toggled), adapter);
+ g_signal_connect(adapter->real, "row-inserted", G_CALLBACK(gsltma_proxy_row_inserted), adapter);
+ g_signal_connect(adapter->real, "rows-reordered", G_CALLBACK(gsltma_proxy_rows_reordered), adapter);
+}
+
+static void
+gsltma_populate_tree_store(GncSxListTreeModelAdapter *model)
+{
+ GtkTreeIter iter;
+ GList *list;
+
+ for (list = model->instances->sx_instance_list; list != NULL; list = list->next)
+ {
+ GncSxInstances *instances = (GncSxInstances*)list->data;
+ FreqSpec *fs;
+ GString *frequency_str;
+ char last_occur_date_buf[MAX_DATE_LENGTH+1];
+ char next_occur_date_buf[MAX_DATE_LENGTH+1];
+
+ frequency_str = g_string_sized_new(32);
+ fs = xaccSchedXactionGetFreqSpec(instances->sx);
+ xaccFreqSpecGetFreqStr(fs, frequency_str);
+
+ {
+ GDate *last_occur = xaccSchedXactionGetLastOccurDate(instances->sx);
+ if (last_occur == NULL || !g_date_valid(last_occur))
+ {
+ g_stpcpy(last_occur_date_buf, "never");
+ }
+ else
+ {
+ qof_print_gdate(last_occur_date_buf,
+ MAX_DATE_LENGTH,
+ last_occur);
+ }
+ }
+
+ qof_print_gdate(next_occur_date_buf, MAX_DATE_LENGTH, &instances->next_instance_date);
+
+ gtk_tree_store_append(model->real, &iter, NULL);
+ gtk_tree_store_set(model->real, &iter,
+ 0, xaccSchedXactionGetName(instances->sx),
+ 1, frequency_str->str,
+ 2, last_occur_date_buf,
+ 3, next_occur_date_buf,
+ -1);
+ g_string_free(frequency_str, TRUE);
+ }
+}
+
+static void
+gsltma_updated_cb(GncSxInstanceModel *instances, gpointer user_data)
+{
+ GncSxListTreeModelAdapter *model = GNC_SX_LIST_TREE_MODEL_ADAPTER(user_data);
+ printf("update\n");
+ gtk_tree_store_clear(model->real);
+ gsltma_populate_tree_store(model);
+}
+
+GncSxListTreeModelAdapter*
+gnc_sx_list_tree_model_adapter_new(GncSxInstanceModel *instances)
+{
+ GncSxListTreeModelAdapter *rtn;
+
+ rtn = GNC_SX_LIST_TREE_MODEL_ADAPTER(g_object_new(GNC_TYPE_SX_LIST_TREE_MODEL_ADAPTER, NULL));
+ rtn->instances = instances;
+
+ gsltma_populate_tree_store(rtn);
+
+ g_signal_connect(G_OBJECT(rtn->instances), "updated", (GCallback)gsltma_updated_cb, (gpointer)rtn);
+
+ return rtn;
+}
+
+GncSxInstances*
+gnc_sx_list_tree_model_adapter_get_sx_instances(GncSxListTreeModelAdapter *model, GtkTreeIter *iter)
+{
+ GtkTreePath *path;
+ gint *indices;
+ gint index;
+
+ path = gtk_tree_model_get_path(GTK_TREE_MODEL(model), iter);
+ if (gtk_tree_path_get_depth(path) > 1)
+ {
+ gtk_tree_path_free(path);
+ return NULL;
+ }
+ indices = gtk_tree_path_get_indices(path);
+ index = indices[0];
+
+ gtk_tree_path_free(path);
+ return (GncSxInstances*)g_list_nth_data(model->instances->sx_instance_list, index);
+}
Added: gnucash/branches/sx-cleanup/src/gnome/gnc-sx-list-tree-model-adapter.h
===================================================================
--- gnucash/branches/sx-cleanup/src/gnome/gnc-sx-list-tree-model-adapter.h 2006-10-09 19:47:15 UTC (rev 14947)
+++ gnucash/branches/sx-cleanup/src/gnome/gnc-sx-list-tree-model-adapter.h 2006-10-09 23:05:38 UTC (rev 14948)
@@ -0,0 +1,51 @@
+/*
+ * gnc-sx-list-tree-model-adapter.h
+ *
+ * Copyright (C) 2006 Josh Sled <jsled at asynchronous.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation Voice: +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
+ * Boston, MA 02110-1301, USA gnu at gnu.org
+ */
+
+#ifndef _GNC_SX_LIST_TREE_MODEL_ADAPTER_H
+#define _GNC_SX_LIST_TREE_MODEL_ADAPTER_H
+
+#include "config.h"
+#include <glib.h>
+#include <glib-object.h>
+#include <gtk/gtk.h>
+#include "gnc-sx-instance-model.h"
+
+G_BEGIN_DECLS
+
+#define GNC_TYPE_SX_LIST_TREE_MODEL_ADAPTER (gnc_sx_list_tree_model_adapter_get_type ())
+#define GNC_SX_LIST_TREE_MODEL_ADAPTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_SX_LIST_TREE_MODEL_ADAPTER, GncSxListTreeModelAdapter))
+#define GNC_SX_LIST_TREE_MODEL_ADAPTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_SX_LIST_TREE_MODEL_ADAPTER, GncSxListTreeModelAdapterClass))
+#define GNC_IS_SX_LIST_TREE_MODEL_ADAPTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_SX_LIST_TREE_MODEL_ADAPTER))
+#define GNC_IS_SX_LIST_TREE_MODEL_ADAPTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_SX_LIST_TREE_MODEL_ADAPTER))
+#define GNC_SX_LIST_TREE_MODEL_ADAPTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_TYPE_SX_LIST_TREE_MODEL_ADAPTER, GncSxListTreeModelAdapterClass))
+
+typedef struct _GncSxListTreeModelAdapter GncSxListTreeModelAdapter;
+typedef struct _GncSxListTreeModelAdapterClass GncSxListTreeModelAdapterClass;
+
+GType gnc_sx_list_tree_model_adapter_get_type(void);
+GncSxListTreeModelAdapter* gnc_sx_list_tree_model_adapter_new(GncSxInstanceModel *instances);
+
+GncSxInstances* gnc_sx_list_tree_model_adapter_get_sx_instances(GncSxListTreeModelAdapter *model, GtkTreeIter *iter);
+
+G_END_DECLS
+
+#endif // _GNC_SX_LIST_TREE_MODEL_ADAPTER_H
Modified: gnucash/branches/sx-cleanup/src/gnome-utils/Makefile.am
===================================================================
--- gnucash/branches/sx-cleanup/src/gnome-utils/Makefile.am 2006-10-09 19:47:15 UTC (rev 14947)
+++ gnucash/branches/sx-cleanup/src/gnome-utils/Makefile.am 2006-10-09 23:05:38 UTC (rev 14948)
@@ -56,6 +56,8 @@
gnc-date-edit.c \
gnc-date-format.c \
gnc-dense-cal.c \
+ gnc-dense-cal-model.c \
+ gnc-dense-cal-store.c \
gnc-druid-gnome.c \
gnc-druid-provider-edge-gnome.c \
gnc-druid-provider-file-gnome.c \
@@ -81,6 +83,7 @@
gnc-period-select.c \
gnc-query-list.c \
gnc-splash.c \
+ gnc-sx-instance-dense-cal-adapter.c \
gnc-tree-model.c \
gnc-tree-model-account-types.c \
gnc-tree-model-account.c \
@@ -125,6 +128,8 @@
gnc-date-edit.h \
gnc-date-format.h \
gnc-dense-cal.h \
+ gnc-dense-cal-model.h \
+ gnc-dense-cal-store.h \
gnc-druid-gnome-ui.h \
gnc-embedded-window.h \
gnc-file.h \
@@ -147,6 +152,7 @@
gnc-period-select.h \
gnc-query-list.h \
gnc-splash.h \
+ gnc-sx-instance-dense-cal-adapter.h \
gnc-tree-model.h \
gnc-tree-model-account-types.h \
gnc-tree-model-account.h \
Added: gnucash/branches/sx-cleanup/src/gnome-utils/gnc-dense-cal-model.c
===================================================================
--- gnucash/branches/sx-cleanup/src/gnome-utils/gnc-dense-cal-model.c 2006-10-09 19:47:15 UTC (rev 14947)
+++ gnucash/branches/sx-cleanup/src/gnome-utils/gnc-dense-cal-model.c 2006-10-09 23:05:38 UTC (rev 14948)
@@ -0,0 +1,132 @@
+/*
+ * gnc-dense-cal-model.c
+ *
+ * Copyright (C) 2006 Joshua Sled <jsled at asynchronous.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation Voice: +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
+ * Boston, MA 02110-1301, USA gnu at gnu.org
+ */
+
+
+#include "config.h"
+#include <glib.h>
+#include <glib-object.h>
+#include "gnc-dense-cal.h"
+#include "gnc-dense-cal-model.h"
+
+enum { GDCM_ADDED, GDCM_UPDATE, GDCM_REMOVE, LAST_SIGNAL };
+static guint gnc_dense_cal_model_signals[LAST_SIGNAL] = { 0 };
+
+static void
+gnc_dense_cal_model_base_init(gpointer g_class)
+{
+ static gboolean initialized = FALSE;
+
+ if (!initialized)
+ {
+ gnc_dense_cal_model_signals[GDCM_ADDED]
+ = g_signal_new("added",
+ G_TYPE_FROM_CLASS(g_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
+ 0 /* default offset */,
+ NULL /* accumulator */,
+ NULL /* accum. data */,
+ g_cclosure_marshal_VOID__UINT,
+ G_TYPE_NONE /* return */,
+ 1 /* n_params */,
+ G_TYPE_UINT /* param types */
+ );
+
+ gnc_dense_cal_model_signals[GDCM_UPDATE]
+ = g_signal_new("update",
+ G_TYPE_FROM_CLASS(g_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
+ 0 /* default offset */,
+ NULL /* accumulator */,
+ NULL /* accum. data */,
+ g_cclosure_marshal_VOID__UINT,
+ G_TYPE_NONE /* return */,
+ 1 /* n_params */,
+ G_TYPE_UINT /* param types */
+ );
+
+ gnc_dense_cal_model_signals[GDCM_REMOVE]
+ = g_signal_new("removing",
+ G_TYPE_FROM_CLASS(g_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
+ 0 /* default offset */,
+ NULL /* accumulator */,
+ NULL /* accum. data */,
+ g_cclosure_marshal_VOID__UINT,
+ G_TYPE_NONE /* return */,
+ 1 /* n_params */,
+ G_TYPE_UINT /* param types */
+ );
+
+ initialized = TRUE;
+ }
+}
+
+GType
+gnc_dense_cal_model_get_type(void)
+{
+ static GType type = 0;
+ if (type == 0) {
+ static const GTypeInfo info = {
+ sizeof(GncDenseCalModelIface),
+ gnc_dense_cal_model_base_init, /* base_init */
+ NULL, /* base_finalize */
+ NULL, /* class_init */
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ 0,
+ 0, /* n_preallocs */
+ NULL /* instance_init */
+ };
+ type = g_type_register_static(G_TYPE_INTERFACE, "GncDenseCalModel", &info, 0);
+ }
+ return type;
+}
+
+GList*
+gnc_dense_cal_model_get_contained(GncDenseCalModel *model)
+{
+ return (*GNC_DENSE_CAL_MODEL_GET_INTERFACE(model)->get_contained)(model);
+}
+
+gchar*
+gnc_dense_cal_model_get_name(GncDenseCalModel *model, guint tag)
+{
+ return (*GNC_DENSE_CAL_MODEL_GET_INTERFACE(model)->get_name)(model, tag);
+}
+
+gchar*
+gnc_dense_cal_model_get_info(GncDenseCalModel *model, guint tag)
+{
+ return (*GNC_DENSE_CAL_MODEL_GET_INTERFACE(model)->get_info)(model, tag);
+}
+
+gint
+gnc_dense_cal_model_get_instance_count(GncDenseCalModel *model, guint tag)
+{
+ return (*GNC_DENSE_CAL_MODEL_GET_INTERFACE(model)->get_instance_count)(model, tag);
+}
+
+void
+gnc_dense_cal_model_get_instance(GncDenseCalModel *model, guint tag, gint instance_index, GDate *date)
+{
+ return (*GNC_DENSE_CAL_MODEL_GET_INTERFACE(model)->get_instance)(model, tag, instance_index, date);
+}
Added: gnucash/branches/sx-cleanup/src/gnome-utils/gnc-dense-cal-model.h
===================================================================
--- gnucash/branches/sx-cleanup/src/gnome-utils/gnc-dense-cal-model.h 2006-10-09 19:47:15 UTC (rev 14947)
+++ gnucash/branches/sx-cleanup/src/gnome-utils/gnc-dense-cal-model.h 2006-10-09 23:05:38 UTC (rev 14948)
@@ -0,0 +1,66 @@
+/*
+ * gnc-dense-cal-model.h
+ *
+ * Copyright (C) 2006 Joshua Sled <jsled at asynchronous.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation Voice: +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
+ * Boston, MA 02110-1301, USA gnu at gnu.org
+ */
+
+#ifndef _GNC_DENSE_CAL_MODEL_H
+#define _GNC_DENSE_CAL_MODEL_H
+
+#include "config.h"
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GNC_TYPE_DENSE_CAL_MODEL (gnc_dense_cal_model_get_type())
+#define GNC_DENSE_CAL_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_DENSE_CAL_MODEL, GncDenseCalModel))
+#define GNC_IS_DENSE_CAL_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_DENSE_CAL_MODEL))
+#define GNC_DENSE_CAL_MODEL_GET_INTERFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GNC_TYPE_DENSE_CAL_MODEL, GncDenseCalModelIface))
+
+typedef struct _GncDenseCalModel GncDenseCalModel; /* non existant */
+typedef struct _GncDenseCalModelIface
+{
+ GTypeInterface parent;
+
+ /* signals */
+ void (*insert)(GncDenseCalModel *mdl, gint tag);
+ void (*update)(GncDenseCalModel *mdl, gint tag);
+ void (*remove)(GncDenseCalModel *mdl, gint tag);
+
+ /* virtual table */
+ GList* (*get_contained)(GncDenseCalModel *model);
+ gchar* (*get_name)(GncDenseCalModel *model, guint tag);
+ gchar* (*get_info)(GncDenseCalModel *model, guint tag);
+ gint (*get_instance_count)(GncDenseCalModel *model, guint tag);
+ void (*get_instance)(GncDenseCalModel *model, guint tag, gint instance_index, GDate *date);
+} GncDenseCalModelIface;
+
+GType gnc_dense_cal_model_get_type(void);
+
+/* @fixme: glist mem alloc policy... ? */
+GList* gnc_dense_cal_model_get_contained(GncDenseCalModel *model);
+gchar* gnc_dense_cal_model_get_name(GncDenseCalModel *model, guint tag);
+gchar* gnc_dense_cal_model_get_info(GncDenseCalModel *model, guint tag);
+gint gnc_dense_cal_model_get_instance_count(GncDenseCalModel *model, guint tag);
+void gnc_dense_cal_model_get_instance(GncDenseCalModel *model, guint tag, gint instance_index, GDate *date);
+
+G_END_DECLS
+
+#endif // _GNC_DENSE_CAL_MODEL_H
Added: gnucash/branches/sx-cleanup/src/gnome-utils/gnc-dense-cal-store.c
===================================================================
--- gnucash/branches/sx-cleanup/src/gnome-utils/gnc-dense-cal-store.c 2006-10-09 19:47:15 UTC (rev 14947)
+++ gnucash/branches/sx-cleanup/src/gnome-utils/gnc-dense-cal-store.c 2006-10-09 23:05:38 UTC (rev 14948)
@@ -0,0 +1,240 @@
+/*
+ * gnc-dense-cal-store.h
+ *
+ * Copyright (C) 2006 Joshua Sled <jsled at asynchronous.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation Voice: +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
+ * Boston, MA 02110-1301, USA gnu at gnu.org
+ */
+
+#include "config.h"
+#include <glib.h>
+#include <glib-object.h>
+#include "gnc-dense-cal.h"
+#include "gnc-dense-cal-model.h"
+#include "gnc-dense-cal-store.h"
+
+struct _GncDenseCalStore
+{
+ GObject parent;
+
+ GDate start_date;
+ gdcs_end_type end_type;
+ GDate end_date;
+ gint n_occurrences;
+ gchar *name;
+ gchar *info;
+ int num_marks;
+ int num_real_marks;
+ GDate **cal_marks;
+};
+
+struct _GncDenseCalStoreClass
+{
+ GObjectClass parent_class;
+};
+
+static GList* gdcs_get_contained(GncDenseCalModel *model);
+static gchar* gdcs_get_name(GncDenseCalModel *model, guint tag);
+static gchar* gdcs_get_info(GncDenseCalModel *model, guint tag);
+static gint gdcs_get_instance_count(GncDenseCalModel *model, guint tag);
+static void gdcs_get_instance(GncDenseCalModel *model, guint tag, gint instance_index, GDate *date);
+
+static void
+gnc_dense_cal_store_iface_init(gpointer g_iface, gpointer iface_data)
+{
+ GncDenseCalModelIface *iface = (GncDenseCalModelIface*)g_iface;
+ iface->get_contained = gdcs_get_contained;
+ iface->get_name = gdcs_get_name;
+ iface->get_info = gdcs_get_info;
+ iface->get_instance_count = gdcs_get_instance_count;
+ iface->get_instance = gdcs_get_instance;
+}
+
+GType
+gnc_dense_cal_store_get_type(void)
+{
+ static GType type = 0;
+ if (type == 0)
+ {
+ static const GTypeInfo info = {
+ sizeof (GncDenseCalStoreClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ NULL, /* class_init */
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof(GncDenseCalStore),
+ 0, /* n_preallocs */
+ NULL /* instance_init */
+ };
+ static const GInterfaceInfo iDenseCalModelInfo = {
+ (GInterfaceInitFunc)gnc_dense_cal_store_iface_init,
+ NULL, /* interface finalize */
+ NULL, /* interface data */
+ };
+ type = g_type_register_static(G_TYPE_OBJECT, "GncDenseCalStore", &info, 0);
+ g_type_add_interface_static(type,
+ GNC_TYPE_DENSE_CAL_MODEL,
+ &iDenseCalModelInfo);
+ }
+ return type;
+}
+
+GncDenseCalStore*
+gnc_dense_cal_store_new(int num_marks)
+{
+ GncDenseCalStore *model = g_object_new(GNC_TYPE_DENSE_CAL_STORE, NULL);
+ model->num_marks = num_marks;
+ model->cal_marks = g_new0(GDate*, num_marks);
+ {
+ int i = 0;
+ for (i = 0; i < model->num_marks; i++)
+ {
+ model->cal_marks[i] = g_date_new();
+ }
+ }
+ model->num_real_marks = 0;
+ g_date_clear(&model->start_date, 1);
+ g_date_set_time_t(&model->start_date, time(NULL));
+ model->end_type = NEVER_END;
+ g_date_clear(&model->end_date, 1);
+ g_date_set_time_t(&model->end_date, time(NULL));
+ model->n_occurrences = 0;
+ return model;
+}
+
+void
+gnc_dense_cal_store_clear(GncDenseCalStore *model)
+{
+ model->num_real_marks = 0;
+ g_signal_emit_by_name(model, "update", GUINT_TO_POINTER(1));
+}
+
+void
+gnc_dense_cal_store_update_name(GncDenseCalStore *model, gchar *name)
+{
+ if (model->name != NULL)
+ {
+ g_free(model->name);
+ }
+ model->name = g_strdup(name);
+ g_signal_emit_by_name(model, "update", GUINT_TO_POINTER(1));
+}
+
+void
+gnc_dense_cal_store_update_info(GncDenseCalStore *model, gchar *info)
+{
+ if (model->info != NULL)
+ {
+ g_free(model->info);
+ }
+ model->info = g_strdup(info);
+ g_signal_emit_by_name(model, "update", GUINT_TO_POINTER(1));
+}
+
+static void
+gdcs_generic_update(GncDenseCalStore *trans, GDate *start, FreqSpec *fs)
+{
+ int i;
+ GDate date;
+
+ date = *start;
+ /* go one day before what's in the box so we can get the correct start
+ * date. */
+ g_date_subtract_days(&date, 1);
+ xaccFreqSpecGetNextInstance(fs, &date, &date);
+
+ i = 0;
+ while ((i < trans->num_marks)
+ && g_date_valid(&date)
+ /* Do checking against end restriction. */
+ && ((trans->end_type == NEVER_END)
+ || (trans->end_type == END_ON_DATE
+ && g_date_compare(&date, &trans->end_date) <= 0)
+ || (trans->end_type == END_AFTER_N_OCCS
+ && i < trans->n_occurrences)))
+ {
+ *trans->cal_marks[i++] = date;
+ xaccFreqSpecGetNextInstance(fs, &date, &date);
+ }
+ trans->num_real_marks = (i-1);
+ g_signal_emit_by_name(trans, "update", GUINT_TO_POINTER(1));
+}
+
+void
+gnc_dense_cal_store_update_no_end(GncDenseCalStore *model, GDate *start, FreqSpec *fs)
+{
+ model->end_type = NEVER_END;
+ gdcs_generic_update(model, start, fs);
+}
+
+void
+gnc_dense_cal_store_update_count_end(GncDenseCalStore *model, GDate *start, FreqSpec *fs, int num_occur)
+{
+ model->end_type = END_AFTER_N_OCCS;
+ model->n_occurrences = num_occur;
+ gdcs_generic_update(model, start, fs);
+}
+
+void
+gnc_dense_cal_store_update_date_end(GncDenseCalStore *model, GDate *start, FreqSpec *fs, GDate *end_date)
+{
+ model->end_type = END_ON_DATE;
+ model->end_date = *end_date;
+ gdcs_generic_update(model, start, fs);
+}
+
+static GList*
+gdcs_get_contained(GncDenseCalModel *model)
+{
+ GList *rtn = NULL;
+ rtn = g_list_append(rtn, GUINT_TO_POINTER(1));
+ return rtn;
+}
+
+static gchar*
+gdcs_get_name(GncDenseCalModel *model, guint tag)
+{
+ GncDenseCalStore *mdl = GNC_DENSE_CAL_STORE(model);
+ // assert(tag == 1)
+ return mdl->name;
+}
+
+static gchar*
+gdcs_get_info(GncDenseCalModel *model, guint tag)
+{
+ GncDenseCalStore *mdl = GNC_DENSE_CAL_STORE(model);
+ // assert(tag == 1)
+ return mdl->info;
+}
+
+static gint
+gdcs_get_instance_count(GncDenseCalModel *model, guint tag)
+{
+ GncDenseCalStore *mdl = GNC_DENSE_CAL_STORE(model);
+ // assert(tag == 1)
+ return mdl->num_real_marks;
+}
+
+static void
+gdcs_get_instance(GncDenseCalModel *model, guint tag, gint instance_index, GDate *date)
+{
+ GncDenseCalStore *mdl = GNC_DENSE_CAL_STORE(model);
+ // assert(tag == 1)
+ // assert 0 < instance_index < model->num_marks;
+ *date = *mdl->cal_marks[instance_index];
+}
Added: gnucash/branches/sx-cleanup/src/gnome-utils/gnc-dense-cal-store.h
===================================================================
--- gnucash/branches/sx-cleanup/src/gnome-utils/gnc-dense-cal-store.h 2006-10-09 19:47:15 UTC (rev 14947)
+++ gnucash/branches/sx-cleanup/src/gnome-utils/gnc-dense-cal-store.h 2006-10-09 23:05:38 UTC (rev 14948)
@@ -0,0 +1,57 @@
+/*
+ * gnc-dense-cal-store.h
+ *
+ * Copyright (C) 2006 Joshua Sled <jsled at asynchronous.org>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation Voice: +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
+ * Boston, MA 02110-1301, USA gnu at gnu.org
+ */
+
+#ifndef _GNC_DENSE_CAL_STORE_H
+#define _GNC_DENSE_CAL_STORE_H
+
+#include "config.h"
+#include <glib.h>
+#include <glib-object.h>
+#include "gnc-dense-cal-model.h"
+#include "gnc-dense-cal.h"
+
+G_BEGIN_DECLS
+
+#define GNC_TYPE_DENSE_CAL_STORE (gnc_dense_cal_store_get_type())
+#define GNC_DENSE_CAL_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_DENSE_CAL_STORE, GncDenseCalStore))
+#define GNC_DENSE_CAL_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_DENSE_CAL_STORE, GncDenseCalStoreClass))
+#define GNC_IS_DENSE_CAL_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_DENSE_CAL_STORE))
+#define GNC_IS_DENSE_CAL_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_DENSE_CAL_STORE))
+#define GNC_DENSE_CAL_STORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_TYPE_DENSE_CAL_STORE, GncDenseCalStore))
+
+typedef enum { NEVER_END, END_ON_DATE, END_AFTER_N_OCCS, BAD_END } gdcs_end_type;
+
+typedef struct _GncDenseCalStore GncDenseCalStore;
+typedef struct _GncDenseCalStoreClass GncDenseCalStoreClass;
+
+GType gnc_dense_cal_store_get_type(void);
+GncDenseCalStore* gnc_dense_cal_store_new(int num_marks);
+void gnc_dense_cal_store_clear(GncDenseCalStore *model);
+void gnc_dense_cal_store_update_name(GncDenseCalStore *model, gchar* name);
+void gnc_dense_cal_store_update_info(GncDenseCalStore *model, gchar* info);
+void gnc_dense_cal_store_update_no_end(GncDenseCalStore *model, GDate *start, FreqSpec *fs);
+void gnc_dense_cal_store_update_count_end(GncDenseCalStore *model, GDate *start, FreqSpec *fs, int num_occur);
+void gnc_dense_cal_store_update_date_end(GncDenseCalStore *model, GDate *start, FreqSpec *fs, GDate *end_date);
+
+G_END_DECLS
+
+#endif // _GNC_DENSE_CAL_STORE_H
Modified: gnucash/branches/sx-cleanup/src/gnome-utils/gnc-dense-cal.c
===================================================================
--- gnucash/branches/sx-cleanup/src/gnome-utils/gnc-dense-cal.c 2006-10-09 19:47:15 UTC (rev 14947)
+++ gnucash/branches/sx-cleanup/src/gnome-utils/gnc-dense-cal.c 2006-10-09 23:05:38 UTC (rev 14948)
@@ -22,317 +22,15 @@
#include "config.h"
-#include <gtk/gtk.h>
+#include "glib-compat.h"
+#include "gnc-dense-cal.h"
+#include "gnc-dense-cal-model.h"
+#include "gnc-engine.h"
#include <glib.h>
#include <glib/gi18n.h>
-#include "glib-compat.h"
+#include <gtk/gtk.h>
#include <math.h>
-#include "gnc-dense-cal.h"
-
-/* For PERR, only... */
-#include "gnc-engine.h"
-
-enum { GDCM_ADDED, GDCM_UPDATE, GDCM_REMOVE, LAST_SIGNAL };
-static guint gnc_dense_cal_model_signals[LAST_SIGNAL] = { 0 };
-
-static void
-gnc_dense_cal_model_base_init(gpointer g_class)
-{
- static gboolean initialized = FALSE;
-
- if (!initialized)
- {
- gnc_dense_cal_model_signals[GDCM_ADDED]
- = g_signal_new("added",
- G_TYPE_FROM_CLASS(g_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0 /* default offset */,
- NULL /* accumulator */,
- NULL /* accum. data */,
- g_cclosure_marshal_VOID__UINT,
- G_TYPE_NONE /* return */,
- 1 /* n_params */,
- G_TYPE_UINT /* param types */
- );
-
- gnc_dense_cal_model_signals[GDCM_UPDATE]
- = g_signal_new("update",
- G_TYPE_FROM_CLASS(g_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0 /* default offset */,
- NULL /* accumulator */,
- NULL /* accum. data */,
- g_cclosure_marshal_VOID__UINT,
- G_TYPE_NONE /* return */,
- 1 /* n_params */,
- G_TYPE_UINT /* param types */
- );
-
- gnc_dense_cal_model_signals[GDCM_REMOVE]
- = g_signal_new("removing",
- G_TYPE_FROM_CLASS(g_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
- 0 /* default offset */,
- NULL /* accumulator */,
- NULL /* accum. data */,
- g_cclosure_marshal_VOID__UINT,
- G_TYPE_NONE /* return */,
- 1 /* n_params */,
- G_TYPE_UINT /* param types */
- );
-
- initialized = TRUE;
- }
-}
-
-GType
-gnc_dense_cal_model_get_type(void)
-{
- static GType type = 0;
- if (type == 0) {
- static const GTypeInfo info = {
- sizeof(GncDenseCalModelIface),
- gnc_dense_cal_model_base_init, /* base_init */
- NULL, /* base_finalize */
- NULL, /* class_init */
- NULL, /* class_finalize */
- NULL, /* class_data */
- 0,
- 0, /* n_preallocs */
- NULL /* instance_init */
- };
- type = g_type_register_static(G_TYPE_INTERFACE, "GncDenseCalModel", &info, 0);
- }
- return type;
-}
-
-GList*
-gnc_dense_cal_model_get_contained(GncDenseCalModel *model)
-{
- return (*GNC_DENSE_CAL_MODEL_GET_INTERFACE(model)->get_contained)(model);
-}
-
-gchar*
-gnc_dense_cal_model_get_name(GncDenseCalModel *model, guint tag)
-{
- return (*GNC_DENSE_CAL_MODEL_GET_INTERFACE(model)->get_name)(model, tag);
-}
-
-gchar*
-gnc_dense_cal_model_get_info(GncDenseCalModel *model, guint tag)
-{
- return (*GNC_DENSE_CAL_MODEL_GET_INTERFACE(model)->get_info)(model, tag);
-}
-
-gint
-gnc_dense_cal_model_get_instance_count(GncDenseCalModel *model, guint tag)
-{
- return (*GNC_DENSE_CAL_MODEL_GET_INTERFACE(model)->get_instance_count)(model, tag);
-}
-
-void
-gnc_dense_cal_model_get_instance(GncDenseCalModel *model, guint tag, gint instance_index, GDate *date)
-{
- return (*GNC_DENSE_CAL_MODEL_GET_INTERFACE(model)->get_instance)(model, tag, instance_index, date);
-}
-
-/* ------------------------------------------------------------ */
-
-static GList* gdctm_get_contained(GncDenseCalModel *model);
-static gchar* gdctm_get_name(GncDenseCalModel *model, guint tag);
-static gchar* gdctm_get_info(GncDenseCalModel *model, guint tag);
-static gint gdctm_get_instance_count(GncDenseCalModel *model, guint tag);
-static void gdctm_get_instance(GncDenseCalModel *model, guint tag, gint instance_index, GDate *date);
-
-static void
-gnc_dense_cal_transient_dense_cal_model_iface_init(gpointer g_iface, gpointer iface_data)
-{
- GncDenseCalModelIface *iface = (GncDenseCalModelIface*)g_iface;
- iface->get_contained = gdctm_get_contained;
- iface->get_name = gdctm_get_name;
- iface->get_info = gdctm_get_info;
- iface->get_instance_count = gdctm_get_instance_count;
- iface->get_instance = gdctm_get_instance;
-}
-
-GType
-gnc_dense_cal_transient_model_get_type(void)
-{
- static GType type = 0;
- if (type == 0)
- {
- static const GTypeInfo info = {
- sizeof (GncDenseCalTransientModelClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- NULL, /* class_init */
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof(GncDenseCalTransientModel),
- 0, /* n_preallocs */
- NULL /* instance_init */
- };
- static const GInterfaceInfo iDenseCalModelInfo = {
- (GInterfaceInitFunc)gnc_dense_cal_transient_dense_cal_model_iface_init,
- NULL, /* interface finalize */
- NULL, /* interface data */
- };
- type = g_type_register_static(G_TYPE_OBJECT, "GncDenseCalTransientModel", &info, 0);
- g_type_add_interface_static(type,
- GNC_TYPE_DENSE_CAL_MODEL,
- &iDenseCalModelInfo);
- }
- return type;
-}
-
-GncDenseCalTransientModel*
-gnc_dense_cal_transient_model_new(int num_marks)
-{
- GncDenseCalTransientModel *model = g_object_new(GNC_TYPE_DENSE_CAL_TRANSIENT_MODEL, NULL);
- model->num_marks = num_marks;
- model->cal_marks = g_new0(GDate*, num_marks);
- {
- int i = 0;
- for (i = 0; i < model->num_marks; i++)
- {
- model->cal_marks[i] = g_date_new();
- }
- }
- model->num_real_marks = 0;
- g_date_clear(&model->start_date, 1);
- g_date_set_time_t(&model->start_date, time(NULL));
- model->end_type = NEVER_END;
- g_date_clear(&model->end_date, 1);
- g_date_set_time_t(&model->end_date, time(NULL));
- model->n_occurrences = 0;
- return model;
-}
-
-void
-gnc_dense_cal_transient_model_clear(GncDenseCalTransientModel *model)
-{
- model->num_real_marks = 0;
- g_signal_emit_by_name(model, "update", GUINT_TO_POINTER(1));
-}
-
-void
-gnc_dense_cal_transient_model_update_name(GncDenseCalTransientModel *model, gchar *name)
-{
- if (model->name != NULL)
- {
- g_free(model->name);
- }
- model->name = g_strdup(name);
- g_signal_emit_by_name(model, "update", GUINT_TO_POINTER(1));
-}
-
-void
-gnc_dense_cal_transient_model_update_info(GncDenseCalTransientModel *model, gchar *info)
-{
- if (model->info != NULL)
- {
- g_free(model->info);
- }
- model->info = g_strdup(info);
- g_signal_emit_by_name(model, "update", GUINT_TO_POINTER(1));
-}
-
-static void
-gdctm_generic_update(GncDenseCalTransientModel *trans, GDate *start, FreqSpec *fs)
-{
- int i;
- GDate date;
-
- date = *start;
- /* go one day before what's in the box so we can get the correct start
- * date. */
- g_date_subtract_days(&date, 1);
- xaccFreqSpecGetNextInstance(fs, &date, &date);
-
- i = 0;
- while ((i < trans->num_marks)
- && g_date_valid(&date)
- /* Do checking against end restriction. */
- && ((trans->end_type == NEVER_END)
- || (trans->end_type == END_ON_DATE
- && g_date_compare(&date, &trans->end_date) <= 0)
- || (trans->end_type == END_AFTER_N_OCCS
- && i < trans->n_occurrences)))
- {
- *trans->cal_marks[i++] = date;
- xaccFreqSpecGetNextInstance(fs, &date, &date);
- }
- trans->num_real_marks = (i-1);
- g_signal_emit_by_name(trans, "update", GUINT_TO_POINTER(1));
-}
-
-void
-gnc_dense_cal_transient_model_update_no_end(GncDenseCalTransientModel *model, GDate *start, FreqSpec *fs)
-{
- model->end_type = NEVER_END;
- gdctm_generic_update(model, start, fs);
-}
-
-void
-gnc_dense_cal_transient_model_update_count_end(GncDenseCalTransientModel *model, GDate *start, FreqSpec *fs, int num_occur)
-{
- model->end_type = END_AFTER_N_OCCS;
- model->n_occurrences = num_occur;
- gdctm_generic_update(model, start, fs);
-}
-
-void
-gnc_dense_cal_transient_model_update_date_end(GncDenseCalTransientModel *model, GDate *start, FreqSpec *fs, GDate *end_date)
-{
- model->end_type = END_ON_DATE;
- model->end_date = *end_date;
- gdctm_generic_update(model, start, fs);
-}
-
-static GList*
-gdctm_get_contained(GncDenseCalModel *model)
-{
- GList *rtn = NULL;
- rtn = g_list_append(rtn, GUINT_TO_POINTER(1));
- return rtn;
-}
-
-static gchar*
-gdctm_get_name(GncDenseCalModel *model, guint tag)
-{
- GncDenseCalTransientModel *mdl = GNC_DENSE_CAL_TRANSIENT_MODEL(model);
- // assert(tag == 1)
- return mdl->name;
-}
-
-static gchar*
-gdctm_get_info(GncDenseCalModel *model, guint tag)
-{
- GncDenseCalTransientModel *mdl = GNC_DENSE_CAL_TRANSIENT_MODEL(model);
- // assert(tag == 1)
- return mdl->info;
-}
-
-static gint
-gdctm_get_instance_count(GncDenseCalModel *model, guint tag)
-{
- GncDenseCalTransientModel *mdl = GNC_DENSE_CAL_TRANSIENT_MODEL(model);
- // assert(tag == 1)
- return mdl->num_real_marks;
-}
-
-static void
-gdctm_get_instance(GncDenseCalModel *model, guint tag, gint instance_index, GDate *date)
-{
- GncDenseCalTransientModel *mdl = GNC_DENSE_CAL_TRANSIENT_MODEL(model);
- // assert(tag == 1)
- // assert 0 < instance_index < model->num_marks;
- *date = *mdl->cal_marks[instance_index];
-}
-
-/* ------------------------------------------------------------ */
-
/**
* Todo:
* . marking
Modified: gnucash/branches/sx-cleanup/src/gnome-utils/gnc-dense-cal.h
===================================================================
--- gnucash/branches/sx-cleanup/src/gnome-utils/gnc-dense-cal.h 2006-10-09 19:47:15 UTC (rev 14947)
+++ gnucash/branches/sx-cleanup/src/gnome-utils/gnc-dense-cal.h 2006-10-09 23:05:38 UTC (rev 14948)
@@ -20,92 +20,18 @@
* Boston, MA 02110-1301, USA gnu at gnu.org *
\********************************************************************/
-#ifndef _DENSECAL_H_
-#define _DENSECAL_H_
+#ifndef _GNC_DENSE_CAL_H
+#define _GNC_DENSE_CAL_H
-#include <gdk/gdk.h>
-#include <gtk/gtkadjustment.h>
-#include <gtk/gtkwidget.h>
-#include <glib.h>
+#include "config.h"
+
#include <FreqSpec.h>
+#include <glib.h>
+#include "gnc-dense-cal-model.h"
+#include <gtk/gtk.h>
G_BEGIN_DECLS
-#define GNC_TYPE_DENSE_CAL_MODEL (gnc_dense_cal_model_get_type())
-#define GNC_DENSE_CAL_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_DENSE_CAL_MODEL, GncDenseCalModel))
-#define GNC_IS_DENSE_CAL_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_DENSE_CAL_MODEL))
-#define GNC_DENSE_CAL_MODEL_GET_INTERFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GNC_TYPE_DENSE_CAL_MODEL, GncDenseCalModelIface))
-
-typedef struct _GncDenseCalModel GncDenseCalModel; /* non existant */
-typedef struct _GncDenseCalModelIface GncDenseCalModelIface;
-
-struct _GncDenseCalModelIface
-{
- GTypeInterface parent;
-
- /* signals */
- void (*insert)(GncDenseCalModel *mdl, gint tag);
- void (*update)(GncDenseCalModel *mdl, gint tag);
- void (*remove)(GncDenseCalModel *mdl, gint tag);
-
- /* virtual table */
- GList* (*get_contained)(GncDenseCalModel *model);
- gchar* (*get_name)(GncDenseCalModel *model, guint tag);
- gchar* (*get_info)(GncDenseCalModel *model, guint tag);
- gint (*get_instance_count)(GncDenseCalModel *model, guint tag);
- void (*get_instance)(GncDenseCalModel *model, guint tag, gint instance_index, GDate *date);
-};
-
-GType gnc_dense_cal_model_get_type(void);
-
-/* @fixme: glist mem alloc policy... ? */
-GList* gnc_dense_cal_model_get_contained(GncDenseCalModel *model);
-gchar* gnc_dense_cal_model_get_name(GncDenseCalModel *model, guint tag);
-gchar* gnc_dense_cal_model_get_info(GncDenseCalModel *model, guint tag);
-gint gnc_dense_cal_model_get_instance_count(GncDenseCalModel *model, guint tag);
-void gnc_dense_cal_model_get_instance(GncDenseCalModel *model, guint tag, gint instance_index, GDate *date);
-
-/* ------------------------------------------------------------ */
-#define GNC_TYPE_DENSE_CAL_TRANSIENT_MODEL (gnc_dense_cal_transient_model_get_type())
-#define GNC_DENSE_CAL_TRANSIENT_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_DENSE_CAL_TRANSIENT_MODEL, GncDenseCalTransientModel))
-#define GNC_DENSE_CAL_TRANSIENT_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_DENSE_CAL_TRANSIENT_MODEL, GncDenseCalTransientModelClass))
-#define GNC_IS_DENSE_CAL_TRANSIENT_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_DENSE_CAL_TRANSIENT_MODEL))
-#define GNC_IS_DENSE_CAL_TRANSIENT_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_DENSE_CAL_TRANSIENT_MODEL))
-#define GNC_DENSE_CAL_TRANSIENT_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_TYPE_DENSE_CAL_TRANSIENT_MODEL, GncDenseCalTransientModel))
-
-typedef enum { NEVER_END, END_ON_DATE, END_AFTER_N_OCCS, BAD_END } gdctm_end_type;
-
-typedef struct _GncDenseCalTransientModel
-{
- GObject parent;
-
- GDate start_date;
- gdctm_end_type end_type;
- GDate end_date;
- gint n_occurrences;
- gchar *name;
- gchar *info;
- int num_marks;
- int num_real_marks;
- GDate **cal_marks;
-} GncDenseCalTransientModel;
-
-typedef struct _GncDenseCalTransientModelClass
-{
- GObjectClass parent_class;
-} GncDenseCalTransientModelClass;
-
-GType gnc_dense_cal_transient_model_get_type(void);
-GncDenseCalTransientModel* gnc_dense_cal_transient_model_new(int num_marks);
-void gnc_dense_cal_transient_model_clear(GncDenseCalTransientModel *model);
-void gnc_dense_cal_transient_model_update_name(GncDenseCalTransientModel *model, gchar* name);
-void gnc_dense_cal_transient_model_update_info(GncDenseCalTransientModel *model, gchar* info);
-void gnc_dense_cal_transient_model_update_no_end(GncDenseCalTransientModel *model, GDate *start, FreqSpec *fs);
-void gnc_dense_cal_transient_model_update_count_end(GncDenseCalTransientModel *model, GDate *start, FreqSpec *fs, int num_occur);
-void gnc_dense_cal_transient_model_update_date_end(GncDenseCalTransientModel *model, GDate *start, FreqSpec *fs, GDate *end_date);
-
-/* ------------------------------------------------------------ */
-
#define GNC_TYPE_DENSE_CAL (gnc_dense_cal_get_type ())
#define GNC_DENSE_CAL(obj) GTK_CHECK_CAST (obj, gnc_dense_cal_get_type (), GncDenseCal)
#define GNC_DENSE_CAL_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gnc_dense_cal_get_type (), GncDenseCalClass)
@@ -126,75 +52,75 @@
struct _GncDenseCal
{
- GtkWidget widget;
+ GtkWidget widget;
- GdkPixmap *drawbuf;
+ GdkPixmap *drawbuf;
- gboolean initialized;
+ gboolean initialized;
- gboolean showPopup;
- GtkWindow *transPopup;
+ gboolean showPopup;
+ GtkWindow *transPopup;
- gint min_x_scale;
- gint min_y_scale;
+ gint min_x_scale;
+ gint min_y_scale;
- gint x_scale;
- gint y_scale;
+ gint x_scale;
+ gint y_scale;
- gint numMonths;
- gint monthsPerCol;
- gint num_weeks; /* computed */
+ gint numMonths;
+ gint monthsPerCol;
+ gint num_weeks; /* computed */
- GDateMonth month;
- gint year;
- gint firstOfMonthOffset;
+ GDateMonth month;
+ gint year;
+ gint firstOfMonthOffset;
- gint leftPadding;
- gint topPadding;
+ gint leftPadding;
+ gint topPadding;
- gboolean needInitMonthLabels;
- gdc_month_coords monthPositions[12];
- GdkFont *monthLabelFont;
- GdkFont *dayLabelFont;
- GdkPixmap *monthLabels[12];
+ gboolean needInitMonthLabels;
+ gdc_month_coords monthPositions[12];
+ GdkFont *monthLabelFont;
+ GdkFont *dayLabelFont;
+ GdkPixmap *monthLabels[12];
- GdkColor weekColors[MAX_COLORS];
+ GdkColor weekColors[MAX_COLORS];
- guint label_lbearing;
- guint label_ascent;
- guint label_width;
- guint label_height;
- guint dayLabelHeight;
+ guint label_lbearing;
+ guint label_ascent;
+ guint label_width;
+ guint label_height;
+ guint dayLabelHeight;
- GncDenseCalModel *model;
+ GncDenseCalModel *model;
- guint lastMarkTag;
+ guint lastMarkTag;
- /**
- * A GList of gdc_mark_data structs, one for each active/valid markTag.
- **/
- GList *markData;
- int numMarks;
- /* array of GList*s of per-cell markings. */
- GList **marks;
+ /**
+ * A GList of gdc_mark_data structs, one for each active/valid markTag.
+ **/
+ GList *markData;
+ int numMarks;
+ /* array of GList*s of per-cell markings. */
+ GList **marks;
- int disposed; /* private */
+ int disposed; /* private */
};
struct _GncDenseCalClass
{
- GtkWidgetClass parent_class;
+ GtkWidgetClass parent_class;
};
typedef struct _gdc_mark_data {
- gchar *name;
- gchar *info;
- guint tag;
- /* GdkColor markStyle; */
- /**
- * A GList of the dcal->marks indexes containing this mark.
- **/
- GList *ourMarks;
+ gchar *name;
+ gchar *info;
+ guint tag;
+ /* GdkColor markStyle; */
+ /**
+ * A GList of the dcal->marks indexes containing this mark.
+ **/
+ GList *ourMarks;
} gdc_mark_data;
GtkWidget* gnc_dense_cal_new (void);
@@ -202,7 +128,6 @@
GType gnc_dense_cal_get_type (void);
void gnc_dense_cal_set_model(GncDenseCal *cal, GncDenseCalModel *model);
-
void gnc_dense_cal_set_month(GncDenseCal *dcal, GDateMonth mon);
/**
* @param year Julian year: 2000 = 2000AD.
@@ -224,4 +149,4 @@
G_END_DECLS
-#endif /* _DENSECAL_H_ */
+#endif /* _GNC_DENSE_CAL_H */
Added: gnucash/branches/sx-cleanup/src/gnome-utils/gnc-sx-instance-dense-cal-adapter.c
===================================================================
--- gnucash/branches/sx-cleanup/src/gnome-utils/gnc-sx-instance-dense-cal-adapter.c 2006-10-09 19:47:15 UTC (rev 14947)
+++ gnucash/branches/sx-cleanup/src/gnome-utils/gnc-sx-instance-dense-cal-adapter.c 2006-10-09 23:05:38 UTC (rev 14948)
@@ -0,0 +1,219 @@
+/*
+ * gnc-sx-instance-dense-cal-adapter.c
+ *
+ * Copyright (C) 2006 Josh Sled <jsled at asynchronous.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation Voice: +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
+ * Boston, MA 02110-1301, USA gnu at gnu.org
+ */
+
+#include "config.h"
+#include <glib.h>
+#include "gnc-sx-instance-dense-cal-adapter.h"
+#include "gnc-dense-cal.h"
+
+static GList* gsidca_get_contained(GncDenseCalModel *model);
+static gchar* gsidca_get_name(GncDenseCalModel *model, guint tag);
+static gchar* gsidca_get_info(GncDenseCalModel *model, guint tag);
+static gint gsidca_get_instance_count(GncDenseCalModel *model, guint tag);
+static void gsidca_get_instance(GncDenseCalModel *model, guint tag, gint instance_index, GDate *date);
+
+struct _GncSxInstanceDenseCalAdapterClass
+{
+ GObjectClass parent;
+};
+
+struct _GncSxInstanceDenseCalAdapter
+{
+ GObject parent;
+ GncSxInstanceModel *instances;
+};
+
+static void
+gnc_sx_instance_dense_cal_adapter_class_init(GncSxInstanceDenseCalAdapterClass *klass)
+{
+ ; /* nop */
+}
+
+static void
+gnc_sx_instance_dense_cal_adapter_init(GTypeInstance *instance, gpointer klass)
+{
+ /*GncSxInstanceDenseCalAdapter *adapter = GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(instance);*/
+ ; /* nop */
+}
+
+static void
+gnc_sx_instance_dense_cal_adapter_interface_init(gpointer g_iface, gpointer iface_data)
+{
+ GncDenseCalModelIface *iface = (GncDenseCalModelIface*)g_iface;
+ iface->get_contained = gsidca_get_contained;
+ iface->get_name = gsidca_get_name;
+ iface->get_info = gsidca_get_info;
+ iface->get_instance_count = gsidca_get_instance_count;
+ iface->get_instance = gsidca_get_instance;
+}
+
+static void
+gsidca_instances_added_cb(GncSxInstanceModel *model, gpointer instance_added, gpointer user_data)
+{
+ GncSxInstanceDenseCalAdapter *adapter = GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(user_data);
+ g_signal_emit_by_name(adapter, "added", GPOINTER_TO_UINT(instance_added));
+}
+
+static void
+gsidca_instances_updated_cb(GncSxInstanceModel *model, gpointer user_data)
+{
+ GncSxInstanceDenseCalAdapter *adapter = GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(user_data);
+ // @@fixme figure out which; emit appropriate signal.
+ GList *exposed_tags;
+ printf("instances updated\n");
+ for (exposed_tags = gsidca_get_contained(GNC_DENSE_CAL_MODEL(adapter)); exposed_tags != NULL; exposed_tags = exposed_tags->next)
+ {
+ g_signal_emit_by_name(adapter, "update", GPOINTER_TO_UINT(exposed_tags->data));
+ }
+}
+
+static void
+gsidca_instances_removing_cb(GncSxInstanceModel *model, gpointer instance_to_be_removed, gpointer user_data)
+{
+ GncSxInstanceDenseCalAdapter *adapter = GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(user_data);
+ printf("removing instance...\n");
+ g_signal_emit_by_name(adapter, "removing", GPOINTER_TO_UINT(instance_to_be_removed));
+}
+
+GncSxInstanceDenseCalAdapter*
+gnc_sx_instance_dense_cal_adapter_new(GncSxInstanceModel *instances)
+{
+ GncSxInstanceDenseCalAdapter *adapter = g_object_new(GNC_TYPE_SX_INSTANCE_DENSE_CAL_ADAPTER, NULL);
+ adapter->instances = instances;
+ g_signal_connect(instances, "added", (GCallback)gsidca_instances_added_cb, adapter);
+ g_signal_connect(instances, "updated", (GCallback)gsidca_instances_updated_cb, adapter);
+ g_signal_connect(instances, "removing", (GCallback)gsidca_instances_removing_cb, adapter);
+ return adapter;
+}
+
+GType
+gnc_sx_instance_dense_cal_adapter_get_type(void)
+{
+ static GType type = 0;
+ if (type == 0)
+ {
+ static const GTypeInfo info = {
+ sizeof (GncSxInstanceDenseCalAdapterClass),
+ NULL, /* base init */
+ NULL, /* base finalize */
+ (GClassInitFunc)gnc_sx_instance_dense_cal_adapter_class_init,
+ NULL, /* class finalize */
+ NULL, /* class data */
+ sizeof(GncSxInstanceDenseCalAdapter),
+ 0, /* n_preallocs */
+ (GInstanceInitFunc)gnc_sx_instance_dense_cal_adapter_init
+ };
+ static const GInterfaceInfo iDenseCalModelInfo = {
+ (GInterfaceInitFunc)gnc_sx_instance_dense_cal_adapter_interface_init,
+ NULL, /* interface finalize */
+ NULL, /* interface data */
+ };
+
+ type = g_type_register_static (G_TYPE_OBJECT,
+ "GncSxInstanceDenseCalAdapterType",
+ &info, 0);
+ g_type_add_interface_static(type,
+ GNC_TYPE_DENSE_CAL_MODEL,
+ &iDenseCalModelInfo);
+ }
+ return type;
+}
+
+static gint
+gsidca_find_sx_with_tag(gconstpointer list_data,
+ gconstpointer find_data)
+{
+ GncSxInstances *sx_instances = (GncSxInstances*)list_data;
+ return (GUINT_TO_POINTER(GPOINTER_TO_UINT(sx_instances->sx)) == find_data ? 0 : 1);
+}
+
+static GList*
+gsidca_get_contained(GncDenseCalModel *model)
+{
+ GncSxInstanceDenseCalAdapter *adapter = GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(model);
+ //"removing return gnc_g_list_map(instances->sxes, sx_to_tag, null);
+ GList *list = NULL, *sxes;
+ for (sxes = adapter->instances->sx_instance_list; sxes != NULL; sxes = sxes->next)
+ {
+ GncSxInstances *sx_instances = (GncSxInstances*)sxes->data;
+ list = g_list_append(list, GUINT_TO_POINTER(GPOINTER_TO_UINT(sx_instances->sx)));
+ }
+ return list;
+}
+
+static gchar*
+gsidca_get_name(GncDenseCalModel *model, guint tag)
+{
+ GncSxInstanceDenseCalAdapter *adapter = GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(model);
+ GncSxInstances *insts
+ = (GncSxInstances*)g_list_find_custom(adapter->instances->sx_instance_list, GUINT_TO_POINTER(tag), gsidca_find_sx_with_tag)->data;
+ if (insts == NULL)
+ return NULL;
+ return xaccSchedXactionGetName(insts->sx);
+}
+
+static gchar*
+gsidca_get_info(GncDenseCalModel *model, guint tag)
+{
+ GncSxInstanceDenseCalAdapter *adapter = GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(model);
+ // g_list_find(instances->sxes, {sx_to_tag, tag}).get_freq_spec().get_freq_str();
+ FreqSpec *spec;
+ GString *info;
+ gchar *info_str;
+ GncSxInstances *insts
+ = (GncSxInstances*)g_list_find_custom(adapter->instances->sx_instance_list, GUINT_TO_POINTER(tag), gsidca_find_sx_with_tag)->data;
+ if (insts == NULL)
+ return NULL;
+ spec = xaccSchedXactionGetFreqSpec(insts->sx);
+ info = g_string_sized_new(16);
+ xaccFreqSpecGetFreqStr(spec, info);
+ info_str = info->str; // @fixme leaked... :/
+ g_string_free(info, FALSE);
+ return info_str;
+}
+
+static gint
+gsidca_get_instance_count(GncDenseCalModel *model, guint tag)
+{
+ GncSxInstanceDenseCalAdapter *adapter = GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(model);
+ // g_list_find(instances->sxes, {sx_to_tag, tag}).length();
+ GncSxInstances *insts
+ = (GncSxInstances*)g_list_find_custom(adapter->instances->sx_instance_list, GUINT_TO_POINTER(tag), gsidca_find_sx_with_tag)->data;
+ if (insts == NULL)
+ return 0;
+ return g_list_length(insts->list);
+}
+
+static void
+gsidca_get_instance(GncDenseCalModel *model, guint tag, gint instance_index, GDate *date)
+{
+ GncSxInstanceDenseCalAdapter *adapter = GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(model);
+ GncSxInstance *inst;
+ GncSxInstances *insts
+ = (GncSxInstances*)g_list_find_custom(adapter->instances->sx_instance_list, GUINT_TO_POINTER(tag), gsidca_find_sx_with_tag)->data;
+ if (insts == NULL)
+ return;
+ inst = (GncSxInstance*)g_list_nth_data(insts->list, instance_index);
+ g_date_valid(&inst->date);
+ *date = inst->date;
+ g_date_valid(date);
+}
Added: gnucash/branches/sx-cleanup/src/gnome-utils/gnc-sx-instance-dense-cal-adapter.h
===================================================================
--- gnucash/branches/sx-cleanup/src/gnome-utils/gnc-sx-instance-dense-cal-adapter.h 2006-10-09 19:47:15 UTC (rev 14947)
+++ gnucash/branches/sx-cleanup/src/gnome-utils/gnc-sx-instance-dense-cal-adapter.h 2006-10-09 23:05:38 UTC (rev 14948)
@@ -0,0 +1,43 @@
+/*
+ * gnc-sx-instance-dense-cal-adapter.h
+ *
+ * Copyright (C) 2006 Josh Sled <jsled at asynchronous.org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation Voice: +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
+ * Boston, MA 02110-1301, USA gnu at gnu.org
+ */
+
+#ifndef _GNC_SX_INSTANCE_DENSE_CAL_ADAPTER_H
+#define _GNC_SX_INSTANCE_DENSE_CAL_ADAPTER_H
+
+#include "config.h"
+#include <glib.h>
+#include "gnc-sx-instance-model.h"
+
+typedef struct _GncSxInstanceDenseCalAdapterClass GncSxInstanceDenseCalAdapterClass;
+typedef struct _GncSxInstanceDenseCalAdapter GncSxInstanceDenseCalAdapter;
+
+#define GNC_TYPE_SX_INSTANCE_DENSE_CAL_ADAPTER (gnc_sx_instance_dense_cal_adapter_get_type ())
+#define GNC_SX_INSTANCE_DENSE_CAL_ADAPTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_SX_INSTANCE_DENSE_CAL_ADAPTER, GncSxInstanceDenseCalAdapter))
+#define GNC_SX_INSTANCE_DENSE_CAL_ADAPTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_SX_INSTANCE_DENSE_CAL_ADAPTER, GncSxInstanceDenseCalAdapterClass))
+#define GNC_IS_SX_INSTANCE_DENSE_CAL_ADAPTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_SX_INSTANCE_DENSE_CAL_ADAPTER))
+#define GNC_IS_SX_INSTANCE_DENSE_CAL_ADAPTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_SX_INSTANCE_DENSE_CAL_ADAPTER))
+#define GNC_SX_INSTANCE_DENSE_CAL_ADAPTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_TYPE_SX_INSTANCE_DENSE_CAL_ADAPTER, GncSxInstanceDenseCalAdapterClass))
+
+GncSxInstanceDenseCalAdapter* gnc_sx_instance_dense_cal_adapter_new(GncSxInstanceModel *instances);
+GType gnc_sx_instance_dense_cal_adapter_get_type(void);
+
+#endif // _GNC_SX_INSTANCE_DENSE_CAL_ADAPTER_H
More information about the gnucash-changes
mailing list