Skip to content

Commit

Permalink
Bug 355496 - Indication of Read Only Register
Browse files Browse the repository at this point in the history
Currently a read only register allows you to do a lot of actions like
duplicate transaction, delete transactions, schedule transactions and
more. This commit adds a check for the register being read only and
disable all the actions that would be for a read only book.
  • Loading branch information
Bob-IT committed Dec 10, 2020
1 parent f0fc1e5 commit f3eae75
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 55 deletions.
117 changes: 70 additions & 47 deletions gnucash/gnome/gnc-plugin-page-register.c
Expand Up @@ -1086,7 +1086,7 @@ gnc_plugin_page_register_ui_update (gpointer various,
GncPluginPageRegisterPrivate* priv;
SplitRegister* reg;
GtkAction* action;
gboolean expanded, voided, read_only = FALSE;
gboolean expanded, voided, read_only = FALSE, read_only_reg = FALSE;
Transaction* trans;
GList* invoices;
CursorClass cursor_class;
Expand All @@ -1106,78 +1106,101 @@ gnc_plugin_page_register_ui_update (gpointer various,
g_signal_handlers_unblock_by_func
(action, gnc_plugin_page_register_cmd_expand_transaction, page);

/* If we are in a readonly book, or possibly a place holder
* account register make any modifying action inactive */
if (qof_book_is_readonly (gnc_get_current_book()) ||
gnc_split_reg_get_read_only (priv->gsr))
read_only_reg = TRUE;

/* Set available actions based on read only */
trans = gnc_split_register_get_current_trans (reg);

if (trans)
read_only = xaccTransIsReadonlyByPostedDate (trans);
voided = xaccTransHasSplitsInState (trans, VREC);
/* If the register is not read only, make any modifying action active
* to start with */
if (!read_only_reg)
{
const char** iter;
for (iter = readonly_inactive_actions; *iter; ++iter)
{
/* Set the action's sensitivity */
GtkAction* action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page), *iter);
gtk_action_set_sensitive (action, TRUE);
}

action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page),
"CutTransactionAction");
gtk_action_set_sensitive (GTK_ACTION (action), !read_only & !voided);
if (trans)
read_only = xaccTransIsReadonlyByPostedDate (trans);

action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page),
"PasteTransactionAction");
gtk_action_set_sensitive (GTK_ACTION (action), !read_only & !voided);
voided = xaccTransHasSplitsInState (trans, VREC);

action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page),
"DeleteTransactionAction");
gtk_action_set_sensitive (GTK_ACTION (action), !read_only & !voided);
action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page),
"CutTransactionAction");
gtk_action_set_sensitive (GTK_ACTION (action), !read_only & !voided);

action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page),
"DuplicateTransactionAction");
gtk_action_set_sensitive (GTK_ACTION (action), TRUE);
action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page),
"PasteTransactionAction");
gtk_action_set_sensitive (GTK_ACTION (action), !read_only & !voided);

if (cursor_class == CURSOR_CLASS_SPLIT)
{
action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page),
"DuplicateTransactionAction");
"DeleteTransactionAction");
gtk_action_set_sensitive (GTK_ACTION (action), !read_only & !voided);
}

action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page),
"RemoveTransactionSplitsAction");
gtk_action_set_sensitive (GTK_ACTION (action), !read_only & !voided);
action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page),
"DuplicateTransactionAction");
gtk_action_set_sensitive (GTK_ACTION (action), !read_only & TRUE);

/* Set 'Void' and 'Unvoid' */
if (read_only)
voided = TRUE;
if (cursor_class == CURSOR_CLASS_SPLIT)
{
action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page),
"DuplicateTransactionAction");
gtk_action_set_sensitive (GTK_ACTION (action), !read_only & !voided);
}

action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page),
"VoidTransactionAction");
gtk_action_set_sensitive (GTK_ACTION (action), !voided);
action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page),
"RemoveTransactionSplitsAction");
gtk_action_set_sensitive (GTK_ACTION (action), !read_only & !voided);

if (read_only)
voided = FALSE;
/* Set 'Void' and 'Unvoid' */
if (read_only)
voided = TRUE;

action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page),
"UnvoidTransactionAction");
gtk_action_set_sensitive (GTK_ACTION (action), voided);
action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page),
"VoidTransactionAction");
gtk_action_set_sensitive (GTK_ACTION (action), !voided);

/* Set 'Open and Remove Linked Documents' */
uri = xaccTransGetDocLink (trans);
if (read_only)
voided = FALSE;

action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page),
"UnvoidTransactionAction");
gtk_action_set_sensitive (GTK_ACTION (action), voided);
}

/* Set 'Open and Remove Linked Documents' */
action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE(page),
"LinkedTransactionOpenAction");
gtk_action_set_sensitive (GTK_ACTION(action), (uri ? TRUE:FALSE));

if (trans)
{
uri = xaccTransGetDocLink (trans);
gtk_action_set_sensitive (GTK_ACTION(action), (uri ? TRUE:FALSE));
}
/* Set 'ExecAssociatedInvoice'
We can determine an invoice from a txn if either
- it is an invoice transaction
- it has splits with an invoice associated with it
*/
action = gnc_plugin_page_get_action (GNC_PLUGIN_PAGE (page),
"JumpLinkedInvoiceAction");

invoices = invoices_from_transaction (trans);
gtk_action_set_sensitive (GTK_ACTION (action), (invoices != NULL));
g_list_free (invoices);
if (trans)
{
invoices = invoices_from_transaction (trans);
gtk_action_set_sensitive (GTK_ACTION (action), (invoices != NULL));
g_list_free (invoices);
}

gnc_plugin_business_split_reg_ui_update (GNC_PLUGIN_PAGE (page));

/* If we are in a readonly book, make any modifying action inactive */
if (qof_book_is_readonly (gnc_get_current_book()))
/* If we are read only, make any modifying action inactive */
if (read_only_reg)
{
const char** iter;
for (iter = readonly_inactive_actions; *iter; ++iter)
Expand Down Expand Up @@ -1937,7 +1960,7 @@ finish_scrub (GncPluginPage* page)
(GNC_PLUGIN_PAGE(page))),
FALSE,
_("'Check & Repair' is currently running, do you want to abort it?"));

show_abort_verify = FALSE;

if (ret)
Expand Down Expand Up @@ -5020,10 +5043,10 @@ scrub_kp_handler (GtkWidget *widget, GdkEventKey *event, gpointer data)
{
gboolean abort_scrub = gnc_verify_dialog (GTK_WINDOW(widget), FALSE,
_("'Check & Repair' is currently running, do you want to abort it?"));

if (abort_scrub)
gnc_set_abort_scrub (TRUE);

return TRUE;
}
default:
Expand Down
18 changes: 14 additions & 4 deletions gnucash/gnome/gnc-split-reg.c
Expand Up @@ -73,7 +73,7 @@ static GtkWidget* add_summary_label( GtkWidget *summarybar, gboolean pack_start,

static void gsr_summarybar_set_arrow_draw (GNCSplitReg *gsr);

static void gnc_split_reg_determine_read_only( GNCSplitReg *gsr );
static void gnc_split_reg_determine_read_only( GNCSplitReg *gsr, gboolean show_dialog );
static gboolean is_trans_readonly_and_warn (GtkWindow *parent, Transaction *trans);

static GNCPlaceholderType gnc_split_reg_get_placeholder( GNCSplitReg *gsr );
Expand Down Expand Up @@ -378,7 +378,7 @@ gnc_split_reg_init2( GNCSplitReg *gsr )
{
if ( !gsr ) return;

gnc_split_reg_determine_read_only( gsr );
gnc_split_reg_determine_read_only( gsr, TRUE );

gsr_setup_status_widgets( gsr );
/* ordering is important here... setup_status before create_table */
Expand Down Expand Up @@ -2488,7 +2488,7 @@ gtk_callback_bug_workaround (gpointer argp)
**/
static
void
gnc_split_reg_determine_read_only( GNCSplitReg *gsr )
gnc_split_reg_determine_read_only( GNCSplitReg *gsr, gboolean show_dialog )
{
SplitRegister *reg;

Expand Down Expand Up @@ -2542,7 +2542,8 @@ gnc_split_reg_determine_read_only( GNCSplitReg *gsr )
args = g_malloc(sizeof(dialog_args));
args->string = string;
args->gsr = gsr;
g_timeout_add (250, gtk_callback_bug_workaround, args); /* 0.25 seconds */
if (show_dialog)
g_timeout_add (250, gtk_callback_bug_workaround, args); /* 0.25 seconds */
}

/* Make the contents immutable */
Expand Down Expand Up @@ -2631,7 +2632,16 @@ gnc_split_reg_get_summarybar( GNCSplitReg *gsr )
gboolean
gnc_split_reg_get_read_only( GNCSplitReg *gsr )
{
SplitRegister *reg;

g_assert( gsr );

// reset read_only flag
gsr->read_only = FALSE;
gnc_split_reg_determine_read_only (gsr, FALSE);

reg = gnc_ledger_display_get_split_register( gsr->ledger );
gnc_split_register_set_read_only( reg, gsr->read_only );
return gsr->read_only;
}

Expand Down
13 changes: 9 additions & 4 deletions gnucash/gnome/gnc-split-reg2.c
Expand Up @@ -53,7 +53,7 @@ void gnc_split_reg2_raise (GNCSplitReg2 *gsr);
static GtkWidget* add_summary_label (GtkWidget *summarybar,
const char *label_str);

static void gnc_split_reg2_determine_read_only (GNCSplitReg2 *gsr);
static void gnc_split_reg2_determine_read_only (GNCSplitReg2 *gsr, gboolean show_dialog);

static void gnc_split_reg2_determine_account_pr (GNCSplitReg2 *gsr);

Expand Down Expand Up @@ -200,7 +200,7 @@ gnc_split_reg2_init2 (GNCSplitReg2 *gsr)
{
if (!gsr) return;

gnc_split_reg2_determine_read_only (gsr);
gnc_split_reg2_determine_read_only (gsr, TRUE);

gnc_split_reg2_determine_account_pr (gsr);

Expand Down Expand Up @@ -978,7 +978,7 @@ gtk_callback_bug_workaround (gpointer argp)
**/
static
void
gnc_split_reg2_determine_read_only (GNCSplitReg2 *gsr) //this works
gnc_split_reg2_determine_read_only (GNCSplitReg2 *gsr, gboolean show_dialog)
{

if (qof_book_is_readonly (gnc_get_current_book()))
Expand Down Expand Up @@ -1018,7 +1018,8 @@ gnc_split_reg2_determine_read_only (GNCSplitReg2 *gsr) //this works
gsr->read_only = TRUE;
/* Put up a warning dialog */
args->gsr = gsr;
g_timeout_add (250, gtk_callback_bug_workaround, args); /* 0.25 seconds */
if (show_dialog)
g_timeout_add (250, gtk_callback_bug_workaround, args); /* 0.25 seconds */
}
}

Expand Down Expand Up @@ -1125,6 +1126,10 @@ gboolean
gnc_split_reg2_get_read_only (GNCSplitReg2 *gsr)
{
g_assert (gsr);

// reset read_only flag
gsr->read_only = FALSE;
gnc_split_reg2_determine_read_only (gsr, FALSE);
return gsr->read_only;
}

Expand Down

0 comments on commit f3eae75

Please sign in to comment.