GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gnc-plugin-page-invoice.c
1 /*
2  * gnc-plugin-page-invoice.c --
3  *
4  * Copyright (C) 2005,2006 David Hampton <[email protected]>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, contact:
18  *
19  * Free Software Foundation Voice: +1-617-542-5942
20  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
21  * Boston, MA 02110-1301, USA [email protected]
22  */
23 
24 #include "config.h"
25 
26 #include <gtk/gtk.h>
27 #include <glib/gi18n.h>
28 
29 #include "gnc-plugin.h"
30 #include "business-gnome-utils.h"
31 #include "dialog-invoice.h"
32 #include "gnc-ledger-display.h"
34 
35 #include "dialog-account.h"
36 #include "gnc-component-manager.h"
37 #include "gnc-gobject-utils.h"
38 #include "gnc-gnome-utils.h"
39 #include "gnc-icons.h"
40 #include "gnucash-sheet.h"
41 #include "gnc-prefs.h"
42 #include "gnc-ui-util.h"
43 #include "gnc-window.h"
44 
45 /* This static indicates the debugging module that this .o belongs to. */
46 static QofLogModule log_module = GNC_MOD_GUI;
47 
48 static void gnc_plugin_page_invoice_class_init (GncPluginPageInvoiceClass *klass);
49 static void gnc_plugin_page_invoice_init (GncPluginPageInvoice *plugin_page);
50 static void gnc_plugin_page_invoice_finalize (GObject *object);
51 
52 static GtkWidget *gnc_plugin_page_invoice_create_widget (GncPluginPage *plugin_page);
53 static void gnc_plugin_page_invoice_destroy_widget (GncPluginPage *plugin_page);
54 static void gnc_plugin_page_invoice_save_page (GncPluginPage *plugin_page, GKeyFile *file, const gchar *group);
55 static GncPluginPage *gnc_plugin_page_invoice_recreate_page (GtkWidget *window, GKeyFile *file, const gchar *group);
56 static void gnc_plugin_page_invoice_window_changed (GncPluginPage *plugin_page, GtkWidget *window);
57 
58 static void gnc_plugin_page_invoice_summarybar_position_changed(gpointer prefs, gchar* pref, gpointer user_data);
59 
60 /* Command callbacks */
61 static void gnc_plugin_page_invoice_cmd_new_invoice (GtkAction *action, GncPluginPageInvoice *plugin_page);
62 static void gnc_plugin_page_invoice_cmd_new_account (GtkAction *action, GncPluginPageInvoice *plugin_page);
63 static void gnc_plugin_page_invoice_cmd_print (GtkAction *action, GncPluginPageInvoice *plugin_page);
64 static void gnc_plugin_page_invoice_cmd_cut (GtkAction *action, GncPluginPageInvoice *plugin_page);
65 static void gnc_plugin_page_invoice_cmd_copy (GtkAction *action, GncPluginPageInvoice *plugin_page);
66 static void gnc_plugin_page_invoice_cmd_paste (GtkAction *action, GncPluginPageInvoice *plugin_page);
67 static void gnc_plugin_page_invoice_cmd_edit (GtkAction *action, GncPluginPageInvoice *plugin_page);
68 static void gnc_plugin_page_invoice_cmd_duplicateInvoice (GtkAction *action, GncPluginPageInvoice *plugin_page);
69 static void gnc_plugin_page_invoice_cmd_post (GtkAction *action, GncPluginPageInvoice *plugin_page);
70 static void gnc_plugin_page_invoice_cmd_unpost (GtkAction *action, GncPluginPageInvoice *plugin_page);
71 
72 static void gnc_plugin_page_invoice_cmd_sort_changed (GtkAction *action,
73  GtkRadioAction *current,
74  GncPluginPageInvoice *plugin_page);
75 
76 static void gnc_plugin_page_invoice_cmd_enter (GtkAction *action, GncPluginPageInvoice *plugin_page);
77 static void gnc_plugin_page_invoice_cmd_cancel (GtkAction *action, GncPluginPageInvoice *plugin_page);
78 static void gnc_plugin_page_invoice_cmd_delete (GtkAction *action, GncPluginPageInvoice *plugin_page);
79 static void gnc_plugin_page_invoice_cmd_blank (GtkAction *action, GncPluginPageInvoice *plugin_page);
80 static void gnc_plugin_page_invoice_cmd_duplicateEntry (GtkAction *action, GncPluginPageInvoice *plugin_page);
81 static void gnc_plugin_page_invoice_cmd_pay_invoice (GtkAction *action, GncPluginPageInvoice *plugin_page);
82 static void gnc_plugin_page_invoice_cmd_company_report (GtkAction *action, GncPluginPageInvoice *plugin_page);
83 
84 static void gnc_plugin_page_redraw_help_cb( GnucashRegister *gsr, GncPluginPageInvoice *invoice_page );
85 static void gnc_plugin_page_invoice_refresh_cb (GHashTable *changes, gpointer user_data);
86 
87 static void gnc_plugin_page_invoice_cmd_entryUp (GtkAction *action, GncPluginPageInvoice *plugin_page);
88 static void gnc_plugin_page_invoice_cmd_entryDown (GtkAction *action, GncPluginPageInvoice *plugin_page);
89 
90 /************************************************************
91  * Actions *
92  ************************************************************/
93 // FIXME: The texts are wrong if we have a Bill or Expence Voucher.
94 static GtkActionEntry gnc_plugin_page_invoice_actions [] =
95 {
96  /* Toplevel */
97  { "FakeToplevel", NULL, "", NULL, NULL, NULL },
98  { "SortOrderAction", NULL, N_("Sort _Order"), NULL, NULL, NULL },
99 
100  /* File menu */
101  {
102  "FileNewAccountAction", GNC_STOCK_NEW_ACCOUNT, N_("New _Account..."), NULL,
103  N_("Create a new account"),
104  G_CALLBACK (gnc_plugin_page_invoice_cmd_new_account)
105  },
106  {
107  "FilePrintAction", GTK_STOCK_PRINT, N_("Print Invoice"), "<control>p",
108  N_("Make a printable invoice"),
109  G_CALLBACK (gnc_plugin_page_invoice_cmd_print)
110  },
111 
112  /* Edit menu */
113  {
114  "EditCutAction", GTK_STOCK_CUT, N_("_Cut"), NULL,
115  NULL,
116  G_CALLBACK (gnc_plugin_page_invoice_cmd_cut)
117  },
118  {
119  "EditCopyAction", GTK_STOCK_COPY, N_("Copy"), NULL,
120  NULL,
121  G_CALLBACK (gnc_plugin_page_invoice_cmd_copy)
122  },
123  {
124  "EditPasteAction", GTK_STOCK_PASTE, N_("_Paste"), NULL,
125  NULL,
126  G_CALLBACK (gnc_plugin_page_invoice_cmd_paste)
127  },
128  {
129  "EditEditInvoiceAction", GNC_STOCK_INVOICE_EDIT, N_("_Edit Invoice"), NULL,
130  N_("Edit this invoice"),
131  G_CALLBACK (gnc_plugin_page_invoice_cmd_edit)
132  },
133  {
134  "EditDuplicateInvoiceAction", GNC_STOCK_INVOICE_DUPLICATE, N_("_Duplicate Invoice"),
135  NULL, N_("Create a new invoice as a duplicate of the current one"),
136  G_CALLBACK (gnc_plugin_page_invoice_cmd_duplicateInvoice)
137  },
138  {
139  "EditPostInvoiceAction", GNC_STOCK_INVOICE_POST, N_("_Post Invoice"), NULL,
140  N_("Post this Invoice to your Chart of Accounts"),
141  G_CALLBACK (gnc_plugin_page_invoice_cmd_post)
142  },
143  {
144  "EditUnpostInvoiceAction", GNC_STOCK_INVOICE_UNPOST, N_("_Unpost Invoice"), NULL,
145  N_("Unpost this Invoice and make it editable"),
146  G_CALLBACK (gnc_plugin_page_invoice_cmd_unpost)
147  },
148 
149  /* Actions menu */
150  {
151  "RecordEntryAction", GTK_STOCK_ADD, N_("_Enter"), NULL,
152  N_("Record the current entry"),
153  G_CALLBACK (gnc_plugin_page_invoice_cmd_enter)
154  },
155  {
156  "CancelEntryAction", GTK_STOCK_CANCEL, N_("_Cancel"), NULL,
157  N_("Cancel the current entry"),
158  G_CALLBACK (gnc_plugin_page_invoice_cmd_cancel)
159  },
160  {
161  "DeleteEntryAction", GTK_STOCK_DELETE, N_("_Delete"), NULL,
162  N_("Delete the current entry"),
163  G_CALLBACK (gnc_plugin_page_invoice_cmd_delete)
164  },
165  {
166  "BlankEntryAction", GTK_STOCK_GOTO_BOTTOM, N_("_Blank"), NULL,
167  N_("Move to the blank entry at the bottom of the Invoice"),
168  G_CALLBACK (gnc_plugin_page_invoice_cmd_blank)
169  },
170  {
171  "DuplicateEntryAction", GTK_STOCK_COPY, N_("Dup_licate Entry"), NULL,
172  N_("Make a copy of the current entry"),
173  G_CALLBACK (gnc_plugin_page_invoice_cmd_duplicateEntry)
174  },
175  {
176  "EntryUpAction", GTK_STOCK_GO_UP, N_("Move Entry _Up"), NULL,
177  N_("Move the current entry one row upwards"),
178  G_CALLBACK (gnc_plugin_page_invoice_cmd_entryUp)
179  },
180  {
181  "EntryDownAction", GTK_STOCK_GO_DOWN, N_("Move Entry Do_wn"), NULL,
182  N_("Move the current entry one row downwards"),
183  G_CALLBACK (gnc_plugin_page_invoice_cmd_entryDown)
184  },
185 
186  /* Business menu */
187  {
188  "BusinessNewInvoiceAction", GNC_STOCK_INVOICE_NEW, N_("New _Invoice"), "",
189  N_("Create a new invoice for the same owner as the current one"),
190  G_CALLBACK (gnc_plugin_page_invoice_cmd_new_invoice)
191  },
192  {
193  "ToolsProcessPaymentAction", GNC_STOCK_INVOICE_PAY, N_("_Pay Invoice"), NULL,
194  N_("Enter a payment for the owner of this Invoice"),
195  G_CALLBACK (gnc_plugin_page_invoice_cmd_pay_invoice)
196  },
197 
198  /* Reports menu */
199  {
200  "ReportsCompanyReportAction", NULL, N_("_Company Report"), NULL,
201  N_("Open a company report window for the owner of this Invoice"),
202  G_CALLBACK (gnc_plugin_page_invoice_cmd_company_report)
203  },
204 };
205 static guint gnc_plugin_page_invoice_n_actions = G_N_ELEMENTS (gnc_plugin_page_invoice_actions);
206 
207 static GtkRadioActionEntry radio_entries [] =
208 {
209  { "SortStandardAction", NULL, N_("_Standard"), NULL, N_("Keep normal invoice order"), INVSORT_BY_STANDARD },
210  { "SortDateAction", NULL, N_("_Date"), NULL, N_("Sort by date"), INVSORT_BY_DATE },
211  { "SortDateEntryAction", NULL, N_("Date of _Entry"), NULL, N_("Sort by the date of entry"), INVSORT_BY_DATE_ENTERED },
212  { "SortQuantityAction", NULL, N_("_Quantity"), NULL, N_("Sort by quantity"), INVSORT_BY_QTY },
213  { "SortPriceAction", NULL, N_("_Price"), NULL, N_("Sort by price"), INVSORT_BY_PRICE },
214  { "SortDescriptionAction", NULL, N_("Descri_ption"), NULL, N_("Sort by description"), INVSORT_BY_DESC },
215 };
216 static guint n_radio_entries = G_N_ELEMENTS (radio_entries);
217 
218 static const gchar *invoice_book_readwrite_actions[] =
219 {
220  // Only insert actions here which are not yet in posted_actions and unposted_actions!
221  "FileNewAccountAction",
222  "EditDuplicateInvoiceAction",
223  "BusinessNewInvoiceAction",
224  "ToolsProcessPaymentAction",
225  NULL
226 };
227 
228 static const gchar *posted_actions[] =
229 {
230  NULL
231 };
232 
233 static const gchar *unposted_actions[] =
234 {
235  "EditCutAction",
236  "EditPasteAction",
237  "EditEditInvoiceAction",
238  "EditPostInvoiceAction",
239  "RecordEntryAction",
240  "CancelEntryAction",
241  "DeleteEntryAction",
242  "DuplicateEntryAction",
243  "EntryUpAction",
244  "EntryDownAction",
245  "BlankEntryAction",
246  NULL
247 };
248 
249 static const gchar *can_unpost_actions[] =
250 {
251  "EditUnpostInvoiceAction",
252  NULL
253 };
254 
256 static action_toolbar_labels toolbar_labels[] =
257 {
258  { "RecordEntryAction", N_("Enter") },
259  { "CancelEntryAction", N_("Cancel") },
260  { "DeleteEntryAction", N_("Delete") },
261  { "DuplicateEntryAction", N_("Duplicate") },
262  { "EntryUpAction", N_("Up") },
263  { "EntryDownAction", N_("Down") },
264  { "BlankEntryAction", N_("Blank") },
265  { "EditPostInvoiceAction", N_("Post") },
266  { "EditUnpostInvoiceAction", N_("Unpost") },
267  { NULL, NULL },
268 };
269 
270 
271 /************************************************************/
272 /* Data Structures */
273 /************************************************************/
274 
276 {
277  InvoiceWindow *iw;
278 
279  GtkWidget *widget;
280 
281  gint component_manager_id;
283 
284 #define GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(o) \
285  (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_PLUGIN_PAGE_INVOICE, GncPluginPageInvoicePrivate))
286 
287 static GObjectClass *parent_class = NULL;
288 
289 /************************************************************/
290 /* Implementation */
291 /************************************************************/
292 
293 GType
295 {
296  static GType gnc_plugin_page_invoice_type = 0;
297 
298  if (gnc_plugin_page_invoice_type == 0)
299  {
300  static const GTypeInfo our_info =
301  {
302  sizeof (GncPluginPageInvoiceClass),
303  NULL,
304  NULL,
305  (GClassInitFunc) gnc_plugin_page_invoice_class_init,
306  NULL,
307  NULL,
308  sizeof (GncPluginPageInvoice),
309  0,
310  (GInstanceInitFunc) gnc_plugin_page_invoice_init
311  };
312 
313  gnc_plugin_page_invoice_type = g_type_register_static (GNC_TYPE_PLUGIN_PAGE,
314  "GncPluginPageInvoice",
315  &our_info, 0);
316  }
317 
318  return gnc_plugin_page_invoice_type;
319 }
320 
323 {
325  GncPluginPageInvoice *invoice_page;
326  GncPluginPage *plugin_page;
327  const GList *item;
328 
329  /* Is there an existing page? */
330  item = gnc_gobject_tracking_get_list(GNC_PLUGIN_PAGE_INVOICE_NAME);
331  for ( ; item; item = g_list_next(item))
332  {
333  invoice_page = (GncPluginPageInvoice *)item->data;
334  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(invoice_page);
335  if (priv->iw == iw)
336  return GNC_PLUGIN_PAGE(invoice_page);
337  }
338 
339  invoice_page = g_object_new (GNC_TYPE_PLUGIN_PAGE_INVOICE, (char *)NULL);
340  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(invoice_page);
341  priv->iw = iw;
342 
343  plugin_page = GNC_PLUGIN_PAGE(invoice_page);
345  gnc_plugin_page_set_uri(plugin_page, "default:");
346 
347  priv->component_manager_id = 0;
348  return plugin_page;
349 }
350 
351 static void
352 gnc_plugin_page_invoice_class_init (GncPluginPageInvoiceClass *klass)
353 {
354  GObjectClass *object_class = G_OBJECT_CLASS (klass);
355  GncPluginPageClass *gnc_plugin_class = GNC_PLUGIN_PAGE_CLASS(klass);
356 
357  parent_class = g_type_class_peek_parent (klass);
358 
359  object_class->finalize = gnc_plugin_page_invoice_finalize;
360 
361  gnc_plugin_class->tab_icon = NULL;
362  gnc_plugin_class->plugin_name = GNC_PLUGIN_PAGE_INVOICE_NAME;
363  gnc_plugin_class->create_widget = gnc_plugin_page_invoice_create_widget;
364  gnc_plugin_class->destroy_widget = gnc_plugin_page_invoice_destroy_widget;
365  gnc_plugin_class->save_page = gnc_plugin_page_invoice_save_page;
366  gnc_plugin_class->recreate_page = gnc_plugin_page_invoice_recreate_page;
367  gnc_plugin_class->window_changed = gnc_plugin_page_invoice_window_changed;
368 
369  g_type_class_add_private(klass, sizeof(GncPluginPageInvoicePrivate));
370 }
371 
372 static void
373 gnc_plugin_page_invoice_init (GncPluginPageInvoice *plugin_page)
374 {
375  GncPluginPage *parent;
376  GtkActionGroup *action_group;
377  gboolean use_new;
378 
379  /* Init parent declared variables */
380  parent = GNC_PLUGIN_PAGE(plugin_page);
381  use_new = gnc_prefs_get_bool (GNC_PREFS_GROUP_INVOICE, GNC_PREF_USE_NEW);
382  g_object_set(G_OBJECT(plugin_page),
383  "page-name", _("Invoice"),
384  "page-uri", "default:",
385  "ui-description", "gnc-plugin-page-invoice-ui.xml",
386  "use-new-window", use_new,
387  (char *)NULL);
388 
389  /* change me when the system supports multiple books */
390  gnc_plugin_page_add_book(parent, gnc_get_current_book());
391 
392  /* Create menu and toolbar information */
393  action_group =
395  "GncPluginPageInvoiceActions");
396  gtk_action_group_add_actions (action_group, gnc_plugin_page_invoice_actions,
397  gnc_plugin_page_invoice_n_actions, plugin_page);
398  gtk_action_group_add_radio_actions (action_group,
399  radio_entries, n_radio_entries,
400  REG_STYLE_LEDGER,
401  G_CALLBACK(gnc_plugin_page_invoice_cmd_sort_changed),
402  plugin_page);
403 
404  gnc_plugin_init_short_names (action_group, toolbar_labels);
405 }
406 
407 static void
408 gnc_plugin_page_invoice_finalize (GObject *object)
409 {
410  g_return_if_fail (GNC_IS_PLUGIN_PAGE_INVOICE (object));
411 
412  ENTER("object %p", object);
413  G_OBJECT_CLASS (parent_class)->finalize (object);
414  LEAVE(" ");
415 }
416 
417 
418 void
419 gnc_plugin_page_invoice_update_menus (GncPluginPage *page, gboolean is_posted, gboolean can_unpost)
420 {
421  GtkActionGroup *action_group;
422  gboolean is_readonly = qof_book_is_readonly(gnc_get_current_book());
423 
424  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(page));
425 
426  if (is_readonly)
427  {
428  // Are we readonly? Then don't allow any actions.
429  is_posted = TRUE;
430  can_unpost = FALSE;
431  }
432 
433  action_group = gnc_plugin_page_get_action_group(page);
434  gnc_plugin_update_actions (action_group, posted_actions,
435  "sensitive", is_posted);
436  gnc_plugin_update_actions (action_group, unposted_actions,
437  "sensitive", !is_posted);
438  gnc_plugin_update_actions (action_group, can_unpost_actions,
439  "sensitive", can_unpost);
440  gnc_plugin_update_actions (action_group, invoice_book_readwrite_actions,
441  "sensitive", !is_readonly);
442 }
443 
444 
445 /* Virtual Functions */
446 
447 static GtkWidget *
448 gnc_plugin_page_invoice_create_widget (GncPluginPage *plugin_page)
449 {
450  GncPluginPageInvoice *page;
452  GtkWidget *regWidget, *widget;
453 
454  ENTER("page %p", plugin_page);
455  page = GNC_PLUGIN_PAGE_INVOICE (plugin_page);
456  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(page);
457  if (priv->widget != NULL)
458  {
459  LEAVE("");
460  return priv->widget;
461  }
462 
463  priv->widget = gtk_vbox_new (FALSE, 0);
464  gtk_widget_show (priv->widget);
465 
466  widget = gnc_invoice_create_page(priv->iw, page);
467  gtk_widget_show (widget);
468  gtk_box_pack_start(GTK_BOX (priv->widget), widget, TRUE, TRUE, 0);
469 
470  plugin_page->summarybar = gnc_invoice_window_create_summary_bar(priv->iw);
471  gtk_box_pack_start(GTK_BOX (priv->widget), plugin_page->summarybar, FALSE, FALSE, 0);
472  gnc_plugin_page_invoice_summarybar_position_changed(NULL, NULL, page);
473  gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL,
474  GNC_PREF_SUMMARYBAR_POSITION_TOP,
475  gnc_plugin_page_invoice_summarybar_position_changed,
476  page);
477  gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL,
478  GNC_PREF_SUMMARYBAR_POSITION_BOTTOM,
479  gnc_plugin_page_invoice_summarybar_position_changed,
480  page);
481 
482  regWidget = gnc_invoice_get_register(priv->iw);
483  if (regWidget)
484  {
485  g_signal_connect (G_OBJECT (regWidget), "redraw-help",
486  G_CALLBACK (gnc_plugin_page_redraw_help_cb), page);
487  }
488 
489  priv->component_manager_id =
490  gnc_register_gui_component(GNC_PLUGIN_PAGE_INVOICE_NAME,
491  gnc_plugin_page_invoice_refresh_cb,
492  NULL, page);
493 
494  LEAVE("");
495  return priv->widget;
496 }
497 
498 static void
499 gnc_plugin_page_invoice_destroy_widget (GncPluginPage *plugin_page)
500 {
501  GncPluginPageInvoice *page;
503 
504  ENTER("page %p", plugin_page);
505  page = GNC_PLUGIN_PAGE_INVOICE (plugin_page);
506  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(page);
507 
508  gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL,
509  GNC_PREF_SUMMARYBAR_POSITION_TOP,
510  gnc_plugin_page_invoice_summarybar_position_changed,
511  page);
512  gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL,
513  GNC_PREF_SUMMARYBAR_POSITION_BOTTOM,
514  gnc_plugin_page_invoice_summarybar_position_changed,
515  page);
516 
517  if (priv->widget == NULL)
518  {
519  LEAVE("");
520  return;
521  }
522 
523  if (priv->component_manager_id)
524  {
525  gnc_unregister_gui_component(priv->component_manager_id);
526  priv->component_manager_id = 0;
527  }
528 
529  gtk_widget_hide(priv->widget);
530  gnc_invoice_window_destroy_cb(priv->widget, priv->iw);
531  priv->widget = NULL;
532  LEAVE("");
533 }
534 
544 static void
545 gnc_plugin_page_invoice_save_page (GncPluginPage *plugin_page,
546  GKeyFile *key_file,
547  const gchar *group_name)
548 {
549  GncPluginPageInvoice *invoice;
551 
552  g_return_if_fail (GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
553  g_return_if_fail (key_file != NULL);
554  g_return_if_fail (group_name != NULL);
555 
556  ENTER("page %p, key_file %p, group_name %s", plugin_page, key_file,
557  group_name);
558 
559  invoice = GNC_PLUGIN_PAGE_INVOICE(plugin_page);
560  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(invoice);
561 
562  gnc_invoice_save_page(priv->iw, key_file, group_name);
563  LEAVE(" ");
564 }
565 
566 
567 
577 static GncPluginPage *
578 gnc_plugin_page_invoice_recreate_page (GtkWidget *window,
579  GKeyFile *key_file,
580  const gchar *group_name)
581 {
582  GncPluginPage *page;
583 
584  g_return_val_if_fail(GNC_IS_MAIN_WINDOW(window), NULL);
585  g_return_val_if_fail(key_file, NULL);
586  g_return_val_if_fail(group_name, NULL);
587  ENTER("key_file %p, group_name %s", key_file, group_name);
588 
589  /* Create the new page. */
590  page = gnc_invoice_recreate_page(GNC_MAIN_WINDOW(window),
591  key_file, group_name);
592 
593  LEAVE(" ");
594  return page;
595 }
596 
597 
598 static void
599 gnc_plugin_page_invoice_window_changed (GncPluginPage *plugin_page,
600  GtkWidget *window)
601 {
602  GncPluginPageInvoice *page;
604 
605  g_return_if_fail (GNC_IS_PLUGIN_PAGE_INVOICE (plugin_page));
606 
607  page = GNC_PLUGIN_PAGE_INVOICE(plugin_page);
608  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(page);
609  gnc_invoice_window_changed (priv->iw, window);
610 }
611 
612 
613 static void
614 gnc_plugin_page_invoice_summarybar_position_changed(gpointer prefs, gchar *pref, gpointer user_data)
615 {
616  GncPluginPage *plugin_page;
617  GncPluginPageInvoice *page;
619  GtkPositionType position = GTK_POS_BOTTOM;
620 
621  g_return_if_fail(user_data != NULL);
622 
623  plugin_page = GNC_PLUGIN_PAGE(user_data);
624  page = GNC_PLUGIN_PAGE_INVOICE (user_data);
625  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(page);
626 
627  if (gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_SUMMARYBAR_POSITION_TOP))
628  position = GTK_POS_TOP;
629 
630  gtk_box_reorder_child(GTK_BOX(priv->widget),
631  plugin_page->summarybar,
632  (position == GTK_POS_TOP ? 0 : -1) );
633 }
634 
635 
636 /************************************************************/
637 /* Command callbacks */
638 /************************************************************/
639 
640 static void
641 gnc_plugin_page_invoice_cmd_new_invoice (GtkAction *action,
642  GncPluginPageInvoice *plugin_page)
643 {
645 
646  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
647 
648  ENTER("(action %p, plugin_page %p)", action, plugin_page);
649  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(plugin_page);
650  gnc_invoice_window_new_invoice_cb(NULL, priv->iw);
651  LEAVE(" ");
652 }
653 
654 static void
655 gnc_plugin_page_invoice_cmd_new_account (GtkAction *action,
656  GncPluginPageInvoice *plugin_page)
657 {
658  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
659 
660  ENTER("(action %p, plugin_page %p)", action, plugin_page);
661  gnc_ui_new_account_window (gnc_get_current_book(), NULL);
662  LEAVE(" ");
663 }
664 
665 static void
666 gnc_plugin_page_invoice_cmd_print (GtkAction *action,
667  GncPluginPageInvoice *plugin_page)
668 {
670 
671  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
672 
673  ENTER("(action %p, plugin_page %p)", action, plugin_page);
674  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(plugin_page);
675  gnc_invoice_window_printCB(NULL, priv->iw);
676  LEAVE(" ");
677 }
678 
679 static void
680 gnc_plugin_page_invoice_cmd_cut (GtkAction *action,
681  GncPluginPageInvoice *plugin_page)
682 {
684 
685  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
686 
687  ENTER("(action %p, plugin_page %p)", action, plugin_page);
688  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(plugin_page);
689  gnc_invoice_window_cut_cb(NULL, priv->iw);
690  LEAVE(" ");
691 }
692 
693 static void
694 gnc_plugin_page_invoice_cmd_copy (GtkAction *action,
695  GncPluginPageInvoice *plugin_page)
696 {
698 
699  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
700 
701  ENTER("(action %p, plugin_page %p)", action, plugin_page);
702  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(plugin_page);
703  gnc_invoice_window_copy_cb(NULL, priv->iw);
704  LEAVE(" ");
705 }
706 
707 static void
708 gnc_plugin_page_invoice_cmd_paste (GtkAction *action,
709  GncPluginPageInvoice *plugin_page)
710 {
712 
713  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
714 
715  ENTER("(action %p, plugin_page %p)", action, plugin_page);
716  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(plugin_page);
717  gnc_invoice_window_paste_cb(NULL, priv->iw);
718  LEAVE(" ");
719 }
720 
721 static void
722 gnc_plugin_page_invoice_cmd_edit (GtkAction *action,
723  GncPluginPageInvoice *plugin_page)
724 {
726 
727  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
728 
729  ENTER("(action %p, plugin_page %p)", action, plugin_page);
730  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(plugin_page);
731  gnc_invoice_window_editCB(NULL, priv->iw);
732  LEAVE(" ");
733 }
734 
735 static void
736 gnc_plugin_page_invoice_cmd_duplicateInvoice (GtkAction *action,
737  GncPluginPageInvoice *plugin_page)
738 {
740 
741  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
742 
743  ENTER("(action %p, plugin_page %p)", action, plugin_page);
744  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(plugin_page);
745  gnc_invoice_window_duplicateInvoiceCB(NULL, priv->iw);
746  LEAVE(" ");
747 }
748 
749 static void
750 gnc_plugin_page_invoice_cmd_post (GtkAction *action,
751  GncPluginPageInvoice *plugin_page)
752 {
754 
755  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
756 
757  ENTER("(action %p, plugin_page %p)", action, plugin_page);
758  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(plugin_page);
759  gnc_invoice_window_postCB(NULL, priv->iw);
760  LEAVE(" ");
761 }
762 
763 static void
764 gnc_plugin_page_invoice_cmd_unpost (GtkAction *action,
765  GncPluginPageInvoice *plugin_page)
766 {
768 
769  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
770 
771  ENTER("(action %p, plugin_page %p)", action, plugin_page);
772  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(plugin_page);
773  gnc_invoice_window_unpostCB(NULL, priv->iw);
774  LEAVE(" ");
775 }
776 
777 static void
778 gnc_plugin_page_invoice_cmd_sort_changed (GtkAction *action,
779  GtkRadioAction *current,
780  GncPluginPageInvoice *plugin_page)
781 {
783  invoice_sort_type_t value;
784 
785  ENTER("(action %p, radio action %p, plugin_page %p)",
786  action, current, plugin_page);
787  LEAVE("g_return testing...");
788 
789  g_return_if_fail(GTK_IS_ACTION(action));
790  g_return_if_fail(GTK_IS_RADIO_ACTION(current));
791  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
792 
793  ENTER("...passed (action %p, radio action %p, plugin_page %p)",
794  action, current, plugin_page);
795  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(plugin_page);
796  value = gtk_radio_action_get_current_value(current);
797  gnc_invoice_window_sort (priv->iw, value);
798  LEAVE(" ");
799 }
800 
801 
802 static void
803 gnc_plugin_page_invoice_cmd_enter (GtkAction *action,
804  GncPluginPageInvoice *plugin_page)
805 {
807 
808  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
809 
810  ENTER("(action %p, plugin_page %p)", action, plugin_page);
811  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(plugin_page);
812  gnc_invoice_window_recordCB(NULL, priv->iw);
813  LEAVE(" ");
814 }
815 
816 static void
817 gnc_plugin_page_invoice_cmd_cancel (GtkAction *action,
818  GncPluginPageInvoice *plugin_page)
819 {
821 
822  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
823 
824  ENTER("(action %p, plugin_page %p)", action, plugin_page);
825  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(plugin_page);
826  gnc_invoice_window_cancelCB(NULL, priv->iw);
827  LEAVE(" ");
828 }
829 
830 static void
831 gnc_plugin_page_invoice_cmd_delete (GtkAction *action,
832  GncPluginPageInvoice *plugin_page)
833 {
835 
836  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
837 
838  ENTER("(action %p, plugin_page %p)", action, plugin_page);
839  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(plugin_page);
840  gnc_invoice_window_deleteCB(NULL, priv->iw);
841  LEAVE(" ");
842 }
843 
844 static void
845 gnc_plugin_page_invoice_cmd_blank (GtkAction *action,
846  GncPluginPageInvoice *plugin_page)
847 {
849 
850  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
851 
852  ENTER("(action %p, plugin_page %p)", action, plugin_page);
853  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(plugin_page);
854  gnc_invoice_window_blankCB(NULL, priv->iw);
855  LEAVE(" ");
856 }
857 
858 static void
859 gnc_plugin_page_invoice_cmd_duplicateEntry (GtkAction *action,
860  GncPluginPageInvoice *plugin_page)
861 {
863 
864  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
865 
866  ENTER("(action %p, plugin_page %p)", action, plugin_page);
867  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(plugin_page);
868  gnc_invoice_window_duplicateCB(NULL, priv->iw);
869  LEAVE(" ");
870 }
871 
872 static void
873 gnc_plugin_page_invoice_cmd_entryUp (GtkAction *action,
874  GncPluginPageInvoice *plugin_page)
875 {
877  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
878 
879  ENTER("(action %p, plugin_page %p)", action, plugin_page);
880  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(plugin_page);
881  gnc_invoice_window_entryUpCB(NULL, priv->iw);
882  LEAVE(" ");
883 }
884 
885 static void
886 gnc_plugin_page_invoice_cmd_entryDown (GtkAction *action,
887  GncPluginPageInvoice *plugin_page)
888 {
890  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
891 
892  ENTER("(action %p, plugin_page %p)", action, plugin_page);
893  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(plugin_page);
894  gnc_invoice_window_entryDownCB(NULL, priv->iw);
895  LEAVE(" ");
896 }
897 
898 static void
899 gnc_plugin_page_invoice_cmd_pay_invoice (GtkAction *action,
900  GncPluginPageInvoice *plugin_page)
901 {
903 
904  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
905 
906  ENTER("(action %p, plugin_page %p)", action, plugin_page);
907  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(plugin_page);
908  gnc_invoice_window_payment_cb(NULL, priv->iw);
909  LEAVE(" ");
910 }
911 
912 static void
913 gnc_plugin_page_invoice_cmd_company_report (GtkAction *action,
914  GncPluginPageInvoice *plugin_page)
915 {
917 
918  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
919 
920  ENTER("(action %p, plugin_page %p)", action, plugin_page);
921  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(plugin_page);
922  gnc_invoice_window_report_owner_cb(NULL, priv->iw);
923  LEAVE(" ");
924 }
925 
926 /************************************************************/
927 /* Auxiliary functions */
928 /************************************************************/
929 
930 static void
931 gnc_plugin_page_redraw_help_cb (GnucashRegister *g_reg,
932  GncPluginPageInvoice *invoice_page)
933 {
935  GncWindow *window;
936  const char *status;
937  char *help;
938 
939  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(invoice_page));
940 
941  window = GNC_WINDOW(GNC_PLUGIN_PAGE(invoice_page)->window);
942 
943  /* Get the text from the ledger */
944  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(invoice_page);
945  help = gnc_invoice_get_help(priv->iw);
946  status = help ? help : g_strdup("");
947  gnc_window_set_status(window, GNC_PLUGIN_PAGE(invoice_page), status);
948  g_free(help);
949 }
950 
951 
952 void
954 {
955  GncPluginPageInvoice *page;
957  gchar *title;
958 
959  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
960 
961  page = GNC_PLUGIN_PAGE_INVOICE(plugin_page);
962  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(page);
963  title = gnc_invoice_get_title(priv->iw);
964  main_window_update_page_name(plugin_page, title);
965  g_free(title);
966 }
967 
968 static void
969 gnc_plugin_page_invoice_refresh_cb (GHashTable *changes, gpointer user_data)
970 {
971  GncPluginPageInvoice *page = user_data;
973  GtkWidget *reg;
974 
975  g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(page));
976 
977  /* We're only looking for forced updates here. */
978  if (changes)
979  return;
980 
981  priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(page);
982  reg = gnc_invoice_get_register(priv->iw);
983  gnucash_register_refresh_from_prefs(GNUCASH_REGISTER(reg));
984  gtk_widget_queue_draw(priv->widget);
985 }
utility functions for the GnuCash UI
const gchar * tab_icon
GType gnc_plugin_page_invoice_get_type(void)
const GList * gnc_gobject_tracking_get_list(const gchar *name)
GncPluginPage *(* recreate_page)(GtkWidget *window, GKeyFile *file, const gchar *group)
gulong gnc_prefs_register_cb(const char *group, const gchar *pref_name, gpointer func, gpointer user_data)
Definition: gnc-prefs.c:128
Dialog for create/edit an account.
utility functions for the GnuCash UI
void gnc_plugin_page_set_uri(GncPluginPage *page, const char *name)
Functions that are supported by all types of windows.
GtkActionGroup * gnc_plugin_page_get_action_group(GncPluginPage *page)
#define ENTER(format, args...)
Definition: qoflog.h:261
void gnc_plugin_page_invoice_update_menus(GncPluginPage *page, gboolean is_posted, gboolean can_unpost)
Gobject helper routines.
void(* destroy_widget)(GncPluginPage *plugin_page)
GncPluginPage * gnc_plugin_page_invoice_new(InvoiceWindow *iw)
void gnc_plugin_init_short_names(GtkActionGroup *action_group, action_toolbar_labels *toolbar_labels)
Definition: gnc-plugin.c:263
const gchar * plugin_name
Gnome specific utility functions.
void(* window_changed)(GncPluginPage *plugin_page, GtkWidget *window)
Generic api to store and retrieve preferences.
gboolean qof_book_is_readonly(const QofBook *book)
void gnc_plugin_update_actions(GtkActionGroup *action_group, const gchar **action_names, const gchar *property_name, gboolean value)
Definition: gnc-plugin.c:313
void gnc_ui_new_account_window(QofBook *book, Account *parent)
GtkWidget *(* create_widget)(GncPluginPage *plugin_page)
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Definition: gnc-prefs.c:196
Functions for adding plugins to a GnuCash window.
#define LEAVE(format, args...)
Definition: qoflog.h:271
void(* save_page)(GncPluginPage *page, GKeyFile *file, const gchar *group)
void gnc_plugin_page_add_book(GncPluginPage *page, QofBook *book)
GtkActionGroup * gnc_plugin_page_create_action_group(GncPluginPage *page, const gchar *group_name)
void main_window_update_page_name(GncPluginPage *page, const gchar *name_in)
GtkWidget * summarybar
void gnc_plugin_page_invoice_update_title(GncPluginPage *plugin_page)
const gchar * QofLogModule
Definition: qofid.h:89
void gnc_prefs_remove_cb_by_func(const gchar *group, const gchar *pref_name, gpointer func, gpointer user_data)
Definition: gnc-prefs.c:148