GnuCash c935c2f+
Loading...
Searching...
No Matches
Files | Data Structures | Macros | Enumerations | Enumerator | Functions | Variables
Budgets

gnc-budget_view.c – Budget display widget More...

Files

file  gnc-budget.h
 GnuCash Budgets.
 
file  gnc-tree-model-budget.h
 provides some utilities for working with the list of budgets in a book.
 
file  gnc-budget-view.c
 File to define budget views for gnucash (the actual display of the budget, along with some calculations and event handlers).
 
file  gnc-budget-view.h
 
file  gnc-plugin-page-budget.h
 

Data Structures

struct  GncBudgetView
 
struct  GncBudgetViewClass
 
struct  GncBudgetViewPrivate
 the private budget view structure More...
 
struct  BudgetAccumulationInfo
 Action for when a selection in a gnc budget view is changed. More...
 
struct  GncPluginPageBudget
 
struct  GncPluginPageBudgetClass
 

Macros

#define GNC_TYPE_BUDGET   (gnc_budget_get_type ())
 
#define GNC_BUDGET(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_BUDGET, GncBudget))
 
#define GNC_BUDGET_CLASS(k)    (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_BUDGET, GncBudgetClass))
 
#define GNC_IS_BUDGET(o)    (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_BUDGET))
 
#define GNC_IS_BUDGET_CLASS(k)    (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_BUDGET))
 
#define GNC_BUDGET_GET_CLASS(o)    (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_BUDGET, GncBudgetClass))
 
#define GNC_BUDGET_MAX_NUM_PERIODS_DIGITS   3
 
#define GNC_BUDGET_NOTES_PATH   "notes"
 
#define gnc_budget_return_guid(X)    (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null()))
 
#define gnc_budget_lookup_direct(g, b)   gnc_budget_lookup(&(g),(b))
 
#define PLUGIN_PAGE_BUDGET_CM_CLASS   "budget-view"
 
#define STATE_SECTION_PREFIX   "Budget"
 
#define GNC_BUDGET_VIEW_GET_PRIVATE(o)    ((GncBudgetViewPrivate*)gnc_budget_view_get_instance_private((GncBudgetView*)o))
 
#define BUDGET_GUID   "Budget GncGUID"
 
#define GNC_TYPE_BUDGET_VIEW   (gnc_budget_view_get_type ())
 
#define GNC_BUDGET_VIEW(obj)   (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_BUDGET_VIEW, GncBudgetView))
 
#define GNC_BUDGET_VIEW_CLASS(klass)   (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_BUDGET_VIEW, GncBudgetViewClass))
 
#define GNC_IS_BUDGET_VIEW(obj)   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_BUDGET_VIEW))
 
#define GNC_IS_BUDGET_VIEW_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_BUDGET_VIEW))
 
#define GNC_BUDGET_VIEW_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_TYPE_BUDGET_VIEW, GncBudgetViewClass))
 
#define GNC_BUDGET_VIEW_NAME   "GncBudgetView"
 
#define GNC_TYPE_PLUGIN_PAGE_BUDGET   (gnc_plugin_page_budget_get_type ())
 
#define GNC_PLUGIN_PAGE_BUDGET(obj)   (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_PLUGIN_PAGE_BUDGET, GncPluginPageBudget))
 
#define GNC_PLUGIN_PAGE_BUDGET_CLASS(klass)   (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_PLUGIN_PAGE_BUDGET, GncPluginPageBudgetClass))
 
#define GNC_IS_PLUGIN_PAGE_BUDGET(obj)   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_PLUGIN_PAGE_BUDGET))
 
#define GNC_IS_PLUGIN_PAGE_BUDGET_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_PLUGIN_PAGE_BUDGET))
 
#define GNC_PLUGIN_PAGE_BUDGET_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_TYPE_PLUGIN_PAGE_BUDGET, GncPluginPageBudgetClass))
 
#define GNC_PLUGIN_PAGE_BUDGET_NAME   "GncPluginPageBudget"
 

Enumerations

enum  { BUDGET_GUID_COLUMN , BUDGET_NAME_COLUMN , BUDGET_DESCRIPTION_COLUMN , BUDGET_LIST_NUM_COLS }
 
enum  { TOTALS_TYPE_INCOME , TOTALS_TYPE_EXPENSES , TOTALS_TYPE_ASSET_LIAB_EQ , TOTALS_TYPE_REMAINDER }
 

Functions

GType gnc_budget_get_type (void)
 
gboolean gnc_budget_register (void)
 
GncBudget * gnc_budget_new (QofBook *book)
 Creates and initializes a Budget.
 
void gnc_budget_destroy (GncBudget *budget)
 Deletes the given budget object.
 
void gnc_budget_begin_edit (GncBudget *bgt)
 
void gnc_budget_commit_edit (GncBudget *bgt)
 
GncBudget * gnc_budget_clone (const GncBudget *budget)
 Clones a budget creating a copy.
 
const GncGUIDgnc_budget_get_guid (const GncBudget *budget)
 
void gnc_budget_set_name (GncBudget *budget, const gchar *name)
 Set/Get the name of the Budget.
 
const gchar * gnc_budget_get_name (const GncBudget *budget)
 
void gnc_budget_set_description (GncBudget *budget, const gchar *description)
 Set/Get the description of the Budget.
 
const gchar * gnc_budget_get_description (const GncBudget *budget)
 
void gnc_budget_set_num_periods (GncBudget *budget, guint num_periods)
 Set/Get the number of periods in the Budget.
 
guint gnc_budget_get_num_periods (const GncBudget *budget)
 
void gnc_budget_set_recurrence (GncBudget *budget, const Recurrence *r)
 
const Recurrencegnc_budget_get_recurrence (const GncBudget *budget)
 
time64 gnc_budget_get_period_start_date (const GncBudget *budget, guint period_num)
 Get the starting date of the Budget period.
 
time64 gnc_budget_get_period_end_date (const GncBudget *budget, guint period_num)
 Get the ending date of the Budget period.
 
void gnc_budget_set_account_period_value (GncBudget *budget, const Account *account, guint period_num, gnc_numeric val)
 
void gnc_budget_unset_account_period_value (GncBudget *budget, const Account *account, guint period_num)
 
gboolean gnc_budget_is_account_period_value_set (const GncBudget *budget, const Account *account, guint period_num)
 
gnc_numeric gnc_budget_get_account_period_value (const GncBudget *budget, const Account *account, guint period_num)
 
gnc_numeric gnc_budget_get_account_period_actual_value (const GncBudget *budget, Account *account, guint period_num)
 
void gnc_budget_set_account_period_note (GncBudget *budget, const Account *account, guint period_num, const gchar *note)
 
const gchar * gnc_budget_get_account_period_note (const GncBudget *budget, const Account *account, guint period_num)
 
GncBudget * gnc_budget_get_default (QofBook *book)
 
GncBudget * gnc_budget_lookup (const GncGUID *guid, const QofBook *book)
 
GtkTreeModel * gnc_tree_model_budget_new (QofBook *book)
 
void gnc_tree_view_budget_set_model (GtkTreeView *tv, GtkTreeModel *tm)
 
GncBudget * gnc_tree_model_budget_get_budget (GtkTreeModel *tm, GtkTreeIter *iter)
 
gboolean gnc_tree_model_budget_get_iter_for_budget (GtkTreeModel *tm, GtkTreeIter *iter, GncBudget *bgt)
 
GncBudgetView * gnc_budget_view_new (GncBudget *budget, AccountFilterDialog *fd)
 Create new gnc budget view.
 
void gnc_budget_view_set_show_account_code (GncBudgetView *budget_view, gboolean show_account_code)
 
gboolean gnc_budget_view_get_show_account_code (GncBudgetView *budget_view)
 
void gnc_budget_view_set_show_account_description (GncBudgetView *budget_view, gboolean show_account_desc)
 
gboolean gnc_budget_view_get_show_account_description (GncBudgetView *budget_view)
 
GtkTreeSelection * gnc_budget_view_get_selection (GncBudgetView *budget_view)
 returns the current selection in the gnc budget view.
 
Accountgnc_budget_view_get_account_from_path (GncBudgetView *budget_view, GtkTreePath *path)
 
GtkWidget * gnc_budget_view_get_account_tree_view (GncBudgetView *budget_view)
 
GList * gnc_budget_view_get_selected_accounts (GncBudgetView *budget_view)
 
void gnc_budget_view_save (GncBudgetView *budget_view, GKeyFile *key_file, const gchar *group_name)
 
gboolean gnc_budget_view_restore (GncBudgetView *budget_view, GKeyFile *key_file, const gchar *group_name)
 
void gnc_budget_view_delete_budget (GncBudgetView *budget_view)
 
void gnc_budget_view_save_account_filter (GncBudgetView *budget_view)
 
void gnc_budget_view_refresh (GncBudgetView *budget_view)
 refreshes the current budget view
 
GType gnc_budget_view_get_type (void)
 
GType gnc_plugin_page_budget_get_type (void)
 
GncPluginPagegnc_plugin_page_budget_new (GncBudget *budget)
 Create a new "budget" plugin page.
 
void gnc_budget_gui_delete_budget (GncBudget *budget)
 

Variables

GtkBox GncBudgetView::w
 
GtkBoxClass GncBudgetViewClass::w
 
GtkTreeView * GncBudgetViewPrivate::tree_view
 
GtkTreeView * GncBudgetViewPrivate::totals_tree_view
 
GtkWidget * GncBudgetViewPrivate::totals_scroll_window
 
GtkAdjustment * GncBudgetViewPrivate::hadj
 
GncBudget * GncBudgetViewPrivate::budget
 
GncGUID GncBudgetViewPrivate::key
 
gboolean GncBudgetViewPrivate::use_red_color
 
GList * GncBudgetViewPrivate::period_col_list
 
GList * GncBudgetViewPrivate::totals_col_list
 
GtkTreeViewColumn * GncBudgetViewPrivate::total_col
 
AccountFilterDialogGncBudgetViewPrivate::fd
 
AccountGncBudgetViewPrivate::rootAcct
 
gboolean GncBudgetViewPrivate::show_account_code
 
gboolean GncBudgetViewPrivate::show_account_desc
 
GtkCellRenderer * GncBudgetViewPrivate::temp_cr
 
GtkCellEditable * GncBudgetViewPrivate::temp_ce
 
gnc_numeric BudgetAccumulationInfo::total
 
GncBudget * BudgetAccumulationInfo::budget
 
guint BudgetAccumulationInfo::period_num
 
GNCPriceDB * BudgetAccumulationInfo::pdb
 
gnc_commodity * BudgetAccumulationInfo::total_currency
 

Detailed Description

gnc-budget_view.c – Budget display widget

Macro Definition Documentation

◆ BUDGET_GUID

#define BUDGET_GUID   "Budget GncGUID"

Definition at line 586 of file gnc-budget-view.c.

◆ GNC_BUDGET

#define GNC_BUDGET (   o)     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_BUDGET, GncBudget))

Definition at line 84 of file gnc-budget.h.

120 : *(guid_null()))
121
123void gnc_budget_set_name(GncBudget* budget, const gchar* name);
124/*@ dependent @*/
125const gchar* gnc_budget_get_name(const GncBudget* budget);
126
128void gnc_budget_set_description(GncBudget* budget, const gchar* description);
129/*@ dependent @*/
130const gchar* gnc_budget_get_description(const GncBudget* budget);
131
133void gnc_budget_set_num_periods(GncBudget* budget, guint num_periods);
134guint gnc_budget_get_num_periods(const GncBudget* budget);
135
136void gnc_budget_set_recurrence(GncBudget *budget, const Recurrence *r);
137/*@ dependent @*/
138const Recurrence * gnc_budget_get_recurrence(const GncBudget *budget);
139
141time64 gnc_budget_get_period_start_date(const GncBudget* budget, guint period_num);
142
144time64 gnc_budget_get_period_end_date(const GncBudget* budget, guint period_num);
145
146/* Period indices are zero-based. */
147void gnc_budget_set_account_period_value(
148 GncBudget* budget, const Account* account, guint period_num, gnc_numeric val);
149void gnc_budget_unset_account_period_value(
150 GncBudget* budget, const Account* account, guint period_num);
151
152gboolean gnc_budget_is_account_period_value_set(
153 const GncBudget *budget, const Account *account, guint period_num);
154
155/* get the budget account period's budgeted value */
156gnc_numeric gnc_budget_get_account_period_value(
157 const GncBudget *budget, const Account *account, guint period_num);
158
159/* get the budget account period's actual value, including children,
160 excluding closing entries */
161gnc_numeric gnc_budget_get_account_period_actual_value(
162 const GncBudget *budget, Account *account, guint period_num);
163
164/* get/set the budget account period's note */
165void gnc_budget_set_account_period_note(GncBudget *budget,
166 const Account *account, guint period_num, const gchar *note);
167const gchar *gnc_budget_get_account_period_note (const GncBudget *budget,
168 const Account *account, guint period_num);
169
170/* Returns some budget in the book, or NULL. */
171GncBudget* gnc_budget_get_default(QofBook *book);
172
173/* Get the budget associated with the given GncGUID from the given book. */
174/*@ dependent @*/
175GncBudget* gnc_budget_lookup (const GncGUID *guid, const QofBook *book);
176#define gnc_budget_lookup_direct(g,b) gnc_budget_lookup(&(g),(b))
177
178#ifdef __cplusplus
179}
180#endif
181
182
183#endif // __BUDGET_H__
184
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Definition gnc-date.h:87
const GncGUID * guid_null(void)
Returns a GncGUID which is guaranteed to never reference any entity.
Definition guid.cpp:165
void gnc_budget_set_num_periods(GncBudget *budget, guint num_periods)
Set/Get the number of periods in the Budget.
void gnc_budget_set_description(GncBudget *budget, const gchar *description)
Set/Get the description of the Budget.
time64 gnc_budget_get_period_start_date(const GncBudget *budget, guint period_num)
Get the starting date of the Budget period.
void gnc_budget_set_name(GncBudget *budget, const gchar *name)
Set/Get the name of the Budget.
time64 gnc_budget_get_period_end_date(const GncBudget *budget, guint period_num)
Get the ending date of the Budget period.
STRUCTS.
The type used to store guids in C.
Definition guid.h:75
QofBook reference.
Definition qofbook-p.hpp:47

◆ GNC_BUDGET_CLASS

#define GNC_BUDGET_CLASS (   k)     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_BUDGET, GncBudgetClass))

Definition at line 86 of file gnc-budget.h.

◆ GNC_BUDGET_GET_CLASS

#define GNC_BUDGET_GET_CLASS (   o)     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_BUDGET, GncBudgetClass))

Definition at line 92 of file gnc-budget.h.

◆ gnc_budget_lookup_direct

#define gnc_budget_lookup_direct (   g,
 
)    gnc_budget_lookup(&(g),(b))

Definition at line 176 of file gnc-budget.h.

◆ GNC_BUDGET_MAX_NUM_PERIODS_DIGITS

#define GNC_BUDGET_MAX_NUM_PERIODS_DIGITS   3

Definition at line 96 of file gnc-budget.h.

◆ GNC_BUDGET_NOTES_PATH

#define GNC_BUDGET_NOTES_PATH   "notes"

Definition at line 98 of file gnc-budget.h.

◆ gnc_budget_return_guid

#define gnc_budget_return_guid (   X)     (X ? *(qof_entity_get_guid(QOF_INSTANCE(X))) : *(guid_null()))

Definition at line 119 of file gnc-budget.h.

120 : *(guid_null()))

◆ GNC_BUDGET_VIEW

#define GNC_BUDGET_VIEW (   obj)    (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_BUDGET_VIEW, GncBudgetView))

Definition at line 44 of file gnc-budget-view.h.

◆ GNC_BUDGET_VIEW_CLASS

#define GNC_BUDGET_VIEW_CLASS (   klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_BUDGET_VIEW, GncBudgetViewClass))

Definition at line 45 of file gnc-budget-view.h.

◆ GNC_BUDGET_VIEW_GET_CLASS

#define GNC_BUDGET_VIEW_GET_CLASS (   obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_TYPE_BUDGET_VIEW, GncBudgetViewClass))

Definition at line 48 of file gnc-budget-view.h.

◆ GNC_BUDGET_VIEW_GET_PRIVATE

#define GNC_BUDGET_VIEW_GET_PRIVATE (   o)     ((GncBudgetViewPrivate*)gnc_budget_view_get_instance_private((GncBudgetView*)o))

Definition at line 180 of file gnc-budget-view.c.

188{
189 GncBudgetView *budget_view;
191
192 g_return_val_if_fail (GNC_IS_BUDGET(budget), NULL);
193 ENTER(" ");
194
195 budget_view = g_object_new (GNC_TYPE_BUDGET_VIEW, NULL);
196
197 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
198 priv->budget = budget;
199 priv->key = *gnc_budget_get_guid (budget);
200 priv->fd = fd;
201 priv->total_col = NULL;
202 priv->show_account_code = FALSE;
203 priv->show_account_desc = FALSE;
204 gbv_create_widget (budget_view);
205
206 LEAVE("new budget view %p", budget_view);
207 return budget_view;
208}
209
210static void
211gnc_budget_view_class_init (GncBudgetViewClass *klass)
212{
213 GObjectClass *object_class = G_OBJECT_CLASS(klass);
214
215 object_class->finalize = gnc_budget_view_finalize;
216
217 g_signal_new ("account-activated", GNC_TYPE_BUDGET_VIEW, G_SIGNAL_RUN_LAST,
218 0, NULL, NULL, NULL, G_TYPE_NONE, 1, GNC_TYPE_ACCOUNT);
219}
220
221static void
222gnc_budget_view_init (GncBudgetView *budget_view)
223{
225
226 ENTER("view %p", budget_view);
227
228 gtk_orientable_set_orientation (GTK_ORIENTABLE(budget_view), GTK_ORIENTATION_VERTICAL);
229
230 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
231
232 /* Keep track of the root account */
233 priv->rootAcct = gnc_book_get_root_account (gnc_get_current_book());
234
235 LEAVE("");
236}
237
238static void
239gbv_treeview_update_grid_lines (gpointer prefs, gchar *pref, gpointer user_data)
240{
241 GtkTreeView *view = user_data;
242 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW(view), gnc_tree_view_get_grid_lines_pref ());
243}
244
245void
246gnc_budget_view_set_show_account_code (GncBudgetView *budget_view, gboolean show_account_code)
247{
248 GncBudgetViewPrivate *priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
249 priv->show_account_code = show_account_code;
250 gnc_budget_view_refresh (budget_view);
251}
252
253gboolean
254gnc_budget_view_get_show_account_code (GncBudgetView *budget_view)
255{
256 GncBudgetViewPrivate *priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
257 return priv->show_account_code;
258}
259
260void
261gnc_budget_view_set_show_account_description (GncBudgetView *budget_view, gboolean show_account_desc)
262{
263 GncBudgetViewPrivate *priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
264 priv->show_account_desc = show_account_desc;
265 gnc_budget_view_refresh (budget_view);
266}
267
268gboolean
269gnc_budget_view_get_show_account_description (GncBudgetView *budget_view)
270{
271 GncBudgetViewPrivate *priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
272 return priv->show_account_desc;
273}
274
275static void
276gbv_update_use_red (gpointer prefs, gchar *pref, gpointer user_data)
277{
278 GncBudgetView *budget_view = user_data;
279 GncBudgetViewPrivate *priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
280
281 priv->use_red_color = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL,
282 GNC_PREF_NEGATIVE_IN_RED);
283}
284
285static void
286gnc_budget_view_finalize (GObject *object)
287{
288 GncBudgetView *budget_view;
290
291 ENTER("object %p", object);
292 budget_view = GNC_BUDGET_VIEW(object);
293 g_return_if_fail (GNC_IS_BUDGET_VIEW(budget_view));
294
295 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
296
297 g_list_free (priv->period_col_list);
298 g_list_free (priv->totals_col_list);
299
300 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL, GNC_PREF_GRID_LINES_HORIZONTAL,
301 gbv_treeview_update_grid_lines, priv->totals_tree_view);
302 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL, GNC_PREF_GRID_LINES_VERTICAL,
303 gbv_treeview_update_grid_lines, priv->totals_tree_view);
304 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED,
305 gbv_update_use_red, budget_view);
306
307 G_OBJECT_CLASS(gnc_budget_view_parent_class)->finalize (object);
308 LEAVE(" ");
309}
310
316GtkTreeSelection*
317gnc_budget_view_get_selection (GncBudgetView *budget_view)
318{
320
321 g_return_val_if_fail (GNC_IS_BUDGET_VIEW(budget_view), NULL);
322
323 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
324 return gtk_tree_view_get_selection (GTK_TREE_VIEW(priv->tree_view));
325}
326
327Account*
328gnc_budget_view_get_account_from_path (GncBudgetView *budget_view, GtkTreePath *path)
329{
331
332 g_return_val_if_fail (GNC_IS_BUDGET_VIEW(budget_view), NULL);
333
334 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
335 return gnc_tree_view_account_get_account_from_path (GNC_TREE_VIEW_ACCOUNT(priv->tree_view), path);
336}
337
338GtkWidget*
339gnc_budget_view_get_account_tree_view (GncBudgetView *budget_view)
340{
342
343 g_return_val_if_fail (GNC_IS_BUDGET_VIEW(budget_view), NULL);
344
345 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
346 return GTK_WIDGET(priv->fd->tree_view);
347}
348
349GList*
350gnc_budget_view_get_selected_accounts (GncBudgetView *budget_view)
351{
353
354 g_return_val_if_fail (GNC_IS_BUDGET_VIEW(budget_view), NULL);
355
356 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
357 return gnc_tree_view_account_get_selected_accounts (GNC_TREE_VIEW_ACCOUNT(priv->tree_view));
358}
359
360static void
361gbv_totals_scrollbar_value_changed_cb (GtkAdjustment *adj, GncBudgetView *budget_view)
362{
364
365 g_return_if_fail (GNC_IS_BUDGET_VIEW(budget_view));
366
367 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
368 gtk_adjustment_set_value (priv->hadj, gtk_adjustment_get_value (adj));
369}
370
371static gboolean
372gbv_totals_tree_view_redraw_idle (GtkTreeView *view)
373{
374 gtk_widget_queue_draw (GTK_WIDGET(view));
375 return FALSE;
376}
377
378static void
379gbv_tree_view_model_row_changed_cb (GtkTreeModel *tree_model, GtkTreePath *path,
380 GtkTreeIter *iter, gpointer user_data)
381{
382 GncBudgetView *budget_view = user_data;
383 GncBudgetViewPrivate *priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
384
385 // The model row-changed signal can be emitted multiple times so we
386 // use an idle_add to do a redraw of the totals tree view once
387 g_idle_remove_by_data (priv->totals_tree_view);
388 g_idle_add ((GSourceFunc)gbv_totals_tree_view_redraw_idle, priv->totals_tree_view);
389}
390
391/****************************
392 * GncPluginPage Functions *
393 ***************************/
401static void
402gbv_create_widget (GncBudgetView *budget_view)
403{
405 GtkTreeSelection *selection;
406 GtkTreeView *tree_view;
407 GtkWidget *scrolled_window;
408 GtkAdjustment *h_adj;
409 GtkWidget *h_scrollbar;
410 GtkBox *vbox;
411 GtkListStore *totals_tree_model;
412 GtkTreeView *totals_tree_view;
413 GtkTreeViewColumn *totals_title_col, *name_col, *code_col, *desc_col;
414 GtkTreeIter iter;
415 GtkWidget *h_separator;
416 gchar *state_section;
417 gchar guidstr[GUID_ENCODING_LENGTH+1];
418
419 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
420 vbox = GTK_BOX(budget_view);
421
422 // Set the name for this widget so it can be easily manipulated with css
423 gtk_widget_set_name (GTK_WIDGET(vbox), "gnc-id-budget-page");
424
425 // Accounts scroll window
426 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
427 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(scrolled_window),
428 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
429
430 // Create Accounts tree_view
431 tree_view = gnc_tree_view_account_new (FALSE);
432 gtk_tree_view_set_headers_visible (tree_view, TRUE);
433
434 guid_to_string_buff (&priv->key, guidstr);
435 state_section = g_strjoin (" ", STATE_SECTION_PREFIX, guidstr, NULL);
436 g_object_set (G_OBJECT(tree_view), "state-section", state_section, NULL);
437 g_free (state_section);
438
439 gnc_tree_view_configure_columns (GNC_TREE_VIEW(tree_view));
440 priv->tree_view = tree_view;
441 selection = gtk_tree_view_get_selection (tree_view);
442 gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
443
444 // make sure the account column is the expand column
445 gnc_tree_view_expand_columns (GNC_TREE_VIEW(tree_view), "name", NULL);
446 name_col = gnc_tree_view_find_column_by_name (GNC_TREE_VIEW(priv->tree_view), "name");
447 gtk_tree_view_column_set_reorderable (name_col, FALSE);
448
449 // Accounts filter
450 priv->fd->tree_view = GNC_TREE_VIEW_ACCOUNT(priv->tree_view);
451 gnc_tree_view_account_set_filter (GNC_TREE_VIEW_ACCOUNT(tree_view),
453 priv->fd, NULL);
454
455 // get the visibility of the account code column
456 code_col = gnc_tree_view_find_column_by_name (GNC_TREE_VIEW(priv->tree_view), "account-code");
457 priv->show_account_code = gtk_tree_view_column_get_visible (code_col);
458 gtk_tree_view_column_set_reorderable (code_col, FALSE);
459
460 // get the visibility of the account description column
461 desc_col = gnc_tree_view_find_column_by_name (GNC_TREE_VIEW(priv->tree_view), "description");
462 priv->show_account_desc = gtk_tree_view_column_get_visible (desc_col);
463 gtk_tree_view_column_set_reorderable (desc_col, FALSE);
464
465 // Add accounts tree view to scroll window
466 gtk_container_add (GTK_CONTAINER(scrolled_window), GTK_WIDGET(tree_view));
467
468 g_object_set (tree_view, "has-tooltip", TRUE, NULL);
469 g_signal_connect (G_OBJECT(tree_view), "query-tooltip",
470 G_CALLBACK(query_tooltip_tree_view_cb), budget_view);
471 g_signal_connect (G_OBJECT(tree_view), "row-activated",
472 G_CALLBACK(gbv_row_activated_cb), budget_view);
473
474 // save the main scrolled window horizontal adjustment
475 priv->hadj = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW(scrolled_window));
476
477 PINFO("Number of Created Account columns is %d", gtk_tree_view_get_n_columns (tree_view));
478
479#if 0
480 g_signal_connect (G_OBJECT(selection), "changed",
481 G_CALLBACK(gbv_selection_changed_cb), budget_view);
482 g_signal_connect (G_OBJECT(tree_view), "button-press-event",
483 G_CALLBACK(gbv_button_press_cb), budget_view);
484 gbv_selection_changed_cb (NULL, budget_view);
485#endif
486
487 // Totals scroll window
488 priv->totals_scroll_window = gtk_scrolled_window_new (NULL, NULL);
489 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(priv->totals_scroll_window),
490 GTK_POLICY_AUTOMATIC, GTK_POLICY_NEVER); // horizontal/vertical
491
492 h_adj = gtk_scrolled_window_get_hadjustment (GTK_SCROLLED_WINDOW(priv->totals_scroll_window));
493 g_signal_connect (G_OBJECT(h_adj), "value-changed",
494 G_CALLBACK(gbv_totals_scrollbar_value_changed_cb), budget_view);
495
496 // Create totals tree view
497 totals_tree_model = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING);
498 gtk_list_store_append (totals_tree_model, &iter);
499 gtk_list_store_set (totals_tree_model, &iter, 0, _("Income"),
500 1, TOTALS_TYPE_INCOME, 2, " ", 3, " ", -1);
501 gtk_list_store_append (totals_tree_model, &iter);
502 gtk_list_store_set (totals_tree_model, &iter, 0, _("Expenses"),
503 1, TOTALS_TYPE_EXPENSES, 2, " ", 3, " ", -1);
504 gtk_list_store_append (totals_tree_model, &iter);
505 gtk_list_store_set (totals_tree_model, &iter, 0, _("Transfer"),
506 1, TOTALS_TYPE_ASSET_LIAB_EQ, 2, " ", 3, " ", -1);
507 gtk_list_store_append (totals_tree_model, &iter);
508 gtk_list_store_set (totals_tree_model, &iter, 0, _("Remaining to Budget"),
509 1, TOTALS_TYPE_REMAINDER, 2, " ", 3, " ", -1);
510
511 totals_tree_view = GTK_TREE_VIEW(gtk_tree_view_new ());
512 priv->totals_tree_view = totals_tree_view;
513 gtk_tree_selection_set_mode (gtk_tree_view_get_selection (totals_tree_view), GTK_SELECTION_NONE);
514 gtk_tree_view_set_headers_visible (totals_tree_view, FALSE);
515 gtk_tree_view_set_model (totals_tree_view, GTK_TREE_MODEL(totals_tree_model));
516 g_object_unref (totals_tree_model);
517
518 // add the totals title column
519 totals_title_col = gtk_tree_view_column_new_with_attributes ("", gtk_cell_renderer_text_new (), "text", 0, NULL);
520 gtk_tree_view_column_set_expand (totals_title_col, TRUE);
521 gtk_tree_view_column_set_sizing (totals_title_col, GTK_TREE_VIEW_COLUMN_FIXED);
522 gtk_tree_view_append_column (totals_tree_view, totals_title_col);
523
524 // add the totals account code column
525 code_col = gtk_tree_view_column_new_with_attributes ("", gtk_cell_renderer_text_new(), "text", 2, NULL);
526 gtk_tree_view_column_set_sizing (code_col, GTK_TREE_VIEW_COLUMN_FIXED);
527 gtk_tree_view_append_column (totals_tree_view, code_col);
528 gtk_tree_view_column_set_visible (code_col, priv->show_account_code);
529
530 // add the totals account description column
531 desc_col = gtk_tree_view_column_new_with_attributes ("", gtk_cell_renderer_text_new(), "text", 3, NULL);
532 gtk_tree_view_column_set_sizing (desc_col, GTK_TREE_VIEW_COLUMN_FIXED);
533 gtk_tree_view_append_column (totals_tree_view, desc_col);
534 gtk_tree_view_column_set_visible (desc_col, priv->show_account_desc);
535
536 // Add totals tree view to scroll window
537 gtk_container_add (GTK_CONTAINER(priv->totals_scroll_window), GTK_WIDGET(totals_tree_view));
538
539 // Set grid lines option to preference
540 gtk_tree_view_set_grid_lines (GTK_TREE_VIEW(totals_tree_view), gnc_tree_view_get_grid_lines_pref ());
541 gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL, GNC_PREF_GRID_LINES_HORIZONTAL,
542 gbv_treeview_update_grid_lines, totals_tree_view);
543 gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL, GNC_PREF_GRID_LINES_VERTICAL,
544 gbv_treeview_update_grid_lines, totals_tree_view);
545
546 // get initial value and register prefs call back for use red color
547 priv->use_red_color = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED);
548 gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED,
549 gbv_update_use_red, budget_view);
550
551 PINFO("Number of Created totals columns is %d", gtk_tree_view_get_n_columns (totals_tree_view));
552
553 gtk_box_set_homogeneous (GTK_BOX(vbox), FALSE);
554
555 gtk_box_pack_start (GTK_BOX(vbox), scrolled_window, /*expand*/TRUE, /*fill*/TRUE, 0);
556
557 h_separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
558 gtk_box_pack_end (GTK_BOX(vbox), h_separator, /*expand*/FALSE, /*fill*/TRUE, 0);
559
560 gtk_box_pack_start (GTK_BOX(vbox), GTK_WIDGET(priv->totals_scroll_window), /*expand*/FALSE, /*fill*/TRUE, 0);
561
562 gtk_widget_show_all (GTK_WIDGET(vbox));
563
564 // hide the account scroll window horizontal scroll bar
565 h_scrollbar = gtk_scrolled_window_get_hscrollbar (GTK_SCROLLED_WINDOW(scrolled_window));
566 gtk_widget_hide (h_scrollbar);
567
568 g_signal_connect (G_OBJECT(tree_view), "size-allocate",
569 G_CALLBACK(gbv_treeview_resized_cb), budget_view);
570
571 // Read account filter state information from budget section
572 gnc_tree_view_account_restore_filter (GNC_TREE_VIEW_ACCOUNT(priv->tree_view),
573 priv->fd,
576 GNC_TREE_VIEW(priv->tree_view)));
577
578 // use the model row-changed signal to do a redraw on the totals tree view
579 g_signal_connect (G_OBJECT(gtk_tree_view_get_model (GTK_TREE_VIEW(tree_view))), "row-changed",
580 G_CALLBACK(gbv_tree_view_model_row_changed_cb), budget_view);
581
582 gnc_budget_view_refresh (budget_view);
583}
584
585#define BUDGET_GUID "Budget GncGUID"
586
587/***********************************************************************
588 * Save enough information about this view that it can *
589 * be recreated next time the user starts gnucash. *
590 * *
591 * @param budget_view The view to save. *
592 * *
593 * @param key_file A pointer to the GKeyFile data structure where the *
594 * page information should be written. *
595 * *
596 * @param group_name The group name to use when saving data. *
597 **********************************************************************/
598void
599gnc_budget_view_save (GncBudgetView *budget_view, GKeyFile *key_file, const gchar *group_name)
600{
602
603 g_return_if_fail (budget_view != NULL);
604 g_return_if_fail (key_file != NULL);
605 g_return_if_fail (group_name != NULL);
606
607 ENTER("view %p, key_file %p, group_name %s", budget_view, key_file, group_name);
608
609 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
610
611 // Save the account filter and page state information to page section
612 gnc_tree_view_account_save (GNC_TREE_VIEW_ACCOUNT(priv->tree_view),
613 priv->fd, key_file, group_name);
614 LEAVE(" ");
615}
616
617
618/***********************************************************************
619 * Create a new plugin page based on the information saved
620 * during a previous instantiation of gnucash.
621 *
622 * @param budget_view The budget view to be restored
623 *
624 * @param key_file A pointer to the GKeyFile data structure where the
625 * page information should be read.
626 *
627 * @param group_name The group name to use when restoring data.
628 *
629 * @return TRUE if successful, FALSE if unsuccessful
630 **********************************************************************/
631gboolean
632gnc_budget_view_restore (GncBudgetView *budget_view, GKeyFile *key_file, const gchar *group_name)
633{
635 GError *error = NULL;
636 char *guid_str;
637 GncGUID guid;
638 GncBudget *bgt;
639 QofBook *book;
640 gboolean has_guid;
641
642 g_return_val_if_fail (key_file, FALSE);
643 g_return_val_if_fail (group_name, FALSE);
644
645 ENTER("key_file %p, group_name %s", key_file, group_name);
646
647 guid_str = g_key_file_get_string (key_file, group_name, BUDGET_GUID,
648 &error);
649 if (error)
650 {
651 g_warning ("error reading group %s key %s: %s",
652 group_name, BUDGET_GUID, error->message);
653 g_error_free (error);
654 error = NULL;
655 return FALSE;
656 }
657 has_guid = string_to_guid (guid_str, &guid);
658 g_free (guid_str);
659
660 if (!has_guid)
661 {
662 return FALSE;
663 }
664
665 book = qof_session_get_book (gnc_get_current_session());
666 bgt = gnc_budget_lookup (&guid, book);
667 if (!bgt)
668 {
669 return FALSE;
670 }
671
672 /* Create the new view */
673 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
674
675 // Restore the account filter and page state information from page section
676 gnc_tree_view_account_restore (GNC_TREE_VIEW_ACCOUNT(priv->tree_view),
677 priv->fd, key_file, group_name);
678 LEAVE(" ");
679
680 return TRUE;
681}
682
683/***********************************************************************
684 * The budget associated with this view is about to be removed from *
685 * the book. So drop any saved state we still have. *
686 * *
687 * @param budget_view The view to which the budget is associated. *
688 **********************************************************************/
689void
690gnc_budget_view_delete_budget (GncBudgetView *budget_view)
691{
693 gchar guidstr[GUID_ENCODING_LENGTH+1];
694
695 g_return_if_fail (budget_view != NULL);
696
697 ENTER("view %p", budget_view);
698
699 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
700
701 guid_to_string_buff (&priv->key, guidstr);
703 g_object_set (G_OBJECT(priv->tree_view), "state-section", NULL, NULL);
704
705 LEAVE(" ");
706}
707
708/***********************************************************************
709 * Save the Account filter information for this budget *
710 * *
711 * @param budget_view The view to which the budget is associated. *
712 **********************************************************************/
713void
714gnc_budget_view_save_account_filter (GncBudgetView *budget_view)
715{
717
718 g_return_if_fail (budget_view != NULL);
719
720 ENTER("view %p", budget_view);
721
722 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
723
724 // Save account filter state information to budget section
725 gnc_tree_view_account_save_filter (GNC_TREE_VIEW_ACCOUNT(priv->tree_view),
726 priv->fd, gnc_state_get_current (),
728 GNC_TREE_VIEW(priv->tree_view)));
729 LEAVE(" ");
730}
731
732#if 0
733/***********************************************************************
734 * This button press handler calls the common button press handler
735 * for all pages. The GtkTreeView eats all button presses and
736 * doesn't pass them up the widget tree, even when it doesn't do
737 * anything with them. The only way to get access to the button
738 * presses in an account tree page is here on the tree view widget.
739 * Button presses on all other pages are caught by the signal
740 * registered in gnc-main-window.c.
741 **********************************************************************/
742static gboolean
743gbv_button_press_cb (GtkWidget *widget, GdkEventButton *event,
744 GncBudgetView *budget_view)
745{
746 gboolean result;
747
748 g_return_val_if_fail (budget_view != NULL, FALSE);
749
750 ENTER("widget %p, event %p, page %p", widget, event, page);
751 result = gnc_main_window_button_press_cb (widget, event, page);
752 LEAVE(" ");
753 return result;
754}
755#endif
756
761static gboolean
762gbv_key_press_cb (GtkWidget *widget, GdkEventKey *event, gpointer user_data)
763{
764 GtkTreeViewColumn *col;
765 GtkTreePath *path = NULL;
766 GncBudgetViewPrivate *priv = GNC_BUDGET_VIEW_GET_PRIVATE(user_data);
767 GtkTreeView *tv = priv->tree_view;
768 gboolean shifted;
769 gint period_num, num_periods;
770 gpointer data;
771
772 if (event->type != GDK_KEY_PRESS || !priv->temp_cr)
773 return FALSE;
774
775 switch (event->keyval)
776 {
777 case GDK_KEY_KP_Decimal:
778 if (event->keyval == GDK_KEY_KP_Decimal)
779 {
780 struct lconv *lc = gnc_localeconv ();
781 event->keyval = lc->mon_decimal_point[0];
782 event->string[0] = lc->mon_decimal_point[0];
783 }
784 return FALSE;
785 case GDK_KEY_Tab:
786 case GDK_KEY_ISO_Left_Tab:
787 case GDK_KEY_KP_Tab:
788 shifted = event->state & GDK_SHIFT_MASK;
789 gtk_tree_view_get_cursor (tv, &path, &col);
790 if (!path)
791 return TRUE;
792 data = g_object_get_data (G_OBJECT(col), "period_num");
793 period_num = GPOINTER_TO_UINT(data);
794 num_periods = gnc_budget_get_num_periods (priv->budget);
795
796 if (period_num >= num_periods)
797 period_num = num_periods - 1;
798
799 if (shifted)
800 period_num--;
801 else
802 period_num++;
803
804 if (period_num >= num_periods)
805 {
806 period_num = 0;
807 if (gtk_tree_view_row_expanded (tv, path))
808 {
809 gtk_tree_path_down (path);
810 }
811 else
812 {
813 gtk_tree_path_next (path);
814 while (!gnc_tree_view_path_is_valid (GNC_TREE_VIEW(tv), path) &&
815 gtk_tree_path_get_depth (path) > 1)
816 {
817 gtk_tree_path_up (path);
818 gtk_tree_path_next (path);
819 }
820 }
821 }
822 else if (period_num < 0)
823 {
824 period_num = num_periods - 1;
825 if (!gtk_tree_path_prev (path))
826 gtk_tree_path_up (path);
827 else
828 {
829 while (gtk_tree_view_row_expanded (tv, path))
830 {
831 gtk_tree_path_down (path);
832 do
833 {
834 gtk_tree_path_next (path);
835 } while (
836 gnc_tree_view_path_is_valid (GNC_TREE_VIEW(tv), path));
837 gtk_tree_path_prev (path);
838 }
839 }
840 }
841
842 col = g_list_nth_data (priv->period_col_list, period_num);
843
844 // finish editing
845 if (priv->temp_ce)
846 {
847 gtk_cell_editable_editing_done (priv->temp_ce);
848 gtk_cell_editable_remove_widget (priv->temp_ce);
849
850 while (gtk_events_pending())
851 gtk_main_iteration ();
852 }
853
854 if (gnc_tree_view_path_is_valid (GNC_TREE_VIEW(tv), path))
855 gtk_tree_view_set_cursor (tv, path, col, TRUE);
856 gtk_tree_path_free (path);
857 break;
858 default:
859 return FALSE;
860 }
861
862 return TRUE;
863}
864
867static void
868gbv_treeview_resized_cb (GtkWidget *widget, GtkAllocation *allocation,
869 GncBudgetView *budget_view)
870{
871 GncBudgetViewPrivate* priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
872 GList *columns = gtk_tree_view_get_columns (GTK_TREE_VIEW(priv->tree_view));
873 GList *total_columns = gtk_tree_view_get_columns (GTK_TREE_VIEW (priv->totals_tree_view));
874
875 ENTER("");
876
877 for (GList *node = columns, *total_node = total_columns;
878 node; node = g_list_next (node))
879 {
880 GtkTreeViewColumn *tree_view_col = node->data;
881 const gchar *name = g_object_get_data (G_OBJECT(tree_view_col), PREF_NAME);
882
883 // if we do not show account code, step over the equivalent totals column
884 if ((g_strcmp0 (name, "account-code") == 0) && (!priv->show_account_code))
885 total_node = g_list_next (total_node);
886
887 // if we do not show account description, step over the
888 // equivalent totals column
889 if ((g_strcmp0 (name, "description") == 0) && (!priv->show_account_desc))
890 total_node = g_list_next (total_node);
891
892 if (gtk_tree_view_column_get_visible (tree_view_col) && total_node != NULL)
893 {
894 gint col_width = gtk_tree_view_column_get_width (tree_view_col);
895 GtkTreeViewColumn *totals_view_col = total_node->data;
896 if (GTK_IS_TREE_VIEW_COLUMN(totals_view_col))
897 gtk_tree_view_column_set_fixed_width (totals_view_col, col_width);
898 total_node = g_list_next (total_node);
899 }
900 }
901 // make sure the account column is the expand column
902 gnc_tree_view_expand_columns (GNC_TREE_VIEW(priv->tree_view), "name", NULL);
903 g_list_free (columns);
904 g_list_free (total_columns);
905 LEAVE("");
906}
907
910static void
911gbv_row_activated_cb (GtkTreeView *treeview, GtkTreePath *path,
912 GtkTreeViewColumn *col, GncBudgetView *budget_view)
913{
914 Account *account;
915
916 g_return_if_fail (GNC_IS_BUDGET_VIEW(budget_view));
917
919 GNC_TREE_VIEW_ACCOUNT(treeview), path);
920 if (account == NULL)
921 return;
922
923 g_signal_emit_by_name (budget_view, "account-activated", account);
924}
925
926static gboolean
927query_tooltip_tree_view_cb (GtkWidget *widget, gint x, gint y,
928 gboolean keyboard_tip, GtkTooltip *tooltip,
929 GncBudgetView *view)
930{
931 GtkTreeView *tree_view = GTK_TREE_VIEW(widget);
932 GncBudgetViewPrivate *priv = GNC_BUDGET_VIEW_GET_PRIVATE(view);
933 GtkTreePath *path = NULL;
934 GtkTreeViewColumn *column = NULL;
935 const gchar *note;
936 guint period_num;
937 Account *account;
938
939 gtk_tree_view_convert_widget_to_bin_window_coords (tree_view, x, y, &x, &y);
940
941 if (keyboard_tip || !gtk_tree_view_get_path_at_pos (tree_view, x, y, &path,
942 &column, NULL, NULL))
943 {
944 gtk_tree_path_free (path);
945 return FALSE;
946 }
947
948 if (!column)
949 {
950 gtk_tree_path_free (path);
951 return FALSE;
952 }
953
954 period_num = GPOINTER_TO_UINT(g_object_get_data (G_OBJECT(column), "period_num"));
955 if (!period_num && priv->period_col_list->data != column)
956 {
957 gtk_tree_path_free (path);
958 return FALSE;
959 }
961 GNC_TREE_VIEW_ACCOUNT(widget), path);
962 note = gnc_budget_get_account_period_note (priv->budget, account, period_num);
963 if (!note)
964 {
965 gtk_tree_path_free (path);
966 return FALSE;
967 }
968
969 gtk_tooltip_set_text (tooltip, note);
970 gtk_tree_view_set_tooltip_cell (tree_view, tooltip, path, column, NULL);
971 gtk_tree_path_free (path);
972
973 return TRUE;
974}
975
978#if 0
979static void
980gbv_selection_changed_cb (GtkTreeSelection *selection, GncBudgetView *budget_view)
981{
982 GtkTreeView *tree_view;
983 GList *acct_list;
984 gboolean sensitive;
985
986 if (!selection)
987 sensitive = FALSE;
988 else
989 {
990 g_return_if_fail (GTK_IS_TREE_SELECTION(selection));
991 tree_view = gtk_tree_selection_get_tree_view (selection);
993 GNC_TREE_VIEW_ACCOUNT(tree_view));
994
995 /* Check here for placeholder accounts, etc. */
996 sensitive = (g_list_length (acct_list) > 0);
997 g_list_free (acct_list);
998 }
999}
1000#endif
1001
1009typedef struct
1010{
1011 gnc_numeric total;
1012 GncBudget *budget;
1013 guint period_num;
1014 GNCPriceDB *pdb;
1015 gnc_commodity *total_currency;
1017
1022static void
1023budget_accum_helper (Account *account, gpointer data)
1024{
1026 gnc_numeric numeric;
1027 gnc_commodity *currency;
1028
1029 currency = gnc_account_get_currency_or_parent (account);
1030
1031 if (gnc_budget_is_account_period_value_set (info->budget, account, info->period_num))
1032 {
1033 numeric = gnc_budget_get_account_period_value (info->budget, account,
1034 info->period_num);
1036 info->pdb, numeric, currency, info->total_currency,
1037 gnc_budget_get_period_start_date (info->budget, info->period_num));
1038 info->total = gnc_numeric_add (info->total, numeric, GNC_DENOM_AUTO,
1039 GNC_HOW_DENOM_LCD);
1040 }
1041 else if (gnc_account_n_children (account) != 0)
1042 {
1043 numeric = gbv_get_accumulated_budget_amount (info->budget, account,
1044 info->period_num);
1046 info->pdb, numeric, currency, info->total_currency,
1047 gnc_budget_get_period_start_date (info->budget, info->period_num));
1048
1049 info->total = gnc_numeric_add (info->total, numeric, GNC_DENOM_AUTO,
1050 GNC_HOW_DENOM_LCD);
1051 }
1052}
1053
1058static gnc_numeric
1059gbv_get_accumulated_budget_amount (GncBudget *budget, Account *account, guint period_num)
1060{
1062
1063 info.total = gnc_numeric_zero ();
1064 info.budget = budget;
1065 info.period_num = period_num;
1066 info.pdb = gnc_pricedb_get_db (gnc_account_get_book (account));
1067 info.total_currency = gnc_account_get_currency_or_parent (account);
1068
1069 if (!gnc_budget_is_account_period_value_set (budget, account, period_num))
1070 gnc_account_foreach_child (account, budget_accum_helper, &info);
1071 else
1072 info.total = gnc_budget_get_account_period_value (budget, account, period_num);
1073
1074 return info.total;
1075}
1076
1077
1085static gchar *
1086budget_col_source (Account *account, GtkTreeViewColumn *col,
1087 GtkCellRenderer *cell)
1088{
1089 GncBudgetView *budget_view;
1091 guint period_num;
1092 gnc_numeric numeric;
1093 gchar amtbuff[100]; //FIXME: overkill, where's the #define?
1094 const gchar *note;
1095
1096 budget_view = GNC_BUDGET_VIEW(g_object_get_data (G_OBJECT(col), "budget_view"));
1097 period_num = GPOINTER_TO_UINT(g_object_get_data (G_OBJECT(col), "period_num"));
1098
1099 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
1100
1101 if (!gnc_budget_is_account_period_value_set (priv->budget, account, period_num))
1102 {
1103 if (gnc_account_n_children (account) == 0)
1104 amtbuff[0] = '\0';
1105 else
1106 {
1107 GdkRGBA color;
1108 GtkStyleContext *stylectxt = gtk_widget_get_style_context (GTK_WIDGET(priv->tree_view));
1109 gtk_style_context_get_color (stylectxt, GTK_STATE_FLAG_NORMAL, &color);
1110
1111 numeric = gbv_get_accumulated_budget_amount (priv->budget, account, period_num);
1112
1113 if (gnc_reverse_balance (account))
1115
1116 xaccSPrintAmount (amtbuff, numeric, gnc_account_print_info (account, FALSE));
1117 if (gnc_is_dark_theme (&color))
1118 g_object_set (cell, "foreground",
1119 priv->use_red_color && gnc_numeric_negative_p (numeric)
1120 ? "darkred"
1121 : "darkgray",
1122 NULL);
1123 else
1124 g_object_set (cell, "foreground",
1125 priv->use_red_color && gnc_numeric_negative_p (numeric)
1126 ? "PaleVioletRed"
1127 : "dimgray",
1128 NULL);
1129 }
1130 }
1131 else
1132 {
1133 numeric = gnc_budget_get_account_period_value (priv->budget, account,
1134 period_num);
1135 if (gnc_numeric_check (numeric))
1136 strcpy (amtbuff, "error");
1137 else
1138 {
1139 if (gnc_reverse_balance (account))
1141
1142 xaccSPrintAmount (amtbuff, numeric,
1143 gnc_account_print_info (account, FALSE));
1144
1145 if (priv->use_red_color && gnc_numeric_negative_p (numeric))
1146 {
1147 gchar *color = gnc_get_negative_color ();
1148 g_object_set (cell, "foreground", color, NULL);
1149 g_free (color);
1150 }
1151 else
1152 g_object_set (cell, "foreground", NULL, NULL);
1153 }
1154 }
1155
1156 note = gnc_budget_get_account_period_note (priv->budget, account, period_num);
1157 g_object_set (cell, "flagged", note != NULL, NULL);
1158
1159 return g_strdup (amtbuff);
1160}
1161
1165static gnc_numeric
1166bgv_get_total_for_account (Account *account, GncBudget *budget, gnc_commodity *new_currency)
1167{
1168 guint num_periods;
1169 int period_num;
1170 gnc_numeric numeric;
1171 gnc_numeric total = gnc_numeric_zero ();
1172 GNCPriceDB *pdb;
1173 gnc_commodity *currency;
1174
1175 if (new_currency)
1176 {
1177 pdb = gnc_pricedb_get_db (gnc_get_current_book ());
1178 currency = gnc_account_get_currency_or_parent (account);
1179 }
1180
1181 num_periods = gnc_budget_get_num_periods (budget);
1182 for (period_num = 0; period_num < num_periods; ++period_num)
1183 {
1184 if (!gnc_budget_is_account_period_value_set (budget, account, period_num))
1185 {
1186 if (gnc_account_n_children (account) != 0)
1187 {
1188 numeric = gbv_get_accumulated_budget_amount (budget, account, period_num);
1189
1190 if (new_currency)
1191 {
1193 pdb, numeric, currency, new_currency,
1194 gnc_budget_get_period_start_date (budget, period_num));
1195 }
1196 total = gnc_numeric_add (total, numeric, GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD);
1197 }
1198 }
1199 else
1200 {
1201 numeric = gnc_budget_get_account_period_value (budget, account, period_num);
1202 if (!gnc_numeric_check (numeric))
1203 {
1204 if (new_currency)
1205 {
1207 pdb, numeric, currency, new_currency,
1208 gnc_budget_get_period_start_date (budget, period_num));
1209 }
1210 total = gnc_numeric_add (total, numeric, GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD);
1211 }
1212 }
1213 }
1214
1215 return total;
1216}
1217
1220static gchar *
1221budget_total_col_source (Account *account, GtkTreeViewColumn *col,
1222 GtkCellRenderer *cell)
1223{
1224 GncBudgetView *budget_view;
1226 gnc_numeric total;
1227 gchar amtbuff[100]; //FIXME: overkill, where's the #define?
1228
1229 budget_view = GNC_BUDGET_VIEW(g_object_get_data (G_OBJECT(col), "budget_view"));
1230 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
1231
1232 total = bgv_get_total_for_account (account, priv->budget, NULL);
1233 if (gnc_reverse_balance (account))
1234 total = gnc_numeric_neg (total);
1235
1236 xaccSPrintAmount (amtbuff, total, gnc_account_print_info (account, TRUE));
1237
1238 if (priv->use_red_color && gnc_numeric_negative_p (total))
1239 {
1240 gchar *color = gnc_get_negative_color ();
1241 g_object_set (cell, "foreground", color, NULL);
1242 g_free (color);
1243 }
1244 else
1245 g_object_set (cell, "foreground", NULL, NULL);
1246
1247 return g_strdup (amtbuff);
1248}
1249
1257static void
1258budget_col_edited (Account *account, GtkTreeViewColumn *col,
1259 const gchar *new_text)
1260{
1261 GncBudgetView *budget_view;
1263 guint period_num;
1264 gnc_numeric numeric = gnc_numeric_error (GNC_ERROR_ARG);
1265
1266 if (qof_book_is_readonly (gnc_get_current_book ()))
1267 return;
1268
1269 if (!xaccParseAmount (new_text, TRUE, &numeric, NULL) &&
1270 !(new_text && *new_text == '\0'))
1271 return;
1272
1273 period_num = GPOINTER_TO_UINT(g_object_get_data (G_OBJECT(col), "period_num"));
1274
1275 budget_view = GNC_BUDGET_VIEW(g_object_get_data (G_OBJECT(col), "budget_view"));
1276 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
1277
1278 if (new_text && *new_text == '\0')
1279 gnc_budget_unset_account_period_value (priv->budget, account, period_num);
1280 else
1281 {
1282 if (gnc_reverse_balance (account))
1284 gnc_budget_set_account_period_value (priv->budget, account, period_num,
1285 numeric);
1286 }
1287}
1288
1301static void
1302totals_col_source (GtkTreeViewColumn *col, GtkCellRenderer *cell,
1303 GtkTreeModel *s_model, GtkTreeIter *s_iter,
1304 gpointer user_data)
1305{
1306 gnc_numeric total = gnc_numeric_zero ();
1307 GncBudgetView *budget_view = GNC_BUDGET_VIEW(user_data);
1308 GncBudgetViewPrivate *priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
1309 gint period_num = GPOINTER_TO_INT(g_object_get_data (G_OBJECT(col), "period_num"));
1310 GNCPriceDB *pdb = gnc_pricedb_get_db (gnc_get_current_book ());
1311 gnc_commodity *total_currency = gnc_default_currency ();
1312 GList *top_level_accounts = gnc_account_get_children (priv->rootAcct);
1313 gint row_type;
1314
1315 gtk_tree_model_get (s_model, s_iter, 1, &row_type, -1);
1316
1317 // step through each child account of the root, find the total
1318 // income, expenses, liabilities, and assets.
1319 for (GList *node = top_level_accounts; node; node = g_list_next (node))
1320 {
1321 Account *account = node->data;
1323
1324 if ((row_type == TOTALS_TYPE_INCOME && acctype == ACCT_TYPE_INCOME) ||
1325 (row_type == TOTALS_TYPE_EXPENSES && acctype == ACCT_TYPE_EXPENSE) ||
1326 (row_type == TOTALS_TYPE_REMAINDER) ||
1327 (row_type == TOTALS_TYPE_ASSET_LIAB_EQ &&
1328 (acctype == ACCT_TYPE_ASSET || acctype == ACCT_TYPE_LIABILITY ||
1329 acctype == ACCT_TYPE_EQUITY)))
1330 {
1331 gnc_numeric value; // used to assist in adding and subtracting
1332 // find the total for this account
1333 if (period_num < 0)
1334 value = bgv_get_total_for_account (account, priv->budget, total_currency);
1335 else
1336 {
1337 gnc_commodity *currency = gnc_account_get_currency_or_parent (account);
1338 value = gbv_get_accumulated_budget_amount
1339 (priv->budget, account, period_num);
1340
1342 (pdb, value, currency, total_currency,
1343 gnc_budget_get_period_start_date (priv->budget, period_num));
1344 }
1345
1346 total = gnc_numeric_add (total, value, GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD);
1347 }
1348 }
1349
1350 total = gnc_numeric_neg (total);
1351
1352 GNCPrintAmountInfo pinfo = gnc_commodity_print_info (total_currency, period_num < 0);
1353 gchar *color = (priv->use_red_color && gnc_numeric_negative_p (total)) ?
1354 gnc_get_negative_color () : NULL;
1355
1356 g_object_set (G_OBJECT(cell),
1357 "text", xaccPrintAmount (total, pinfo),
1358 "xalign", 1.0,
1359 "foreground", color,
1360 NULL);
1361
1362 g_free (color);
1363 g_list_free (top_level_accounts);
1364}
1365
1371static void
1372gbv_refresh_col_titles (GncBudgetView *budget_view)
1373{
1375 const Recurrence *r;
1376 GDate date, nextdate;
1377 gchar title[MAX_DATE_LENGTH + 1];
1378
1379 g_return_if_fail (budget_view != NULL);
1380 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
1381
1382 /* Show the dates in column titles */
1383 r = gnc_budget_get_recurrence (priv->budget);
1384 date = r->start;
1385 for (GList *node = priv->period_col_list; node; node = g_list_next (node))
1386 {
1387 GtkTreeViewColumn *col = GTK_TREE_VIEW_COLUMN (node->data);
1388 guint titlelen = qof_print_gdate (title, MAX_DATE_LENGTH, &date);
1389
1390 if (titlelen > 0)
1391 gtk_tree_view_column_set_title (col, title);
1392
1393 recurrenceNextInstance (r, &date, &nextdate);
1394 date = nextdate;
1395 }
1396}
1397
1398static void
1399gbv_renderer_add_padding (GtkCellRenderer *renderer)
1400{
1401 gint xpad, ypad;
1402
1403 gtk_cell_renderer_get_padding (renderer, &xpad, &ypad);
1404 if (xpad < 5)
1405 gtk_cell_renderer_set_padding (renderer, 5, ypad);
1406}
1407
1410static GtkTreeViewColumn*
1411gbv_create_totals_column (GncBudgetView *budget_view, gint period_num)
1412{
1413 GtkTreeViewColumn *col;
1414 GtkCellRenderer* renderer;
1415
1416 g_return_val_if_fail (budget_view != NULL, NULL);
1417
1418 renderer = gtk_cell_renderer_text_new ();
1419 col = gtk_tree_view_column_new_with_attributes ("", renderer, NULL);
1420
1421 // add some padding to the right of the numbers
1422 gbv_renderer_add_padding (renderer);
1423
1424 gtk_tree_view_column_set_cell_data_func (col, renderer, totals_col_source, budget_view, NULL);
1425 g_object_set_data (G_OBJECT(col), "budget_view", budget_view);
1426 g_object_set_data (G_OBJECT(col), "period_num", GUINT_TO_POINTER(period_num));
1427 gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED);
1428
1429 return col;
1430}
1431
1436static void
1437gbv_col_edited_cb (GtkCellRendererText *cell, gchar *path_string,
1438 gchar *new_text, gpointer user_data)
1439{
1440 GncBudgetView *budget_view = GNC_BUDGET_VIEW(user_data);
1441 GncBudgetViewPrivate *priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
1442
1443 gtk_widget_queue_draw (GTK_WIDGET(priv->totals_tree_view));
1444}
1445
1446/* The main Start Editing Call back for the budget columns, for key navigation
1447 */
1448static void
1449gdv_editing_started_cb (GtkCellRenderer *cr, GtkCellEditable *editable,
1450 const gchar *path_string, gpointer user_data)
1451{
1452 GncBudgetViewPrivate *priv = GNC_BUDGET_VIEW_GET_PRIVATE(user_data);
1453
1454 priv->temp_cr = cr;
1455 priv->temp_ce = editable;
1456
1457 g_signal_connect (G_OBJECT(editable), "key-press-event",
1458 G_CALLBACK(gbv_key_press_cb), user_data);
1459}
1460
1461static void
1462gdv_editing_canceled_cb (GtkCellRenderer *cr, gpointer user_data)
1463{
1464 GncBudgetViewPrivate *priv = GNC_BUDGET_VIEW_GET_PRIVATE(user_data);
1465
1466 priv->temp_cr = NULL;
1467 priv->temp_ce = NULL;
1468}
1469
1475void
1476gnc_budget_view_refresh (GncBudgetView *budget_view)
1477{
1478 // Column identifiers
1479 enum {
1480 code_column = 1,
1481 description_column = 2,
1482 startPeriods_column = 3
1483 // The Totals column will be after the periods columns.
1484 };
1485
1487 gint num_periods;
1488 gint num_periods_visible;
1489 GtkTreeViewColumn *col, *code_col, *desc_col;
1490 GList *col_list;
1491 GList *totals_col_list;
1492 GdkRGBA *note_color, *note_color_selected;
1493 GtkStyleContext *stylectxt;
1494
1495 ENTER("view %p", budget_view);
1496
1497 g_return_if_fail (budget_view != NULL);
1498 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
1499
1500 stylectxt = gtk_widget_get_style_context (GTK_WIDGET(priv->tree_view));
1501 gtk_style_context_get (stylectxt, GTK_STATE_FLAG_SELECTED, "background-color", &note_color, NULL);
1502 gtk_style_context_get (stylectxt, GTK_STATE_FLAG_NORMAL, "background-color", &note_color_selected, NULL);
1503
1504 num_periods = gnc_budget_get_num_periods (priv->budget);
1505
1506 col_list = g_list_reverse (priv->period_col_list);
1507 totals_col_list = g_list_reverse (priv->totals_col_list);
1508 num_periods_visible = g_list_length (col_list);
1509
1510 /* Hide any unneeded extra columns */
1511 while (num_periods_visible > num_periods)
1512 {
1513 col = GTK_TREE_VIEW_COLUMN (col_list->data);
1514 gtk_tree_view_remove_column (GTK_TREE_VIEW(priv->tree_view), col);
1515 col_list = g_list_delete_link (col_list, col_list);
1516 num_periods_visible--;
1517
1518 col = GTK_TREE_VIEW_COLUMN(totals_col_list->data);
1519 gtk_tree_view_remove_column (GTK_TREE_VIEW(priv->totals_tree_view), col);
1520 totals_col_list = g_list_delete_link (totals_col_list, totals_col_list);
1521 }
1522
1523 gnc_tree_view_configure_columns (GNC_TREE_VIEW(priv->tree_view));
1524
1525 // set visibility of the account code columns
1526 code_col = gnc_tree_view_find_column_by_name (GNC_TREE_VIEW(priv->tree_view), "account-code");
1527 gtk_tree_view_column_set_visible (code_col, priv->show_account_code);
1528 code_col = gtk_tree_view_get_column (GTK_TREE_VIEW(priv->totals_tree_view), code_column);
1529 gtk_tree_view_column_set_visible (code_col, priv->show_account_code);
1530
1531 // set visibility of the account description columns
1532 desc_col = gnc_tree_view_find_column_by_name (GNC_TREE_VIEW(priv->tree_view), "description");
1533 gtk_tree_view_column_set_visible (desc_col, priv->show_account_desc);
1534 desc_col = gtk_tree_view_get_column (GTK_TREE_VIEW(priv->totals_tree_view), description_column);
1535 gtk_tree_view_column_set_visible (desc_col, priv->show_account_desc);
1536
1537 /* If we're creating new columns to be appended to already existing
1538 * columns, first delete the total column. (Then regenerate after
1539 * new columns have been appended */
1540 if (num_periods_visible != 0 && num_periods > num_periods_visible)
1541 {
1542 /* Delete the totals column */
1543 col = priv->total_col;
1544 gtk_tree_view_remove_column (GTK_TREE_VIEW(priv->tree_view), col);
1545 priv->total_col = NULL;
1546 col = gtk_tree_view_get_column (GTK_TREE_VIEW(priv->totals_tree_view),
1547 startPeriods_column + num_periods_visible);
1548 gtk_tree_view_remove_column (GTK_TREE_VIEW(priv->totals_tree_view), col);
1549 }
1550
1551 /* Create any needed columns */
1552 while (num_periods_visible < num_periods)
1553 {
1554 GtkCellRenderer *renderer = gnc_cell_renderer_text_flag_new ();
1555 g_object_set (renderer, "flag-color-rgba", note_color, NULL);
1556 g_object_set (renderer, "flag-color-rgba-selected", note_color_selected, NULL);
1557
1558 col = gnc_tree_view_account_add_custom_column_renderer (
1559 GNC_TREE_VIEW_ACCOUNT(priv->tree_view), "",
1560 budget_col_source, budget_col_edited, renderer);
1561 g_object_set_data (G_OBJECT(col), "budget_view", budget_view);
1562 g_object_set_data (G_OBJECT(col), "period_num", GUINT_TO_POINTER(num_periods_visible));
1563 col_list = g_list_prepend (col_list, col);
1564
1565 // add some padding to the right of the numbers
1566 gbv_renderer_add_padding (renderer);
1567
1568 g_signal_connect (G_OBJECT(renderer), "edited", (GCallback)gbv_col_edited_cb, budget_view);
1569 g_signal_connect (G_OBJECT(renderer), "editing-started",
1570 (GCallback)gdv_editing_started_cb, budget_view);
1571 g_signal_connect (G_OBJECT(renderer), "editing-canceled",
1572 (GCallback)gdv_editing_canceled_cb, budget_view);
1573 col = gbv_create_totals_column (budget_view, num_periods_visible);
1574 if (col != NULL)
1575 {
1576 gtk_tree_view_append_column (priv->totals_tree_view, col);
1577 totals_col_list = g_list_prepend (totals_col_list, col);
1578 }
1579
1580 num_periods_visible++;
1581 }
1582
1583 gdk_rgba_free (note_color);
1584 gdk_rgba_free (note_color_selected);
1585
1586 priv->period_col_list = g_list_reverse (col_list);
1587 priv->totals_col_list = g_list_reverse (totals_col_list);
1588
1589 if (priv->total_col == NULL)
1590 {
1591 gchar title[MAX_DATE_LENGTH + 1];
1592 guint titlelen;
1593 GDate *date;
1594 GtkCellRenderer* renderer;
1595
1596 priv->total_col = gnc_tree_view_account_add_custom_column (
1597 GNC_TREE_VIEW_ACCOUNT(priv->tree_view), _("Total"),
1598 budget_total_col_source, NULL);
1599
1600 // set column title alignment to right to match column data
1601 gtk_tree_view_column_set_alignment (priv->total_col, 1.0);
1602
1603 // set a minimum column size based on the date length, adds some space to the column
1604 date = g_date_new_dmy (31, 12, 2018);
1605 titlelen = qof_print_gdate (title, MAX_DATE_LENGTH, date);
1606 if (titlelen > 0)
1607 {
1608 PangoLayout *layout = gtk_widget_create_pango_layout (GTK_WIDGET(budget_view), title);
1609 PangoRectangle logical_rect;
1610 pango_layout_set_width (layout, -1);
1611 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1612 g_object_unref (layout);
1613
1614 gtk_tree_view_column_set_min_width (priv->total_col, logical_rect.width);
1615 }
1616 g_date_free (date);
1617 g_object_set_data (G_OBJECT(priv->total_col), "budget_view", budget_view);
1618
1619 // as we only have one renderer/column, use this function to get it
1620 renderer = gnc_tree_view_column_get_renderer (priv->total_col);
1621
1622 // add some padding to the right of the numbers
1623 gbv_renderer_add_padding (renderer);
1624
1625 col = gbv_create_totals_column (budget_view, -1);
1626 if (col != NULL)
1627 gtk_tree_view_append_column (priv->totals_tree_view, col);
1628 }
1629 gbv_refresh_col_titles (budget_view);
1630
1631 PINFO("Number of columns is %d, totals columns is %d",
1632 gtk_tree_view_get_n_columns (priv->tree_view), gtk_tree_view_get_n_columns (priv->totals_tree_view));
1633
1634 LEAVE(" ");
1635}
1636
GNCAccountType
The account types are used to determine how the transaction data in the account is displayed.
Definition Account.h:103
gnc_commodity * gnc_account_get_currency_or_parent(const Account *account)
Returns a gnc_commodity that is a currency, suitable for being a Transaction's currency.
Definition Account.cpp:3415
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account's account type.
Definition Account.cpp:3267
GList * gnc_account_get_children(const Account *account)
This routine returns a GList of all children accounts of the specified account.
Definition Account.cpp:2960
void gnc_account_foreach_child(const Account *acc, AccountCb thunk, gpointer user_data)
This method will traverse the immediate children of this accounts, calling 'func' on each account.
Definition Account.cpp:3225
gint gnc_account_n_children(const Account *account)
Return the number of children of the specified account.
Definition Account.cpp:2976
QofBook * qof_session_get_book(const QofSession *session)
Returns the QofBook of this session.
gboolean qof_book_is_readonly(const QofBook *book)
Return whether the book is read only.
Definition qofbook.cpp:497
#define MAX_DATE_LENGTH
The maximum length of a string created by the date printers.
Definition gnc-date.h:108
size_t qof_print_gdate(char *buf, size_t len, const GDate *gd)
Convenience; calls through to qof_print_date_dmy_buff().
Definition gnc-date.cpp:598
GNCAccountType xaccAccountTypeGetFundamental(GNCAccountType t)
Convenience function to return the fundamental type asset/liability/income/expense/equity given an ac...
Definition Account.cpp:4495
#define GUID_ENCODING_LENGTH
Number of characters needed to encode a guid as a string not including the null terminator.
Definition guid.h:84
gchar * guid_to_string_buff(const GncGUID *guid, gchar *str)
The guid_to_string_buff() routine puts a null-terminated string encoding of the id into the memory po...
Definition guid.cpp:208
gboolean gnc_main_window_button_press_cb(GtkWidget *whatever, GdkEventButton *event, GncPluginPage *page)
Callback function invoked when the user clicks in the content of any Gnucash window.
gint gnc_state_drop_sections_for(const gchar *partial_name)
Drop all sections from the state file whose name contains partial_name.
Definition gnc-state.c:260
GKeyFile * gnc_state_get_current(void)
Returns a pointer to the most recently loaded state.
Definition gnc-state.c:248
void gnc_tree_view_configure_columns(GncTreeView *view)
Make all the correct columns visible, respecting their default visibility setting,...
GtkCellRenderer * gnc_tree_view_column_get_renderer(GtkTreeViewColumn *column)
Return the "main" cell renderer from a GtkTreeViewColumn added to a GncTreeView my one of the conveni...
const gchar * gnc_tree_view_get_state_section(GncTreeView *view)
Get the name of the state section this tree view is associated with.
void gnc_tree_view_expand_columns(GncTreeView *view, gchar *first_column_name,...)
This function set the columns that will be allocated the free space in the view.
GtkTreeViewColumn * gnc_tree_view_find_column_by_name(GncTreeView *view, const gchar *wanted)
Find a tree column given the "pref name" used with saved state.
gboolean gnc_is_dark_theme(GdkRGBA *fg_color)
Return whether the current gtk theme is a dark one.
GList * gnc_tree_view_account_get_selected_accounts(GncTreeViewAccount *view)
This function returns a list of the accounts associated with the selected items in the account tree v...
Account * gnc_tree_view_account_get_account_from_path(GncTreeViewAccount *view, GtkTreePath *s_path)
This function returns the account associated with the specified path.
GtkTreeView * gnc_tree_view_account_new(gboolean show_root)
Create a new account tree view.
gboolean gnc_plugin_page_account_tree_filter_accounts(Account *account, gpointer user_data)
This function tells the account tree view whether or not to filter out a particular account.
GtkTreeViewColumn * gnc_tree_view_account_add_custom_column(GncTreeViewAccount *account_view, const gchar *column_title, GncTreeViewAccountColumnSource col_source_cb, GncTreeViewAccountColumnTextEdited col_edited_cb)
Add a new custom column to the set of columns in an account tree view.
void gnc_tree_view_account_set_filter(GncTreeViewAccount *view, gnc_tree_view_account_filter_func func, gpointer data, GSourceFunc destroy)
This function attaches a filter function to the given account tree.
int xaccSPrintAmount(char *bufp, gnc_numeric val, GNCPrintAmountInfo info)
Make a string representation of a gnc_numeric.
const char * xaccPrintAmount(gnc_numeric val, GNCPrintAmountInfo info)
Make a string representation of a gnc_numeric.
gnc_commodity * gnc_default_currency(void)
Return the default currency set by the user.
gboolean xaccParseAmount(const char *in_str, gboolean monetary, gnc_numeric *result, char **endstr)
Parses in_str to obtain a numeric result.
#define PINFO(format, args...)
Print an informational note.
Definition qoflog.h:256
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition qoflog.h:282
#define ENTER(format, args...)
Print a function entry debugging message.
Definition qoflog.h:272
#define GNC_DENOM_AUTO
Values that can be passed as the 'denom' argument.
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...
gboolean gnc_numeric_negative_p(gnc_numeric a)
Returns 1 if a < 0, otherwise returns 0.
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_numeric gnc_numeric_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Return a+b.
@ GNC_ERROR_ARG
Argument is not a valid number.
void gnc_prefs_remove_cb_by_func(const gchar *group, const gchar *pref_name, gpointer func, gpointer user_data)
Remove a function that was registered for a callback when the given preference changed.
gulong gnc_prefs_register_cb(const char *group, const gchar *pref_name, gpointer func, gpointer user_data)
Register a callback that gets triggered when the given preference changes.
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Get a boolean value from the preferences backend.
gnc_numeric gnc_pricedb_convert_balance_nearest_price_t64(GNCPriceDB *pdb, gnc_numeric balance, const gnc_commodity *balance_currency, const gnc_commodity *new_currency, time64 t)
Convert a balance from one currency to another using the price nearest to the given time.
GNCPriceDB * gnc_pricedb_get_db(QofBook *book)
Return the pricedb associated with the book.
void gnc_budget_view_refresh(GncBudgetView *budget_view)
refreshes the current budget view
GtkTreeSelection * gnc_budget_view_get_selection(GncBudgetView *budget_view)
returns the current selection in the gnc budget view.
@ TOTALS_TYPE_REMAINDER
This total is Remaining to Budget.
@ TOTALS_TYPE_ASSET_LIAB_EQ
This total is Asset/Liab/Equity type.
@ TOTALS_TYPE_EXPENSES
This total is Expenses type.
@ TOTALS_TYPE_INCOME
This total is Income type.
Action for when a selection in a gnc budget view is changed.
the private budget view structure

◆ GNC_BUDGET_VIEW_NAME

#define GNC_BUDGET_VIEW_NAME   "GncBudgetView"

Definition at line 50 of file gnc-budget-view.h.

◆ GNC_IS_BUDGET

#define GNC_IS_BUDGET (   o)     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_BUDGET))

Definition at line 88 of file gnc-budget.h.

◆ GNC_IS_BUDGET_CLASS

#define GNC_IS_BUDGET_CLASS (   k)     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_BUDGET))

Definition at line 90 of file gnc-budget.h.

◆ GNC_IS_BUDGET_VIEW

#define GNC_IS_BUDGET_VIEW (   obj)    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_BUDGET_VIEW))

Definition at line 46 of file gnc-budget-view.h.

◆ GNC_IS_BUDGET_VIEW_CLASS

#define GNC_IS_BUDGET_VIEW_CLASS (   klass)    (G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_BUDGET_VIEW))

Definition at line 47 of file gnc-budget-view.h.

◆ GNC_IS_PLUGIN_PAGE_BUDGET

#define GNC_IS_PLUGIN_PAGE_BUDGET (   obj)    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_PLUGIN_PAGE_BUDGET))

Definition at line 44 of file gnc-plugin-page-budget.h.

◆ GNC_IS_PLUGIN_PAGE_BUDGET_CLASS

#define GNC_IS_PLUGIN_PAGE_BUDGET_CLASS (   klass)    (G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_PLUGIN_PAGE_BUDGET))

Definition at line 45 of file gnc-plugin-page-budget.h.

◆ GNC_PLUGIN_PAGE_BUDGET

#define GNC_PLUGIN_PAGE_BUDGET (   obj)    (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_PLUGIN_PAGE_BUDGET, GncPluginPageBudget))

Definition at line 42 of file gnc-plugin-page-budget.h.

◆ GNC_PLUGIN_PAGE_BUDGET_CLASS

#define GNC_PLUGIN_PAGE_BUDGET_CLASS (   klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_PLUGIN_PAGE_BUDGET, GncPluginPageBudgetClass))

Definition at line 43 of file gnc-plugin-page-budget.h.

◆ GNC_PLUGIN_PAGE_BUDGET_GET_CLASS

#define GNC_PLUGIN_PAGE_BUDGET_GET_CLASS (   obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_TYPE_PLUGIN_PAGE_BUDGET, GncPluginPageBudgetClass))

Definition at line 46 of file gnc-plugin-page-budget.h.

◆ GNC_PLUGIN_PAGE_BUDGET_NAME

#define GNC_PLUGIN_PAGE_BUDGET_NAME   "GncPluginPageBudget"

Definition at line 48 of file gnc-plugin-page-budget.h.

◆ GNC_TYPE_BUDGET

#define GNC_TYPE_BUDGET   (gnc_budget_get_type ())

Definition at line 83 of file gnc-budget.h.

◆ GNC_TYPE_BUDGET_VIEW

#define GNC_TYPE_BUDGET_VIEW   (gnc_budget_view_get_type ())

Definition at line 43 of file gnc-budget-view.h.

◆ GNC_TYPE_PLUGIN_PAGE_BUDGET

#define GNC_TYPE_PLUGIN_PAGE_BUDGET   (gnc_plugin_page_budget_get_type ())

Definition at line 41 of file gnc-plugin-page-budget.h.

◆ PLUGIN_PAGE_BUDGET_CM_CLASS

#define PLUGIN_PAGE_BUDGET_CM_CLASS   "budget-view"

Definition at line 82 of file gnc-budget-view.c.

◆ STATE_SECTION_PREFIX

#define STATE_SECTION_PREFIX   "Budget"

Definition at line 83 of file gnc-budget-view.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Todo:
This file is poorly named, since it covers both model and view.

Definition at line 42 of file gnc-tree-model-budget.h.

43{
44 BUDGET_GUID_COLUMN,
45 BUDGET_NAME_COLUMN,
46 BUDGET_DESCRIPTION_COLUMN,
47 BUDGET_LIST_NUM_COLS
48};

◆ anonymous enum

anonymous enum
Enumerator
TOTALS_TYPE_INCOME 

This total is Income type.

TOTALS_TYPE_EXPENSES 

This total is Expenses type.

TOTALS_TYPE_ASSET_LIAB_EQ 

This total is Asset/Liab/Equity type.

TOTALS_TYPE_REMAINDER 

This total is Remaining to Budget.

Definition at line 97 of file gnc-budget-view.c.

Function Documentation

◆ gnc_budget_begin_edit()

void gnc_budget_begin_edit ( GncBudget *  bgt)

Definition at line 291 of file gnc-budget.cpp.

292{
293 qof_begin_edit(QOF_INSTANCE(bgt));
294}
gboolean qof_begin_edit(QofInstance *inst)
begin_edit

◆ gnc_budget_clone()

GncBudget * gnc_budget_clone ( const GncBudget *  budget)

Clones a budget creating a copy.

Definition at line 355 of file gnc-budget.cpp.

356{
357 GncBudget* new_b;
358 Account* root;
359 CloneBudgetData_t clone_data;
360
361 g_return_val_if_fail(old_b != nullptr, nullptr);
362
363 ENTER(" ");
364
366 gnc_budget_begin_edit(new_b);
367 gnc_budget_set_name(new_b, gnc_budget_get_name(old_b));
368 gnc_budget_set_description(new_b, gnc_budget_get_description(old_b));
369 gnc_budget_set_recurrence(new_b, gnc_budget_get_recurrence(old_b));
370 gnc_budget_set_num_periods(new_b, gnc_budget_get_num_periods(old_b));
371
372 root = gnc_book_get_root_account(qof_instance_get_book(old_b));
373 clone_data.old_b = old_b;
374 clone_data.new_b = new_b;
375 clone_data.num_periods = gnc_budget_get_num_periods(new_b);
376 gnc_account_foreach_descendant(root, clone_budget_values_cb, &clone_data);
377
378 gnc_budget_commit_edit(new_b);
379
380 LEAVE(" ");
381
382 return new_b;
383}
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
GncBudget * gnc_budget_new(QofBook *book)
Creates and initializes a Budget.
Data structure for containing info while cloning budget values.

◆ gnc_budget_commit_edit()

void gnc_budget_commit_edit ( GncBudget *  bgt)

Definition at line 297 of file gnc-budget.cpp.

298{
299 if (!qof_commit_edit(QOF_INSTANCE(bgt))) return;
300 qof_commit_edit_part2(QOF_INSTANCE(bgt), commit_err,
301 noop, gnc_budget_free);
302}
gboolean qof_commit_edit_part2(QofInstance *inst, void(*on_error)(QofInstance *, QofBackendError), void(*on_done)(QofInstance *), void(*on_free)(QofInstance *))
part2 – deal with the backend
gboolean qof_commit_edit(QofInstance *inst)
commit_edit helpers

◆ gnc_budget_destroy()

void gnc_budget_destroy ( GncBudget *  budget)

Deletes the given budget object.

Definition at line 321 of file gnc-budget.cpp.

322{
323 g_return_if_fail(GNC_IS_BUDGET(budget));
324 gnc_budget_begin_edit(budget);
325 qof_instance_set_dirty(&budget->inst);
326 qof_instance_set_destroying(budget, TRUE);
327 gnc_budget_commit_edit(budget);
328}

◆ gnc_budget_get_account_period_actual_value()

gnc_numeric gnc_budget_get_account_period_actual_value ( const GncBudget *  budget,
Account account,
guint  period_num 
)

Definition at line 662 of file gnc-budget.cpp.

664{
665 // FIXME: maybe zero is not best error return val.
666 g_return_val_if_fail(GNC_IS_BUDGET(budget) && acc, gnc_numeric_zero());
667 return recurrenceGetAccountPeriodValue(&GET_PRIVATE(budget)->recurrence,
668 acc, period_num);
669}

◆ gnc_budget_get_account_period_note()

const gchar * gnc_budget_get_account_period_note ( const GncBudget *  budget,
const Account account,
guint  period_num 
)

Definition at line 639 of file gnc-budget.cpp.

641{
642 g_return_val_if_fail (period_num < GET_PRIVATE(budget)->num_periods, nullptr);
643 auto& data = get_perioddata (budget, account, period_num);
644 return data.note.empty () ? nullptr : data.note.c_str();
645}

◆ gnc_budget_get_account_period_value()

gnc_numeric gnc_budget_get_account_period_value ( const GncBudget *  budget,
const Account account,
guint  period_num 
)

Definition at line 588 of file gnc-budget.cpp.

591{
592 g_return_val_if_fail (period_num < GET_PRIVATE(budget)->num_periods,
593 gnc_numeric_zero());
594 auto& data = get_perioddata (budget, account, period_num);
595
596 return data.opt_value.has_value() ? data.opt_value.value() : gnc_numeric_zero();
597}

◆ gnc_budget_get_default()

GncBudget * gnc_budget_get_default ( QofBook book)

Definition at line 721 of file gnc-budget.cpp.

722{
723 QofCollection *col;
724 GncBudget *bgt = nullptr;
725 GncGUID *default_budget_guid = nullptr;
726
727 g_return_val_if_fail(book, nullptr);
728
729 qof_instance_get (QOF_INSTANCE (book),
730 "default-budget", &default_budget_guid,
731 nullptr);
732 if (default_budget_guid)
733 {
734 col = qof_book_get_collection(book, GNC_ID_BUDGET);
735 bgt = (GncBudget *) qof_collection_lookup_entity(col,
736 default_budget_guid);
737 }
738
739 /* Revert to 2.2.x behavior if the book has no default budget. */
740
741 if ( bgt == nullptr )
742 {
743 col = qof_book_get_collection(book, GNC_ID_BUDGET);
744 if (qof_collection_count(col) > 0)
745 {
746 qof_collection_foreach(col, just_get_one, &bgt);
747 }
748 }
749
750 guid_free (default_budget_guid);
751 return bgt;
752}
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
Definition qofbook.cpp:521
QofInstance * qof_collection_lookup_entity(const QofCollection *col, const GncGUID *guid)
Find the entity going only from its guid.
Definition qofid.cpp:209
guint qof_collection_count(const QofCollection *col)
return the number of entities in the collection.
Definition qofid.cpp:221
void qof_instance_get(const QofInstance *inst, const gchar *first_prop,...)
Wrapper for g_object_get.

◆ gnc_budget_get_description()

const gchar * gnc_budget_get_description ( const GncBudget *  budget)

Definition at line 429 of file gnc-budget.cpp.

430{
431 g_return_val_if_fail(GNC_IS_BUDGET(budget), nullptr);
432 return GET_PRIVATE(budget)->description;
433}

◆ gnc_budget_get_guid()

const GncGUID * gnc_budget_get_guid ( const GncBudget *  budget)

Definition at line 459 of file gnc-budget.cpp.

460{
461 g_return_val_if_fail(budget, nullptr);
462 g_return_val_if_fail(GNC_IS_BUDGET(budget), nullptr);
463 return qof_instance_get_guid(QOF_INSTANCE(budget));
464}
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.

◆ gnc_budget_get_name()

const gchar * gnc_budget_get_name ( const GncBudget *  budget)

Definition at line 404 of file gnc-budget.cpp.

405{
406 g_return_val_if_fail(GNC_IS_BUDGET(budget), nullptr);
407 return GET_PRIVATE(budget)->name;
408}

◆ gnc_budget_get_num_periods()

guint gnc_budget_get_num_periods ( const GncBudget *  budget)

Definition at line 488 of file gnc-budget.cpp.

489{
490 g_return_val_if_fail(GNC_IS_BUDGET(budget), 0);
491 return GET_PRIVATE(budget)->num_periods;
492}

◆ gnc_budget_get_period_end_date()

time64 gnc_budget_get_period_end_date ( const GncBudget *  budget,
guint  period_num 
)

Get the ending date of the Budget period.

Definition at line 655 of file gnc-budget.cpp.

656{
657 g_return_val_if_fail (GNC_IS_BUDGET(budget), 0);
658 return recurrenceGetPeriodTime(&GET_PRIVATE(budget)->recurrence, period_num, TRUE);
659}

◆ gnc_budget_get_period_start_date()

time64 gnc_budget_get_period_start_date ( const GncBudget *  budget,
guint  period_num 
)

Get the starting date of the Budget period.

Definition at line 648 of file gnc-budget.cpp.

649{
650 g_return_val_if_fail (GNC_IS_BUDGET(budget), 0);
651 return recurrenceGetPeriodTime(&GET_PRIVATE(budget)->recurrence, period_num, FALSE);
652}

◆ gnc_budget_get_recurrence()

const Recurrence * gnc_budget_get_recurrence ( const GncBudget *  budget)

Definition at line 452 of file gnc-budget.cpp.

453{
454 g_return_val_if_fail(budget, nullptr);
455 return (&GET_PRIVATE(budget)->recurrence);
456}

◆ gnc_budget_gui_delete_budget()

void gnc_budget_gui_delete_budget ( GncBudget *  budget)

Definition at line 928 of file gnc-plugin-page-budget.cpp.

929{
930 const char *name;
931
932 g_return_if_fail (GNC_IS_BUDGET(budget));
933 name = gnc_budget_get_name (budget);
934 if (!name)
935 name = _("Unnamed Budget");
936
937 if (gnc_verify_dialog (NULL, FALSE, _("Delete %s?"), name))
938 {
939 QofBook* book = gnc_get_current_book ();
940
941 gnc_suspend_gui_refresh ();
942 gnc_budget_destroy (budget);
943
944 if (qof_collection_count (qof_book_get_collection (book, GNC_ID_BUDGET)) == 0)
945 {
946 gnc_features_set_unused (book, GNC_FEATURE_BUDGET_UNREVERSED);
947 PWARN ("No budgets left. Removing feature BUDGET_UNREVERSED.");
948 }
949 // Views should close themselves because the CM will notify them.
950 gnc_resume_gui_refresh ();
951 }
952}
#define PWARN(format, args...)
Log a warning.
Definition qoflog.h:250
void gnc_features_set_unused(QofBook *book, const gchar *feature)
Indicate that the current book does not use the given feature.
void gnc_budget_destroy(GncBudget *budget)
Deletes the given budget object.

◆ gnc_budget_is_account_period_value_set()

gboolean gnc_budget_is_account_period_value_set ( const GncBudget *  budget,
const Account account,
guint  period_num 
)

Definition at line 579 of file gnc-budget.cpp.

582{
583 g_return_val_if_fail (period_num < GET_PRIVATE(budget)->num_periods, false);
584 return get_perioddata (budget, account, period_num).opt_value.has_value();
585}

◆ gnc_budget_lookup()

GncBudget * gnc_budget_lookup ( const GncGUID guid,
const QofBook book 
)

Definition at line 704 of file gnc-budget.cpp.

705{
706 QofCollection *col;
707
708 g_return_val_if_fail(guid, nullptr);
709 g_return_val_if_fail(book, nullptr);
710 col = qof_book_get_collection (book, GNC_ID_BUDGET);
711 return GNC_BUDGET(qof_collection_lookup_entity (col, guid));
712}

◆ gnc_budget_new()

GncBudget * gnc_budget_new ( QofBook book)

Creates and initializes a Budget.

Definition at line 305 of file gnc-budget.cpp.

306{
307 g_return_val_if_fail(book, nullptr);
308
309 ENTER(" ");
310
311 auto budget { static_cast<GncBudget*>(g_object_new(GNC_TYPE_BUDGET, nullptr)) };
312 qof_instance_init_data (&budget->inst, GNC_ID_BUDGET, book);
313
314 qof_event_gen( &budget->inst, QOF_EVENT_CREATE , nullptr);
315
316 LEAVE(" ");
317 return budget;
318}
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition qofevent.cpp:231
void qof_instance_init_data(QofInstance *inst, QofIdType type, QofBook *book)
Initialise the settings associated with an instance.

◆ gnc_budget_register()

gboolean gnc_budget_register ( void  )

Definition at line 815 of file gnc-budget.cpp.

816{
817 static QofParam params[] =
818 {
819 {
820 "name", QOF_TYPE_STRING,
821 (QofAccessFunc) gnc_budget_get_name,
823 },
824 {
825 "description", QOF_TYPE_STRING,
826 (QofAccessFunc) gnc_budget_get_description,
828 },
829 {
830 "recurrence_period_type", QOF_TYPE_INT32,
831 (QofAccessFunc) gnc_budget_get_rec_pt, nullptr
832 },
833 /* Signedness problem: Should be unsigned. */
834 {
835 "recurrence_multiplier", QOF_TYPE_INT32,
836 (QofAccessFunc) gnc_budget_get_rec_mult, nullptr
837 },
838 /* This is the same way that SchedXaction.c uses QOF_TYPE_DATE
839 but I don't think QOF actually supports a GDate, so I think
840 this is wrong. */
841 {
842 "recurrence_date", QOF_TYPE_DATE,
843 (QofAccessFunc) gnc_budget_get_rec_time, nullptr
844 },
845 /* Signedness problem: Should be unsigned. */
846 {
847 "num_periods", QOF_TYPE_INT32,
848 (QofAccessFunc) gnc_budget_get_num_periods,
850 },
851 {
852 QOF_PARAM_BOOK, QOF_ID_BOOK,
854 },
855 {
856 QOF_PARAM_GUID, QOF_TYPE_GUID,
858 },
859 { nullptr },
860 };
861
862 qof_class_register(GNC_ID_BUDGET, (QofSortFunc) nullptr, params);
863 return qof_object_register(&budget_object_def);
864}
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
The QofAccessFunc defines an arbitrary function pointer for access functions.
Definition qofclass.h:123
void(* QofSetterFunc)(gpointer, gpointer)
The QofSetterFunc defines an function pointer for parameter setters.
Definition qofclass.h:130
void qof_class_register(QofIdTypeConst obj_name, QofSortFunc default_sort_function, const QofParam *params)
This function registers a new object class with the Qof subsystem.
Definition qofclass.cpp:86
int(* QofSortFunc)(gconstpointer, gconstpointer)
This function is the default sort function for a particular object type.
Definition qofclass.h:168
gboolean qof_object_register(const QofObject *object)
Register new types of object objects.
#define QOF_PARAM_BOOK
"Known" Object Parameters – all objects must support these
Definition qofquery.h:108

◆ gnc_budget_set_account_period_note()

void gnc_budget_set_account_period_note ( GncBudget *  budget,
const Account account,
guint  period_num,
const gchar *  note 
)

Definition at line 600 of file gnc-budget.cpp.

602{
603 g_return_if_fail (budget != nullptr);
604 g_return_if_fail (account != nullptr);
605
606 /* Watch out for an off-by-one error here:
607 * period_num starts from 0 while num_periods starts from 1 */
608 if (period_num >= GET_PRIVATE(budget)->num_periods)
609 {
610 PWARN("Period %i does not exist", period_num);
611 return;
612 }
613
614 auto& perioddata = get_perioddata (budget, account, period_num);
615 auto budget_kvp { QOF_INSTANCE (budget)->kvp_data };
616 auto path = make_period_note_path (account, period_num);
617
618 gnc_budget_begin_edit(budget);
619 if (note == nullptr)
620 {
621 delete budget_kvp->set_path (path, nullptr);
622 perioddata.note.clear ();
623 }
624 else
625 {
626 KvpValue* v = new KvpValue (g_strdup (note));
627
628 delete budget_kvp->set_path (path, v);
629 perioddata.note = note;
630 }
631 qof_instance_set_dirty(&budget->inst);
632 gnc_budget_commit_edit(budget);
633
634 qof_event_gen( &budget->inst, QOF_EVENT_MODIFY, nullptr);
635
636}

◆ gnc_budget_set_account_period_value()

void gnc_budget_set_account_period_value ( GncBudget *  budget,
const Account account,
guint  period_num,
gnc_numeric  val 
)

Definition at line 541 of file gnc-budget.cpp.

543{
544 g_return_if_fail (budget != nullptr);
545 g_return_if_fail (account != nullptr);
546
547 /* Watch out for an off-by-one error here:
548 * period_num starts from 0 while num_periods starts from 1 */
549 if (period_num >= GET_PRIVATE(budget)->num_periods)
550 {
551 PWARN("Period %i does not exist", period_num);
552 return;
553 }
554
555 auto& perioddata = get_perioddata (budget, account, period_num);
556 auto budget_kvp { QOF_INSTANCE (budget)->kvp_data };
557 auto path = make_period_data_path (account, period_num);
558
559 gnc_budget_begin_edit(budget);
560 if (gnc_numeric_check(val))
561 {
562 delete budget_kvp->set_path (path, nullptr);
563 perioddata.opt_value.reset();
564 }
565 else
566 {
567 KvpValue* v = new KvpValue (val);
568 delete budget_kvp->set_path (path, v);
569 perioddata.opt_value = val;
570 }
571 qof_instance_set_dirty(&budget->inst);
572 gnc_budget_commit_edit(budget);
573
574 qof_event_gen( &budget->inst, QOF_EVENT_MODIFY, nullptr);
575
576}
GNCNumericErrorCode gnc_numeric_check(gnc_numeric in)
Check for error signal in value.

◆ gnc_budget_set_description()

void gnc_budget_set_description ( GncBudget *  budget,
const gchar *  description 
)

Set/Get the description of the Budget.

Definition at line 411 of file gnc-budget.cpp.

412{
413 GncBudgetPrivate* priv;
414
415 g_return_if_fail(GNC_IS_BUDGET(budget));
416 g_return_if_fail(description);
417
418 priv = GET_PRIVATE(budget);
419 if ( description == priv->description ) return;
420 gnc_budget_begin_edit(budget);
421 CACHE_REPLACE(priv->description, description);
422 qof_instance_set_dirty(&budget->inst);
423 gnc_budget_commit_edit(budget);
424
425 qof_event_gen( &budget->inst, QOF_EVENT_MODIFY, nullptr);
426}

◆ gnc_budget_set_name()

void gnc_budget_set_name ( GncBudget *  budget,
const gchar *  name 
)

Set/Get the name of the Budget.

Definition at line 386 of file gnc-budget.cpp.

387{
388 GncBudgetPrivate* priv;
389
390 g_return_if_fail(GNC_IS_BUDGET(budget) && name);
391
392 priv = GET_PRIVATE(budget);
393 if ( name == priv->name ) return;
394
395 gnc_budget_begin_edit(budget);
396 CACHE_REPLACE(priv->name, name);
397 qof_instance_set_dirty(&budget->inst);
398 gnc_budget_commit_edit(budget);
399
400 qof_event_gen( &budget->inst, QOF_EVENT_MODIFY, nullptr);
401}

◆ gnc_budget_set_num_periods()

void gnc_budget_set_num_periods ( GncBudget *  budget,
guint  num_periods 
)

Set/Get the number of periods in the Budget.

Definition at line 467 of file gnc-budget.cpp.

468{
469 GncBudgetPrivate* priv;
470
471 g_return_if_fail(GNC_IS_BUDGET(budget));
472 g_return_if_fail(num_periods > 0);
473
474 priv = GET_PRIVATE(budget);
475 if ( priv->num_periods == num_periods ) return;
476
477 gnc_budget_begin_edit(budget);
478 priv->num_periods = num_periods;
479 std::for_each (priv->acct_map.begin(), priv->acct_map.end(),
480 [num_periods](auto& it){ it.second.resize(num_periods); });
481 qof_instance_set_dirty(&budget->inst);
482 gnc_budget_commit_edit(budget);
483
484 qof_event_gen( &budget->inst, QOF_EVENT_MODIFY, nullptr);
485}

◆ gnc_budget_set_recurrence()

void gnc_budget_set_recurrence ( GncBudget *  budget,
const Recurrence r 
)

Definition at line 436 of file gnc-budget.cpp.

437{
438 GncBudgetPrivate* priv;
439
440 g_return_if_fail(budget && r);
441 priv = GET_PRIVATE(budget);
442
443 gnc_budget_begin_edit(budget);
444 priv->recurrence = *r;
445 qof_instance_set_dirty(&budget->inst);
446 gnc_budget_commit_edit(budget);
447
448 qof_event_gen(&budget->inst, QOF_EVENT_MODIFY, nullptr);
449}

◆ gnc_budget_unset_account_period_value()

void gnc_budget_unset_account_period_value ( GncBudget *  budget,
const Account account,
guint  period_num 
)

Definition at line 517 of file gnc-budget.cpp.

519{
520 g_return_if_fail (budget != nullptr);
521 g_return_if_fail (account != nullptr);
522 g_return_if_fail (period_num < GET_PRIVATE(budget)->num_periods);
523
524 auto& data = get_perioddata (budget, account, period_num);
525 data.opt_value.reset();
526
527 gnc_budget_begin_edit(budget);
528 auto path = make_period_data_path (account, period_num);
529 auto budget_kvp { QOF_INSTANCE (budget)->kvp_data };
530 delete budget_kvp->set_path (path, nullptr);
531 qof_instance_set_dirty(&budget->inst);
532 gnc_budget_commit_edit(budget);
533
534 qof_event_gen( &budget->inst, QOF_EVENT_MODIFY, nullptr);
535
536}

◆ gnc_budget_view_delete_budget()

void gnc_budget_view_delete_budget ( GncBudgetView *  budget_view)

Definition at line 691 of file gnc-budget-view.c.

692{
694 gchar guidstr[GUID_ENCODING_LENGTH+1];
695
696 g_return_if_fail (budget_view != NULL);
697
698 ENTER("view %p", budget_view);
699
700 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
701
702 guid_to_string_buff (&priv->key, guidstr);
704 g_object_set (G_OBJECT(priv->tree_view), "state-section", NULL, NULL);
705
706 LEAVE(" ");
707}

◆ gnc_budget_view_get_account_from_path()

Account * gnc_budget_view_get_account_from_path ( GncBudgetView *  budget_view,
GtkTreePath *  path 
)

Definition at line 329 of file gnc-budget-view.c.

330{
332
333 g_return_val_if_fail (GNC_IS_BUDGET_VIEW(budget_view), NULL);
334
335 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
336 return gnc_tree_view_account_get_account_from_path (GNC_TREE_VIEW_ACCOUNT(priv->tree_view), path);
337}

◆ gnc_budget_view_get_account_tree_view()

GtkWidget * gnc_budget_view_get_account_tree_view ( GncBudgetView *  budget_view)

Definition at line 340 of file gnc-budget-view.c.

341{
343
344 g_return_val_if_fail (GNC_IS_BUDGET_VIEW(budget_view), NULL);
345
346 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
347 return GTK_WIDGET(priv->fd->tree_view);
348}

◆ gnc_budget_view_get_selected_accounts()

GList * gnc_budget_view_get_selected_accounts ( GncBudgetView *  budget_view)

Definition at line 351 of file gnc-budget-view.c.

352{
354
355 g_return_val_if_fail (GNC_IS_BUDGET_VIEW(budget_view), NULL);
356
357 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
358 return gnc_tree_view_account_get_selected_accounts (GNC_TREE_VIEW_ACCOUNT(priv->tree_view));
359}

◆ gnc_budget_view_get_selection()

GtkTreeSelection * gnc_budget_view_get_selection ( GncBudgetView *  budget_view)

returns the current selection in the gnc budget view.

Returns the current selection in the gnc budget view by using the macro GNC_BUDGET_VIEW_GET_PRIVATE.

Definition at line 318 of file gnc-budget-view.c.

319{
321
322 g_return_val_if_fail (GNC_IS_BUDGET_VIEW(budget_view), NULL);
323
324 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
325 return gtk_tree_view_get_selection (GTK_TREE_VIEW(priv->tree_view));
326}

◆ gnc_budget_view_get_show_account_code()

gboolean gnc_budget_view_get_show_account_code ( GncBudgetView *  budget_view)

Definition at line 255 of file gnc-budget-view.c.

256{
257 GncBudgetViewPrivate *priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
258 return priv->show_account_code;
259}

◆ gnc_budget_view_get_show_account_description()

gboolean gnc_budget_view_get_show_account_description ( GncBudgetView *  budget_view)

Definition at line 270 of file gnc-budget-view.c.

271{
272 GncBudgetViewPrivate *priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
273 return priv->show_account_desc;
274}

◆ gnc_budget_view_new()

GncBudgetView * gnc_budget_view_new ( GncBudget *  budget,
AccountFilterDialog fd 
)

Create new gnc budget view.

Create a new "budget" display widget.

As the name suggests, this creates a new gnc budget view.

Returns
The newly created widget

Definition at line 188 of file gnc-budget-view.c.

189{
190 GncBudgetView *budget_view;
192
193 g_return_val_if_fail (GNC_IS_BUDGET(budget), NULL);
194 ENTER(" ");
195
196 budget_view = g_object_new (GNC_TYPE_BUDGET_VIEW, NULL);
197
198 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
199 priv->budget = budget;
200 priv->key = *gnc_budget_get_guid (budget);
201 priv->fd = fd;
202 priv->total_col = NULL;
203 priv->show_account_code = FALSE;
204 priv->show_account_desc = FALSE;
205 gbv_create_widget (budget_view);
206
207 LEAVE("new budget view %p", budget_view);
208 return budget_view;
209}

◆ gnc_budget_view_refresh()

void gnc_budget_view_refresh ( GncBudgetView *  budget_view)

refreshes the current budget view

The function will step through to only display the columns that are set as visible, and will add any needed columns (e.g. the totals column).

Definition at line 1477 of file gnc-budget-view.c.

1478{
1479 // Column identifiers
1480 enum {
1481 code_column = 1,
1482 description_column = 2,
1483 startPeriods_column = 3
1484 // The Totals column will be after the periods columns.
1485 };
1486
1488 gint num_periods;
1489 gint num_periods_visible;
1490 GtkTreeViewColumn *col, *code_col, *desc_col;
1491 GList *col_list;
1492 GList *totals_col_list;
1493 GdkRGBA *note_color, *note_color_selected;
1494 GtkStyleContext *stylectxt;
1495
1496 ENTER("view %p", budget_view);
1497
1498 g_return_if_fail (budget_view != NULL);
1499 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
1500
1501 stylectxt = gtk_widget_get_style_context (GTK_WIDGET(priv->tree_view));
1502 gtk_style_context_get (stylectxt, GTK_STATE_FLAG_SELECTED, "background-color", &note_color, NULL);
1503 gtk_style_context_get (stylectxt, GTK_STATE_FLAG_NORMAL, "background-color", &note_color_selected, NULL);
1504
1505 num_periods = gnc_budget_get_num_periods (priv->budget);
1506
1507 col_list = g_list_reverse (priv->period_col_list);
1508 totals_col_list = g_list_reverse (priv->totals_col_list);
1509 num_periods_visible = g_list_length (col_list);
1510
1511 /* Hide any unneeded extra columns */
1512 while (num_periods_visible > num_periods)
1513 {
1514 col = GTK_TREE_VIEW_COLUMN (col_list->data);
1515 gtk_tree_view_remove_column (GTK_TREE_VIEW(priv->tree_view), col);
1516 col_list = g_list_delete_link (col_list, col_list);
1517 num_periods_visible--;
1518
1519 col = GTK_TREE_VIEW_COLUMN(totals_col_list->data);
1520 gtk_tree_view_remove_column (GTK_TREE_VIEW(priv->totals_tree_view), col);
1521 totals_col_list = g_list_delete_link (totals_col_list, totals_col_list);
1522 }
1523
1524 gnc_tree_view_configure_columns (GNC_TREE_VIEW(priv->tree_view));
1525
1526 // set visibility of the account code columns
1527 code_col = gnc_tree_view_find_column_by_name (GNC_TREE_VIEW(priv->tree_view), "account-code");
1528 gtk_tree_view_column_set_visible (code_col, priv->show_account_code);
1529 code_col = gtk_tree_view_get_column (GTK_TREE_VIEW(priv->totals_tree_view), code_column);
1530 gtk_tree_view_column_set_visible (code_col, priv->show_account_code);
1531
1532 // set visibility of the account description columns
1533 desc_col = gnc_tree_view_find_column_by_name (GNC_TREE_VIEW(priv->tree_view), "description");
1534 gtk_tree_view_column_set_visible (desc_col, priv->show_account_desc);
1535 desc_col = gtk_tree_view_get_column (GTK_TREE_VIEW(priv->totals_tree_view), description_column);
1536 gtk_tree_view_column_set_visible (desc_col, priv->show_account_desc);
1537
1538 /* If we're creating new columns to be appended to already existing
1539 * columns, first delete the total column. (Then regenerate after
1540 * new columns have been appended */
1541 if (num_periods_visible != 0 && num_periods > num_periods_visible)
1542 {
1543 /* Delete the totals column */
1544 col = priv->total_col;
1545 gtk_tree_view_remove_column (GTK_TREE_VIEW(priv->tree_view), col);
1546 priv->total_col = NULL;
1547 col = gtk_tree_view_get_column (GTK_TREE_VIEW(priv->totals_tree_view),
1548 startPeriods_column + num_periods_visible);
1549 gtk_tree_view_remove_column (GTK_TREE_VIEW(priv->totals_tree_view), col);
1550 }
1551
1552 /* Create any needed columns */
1553 while (num_periods_visible < num_periods)
1554 {
1555 GtkCellRenderer *renderer = gnc_cell_renderer_text_flag_new ();
1556 g_object_set (renderer, "flag-color-rgba", note_color, NULL);
1557 g_object_set (renderer, "flag-color-rgba-selected", note_color_selected, NULL);
1558
1559 col = gnc_tree_view_account_add_custom_column_renderer (
1560 GNC_TREE_VIEW_ACCOUNT(priv->tree_view), "",
1561 budget_col_source, budget_col_edited, renderer);
1562 g_object_set_data (G_OBJECT(col), "budget_view", budget_view);
1563 g_object_set_data (G_OBJECT(col), "period_num", GUINT_TO_POINTER(num_periods_visible));
1564 col_list = g_list_prepend (col_list, col);
1565
1566 // add some padding to the right of the numbers
1567 gbv_renderer_add_padding (renderer);
1568
1569 g_signal_connect (G_OBJECT(renderer), "edited", (GCallback)gbv_col_edited_cb, budget_view);
1570 g_signal_connect (G_OBJECT(renderer), "editing-started",
1571 (GCallback)gdv_editing_started_cb, budget_view);
1572 g_signal_connect (G_OBJECT(renderer), "editing-canceled",
1573 (GCallback)gdv_editing_canceled_cb, budget_view);
1574 col = gbv_create_totals_column (budget_view, num_periods_visible);
1575 if (col != NULL)
1576 {
1577 gtk_tree_view_append_column (priv->totals_tree_view, col);
1578 totals_col_list = g_list_prepend (totals_col_list, col);
1579 }
1580
1581 num_periods_visible++;
1582 }
1583
1584 gdk_rgba_free (note_color);
1585 gdk_rgba_free (note_color_selected);
1586
1587 priv->period_col_list = g_list_reverse (col_list);
1588 priv->totals_col_list = g_list_reverse (totals_col_list);
1589
1590 if (priv->total_col == NULL)
1591 {
1592 gchar title[MAX_DATE_LENGTH + 1];
1593 guint titlelen;
1594 GDate *date;
1595 GtkCellRenderer* renderer;
1596
1597 priv->total_col = gnc_tree_view_account_add_custom_column (
1598 GNC_TREE_VIEW_ACCOUNT(priv->tree_view), _("Total"),
1599 budget_total_col_source, NULL);
1600
1601 // set column title alignment to right to match column data
1602 gtk_tree_view_column_set_alignment (priv->total_col, 1.0);
1603
1604 // set a minimum column size based on the date length, adds some space to the column
1605 date = g_date_new_dmy (31, 12, 2018);
1606 titlelen = qof_print_gdate (title, MAX_DATE_LENGTH, date);
1607 if (titlelen > 0)
1608 {
1609 PangoLayout *layout = gtk_widget_create_pango_layout (GTK_WIDGET(budget_view), title);
1610 PangoRectangle logical_rect;
1611 pango_layout_set_width (layout, -1);
1612 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
1613 g_object_unref (layout);
1614
1615 gtk_tree_view_column_set_min_width (priv->total_col, logical_rect.width);
1616 }
1617 g_date_free (date);
1618 g_object_set_data (G_OBJECT(priv->total_col), "budget_view", budget_view);
1619
1620 // as we only have one renderer/column, use this function to get it
1621 renderer = gnc_tree_view_column_get_renderer (priv->total_col);
1622
1623 // add some padding to the right of the numbers
1624 gbv_renderer_add_padding (renderer);
1625
1626 col = gbv_create_totals_column (budget_view, -1);
1627 if (col != NULL)
1628 gtk_tree_view_append_column (priv->totals_tree_view, col);
1629 }
1630 gbv_refresh_col_titles (budget_view);
1631
1632 PINFO("Number of columns is %d, totals columns is %d",
1633 gtk_tree_view_get_n_columns (priv->tree_view), gtk_tree_view_get_n_columns (priv->totals_tree_view));
1634
1635 LEAVE(" ");
1636}

◆ gnc_budget_view_restore()

gboolean gnc_budget_view_restore ( GncBudgetView *  budget_view,
GKeyFile *  key_file,
const gchar *  group_name 
)

Definition at line 633 of file gnc-budget-view.c.

634{
636 GError *error = NULL;
637 char *guid_str;
638 GncGUID guid;
639 GncBudget *bgt;
640 QofBook *book;
641 gboolean has_guid;
642
643 g_return_val_if_fail (key_file, FALSE);
644 g_return_val_if_fail (group_name, FALSE);
645
646 ENTER("key_file %p, group_name %s", key_file, group_name);
647
648 guid_str = g_key_file_get_string (key_file, group_name, BUDGET_GUID,
649 &error);
650 if (error)
651 {
652 g_warning ("error reading group %s key %s: %s",
653 group_name, BUDGET_GUID, error->message);
654 g_error_free (error);
655 error = NULL;
656 return FALSE;
657 }
658 has_guid = string_to_guid (guid_str, &guid);
659 g_free (guid_str);
660
661 if (!has_guid)
662 {
663 return FALSE;
664 }
665
666 book = qof_session_get_book (gnc_get_current_session());
667 bgt = gnc_budget_lookup (&guid, book);
668 if (!bgt)
669 {
670 return FALSE;
671 }
672
673 /* Create the new view */
674 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
675
676 // Restore the account filter and page state information from page section
677 gnc_tree_view_account_restore (GNC_TREE_VIEW_ACCOUNT(priv->tree_view),
678 priv->fd, key_file, group_name);
679 LEAVE(" ");
680
681 return TRUE;
682}

◆ gnc_budget_view_save()

void gnc_budget_view_save ( GncBudgetView *  budget_view,
GKeyFile *  key_file,
const gchar *  group_name 
)

Definition at line 600 of file gnc-budget-view.c.

601{
603
604 g_return_if_fail (budget_view != NULL);
605 g_return_if_fail (key_file != NULL);
606 g_return_if_fail (group_name != NULL);
607
608 ENTER("view %p, key_file %p, group_name %s", budget_view, key_file, group_name);
609
610 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
611
612 // Save the account filter and page state information to page section
613 gnc_tree_view_account_save (GNC_TREE_VIEW_ACCOUNT(priv->tree_view),
614 priv->fd, key_file, group_name);
615 LEAVE(" ");
616}

◆ gnc_budget_view_save_account_filter()

void gnc_budget_view_save_account_filter ( GncBudgetView *  budget_view)

Definition at line 715 of file gnc-budget-view.c.

716{
718
719 g_return_if_fail (budget_view != NULL);
720
721 ENTER("view %p", budget_view);
722
723 priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
724
725 // Save account filter state information to budget section
726 gnc_tree_view_account_save_filter (GNC_TREE_VIEW_ACCOUNT(priv->tree_view),
727 priv->fd, gnc_state_get_current (),
729 GNC_TREE_VIEW(priv->tree_view)));
730 LEAVE(" ");
731}

◆ gnc_budget_view_set_show_account_code()

void gnc_budget_view_set_show_account_code ( GncBudgetView *  budget_view,
gboolean  show_account_code 
)

Definition at line 247 of file gnc-budget-view.c.

248{
249 GncBudgetViewPrivate *priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
250 priv->show_account_code = show_account_code;
251 gnc_budget_view_refresh (budget_view);
252}

◆ gnc_budget_view_set_show_account_description()

void gnc_budget_view_set_show_account_description ( GncBudgetView *  budget_view,
gboolean  show_account_desc 
)

Definition at line 262 of file gnc-budget-view.c.

263{
264 GncBudgetViewPrivate *priv = GNC_BUDGET_VIEW_GET_PRIVATE(budget_view);
265 priv->show_account_desc = show_account_desc;
266 gnc_budget_view_refresh (budget_view);
267}

◆ gnc_plugin_page_budget_new()

GncPluginPage * gnc_plugin_page_budget_new ( GncBudget *  budget)

Create a new "budget" plugin page.

Returns
The newly created plugin page.

Definition at line 234 of file gnc-plugin-page-budget.cpp.

235{
237 gchar* label;
238 const GList *item;
239
240 g_return_val_if_fail (GNC_IS_BUDGET(budget), NULL);
241 ENTER(" ");
242
243 /* Is there an existing page? */
244 item = gnc_gobject_tracking_get_list (GNC_PLUGIN_PAGE_BUDGET_NAME);
245 for ( ; item; item = g_list_next (item))
246 {
247 auto plugin_page = GNC_PLUGIN_PAGE_BUDGET(item->data);
248 priv = GNC_PLUGIN_PAGE_BUDGET_GET_PRIVATE(plugin_page);
249 if (priv->budget == budget)
250 {
251 LEAVE("existing budget page %p", plugin_page);
252 return GNC_PLUGIN_PAGE(plugin_page);
253 }
254 }
255
256 auto plugin_page = GNC_PLUGIN_PAGE_BUDGET (g_object_new (GNC_TYPE_PLUGIN_PAGE_BUDGET, nullptr));
257
258 priv = GNC_PLUGIN_PAGE_BUDGET_GET_PRIVATE(plugin_page);
259 priv->budget = budget;
260 priv->delete_budget = FALSE;
261 priv->key = *gnc_budget_get_guid (budget);
262 priv->reportPage = NULL;
263 label = g_strdup_printf ("%s: %s", _("Budget"), gnc_budget_get_name (budget));
264 g_object_set (G_OBJECT(plugin_page), "page-name", label, NULL);
265 g_free (label);
266 LEAVE("new budget page %p", plugin_page);
267 return GNC_PLUGIN_PAGE(plugin_page);
268}
const GList * gnc_gobject_tracking_get_list(const gchar *name)
Get a list of all known objects of a specified type.

◆ gnc_tree_model_budget_get_budget()

GncBudget * gnc_tree_model_budget_get_budget ( GtkTreeModel *  tm,
GtkTreeIter *  iter 
)

Definition at line 108 of file gnc-tree-model-budget.c.

109{
110 GncBudget *bgt;
111 GncGUID *guid;
112
113 gtk_tree_model_get (tm, iter, BUDGET_GUID_COLUMN, &guid, -1);
114 bgt = gnc_budget_lookup(guid, gnc_get_current_book());
115 return bgt;
116}

◆ gnc_tree_model_budget_get_iter_for_budget()

gboolean gnc_tree_model_budget_get_iter_for_budget ( GtkTreeModel *  tm,
GtkTreeIter *  iter,
GncBudget *  bgt 
)

Definition at line 119 of file gnc-tree-model-budget.c.

121{
122 const GncGUID *guid1;
123 GncGUID *guid2;
124
125 g_return_val_if_fail(GNC_BUDGET(bgt), FALSE);
126
127 guid1 = gnc_budget_get_guid(bgt);
128 if (!gtk_tree_model_get_iter_first(tm, iter))
129 return FALSE;
130 while (gtk_list_store_iter_is_valid(GTK_LIST_STORE(tm), iter))
131 {
132 gtk_tree_model_get (tm, iter, BUDGET_GUID_COLUMN, &guid2, -1);
133
134 if (guid_equal(guid1, guid2))
135 return TRUE;
136
137 if (!gtk_tree_model_iter_next(tm, iter))
138 return FALSE;
139 }
140 return FALSE;
141}
gboolean guid_equal(const GncGUID *guid_1, const GncGUID *guid_2)
Given two GUIDs, return TRUE if they are non-NULL and equal.
Definition guid.cpp:237

◆ gnc_tree_model_budget_new()

GtkTreeModel * gnc_tree_model_budget_new ( QofBook book)

Definition at line 70 of file gnc-tree-model-budget.c.

71{
72 GtkListStore* store;
73
74 store = gtk_list_store_new (BUDGET_LIST_NUM_COLS,
75 G_TYPE_POINTER,
76 G_TYPE_STRING,
77 G_TYPE_STRING);
78
79 qof_collection_foreach(qof_book_get_collection(book, GNC_ID_BUDGET),
80 add_budget_to_model, GTK_TREE_MODEL(store));
81
82 return GTK_TREE_MODEL(store);
83}

◆ gnc_tree_view_budget_set_model()

void gnc_tree_view_budget_set_model ( GtkTreeView *  tv,
GtkTreeModel *  tm 
)

Definition at line 86 of file gnc-tree-model-budget.c.

87{
88 GtkCellRenderer *renderer;
89 GtkTreeViewColumn *column;
90
91 gtk_tree_view_set_model (tv, tm);
92
93 /* column for name */
94 renderer = gtk_cell_renderer_text_new ();
95 column = gtk_tree_view_column_new_with_attributes (
96 _("Name"), renderer, "text", BUDGET_NAME_COLUMN, NULL);
97 gtk_tree_view_append_column (tv, column);
98
99 /* column for description */
100 renderer = gtk_cell_renderer_text_new ();
101 column = gtk_tree_view_column_new_with_attributes (
102 _("Description"), renderer, "text", BUDGET_DESCRIPTION_COLUMN, NULL);
103 gtk_tree_view_append_column (tv, column);
104
105}

Variable Documentation

◆ budget [1/2]

GncBudget* GncBudgetViewPrivate::budget

Definition at line 162 of file gnc-budget-view.c.

◆ budget [2/2]

GncBudget* BudgetAccumulationInfo::budget

Definition at line 1013 of file gnc-budget-view.c.

◆ fd

AccountFilterDialog* GncBudgetViewPrivate::fd

Definition at line 169 of file gnc-budget-view.c.

◆ hadj

GtkAdjustment* GncBudgetViewPrivate::hadj

Definition at line 160 of file gnc-budget-view.c.

◆ key

GncGUID GncBudgetViewPrivate::key

Definition at line 163 of file gnc-budget-view.c.

◆ pdb

GNCPriceDB* BudgetAccumulationInfo::pdb

Definition at line 1015 of file gnc-budget-view.c.

◆ period_col_list

GList* GncBudgetViewPrivate::period_col_list

Definition at line 166 of file gnc-budget-view.c.

◆ period_num

guint BudgetAccumulationInfo::period_num

Definition at line 1014 of file gnc-budget-view.c.

◆ rootAcct

Account* GncBudgetViewPrivate::rootAcct

Definition at line 170 of file gnc-budget-view.c.

◆ show_account_code

gboolean GncBudgetViewPrivate::show_account_code

Definition at line 171 of file gnc-budget-view.c.

◆ show_account_desc

gboolean GncBudgetViewPrivate::show_account_desc

Definition at line 172 of file gnc-budget-view.c.

◆ temp_ce

GtkCellEditable* GncBudgetViewPrivate::temp_ce

Definition at line 175 of file gnc-budget-view.c.

◆ temp_cr

GtkCellRenderer* GncBudgetViewPrivate::temp_cr

Definition at line 174 of file gnc-budget-view.c.

◆ total

gnc_numeric BudgetAccumulationInfo::total

Definition at line 1012 of file gnc-budget-view.c.

◆ total_col

GtkTreeViewColumn* GncBudgetViewPrivate::total_col

Definition at line 168 of file gnc-budget-view.c.

◆ total_currency

gnc_commodity* BudgetAccumulationInfo::total_currency

Definition at line 1016 of file gnc-budget-view.c.

◆ totals_col_list

GList* GncBudgetViewPrivate::totals_col_list

Definition at line 167 of file gnc-budget-view.c.

◆ totals_scroll_window

GtkWidget* GncBudgetViewPrivate::totals_scroll_window

Definition at line 159 of file gnc-budget-view.c.

◆ totals_tree_view

GtkTreeView* GncBudgetViewPrivate::totals_tree_view

Definition at line 158 of file gnc-budget-view.c.

◆ tree_view

GtkTreeView* GncBudgetViewPrivate::tree_view

Definition at line 157 of file gnc-budget-view.c.

◆ use_red_color

gboolean GncBudgetViewPrivate::use_red_color

Definition at line 164 of file gnc-budget-view.c.

◆ w [1/2]

GtkBox GncBudgetView::w

Definition at line 89 of file gnc-budget-view.c.

◆ w [2/2]

GtkBoxClass GncBudgetViewClass::w

Definition at line 94 of file gnc-budget-view.c.