gnucash stable: [qofbook.h] add further getters/setters for QofBook

Christopher Lam clam at code.gnucash.org
Tue Jun 9 21:46:28 EDT 2026


Updated	 via  https://github.com/Gnucash/gnucash/commit/db6cac5b (commit)
	from  https://github.com/Gnucash/gnucash/commit/f3c053fb (commit)



commit db6cac5b8291f513651f7ff813d329c587fac111
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Jun 7 08:40:07 2026 +0800

    [qofbook.h] add further getters/setters for QofBook

diff --git a/gnucash/gnome-utils/gnc-main-window.cpp b/gnucash/gnome-utils/gnc-main-window.cpp
index 84d87a4505..b836392a27 100644
--- a/gnucash/gnome-utils/gnc-main-window.cpp
+++ b/gnucash/gnome-utils/gnc-main-window.cpp
@@ -4664,7 +4664,7 @@ gnc_book_options_dialog_apply_helper(GncOptionDB * options)
         qof_book_use_split_action_for_num_field (book);
 
     // mark cached value as invalid so we get new value
-    book->cached_num_days_autoreadonly_isvalid = FALSE;
+    qof_book_reset_num_days_autoreadonly_cache (book);
     use_read_only_threshold_after = qof_book_get_num_days_autoreadonly (book);
 
     if (use_split_action_for_num_before != use_split_action_for_num_after)
diff --git a/libgnucash/engine/qofbook.cpp b/libgnucash/engine/qofbook.cpp
index 399309827e..67cccfc854 100644
--- a/libgnucash/engine/qofbook.cpp
+++ b/libgnucash/engine/qofbook.cpp
@@ -576,6 +576,18 @@ void qof_book_mark_closed (QofBook *book)
     book->book_open = 'n';
 }
 
+gboolean qof_book_is_open (const QofBook *book)
+{
+    g_return_val_if_fail (book, FALSE);
+    return book->book_open == 'y';
+}
+
+void qof_book_swap_books_readonly (QofBook *book, QofBook *other)
+{
+    g_return_if_fail (book && other);
+    std::swap (book->read_only, other->read_only);
+}
+
 gint64
 qof_book_get_counter (QofBook *book, const char *counter_name)
 {
@@ -965,6 +977,12 @@ gboolean qof_book_uses_autoreadonly (const QofBook *book)
     return (qof_book_get_num_days_autoreadonly(book) != 0);
 }
 
+void qof_book_reset_num_days_autoreadonly_cache (QofBook *book)
+{
+    g_return_if_fail (book);
+    book->cached_num_days_autoreadonly_isvalid = FALSE;
+}
+
 gint qof_book_get_num_days_autoreadonly (const QofBook *book)
 {
     g_assert(book);
diff --git a/libgnucash/engine/qofbook.h b/libgnucash/engine/qofbook.h
index 0b2d663639..6a5ce8d0c8 100644
--- a/libgnucash/engine/qofbook.h
+++ b/libgnucash/engine/qofbook.h
@@ -218,6 +218,10 @@ and once marked closed, books cannot be marked as open.
 */
 void qof_book_mark_closed (QofBook *book);
 
+gboolean qof_book_is_open (const QofBook *book);
+
+void qof_book_swap_books_readonly (QofBook *book, QofBook *other);
+
 /** Return The table of entities of the given type.
  *
  *  When an object's constructor calls qof_instance_init(), a
@@ -270,6 +274,8 @@ gboolean qof_book_empty(const QofBook *book);
 /** Returns flag indicating whether this book uses trading accounts */
 gboolean qof_book_use_trading_accounts (const QofBook *book);
 
+void qof_book_reset_num_days_autoreadonly_cache (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. */
 gboolean qof_book_uses_autoreadonly (const QofBook *book);
diff --git a/libgnucash/engine/qofsession.cpp b/libgnucash/engine/qofsession.cpp
index 81392db879..b7f43a1d29 100644
--- a/libgnucash/engine/qofsession.cpp
+++ b/libgnucash/engine/qofsession.cpp
@@ -401,7 +401,7 @@ QofBook *
 QofSessionImpl::get_book () const noexcept
 {
     if (!m_book) return nullptr;
-    if ('y' == m_book->book_open)
+    if (qof_book_is_open (m_book))
         return m_book;
     return nullptr;
 }
@@ -508,7 +508,7 @@ QofSessionImpl::swap_books (QofSessionImpl & other) noexcept
     ENTER ("sess1=%p sess2=%p", this, &other);
     // don't swap (that is, double-swap) read_only flags
     if (m_book && other.m_book)
-        std::swap (m_book->read_only, other.m_book->read_only);
+        qof_book_swap_books_readonly (m_book, other.m_book);
     std::swap (m_book, other.m_book);
     auto mybackend = qof_book_get_backend (m_book);
     qof_book_set_backend (m_book, qof_book_get_backend (other.m_book));



Summary of changes:
 gnucash/gnome-utils/gnc-main-window.cpp |  2 +-
 libgnucash/engine/qofbook.cpp           | 18 ++++++++++++++++++
 libgnucash/engine/qofbook.h             |  6 ++++++
 libgnucash/engine/qofsession.cpp        |  4 ++--
 4 files changed, 27 insertions(+), 3 deletions(-)



More information about the gnucash-changes mailing list