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,
113 g_return_if_fail(GNC_IS_JOB(
object));
115 job = GNC_JOB(
object);
119 g_value_set_string(value, job->name);
121 case PROP_PDF_DIRNAME:
125 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
131 gnc_job_set_property (GObject *
object,
138 g_return_if_fail(GNC_IS_JOB(
object));
140 job = GNC_JOB(
object);
141 g_assert (qof_instance_get_editlevel(job));
146 gncJobSetName(job, g_value_get_string(value));
148 case PROP_PDF_DIRNAME:
152 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
171 gnc_job_class_init (GncJobClass *klass)
173 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
174 QofInstanceClass* qof_class = QOF_INSTANCE_CLASS(klass);
176 gobject_class->dispose = gnc_job_dispose;
177 gobject_class->finalize = gnc_job_finalize;
178 gobject_class->set_property = gnc_job_set_property;
179 gobject_class->get_property = gnc_job_get_property;
181 qof_class->get_display_name = NULL;
182 qof_class->refers_to_object = NULL;
183 qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
185 g_object_class_install_property
188 g_param_spec_string (
"name",
190 "The job name is an arbitrary string " 191 "assigned by the user. It is intended to " 192 "a short character string that is displayed " 193 "by the GUI as the job mnemonic.",
197 g_object_class_install_property
200 g_param_spec_string (
"export-pdf-dir",
201 "Export PDF Directory Name",
202 "A subdirectory for exporting PDF reports which is " 203 "appended to the target directory when writing them " 204 "out. It is retrieved from preferences and stored on " 205 "each 'Owner' object which prints items after " 212 GncJob *gncJobCreate (QofBook *book)
216 if (!book)
return NULL;
218 job = g_object_new (GNC_TYPE_JOB, NULL);
221 job->id = CACHE_INSERT (
"");
222 job->name = CACHE_INSERT (
"");
223 job->desc = CACHE_INSERT (
"");
232 static void free_job_list (GncJob *job)
234 gncJobBeginEdit (job);
238 void gncJobFreeList (GList *jobs)
240 GList *job_list = g_list_copy (jobs);
241 g_list_free_full (job_list, (GDestroyNotify)free_job_list);
244 void gncJobDestroy (GncJob *job)
247 qof_instance_set_destroying(job, TRUE);
248 gncJobCommitEdit (job);
251 static void gncJobFree (GncJob *job)
257 CACHE_REMOVE (job->id);
258 CACHE_REMOVE (job->name);
259 CACHE_REMOVE (job->desc);
263 case GNC_OWNER_CUSTOMER:
266 case GNC_OWNER_VENDOR:
274 g_object_unref (job);
281 #define SET_STR(obj, member, str) { \ 282 if (!g_strcmp0 (member, str)) return; \ 283 gncJobBeginEdit (obj); \ 284 CACHE_REPLACE (member, str); \ 287 void gncJobSetID (GncJob *job,
const char *
id)
291 SET_STR(job, job->id,
id);
293 gncJobCommitEdit (job);
296 void gncJobSetName (GncJob *job,
const char *name)
300 SET_STR(job, job->name, name);
302 gncJobCommitEdit (job);
305 void gncJobSetReference (GncJob *job,
const char *desc)
309 SET_STR(job, job->desc, desc);
311 gncJobCommitEdit (job);
314 void gncJobSetRate (GncJob *job, gnc_numeric rate)
319 gncJobBeginEdit (job);
322 GValue v = G_VALUE_INIT;
323 g_value_init (&v, GNC_TYPE_NUMERIC);
324 g_value_set_boxed (&v, &rate);
333 gncJobCommitEdit (job);
336 void gncJobSetOwner (GncJob *job,
GncOwner *owner)
344 case GNC_OWNER_CUSTOMER:
345 case GNC_OWNER_VENDOR:
352 gncJobBeginEdit (job);
356 case GNC_OWNER_CUSTOMER:
359 case GNC_OWNER_VENDOR:
366 gncOwnerCopy (owner, &(job->owner));
370 case GNC_OWNER_CUSTOMER:
373 case GNC_OWNER_VENDOR:
381 gncJobCommitEdit (job);
384 void gncJobSetActive (GncJob *job, gboolean active)
387 if (active == job->active)
return;
388 gncJobBeginEdit (job);
389 job->active = active;
391 gncJobCommitEdit (job);
402 gncJobBeginEdit (job);
405 gncJobCommitEdit (job);
408 void gncJobBeginEdit (GncJob *job)
415 PERR(
"Job QofBackend Failure: %d", errcode);
416 gnc_engine_signal_commit_error( errcode );
421 GncJob *job = (GncJob *)inst;
427 void gncJobCommitEdit (GncJob *job)
435 gncJobOnDone, job_free);
441 const char * gncJobGetID (
const GncJob *job)
443 if (!job)
return NULL;
447 const char * gncJobGetName (
const GncJob *job)
449 if (!job)
return NULL;
453 const char * gncJobGetReference (
const GncJob *job)
455 if (!job)
return NULL;
459 gnc_numeric gncJobGetRate (
const GncJob *job)
461 GValue v = G_VALUE_INIT;
462 gnc_numeric *rate = NULL;
464 if (!job)
return gnc_numeric_zero ();
466 if (G_VALUE_HOLDS_BOXED (&v))
467 rate = (gnc_numeric*)g_value_get_boxed (&v);
468 retval = rate ? *rate : gnc_numeric_zero ();
473 GncOwner * gncJobGetOwner (GncJob *job)
475 if (!job)
return NULL;
476 return &(job->owner);
479 gboolean gncJobGetActive (
const GncJob *job)
481 if (!job)
return FALSE;
486 qofJobGetOwner (GncJob *job)
497 int gncJobCompare (
const GncJob * a,
const GncJob *b)
499 if (!a && !b)
return 0;
500 if (!a && b)
return 1;
501 if (a && !b)
return -1;
503 return (g_strcmp0(a->id, b->id));
506 gboolean gncJobEqual(
const GncJob * a,
const GncJob *b)
508 if (a == NULL && b == NULL)
return TRUE;
509 if (a == NULL || b == NULL)
return FALSE;
511 g_return_val_if_fail(GNC_IS_JOB(a), FALSE);
512 g_return_val_if_fail(GNC_IS_JOB(b), FALSE);
514 if (g_strcmp0(a->id, b->id) != 0)
516 PWARN(
"IDs differ: %s vs %s", a->id, b->id);
520 if (g_strcmp0(a->name, b->name) != 0)
522 PWARN(
"Names differ: %s vs %s", a->name, b->name);
526 if (g_strcmp0(a->desc, b->desc) != 0)
528 PWARN(
"Descriptions differ: %s vs %s", a->desc, b->desc);
534 PWARN(
"Rates differ");
538 if (a->active != b->active)
540 PWARN(
"Active flags differ");
555 static const char * _gncJobPrintable (gpointer item)
558 if (!item)
return NULL;
563 static QofObject gncJobDesc =
566 DI(.e_type = ) _GNC_MOD_NAME,
567 DI(.type_label = ) "Job",
568 DI(.create = ) (gpointer)gncJobCreate,
569 DI(.book_begin = ) NULL,
570 DI(.book_end = ) NULL,
573 DI(.foreach = ) qof_collection_foreach,
574 DI(.printable = ) _gncJobPrintable,
578 gboolean gncJobRegister (
void)
580 static QofParam params[] =
587 { JOB_OWNER, GNC_ID_OWNER, (
QofAccessFunc)gncJobGetOwner, NULL },
588 { QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (
QofAccessFunc)gncJobGetActive, NULL },
595 qofJobGetOwner(NULL);
596 qofJobSetOwner(NULL, NULL);
600 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(* 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
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.
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.