27 #include <glib/gi18n.h>
30 #include "gnc-plugin-budget.h"
37 #include "gnc-component-manager.h"
39 #define PLUGIN_ACTIONS_NAME "gnc-plugin-budget-actions"
40 #define PLUGIN_UI_FILENAME "gnc-plugin-budget-ui.xml"
46 static void gnc_plugin_budget_finalize (GObject *
object);
49 static void gnc_plugin_budget_cmd_new_budget (GtkAction *action,
51 static void gnc_plugin_budget_cmd_open_budget (GtkAction *action,
53 static void gnc_plugin_budget_cmd_copy_budget (GtkAction *action,
56 static GtkActionEntry gnc_plugin_actions [] =
59 "NewBudgetAction", NULL, N_(
"New Budget"), NULL,
60 N_(
"Create a new Budget"),
61 G_CALLBACK (gnc_plugin_budget_cmd_new_budget)
65 "OpenBudgetAction", NULL, N_(
"Open Budget"), NULL,
66 N_(
"Open an existing Budget"),
67 G_CALLBACK (gnc_plugin_budget_cmd_open_budget)
71 "CopyBudgetAction", NULL, N_(
"Copy Budget"), NULL,
72 N_(
"Copy an existing Budget"),
73 G_CALLBACK (gnc_plugin_budget_cmd_copy_budget)
76 static guint gnc_plugin_n_actions = G_N_ELEMENTS (gnc_plugin_actions);
83 #define GNC_PLUGIN_BUDGET_GET_PRIVATE(o) \
84 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_PLUGIN_BUDGET, GncPluginBudgetPrivate))
86 static GObjectClass *parent_class = NULL;
89 gnc_plugin_budget_get_type (
void)
91 static GType gnc_plugin_budget_type = 0;
93 if (!gnc_plugin_budget_type)
95 static const GTypeInfo our_info =
100 (GClassInitFunc) gnc_plugin_budget_class_init,
105 (GInstanceInitFunc) gnc_plugin_budget_init
108 gnc_plugin_budget_type = g_type_register_static(
109 GNC_TYPE_PLUGIN,
"GncPluginBudget", &our_info, 0);
112 return gnc_plugin_budget_type;
122 GNC_TYPE_PLUGIN_PAGE_BUDGET;
124 plugin = g_object_new (GNC_TYPE_PLUGIN_BUDGET, NULL);
126 return GNC_PLUGIN (plugin);
132 GObjectClass *object_class = G_OBJECT_CLASS (klass);
136 parent_class = g_type_class_peek_parent (klass);
137 object_class->finalize = gnc_plugin_budget_finalize;
139 plugin_class->
plugin_name = GNC_PLUGIN_BUDGET_NAME;
141 plugin_class->
actions = gnc_plugin_actions;
142 plugin_class->
n_actions = gnc_plugin_n_actions;
155 gnc_plugin_budget_finalize(GObject *
object)
157 g_return_if_fail(GNC_IS_PLUGIN_BUDGET (
object));
160 (parent_class->finalize)(
object);
171 gnc_plugin_budget_cmd_new_budget (GtkAction *action,
177 g_return_if_fail (data != NULL);
186 gnc_plugin_budget_cmd_open_budget (GtkAction *action,
193 g_return_if_fail (data != NULL);
195 book = gnc_get_current_book();
202 bgt = gnc_budget_get_default(book);
206 bgt = gnc_budget_gui_select_budget(book);
214 gnc_plugin_budget_cmd_new_budget(action, data);
220 gnc_plugin_budget_cmd_copy_budget (GtkAction *action,
227 g_return_if_fail (data != NULL);
229 book = gnc_get_current_book();
236 bgt = gnc_budget_get_default(book);
240 bgt = gnc_budget_gui_select_budget(book);
249 name = g_strdup_printf(
"Copy of %s", gnc_budget_get_name(bgt));
259 gnc_plugin_budget_cmd_new_budget(action, data);
268 row_activated_cb(GtkTreeView *tv, GtkTreePath *path, GtkTreeViewColumn *column,
271 gtk_dialog_response(GTK_DIALOG(data), GTK_RESPONSE_OK);
275 gnc_budget_gui_select_budget(
QofBook *book)
281 GtkTreeSelection *sel;
286 dlg = GTK_DIALOG(gtk_dialog_new_with_buttons(
287 _(
"Select a Budget"), NULL, GTK_DIALOG_MODAL,
288 GTK_STOCK_OK, GTK_RESPONSE_OK,
289 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL));
291 tv = GTK_TREE_VIEW(gtk_tree_view_new());
292 sel = gtk_tree_view_get_selection(tv);
293 gtk_tree_selection_set_mode(sel, GTK_SELECTION_BROWSE);
294 g_signal_connect(tv,
"row-activated", G_CALLBACK(row_activated_cb), dlg);
295 tm = gnc_tree_model_budget_new(book);
296 gnc_tree_view_budget_set_model(tv, tm);
298 gtk_container_add(GTK_CONTAINER(dlg->vbox), GTK_WIDGET(tv));
299 gtk_widget_show_all(GTK_WIDGET(dlg));
302 response = gtk_dialog_run(dlg);
305 case GTK_RESPONSE_OK:
306 ok = gtk_tree_selection_get_selected(sel, &tm, &iter);
309 bgt = gnc_tree_model_budget_get_budget(tm, &iter);
316 gtk_widget_destroy(GTK_WIDGET(dlg));
utility functions for the GnuCash UI
GncBudget * gnc_budget_new(QofBook *book)
GncPluginPage * gnc_plugin_page_budget_new(GncBudget *budget)
#define ENTER(format, args...)
const gchar * ui_filename
void gnc_main_window_open_page(GncMainWindow *window, GncPluginPage *page)
GncBudget * gnc_budget_clone(const GncBudget *old_b)
void gnc_budget_set_name(GncBudget *budget, const gchar *name)
const gchar * actions_name
const gchar * plugin_name
#define PLUGIN_ACTIONS_NAME
#define LEAVE(format, args...)
QofCollection * qof_book_get_collection(const QofBook *, QofIdType)
guint qof_collection_count(const QofCollection *col)
provides some utilities for working with the list of budgets in a book.
#define PLUGIN_UI_FILENAME
const gchar * QofLogModule