GnuCash c935c2f+
Loading...
Searching...
No Matches
Files | Macros | Functions

Files

file  gncJob.h
 Job Interface.
 

Macros

#define GNC_ID_JOB   "gncJob"
 
#define GNC_TYPE_JOB   (gnc_job_get_type ())
 
#define GNC_JOB(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_JOB, GncJob))
 
#define GNC_JOB_CLASS(k)    (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_JOB, GncJobClass))
 
#define GNC_IS_JOB(o)    (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_JOB))
 
#define GNC_IS_JOB_CLASS(k)    (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_JOB))
 
#define GNC_JOB_GET_CLASS(o)    (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_JOB, GncJobClass))
 
#define JOB_ID   "id"
 
#define JOB_NAME   "name"
 
#define JOB_REFERENCE   "reference"
 
#define JOB_RATE   "rate"
 
#define JOB_OWNER   "owner"
 
#define Q_JOB_OWNER   "owner_collection"
 
#define JOB_ACTIVE   "active"
 
#define gncJobGetBook(x)   qof_instance_get_book(QOF_INSTANCE(x))
 deprecated functions
 
#define gncJobGetGUID(x)   qof_instance_get_guid(QOF_INSTANCE(x))
 
#define gncJobRetGUID(x)   (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null()))
 
#define gncJobLookupDirect(G, B)   gncJobLookup((B),&(G))
 

Functions

GType gnc_job_get_type (void)
 
GncJob * gncJobCreate (QofBook *book)
 
void gncJobDestroy (GncJob *job)
 
void gncJobFreeList (GList *jobs)
 
void gncJobBeginEdit (GncJob *job)
 
void gncJobCommitEdit (GncJob *job)
 
int gncJobCompare (const GncJob *a, const GncJob *b)
 
gboolean gncJobEqual (const GncJob *a, const GncJob *b)
 

Set Functions

void gncJobSetID (GncJob *job, const char *id)
 
void gncJobSetName (GncJob *job, const char *jobname)
 
void gncJobSetReference (GncJob *job, const char *owner_reference)
 
void gncJobSetRate (GncJob *job, gnc_numeric rate)
 
void gncJobSetOwner (GncJob *job, GncOwner *owner)
 
void gncJobSetActive (GncJob *job, gboolean active)
 

Get Functions

const char * gncJobGetID (const GncJob *job)
 
const char * gncJobGetName (const GncJob *job)
 
const char * gncJobGetReference (const GncJob *job)
 
gnc_numeric gncJobGetRate (const GncJob *job)
 
GncOwnergncJobGetOwner (GncJob *job)
 
gboolean gncJobGetActive (const GncJob *job)
 

Detailed Description

Macro Definition Documentation

◆ GNC_ID_JOB

#define GNC_ID_JOB   "gncJob"

Definition at line 44 of file gncJob.h.

◆ GNC_IS_JOB

#define GNC_IS_JOB (   o)     (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_JOB))

Definition at line 52 of file gncJob.h.

99{
100 QOF_BOOK_RETURN_ENTITY(book, guid, GNC_ID_JOB, GncJob);
101}
102
103/* Other functions */
104
105int gncJobCompare (const GncJob *a, const GncJob *b);
106gboolean gncJobEqual(const GncJob *a, const GncJob *b);
107
108#define JOB_ID "id"
109#define JOB_NAME "name"
110#define JOB_REFERENCE "reference"
111#define JOB_RATE "rate"
112#define JOB_OWNER "owner"
113#define Q_JOB_OWNER "owner_collection"
114#define JOB_ACTIVE "active"
115
117#define gncJobGetBook(x) qof_instance_get_book(QOF_INSTANCE(x))
118#define gncJobGetGUID(x) qof_instance_get_guid(QOF_INSTANCE(x))
119#define gncJobRetGUID(x) (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null()))
120#define gncJobLookupDirect(G,B) gncJobLookup((B),&(G))
121
122#ifdef __cplusplus
123}
124#endif
125
126#endif /* GNC_JOB_H_ */
#define QOF_BOOK_RETURN_ENTITY(book, guid, e_type, c_type)
Encapsulates all the information about a dataset manipulated by QOF.
Definition qofbook.h:101

◆ GNC_IS_JOB_CLASS

#define GNC_IS_JOB_CLASS (   k)     (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_JOB))

Definition at line 54 of file gncJob.h.

◆ GNC_JOB

#define GNC_JOB (   o)     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_JOB, GncJob))

Definition at line 48 of file gncJob.h.

◆ GNC_JOB_CLASS

#define GNC_JOB_CLASS (   k)     (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_JOB, GncJobClass))

Definition at line 50 of file gncJob.h.

◆ GNC_JOB_GET_CLASS

#define GNC_JOB_GET_CLASS (   o)     (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_JOB, GncJobClass))

Definition at line 56 of file gncJob.h.

◆ GNC_TYPE_JOB

#define GNC_TYPE_JOB   (gnc_job_get_type ())

Definition at line 47 of file gncJob.h.

◆ gncJobGetBook

#define gncJobGetBook (   x)    qof_instance_get_book(QOF_INSTANCE(x))

deprecated functions

Definition at line 117 of file gncJob.h.

◆ gncJobGetGUID

#define gncJobGetGUID (   x)    qof_instance_get_guid(QOF_INSTANCE(x))

Definition at line 118 of file gncJob.h.

◆ gncJobLookupDirect

#define gncJobLookupDirect (   G,
 
)    gncJobLookup((B),&(G))

Definition at line 120 of file gncJob.h.

◆ gncJobRetGUID

#define gncJobRetGUID (   x)    (x ? *(qof_instance_get_guid(QOF_INSTANCE(x))) : *(guid_null()))

Definition at line 119 of file gncJob.h.

◆ JOB_ACTIVE

#define JOB_ACTIVE   "active"

Definition at line 114 of file gncJob.h.

◆ JOB_ID

#define JOB_ID   "id"

Definition at line 108 of file gncJob.h.

◆ JOB_NAME

#define JOB_NAME   "name"

Definition at line 109 of file gncJob.h.

◆ JOB_OWNER

#define JOB_OWNER   "owner"

Definition at line 112 of file gncJob.h.

◆ JOB_RATE

#define JOB_RATE   "rate"

Definition at line 111 of file gncJob.h.

◆ JOB_REFERENCE

#define JOB_REFERENCE   "reference"

Definition at line 110 of file gncJob.h.

◆ Q_JOB_OWNER

#define Q_JOB_OWNER   "owner_collection"

Definition at line 113 of file gncJob.h.

Function Documentation

◆ gncJobBeginEdit()

void gncJobBeginEdit ( GncJob *  job)

Definition at line 408 of file gncJob.c.

409{
410 qof_begin_edit(&job->inst);
411}
gboolean qof_begin_edit(QofInstance *inst)
begin_edit

◆ gncJobCommitEdit()

void gncJobCommitEdit ( GncJob *  job)

Definition at line 427 of file gncJob.c.

428{
429 /* GnuCash 2.6.3 and earlier didn't handle job kvp's... */
430 if (qof_instance_has_kvp (QOF_INSTANCE (job)))
431 gnc_features_set_used (qof_instance_get_book (QOF_INSTANCE (job)), GNC_FEATURE_KVP_EXTRA_DATA);
432
433 if (!qof_commit_edit (QOF_INSTANCE(job))) return;
434 qof_commit_edit_part2 (&job->inst, gncJobOnError,
435 gncJobOnDone, job_free);
436}
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
gboolean qof_instance_has_kvp(QofInstance *inst)
Report whether a QofInstance has anything stored in KVP.
void gnc_features_set_used(QofBook *book, const gchar *feature)
Indicate that the current book uses the given feature.
gboolean qof_commit_edit_part2(QofInstance *inst, void(*on_error)(QofInstance *, QofBackendError), void(*on_done)(QofInstance *), void(*on_free)(QofInstance *))
part2 – deal with the backend
gboolean qof_commit_edit(QofInstance *inst)
commit_edit helpers

◆ gncJobCompare()

int gncJobCompare ( const GncJob *  a,
const GncJob *  b 
)

Definition at line 497 of file gncJob.c.

498{
499 if (!a && !b) return 0;
500 if (!a && b) return 1;
501 if (a && !b) return -1;
502
503 return (g_strcmp0(a->id, b->id));
504}

◆ gncJobCreate()

GncJob * gncJobCreate ( QofBook book)

Definition at line 212 of file gncJob.c.

213{
214 GncJob *job;
215
216 if (!book) return NULL;
217
218 job = g_object_new (GNC_TYPE_JOB, NULL);
219 qof_instance_init_data (&job->inst, _GNC_MOD_NAME, book);
220
221 job->id = CACHE_INSERT ("");
222 job->name = CACHE_INSERT ("");
223 job->desc = CACHE_INSERT ("");
224 job->active = TRUE;
225
226 /* GncOwner not initialized */
227 qof_event_gen (&job->inst, QOF_EVENT_CREATE, NULL);
228
229 return job;
230}
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition qofevent.cpp:231
void qof_instance_init_data(QofInstance *inst, QofIdType type, QofBook *book)
Initialise the settings associated with an instance.

◆ gncJobDestroy()

void gncJobDestroy ( GncJob *  job)

Definition at line 244 of file gncJob.c.

245{
246 if (!job) return;
247 qof_instance_set_destroying(job, TRUE);
248 gncJobCommitEdit (job);
249}

◆ gncJobEqual()

gboolean gncJobEqual ( const GncJob *  a,
const GncJob *  b 
)

Definition at line 506 of file gncJob.c.

507{
508 if (a == NULL && b == NULL) return TRUE;
509 if (a == NULL || b == NULL) return FALSE;
510
511 g_return_val_if_fail(GNC_IS_JOB(a), FALSE);
512 g_return_val_if_fail(GNC_IS_JOB(b), FALSE);
513
514 if (g_strcmp0(a->id, b->id) != 0)
515 {
516 PWARN("IDs differ: %s vs %s", a->id, b->id);
517 return FALSE;
518 }
519
520 if (g_strcmp0(a->name, b->name) != 0)
521 {
522 PWARN("Names differ: %s vs %s", a->name, b->name);
523 return FALSE;
524 }
525
526 if (g_strcmp0(a->desc, b->desc) != 0)
527 {
528 PWARN("Descriptions differ: %s vs %s", a->desc, b->desc);
529 return FALSE;
530 }
531
532 if (!gnc_numeric_equal(gncJobGetRate(a), gncJobGetRate(b)))
533 {
534 PWARN("Rates differ");
535 return FALSE;
536 }
537
538 if (a->active != b->active)
539 {
540 PWARN("Active flags differ");
541 return FALSE;
542 }
543
544 /* FIXME: Need real tests */
545#if 0
546 GncOwner owner;
547#endif
548
549 return TRUE;
550}
#define PWARN(format, args...)
Log a warning.
Definition qoflog.h:250
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
Equivalence predicate: Returns TRUE (1) if a and b represent the same number.

◆ gncJobFreeList()

void gncJobFreeList ( GList *  jobs)

Definition at line 238 of file gncJob.c.

239{
240 GList *job_list = g_list_copy (jobs);
241 g_list_free_full (job_list, (GDestroyNotify)free_job_list);
242}

◆ gncJobGetActive()

gboolean gncJobGetActive ( const GncJob *  job)

Definition at line 479 of file gncJob.c.

480{
481 if (!job) return FALSE;
482 return job->active;
483}

◆ gncJobGetID()

const char * gncJobGetID ( const GncJob *  job)

Definition at line 441 of file gncJob.c.

442{
443 if (!job) return NULL;
444 return job->id;
445}

◆ gncJobGetName()

const char * gncJobGetName ( const GncJob *  job)

Definition at line 447 of file gncJob.c.

448{
449 if (!job) return NULL;
450 return job->name;
451}

◆ gncJobGetOwner()

GncOwner * gncJobGetOwner ( GncJob *  job)

Definition at line 473 of file gncJob.c.

474{
475 if (!job) return NULL;
476 return &(job->owner);
477}

◆ gncJobGetRate()

gnc_numeric gncJobGetRate ( const GncJob *  job)

Definition at line 459 of file gncJob.c.

460{
461 GValue v = G_VALUE_INIT;
462 gnc_numeric *rate = NULL;
463 gnc_numeric retval;
464 if (!job) return gnc_numeric_zero ();
465 qof_instance_get_kvp (QOF_INSTANCE (job), &v, 1, GNC_JOB_RATE);
466 if (G_VALUE_HOLDS_BOXED (&v))
467 rate = (gnc_numeric*)g_value_get_boxed (&v);
468 retval = rate ? *rate : gnc_numeric_zero ();
469 g_value_unset (&v);
470 return retval;
471}
void qof_instance_get_kvp(QofInstance *, GValue *value, unsigned count,...)
Retrieves the contents of a KVP slot into a provided GValue.

◆ gncJobGetReference()

const char * gncJobGetReference ( const GncJob *  job)

Definition at line 453 of file gncJob.c.

454{
455 if (!job) return NULL;
456 return job->desc;
457}

◆ gncJobSetActive()

void gncJobSetActive ( GncJob *  job,
gboolean  active 
)

Definition at line 384 of file gncJob.c.

385{
386 if (!job) return;
387 if (active == job->active) return;
388 gncJobBeginEdit (job);
389 job->active = active;
390 mark_job (job);
391 gncJobCommitEdit (job);
392}

◆ gncJobSetID()

void gncJobSetID ( GncJob *  job,
const char *  id 
)

Definition at line 287 of file gncJob.c.

288{
289 if (!job) return;
290 if (!id) return;
291 SET_STR(job, job->id, id);
292 mark_job (job);
293 gncJobCommitEdit (job);
294}

◆ gncJobSetName()

void gncJobSetName ( GncJob *  job,
const char *  jobname 
)

Definition at line 296 of file gncJob.c.

297{
298 if (!job) return;
299 if (!name) return;
300 SET_STR(job, job->name, name);
301 mark_job (job);
302 gncJobCommitEdit (job);
303}

◆ gncJobSetOwner()

void gncJobSetOwner ( GncJob *  job,
GncOwner owner 
)

Definition at line 336 of file gncJob.c.

337{
338 if (!job) return;
339 if (!owner) return;
340 if (gncOwnerEqual (owner, &(job->owner))) return;
341
342 switch (gncOwnerGetType (owner))
343 {
344 case GNC_OWNER_CUSTOMER:
345 case GNC_OWNER_VENDOR:
346 break;
347 default:
348 PERR("Unsupported Owner type: %d", gncOwnerGetType(owner));
349 return;
350 }
351
352 gncJobBeginEdit (job);
353
354 switch (gncOwnerGetType (&(job->owner)))
355 {
356 case GNC_OWNER_CUSTOMER:
357 gncCustomerRemoveJob (gncOwnerGetCustomer(&job->owner), job);
358 break;
359 case GNC_OWNER_VENDOR:
360 gncVendorRemoveJob (gncOwnerGetVendor(&job->owner), job);
361 break;
362 default:
363 break;
364 }
365
366 gncOwnerCopy (owner, &(job->owner));
367
368 switch (gncOwnerGetType (&(job->owner)))
369 {
370 case GNC_OWNER_CUSTOMER:
371 gncCustomerAddJob (gncOwnerGetCustomer(&job->owner), job);
372 break;
373 case GNC_OWNER_VENDOR:
374 gncVendorAddJob (gncOwnerGetVendor(&job->owner), job);
375 break;
376 default:
377 break;
378 }
379
380 mark_job (job);
381 gncJobCommitEdit (job);
382}
#define PERR(format, args...)
Log a serious error.
Definition qoflog.h:244
GncCustomer * gncOwnerGetCustomer(const GncOwner *owner)
If the given owner is of type GNC_OWNER_CUSTOMER, returns the pointer to the customer object.
Definition gncOwner.c:369
GncVendor * gncOwnerGetVendor(const GncOwner *owner)
If the given owner is of type GNC_OWNER_VENDOR, returns the pointer to the vendor object.
Definition gncOwner.c:383
gboolean gncOwnerEqual(const GncOwner *a, const GncOwner *b)
Assess equality by checking.
Definition gncOwner.c:404
GncOwnerType gncOwnerGetType(const GncOwner *owner)
Returns the GncOwnerType of this owner.
Definition gncOwner.c:200

◆ gncJobSetRate()

void gncJobSetRate ( GncJob *  job,
gnc_numeric  rate 
)

Definition at line 314 of file gncJob.c.

315{
316 if (!job) return;
317 if (gnc_numeric_equal (gncJobGetRate(job), rate)) return;
318
319 gncJobBeginEdit (job);
320 if (!gnc_numeric_zero_p(rate))
321 {
322 GValue v = G_VALUE_INIT;
323 g_value_init (&v, GNC_TYPE_NUMERIC);
324 g_value_set_boxed (&v, &rate);
325 qof_instance_set_kvp (QOF_INSTANCE (job), &v, 1, GNC_JOB_RATE);
326 g_value_unset (&v);
327 }
328 else
329 {
330 qof_instance_set_kvp (QOF_INSTANCE (job), NULL, 1, GNC_JOB_RATE);
331 }
332 mark_job (job);
333 gncJobCommitEdit (job);
334}
void qof_instance_set_kvp(QofInstance *, GValue const *value, unsigned count,...)
Sets a KVP slot to a value from a GValue.
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.

◆ gncJobSetReference()

void gncJobSetReference ( GncJob *  job,
const char *  owner_reference 
)

Definition at line 305 of file gncJob.c.

306{
307 if (!job) return;
308 if (!desc) return;
309 SET_STR(job, job->desc, desc);
310 mark_job (job);
311 gncJobCommitEdit (job);
312}