dialog-find-transactions.c

00001 /********************************************************************\
00002  * dialog-find-transactions.c : locate transactions and show them   *
00003  * Copyright (C) 2000 Bill Gribble <grib@billgribble.com>           *
00004  *                                                                  *
00005  * This program is free software; you can redistribute it and/or    *
00006  * modify it under the terms of the GNU General Public License as   *
00007  * published by the Free Software Foundation; either version 2 of   *
00008  * the License, or (at your option) any later version.              *
00009  *                                                                  *
00010  * This program is distributed in the hope that it will be useful,  *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00013  * GNU General Public License for more details.                     *
00014  *                                                                  *
00015  * You should have received a copy of the GNU General Public License*
00016  * along with this program; if not, contact:                        *
00017  *                                                                  *
00018  * Free Software Foundation           Voice:  +1-617-542-5942       *
00019  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
00020  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
00021 \********************************************************************/
00022 
00023 #include "config.h"
00024 
00025 #include <gtk/gtk.h>
00026 #include <glib/gi18n.h>
00027 #include <stdio.h>
00028 
00029 #include "gnc-ui-util.h"
00030 #include "Query.h"
00031 #include "QueryCore.h"
00032 #include "QueryNew.h"
00033 #include "QueryObject.h"
00034 #include "SX-book.h"
00035 #include "Transaction.h"
00036 #include "dialog-find-transactions.h"
00037 #include "gnc-main-window.h"
00038 #include "gnc-plugin-page-register.h"
00039 #include "search-param.h"
00040 
00041 #define GCONF_SECTION "dialogs/find"
00042 
00043 struct _ftd_data {
00044   QueryNew *            q;
00045   QueryNew *            ledger_q;
00046   GNCSearchWindow *     sw;
00047 };
00048 
00049 static void
00050 do_find_cb (QueryNew *query, gpointer user_data, gpointer *result)
00051 {
00052   struct _ftd_data *ftd = user_data;
00053   GNCLedgerDisplay *ledger;
00054   gboolean new_ledger = FALSE;
00055   GncPluginPage *page;
00056 
00057   ledger = gnc_ledger_display_find_by_query (ftd->ledger_q);
00058   if(!ledger) {
00059     new_ledger = TRUE;
00060     ledger = gnc_ledger_display_query (query, SEARCH_LEDGER,
00061                                        REG_STYLE_JOURNAL);
00062   }
00063   else
00064     gnc_ledger_display_set_query (ledger, query);
00065 
00066   gnc_ledger_display_refresh (ledger);
00067 
00068   if (new_ledger) {
00069     page = gnc_plugin_page_register_new_ledger (ledger);
00070     gnc_main_window_open_page (NULL, page);
00071   }
00072 
00073   gncQueryDestroy (ftd->q);
00074 
00075   gnc_search_dialog_destroy (ftd->sw);
00076 }
00077 
00078 static void
00079 free_ftd_cb (gpointer user_data)
00080 {
00081   struct _ftd_data *ftd = user_data;
00082 
00083   if (!ftd)
00084     return;
00085 
00086   g_free (ftd);
00087 }
00088 
00089 GNCSearchWindow * 
00090 gnc_ui_find_transactions_dialog_create(GNCLedgerDisplay * orig_ledg)
00091 {
00092   GNCIdType type = GNC_ID_SPLIT;
00093   struct _ftd_data *ftd;
00094   static GList *params = NULL;
00095   QueryNew *start_q, *show_q = NULL;
00096 
00097   /* Build parameter list in reverse order */
00098   if (params == NULL) {
00099     params = gnc_search_param_prepend (params, N_("All Accounts"),
00100                                        ACCOUNT_MATCH_ALL_TYPE,
00101                                        type, SPLIT_TRANS, TRANS_SPLITLIST,
00102                                        SPLIT_ACCOUNT_GUID, NULL);
00103     params = gnc_search_param_prepend (params, N_("Account"), GNC_ID_ACCOUNT,
00104                                        type, SPLIT_ACCOUNT, QUERY_PARAM_GUID,
00105                                        NULL);
00106     params = gnc_search_param_prepend (params, N_("Balanced"), NULL,
00107                                        type, SPLIT_TRANS, TRANS_IS_BALANCED,
00108                                        NULL);
00109     params = gnc_search_param_prepend (params, N_("Reconcile"), RECONCILED_MATCH_TYPE,
00110                                        type, SPLIT_RECONCILE, NULL);
00111     params = gnc_search_param_prepend (params, N_("Share Price"), NULL,
00112                                        type, SPLIT_SHARE_PRICE, NULL);
00113     params = gnc_search_param_prepend (params, N_("Shares"), NULL,
00114                                        type, SPLIT_AMOUNT, NULL);
00115     params = gnc_search_param_prepend (params, N_("Value"), NULL,
00116                                        type, SPLIT_VALUE, NULL);
00117     params = gnc_search_param_prepend (params, N_("Date Posted"), NULL,
00118                                        type, SPLIT_TRANS, TRANS_DATE_POSTED,
00119                                        NULL);
00120     params = gnc_search_param_prepend (params, N_("Notes"), NULL,
00121                                        type, SPLIT_TRANS, TRANS_NOTES, NULL);
00122     params = gnc_search_param_prepend (params, N_("Action"), NULL,
00123                                        type, SPLIT_ACTION, NULL);
00124     params = gnc_search_param_prepend (params, N_("Number"), NULL,
00125                                        type, SPLIT_TRANS, TRANS_NUM, NULL);
00126     params = gnc_search_param_prepend (params, N_("Memo"), NULL,
00127                                        type, SPLIT_MEMO, NULL);
00128     params = gnc_search_param_prepend (params, N_("Description"), NULL,
00129                                        type, SPLIT_TRANS, TRANS_DESCRIPTION,
00130                                        NULL);
00131   }
00132 
00133   ftd = g_new0 (struct _ftd_data, 1);
00134 
00135   if(orig_ledg) {
00136     ftd->ledger_q = gnc_ledger_display_get_query (orig_ledg);
00137     start_q = show_q = gncQueryCopy (ftd->ledger_q);
00138   } else {
00139     start_q = gncQueryCreate ();
00140     gncQuerySetBook (start_q, gnc_get_current_book ());
00141 
00142     /* In lieu of not "mis-using" some portion of the infrastructure by writing
00143      * a bunch of new code, we just filter out the accounts of the template
00144      * transactions.  While these are in a seperate Account trees just for this
00145      * reason, the query engine makes no distinction between Account trees.
00146      * See Gnome Bug 86302.
00147      *  -- jsled 
00148      *
00149      * copied from gnc-ledger-display.c:gnc_ledger_display_gl()  -- warlord
00150      *
00151      * <jsled> Alternatively, you could look for a GNC_SX_ACCOUNT [SchedAction.h] 
00152      * key in the KVP frame of the split.
00153      */
00154     {
00155       Account *tRoot;
00156       GList *al;
00157     
00158       tRoot = gnc_book_get_template_root( gnc_get_current_book() );
00159       al = gnc_account_get_descendants( tRoot );
00160       xaccQueryAddAccountMatch( start_q, al, GUID_MATCH_NONE, QUERY_AND );
00161       g_list_free (al);
00162       al = NULL;
00163       tRoot = NULL;
00164     }
00165 
00166     ftd->q = start_q;           /* save this to destroy it later */
00167   }
00168 
00169   ftd->sw = gnc_search_dialog_create (type, _("Find Transaction"),
00170                                       params, NULL, start_q, show_q,
00171                                       NULL, do_find_cb, NULL,
00172                                       ftd, free_ftd_cb, GCONF_SECTION, NULL);
00173 
00174   if (!ftd->sw) {
00175     free_ftd_cb (ftd);
00176     return NULL;
00177   }
00178 
00179   return ftd->sw;
00180 }

Generated on Thu Jul 3 05:06:30 2008 for GnuCash by  doxygen 1.5.2