2003-06-10 10:07:52 -05:00
|
|
|
/********************************************************************\
|
|
|
|
* SX-book.c -- scheduled transaction dataset access *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 2 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* 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 *
|
|
|
|
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
|
|
|
|
* Boston, MA 02111-1307, USA gnu@gnu.org *
|
|
|
|
\********************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FILE:
|
|
|
|
* SX-book.c
|
|
|
|
*
|
|
|
|
* FUNCTION:
|
|
|
|
* Anchor Scheduled Transaction Info into the book.
|
|
|
|
* See src/doc/books.txt for design overview.
|
|
|
|
*
|
|
|
|
* HISTORY:
|
|
|
|
* Copyright (c) 2003 Linas Vepstas <linas@linas.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include "gnc-engine.h"
|
2003-06-10 10:21:47 -05:00
|
|
|
#include "gnc-trace.h"
|
|
|
|
#include "Group.h"
|
|
|
|
#include "GroupP.h"
|
2003-06-10 10:07:52 -05:00
|
|
|
#include "SchedXaction.h"
|
|
|
|
#include "SX-book.h"
|
|
|
|
#include "SX-book-p.h"
|
2003-06-24 19:52:46 -05:00
|
|
|
#include "qofbook.h"
|
|
|
|
#include "qofbook-p.h"
|
2003-06-24 21:08:22 -05:00
|
|
|
#include "qofobject.h"
|
2003-06-10 10:07:52 -05:00
|
|
|
|
2003-06-10 10:21:47 -05:00
|
|
|
static short module = MOD_SX;
|
2003-06-10 10:07:52 -05:00
|
|
|
|
|
|
|
/* ====================================================================== */
|
|
|
|
|
|
|
|
#define GNC_SCHEDXACTIONS "gnc_schedxactions"
|
|
|
|
SchedXactions *
|
2003-06-24 19:52:46 -05:00
|
|
|
gnc_book_get_schedxaction_list( QofBook *book )
|
2003-06-10 10:07:52 -05:00
|
|
|
{
|
|
|
|
if ( book == NULL ) return NULL;
|
2003-06-24 19:52:46 -05:00
|
|
|
return qof_book_get_data (book, GNC_SCHEDXACTIONS);
|
2003-06-10 10:07:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
GList *
|
2003-06-24 19:52:46 -05:00
|
|
|
gnc_book_get_schedxactions( QofBook *book )
|
2003-06-10 10:07:52 -05:00
|
|
|
{
|
|
|
|
SchedXactions *list;
|
|
|
|
if ( book == NULL ) return NULL;
|
2003-06-24 19:52:46 -05:00
|
|
|
list = qof_book_get_data (book, GNC_SCHEDXACTIONS);
|
2003-06-10 10:07:52 -05:00
|
|
|
if (list) return list->sx_list;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-06-24 19:52:46 -05:00
|
|
|
gnc_book_set_schedxactions( QofBook *book, GList *newList )
|
2003-06-10 10:07:52 -05:00
|
|
|
{
|
|
|
|
SchedXactions *old_list, *new_list;
|
|
|
|
if ( book == NULL ) return;
|
|
|
|
|
2003-06-24 19:52:46 -05:00
|
|
|
old_list = qof_book_get_data (book, GNC_SCHEDXACTIONS);
|
2003-06-10 14:31:53 -05:00
|
|
|
if (old_list && old_list->sx_list == newList)
|
|
|
|
{
|
|
|
|
/* Assume the worst, that any 'set' means the data has
|
|
|
|
* changed, and needs to be saved. */
|
|
|
|
old_list->sx_notsaved = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
2003-06-10 10:07:52 -05:00
|
|
|
|
|
|
|
new_list = g_new (SchedXactions, 1);
|
|
|
|
new_list->book = book;
|
|
|
|
new_list->sx_list = newList;
|
|
|
|
new_list->sx_notsaved = TRUE;
|
|
|
|
if (NULL == newList) new_list->sx_notsaved = FALSE;
|
|
|
|
|
2003-06-24 19:52:46 -05:00
|
|
|
qof_book_set_data (book, GNC_SCHEDXACTIONS, new_list);
|
2003-06-10 10:07:52 -05:00
|
|
|
|
|
|
|
g_free (old_list);
|
|
|
|
}
|
|
|
|
|
2003-06-10 10:21:47 -05:00
|
|
|
/* ====================================================================== */
|
|
|
|
|
|
|
|
#define GNC_TEMPLATE_GROUP "gnc_template_group"
|
|
|
|
AccountGroup *
|
2003-06-24 19:52:46 -05:00
|
|
|
gnc_book_get_template_group( QofBook *book )
|
2003-06-10 10:21:47 -05:00
|
|
|
{
|
|
|
|
if (!book) return NULL;
|
2003-06-24 19:52:46 -05:00
|
|
|
return qof_book_get_data (book, GNC_TEMPLATE_GROUP);
|
2003-06-10 10:21:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-06-24 19:52:46 -05:00
|
|
|
gnc_book_set_template_group (QofBook *book, AccountGroup *templateGroup)
|
2003-06-10 10:21:47 -05:00
|
|
|
{
|
|
|
|
AccountGroup *old_grp;
|
|
|
|
if (!book) return;
|
|
|
|
|
|
|
|
if (templateGroup && templateGroup->book != book)
|
|
|
|
{
|
|
|
|
PERR ("cannot mix and match books freely!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
old_grp = gnc_book_get_template_group (book);
|
|
|
|
if (old_grp == templateGroup) return;
|
|
|
|
|
2003-06-24 19:52:46 -05:00
|
|
|
qof_book_set_data (book, GNC_TEMPLATE_GROUP, templateGroup);
|
2003-06-10 10:21:47 -05:00
|
|
|
|
|
|
|
xaccAccountGroupBeginEdit (old_grp);
|
|
|
|
xaccAccountGroupDestroy (old_grp);
|
|
|
|
}
|
|
|
|
|
2003-06-10 17:22:47 -05:00
|
|
|
|
|
|
|
/* ====================================================================== */
|
|
|
|
/* gncObject function implementation and registration */
|
|
|
|
/* XXX Its not clear to me if the template group and the sched xactions
|
|
|
|
* should be treated together or not. I got lazy, and mashed them together.
|
|
|
|
* For right now, this works. If you feel you need to slit this up into
|
|
|
|
* two separate gnc Objects, that's OK with me.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
2003-06-24 19:52:46 -05:00
|
|
|
sxtt_book_begin (QofBook *book)
|
2003-06-10 17:22:47 -05:00
|
|
|
{
|
|
|
|
gnc_book_set_schedxactions (book, NULL);
|
|
|
|
gnc_book_set_template_group (book, xaccMallocAccountGroup(book));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-06-24 19:52:46 -05:00
|
|
|
sxtt_book_end (QofBook *book)
|
2003-06-10 17:22:47 -05:00
|
|
|
{
|
|
|
|
gnc_book_set_template_group (book, NULL);
|
|
|
|
gnc_book_set_schedxactions (book, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ====================================================================== */
|
|
|
|
/* dirty flag stuff */
|
|
|
|
|
|
|
|
static void
|
|
|
|
mark_sx_clean(gpointer data, gpointer user_data)
|
|
|
|
{
|
|
|
|
SchedXaction *sx = (SchedXaction *) data;
|
|
|
|
xaccSchedXactionSetDirtyness(sx, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-06-24 19:52:46 -05:00
|
|
|
book_sxns_mark_saved(QofBook *book)
|
2003-06-10 17:22:47 -05:00
|
|
|
{
|
|
|
|
SchedXactions *sxl;
|
|
|
|
|
|
|
|
sxl = gnc_book_get_schedxaction_list (book);
|
|
|
|
if (sxl) sxl->sx_notsaved = FALSE;
|
|
|
|
g_list_foreach(gnc_book_get_schedxactions(book),
|
|
|
|
mark_sx_clean,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2003-06-24 19:52:46 -05:00
|
|
|
book_sxlist_notsaved(QofBook *book)
|
2003-06-10 17:22:47 -05:00
|
|
|
{
|
|
|
|
GList *sxlist;
|
|
|
|
SchedXaction *sx;
|
|
|
|
SchedXactions *sxl;
|
|
|
|
|
|
|
|
sxl = gnc_book_get_schedxaction_list (book);
|
|
|
|
if((sxl && sxl->sx_notsaved)
|
|
|
|
||
|
|
|
|
xaccGroupNotSaved(gnc_book_get_template_group(book))) return TRUE;
|
|
|
|
|
|
|
|
for(sxlist = gnc_book_get_schedxactions(book);
|
|
|
|
sxlist != NULL;
|
|
|
|
sxlist = g_list_next(sxlist))
|
|
|
|
{
|
|
|
|
sx = (SchedXaction *) (sxlist->data);
|
|
|
|
if (xaccSchedXactionIsDirty( sx ))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-06-24 19:52:46 -05:00
|
|
|
sxtt_mark_clean(QofBook *book)
|
2003-06-10 17:22:47 -05:00
|
|
|
{
|
|
|
|
xaccGroupMarkSaved(gnc_book_get_template_group(book));
|
|
|
|
book_sxns_mark_saved(book);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-24 21:08:22 -05:00
|
|
|
static QofObject sxtt_object_def =
|
2003-06-10 17:22:47 -05:00
|
|
|
{
|
|
|
|
interface_version: GNC_OBJECT_VERSION,
|
|
|
|
name: GNC_ID_SXTT,
|
|
|
|
type_label: "SXTT",
|
|
|
|
book_begin: sxtt_book_begin,
|
|
|
|
book_end: sxtt_book_end,
|
|
|
|
is_dirty: book_sxlist_notsaved,
|
|
|
|
mark_clean: sxtt_mark_clean,
|
|
|
|
foreach: NULL,
|
|
|
|
printable: NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gnc_sxtt_register (void)
|
|
|
|
{
|
2003-06-24 21:08:22 -05:00
|
|
|
return qof_object_register (&sxtt_object_def);
|
2003-06-10 17:22:47 -05:00
|
|
|
}
|
|
|
|
|
2003-06-10 10:07:52 -05:00
|
|
|
/* ========================== END OF FILE =============================== */
|