Add UI for a bunch of new Query types, and hook them into the

Search UI.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6705 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Derek Atkins 2002-02-09 04:22:29 +00:00
parent 1e45d1ebad
commit 2e42ed44b9
13 changed files with 1741 additions and 47 deletions

View File

@ -18,14 +18,24 @@ AM_CFLAGS = \
libgncmod_gnome_search_la_SOURCES = \
gncmod-gnome-search.c \
dialog-search.c \
search-boolean.c \
search-core-type.c \
search-date.c \
search-debcred.c \
search-double.c \
search-int64.c \
search-numeric.c \
search-param.c \
search-string.c
noinst_HEADERS = \
search-boolean.h \
search-core-type.h \
search-date.h \
search-debcred.h \
search-double.h \
search-int64.h \
search-numeric.h \
search-param.h \
search-string.h

View File

@ -371,23 +371,43 @@ gnc_search_dialog_destroy (GNCSearchWindow *sw)
gnc_close_gui_component_by_data (DIALOG_SEARCH_CM_CLASS, sw);
}
static GNCSearchParam *
make_param (GNCIdTypeConst type, const char *title, const char *path1,
const char *path2)
{
GSList *l = NULL;
GNCSearchParam *param = gnc_search_param_new ();
gnc_search_param_set_title (param, title);
if (path2)
l = g_slist_prepend (l, path2);
l = g_slist_prepend (l, path1);
gnc_search_param_set_param_path (param, type, l);
return param;
}
static GList *
get_params_list (GNCIdTypeConst type)
{
GList *list = NULL;
GNCSearchParam *param;
param = gnc_search_param_new ();
gnc_search_param_set_title (param, "Split Memo");
gnc_search_param_set_param_path (param, type,
g_slist_prepend (NULL, SPLIT_MEMO));
list = g_list_prepend (list, param);
param = gnc_search_param_new ();
gnc_search_param_set_title (param, "Date Reconciled");
gnc_search_param_set_param_path (param, type,
g_slist_prepend (NULL, SPLIT_DATE_RECONCILED));
list = g_list_prepend (list, param);
list = g_list_prepend (list, make_param (type, "Split->Txn->Void?",
SPLIT_TRANS, TRANS_VOID_STATUS));
list = g_list_prepend (list, make_param (type, "Split Int64",
"d-share-int64", NULL));
list = g_list_prepend (list, make_param (type, "Split Amount (double)",
"d-share-amount", NULL));
list = g_list_prepend (list, make_param (type, "Split Value (debcred)",
SPLIT_VALUE, NULL));
list = g_list_prepend (list, make_param (type, "Split Amount (numeric)",
SPLIT_AMOUNT, NULL));
list = g_list_prepend (list, make_param (type, "Date Reconciled (date)",
SPLIT_DATE_RECONCILED, NULL));
list = g_list_prepend (list, make_param (type, "Split Memo (string)",
SPLIT_MEMO, NULL));
return list;
}

View File

@ -0,0 +1,263 @@
/*
* Copyright (C) 2002 Derek Atkins
*
* Authors: Derek Atkins <warlord@MIT.EDU>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <gnome.h>
#include "QueryCore.h"
#include "search-boolean.h"
#define d(x)
static GNCSearchCoreType *clone(GNCSearchCoreType *fe);
static gboolean validate (GNCSearchCoreType *fe);
static GtkWidget *get_widget(GNCSearchCoreType *fe);
static QueryPredData_t get_predicate (GNCSearchCoreType *fe);
static void gnc_search_boolean_class_init (GNCSearchBooleanClass *class);
static void gnc_search_boolean_init (GNCSearchBoolean *gspaper);
static void gnc_search_boolean_finalise (GtkObject *obj);
#define _PRIVATE(x) (((GNCSearchBoolean *)(x))->priv)
struct _GNCSearchBooleanPrivate {
};
static GNCSearchCoreTypeClass *parent_class;
enum {
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
guint
gnc_search_boolean_get_type (void)
{
static guint type = 0;
if (!type) {
GtkTypeInfo type_info = {
"GNCSearchBoolean",
sizeof(GNCSearchBoolean),
sizeof(GNCSearchBooleanClass),
(GtkClassInitFunc)gnc_search_boolean_class_init,
(GtkObjectInitFunc)gnc_search_boolean_init,
(GtkArgSetFunc)NULL,
(GtkArgGetFunc)NULL
};
type = gtk_type_unique(gnc_search_core_type_get_type (), &type_info);
}
return type;
}
static void
gnc_search_boolean_class_init (GNCSearchBooleanClass *class)
{
GtkObjectClass *object_class;
GNCSearchCoreTypeClass *gnc_search_core_type = (GNCSearchCoreTypeClass *)class;
object_class = (GtkObjectClass *)class;
parent_class = gtk_type_class(gnc_search_core_type_get_type ());
object_class->finalize = gnc_search_boolean_finalise;
/* override methods */
gnc_search_core_type->validate = validate;
gnc_search_core_type->get_widget = get_widget;
gnc_search_core_type->get_predicate = get_predicate;
gnc_search_core_type->clone = clone;
/* signals */
gtk_object_class_add_signals(object_class, signals, LAST_SIGNAL);
}
static void
gnc_search_boolean_init (GNCSearchBoolean *o)
{
o->priv = g_malloc0 (sizeof (*o->priv));
o->how = COMPARE_EQUAL;
o->value = TRUE;
}
static void
gnc_search_boolean_finalise (GtkObject *obj)
{
GNCSearchBoolean *o = (GNCSearchBoolean *)obj;
g_assert (IS_GNCSEARCH_BOOLEAN (o));
g_free(o->priv);
((GtkObjectClass *)(parent_class))->finalize(obj);
}
/**
* gnc_search_boolean_new:
*
* Create a new GNCSearchBoolean object.
*
* Return value: A new #GNCSearchBoolean object.
**/
GNCSearchBoolean *
gnc_search_boolean_new (void)
{
GNCSearchBoolean *o = (GNCSearchBoolean *)gtk_type_new(gnc_search_boolean_get_type ());
return o;
}
void
gnc_search_boolean_set_value (GNCSearchBoolean *fi, gboolean value)
{
g_return_if_fail (fi);
g_return_if_fail (IS_GNCSEARCH_BOOLEAN (fi));
fi->value = value;
}
void
gnc_search_boolean_set_how (GNCSearchBoolean *fi, query_compare_t how)
{
g_return_if_fail (fi);
g_return_if_fail (IS_GNCSEARCH_BOOLEAN (fi));
fi->how = how;
}
static gboolean
validate (GNCSearchCoreType *fe)
{
GNCSearchBoolean *fi = (GNCSearchBoolean *)fe;
gboolean valid = TRUE;
g_return_val_if_fail (fi, FALSE);
g_return_val_if_fail (IS_GNCSEARCH_BOOLEAN (fi), FALSE);
/* XXX */
return valid;
}
static void
option_changed (GtkWidget *widget, GNCSearchBoolean *fe)
{
fe->how = (query_compare_t)
gtk_object_get_data (GTK_OBJECT (widget), "option");
}
static void
toggle_changed (GtkToggleButton *button, GNCSearchBoolean *fe)
{
fe->value = gtk_toggle_button_get_active (button);
}
static GtkWidget *
add_menu_item (GtkWidget *menu, gpointer user_data, char *label,
query_compare_t option)
{
GtkWidget *item = gtk_menu_item_new_with_label (label);
gtk_object_set_data (GTK_OBJECT (item), "option", (gpointer) option);
gtk_signal_connect (GTK_OBJECT (item), "activate", option_changed, user_data);
gtk_menu_append (GTK_MENU (menu), item);
gtk_widget_show (item);
return item;
}
#define ADD_MENU_ITEM(str,op) { \
item = add_menu_item (menu, fe, str, op); \
if (fi->how == op) { current = index; first = item; } \
index++; \
}
static GtkWidget *
make_menu (GNCSearchCoreType *fe)
{
GNCSearchBoolean *fi = (GNCSearchBoolean *)fe;
GtkWidget *menu, *item, *first, *opmenu;
int current = 0, index = 0;
menu = gtk_menu_new ();
ADD_MENU_ITEM (_("is"), COMPARE_EQUAL);
first = item; /* Force one */
ADD_MENU_ITEM (_("is not"), COMPARE_NEQ);
opmenu = gtk_option_menu_new ();
gtk_option_menu_set_menu (GTK_OPTION_MENU (opmenu), menu);
gtk_signal_emit_by_name (GTK_OBJECT (first), "activate", fe);
gtk_option_menu_set_history (GTK_OPTION_MENU (opmenu), current);
return opmenu;
}
static GtkWidget *
get_widget (GNCSearchCoreType *fe)
{
GtkWidget *toggle, *menu, *box;
GNCSearchBoolean *fi = (GNCSearchBoolean *)fe;
g_return_val_if_fail (fi, NULL);
g_return_val_if_fail (IS_GNCSEARCH_BOOLEAN (fi), NULL);
box = gtk_hbox_new (FALSE, 3);
/* Build and connect the option menu */
menu = make_menu (fe);
gtk_box_pack_start (GTK_BOX (box), menu, FALSE, FALSE, 3);
/* Build and connect the toggle */
toggle = gtk_toggle_button_new_with_label (_("set true"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), fi->value);
gtk_signal_connect (GTK_OBJECT (toggle), "toggled", toggle_changed, fe);
gtk_box_pack_start (GTK_BOX (box), toggle, FALSE, FALSE, 3);
/* And return the box */
return box;
}
static QueryPredData_t get_predicate (GNCSearchCoreType *fe)
{
GNCSearchBoolean *fi = (GNCSearchBoolean *)fe;
g_return_val_if_fail (fi, NULL);
g_return_val_if_fail (IS_GNCSEARCH_BOOLEAN (fi), NULL);
return gncQueryBooleanPredicate (fi->how, fi->value);
}
static GNCSearchCoreType *clone(GNCSearchCoreType *fe)
{
GNCSearchBoolean *se, *fse = (GNCSearchBoolean *)fe;
g_return_val_if_fail (fse, NULL);
g_return_val_if_fail (IS_GNCSEARCH_BOOLEAN (fse), NULL);
se = gnc_search_boolean_new ();
gnc_search_boolean_set_value (se, fse->value);
gnc_search_boolean_set_how (se, fse->how);
return (GNCSearchCoreType *)se;
}

View File

@ -0,0 +1,58 @@
/*
* Copyright (C) 2002 Derek Atkins
*
* Authors: Derek Atkins <warlord@MIT.EDU>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef _GNCSEARCH_BOOLEAN_H
#define _GNCSEARCH_BOOLEAN_H
#include "search-core-type.h"
#include "QueryNew.h"
#define GNCSEARCH_BOOLEAN(obj) GTK_CHECK_CAST (obj, gnc_search_boolean_get_type (), GNCSearchBoolean)
#define GNCSEARCH_BOOLEAN_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gnc_search_boolean_get_type (), GNCSearchBooleanClass)
#define IS_GNCSEARCH_BOOLEAN(obj) GTK_CHECK_TYPE (obj, gnc_search_boolean_get_type ())
typedef struct _GNCSearchBoolean GNCSearchBoolean;
typedef struct _GNCSearchBooleanClass GNCSearchBooleanClass;
struct _GNCSearchBoolean {
GNCSearchCoreType parent;
struct _GNCSearchBooleanPrivate *priv;
query_compare_t how;
gboolean value;
};
struct _GNCSearchBooleanClass {
GNCSearchCoreTypeClass parent_class;
/* virtual methods */
/* signals */
};
guint gnc_search_boolean_get_type (void);
GNCSearchBoolean *gnc_search_boolean_new (void);
/* methods */
void gnc_search_boolean_set_value (GNCSearchBoolean *fi, gboolean val);
void gnc_search_boolean_set_how (GNCSearchBoolean *fi, query_compare_t how);
#endif /* ! _GNCSEARCH_BOOLEAN_H */

View File

@ -30,19 +30,11 @@
#include "search-core-type.h"
#include "search-string.h"
#include "search-date.h"
#if 0
#include "search-input.h"
#include "search-option.h"
#include "search-code.h"
#include "search-colour.h"
#include "search-datespec.h"
#include "search-score.h"
#include "search-int.h"
#include "search-folder.h"
#include "search-source.h"
#endif
#include "search-debcred.h"
#include "search-double.h"
#include "search-int64.h"
#include "search-numeric.h"
#include "search-boolean.h"
static gboolean validate (GNCSearchCoreType *fe);
@ -197,29 +189,16 @@ gnc_search_core_type_new_type_name (const char *type)
return (GNCSearchCoreType *)gnc_search_string_new ();
} else if (!strcmp (type, QUERYCORE_DATE)) {
return (GNCSearchCoreType *)gnc_search_date_new ();
#if 0
} else if (!strcmp (type, "folder")) {
return (GNCSearchCoreType *)gnc_search_folder_new ();
} else if (!strcmp (type, "address")) {
/* FIXME: temporary ... need real address type */
return (GNCSearchCoreType *)gnc_search_input_new_type_name (type);
} else if (!strcmp (type, "code")) {
return (GNCSearchCoreType *)gnc_search_code_new ();
} else if (!strcmp (type, "colour")) {
return (GNCSearchCoreType *)gnc_search_colour_new ();
} else if (!strcmp (type, "optionlist") || !strcmp (type, "system-flag")) {
return (GNCSearchCoreType *)gnc_search_option_new ();
} else if (!strcmp (type, "datespec")) {
return (GNCSearchCoreType *)gnc_search_datespec_new ();
} else if (!strcmp (type, "score")) {
return (GNCSearchCoreType *)gnc_search_score_new ();
} else if (!strcmp (type, "integer")) {
return (GNCSearchCoreType *)gnc_search_int_new ();
} else if (!strcmp (type, "regex")) {
return (GNCSearchCoreType *)gnc_search_input_new_type_name (type);
} else if (!strcmp (type, "source")) {
return (GNCSearchCoreType *)gnc_search_source_new ();
#endif
} else if (!strcmp (type, QUERYCORE_INT64)) {
return (GNCSearchCoreType *)gnc_search_int64_new ();
} else if (!strcmp (type, QUERYCORE_DOUBLE)) {
return (GNCSearchCoreType *)gnc_search_double_new ();
} else if (!strcmp (type, QUERYCORE_NUMERIC)) {
return (GNCSearchCoreType *)gnc_search_numeric_new ();
} else if (!strcmp (type, QUERYCORE_DEBCRED)) {
return (GNCSearchCoreType *)gnc_search_debcred_new ();
} else if (!strcmp (type, QUERYCORE_BOOLEAN)) {
return (GNCSearchCoreType *)gnc_search_boolean_new ();
} else {
g_warning("Unknown search type '%s'", type);
return 0;

View File

@ -0,0 +1,318 @@
/*
* Copyright (C) 2002 Derek Atkins
*
* Authors: Derek Atkins <warlord@MIT.EDU>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <gnome.h>
#include "gnc-amount-edit.h"
#include "QueryCore.h"
#include "search-debcred.h"
#define d(x)
static GNCSearchCoreType *clone(GNCSearchCoreType *fe);
static gboolean validate (GNCSearchCoreType *fe);
static GtkWidget *get_widget(GNCSearchCoreType *fe);
static QueryPredData_t get_predicate (GNCSearchCoreType *fe);
static void gnc_search_debcred_class_init (GNCSearchDebcredClass *class);
static void gnc_search_debcred_init (GNCSearchDebcred *gspaper);
static void gnc_search_debcred_finalise (GtkObject *obj);
#define _PRIVATE(x) (((GNCSearchDebcred *)(x))->priv)
struct _GNCSearchDebcredPrivate {
};
static GNCSearchCoreTypeClass *parent_class;
enum {
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
guint
gnc_search_debcred_get_type (void)
{
static guint type = 0;
if (!type) {
GtkTypeInfo type_info = {
"GNCSearchDebcred",
sizeof(GNCSearchDebcred),
sizeof(GNCSearchDebcredClass),
(GtkClassInitFunc)gnc_search_debcred_class_init,
(GtkObjectInitFunc)gnc_search_debcred_init,
(GtkArgSetFunc)NULL,
(GtkArgGetFunc)NULL
};
type = gtk_type_unique(gnc_search_core_type_get_type (), &type_info);
}
return type;
}
static void
gnc_search_debcred_class_init (GNCSearchDebcredClass *class)
{
GtkObjectClass *object_class;
GNCSearchCoreTypeClass *gnc_search_core_type = (GNCSearchCoreTypeClass *)class;
object_class = (GtkObjectClass *)class;
parent_class = gtk_type_class(gnc_search_core_type_get_type ());
object_class->finalize = gnc_search_debcred_finalise;
/* override methods */
gnc_search_core_type->validate = validate;
gnc_search_core_type->get_widget = get_widget;
gnc_search_core_type->get_predicate = get_predicate;
gnc_search_core_type->clone = clone;
/* signals */
gtk_object_class_add_signals(object_class, signals, LAST_SIGNAL);
}
static void
gnc_search_debcred_init (GNCSearchDebcred *o)
{
o->priv = g_malloc0 (sizeof (*o->priv));
o->value = gnc_numeric_zero ();
o->how = COMPARE_LT;
o->option = NUMERIC_MATCH_ANY;
}
static void
gnc_search_debcred_finalise (GtkObject *obj)
{
GNCSearchDebcred *o = (GNCSearchDebcred *)obj;
g_assert (IS_GNCSEARCH_DEBCRED (o));
g_free(o->priv);
((GtkObjectClass *)(parent_class))->finalize(obj);
}
/**
* gnc_search_debcred_new:
*
* Create a new GNCSearchDebcred object.
*
* Return value: A new #GNCSearchDebcred object.
**/
GNCSearchDebcred *
gnc_search_debcred_new (void)
{
GNCSearchDebcred *o = (GNCSearchDebcred *)gtk_type_new(gnc_search_debcred_get_type ());
return o;
}
void
gnc_search_debcred_set_value (GNCSearchDebcred *fi, gnc_numeric value)
{
g_return_if_fail (fi);
g_return_if_fail (IS_GNCSEARCH_DEBCRED (fi));
fi->value = value;
}
void
gnc_search_debcred_set_how (GNCSearchDebcred *fi, query_compare_t how)
{
g_return_if_fail (fi);
g_return_if_fail (IS_GNCSEARCH_DEBCRED (fi));
fi->how = how;
}
void
gnc_search_debcred_set_option (GNCSearchDebcred *fi, numeric_match_t option)
{
g_return_if_fail (fi);
g_return_if_fail (IS_GNCSEARCH_DEBCRED (fi));
fi->option = option;
}
static gboolean
validate (GNCSearchCoreType *fe)
{
GNCSearchDebcred *fi = (GNCSearchDebcred *)fe;
gboolean valid = TRUE;
g_return_val_if_fail (fi, FALSE);
g_return_val_if_fail (IS_GNCSEARCH_DEBCRED (fi), FALSE);
/* XXX */
return valid;
}
static void
how_option_changed (GtkWidget *widget, GNCSearchDebcred *fe)
{
fe->how = (query_compare_t)
gtk_object_get_data (GTK_OBJECT (widget), "option");
}
static void
option_changed (GtkWidget *widget, GNCSearchDebcred *fe)
{
fe->option = (numeric_match_t)
gtk_object_get_data (GTK_OBJECT (widget), "option");
}
static void
entry_changed (GNCAmountEdit *entry, GNCSearchDebcred *fe)
{
fe->value = gnc_amount_edit_get_amount (entry);
}
static GtkWidget *
add_menu_item (GtkWidget *menu, gpointer user_data, char *label,
query_compare_t option, GtkSignalFunc fcn)
{
GtkWidget *item = gtk_menu_item_new_with_label (label);
gtk_object_set_data (GTK_OBJECT (item), "option", (gpointer) option);
gtk_signal_connect (GTK_OBJECT (item), "activate", fcn, user_data);
gtk_menu_append (GTK_MENU (menu), item);
gtk_widget_show (item);
return item;
}
#define ADD_MENU_ITEM(cmp,str,op,fcn) { \
item = add_menu_item (menu, fe, str, op, fcn); \
if (cmp == op) { current = index; first = item; } \
index++; \
}
static GtkWidget *
make_how_menu (GNCSearchCoreType *fe)
{
GNCSearchDebcred *fi = (GNCSearchDebcred *)fe;
GtkWidget *menu, *item, *first, *opmenu;
int current = 0, index = 0;
menu = gtk_menu_new ();
ADD_MENU_ITEM (fi->how, _("less than"), COMPARE_LT, how_option_changed);
first = item; /* Force one */
ADD_MENU_ITEM (fi->how, _("less than or equal to"), COMPARE_LTE,
how_option_changed);
ADD_MENU_ITEM (fi->how, _("equal to"), COMPARE_EQUAL, how_option_changed);
ADD_MENU_ITEM (fi->how, _("not equal to"), COMPARE_NEQ,
how_option_changed);
ADD_MENU_ITEM (fi->how, _("greater than"), COMPARE_GT,
how_option_changed);
ADD_MENU_ITEM (fi->how, _("greater than or equal to"), COMPARE_GTE,
how_option_changed);
opmenu = gtk_option_menu_new ();
gtk_option_menu_set_menu (GTK_OPTION_MENU (opmenu), menu);
gtk_signal_emit_by_name (GTK_OBJECT (first), "activate", fe);
gtk_option_menu_set_history (GTK_OPTION_MENU (opmenu), current);
return opmenu;
}
static GtkWidget *
make_option_menu (GNCSearchCoreType *fe)
{
GNCSearchDebcred *fi = (GNCSearchDebcred *)fe;
GtkWidget *menu, *item, *first, *opmenu;
int current = 0, index = 0;
menu = gtk_menu_new ();
ADD_MENU_ITEM (fi->option, _("has credits or debits"), NUMERIC_MATCH_ANY,
option_changed);
first = item; /* Force one */
ADD_MENU_ITEM (fi->option, _("has debits"), NUMERIC_MATCH_DEBIT,
option_changed);
ADD_MENU_ITEM (fi->option, _("has credits"), NUMERIC_MATCH_CREDIT,
option_changed);
opmenu = gtk_option_menu_new ();
gtk_option_menu_set_menu (GTK_OPTION_MENU (opmenu), menu);
gtk_signal_emit_by_name (GTK_OBJECT (first), "activate", fe);
gtk_option_menu_set_history (GTK_OPTION_MENU (opmenu), current);
return opmenu;
}
static GtkWidget *
get_widget (GNCSearchCoreType *fe)
{
GtkWidget *entry, *menu, *box;
GNCSearchDebcred *fi = (GNCSearchDebcred *)fe;
g_return_val_if_fail (fi, NULL);
g_return_val_if_fail (IS_GNCSEARCH_DEBCRED (fi), NULL);
box = gtk_hbox_new (FALSE, 3);
/* Build and connect the option menus */
menu = make_option_menu (fe);
gtk_box_pack_start (GTK_BOX (box), menu, FALSE, FALSE, 3);
menu = make_how_menu (fe);
gtk_box_pack_start (GTK_BOX (box), menu, FALSE, FALSE, 3);
/* Build and connect the entry window */
entry = gnc_amount_edit_new ();
gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (entry), fi->value);
gtk_signal_connect (GTK_OBJECT (entry), "amount_changed", entry_changed, fe);
gtk_box_pack_start (GTK_BOX (box), entry, FALSE, FALSE, 3);
/* And return the box */
return box;
}
static QueryPredData_t get_predicate (GNCSearchCoreType *fe)
{
GNCSearchDebcred *fi = (GNCSearchDebcred *)fe;
g_return_val_if_fail (fi, NULL);
g_return_val_if_fail (IS_GNCSEARCH_DEBCRED (fi), NULL);
return gncQueryNumericPredicate (fi->how, fi->option, fi->value);
}
static GNCSearchCoreType *clone(GNCSearchCoreType *fe)
{
GNCSearchDebcred *se, *fse = (GNCSearchDebcred *)fe;
g_return_val_if_fail (fse, NULL);
g_return_val_if_fail (IS_GNCSEARCH_DEBCRED (fse), NULL);
se = gnc_search_debcred_new ();
gnc_search_debcred_set_value (se, fse->value);
gnc_search_debcred_set_how (se, fse->how);
gnc_search_debcred_set_option (se, fse->option);
return (GNCSearchCoreType *)se;
}

View File

@ -0,0 +1,61 @@
/*
* Copyright (C) 2002 Derek Atkins
*
* Authors: Derek Atkins <warlord@MIT.EDU>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef _GNCSEARCH_DEBCRED_H
#define _GNCSEARCH_DEBCRED_H
#include "search-core-type.h"
#include "gnc-numeric.h"
#include "QueryNew.h"
#define GNCSEARCH_DEBCRED(obj) GTK_CHECK_CAST (obj, gnc_search_debcred_get_type (), GNCSearchDebcred)
#define GNCSEARCH_DEBCRED_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gnc_search_debcred_get_type (), GNCSearchDebcredClass)
#define IS_GNCSEARCH_DEBCRED(obj) GTK_CHECK_TYPE (obj, gnc_search_debcred_get_type ())
typedef struct _GNCSearchDebcred GNCSearchDebcred;
typedef struct _GNCSearchDebcredClass GNCSearchDebcredClass;
struct _GNCSearchDebcred {
GNCSearchCoreType parent;
struct _GNCSearchDebcredPrivate *priv;
query_compare_t how;
gnc_numeric value;
numeric_match_t option;
};
struct _GNCSearchDebcredClass {
GNCSearchCoreTypeClass parent_class;
/* virtual methods */
/* signals */
};
guint gnc_search_debcred_get_type (void);
GNCSearchDebcred *gnc_search_debcred_new (void);
/* methods */
void gnc_search_debcred_set_value (GNCSearchDebcred *fi, gnc_numeric val);
void gnc_search_debcred_set_how (GNCSearchDebcred *fi, query_compare_t how);
void gnc_search_debcred_set_option (GNCSearchDebcred *fi, numeric_match_t option);
#endif /* ! _GNCSEARCH_DEBCRED_H */

View File

@ -0,0 +1,268 @@
/*
* Copyright (C) 2002 Derek Atkins
*
* Authors: Derek Atkins <warlord@MIT.EDU>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <gnome.h>
#include "gnc-amount-edit.h"
#include "QueryCore.h"
#include "search-double.h"
#define d(x)
static GNCSearchCoreType *clone(GNCSearchCoreType *fe);
static gboolean validate (GNCSearchCoreType *fe);
static GtkWidget *get_widget(GNCSearchCoreType *fe);
static QueryPredData_t get_predicate (GNCSearchCoreType *fe);
static void gnc_search_double_class_init (GNCSearchDoubleClass *class);
static void gnc_search_double_init (GNCSearchDouble *gspaper);
static void gnc_search_double_finalise (GtkObject *obj);
#define _PRIVATE(x) (((GNCSearchDouble *)(x))->priv)
struct _GNCSearchDoublePrivate {
};
static GNCSearchCoreTypeClass *parent_class;
enum {
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
guint
gnc_search_double_get_type (void)
{
static guint type = 0;
if (!type) {
GtkTypeInfo type_info = {
"GNCSearchDouble",
sizeof(GNCSearchDouble),
sizeof(GNCSearchDoubleClass),
(GtkClassInitFunc)gnc_search_double_class_init,
(GtkObjectInitFunc)gnc_search_double_init,
(GtkArgSetFunc)NULL,
(GtkArgGetFunc)NULL
};
type = gtk_type_unique(gnc_search_core_type_get_type (), &type_info);
}
return type;
}
static void
gnc_search_double_class_init (GNCSearchDoubleClass *class)
{
GtkObjectClass *object_class;
GNCSearchCoreTypeClass *gnc_search_core_type = (GNCSearchCoreTypeClass *)class;
object_class = (GtkObjectClass *)class;
parent_class = gtk_type_class(gnc_search_core_type_get_type ());
object_class->finalize = gnc_search_double_finalise;
/* override methods */
gnc_search_core_type->validate = validate;
gnc_search_core_type->get_widget = get_widget;
gnc_search_core_type->get_predicate = get_predicate;
gnc_search_core_type->clone = clone;
/* signals */
gtk_object_class_add_signals(object_class, signals, LAST_SIGNAL);
}
static void
gnc_search_double_init (GNCSearchDouble *o)
{
o->priv = g_malloc0 (sizeof (*o->priv));
o->how = COMPARE_LT;
}
static void
gnc_search_double_finalise (GtkObject *obj)
{
GNCSearchDouble *o = (GNCSearchDouble *)obj;
g_assert (IS_GNCSEARCH_DOUBLE (o));
g_free(o->priv);
((GtkObjectClass *)(parent_class))->finalize(obj);
}
/**
* gnc_search_double_new:
*
* Create a new GNCSearchDouble object.
*
* Return value: A new #GNCSearchDouble object.
**/
GNCSearchDouble *
gnc_search_double_new (void)
{
GNCSearchDouble *o = (GNCSearchDouble *)gtk_type_new(gnc_search_double_get_type ());
return o;
}
void
gnc_search_double_set_value (GNCSearchDouble *fi, double value)
{
g_return_if_fail (fi);
g_return_if_fail (IS_GNCSEARCH_DOUBLE (fi));
fi->value = value;
}
void
gnc_search_double_set_how (GNCSearchDouble *fi, query_compare_t how)
{
g_return_if_fail (fi);
g_return_if_fail (IS_GNCSEARCH_DOUBLE (fi));
fi->how = how;
}
static gboolean
validate (GNCSearchCoreType *fe)
{
GNCSearchDouble *fi = (GNCSearchDouble *)fe;
gboolean valid = TRUE;
g_return_val_if_fail (fi, FALSE);
g_return_val_if_fail (IS_GNCSEARCH_DOUBLE (fi), FALSE);
/* XXX */
return valid;
}
static void
option_changed (GtkWidget *widget, GNCSearchDouble *fe)
{
fe->how = (query_compare_t)
gtk_object_get_data (GTK_OBJECT (widget), "option");
}
static void
entry_changed (GNCAmountEdit *entry, GNCSearchDouble *fe)
{
fe->value = gnc_amount_edit_get_damount (entry);
}
static GtkWidget *
add_menu_item (GtkWidget *menu, gpointer user_data, char *label,
query_compare_t option)
{
GtkWidget *item = gtk_menu_item_new_with_label (label);
gtk_object_set_data (GTK_OBJECT (item), "option", (gpointer) option);
gtk_signal_connect (GTK_OBJECT (item), "activate", option_changed, user_data);
gtk_menu_append (GTK_MENU (menu), item);
gtk_widget_show (item);
return item;
}
#define ADD_MENU_ITEM(str,op) { \
item = add_menu_item (menu, fe, str, op); \
if (fi->how == op) { current = index; first = item; } \
index++; \
}
static GtkWidget *
make_menu (GNCSearchCoreType *fe)
{
GNCSearchDouble *fi = (GNCSearchDouble *)fe;
GtkWidget *menu, *item, *first, *opmenu;
int current = 0, index = 0;
menu = gtk_menu_new ();
ADD_MENU_ITEM (_("is less than"), COMPARE_LT);
first = item; /* Force one */
ADD_MENU_ITEM (_("is less than or equal to"), COMPARE_LTE);
ADD_MENU_ITEM (_("equals"), COMPARE_EQUAL);
ADD_MENU_ITEM (_("does not equal"), COMPARE_NEQ);
ADD_MENU_ITEM (_("is greater than"), COMPARE_GT);
ADD_MENU_ITEM (_("is greater than or equal to"), COMPARE_GTE);
opmenu = gtk_option_menu_new ();
gtk_option_menu_set_menu (GTK_OPTION_MENU (opmenu), menu);
gtk_signal_emit_by_name (GTK_OBJECT (first), "activate", fe);
gtk_option_menu_set_history (GTK_OPTION_MENU (opmenu), current);
return opmenu;
}
static GtkWidget *
get_widget (GNCSearchCoreType *fe)
{
GtkWidget *entry, *menu, *box;
GNCSearchDouble *fi = (GNCSearchDouble *)fe;
g_return_val_if_fail (fi, NULL);
g_return_val_if_fail (IS_GNCSEARCH_DOUBLE (fi), NULL);
box = gtk_hbox_new (FALSE, 3);
/* Build and connect the option menu */
menu = make_menu (fe);
gtk_box_pack_start (GTK_BOX (box), menu, FALSE, FALSE, 3);
/* Build and connect the entry window */
entry = gnc_amount_edit_new ();
if (fi->value)
gnc_amount_edit_set_damount (GNC_AMOUNT_EDIT (entry), fi->value);
gtk_signal_connect (GTK_OBJECT (entry), "amount_changed", entry_changed, fe);
gtk_box_pack_start (GTK_BOX (box), entry, FALSE, FALSE, 3);
/* And return the box */
return box;
}
static QueryPredData_t get_predicate (GNCSearchCoreType *fe)
{
GNCSearchDouble *fi = (GNCSearchDouble *)fe;
g_return_val_if_fail (fi, NULL);
g_return_val_if_fail (IS_GNCSEARCH_DOUBLE (fi), NULL);
return gncQueryDoublePredicate (fi->how, fi->value);
}
static GNCSearchCoreType *clone(GNCSearchCoreType *fe)
{
GNCSearchDouble *se, *fse = (GNCSearchDouble *)fe;
g_return_val_if_fail (fse, NULL);
g_return_val_if_fail (IS_GNCSEARCH_DOUBLE (fse), NULL);
se = gnc_search_double_new ();
gnc_search_double_set_value (se, fse->value);
gnc_search_double_set_how (se, fse->how);
return (GNCSearchCoreType *)se;
}

View File

@ -0,0 +1,58 @@
/*
* Copyright (C) 2002 Derek Atkins
*
* Authors: Derek Atkins <warlord@MIT.EDU>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef _GNCSEARCH_DOUBLE_H
#define _GNCSEARCH_DOUBLE_H
#include "search-core-type.h"
#include "QueryNew.h"
#define GNCSEARCH_DOUBLE(obj) GTK_CHECK_CAST (obj, gnc_search_double_get_type (), GNCSearchDouble)
#define GNCSEARCH_DOUBLE_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gnc_search_double_get_type (), GNCSearchDoubleClass)
#define IS_GNCSEARCH_DOUBLE(obj) GTK_CHECK_TYPE (obj, gnc_search_double_get_type ())
typedef struct _GNCSearchDouble GNCSearchDouble;
typedef struct _GNCSearchDoubleClass GNCSearchDoubleClass;
struct _GNCSearchDouble {
GNCSearchCoreType parent;
struct _GNCSearchDoublePrivate *priv;
query_compare_t how;
double value;
};
struct _GNCSearchDoubleClass {
GNCSearchCoreTypeClass parent_class;
/* virtual methods */
/* signals */
};
guint gnc_search_double_get_type (void);
GNCSearchDouble *gnc_search_double_new (void);
/* methods */
void gnc_search_double_set_value (GNCSearchDouble *fi, double val);
void gnc_search_double_set_how (GNCSearchDouble *fi, query_compare_t how);
#endif /* ! _GNCSEARCH_DOUBLE_H */

View File

@ -0,0 +1,274 @@
/*
* Copyright (C) 2002 Derek Atkins
*
* Authors: Derek Atkins <warlord@MIT.EDU>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <gnome.h>
#include "gnc-amount-edit.h"
#include "QueryCore.h"
#include "search-int64.h"
#define d(x)
static GNCSearchCoreType *clone(GNCSearchCoreType *fe);
static gboolean validate (GNCSearchCoreType *fe);
static GtkWidget *get_widget(GNCSearchCoreType *fe);
static QueryPredData_t get_predicate (GNCSearchCoreType *fe);
static void gnc_search_int64_class_init (GNCSearchInt64Class *class);
static void gnc_search_int64_init (GNCSearchInt64 *gspaper);
static void gnc_search_int64_finalise (GtkObject *obj);
#define _PRIVATE(x) (((GNCSearchInt64 *)(x))->priv)
struct _GNCSearchInt64Private {
};
static GNCSearchCoreTypeClass *parent_class;
enum {
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
guint
gnc_search_int64_get_type (void)
{
static guint type = 0;
if (!type) {
GtkTypeInfo type_info = {
"GNCSearchInt64",
sizeof(GNCSearchInt64),
sizeof(GNCSearchInt64Class),
(GtkClassInitFunc)gnc_search_int64_class_init,
(GtkObjectInitFunc)gnc_search_int64_init,
(GtkArgSetFunc)NULL,
(GtkArgGetFunc)NULL
};
type = gtk_type_unique(gnc_search_core_type_get_type (), &type_info);
}
return type;
}
static void
gnc_search_int64_class_init (GNCSearchInt64Class *class)
{
GtkObjectClass *object_class;
GNCSearchCoreTypeClass *gnc_search_core_type = (GNCSearchCoreTypeClass *)class;
object_class = (GtkObjectClass *)class;
parent_class = gtk_type_class(gnc_search_core_type_get_type ());
object_class->finalize = gnc_search_int64_finalise;
/* override methods */
gnc_search_core_type->validate = validate;
gnc_search_core_type->get_widget = get_widget;
gnc_search_core_type->get_predicate = get_predicate;
gnc_search_core_type->clone = clone;
/* signals */
gtk_object_class_add_signals(object_class, signals, LAST_SIGNAL);
}
static void
gnc_search_int64_init (GNCSearchInt64 *o)
{
o->priv = g_malloc0 (sizeof (*o->priv));
o->how = COMPARE_LT;
}
static void
gnc_search_int64_finalise (GtkObject *obj)
{
GNCSearchInt64 *o = (GNCSearchInt64 *)obj;
g_assert (IS_GNCSEARCH_INT64 (o));
g_free(o->priv);
((GtkObjectClass *)(parent_class))->finalize(obj);
}
/**
* gnc_search_int64_new:
*
* Create a new GNCSearchInt64 object.
*
* Return value: A new #GNCSearchInt64 object.
**/
GNCSearchInt64 *
gnc_search_int64_new (void)
{
GNCSearchInt64 *o = (GNCSearchInt64 *)gtk_type_new(gnc_search_int64_get_type ());
return o;
}
void
gnc_search_int64_set_value (GNCSearchInt64 *fi, gint64 value)
{
g_return_if_fail (fi);
g_return_if_fail (IS_GNCSEARCH_INT64 (fi));
fi->value = value;
}
void
gnc_search_int64_set_how (GNCSearchInt64 *fi, query_compare_t how)
{
g_return_if_fail (fi);
g_return_if_fail (IS_GNCSEARCH_INT64 (fi));
fi->how = how;
}
static gboolean
validate (GNCSearchCoreType *fe)
{
GNCSearchInt64 *fi = (GNCSearchInt64 *)fe;
gboolean valid = TRUE;
g_return_val_if_fail (fi, FALSE);
g_return_val_if_fail (IS_GNCSEARCH_INT64 (fi), FALSE);
/* XXX */
return valid;
}
static void
option_changed (GtkWidget *widget, GNCSearchInt64 *fe)
{
fe->how = (query_compare_t)
gtk_object_get_data (GTK_OBJECT (widget), "option");
}
static void
entry_changed (GNCAmountEdit *entry, GNCSearchInt64 *fe)
{
gnc_numeric value = gnc_amount_edit_get_amount (entry);
g_assert (value.denom == 1);
fe->value = value.num;
}
static GtkWidget *
add_menu_item (GtkWidget *menu, gpointer user_data, char *label,
query_compare_t option)
{
GtkWidget *item = gtk_menu_item_new_with_label (label);
gtk_object_set_data (GTK_OBJECT (item), "option", (gpointer) option);
gtk_signal_connect (GTK_OBJECT (item), "activate", option_changed, user_data);
gtk_menu_append (GTK_MENU (menu), item);
gtk_widget_show (item);
return item;
}
#define ADD_MENU_ITEM(str,op) { \
item = add_menu_item (menu, fe, str, op); \
if (fi->how == op) { current = index; first = item; } \
index++; \
}
static GtkWidget *
make_menu (GNCSearchCoreType *fe)
{
GNCSearchInt64 *fi = (GNCSearchInt64 *)fe;
GtkWidget *menu, *item, *first, *opmenu;
int current = 0, index = 0;
menu = gtk_menu_new ();
ADD_MENU_ITEM (_("is less than"), COMPARE_LT);
first = item; /* Force one */
ADD_MENU_ITEM (_("is less than or equal to"), COMPARE_LTE);
ADD_MENU_ITEM (_("equals"), COMPARE_EQUAL);
ADD_MENU_ITEM (_("does not equal"), COMPARE_NEQ);
ADD_MENU_ITEM (_("is greater than"), COMPARE_GT);
ADD_MENU_ITEM (_("is greater than or equal to"), COMPARE_GTE);
opmenu = gtk_option_menu_new ();
gtk_option_menu_set_menu (GTK_OPTION_MENU (opmenu), menu);
gtk_signal_emit_by_name (GTK_OBJECT (first), "activate", fe);
gtk_option_menu_set_history (GTK_OPTION_MENU (opmenu), current);
return opmenu;
}
static GtkWidget *
get_widget (GNCSearchCoreType *fe)
{
GtkWidget *entry, *menu, *box;
GNCSearchInt64 *fi = (GNCSearchInt64 *)fe;
g_return_val_if_fail (fi, NULL);
g_return_val_if_fail (IS_GNCSEARCH_INT64 (fi), NULL);
box = gtk_hbox_new (FALSE, 3);
/* Build and connect the option menu */
menu = make_menu (fe);
gtk_box_pack_start (GTK_BOX (box), menu, FALSE, FALSE, 3);
/* Build and connect the entry window */
entry = gnc_amount_edit_new ();
gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (entry),
gnc_integral_print_info ());
if (fi->value) {
gnc_numeric value = gnc_numeric_create (fi->value, 1);
gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (entry), value);
}
gtk_signal_connect (GTK_OBJECT (entry), "amount_changed", entry_changed, fe);
gtk_box_pack_start (GTK_BOX (box), entry, FALSE, FALSE, 3);
/* And return the box */
return box;
}
static QueryPredData_t get_predicate (GNCSearchCoreType *fe)
{
GNCSearchInt64 *fi = (GNCSearchInt64 *)fe;
g_return_val_if_fail (fi, NULL);
g_return_val_if_fail (IS_GNCSEARCH_INT64 (fi), NULL);
return gncQueryInt64Predicate (fi->how, fi->value);
}
static GNCSearchCoreType *clone(GNCSearchCoreType *fe)
{
GNCSearchInt64 *se, *fse = (GNCSearchInt64 *)fe;
g_return_val_if_fail (fse, NULL);
g_return_val_if_fail (IS_GNCSEARCH_INT64 (fse), NULL);
se = gnc_search_int64_new ();
gnc_search_int64_set_value (se, fse->value);
gnc_search_int64_set_how (se, fse->how);
return (GNCSearchCoreType *)se;
}

View File

@ -0,0 +1,58 @@
/*
* Copyright (C) 2002 Derek Atkins
*
* Authors: Derek Atkins <warlord@MIT.EDU>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef _GNCSEARCH_INT64_H
#define _GNCSEARCH_INT64_H
#include "search-core-type.h"
#include "QueryNew.h"
#define GNCSEARCH_INT64(obj) GTK_CHECK_CAST (obj, gnc_search_int64_get_type (), GNCSearchInt64)
#define GNCSEARCH_INT64_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gnc_search_int64_get_type (), GNCSearchInt64Class)
#define IS_GNCSEARCH_INT64(obj) GTK_CHECK_TYPE (obj, gnc_search_int64_get_type ())
typedef struct _GNCSearchInt64 GNCSearchInt64;
typedef struct _GNCSearchInt64Class GNCSearchInt64Class;
struct _GNCSearchInt64 {
GNCSearchCoreType parent;
struct _GNCSearchInt64Private *priv;
query_compare_t how;
gint64 value;
};
struct _GNCSearchInt64Class {
GNCSearchCoreTypeClass parent_class;
/* virtual methods */
/* signals */
};
guint gnc_search_int64_get_type (void);
GNCSearchInt64 *gnc_search_int64_new (void);
/* methods */
void gnc_search_int64_set_value (GNCSearchInt64 *fi, gint64 val);
void gnc_search_int64_set_how (GNCSearchInt64 *fi, query_compare_t how);
#endif /* ! _GNCSEARCH_INT64_H */

View File

@ -0,0 +1,268 @@
/*
* Copyright (C) 2002 Derek Atkins
*
* Authors: Derek Atkins <warlord@MIT.EDU>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <gnome.h>
#include "gnc-amount-edit.h"
#include "QueryCore.h"
#include "search-numeric.h"
#define d(x)
static GNCSearchCoreType *clone(GNCSearchCoreType *fe);
static gboolean validate (GNCSearchCoreType *fe);
static GtkWidget *get_widget(GNCSearchCoreType *fe);
static QueryPredData_t get_predicate (GNCSearchCoreType *fe);
static void gnc_search_numeric_class_init (GNCSearchNumericClass *class);
static void gnc_search_numeric_init (GNCSearchNumeric *gspaper);
static void gnc_search_numeric_finalise (GtkObject *obj);
#define _PRIVATE(x) (((GNCSearchNumeric *)(x))->priv)
struct _GNCSearchNumericPrivate {
};
static GNCSearchCoreTypeClass *parent_class;
enum {
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
guint
gnc_search_numeric_get_type (void)
{
static guint type = 0;
if (!type) {
GtkTypeInfo type_info = {
"GNCSearchNumeric",
sizeof(GNCSearchNumeric),
sizeof(GNCSearchNumericClass),
(GtkClassInitFunc)gnc_search_numeric_class_init,
(GtkObjectInitFunc)gnc_search_numeric_init,
(GtkArgSetFunc)NULL,
(GtkArgGetFunc)NULL
};
type = gtk_type_unique(gnc_search_core_type_get_type (), &type_info);
}
return type;
}
static void
gnc_search_numeric_class_init (GNCSearchNumericClass *class)
{
GtkObjectClass *object_class;
GNCSearchCoreTypeClass *gnc_search_core_type = (GNCSearchCoreTypeClass *)class;
object_class = (GtkObjectClass *)class;
parent_class = gtk_type_class(gnc_search_core_type_get_type ());
object_class->finalize = gnc_search_numeric_finalise;
/* override methods */
gnc_search_core_type->validate = validate;
gnc_search_core_type->get_widget = get_widget;
gnc_search_core_type->get_predicate = get_predicate;
gnc_search_core_type->clone = clone;
/* signals */
gtk_object_class_add_signals(object_class, signals, LAST_SIGNAL);
}
static void
gnc_search_numeric_init (GNCSearchNumeric *o)
{
o->priv = g_malloc0 (sizeof (*o->priv));
o->value = gnc_numeric_zero ();
o->how = COMPARE_LT;
}
static void
gnc_search_numeric_finalise (GtkObject *obj)
{
GNCSearchNumeric *o = (GNCSearchNumeric *)obj;
g_assert (IS_GNCSEARCH_NUMERIC (o));
g_free(o->priv);
((GtkObjectClass *)(parent_class))->finalize(obj);
}
/**
* gnc_search_numeric_new:
*
* Create a new GNCSearchNumeric object.
*
* Return value: A new #GNCSearchNumeric object.
**/
GNCSearchNumeric *
gnc_search_numeric_new (void)
{
GNCSearchNumeric *o = (GNCSearchNumeric *)gtk_type_new(gnc_search_numeric_get_type ());
return o;
}
void
gnc_search_numeric_set_value (GNCSearchNumeric *fi, gnc_numeric value)
{
g_return_if_fail (fi);
g_return_if_fail (IS_GNCSEARCH_NUMERIC (fi));
fi->value = value;
}
void
gnc_search_numeric_set_how (GNCSearchNumeric *fi, query_compare_t how)
{
g_return_if_fail (fi);
g_return_if_fail (IS_GNCSEARCH_NUMERIC (fi));
fi->how = how;
}
static gboolean
validate (GNCSearchCoreType *fe)
{
GNCSearchNumeric *fi = (GNCSearchNumeric *)fe;
gboolean valid = TRUE;
g_return_val_if_fail (fi, FALSE);
g_return_val_if_fail (IS_GNCSEARCH_NUMERIC (fi), FALSE);
/* XXX */
return valid;
}
static void
option_changed (GtkWidget *widget, GNCSearchNumeric *fe)
{
fe->how = (query_compare_t)
gtk_object_get_data (GTK_OBJECT (widget), "option");
}
static void
entry_changed (GNCAmountEdit *entry, GNCSearchNumeric *fe)
{
fe->value = gnc_amount_edit_get_amount (entry);
}
static GtkWidget *
add_menu_item (GtkWidget *menu, gpointer user_data, char *label,
query_compare_t option)
{
GtkWidget *item = gtk_menu_item_new_with_label (label);
gtk_object_set_data (GTK_OBJECT (item), "option", (gpointer) option);
gtk_signal_connect (GTK_OBJECT (item), "activate", option_changed, user_data);
gtk_menu_append (GTK_MENU (menu), item);
gtk_widget_show (item);
return item;
}
#define ADD_MENU_ITEM(str,op) { \
item = add_menu_item (menu, fe, str, op); \
if (fi->how == op) { current = index; first = item; } \
index++; \
}
static GtkWidget *
make_menu (GNCSearchCoreType *fe)
{
GNCSearchNumeric *fi = (GNCSearchNumeric *)fe;
GtkWidget *menu, *item, *first, *opmenu;
int current = 0, index = 0;
menu = gtk_menu_new ();
ADD_MENU_ITEM (_("is less than"), COMPARE_LT);
first = item; /* Force one */
ADD_MENU_ITEM (_("is less than or equal to"), COMPARE_LTE);
ADD_MENU_ITEM (_("equals"), COMPARE_EQUAL);
ADD_MENU_ITEM (_("does not equal"), COMPARE_NEQ);
ADD_MENU_ITEM (_("is greater than"), COMPARE_GT);
ADD_MENU_ITEM (_("is greater than or equal to"), COMPARE_GTE);
opmenu = gtk_option_menu_new ();
gtk_option_menu_set_menu (GTK_OPTION_MENU (opmenu), menu);
gtk_signal_emit_by_name (GTK_OBJECT (first), "activate", fe);
gtk_option_menu_set_history (GTK_OPTION_MENU (opmenu), current);
return opmenu;
}
static GtkWidget *
get_widget (GNCSearchCoreType *fe)
{
GtkWidget *entry, *menu, *box;
GNCSearchNumeric *fi = (GNCSearchNumeric *)fe;
g_return_val_if_fail (fi, NULL);
g_return_val_if_fail (IS_GNCSEARCH_NUMERIC (fi), NULL);
box = gtk_hbox_new (FALSE, 3);
/* Build and connect the option menu */
menu = make_menu (fe);
gtk_box_pack_start (GTK_BOX (box), menu, FALSE, FALSE, 3);
/* Build and connect the entry window */
entry = gnc_amount_edit_new ();
gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (entry), fi->value);
gtk_signal_connect (GTK_OBJECT (entry), "amount_changed", entry_changed, fe);
gtk_box_pack_start (GTK_BOX (box), entry, FALSE, FALSE, 3);
/* And return the box */
return box;
}
static QueryPredData_t get_predicate (GNCSearchCoreType *fe)
{
GNCSearchNumeric *fi = (GNCSearchNumeric *)fe;
g_return_val_if_fail (fi, NULL);
g_return_val_if_fail (IS_GNCSEARCH_NUMERIC (fi), NULL);
return gncQueryNumericPredicate (fi->how, NUMERIC_MATCH_ANY, fi->value);
}
static GNCSearchCoreType *clone(GNCSearchCoreType *fe)
{
GNCSearchNumeric *se, *fse = (GNCSearchNumeric *)fe;
g_return_val_if_fail (fse, NULL);
g_return_val_if_fail (IS_GNCSEARCH_NUMERIC (fse), NULL);
se = gnc_search_numeric_new ();
gnc_search_numeric_set_value (se, fse->value);
gnc_search_numeric_set_how (se, fse->how);
return (GNCSearchCoreType *)se;
}

View File

@ -0,0 +1,59 @@
/*
* Copyright (C) 2002 Derek Atkins
*
* Authors: Derek Atkins <warlord@MIT.EDU>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* 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, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef _GNCSEARCH_NUMERIC_H
#define _GNCSEARCH_NUMERIC_H
#include "search-core-type.h"
#include "gnc-numeric.h"
#include "QueryNew.h"
#define GNCSEARCH_NUMERIC(obj) GTK_CHECK_CAST (obj, gnc_search_numeric_get_type (), GNCSearchNumeric)
#define GNCSEARCH_NUMERIC_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gnc_search_numeric_get_type (), GNCSearchNumericClass)
#define IS_GNCSEARCH_NUMERIC(obj) GTK_CHECK_TYPE (obj, gnc_search_numeric_get_type ())
typedef struct _GNCSearchNumeric GNCSearchNumeric;
typedef struct _GNCSearchNumericClass GNCSearchNumericClass;
struct _GNCSearchNumeric {
GNCSearchCoreType parent;
struct _GNCSearchNumericPrivate *priv;
query_compare_t how;
gnc_numeric value;
};
struct _GNCSearchNumericClass {
GNCSearchCoreTypeClass parent_class;
/* virtual methods */
/* signals */
};
guint gnc_search_numeric_get_type (void);
GNCSearchNumeric *gnc_search_numeric_new (void);
/* methods */
void gnc_search_numeric_set_value (GNCSearchNumeric *fi, gnc_numeric val);
void gnc_search_numeric_set_how (GNCSearchNumeric *fi, query_compare_t how);
#endif /* ! _GNCSEARCH_NUMERIC_H */