GnuCash  5.6-150-g038405b370+
search-reconciled.c
1 /*
2  * Copyright (C) 2002 Derek Atkins
3  *
4  * Authors: Derek Atkins <warlord@MIT.EDU>
5  *
6  * Copyright (c) 2006 David Hampton <hampton@employees.org>
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 <stdint.h>
29 #include <gtk/gtk.h>
30 #include <glib/gi18n.h>
31 
32 #include "qof.h"
33 #include "Transaction.h" /* for ?REC */
34 
35 #include "search-reconciled.h"
36 #include "search-core-utils.h"
37 
38 #define d(x)
39 
40 static void pass_parent (GNCSearchCoreType *fe, gpointer parent);
41 static GNCSearchCoreType *gncs_clone(GNCSearchCoreType *fe);
42 static gboolean gncs_validate (GNCSearchCoreType *fe);
43 static GtkWidget *gncs_get_widget(GNCSearchCoreType *fe);
44 static QofQueryPredData* gncs_get_predicate (GNCSearchCoreType *fe);
45 
46 static void gnc_search_reconciled_finalize (GObject *obj);
47 
49 {
50  GNCSearchCoreType parent_instance;
51 
52  QofCharMatch how;
53  cleared_match_t value;
54 
55  GtkWindow *parent;
56 };
57 
58 G_DEFINE_TYPE(GNCSearchReconciled, gnc_search_reconciled, GNC_TYPE_SEARCH_CORE_TYPE)
59 
60 static void
61 gnc_search_reconciled_class_init (GNCSearchReconciledClass *klass)
62 {
63  GObjectClass *object_class;
64  GNCSearchCoreTypeClass *gnc_search_core_type = (GNCSearchCoreTypeClass *)klass;
65 
66  object_class = G_OBJECT_CLASS (klass);
67 
68  object_class->finalize = gnc_search_reconciled_finalize;
69 
70  /* override methods */
71  gnc_search_core_type->pass_parent = pass_parent;
72  gnc_search_core_type->validate = gncs_validate;
73  gnc_search_core_type->get_widget = gncs_get_widget;
74  gnc_search_core_type->get_predicate = gncs_get_predicate;
75  gnc_search_core_type->clone = gncs_clone;
76 }
77 
78 static void
79 gnc_search_reconciled_init (GNCSearchReconciled *o)
80 {
81  o->how = QOF_CHAR_MATCH_ANY;
82  o->value = CLEARED_NO;
83 }
84 
85 static void
86 gnc_search_reconciled_finalize (GObject *obj)
87 {
88  GNCSearchReconciled *o = (GNCSearchReconciled *)obj;
89  g_assert (GNC_IS_SEARCH_RECONCILED (o));
90 
91  G_OBJECT_CLASS (gnc_search_reconciled_parent_class)->finalize(obj);
92 }
93 
101 GNCSearchReconciled *
102 gnc_search_reconciled_new (void)
103 {
104  GNCSearchReconciled *o = g_object_new(GNC_TYPE_SEARCH_RECONCILED, NULL);
105  return o;
106 }
107 
108 void
109 gnc_search_reconciled_set_value (GNCSearchReconciled *fi, cleared_match_t value)
110 {
111  g_return_if_fail (fi);
112  g_return_if_fail (GNC_IS_SEARCH_RECONCILED (fi));
113 
114  fi->value = value;
115 }
116 
117 void
118 gnc_search_reconciled_set_how (GNCSearchReconciled *fi, QofCharMatch how)
119 {
120  g_return_if_fail (fi);
121  g_return_if_fail (GNC_IS_SEARCH_RECONCILED (fi));
122  fi->how = how;
123 }
124 
125 static void
126 pass_parent (GNCSearchCoreType *fe, gpointer parent)
127 {
128  GNCSearchReconciled *fi = (GNCSearchReconciled *)fe;
129 
130  g_return_if_fail (fi);
131  g_return_if_fail (GNC_IS_SEARCH_RECONCILED (fi));
132 
133  fi->parent = GTK_WINDOW(parent);
134 }
135 
136 static gboolean
137 gncs_validate (GNCSearchCoreType *fe)
138 {
139  GNCSearchReconciled *fi = (GNCSearchReconciled *)fe;
140  gboolean valid = TRUE;
141 
142  g_return_val_if_fail (fi, FALSE);
143  g_return_val_if_fail (GNC_IS_SEARCH_RECONCILED (fi), FALSE);
144 
145  /* XXX */
146 
147  return valid;
148 }
149 
150 static void
151 toggle_changed (GtkToggleButton *button, GNCSearchReconciled *fe)
152 {
153  gboolean is_on = gtk_toggle_button_get_active (button);
154 #ifdef __LP64__
155  cleared_match_t value =
156  (cleared_match_t) ((uint64_t)g_object_get_data (G_OBJECT (button), "button-value") & 0xffffffff); // Binary mask to silence void-pointer-to-enum-cast warning.
157 #else
158  cleared_match_t value =
159  (cleared_match_t)g_object_get_data (G_OBJECT (button), "button-value");
160 #endif
161 
162  if (is_on)
163  fe->value |= value;
164  else
165  fe->value &= ~value;
166 }
167 
168 static GtkWidget *
169 make_menu (GNCSearchCoreType *fe)
170 {
171  GNCSearchReconciled *fi = (GNCSearchReconciled *)fe;
172  GtkComboBox *combo;
173 
174  combo = GTK_COMBO_BOX(gnc_combo_box_new_search());
175  gnc_combo_box_search_add(combo, _("is"), QOF_CHAR_MATCH_ANY);
176  gnc_combo_box_search_add(combo, _("is not"), QOF_CHAR_MATCH_NONE);
177  gnc_combo_box_search_changed(combo, &fi->how);
178  gnc_combo_box_search_set_active(combo, fi->how ? fi->how : QOF_CHAR_MATCH_ANY);
179 
180  return GTK_WIDGET(combo);
181 }
182 
183 static GtkWidget *
184 make_toggle (GNCSearchReconciled *fi, char *label, cleared_match_t option)
185 {
186  GtkWidget *toggle;
187 
188  toggle = gtk_check_button_new_with_label (label);
189  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), (fi->value & option));
190  g_object_set_data (G_OBJECT (toggle), "button-value", (gpointer) option);
191  g_signal_connect (G_OBJECT (toggle), "toggled", G_CALLBACK (toggle_changed), fi);
192 
193  return toggle;
194 }
195 
196 static GtkWidget *
197 gncs_get_widget (GNCSearchCoreType *fe)
198 {
199  GtkWidget *toggle, *menu, *box;
200  GNCSearchReconciled *fi = (GNCSearchReconciled *)fe;
201 
202  g_return_val_if_fail (fi, NULL);
203  g_return_val_if_fail (GNC_IS_SEARCH_RECONCILED (fi), NULL);
204 
205  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
206  gtk_box_set_homogeneous (GTK_BOX (box), FALSE);
207 
208  /* Build and connect the option menu */
209  menu = make_menu (fe);
210  gtk_box_pack_start (GTK_BOX (box), menu, FALSE, FALSE, 3);
211 
212  /* Build and connect the toggles */
213  toggle = make_toggle (fi, _("Not Cleared"), CLEARED_NO);
214  gtk_box_pack_start (GTK_BOX (box), toggle, FALSE, FALSE, 3);
215 
216  toggle = make_toggle (fi, _("Cleared"), CLEARED_CLEARED);
217  gtk_box_pack_start (GTK_BOX (box), toggle, FALSE, FALSE, 3);
218 
219  toggle = make_toggle (fi, _("Reconciled"), CLEARED_RECONCILED);
220  gtk_box_pack_start (GTK_BOX (box), toggle, FALSE, FALSE, 3);
221 
222  toggle = make_toggle (fi, _("Frozen"), CLEARED_FROZEN);
223  gtk_box_pack_start (GTK_BOX (box), toggle, FALSE, FALSE, 3);
224 
225  toggle = make_toggle (fi, _("Voided"), CLEARED_VOIDED);
226  gtk_box_pack_start (GTK_BOX (box), toggle, FALSE, FALSE, 3);
227 
228  /* And return the box */
229  return box;
230 }
231 
232 static QofQueryPredData* gncs_get_predicate (GNCSearchCoreType *fe)
233 {
234  GNCSearchReconciled *fi = (GNCSearchReconciled *)fe;
235  char chars[6];
236  cleared_match_t value;
237  int i;
238 
239  g_return_val_if_fail (fi, NULL);
240  g_return_val_if_fail (GNC_IS_SEARCH_RECONCILED (fi), NULL);
241 
242  /* This code should look a lot like xaccQueryAddClearedMatch() */
243 
244  value = fi->value;
245  i = 0;
246 
247  if (value & CLEARED_CLEARED)
248  chars[i++] = CREC;
249  if (value & CLEARED_RECONCILED)
250  chars[i++] = YREC;
251  if (value & CLEARED_FROZEN)
252  chars[i++] = FREC;
253  if (value & CLEARED_NO)
254  chars[i++] = NREC;
255  if (value & CLEARED_VOIDED)
256  chars[i++] = VREC;
257  chars[i] = '\0';
258 
259  return qof_query_char_predicate (fi->how, chars);
260 }
261 
262 static GNCSearchCoreType *gncs_clone(GNCSearchCoreType *fe)
263 {
264  GNCSearchReconciled *se, *fse = (GNCSearchReconciled *)fe;
265 
266  g_return_val_if_fail (fse, NULL);
267  g_return_val_if_fail (GNC_IS_SEARCH_RECONCILED (fse), NULL);
268 
269  se = gnc_search_reconciled_new ();
270  gnc_search_reconciled_set_value (se, fse->value);
271  gnc_search_reconciled_set_how (se, fse->how);
272 
273  return (GNCSearchCoreType *)se;
274 }
#define VREC
split is void
Definition: Split.h:77
#define YREC
The Split has been reconciled.
Definition: Split.h:74
#define FREC
frozen into accounting period
Definition: Split.h:75
QofCharMatch
A CHAR type is for a RECNCell, Comparisons for QOF_TYPE_CHAR &#39;ANY&#39; will match any character in the st...
Definition: qofquerycore.h:132
#define CREC
The Split has been cleared.
Definition: Split.h:73
API for Transactions and Splits (journal entries)
#define NREC
not reconciled or cleared
Definition: Split.h:76