GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
search-reconciled.c
1 /*
2  * Copyright (C) 2002 Derek Atkins
3  *
4  * Authors: Derek Atkins <[email protected]>
5  *
6  * Copyright (c) 2006 David Hampton <[email protected]>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public
19  * License along with this program; if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  */
23 
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27 
28 #include <gtk/gtk.h>
29 #include <glib/gi18n.h>
30 
31 #include "qof.h"
32 #include "Transaction.h" /* for ?REC */
33 
34 #include "search-reconciled.h"
35 #include "search-core-utils.h"
36 
37 #define d(x)
38 
39 static GNCSearchCoreType *gncs_clone(GNCSearchCoreType *fe);
40 static gboolean gncs_validate (GNCSearchCoreType *fe);
41 static GtkWidget *gncs_get_widget(GNCSearchCoreType *fe);
42 static QofQueryPredData* gncs_get_predicate (GNCSearchCoreType *fe);
43 
44 static void gnc_search_reconciled_class_init (GNCSearchReconciledClass *klass);
45 static void gnc_search_reconciled_init (GNCSearchReconciled *gspaper);
46 static void gnc_search_reconciled_finalize (GObject *obj);
47 
49 
51 {
52  gpointer dummy;
53 };
54 
55 #define _PRIVATE(o) \
56  (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_SEARCH_RECONCILED, GNCSearchReconciledPrivate))
57 
58 static GNCSearchCoreTypeClass *parent_class;
59 
60 GType
61 gnc_search_reconciled_get_type (void)
62 {
63  static GType type = 0;
64 
65  if (!type)
66  {
67  GTypeInfo type_info =
68  {
69  sizeof(GNCSearchReconciledClass), /* class_size */
70  NULL, /* base_init */
71  NULL, /* base_finalize */
72  (GClassInitFunc)gnc_search_reconciled_class_init,
73  NULL, /* class_finalize */
74  NULL, /* class_data */
75  sizeof(GNCSearchReconciled), /* */
76  0, /* n_preallocs */
77  (GInstanceInitFunc)gnc_search_reconciled_init,
78  };
79 
80  type = g_type_register_static (GNC_TYPE_SEARCH_CORE_TYPE,
81  "GNCSearchReconciled",
82  &type_info, 0);
83  }
84 
85  return type;
86 }
87 
88 static void
89 gnc_search_reconciled_class_init (GNCSearchReconciledClass *klass)
90 {
91  GObjectClass *object_class;
92  GNCSearchCoreTypeClass *gnc_search_core_type = (GNCSearchCoreTypeClass *)klass;
93 
94  object_class = G_OBJECT_CLASS (klass);
95  parent_class = g_type_class_peek_parent (klass);
96 
97  object_class->finalize = gnc_search_reconciled_finalize;
98 
99  /* override methods */
100  gnc_search_core_type->validate = gncs_validate;
101  gnc_search_core_type->get_widget = gncs_get_widget;
102  gnc_search_core_type->get_predicate = gncs_get_predicate;
103  gnc_search_core_type->clone = gncs_clone;
104 
105  g_type_class_add_private(klass, sizeof(GNCSearchReconciledPrivate));
106 }
107 
108 static void
109 gnc_search_reconciled_init (GNCSearchReconciled *o)
110 {
111  o->how = QOF_CHAR_MATCH_ANY;;
112  o->value = CLEARED_NO;
113 }
114 
115 static void
116 gnc_search_reconciled_finalize (GObject *obj)
117 {
119  g_assert (IS_GNCSEARCH_RECONCILED (o));
120 
121  G_OBJECT_CLASS (parent_class)->finalize(obj);
122 }
123 
132 gnc_search_reconciled_new (void)
133 {
134  GNCSearchReconciled *o = g_object_new(GNC_TYPE_SEARCH_RECONCILED, NULL);
135  return o;
136 }
137 
138 void
139 gnc_search_reconciled_set_value (GNCSearchReconciled *fi, cleared_match_t value)
140 {
141  g_return_if_fail (fi);
142  g_return_if_fail (IS_GNCSEARCH_RECONCILED (fi));
143 
144  fi->value = value;
145 }
146 
147 void
148 gnc_search_reconciled_set_how (GNCSearchReconciled *fi, QofCharMatch how)
149 {
150  g_return_if_fail (fi);
151  g_return_if_fail (IS_GNCSEARCH_RECONCILED (fi));
152  fi->how = how;
153 }
154 
155 static gboolean
156 gncs_validate (GNCSearchCoreType *fe)
157 {
159  gboolean valid = TRUE;
160 
161  g_return_val_if_fail (fi, FALSE);
162  g_return_val_if_fail (IS_GNCSEARCH_RECONCILED (fi), FALSE);
163 
164  /* XXX */
165 
166  return valid;
167 }
168 
169 static void
170 toggle_changed (GtkToggleButton *button, GNCSearchReconciled *fe)
171 {
172  gboolean is_on = gtk_toggle_button_get_active (button);
173  cleared_match_t value =
174  (cleared_match_t) g_object_get_data (G_OBJECT (button), "button-value");
175 
176  if (is_on)
177  fe->value |= value;
178  else
179  fe->value &= ~value;
180 }
181 
182 static GtkWidget *
183 make_menu (GNCSearchCoreType *fe)
184 {
186  GtkComboBox *combo;
187 
188  combo = GTK_COMBO_BOX(gnc_combo_box_new_search());
189  gnc_combo_box_search_add(combo, _("is"), QOF_CHAR_MATCH_ANY);
190  gnc_combo_box_search_add(combo, _("is not"), QOF_CHAR_MATCH_NONE);
191  gnc_combo_box_search_changed(combo, &fi->how);
192  gnc_combo_box_search_set_active(combo, fi->how ? fi->how : QOF_CHAR_MATCH_ANY);
193 
194  return GTK_WIDGET(combo);
195 }
196 
197 static GtkWidget *
198 make_toggle (GNCSearchReconciled *fi, char *label, cleared_match_t option)
199 {
200  GtkWidget *toggle;
201 
202  toggle = gtk_toggle_button_new_with_label (label);
203  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), (fi->value & option));
204  g_object_set_data (G_OBJECT (toggle), "button-value", (gpointer) option);
205  g_signal_connect (G_OBJECT (toggle), "toggled", G_CALLBACK (toggle_changed), fi);
206 
207  return toggle;
208 }
209 
210 static GtkWidget *
211 gncs_get_widget (GNCSearchCoreType *fe)
212 {
213  GtkWidget *toggle, *menu, *box;
215 
216  g_return_val_if_fail (fi, NULL);
217  g_return_val_if_fail (IS_GNCSEARCH_RECONCILED (fi), NULL);
218 
219  box = gtk_hbox_new (FALSE, 3);
220 
221  /* Build and connect the option menu */
222  menu = make_menu (fe);
223  gtk_box_pack_start (GTK_BOX (box), menu, FALSE, FALSE, 3);
224 
225  /* Build and connect the toggles */
226  toggle = make_toggle (fi, _("Not Cleared"), CLEARED_NO);
227  gtk_box_pack_start (GTK_BOX (box), toggle, FALSE, FALSE, 3);
228 
229  toggle = make_toggle (fi, _("Cleared"), CLEARED_CLEARED);
230  gtk_box_pack_start (GTK_BOX (box), toggle, FALSE, FALSE, 3);
231 
232  toggle = make_toggle (fi, _("Reconciled"), CLEARED_RECONCILED);
233  gtk_box_pack_start (GTK_BOX (box), toggle, FALSE, FALSE, 3);
234 
235  toggle = make_toggle (fi, _("Frozen"), CLEARED_FROZEN);
236  gtk_box_pack_start (GTK_BOX (box), toggle, FALSE, FALSE, 3);
237 
238  toggle = make_toggle (fi, _("Voided"), CLEARED_VOIDED);
239  gtk_box_pack_start (GTK_BOX (box), toggle, FALSE, FALSE, 3);
240 
241  /* And return the box */
242  return box;
243 }
244 
245 static QofQueryPredData* gncs_get_predicate (GNCSearchCoreType *fe)
246 {
248  char chars[6];
249  cleared_match_t value;
250  int i;
251 
252  g_return_val_if_fail (fi, NULL);
253  g_return_val_if_fail (IS_GNCSEARCH_RECONCILED (fi), NULL);
254 
255  /* This code should look a lot like xaccQueryAddClearedMatch() */
256 
257  value = fi->value;
258  i = 0;
259 
260  if (value & CLEARED_CLEARED)
261  chars[i++] = CREC;
262  if (value & CLEARED_RECONCILED)
263  chars[i++] = YREC;
264  if (value & CLEARED_FROZEN)
265  chars[i++] = FREC;
266  if (value & CLEARED_NO)
267  chars[i++] = NREC;
268  if (value & CLEARED_VOIDED)
269  chars[i++] = VREC;
270  chars[i] = '\0';
271 
272  return qof_query_char_predicate (fi->how, chars);
273 }
274 
275 static GNCSearchCoreType *gncs_clone(GNCSearchCoreType *fe)
276 {
277  GNCSearchReconciled *se, *fse = (GNCSearchReconciled *)fe;
278 
279  g_return_val_if_fail (fse, NULL);
280  g_return_val_if_fail (IS_GNCSEARCH_RECONCILED (fse), NULL);
281 
282  se = gnc_search_reconciled_new ();
283  gnc_search_reconciled_set_value (se, fse->value);
284  gnc_search_reconciled_set_how (se, fse->how);
285 
286  return (GNCSearchCoreType *)se;
287 }
#define VREC
Definition: Split.h:71
#define YREC
Definition: Split.h:68
#define FREC
Definition: Split.h:69
QofCharMatch
Definition: qofquerycore.h:133
#define CREC
Definition: Split.h:67
API for Transactions and Splits (journal entries)
#define NREC
Definition: Split.h:70