33 #include <qofinstance-p.h> 39 #include "gncOwnerP.h" 53 QofInstanceClass parent_class;
56 static QofLogModule log_module = GNC_MOD_BUSINESS;
58 #define _GNC_MOD_NAME GNC_ID_JOB 59 #define GNC_JOB_RATE "job-rate" 64 static inline void mark_job (GncJob *job);
65 void mark_job (GncJob *job)
67 qof_instance_set_dirty(&job->inst);
86 G_DEFINE_TYPE(GncJob, gnc_job, QOF_TYPE_INSTANCE);
89 gnc_job_init(GncJob* job)
94 gnc_job_dispose(GObject *jobp)
96 G_OBJECT_CLASS(gnc_job_parent_class)->dispose(jobp);
100 gnc_job_finalize(GObject* jobp)
102 G_OBJECT_CLASS(gnc_job_parent_class)->finalize(jobp);
106 gnc_job_get_property (GObject *
object,
114 g_return_if_fail(GNC_IS_JOB(
object));
116 job = GNC_JOB(
object);
120 g_value_set_string(value, job->name);
122 case PROP_PDF_DIRNAME:
126 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
132 gnc_job_set_property (GObject *
object,
140 g_return_if_fail(GNC_IS_JOB(
object));
142 job = GNC_JOB(
object);
143 g_assert (qof_instance_get_editlevel(job));
148 gncJobSetName(job, g_value_get_string(value));
150 case PROP_PDF_DIRNAME:
154 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
166 impl_get_typed_referring_object_list(
const QofInstance* inst,
const QofInstance* ref)
173 gnc_job_class_init (GncJobClass *klass)
175 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
176 QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
178 gobject_class->dispose = gnc_job_dispose;
179 gobject_class->finalize = gnc_job_finalize;
180 gobject_class->set_property = gnc_job_set_property;
181 gobject_class->get_property = gnc_job_get_property;
183 qof_class->get_display_name = NULL;
184 qof_class->refers_to_object = NULL;
185 qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
187 g_object_class_install_property
190 g_param_spec_string (
"name",
192 "The job name is an arbitrary string " 193 "assigned by the user. It is intended to " 194 "a short character string that is displayed " 195 "by the GUI as the job mnemonic.",
199 g_object_class_install_property
202 g_param_spec_string (
"export-pdf-dir",
203 "Export PDF Directory Name",
204 "A subdirectory for exporting PDF reports which is " 205 "appended to the target directory when writing them " 206 "out. It is retrieved from preferences and stored on " 207 "each 'Owner' object which prints items after " 214 GncJob *gncJobCreate (QofBook *book)
218 if (!book)
return NULL;
220 job = g_object_new (GNC_TYPE_JOB, NULL);
223 job->id = CACHE_INSERT (
"");
224 job->name = CACHE_INSERT (
"");
225 job->desc = CACHE_INSERT (
"");
234 void gncJobDestroy (GncJob *job)
237 qof_instance_set_destroying(job, TRUE);
238 gncJobCommitEdit (job);
241 static void gncJobFree (GncJob *job)
247 CACHE_REMOVE (job->id);
248 CACHE_REMOVE (job->name);
249 CACHE_REMOVE (job->desc);
253 case GNC_OWNER_CUSTOMER:
256 case GNC_OWNER_VENDOR:
264 g_object_unref (job);
271 #define SET_STR(obj, member, str) { \ 272 if (!g_strcmp0 (member, str)) return; \ 273 gncJobBeginEdit (obj); \ 274 CACHE_REPLACE (member, str); \ 277 void gncJobSetID (GncJob *job,
const char *
id)
281 SET_STR(job, job->id,
id);
283 gncJobCommitEdit (job);
286 void gncJobSetName (GncJob *job,
const char *name)
290 SET_STR(job, job->name, name);
292 gncJobCommitEdit (job);
295 void gncJobSetReference (GncJob *job,
const char *desc)
299 SET_STR(job, job->desc, desc);
301 gncJobCommitEdit (job);
304 void gncJobSetRate (GncJob *job, gnc_numeric rate)
309 gncJobBeginEdit (job);
312 GValue v = G_VALUE_INIT;
313 g_value_init (&v, GNC_TYPE_NUMERIC);
314 g_value_set_boxed (&v, &rate);
323 gncJobCommitEdit (job);
326 void gncJobSetOwner (GncJob *job,
GncOwner *owner)
334 case GNC_OWNER_CUSTOMER:
335 case GNC_OWNER_VENDOR:
342 gncJobBeginEdit (job);
346 case GNC_OWNER_CUSTOMER:
349 case GNC_OWNER_VENDOR:
356 gncOwnerCopy (owner, &(job->owner));
360 case GNC_OWNER_CUSTOMER:
363 case GNC_OWNER_VENDOR:
371 gncJobCommitEdit (job);
374 void gncJobSetActive (GncJob *job, gboolean active)
377 if (active == job->active)
return;
378 gncJobBeginEdit (job);
379 job->active = active;
381 gncJobCommitEdit (job);
385 qofJobSetOwner (GncJob *job, QofInstance *ent)
392 gncJobBeginEdit (job);
395 gncJobCommitEdit (job);
398 void gncJobBeginEdit (GncJob *job)
405 PERR(
"Job QofBackend Failure: %d", errcode);
406 gnc_engine_signal_commit_error( errcode );
409 static void job_free (QofInstance *inst)
411 GncJob *job = (GncJob *)inst;
415 static void gncJobOnDone (QofInstance *
qof) { }
417 void gncJobCommitEdit (GncJob *job)
425 gncJobOnDone, job_free);
431 const char * gncJobGetID (
const GncJob *job)
433 if (!job)
return NULL;
437 const char * gncJobGetName (
const GncJob *job)
439 if (!job)
return NULL;
443 const char * gncJobGetReference (
const GncJob *job)
445 if (!job)
return NULL;
449 gnc_numeric gncJobGetRate (
const GncJob *job)
451 GValue v = G_VALUE_INIT;
452 gnc_numeric *rate = NULL;
454 if (!job)
return gnc_numeric_zero ();
456 if (G_VALUE_HOLDS_BOXED (&v))
457 rate = (gnc_numeric*)g_value_get_boxed (&v);
458 retval = rate ? *rate : gnc_numeric_zero ();
463 GncOwner * gncJobGetOwner (GncJob *job)
465 if (!job)
return NULL;
466 return &(job->owner);
469 gboolean gncJobGetActive (
const GncJob *job)
471 if (!job)
return FALSE;
476 qofJobGetOwner (GncJob *job)
487 int gncJobCompare (
const GncJob * a,
const GncJob *b)
489 if (!a && !b)
return 0;
490 if (!a && b)
return 1;
491 if (a && !b)
return -1;
493 return (g_strcmp0(a->id, b->id));
496 gboolean gncJobEqual(
const GncJob * a,
const GncJob *b)
498 if (a == NULL && b == NULL)
return TRUE;
499 if (a == NULL || b == NULL)
return FALSE;
501 g_return_val_if_fail(GNC_IS_JOB(a), FALSE);
502 g_return_val_if_fail(GNC_IS_JOB(b), FALSE);
504 if (g_strcmp0(a->id, b->id) != 0)
506 PWARN(
"IDs differ: %s vs %s", a->id, b->id);
510 if (g_strcmp0(a->name, b->name) != 0)
512 PWARN(
"Names differ: %s vs %s", a->name, b->name);
516 if (g_strcmp0(a->desc, b->desc) != 0)
518 PWARN(
"Descriptions differ: %s vs %s", a->desc, b->desc);
524 PWARN(
"Rates differ");
528 if (a->active != b->active)
530 PWARN(
"Active flags differ");
545 static const char * _gncJobPrintable (gpointer item)
548 if (!item)
return NULL;
553 static QofObject gncJobDesc =
556 DI(.e_type = ) _GNC_MOD_NAME,
557 DI(.type_label = ) "Job",
558 DI(.create = ) (gpointer)gncJobCreate,
559 DI(.book_begin = ) NULL,
560 DI(.book_end = ) NULL,
564 DI(.printable = ) _gncJobPrintable,
568 gboolean gncJobRegister (
void)
570 static QofParam params[] =
577 { JOB_OWNER, GNC_ID_OWNER, (
QofAccessFunc)gncJobGetOwner, NULL },
578 { QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (
QofAccessFunc)gncJobGetActive, NULL },
594 qofJobGetOwner(NULL);
595 qofJobSetOwner(NULL, NULL);
599 gchar *gncJobNextID (QofBook *book)
int qof_instance_version_cmp(const QofInstance *left, const QofInstance *right)
Compare two instances, based on their last update times.
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
Equivalence predicate: Returns TRUE (1) if a and b represent the same number.
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
void qof_instance_set_kvp(QofInstance *, GValue const *value, unsigned count,...)
Sets a KVP slot to a value from a GValue.
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
gboolean qof_collection_is_dirty(const QofCollection *col)
Return value of 'dirty' flag on collection.
QofBackendError
The errors that can be reported to the GUI & other front-end users.
gchar * qof_book_increment_and_format_counter(QofBook *book, const char *counter_name)
This will increment the named counter for this book and format it.
void gnc_features_set_used(QofBook *book, const gchar *feature)
Indicate that the current book uses the given feature.
void qof_class_register(QofIdTypeConst obj_name, QofSortFunc default_sort_function, const QofParam *params)
This function registers a new object class with the Qof subsystem.
gboolean gncOwnerEqual(const GncOwner *a, const GncOwner *b)
Assess equality by checking.
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
int(* QofSortFunc)(gconstpointer, gconstpointer)
This function is the default sort function for a particular object type.
#define QOF_OBJECT_VERSION
Defines the version of the core object object registration interface.
gboolean qof_commit_edit(QofInstance *inst)
commit_edit helpers
#define PERR(format, args...)
Log a serious error.
#define QOF_PARAM_BOOK
"Known" Object Parameters – all objects must support these
void qof_collection_foreach(const QofCollection *col, QofInstanceForeachCB cb_func, gpointer user_data)
Call the callback for each entity in the collection.
void(* QofSetterFunc)(gpointer, gpointer)
The QofSetterFunc defines an function pointer for parameter setters.
void qof_instance_get_kvp(QofInstance *, GValue *value, unsigned count,...)
Retrieves the contents of a KVP slot into a provided GValue.
QofInstance * qofOwnerGetOwner(const GncOwner *owner)
return the owner itself as an entity.
#define PWARN(format, args...)
Log a warning.
void qof_instance_init_data(QofInstance *inst, QofIdType type, QofBook *book)
Initialise the settings associated with an instance.
gboolean qof_begin_edit(QofInstance *inst)
begin_edit
gboolean qof_choice_create(char *type)
Set an object as using QOF_TYPE_CHOICE.
void qofOwnerSetEntity(GncOwner *owner, QofInstance *ent)
set the owner from the entity.
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
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
The QofAccessFunc defines an arbitrary function pointer for access functions.
void qof_collection_mark_clean(QofCollection *)
reset value of dirty flag
GncOwnerType gncOwnerGetType(const GncOwner *owner)
Returns the GncOwnerType of this owner.
Business Invoice Interface.
gboolean qof_choice_add_class(const char *select, char *option, char *param_name)
Add the choices for this parameter to the object.
GncVendor * gncOwnerGetVendor(const GncOwner *owner)
If the given owner is of type GNC_OWNER_VENDOR, returns the pointer to the vendor object...
GncCustomer * gncOwnerGetCustomer(const GncOwner *owner)
If the given owner is of type GNC_OWNER_CUSTOMER, returns the pointer to the customer object...
gboolean qof_object_register(const QofObject *object)
Register new types of object objects.
gboolean qof_instance_has_kvp(QofInstance *inst)
Report whether a QofInstance has anything stored in KVP.
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Utility functions for file access.