33 #include <qofinstance-p.h>
39 #include "gncOwnerP.h"
58 #define _GNC_MOD_NAME GNC_ID_JOB
59 #define GNC_JOB_RATE "job-rate"
64 G_INLINE_FUNC
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);
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:
123 key = OWNER_EXPORT_PDF_DIRNAME;
124 qof_instance_get_kvp (QOF_INSTANCE (job), key, value);
127 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
133 gnc_job_set_property (GObject *
object,
141 g_return_if_fail(GNC_IS_JOB(
object));
143 job = GNC_JOB(
object);
144 g_assert (qof_instance_get_editlevel(job));
149 gncJobSetName(job, g_value_get_string(value));
151 case PROP_PDF_DIRNAME:
152 key = OWNER_EXPORT_PDF_DIRNAME;
153 qof_instance_set_kvp (QOF_INSTANCE (job), key, value);
156 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
177 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
180 gobject_class->dispose = gnc_job_dispose;
181 gobject_class->finalize = gnc_job_finalize;
182 gobject_class->set_property = gnc_job_set_property;
183 gobject_class->get_property = gnc_job_get_property;
185 qof_class->get_display_name = NULL;
186 qof_class->refers_to_object = NULL;
187 qof_class->get_typed_referring_object_list = impl_get_typed_referring_object_list;
189 g_object_class_install_property
192 g_param_spec_string (
"name",
194 "The job name is an arbitrary string "
195 "assigned by the user. It is intended to "
196 "a short character string that is displayed "
197 "by the GUI as the job mnemonic.",
201 g_object_class_install_property
204 g_param_spec_string (
"export-pdf-dir",
205 "Export PDF Directory Name",
206 "A subdirectory for exporting PDF reports which is "
207 "appended to the target directory when writing them "
208 "out. It is retrieved from preferences and stored on "
209 "each 'Owner' object which prints items after "
220 if (!book)
return NULL;
222 job = g_object_new (GNC_TYPE_JOB, NULL);
225 job->id = CACHE_INSERT (
"");
226 job->name = CACHE_INSERT (
"");
227 job->desc = CACHE_INSERT (
"");
236 void gncJobDestroy (
GncJob *job)
239 qof_instance_set_destroying(job, TRUE);
240 gncJobCommitEdit (job);
243 static void gncJobFree (
GncJob *job)
249 CACHE_REMOVE (job->id);
250 CACHE_REMOVE (job->name);
251 CACHE_REMOVE (job->desc);
255 case GNC_OWNER_CUSTOMER:
258 case GNC_OWNER_VENDOR:
266 g_object_unref (job);
273 #define SET_STR(obj, member, str) { \
276 if (!g_strcmp0 (member, str)) return; \
277 gncJobBeginEdit (obj); \
278 tmp = CACHE_INSERT (str); \
279 CACHE_REMOVE (member); \
283 void gncJobSetID (
GncJob *job,
const char *
id)
287 SET_STR(job, job->id,
id);
289 gncJobCommitEdit (job);
292 void gncJobSetName (
GncJob *job,
const char *name)
296 SET_STR(job, job->name, name);
298 gncJobCommitEdit (job);
301 void gncJobSetReference (
GncJob *job,
const char *desc)
305 SET_STR(job, job->desc, desc);
307 gncJobCommitEdit (job);
315 gncJobBeginEdit (job);
325 GNC_JOB_RATE, value);
329 gncJobCommitEdit (job);
340 case GNC_OWNER_CUSTOMER:
341 case GNC_OWNER_VENDOR:
348 gncJobBeginEdit (job);
352 case GNC_OWNER_CUSTOMER:
355 case GNC_OWNER_VENDOR:
362 gncOwnerCopy (owner, &(job->owner));
366 case GNC_OWNER_CUSTOMER:
369 case GNC_OWNER_VENDOR:
377 gncJobCommitEdit (job);
380 void gncJobSetActive (
GncJob *job, gboolean active)
383 if (active == job->active)
return;
384 gncJobBeginEdit (job);
385 job->active = active;
387 gncJobCommitEdit (job);
398 gncJobBeginEdit (job);
401 gncJobCommitEdit (job);
404 void gncJobBeginEdit (
GncJob *job)
411 PERR(
"Job QofBackend Failure: %d", errcode);
412 gnc_engine_signal_commit_error( errcode );
423 void gncJobCommitEdit (
GncJob *job)
431 gncJobOnDone, job_free);
437 const char * gncJobGetID (
const GncJob *job)
439 if (!job)
return NULL;
443 const char * gncJobGetName (
const GncJob *job)
445 if (!job)
return NULL;
449 const char * gncJobGetReference (
const GncJob *job)
451 if (!job)
return NULL;
457 if (!job)
return gnc_numeric_zero ();
458 return kvp_frame_get_numeric(job->inst.kvp_data, GNC_JOB_RATE);
463 if (!job)
return NULL;
464 return &(job->owner);
467 gboolean gncJobGetActive (
const GncJob *job)
469 if (!job)
return FALSE;
474 qofJobGetOwner (
GncJob *job)
487 if (!a && !b)
return 0;
488 if (!a && b)
return 1;
489 if (a && !b)
return -1;
491 return (g_strcmp0(a->id, b->id));
496 if (a == NULL && b == NULL)
return TRUE;
497 if (a == NULL || b == NULL)
return FALSE;
499 g_return_val_if_fail(GNC_IS_JOB(a), FALSE);
500 g_return_val_if_fail(GNC_IS_JOB(b), FALSE);
502 if (g_strcmp0(a->id, b->id) != 0)
504 PWARN(
"IDs differ: %s vs %s", a->id, b->id);
508 if (g_strcmp0(a->name, b->name) != 0)
510 PWARN(
"Names differ: %s vs %s", a->name, b->name);
514 if (g_strcmp0(a->desc, b->desc) != 0)
516 PWARN(
"Descriptions differ: %s vs %s", a->desc, b->desc);
522 PWARN(
"Rates differ");
526 if (a->active != b->active)
528 PWARN(
"Active flags differ");
543 static const char * _gncJobPrintable (gpointer item)
546 if (!item)
return NULL;
554 DI(.e_type = ) _GNC_MOD_NAME,
555 DI(.type_label = ) "Job",
556 DI(.create = ) (gpointer)gncJobCreate,
557 DI(.book_begin = ) NULL,
558 DI(.book_end = ) NULL,
562 DI(.printable = ) _gncJobPrintable,
566 gboolean gncJobRegister (
void)
575 #ifdef GNUCASH_MAJOR_VERSION
576 { JOB_OWNER, GNC_ID_OWNER, (
QofAccessFunc)gncJobGetOwner, NULL },
580 { QOF_PARAM_ACTIVE, QOF_TYPE_BOOLEAN, (
QofAccessFunc)gncJobGetActive, NULL },
596 #ifdef GNUCASH_MAJOR_VERSION
597 qofJobGetOwner(NULL);
598 qofJobSetOwner(NULL, NULL);
603 gchar *gncJobNextID (
QofBook *book)
int qof_instance_version_cmp(const QofInstance *left, const QofInstance *right)
gboolean gnc_numeric_equal(gnc_numeric a, gnc_numeric b)
const GncGUID * qof_instance_get_guid(gconstpointer)
QofBook * qof_instance_get_book(gconstpointer)
gboolean qof_collection_is_dirty(const QofCollection *col)
QofBackendError
The errors that can be reported to the GUI & other front-end users.
gboolean kvp_frame_is_empty(const KvpFrame *frame)
gchar * qof_book_increment_and_format_counter(QofBook *book, const char *counter_name)
void gnc_features_set_used(QofBook *book, const gchar *feature)
void qof_class_register(QofIdTypeConst obj_name, QofSortFunc default_sort_fcn, const QofParam *params)
gboolean gncOwnerEqual(const GncOwner *a, const GncOwner *b)
gboolean gnc_numeric_zero_p(gnc_numeric a)
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
#define QOF_OBJECT_VERSION
gboolean qof_commit_edit(QofInstance *inst)
#define PERR(format, args...)
void qof_collection_foreach(const QofCollection *, QofInstanceForeachCB, gpointer user_data)
QofInstance * qofOwnerGetOwner(const GncOwner *owner)
#define PWARN(format, args...)
void qof_instance_init_data(QofInstance *, QofIdType, QofBook *)
gboolean qof_begin_edit(QofInstance *inst)
gboolean qof_choice_create(char *type)
Set an object as using QOF_TYPE_CHOICE.
void qofOwnerSetEntity(GncOwner *owner, QofInstance *ent)
void kvp_frame_set_numeric(KvpFrame *frame, const gchar *path, gnc_numeric nval)
int(* QofSortFunc)(gconstpointer, gconstpointer)
gboolean qof_commit_edit_part2(QofInstance *inst, void(*on_error)(QofInstance *, QofBackendError), void(*on_done)(QofInstance *), void(*on_free)(QofInstance *))
void qof_collection_mark_clean(QofCollection *)
KvpFrame * kvp_frame_set_value_nc(KvpFrame *frame, const gchar *path, KvpValue *value)
GncOwnerType gncOwnerGetType(const GncOwner *owner)
Business Invoice Interface.
gboolean qof_choice_add_class(const char *choice, char *add, char *param_name)
Add the choices for this parameter to the object.
struct KvpFrameImpl KvpFrame
void(* QofSetterFunc)(gpointer, gpointer)
GncVendor * gncOwnerGetVendor(const GncOwner *owner)
GncCustomer * gncOwnerGetCustomer(const GncOwner *owner)
gboolean qof_object_register(const QofObject *object)
void kvp_value_delete(KvpValue *value)
void qof_event_gen(QofInstance *entity, QofEventId event_type, gpointer event_data)
Invoke all registered event handlers using the given arguments.
#define QOF_TYPE_CHOICE
Identify an object as containing a choice.
struct KvpValueImpl KvpValue
const gchar * QofLogModule
Utility functions for file access.