r22292 - gnucash/trunk - Bug #677859 - Remove depreciated CList functions
Geert Janssens
gjanssens at code.gnucash.org
Tue Aug 7 14:24:14 EDT 2012
Author: gjanssens
Date: 2012-08-07 14:24:13 -0400 (Tue, 07 Aug 2012)
New Revision: 22292
Trac: http://svn.gnucash.org/trac/changeset/22292
Added:
gnucash/trunk/src/gnome-utils/dialog-query-view.c
gnucash/trunk/src/gnome-utils/dialog-query-view.h
gnucash/trunk/src/gnome-utils/gnc-query-view.c
gnucash/trunk/src/gnome-utils/gnc-query-view.h
gnucash/trunk/src/gnome-utils/gtkbuilder/dialog-query-view.glade
gnucash/trunk/src/gnome/reconcile-view.c
gnucash/trunk/src/gnome/reconcile-view.h
Removed:
gnucash/trunk/src/gnome-utils/dialog-query-list.c
gnucash/trunk/src/gnome-utils/dialog-query-list.h
gnucash/trunk/src/gnome-utils/gnc-query-list.c
gnucash/trunk/src/gnome-utils/gnc-query-list.h
gnucash/trunk/src/gnome-utils/gtkbuilder/dialog-query-list.glade
gnucash/trunk/src/gnome/reconcile-list.c
gnucash/trunk/src/gnome/reconcile-list.h
Modified:
gnucash/trunk/po/POTFILES.in
gnucash/trunk/src/business/business-gnome/dialog-customer.c
gnucash/trunk/src/business/business-gnome/dialog-employee.c
gnucash/trunk/src/business/business-gnome/dialog-invoice.c
gnucash/trunk/src/business/business-gnome/dialog-invoice.h
gnucash/trunk/src/business/business-gnome/dialog-job.c
gnucash/trunk/src/business/business-gnome/dialog-order.c
gnucash/trunk/src/business/business-gnome/dialog-vendor.c
gnucash/trunk/src/gnome-search/dialog-search.c
gnucash/trunk/src/gnome-search/dialog-search.h
gnucash/trunk/src/gnome-utils/Makefile.am
gnucash/trunk/src/gnome-utils/dialog-utils.c
gnucash/trunk/src/gnome-utils/dialog-utils.h
gnucash/trunk/src/gnome-utils/gtkbuilder/Makefile.am
gnucash/trunk/src/gnome/Makefile.am
gnucash/trunk/src/gnome/window-reconcile.c
gnucash/trunk/src/gnome/window-reconcile.h
Log:
Bug #677859 - Remove depreciated CList functions
Patch by Robert Fewell
Modified: gnucash/trunk/po/POTFILES.in
===================================================================
--- gnucash/trunk/po/POTFILES.in 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/po/POTFILES.in 2012-08-07 18:24:13 UTC (rev 22292)
@@ -220,7 +220,7 @@
src/gnome/gtkbuilder/gnc-plugin-page-register.glade
src/gnome/gtkbuilder/window-autoclear.glade
src/gnome/gtkbuilder/window-reconcile.glade
-src/gnome/reconcile-list.c
+src/gnome/reconcile-view.c
src/gnome/schemas/apps_gnucash_dialog_commodities.schemas.in
src/gnome/schemas/apps_gnucash_dialog_common.schemas.in
src/gnome/schemas/apps_gnucash_dialog_prices.schemas.in
@@ -260,7 +260,7 @@
src/gnome-utils/dialog-object-references.c
src/gnome-utils/dialog-options.c
src/gnome-utils/dialog-preferences.c
-src/gnome-utils/dialog-query-list.c
+src/gnome-utils/dialog-query-view.c
src/gnome-utils/dialog-reset-warnings.c
src/gnome-utils/dialog-tax-table.c
src/gnome-utils/dialog-totd.c
@@ -297,7 +297,7 @@
src/gnome-utils/gnc-plugin-manager.c
src/gnome-utils/gnc-plugin-menu-additions.c
src/gnome-utils/gnc-plugin-page.c
-src/gnome-utils/gnc-query-list.c
+src/gnome-utils/gnc-query-view.c
src/gnome-utils/gnc-recurrence.c
src/gnome-utils/gnc-splash.c
src/gnome-utils/gnc-sx-instance-dense-cal-adapter.c
@@ -325,7 +325,7 @@
src/gnome-utils/gtkbuilder/dialog-object-references.glade
src/gnome-utils/gtkbuilder/dialog-options.glade
src/gnome-utils/gtkbuilder/dialog-preferences.glade
-src/gnome-utils/gtkbuilder/dialog-query-list.glade
+src/gnome-utils/gtkbuilder/dialog-query-view.glade
src/gnome-utils/gtkbuilder/dialog-reset-warnings.glade
src/gnome-utils/gtkbuilder/dialog-tax-table.glade
src/gnome-utils/gtkbuilder/dialog-totd.glade
Modified: gnucash/trunk/src/business/business-gnome/dialog-customer.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-customer.c 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/src/business/business-gnome/dialog-customer.c 2012-08-07 18:24:13 UTC (rev 22292)
@@ -911,7 +911,7 @@
g_return_val_if_fail (book, NULL);
- /* Build parameter list in reverse order*/
+ /* Build parameter list in reverse order */
if (params == NULL)
{
params = gnc_search_param_prepend (params, _("Shipping Contact"), NULL, type,
Modified: gnucash/trunk/src/business/business-gnome/dialog-employee.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-employee.c 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/src/business/business-gnome/dialog-employee.c 2012-08-07 18:24:13 UTC (rev 22292)
@@ -715,7 +715,7 @@
g_return_val_if_fail (book, NULL);
- /* Build parameter list in reverse order*/
+ /* Build parameter list in reverse order */
if (params == NULL)
{
params = gnc_search_param_prepend (params, _("Employee ID"), NULL, type,
Modified: gnucash/trunk/src/business/business-gnome/dialog-invoice.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-invoice.c 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/src/business/business-gnome/dialog-invoice.c 2012-08-07 18:24:13 UTC (rev 22292)
@@ -64,7 +64,7 @@
#include "guile-mappings.h"
#include "dialog-dup-trans.h"
-#include "dialog-query-list.h"
+#include "dialog-query-view.h"
#include "gnc-plugin-business.h"
#include "gnc-plugin-page-invoice.h"
@@ -3040,7 +3040,7 @@
label);
}
-DialogQueryList *
+DialogQueryView *
gnc_invoice_show_bills_due (QofBook *book, double days_in_advance)
{
QofIdType type = GNC_INVOICE_MODULE_NAME;
@@ -3049,11 +3049,11 @@
time_t end_date;
GList *res;
gchar *message;
- DialogQueryList *dialog;
+ DialogQueryView *dialog;
gint len;
Timespec ts;
static GList *param_list = NULL;
- static GNCDisplayListButton buttons[] =
+ static GNCDisplayViewButton buttons[] =
{
{ N_("View/Edit Bill"), edit_invoice_direct },
{ N_("Process Payment"), pay_invoice_direct },
@@ -3121,15 +3121,16 @@
"The following %d bills are due:",
len),
len);
- dialog = gnc_dialog_query_list_create(param_list, q,
- _("Due Bills Reminder"),
+ dialog = gnc_dialog_query_view_create(param_list, q,
+ _("Due Bills Reminder"),
message,
TRUE, FALSE,
+ 1, GTK_SORT_ASCENDING,
buttons, NULL);
+
g_free(message);
qof_query_destroy(q);
return dialog;
-
}
void
Modified: gnucash/trunk/src/business/business-gnome/dialog-invoice.h
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-invoice.h 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/src/business/business-gnome/dialog-invoice.h 2012-08-07 18:24:13 UTC (rev 22292)
@@ -33,7 +33,7 @@
#include "gncInvoice.h"
#include "gncOwner.h"
#include "dialog-search.h"
-#include "dialog-query-list.h"
+#include "dialog-query-view.h"
typedef enum
{
@@ -90,7 +90,7 @@
GtkWidget * gnc_invoice_create_page (InvoiceWindow *iw, gpointer page);
-DialogQueryList *gnc_invoice_show_bills_due (QofBook *book, double days_in_advance);
+DialogQueryView *gnc_invoice_show_bills_due (QofBook *book, double days_in_advance);
GtkWidget *gnc_invoice_get_register(InvoiceWindow *iw);
Modified: gnucash/trunk/src/business/business-gnome/dialog-job.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-job.c 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/src/business/business-gnome/dialog-job.c 2012-08-07 18:24:13 UTC (rev 22292)
@@ -552,7 +552,7 @@
g_return_val_if_fail (book, NULL);
- /* Build parameter list in reverse order*/
+ /* Build parameter list in reverse order */
if (params == NULL)
{
params = gnc_search_param_prepend (params, _("Owner's Name"), NULL, type,
Modified: gnucash/trunk/src/business/business-gnome/dialog-order.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-order.c 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/src/business/business-gnome/dialog-order.c 2012-08-07 18:24:13 UTC (rev 22292)
@@ -858,7 +858,7 @@
g_return_val_if_fail (book, NULL);
- /* Build parameter list in reverse order*/
+ /* Build parameter list in reverse order */
if (params == NULL)
{
params = gnc_search_param_prepend (params, _("Order Notes"), NULL, type,
Modified: gnucash/trunk/src/business/business-gnome/dialog-vendor.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-vendor.c 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/src/business/business-gnome/dialog-vendor.c 2012-08-07 18:24:13 UTC (rev 22292)
@@ -716,7 +716,7 @@
g_return_val_if_fail (book, NULL);
- /* Build parameter list in reverse order*/
+ /* Build parameter list in reverse order */
if (params == NULL)
{
params = gnc_search_param_prepend (params, _("Billing Contact"), NULL, type,
Modified: gnucash/trunk/src/gnome/Makefile.am
===================================================================
--- gnucash/trunk/src/gnome/Makefile.am 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/src/gnome/Makefile.am 2012-08-07 18:24:13 UTC (rev 22292)
@@ -52,7 +52,7 @@
gnc-plugin-page-register.c \
gnc-plugin-page-register2.c \
gnc-split-reg.c \
- reconcile-list.c \
+ reconcile-view.c \
top-level.c \
window-reconcile.c \
window-autoclear.c
@@ -90,7 +90,7 @@
gnc-plugin-page-register.h \
gnc-plugin-page-register2.h \
gnc-split-reg.h \
- reconcile-list.h \
+ reconcile-view.h \
top-level.h \
window-reconcile.h \
window-autoclear.h
Deleted: gnucash/trunk/src/gnome/reconcile-list.c
===================================================================
--- gnucash/trunk/src/gnome/reconcile-list.c 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/src/gnome/reconcile-list.c 2012-08-07 18:24:13 UTC (rev 22292)
@@ -1,710 +0,0 @@
-/********************************************************************\
- * reconcile-list.c -- A list of accounts to be reconciled for *
- * GnuCash. *
- * Copyright (C) 1998,1999 Jeremy Collins *
- * Copyright (C) 1998-2000 Linas Vepstas *
- * *
- * 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 "gnc-date.h"
-#include "qof.h"
-#include "Transaction.h"
-#include "gnc-ui-util.h"
-#include "gnc-gconf-utils.h"
-#include "reconcile-list.h"
-#include "search-param.h"
-#include "gnc-component-manager.h"
-
-/* Signal codes */
-enum
-{
- TOGGLE_RECONCILED,
- DOUBLE_CLICK_SPLIT,
- LAST_SIGNAL
-};
-
-
-/** Static Globals ****************************************************/
-static GNCQueryListClass *parent_class = NULL;
-static guint reconcile_list_signals[LAST_SIGNAL] = {0};
-
-
-/** Static function declarations **************************************/
-static void gnc_reconcile_list_init(GNCReconcileList *list);
-static void gnc_reconcile_list_class_init(GNCReconcileListClass *klass);
-static void gnc_reconcile_list_finalize (GObject *object);
-static gpointer gnc_reconcile_list_is_reconciled(gpointer item, gpointer user_data);
-static void gnc_reconcile_list_line_toggled (GNCQueryList *list, gpointer item,
- gpointer user_data);
-static void gnc_reconcile_list_double_click_entry (GNCQueryList *list,
- gpointer item,
- gpointer user_data);
-
-
-GType
-gnc_reconcile_list_get_type (void)
-{
- static GType gnc_reconcile_list_type = 0;
-
- if (gnc_reconcile_list_type == 0)
- {
- static const GTypeInfo gnc_reconcile_list_info =
- {
- sizeof (GNCReconcileListClass),
- NULL,
- NULL,
- (GClassInitFunc) gnc_reconcile_list_class_init,
- NULL,
- NULL,
- sizeof (GNCReconcileList),
- 0,
- (GInstanceInitFunc) gnc_reconcile_list_init
- };
-
- gnc_reconcile_list_type = g_type_register_static (GNC_TYPE_QUERY_LIST,
- "GncReconcileList",
- &gnc_reconcile_list_info, 0);
- }
-
- return gnc_reconcile_list_type;
-}
-
-
-/********************************************************************\
- * gnc_reconcile_list_new *
- * creates the account tree *
- * *
- * Args: account - the account to use in filling up the splits. *
- * type - the type of list, RECLIST_DEBIT or RECLIST_CREDIT*
- * Returns: the account tree widget, or NULL if there was a problem.*
-\********************************************************************/
-static void
-gnc_reconcile_list_construct(GNCReconcileList *list, Query *query)
-{
- GNCQueryList *qlist = GNC_QUERY_LIST (list);
- gboolean inv_sort = FALSE;
-
- if (list->list_type == RECLIST_CREDIT)
- inv_sort = TRUE;
-
- gnc_query_list_construct (qlist, list->column_list, query);
- gnc_query_list_set_numerics (qlist, TRUE, inv_sort);
-
- /* Now set up the signals for the QueryList */
- g_signal_connect (G_OBJECT (qlist), "line_toggled",
- G_CALLBACK(gnc_reconcile_list_line_toggled), list);
- g_signal_connect (G_OBJECT (qlist), "double_click_entry",
- G_CALLBACK(gnc_reconcile_list_double_click_entry), list);
-}
-
-GtkWidget *
-gnc_reconcile_list_new(Account *account, GNCReconcileListType type,
- time_t statement_date)
-{
- GNCReconcileList *list;
- gboolean include_children, auto_check;
- GList *accounts = NULL;
- GList *splits;
- Query *query;
-
- g_return_val_if_fail(account, NULL);
- g_return_val_if_fail((type == RECLIST_DEBIT) ||
- (type == RECLIST_CREDIT), NULL);
-
- list = g_object_new (GNC_TYPE_RECONCILE_LIST,
- "n-columns", 5,
- NULL);
-
- list->account = account;
- list->list_type = type;
- list->statement_date = statement_date;
-
- query = qof_query_create_for(GNC_ID_SPLIT);
- qof_query_set_book(query, gnc_get_current_book ());
-
- include_children = xaccAccountGetReconcileChildrenStatus(account);
- if (include_children)
- accounts = gnc_account_get_descendants(account);
-
- /* match the account */
- accounts = g_list_prepend (accounts, account);
-
- xaccQueryAddAccountMatch (query, accounts, QOF_GUID_MATCH_ANY, QOF_QUERY_AND);
-
- g_list_free (accounts);
-
- /* limit the matches to CREDITs and DEBITs only, depending on the type */
- if (type == RECLIST_CREDIT)
- xaccQueryAddValueMatch(query, gnc_numeric_zero (),
- QOF_NUMERIC_MATCH_CREDIT,
- QOF_COMPARE_GTE, QOF_QUERY_AND);
- else
- xaccQueryAddValueMatch(query, gnc_numeric_zero (),
- QOF_NUMERIC_MATCH_DEBIT,
- QOF_COMPARE_GTE, QOF_QUERY_AND);
-
- /* limit the matches only to Cleared and Non-reconciled splits */
- xaccQueryAddClearedMatch(query, CLEARED_NO | CLEARED_CLEARED, QOF_QUERY_AND);
-
- /* initialize the QueryList */
- gnc_reconcile_list_construct (list, query);
-
- /* find the list of splits to auto-reconcile */
- auto_check = gnc_gconf_get_bool(GCONF_RECONCILE_SECTION,
- "check_cleared", NULL);
-
- if (auto_check)
- {
- for (splits = qof_query_run(query); splits; splits = splits->next)
- {
- Split *split = splits->data;
- char recn = xaccSplitGetReconcile(split);
- time_t trans_date = xaccTransGetDate(xaccSplitGetParent(split));
-
- /* Just an extra verification that our query is correct ;) */
- g_assert (recn == NREC || recn == CREC);
-
- if (recn == CREC &&
- difftime(trans_date, statement_date) <= 0)
- g_hash_table_insert (list->reconciled, split, split);
- }
- }
-
- /* Free the query -- we don't need it anymore */
- qof_query_destroy(query);
-
- return GTK_WIDGET(list);
-}
-
-static void
-gnc_reconcile_list_init (GNCReconcileList *list)
-{
- GNCSearchParam *param;
- GList *columns = NULL;
-
- list->reconciled = g_hash_table_new (NULL, NULL);
- list->account = NULL;
- list->sibling = NULL;
-
- param = gnc_search_param_new();
- gnc_search_param_set_param_fcn (param, QOF_TYPE_BOOLEAN,
- gnc_reconcile_list_is_reconciled, list);
- gnc_search_param_set_title (param, _("Reconciled:R") + 11);
- gnc_search_param_set_justify (param, GTK_JUSTIFY_CENTER);
- gnc_search_param_set_passive (param, TRUE);
- gnc_search_param_set_non_resizeable (param, TRUE);
- columns = g_list_prepend (columns, param);
- columns = gnc_search_param_prepend_with_justify (columns, _("Amount"),
- GTK_JUSTIFY_RIGHT,
- NULL, GNC_ID_SPLIT,
- SPLIT_AMOUNT, NULL);
- columns = gnc_search_param_prepend (columns, _("Description"), NULL,
- GNC_ID_SPLIT, SPLIT_TRANS,
- TRANS_DESCRIPTION, NULL);
- columns = gnc_search_param_prepend_with_justify (columns, _("Num"),
- GTK_JUSTIFY_CENTER,
- NULL, GNC_ID_SPLIT,
- SPLIT_TRANS, TRANS_NUM, NULL);
- columns = gnc_search_param_prepend (columns, _("Date"), NULL, GNC_ID_SPLIT,
- SPLIT_TRANS, TRANS_DATE_POSTED, NULL);
-
- list->column_list = columns;
-}
-
-
-static void
-gnc_reconcile_list_class_init (GNCReconcileListClass *klass)
-{
- GObjectClass *object_class;
-
- object_class = G_OBJECT_CLASS (klass);
-
- parent_class = g_type_class_peek_parent (klass);
-
- reconcile_list_signals[TOGGLE_RECONCILED] =
- g_signal_new("toggle_reconciled",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (GNCReconcileListClass,
- toggle_reconciled),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
-
- reconcile_list_signals[DOUBLE_CLICK_SPLIT] =
- g_signal_new("double_click_split",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (GNCReconcileListClass,
- double_click_split),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1,
- G_TYPE_POINTER);
-
- object_class->finalize = gnc_reconcile_list_finalize;
-
- klass->toggle_reconciled = NULL;
- klass->double_click_split = NULL;
-}
-
-static void
-gnc_reconcile_list_toggle_split(GNCReconcileList *list, Split *split)
-{
- Split *current;
-
- g_return_if_fail (GNC_IS_RECONCILE_LIST(list));
- g_return_if_fail (list->reconciled != NULL);
-
- current = g_hash_table_lookup (list->reconciled, split);
-
- if (current == NULL)
- g_hash_table_insert (list->reconciled, split, split);
- else
- g_hash_table_remove (list->reconciled, split);
-
- gnc_query_list_refresh_item (GNC_QUERY_LIST(list), split);
-}
-
-static void
-gnc_reconcile_list_toggle_children(Account *account, GNCReconcileList *list, Split *split)
-{
- GList *child_accounts, *node;
- Transaction *transaction;
-
- /*
- * Need to get all splits in this transaction and identify any that are
- * in the same heirarchy as the account being reconciled (not necessarily
- * the account this split is from.)
- *
- * For each of these splits toggle them all to the same state.
- */
- child_accounts = gnc_account_get_descendants(account);
- child_accounts = g_list_prepend(child_accounts, account);
- transaction = xaccSplitGetParent(split);
- for (node = xaccTransGetSplitList(transaction); node; node = node->next)
- {
- Split *other_split;
- Account *other_account;
- GNCReconcileList *current_list;
-
- other_split = node->data;
- other_account = xaccSplitGetAccount(other_split);
- if (other_split == split)
- continue;
- /* Check this 'other' account in in the same heirarchy */
- if (!g_list_find(child_accounts, other_account))
- continue;
- /* Search our sibling list for this split first. We search the
- * sibling list first because that it where it is most likely to be.
- */
- current_list = list->sibling;
- if (!gnc_query_list_item_in_list (GNC_QUERY_LIST(current_list), other_split))
- {
- /* Not in the sibling list, try this list */
- current_list = list;
- if (!gnc_query_list_item_in_list (GNC_QUERY_LIST(current_list), other_split))
- /* We can't find it, nothing more I can do about it */
- continue;
- }
- gnc_reconcile_list_toggle_split(current_list, other_split);
- }
- g_list_free(child_accounts);
-}
-
-static void
-gnc_reconcile_list_toggle (GNCReconcileList *list, Split *split)
-{
- gboolean include_children;
-
- g_return_if_fail (GNC_IS_RECONCILE_LIST(list));
- g_return_if_fail (list->reconciled != NULL);
-
- gnc_reconcile_list_toggle_split(list, split);
-
- include_children = xaccAccountGetReconcileChildrenStatus(list->account);
- if (include_children)
- gnc_reconcile_list_toggle_children(list->account, list, split);
-
- g_signal_emit (G_OBJECT (list),
- reconcile_list_signals[TOGGLE_RECONCILED], 0, split);
-}
-
-static void
-gnc_reconcile_list_line_toggled (GNCQueryList *list, gpointer item,
- gpointer user_data)
-{
- GNCReconcileList *rlist = user_data;
-
- g_return_if_fail(item);
- g_return_if_fail(user_data);
- g_return_if_fail(GNC_IS_RECONCILE_LIST(rlist));
-
- gnc_reconcile_list_toggle (rlist, item);
-}
-
-static void gnc_reconcile_list_double_click_entry (GNCQueryList *list,
- gpointer item,
- gpointer user_data)
-{
- GNCReconcileList *rlist = user_data;
-
- g_return_if_fail(item);
- g_return_if_fail(user_data);
- g_return_if_fail(GNC_IS_RECONCILE_LIST(rlist));
-
- g_signal_emit(G_OBJECT(rlist),
- reconcile_list_signals[DOUBLE_CLICK_SPLIT], 0, item);
-}
-
-static void
-gnc_reconcile_list_finalize (GObject *object)
-{
- GNCReconcileList *list = GNC_RECONCILE_LIST(object);
-
- if (list->reconciled != NULL)
- {
- g_hash_table_destroy(list->reconciled);
- list->reconciled = NULL;
- }
-
- G_OBJECT_CLASS (parent_class)->finalize (object);
-}
-
-gint
-gnc_reconcile_list_get_needed_height (GNCReconcileList *list, gint num_rows)
-{
- g_return_val_if_fail (list != NULL, 0);
- g_return_val_if_fail (GNC_IS_RECONCILE_LIST(list), 0);
-
- if (!gtk_widget_get_realized (GTK_WIDGET(list)))
- return 0;
-
- return gnc_query_list_get_needed_height (GNC_QUERY_LIST(list), num_rows);
-}
-
-gint
-gnc_reconcile_list_get_num_splits (GNCReconcileList *list)
-{
- g_return_val_if_fail (list != NULL, 0);
- g_return_val_if_fail (GNC_IS_RECONCILE_LIST(list), 0);
-
- return gnc_query_list_get_num_entries(GNC_QUERY_LIST(list));
-}
-
-Split *
-gnc_reconcile_list_get_current_split (GNCReconcileList *list)
-{
- g_return_val_if_fail (list != NULL, NULL);
- g_return_val_if_fail (GNC_IS_RECONCILE_LIST(list), NULL);
-
- return gnc_query_list_get_current_entry(GNC_QUERY_LIST(list));
-}
-
-/********************************************************************\
- * gnc_reconcile_list_is_reconciled *
- * Is the item a reconciled split? *
- * *
- * Args: item - the split to be checked *
- * user_data - a pointer to the GNCReconcileList *
- * Returns: whether the split is to be reconciled. *
-\********************************************************************/
-static gpointer
-gnc_reconcile_list_is_reconciled(gpointer item, gpointer user_data)
-{
- GNCReconcileList *list = user_data;
- Split *current;
-
- g_return_val_if_fail(item, NULL);
- g_return_val_if_fail(list, NULL);
- g_return_val_if_fail(GNC_IS_RECONCILE_LIST(list), NULL);
-
- if (!list->reconciled)
- return NULL;
-
- current = g_hash_table_lookup(list->reconciled, item);
- return GINT_TO_POINTER(current != NULL);
-}
-
-static void
-grl_refresh_helper (gpointer key, gpointer value, gpointer user_data)
-{
- GNCReconcileList *list = user_data;
- GNCQueryList *qlist = GNC_QUERY_LIST(list);
-
- if (!gnc_query_list_item_in_list(qlist, key))
- g_hash_table_remove(list->reconciled, key);
-}
-
-/********************************************************************\
- * gnc_reconcile_list_refresh *
- * refreshes the list *
- * *
- * Args: list - list to refresh *
- * Returns: nothing *
-\********************************************************************/
-void
-gnc_reconcile_list_refresh (GNCReconcileList *list)
-{
- GNCQueryList *qlist;
-
- g_return_if_fail (list != NULL);
- g_return_if_fail (GNC_IS_RECONCILE_LIST(list));
-
- qlist = GNC_QUERY_LIST(list);
- gnc_query_list_refresh(qlist);
-
- /* Now verify that everything in the reconcile hash is still in qlist */
- if (list->reconciled)
- g_hash_table_foreach(list->reconciled, grl_refresh_helper, list);
-}
-
-
-/********************************************************************\
- * gnc_reconcile_list_reconciled_balance *
- * returns the reconciled balance of the list *
- * *
- * Args: list - list to get reconciled balance of *
- * Returns: reconciled balance (gnc_numeric) *
-\********************************************************************/
-static void
-grl_balance_hash_helper (gpointer key, gpointer value, gpointer user_data)
-{
- Split *split = key;
- gnc_numeric *total = user_data;
-
- *total = gnc_numeric_add_fixed (*total, xaccSplitGetAmount (split));
-}
-
-gnc_numeric
-gnc_reconcile_list_reconciled_balance (GNCReconcileList *list)
-{
- gnc_numeric total = gnc_numeric_zero ();
-
- g_return_val_if_fail (list != NULL, total);
- g_return_val_if_fail (GNC_IS_RECONCILE_LIST(list), total);
-
- if (list->reconciled == NULL)
- return total;
-
- g_hash_table_foreach (list->reconciled, grl_balance_hash_helper, &total);
-
- return gnc_numeric_abs (total);
-}
-
-
-/********************************************************************\
- * gnc_reconcile_list_commit *
- * Commit the reconcile information in the list. only change the *
- * state of those items marked as reconciled. All others should *
- * retain their previous state (none, cleared, voided, etc.). *
- * *
- * Args: list - list to commit *
- * date - date to set as the reconcile date *
- * Returns: nothing *
-\********************************************************************/
-static void
-grl_commit_hash_helper (gpointer key, gpointer value, gpointer user_data)
-{
- Split *split = key;
- time_t *date = user_data;
-
- xaccSplitSetReconcile (split, YREC);
- xaccSplitSetDateReconciledSecs (split, *date);
-}
-
-void
-gnc_reconcile_list_commit (GNCReconcileList *list, time_t date)
-{
- g_return_if_fail (list != NULL);
- g_return_if_fail (GNC_IS_RECONCILE_LIST(list));
-
- if (list->reconciled == NULL)
- return;
-
- gnc_suspend_gui_refresh();
- g_hash_table_foreach (list->reconciled, grl_commit_hash_helper, &date);
- gnc_resume_gui_refresh();
-}
-
-
-/********************************************************************\
- * gnc_reconcile_list_postpone *
- * postpone the reconcile information in the list by setting *
- * reconciled splits to cleared status *
- * *
- * Args: list - list to commit *
- * Returns: nothing *
-\********************************************************************/
-void
-gnc_reconcile_list_postpone (GNCReconcileList *list)
-{
- GtkCList *clist = GTK_CLIST(list); /* This is cheating! */
- Split *split;
- int num_splits;
- int i;
-
- g_return_if_fail(list != NULL);
- g_return_if_fail(GNC_IS_RECONCILE_LIST(list));
-
- if (list->reconciled == NULL)
- return;
-
- num_splits = gnc_query_list_get_num_entries(GNC_QUERY_LIST(list));
- gnc_suspend_gui_refresh();
- for (i = 0; i < num_splits; i++)
- {
- char recn;
-
- split = gtk_clist_get_row_data (clist, i);
-
- // Don't change splits past reconciliation date that haven't been
- // set to be reconciled
- if ( difftime(list->statement_date,
- xaccTransGetDate(xaccSplitGetParent(split))) >= 0 ||
- g_hash_table_lookup(list->reconciled, split))
- {
- recn = g_hash_table_lookup (list->reconciled, split) ? CREC : NREC;
-
- xaccSplitSetReconcile (split, recn);
- }
- }
- gnc_resume_gui_refresh();
-}
-
-
-/********************************************************************\
- * gnc_reconcile_list_unselect_all *
- * unselect all splits in the list *
- * *
- * Args: list - list to unselect all *
- * Returns: nothing *
-\********************************************************************/
-void
-gnc_reconcile_list_unselect_all(GNCReconcileList *list)
-{
- g_return_if_fail (list != NULL);
- g_return_if_fail (GNC_IS_RECONCILE_LIST(list));
-
- gnc_query_list_unselect_all (GNC_QUERY_LIST(list));
-}
-
-
-/********************************************************************\
- * gnc_reconcile_list_changed *
- * returns true if any splits have been reconciled *
- * *
- * Args: list - list to get changed status for *
- * Returns: true if any reconciled splits *
-\********************************************************************/
-gboolean
-gnc_reconcile_list_changed (GNCReconcileList *list)
-{
- g_return_val_if_fail (list != NULL, FALSE);
- g_return_val_if_fail (GNC_IS_RECONCILE_LIST(list), FALSE);
-
- return g_hash_table_size (list->reconciled) != 0;
-}
-
-#if 0
-static void
-gnc_reconcile_list_fill(GNCReconcileList *list)
-{
- const gchar *strings[list->num_columns + 1];
- GNCPrintAmountInfo print_info;
- Transaction *trans;
- gboolean auto_check;
- GList *splits;
- Split *split;
-
- auto_check = gnc_gconf_get_bool(GCONF_RECONCILE_SECTION,
- "check_cleared", NULL);
-
- strings[5] = NULL;
-
- print_info = gnc_account_print_info (list->account, FALSE);
-
- for (splits = qof_query_run (list->query); splits; splits = splits->next)
- {
- gnc_numeric amount;
- Timespec ts;
- const gchar *trans_num;
- char recn;
- int row, len;
-
- split = splits->data;
- trans = xaccSplitGetParent (split);
- trans_num = xaccTransGetNum (trans);
-
- recn = xaccSplitGetReconcile(split);
- if ((recn != NREC) && (recn != CREC))
- continue;
-
- amount = xaccSplitGetAmount (split);
-
- if (gnc_numeric_negative_p (amount))
- {
- if (list->list_type == RECLIST_DEBIT)
- {
- continue;
- }
- }
- else if (gnc_numeric_positive_p (amount))
- {
- if (list->list_type == RECLIST_CREDIT)
- {
- continue;
- }
- }
- else
- {
- len = trans_num ? strlen(trans_num) : 0;
- if ((len && (list->list_type == RECLIST_DEBIT)) ||
- (!len && (list->list_type == RECLIST_CREDIT)))
- continue;
- }
-
- xaccTransGetDatePostedTS (trans, &ts);
-
- strings[0] = gnc_print_date (ts);
- strings[1] = trans_num;
- strings[2] = xaccTransGetDescription (trans);
- strings[3] = xaccPrintAmount (gnc_numeric_abs (amount), print_info);
- strings[4] = "";
-
- if (list->first_fill && auto_check && recn == CREC)
- g_hash_table_insert (list->reconciled, split, split);
-
- row = gtk_clist_append (GTK_CLIST(list), (gchar **) strings);
- gtk_clist_set_row_data (GTK_CLIST(list), row, split);
-
- update_toggle (GTK_CLIST (list), row);
-
- list->num_splits++;
- }
-
- list->first_fill = FALSE;
-}
-#endif
Deleted: gnucash/trunk/src/gnome/reconcile-list.h
===================================================================
--- gnucash/trunk/src/gnome/reconcile-list.h 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/src/gnome/reconcile-list.h 2012-08-07 18:24:13 UTC (rev 22292)
@@ -1,104 +0,0 @@
-/********************************************************************\
- * reconcile-list.h -- GNOME reconcile list functions *
- * Copyright (C) 1998,1999 Linas Vepstas *
- * Copyright (C) 2003 Derek Atkins <derek at ihtfp.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 GNC_RECONCILE_LIST_H
-#define GNC_RECONCILE_LIST_H
-
-#include "gnc-query-list.h"
-#include "qof.h"
-
-G_BEGIN_DECLS
-
-#define GNC_TYPE_RECONCILE_LIST (gnc_reconcile_list_get_type ())
-#define GNC_RECONCILE_LIST(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_RECONCILE_LIST, GNCReconcileList))
-#define GNC_RECONCILE_LIST_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GNC_TYPE_RECONCILE_LIST, GNCReconcileListClass))
-#define GNC_IS_RECONCILE_LIST(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_RECONCILE_LIST))
-#define GNC_IS_RECONCILE_LIST_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_RECONCILE_LIST))
-
-typedef struct GNCReconcileList GNCReconcileList;
-
-typedef enum
-{
- RECLIST_DEBIT,
- RECLIST_CREDIT
-} GNCReconcileListType;
-
-struct GNCReconcileList
-{
- GNCQueryList qlist;
-
- GHashTable *reconciled;
- Account *account;
- GList *column_list;
-
- time_t statement_date;
-
- GNCReconcileList *sibling;
- GNCReconcileListType list_type;
- gboolean no_toggle;
-};
-
-typedef struct
-{
- GtkCListClass parent_class;
-
- void (*toggle_reconciled) (GNCReconcileList *list,
- Split *split);
- void (*double_click_split) (GNCReconcileList *list,
- Split *split);
-} GNCReconcileListClass;
-
-#define GCONF_RECONCILE_SECTION "dialogs/reconcile"
-
-/***********************************************************
- * public functions *
- ***********************************************************/
-
-GType gnc_reconcile_list_get_type (void);
-
-GtkWidget * gnc_reconcile_list_new (Account * account,
- GNCReconcileListType type,
- time_t date);
-
-gint gnc_reconcile_list_get_needed_height(GNCReconcileList *list,
- gint num_rows);
-
-gint gnc_reconcile_list_get_num_splits(GNCReconcileList *list);
-
-Split * gnc_reconcile_list_get_current_split(GNCReconcileList *list);
-
-void gnc_reconcile_list_refresh (GNCReconcileList *list);
-
-gnc_numeric gnc_reconcile_list_reconciled_balance(GNCReconcileList *list);
-
-void gnc_reconcile_list_commit (GNCReconcileList *list, time_t date);
-
-void gnc_reconcile_list_postpone (GNCReconcileList *list);
-
-void gnc_reconcile_list_unselect_all(GNCReconcileList *list);
-
-gboolean gnc_reconcile_list_changed(GNCReconcileList *list);
-
-G_END_DECLS
-
-#endif /* RECONCILE_LIST_H */
Added: gnucash/trunk/src/gnome/reconcile-view.c
===================================================================
--- gnucash/trunk/src/gnome/reconcile-view.c (rev 0)
+++ gnucash/trunk/src/gnome/reconcile-view.c 2012-08-07 18:24:13 UTC (rev 22292)
@@ -0,0 +1,692 @@
+/********************************************************************\
+ * reconcile-view.c -- A view of accounts to be reconciled for *
+ * GnuCash. *
+ * Copyright (C) 1998,1999 Jeremy Collins *
+ * Copyright (C) 1998-2000 Linas Vepstas *
+ * Copyright (C) 2012 Robert Fewell *
+ * *
+ * 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 "gnc-date.h"
+#include "qof.h"
+#include "Transaction.h"
+#include "gnc-ui-util.h"
+#include "gnc-gconf-utils.h"
+#include "reconcile-view.h"
+#include "search-param.h"
+#include "gnc-component-manager.h"
+
+/* Signal codes */
+enum
+{
+ TOGGLE_RECONCILED,
+ LINE_SELECTED,
+ DOUBLE_CLICK_SPLIT,
+ LAST_SIGNAL
+};
+
+
+/** Static Globals ****************************************************/
+static GNCQueryViewClass *parent_class = NULL;
+static guint reconcile_view_signals[LAST_SIGNAL] = {0};
+
+/** Static function declarations **************************************/
+static void gnc_reconcile_view_init (GNCReconcileView *view);
+static void gnc_reconcile_view_class_init (GNCReconcileViewClass *klass);
+static void gnc_reconcile_view_finalize (GObject *object);
+static gpointer gnc_reconcile_view_is_reconciled (gpointer item, gpointer user_data);
+static void gnc_reconcile_view_line_toggled (GNCQueryView *qview, gpointer item, gpointer user_data);
+static void gnc_reconcile_view_double_click_entry (GNCQueryView *qview, gpointer item, gpointer user_data);
+static void gnc_reconcile_view_row_selected (GNCQueryView *qview, gpointer item, gpointer user_data);
+
+
+GType
+gnc_reconcile_view_get_type (void)
+{
+ static GType gnc_reconcile_view_type = 0;
+
+ if (gnc_reconcile_view_type == 0)
+ {
+ static const GTypeInfo gnc_reconcile_view_info =
+ {
+ sizeof (GNCReconcileViewClass),
+ NULL,
+ NULL,
+ (GClassInitFunc) gnc_reconcile_view_class_init,
+ NULL,
+ NULL,
+ sizeof (GNCReconcileView),
+ 0,
+ (GInstanceInitFunc) gnc_reconcile_view_init
+ };
+
+ gnc_reconcile_view_type = g_type_register_static (GNC_TYPE_QUERY_VIEW,
+ "GncReconcileView",
+ &gnc_reconcile_view_info, 0);
+ }
+
+ return gnc_reconcile_view_type;
+}
+
+
+/****************************************************************************\
+ * gnc_reconcile_view_new *
+ * creates the account tree *
+ * *
+ * Args: account - the account to use in filling up the splits. *
+ * type - the type of view, RECLIST_DEBIT or RECLIST_CREDIT *
+ * statement_date - date of statement *
+ * Returns: the account tree widget, or NULL if there was a problem. *
+\****************************************************************************/
+static void
+gnc_reconcile_view_construct (GNCReconcileView *view, Query *query)
+{
+ GNCQueryView *qview = GNC_QUERY_VIEW (view);
+ GtkTreeViewColumn *col;
+ GtkTreeSelection *selection;
+ gboolean inv_sort = FALSE;
+
+ if (view->view_type == RECLIST_CREDIT)
+ inv_sort = TRUE;
+
+ /* Construct the view */
+ gnc_query_view_construct (qview, view->column_list, query);
+ gnc_query_view_set_numerics (qview, TRUE, inv_sort);
+
+ /* Set the description field to have spare space */
+ col = gtk_tree_view_get_column (GTK_TREE_VIEW (qview), 2);
+ gtk_tree_view_column_set_expand (col, TRUE);
+
+ /* Set the selection method */
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (qview));
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
+
+ /* Now set up the signals for the QueryView */
+ g_signal_connect (G_OBJECT (qview), "column_toggled",
+ G_CALLBACK (gnc_reconcile_view_line_toggled), view);
+ g_signal_connect (G_OBJECT (qview), "double_click_entry",
+ G_CALLBACK (gnc_reconcile_view_double_click_entry), view);
+ g_signal_connect (G_OBJECT (qview), "row_selected",
+ G_CALLBACK (gnc_reconcile_view_row_selected), view);
+}
+
+GtkWidget *
+gnc_reconcile_view_new (Account *account, GNCReconcileViewType type,
+ time_t statement_date)
+{
+ GNCReconcileView *view;
+ GtkListStore *liststore;
+ gboolean include_children, auto_check;
+ GList *accounts = NULL;
+ GList *splits;
+ Query *query;
+
+ g_return_val_if_fail (account, NULL);
+ g_return_val_if_fail ((type == RECLIST_DEBIT) ||
+ (type == RECLIST_CREDIT), NULL);
+
+ view = g_object_new (GNC_TYPE_RECONCILE_VIEW, NULL);
+
+ /* Create the list store with 6 columns and add to treeview,
+ column 0 will be a pointer to the entry */
+ liststore = gtk_list_store_new (6, G_TYPE_POINTER, G_TYPE_STRING,
+ G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN );
+ gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL (liststore));
+ g_object_unref (liststore);
+
+ view->account = account;
+ view->view_type = type;
+ view->statement_date = statement_date;
+
+ query = qof_query_create_for (GNC_ID_SPLIT);
+ qof_query_set_book (query, gnc_get_current_book ());
+
+ include_children = xaccAccountGetReconcileChildrenStatus (account);
+ if (include_children)
+ accounts = gnc_account_get_descendants (account);
+
+ /* match the account */
+ accounts = g_list_prepend (accounts, account);
+
+ xaccQueryAddAccountMatch (query, accounts, QOF_GUID_MATCH_ANY, QOF_QUERY_AND);
+
+ g_list_free (accounts);
+
+ /* limit the matches to CREDITs and DEBITs only, depending on the type */
+ if (type == RECLIST_CREDIT)
+ xaccQueryAddValueMatch(query, gnc_numeric_zero (),
+ QOF_NUMERIC_MATCH_CREDIT,
+ QOF_COMPARE_GTE, QOF_QUERY_AND);
+ else
+ xaccQueryAddValueMatch(query, gnc_numeric_zero (),
+ QOF_NUMERIC_MATCH_DEBIT,
+ QOF_COMPARE_GTE, QOF_QUERY_AND);
+
+ /* limit the matches only to Cleared and Non-reconciled splits */
+ xaccQueryAddClearedMatch (query, CLEARED_NO | CLEARED_CLEARED, QOF_QUERY_AND);
+
+ /* Initialize the QueryList */
+ gnc_reconcile_view_construct (view, query);
+
+ /* find the list of splits to auto-reconcile */
+ auto_check = gnc_gconf_get_bool (GCONF_RECONCILE_SECTION,
+ "check_cleared", NULL);
+
+ if (auto_check)
+ {
+ for (splits = qof_query_run (query); splits; splits = splits->next)
+ {
+ Split *split = splits->data;
+ char recn = xaccSplitGetReconcile (split);
+ time_t trans_date = xaccTransGetDate (xaccSplitGetParent (split));
+
+ /* Just an extra verification that our query is correct ;) */
+ g_assert (recn == NREC || recn == CREC);
+
+ if (recn == CREC &&
+ difftime (trans_date, statement_date) <= 0)
+ g_hash_table_insert (view->reconciled, split, split);
+ }
+ }
+
+ /* Free the query -- we don't need it anymore */
+ qof_query_destroy (query);
+
+ return GTK_WIDGET (view);
+}
+
+
+static void
+gnc_reconcile_view_init (GNCReconcileView *view)
+{
+ GNCSearchParam *param;
+ GList *columns = NULL;
+
+ view->reconciled = g_hash_table_new (NULL, NULL);
+ view->account = NULL;
+ view->sibling = NULL;
+
+ param = gnc_search_param_new();
+ gnc_search_param_set_param_fcn (param, QOF_TYPE_BOOLEAN,
+ gnc_reconcile_view_is_reconciled, view);
+ gnc_search_param_set_title (param, _("Reconciled:R") + 11);
+ gnc_search_param_set_justify (param, GTK_JUSTIFY_CENTER);
+ gnc_search_param_set_passive (param, TRUE);
+ gnc_search_param_set_non_resizeable (param, TRUE);
+ columns = g_list_prepend (columns, param);
+ columns = gnc_search_param_prepend_with_justify (columns, _("Amount"),
+ GTK_JUSTIFY_RIGHT,
+ NULL, GNC_ID_SPLIT,
+ SPLIT_AMOUNT, NULL);
+ columns = gnc_search_param_prepend (columns, _("Description"), NULL,
+ GNC_ID_SPLIT, SPLIT_TRANS,
+ TRANS_DESCRIPTION, NULL);
+ columns = gnc_search_param_prepend_with_justify (columns, _("Num"),
+ GTK_JUSTIFY_CENTER,
+ NULL, GNC_ID_SPLIT,
+ SPLIT_TRANS, TRANS_NUM, NULL);
+ columns = gnc_search_param_prepend (columns, _("Date"), NULL, GNC_ID_SPLIT,
+ SPLIT_TRANS, TRANS_DATE_POSTED, NULL);
+
+ view->column_list = columns;
+}
+
+
+static void
+gnc_reconcile_view_class_init (GNCReconcileViewClass *klass)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+
+ parent_class = g_type_class_peek_parent (klass);
+
+ reconcile_view_signals[TOGGLE_RECONCILED] =
+ g_signal_new("toggle_reconciled",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GNCReconcileViewClass,
+ toggle_reconciled),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1,
+ G_TYPE_POINTER);
+
+ reconcile_view_signals[LINE_SELECTED] =
+ g_signal_new("line_selected",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GNCReconcileViewClass,
+ line_selected),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1,
+ G_TYPE_POINTER);
+
+ reconcile_view_signals[DOUBLE_CLICK_SPLIT] =
+ g_signal_new("double_click_split",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GNCReconcileViewClass,
+ double_click_split),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1,
+ G_TYPE_POINTER);
+
+ object_class->finalize = gnc_reconcile_view_finalize;
+
+ klass->toggle_reconciled = NULL;
+ klass->line_selected = NULL;
+ klass->double_click_split = NULL;
+}
+
+
+static void
+gnc_reconcile_view_toggle_split (GNCReconcileView *view, Split *split)
+{
+ Split *current;
+
+ g_return_if_fail (GNC_IS_RECONCILE_VIEW (view));
+ g_return_if_fail (view->reconciled != NULL);
+
+ current = g_hash_table_lookup (view->reconciled, split);
+
+ if (current == NULL)
+ g_hash_table_insert (view->reconciled, split, split);
+ else
+ g_hash_table_remove (view->reconciled, split);
+}
+
+
+static void
+gnc_reconcile_view_toggle_children (Account *account, GNCReconcileView *view, Split *split)
+{
+ GList *child_accounts, *node;
+ Transaction *transaction;
+
+ /*
+ * Need to get all splits in this transaction and identify any that are
+ * in the same heirarchy as the account being reconciled (not necessarily
+ * the account this split is from.)
+ *
+ * For each of these splits toggle them all to the same state.
+ */
+ child_accounts = gnc_account_get_descendants (account);
+ child_accounts = g_list_prepend (child_accounts, account);
+ transaction = xaccSplitGetParent (split);
+ for (node = xaccTransGetSplitList (transaction); node; node = node->next)
+ {
+ Split *other_split;
+ Account *other_account;
+ GNCReconcileView *current_view;
+
+ other_split = node->data;
+ other_account = xaccSplitGetAccount (other_split);
+ if (other_split == split)
+ continue;
+ /* Check this 'other' account in in the same heirarchy */
+ if (!g_list_find (child_accounts, other_account))
+ continue;
+ /* Search our sibling view for this split first. We search the
+ * sibling list first because that it where it is most likely to be.
+ */
+ current_view = view->sibling;
+ if (!gnc_query_view_item_in_view (GNC_QUERY_VIEW (current_view), other_split))
+ {
+ /* Not in the sibling view, try this view */
+ current_view = view;
+ if (!gnc_query_view_item_in_view (GNC_QUERY_VIEW (current_view), other_split))
+ /* We can't find it, nothing more I can do about it */
+ continue;
+ }
+ gnc_reconcile_view_toggle_split (current_view, other_split);
+ }
+ g_list_free (child_accounts);
+}
+
+
+static void
+gnc_reconcile_view_toggle (GNCReconcileView *view, Split *split)
+{
+ gboolean include_children;
+
+ g_return_if_fail (GNC_IS_RECONCILE_VIEW (view));
+ g_return_if_fail (view->reconciled != NULL);
+
+ gnc_reconcile_view_toggle_split (view, split);
+
+ include_children = xaccAccountGetReconcileChildrenStatus (view->account);
+ if (include_children)
+ gnc_reconcile_view_toggle_children (view->account, view, split);
+
+ g_signal_emit (G_OBJECT (view),
+ reconcile_view_signals[TOGGLE_RECONCILED], 0, split);
+}
+
+
+static void
+gnc_reconcile_view_line_toggled (GNCQueryView *qview,
+ gpointer item,
+ gpointer user_data)
+{
+ GNCReconcileView *view;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gpointer entry;
+
+ g_return_if_fail (user_data);
+ g_return_if_fail (GNC_IS_QUERY_VIEW (qview));
+
+ view = user_data;
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (qview));
+ gtk_tree_model_iter_nth_child (model, &iter, NULL, qview->toggled_row);
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter, qview->toggled_column, GPOINTER_TO_INT(item), -1);
+ gtk_tree_model_get (model, &iter, 0, &entry, -1);
+
+ gnc_reconcile_view_toggle (view, entry);
+}
+
+
+static void
+gnc_reconcile_view_double_click_entry (GNCQueryView *qview,
+ gpointer item,
+ gpointer user_data)
+{
+ GNCReconcileView *view;
+
+ g_return_if_fail (user_data);
+ g_return_if_fail (GNC_IS_QUERY_VIEW (qview));
+
+ view = user_data;
+
+ g_signal_emit(G_OBJECT (view),
+ reconcile_view_signals[DOUBLE_CLICK_SPLIT], 0, item);
+}
+
+
+static void
+gnc_reconcile_view_row_selected (GNCQueryView *qview,
+ gpointer item,
+ gpointer user_data)
+{
+ GNCReconcileView *view;
+
+ g_return_if_fail(user_data);
+ g_return_if_fail(GNC_IS_QUERY_VIEW(qview));
+
+ view = user_data;
+
+ g_signal_emit(G_OBJECT(view),
+ reconcile_view_signals[LINE_SELECTED], 0, item);
+}
+
+
+static void
+gnc_reconcile_view_finalize (GObject *object)
+{
+ GNCReconcileView *view = GNC_RECONCILE_VIEW (object);
+
+ if (view->reconciled != NULL)
+ {
+ g_hash_table_destroy (view->reconciled);
+ view->reconciled = NULL;
+ }
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+
+gint
+gnc_reconcile_view_get_num_splits (GNCReconcileView *view)
+{
+ g_return_val_if_fail (view != NULL, 0);
+ g_return_val_if_fail (GNC_IS_RECONCILE_VIEW (view), 0);
+
+ return gnc_query_view_get_num_entries (GNC_QUERY_VIEW (view));
+}
+
+
+Split *
+gnc_reconcile_view_get_current_split (GNCReconcileView *view)
+{
+ g_return_val_if_fail (view != NULL, NULL);
+ g_return_val_if_fail (GNC_IS_RECONCILE_VIEW (view), NULL);
+
+ return gnc_query_view_get_selected_entry (GNC_QUERY_VIEW (view));
+}
+
+
+/********************************************************************\
+ * gnc_reconcile_view_is_reconciled *
+ * Is the item a reconciled split? *
+ * *
+ * Args: item - the split to be checked *
+ * user_data - a pointer to the GNCReconcileView *
+ * Returns: whether the split is to be reconciled. *
+\********************************************************************/
+static gpointer
+gnc_reconcile_view_is_reconciled (gpointer item, gpointer user_data)
+{
+ GNCReconcileView *view = user_data;
+ Split *current;
+
+ g_return_val_if_fail (item, NULL);
+ g_return_val_if_fail (view, NULL);
+ g_return_val_if_fail (GNC_IS_RECONCILE_VIEW (view), NULL);
+
+ if (!view->reconciled)
+ return NULL;
+
+ current = g_hash_table_lookup (view->reconciled, item);
+ return GINT_TO_POINTER (current != NULL);
+}
+
+
+/********************************************************************\
+ * gnc_reconcile_view_refresh *
+ * refreshes the view *
+ * *
+ * Args: view - view to refresh *
+ * Returns: nothing *
+\********************************************************************/
+static void
+grv_refresh_helper (gpointer key, gpointer value, gpointer user_data)
+{
+ GNCReconcileView *view = user_data;
+ GNCQueryView *qview = GNC_QUERY_VIEW (view);
+
+ if (!gnc_query_view_item_in_view (qview, key))
+ g_hash_table_remove (view->reconciled, key);
+}
+
+void
+gnc_reconcile_view_refresh (GNCReconcileView *view)
+{
+ GNCQueryView *qview;
+
+ g_return_if_fail (view != NULL);
+ g_return_if_fail (GNC_IS_RECONCILE_VIEW (view));
+
+ qview = GNC_QUERY_VIEW (view);
+ gnc_query_view_refresh (qview);
+
+ /* Now verify that everything in the reconcile hash is still in qview */
+ if (view->reconciled)
+ g_hash_table_foreach (view->reconciled, grv_refresh_helper, view);
+}
+
+
+/********************************************************************\
+ * gnc_reconcile_view_reconciled_balance *
+ * returns the reconciled balance of the view *
+ * *
+ * Args: view - view to get reconciled balance of *
+ * Returns: reconciled balance (gnc_numeric) *
+\********************************************************************/
+static void
+grv_balance_hash_helper (gpointer key, gpointer value, gpointer user_data)
+{
+ Split *split = key;
+ gnc_numeric *total = user_data;
+
+ *total = gnc_numeric_add_fixed (*total, xaccSplitGetAmount (split));
+}
+
+gnc_numeric
+gnc_reconcile_view_reconciled_balance (GNCReconcileView *view)
+{
+ gnc_numeric total = gnc_numeric_zero ();
+
+ g_return_val_if_fail (view != NULL, total);
+ g_return_val_if_fail (GNC_IS_RECONCILE_VIEW (view), total);
+
+ if (view->reconciled == NULL)
+ return total;
+
+ g_hash_table_foreach (view->reconciled, grv_balance_hash_helper, &total);
+
+ return gnc_numeric_abs (total);
+}
+
+
+/********************************************************************\
+ * gnc_reconcile_view_commit *
+ * Commit the reconcile information in the view. Only change the *
+ * state of those items marked as reconciled. All others should *
+ * retain their previous state (none, cleared, voided, etc.). *
+ * *
+ * Args: view - view to commit *
+ * date - date to set as the reconcile date *
+ * Returns: nothing *
+\********************************************************************/
+static void
+grv_commit_hash_helper (gpointer key, gpointer value, gpointer user_data)
+{
+ Split *split = key;
+ time_t *date = user_data;
+
+ xaccSplitSetReconcile (split, YREC);
+ xaccSplitSetDateReconciledSecs (split, *date);
+}
+
+void
+gnc_reconcile_view_commit (GNCReconcileView *view, time_t date)
+{
+ g_return_if_fail (view != NULL);
+ g_return_if_fail (GNC_IS_RECONCILE_VIEW (view));
+
+ if (view->reconciled == NULL)
+ return;
+
+ gnc_suspend_gui_refresh();
+ g_hash_table_foreach (view->reconciled, grv_commit_hash_helper, &date);
+ gnc_resume_gui_refresh();
+}
+
+
+/********************************************************************\
+ * gnc_reconcile_view_postpone *
+ * postpone the reconcile information in the view by setting *
+ * reconciled splits to cleared status *
+ * *
+ * Args: view - view to commit *
+ * Returns: nothing *
+\********************************************************************/
+void
+gnc_reconcile_view_postpone (GNCReconcileView *view)
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ int num_splits;
+ int i;
+ gpointer entry = NULL;
+
+ g_return_if_fail (view != NULL);
+ g_return_if_fail (GNC_IS_RECONCILE_VIEW (view));
+
+ if (view->reconciled == NULL)
+ return;
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (GNC_QUERY_VIEW (view)));
+ gtk_tree_model_get_iter_first (model, &iter);
+
+ num_splits = gnc_query_view_get_num_entries (GNC_QUERY_VIEW (view));
+
+ gnc_suspend_gui_refresh();
+ for (i = 0; i < num_splits; i++)
+ {
+ char recn;
+
+ gtk_tree_model_get (model, &iter, 0, &entry, -1);
+
+ // Don't change splits past reconciliation date that haven't been
+ // set to be reconciled
+ if ( difftime(view->statement_date,
+ xaccTransGetDate (xaccSplitGetParent (entry))) >= 0 ||
+ g_hash_table_lookup (view->reconciled, entry))
+ {
+ recn = g_hash_table_lookup (view->reconciled, entry) ? CREC : NREC;
+ xaccSplitSetReconcile (entry, recn);
+ }
+ gtk_tree_model_iter_next (model, &iter);
+ }
+ gnc_resume_gui_refresh();
+}
+
+
+/********************************************************************\
+ * gnc_reconcile_view_unselect_all *
+ * unselect all splits in the view *
+ * *
+ * Args: view - view to unselect all *
+ * Returns: nothing *
+\********************************************************************/
+void
+gnc_reconcile_view_unselect_all(GNCReconcileView *view)
+{
+ g_return_if_fail (view != NULL);
+ g_return_if_fail (GNC_IS_RECONCILE_VIEW (view));
+
+ gnc_query_view_unselect_all (GNC_QUERY_VIEW (view));
+}
+
+
+/********************************************************************\
+ * gnc_reconcile_view_changed *
+ * returns true if any splits have been reconciled *
+ * *
+ * Args: view - view to get changed status for *
+ * Returns: true if any reconciled splits *
+\********************************************************************/
+gboolean
+gnc_reconcile_view_changed (GNCReconcileView *view)
+{
+ g_return_val_if_fail (view != NULL, FALSE);
+ g_return_val_if_fail (GNC_IS_RECONCILE_VIEW (view), FALSE);
+
+ return g_hash_table_size (view->reconciled) != 0;
+}
+
Added: gnucash/trunk/src/gnome/reconcile-view.h
===================================================================
--- gnucash/trunk/src/gnome/reconcile-view.h (rev 0)
+++ gnucash/trunk/src/gnome/reconcile-view.h 2012-08-07 18:24:13 UTC (rev 22292)
@@ -0,0 +1,101 @@
+/********************************************************************\
+ * reconcile-view.h -- GNOME reconcile view functions *
+ * Copyright (C) 1998,1999 Linas Vepstas *
+ * Copyright (C) 2003 Derek Atkins <derek at ihtfp.com> *
+ * Copyright (C) 2012 Robert Fewell *
+ * *
+ * 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 GNC_RECONCILE_VIEW_H
+#define GNC_RECONCILE_VIEW_H
+
+#include "gnc-query-view.h"
+#include "qof.h"
+
+G_BEGIN_DECLS
+
+#define GNC_TYPE_RECONCILE_VIEW (gnc_reconcile_view_get_type ())
+#define GNC_RECONCILE_VIEW(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_RECONCILE_VIEW, GNCReconcileView))
+#define GNC_RECONCILE_VIEW_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GNC_TYPE_RECONCILE_VIEW, GNCReconcileViewClass))
+#define GNC_IS_RECONCILE_VIEW(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_RECONCILE_VIEW))
+#define GNC_IS_RECONCILE_VIEW_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_RECONCILE_VIEW))
+
+typedef struct GNCReconcileView GNCReconcileView;
+
+typedef enum
+{
+ RECLIST_DEBIT,
+ RECLIST_CREDIT
+} GNCReconcileViewType;
+
+struct GNCReconcileView
+{
+ GNCQueryView qview;
+
+ GHashTable *reconciled;
+ Account *account;
+ GList *column_list;
+
+ time_t statement_date;
+
+ GNCReconcileView *sibling;
+ GNCReconcileViewType view_type;
+ gboolean no_toggle;
+};
+
+typedef struct
+{
+ GtkTreeViewClass parent_class;
+
+ void (*toggle_reconciled) (GNCReconcileView *view, Split *split);
+ void (*line_selected) (GNCReconcileView *view, Split *split);
+ void (*double_click_split) (GNCReconcileView *view, Split *split);
+} GNCReconcileViewClass;
+
+#define GCONF_RECONCILE_SECTION "dialogs/reconcile"
+
+/***********************************************************
+ * public functions *
+ ***********************************************************/
+
+GType gnc_reconcile_view_get_type (void);
+
+GtkWidget * gnc_reconcile_view_new (Account * account,
+ GNCReconcileViewType type,
+ time_t date);
+
+gint gnc_reconcile_view_get_num_splits (GNCReconcileView *view);
+
+Split * gnc_reconcile_view_get_current_split (GNCReconcileView *view);
+
+void gnc_reconcile_view_refresh (GNCReconcileView *view);
+
+gnc_numeric gnc_reconcile_view_reconciled_balance (GNCReconcileView *view);
+
+void gnc_reconcile_view_commit (GNCReconcileView *view, time_t date);
+
+void gnc_reconcile_view_postpone (GNCReconcileView *view);
+
+void gnc_reconcile_view_unselect_all (GNCReconcileView *view);
+
+gboolean gnc_reconcile_view_changed (GNCReconcileView *view);
+
+G_END_DECLS
+
+#endif /* GNC_RECONCILE_VIEW_H */
Modified: gnucash/trunk/src/gnome/window-reconcile.c
===================================================================
--- gnucash/trunk/src/gnome/window-reconcile.c 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/src/gnome/window-reconcile.c 2012-08-07 18:24:13 UTC (rev 22292)
@@ -53,9 +53,10 @@
#include "gnc-ui.h"
#include "gnc-ui-balances.h"
#include "guile-util.h"
-#include "reconcile-list.h"
+#include "reconcile-view.h"
#include "window-reconcile.h"
+#define GCONF_SECTION "dialogs/window-reconcile"
#define WINDOW_RECONCILE_CM_CLASS "window-reconcile"
@@ -91,7 +92,7 @@
GtkWidget *debit_frame; /* Frame around debit matrix */
GtkWidget *credit_frame; /* Frame around credit matrix */
- gboolean delete_refresh; /* do a refresh upon a window deletion */
+ gboolean delete_refresh; /* do a refresh upon a window deletion */
};
@@ -148,11 +149,11 @@
static void recnCancelCB (GtkAction *action, gpointer data);
void gnc_start_recn_children_changed (GtkWidget *widget, startRecnWindowData *data);
-void gnc_start_recn_interest_clicked_cb(GtkButton *button, startRecnWindowData *data);
+void gnc_start_recn_interest_clicked_cb (GtkButton *button, startRecnWindowData *data);
-static void gnc_reconcile_window_set_sensitivity(RecnWindow *recnData);
-static char * gnc_recn_make_window_name(Account *account);
-static void gnc_recn_set_window_name(RecnWindow *recnData);
+static void gnc_reconcile_window_set_sensitivity (RecnWindow *recnData);
+static char * gnc_recn_make_window_name (Account *account);
+static void gnc_recn_set_window_name (RecnWindow *recnData);
static gboolean find_by_account (gpointer find_data, gpointer user_data);
@@ -186,8 +187,8 @@
if (recnData == NULL)
return;
- gnc_reconcile_list_refresh(GNC_RECONCILE_LIST(recnData->debit));
- gnc_reconcile_list_refresh(GNC_RECONCILE_LIST(recnData->credit));
+ gnc_reconcile_view_refresh(GNC_RECONCILE_VIEW(recnData->debit));
+ gnc_reconcile_view_refresh(GNC_RECONCILE_VIEW(recnData->credit));
gnc_reconcile_window_set_sensitivity(recnData);
@@ -270,11 +271,11 @@
if (reverse_balance)
ending = gnc_numeric_neg (ending);
- debit = gnc_reconcile_list_reconciled_balance
- (GNC_RECONCILE_LIST(recnData->debit));
+ debit = gnc_reconcile_view_reconciled_balance
+ (GNC_RECONCILE_VIEW(recnData->debit));
- credit = gnc_reconcile_list_reconciled_balance
- (GNC_RECONCILE_LIST(recnData->credit));
+ credit = gnc_reconcile_view_reconciled_balance
+ (GNC_RECONCILE_VIEW(recnData->credit));
/* Update the total debit and credit fields */
amount = xaccPrintAmount(debit, print_info);
@@ -811,15 +812,15 @@
gnc_reconcile_window_set_sensitivity(RecnWindow *recnData)
{
gboolean sensitive = FALSE;
- GNCReconcileList *list;
+ GNCReconcileView *view;
GtkAction *action;
- list = GNC_RECONCILE_LIST(recnData->debit);
- if (gnc_reconcile_list_get_current_split(list) != NULL)
+ view = GNC_RECONCILE_VIEW(recnData->debit);
+ if (gnc_reconcile_view_get_current_split(view) != NULL)
sensitive = TRUE;
- list = GNC_RECONCILE_LIST(recnData->credit);
- if (gnc_reconcile_list_get_current_split(list) != NULL)
+ view = GNC_RECONCILE_VIEW(recnData->credit);
+ if (gnc_reconcile_view_get_current_split(view) != NULL)
sensitive = TRUE;
action = gtk_action_group_get_action (recnData->action_group,
@@ -832,16 +833,24 @@
static void
-gnc_reconcile_window_list_cb(GNCReconcileList *list, Split *split,
+gnc_reconcile_window_list_cb(GNCReconcileView *view, Split *split,
gpointer data)
{
RecnWindow *recnData = data;
-
gnc_reconcile_window_set_sensitivity(recnData);
recnRecalculateBalance(recnData);
}
+static void
+gnc_reconcile_window_row_cb(GNCReconcileView *view, Split *split,
+ gpointer data)
+{
+ RecnWindow *recnData = data;
+ gnc_reconcile_window_set_sensitivity(recnData);
+}
+
+
/** Popup a contextual menu. This function ends up being called when
* the user right-clicks in the context of a window, or uses the
* keyboard context-menu request key combination (Shift-F10 by
@@ -912,18 +921,28 @@
GdkEventButton *event,
RecnWindow *recnData)
{
- GtkCList *this_list;
- gint row, column;
+ GNCQueryView *qview = GNC_QUERY_VIEW(widget);
+ GtkTreeModel *model;
+ GtkTreeSelection *selection;
+ GtkTreePath *path;
+ model = gtk_tree_view_get_model(GTK_TREE_VIEW(qview));
+
if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
{
- this_list = GTK_CLIST(widget);
- gtk_clist_get_selection_info(this_list, event->x, event->y, &row, &column);
- gtk_clist_select_row(this_list, row, column);
+
+ /* Get tree path for row that was clicked */
+ gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(qview),
+ (gint) event->x,
+ (gint) event->y,
+ &path, NULL, NULL, NULL);
+
+ selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(qview));
+ gtk_tree_selection_select_path(selection, path);
+ gtk_tree_path_free(path);
do_popup_menu(recnData, event);
return TRUE;
}
-
return FALSE;
}
@@ -949,7 +968,7 @@
static void
-gnc_reconcile_window_double_click_cb(GNCReconcileList *list, Split *split,
+gnc_reconcile_window_double_click_cb(GNCReconcileView *view, Split *split,
gpointer data)
{
RecnWindow *recnData = data;
@@ -971,18 +990,18 @@
gpointer data)
{
RecnWindow *recnData = data;
- GNCReconcileList *this_list, *other_list;
- GNCReconcileList *debit, *credit;
+ GNCReconcileView *this_view, *other_view;
+ GNCReconcileView *debit, *credit;
- this_list = GNC_RECONCILE_LIST(widget);
+ this_view = GNC_RECONCILE_VIEW(widget);
- debit = GNC_RECONCILE_LIST(recnData->debit);
- credit = GNC_RECONCILE_LIST(recnData->credit);
+ debit = GNC_RECONCILE_VIEW(recnData->debit);
+ credit = GNC_RECONCILE_VIEW(recnData->credit);
- other_list = GNC_RECONCILE_LIST(this_list == debit ? credit : debit);
+ other_view = GNC_RECONCILE_VIEW(this_view == debit ? credit : debit);
/* clear the *other* list so we always have no more than one selection */
- gnc_reconcile_list_unselect_all(other_list);
+ gnc_reconcile_view_unselect_all(other_view);
}
@@ -991,7 +1010,7 @@
gpointer data)
{
RecnWindow *recnData = data;
- GtkWidget *this_list, *other_list;
+ GtkWidget *this_view, *other_view;
GtkWidget *debit, *credit;
switch (event->keyval)
@@ -1006,14 +1025,14 @@
g_signal_stop_emission_by_name (widget, "key_press_event");
- this_list = widget;
+ this_view = widget;
debit = recnData->debit;
credit = recnData->credit;
- other_list = (this_list == debit ? credit : debit);
+ other_view = (this_view == debit ? credit : debit);
- gtk_widget_grab_focus (other_list);
+ gtk_widget_grab_focus (other_view);
return TRUE;
}
@@ -1050,13 +1069,13 @@
static GtkWidget *
-gnc_reconcile_window_create_list_box(Account *account,
- GNCReconcileListType type,
+gnc_reconcile_window_create_view_box(Account *account,
+ GNCReconcileViewType type,
RecnWindow *recnData,
GtkWidget **list_save,
GtkWidget **total_save)
{
- GtkWidget *frame, *scrollWin, *list, *vbox, *label, *hbox;
+ GtkWidget *frame, *scrollWin, *view, *vbox, *label, *hbox;
frame = gtk_frame_new(NULL);
@@ -1067,22 +1086,25 @@
vbox = gtk_vbox_new(FALSE, 5);
- list = gnc_reconcile_list_new(account, type, recnData->statement_date);
- *list_save = list;
+ view = gnc_reconcile_view_new(account, type, recnData->statement_date);
+ *list_save = view;
- g_signal_connect(list, "toggle_reconciled",
+ g_signal_connect(view, "toggle_reconciled",
G_CALLBACK(gnc_reconcile_window_list_cb),
recnData);
- g_signal_connect(list, "button_press_event",
+ g_signal_connect(view, "line_selected",
+ G_CALLBACK(gnc_reconcile_window_row_cb),
+ recnData);
+ g_signal_connect(view, "button_press_event",
G_CALLBACK(gnc_reconcile_window_button_press_cb),
recnData);
- g_signal_connect(list, "double_click_split",
+ g_signal_connect(view, "double_click_split",
G_CALLBACK(gnc_reconcile_window_double_click_cb),
recnData);
- g_signal_connect(list, "focus_in_event",
+ g_signal_connect(view, "focus_in_event",
G_CALLBACK(gnc_reconcile_window_focus_cb),
recnData);
- g_signal_connect(list, "key_press_event",
+ g_signal_connect(view, "key_press_event",
G_CALLBACK(gnc_reconcile_key_press_cb),
recnData);
@@ -1093,7 +1115,7 @@
gtk_container_set_border_width(GTK_CONTAINER(scrollWin), 5);
gtk_container_add(GTK_CONTAINER(frame), scrollWin);
- gtk_container_add(GTK_CONTAINER(scrollWin), list);
+ gtk_container_add(GTK_CONTAINER(scrollWin), view);
gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
hbox = gtk_hbox_new(FALSE, 5);
@@ -1114,16 +1136,16 @@
static Split *
gnc_reconcile_window_get_current_split(RecnWindow *recnData)
{
- GNCReconcileList *list;
+ GNCReconcileView *view;
Split *split;
- list = GNC_RECONCILE_LIST(recnData->debit);
- split = gnc_reconcile_list_get_current_split(list);
+ view = GNC_RECONCILE_VIEW(recnData->debit);
+ split = gnc_reconcile_view_get_current_split(view);
if (split != NULL)
return split;
- list = GNC_RECONCILE_LIST(recnData->credit);
- split = gnc_reconcile_list_get_current_split(list);
+ view = GNC_RECONCILE_VIEW(recnData->credit);
+ split = gnc_reconcile_view_get_current_split(view);
return split;
}
@@ -1558,6 +1580,7 @@
{
RecnWindow *recnData = user_data;
+ gnc_save_window_size(GCONF_SECTION, GTK_WINDOW(recnData->window));
gtk_widget_destroy (recnData->window);
}
@@ -1733,7 +1756,6 @@
g_signal_connect (recnData->window, "key_press_event",
G_CALLBACK(recn_key_press_cb), recnData);
-
/* The main area */
{
GtkWidget *frame = gtk_frame_new(NULL);
@@ -1742,24 +1764,25 @@
GtkWidget *debits_box;
GtkWidget *credits_box;
- gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 10);
/* Force a reasonable starting size */
gtk_window_set_default_size(GTK_WINDOW(recnData->window), 800, 600);
+ gnc_restore_window_size (GCONF_SECTION, GTK_WINDOW(recnData->window));
gtk_container_add(GTK_CONTAINER(frame), main_area);
gtk_container_set_border_width(GTK_CONTAINER(main_area), 10);
- debits_box = gnc_reconcile_window_create_list_box
+ debits_box = gnc_reconcile_window_create_view_box
(account, RECLIST_DEBIT, recnData,
&recnData->debit, &recnData->total_debit);
- credits_box = gnc_reconcile_window_create_list_box
+ credits_box = gnc_reconcile_window_create_view_box
(account, RECLIST_CREDIT, recnData,
&recnData->credit, &recnData->total_credit);
- GNC_RECONCILE_LIST(recnData->debit)->sibling = GNC_RECONCILE_LIST(recnData->credit);
- GNC_RECONCILE_LIST(recnData->credit)->sibling = GNC_RECONCILE_LIST(recnData->debit);
+ GNC_RECONCILE_VIEW(recnData->debit)->sibling = GNC_RECONCILE_VIEW(recnData->credit);
+ GNC_RECONCILE_VIEW(recnData->credit)->sibling = GNC_RECONCILE_VIEW(recnData->debit);
gtk_box_pack_start(GTK_BOX(main_area), debcred_area, TRUE, TRUE, 0);
gtk_table_set_col_spacings(GTK_TABLE(debcred_area), 15);
@@ -1844,28 +1867,6 @@
/* Set up the data */
recnRefresh (recnData);
-
- /* Clamp down on the size */
- {
- GNCReconcileList *rlist;
- gint height, num_debits, num_credits, num_show;
-
- num_credits = gnc_reconcile_list_get_num_splits
- (GNC_RECONCILE_LIST(recnData->credit));
- num_debits = gnc_reconcile_list_get_num_splits
- (GNC_RECONCILE_LIST(recnData->debit));
-
- num_show = MAX(num_debits, num_credits);
- num_show = MIN(num_show, 15);
- num_show = MAX(num_show, 8);
-
- gtk_widget_realize(recnData->credit);
- rlist = GNC_RECONCILE_LIST(recnData->credit);
- height = gnc_reconcile_list_get_needed_height(rlist, num_show);
-
- gtk_widget_set_size_request(recnData->credit, -1, height);
- gtk_widget_set_size_request(recnData->debit, -1, height);
- }
}
/* Allow resize */
@@ -1881,6 +1882,10 @@
gnc_window_adjust_for_screen(GTK_WINDOW(recnData->window));
+ /* Set the sort orders of the debit and credit tree views */
+ gnc_query_sort_order(GNC_QUERY_VIEW(recnData->debit), 1, GTK_SORT_ASCENDING);
+ gnc_query_sort_order(GNC_QUERY_VIEW(recnData->credit), 1, GTK_SORT_ASCENDING);
+
gtk_widget_grab_focus (recnData->debit);
return recnData;
@@ -1939,9 +1944,9 @@
{
gboolean changed = FALSE;
- if (gnc_reconcile_list_changed(GNC_RECONCILE_LIST(recnData->credit)))
+ if (gnc_reconcile_view_changed(GNC_RECONCILE_VIEW(recnData->credit)))
changed = TRUE;
- if (gnc_reconcile_list_changed(GNC_RECONCILE_LIST(recnData->debit)))
+ if (gnc_reconcile_view_changed(GNC_RECONCILE_VIEW(recnData->debit)))
changed = TRUE;
if (changed)
@@ -2076,8 +2081,8 @@
recnData->delete_refresh = TRUE;
- gnc_reconcile_list_commit(GNC_RECONCILE_LIST(recnData->credit), date);
- gnc_reconcile_list_commit(GNC_RECONCILE_LIST(recnData->debit), date);
+ gnc_reconcile_view_commit(GNC_RECONCILE_VIEW(recnData->credit), date);
+ gnc_reconcile_view_commit(GNC_RECONCILE_VIEW(recnData->debit), date);
auto_payment = gnc_gconf_get_bool(GCONF_RECONCILE_SECTION,
"auto_cc_payment", NULL);
@@ -2132,8 +2137,8 @@
recnData->delete_refresh = TRUE;
- gnc_reconcile_list_postpone (GNC_RECONCILE_LIST(recnData->credit));
- gnc_reconcile_list_postpone (GNC_RECONCILE_LIST(recnData->debit));
+ gnc_reconcile_view_postpone (GNC_RECONCILE_VIEW(recnData->credit));
+ gnc_reconcile_view_postpone (GNC_RECONCILE_VIEW(recnData->debit));
account = recn_get_account (recnData);
Modified: gnucash/trunk/src/gnome/window-reconcile.h
===================================================================
--- gnucash/trunk/src/gnome/window-reconcile.h 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/src/gnome/window-reconcile.h 2012-08-07 18:24:13 UTC (rev 22292)
@@ -65,4 +65,4 @@
void gnc_ui_reconcile_window_raise(RecnWindow * recnData);
-#endif
+#endif /* WINDOW_RECONCILE_H */
Modified: gnucash/trunk/src/gnome-search/dialog-search.c
===================================================================
--- gnucash/trunk/src/gnome-search/dialog-search.c 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/src/gnome-search/dialog-search.c 2012-08-07 18:24:13 UTC (rev 22292)
@@ -33,7 +33,7 @@
#include "gnc-ui-util.h"
#include "gnc-ui.h"
#include "gnc-gui-query.h"
-#include "gnc-query-list.h"
+#include "gnc-query-view.h"
#include "gnc-gconf-utils.h"
#include "gnc-session.h"
#include "qof.h"
@@ -72,7 +72,7 @@
GtkWidget *result_hbox;
/* The "results" sub-window widgets */
- GtkWidget *result_list;
+ GtkWidget *result_view;
gpointer selected_item;
GList *selected_item_list;
@@ -85,6 +85,7 @@
/* The Select button */
GtkWidget *select_button;
+ GList *button_list;
/* The close/cancel buttons */
GtkWidget *close_button;
@@ -117,7 +118,7 @@
GList *params_list; /* List of GNCSearchParams */
GList *display_list; /* List of GNCSearchParams for Display */
gint num_cols; /* Number of Display Columns */
- GList *crit_list; /* list of crit_data */
+ GList *crit_list; /* List of crit_data */
gint component_id;
const gchar *gconf_section;
@@ -136,47 +137,30 @@
static void search_clear_criteria (GNCSearchWindow *sw);
static void gnc_search_dialog_display_results (GNCSearchWindow *sw);
-/** The callback for converting the row numbers from a GTree to actual item
-pointers in a GList */
-static void cb_tree_to_itemlist (gpointer element,
- gpointer user_data)
-{
- GNCSearchWindow *sw = user_data;
- gint row_number = GPOINTER_TO_INT(element);
- gpointer item = gtk_clist_get_row_data (GTK_CLIST(sw->result_list), row_number);
- sw->selected_item_list = g_list_prepend(sw->selected_item_list, item);
-}
-
static void
gnc_search_callback_button_execute (GNCSearchCallbackButton *cb,
GNCSearchWindow *sw)
{
- GNCQueryList* gql = GNC_QUERY_LIST(sw->result_list);
- GtkCList* clist;
+ GNCQueryView *qview = GNC_QUERY_VIEW(sw->result_view);
+ GtkTreeSelection *selection;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
// Sanity check
- g_assert(gql);
- clist = &gql->clist;
- g_assert(clist->selection_mode == GTK_SELECTION_MULTIPLE);
+ g_assert(qview);
+ selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(qview));
+ g_assert(gtk_tree_selection_get_mode(selection) == GTK_SELECTION_MULTIPLE);
+ selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(qview));
- // Do we have a callback for multi-selections, and also more than one selected item?
- if (cb->cb_multiselect_fn && (!cb->cb_fcn || g_list_length(clist->selection) > 1))
+ /* Do we have a callback for multi-selections ? */
+ if (cb->cb_multiselect_fn && (!cb->cb_fcn ))
{
- GList *selected_rows_list = clist->selection;
- // Yes, use the multi-selection callback
-
- // Obtain the GncInvoice pointer for each selected row
- sw->selected_item_list = NULL;
- g_list_foreach(selected_rows_list, cb_tree_to_itemlist, sw);
+ /* We have allready populated the selected_item_list from the select row callback */
// We use g_list_prepend (for performance reasons), so we have to reverse once here
sw->selected_item_list = g_list_reverse(sw->selected_item_list);
// Call the callback
(cb->cb_multiselect_fn)(sw->selected_item_list, sw->user_data);
-
- // And clean up again
- g_list_free(sw->selected_item_list);
- sw->selected_item_list = NULL;
}
else
{
@@ -198,6 +182,50 @@
static void
+gnc_search_dialog_select_buttons_enable (GNCSearchWindow *sw, gint selected)
+{
+ gint i;
+ gboolean enable, read_only;
+ GList *blist;
+
+ read_only = qof_book_is_readonly (gnc_get_current_book ());
+
+ for (blist = sw->button_list; blist; blist = blist->next)
+ {
+ GNCSearchCallbackButton *button_spec = g_object_get_data (G_OBJECT(blist->data) , "data");
+
+ if(selected == 0)
+ {
+ gtk_widget_set_sensitive (GTK_WIDGET(blist->data), FALSE);
+ continue;
+ }
+
+ if(read_only == TRUE)
+ {
+ if((selected > 1) && (!(button_spec->cb_multiselect_fn == NULL)) && (button_spec->sensitive_if_readonly == TRUE))
+ enable = TRUE;
+ else
+ enable = FALSE;
+
+ if((selected == 1) && (button_spec->sensitive_if_readonly == TRUE))
+ enable = TRUE;
+ }
+ else
+ {
+ if((selected > 1) && (!(button_spec->cb_multiselect_fn == NULL)))
+ enable = TRUE;
+ else
+ enable = FALSE;
+
+ if(selected == 1)
+ enable = TRUE;
+ }
+ gtk_widget_set_sensitive (GTK_WIDGET(blist->data), enable);
+ }
+}
+
+
+static void
gnc_search_dialog_select_cb (GtkButton *button, GNCSearchWindow *sw)
{
g_return_if_fail (sw->selected_cb);
@@ -213,91 +241,71 @@
gnc_search_dialog_destroy (sw);
}
-#if 0
+
static void
-gnc_search_dialog_line_toggled (GNCQueryList *list, gpointer item,
- gpointer user_data)
+gnc_search_dialog_select_row_cb (GNCQueryView *qview,
+ gpointer item,
+ gpointer user_data)
{
- GNCSearchWindow *sw = user_data;
- if (sw->selected_item == item)
- sw->selected_item = NULL;
+ GNCSearchWindow *sw = user_data;
+ gint number_of_rows;
+
+ sw->selected_item_list = NULL;
+ sw->selected_item = NULL;
+
+ number_of_rows = GPOINTER_TO_INT(item);
+
+ gnc_search_dialog_select_buttons_enable(sw, number_of_rows);
+
+ if(number_of_rows == 1)
+ {
+ sw->selected_item = qview->selected_entry;
+ sw->selected_item_list = qview->selected_entry_list;
+ }
else
- sw->selected_item = item;
+ sw->selected_item_list = qview->selected_entry_list;
}
+
static void
-gnc_search_dialog_double_click_entry (GNCQueryList *list, gpointer item,
- gpointer user_data)
+gnc_search_dialog_double_click_cb (GNCQueryView *qview,
+ gpointer item,
+ gpointer user_data)
{
- GNCSearchWindow *sw = user_data;
+ GNCSearchWindow *sw = user_data;
- /* Force the selected item */
sw->selected_item = item;
-
- /* If we double-click an item, then either "select" it, or run it
- * through the first button (which should be view/edit
- */
if (sw->selected_cb)
- /* Select the time */
+ /* Select the item */
gnc_search_dialog_select_cb (NULL, sw);
else if (sw->buttons)
/* Call the first button (usually view/edit) */
gnc_search_callback_button_execute (sw->buttons, sw);
-}
-#endif
-
-static void
-gnc_search_dialog_select_row_cb (GtkCList *clist, gint row, gint column,
- GdkEventButton *event, gpointer user_data)
-{
- GNCSearchWindow *sw = user_data;
- sw->selected_item = gtk_clist_get_row_data (clist, row);
- //g_message("select-row, row=%d", row);
-
- /* If we double-click an item, then either "select" it, or run it
- * through the first button (which should be view/edit
- */
- if (event && event->type == GDK_2BUTTON_PRESS)
- {
- if (sw->selected_cb)
- /* Select the time */
- gnc_search_dialog_select_cb (NULL, sw);
- else if (sw->buttons)
- /* Call the first button (usually view/edit) */
- gnc_search_callback_button_execute (sw->buttons, sw);
-
- /* If we get here, then nothing to do for a double-click */
- }
+ /* If we get here, then nothing to do for a double-click */
}
static void
-gnc_search_dialog_unselect_row_cb (GtkCList *clist, gint row, gint column,
- GdkEventButton *event, gpointer user_data)
+gnc_search_dialog_init_result_view (GNCSearchWindow *sw)
{
- GNCSearchWindow *sw = user_data;
- gpointer item = gtk_clist_get_row_data (clist, row);
- //g_message("unselect-row, row=%d", row);
+ GtkTreeSelection *selection;
- if (sw->selected_item == item)
- sw->selected_item = NULL;
-}
+ sw->result_view = gnc_query_view_new(sw->display_list, sw->q);
+ // We want the multi-selection mode of the tree view.
+ selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(sw->result_view));
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
-static void
-gnc_search_dialog_init_result_list (GNCSearchWindow *sw)
-{
- sw->result_list = gnc_query_list_new(sw->display_list, sw->q);
+ /* Set the sort order of the tree view */
+ gnc_query_sort_order(GNC_QUERY_VIEW(sw->result_view), 1, GTK_SORT_ASCENDING);
- // We want the multi-selection mode of GtkCList.
- gtk_clist_set_selection_mode(&GNC_QUERY_LIST(sw->result_list)->clist, GTK_SELECTION_MULTIPLE);
-
/* Setup the list callbacks */
- g_signal_connect (G_OBJECT (sw->result_list), "select-row",
+ g_signal_connect (GNC_QUERY_VIEW(sw->result_view), "row_selected",
G_CALLBACK (gnc_search_dialog_select_row_cb), sw);
- g_signal_connect (G_OBJECT (sw->result_list), "unselect-row",
- G_CALLBACK (gnc_search_dialog_unselect_row_cb), sw);
+
+ g_signal_connect (GNC_QUERY_VIEW(sw->result_view), "double_click_entry",
+ G_CALLBACK(gnc_search_dialog_double_click_cb), sw);
}
@@ -307,23 +315,26 @@
gdouble max_count;
/* Check if this is the first time this is called for this window.
- * If so, then build the results sub-window, the scrolled listbox,
+ * If so, then build the results sub-window, the scrolled treeview,
* and the active buttons.
*/
- if (sw->result_list == NULL)
+ if (sw->result_view == NULL)
{
- GtkWidget *scroller, *button_box, *button;
+ GtkWidget *scroller, *frame, *button_box, *button;
- /* Create the list */
- gnc_search_dialog_init_result_list (sw);
+ /* Create the view */
+ gnc_search_dialog_init_result_view (sw);
- /* Create the scroller and add the list to the scroller */
+ frame = gtk_frame_new(NULL);
+
+ /* Create the scroller and add the view to the scroller */
scroller = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroller),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_widget_set_size_request(GTK_WIDGET(scroller), 300, 100);
- gtk_container_add (GTK_CONTAINER (scroller), sw->result_list);
+ gtk_container_add (GTK_CONTAINER (scroller), sw->result_view);
+ gtk_container_add(GTK_CONTAINER(frame), scroller);
/* Create the button_box */
button_box = gtk_vbox_new (FALSE, 3);
@@ -344,34 +355,41 @@
GNCSearchCallbackButton* button_spec = sw->buttons + i;
button = gtk_button_new_with_label (_(button_spec->label));
g_object_set_data (G_OBJECT (button), "data", button_spec);
+
if (qof_book_is_readonly (gnc_get_current_book ()))
- {
gtk_widget_set_sensitive (GTK_WIDGET(button), button_spec->sensitive_if_readonly);
- }
+
+ /* Save the button pointer */
+ sw->button_list = g_list_append(sw->button_list, button);
+
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (gnc_search_dialog_result_clicked), sw);
gtk_box_pack_start (GTK_BOX (button_box), button, FALSE, FALSE, 3);
}
}
- /* Add the scrolled-list and button-box to the results_box */
+ /* Add the scrolled-view and button-box to the results_box */
gtk_box_pack_end (GTK_BOX (sw->result_hbox), button_box, FALSE, FALSE, 3);
- gtk_box_pack_end (GTK_BOX (sw->result_hbox), scroller, TRUE, TRUE, 3);
+ gtk_box_pack_end (GTK_BOX (sw->result_hbox), frame, TRUE, TRUE, 3);
/* And show the results */
gtk_widget_show_all (sw->result_hbox);
- /* But maybe hide the select button */
+ /* But may be hide the select button */
if (!sw->selected_cb)
gtk_widget_hide (sw->select_button);
}
+ else
+ /* Update the query in the view */
+ gnc_query_view_reset_query (GNC_QUERY_VIEW(sw->result_view), sw->q);
- /* Update the query in the list */
- gnc_query_list_reset_query (GNC_QUERY_LIST(sw->result_list), sw->q);
+ /* Deselect all the select buttons and any items */
+ gnc_search_dialog_select_buttons_enable (sw, 0);
+ gnc_query_view_unselect_all (GNC_QUERY_VIEW(sw->result_view));
/* set 'new search' if fewer than max_count items is returned. */
max_count = gnc_gconf_get_float("dialogs/search", "new_search_limit", NULL);
- if (gnc_query_list_get_num_entries(GNC_QUERY_LIST(sw->result_list)) < max_count)
+ if (gnc_query_view_get_num_entries(GNC_QUERY_VIEW(sw->result_view)) < max_count)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (sw->new_rb), TRUE);
}
@@ -824,9 +842,7 @@
gtk_widget_set_sensitive(sw->grouping_combo, TRUE);
gtk_widget_hide(sw->match_all_label);
}
-
/* create a new criterion element */
-
new = gnc_search_core_type_new_type_name
(gnc_search_param_get_param_type (sw->last_param));
@@ -864,9 +880,12 @@
gnc_unregister_gui_component (sw->component_id);
- /* XXX: Clear the params_list? */
+ /* Clear the crit list */
g_list_free (sw->crit_list);
+ /* Clear the button list */
+ g_list_free (sw->button_list);
+
/* Destroy the queries */
if (sw->q) qof_query_destroy (sw->q);
if (sw->start_q) qof_query_destroy (sw->start_q);
@@ -1029,7 +1048,6 @@
g_signal_connect (sw->active_only_check, "toggled",
G_CALLBACK (search_active_only_cb), sw);
-
/* Figure out if we this object-type has an "active" parameter, and
* if not, then set the active-check button insensitive
*/
Modified: gnucash/trunk/src/gnome-search/dialog-search.h
===================================================================
--- gnucash/trunk/src/gnome-search/dialog-search.h 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/src/gnome-search/dialog-search.h 2012-08-07 18:24:13 UTC (rev 22292)
@@ -21,8 +21,8 @@
* Boston, MA 02110-1301, USA gnu at gnu.org
*/
-#ifndef _GNC_DIALOG_SEARCH_H
-#define _GNC_DIALOG_SEARCH_H
+#ifndef GNC_DIALOG_SEARCH_H
+#define GNC_DIALOG_SEARCH_H
#include "GNCId.h"
#include "qof.h"
@@ -72,14 +72,14 @@
typedef struct
{
- const char * label;
- GNCSearchCallback cb_fcn;
- GNCSearchMultiSelectedCB cb_multiselect_fn;
+ const char *label;
+ GNCSearchCallback cb_fcn;
+ GNCSearchMultiSelectedCB cb_multiselect_fn;
/** TRUE if this action should be sensitive even in a read-only book. If
FALSE, this action is sensitive in read-write book but not in a read-only
book. */
- gboolean sensitive_if_readonly;
+ gboolean sensitive_if_readonly;
} GNCSearchCallbackButton;
/* Caller MUST supply _EITHER_ a result_callback or a list of callback
@@ -140,4 +140,4 @@
/* Test the dialog */
void gnc_search_dialog_test (void);
-#endif
+#endif /* GNC_DIALOG_SEARCH_H */
Modified: gnucash/trunk/src/gnome-utils/Makefile.am
===================================================================
--- gnucash/trunk/src/gnome-utils/Makefile.am 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/src/gnome-utils/Makefile.am 2012-08-07 18:24:13 UTC (rev 22292)
@@ -39,7 +39,7 @@
dialog-object-references.c \
dialog-options.c \
dialog-preferences.c \
- dialog-query-list.c \
+ dialog-query-view.c \
dialog-reset-warnings.c \
dialog-tax-table.c \
dialog-totd.c \
@@ -80,7 +80,7 @@
gnc-plugin-page.c \
gnc-plugin.c \
gnc-period-select.c \
- gnc-query-list.c \
+ gnc-query-view.c \
gnc-splash.c \
gnc-sx-instance-dense-cal-adapter.c \
gnc-sx-list-tree-model-adapter.c \
@@ -121,7 +121,7 @@
dialog-preferences.h \
dialog-object-references.h \
dialog-options.h \
- dialog-query-list.h \
+ dialog-query-view.h \
dialog-reset-warnings.h \
dialog-totd.h \
dialog-transfer.h \
@@ -157,7 +157,7 @@
gnc-plugin-page.h \
gnc-plugin.h \
gnc-period-select.h \
- gnc-query-list.h \
+ gnc-query-view.h \
gnc-splash.h \
gnc-sx-instance-dense-cal-adapter.h \
gnc-sx-list-tree-model-adapter.h \
Deleted: gnucash/trunk/src/gnome-utils/dialog-query-list.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-query-list.c 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/src/gnome-utils/dialog-query-list.c 2012-08-07 18:24:13 UTC (rev 22292)
@@ -1,325 +0,0 @@
-/*
- * dialog-query-list.c -- a simple dialog to display a querylist and
- * allow users to select items (or close the list)
- *
- * Created By: Derek Atkins <derek at ihtfp.com>
- * Copyright (c) 2003 Derek Atkins <warlord at MIT.EDU>
- *
- * 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 "qof.h"
-
-#include "dialog-utils.h"
-#include "gnc-component-manager.h"
-
-#include "dialog-query-list.h"
-#include "gnc-query-list.h"
-
-struct _DialogQueryList
-{
- GtkWidget * dialog;
- GtkWidget * label;
- GtkWidget * qlist;
- GtkWidget * button_box;
- GNCDisplayListButton * buttons;
- gpointer user_data;
- GList * books;
- gint component_id;
-};
-
-static void
-dql_clear_booklist (DialogQueryList *dql)
-{
- GList *node;
-
- g_return_if_fail (dql);
-
- for (node = dql->books; node; node = node->next)
- guid_free ((GncGUID*)node->data);
- g_list_free (dql->books);
- dql->books = NULL;
-}
-
-static void
-dql_build_booklist (DialogQueryList *dql, Query *q)
-{
- GList *node;
-
- g_return_if_fail (dql);
-
- for (node = qof_query_get_books(q); node; node = node->next)
- {
- QofBook *book = node->data;
- GncGUID *guid = guid_malloc();
- *guid = *(qof_book_get_guid(book));
- dql->books = g_list_prepend(dql->books, guid);
- }
-}
-
-static void
-gnc_dialog_query_run_callback (GNCDisplayListButton *cb, gpointer item,
- DialogQueryList *dql)
-{
- if (!cb)
- return;
-
- if (cb->cb_fcn)
- (cb->cb_fcn)(item, dql->user_data);
-}
-
-static void
-gnc_dialog_query_list_button_clicked (GtkButton *button, DialogQueryList *dql)
-{
- GNCDisplayListButton *cb;
- gpointer current;
-
- g_return_if_fail (dql);
- current = gnc_query_list_get_current_entry (GNC_QUERY_LIST (dql->qlist));
- if (!current)
- return;
-
- cb = g_object_get_data (G_OBJECT (button), "data");
- g_return_if_fail (cb);
-
- gnc_dialog_query_run_callback (cb, current, dql);
-}
-
-static void
-gnc_dialog_query_list_double_click_entry (GNCQueryList *list, gpointer item,
- gpointer user_data)
-{
- DialogQueryList *dql = user_data;
-
- g_return_if_fail (dql);
- g_return_if_fail (item);
-
- if (!dql->buttons)
- return;
-
- gnc_dialog_query_run_callback (dql->buttons, item, dql);
-}
-
-static int
-gnc_dialog_query_list_delete_cb (GtkDialog *dialog, GdkEvent *event, DialogQueryList *dql)
-{
- g_return_val_if_fail (dql, TRUE);
-
- gnc_unregister_gui_component (dql->component_id);
-
- /* XXX: Clear/destroy the param_list? */
-
- /* destroy the book list */
- dql_clear_booklist (dql);
-
- /* Destroy and exit */
- gtk_widget_destroy(dql->dialog);
- g_free (dql);
- return FALSE;
-}
-
-static void
-close_handler (gpointer data)
-{
- DialogQueryList * dql = data;
-
- g_return_if_fail (dql);
- gnc_dialog_query_list_delete_cb (GTK_DIALOG(dql->dialog), NULL, dql);
-}
-
-static void
-gnc_dialog_query_list_refresh_handler (GHashTable *changes, gpointer user_data)
-{
- DialogQueryList *dql = (DialogQueryList *)user_data;
- const EventInfo *info;
- GList *node;
-
- if (changes)
- {
- for (node = dql->books; node; node = node->next)
- {
- info = gnc_gui_get_entity_events (changes, (const GncGUID*)(node->data));
- if (info && (info->event_mask & QOF_EVENT_DESTROY))
- {
- gnc_close_gui_component (dql->component_id);
- return;
- }
- }
- }
-}
-
-static void
-gnc_dialog_query_list_close (GtkButton *button, DialogQueryList *dql)
-{
- /* Don't select anything */
- gnc_dialog_query_list_destroy (dql);
-}
-
-/*****************************************************************/
-/* PUBLIC INTERFACES */
-
-DialogQueryList *
-gnc_dialog_query_list_new (GList *param_list, Query *q)
-{
- GtkBuilder *builder;
- DialogQueryList *dql;
- GtkWidget *scroller, *close;
- GList *node;
-
- dql = g_new0 (DialogQueryList, 1);
- builder = gtk_builder_new();
- gnc_builder_add_from_file (builder, "dialog-query-list.glade", "Query List Dialog");
-
- /* Grab the dialog, save the dialog info */
- dql->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "Query List Dialog"));
- g_object_set_data (G_OBJECT (dql->dialog), "dialog-info", dql);
-
- /* grab the widgets */
- dql->label = GTK_WIDGET(gtk_builder_get_object (builder, "dialog_label"));
- dql->button_box = GTK_WIDGET(gtk_builder_get_object (builder, "button_vbox"));
- scroller = GTK_WIDGET(gtk_builder_get_object (builder, "result_scroller"));
- close = GTK_WIDGET(gtk_builder_get_object (builder, "close_button"));
-
- /* build the query list */
- dql->qlist = gnc_query_list_new (param_list, q);
- gtk_container_add (GTK_CONTAINER (scroller), dql->qlist);
-
- /* connect the double-click signal of the qlist */
- g_signal_connect (G_OBJECT (dql->qlist), "double_click_entry",
- G_CALLBACK(gnc_dialog_query_list_double_click_entry), dql);
-
- /* connect to the close button */
- g_signal_connect (G_OBJECT (close), "clicked",
- G_CALLBACK (gnc_dialog_query_list_close), dql);
-
- /* connect to the cleanup */
- g_signal_connect (G_OBJECT (dql->dialog), "delete_event",
- G_CALLBACK (gnc_dialog_query_list_delete_cb), dql);
-
- /* register ourselves */
- dql->component_id = gnc_register_gui_component ("GNC Dialog Query List",
- gnc_dialog_query_list_refresh_handler,
- close_handler, dql);
-
- /* Build the book list */
- dql_build_booklist (dql, q);
-
- /* and register the books */
- for (node = dql->books; node; node = node->next)
- gnc_gui_component_watch_entity (dql->component_id, (GncGUID*)node->data,
- QOF_EVENT_DESTROY);
-
- g_object_unref(G_OBJECT(builder));
-
- return dql;
-}
-
-void gnc_dialog_query_list_set_title (DialogQueryList *dql, const char *title)
-{
- if (!dql || !title) return;
- gtk_window_set_title (GTK_WINDOW (dql->dialog), title);
-}
-
-void gnc_dialog_query_list_set_label (DialogQueryList *dql, const char *label)
-{
- if (!dql || !label) return;
- gtk_label_set_text (GTK_LABEL(dql->label), label);
-}
-
-void gnc_dialog_query_list_set_buttons (DialogQueryList *dql,
- GNCDisplayListButton *buttons,
- gpointer user_data)
-{
- GtkWidget *button;
- int i;
-
- if (!dql || !buttons) return;
- g_return_if_fail (dql->buttons == NULL);
-
- dql->buttons = buttons;
- dql->user_data = user_data;
-
- /* build up the buttons */
- for (i = 0; buttons[i].label; i++)
- {
- /* Note: The "label" member of the GNCDisplayListButton still
- * isn't translated. Hence, we must translate it here. */
- button = gtk_button_new_with_label (_(buttons[i].label));
- g_object_set_data (G_OBJECT (button), "data", &(dql->buttons[i]));
- g_signal_connect (G_OBJECT (button), "clicked",
- G_CALLBACK(gnc_dialog_query_list_button_clicked), dql);
- gtk_box_pack_start (GTK_BOX (dql->button_box), button, FALSE, FALSE, 3);
- }
-}
-
-void gnc_dialog_query_list_set_numerics (DialogQueryList *dql, gboolean abs,
- gboolean inv_sort)
-{
- if (!dql) return;
-
- gnc_query_list_set_numerics (GNC_QUERY_LIST(dql->qlist), abs, inv_sort);
-}
-
-void gnc_dialog_query_list_refresh (DialogQueryList *dql)
-{
- if (!dql) return;
-
- gnc_query_list_refresh (GNC_QUERY_LIST(dql->qlist));
- gtk_widget_show_all (dql->dialog);
-}
-
-void gnc_dialog_query_list_destroy (DialogQueryList *dql)
-{
- if (!dql) return;
- gnc_close_gui_component (dql->component_id);
-}
-
-DialogQueryList *
-gnc_dialog_query_list_create (GList *param_list, Query *q,
- const char *title, const char *label,
- gboolean abs, gboolean inv_sort,
- GNCDisplayListButton *buttons, gpointer user_data)
-{
- DialogQueryList *dql;
-
- if (!param_list || !q)
- return NULL;
-
- dql = gnc_dialog_query_list_new (param_list, q);
- if (!dql)
- return NULL;
-
- if (title)
- gnc_dialog_query_list_set_title (dql, title);
-
- if (label)
- gnc_dialog_query_list_set_label (dql, label);
-
- gnc_dialog_query_list_set_numerics (dql, abs, inv_sort);
-
- if (buttons)
- gnc_dialog_query_list_set_buttons (dql, buttons, user_data);
-
- gnc_dialog_query_list_refresh (dql);
-
- return dql;
-}
Deleted: gnucash/trunk/src/gnome-utils/dialog-query-list.h
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-query-list.h 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/src/gnome-utils/dialog-query-list.h 2012-08-07 18:24:13 UTC (rev 22292)
@@ -1,61 +0,0 @@
-/*
- * dialog-query-list.h -- a simple dialog to display a querylist and
- * allow users to select items (or close the list)
- *
- * Created By: Derek Atkins <derek at ihtfp.com>
- * Copyright (c) 2003 Derek Atkins <warlord at MIT.EDU>
- *
- * 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 GNC_DIALOG_QUERY_LIST_H
-#define GNC_DIALOG_QUERY_LIST_H
-
-#include "Query.h"
-
-typedef struct _DialogQueryList DialogQueryList;
-
-typedef void (*GNCDisplayListCB)(gpointer obj, gpointer user_data);
-typedef struct
-{
- const char * label;
- GNCDisplayListCB cb_fcn;
-} GNCDisplayListButton;
-
-DialogQueryList *
-gnc_dialog_query_list_new (GList *param_list, Query *q);
-
-void gnc_dialog_query_list_set_title (DialogQueryList *dql, const char *title);
-void gnc_dialog_query_list_set_label (DialogQueryList *dql, const char *label);
-void gnc_dialog_query_list_set_buttons (DialogQueryList *dql,
- GNCDisplayListButton *buttons,
- gpointer user_data);
-void gnc_dialog_query_list_set_numerics (DialogQueryList *dql, gboolean abs,
- gboolean inv_sort);
-
-void gnc_dialog_query_list_refresh (DialogQueryList *dql);
-void gnc_dialog_query_list_destroy (DialogQueryList *dql);
-
-DialogQueryList *
-gnc_dialog_query_list_create (GList *param_list, Query *q,
- const char *title, const char *label,
- gboolean abs, gboolean inv_sort,
- GNCDisplayListButton *buttons, gpointer user_data);
-
-
-#endif /* GNC_DIALOG_QUERY_LIST_H */
Added: gnucash/trunk/src/gnome-utils/dialog-query-view.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-query-view.c (rev 0)
+++ gnucash/trunk/src/gnome-utils/dialog-query-view.c 2012-08-07 18:24:13 UTC (rev 22292)
@@ -0,0 +1,346 @@
+/*
+ * dialog-query-view.c -- a simple dialog to display a query view and
+ * allow users to select items (or close the view)
+ *
+ * Created By: Derek Atkins <derek at ihtfp.com>
+ * Copyright (c) 2003 Derek Atkins <warlord at MIT.EDU>
+ * Copyright (c) 2012 Robert Fewell
+ *
+ * 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 "qof.h"
+
+#include "dialog-utils.h"
+#include "gnc-component-manager.h"
+
+#include "dialog-query-view.h"
+#include "gnc-query-view.h"
+
+struct _DialogQueryView
+{
+ GtkWidget * dialog;
+ GtkWidget * label;
+ GtkWidget * qview;
+ GtkWidget * button_box;
+ GNCDisplayViewButton * buttons;
+ gpointer user_data;
+ GList * books;
+ gint component_id;
+};
+
+static void
+dqv_clear_booklist (DialogQueryView *dqv)
+{
+ GList *node;
+
+ g_return_if_fail (dqv);
+
+ for (node = dqv->books; node; node = node->next)
+ guid_free ((GncGUID*)node->data);
+ g_list_free (dqv->books);
+ dqv->books = NULL;
+}
+
+static void
+dqv_build_booklist (DialogQueryView *dqv, Query *q)
+{
+ GList *node;
+
+ g_return_if_fail (dqv);
+
+ for (node = qof_query_get_books(q); node; node = node->next)
+ {
+ QofBook *book = node->data;
+ GncGUID *guid = guid_malloc();
+ *guid = *(qof_book_get_guid(book));
+ dqv->books = g_list_prepend(dqv->books, guid);
+ }
+}
+
+static void
+gnc_dialog_query_run_callback (GNCDisplayViewButton *cb, gpointer item,
+ DialogQueryView *dqv)
+{
+ if (!cb)
+ return;
+
+ if (cb->cb_fcn)
+ (cb->cb_fcn)(item, dqv->user_data);
+}
+
+static void
+gnc_dialog_query_view_button_clicked (GtkButton *button, DialogQueryView *dqv)
+{
+ GNCDisplayViewButton *cb;
+ gpointer entry;
+
+ g_return_if_fail (dqv);
+ entry = gnc_query_view_get_selected_entry (GNC_QUERY_VIEW (dqv->qview));
+ if (!entry)
+ return;
+
+ cb = g_object_get_data (G_OBJECT (button), "data");
+ g_return_if_fail (cb);
+
+ gnc_dialog_query_run_callback (cb, entry, dqv);
+}
+
+static void
+gnc_dialog_query_view_double_click_entry (GNCQueryView *qview, gpointer item,
+ gpointer user_data)
+{
+ DialogQueryView *dqv = user_data;
+
+ g_return_if_fail (dqv);
+ g_return_if_fail (item);
+
+ if (!dqv->buttons)
+ return;
+
+ gnc_dialog_query_run_callback (dqv->buttons, item, dqv);
+}
+
+static int
+gnc_dialog_query_view_delete_cb (GtkDialog *dialog, GdkEvent *event, DialogQueryView *dqv)
+{
+ g_return_val_if_fail (dqv, TRUE);
+
+ gnc_unregister_gui_component (dqv->component_id);
+
+ /* destroy the book list */
+ dqv_clear_booklist (dqv);
+
+ /* Destroy and exit */
+ gtk_widget_destroy(dqv->dialog);
+ g_free (dqv);
+ return FALSE;
+}
+
+static void
+close_handler (gpointer data)
+{
+ DialogQueryView *dqv = data;
+
+ g_return_if_fail (dqv);
+ gnc_dialog_query_view_delete_cb (GTK_DIALOG(dqv->dialog), NULL, dqv);
+}
+
+static void
+gnc_dialog_query_view_refresh_handler (GHashTable *changes, gpointer user_data)
+{
+ DialogQueryView *dqv = (DialogQueryView *)user_data;
+ const EventInfo *info;
+ GList *node;
+
+ if (changes)
+ {
+ for (node = dqv->books; node; node = node->next)
+ {
+ info = gnc_gui_get_entity_events (changes, (const GncGUID*)(node->data));
+ if (info && (info->event_mask & QOF_EVENT_DESTROY))
+ {
+ gnc_close_gui_component (dqv->component_id);
+ return;
+ }
+ }
+ }
+}
+
+static void
+gnc_dialog_query_view_close (GtkButton *button, DialogQueryView *dqv)
+{
+ /* Don't select anything */
+ gnc_dialog_query_view_destroy (dqv);
+}
+
+/*****************************************************************/
+/* PUBLIC INTERFACES */
+
+DialogQueryView *
+gnc_dialog_query_view_new (GList *param_list, Query *q)
+{
+ GtkBuilder *builder;
+ DialogQueryView *dqv;
+ GtkWidget *result_hbox, *close, *scrollWin, *frame, *but_hbox;
+ GList *node;
+
+ dqv = g_new0 (DialogQueryView, 1);
+ builder = gtk_builder_new();
+ gnc_builder_add_from_file (builder, "dialog-query-view.glade", "Query View Dialog");
+
+ /* Grab the dialog, save the dialog info */
+ dqv->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "Query View Dialog"));
+ g_object_set_data (G_OBJECT (dqv->dialog), "dialog-info", dqv);
+
+ /* grab the widgets */
+ dqv->label = GTK_WIDGET(gtk_builder_get_object (builder, "dialog_label"));
+ result_hbox = GTK_WIDGET(gtk_builder_get_object (builder, "result_hbox"));
+ close = GTK_WIDGET(gtk_builder_get_object (builder, "close_button"));
+
+ /* build the query list */
+ dqv->qview = gnc_query_view_new (param_list, q);
+
+ frame = gtk_frame_new(NULL);
+
+ scrollWin = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrollWin),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ gtk_container_set_border_width(GTK_CONTAINER(scrollWin), 5);
+
+ gtk_container_add(GTK_CONTAINER(scrollWin), dqv->qview);
+ gtk_container_add(GTK_CONTAINER(frame), scrollWin);
+
+ gtk_box_pack_start (GTK_BOX (result_hbox), frame, TRUE, TRUE, 3);
+
+ /* Create the button_box */
+ dqv->button_box = gtk_vbox_new (FALSE, 2);
+ gtk_box_pack_start (GTK_BOX (result_hbox), dqv->button_box, FALSE, FALSE, 3);
+
+ /* connect the double-click signal of the qview */
+ g_signal_connect (G_OBJECT (dqv->qview), "double_click_entry",
+ G_CALLBACK(gnc_dialog_query_view_double_click_entry), dqv);
+
+ /* connect to the close button */
+ g_signal_connect (G_OBJECT (close), "clicked",
+ G_CALLBACK (gnc_dialog_query_view_close), dqv);
+
+ /* connect to the cleanup */
+ g_signal_connect (G_OBJECT (dqv->dialog), "delete_event",
+ G_CALLBACK (gnc_dialog_query_view_delete_cb), dqv);
+
+ /* register ourselves */
+ dqv->component_id = gnc_register_gui_component ("GNC Dialog Query View",
+ gnc_dialog_query_view_refresh_handler,
+ close_handler, dqv);
+
+ /* Build the book list */
+ dqv_build_booklist (dqv, q);
+
+ /* and register the books */
+ for (node = dqv->books; node; node = node->next)
+ gnc_gui_component_watch_entity (dqv->component_id, (GncGUID*)node->data,
+ QOF_EVENT_DESTROY);
+
+ g_object_unref(G_OBJECT(builder));
+
+ return dqv;
+}
+
+void gnc_dialog_query_view_set_title (DialogQueryView *dqv, const char *title)
+{
+ if (!dqv || !title) return;
+ gtk_window_set_title (GTK_WINDOW (dqv->dialog), title);
+}
+
+void gnc_dialog_query_view_set_label (DialogQueryView *dqv, const char *label)
+{
+ if (!dqv || !label) return;
+ gtk_label_set_text (GTK_LABEL(dqv->label), label);
+}
+
+void gnc_dialog_query_view_set_buttons (DialogQueryView *dqv,
+ GNCDisplayViewButton *buttons,
+ gpointer user_data)
+{
+ GtkWidget *button;
+ int i;
+
+ if (!dqv || !buttons) return;
+ g_return_if_fail (dqv->buttons == NULL);
+
+ dqv->buttons = buttons;
+ dqv->user_data = user_data;
+
+ /* build up the buttons */
+ for (i = 0; buttons[i].label; i++)
+ {
+ /* Note: The "label" member of the GNCDisplayListButton still
+ * isn't translated. Hence, we must translate it here. */
+ button = gtk_button_new_with_label (_(buttons[i].label));
+ g_object_set_data (G_OBJECT (button), "data", &(dqv->buttons[i]));
+ g_signal_connect (G_OBJECT (button), "clicked",
+ G_CALLBACK(gnc_dialog_query_view_button_clicked), dqv);
+ gtk_box_pack_start (GTK_BOX (dqv->button_box), button, FALSE, FALSE, 3);
+ }
+}
+
+void gnc_dialog_query_view_set_numerics (DialogQueryView *dqv, gboolean abs,
+ gboolean inv_sort)
+{
+ if (!dqv) return;
+
+ gnc_query_view_set_numerics (GNC_QUERY_VIEW(dqv->qview), abs, inv_sort);
+}
+
+void gnc_dialog_query_view_refresh (DialogQueryView *dqv)
+{
+ if (!dqv) return;
+
+ gnc_query_view_refresh (GNC_QUERY_VIEW(dqv->qview));
+ gtk_widget_show_all (dqv->dialog);
+}
+
+void gnc_dialog_query_view_destroy (DialogQueryView *dqv)
+{
+ if (!dqv) return;
+ gnc_close_gui_component (dqv->component_id);
+}
+
+DialogQueryView *
+gnc_dialog_query_view_create (GList *param_list, Query *q,
+ const char *title, const char *label,
+ gboolean abs, gboolean inv_sort,
+ gint sort_column, GtkSortType order,
+ GNCDisplayViewButton *buttons, gpointer user_data)
+{
+ DialogQueryView *dqv;
+
+ if (!param_list || !q)
+ return NULL;
+
+ dqv = gnc_dialog_query_view_new (param_list, q);
+ if (!dqv)
+ return NULL;
+
+ if (title)
+ gnc_dialog_query_view_set_title (dqv, title);
+
+ if (label)
+ gnc_dialog_query_view_set_label (dqv, label);
+
+ gnc_dialog_query_view_set_numerics (dqv, abs, inv_sort);
+
+ if (buttons)
+ gnc_dialog_query_view_set_buttons (dqv, buttons, user_data);
+
+ gnc_dialog_query_view_refresh (dqv);
+
+ /* Set the sort order */
+ gnc_query_sort_order (GNC_QUERY_VIEW (dqv->qview), sort_column, order);
+
+ /* Unselect all rows */
+ gnc_query_view_unselect_all (GNC_QUERY_VIEW (dqv->qview));
+
+ return dqv;
+}
Copied: gnucash/trunk/src/gnome-utils/dialog-query-view.h (from rev 22291, gnucash/trunk/src/gnome-utils/dialog-query-list.h)
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-query-view.h (rev 0)
+++ gnucash/trunk/src/gnome-utils/dialog-query-view.h 2012-08-07 18:24:13 UTC (rev 22292)
@@ -0,0 +1,63 @@
+/*
+ * dialog-query-view.h -- a simple dialog to display a query view and
+ * allow users to select items (or close the view)
+ *
+ * Created By: Derek Atkins <derek at ihtfp.com>
+ * Copyright (c) 2003 Derek Atkins <warlord at MIT.EDU>
+ * Copyright (c) 2012 Robert Fewell
+ *
+ * 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 GNC_DIALOG_QUERY_VIEW_H
+#define GNC_DIALOG_QUERY_VIEW_H
+
+#include "Query.h"
+
+typedef struct _DialogQueryView DialogQueryView;
+
+typedef void (*GNCDisplayViewCB)(gpointer obj, gpointer user_data);
+typedef struct
+{
+ const char *label;
+ GNCDisplayViewCB cb_fcn;
+} GNCDisplayViewButton;
+
+DialogQueryView *
+gnc_dialog_query_view_new (GList *param_list, Query *q);
+
+void gnc_dialog_query_view_set_title (DialogQueryView *dqv, const char *title);
+void gnc_dialog_query_view_set_label (DialogQueryView *dqv, const char *label);
+void gnc_dialog_query_view_set_buttons (DialogQueryView *dqv,
+ GNCDisplayViewButton *buttons,
+ gpointer user_data);
+void gnc_dialog_query_view_set_numerics (DialogQueryView *dqv, gboolean abs,
+ gboolean inv_sort);
+
+void gnc_dialog_query_view_refresh (DialogQueryView *dqv);
+void gnc_dialog_query_view_destroy (DialogQueryView *dqv);
+
+DialogQueryView *
+gnc_dialog_query_view_create (GList *param_list, Query *q,
+ const char *title, const char *label,
+ gboolean abs, gboolean inv_sort,
+ gint sort_column, GtkSortType order,
+ GNCDisplayViewButton *buttons, gpointer user_data);
+
+
+#endif /* GNC_DIALOG_QUERY_VIEW_H */
Modified: gnucash/trunk/src/gnome-utils/dialog-utils.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-utils.c 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/src/gnome-utils/dialog-utils.c 2012-08-07 18:24:13 UTC (rev 22292)
@@ -431,225 +431,6 @@
}
-typedef struct
-{
- int row;
- int col;
- gboolean checked;
-} GNCCListCheckNode;
-
-typedef struct
-{
- GdkPixmap *on_pixmap;
- GdkPixmap *off_pixmap;
- GdkBitmap *mask;
-
- GList *pending_checks;
-} GNCCListCheckInfo;
-
-static void
-free_check_list (GList *list)
-{
- GList *node;
-
- for (node = list; node; node = node->next)
- g_free (node->data);
-
- g_list_free (list);
-}
-
-static void
-check_realize (GtkWidget *widget, gpointer user_data)
-{
- GNCCListCheckInfo *check_info = user_data;
- GdkGCValues gc_values;
- GtkCList *clist;
- gint font_height;
- gint check_size;
- GdkColormap *cm;
- GtkStyle *style;
- GList *list;
- GList *node;
- GdkGC *gc;
- PangoLayout *layout;
-
- if (check_info->mask)
- return;
-
- layout = gtk_widget_create_pango_layout(widget, "sample");
- pango_layout_get_pixel_size(layout, NULL, &font_height);
- g_object_unref(layout);
- check_size = (font_height > 0) ? font_height - 6 : 9;
-
- check_info->mask = gdk_pixmap_new (NULL, check_size, check_size, 1);
-
- check_info->on_pixmap = gdk_pixmap_new (widget->window,
- check_size, check_size, -1);
-
- check_info->off_pixmap = gdk_pixmap_new (widget->window,
- check_size, check_size, -1);
-
- style = gtk_widget_get_style (widget);
- gc_values.foreground = style->white;
- gc = gtk_gc_get (1, gtk_widget_get_colormap (widget),
- &gc_values, GDK_GC_FOREGROUND);
-
- gdk_draw_rectangle (check_info->mask, gc, TRUE,
- 0, 0, check_size, check_size);
-
- gtk_gc_release (gc);
-
- gc = style->base_gc[GTK_STATE_NORMAL];
-
- gdk_draw_rectangle (check_info->on_pixmap, gc, TRUE,
- 0, 0, check_size, check_size);
- gdk_draw_rectangle (check_info->off_pixmap, gc, TRUE,
- 0, 0, check_size, check_size);
-
- cm = gtk_widget_get_colormap (widget);
-
- gc_values.foreground.red = 0;
- gc_values.foreground.green = 65535 / 2;
- gc_values.foreground.blue = 0;
-
- gdk_colormap_alloc_color (cm, &gc_values.foreground, FALSE, TRUE);
-
- gc = gdk_gc_new_with_values (widget->window, &gc_values, GDK_GC_FOREGROUND);
-
- gdk_draw_line (check_info->on_pixmap, gc,
- 1, check_size / 2,
- check_size / 3, check_size - 5);
- gdk_draw_line (check_info->on_pixmap, gc,
- 1, check_size / 2 + 1,
- check_size / 3, check_size - 4);
-
- gdk_draw_line (check_info->on_pixmap, gc,
- check_size / 3, check_size - 5,
- check_size - 3, 2);
- gdk_draw_line (check_info->on_pixmap, gc,
- check_size / 3, check_size - 4,
- check_size - 3, 1);
-
- g_object_unref (gc);
-
- clist = GTK_CLIST (widget);
-
- list = check_info->pending_checks;
- check_info->pending_checks = NULL;
-
- /* reverse so we apply in the order of the calls */
- list = g_list_reverse (list);
-
- for (node = list; node; node = node->next)
- {
- GNCCListCheckNode *cl_node = node->data;
-
- gnc_clist_set_check (clist, cl_node->row, cl_node->col, cl_node->checked);
- }
-
- free_check_list (list);
-}
-
-static void
-check_unrealize (GtkWidget *widget, gpointer user_data)
-{
- GNCCListCheckInfo *check_info = user_data;
-
- if (check_info->mask)
- g_object_unref (check_info->mask);
-
- if (check_info->on_pixmap)
- g_object_unref (check_info->on_pixmap);
-
- if (check_info->off_pixmap)
- g_object_unref (check_info->off_pixmap);
-
- check_info->mask = NULL;
- check_info->on_pixmap = NULL;
- check_info->off_pixmap = NULL;
-}
-
-static void
-check_destroy (GtkWidget *widget, gpointer user_data)
-{
- GNCCListCheckInfo *check_info = user_data;
-
- free_check_list (check_info->pending_checks);
- check_info->pending_checks = NULL;
-
- g_free (check_info);
-}
-
-static GNCCListCheckInfo *
-gnc_clist_add_check (GtkCList *list)
-{
- GNCCListCheckInfo *check_info;
- GObject *object;
-
- object = G_OBJECT (list);
-
- check_info = g_object_get_data (object, "gnc-check-info");
- if (check_info)
- {
- PWARN ("clist already has check");
- return check_info;
- }
-
- check_info = g_new0 (GNCCListCheckInfo, 1);
-
- g_object_set_data (object, "gnc-check-info", check_info);
-
- g_signal_connect (object, "realize",
- G_CALLBACK (check_realize), check_info);
- g_signal_connect (object, "unrealize",
- G_CALLBACK (check_unrealize), check_info);
- g_signal_connect (object, "destroy",
- G_CALLBACK (check_destroy), check_info);
-
- if (gtk_widget_get_realized (GTK_WIDGET (list)))
- check_realize (GTK_WIDGET (list), check_info);
-
- return check_info;
-}
-
-
-void
-gnc_clist_set_check (GtkCList *list, int row, int col, gboolean checked)
-{
- GNCCListCheckInfo *check_info;
- GdkPixmap *pixmap;
-
- g_return_if_fail (GTK_IS_CLIST (list));
-
- check_info = g_object_get_data (G_OBJECT (list), "gnc-check-info");
- if (!check_info)
- check_info = gnc_clist_add_check (list);
-
- if (!gtk_widget_get_realized (GTK_WIDGET (list)))
- {
- GNCCListCheckNode *node;
-
- node = g_new0 (GNCCListCheckNode, 1);
-
- node->row = row;
- node->col = col;
- node->checked = checked;
-
- check_info->pending_checks =
- g_list_prepend (check_info->pending_checks, node);
-
- return;
- }
-
- pixmap = checked ? check_info->on_pixmap : check_info->off_pixmap;
-
- if (checked)
- gtk_clist_set_pixmap (list, row, col, pixmap, check_info->mask);
- else
- gtk_clist_set_text (list, row, col, "");
-}
-
-
/*--------------------------------------------------------------------------
* GtkBuilder support functions
*-------------------------------------------------------------------------*/
@@ -695,11 +476,10 @@
return result;
}
-/*
- * The following function is built from a couple of glade functions.
- */
-//GModule *allsymbols = NULL;
+/*---------------------------------------------------------------------
+ * The following function is built from a couple of glade functions.
+ *--------------------------------------------------------------------*/
void
gnc_builder_connect_full_func(GtkBuilder *builder,
GObject *signal_object,
@@ -740,8 +520,10 @@
g_signal_connect_data(signal_object, signal_name, func,
user_data, NULL , flags);
}
+/*--------------------------------------------------------------------------
+ * End of GtkBuilder utilities
+ *-------------------------------------------------------------------------*/
-/* End of GtkBuilder utilities */
void
gnc_gtk_dialog_add_button (GtkWidget *dialog, const gchar *label, const gchar *stock_id, guint response)
Modified: gnucash/trunk/src/gnome-utils/dialog-utils.h
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-utils.h 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/src/gnome-utils/dialog-utils.h 2012-08-07 18:24:13 UTC (rev 22292)
@@ -33,7 +33,6 @@
void gnc_get_deficit_color (GdkColor *color);
void gnc_set_label_color (GtkWidget *label, gnc_numeric value);
-
/********************************************************************\
* Returns the window size to use for the given option prefix, *
* if window sizes are being saved, otherwise returns 0 for both. *
@@ -56,7 +55,6 @@
\********************************************************************/
void gnc_save_window_size (const char *section, GtkWindow *window);
-
/********************************************************************\
* Adjust the window size if it is bigger than the screen size. *
* *
@@ -65,27 +63,12 @@
\********************************************************************/
void gnc_window_adjust_for_screen (GtkWindow * window);
-
gboolean gnc_handle_date_accelerator (GdkEventKey *event,
struct tm *tm,
const char *date_str);
-
-/* This function sets a pixmap of a set or cleared check mark in a
- * cell of a GtkCList row.
- *
- * There are some restrictions on using this function. If you mix
- * this function with gtk_clist_{insert, prepend, remove} before
- * the clist is realized, then the checks may appear in the wrong
- * place. Stick to gtk_clist_append, or use gnc_clist_set_check
- * after you have built the list. This only applies to unrealized
- * widgets. */
-#ifdef __GTK_CLIST_H__
-void gnc_clist_set_check (GtkCList *list, int row, int col,
- gboolean checked);
-#endif
-
gboolean gnc_builder_add_from_file (GtkBuilder *builder, const char *filename, const char *root);
+
void gnc_builder_connect_full_func (GtkBuilder *builder,
GObject *signal_object,
const gchar *signal_name,
@@ -94,7 +77,6 @@
GConnectFlags flags,
gpointer user_data);
-
/** This function generates a button with icon and adds it to a
* GtkDialog. This is similar to just adding a stock button to the
* dialog, only you can add an arbitrary pairing of button and label,
@@ -113,10 +95,9 @@
const gchar *stock_id,
guint response);
-
/** Note: This dialog is modal! (It calls gtk_dialog_run() which is modal.)
*/
gint
gnc_dialog_run(GtkDialog *dialog, const gchar *gconf_key);
-#endif
+#endif /* DIALOG_UTILS_H */
Deleted: gnucash/trunk/src/gnome-utils/gnc-query-list.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-query-list.c 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/src/gnome-utils/gnc-query-list.c 2012-08-07 18:24:13 UTC (rev 22292)
@@ -1,952 +0,0 @@
-/********************************************************************\
- * gnc-query-list.c -- A query display list. *
- * Copyright (C) 2003 Derek Atkins <derek at ihtfp.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 "dialog-utils.h"
-#include "gnc-ui-util.h"
-#include "qof.h"
-#include "gnc-component-manager.h"
-#include "gnc-query-list.h"
-#include "search-param.h"
-
-/* Signal codes */
-enum
-{
- LINE_TOGGLED,
- DOUBLE_CLICK_ENTRY,
- LAST_SIGNAL
-};
-
-typedef struct _GNCQueryListPriv GNCQueryListPriv;
-
-struct _GNCQueryListPriv
-{
- const QofParam * get_guid;
- gint component_id;
-};
-
-struct _OriginalGtkCListPointers
-{
- void (*original_select_row) (GtkCList *clist,
- gint row,
- gint column,
- GdkEvent *event);
- void (*original_unselect_row) (GtkCList *clist,
- gint row,
- gint column,
- GdkEvent *event);
-};
-
-#define GNC_QUERY_LIST_GET_PRIVATE(o) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_QUERY_LIST, GNCQueryListPriv))
-
-/* Impossible to get at runtime. Assume this is a reasonable number */
-#define ARROW_SIZE 14
-#define VSCROLLBAR_SLOP 40
-
-
-/** Static Globals ****************************************************/
-static GtkCListClass *parent_class = NULL;
-static struct _OriginalGtkCListPointers original_parent_class_functions;
-static guint query_list_signals[LAST_SIGNAL] = {0};
-
-
-/** Static function declarations **************************************/
-static void gnc_query_list_init(GNCQueryList *list);
-static void gnc_query_list_init_clist (GNCQueryList *list);
-static void gnc_query_list_class_init(GNCQueryListClass *klass);
-static void gnc_query_list_select_row(GtkCList *clist, gint row,
- gint column, GdkEvent *event);
-static void gnc_query_list_unselect_row(GtkCList *clist, gint row,
- gint column, GdkEvent *event);
-static void gnc_query_list_destroy(GtkObject *object);
-static void gnc_query_list_fill(GNCQueryList *list);
-static void gnc_query_list_click_column_cb(GtkWidget *w, gint column,
- gpointer data);
-static void gnc_query_list_size_allocate_cb(GtkWidget *w,
- GtkAllocation *allocation,
- gpointer data);
-
-static void gnc_query_list_set_query_sort (GNCQueryList *list, gboolean new_column);
-
-GType
-gnc_query_list_get_type (void)
-{
- static GType gnc_query_list_type = 0;
-
- if (!gnc_query_list_type)
- {
- GTypeInfo type_info =
- {
- sizeof(GNCQueryListClass), /* class_size */
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc)gnc_query_list_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GNCQueryList), /* */
- 0, /* n_preallocs */
- (GInstanceInitFunc)gnc_query_list_init,
- };
-
- gnc_query_list_type = g_type_register_static(GTK_TYPE_CLIST,
- "GNCQueryList",
- &type_info, 0);
- }
-
- return gnc_query_list_type;
-}
-
-
-/********************************************************************\
- * gnc_query_list_new *
- * creates the query list *
- * *
- * Args: param_list - the list of params *
- * query - the query to use to find entries *
- * Returns: the query list widget, or NULL if there was a problem. *
-\********************************************************************/
-void
-gnc_query_list_construct (GNCQueryList *list, GList *param_list, Query *query)
-{
- GNCQueryListPriv *priv;
-
- g_return_if_fail(list);
- g_return_if_fail(param_list);
- g_return_if_fail(query);
- g_return_if_fail(IS_GNC_QUERY_LIST(list));
-
- /* more configuration */
- list->query = qof_query_copy(query);
- list->column_params = param_list;
-
- /* cache the function to get the guid of this query type */
- priv = GNC_QUERY_LIST_GET_PRIVATE(list);
- priv->get_guid =
- qof_class_get_parameter (qof_query_get_search_for(query), QOF_PARAM_GUID);
-
- /* Initialize the CList */
- gnc_query_list_init_clist(list);
-
- /* Set initial sort order */
- gnc_query_list_set_query_sort(list, TRUE);
-}
-
-
-GtkWidget *
-gnc_query_list_new(GList *param_list, Query *query)
-{
- GNCQueryList *list;
- gint columns;
-
- g_return_val_if_fail(param_list, NULL);
- g_return_val_if_fail(query, NULL);
-
- columns = g_list_length(param_list);
- list = GNC_QUERY_LIST(g_object_new(gnc_query_list_get_type(),
- "n_columns", columns,
- NULL));
-
- gnc_query_list_construct(list, param_list, query);
-
- return GTK_WIDGET(list);
-}
-
-void gnc_query_list_reset_query (GNCQueryList *list, Query *query)
-{
- g_return_if_fail(list);
- g_return_if_fail(query);
- g_return_if_fail (IS_GNC_QUERY_LIST(list));
-
- qof_query_destroy(list->query);
- list->query = qof_query_copy(query);
- gnc_query_list_set_query_sort(list, TRUE);
-}
-
-static void
-update_booleans (GNCQueryList *list, gint row)
-{
- GtkCList *clist = GTK_CLIST(list);
- gpointer entry;
- GList *node;
- gint i;
- gboolean result;
-
- entry = gtk_clist_get_row_data (clist, row);
- for (i = 0, node = list->column_params; node; node = node->next, i++)
- {
- GNCSearchParam *param = node->data;
- const char *type = gnc_search_param_get_param_type (param);
-
- /* if this is a boolean, ignore it now -- we'll use a checkmark later */
- if (g_strcmp0 (type, QOF_TYPE_BOOLEAN))
- continue;
-
- result = (gboolean) GPOINTER_TO_INT(gnc_search_param_compute_value(param, entry));
- gnc_clist_set_check (clist, row, i, result);
- }
-}
-
-static void
-gnc_query_list_column_title (GNCQueryList *list, gint column, const gchar *title)
-{
- GtkWidget *hbox, *label, *arrow;
-
- hbox = gtk_hbox_new(FALSE, 2);
- gtk_widget_show(hbox);
- gtk_clist_set_column_widget(GTK_CLIST(list), column, hbox);
-
- label = gtk_label_new(title);
- gtk_widget_show(label);
- gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
-
- arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_ETCHED_IN);
- list->title_arrows[column] = arrow;
- if (column == 0)
- gtk_widget_show(arrow);
- gtk_box_pack_end(GTK_BOX(hbox), arrow, FALSE, FALSE, 0);
-}
-
-static void
-gnc_query_list_refresh_handler (GHashTable *changes, gpointer user_data)
-{
- GNCQueryList *list = (GNCQueryList *)user_data;
- g_return_if_fail (list);
- g_return_if_fail (IS_GNC_QUERY_LIST(list));
-
- gnc_query_list_refresh (list);
-}
-
-static void
-gnc_query_list_init (GNCQueryList *list)
-{
- GNCQueryListPriv *priv;
-
- list->query = NULL;
- list->no_toggle = FALSE;
- list->always_unselect = FALSE;
-
- list->num_columns = 0;
- list->column_params = NULL;
-
- list->sort_column = 0;
- list->increasing = TRUE;
- list->title_arrows = NULL;
-
- list->prev_allocation = -1;
- list->title_widths = NULL;
-
- list->numeric_abs = FALSE;
- list->numeric_inv_sort = FALSE;
-
- priv = GNC_QUERY_LIST_GET_PRIVATE(list);
- priv->component_id =
- gnc_register_gui_component ("gnc-query-list-cm-class",
- gnc_query_list_refresh_handler,
- NULL, list);
-}
-
-static void
-gnc_query_list_init_clist (GNCQueryList *list)
-{
- GtkCList *clist = GTK_CLIST (list);
- GList *node;
- gchar **titles;
- gint i;
-
- /* compute the number of columns and fill in the rest of the list */
- list->num_columns = g_list_length(list->column_params);
- list->title_arrows = g_new0(GtkWidget*, list->num_columns);
- list->title_widths = g_new0(gint, list->num_columns);
-
- /* build an array of titles */
- titles = g_new0(gchar*, list->num_columns);
- for (i = 0, node = list->column_params; node; node = node->next, i++)
- {
- GNCSearchParam *param = node->data;
- titles[i] = (gchar *)param->title;
- }
-
- gtk_clist_column_titles_show (clist);
- gtk_clist_set_shadow_type (clist, GTK_SHADOW_IN);
-
- /* build all the column titles */
- for (i = 0; i < list->num_columns; i++)
- gnc_query_list_column_title(list, i, titles[i]);
-
- /* set the column justification */
- for (i = 0, node = list->column_params; node; node = node->next, i++)
- {
- GNCSearchParam *param = node->data;
- gtk_clist_set_column_justification (clist, i, param->justify);
-
- if (param->passive)
- gtk_clist_column_title_passive (clist, i);
-
- if (param->non_resizeable)
- gtk_clist_set_column_resizeable (clist, i, FALSE);
- }
-
- g_signal_connect (clist, "click_column",
- G_CALLBACK(gnc_query_list_click_column_cb),
- NULL);
- g_signal_connect (clist, "size_allocate",
- G_CALLBACK(gnc_query_list_size_allocate_cb),
- NULL);
-
-
-#if 0
- {
- GtkStyle *style;
- GdkFont *font = NULL;
- gint width;
-
- style = gtk_widget_get_style (GTK_WIDGET(list));
- font = style->font;
- if (font != NULL)
- {
- for (i = 0, node = list->column_params; node; node = node->next, i++)
- {
- GNCSearchParam *param = node->data;
- width = gdk_string_width (font, titles[i]) + 5;
- if (!param->passive)
- width += ARROW_SIZE;
- gtk_clist_set_column_min_width (clist, i, width);
- list->title_widths[i] = width;
- }
- }
- }
-#endif
- g_free(titles);
-}
-
-static void
-gnc_query_list_class_init (GNCQueryListClass *klass)
-{
- GtkObjectClass *object_class;
- GtkCListClass *clist_class;
-
- object_class = (GtkObjectClass*) klass;
- clist_class = (GtkCListClass*) klass;
-
- parent_class = gtk_type_class(GTK_TYPE_CLIST);
-
- g_type_class_add_private(klass, sizeof(GNCQueryListPriv));
-
- query_list_signals[LINE_TOGGLED] =
- g_signal_new("line_toggled",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET(GNCQueryListClass, line_toggled),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE,
- 1,
- G_TYPE_POINTER);
-
- query_list_signals[DOUBLE_CLICK_ENTRY] =
- g_signal_new("double_click_entry",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET(GNCQueryListClass, double_click_entry),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE,
- 1,
- G_TYPE_POINTER);
-
- object_class->destroy = gnc_query_list_destroy;
-
- // Watch out: This code messes with the callback function pointers directly
- // in the GtkCList structure, which unexpectedly also modifies the behaviour
- // of any other GtkCList inside our process. We add the workaround to store
- // the original pointers, and because we happen to know the other GtkCList
- // in our process has a different selection_mode, we switch to the original
- // functions based on that criterion. Yes, that's a hack. But the actual
- // solution is rather fixing *this* code not to mess up the parent's class structure!
- original_parent_class_functions.original_select_row = clist_class->select_row;
- clist_class->select_row = gnc_query_list_select_row;
- original_parent_class_functions.original_unselect_row = clist_class->unselect_row;
- clist_class->unselect_row = gnc_query_list_unselect_row;
-
- klass->line_toggled = NULL;
- klass->double_click_entry = NULL;
-}
-
-static void
-gnc_query_list_toggle (GNCQueryList *list)
-{
- gpointer entry;
- gint row;
-
- g_return_if_fail (IS_GNC_QUERY_LIST(list));
-
- if (list->no_toggle)
- return;
-
- row = list->current_row;
- entry = gtk_clist_get_row_data (GTK_CLIST(list), row);
- list->current_entry = entry;
-
- g_signal_emit (list, query_list_signals[LINE_TOGGLED], 0, entry);
-
- update_booleans (list, row);
-}
-
-static void
-gnc_query_list_select_row (GtkCList *clist, gint row, gint column,
- GdkEvent *event)
-{
- GNCQueryList *list = GNC_QUERY_LIST(clist);
-
- if (clist->selection_mode == GTK_SELECTION_MULTIPLE)
- {
- // This is the GtkCTree instance of dialog-search.c. Don't mess with it.
- original_parent_class_functions.original_select_row(clist, row, column, event);
- return;
- }
-
- list->current_row = row;
-
- gnc_query_list_toggle (list);
- if (event == NULL)
- {
- /* User pressed the space key */
- parent_class->scroll_vertical(clist, GTK_SCROLL_STEP_FORWARD, 0.0);
- }
-
- /* This will trigger an unselect event for the currently selected row */
- parent_class->select_row (clist, row, column, event);
-
- if (event && (event->type == GDK_2BUTTON_PRESS))
- {
- gpointer entry;
-
- entry = gtk_clist_get_row_data (clist, row);
-
- g_signal_emit(list, query_list_signals[DOUBLE_CLICK_ENTRY], 0, entry);
- }
-}
-
-static void
-gnc_query_list_unselect_row (GtkCList *clist, gint row, gint column,
- GdkEvent *event)
-{
- GNCQueryList *list = GNC_QUERY_LIST(clist);
-
- if (clist->selection_mode == GTK_SELECTION_MULTIPLE)
- {
- // This is the GtkCTree instance of dialog-search.c. Don't mess with it.
- original_parent_class_functions.original_unselect_row(clist, row, column, event);
- return;
- }
-
- if (row == list->current_row)
- {
- gnc_query_list_toggle (list);
- if (event == NULL)
- {
- /* User pressed the space key */
- parent_class->scroll_vertical(clist, GTK_SCROLL_STEP_FORWARD, 0.0);
- }
- if (!list->always_unselect)
- return;
- }
-
- parent_class->unselect_row (clist, row, column, event);
-
- if (event && (event->type == GDK_2BUTTON_PRESS))
- {
- gpointer entry;
-
- entry = gtk_clist_get_row_data (clist, row);
-
- g_signal_emit (list, query_list_signals[DOUBLE_CLICK_ENTRY], 0, entry);
- }
-}
-
-static void
-gnc_query_list_destroy (GtkObject *object)
-{
- GNCQueryList *list = GNC_QUERY_LIST(object);
- GNCQueryListPriv *priv;
-
- priv = GNC_QUERY_LIST_GET_PRIVATE(list);
- if (priv->component_id > 0)
- {
- gnc_unregister_gui_component (priv->component_id);
- priv->component_id = 0;
- }
- if (list->query)
- {
- qof_query_destroy(list->query);
- list->query = NULL;
- }
- if (list->column_params)
- {
- /* XXX: free the params list??? */
- }
- if (list->title_arrows)
- {
- g_free(list->title_arrows);
- list->title_arrows = NULL;
- }
- if (list->title_widths)
- {
- g_free(list->title_widths);
- list->title_widths = NULL;
- }
-
- if (GTK_OBJECT_CLASS(parent_class)->destroy)
- GTK_OBJECT_CLASS(parent_class)->destroy (object);
-}
-
-gint
-gnc_query_list_get_needed_height (GNCQueryList *list, gint num_rows)
-{
- GtkCList *clist;
- gint list_height;
- gint title_height;
-
- g_return_val_if_fail (list != NULL, 0);
- g_return_val_if_fail (IS_GNC_QUERY_LIST(list), 0);
-
- if (!gtk_widget_get_realized (GTK_WIDGET(list)))
- return 0;
-
- clist = GTK_CLIST (list);
-
- /* sync with gtkclist.c */
- title_height = (clist->column_title_area.height +
- (GTK_WIDGET(list)->style->ythickness +
- GTK_CONTAINER(list)->border_width) * 2);
- list_height = (clist->row_height * num_rows) + (num_rows + 1);
-
- return title_height + list_height;
-}
-
-gint
-gnc_query_list_get_num_entries (GNCQueryList *list)
-{
- g_return_val_if_fail (list != NULL, 0);
- g_return_val_if_fail (IS_GNC_QUERY_LIST(list), 0);
-
- return list->num_entries;
-}
-
-gpointer
-gnc_query_list_get_current_entry (GNCQueryList *list)
-{
- g_return_val_if_fail (list != NULL, NULL);
- g_return_val_if_fail (IS_GNC_QUERY_LIST(list), NULL);
-
- return list->current_entry;
-}
-
-/********************************************************************\
- * gnc_query_list_recompute_widths *
- * Given a new widget width, recompute the widths of each column. *
- * Give any excess allocation to the description field. This also *
- * handles the case of allocating column widths when the list is *
- * first filled with data. *
- * *
- * Args: list - a GncQueryList widget *
- * allocated - the allocated width for this list *
- * Returns: nothing *
-\********************************************************************/
-static void
-gnc_query_list_recompute_widths (GNCQueryList *list, gint allocated)
-{
- GtkCList *clist = GTK_CLIST(list);
- gint total_width, desc_width = 0, excess, i;
-
- /* Prevent loops when allocation is bigger than total widths */
- if (allocated == list->prev_allocation)
- return;
-
- /* Enforce column minimum widths */
- total_width = 0;
- for (i = 0; i < list->num_columns; i++)
- {
- gint width;
-
- width = gtk_clist_optimal_column_width(clist, i);
- if (width < list->title_widths[i])
- width = list->title_widths[i];
- total_width += width;
- gtk_clist_set_column_width (clist, i, width);
- if (i == 2)
- desc_width = width;
- }
-
- /* Did the list use its full allocation?
- *
- * Add/subtract any underage/overage to/from the description column
- */
- if (allocated <= 1)
- allocated = list->prev_allocation;
- list->prev_allocation = allocated;
- excess = allocated - total_width - VSCROLLBAR_SLOP;
-
- /* XXX: Choose a generic column to resize */
- gtk_clist_set_column_width (clist, 2, desc_width + excess);
-}
-
-/********************************************************************\
- * gnc_query_list_size_allocate_cb *
- * The allocated size has changed. Need to recompute the *
- * column widths *
- * *
- * Args: w - a GncQueryList widget *
- * allocation - a widget allocation desctiption *
- * data - unused *
- * Returns: nothing *
-\********************************************************************/
-static void
-gnc_query_list_size_allocate_cb (GtkWidget *w,
- GtkAllocation *allocation,
- gpointer data)
-{
- GNCQueryList *list = GNC_QUERY_LIST(w);
-
- g_return_if_fail (list != NULL);
- gnc_query_list_recompute_widths(list, allocation->width);
-}
-
-/********************************************************************\
- * gnc_query_list_refresh *
- * refreshes the list *
- * *
- * Args: list - list to refresh *
- * Returns: nothing *
-\********************************************************************/
-void
-gnc_query_list_refresh (GNCQueryList *list)
-{
- GtkCList *clist = GTK_CLIST(list);
- GtkAdjustment *adjustment;
- gfloat save_value = 0.0;
- gpointer *old_focus_entry;
- gpointer *old_entry;
- gint old_focus_row;
- gint new_row;
-
- g_return_if_fail (list != NULL);
- g_return_if_fail (IS_GNC_QUERY_LIST(list));
-
- adjustment = gtk_clist_get_vadjustment (GTK_CLIST(list));
- if (adjustment != NULL)
- save_value = adjustment->value;
-
- old_focus_row = clist->focus_row;
- old_focus_entry = gtk_clist_get_row_data (clist, old_focus_row);
-
- gtk_clist_freeze (clist);
- gtk_clist_clear (clist);
-
- old_entry = list->current_entry;
- list->num_entries = 0;
- list->current_row = -1;
- list->current_entry = NULL;
-
- gnc_query_list_fill (list);
-
- gnc_query_list_recompute_widths (list, -1);
-
- if (adjustment)
- {
- save_value = CLAMP (save_value, adjustment->lower, adjustment->upper);
- gtk_adjustment_set_value (adjustment, save_value);
- }
-
- if (old_entry)
- {
- new_row = gtk_clist_find_row_from_data (clist, old_entry);
- if (new_row >= 0)
- {
- list->no_toggle = TRUE;
- gtk_clist_select_row (clist, new_row, 0);
- list->no_toggle = FALSE;
- list->current_entry = old_entry;
- }
- }
-
- if (old_focus_entry)
- {
- new_row = gtk_clist_find_row_from_data (clist, old_focus_entry);
-
- if (new_row < 0)
- new_row = old_focus_row;
-
- if (new_row >= 0)
- clist->focus_row = new_row;
- }
-
- gtk_clist_thaw (clist);
-}
-
-/********************************************************************\
- * gnc_query_list_set_query_sort *
- * sets the sorting order of entries in the list *
- * *
- * Args: list - list to change the sort order for *
- * new_column - is this a new column (so should we set the *
- * query sort order or just set the 'increasing' *
- * Returns: nothing *
-\********************************************************************/
-static void
-gnc_query_list_set_query_sort (GNCQueryList *list, gboolean new_column)
-{
- gboolean sort_order = list->increasing;
- GList *node;
- GNCSearchParam *param;
-
- /* Find the column parameter definition */
- node = g_list_nth(list->column_params, list->sort_column);
- param = node->data;
-
- /* If we're asked to invert numerics, and if this is a numeric or
- * debred column, then invert the sort order.
- */
- if (list->numeric_inv_sort)
- {
- const char *type = gnc_search_param_get_param_type (param);
- if (!g_strcmp0(type, QOF_TYPE_NUMERIC) ||
- !g_strcmp0(type, QOF_TYPE_DEBCRED))
- sort_order = !sort_order;
- }
-
- /* Set the sort order for the engine, if the key changed */
- if (new_column)
- {
- GSList *p1, *p2;
-
- p1 = gnc_search_param_get_param_path(param);
- p2 = g_slist_prepend(NULL, QUERY_DEFAULT_SORT);
- qof_query_set_sort_order (list->query, p1, p2, NULL);
- }
-
- qof_query_set_sort_increasing (list->query,
- sort_order,
- sort_order,
- sort_order);
-
- /*
- * Recompute the list. Is this really necessary? Why not just sort
- * the rows already in the clist? Answer: it would be an n-squared
- * algorithm to get the clist to match the resulting list.
- */
- gnc_query_list_refresh(list);
-}
-
-/********************************************************************\
- * gnc_query_list_set_sort_column *
- * sets the sorting order of entries in the list *
- * *
- * Args: list - list to change the sort order for *
- * column - the column to sort on *
- * Returns: nothing *
-\********************************************************************/
-static void
-gnc_query_list_set_sort_column (GNCQueryList *list, gint sort_column)
-{
- gint column;
- gboolean new_column = FALSE;
-
- g_return_if_fail (list != NULL);
- g_return_if_fail (IS_GNC_QUERY_LIST(list));
- g_return_if_fail (list->query != NULL);
-
- /* Clear all arrows */
- for (column = 0; column < list->num_columns; column++)
- {
- if (list->title_arrows[column])
- gtk_widget_hide(list->title_arrows[column]);
- }
-
- /* Is this a new column or a re-click on the existing column? */
- column = sort_column;
- new_column = (list->sort_column != sort_column);
-
- list->increasing = new_column ? TRUE : !list->increasing;
- list->sort_column = sort_column;
-
- /* Set the appropriate arrow */
- gtk_arrow_set(GTK_ARROW(list->title_arrows[column]),
- list->increasing ? GTK_ARROW_DOWN : GTK_ARROW_UP,
- GTK_SHADOW_ETCHED_IN);
- gtk_widget_show(list->title_arrows[column]);
-
- gnc_query_list_set_query_sort (list, new_column);
-}
-
-static void
-gnc_query_list_click_column_cb(GtkWidget *w, gint column, gpointer data)
-{
- GNCQueryList *list = GNC_QUERY_LIST(w);
- gnc_query_list_set_sort_column(list, column);
-}
-
-static void
-gnc_query_list_fill(GNCQueryList *list)
-{
- GNCQueryListPriv *priv;
- gchar *strings[list->num_columns + 1];
- GList *entries, *item;
- const GncGUID *guid;
- gint i;
-
- /* Clear all watches */
- priv = GNC_QUERY_LIST_GET_PRIVATE(list);
- gnc_gui_component_clear_watches (priv->component_id);
-
- /* Reverse the list now because 'append()' takes too long */
- entries = qof_query_run(list->query);
-
- for (item = entries; item; item = item->next)
- {
- GList *node;
- gint row;
- const QofParam *gup;
- QofParam *qp = NULL;
-
- for (i = 0, node = list->column_params; node; node = node->next)
- {
- GNCSearchParam *param = node->data;
- GSList *converters = gnc_search_param_get_converters (param);
- const char *type = gnc_search_param_get_param_type (param);
- gpointer res = item->data;
-
- /* if this is a boolean, ignore it now -- we'll use a checkmark later */
- if (!g_strcmp0 (type, QOF_TYPE_BOOLEAN))
- {
- strings[i++] = g_strdup("");
- continue;
- }
-
- /* Do all the object conversions */
- for (; converters; converters = converters->next)
- {
- qp = converters->data;
- if (converters->next)
- {
- res = (qp->param_getfcn)(res, qp);
- }
- }
-
- /* Now convert this to a text value for the row */
- if (!g_strcmp0(type, QOF_TYPE_DEBCRED) ||
- !g_strcmp0(type, QOF_TYPE_NUMERIC))
- {
- gnc_numeric (*nfcn)(gpointer, QofParam *) =
- (gnc_numeric(*)(gpointer, QofParam *))(qp->param_getfcn);
- gnc_numeric value = nfcn(res, qp);
- if (list->numeric_abs)
- value = gnc_numeric_abs (value);
- strings[i++] = g_strdup(xaccPrintAmount(value, gnc_default_print_info(FALSE)));
- }
- else
- strings[i++] = qof_query_core_to_string (type, res, qp);
- }
-
- row = gtk_clist_append (GTK_CLIST(list), (gchar **) strings);
- gtk_clist_set_row_data (GTK_CLIST(list), row, item->data);
-
- /* Free up our strings */
- for (i = 0; i < list->num_columns; i++)
- {
- if (strings[i])
- g_free (strings[i]);
- }
-
- /* Now update any checkmarks */
- update_booleans (list, row);
-
- /* and set a watcher on this item */
- gup = priv->get_guid;
- guid = (const GncGUID*)((gup->param_getfcn)(item->data, gup));
- gnc_gui_component_watch_entity (priv->component_id, guid,
- QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
-
- list->num_entries++;
- }
-}
-
-/********************************************************************\
- * gnc_query_list_unselect_all *
- * unselect all items in the list *
- * *
- * Args: list - list to unselect all *
- * Returns: nothing *
-\********************************************************************/
-void
-gnc_query_list_unselect_all(GNCQueryList *list)
-{
- g_return_if_fail (list != NULL);
- g_return_if_fail (IS_GNC_QUERY_LIST(list));
-
- list->no_toggle = TRUE;
- list->always_unselect = TRUE;
-
- gtk_clist_unselect_all (GTK_CLIST(list));
-
- list->always_unselect = FALSE;
- list->no_toggle = FALSE;
-
- list->current_entry = NULL;
-}
-
-
-gboolean gnc_query_list_item_in_list (GNCQueryList *list, gpointer item)
-{
- g_return_val_if_fail(list, FALSE);
- g_return_val_if_fail(item, FALSE);
- g_return_val_if_fail(IS_GNC_QUERY_LIST(list), FALSE);
-
- return (gtk_clist_find_row_from_data(GTK_CLIST(list), item) != -1);
-}
-
-void gnc_query_list_refresh_item (GNCQueryList *list, gpointer item)
-{
- gint row;
-
- g_return_if_fail(list);
- g_return_if_fail(item);
- g_return_if_fail(IS_GNC_QUERY_LIST(list));
-
- row = gtk_clist_find_row_from_data(GTK_CLIST(list), item);
- if (row != -1)
- update_booleans (list, row);
-}
-
-void
-gnc_query_list_set_numerics (GNCQueryList *list, gboolean abs, gboolean inv_sort)
-{
- g_return_if_fail(list);
- g_return_if_fail(IS_GNC_QUERY_LIST(list));
-
- list->numeric_abs = abs;
- list->numeric_inv_sort = inv_sort;
-}
Deleted: gnucash/trunk/src/gnome-utils/gnc-query-list.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-query-list.h 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/src/gnome-utils/gnc-query-list.h 2012-08-07 18:24:13 UTC (rev 22292)
@@ -1,116 +0,0 @@
-/********************************************************************\
- * gnc-query-list.h -- GnuCash GNOME query display list widget *
- * Copyright (C) 2003 Derek Atkins <derek at ihtfp.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 GNC_QUERY_LIST_H
-#define GNC_QUERY_LIST_H
-
-#include <gtk/gtk.h>
-
-#include "Query.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-#define GNC_TYPE_QUERY_LIST (gnc_query_list_get_type ())
-#define GNC_QUERY_LIST(obj) G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_QUERY_LIST, GNCQueryList)
-#define GNC_QUERY_LIST_CLASS(klass) G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_QUERY_LIST, GNCQueryListClass)
-#define IS_GNC_QUERY_LIST(obj) G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_QUERY_LIST)
-#define IS_GNC_QUERY_LIST_CLASS(klass) G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_QUERY_LIST)
-
- typedef struct _GNCQueryList GNCQueryList;
- typedef struct _GNCQueryListClass GNCQueryListClass;
-
- struct _GNCQueryList
- {
- GtkCList clist;
-
- /* Query information */
- Query *query;
- gboolean no_toggle;
- gboolean always_unselect;
- gint current_row;
- gint num_entries;
- gpointer current_entry;
-
- /* Column information */
- gint num_columns;
- GList *column_params;
-
- /* numeric information */
- gboolean numeric_abs;
- gboolean numeric_inv_sort;
-
- /* Sorting info */
- gint sort_column;
- gboolean increasing;
- GtkWidget **title_arrows;
-
- /* Column resizing */
- gint prev_allocation;
- gint *title_widths;
- };
-
- struct _GNCQueryListClass
- {
- GtkCListClass clist_class;
-
- void (*line_toggled) (GNCQueryList *list, gpointer entry);
- void (*double_click_entry) (GNCQueryList *list, gpointer entry);
- };
-
- /***********************************************************
- * public functions *
- ***********************************************************/
-
- GType gnc_query_list_get_type (void);
-
- /* The param_list remains owned by the caller but is used by the
- * query-list; do not destroy it until you destroy this query-list.
- * The query will be copied by the query-list so the caller may do
- * whatever they want.
- */
- GtkWidget * gnc_query_list_new (GList *param_list, Query *query);
- void gnc_query_list_construct (GNCQueryList *list, GList *param_list, Query *query);
- void gnc_query_list_reset_query (GNCQueryList *list, Query *query);
-
- void gnc_query_list_set_numerics (GNCQueryList *list, gboolean abs, gboolean inv_sort);
-
- gint gnc_query_list_get_needed_height(GNCQueryList *list, gint num_rows);
-
- gint gnc_query_list_get_num_entries(GNCQueryList *list);
-
- gpointer gnc_query_list_get_current_entry(GNCQueryList *list);
-
- void gnc_query_list_refresh (GNCQueryList *list);
-
- void gnc_query_list_unselect_all(GNCQueryList *list);
-
- gboolean gnc_query_list_item_in_list (GNCQueryList *list, gpointer item);
-
- void gnc_query_list_refresh_item (GNCQueryList *list, gpointer item);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* GNC_QUERY_LIST_H */
Added: gnucash/trunk/src/gnome-utils/gnc-query-view.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-query-view.c (rev 0)
+++ gnucash/trunk/src/gnome-utils/gnc-query-view.c 2012-08-07 18:24:13 UTC (rev 22292)
@@ -0,0 +1,906 @@
+/********************************************************************\
+ * gnc-query-view.c -- A query display view. *
+ * Copyright (C) 2003 Derek Atkins <derek at ihtfp.com> *
+ * Copyright (C) 2012 Robert Fewell *
+ * *
+ * 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 "dialog-utils.h"
+#include "gnc-ui-util.h"
+#include "qof.h"
+#include "gnc-component-manager.h"
+#include "gnc-query-view.h"
+#include "search-param.h"
+
+/* Signal codes */
+enum
+{
+ COLUMN_TOGGLED,
+ ROW_SELECTED,
+ DOUBLE_CLICK_ENTRY,
+ LAST_SIGNAL
+};
+
+typedef struct _GNCQueryViewPriv GNCQueryViewPriv;
+
+struct _GNCQueryViewPriv
+{
+ const QofParam *get_guid;
+ gint component_id;
+};
+
+#define GNC_QUERY_VIEW_GET_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_QUERY_VIEW, GNCQueryViewPriv))
+
+/** Static Globals ****************************************************/
+static GtkTreeViewClass *parent_class = NULL;
+static guint query_view_signals[LAST_SIGNAL] = {0};
+
+/** Static function declarations **************************************/
+static void gnc_query_view_init (GNCQueryView *qview);
+static void gnc_query_view_init_view (GNCQueryView *qview);
+static void gnc_query_view_class_init (GNCQueryViewClass *klass);
+static void gnc_query_view_select_row_cb (GtkTreeSelection *selection, gpointer user_data);
+static void gnc_query_view_toggled_cb (GtkCellRendererToggle *cell_renderer,
+ gchar *path, gpointer user_data);
+static void gnc_query_view_double_click_cb (GtkTreeView *tree_view,
+ GtkTreePath *path,
+ GtkTreeViewColumn *column,
+ gpointer user_data);
+
+static void gnc_query_view_destroy (GtkObject *object);
+static void gnc_query_view_fill (GNCQueryView *qview);
+static void gnc_query_view_set_query_sort (GNCQueryView *qview, gboolean new_column);
+
+
+GType
+gnc_query_view_get_type (void)
+{
+ static GType gnc_query_view_type = 0;
+
+ if (!gnc_query_view_type)
+ {
+ GTypeInfo type_info =
+ {
+ sizeof(GNCQueryViewClass), /* class_size */
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ (GClassInitFunc)gnc_query_view_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (GNCQueryView), /* */
+ 0, /* n_preallocs */
+ (GInstanceInitFunc)gnc_query_view_init,
+ };
+
+ gnc_query_view_type = g_type_register_static (GTK_TYPE_TREE_VIEW,
+ "GNCQueryView",
+ &type_info, 0);
+ }
+ return gnc_query_view_type;
+}
+
+
+/********************************************************************\
+ * gnc_query_view_new *
+ * creates the query view *
+ * *
+ * Args: param_list - the list of params *
+ * query - the query to use to find entries *
+ * Returns: the query view widget, or NULL if there was a problem. *
+\********************************************************************/
+void
+gnc_query_view_construct (GNCQueryView *qview, GList *param_list, Query *query)
+{
+ GNCQueryViewPriv *priv;
+
+ g_return_if_fail (qview);
+ g_return_if_fail (param_list);
+ g_return_if_fail (query);
+ g_return_if_fail (GNC_IS_QUERY_VIEW(qview));
+
+ /* more configuration */
+ qview->query = qof_query_copy (query);
+ qview->column_params = param_list;
+
+ /* cache the function to get the guid of this query type */
+ priv = GNC_QUERY_VIEW_GET_PRIVATE (qview);
+ priv->get_guid =
+ qof_class_get_parameter (qof_query_get_search_for (query), QOF_PARAM_GUID);
+
+ /* Initialize the Tree View */
+ gnc_query_view_init_view (qview);
+
+ /* Set initial sort order */
+ gnc_query_view_set_query_sort (qview, TRUE);
+}
+
+GtkWidget *
+gnc_query_view_new (GList *param_list, Query *query)
+{
+ GNCQueryView *qview;
+ GtkListStore *liststore;
+ GList *node;
+ gint columns, i;
+ gsize array_size;
+ GType *types;
+
+ g_return_val_if_fail (param_list, NULL);
+ g_return_val_if_fail (query, NULL);
+
+ /* Add 1 to param_list length for extra pointer column */
+ columns = g_list_length (param_list) + 1;
+ qview = GNC_QUERY_VIEW (g_object_new (gnc_query_view_get_type(), NULL));
+
+ array_size = sizeof( GType ) * columns;
+ types = g_slice_alloc ( array_size );
+
+ types[0] = G_TYPE_POINTER;
+
+ /* Get the types for the list store */
+ for (i = 0, node = param_list; node; node = node->next, i++)
+ {
+ GNCSearchParam *param = node->data;
+ const char *type = gnc_search_param_get_param_type (param);
+
+ if (g_strcmp0 (type, QOF_TYPE_BOOLEAN) == 0)
+ types[i+1] = G_TYPE_BOOLEAN;
+ else
+ types[i+1] = G_TYPE_STRING;
+ }
+
+ /* Create the list store and add to treeview */
+ liststore = gtk_list_store_newv (columns, types );
+ gtk_tree_view_set_model (GTK_TREE_VIEW (qview), GTK_TREE_MODEL (liststore));
+ g_object_unref (liststore);
+
+ /* Free array */
+ g_slice_free1( array_size, types );
+
+ gnc_query_view_construct (qview, param_list, query);
+
+ return GTK_WIDGET (qview);
+}
+
+
+void gnc_query_view_reset_query (GNCQueryView *qview, Query *query)
+{
+ g_return_if_fail (qview);
+ g_return_if_fail (query);
+ g_return_if_fail (GNC_IS_QUERY_VIEW (qview));
+
+ qof_query_destroy (qview->query);
+ qview->query = qof_query_copy (query);
+
+ gnc_query_view_set_query_sort (qview, TRUE);
+}
+
+
+static void
+gnc_query_view_refresh_handler (GHashTable *changes, gpointer user_data)
+{
+ GNCQueryView *qview = (GNCQueryView *)user_data;
+ g_return_if_fail (qview);
+ g_return_if_fail (GNC_IS_QUERY_VIEW (qview));
+
+ gnc_query_view_set_query_sort (qview, TRUE);
+}
+
+
+static void
+gnc_query_view_init (GNCQueryView *qview)
+{
+ GNCQueryViewPriv *priv;
+
+ qview->query = NULL;
+
+ qview->num_columns = 0;
+ qview->column_params = NULL;
+
+ qview->sort_column = 0;
+ qview->increasing = FALSE;
+
+ qview->numeric_abs = FALSE;
+ qview->numeric_inv_sort = FALSE;
+
+ priv = GNC_QUERY_VIEW_GET_PRIVATE (qview);
+ priv->component_id =
+ gnc_register_gui_component ("gnc-query-view-cm-class",
+ gnc_query_view_refresh_handler,
+ NULL, qview);
+}
+
+
+static gint
+sort_iter_compare_func (GtkTreeModel *model,
+ GtkTreeIter *a,
+ GtkTreeIter *b,
+ gpointer userdata)
+{
+ /* This is really a dummy sort function, it leaves the list as is. */
+ return 0;
+}
+
+
+/********************************************************************\
+ * gnc_query_sort_order *
+ * allows the sort order to be specified *
+ * *
+ * Args: qview - the view to sort *
+ * column - the sort column in the tree view, 1 -> *
+ * order - GTK_SORT_ASCENDING or GTK_SORT_DESCENDING *
+\********************************************************************/
+void
+gnc_query_sort_order ( GNCQueryView *qview, gint column, GtkSortType order)
+{
+ GtkTreeSortable *sortable;
+ gint sortcol;
+
+ g_return_if_fail (qview != NULL);
+ g_return_if_fail (GNC_IS_QUERY_VIEW (qview));
+
+ sortable = GTK_TREE_SORTABLE (gtk_tree_view_get_model (GTK_TREE_VIEW (qview)));
+
+ if((column > qview->num_columns) || (column == 0) )
+ sortcol = 1;
+ else
+ sortcol = column;
+
+ gtk_tree_sortable_set_sort_column_id (sortable, sortcol, order);
+}
+
+
+static void
+gnc_query_sort_cb (GtkTreeSortable *sortable, gpointer user_data)
+{
+ GNCQueryView *qview = GNC_QUERY_VIEW (user_data);
+ GtkSortType type;
+ gint sortcol;
+ gboolean new_column = FALSE;
+
+ g_return_if_fail (qview != NULL);
+ g_return_if_fail (GNC_IS_QUERY_VIEW (qview));
+ g_return_if_fail (qview->query != NULL);
+
+ gtk_tree_sortable_get_sort_column_id (sortable, &sortcol, &type);
+
+ /* We need to subtract 1 for the added pointer column in the liststore
+ which is not displayed to align back to params */
+ sortcol = sortcol - 1;
+
+ if(type == GTK_SORT_ASCENDING)
+ qview->increasing = TRUE;
+ else
+ qview->increasing = FALSE;
+
+ /* Is this a new column or a re-click on the existing column? */
+ new_column = (qview->sort_column != sortcol);
+
+ /* Save the column */
+ qview->sort_column = sortcol;
+
+ gnc_query_view_set_query_sort (qview, new_column);
+}
+
+
+static void
+gnc_query_view_init_view (GNCQueryView *qview)
+{
+ GtkTreeView *view = GTK_TREE_VIEW (qview);
+ GtkTreeSortable *sortable;
+ GtkTreeSelection *selection;
+ GtkTreeViewColumn *col;
+ GtkCellRenderer *renderer;
+ GList *node;
+ gint i;
+
+ sortable = GTK_TREE_SORTABLE (gtk_tree_view_get_model (GTK_TREE_VIEW (view)));
+
+ /* compute the number of columns and fill in the rest of the view */
+ qview->num_columns = g_list_length (qview->column_params);
+
+ for (i = 0, node = qview->column_params; node; node = node->next, i++)
+ {
+ const char *type;
+ gfloat algn = 0;
+ GNCSearchParam *param = node->data;
+
+ col = gtk_tree_view_column_new ();
+
+ /* Set the column title */
+ gtk_tree_view_column_set_title (col, (gchar *)param->title);
+
+ /* pack tree view column into tree view */
+ gtk_tree_view_append_column (view, col);
+
+ /* Get justification */
+ if (param->justify == GTK_JUSTIFY_CENTER)
+ algn = 0.5;
+ else if (param->justify == GTK_JUSTIFY_RIGHT)
+ algn = 1.0;
+
+ /* Set column resizeable */
+ if (param->non_resizeable)
+ {
+ gtk_tree_view_column_set_resizable (col, FALSE);
+ gtk_tree_view_column_set_expand (col, FALSE);
+ }
+ else
+ gtk_tree_view_column_set_resizable (col, TRUE);
+
+ /* Set column clickable */
+ if (param->passive)
+ gtk_tree_view_column_set_clickable (col, FALSE);
+ else
+ {
+ gtk_tree_view_column_set_clickable (col, TRUE);
+ /* Add sortable columns */
+ gtk_tree_view_column_set_sort_column_id (col, i+1);
+ gtk_tree_sortable_set_sort_func (sortable, i+1, sort_iter_compare_func,
+ GINT_TO_POINTER (i+1), NULL);
+ }
+
+ type = gnc_search_param_get_param_type (param);
+
+ if (g_strcmp0 (type, QOF_TYPE_BOOLEAN) == 0)
+ {
+ renderer = gtk_cell_renderer_toggle_new ();
+
+ /* pack cell renderer toggle into tree view column */
+ gtk_tree_view_column_pack_start (col, renderer, TRUE);
+ gtk_tree_view_column_add_attribute (col, renderer, "active", i+1);
+ g_object_set (renderer, "xalign", algn, NULL );
+ g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (i+1) );
+ g_signal_connect (renderer, "toggled", G_CALLBACK (gnc_query_view_toggled_cb), view);
+ }
+ else
+ {
+ renderer = gtk_cell_renderer_text_new ();
+
+ /* pack cell renderer text into tree view column */
+ gtk_tree_view_column_pack_start (col, renderer, TRUE);
+ gtk_tree_view_column_add_attribute (col, renderer, "text", i+1);
+ g_object_set (renderer, "xalign", algn, NULL );
+ g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (i+1) );
+ }
+ }
+
+ /* set initial sort order */
+ gtk_tree_sortable_set_default_sort_func (sortable, NULL, NULL, NULL);
+ gtk_tree_sortable_set_sort_column_id (sortable, 1, GTK_SORT_DESCENDING);
+
+ g_signal_connect (sortable, "sort-column-changed",
+ G_CALLBACK (gnc_query_sort_cb),
+ view);
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
+ g_signal_connect (selection, "changed",
+ G_CALLBACK (gnc_query_view_select_row_cb),
+ NULL);
+
+ g_signal_connect (view, "row-activated",
+ G_CALLBACK (gnc_query_view_double_click_cb),
+ NULL);
+}
+
+
+static void
+gnc_query_view_class_init (GNCQueryViewClass *klass)
+{
+ GtkObjectClass *object_class;
+ GtkTreeViewClass *view_class;
+
+ object_class = (GtkObjectClass*) klass;
+ view_class = (GtkTreeViewClass*) klass;
+
+ parent_class = g_type_class_peek (GTK_TYPE_TREE_VIEW);
+
+ g_type_class_add_private (klass, sizeof(GNCQueryViewPriv));
+
+ query_view_signals[COLUMN_TOGGLED] =
+ g_signal_new("column_toggled",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GNCQueryViewClass, column_toggled),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_POINTER);
+
+ query_view_signals[ROW_SELECTED] =
+ g_signal_new("row_selected",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GNCQueryViewClass, row_selected),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_POINTER);
+
+ query_view_signals[DOUBLE_CLICK_ENTRY] =
+ g_signal_new("double_click_entry",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GNCQueryViewClass, double_click_entry),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_POINTER);
+
+ object_class->destroy = gnc_query_view_destroy;
+
+ klass->column_toggled = NULL;
+ klass->row_selected = NULL;
+ klass->double_click_entry = NULL;
+}
+
+
+static void
+gnc_query_view_select_row_cb (GtkTreeSelection *selection, gpointer user_data)
+{
+ GNCQueryView *qview = GNC_QUERY_VIEW (gtk_tree_selection_get_tree_view (selection));
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gint number_of_rows;
+ gpointer entry = NULL;
+ GList *node;
+ GList *list_of_rows;
+
+ qview->selected_entry_list = NULL;
+ qview->selected_entry = NULL;
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (qview));
+ list_of_rows = gtk_tree_selection_get_selected_rows (selection, &model);
+ number_of_rows = gtk_tree_selection_count_selected_rows (selection);
+
+ /* We get a list of TreePaths */
+ for(node = list_of_rows; node; node = node->next)
+ {
+ GtkTreeIter iter;
+ if(gtk_tree_model_get_iter(model, &iter, node->data))
+ {
+ /* now iter is a valid row iterator */
+ gtk_tree_model_get (model, &iter, 0, &entry, -1);
+ if(number_of_rows == 1)
+ {
+ qview->selected_entry = entry;
+ qview->selected_entry_list = g_list_prepend(qview->selected_entry_list, entry);
+ }
+ else
+ {
+ qview->selected_entry = NULL;
+ qview->selected_entry_list = g_list_prepend(qview->selected_entry_list, entry);
+ }
+ }
+ gtk_tree_path_free(node->data);
+ }
+ g_list_free(list_of_rows);
+
+ g_signal_emit (qview, query_view_signals[ROW_SELECTED], 0, GINT_TO_POINTER(number_of_rows));
+}
+
+
+static void
+gnc_query_view_double_click_cb (GtkTreeView *view,
+ GtkTreePath *path,
+ GtkTreeViewColumn *column,
+ gpointer user_data)
+{
+ GNCQueryView *qview = GNC_QUERY_VIEW(view);
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gpointer entry = NULL;
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
+
+ if (gtk_tree_model_get_iter (model, &iter, path))
+ gtk_tree_model_get (model, &iter, 0, &entry, -1);
+
+ qview->selected_entry = entry;
+ qview->selected_entry_list = NULL;
+
+ g_signal_emit (qview, query_view_signals[DOUBLE_CLICK_ENTRY], 0, entry);
+}
+
+
+static void
+gnc_query_view_toggled_cb (GtkCellRendererToggle *cell_renderer,
+ gchar *path,
+ gpointer user_data)
+{
+ GNCQueryView *qview = GNC_QUERY_VIEW (user_data);
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ GtkTreePath *treepath;
+ gint *indices;
+ gpointer entry = NULL;
+ gboolean toggled;
+ gint column;
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (qview));
+
+ column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell_renderer),"column"));
+
+ toggled = gtk_cell_renderer_toggle_get_active (cell_renderer);
+
+ treepath = gtk_tree_path_new_from_string (path);
+
+ if (gtk_tree_model_get_iter(model, &iter, treepath))
+ {
+ gtk_tree_model_get (model, &iter, 0, &entry, -1);
+ indices = gtk_tree_path_get_indices (treepath);
+ qview->toggled_row = indices[0];
+ qview->toggled_column = column;
+ qview->selected_entry = entry;
+
+ if(toggled)
+ g_signal_emit (qview, query_view_signals[COLUMN_TOGGLED], 0, GINT_TO_POINTER(0));
+ else
+ g_signal_emit (qview, query_view_signals[COLUMN_TOGGLED], 0, GINT_TO_POINTER(1));
+ }
+ qview->selected_entry = entry;
+}
+
+
+static void
+gnc_query_view_destroy (GtkObject *object)
+{
+ GNCQueryView *qview = GNC_QUERY_VIEW (object);
+ GNCQueryViewPriv *priv;
+
+ priv = GNC_QUERY_VIEW_GET_PRIVATE (qview);
+ if (priv->component_id > 0)
+ {
+ gnc_unregister_gui_component (priv->component_id);
+ priv->component_id = 0;
+ }
+ /* Free the selected entry list */
+ if (qview->selected_entry_list)
+ {
+ g_list_free(qview->selected_entry_list);
+ qview->selected_entry_list = NULL;
+ }
+ /* Remove the query */
+ if (qview->query)
+ {
+ qof_query_destroy (qview->query);
+ qview->query = NULL;
+ }
+ if (GTK_OBJECT_CLASS (parent_class)->destroy)
+ GTK_OBJECT_CLASS (parent_class)->destroy (object);
+}
+
+
+gint
+gnc_query_view_get_num_entries (GNCQueryView *qview)
+{
+ g_return_val_if_fail (qview != NULL, 0);
+ g_return_val_if_fail (GNC_IS_QUERY_VIEW (qview), 0);
+
+ return qview->num_entries;
+}
+
+
+gpointer
+gnc_query_view_get_selected_entry (GNCQueryView *qview)
+{
+ g_return_val_if_fail (qview != NULL, NULL);
+ g_return_val_if_fail (GNC_IS_QUERY_VIEW (qview), NULL);
+
+ return qview->selected_entry;
+}
+
+
+GList *
+gnc_query_view_get_selected_entry_list (GNCQueryView *qview)
+{
+ g_return_val_if_fail (qview != NULL, NULL);
+ g_return_val_if_fail (GNC_IS_QUERY_VIEW (qview), NULL);
+
+ return qview->selected_entry_list;
+}
+
+
+static void
+gnc_query_view_refresh_selected (GNCQueryView *qview, GList *old_entry)
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ GtkTreeSelection *selection;
+ GList *node;
+ gboolean valid;
+
+ g_return_if_fail (qview != NULL);
+ g_return_if_fail (GNC_IS_QUERY_VIEW (qview));
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (qview));
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (qview));
+
+ if(g_list_length (old_entry) > 0)
+ {
+ /* Walk the list of old entries */
+ for(node = old_entry; node; node = node->next)
+ {
+ gpointer pointer;
+
+ valid = gtk_tree_model_get_iter_first (model, &iter);
+
+ while (valid)
+ {
+ // Walk through the liststore, reading each row
+ gtk_tree_model_get (model, &iter, 0, &pointer, -1);
+
+ if(pointer == node->data)
+ {
+ gtk_tree_selection_select_iter (selection, &iter);
+ break;
+ }
+ valid = gtk_tree_model_iter_next (model, &iter);
+ }
+ }
+ }
+}
+
+
+/********************************************************************\
+ * gnc_query_view_refresh *
+ * refreshes the view *
+ * *
+ * Args: qview - view to refresh *
+ * Returns: nothing *
+\********************************************************************/
+void
+gnc_query_view_refresh (GNCQueryView *qview)
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ GtkTreeSelection *selection;
+ GList *old_entry;
+
+ g_return_if_fail (qview != NULL);
+ g_return_if_fail (GNC_IS_QUERY_VIEW (qview));
+
+ old_entry = qview->selected_entry_list;
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (qview));
+ gtk_list_store_clear (GTK_LIST_STORE (model));
+
+ qview->num_entries = 0;
+ qview->selected_entry = NULL;
+ qview->selected_entry_list = NULL;
+
+ gnc_query_view_fill (qview);
+
+ gnc_query_view_refresh_selected (qview, old_entry);
+
+ g_list_free(old_entry);
+}
+
+
+/********************************************************************\
+ * gnc_query_view_set_query_sort *
+ * sets the sorting order of entries in the view *
+ * *
+ * Args: qview - view to change the sort order for *
+ * new_column - is this a new column (so should we set the *
+ * query sort order or just set the 'increasing' *
+ * Returns: nothing *
+\********************************************************************/
+static void
+gnc_query_view_set_query_sort (GNCQueryView *qview, gboolean new_column)
+{
+ gboolean sort_order = qview->increasing;
+ GList *node;
+ GNCSearchParam *param;
+
+ /* Find the column parameter definition */
+ node = g_list_nth (qview->column_params, qview->sort_column);
+ param = node->data;
+
+ /* If we're asked to invert numerics, and if this is a numeric or
+ * debred column, then invert the sort order.
+ */
+ if (qview->numeric_inv_sort)
+ {
+ const char *type = gnc_search_param_get_param_type (param);
+ if (!g_strcmp0(type, QOF_TYPE_NUMERIC) ||
+ !g_strcmp0(type, QOF_TYPE_DEBCRED))
+ sort_order = !sort_order;
+ }
+
+ /* Set the sort order for the engine, if the key changed */
+ if (new_column)
+ {
+ GSList *p1, *p2;
+
+ p1 = gnc_search_param_get_param_path (param);
+ p2 = g_slist_prepend (NULL, QUERY_DEFAULT_SORT);
+ qof_query_set_sort_order (qview->query, p1, p2, NULL);
+ }
+
+ qof_query_set_sort_increasing (qview->query,
+ sort_order,
+ sort_order,
+ sort_order);
+
+ gnc_query_view_refresh (qview);
+}
+
+
+/********************************************************************\
+ * gnc_query_view_fill *
+ * Add all items to the list store *
+ * *
+ * Args: qview - view to add item to *
+ * Returns: nothing *
+\********************************************************************/
+static void
+gnc_query_view_fill (GNCQueryView *qview)
+{
+ GNCQueryViewPriv *priv;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ GList *entries, *item;
+ const GncGUID *guid;
+ gint i;
+
+ /* Clear all watches */
+ priv = GNC_QUERY_VIEW_GET_PRIVATE (qview);
+ gnc_gui_component_clear_watches (priv->component_id);
+
+ entries = qof_query_run (qview->query);
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (qview));
+
+ for (item = entries; item; item = item->next)
+ {
+ GList *node;
+ gint row;
+ const QofParam *gup;
+ QofParam *qp = NULL;
+
+ /* Add a row to the list store */
+ gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+ /* Add a pointer to the data in the first column of the list store */
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, item->data, -1);
+
+ for (i = 0, node = qview->column_params; node; node = node->next)
+ {
+ gboolean result;
+ GNCSearchParam *param = node->data;
+ GSList *converters = gnc_search_param_get_converters (param);
+ const char *type = gnc_search_param_get_param_type (param);
+ gpointer res = item->data;
+ gchar *qofstring;
+
+ /* Test for boolean type */
+ if (g_strcmp0 (type, QOF_TYPE_BOOLEAN) == 0)
+ {
+ result = (gboolean) GPOINTER_TO_INT (gnc_search_param_compute_value (param, res));
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter, i + 1, result, -1);
+ i++;
+ continue;
+ }
+
+ /* Do all the object conversions */
+ for (; converters; converters = converters->next)
+ {
+ qp = converters->data;
+ if (converters->next)
+ res = (qp->param_getfcn)(res, qp);
+ }
+
+ /* Now convert this to a text value for the row */
+ if ( g_strcmp0(type, QOF_TYPE_DEBCRED) == 0 || g_strcmp0(type, QOF_TYPE_NUMERIC) == 0 )
+ {
+
+ gnc_numeric (*nfcn)(gpointer, QofParam *) =
+ (gnc_numeric(*)(gpointer, QofParam *))(qp->param_getfcn);
+ gnc_numeric value = nfcn(res, qp);
+
+ if (qview->numeric_abs)
+ value = gnc_numeric_abs (value);
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter, i + 1, xaccPrintAmount (value, gnc_default_print_info (FALSE)), -1);
+ }
+ else
+ {
+ qofstring = qof_query_core_to_string (type, res, qp);
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter, i + 1, qofstring , -1);
+ g_free(qofstring);
+ }
+ i++;
+ }
+ row++;
+ /* and set a watcher on this item */
+ gup = priv->get_guid;
+ guid = (const GncGUID*)((gup->param_getfcn)(item->data, gup));
+ gnc_gui_component_watch_entity (priv->component_id, guid,
+ QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
+
+ qview->num_entries++;
+ }
+}
+
+
+/********************************************************************\
+ * gnc_query_view_unselect_all *
+ * unselect all items in the view *
+ * *
+ * Args: qview - view to unselect all *
+ * Returns: nothing *
+\********************************************************************/
+void
+gnc_query_view_unselect_all (GNCQueryView *qview)
+{
+ GtkTreeSelection *selection;
+
+ g_return_if_fail (qview != NULL);
+ g_return_if_fail (GNC_IS_QUERY_VIEW (qview));
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (qview));
+ gtk_tree_selection_unselect_all (selection);
+
+ qview->selected_entry = NULL;
+ qview->selected_entry_list = NULL;
+}
+
+
+gboolean gnc_query_view_item_in_view (GNCQueryView *qview, gpointer item)
+{
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gboolean valid;
+ gpointer pointer;
+
+ g_return_val_if_fail (qview, FALSE);
+ g_return_val_if_fail (item, FALSE);
+ g_return_val_if_fail (GNC_IS_QUERY_VIEW (qview), FALSE);
+
+ model = gtk_tree_view_get_model (GTK_TREE_VIEW (qview));
+ valid = gtk_tree_model_get_iter_first (model, &iter);
+
+ while (valid)
+ {
+ // Walk through the list, reading each row
+ gtk_tree_model_get (model, &iter, 0, &pointer, -1);
+
+ if(pointer == item)
+ return TRUE;
+
+ valid = gtk_tree_model_iter_next (model, &iter);
+ }
+ return FALSE;
+}
+
+
+void
+gnc_query_view_set_numerics (GNCQueryView *qview, gboolean abs, gboolean inv_sort)
+{
+ g_return_if_fail (qview);
+ g_return_if_fail (GNC_IS_QUERY_VIEW (qview));
+
+ qview->numeric_abs = abs;
+ qview->numeric_inv_sort = inv_sort;
+}
Added: gnucash/trunk/src/gnome-utils/gnc-query-view.h
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-query-view.h (rev 0)
+++ gnucash/trunk/src/gnome-utils/gnc-query-view.h 2012-08-07 18:24:13 UTC (rev 22292)
@@ -0,0 +1,125 @@
+/********************************************************************\
+ * gnc-query-view.h -- GnuCash GNOME query display view widget *
+ * Copyright (C) 2003 Derek Atkins <derek at ihtfp.com> *
+ * Copyright (C) 2012 Robert Fewell *
+ * *
+ * 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 GNC_QUERY_VIEW_H
+#define GNC_QUERY_VIEW_H
+
+#include <gtk/gtk.h>
+
+#include "Query.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#define GNC_TYPE_QUERY_VIEW (gnc_query_view_get_type ())
+#define GNC_QUERY_VIEW(obj) G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_QUERY_VIEW, GNCQueryView)
+#define GNC_QUERY_VIEW_CLASS(klass) G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_QUERY_VIEW, GNCQueryViewClass)
+#define GNC_IS_QUERY_VIEW(obj) G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_QUERY_VIEW)
+#define GNC_IS_QUERY_VIEW_CLASS(klass) G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_QUERY_VIEW)
+
+ typedef struct _GNCQueryView GNCQueryView;
+ typedef struct _GNCQueryViewClass GNCQueryViewClass;
+
+ struct _GNCQueryView
+ {
+ GtkTreeView qview;
+
+ /* Query information */
+ Query *query;
+ gint num_entries;
+
+ /* Select information */
+ gpointer selected_entry;
+ GList *selected_entry_list;
+ gint toggled_row;
+ gint toggled_column;
+
+ /* Column information */
+ gint num_columns;
+ GList *column_params;
+
+ /* numeric information */
+ gboolean numeric_abs;
+ gboolean numeric_inv_sort;
+
+ /* Sorting info */
+ gint sort_column;
+ gboolean increasing;
+ };
+
+ struct _GNCQueryViewClass
+ {
+ GtkTreeViewClass view_class;
+
+ /* This signal is emitted when a toggle happens, the pointer has
+ an interger value for the active setting of the toggle */
+ void (*column_toggled) (GNCQueryView *qview, gpointer item);
+
+ /* This signal is emitted when a row is selected, the pointer has
+ an interger value for the number of rows selected */
+ void (*row_selected) (GNCQueryView *qview, gpointer item);
+
+ /* This signal is emitted when a row is double clicked, the pointer has
+ a pointer to the entry */
+ void (*double_click_entry) (GNCQueryView *qview, gpointer entry);
+ };
+
+ /***********************************************************
+ * public functions *
+ ***********************************************************/
+
+ GType gnc_query_view_get_type (void);
+
+ /* The param_list remains owned by the caller but is used by the
+ * query-view; do not destroy it until you destroy this query-view.
+ * The query will be copied by the query-view so the caller may do
+ * whatever they want.
+ */
+ GtkWidget * gnc_query_view_new (GList *param_list, Query *query);
+
+ void gnc_query_view_construct (GNCQueryView *qview, GList *param_list, Query *query);
+
+ void gnc_query_view_reset_query (GNCQueryView *view, Query *query);
+
+ void gnc_query_view_set_numerics (GNCQueryView *qview, gboolean abs, gboolean inv_sort);
+
+ gint gnc_query_view_get_num_entries (GNCQueryView *qview);
+
+ gpointer gnc_query_view_get_selected_entry (GNCQueryView *qview);
+
+ GList * gnc_query_view_get_selected_entry_list (GNCQueryView *qview);
+
+ void gnc_query_view_refresh (GNCQueryView *qview);
+
+ void gnc_query_view_unselect_all (GNCQueryView *qview);
+
+ gboolean gnc_query_view_item_in_view (GNCQueryView *qview, gpointer item);
+
+ void gnc_query_sort_order (GNCQueryView *qview, gint column, GtkSortType order);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* GNC_QUERY_VIEW_H */
Modified: gnucash/trunk/src/gnome-utils/gtkbuilder/Makefile.am
===================================================================
--- gnucash/trunk/src/gnome-utils/gtkbuilder/Makefile.am 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/src/gnome-utils/gtkbuilder/Makefile.am 2012-08-07 18:24:13 UTC (rev 22292)
@@ -9,7 +9,7 @@
dialog-object-references.glade \
dialog-options.glade \
dialog-preferences.glade \
- dialog-query-list.glade \
+ dialog-query-view.glade \
dialog-reset-warnings.glade \
dialog-tax-table.glade \
dialog-totd.glade \
Deleted: gnucash/trunk/src/gnome-utils/gtkbuilder/dialog-query-list.glade
===================================================================
--- gnucash/trunk/src/gnome-utils/gtkbuilder/dialog-query-list.glade 2012-08-07 17:25:12 UTC (rev 22291)
+++ gnucash/trunk/src/gnome-utils/gtkbuilder/dialog-query-list.glade 2012-08-07 18:24:13 UTC (rev 22292)
@@ -1,117 +0,0 @@
-<?xml version="1.0"?>
-<interface>
- <requires lib="gtk+" version="2.16"/>
- <!-- interface-naming-policy project-wide -->
- <object class="GtkDialog" id="Query List Dialog">
- <property name="can_focus">False</property>
- <property name="default_width">500</property>
- <property name="default_height">300</property>
- <property name="type_hint">dialog</property>
- <child internal-child="vbox">
- <object class="GtkVBox" id="dialog-vbox1">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="spacing">8</property>
- <child internal-child="action_area">
- <object class="GtkHButtonBox" id="dialog-action_area1">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="layout_style">end</property>
- <child>
- <object class="GtkButton" id="close_button">
- <property name="label">gtk-close</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="can_default">True</property>
- <property name="receives_default">True</property>
- <property name="use_action_appearance">False</property>
- <property name="use_stock">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="pack_type">end</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkVBox" id="vbox1">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <child>
- <object class="GtkLabel" id="dialog_label">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="justify">center</property>
- <property name="wrap">True</property>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="padding">5</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkHBox" id="hbox1">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <child>
- <object class="GtkScrolledWindow" id="result_scroller">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="hscrollbar_policy">automatic</property>
- <property name="vscrollbar_policy">automatic</property>
- <child>
- <placeholder/>
- </child>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkVBox" id="button_vbox">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <child>
- <placeholder/>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="padding">3</property>
- <property name="position">1</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="expand">True</property>
- <property name="fill">True</property>
- <property name="position">2</property>
- </packing>
- </child>
- </object>
- </child>
- <action-widgets>
- <action-widget response="0">close_button</action-widget>
- </action-widgets>
- </object>
-</interface>
Copied: gnucash/trunk/src/gnome-utils/gtkbuilder/dialog-query-view.glade (from rev 22291, gnucash/trunk/src/gnome-utils/gtkbuilder/dialog-query-list.glade)
===================================================================
--- gnucash/trunk/src/gnome-utils/gtkbuilder/dialog-query-view.glade (rev 0)
+++ gnucash/trunk/src/gnome-utils/gtkbuilder/dialog-query-view.glade 2012-08-07 18:24:13 UTC (rev 22292)
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk+" version="2.16"/>
+ <object class="GtkDialog" id="Query View Dialog">
+ <property name="can_focus">False</property>
+ <property name="default_width">500</property>
+ <property name="default_height">300</property>
+ <property name="type_hint">dialog</property>
+ <child internal-child="vbox">
+ <object class="GtkBox" id="dialog-vbox1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">8</property>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox" id="dialog-action_area1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="layout_style">end</property>
+ <child>
+ <object class="GtkButton" id="close_button">
+ <property name="label">gtk-close</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkVBox" id="vbox1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkLabel" id="dialog_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="justify">center</property>
+ <property name="wrap">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="padding">5</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkHBox" id="result_hbox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="padding">3</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="0">close_button</action-widget>
+ </action-widgets>
+ </object>
+</interface>
More information about the gnucash-changes
mailing list