Modify proposed code to use new GncReportCombo widget.

pull/1333/head
Robert Fewell 3 years ago
parent b49b5c86bb
commit b41e491ec5

@ -54,6 +54,7 @@
#include "gnc-guile-utils.h"
#include "gnc-prefs.h"
#include "gnc-commodity.h"
#include "gnc-report-combo.h"
typedef enum
{
@ -106,7 +107,7 @@ gnc_get_builtin_default_invoice_print_report (void)
return PRINTABLE_INVOICE_GUID;
}
const char *
const char *
gnc_migrate_default_invoice_print_report (void)
{
QofBook *book = gnc_get_current_book ();
@ -136,171 +137,41 @@ gnc_get_default_invoice_print_report (void)
return default_guid;
}
static gboolean
select_default (GtkWidget *combo, const gchar *default_guid)
{
GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX(combo));
GtkTreeIter iter;
gboolean found = FALSE;
gboolean valid_iter = gtk_tree_model_get_iter_first (model, &iter);
while (valid_iter)
{
gchar *guid;
gtk_tree_model_get (model, &iter, COL_INV_GUID, &guid, -1);
if (g_strcmp0 (default_guid, guid) == 0)
{
gtk_combo_box_set_active_iter (GTK_COMBO_BOX(combo), &iter);
g_free (guid);
found = TRUE;
break;
}
g_free (guid);
valid_iter = gtk_tree_model_iter_next (model, &iter);
}
return found;
}
/********************************************************************
* update_invoice_list
*
* this procedure does the real work of displaying a sorted list of
* available invoice reports
********************************************************************/
static gchar *
update_invoice_list (GtkWidget *combo)
GtkWidget *
gnc_default_invoice_report_combo (const char* guid_scm_function)
{
SCM get_rpt_guids = scm_c_eval_string ("gnc:custom-report-invoice-template-guids");
GSList *invoice_list = NULL;
SCM template_menu_name = scm_c_eval_string ("gnc:report-template-menu-name/report-guid");
SCM get_rpt_guids = scm_c_eval_string (guid_scm_function);
SCM reportlist;
SCM rpt_guids;
GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX(combo));
GtkListStore *store = GTK_LIST_STORE(model);
gchar *default_guid = gnc_get_default_invoice_print_report ();
gchar *default_name = NULL;
gboolean have_default = FALSE;
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(model),
COL_INV_NAME, GTK_SORT_ASCENDING);
if (!scm_is_procedure (get_rpt_guids))
return NULL;
reportlist = scm_call_0 (get_rpt_guids);
rpt_guids = reportlist;
gtk_list_store_clear (store);
if (scm_is_list (rpt_guids))
{
int i;
GtkTreeIter iter;
for (i = 0; !scm_is_null (rpt_guids); i++)
for (int i = 0; !scm_is_null (rpt_guids); i++)
{
gchar *guid_str = scm_to_utf8_string (SCM_CAR(rpt_guids));
gchar *name = gnc_scm_to_utf8_string (scm_call_2(template_menu_name,
SCM_CAR(rpt_guids), SCM_BOOL_F));
gtk_list_store_append (store, &iter);
gtk_list_store_set (store, &iter,
COL_INV_NAME, name,
COL_INV_GUID, guid_str,
COL_INV_MISSING, FALSE,
-1);
g_free (name);
g_free (guid_str);
rpt_guids = SCM_CDR(rpt_guids);
}
}
have_default = select_default (combo, default_guid);
if (!have_default)
{
GtkTreeIter iter;
QofBook *book = gnc_get_current_book ();
default_name = qof_book_get_default_invoice_report_name (book);
gtk_list_store_prepend (store, &iter);
gtk_list_store_set (store, &iter,
COL_INV_NAME, default_name,
COL_INV_GUID, default_guid,
COL_INV_MISSING, TRUE,
-1);
gtk_combo_box_set_active_iter (GTK_COMBO_BOX(combo), &iter);
}
g_free (default_guid);
return default_name;
}
static void
combo_changed_cb (GtkComboBox *widget, gpointer user_data)
{
GtkTreeIter iter;
if (gtk_combo_box_get_active_iter (widget, &iter))
{
GtkTreeModel *model = gtk_combo_box_get_model (widget);
gboolean missing;
gtk_tree_model_get (model, &iter, COL_INV_MISSING, &missing, -1);
// set visibility of the warning image
gtk_widget_set_visible (GTK_WIDGET(user_data), missing);
gtk_widget_queue_resize (GTK_WIDGET(widget));
}
}
void
gnc_default_print_report_list (GtkWidget *combo, GtkWidget *warning)
{
gchar *default_name = update_invoice_list (combo);
if (default_name)
{
/* Translators: %s is the default invoice report name. */
gchar *tool_tip = g_strdup_printf (_("'%s' is missing"),
default_name);
gtk_widget_show (warning);
// Note: invoice_list and entries freed in report combo
ReportListEntry *rle = g_new0 (ReportListEntry, 1);
gtk_widget_set_tooltip_text (warning, tool_tip);
g_free (tool_tip);
}
g_free (default_name);
g_signal_connect (G_OBJECT(combo), "changed",
G_CALLBACK(combo_changed_cb), warning);
}
rle->report_guid = guid_str;
rle->report_name = name;
void
gnc_default_print_report_list_combo_set_report (GtkComboBox *cbox,
const gchar *guid)
{
if (guid && *guid)
select_default (GTK_WIDGET(cbox), guid);
else
select_default (GTK_WIDGET(cbox), gnc_get_builtin_default_invoice_print_report ());
}
invoice_list = g_slist_append (invoice_list, rle);
gchar*
gnc_default_print_report_list_combo_get_report (GtkComboBox *cbox)
{
GtkTreeModel *model = gtk_combo_box_get_model (cbox);
GtkTreeIter iter;
gchar *report = NULL;
if (gtk_combo_box_get_active_iter (cbox, &iter))
{
gchar *report_guid;
gchar *report_name;
gtk_tree_model_get (model, &iter, COL_INV_NAME, &report_name,
COL_INV_GUID, &report_guid,
-1);
report = g_strconcat (report_guid, "/", report_name, NULL);
g_free (report_guid);
g_free (report_name);
rpt_guids = SCM_CDR(rpt_guids);
}
}
return report;
return gnc_report_combo_new (invoice_list);
}
static GtkWidget * gnc_owner_new (GtkWidget *label, GtkWidget *hbox,

@ -50,7 +50,7 @@ const char *gnc_get_builtin_default_invoice_print_report (void);
/** Migrate the Default Invoice Report from prefs to book properties
* used to print Invoices
*
*
* @return The guid of the saved Invoice Report
*/
const char * gnc_migrate_default_invoice_print_report (void);
@ -71,24 +71,14 @@ char *gnc_get_default_invoice_print_report (void);
*/
void gnc_default_print_report_list (GtkWidget *combo, GtkWidget *warning);
/** Retrieve the string representing the Invoice Report used as the default
* to print Invoices. This is a concatination of report name and guid
/** Create a report combo to show a list of Invoice reports so that
* a default Invoice Report can be selected.
*
* @param combo The GtkComboBox that presents the list.
*
* @return The string used to represent the selected Invoice Report
*/
gchar *gnc_default_print_report_list_combo_get_report (GtkComboBox *cbox);
/** Set the active report to the guid string
* @param guid_scm_function The SCM function to create the report list
*
* @param combo The GtkComboBox that presents the list.
*
* @param guid The guid of the Invoice Report
* @return The Widget for the report combo
*/
void gnc_default_print_report_list_combo_set_report (GtkComboBox *cbox,
const gchar *guid);
GtkWidget * gnc_default_invoice_report_combo (const char* guid_scm_function);
GtkWidget * gnc_owner_select_create (GtkWidget *label, GtkWidget *hbox,
QofBook *book, GncOwner *owner);

@ -33,6 +33,10 @@
#include <gnc-general-search.h> // for GNC_GENERAL_SEARCH
#include "dialog-utils.h" // for gnc_builder_add_from_file
extern "C"
{
#include "gnc-report-combo.h"
}
#include <iostream>
#include <sstream>
@ -190,13 +194,23 @@ public:
GncOptionGtkUIItem(widget, GncOptionUIType::INV_REPORT) {}
void set_ui_item_from_option(GncOption& option) noexcept override
{
auto guid_string{option.get_value<std::string>()};
gnc_default_print_report_list_combo_set_report (GTK_COMBO_BOX(get_widget()),
guid_string.c_str());
std::string guid_string;
auto str{option.get_value<std::string>()};
if (str.empty())
{
static const std::string default_guid_string(gnc_get_builtin_default_invoice_print_report ());
guid_string = default_guid_string + "/ ";
}
else
guid_string = str;
gnc_report_combo_set_active_guid_name (GNC_REPORT_COMBO(get_widget()),
guid_string.c_str());
}
void set_option_from_ui_item(GncOption& option) noexcept override
{
auto report_guid_name = gnc_default_print_report_list_combo_get_report (GTK_COMBO_BOX(get_widget()));
auto report_guid_name = gnc_report_combo_get_active_guid_name (GNC_REPORT_COMBO(get_widget()));
option.set_value(std::string{report_guid_name});
g_free (report_guid_name);
}
@ -207,28 +221,15 @@ create_option_widget<GncOptionUIType::INV_REPORT>(GncOption& option,
GtkGrid *page_box,
int row)
{
constexpr const char* glade_file{"business-options-gnome.glade"};
constexpr const char* glade_store{"liststore_print_invoice"};
constexpr const char* glade_hbox{"invoice_report_hbox"};
constexpr const char* glade_menu{"invoice_report_combo"};
constexpr const char* glade_warning{"invoice_warning_image"};
auto builder{gtk_builder_new()};
gnc_builder_add_from_file(builder, glade_file, glade_store);
gnc_builder_add_from_file(builder, glade_file, glade_hbox);
auto widget{GTK_WIDGET(gtk_builder_get_object(builder, glade_menu))};
auto widget_hbox{GTK_WIDGET(gtk_builder_get_object(builder, glade_hbox))};
auto widget_warning{GTK_WIDGET(gtk_builder_get_object(builder, glade_warning))};
g_object_set_data(G_OBJECT(widget), "warning-image", widget_warning);
gnc_default_print_report_list (GTK_WIDGET(widget), GTK_WIDGET(widget_warning));
constexpr const char* inv_report{"gnc:custom-report-invoice-template-guids"};
auto widget = gnc_default_invoice_report_combo (inv_report);
option.set_ui_item(std::make_unique<GncGtkInvReportUIItem>(widget));
option.set_ui_item_from_option();
g_signal_connect (G_OBJECT (widget), "changed",
G_CALLBACK (gnc_option_changed_widget_cb), &option);
wrap_widget (option, widget_hbox, page_box, row);
g_object_unref(builder); // Needs to wait until after widget has been reffed.
wrap_widget (option, widget, page_box, row);
}
void

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.22"/>
<object class="GtkListStore" id="liststore_print_invoice">
@ -12,46 +12,6 @@
<column type="gboolean"/>
</columns>
</object>
<object class="GtkWindow" id="dummy_toplevel_window2">
<property name="can-focus">False</property>
<child>
<object class="GtkBox" id="invoice_report_hbox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkComboBox" id="invoice_report_combo">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="model">liststore_print_invoice</property>
<child>
<object class="GtkCellRendererText" id="cell_renderer_text"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkImage" id="invoice_warning_image">
<property name="can-focus">False</property>
<property name="no-show-all">True</property>
<property name="icon-name">dialog-warning</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkListStore" id="taxtable_store">
<columns>
<!-- column-name taxtable_name -->

Loading…
Cancel
Save