GnuCash 2.4.99
gnc-plugin-page-owner-tree.c
Go to the documentation of this file.
00001 /*
00002  * gnc-plugin-page-owner-tree.c --
00003  *
00004  * Copyright (C) 2011 Geert Janssens <geert@kobaltwit.be>
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License as
00008  * published by the Free Software Foundation; either version 2 of
00009  * the License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, contact:
00018  *
00019  * Free Software Foundation           Voice:  +1-617-542-5942
00020  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
00021  * Boston, MA  02110-1301,  USA       gnu@gnu.org
00022  */
00023 
00034 #include "config.h"
00035 
00036 #include <gtk/gtk.h>
00037 #include <glib/gi18n.h>
00038 #include "swig-runtime.h"
00039 
00040 #include "gnc-plugin.h"
00041 #include "gnc-plugin-page-owner-tree.h"
00042 #include "gnc-plugin-page-report.h"
00043 
00044 #include "dialog-vendor.h"
00045 #include "dialog-customer.h"
00046 #include "dialog-employee.h"
00047 #include "dialog-invoice.h"
00048 #include "dialog-job.h"
00049 
00050 #include "gncOwner.h"
00051 #include "dialog-utils.h"
00052 #include "gnc-component-manager.h"
00053 #include "gnc-engine.h"
00054 #include "gnc-gconf-utils.h"
00055 #include "gnc-gnome-utils.h"
00056 #include "gnc-gobject-utils.h"
00057 #include "gnc-icons.h"
00058 #include "gnc-session.h"
00059 #include "gnc-tree-view-owner.h"
00060 #include "gnc-ui.h"
00061 #include "gnc-ui-util.h"
00062 #include "guile-mappings.h"
00063 #include "dialog-lot-viewer.h"
00064 #include "dialog-object-references.h"
00065 
00066 /* This static indicates the debugging module that this .o belongs to.  */
00067 static QofLogModule log_module = GNC_MOD_GUI;
00068 
00069 #define PLUGIN_PAGE_ACCT_TREE_CM_CLASS "plugin-page-owner-tree"
00070 #define GCONF_SECTION "window/pages/owner_tree"
00071 
00072 #define DELETE_DIALOG_FILTER  "filter"
00073 #define DELETE_DIALOG_OWNER "owner"
00074 
00075 enum
00076 {
00077     OWNER_SELECTED,
00078     LAST_SIGNAL
00079 };
00080 
00081 typedef struct GncPluginPageOwnerTreePrivate
00082 {
00083     GtkWidget   *widget;
00084     GtkTreeView *tree_view;
00085     gint         component_id;
00086     GncOwnerType owner_type;
00087     const gchar *gconf_section;
00088     OwnerFilterDialog fd;
00089 } GncPluginPageOwnerTreePrivate;
00090 
00091 #define GNC_PLUGIN_PAGE_OWNER_TREE_GET_PRIVATE(o)  \
00092    (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_PLUGIN_PAGE_OWNER_TREE, GncPluginPageOwnerTreePrivate))
00093 
00094 static GObjectClass *parent_class = NULL;
00095 
00096 /************************************************************
00097  *                        Prototypes                        *
00098  ************************************************************/
00099 /* Plugin Actions */
00100 static void gnc_plugin_page_owner_tree_class_init (GncPluginPageOwnerTreeClass *klass);
00101 static void gnc_plugin_page_owner_tree_init (GncPluginPageOwnerTree *plugin_page);
00102 static void gnc_plugin_page_owner_tree_finalize (GObject *object);
00103 static void gnc_plugin_page_owner_tree_selected (GObject *object, gpointer user_data);
00104 
00105 static GtkWidget *gnc_plugin_page_owner_tree_create_widget (GncPluginPage *plugin_page);
00106 static void gnc_plugin_page_owner_tree_destroy_widget (GncPluginPage *plugin_page);
00107 static void gnc_plugin_page_owner_tree_save_page (GncPluginPage *plugin_page, GKeyFile *file, const gchar *group);
00108 static GncPluginPage *gnc_plugin_page_owner_tree_recreate_page (GtkWidget *window, GKeyFile *file, const gchar *group);
00109 
00110 /* Callbacks */
00111 static gboolean gnc_plugin_page_owner_tree_button_press_cb (GtkWidget *widget,
00112         GdkEventButton *event,
00113         GncPluginPage *page);
00114 static void gnc_plugin_page_owner_tree_double_click_cb (GtkTreeView        *treeview,
00115         GtkTreePath        *path,
00116         GtkTreeViewColumn  *col,
00117         GncPluginPageOwnerTree *page);
00118 
00119 static void gnc_plugin_page_owner_tree_selection_changed_cb (GtkTreeSelection *selection,
00120         GncPluginPageOwnerTree *page);
00121 
00122 /* Command callbacks */
00123 static void gnc_plugin_page_owner_tree_cmd_new_owner (GtkAction *action, GncPluginPageOwnerTree *page);
00124 static void gnc_plugin_page_owner_tree_cmd_edit_owner (GtkAction *action, GncPluginPageOwnerTree *page);
00125 static void gnc_plugin_page_owner_tree_cmd_delete_owner (GtkAction *action, GncPluginPageOwnerTree *page);
00126 static void gnc_plugin_page_owner_tree_cmd_view_filter_by (GtkAction *action, GncPluginPageOwnerTree *page);
00127 static void gnc_plugin_page_owner_tree_cmd_new_invoice (GtkAction *action, GncPluginPageOwnerTree *page);
00128 static void gnc_plugin_page_owner_tree_cmd_owners_report (GtkAction *action, GncPluginPageOwnerTree *plugin_page);
00129 static void gnc_plugin_page_owner_tree_cmd_owner_report (GtkAction *action, GncPluginPageOwnerTree *plugin_page);
00130 
00131 
00132 static guint plugin_page_signals[LAST_SIGNAL] = { 0 };
00133 
00134 
00135 static GtkActionEntry gnc_plugin_page_owner_tree_actions [] =
00136 {
00137     /* Toplevel */
00138     { "FakeToplevel", NULL, "", NULL, NULL, NULL },
00139 
00140     /* Edit menu */
00141     {
00142         "OTEditVendorAction", GNC_STOCK_EDIT_ACCOUNT, N_("E_dit Vendor"), "<control>e",
00143         N_("Edit the selected vendor"),
00144         G_CALLBACK (gnc_plugin_page_owner_tree_cmd_edit_owner)
00145     },
00146     {
00147         "OTEditCustomerAction", GNC_STOCK_EDIT_ACCOUNT, N_("E_dit Customer"), "<control>e",
00148         N_("Edit the selected customer"),
00149         G_CALLBACK (gnc_plugin_page_owner_tree_cmd_edit_owner)
00150     },
00151     {
00152         "OTEditEmployeeAction", GNC_STOCK_EDIT_ACCOUNT, N_("E_dit Employee"), "<control>e",
00153         N_("Edit the selected employee"),
00154         G_CALLBACK (gnc_plugin_page_owner_tree_cmd_edit_owner)
00155     },
00156     {
00157         "OTNewVendorAction", GNC_STOCK_NEW_ACCOUNT, N_("_New Vendor..."), NULL,
00158         N_("Create a new vendor"),
00159         G_CALLBACK (gnc_plugin_page_owner_tree_cmd_new_owner)
00160     },
00161     {
00162         "OTNewCustomerAction", GNC_STOCK_NEW_ACCOUNT, N_("_New Customer..."), NULL,
00163         N_("Create a new customer"),
00164         G_CALLBACK (gnc_plugin_page_owner_tree_cmd_new_owner)
00165     },
00166     {
00167         "OTNewEmployeeAction", GNC_STOCK_NEW_ACCOUNT, N_("_New Employee..."), NULL,
00168         N_("Create a new employee"),
00169         G_CALLBACK (gnc_plugin_page_owner_tree_cmd_new_owner)
00170     },
00171 
00172 /* FIXME disabled due to crash    {
00173         "EditDeleteOwnerAction", GNC_STOCK_DELETE_ACCOUNT, N_("_Delete Owner..."), "Delete",
00174         N_("Delete selected owner"),
00175         G_CALLBACK (gnc_plugin_page_owner_tree_cmd_delete_owner)
00176     }, */
00177 
00178     /* View menu */
00179     {
00180         "ViewFilterByAction", NULL, N_("_Filter By..."), NULL, NULL,
00181         G_CALLBACK (gnc_plugin_page_owner_tree_cmd_view_filter_by)
00182     },
00183 
00184     /* Business menu */
00185     {
00186         "OTNewBillAction", GNC_STOCK_INVOICE_NEW, N_("New _Bill..."), NULL,
00187         N_("Create a new bill"),
00188         G_CALLBACK (gnc_plugin_page_owner_tree_cmd_new_invoice)
00189     },
00190     {
00191         "OTNewInvoiceAction", GNC_STOCK_INVOICE_NEW, N_("New _Invoice..."), NULL,
00192         N_("Create a new invoice"),
00193         G_CALLBACK (gnc_plugin_page_owner_tree_cmd_new_invoice)
00194     },
00195     {
00196         "OTNewVoucherAction", GNC_STOCK_INVOICE_NEW, N_("New _Voucher..."), NULL,
00197         N_("Create a new voucher"),
00198         G_CALLBACK (gnc_plugin_page_owner_tree_cmd_new_invoice)
00199     },
00200     {
00201         "OTVendorListingReportAction", GTK_STOCK_PRINT_PREVIEW, N_("Vendor Listing"), NULL,
00202         N_("Show vendor aging overview for all vendors"),
00203         G_CALLBACK (gnc_plugin_page_owner_tree_cmd_owners_report)
00204     },
00205     {
00206         "OTCustomerListingReportAction", GTK_STOCK_PRINT_PREVIEW, N_("Customer Listing"), NULL,
00207         N_("Show customer aging overview for all customers"),
00208         G_CALLBACK (gnc_plugin_page_owner_tree_cmd_owners_report)
00209     },
00210     {
00211         "OTVendorReportAction", NULL, N_("Vendor Report"), NULL,
00212         N_("Show vendor report"),
00213         G_CALLBACK (gnc_plugin_page_owner_tree_cmd_owner_report)
00214     },
00215     {
00216         "OTCustomerReportAction", NULL, N_("Customer Report"), NULL,
00217         N_("Show customer report"),
00218         G_CALLBACK (gnc_plugin_page_owner_tree_cmd_owner_report)
00219     },
00220     {
00221         "OTEmployeeReportAction", NULL, N_("Employee Report"), NULL,
00222         N_("Show employee report"),
00223         G_CALLBACK (gnc_plugin_page_owner_tree_cmd_owner_report)
00224     },
00225 };
00227 static guint gnc_plugin_page_owner_tree_n_actions = G_N_ELEMENTS (gnc_plugin_page_owner_tree_actions);
00228 
00229 
00232 static const gchar *actions_requiring_owner_rw[] =
00233 {
00234     "OTEditVendorAction",
00235     "OTEditCustomerAction",
00236     "OTEditEmployeeAction",
00237 /* FIXME disabled due to crash    "EditDeleteOwnerAction", */
00238     NULL
00239 };
00240 
00243 static const gchar *actions_requiring_owner_always[] =
00244 {
00245     "OTVendorReportAction",
00246     "OTCustomerReportAction",
00247     "OTEmployeeReportAction",
00248     NULL
00249 };
00250 
00251 /* This is the list of actions which are switched inactive in a read-only book. */
00252 static const gchar* readonly_inactive_actions[] =
00253 {
00254     "OTNewVendorAction",
00255     "OTNewCustomerAction",
00256     "OTNewEmployeeAction",
00257     "OTNewBillAction",
00258     "OTNewInvoiceAction",
00259     "OTNewVoucherAction",
00260     NULL
00261 };
00262 
00263 
00265 static action_toolbar_labels toolbar_labels[] =
00266 {
00267     { "OTEditVendorAction",             N_("Edit") },
00268     { "OTEditCustomerAction",           N_("Edit") },
00269     { "OTEditEmployeeAction",           N_("Edit") },
00270     { "OTNewVendorAction",              N_("New") },
00271     { "OTNewCustomerAction",            N_("New") },
00272     { "OTNewEmployeeAction",            N_("New") },
00273     { "OTNewBillAction",                N_("New Bill") },
00274     { "OTNewInvoiceAction",             N_("New Invoice") },
00275     { "OTNewVoucherAction",             N_("New Voucher") },
00276     { "OTVendorListingReportAction",    N_("Vendor Listing") },
00277     { "OTCustomerListingReportAction",  N_("Customer Listing") },
00278 /* FIXME disable due to crash   { "EditDeleteOwnerAction",   N_("Delete") },*/
00279     { NULL, NULL },
00280 };
00281 
00285 typedef struct
00286 {
00288     const char *action_name;
00290     GncOwnerType owner_type;
00291 } action_owners_struct;
00292 
00293 static action_owners_struct action_owners[] =
00294 {
00295     { "OTEditVendorAction",            GNC_OWNER_VENDOR },
00296     { "OTEditCustomerAction",          GNC_OWNER_CUSTOMER },
00297     { "OTEditEmployeeAction",          GNC_OWNER_EMPLOYEE },
00298     { "OTNewVendorAction",             GNC_OWNER_VENDOR },
00299     { "OTNewCustomerAction",           GNC_OWNER_CUSTOMER },
00300     { "OTNewEmployeeAction",           GNC_OWNER_EMPLOYEE },
00301     { "OTNewBillAction",               GNC_OWNER_VENDOR },
00302     { "OTNewInvoiceAction",            GNC_OWNER_CUSTOMER },
00303     { "OTNewVoucherAction",            GNC_OWNER_EMPLOYEE },
00304     { "OTVendorListingReportAction",   GNC_OWNER_VENDOR },
00305     { "OTCustomerListingReportAction", GNC_OWNER_CUSTOMER },
00306     { "OTVendorReportAction",          GNC_OWNER_VENDOR },
00307     { "OTCustomerReportAction",        GNC_OWNER_CUSTOMER },
00308     { "OTEmployeeReportAction",        GNC_OWNER_EMPLOYEE },
00309     { NULL, GNC_OWNER_NONE },
00310 };
00311 
00312 GType
00313 gnc_plugin_page_owner_tree_get_type (void)
00314 {
00315     static GType gnc_plugin_page_owner_tree_type = 0;
00316 
00317     if (gnc_plugin_page_owner_tree_type == 0)
00318     {
00319         static const GTypeInfo our_info =
00320         {
00321             sizeof (GncPluginPageOwnerTreeClass),
00322             NULL,
00323             NULL,
00324             (GClassInitFunc) gnc_plugin_page_owner_tree_class_init,
00325             NULL,
00326             NULL,
00327             sizeof (GncPluginPageOwnerTree),
00328             0,
00329             (GInstanceInitFunc) gnc_plugin_page_owner_tree_init
00330         };
00331 
00332         gnc_plugin_page_owner_tree_type = g_type_register_static (GNC_TYPE_PLUGIN_PAGE,
00333                                           GNC_PLUGIN_PAGE_OWNER_TREE_NAME,
00334                                           &our_info, 0);
00335     }
00336 
00337     return gnc_plugin_page_owner_tree_type;
00338 }
00339 
00340 GncPluginPage *
00341 gnc_plugin_page_owner_tree_new (GncOwnerType owner_type)
00342 {
00343     GncPluginPageOwnerTree *plugin_page;
00344 
00345     GncPluginPageOwnerTreePrivate *priv;
00346     gchar* label = "";
00347     const GList *item;
00348 
00349     GtkActionGroup *action_group;
00350     GtkAction    *action;
00351     GValue        gvalue = { 0 };
00352     gint          i;
00353 
00354     g_return_val_if_fail( (owner_type != GNC_OWNER_UNDEFINED)
00355                           && (owner_type != GNC_OWNER_NONE), NULL);
00356     ENTER(" ");
00357 
00358     /* Is there an existing page? */
00359     item = gnc_gobject_tracking_get_list(GNC_PLUGIN_PAGE_OWNER_TREE_NAME);
00360     for ( ; item; item = g_list_next(item))
00361     {
00362         plugin_page = (GncPluginPageOwnerTree *)item->data;
00363         priv = GNC_PLUGIN_PAGE_OWNER_TREE_GET_PRIVATE(plugin_page);
00364         if (priv->owner_type == owner_type)
00365         {
00366             LEAVE("existing %s tree page %p", gncOwnerTypeToQofIdType(owner_type), plugin_page);
00367             return GNC_PLUGIN_PAGE(plugin_page);
00368         }
00369     }
00370 
00371     plugin_page = g_object_new(GNC_TYPE_PLUGIN_PAGE_OWNER_TREE, NULL);
00372 
00373     priv = GNC_PLUGIN_PAGE_OWNER_TREE_GET_PRIVATE(plugin_page);
00374     priv->owner_type = owner_type;
00375 
00376     switch (owner_type)
00377     {
00378     case GNC_OWNER_NONE :
00379     case GNC_OWNER_UNDEFINED :
00380         break;
00381     case GNC_OWNER_CUSTOMER :
00382     {
00383         label = N_("Customers");
00384         priv->gconf_section = g_strdup("window/pages/customer_tree");
00385         break;
00386     }
00387     case GNC_OWNER_JOB :
00388     {
00389         label = N_("Jobs");
00390         priv->gconf_section = g_strdup("window/pages/job_tree");
00391         break;
00392     }
00393     case GNC_OWNER_VENDOR :
00394     {
00395         label = N_("Vendors");
00396         priv->gconf_section = g_strdup("window/pages/vendor_tree");
00397         break;
00398     }
00399     case GNC_OWNER_EMPLOYEE :
00400     {
00401         label = N_("Employees");
00402         priv->gconf_section = g_strdup("window/pages/employee_tree");
00403         break;
00404     }
00405     }
00406 
00407     /* Hide menu and toolbar items that are not relevant for the active owner list */
00408     action_group = gnc_plugin_page_get_action_group(GNC_PLUGIN_PAGE(plugin_page));
00409     g_value_init (&gvalue, G_TYPE_BOOLEAN);
00410     for (i = 0; action_owners[i].action_name; i++)
00411     {
00412         action = gtk_action_group_get_action (action_group, action_owners[i].action_name);
00413         g_value_set_boolean (&gvalue, (priv->owner_type == action_owners[i].owner_type) );
00414         g_object_set_property (G_OBJECT(action), "visible", &gvalue);
00415     }
00416 
00417 
00418     g_object_set(G_OBJECT(plugin_page), "page-name", label, NULL);
00419 
00420     LEAVE("new %s tree page %p", gncOwnerTypeToQofIdType(owner_type), plugin_page);
00421     return GNC_PLUGIN_PAGE(plugin_page);
00422 }
00423 
00424 static void
00425 gnc_plugin_page_owner_tree_class_init (GncPluginPageOwnerTreeClass *klass)
00426 {
00427     GObjectClass *object_class = G_OBJECT_CLASS (klass);
00428     GncPluginPageClass *gnc_plugin_class = GNC_PLUGIN_PAGE_CLASS(klass);
00429 
00430     parent_class = g_type_class_peek_parent (klass);
00431 
00432     object_class->finalize = gnc_plugin_page_owner_tree_finalize;
00433 
00434     gnc_plugin_class->tab_icon        = GNC_STOCK_ACCOUNT;
00435     gnc_plugin_class->plugin_name     = GNC_PLUGIN_PAGE_OWNER_TREE_NAME;
00436     gnc_plugin_class->create_widget   = gnc_plugin_page_owner_tree_create_widget;
00437     gnc_plugin_class->destroy_widget  = gnc_plugin_page_owner_tree_destroy_widget;
00438     gnc_plugin_class->save_page       = gnc_plugin_page_owner_tree_save_page;
00439     gnc_plugin_class->recreate_page   = gnc_plugin_page_owner_tree_recreate_page;
00440 
00441     g_type_class_add_private(klass, sizeof(GncPluginPageOwnerTreePrivate));
00442 
00443     plugin_page_signals[OWNER_SELECTED] =
00444         g_signal_new ("owner_selected",
00445                       G_OBJECT_CLASS_TYPE (object_class),
00446                       G_SIGNAL_RUN_FIRST,
00447                       G_STRUCT_OFFSET (GncPluginPageOwnerTreeClass, owner_selected),
00448                       NULL, NULL,
00449                       g_cclosure_marshal_VOID__POINTER,
00450                       G_TYPE_NONE, 1,
00451                       G_TYPE_POINTER);
00452 }
00453 
00454 static void
00455 gnc_plugin_page_owner_tree_init (GncPluginPageOwnerTree *plugin_page)
00456 {
00457     GtkActionGroup *action_group;
00458     GncPluginPageOwnerTreePrivate *priv;
00459     GncPluginPage *parent;
00460 
00461     ENTER("page %p", plugin_page);
00462     priv = GNC_PLUGIN_PAGE_OWNER_TREE_GET_PRIVATE(plugin_page);
00463 
00464     /* Init parent declared variables */
00465     parent = GNC_PLUGIN_PAGE(plugin_page);
00466     g_object_set(G_OBJECT(plugin_page),
00467                  "page-name",      _("Owners"),
00468                  "page-uri",       "default:",
00469                  "ui-description", "gnc-plugin-page-owner-tree-ui.xml",
00470                  NULL);
00471     g_signal_connect (G_OBJECT (plugin_page), "selected",
00472                       G_CALLBACK (gnc_plugin_page_owner_tree_selected), plugin_page);
00473 
00474     /* change me when the system supports multiple books */
00475     gnc_plugin_page_add_book(parent, gnc_get_current_book());
00476 
00477     /* Create menu and toolbar information */
00478     action_group =
00479         gnc_plugin_page_create_action_group(parent,
00480                                             "GncPluginPageOwnerTreeActions");
00481     gtk_action_group_add_actions(action_group,
00482                                  gnc_plugin_page_owner_tree_actions,
00483                                  gnc_plugin_page_owner_tree_n_actions,
00484                                  plugin_page);
00485     gnc_plugin_init_short_names (action_group, toolbar_labels);
00486 
00487 
00488     /* Init filter */
00489     priv->fd.show_inactive = TRUE;
00490     priv->fd.show_zero_total = TRUE;
00491 
00492     LEAVE("page %p, priv %p, action group %p",
00493           plugin_page, priv, action_group);
00494 }
00495 
00496 static void
00497 gnc_plugin_page_owner_tree_finalize (GObject *object)
00498 {
00499     GncPluginPageOwnerTree *page;
00500     GncPluginPageOwnerTreePrivate *priv;
00501 
00502     ENTER("object %p", object);
00503     page = GNC_PLUGIN_PAGE_OWNER_TREE (object);
00504     g_return_if_fail (GNC_IS_PLUGIN_PAGE_OWNER_TREE (page));
00505     priv = GNC_PLUGIN_PAGE_OWNER_TREE_GET_PRIVATE(page);
00506     g_return_if_fail (priv != NULL);
00507 
00508     G_OBJECT_CLASS (parent_class)->finalize (object);
00509     LEAVE(" ");
00510 }
00511 
00512 static void update_inactive_actions(GncPluginPage *plugin_page)
00513 {
00514     GtkActionGroup *action_group;
00515     gboolean is_sensitive = !qof_book_is_readonly(gnc_get_current_book());
00516 
00517     // We are readonly - so we have to switch particular actions to inactive.
00518     g_return_if_fail(plugin_page);
00519     g_return_if_fail(GNC_IS_PLUGIN_PAGE(plugin_page));
00520 
00521     /* Get the action group */
00522     action_group = gnc_plugin_page_get_action_group(plugin_page);
00523     g_return_if_fail(GTK_IS_ACTION_GROUP (action_group));
00524 
00525     /* Set the action's sensitivity */
00526     gnc_plugin_update_actions (action_group, readonly_inactive_actions,
00527                                "sensitive", is_sensitive);
00528 }
00529 
00530 static void
00531 gnc_plugin_page_owner_tree_selected (GObject *object, gpointer user_data)
00532 {
00533     GncPluginPage *page = GNC_PLUGIN_PAGE (object);
00534     g_return_if_fail (GNC_IS_PLUGIN_PAGE (page));
00535     update_inactive_actions(page);
00536 }
00537 
00538 
00539 GncOwner *
00540 gnc_plugin_page_owner_tree_get_current_owner (GncPluginPageOwnerTree *page)
00541 {
00542     GncPluginPageOwnerTreePrivate *priv;
00543     GncOwner *owner;
00544 
00545     priv = GNC_PLUGIN_PAGE_OWNER_TREE_GET_PRIVATE(page);
00546     ENTER("page %p (tree view %p)", page, priv->tree_view);
00547     owner = gnc_tree_view_owner_get_selected_owner (GNC_TREE_VIEW_OWNER(priv->tree_view));
00548     if (owner == NULL)
00549     {
00550         LEAVE("no owner");
00551         return NULL;
00552     }
00553 
00554     LEAVE("owner %p", owner);
00555     return owner;
00556 }
00557 
00558 
00559 /* Virtual Functions */
00560 
00561 static void
00562 gnc_plugin_page_owner_refresh_cb (GHashTable *changes, gpointer user_data)
00563 {
00564     GncPluginPageOwnerTree *page = user_data;
00565     GncPluginPageOwnerTreePrivate *priv;
00566 
00567     g_return_if_fail(GNC_IS_PLUGIN_PAGE_OWNER_TREE(page));
00568 
00569     /* We're only looking for forced updates here. */
00570     if (changes)
00571         return;
00572 
00573     priv = GNC_PLUGIN_PAGE_OWNER_TREE_GET_PRIVATE(page);
00574     gtk_widget_queue_draw(priv->widget);
00575 }
00576 
00577 static void
00578 gnc_plugin_page_owner_tree_close_cb (gpointer user_data)
00579 {
00580     GncPluginPage *plugin_page;
00581     GncPluginPageOwnerTree *page;
00582 
00583     plugin_page = GNC_PLUGIN_PAGE(user_data);
00584     page = GNC_PLUGIN_PAGE_OWNER_TREE (plugin_page);
00585     gnc_main_window_close_page(plugin_page);
00586 }
00587 
00588 static GtkWidget *
00589 gnc_plugin_page_owner_tree_create_widget (GncPluginPage *plugin_page)
00590 {
00591     GncPluginPageOwnerTree *page;
00592     GncPluginPageOwnerTreePrivate *priv;
00593     GtkTreeSelection *selection;
00594     GtkTreeView *tree_view;
00595     GtkWidget *scrolled_window;
00596     GtkTreeViewColumn *col;
00597 
00598     ENTER("page %p", plugin_page);
00599     page = GNC_PLUGIN_PAGE_OWNER_TREE (plugin_page);
00600     priv = GNC_PLUGIN_PAGE_OWNER_TREE_GET_PRIVATE(page);
00601     if (priv->widget != NULL)
00602     {
00603         LEAVE("widget = %p", priv->widget);
00604         return priv->widget;
00605     }
00606 
00607     priv->widget = gtk_vbox_new (FALSE, 0);
00608     gtk_widget_show (priv->widget);
00609 
00610     scrolled_window = gtk_scrolled_window_new (NULL, NULL);
00611     gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
00612                                     GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
00613     gtk_widget_show (scrolled_window);
00614     gtk_box_pack_start (GTK_BOX (priv->widget), scrolled_window,
00615                         TRUE, TRUE, 0);
00616 
00617     tree_view = gnc_tree_view_owner_new(priv->owner_type);
00618 
00619     /* Show default columns */
00620     col = gnc_tree_view_find_column_by_name(
00621               GNC_TREE_VIEW(tree_view), GNC_OWNER_TREE_ID_COL);
00622     g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
00623     col = gnc_tree_view_find_column_by_name(
00624               GNC_TREE_VIEW(tree_view), GNC_OWNER_TREE_ADDRESS_1_COL);
00625     g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
00626     col = gnc_tree_view_find_column_by_name(
00627               GNC_TREE_VIEW(tree_view), GNC_OWNER_TREE_ADDRESS_2_COL);
00628     g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
00629     col = gnc_tree_view_find_column_by_name(
00630               GNC_TREE_VIEW(tree_view), GNC_OWNER_TREE_PHONE_COL);
00631     g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
00632     gnc_tree_view_configure_columns(GNC_TREE_VIEW(tree_view));
00633 
00634     g_object_set(G_OBJECT(tree_view),
00635                  "gconf-section", priv->gconf_section,
00636                  "show-column-menu", TRUE,
00637                  NULL);
00638 
00639     priv->tree_view = tree_view;
00640     selection = gtk_tree_view_get_selection(tree_view);
00641     g_signal_connect (G_OBJECT (selection), "changed",
00642                       G_CALLBACK (gnc_plugin_page_owner_tree_selection_changed_cb), page);
00643     g_signal_connect (G_OBJECT (tree_view), "button-press-event",
00644                       G_CALLBACK (gnc_plugin_page_owner_tree_button_press_cb), page);
00645     g_signal_connect (G_OBJECT (tree_view), "row-activated",
00646                       G_CALLBACK (gnc_plugin_page_owner_tree_double_click_cb), page);
00647 
00648     gtk_tree_view_set_headers_visible(tree_view, TRUE);
00649     gnc_plugin_page_owner_tree_selection_changed_cb (NULL, page);
00650     gtk_widget_show (GTK_WIDGET (tree_view));
00651     gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET(tree_view));
00652 
00653     priv->fd.tree_view = GNC_TREE_VIEW_OWNER(priv->tree_view);
00654     gnc_tree_view_owner_set_filter (
00655         GNC_TREE_VIEW_OWNER(tree_view),
00656         gnc_plugin_page_owner_tree_filter_owners, &priv->fd, NULL);
00657 
00658     priv->component_id =
00659         gnc_register_gui_component(PLUGIN_PAGE_ACCT_TREE_CM_CLASS,
00660                                    gnc_plugin_page_owner_refresh_cb,
00661                                    gnc_plugin_page_owner_tree_close_cb,
00662                                    page);
00663     gnc_gui_component_set_session (priv->component_id,
00664                                    gnc_get_current_session());
00665 
00666     LEAVE("widget = %p", priv->widget);
00667     return priv->widget;
00668 }
00669 
00670 static void
00671 gnc_plugin_page_owner_tree_destroy_widget (GncPluginPage *plugin_page)
00672 {
00673     GncPluginPageOwnerTree *page;
00674     GncPluginPageOwnerTreePrivate *priv;
00675 
00676     ENTER("page %p", plugin_page);
00677     page = GNC_PLUGIN_PAGE_OWNER_TREE (plugin_page);
00678     priv = GNC_PLUGIN_PAGE_OWNER_TREE_GET_PRIVATE(page);
00679 
00680     if (priv->widget)
00681     {
00682         g_object_unref(G_OBJECT(priv->widget));
00683         priv->widget = NULL;
00684     }
00685 
00686     if (priv->component_id)
00687     {
00688         gnc_unregister_gui_component(priv->component_id);
00689         priv->component_id = 0;
00690     }
00691 
00692     LEAVE("widget destroyed");
00693 }
00694 
00695 #define OWNER_TYPE_LABEL     "OwnerType"
00696 
00706 static void
00707 gnc_plugin_page_owner_tree_save_page (GncPluginPage *plugin_page,
00708                                       GKeyFile *key_file,
00709                                       const gchar *group_name)
00710 {
00711     GncPluginPageOwnerTree *owner_page;
00712     GncPluginPageOwnerTreePrivate *priv;
00713 
00714     g_return_if_fail (GNC_IS_PLUGIN_PAGE_OWNER_TREE(plugin_page));
00715     g_return_if_fail (key_file != NULL);
00716     g_return_if_fail (group_name != NULL);
00717 
00718     ENTER("page %p, key_file %p, group_name %s", plugin_page, key_file,
00719           group_name);
00720 
00721     owner_page = GNC_PLUGIN_PAGE_OWNER_TREE(plugin_page);
00722     priv = GNC_PLUGIN_PAGE_OWNER_TREE_GET_PRIVATE(owner_page);
00723 
00724     g_key_file_set_integer(key_file, group_name, OWNER_TYPE_LABEL,
00725                            priv->owner_type);
00726 
00727     gnc_tree_view_owner_save(GNC_TREE_VIEW_OWNER(priv->tree_view),
00728                              &priv->fd, key_file, group_name);
00729     LEAVE(" ");
00730 }
00731 
00732 
00733 
00743 static GncPluginPage *
00744 gnc_plugin_page_owner_tree_recreate_page (GtkWidget *window,
00745         GKeyFile *key_file,
00746         const gchar *group_name)
00747 {
00748     GncPluginPageOwnerTree *owner_page;
00749     GncPluginPageOwnerTreePrivate *priv;
00750     GncPluginPage *page;
00751     GncOwnerType owner_type;
00752 
00753     g_return_val_if_fail(key_file, NULL);
00754     g_return_val_if_fail(group_name, NULL);
00755     ENTER("key_file %p, group_name %s", key_file, group_name);
00756 
00757     /* Create the new page. */
00758     owner_type = g_key_file_get_integer(key_file, group_name, OWNER_TYPE_LABEL, NULL);
00759     page = gnc_plugin_page_owner_tree_new(owner_type);
00760     owner_page = GNC_PLUGIN_PAGE_OWNER_TREE(page);
00761     priv = GNC_PLUGIN_PAGE_OWNER_TREE_GET_PRIVATE(owner_page);
00762 
00763     /* Install it now so we can then manipulate the created widget */
00764     gnc_main_window_open_page(GNC_MAIN_WINDOW(window), page);
00765 
00766     gnc_tree_view_owner_restore(GNC_TREE_VIEW_OWNER(priv->tree_view),
00767                                 &priv->fd, key_file, group_name, owner_type);
00768     LEAVE(" ");
00769     return page;
00770 }
00771 
00772 /* Wrapper function to open the proper edit dialog, depending on the owner type */
00773 static void gnc_ui_owner_edit (GncOwner *owner)
00774 {
00775     if (NULL == owner) return;
00776 
00777     switch (owner->type)
00778     {
00779     case GNC_OWNER_NONE :
00780     case GNC_OWNER_UNDEFINED :
00781         break;
00782     case GNC_OWNER_CUSTOMER :
00783     {
00784         gnc_ui_customer_edit (owner->owner.customer);
00785         break;
00786     }
00787     case GNC_OWNER_JOB :
00788     {
00789         gnc_ui_job_edit (owner->owner.job);
00790         break;
00791     }
00792     case GNC_OWNER_VENDOR :
00793     {
00794         gnc_ui_vendor_edit (owner->owner.vendor);
00795         break;
00796     }
00797     case GNC_OWNER_EMPLOYEE :
00798     {
00799         gnc_ui_employee_edit (owner->owner.employee);
00800         break;
00801     }
00802     }
00803 }
00804 
00805 
00806 /* Callbacks */
00807 
00815 static gboolean
00816 gnc_plugin_page_owner_tree_button_press_cb (GtkWidget *widget,
00817         GdkEventButton *event,
00818         GncPluginPage *page)
00819 {
00820     gboolean result;
00821 
00822     g_return_val_if_fail(GNC_IS_PLUGIN_PAGE(page), FALSE);
00823 
00824     ENTER("widget %p, event %p, page %p", widget, event, page);
00825     result = gnc_main_window_button_press_cb(widget, event, page);
00826     LEAVE(" ");
00827 
00828     /* Always return FALSE.  This will let the tree view callback run as
00829      * well which will select the item under the cursor.  By the time
00830      * the user sees the menu both callbacks will have run and the menu
00831      * actions will operate on the just-selected owner. */
00832     return FALSE;
00833 }
00834 
00835 static void
00836 gnc_plugin_page_owner_tree_double_click_cb (GtkTreeView        *treeview,
00837         GtkTreePath        *path,
00838         GtkTreeViewColumn  *col,
00839         GncPluginPageOwnerTree *page)
00840 {
00841     GncOwner *owner;
00842 
00843     g_return_if_fail (GNC_IS_PLUGIN_PAGE_OWNER_TREE (page));
00844     owner = gnc_tree_view_owner_get_owner_from_path (GNC_TREE_VIEW_OWNER(treeview), path);
00845     gnc_ui_owner_edit (owner);
00846 }
00847 
00848 static void
00849 gnc_plugin_page_owner_tree_selection_changed_cb (GtkTreeSelection *selection,
00850         GncPluginPageOwnerTree *page)
00851 {
00852     GtkActionGroup *action_group;
00853     GtkAction *action;
00854     GtkTreeView *view;
00855     GncOwner *owner = NULL;
00856     gboolean sensitive;
00857     gboolean is_readwrite = !qof_book_is_readonly(gnc_get_current_book());
00858 
00859     g_return_if_fail(GNC_IS_PLUGIN_PAGE_OWNER_TREE(page));
00860 
00861     if (!selection)
00862     {
00863         sensitive = FALSE;
00864     }
00865     else
00866     {
00867         g_return_if_fail(GTK_IS_TREE_SELECTION(selection));
00868         view = gtk_tree_selection_get_tree_view (selection);
00869         owner = gnc_tree_view_owner_get_selected_owner (GNC_TREE_VIEW_OWNER(view));
00870         sensitive = (owner != NULL);
00871     }
00872 
00873     action_group = gnc_plugin_page_get_action_group(GNC_PLUGIN_PAGE(page));
00874     gnc_plugin_update_actions (action_group, actions_requiring_owner_always,
00875                                "sensitive", sensitive);
00876     gnc_plugin_update_actions (action_group, actions_requiring_owner_rw,
00877                                "sensitive", sensitive && is_readwrite);
00878     g_signal_emit (page, plugin_page_signals[OWNER_SELECTED], 0, owner);
00879 }
00880 
00881 /******************************************************************/
00882 /*                     Report helper functions                    */
00883 /******************************************************************/
00884 
00885 static int
00886 build_aging_report (GncOwnerType owner_type)
00887 {
00888     Account *account;
00889     gchar *report_name = NULL;
00890     gchar *report_title = NULL;
00891     swig_type_info * qtype;
00892     SCM args;
00893     SCM func;
00894     SCM arg;
00895 
00896     args = SCM_EOL;
00897 
00898     switch (owner_type)
00899     {
00900     case GNC_OWNER_NONE :
00901     case GNC_OWNER_UNDEFINED :
00902     case GNC_OWNER_EMPLOYEE :
00903     case GNC_OWNER_JOB :
00904     {
00905         return -1;
00906     }
00907     case GNC_OWNER_VENDOR :
00908     {
00909         report_name  = "gnc:payables-report-create";
00910         report_title = _("Vendor Listing");
00911         break;
00912     }
00913     case GNC_OWNER_CUSTOMER :
00914     {
00915         report_name = "gnc:receivables-report-create";
00916         report_title = _("Customer Listing");
00917         break;
00918     }
00919     }
00920 
00921     /* Find report generator function in guile */
00922     func = scm_c_eval_string (report_name);
00923     g_return_val_if_fail (scm_is_procedure (func), -1);
00924 
00925     /* Option Show zero's ? - Yes for the listing report */
00926     arg = SCM_BOOL_T;
00927     args = scm_cons (arg, args);
00928     g_return_val_if_fail (arg != SCM_UNDEFINED, -1);
00929 
00930     /* Option Report title */
00931     arg = scm_makfrom0str (report_title);
00932     args = scm_cons (arg, args);
00933 
00934     /* Option Account - Using False to select default account
00935      *
00936      * XXX I'm not sure if it would make sense to use another
00937      *     account than default */
00938     arg = SCM_BOOL_F;
00939     args = scm_cons (arg, args);
00940     g_return_val_if_fail (arg != SCM_UNDEFINED, -1);
00941 
00942 
00943     /* Apply the function to the args */
00944     arg = scm_apply (func, args, SCM_EOL);
00945     g_return_val_if_fail (scm_is_exact (arg), -1);
00946 
00947     return scm_num2int (arg, SCM_ARG1, G_STRFUNC);
00948 }
00949 
00950 static int build_owner_report (GncOwner *owner, Account *acc)
00951 {
00952     int id;
00953     SCM args;
00954     SCM func;
00955     SCM arg;
00956 
00957     g_return_val_if_fail (owner, -1);
00958 
00959     args = SCM_EOL;
00960 
00961     func = scm_c_eval_string ("gnc:owner-report-create");
00962     g_return_val_if_fail (scm_is_procedure (func), -1);
00963 
00964     if (acc)
00965     {
00966         swig_type_info * qtype = SWIG_TypeQuery("_p_Account");
00967         g_return_val_if_fail (qtype, -1);
00968 
00969         arg = SWIG_NewPointerObj(acc, qtype, 0);
00970         g_return_val_if_fail (arg != SCM_UNDEFINED, -1);
00971         args = scm_cons (arg, args);
00972     }
00973     else
00974     {
00975         args = scm_cons (SCM_BOOL_F, args);
00976     }
00977 
00978     arg = SWIG_NewPointerObj(owner, SWIG_TypeQuery("_p__gncOwner"), 0);
00979     g_return_val_if_fail (arg != SCM_UNDEFINED, -1);
00980     args = scm_cons (arg, args);
00981 
00982     /* Apply the function to the args */
00983     arg = scm_apply (func, args, SCM_EOL);
00984     g_return_val_if_fail (scm_is_exact (arg), -1);
00985     return scm_num2int (arg, SCM_ARG1, G_STRFUNC);
00986 }
00987 
00988 
00989 /************************************************************/
00990 /*                     Command callbacks                    */
00991 /************************************************************/
00992 
00993 static void
00994 gnc_plugin_page_owner_tree_cmd_new_owner (GtkAction *action, GncPluginPageOwnerTree *page)
00995 {
00996     GncPluginPageOwnerTreePrivate *priv;
00997 
00998     g_return_if_fail(GNC_IS_PLUGIN_PAGE_OWNER_TREE(page));
00999 
01000     priv = GNC_PLUGIN_PAGE_OWNER_TREE_GET_PRIVATE (page);
01001 
01002     switch (priv->owner_type)
01003     {
01004     case GNC_OWNER_NONE :
01005     case GNC_OWNER_UNDEFINED :
01006         break;
01007     case GNC_OWNER_CUSTOMER :
01008     {
01009         gnc_ui_customer_new (gnc_get_current_book ());
01010         break;
01011     }
01012     case GNC_OWNER_JOB :
01013     {
01014         /* XXX currently not properly implemented, so disabled for now
01015         gnc_ui_job_new (owner, gnc_get_current_book ()); */
01016         break;
01017     }
01018     case GNC_OWNER_VENDOR :
01019     {
01020         gnc_ui_vendor_new (gnc_get_current_book ());
01021         break;
01022     }
01023     case GNC_OWNER_EMPLOYEE :
01024     {
01025         gnc_ui_employee_new (gnc_get_current_book ());
01026         break;
01027     }
01028     }
01029 }
01030 
01031 static void
01032 gnc_plugin_page_owner_tree_cmd_edit_owner (GtkAction *action, GncPluginPageOwnerTree *page)
01033 {
01034     GncOwner *owner = gnc_plugin_page_owner_tree_get_current_owner (page);
01035     if (NULL == owner) return;
01036 
01037     ENTER("action %p, page %p", action, page);
01038 
01039     gnc_ui_owner_edit (owner);
01040 
01041     LEAVE(" ");
01042 }
01043 
01044 static void
01045 gnc_plugin_page_owner_tree_cmd_delete_owner (GtkAction *action, GncPluginPageOwnerTree *page)
01046 {
01047     GncOwner *owner = gnc_plugin_page_owner_tree_get_current_owner (page);
01048     gchar *owner_name;
01049     GtkWidget *widget;
01050     GtkWidget *window;
01051     GtkWidget *dialog = NULL;
01052     gint response;
01053     GList* list;
01054 
01055     if (NULL == owner) return;
01056 
01057     /* If the owner has objects referring to it, show the list - the owner can't be deleted until these
01058        references are dealt with. */
01059     list = qof_instance_get_referring_object_list(QOF_INSTANCE(gncOwnerGetUndefined(owner)));
01060     if (list != NULL)
01061     {
01062 #define EXPLANATION "The list below shows objects which make use of the owner 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 owner"
01063 
01064         gnc_ui_object_references_show( _(EXPLANATION), list);
01065         g_list_free(list);
01066         return;
01067     }
01068 
01069     window = gnc_plugin_page_get_window(GNC_PLUGIN_PAGE(page));
01070     owner_name = g_strdup (gncOwnerGetName(owner));
01071     if (!owner_name)
01072     {
01073         owner_name = g_strdup (_("(no name)"));
01074     }
01075 
01076     /*
01077      * Present a message to the user which specifies what will be
01078      * deleted, then ask for verification.
01079      */
01080     {
01081         char *message = g_strdup_printf(_("The owner %s will be deleted.\nAre you sure you want to do this?"), owner_name);
01082 
01083         dialog =  gtk_message_dialog_new(GTK_WINDOW(window),
01084                                          GTK_DIALOG_DESTROY_WITH_PARENT,
01085                                          GTK_MESSAGE_QUESTION,
01086                                          GTK_BUTTONS_NONE,
01087                                          "%s", message);
01088         g_free(message);
01089         gtk_dialog_add_buttons(GTK_DIALOG(dialog),
01090                                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
01091                                GTK_STOCK_DELETE, GTK_RESPONSE_ACCEPT,
01092                                (gchar *)NULL);
01093         gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL);
01094         response = gtk_dialog_run(GTK_DIALOG(dialog));
01095         gtk_widget_destroy(dialog);
01096 
01097         if (GTK_RESPONSE_ACCEPT == response)
01098         {
01099             /* FIXME The code below results in a crash.
01100              *       The corresponding menu item/toolbar button is disabled until this is fixed. */
01101             gnc_set_busy_cursor(NULL, TRUE);
01102             gnc_suspend_gui_refresh ();
01103             gncOwnerBeginEdit (owner);
01104             gncOwnerDestroy (owner);
01105             gnc_resume_gui_refresh ();
01106             gnc_unset_busy_cursor(NULL);
01107         }
01108     }
01109     g_free(owner_name);
01110 }
01111 
01112 /*********************/
01113 
01114 static void
01115 gnc_plugin_page_owner_tree_cmd_view_filter_by (GtkAction *action,
01116         GncPluginPageOwnerTree *page)
01117 {
01118     GncPluginPageOwnerTreePrivate *priv;
01119 
01120     g_return_if_fail(GNC_IS_PLUGIN_PAGE_OWNER_TREE(page));
01121     ENTER("(action %p, page %p)", action, page);
01122 
01123     priv = GNC_PLUGIN_PAGE_OWNER_TREE_GET_PRIVATE(page);
01124     owner_filter_dialog_create(&priv->fd, GNC_PLUGIN_PAGE(page));
01125     LEAVE(" ");
01126 }
01127 
01128 
01129 static void
01130 gnc_plugin_page_owner_tree_cmd_new_invoice (GtkAction *action,
01131         GncPluginPageOwnerTree *page)
01132 {
01133     GncPluginPageOwnerTreePrivate *priv;
01134     GncOwner current_owner;
01135 
01136     ENTER("action %p, page %p", action, page);
01137 
01138     priv = GNC_PLUGIN_PAGE_OWNER_TREE_GET_PRIVATE(page);
01139     switch (priv->owner_type)
01140     {
01141     case GNC_OWNER_NONE :
01142     case GNC_OWNER_UNDEFINED :
01143         gncOwnerInitUndefined(&current_owner, NULL);
01144         break;
01145     case GNC_OWNER_CUSTOMER :
01146     {
01147         gncOwnerInitCustomer(&current_owner,
01148                              gncOwnerGetCustomer(gnc_plugin_page_owner_tree_get_current_owner (page)) );
01149         break;
01150     }
01151     case GNC_OWNER_JOB :
01152     {
01153         gncOwnerInitJob(&current_owner,
01154                         gncOwnerGetJob(gnc_plugin_page_owner_tree_get_current_owner (page)) );
01155         break;
01156     }
01157     case GNC_OWNER_VENDOR :
01158     {
01159         gncOwnerInitVendor(&current_owner,
01160                            gncOwnerGetVendor(gnc_plugin_page_owner_tree_get_current_owner (page)) );
01161         break;
01162     }
01163     case GNC_OWNER_EMPLOYEE :
01164     {
01165         gncOwnerInitEmployee(&current_owner,
01166                              gncOwnerGetEmployee(gnc_plugin_page_owner_tree_get_current_owner (page)) );
01167         break;
01168     }
01169     }
01170 
01171     if (gncOwnerGetType(&current_owner) != GNC_OWNER_UNDEFINED)
01172         gnc_ui_invoice_new (&current_owner, gnc_get_current_book());
01173 
01174     LEAVE(" ");
01175 }
01176 
01177 static void
01178 gnc_plugin_page_owner_tree_cmd_owners_report (GtkAction *action,
01179         GncPluginPageOwnerTree *plugin_page)
01180 {
01181     GncPluginPageOwnerTreePrivate *priv;
01182     int id;
01183 
01184     ENTER("(action %p, plugin_page %p)", action, plugin_page);
01185 
01186     g_return_if_fail(GNC_IS_PLUGIN_PAGE_OWNER_TREE(plugin_page));
01187 
01188     priv = GNC_PLUGIN_PAGE_OWNER_TREE_GET_PRIVATE(plugin_page);
01189     id = build_aging_report (priv->owner_type);
01190     if (id >= 0)
01191     {
01192         GncMainWindow *window;
01193         window = GNC_MAIN_WINDOW(GNC_PLUGIN_PAGE(plugin_page)->window);
01194         gnc_main_window_open_report(id, window);
01195     }
01196 
01197     LEAVE(" ");
01198 }
01199 
01200 static void
01201 gnc_plugin_page_owner_tree_cmd_owner_report (GtkAction *action,
01202         GncPluginPageOwnerTree *plugin_page)
01203 {
01204     GncOwner *current_owner;
01205     int id;
01206 
01207     ENTER("(action %p, plugin_page %p)", action, plugin_page);
01208 
01209     g_return_if_fail(GNC_IS_PLUGIN_PAGE_OWNER_TREE(plugin_page));
01210 
01211     current_owner = gnc_plugin_page_owner_tree_get_current_owner (plugin_page);
01212     id = build_owner_report (current_owner, NULL);
01213     if (id >= 0)
01214     {
01215         GncMainWindow *window;
01216         window = GNC_MAIN_WINDOW(GNC_PLUGIN_PAGE(plugin_page)->window);
01217         gnc_main_window_open_report(id, window);
01218     }
01219 
01220     LEAVE(" ");
01221 }
01222 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines