GnuCash  4.8a-176-g88ecf8dd1
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.
 
const gchar * qof_book_get_book_currency_name (QofBook *book)
 Returns pointer to book-currency name for book, if one exists in the KVP, or NULL; does not validate contents nor determine if there is a valid default gain/loss policy, both of which are required, for the 'book-currency' currency accounting method to apply. More...
 
const gchar * qof_book_get_default_gains_policy (QofBook *book)
 Returns pointer to default gain/loss policy for book, if one exists in the KVP, or NULL; does not validate contents nor determine if there is a valid book-currency, both of which are required, for the 'book-currency' currency accounting method to apply. More...
 
GncGUIDqof_book_get_default_gain_loss_acct_guid (QofBook *book)
 Returns pointer to default gain/loss account GUID for book, if one exists in the KVP, or NULL; does not validate contents nor determine if there is a valid book-currency, both of which are required, for the 'book-currency' currency accounting method to apply. More...
 
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...
 
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_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:215
QofCollection * qof_book_get_collection(const QofBook *, QofIdType)
Return The table of entities of the given type.
Definition: qofbook.cpp:604

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 183 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 235 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 419 of file qofbook.cpp.

420 {
421  GHashTable* cols;
422 
423  if (!book) return;
424  ENTER ("book=%p", book);
425 
426  book->shutting_down = TRUE;
427  qof_event_force (&book->inst, QOF_EVENT_DESTROY, NULL);
428 
429  /* Call the list of finalizers, let them do their thing.
430  * Do this before tearing into the rest of the book.
431  */
432  g_hash_table_foreach (book->data_table_finalizers, book_final, book);
433 
434  qof_object_book_end (book);
435 
436  g_hash_table_destroy (book->data_table_finalizers);
437  book->data_table_finalizers = NULL;
438  g_hash_table_destroy (book->data_tables);
439  book->data_tables = NULL;
440 
441  /* qof_instance_release (&book->inst); */
442 
443  /* Note: we need to save this hashtable until after we remove ourself
444  * from it, otherwise we'll crash in our dispose() function when we
445  * DO remove ourself from the collection but the collection had already
446  * been destroyed.
447  */
448  cols = book->hash_of_collections;
449  g_object_unref (book);
450  g_hash_table_destroy (cols);
451  /*book->hash_of_collections = NULL;*/
452 
453  LEAVE ("book=%p", book);
454 }
#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

◆ qof_book_empty()

gboolean qof_book_empty ( const QofBook *  book)

Check if the book has had anything loaded into it.

Definition at line 594 of file qofbook.cpp.

595 {
596  if (!book) return TRUE;
597  auto root_acct_col = qof_book_get_collection (book, GNC_ID_ROOT_ACCOUNT);
598  return qof_collection_get_data(root_acct_col) == nullptr;
599 }
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
Definition: qofbook.cpp:604
gpointer qof_collection_get_data(const QofCollection *col)
Store and retrieve arbitrary object-defined data.
Definition: qofid.cpp:291

◆ 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 1112 of file qofbook.cpp.

1113 {
1114  gint num_days;
1115  GDate* result = NULL;
1116 
1117  g_assert(book);
1118  num_days = qof_book_get_num_days_autoreadonly(book);
1119  if (num_days > 0)
1120  {
1121  result = gnc_g_date_new_today();
1122  g_date_subtract_days(result, num_days);
1123  }
1124  return result;
1125 }
gint qof_book_get_num_days_autoreadonly(const QofBook *book)
Returns the number of days for auto-read-only transactions.
Definition: qofbook.cpp:1092
GDate * gnc_g_date_new_today()
Returns a newly allocated date of the current clock time, taken from time(2).
Definition: gnc-date.cpp:1229

◆ qof_book_get_book_currency_name()

const gchar* qof_book_get_book_currency_name ( QofBook *  book)

Returns pointer to book-currency name for book, if one exists in the KVP, or NULL; does not validate contents nor determine if there is a valid default gain/loss policy, both of which are required, for the 'book-currency' currency accounting method to apply.

Use instead 'gnc_book_get_book_currency_name' which does these validations.

Definition at line 991 of file qofbook.cpp.

992 {
993  const gchar *opt = NULL;
994  qof_instance_get (QOF_INSTANCE (book),
995  "book-currency", &opt,
996  NULL);
997  return opt;
998 }
void qof_instance_get(const QofInstance *inst, const gchar *first_prop,...)
Wrapper for g_object_get.

◆ 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 604 of file qofbook.cpp.

605 {
606  QofCollection *col;
607 
608  if (!book || !entity_type) return NULL;
609 
610  col = static_cast<QofCollection*>(g_hash_table_lookup (book->hash_of_collections, entity_type));
611  if (!col)
612  {
613  col = qof_collection_new (entity_type);
614  g_hash_table_insert(
615  book->hash_of_collections,
616  (gpointer)qof_string_cache_insert(entity_type), col);
617  }
618  return col;
619 }
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:51

◆ 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 663 of file qofbook.cpp.

664 {
665  KvpFrame *kvp;
666  KvpValue *value;
667 
668  if (!book)
669  {
670  PWARN ("No book!!!");
671  return -1;
672  }
673 
674  if (!counter_name || *counter_name == '\0')
675  {
676  PWARN ("Invalid counter name.");
677  return -1;
678  }
679 
680  /* Use the KVP in the book */
681  kvp = qof_instance_get_slots (QOF_INSTANCE (book));
682 
683  if (!kvp)
684  {
685  PWARN ("Book has no KVP_Frame");
686  return -1;
687  }
688 
689  value = kvp->get_slot({"counters", counter_name});
690  if (value)
691  {
692  /* found it */
693  return value->get<int64_t>();
694  }
695  else
696  {
697  /* New counter */
698  return 0;
699  }
700 }
#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 764 of file qofbook.cpp.

765 {
766  KvpFrame *kvp;
767  const char *user_format = NULL;
768  gchar *norm_format = NULL;
769  KvpValue *value;
770  gchar *error = NULL;
771 
772  if (!book)
773  {
774  PWARN ("No book!!!");
775  return NULL;
776  }
777 
778  if (!counter_name || *counter_name == '\0')
779  {
780  PWARN ("Invalid counter name.");
781  return NULL;
782  }
783 
784  /* Get the KVP from the current book */
785  kvp = qof_instance_get_slots (QOF_INSTANCE (book));
786 
787  if (!kvp)
788  {
789  PWARN ("Book has no KVP_Frame");
790  return NULL;
791  }
792 
793  /* Get the format string */
794  value = kvp->get_slot({"counter_formats", counter_name});
795  if (value)
796  {
797  user_format = value->get<const char*>();
798  norm_format = qof_book_normalize_counter_format(user_format, &error);
799  if (!norm_format)
800  {
801  PWARN("Invalid counter format string. Format string: '%s' Counter: '%s' Error: '%s')", user_format, counter_name, error);
802  /* Invalid format string */
803  user_format = NULL;
804  g_free(error);
805  }
806  }
807 
808  /* If no (valid) format string was found, use the default format
809  * string */
810  if (!norm_format)
811  {
812  /* Use the default format */
813  norm_format = g_strdup ("%.6" PRIi64);
814  }
815  return norm_format;
816 }
#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:819

◆ 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_default_gain_loss_acct_guid()

GncGUID* qof_book_get_default_gain_loss_acct_guid ( QofBook *  book)

Returns pointer to default gain/loss account GUID for book, if one exists in the KVP, or NULL; does not validate contents nor determine if there is a valid book-currency, both of which are required, for the 'book-currency' currency accounting method to apply.

Use instead 'gnc_book_get_default_gain_loss_acct' which does these validations.

Definition at line 1021 of file qofbook.cpp.

1022 {
1023  GncGUID *guid = NULL;
1024  qof_instance_get (QOF_INSTANCE (book),
1025  "default-gain-loss-account-guid", &guid,
1026  NULL);
1027  return guid;
1028 
1029 }
void qof_instance_get(const QofInstance *inst, const gchar *first_prop,...)
Wrapper for g_object_get.
The type used to store guids in C.
Definition: guid.h:75

◆ qof_book_get_default_gains_policy()

const gchar* qof_book_get_default_gains_policy ( QofBook *  book)

Returns pointer to default gain/loss policy for book, if one exists in the KVP, or NULL; does not validate contents nor determine if there is a valid book-currency, both of which are required, for the 'book-currency' currency accounting method to apply.

Use instead 'gnc_book_get_default_gains_policy' which does these validations.

Definition at line 1006 of file qofbook.cpp.

1007 {
1008  const gchar *opt = NULL;
1009  qof_instance_get (QOF_INSTANCE (book),
1010  "default-gains-policy", &opt,
1011  NULL);
1012  return opt;
1013 }
void qof_instance_get(const QofInstance *inst, const gchar *first_prop,...)
Wrapper for g_object_get.

◆ 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 1092 of file qofbook.cpp.

1093 {
1094  g_assert(book);
1095 
1096  if (!book->cached_num_days_autoreadonly_isvalid)
1097  {
1098  double tmp;
1099 
1100  // No cached value? Then do the expensive KVP lookup
1101  qof_instance_get (QOF_INSTANCE (book),
1102  PARAM_NAME_NUM_AUTOREAD_ONLY, &tmp,
1103  NULL);
1104 
1105  const_cast<QofBook*>(book)->cached_num_days_autoreadonly = tmp;
1106  const_cast<QofBook*>(book)->cached_num_days_autoreadonly_isvalid = TRUE;
1107  }
1108  // Value is cached now. Use the cheap variable returning.
1109  return (gint) book->cached_num_days_autoreadonly;
1110 }
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 1317 of file qofbook.cpp.

1318 {
1319  KvpFrame *root = qof_instance_get_slots(QOF_INSTANCE (book));
1320  return root->get_slot(gslist_to_option_path(path));
1321 }

◆ 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 504 of file qofbook.cpp.

505 {
506  return book->dirty_time;
507 }

◆ 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 703 of file qofbook.cpp.

704 {
705  KvpFrame *kvp;
706  KvpValue *value;
707  gint64 counter;
708  gchar* format;
709  gchar* result;
710 
711  if (!book)
712  {
713  PWARN ("No book!!!");
714  return NULL;
715  }
716 
717  if (!counter_name || *counter_name == '\0')
718  {
719  PWARN ("Invalid counter name.");
720  return NULL;
721  }
722 
723  /* Get the current counter value from the KVP in the book. */
724  counter = qof_book_get_counter(book, counter_name);
725 
726  /* Check if an error occurred */
727  if (counter < 0)
728  return NULL;
729 
730  /* Increment the counter */
731  counter++;
732 
733  /* Get the KVP from the current book */
734  kvp = qof_instance_get_slots (QOF_INSTANCE (book));
735 
736  if (!kvp)
737  {
738  PWARN ("Book has no KVP_Frame");
739  return NULL;
740  }
741 
742  /* Save off the new counter */
743  qof_book_begin_edit(book);
744  value = new KvpValue(counter);
745  delete kvp->set_path({"counters", counter_name}, value);
746  qof_instance_set_dirty (QOF_INSTANCE (book));
747  qof_book_commit_edit(book);
748 
749  format = qof_book_get_counter_format(book, counter_name);
750 
751  if (!format)
752  {
753  PWARN("Cannot get format for counter");
754  return NULL;
755  }
756 
757  /* Generate a string version of the counter */
758  result = g_strdup_printf(format, counter);
759  g_free (format);
760  return result;
761 }
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:764
#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:663

◆ qof_book_is_readonly()

gboolean qof_book_is_readonly ( const QofBook *  book)

Return whether the book is read only.

Definition at line 580 of file qofbook.cpp.

581 {
582  g_return_val_if_fail( book != NULL, TRUE );
583  return book->read_only;
584 }

◆ 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 653 of file qofbook.cpp.

654 {
655  if (!book)
656  {
657  return;
658  }
659  book->book_open = 'n';
660 }

◆ qof_book_mark_readonly()

void qof_book_mark_readonly ( QofBook *  book)

Mark the book as read only.

Definition at line 587 of file qofbook.cpp.

588 {
589  g_return_if_fail( book != NULL );
590  book->read_only = TRUE;
591 }

◆ 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 481 of file qofbook.cpp.

482 {
483  if (!book) return;
484  if (!book->session_dirty)
485  {
486  /* Set the session dirty upfront, because the callback will check. */
487  book->session_dirty = TRUE;
488  book->dirty_time = gnc_time (NULL);
489  if (book->dirty_cb)
490  book->dirty_cb(book, TRUE, book->dirty_data);
491  }
492 }
time64 gnc_time(time64 *tbuf)
get the current local time
Definition: gnc-date.cpp:273

◆ 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 467 of file qofbook.cpp.

468 {
469  if (!book) return;
470 
471  book->dirty_time = 0;
472  if (book->session_dirty)
473  {
474  /* Set the session clean upfront, because the callback will check. */
475  book->session_dirty = FALSE;
476  if (book->dirty_cb)
477  book->dirty_cb(book, FALSE, book->dirty_data);
478  }
479 }

◆ 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 385 of file qofbook.cpp.

386 {
387  QofBook *book;
388 
389  ENTER (" ");
390  book = static_cast<QofBook*>(g_object_new(QOF_TYPE_BOOK, NULL));
391  qof_object_book_begin (book);
392 
393  qof_event_gen (&book->inst, QOF_EVENT_CREATE, NULL);
394  LEAVE ("book=%p", book);
395  return book;
396 }
void qof_object_book_begin(QofBook *book)
To be called from within the book.
Definition: qofobject.cpp:92
#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 819 of file qofbook.cpp.

820 {
821  const gchar *valid_formats [] = {
822  G_GINT64_FORMAT,
823  "lli",
824  "I64i",
825  PRIi64,
826  "li",
827  NULL,
828  };
829  int i = 0;
830  gchar *normalized_spec = NULL;
831 
832  while (valid_formats[i])
833  {
834 
835  if (err_msg && *err_msg)
836  {
837  g_free (*err_msg);
838  *err_msg = NULL;
839  }
840 
841  normalized_spec = qof_book_normalize_counter_format_internal(p, valid_formats[i], err_msg);
842  if (normalized_spec)
843  return normalized_spec; /* Found a valid format specifier, return */
844  i++;
845  }
846 
847  return NULL;
848 }
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:851

◆ 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 1324 of file qofbook.cpp.

1325 {
1326  KvpFrame *root = qof_instance_get_slots(QOF_INSTANCE (book));
1327  if (path != nullptr)
1328  {
1329  Path path_v {str_KVP_OPTION_PATH};
1330  Path tmp_path;
1331  for (auto item = path; item != nullptr; item = g_slist_next(item))
1332  tmp_path.push_back(static_cast<const char*>(item->data));
1333  delete root->set_path(gslist_to_option_path(path), nullptr);
1334  }
1335  else
1336  delete root->set_path({str_KVP_OPTION_PATH}, nullptr);
1337 }

◆ qof_book_register()

gboolean qof_book_register ( void  )

Register the book object with the QOF object system.

Definition at line 1340 of file qofbook.cpp.

1341 {
1342  static QofParam params[] =
1343  {
1344  { QOF_PARAM_GUID, QOF_TYPE_GUID, (QofAccessFunc)qof_entity_get_guid, NULL },
1345  { QOF_PARAM_KVP, QOF_TYPE_KVP, (QofAccessFunc)qof_instance_get_slots, NULL },
1346  { NULL },
1347  };
1348 
1349  qof_class_register (QOF_ID_BOOK, NULL, params);
1350 
1351  return TRUE;
1352 }
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 1265 of file qofbook.cpp.

1267 {
1268  /* Wrap this in begin/commit so that it commits only once instead of doing
1269  * so for every option. Qof_book_set_option will take care of dirtying the
1270  * book.
1271  */
1272  qof_book_begin_edit (book);
1273  save_cb (odb, book, clear);
1274  qof_book_commit_edit (book);
1275 }

◆ 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 459 of file qofbook.cpp.

460 {
461  if (!book) return FALSE;
462  return !qof_book_empty(book) && book->session_dirty;
463 
464 }
gboolean qof_book_empty(const QofBook *book)
Check if the book has had anything loaded into it.
Definition: qofbook.cpp:594

◆ 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 1304 of file qofbook.cpp.

1305 {
1306  KvpFrame *root = qof_instance_get_slots (QOF_INSTANCE (book));
1307  qof_book_begin_edit (book);
1308  delete root->set_path(gslist_to_option_path(path), value);
1309  qof_instance_set_dirty (QOF_INSTANCE (book));
1310  qof_book_commit_edit (book);
1311 
1312  // Also, mark any cached value as invalid
1313  book->cached_num_field_source_isvalid = FALSE;
1314 }

◆ 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 1086 of file qofbook.cpp.

1087 {
1088  g_assert(book);
1089  return (qof_book_get_num_days_autoreadonly(book) != 0);
1090 }
gint qof_book_get_num_days_autoreadonly(const QofBook *book)
Returns the number of days for auto-read-only transactions.
Definition: qofbook.cpp:1092