Add is_readonly attribute to QofSession class.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21517 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming
2011-11-03 21:48:00 +00:00
parent 2e7198f309
commit 4a5ec547e8
3 changed files with 36 additions and 0 deletions
+1
View File
@@ -64,6 +64,7 @@ struct _QofSession
* between the persistant store and the local engine. */
QofBackend *backend;
gint lock;
gboolean is_readonly;
};
+29
View File
@@ -218,6 +218,7 @@ qof_session_init (QofSession *session)
session->book_id = NULL;
session->backend = NULL;
session->lock = 1;
session->is_readonly = FALSE;
qof_session_clear_error (session);
}
@@ -285,6 +286,18 @@ qof_session_get_backend (const QofSession *session)
return session->backend;
}
gboolean qof_session_is_readonly(const QofSession * session)
{
g_assert(session);
return session->is_readonly;
}
void qof_session_set_readonly(QofSession* session, gboolean is_readonly)
{
g_assert(session);
session->is_readonly = is_readonly;
}
const char *
qof_session_get_file_path (const QofSession *session)
{
@@ -649,6 +662,15 @@ qof_session_save (QofSession *session,
session, session->book_id ? session->book_id : "(null)");
/* Partial book handling. */
book = qof_session_get_book(session);
if (qof_session_is_readonly(session) || qof_book_is_readonly(book))
{
// Well, we are read-only, so saving is not allowed.
msg = g_strdup_printf("session is marked as read-only");
qof_session_push_error(session, ERR_BACKEND_READONLY, msg);
goto leave;
}
partial = (gboolean)GPOINTER_TO_INT(qof_book_get_data(book, PARTIAL_QOFBOOK));
change_backend = FALSE;
msg = g_strdup_printf(" ");
@@ -800,6 +822,13 @@ qof_session_safe_save(QofSession *session, QofPercentageFunc percentage_func)
char *msg = NULL;
g_return_if_fail( be != NULL );
g_return_if_fail( be->safe_sync != NULL );
if (qof_session_is_readonly(session))
{
// Well, we are read-only, so saving is not allowed.
qof_session_push_error(session, ERR_BACKEND_READONLY, "session is marked as read-only");
return;
}
be->percentage = percentage_func;
(be->safe_sync)( be, qof_session_get_book( session ));
err = qof_backend_get_error(session->backend);
+6
View File
@@ -219,6 +219,12 @@ const char * qof_session_get_file_path (const QofSession *session);
const char * qof_session_get_url (const QofSession *session);
/** Returns TRUE if this session is marked as read-only, otherwise FALSE. */
gboolean qof_session_is_readonly(const QofSession * session);
/** Sets the is_readonly value to the given value. */
void qof_session_set_readonly(QofSession* session, gboolean is_readonly);
/**
* The qof_session_not_saved() subroutine will return TRUE
* if any data in the session hasn't been saved to long-term storage.