Skip to content

Commit

Permalink
Change default invoice report dialog
Browse files Browse the repository at this point in the history
If selected default invoice report is missing, hide the timeout and
wait for user selection.
  • Loading branch information
Bob-IT committed Feb 5, 2023
1 parent 45a0746 commit 6946d21
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 16 deletions.
14 changes: 14 additions & 0 deletions gnucash/gnome-utils/gnc-report-combo.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,20 @@ gnc_report_combo_set_active_guid_name (GncReportCombo *grc,
}
}

gboolean
gnc_report_combo_is_warning_visible_for_active (GncReportCombo *grc)
{
GncReportComboPrivate *priv;
gboolean missing = FALSE;

g_return_val_if_fail (grc != NULL, FALSE);
g_return_val_if_fail (GNC_IS_REPORT_COMBO(grc), FALSE);

priv = GET_PRIVATE(grc);

return gtk_widget_is_visible (GTK_WIDGET(priv->warning_image));
}

static void
combo_changed_cb (GtkComboBox *widget, gpointer user_data)
{
Expand Down
10 changes: 9 additions & 1 deletion gnucash/gnome-utils/gnc-report-combo.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ gchar * gnc_report_combo_get_active_name (GncReportCombo *grc);

/** Set the active report to the guid string
*
* @param combo The GtkComboBox that presents the list.
* @param grc The report combo widget.
*
* @param guid_name The concatination of the guid/name of the Invoice Report
*/
Expand All @@ -120,4 +120,12 @@ void gnc_report_combo_set_active_guid_name (GncReportCombo *grc,
*/
gchar * gnc_report_combo_get_active_guid_name (GncReportCombo *grc);

/** Is the warning displayed for active entry.
*
* @param grc The report combo widget.
*
* @return TRUE is warning is displayed, else FALSE
*/
gboolean gnc_report_combo_is_warning_visible_for_active (GncReportCombo *grc);

#endif /* __GNC_REPORT_COMBO_H__ */
44 changes: 29 additions & 15 deletions gnucash/gnome/dialog-invoice.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,8 @@ combo_changed_cb (GtkComboBox *widget, gpointer user_data)

/* This function will return the selected invoice report guid if
* the countdown times out or a selection is made and OK pressed.
*
* If cancel is pressed then it return a NULL
*
* If cancel is pressed then it will return NULL
*/
static char*
use_default_report_template_or_change (GtkWindow *parent)
Expand All @@ -847,20 +847,34 @@ use_default_report_template_or_change (GtkWindow *parent)
GtkWidget *ok_button;
GtkWidget *report_combo_hbox;
GtkWidget *progress_bar;
GtkWidget *label;
gchar *ret_guid = NULL;
gchar *rep_guid = NULL;
gchar *rep_name = NULL;
gboolean warning_visible = FALSE;
gint result;
gdouble timeout;
dialog_args *args;

timeout = qof_book_get_default_invoice_report_timeout (book);

if (timeout == 0)
return gnc_get_default_invoice_print_report ();

combo = gnc_default_invoice_report_combo ("gnc:custom-report-invoice-template-guids");

rep_name = qof_book_get_default_invoice_report_name (book);
rep_guid = gnc_get_default_invoice_print_report ();

gnc_report_combo_set_active (GNC_REPORT_COMBO(combo),
rep_guid,
rep_name);
g_free (rep_guid);
g_free (rep_name);

warning_visible = gnc_report_combo_is_warning_visible_for_active (GNC_REPORT_COMBO(combo));

// When timeout is 0, only return if warning not visible
if (timeout == 0 && !warning_visible)
return gnc_get_default_invoice_print_report ();

builder = gtk_builder_new ();
gnc_builder_add_from_file (builder, "dialog-invoice.glade", "invoice_print_dialog");

Expand All @@ -873,20 +887,12 @@ use_default_report_template_or_change (GtkWindow *parent)
ok_button = GTK_WIDGET(gtk_builder_get_object (builder, "ok_button"));
report_combo_hbox = GTK_WIDGET(gtk_builder_get_object (builder, "report_combo_hbox"));
progress_bar = GTK_WIDGET(gtk_builder_get_object (builder, "progress_bar"));
label = GTK_WIDGET(gtk_builder_get_object (builder, "label"));

gtk_box_pack_start (GTK_BOX(report_combo_hbox), GTK_WIDGET(combo), TRUE, TRUE, 0);

gtk_widget_grab_focus (ok_button);

rep_name = qof_book_get_default_invoice_report_name (book);
rep_guid = gnc_get_default_invoice_print_report ();

gnc_report_combo_set_active (GNC_REPORT_COMBO(combo),
rep_guid,
rep_name);
g_free (rep_guid);
g_free (rep_name);

gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress_bar), 1);

args = g_malloc (sizeof(dialog_args));
Expand All @@ -907,7 +913,15 @@ use_default_report_template_or_change (GtkWindow *parent)
g_signal_connect (G_OBJECT(combo), "notify::popup-shown",
G_CALLBACK (combo_popped_cb), args);

g_timeout_add (100, update_progress_bar, args);
// if warning visible, do not add args timeout, wait for user
if (warning_visible)
{
gtk_label_set_text (GTK_LABEL(label),
N_("Choose a different report template or Printable Invoice will be used"));
gtk_widget_hide (GTK_WIDGET(progress_bar));
}
else
g_timeout_add (100, update_progress_bar, args);

result = gtk_dialog_run (GTK_DIALOG(dialog));

Expand Down

0 comments on commit 6946d21

Please sign in to comment.