[Gnucash-changes] r12878 - gnucash/trunk - Save/restore business
invoice pages.
David Hampton
hampton at cvs.gnucash.org
Wed Jan 18 23:09:01 EST 2006
Author: hampton
Date: 2006-01-18 23:09:00 -0500 (Wed, 18 Jan 2006)
New Revision: 12878
Trac: http://svn.gnucash.org/trac/changeset/12878
Modified:
gnucash/trunk/ChangeLog
gnucash/trunk/src/business/business-core/gncOwner.c
gnucash/trunk/src/business/business-core/gncOwner.h
gnucash/trunk/src/business/business-gnome/dialog-invoice.c
gnucash/trunk/src/business/business-gnome/dialog-invoice.h
gnucash/trunk/src/business/business-gnome/gnc-plugin-page-invoice.c
Log:
Save/restore business invoice pages.
Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog 2006-01-19 04:06:49 UTC (rev 12877)
+++ gnucash/trunk/ChangeLog 2006-01-19 04:09:00 UTC (rev 12878)
@@ -1,5 +1,10 @@
2006-01-18 David Hampton <hampton at employees.org>
+ * src/business/business-core/gncOwner.[ch]:
+ * src/business/business-gnome/dialog-invoice.[ch]:
+ * src/business/business-gnome/gnc-plugin-page-invoice.c:
+ Save/restore business invoice pages.
+
* src/app-utils/gnc-component-manager.c: Tweak a debugging
statement.
Modified: gnucash/trunk/src/business/business-core/gncOwner.c
===================================================================
--- gnucash/trunk/src/business/business-core/gncOwner.c 2006-01-19 04:06:49 UTC (rev 12877)
+++ gnucash/trunk/src/business/business-core/gncOwner.c 2006-01-19 04:09:00 UTC (rev 12878)
@@ -489,6 +489,30 @@
qof_class_register (GNC_ID_LOT, NULL, params);
}
+gboolean gncOwnerGetOwnerFromTypeGuid (QofBook *book, GncOwner *owner, QofIdType type, GUID *guid)
+{
+ if (!book || !owner || !type || !guid) return FALSE;
+
+ if (0 == safe_strcmp(type, GNC_ID_CUSTOMER)) {
+ GncCustomer *customer = gncCustomerLookup(book,guid);
+ gncOwnerInitCustomer(owner, customer);
+ return (NULL != customer);
+ } else if (0 == safe_strcmp(type, GNC_ID_JOB)) {
+ GncJob *job = gncJobLookup(book,guid);
+ gncOwnerInitJob(owner, job);
+ return (NULL != job);
+ } else if (0 == safe_strcmp(type, GNC_ID_VENDOR)) {
+ GncVendor *vendor = gncVendorLookup(book,guid);
+ gncOwnerInitVendor(owner, vendor);
+ return (NULL != vendor);
+ } else if (0 == safe_strcmp(type, GNC_ID_EMPLOYEE)) {
+ GncEmployee *employee = gncEmployeeLookup(book,guid);
+ gncOwnerInitEmployee(owner, employee);
+ return (NULL != employee);
+ }
+ return 0;
+}
+
gboolean gncOwnerRegister (void)
{
static QofParam params[] = {
Modified: gnucash/trunk/src/business/business-core/gncOwner.h
===================================================================
--- gnucash/trunk/src/business/business-core/gncOwner.h 2006-01-19 04:06:49 UTC (rev 12877)
+++ gnucash/trunk/src/business/business-core/gncOwner.h 2006-01-19 04:09:00 UTC (rev 12878)
@@ -135,6 +135,8 @@
*/
gboolean gncOwnerGetOwnerFromLot (GNCLot *lot, GncOwner *owner);
+gboolean gncOwnerGetOwnerFromTypeGuid (QofBook *book, GncOwner *owner, QofIdType type, GUID *guid);
+
#define OWNER_TYPE "type"
#define OWNER_TYPE_STRING "type-string" /**< Allows the type to be handled externally. */
#define OWNER_CUSTOMER "customer"
Modified: gnucash/trunk/src/business/business-gnome/dialog-invoice.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-invoice.c 2006-01-19 04:06:49 UTC (rev 12877)
+++ gnucash/trunk/src/business/business-gnome/dialog-invoice.c 2006-01-19 04:09:00 UTC (rev 12878)
@@ -51,6 +51,7 @@
#include "gncEntryLedger.h"
+#include "gnc-plugin-page.h"
#include "gnc-general-search.h"
#include "dialog-date-close.h"
#include "dialog-invoice.h"
@@ -65,7 +66,6 @@
#include "dialog-query-list.h"
#include "gnc-plugin-business.h"
-#include "gnc-plugin-page.h"
#include "gnc-plugin-page-invoice.h"
#include "gnc-main-window.h"
@@ -79,14 +79,19 @@
void gnc_invoice_window_help_cb (GtkWidget *widget, gpointer data);
void gnc_invoice_id_changed_cb (GtkWidget *widget, gpointer data);
-typedef enum
-{
- NEW_INVOICE,
- MOD_INVOICE,
- EDIT_INVOICE,
- VIEW_INVOICE
-} InvoiceDialogType;
+#define ENUM_INVOICE_TYPE(_) \
+ _(NEW_INVOICE, ) \
+ _(MOD_INVOICE, ) \
+ _(EDIT_INVOICE, ) \
+ _(VIEW_INVOICE, )
+DEFINE_ENUM(InvoiceDialogType, ENUM_INVOICE_TYPE)
+AS_STRING_DEC(InvoiceDialogType, ENUM_INVOICE_TYPE)
+FROM_STRING_DEC(InvoiceDialogType, ENUM_INVOICE_TYPE)
+
+FROM_STRING_FUNC(InvoiceDialogType, ENUM_INVOICE_TYPE)
+AS_STRING_FUNC(InvoiceDialogType, ENUM_INVOICE_TYPE)
+
struct _invoice_select_window {
GNCBook * book;
GncOwner * owner;
@@ -1655,6 +1660,114 @@
return iw;
}
+#define KEY_INVOICE_TYPE "Invoice Type"
+#define KEY_INVOICE_GUID "Invoice GUID"
+#define KEY_OWNER_TYPE "Owner Type"
+#define KEY_OWNER_GUID "Owner GUID"
+
+GncPluginPage *
+gnc_invoice_recreate_page (GKeyFile *key_file,
+ const gchar *group_name)
+{
+ InvoiceWindow *iw;
+ GError *error = NULL;
+ char *tmp_string = NULL, *owner_type = NULL;
+ InvoiceDialogType type;
+ GncInvoice *invoice;
+ GUID guid;
+ QofBook *book;
+ GncOwner owner = { 0 };
+
+ /* Get Invoice Type */
+ tmp_string = g_key_file_get_string(key_file, group_name,
+ KEY_INVOICE_TYPE, &error);
+ if (error) {
+ g_warning("Error reading group %s key %s: %s.",
+ group_name, KEY_INVOICE_TYPE, error->message);
+ goto give_up;
+ }
+ type = InvoiceDialogTypefromString(tmp_string);
+ g_free(tmp_string);
+
+ /* Get Invoice GUID */
+ tmp_string = g_key_file_get_string(key_file, group_name,
+ KEY_INVOICE_GUID, &error);
+ if (error) {
+ g_warning("Error reading group %s key %s: %s.",
+ group_name, KEY_INVOICE_GUID, error->message);
+ goto give_up;
+ }
+ if (!string_to_guid(tmp_string, &guid)) {
+ g_warning("Invalid invoice guid: %s.", tmp_string);
+ goto give_up;
+ }
+ book = gnc_get_current_book();
+ invoice = gncInvoiceLookup(gnc_get_current_book(), &guid);
+ if (invoice == NULL) {
+ g_warning("Can't find invoice %s in current book.", tmp_string);
+ goto give_up;
+ }
+ g_free(tmp_string);
+
+ /* Get Owner Type */
+ owner_type = g_key_file_get_string(key_file, group_name,
+ KEY_OWNER_TYPE, &error);
+ if (error) {
+ g_warning("Error reading group %s key %s: %s.",
+ group_name, KEY_OWNER_TYPE, error->message);
+ goto give_up;
+ }
+
+ /* Get Owner GUID */
+ tmp_string = g_key_file_get_string(key_file, group_name,
+ KEY_OWNER_GUID, &error);
+ if (error) {
+ g_warning("Error reading group %s key %s: %s.",
+ group_name, KEY_OWNER_GUID, error->message);
+ goto give_up;
+ }
+ if (!string_to_guid(tmp_string, &guid)) {
+ g_warning("Invalid owner guid: %s.", tmp_string);
+ goto give_up;
+ }
+
+ if (!gncOwnerGetOwnerFromTypeGuid(book, &owner, owner_type, &guid)) {
+ g_warning("Can't find owner %s in current book.", tmp_string);
+ goto give_up;
+ }
+ g_free(tmp_string);
+ g_free(owner_type);
+
+ iw = gnc_invoice_new_page (book, type, invoice, &owner);
+ return iw->page;
+
+ give_up:
+ g_warning("Giving up on restoring '%s'.", group_name);
+ if (error)
+ g_error_free(error);
+ if (tmp_string)
+ g_free(tmp_string);
+ if (owner_type)
+ g_free(owner_type);
+ return NULL;
+}
+
+void
+gnc_invoice_save_page (InvoiceWindow *iw,
+ GKeyFile *key_file,
+ const gchar *group_name)
+{
+ g_key_file_set_string(key_file, group_name, KEY_INVOICE_TYPE,
+ InvoiceDialogTypeasString(iw->dialog_type));
+ g_key_file_set_string(key_file, group_name, KEY_INVOICE_GUID,
+ guid_to_string(&iw->invoice_guid));
+
+ g_key_file_set_string(key_file, group_name, KEY_OWNER_TYPE,
+ qofOwnerGetType(&iw->owner));
+ g_key_file_set_string(key_file, group_name, KEY_OWNER_GUID,
+ guid_to_string(gncOwnerGetGUID(&iw->owner)));
+}
+
GtkWidget *
gnc_invoice_create_page (InvoiceWindow *iw, gpointer page)
{
Modified: gnucash/trunk/src/business/business-gnome/dialog-invoice.h
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-invoice.h 2006-01-19 04:06:49 UTC (rev 12877)
+++ gnucash/trunk/src/business/business-gnome/dialog-invoice.h 2006-01-19 04:09:00 UTC (rev 12878)
@@ -77,6 +77,11 @@
gchar *gnc_invoice_get_title (InvoiceWindow *iw);
+#ifdef __GNC_PLUGIN_PAGE_H
+GncPluginPage *gnc_invoice_recreate_page (GKeyFile *key_file, const gchar *group_name);
+void gnc_invoice_save_page (InvoiceWindow *iw, GKeyFile *key_file, const gchar *group_name);
+#endif
+
GtkWidget * gnc_invoice_create_page (InvoiceWindow *iw, gpointer page);
DialogQueryList *gnc_invoice_show_bills_due (QofBook *book, double days_in_advance);
Modified: gnucash/trunk/src/business/business-gnome/gnc-plugin-page-invoice.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/gnc-plugin-page-invoice.c 2006-01-19 04:06:49 UTC (rev 12877)
+++ gnucash/trunk/src/business/business-gnome/gnc-plugin-page-invoice.c 2006-01-19 04:09:00 UTC (rev 12878)
@@ -49,6 +49,8 @@
static GtkWidget *gnc_plugin_page_invoice_create_widget (GncPluginPage *plugin_page);
static void gnc_plugin_page_invoice_destroy_widget (GncPluginPage *plugin_page);
+static void gnc_plugin_page_invoice_save_page (GncPluginPage *plugin_page, GKeyFile *file, const gchar *group);
+static GncPluginPage *gnc_plugin_page_invoice_recreate_page (GtkWidget *window, GKeyFile *file, const gchar *group);
static void gnc_plugin_page_invoice_window_changed (GncPluginPage *plugin_page, GtkWidget *window);
@@ -290,6 +292,8 @@
gnc_plugin_class->plugin_name = GNC_PLUGIN_PAGE_INVOICE_NAME;
gnc_plugin_class->create_widget = gnc_plugin_page_invoice_create_widget;
gnc_plugin_class->destroy_widget = gnc_plugin_page_invoice_destroy_widget;
+ gnc_plugin_class->save_page = gnc_plugin_page_invoice_save_page;
+ gnc_plugin_class->recreate_page = gnc_plugin_page_invoice_recreate_page;
gnc_plugin_class->window_changed = gnc_plugin_page_invoice_window_changed;
g_type_class_add_private(klass, sizeof(GncPluginPageInvoicePrivate));
@@ -429,7 +433,68 @@
priv->widget = NULL;
}
+/** Save enough information about this invoice page that it can be
+ * recreated next time the user starts gnucash.
+ *
+ * @param page The page to save.
+ *
+ * @param key_file A pointer to the GKeyFile data structure where the
+ * page information should be written.
+ *
+ * @param group_name The group name to use when saving data. */
static void
+gnc_plugin_page_invoice_save_page (GncPluginPage *plugin_page,
+ GKeyFile *key_file,
+ const gchar *group_name)
+{
+ GncPluginPageInvoice *invoice;
+ GncPluginPageInvoicePrivate *priv;
+
+ g_return_if_fail (GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
+ g_return_if_fail (key_file != NULL);
+ g_return_if_fail (group_name != NULL);
+
+ ENTER("page %p, key_file %p, group_name %s", plugin_page, key_file,
+ group_name);
+
+ invoice = GNC_PLUGIN_PAGE_INVOICE(plugin_page);
+ priv = GNC_PLUGIN_PAGE_INVOICE_GET_PRIVATE(invoice);
+
+ gnc_invoice_save_page(priv->iw, key_file, group_name);
+ LEAVE(" ");
+}
+
+
+
+/** Create a new invoice page based on the information saved during a
+ * previous instantiation of gnucash.
+ *
+ * @param window The window where this page should be installed.
+ *
+ * @param key_file A pointer to the GKeyFile data structure where the
+ * page information should be read.
+ *
+ * @param group_name The group name to use when restoring data. */
+static GncPluginPage *
+gnc_plugin_page_invoice_recreate_page (GtkWidget *window,
+ GKeyFile *key_file,
+ const gchar *group_name)
+{
+ GncPluginPage *page;
+
+ g_return_val_if_fail(key_file, NULL);
+ g_return_val_if_fail(group_name, NULL);
+ ENTER("key_file %p, group_name %s", key_file, group_name);
+
+ /* Create the new page. */
+ page = gnc_invoice_recreate_page(key_file, group_name);
+
+ LEAVE(" ");
+ return page;
+}
+
+
+static void
gnc_plugin_page_invoice_window_changed (GncPluginPage *plugin_page,
GtkWidget *window)
{
More information about the gnucash-changes
mailing list