29 #include <glib/gi18n.h>
34 #include "gnc-gui-query.h"
36 #include "search-account.h"
37 #include "search-core-utils.h"
48 static void gnc_search_account_finalize (GObject *obj);
55 GList * selected_accounts;
59 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_SEARCH_ACCOUNT, GNCSearchAccountPrivate))
65 gnc_search_account_get_type (
void)
67 static GType type = 0;
76 (GClassInitFunc)gnc_search_account_class_init,
81 (GInstanceInitFunc)gnc_search_account_init,
84 type = g_type_register_static (GNC_TYPE_SEARCH_CORE_TYPE,
95 GObjectClass *object_class;
98 object_class = G_OBJECT_CLASS (klass);
99 parent_class = g_type_class_peek_parent (klass);
101 object_class->finalize = gnc_search_account_finalize;
104 gnc_search_core_type->validate = gncs_validate;
105 gnc_search_core_type->get_widget = gncs_get_widget;
106 gnc_search_core_type->get_predicate = gncs_get_predicate;
107 gnc_search_core_type->clone = gncs_clone;
119 gnc_search_account_finalize (GObject *obj)
122 g_assert (IS_GNCSEARCH_ACCOUNT (o));
124 G_OBJECT_CLASS (parent_class)->finalize(obj);
135 gnc_search_account_new (
void)
149 gnc_search_account_matchall_new (
void)
154 o = g_object_new(GNC_TYPE_SEARCH_ACCOUNT, NULL);
156 priv->match_all = TRUE;
166 gboolean valid = TRUE;
168 g_return_val_if_fail (fi, FALSE);
169 g_return_val_if_fail (IS_GNCSEARCH_ACCOUNT (fi), FALSE);
172 if (priv->selected_accounts == NULL && fi->how )
175 gnc_error_dialog (NULL,
"%s", _(
"You have not selected any accounts"));
191 combo = GTK_COMBO_BOX(gnc_combo_box_new_search());
202 gnc_combo_box_search_add(combo, _(
"matches no accounts"), QOF_GUID_MATCH_NONE);
206 gnc_combo_box_search_changed(combo, &fi->how);
207 gnc_combo_box_search_set_active(combo, fi->how ? fi->how : initial);
209 return GTK_WIDGET(combo);
218 if (priv->selected_accounts)
219 return (_(
"Selected Accounts"));
220 return (_(
"Choose Accounts"));
228 GtkWidget *account_tree;
229 GtkWidget *accounts_scroller;
232 GtkTreeSelection *selection;
236 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(account_tree), FALSE);
237 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(account_tree));
238 gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
242 if (priv->selected_accounts)
244 priv->selected_accounts, FALSE);
247 accounts_scroller = gtk_scrolled_window_new (NULL, NULL);
248 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(accounts_scroller),
249 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
250 gtk_container_add(GTK_CONTAINER(accounts_scroller), account_tree);
251 gtk_widget_set_size_request(GTK_WIDGET(accounts_scroller), 300, 300);
254 label = gtk_label_new (_(
"Select Accounts to Match"));
258 GTK_DIALOG(gtk_dialog_new_with_buttons(_(
"Select the Accounts to Compare"),
261 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
262 GTK_STOCK_OK, GTK_RESPONSE_OK,
266 gtk_box_pack_start ((GtkBox *)dialog->vbox, label,
268 gtk_box_pack_start ((GtkBox *)dialog->vbox, accounts_scroller,
271 gtk_widget_show_all (GTK_WIDGET (dialog));
274 if (gtk_dialog_run (dialog) == GTK_RESPONSE_OK)
276 if (priv->selected_accounts)
277 g_list_free (priv->selected_accounts);
279 priv->selected_accounts =
282 desc = describe_button (fi);
283 gtk_label_set_text (GTK_LABEL (GTK_BIN (button)->child), desc);
286 gtk_widget_destroy (GTK_WIDGET (dialog));
292 GtkWidget *button, *label, *menu, *box;
296 g_return_val_if_fail (fi, NULL);
297 g_return_val_if_fail (IS_GNCSEARCH_ACCOUNT (fi), NULL);
299 box = gtk_hbox_new (FALSE, 3);
302 menu = make_menu (fe);
303 gtk_box_pack_start (GTK_BOX (box), menu, FALSE, FALSE, 3);
306 desc = describe_button (fi);
307 label = gtk_label_new (desc);
308 gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
310 button = gtk_button_new ();
311 gtk_container_add (GTK_CONTAINER (button), label);
312 g_signal_connect (G_OBJECT (button),
"clicked", G_CALLBACK (button_clicked), fe);
313 gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 3);
323 GList *l = NULL, *node;
325 g_return_val_if_fail (fi, NULL);
326 g_return_val_if_fail (IS_GNCSEARCH_ACCOUNT (fi), NULL);
329 for (node = priv->selected_accounts; node; node = node->next)
333 l = g_list_prepend (l, (gpointer)guid);
335 l = g_list_reverse (l);
337 return qof_query_guid_predicate (fi->how, l);
345 g_return_val_if_fail (fse, NULL);
346 g_return_val_if_fail (IS_GNCSEARCH_ACCOUNT (fse), NULL);
347 fse_priv = _PRIVATE(fse);
349 se = gnc_search_account_new ();
350 se_priv = _PRIVATE(se);
352 se_priv->match_all = fse_priv->match_all;
353 se_priv->selected_accounts = g_list_copy (fse_priv->selected_accounts);
GList * gnc_tree_view_account_get_selected_accounts(GncTreeViewAccount *view)
void gnc_tree_view_account_set_selected_accounts(GncTreeViewAccount *view, GList *account_list, gboolean show_last)
#define xaccAccountGetGUID(X)
Account handling public routines.
GtkTreeView implementation for gnucash account tree.
GtkTreeView * gnc_tree_view_account_new(gboolean show_root)