26#include <glib/gi18n.h>
28#include "dialog-utils.h"
29#include "gnc-amount-edit.h"
35#include "gnc-autoclear.h"
36#include "window-autoclear.h"
38#define WINDOW_AUTOCLEAR_CM_CLASS "window-autoclear"
40__attribute__((unused))
static QofLogModule log_module = GNC_MOD_GUI;
43struct _AutoClearWindow
50 GNCAmountEdit *end_value;
52 GtkWidget *cancel_button;
53 GtkWidget *show_cleared_splits_button;
54 GtkLabel *status_label;
58void gnc_autoclear_window_ok_cb (GtkWidget *widget,
59 AutoClearWindow *data);
60void gnc_autoclear_window_cancel_cb (GtkWidget *widget,
61 AutoClearWindow *data);
70gnc_ui_autoclear_window_raise(AutoClearWindow * autoClearData)
72 if (autoClearData == NULL)
75 if (autoClearData->window == NULL)
78 gtk_window_present(GTK_WINDOW(autoClearData->window));
82gnc_autoclear_make_window_name(
Account *account)
88 title = g_strconcat(fullname,
" - ",
_(
"Auto-clear"), NULL);
96show_cleared_splits (GList *splits)
98 GNCLedgerDisplay *ledger;
100 Query *book_query, *guid_query;
102 book_query = qof_query_create_for (GNC_ID_SPLIT);
103 guid_query = qof_query_create_for (GNC_ID_SPLIT);
106 for (GList *iter = splits; iter; iter = iter->next)
109 xaccQueryAddGUIDMatch (guid_query, &guid, GNC_ID_SPLIT, QOF_QUERY_OR);
122gnc_autoclear_window_ok_cb (GtkWidget *widget,
123 AutoClearWindow *data)
125 GList *toclear_list = NULL;
127 GError* error = NULL;
129 g_return_if_fail (widget && data);
132 if (gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT(data->end_value), &error))
134 toclear_value = gnc_amount_edit_get_amount(data->end_value);
136 if (gnc_reverse_balance(data->account))
139 toclear_value = gnc_numeric_convert
142#define MAX_AUTOCLEAR_SECONDS 5
144 toclear_list = gnc_account_get_autoclear_splits
145 (data->account, toclear_value, INT64_MAX, &error,
146 MAX_AUTOCLEAR_SECONDS);
149 if (error && error->message)
151 GtkWidget *entry = gnc_amount_edit_gtk_entry (GNC_AMOUNT_EDIT(data->end_value));
152 gtk_label_set_text (data->status_label, error->message);
153 if (gnc_numeric_check (toclear_value) == 0)
154 gnc_amount_edit_set_amount (data->end_value, toclear_value);
155 gtk_widget_grab_focus (GTK_WIDGET(entry));
156 gnc_amount_edit_select_region (GNC_AMOUNT_EDIT(data->end_value), 0, -1);
157 g_error_free (error);
162 for (GList *node = toclear_list; node; node = node->next)
166 if (gtk_toggle_button_get_active
167 (GTK_TOGGLE_BUTTON (data->show_cleared_splits_button)))
168 show_cleared_splits (toclear_list);
170 g_list_free (toclear_list);
173 gtk_widget_destroy (data->window);
179gnc_autoclear_window_cancel_cb (GtkWidget *widget,
180 AutoClearWindow *data)
183 gtk_widget_destroy(data->window);
187static void clear_status_label_cb (GtkEditable *editable, AutoClearWindow *data)
189 gtk_label_set_text (data->status_label,
"");
202autoClearWindow (GtkWidget *parent,
Account *account)
207 AutoClearWindow *data;
211 gnc_commodity *currency;
213 data = g_new0 (AutoClearWindow, 1);
214 data->account = account;
217 builder = gtk_builder_new();
218 gnc_builder_add_from_file (builder,
"window-autoclear.glade",
"auto_clear_start_dialog");
219 data->window = GTK_WIDGET(gtk_builder_get_object (builder,
"auto_clear_start_dialog"));
220 title = gnc_autoclear_make_window_name (account);
221 gtk_window_set_title(GTK_WINDOW(data->window), title);
225 gtk_widget_set_name (GTK_WIDGET(data->window),
"gnc-id-auto-clear");
227 data->show_cleared_splits_button =
228 GTK_WIDGET (gtk_builder_get_object (builder,
"show_cleared_splits_button"));
231 data->end_value = GNC_AMOUNT_EDIT(gnc_amount_edit_new());
234 print_info = gnc_commodity_print_info (currency, FALSE);
235 gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT(data->end_value), print_info);
236 gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT(data->end_value),
239 g_signal_connect(GTK_WIDGET(data->end_value),
"activate",
240 G_CALLBACK(gnc_autoclear_window_ok_cb), data);
242 box = GTK_BOX(gtk_builder_get_object (builder,
"end_value_box"));
243 gtk_box_pack_start(box, GTK_WIDGET(data->end_value), TRUE, TRUE, 0);
245 label = GTK_WIDGET(gtk_builder_get_object (builder,
"end_label"));
246 gnc_amount_edit_make_mnemonic_target (GNC_AMOUNT_EDIT(data->end_value), label);
250 if (gnc_reverse_balance(data->account))
252 gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (data->end_value), after);
253 gtk_widget_grab_focus(GTK_WIDGET(data->end_value));
254 gnc_amount_edit_select_region (GNC_AMOUNT_EDIT (data->end_value), 0, -1);
256 data->status_label = GTK_LABEL(gtk_builder_get_object (builder,
"status_label"));
258 g_signal_connect (GTK_WIDGET(data->end_value),
"changed",
259 G_CALLBACK(clear_status_label_cb), data);
262 gtk_window_set_transient_for (GTK_WINDOW (data->window), GTK_WINDOW (parent));
264 gtk_builder_connect_signals(builder, data);
265 g_object_unref(G_OBJECT(builder));
Additional event handling code.
Gnome specific utility functions.
Functions for adding content to a window.
Functions providing a register page for the GnuCash UI.
void xaccAccountCommitEdit(Account *acc)
ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account u...
void xaccAccountBeginEdit(Account *acc)
The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account up...
gchar * gnc_account_get_full_name(const Account *account)
The gnc_account_get_full_name routine returns the fully qualified name of the account using the given...
int xaccAccountGetCommoditySCU(const Account *acc)
Return the SCU for the account.
gnc_numeric xaccAccountGetClearedBalance(const Account *acc)
Get the current balance of the account, only including cleared transactions.
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity
int gnc_commodity_get_fraction(const gnc_commodity *cm)
Retrieve the fraction for the specified commodity.
const GncGUID * guid_null(void)
Returns a GncGUID which is guaranteed to never reference any entity.
void main_window_update_page_name(GncPluginPage *page, const gchar *name_in)
Update the name of the page in the main window.
void gnc_main_window_open_page(GncMainWindow *window, GncPluginPage *page)
Display a data plugin page in a window.
void gnc_ledger_display_refresh(GNCLedgerDisplay *ld)
redisplay/redraw only the indicated window.
GNCLedgerDisplay * gnc_ledger_display_query(Query *query, SplitRegisterType type, SplitRegisterStyle style)
display a general ledger for an arbitrary query
gnc_numeric gnc_numeric_error(GNCNumericErrorCode error_code)
Create a gnc_numeric object that signals the error condition noted by error_code, rather than a numbe...
gnc_numeric gnc_numeric_neg(gnc_numeric a)
Returns a newly created gnc_numeric that is the negative of the given gnc_numeric value.
@ GNC_ERROR_ARG
Argument is not a valid number.
QofQuery * qof_query_merge(QofQuery *q1, QofQuery *q2, QofQueryOp op)
Combine two queries together using the Boolean set (logical) operator 'op'.
void qof_query_set_book(QofQuery *query, QofBook *book)
Set the book to be searched.
void qof_query_destroy(QofQuery *query)
Frees the resources associate with a Query object.
GncPluginPage * gnc_plugin_page_register_new_ledger(GNCLedgerDisplay *ledger)
Create a new "register" plugin page, given a pointer to an already created ledger.
void xaccSplitSetReconcile(Split *split, char recn)
Set the reconcile flag.
#define xaccSplitGetGUID(X)
#define CREC
The Split has been cleared
The type used to store guids in C.
The instance data structure for a content plugin.