28 #include <glib/gi18n.h>
40 #include "business-urls.h"
41 #include "dialog-customer.h"
42 #include "dialog-employee.h"
43 #include "dialog-vendor.h"
44 #include "dialog-invoice.h"
45 #include "dialog-job.h"
52 #if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 2)
53 # pragma GCC diagnostic warning "-Waddress"
56 #define HANDLE_TYPE(URL_TYPE_STR,OBJ_TYPE) { \
59 QofCollection *coll; \
61 g_return_val_if_fail (location != NULL, FALSE); \
62 g_return_val_if_fail (result != NULL, FALSE); \
63 result->load_to_stream = FALSE; \
65 if (strncmp (URL_TYPE_STR, location, strlen(URL_TYPE_STR))) \
67 result->error_message = \
68 g_strdup_printf (_("Badly formed URL %s"), location); \
71 if (!string_to_guid (location + strlen(URL_TYPE_STR), &guid)) \
73 result->error_message = g_strdup_printf (_("Bad URL: %s"), location); \
77 book = gnc_get_current_book(); \
78 coll = qof_book_get_collection (book, OBJ_TYPE); \
79 entity = qof_collection_lookup_entity (coll, &guid); \
82 result->error_message = g_strdup_printf (_("No such entity: %s"), \
89 customerCB (
const char *location,
const char *label,
96 HANDLE_TYPE (
"customer=", GNC_ID_CUSTOMER);
98 gnc_ui_customer_edit (customer);
104 vendorCB (
const char *location,
const char *label,
111 HANDLE_TYPE (
"vendor=", GNC_ID_VENDOR);
113 gnc_ui_vendor_edit (vendor);
119 employeeCB (
const char *location,
const char *label,
126 HANDLE_TYPE (
"employee=", GNC_ID_EMPLOYEE);
129 gnc_ui_employee_edit (employee);
135 invoiceCB (
const char *location,
const char *label,
142 HANDLE_TYPE (
"invoice=", GNC_ID_INVOICE);
144 gnc_ui_invoice_edit (invoice);
150 jobCB (
const char *location,
const char *label,
157 HANDLE_TYPE (
"job=", GNC_ID_JOB);
159 gnc_ui_job_edit (job);
166 #define RETURN_IF_NULL(inst) \
169 result->error_message = \
170 g_strdup_printf (_("No such owner entity: %s"), location); \
175 ownerreportCB (
const char *location,
const char *label,
178 const char *ownerptr;
186 g_return_val_if_fail (location != NULL, FALSE);
187 g_return_val_if_fail (result != NULL, FALSE);
189 result->load_to_stream = FALSE;
193 acctptr = strchr (location,
'&');
197 if (strncmp (
"owner=", location, 6) != 0)
199 result->error_message = g_strdup_printf (_(
"Badly formed URL %s"),
204 memset (&owner, 0,
sizeof (owner));
206 ownerptr = location + 6;
210 type = GNC_OWNER_CUSTOMER;
213 type = GNC_OWNER_VENDOR;
216 type = GNC_OWNER_EMPLOYEE;
219 type = GNC_OWNER_JOB;
222 result->error_message = g_strdup_printf (_(
"Bad URL: %s"), location);
228 result->error_message = g_strdup_printf (_(
"Bad URL: %s"), location);
235 case GNC_OWNER_CUSTOMER:
238 gncCustomerLookup (gnc_get_current_book (), &guid);
239 RETURN_IF_NULL (customer);
240 gncOwnerInitCustomer (&owner, customer);
244 case GNC_OWNER_VENDOR:
247 gncVendorLookup (gnc_get_current_book (), &guid);
248 RETURN_IF_NULL (vendor);
249 gncOwnerInitVendor (&owner, vendor);
253 case GNC_OWNER_EMPLOYEE:
256 gncEmployeeLookup (gnc_get_current_book (), &guid);
257 RETURN_IF_NULL(employee);
258 gncOwnerInitEmployee (&owner, employee);
265 gncJobLookup (gnc_get_current_book (), &guid);
267 gncOwnerInitJob (&owner, job);
276 if (owner.owner.undefined == NULL)
278 result->error_message =
279 g_strdup_printf (_(
"Entity type does not match %s: %s"),
287 if (strncmp (
"acct=", acctptr, 5) != 0)
289 result->error_message = g_strdup_printf (_(
"Bad URL %s"), location);
295 result->error_message = g_strdup_printf (_(
"Bad URL: %s"), location);
302 result->error_message = g_strdup_printf (_(
"No such Account entity: %s"),
309 gnc_business_call_owner_report (&owner, acc);
315 gnc_business_urls_initialize (
void)
322 GncHTMLUrlCB handler;
325 { GNC_ID_CUSTOMER, GNC_ID_CUSTOMER, customerCB },
326 { GNC_ID_VENDOR, GNC_ID_VENDOR, vendorCB },
327 { GNC_ID_EMPLOYEE, GNC_ID_EMPLOYEE, employeeCB },
328 { GNC_ID_JOB, GNC_ID_JOB, jobCB },
329 { GNC_ID_INVOICE, GNC_ID_INVOICE, invoiceCB },
330 { URL_TYPE_OWNERREPORT,
"gnc-ownerreport", ownerreportCB },
334 for (i = 0; types[i].urltype; i++)
335 gnc_html_register_urltype (types[i].urltype, types[i].protocol);
337 for (i = 0; types[i].urltype; i++)
338 if (types[i].handler)
339 gnc_html_register_url_handler (types[i].urltype, types[i].handler);
utility functions for the GnuCash UI
gboolean string_to_guid(const gchar *string, GncGUID *guid)
Business Invoice Interface.
Account * xaccAccountLookup(const GncGUID *guid, QofBook *book)