Add account-deletion handling for SXes. Bug#312730.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13400 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Joshua Sled 2006-02-26 19:55:17 +00:00
parent 70584b5e72
commit 7d4c8423f1
5 changed files with 242 additions and 5 deletions

View File

@ -15,6 +15,11 @@
2006-02-26 Joshua Sled <jsled@asynchronous.org>
* src/engine/SX-book.c (gnc_sx_get_sxes_referencing_account):
* src/gnome/dialog-scheduledxaction.c: Add handler for
account-deleted events, determine and display editors for SXes
referencing those accounts. Fixes Bug#312730.
* src/report/utility-reports/Makefile.am (SCM_FILE_LINKS):
* src/report/utility-reports/utility-reports.scm:
* src/report/utility-reports/iframe-url.scm:

View File

@ -129,7 +129,6 @@ sxtg_mark_clean(QofCollection *col)
xaccGroupMarkSaved(gnc_collection_get_template_group(col));
}
static QofObject sxtg_object_def =
{
interface_version: QOF_OBJECT_VERSION,
@ -146,13 +145,13 @@ static QofObject sxtg_object_def =
/* ====================================================================== */
SchedXactions *
gnc_collection_get_schedxaction_list( QofCollection *col)
gnc_collection_get_schedxaction_list(QofCollection *col)
{
return qof_collection_get_data (col);
}
GList *
gnc_collection_get_schedxactions( QofCollection *col)
gnc_collection_get_schedxactions(QofCollection *col)
{
SchedXactions *list;
list = qof_collection_get_data (col);
@ -161,7 +160,7 @@ gnc_collection_get_schedxactions( QofCollection *col)
}
GList *
gnc_book_get_schedxactions( QofBook *book )
gnc_book_get_schedxactions(QofBook *book)
{
QofCollection *col;
col = qof_book_get_collection (book, GNC_ID_SXTT);
@ -280,4 +279,28 @@ gnc_sxtt_register (void)
return qof_object_register (&sxtt_object_def);
}
GList*
gnc_sx_get_sxes_referencing_account(QofBook *book, Account *acct)
{
GList *rtn = NULL;
const GUID *acct_guid = xaccAccountGetGUID(acct);
GList *sx_list = gnc_book_get_schedxactions(book);
for (; sx_list != NULL; sx_list = sx_list->next)
{
SchedXaction *sx = (SchedXaction*)sx_list->data;
GList *splits = xaccSchedXactionGetSplits(sx);
for (; splits != NULL; splits = splits->next)
{
Split *s = (Split*)splits->data;
KvpFrame *frame = kvp_frame_get_frame(xaccSplitGetSlots(s), GNC_SX_ID);
GUID *sx_split_acct_guid = kvp_frame_get_guid(frame, GNC_SX_ACCOUNT);
if (guid_equal(acct_guid, sx_split_acct_guid))
{
rtn = g_list_append(rtn, sx);
}
}
}
return rtn;
}
/* ========================== END OF FILE =============================== */

View File

@ -53,6 +53,9 @@ GList * gnc_book_get_schedxactions(QofBook *book);
AccountGroup * gnc_book_get_template_group(QofBook *book);
AccountGroup * gnc_collection_get_template_group(QofCollection *col);
/** @return The list of SXes which reference the given Account. Caller should free this list. **/
GList* gnc_sx_get_sxes_referencing_account(QofBook *book, Account *acct);
#endif /* GNC_SX_BOOK_H */
/** @} */
/** @} */

View File

@ -1,7 +1,7 @@
/********************************************************************\
* dialog-scheduledxaction.c : dialog for scheduled transaction *
* list and editor *
* Copyright (C) 2001,2002 Joshua Sled <jsled@asynchronous.org> *
* Copyright (C) 2001,2002,2006 Joshua Sled <jsled@asynchronous.org>*
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
@ -29,6 +29,9 @@
#include <locale.h>
#include <time.h>
#include "qof.h"
#include "gnc-book.h"
#include "Account.h"
#include "FreqSpec.h"
#include "SchedXaction.h"
#include "SX-book.h"
@ -65,6 +68,8 @@
static QofLogModule log_module = GNC_MOD_SX;
static gint _sx_engine_event_handler_id = -1;
#define SX_LIST_GCONF_SECTION "dialogs/scheduled_trans/transaction_list"
#define SX_LIST_WIN_PREFIX "sx_list_win"
#define SX_LIST_GLADE_NAME "Scheduled Transaction List"
@ -2456,10 +2461,99 @@ on_sx_check_toggled (GtkWidget *togglebutton,
gtk_widget_set_sensitive(widget, create);
}
typedef struct _acct_deletion_handler_data
{
GList *affected_sxes;
GtkWidget *dialog;
} acct_deletion_handler_data;
static void
_open_editors(GtkDialog *dialog, gint response_code, gpointer data)
{
acct_deletion_handler_data *adhd = (acct_deletion_handler_data *)data;
gtk_widget_hide_all(adhd->dialog);
{
GList *sx_iter;
for (sx_iter = adhd->affected_sxes; sx_iter; sx_iter = sx_iter->next)
{
gnc_ui_scheduled_xaction_editor_dialog_create(NULL,
(SchedXaction*)sx_iter->data,
FALSE);
}
}
g_list_free(adhd->affected_sxes);
gtk_widget_destroy(GTK_WIDGET(adhd->dialog));
g_free(adhd);
}
static void
_sx_engine_event_handler(QofEntity *ent, QofEventId event_type, gpointer user_data)
{
Account *acct;
QofBook *book;
GList *affected_sxes;
if (!(event_type & QOF_EVENT_DESTROY))
return;
if (!GNC_IS_ACCOUNT(ent))
return;
acct = GNC_ACCOUNT(ent);
book = qof_instance_get_book(QOF_INSTANCE(acct));
affected_sxes = gnc_sx_get_sxes_referencing_account(book, acct);
if (g_list_length(affected_sxes) == 0)
return;
{
GList *sx_iter;
acct_deletion_handler_data *data;
GladeXML *xml;
GtkWidget *dialog;
GtkListStore *name_list;
GtkTreeView *list;
GtkTreeViewColumn *name_column;
GtkCellRenderer *renderer;
xml = gnc_glade_xml_new("sched-xact.glade", "Account Deletion");
dialog = glade_xml_get_widget(xml, "Account Deletion");
list = GTK_TREE_VIEW(glade_xml_get_widget(xml, "sx_list"));
data = (acct_deletion_handler_data*)g_new0(acct_deletion_handler_data, 1);
data->dialog = dialog;
data->affected_sxes = affected_sxes;
name_list = gtk_list_store_new(1, G_TYPE_STRING);
for (sx_iter = affected_sxes; sx_iter != NULL; sx_iter = sx_iter->next)
{
SchedXaction *sx;
GtkTreeIter iter;
gchar *sx_name;
sx = (SchedXaction*)sx_iter->data;
sx_name = xaccSchedXactionGetName(sx);
gtk_list_store_append(name_list, &iter);
gtk_list_store_set(name_list, &iter, 0, sx_name, -1);
}
gtk_tree_view_set_model(list, GTK_TREE_MODEL(name_list));
g_object_unref(G_OBJECT(name_list));
renderer = gtk_cell_renderer_text_new();
name_column = gtk_tree_view_column_new_with_attributes(_("Name"),
renderer,
"text", 0, NULL);
gtk_tree_view_append_column(list, name_column);
g_signal_connect(G_OBJECT(dialog), "response",
G_CALLBACK(_open_editors), data);
gtk_widget_show_all(GTK_WIDGET(dialog));
}
}
void
gnc_ui_sx_initialize (void)
{
_sx_engine_event_handler_id = qof_event_register_handler(_sx_engine_event_handler, NULL);
gnc_hook_add_dangler(HOOK_BOOK_OPENED,
(GFunc)gnc_sx_sxsincelast_book_opened, NULL);
gnc_preferences_add_page (SX_GLADE_FILE,

View File

@ -8551,4 +8551,116 @@ If you make a mistake or want to make changes later, you can edit the created Sc
</child>
</widget>
<widget class="GtkDialog" id="Account Deletion">
<property name="visible">True</property>
<property name="title" translatable="yes">Account Deletion</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_CENTER</property>
<property name="modal">False</property>
<property name="default_width">320</property>
<property name="default_height">240</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="has_separator">True</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox24">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area24">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="okbutton1">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-ok</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-5</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
<child>
<widget class="GtkVBox" id="vbox181">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkLabel" id="label847994">
<property name="visible">True</property>
<property name="label" translatable="yes">The following Scheduled Transactions reference the deleted account, and must now be corrected. Press OK to edit them.</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">True</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow20">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="shadow_type">GTK_SHADOW_IN</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTreeView" id="sx_list">
<property name="visible">True</property>
<property name="headers_visible">False</property>
<property name="rules_hint">False</property>
<property name="reorderable">False</property>
<property name="enable_search">False</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>