27 #include <glib/gi18n.h> 30 #include "gnc-plugin-budget.h" 38 #include "gnc-component-manager.h" 40 #define PLUGIN_ACTIONS_NAME "gnc-plugin-budget-actions" 41 #define PLUGIN_UI_FILENAME "gnc-plugin-budget.ui" 43 static QofLogModule log_module = GNC_MOD_GUI;
45 static void gnc_plugin_budget_finalize (GObject *
object);
48 static void gnc_plugin_budget_cmd_new_budget (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
49 static void gnc_plugin_budget_cmd_open_budget (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
50 static void gnc_plugin_budget_cmd_copy_budget (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
51 static void gnc_plugin_budget_cmd_delete_budget (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
53 static GActionEntry gnc_plugin_actions [] =
55 {
"ActionsBudgetAction", NULL, NULL, NULL, NULL },
56 {
"NewBudgetAction", gnc_plugin_budget_cmd_new_budget, NULL, NULL, NULL },
57 {
"OpenBudgetAction", gnc_plugin_budget_cmd_open_budget, NULL, NULL, NULL },
58 {
"CopyBudgetAction", gnc_plugin_budget_cmd_copy_budget, NULL, NULL, NULL },
59 {
"DeleteBudgetAction", gnc_plugin_budget_cmd_delete_budget, NULL, NULL, NULL },
63 static guint gnc_plugin_n_actions = G_N_ELEMENTS(gnc_plugin_actions);
66 static const gchar *gnc_plugin_load_ui_items [] =
68 "ActionsPlaceholder3",
72 static const gchar *plugin_writeable_actions[] =
87 gnc_plugin_budget_new (
void)
89 GncPluginBudget *plugin;
94 GNC_TYPE_PLUGIN_PAGE_BUDGET;
96 plugin = g_object_new (GNC_TYPE_PLUGIN_BUDGET, NULL);
98 return GNC_PLUGIN(plugin);
102 page_changed (GncMainWindow *window,
GncPluginPage *page, gpointer user_data)
104 GSimpleActionGroup *simple_action_group =
113 add_to_window (GncPlugin *plugin, GncMainWindow *mainwindow, GQuark type)
115 g_signal_connect (mainwindow,
"page_changed", G_CALLBACK (page_changed), plugin);
119 remove_from_window (GncPlugin *plugin, GncMainWindow *window, GQuark type)
121 g_signal_handlers_disconnect_by_func (window, G_CALLBACK(page_changed), plugin);
124 G_DEFINE_TYPE(GncPluginBudget, gnc_plugin_budget, GNC_TYPE_PLUGIN)
127 gnc_plugin_budget_class_init (GncPluginBudgetClass *klass)
129 GObjectClass *object_class = G_OBJECT_CLASS(klass);
130 GncPluginClass *plugin_class = GNC_PLUGIN_CLASS(klass);
133 object_class->finalize = gnc_plugin_budget_finalize;
135 plugin_class->plugin_name = GNC_PLUGIN_BUDGET_NAME;
137 plugin_class->actions = gnc_plugin_actions;
138 plugin_class->n_actions = gnc_plugin_n_actions;
140 plugin_class->ui_updates = gnc_plugin_load_ui_items;
141 plugin_class->add_to_window = add_to_window;
142 plugin_class->remove_from_window = remove_from_window;
148 gnc_plugin_budget_init (GncPluginBudget *plugin)
153 gnc_plugin_budget_finalize (GObject *
object)
155 g_return_if_fail (GNC_IS_PLUGIN_BUDGET(
object));
158 G_OBJECT_CLASS (gnc_plugin_budget_parent_class)->finalize(
object);
169 gnc_plugin_budget_cmd_new_budget (GSimpleAction *simple,
176 gchar *description, *date;
177 QofBook *book = gnc_get_current_book();
179 g_return_if_fail (data != NULL);
181 if (!gnc_features_check_used (book, GNC_FEATURE_BUDGET_UNREVERSED))
184 PWARN (
"Setting feature BUDGET_UNREVERSED. This book now requires \ 185 GnuCash 3.8 or later.");
192 description = g_strdup_printf (
"%s: %s", _(
"Created"), date);
194 g_free (description);
202 gnc_plugin_budget_cmd_open_budget (GSimpleAction *simple,
209 GncBudget *bgt = NULL;
212 g_return_if_fail (data != NULL);
214 book = gnc_get_current_book ();
220 bgt = gnc_budget_get_default (book);
222 bgt = gnc_budget_gui_select_budget (GTK_WINDOW(data->window), book);
229 gnc_plugin_budget_cmd_new_budget (simple, parameter, user_data);
234 gnc_plugin_budget_cmd_copy_budget (GSimpleAction *simple,
241 GncBudget *bgt = NULL;
244 g_return_if_fail (data != NULL);
246 book = gnc_get_current_book ();
252 bgt = gnc_budget_get_default(book);
254 bgt = gnc_budget_gui_select_budget (GTK_WINDOW(data->window), book);
262 name = g_strdup_printf (
"Copy of %s", gnc_budget_get_name (bgt));
271 gnc_plugin_budget_cmd_new_budget (simple, parameter, user_data);
276 gnc_plugin_budget_cmd_delete_budget (GSimpleAction *simple,
284 g_return_if_fail (data != NULL);
286 book = gnc_get_current_book ();
290 bgt = gnc_budget_gui_select_budget (GTK_WINDOW(data->window), book);
293 gnc_budget_gui_delete_budget (bgt);
301 row_activated_cb (GtkTreeView *tv, GtkTreePath *path,
302 GtkTreeViewColumn *column, gpointer user_data)
304 gtk_dialog_response (GTK_DIALOG(user_data), GTK_RESPONSE_OK);
308 gnc_budget_gui_select_budget (GtkWindow *parent, QofBook *book)
314 GtkTreeSelection *sel;
319 dlg = GTK_DIALOG(gtk_dialog_new_with_buttons (
320 _(
"Select a Budget"), parent, GTK_DIALOG_MODAL,
321 _(
"_Cancel"), GTK_RESPONSE_CANCEL,
322 _(
"_OK"), GTK_RESPONSE_OK, NULL));
324 tv = GTK_TREE_VIEW(gtk_tree_view_new ());
325 sel = gtk_tree_view_get_selection (tv);
326 gtk_tree_selection_set_mode (sel, GTK_SELECTION_BROWSE);
327 g_signal_connect (tv,
"row-activated", G_CALLBACK(row_activated_cb), dlg);
328 tm = gnc_tree_model_budget_new (book);
329 gnc_tree_view_budget_set_model (tv, tm);
331 gtk_container_add (GTK_CONTAINER(gtk_dialog_get_content_area (dlg)), GTK_WIDGET(tv));
332 gtk_widget_show_all (GTK_WIDGET(dlg));
335 bgt = gnc_budget_get_default (book);
337 if (bgt && gnc_tree_model_budget_get_iter_for_budget (tm, &iter, bgt))
339 GtkTreePath *path = gtk_tree_model_get_path (tm, &iter);
340 gtk_tree_view_set_cursor (tv, path, NULL, FALSE);
341 gtk_tree_path_free (path);
345 response = gtk_dialog_run (dlg);
348 case GTK_RESPONSE_OK:
349 ok = gtk_tree_selection_get_selected (sel, &tm, &iter);
351 bgt = gnc_tree_model_budget_get_budget (tm, &iter);
357 gtk_widget_destroy (GTK_WIDGET(dlg));
The instance data structure for a content plugin.
utility functions for the GnuCash UI
GncBudget * gnc_budget_new(QofBook *book)
Creates and initializes a Budget.
void gnc_features_set_used(QofBook *book, const gchar *feature)
Indicate that the current book uses the given feature.
GncPluginPage * gnc_plugin_page_budget_new(GncBudget *budget)
Create a new "budget" plugin page.
#define ENTER(format, args...)
Print a function entry debugging message.
void gnc_main_window_open_page(GncMainWindow *window, GncPluginPage *page)
Display a data plugin page in a window.
#define PWARN(format, args...)
Log a warning.
GncBudget * gnc_budget_clone(const GncBudget *old_b)
Clones a budget creating a copy.
char * gnc_print_time64(time64 time, const char *format)
print a time64 as a date string per format
void gnc_budget_set_name(GncBudget *budget, const gchar *name)
Set/Get the name of the Budget.
gboolean qof_book_is_readonly(const QofBook *book)
Return whether the book is read only.
void gnc_budget_set_description(GncBudget *budget, const gchar *description)
Set/Get the description of the Budget.
#define PLUGIN_ACTIONS_NAME
The label given to the main window for this plugin.
#define LEAVE(format, args...)
Print a function exit debugging message.
time64 gnc_time(time64 *tbuf)
get the current time
GSimpleActionGroup * gnc_main_window_get_action_group(GncMainWindow *window, const gchar *group_name)
Retrieve a specific set of user interface actions from a window.
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
guint qof_collection_count(const QofCollection *col)
return the number of entities in the collection.
Take from locale information.
const gchar * qof_date_format_get_string(QofDateFormat df)
This function returns a strftime formatting string for printing an all numeric date (e...
provides some utilities for working with the list of budgets in a book.
#define PLUGIN_UI_FILENAME
The name of the UI description file for this plugin.
Utility functions for file access.