GnuCash  5.6-133-gc519490283+
Files | Data Structures | Macros | Typedefs | Functions

A QOF Book is a dataset. More...

Files

file  qofbook.h
 Encapsulate all the information about a dataset.
 

Data Structures

struct  QofBook
 QofBook reference. More...
 
struct  QofBookClass
 

Macros

#define __KVP_VALUE
 
#define QOF_TYPE_BOOK   (qof_book_get_type ())
 
#define QOF_BOOK(o)   (G_TYPE_CHECK_INSTANCE_CAST ((o), QOF_TYPE_BOOK, QofBook))
 
#define QOF_BOOK_CLASS(k)   (G_TYPE_CHECK_CLASS_CAST((k), QOF_TYPE_BOOK, QofBookClass))
 
#define QOF_IS_BOOK(o)   (G_TYPE_CHECK_INSTANCE_TYPE ((o), QOF_TYPE_BOOK))
 
#define QOF_IS_BOOK_CLASS(k)   (G_TYPE_CHECK_CLASS_TYPE ((k), QOF_TYPE_BOOK))
 
#define QOF_BOOK_GET_CLASS(o)   (G_TYPE_INSTANCE_GET_CLASS ((o), QOF_TYPE_BOOK, QofBookClass))
 
#define QOF_BOOK_RETURN_ENTITY(book, guid, e_type, c_type)
 Encapsulates all the information about a dataset manipulated by QOF. More...
 
#define qof_book_get_guid(X)   qof_entity_get_guid (QOF_INSTANCE(X))
 deprecated
 

Typedefs

typedef void(* QofBookDirtyCB) (QofBook *, gboolean dirty, gpointer user_data)
 
typedef void(* GncOptionSave) (GncOptionDB *, QofBook *, gboolean)
 
typedef void(* GncOptionLoad) (GncOptionDB *, QofBook *)
 
typedef GList QofBookList
 GList of QofBook.
 
typedef void(* QofBookFinalCB) (QofBook *, gpointer key, gpointer user_data)
 
typedef void(* QofCollectionForeachCB) (QofCollection *, gpointer user_data)
 Invoke the indicated callback on each collection in the book. More...
 

Functions

GType qof_book_get_type (void)
 
gboolean qof_book_register (void)
 Register the book object with the QOF object system. More...
 
QofBook * qof_book_new (void)
 Allocate, initialise and return a new QofBook. More...
 
void qof_book_destroy (QofBook *book)
 End any editing sessions associated with book, and free all memory associated with it. More...
 
void qof_book_mark_closed (QofBook *book)
 Close a book to editing. More...
 
QofCollection * qof_book_get_collection (const QofBook *, QofIdType)
 Return The table of entities of the given type. More...
 
void qof_book_foreach_collection (const QofBook *, QofCollectionForeachCB, gpointer)
 
void qof_book_set_data (QofBook *book, const gchar *key, gpointer data)
 The qof_book_set_data() allows arbitrary pointers to structs to be stored in QofBook. More...
 
void qof_book_set_data_fin (QofBook *book, const gchar *key, gpointer data, QofBookFinalCB)
 Same as qof_book_set_data(), except that the callback will be called when the book is destroyed. More...
 
gpointer qof_book_get_data (const QofBook *book, const gchar *key)
 Retrieves arbitrary pointers to structs stored by qof_book_set_data. More...
 
gboolean qof_book_is_readonly (const QofBook *book)
 Return whether the book is read only. More...
 
void qof_book_mark_readonly (QofBook *book)
 Mark the book as read only. More...
 
gboolean qof_book_empty (const QofBook *book)
 Check if the book has had anything loaded into it. More...
 
gboolean qof_book_use_trading_accounts (const QofBook *book)
 Returns flag indicating whether this book uses trading accounts.
 
gboolean qof_book_uses_autoreadonly (const QofBook *book)
 Returns TRUE if the auto-read-only feature should be used, otherwise FALSE. More...
 
gint qof_book_get_num_days_autoreadonly (const QofBook *book)
 Returns the number of days for auto-read-only transactions. More...
 
GDate * qof_book_get_autoreadonly_gdate (const QofBook *book)
 Returns the GDate that is the threshold for auto-read-only. More...
 
void qof_book_set_default_invoice_report (QofBook *book, const gchar *guid, const gchar *name)
 Save the Invoice Report name / guid to be used as the default for printing Invoices.
 
gchar * qof_book_get_default_invoice_report_guid (const QofBook *book)
 Get the guid of the Invoice Report to be used as the default for printing Invoices.
 
gchar * qof_book_get_default_invoice_report_name (const QofBook *book)
 Get the name of the Invoice Report to be used as the default for printing Invoices.
 
gdouble qof_book_get_default_invoice_report_timeout (const QofBook *book)
 Get the length of time available to change the used Invoice Report when printing Invoices.
 
gboolean qof_book_use_split_action_for_num_field (const QofBook *book)
 Returns TRUE if this book uses split action field as the 'Num' field, FALSE if it uses transaction number field.
 
gboolean qof_book_shutting_down (const QofBook *book)
 Is the book shutting down?
 
gboolean qof_book_session_not_saved (const QofBook *book)
 qof_book_not_saved() returns the value of the session_dirty flag, set when changes to any object in the book are committed (qof_backend->commit_edit has been called) and the backend hasn't yet written out the changes. More...
 
void qof_book_mark_session_saved (QofBook *book)
 The qof_book_mark_saved() routine marks the book as having been saved (to a file, to a database). More...
 
void qof_book_mark_session_dirty (QofBook *book)
 The qof_book_mark_dirty() routine marks the book as having been modified. More...
 
time64 qof_book_get_session_dirty_time (const QofBook *book)
 Retrieve the earliest modification time on the book. More...
 
void qof_book_set_dirty_cb (QofBook *book, QofBookDirtyCB cb, gpointer user_data)
 Set the function to call when a book transitions from clean to dirty, or vice versa.
 
gint64 qof_book_get_counter (QofBook *book, const char *counter_name)
 This will get the named counter for this book. More...
 
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. More...
 
gchar * qof_book_normalize_counter_format (const gchar *format, gchar **err_msg)
 Validate a counter format string. More...
 
char * qof_book_get_counter_format (const QofBook *book, const char *counter_name)
 Get the format string to use for the named counter. More...
 
const char * qof_book_get_string_option (const QofBook *book, const char *opt_name)
 
void qof_book_set_string_option (QofBook *book, const char *opt_name, const char *opt_val)
 
const GncGUIDqof_book_get_guid_option (QofBook *book, GSList *path)
 
void qof_book_option_frame_delete (QofBook *book, const char *opt_name)
 
GHashTable * qof_book_get_features (QofBook *book)
 Access functions for reading and setting the used-features on this book.
 
void qof_book_unset_feature (QofBook *book, const gchar *key)
 
void qof_book_set_feature (QofBook *book, const gchar *key, const gchar *descr)
 
void qof_book_begin_edit (QofBook *book)
 
void qof_book_commit_edit (QofBook *book)
 
void qof_book_save_options (QofBook *book, GncOptionSave save_cb, GncOptionDB *odb, gboolean clear)
 Save a GncOptionsDB back to the book's KVP. More...
 
void qof_book_set_option (QofBook *book, KvpValue *value, GSList *path)
 Save a single option value. More...
 
KvpValue * qof_book_get_option (QofBook *book, GSList *path)
 Read a single option value. More...
 
void qof_book_options_delete (QofBook *book, GSList *path)
 Delete the options. More...
 

Detailed Description

A QOF Book is a dataset.

It provides a single handle through which all the various collections of entities can be found. In particular, given only the type of the entity, the collection can be found.

Books also provide the 'natural' place to working with a storage backend, as a book can encapsulate everything held in storage.

Macro Definition Documentation

◆ QOF_BOOK_RETURN_ENTITY

#define QOF_BOOK_RETURN_ENTITY (   book,
  guid,
  e_type,
  c_type 
)
Value:
{ \
QofInstance *val = NULL; \
if ((guid != NULL) && (book != NULL)) { \
const QofCollection *col; \
col = qof_book_get_collection (book, e_type); \
val = qof_collection_lookup_entity (col, guid); \
} \
return (c_type *) val; \
}
QofInstance * qof_collection_lookup_entity(const QofCollection *col, const GncGUID *guid)
Find the entity going only from its guid.
Definition: qofid.cpp:212
QofCollection * qof_book_get_collection(const QofBook *, QofIdType)
Return The table of entities of the given type.
Definition: qofbook.cpp:521

Encapsulates all the information about a dataset manipulated by QOF.

This is the top-most structure used for anchoring data. This macro looks up an entity by GncGUID and returns a pointer to the entity by ending with a "return" statement. Hence, this macro can only be used as the last statement in the definition of a function, but not somewhere inline in the code.

Definition at line 186 of file qofbook.h.

Typedef Documentation

◆ QofCollectionForeachCB

typedef void(* QofCollectionForeachCB) (QofCollection *, gpointer user_data)

Invoke the indicated callback on each collection in the book.

Definition at line 238 of file qofbook.h.

Function Documentation

◆ qof_book_destroy()

void qof_book_destroy ( QofBook *  book)

End any editing sessions associated with book, and free all memory associated with it.

Definition at line 331 of file qofbook.cpp.

332 {
333  GHashTable* cols;
334 
335  if (!book) return;
336  ENTER ("book=%p", book);
337 
338  book->shutting_down = TRUE;
339  qof_event_force (&book->inst, QOF_EVENT_DESTROY, nullptr);
340 
341  /* Call the list of finalizers, let them do their thing.
342  * Do this before tearing into the rest of the book.
343  */
344  g_hash_table_foreach (book->data_table_finalizers, book_final, book);
345 
346  /* Lots hold a variety of pointers that need to still exist while
347  * cleaning them up so run its book_end before the rest.
348  */
349  auto lots{qof_book_get_collection(book, GNC_ID_LOT)};
350  qof_collection_foreach(lots, destroy_lot, nullptr);
351  qof_object_book_end (book);
352 
353  g_hash_table_destroy (book->data_table_finalizers);
354  book->data_table_finalizers = nullptr;
355  g_hash_table_destroy (book->data_tables);
356  book->data_tables = nullptr;
357 
358  /* qof_instance_release (&book->inst); */
359 
360  /* Note: we need to save this hashtable until after we remove ourself
361  * from it, otherwise we'll crash in our dispose() function when we
362  * DO remove ourself from the collection but the collection had already
363  * been destroyed.
364  */
365  cols = book->hash_of_collections;
366  g_object_unref (book);
367  g_hash_table_destroy (cols);
368 
369  LEAVE ("book=%p", book);
370 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
void qof_collection_foreach(const QofCollection *col, QofInstanceForeachCB cb_func, gpointer user_data)
Call the callback for each entity in the collection.
Definition: qofid.cpp:321
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
Definition: qofbook.cpp:521

◆ qof_book_empty()

gboolean qof_book_empty ( const QofBook *  book)

Check if the book has had anything loaded into it.

Definition at line 511 of file qofbook.cpp.

512 {
513  if (!book) return TRUE;
514  auto root_acct_col = qof_book_get_collection (book, GNC_ID_ROOT_ACCOUNT);
515  return qof_collection_get_data(root_acct_col) == nullptr;
516 }
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
Definition: qofbook.cpp:521
gpointer qof_collection_get_data(const QofCollection *col)
Store and retrieve arbitrary object-defined data.
Definition: qofid.cpp:289

◆ qof_book_get_autoreadonly_gdate()

GDate* qof_book_get_autoreadonly_gdate ( const QofBook *  book)

Returns the GDate that is the threshold for auto-read-only.

Any txn with posted-date lesser than this date should be considered read-only.

If the auto-read-only feature is not used (qof_book_uses_autoreadonly() returns FALSE), NULL is returned here.

The returned object was allocated newly; the caller must g_date_free() the object afterwards.

Definition at line 988 of file qofbook.cpp.

989 {
990  gint num_days;
991  GDate* result = nullptr;
992 
993  g_assert(book);
994  num_days = qof_book_get_num_days_autoreadonly(book);
995  if (num_days > 0)
996  {
997  result = gnc_g_date_new_today();
998  g_date_subtract_days(result, num_days);
999  }
1000  return result;
1001 }
gint qof_book_get_num_days_autoreadonly(const QofBook *book)
Returns the number of days for auto-read-only transactions.
Definition: qofbook.cpp:968
GDate * gnc_g_date_new_today()
Returns a newly allocated date of the current clock time, taken from time(2).
Definition: gnc-date.cpp:1224

◆ qof_book_get_collection()

QofCollection* qof_book_get_collection ( const QofBook *  ,
QofIdType   
)

Return The table of entities of the given type.

When an object's constructor calls qof_instance_init(), a reference to the object is stored in the book. The book stores all the references to initialized instances, sorted by type. This function returns a collection of the references for the specified type.

If the collection doesn't yet exist for the indicated type, it is created. Thus, this routine is guaranteed to return a non-NULL value. (Unless the system malloc failed (out of memory) in which case what happens??).

Definition at line 521 of file qofbook.cpp.

522 {
523  QofCollection *col;
524 
525  if (!book || !entity_type) return nullptr;
526 
527  col = static_cast<QofCollection*>(g_hash_table_lookup (book->hash_of_collections, entity_type));
528  if (!col)
529  {
530  col = qof_collection_new (entity_type);
531  g_hash_table_insert(
532  book->hash_of_collections,
533  (gpointer)qof_string_cache_insert(entity_type), col);
534  }
535  return col;
536 }
const char * qof_string_cache_insert(const char *key)
You can use this function with g_hash_table_insert(), for the key (or value), as long as you use the ...
QofCollection * qof_collection_new(QofIdType type)
create a new collection of entities of type
Definition: qofid.cpp:48

◆ qof_book_get_counter()

gint64 qof_book_get_counter ( QofBook *  book,
const char *  counter_name 
)

This will get the named counter for this book.

The return value is -1 on error or the current value of the counter.

Definition at line 580 of file qofbook.cpp.

581 {
582  KvpFrame *kvp;
583  KvpValue *value;
584 
585  if (!book)
586  {
587  PWARN ("No book!!!");
588  return -1;
589  }
590 
591  if (!counter_name || *counter_name == '\0')
592  {
593  PWARN ("Invalid counter name.");
594  return -1;
595  }
596 
597  /* Use the KVP in the book */
598  kvp = qof_instance_get_slots (QOF_INSTANCE (book));
599 
600  if (!kvp)
601  {
602  PWARN ("Book has no KVP_Frame");
603  return -1;
604  }
605 
606  value = kvp->get_slot({"counters", counter_name});
607  if (value)
608  {
609  auto int_value{value->get<int64_t>()};
610  /* Might be a double because of
611  * https://bugs.gnucash.org/show_bug.cgi?id=798930
612  */
613  if (!int_value)
614  int_value = static_cast<int64_t>(value->get<double>());
615  return int_value;
616  }
617  else
618  {
619  /* New counter */
620  return 0;
621  }
622 }
#define PWARN(format, args...)
Log a warning.
Definition: qoflog.h:250

◆ qof_book_get_counter_format()

char* qof_book_get_counter_format ( const QofBook *  book,
const char *  counter_name 
)

Get the format string to use for the named counter.

The return value is NULL on error or the format string of the counter. The returned string should be freed by the caller.

Definition at line 686 of file qofbook.cpp.

687 {
688  KvpFrame *kvp;
689  const char *user_format = nullptr;
690  gchar *norm_format = nullptr;
691  KvpValue *value;
692  gchar *error = nullptr;
693 
694  if (!book)
695  {
696  PWARN ("No book!!!");
697  return nullptr;
698  }
699 
700  if (!counter_name || *counter_name == '\0')
701  {
702  PWARN ("Invalid counter name.");
703  return nullptr;
704  }
705 
706  /* Get the KVP from the current book */
707  kvp = qof_instance_get_slots (QOF_INSTANCE (book));
708 
709  if (!kvp)
710  {
711  PWARN ("Book has no KVP_Frame");
712  return nullptr;
713  }
714 
715  /* Get the format string */
716  value = kvp->get_slot({"counter_formats", counter_name});
717  if (value)
718  {
719  user_format = value->get<const char*>();
720  norm_format = qof_book_normalize_counter_format(user_format, &error);
721  if (!norm_format)
722  {
723  PWARN("Invalid counter format string. Format string: '%s' Counter: '%s' Error: '%s')", user_format, counter_name, error);
724  /* Invalid format string */
725  user_format = nullptr;
726  g_free(error);
727  }
728  }
729 
730  /* If no (valid) format string was found, use the default format
731  * string */
732  if (!norm_format)
733  {
734  /* Use the default format */
735  norm_format = g_strdup ("%.6" PRIi64);
736  }
737  return norm_format;
738 }
#define PWARN(format, args...)
Log a warning.
Definition: qoflog.h:250
gchar * qof_book_normalize_counter_format(const gchar *p, gchar **err_msg)
Validate a counter format string.
Definition: qofbook.cpp:741

◆ qof_book_get_data()

gpointer qof_book_get_data ( const QofBook *  book,
const gchar *  key 
)

Retrieves arbitrary pointers to structs stored by qof_book_set_data.

◆ qof_book_get_num_days_autoreadonly()

gint qof_book_get_num_days_autoreadonly ( const QofBook *  book)

Returns the number of days for auto-read-only transactions.

If zero, the auto-read-only feature should be disabled (and qof_book_uses_autoreadonly() returns FALSE).

Definition at line 968 of file qofbook.cpp.

969 {
970  g_assert(book);
971 
972  if (!book->cached_num_days_autoreadonly_isvalid)
973  {
974  double tmp;
975 
976  // No cached value? Then do the expensive KVP lookup
977  qof_instance_get (QOF_INSTANCE (book),
978  PARAM_NAME_NUM_AUTOREAD_ONLY, &tmp,
979  nullptr);
980 
981  const_cast<QofBook*>(book)->cached_num_days_autoreadonly = tmp;
982  const_cast<QofBook*>(book)->cached_num_days_autoreadonly_isvalid = TRUE;
983  }
984  // Value is cached now. Use the cheap variable returning.
985  return (gint) book->cached_num_days_autoreadonly;
986 }
void qof_instance_get(const QofInstance *inst, const gchar *first_prop,...)
Wrapper for g_object_get.

◆ qof_book_get_option()

KvpValue* qof_book_get_option ( QofBook *  book,
GSList *  path 
)

Read a single option value.

Used from Scheme, the KvpValue<–>SCM translation is handled by the functions in kvp-scm.c and automated by SWIG. The starting element is set as KVP_OPTION_PATH in qofbookslots.h.

Parameters
bookThe book.
pathA GSList of keys which form a path under KVP_OPTION_PATH.

Definition at line 1374 of file qofbook.cpp.

1375 {
1376  KvpFrame *root = qof_instance_get_slots(QOF_INSTANCE (book));
1377  return root->get_slot(gslist_to_option_path(path));
1378 }

◆ qof_book_get_session_dirty_time()

time64 qof_book_get_session_dirty_time ( const QofBook *  book)

Retrieve the earliest modification time on the book.

Definition at line 420 of file qofbook.cpp.

421 {
422  return book->dirty_time;
423 }

◆ qof_book_increment_and_format_counter()

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.

The return value is NULL on error or the formatted (new) value of the counter. The caller should free the result with g_gree.

Definition at line 625 of file qofbook.cpp.

626 {
627  KvpFrame *kvp;
628  KvpValue *value;
629  gint64 counter;
630  gchar* format;
631  gchar* result;
632 
633  if (!book)
634  {
635  PWARN ("No book!!!");
636  return nullptr;
637  }
638 
639  if (!counter_name || *counter_name == '\0')
640  {
641  PWARN ("Invalid counter name.");
642  return nullptr;
643  }
644 
645  /* Get the current counter value from the KVP in the book. */
646  counter = qof_book_get_counter(book, counter_name);
647 
648  /* Check if an error occurred */
649  if (counter < 0)
650  return nullptr;
651 
652  /* Increment the counter */
653  counter++;
654 
655  /* Get the KVP from the current book */
656  kvp = qof_instance_get_slots (QOF_INSTANCE (book));
657 
658  if (!kvp)
659  {
660  PWARN ("Book has no KVP_Frame");
661  return nullptr;
662  }
663 
664  /* Save off the new counter */
665  qof_book_begin_edit(book);
666  value = new KvpValue(counter);
667  delete kvp->set_path({"counters", counter_name}, value);
668  qof_instance_set_dirty (QOF_INSTANCE (book));
669  qof_book_commit_edit(book);
670 
671  format = qof_book_get_counter_format(book, counter_name);
672 
673  if (!format)
674  {
675  PWARN("Cannot get format for counter");
676  return nullptr;
677  }
678 
679  /* Generate a string version of the counter */
680  result = g_strdup_printf(format, counter);
681  g_free (format);
682  return result;
683 }
char * qof_book_get_counter_format(const QofBook *book, const char *counter_name)
Get the format string to use for the named counter.
Definition: qofbook.cpp:686
#define PWARN(format, args...)
Log a warning.
Definition: qoflog.h:250
gint64 qof_book_get_counter(QofBook *book, const char *counter_name)
This will get the named counter for this book.
Definition: qofbook.cpp:580

◆ qof_book_is_readonly()

gboolean qof_book_is_readonly ( const QofBook *  book)

Return whether the book is read only.

Definition at line 497 of file qofbook.cpp.

498 {
499  g_return_val_if_fail( book != nullptr, TRUE );
500  return book->read_only;
501 }

◆ qof_book_mark_closed()

void qof_book_mark_closed ( QofBook *  book)

Close a book to editing.

It is up to the application to check this flag, and once marked closed, books cannot be marked as open.

Definition at line 570 of file qofbook.cpp.

571 {
572  if (!book)
573  {
574  return;
575  }
576  book->book_open = 'n';
577 }

◆ qof_book_mark_readonly()

void qof_book_mark_readonly ( QofBook *  book)

Mark the book as read only.

Definition at line 504 of file qofbook.cpp.

505 {
506  g_return_if_fail( book != nullptr );
507  book->read_only = TRUE;
508 }

◆ qof_book_mark_session_dirty()

void qof_book_mark_session_dirty ( QofBook *  book)

The qof_book_mark_dirty() routine marks the book as having been modified.

It can be used by frontend when the used has made a change at the book level.

Definition at line 397 of file qofbook.cpp.

398 {
399  if (!book) return;
400  if (!book->session_dirty)
401  {
402  /* Set the session dirty upfront, because the callback will check. */
403  book->session_dirty = TRUE;
404  book->dirty_time = gnc_time (nullptr);
405  if (book->dirty_cb)
406  book->dirty_cb(book, TRUE, book->dirty_data);
407  }
408 }
time64 gnc_time(time64 *tbuf)
get the current time
Definition: gnc-date.cpp:261

◆ qof_book_mark_session_saved()

void qof_book_mark_session_saved ( QofBook *  book)

The qof_book_mark_saved() routine marks the book as having been saved (to a file, to a database).

Used by backends to mark the notsaved flag as FALSE just after loading. Can also be used by the frontend when the used has said to abandon any changes.

Definition at line 383 of file qofbook.cpp.

384 {
385  if (!book) return;
386 
387  book->dirty_time = 0;
388  if (book->session_dirty)
389  {
390  /* Set the session clean upfront, because the callback will check. */
391  book->session_dirty = FALSE;
392  if (book->dirty_cb)
393  book->dirty_cb(book, FALSE, book->dirty_data);
394  }
395 }

◆ qof_book_new()

QofBook* qof_book_new ( void  )

Allocate, initialise and return a new QofBook.

Books contain references to all of the top-level object containers.

Definition at line 290 of file qofbook.cpp.

291 {
292  QofBook *book;
293 
294  ENTER (" ");
295  book = static_cast<QofBook*>(g_object_new(QOF_TYPE_BOOK, nullptr));
296  qof_object_book_begin (book);
297 
298  qof_event_gen (&book->inst, QOF_EVENT_CREATE, nullptr);
299  LEAVE ("book=%p", book);
300  return book;
301 }
void qof_object_book_begin(QofBook *book)
To be called from within the book.
Definition: qofobject.cpp:80
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
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

◆ qof_book_normalize_counter_format()

gchar* qof_book_normalize_counter_format ( const gchar *  format,
gchar **  err_msg 
)

Validate a counter format string.

If valid, returns a normalized format string, that is whatever long int specifier was used will be replaced with the value of the posix "PRIx64" macro. If not valid returns NULL and optionally set an error message is a non-null err_msg parameter was passed. The caller should free the returned format string and error message with g_free.

Definition at line 741 of file qofbook.cpp.

742 {
743  const gchar *valid_formats [] = {
744  G_GINT64_FORMAT,
745  "lli",
746  "I64i",
747  PRIi64,
748  "li",
749  nullptr,
750  };
751  int i = 0;
752  gchar *normalized_spec = nullptr;
753 
754  while (valid_formats[i])
755  {
756 
757  if (err_msg && *err_msg)
758  {
759  g_free (*err_msg);
760  *err_msg = nullptr;
761  }
762 
763  normalized_spec = qof_book_normalize_counter_format_internal(p, valid_formats[i], err_msg);
764  if (normalized_spec)
765  return normalized_spec; /* Found a valid format specifier, return */
766  i++;
767  }
768 
769  return nullptr;
770 }
gchar * qof_book_normalize_counter_format_internal(const gchar *p, const gchar *gint64_format, gchar **err_msg)
Validate a counter format string with a given format specifier.
Definition: qofbook.cpp:773

◆ qof_book_options_delete()

void qof_book_options_delete ( QofBook *  book,
GSList *  path 
)

Delete the options.

Primarily used from Scheme to clear out the options before saving a new set.

Parameters
bookThe book.
listA GList of keys which from a path under KVP_OPTION_PATH. If GList is Null, the whole option is deleted.

Definition at line 1381 of file qofbook.cpp.

1382 {
1383  KvpFrame *root = qof_instance_get_slots(QOF_INSTANCE (book));
1384  if (path != nullptr)
1385  {
1386  Path path_v {str_KVP_OPTION_PATH};
1387  Path tmp_path;
1388  for (auto item = path; item != nullptr; item = g_slist_next(item))
1389  tmp_path.push_back(static_cast<const char*>(item->data));
1390  delete root->set_path(gslist_to_option_path(path), nullptr);
1391  }
1392  else
1393  delete root->set_path({str_KVP_OPTION_PATH}, nullptr);
1394 }

◆ qof_book_register()

gboolean qof_book_register ( void  )

Register the book object with the QOF object system.

Definition at line 1397 of file qofbook.cpp.

1398 {
1399  static QofParam params[] =
1400  {
1401  { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_entity_get_guid, nullptr },
1402  { QOF_PARAM_KVP, QOF_TYPE_KVP, (QofAccessFunc)qof_instance_get_slots, nullptr },
1403  { nullptr },
1404  };
1405 
1406  qof_class_register (QOF_ID_BOOK, nullptr, params);
1407 
1408  return TRUE;
1409 }
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.
Definition: qofclass.cpp:86
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
The QofAccessFunc defines an arbitrary function pointer for access functions.
Definition: qofclass.h:177
const GncGUID * qof_entity_get_guid(gconstpointer ent)
#define QOF_PARAM_KVP
"Known" Object Parameters – some objects might support these
Definition: qofquery.h:113

◆ qof_book_save_options()

void qof_book_save_options ( QofBook *  book,
GncOptionSave  save_cb,
GncOptionDB odb,
gboolean  clear 
)

Save a GncOptionsDB back to the book's KVP.

Parameters
bookThe book.
save_cbA callback function that does the saving.
odbThe GncOptionsDB to save from.
clearShould the GncOptionsDB be emptied after the save?

Definition at line 1322 of file qofbook.cpp.

1324 {
1325  /* Wrap this in begin/commit so that it commits only once instead of doing
1326  * so for every option. Qof_book_set_option will take care of dirtying the
1327  * book.
1328  */
1329  qof_book_begin_edit (book);
1330  save_cb (odb, book, clear);
1331  qof_book_commit_edit (book);
1332 }

◆ qof_book_session_not_saved()

gboolean qof_book_session_not_saved ( const QofBook *  book)

qof_book_not_saved() returns the value of the session_dirty flag, set when changes to any object in the book are committed (qof_backend->commit_edit has been called) and the backend hasn't yet written out the changes.

(Note that SQL backends write commits out immediately; file backends don't, and use the flag to control an autosave timer.)

Definition at line 375 of file qofbook.cpp.

376 {
377  if (!book) return FALSE;
378  return !qof_book_empty(book) && book->session_dirty;
379 
380 }
gboolean qof_book_empty(const QofBook *book)
Check if the book has had anything loaded into it.
Definition: qofbook.cpp:511

◆ qof_book_set_data()

void qof_book_set_data ( QofBook *  book,
const gchar *  key,
gpointer  data 
)

The qof_book_set_data() allows arbitrary pointers to structs to be stored in QofBook.

This is the "preferred" method for extending QofBook to hold new data types. This is also the ideal location to store other arbitrary runtime data that the application may need.

◆ qof_book_set_data_fin()

void qof_book_set_data_fin ( QofBook *  book,
const gchar *  key,
gpointer  data,
QofBookFinalCB   
)

Same as qof_book_set_data(), except that the callback will be called when the book is destroyed.

The argument to the callback will be the book followed by the data pointer.

◆ qof_book_set_option()

void qof_book_set_option ( QofBook *  book,
KvpValue *  value,
GSList *  path 
)

Save a single option value.

Used from Scheme, the KvpValue<–>SCM translation is handled by the functions in kvp-scm.c and automated by SWIG. The starting element is set as KVP_OPTION_PATH in qofbookslots.h.

Parameters
bookThe book.
valueThe KvpValue to store.
pathA GSList of keys which form a path under KVP_OPTION_PATH.

Definition at line 1361 of file qofbook.cpp.

1362 {
1363  KvpFrame *root = qof_instance_get_slots (QOF_INSTANCE (book));
1364  qof_book_begin_edit (book);
1365  delete root->set_path(gslist_to_option_path(path), value);
1366  qof_instance_set_dirty (QOF_INSTANCE (book));
1367  qof_book_commit_edit (book);
1368 
1369  // Also, mark any cached value as invalid
1370  book->cached_num_field_source_isvalid = FALSE;
1371 }

◆ qof_book_uses_autoreadonly()

gboolean qof_book_uses_autoreadonly ( const QofBook *  book)

Returns TRUE if the auto-read-only feature should be used, otherwise FALSE.

This is just a wrapper on qof_book_get_num_days_autoreadonly() == 0.

Definition at line 962 of file qofbook.cpp.

963 {
964  g_assert(book);
965  return (qof_book_get_num_days_autoreadonly(book) != 0);
966 }
gint qof_book_get_num_days_autoreadonly(const QofBook *book)
Returns the number of days for auto-read-only transactions.
Definition: qofbook.cpp:968