r18910 - gnucash/trunk/src - Bug #140400 - Crash when deleting an account that is still in use by the business features

Phil Longstaff plongstaff at code.gnucash.org
Mon Mar 15 10:49:39 EDT 2010


Author: plongstaff
Date: 2010-03-15 10:49:39 -0400 (Mon, 15 Mar 2010)
New Revision: 18910
Trac: http://svn.gnucash.org/trac/changeset/18910

Added:
   gnucash/trunk/src/gnome-utils/dialog-object-references.c
   gnucash/trunk/src/gnome-utils/dialog-object-references.h
   gnucash/trunk/src/gnome-utils/glade/dialog-object-references.glade
Modified:
   gnucash/trunk/src/gnome-utils/Makefile.am
   gnucash/trunk/src/gnome-utils/glade/Makefile.am
   gnucash/trunk/src/gnome/gnc-plugin-page-account-tree.c
Log:
Bug #140400 - Crash when deleting an account that is still in use by the business features

Add a dialog which contains a list of objects referring to the account and an explanation that these need to be deleted or have the account reference modified.

Note: I'm no UI designer.  This is functional, but if anybody wants to pretty it up, go ahead.


Modified: gnucash/trunk/src/gnome/gnc-plugin-page-account-tree.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-plugin-page-account-tree.c	2010-03-15 09:01:50 UTC (rev 18909)
+++ gnucash/trunk/src/gnome/gnc-plugin-page-account-tree.c	2010-03-15 14:49:39 UTC (rev 18910)
@@ -64,6 +64,7 @@
 #include "window-reconcile.h"
 #include "window-autoclear.h"
 #include "window-main-summarybar.h"
+#include "dialog-object-references.h"
 
 /* This static indicates the debugging module that this .o belongs to.  */
 static QofLogModule log_module = GNC_MOD_GUI;
@@ -951,10 +952,22 @@
     Account *ta = NULL; /* transaction adopter */
     Account *daa = NULL; /* descendant account adopter */
     Account *dta = NULL; /* descendant transaction adopter */
+    GList* list;
 
     if (NULL == account)
         return;
 
+    /* If the account has objects referring to it, show the list - the account can't be deleted until these
+       references are dealt with. */
+    list = qof_instance_get_referring_object_list(QOF_INSTANCE(account));
+    if (list != NULL) {
+#define EXPLANATION "The list below shows objects which make use of the account which you want to delete.\nBefore you can delete it, you must either delete those objects or else modify them so they make use\nof another account"
+
+        gnc_ui_object_references_show( _(EXPLANATION), list);
+        g_list_free(list);
+        return;
+    }
+
     window = gnc_plugin_page_get_window(GNC_PLUGIN_PAGE(page));
     acct_name = gnc_account_get_full_name(account);
     if (!acct_name)

Modified: gnucash/trunk/src/gnome-utils/Makefile.am
===================================================================
--- gnucash/trunk/src/gnome-utils/Makefile.am	2010-03-15 09:01:50 UTC (rev 18909)
+++ gnucash/trunk/src/gnome-utils/Makefile.am	2010-03-15 14:49:39 UTC (rev 18910)
@@ -33,6 +33,7 @@
   dialog-book-close.c \
   dialog-commodity.c \
   dialog-file-access.c \
+  dialog-object-references.c \
   dialog-options.c \
   dialog-preferences.c \
   dialog-query-list.c \
@@ -111,6 +112,7 @@
   dialog-commodity.h \
   dialog-file-access.h \
   dialog-preferences.h \
+  dialog-object-references.h \
   dialog-options.h \
   dialog-query-list.h \
   dialog-reset-warnings.h \

Added: gnucash/trunk/src/gnome-utils/dialog-object-references.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-object-references.c	                        (rev 0)
+++ gnucash/trunk/src/gnome-utils/dialog-object-references.c	2010-03-15 14:49:39 UTC (rev 18910)
@@ -0,0 +1,88 @@
+/********************************************************************\
+ * dialog-object-references.c -- dialog for displaying a list of    *
+ *                               objects which refer to another     *
+ *                               specific object                    *
+ *                                                                  *
+ * Copyright (C) 2010 Phil Longstaff (plongstaff at rogers.com)        *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+\********************************************************************/
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <glade/glade.h>
+
+#include "gnc-ui.h"
+#include "dialog-utils.h"
+#include "dialog-object-references.h"
+
+static QofLogModule log_module = GNC_MOD_GUI;
+
+void
+gnc_ui_object_references_show( const gchar* explanation_text, GList* objlist )
+{
+    GtkWidget* dialog;
+    GladeXML* xml;
+    GtkWidget* box;
+    GList* ds_node;
+    GtkButton* op;
+    GList* node;
+    GtkLabel* explanation;
+    GtkListStore* store;
+    GtkWidget* listview;
+    GtkTreeViewColumn* column;
+    GtkCellRenderer* renderer;
+    gint response;
+
+    /* Open the dialog */
+    xml = gnc_glade_xml_new( "dialog-object-references.glade", "Object references" );
+    dialog = glade_xml_get_widget( xml, "Object references" );
+
+    explanation = GTK_LABEL(glade_xml_get_widget( xml, "lbl_explanation" ));
+    gtk_label_set_text( explanation, explanation_text );
+
+    /* Set up the list store */
+    store = gtk_list_store_new( 1, G_TYPE_STRING );
+    for( node = objlist; node != NULL; node = node->next )
+    {
+        QofInstance* inst = node->data;
+        GtkTreeIter iter;
+
+        gtk_list_store_append( store, &iter );
+        gtk_list_store_set( store, &iter, 0, qof_instance_get_display_name( inst ), -1 );
+    }
+
+    /* Set up the list view */
+    listview = gtk_tree_view_new_with_model( GTK_TREE_MODEL(store) );
+    renderer = gtk_cell_renderer_text_new();
+    column = gtk_tree_view_column_new_with_attributes( "Object", renderer, "text", 0, NULL );
+    gtk_tree_view_append_column( GTK_TREE_VIEW(listview), column );
+
+    box = glade_xml_get_widget( xml, "hbox_list" );
+    gtk_container_add( GTK_CONTAINER(box), listview );
+
+    /* Autoconnect signals */
+    glade_xml_signal_autoconnect_full( xml, gnc_glade_autoconnect_full_func, dialog );
+
+    /* Run the dialog */
+    gtk_widget_show_all( dialog );
+    response = gtk_dialog_run( GTK_DIALOG(dialog) );
+    gtk_widget_destroy( dialog );
+}

Added: gnucash/trunk/src/gnome-utils/dialog-object-references.h
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-object-references.h	                        (rev 0)
+++ gnucash/trunk/src/gnome-utils/dialog-object-references.h	2010-03-15 14:49:39 UTC (rev 18910)
@@ -0,0 +1,43 @@
+/********************************************************************\
+ * dialog-object-references.h -- dialog for displaying a list of    *
+ *                               objects which refer to a specific  *
+ *                               object                             *
+ *                                                                  *
+ * Copyright (C) 2010 Phil Longstaff (plongstaff at rogers.com)        *
+ *                                                                  *
+ * 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       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+\********************************************************************/
+
+#ifndef DIALOG_OBJECT_REFERENCES_H
+#define DIALOG_OBJECT_REFERENCES_H
+
+/** @addtogroup GUI
+    @{ */
+/** @file dialog-object-references.h
+ *
+ *  This file contains the functions to present a dialog box with a
+ *  list of object references and an explanation that these objects
+ *  must be modified to not refer to another specific object so that
+ *  that object may be deleted.
+ */
+
+void gnc_ui_object_references_show( const gchar* explanation, GList* objlist );
+
+/** @} */
+
+#endif /* DIALOG_OBJECT_REFERENCES_H */

Modified: gnucash/trunk/src/gnome-utils/glade/Makefile.am
===================================================================
--- gnucash/trunk/src/gnome-utils/glade/Makefile.am	2010-03-15 09:01:50 UTC (rev 18909)
+++ gnucash/trunk/src/gnome-utils/glade/Makefile.am	2010-03-15 14:49:39 UTC (rev 18910)
@@ -3,6 +3,7 @@
   commodity.glade \
   dialog-book-close.glade \
   dialog-file-access.glade \
+  dialog-object-references.glade \
   dialog-query-list.glade \
   dialog-reset-warnings.glade \
   druid-provider-multifile.glade \

Added: gnucash/trunk/src/gnome-utils/glade/dialog-object-references.glade
===================================================================
--- gnucash/trunk/src/gnome-utils/glade/dialog-object-references.glade	                        (rev 0)
+++ gnucash/trunk/src/gnome-utils/glade/dialog-object-references.glade	2010-03-15 14:49:39 UTC (rev 18910)
@@ -0,0 +1,73 @@
+<?xml version="1.0"?>
+<glade-interface>
+  <!-- interface-requires gtk+ 2.8 -->
+  <!-- interface-naming-policy project-wide -->
+  <widget class="GtkDialog" id="Object references">
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">Object references</property>
+    <property name="type_hint">normal</property>
+    <property name="has_separator">False</property>
+    <child internal-child="vbox">
+      <widget class="GtkVBox" id="dialog-vbox1">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child>
+          <widget class="GtkVBox" id="vbox1">
+            <property name="visible">True</property>
+            <property name="orientation">vertical</property>
+            <child>
+              <widget class="GtkLabel" id="lbl_explanation">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Explanation</property>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <widget class="GtkHBox" id="hbox_list">
+                <property name="visible">True</property>
+                <child>
+                  <placeholder/>
+                </child>
+              </widget>
+              <packing>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <widget class="GtkHButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="layout_style">end</property>
+            <child>
+              <widget class="GtkButton" id="button1">
+                <property name="label">gtk-ok</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </widget>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+          </widget>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </widget>
+    </child>
+  </widget>
+</glade-interface>



More information about the gnucash-changes mailing list