GnuCash c935c2f+
Loading...
Searching...
No Matches
Files | Data Structures | Enumerations | Functions
Commodity windows

Files

file  dialog-commodity.h
 "select" and "new" commodity windows
 

Data Structures

struct  SelectCommodityWindow
 
struct  CommodityWindow
 

Enumerations

enum  { SOURCE_COL_NAME = 0 , SOURCE_COL_FQ_SUPPORTED , NUM_SOURCE_COLS }
 
enum  dialog_commodity_mode { DIAG_COMM_CURRENCY , DIAG_COMM_NON_CURRENCY , DIAG_COMM_NON_CURRENCY_SELECT , DIAG_COMM_ALL }
 The dialog commodity types are used to determine what commodity namespaces the currency dialog will present to a user. More...
 

Functions

void gnc_ui_select_commodity_new_cb (GtkButton *button, gpointer user_data)
 This function is called whenever the user clicks on the "New" button in the commodity picker.
 
void gnc_ui_select_commodity_changed_cb (GtkComboBox *cbwe, gpointer user_data)
 This function is called whenever the commodity combo box is changed.
 
void gnc_ui_select_commodity_namespace_changed_cb (GtkComboBox *cbwe, gpointer user_data)
 This function is called whenever the commodity namespace combo box is changed.
 
void gnc_ui_commodity_changed_cb (GtkWidget *dummy, gpointer user_data)
 
void gnc_ui_commodity_quote_info_cb (GtkWidget *w, gpointer data)
 
gboolean gnc_ui_commodity_dialog_to_object (CommodityWindow *w)
 
void gnc_ui_update_namespace_picker (GtkWidget *cbwe, const char *init_string, dialog_commodity_mode mode)
 

Commodity Selection

gnc_commodity * gnc_ui_select_commodity_modal_full (gnc_commodity *orig_sel, GtkWidget *parent, dialog_commodity_mode mode, const char *user_message, const char *cusip, const char *fullname, const char *mnemonic)
 Ask the user to select a commodity from the existing set of commodities.
 
gnc_commodity * gnc_ui_select_commodity_modal (gnc_commodity *orig_sel, GtkWidget *parent, dialog_commodity_mode mode)
 Ask the user to select a commodity from the existing set of commodities.
 

Auxiliary Dialog Functions

void gnc_ui_update_commodity_picker (GtkWidget *cbwe, const gchar *name_space, const gchar *sel)
 Given a combo box, fill in all the known commodities for the specified namespace, and then select one.
 
gchar * gnc_ui_namespace_picker_ns (GtkWidget *cbwe)
 Given a combo box, return the currently selected namespaces.
 
void gnc_ui_update_namespace_picker (GtkWidget *cbwe, const gchar *sel, dialog_commodity_mode mode)
 Given a combo box, fill in the known commodity namespaces and then select one.
 

Commodity Creation or Modification

gnc_commodity * gnc_ui_new_commodity_modal_full (const char *name_space, GtkWidget *parent, const char *cusip, const char *fullname, const char *mnemonic, const char *user_symbol, int fraction)
 Ask the user to provide the information necessary to create a new commodity.
 
gnc_commodity * gnc_ui_new_commodity_modal (const char *default_namespace, GtkWidget *parent)
 Ask the user to provide the information necessary to create a new commodity.
 
gboolean gnc_ui_edit_commodity_modal (gnc_commodity *commodity, GtkWidget *parent)
 Given an existing commodity, uses the gnc_ui_build_commodity_dialog() routine to build a basic edit dialog, then fills in the price quote information at the bottom of the dialog.
 

Detailed Description

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Definition at line 54 of file dialog-commodity.cpp.

55{
56 SOURCE_COL_NAME = 0,
57 SOURCE_COL_FQ_SUPPORTED,
58 NUM_SOURCE_COLS
59};

◆ dialog_commodity_mode

The dialog commodity types are used to determine what commodity namespaces the currency dialog will present to a user.

These values can be safely changed from one release to the next. Note that if values are added, the routines in dialog-commodity.c will need to be updated to match.

Enumerator
DIAG_COMM_CURRENCY 

Dialog box should only allow selection of a currency.

DIAG_COMM_NON_CURRENCY 

Dialog box should allow selection of anything but a currency.

DIAG_COMM_NON_CURRENCY_SELECT 

Dialog box should allow selection of anything but a currency and should include the "ALL" namespace to display all such commodities in a single list.

DIAG_COMM_ALL 

Dialog box should allow selection of anything.

Definition at line 51 of file dialog-commodity.h.

52{
dialog_commodity_mode
The dialog commodity types are used to determine what commodity namespaces the currency dialog will p...
@ DIAG_COMM_NON_CURRENCY
Dialog box should allow selection of anything but a currency.
@ DIAG_COMM_CURRENCY
Dialog box should only allow selection of a currency.
@ DIAG_COMM_ALL
Dialog box should allow selection of anything.
@ DIAG_COMM_NON_CURRENCY_SELECT
Dialog box should allow selection of anything but a currency and should include the "ALL" namespace t...

Function Documentation

◆ gnc_ui_commodity_changed_cb()

void gnc_ui_commodity_changed_cb ( GtkWidget *  dummy,
gpointer  user_data 
)

Definition at line 712 of file dialog-commodity.cpp.

713{
714 auto w = static_cast<CommodityWindow*>(user_data);
715 gchar *name_space;
716 const char * fullname;
717 const char * mnemonic;
718 gboolean ok;
719
720 ENTER("widget=%p, user_data=%p", dummy, user_data);
721 if (!w->is_currency)
722 {
723 name_space = gnc_ui_namespace_picker_ns (w->namespace_combo);
724 fullname = gtk_entry_get_text(GTK_ENTRY(w->fullname_entry));
725 mnemonic = gtk_entry_get_text(GTK_ENTRY(w->mnemonic_entry));
726 DEBUG("namespace=%s, name=%s, mnemonic=%s", name_space, fullname, mnemonic);
727 ok = (fullname && name_space && mnemonic &&
728 fullname[0] && name_space[0] && mnemonic[0]);
729 g_free(name_space);
730 }
731 else
732 {
733 ok = TRUE;
734 }
735 gtk_widget_set_sensitive(w->ok_button, ok);
736 gtk_dialog_set_default_response(GTK_DIALOG(w->dialog), ok ? 0 : 1);
737 LEAVE("sensitive=%d, default = %d", ok, ok ? 0 : 1);
738}
gchar * gnc_ui_namespace_picker_ns(GtkWidget *cbwe)
Given a combo box, return the currently selected namespaces.
#define DEBUG(format, args...)
Print a debugging message.
Definition qoflog.h:264
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition qoflog.h:282
#define ENTER(format, args...)
Print a function entry debugging message.
Definition qoflog.h:272

◆ gnc_ui_commodity_dialog_to_object()

gboolean gnc_ui_commodity_dialog_to_object ( CommodityWindow *  w)

Definition at line 1231 of file dialog-commodity.cpp.

1232{
1233 gnc_quote_source *source;
1234 QuoteSourceType type;
1235 const char * fullname = gtk_entry_get_text(GTK_ENTRY(w->fullname_entry));
1236 gchar *name_space = gnc_ui_namespace_picker_ns (w->namespace_combo);
1237 const char * mnemonic = gtk_entry_get_text(GTK_ENTRY(w->mnemonic_entry));
1238 const char * user_symbol = gtk_entry_get_text(GTK_ENTRY(w->user_symbol_entry));
1239 const char * code = gtk_entry_get_text(GTK_ENTRY(w->code_entry));
1240 QofBook * book = gnc_get_current_book ();
1241 int fraction = gtk_spin_button_get_value_as_int
1242 (GTK_SPIN_BUTTON(w->fraction_spinbutton));
1243 const char *string;
1244 gnc_commodity * c;
1245 gint selection;
1246
1247 ENTER(" ");
1248 /* Special case currencies */
1249 if (gnc_commodity_namespace_is_iso (name_space))
1250 {
1251 if (w->edit_commodity)
1252 {
1253 gboolean quote_set;
1254 quote_set = gtk_toggle_button_get_active
1255 (GTK_TOGGLE_BUTTON (w->get_quote_check));
1256 c = w->edit_commodity;
1257 gnc_commodity_begin_edit(c);
1258 gnc_commodity_user_set_quote_flag (c, quote_set);
1259 if (quote_set)
1260 {
1261 selection = gtk_combo_box_get_active(GTK_COMBO_BOX(w->quote_tz_menu));
1262 string = gnc_timezone_menu_position_to_string(selection);
1263 gnc_commodity_set_quote_tz(c, string);
1264 }
1265 else
1266 gnc_commodity_set_quote_tz(c, nullptr);
1267
1268 gnc_commodity_set_user_symbol(c, user_symbol);
1269
1270 gnc_commodity_commit_edit(c);
1271 g_free (name_space);
1272 return TRUE;
1273 }
1274 gnc_warning_dialog (GTK_WINDOW (w->dialog), "%s",
1275 _("You may not create a new national currency."));
1276 g_free (name_space);
1277 return FALSE;
1278 }
1279
1280 /* Don't allow user to create commodities in namespace
1281 * "template". That's reserved for scheduled transaction use.
1282 */
1283 if (g_utf8_collate(name_space, GNC_COMMODITY_NS_TEMPLATE) == 0)
1284 {
1285 gnc_warning_dialog (GTK_WINDOW (w->dialog),
1286 _("%s is a reserved commodity type."
1287 " Please use something else."), GNC_COMMODITY_NS_TEMPLATE);
1288 g_free (name_space);
1289 return FALSE;
1290 }
1291
1292 if (fullname && fullname[0] &&
1293 name_space && name_space[0] &&
1294 mnemonic && mnemonic[0])
1295 {
1296 c = gnc_commodity_table_lookup (gnc_get_current_commodities(),
1297 name_space, mnemonic);
1298
1299 if ((!w->edit_commodity && c) ||
1300 (w->edit_commodity && c && (c != w->edit_commodity)))
1301 {
1302 gnc_warning_dialog (GTK_WINDOW (w->dialog), "%s", _("That commodity already exists."));
1303 g_free(name_space);
1304 return FALSE;
1305 }
1306
1307 if (!w->edit_commodity)
1308 {
1309 c = gnc_commodity_new(book, fullname, name_space, mnemonic, code, fraction);
1310 w->edit_commodity = c;
1311 gnc_commodity_begin_edit(c);
1312
1313 gnc_commodity_set_user_symbol(c, user_symbol);
1314 }
1315 else
1316 {
1317 c = w->edit_commodity;
1318 gnc_commodity_begin_edit(c);
1319
1320 gnc_commodity_table_remove (gnc_get_current_commodities(), c);
1321
1322 gnc_commodity_set_fullname (c, fullname);
1323 gnc_commodity_set_mnemonic (c, mnemonic);
1324 gnc_commodity_set_namespace (c, name_space);
1325 gnc_commodity_set_cusip (c, code);
1326 gnc_commodity_set_fraction (c, fraction);
1327 gnc_commodity_set_user_symbol(c, user_symbol);
1328 }
1329
1330 gnc_commodity_user_set_quote_flag (c, gtk_toggle_button_get_active
1331 (GTK_TOGGLE_BUTTON (w->get_quote_check)));
1332
1333 for (type = SOURCE_SINGLE; type < SOURCE_MAX; type = static_cast<QuoteSourceType>(type+1))
1334 {
1335 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w->source_button[type])))
1336 break;
1337 }
1338 selection = gtk_combo_box_get_active(GTK_COMBO_BOX(w->source_menu[type]));
1339 source = gnc_quote_source_lookup_by_ti (type, selection);
1341
1342 selection = gtk_combo_box_get_active(GTK_COMBO_BOX(w->quote_tz_menu));
1343 string = gnc_timezone_menu_position_to_string(selection);
1344 gnc_commodity_set_quote_tz(c, string);
1345 gnc_commodity_commit_edit(c);
1346
1347 /* remember the commodity */
1348 gnc_commodity_table_insert(gnc_get_current_commodities(), c);
1349 }
1350 else
1351 {
1352 gnc_warning_dialog (GTK_WINDOW (w->dialog), "%s",
1353 _("You must enter a non-empty \"Full name\", "
1354 "\"Symbol/abbreviation\", "
1355 "and \"Type\" for the commodity."));
1356 g_free(name_space);
1357 return FALSE;
1358 }
1359 g_free(name_space);
1360 LEAVE(" ");
1361 return TRUE;
1362}
void gnc_commodity_set_cusip(gnc_commodity *cm, const char *cusip)
Set the 'exchange code' for the specified commodity.
void gnc_commodity_table_remove(gnc_commodity_table *table, gnc_commodity *comm)
Remove a commodity from the commodity table.
void gnc_commodity_set_namespace(gnc_commodity *cm, const char *name_space)
Set the namespace for the specified commodity.
gnc_commodity * gnc_commodity_new(QofBook *book, const char *fullname, const char *name_space, const char *mnemonic, const char *cusip, int fraction)
Create a new commodity.
void gnc_commodity_set_fullname(gnc_commodity *cm, const char *fullname)
Set the full name for the specified commodity.
gboolean gnc_commodity_namespace_is_iso(const char *name_space)
Checks to see if the specified commodity namespace is the namespace for ISO 4217 currencies.
void gnc_commodity_set_quote_source(gnc_commodity *cm, gnc_quote_source *src)
Set the automatic price quote source for the specified commodity.
void gnc_commodity_set_fraction(gnc_commodity *cm, int fraction)
Set the fraction for the specified commodity.
gnc_quote_source * gnc_quote_source_lookup_by_ti(QuoteSourceType type, gint index)
Given the type/index of a quote source, find the data structure identified by this pair.
gnc_commodity * gnc_commodity_table_insert(gnc_commodity_table *table, gnc_commodity *comm)
Add a new commodity to the commodity table.
QuoteSourceType
The quote source type enum account types are used to determine how the transaction data in the accoun...
void gnc_commodity_set_user_symbol(gnc_commodity *cm, const char *user_symbol)
Set a user-defined symbol for the specified commodity.
void gnc_commodity_user_set_quote_flag(gnc_commodity *cm, const gboolean flag)
Set the automatic price quote flag for the specified commodity, based on user input.
void gnc_commodity_set_mnemonic(gnc_commodity *cm, const char *mnemonic)
Set the mnemonic for the specified commodity.
void gnc_commodity_set_quote_tz(gnc_commodity *cm, const char *tz)
Set the automatic price quote timezone for the specified commodity.
@ SOURCE_SINGLE
This quote source pulls from a single specific web site.
QofBook reference.
Definition qofbook-p.hpp:47

◆ gnc_ui_commodity_quote_info_cb()

void gnc_ui_commodity_quote_info_cb ( GtkWidget *  w,
gpointer  data 
)

Definition at line 680 of file dialog-commodity.cpp.

681{
682 auto cw = static_cast<CommodityWindow*>(data);
683 gboolean get_quote, allow_src, active;
684 const gchar *text;
685 gint i;
686
687 ENTER(" ");
688 get_quote = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w));
689
690 text = gtk_entry_get_text( GTK_ENTRY( gtk_bin_get_child( GTK_BIN( GTK_COMBO_BOX(cw->namespace_combo)))));
691
692 allow_src = !gnc_commodity_namespace_is_iso(text);
693
694 gtk_widget_set_sensitive(cw->source_label, get_quote && allow_src);
695
696 for (i = SOURCE_SINGLE; i < SOURCE_MAX; i++)
697 {
698 if (!cw->source_button[i])
699 continue;
700 active =
701 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cw->source_button[i]));
702 gtk_widget_set_sensitive(cw->source_button[i], get_quote && allow_src);
703 gtk_widget_set_sensitive(cw->source_menu[i], get_quote && allow_src && active);
704 }
705 gtk_widget_set_sensitive(cw->quote_tz_label, get_quote);
706 gtk_widget_set_sensitive(cw->quote_tz_menu, get_quote);
707 LEAVE(" ");
708}

◆ gnc_ui_edit_commodity_modal()

gboolean gnc_ui_edit_commodity_modal ( gnc_commodity *  commodity,
GtkWidget *  parent 
)

Given an existing commodity, uses the gnc_ui_build_commodity_dialog() routine to build a basic edit dialog, then fills in the price quote information at the bottom of the dialog.

Allow the user to edit the information about a commodity.

For currencies, only the price quote information may be changed. For any other commodity, all aspects of the commodity information may be changed except that the namespace may not be changed to indicate a currency. The new information overwrites any old information, so this routine may not be used to create new commodities.

Parameters
commodityThe commodity to edit.
parentThe parent window of the new dialog.
Returns
The newly created commodity, or NULL if the user cancelled.

Definition at line 1214 of file dialog-commodity.cpp.

1216{
1217 gnc_commodity *result;
1218
1219 ENTER(" ");
1220 result = gnc_ui_common_commodity_modal(commodity, parent, nullptr, nullptr,
1221 nullptr, nullptr, nullptr, 0);
1222 LEAVE(" ");
1223 return result != nullptr;
1224}

◆ gnc_ui_namespace_picker_ns()

gchar * gnc_ui_namespace_picker_ns ( GtkWidget *  cbwe)

Given a combo box, return the currently selected namespaces.

Parameters
cbweThe combo box of namespaces.
Returns
The currently selected namespace.
Note
This string must be freed by with g_free.

Definition at line 658 of file dialog-commodity.cpp.

659{
660 const gchar *name_space;
661
662 g_return_val_if_fail(GTK_IS_COMBO_BOX (cbwe), nullptr);
663
664 name_space = gtk_entry_get_text( GTK_ENTRY( gtk_bin_get_child( GTK_BIN( GTK_COMBO_BOX(cbwe)))));
665
666 /* Map several currency related names to one common namespace */
667 if ((g_strcmp0 (name_space, GNC_COMMODITY_NS_ISO) == 0) ||
668 (g_strcmp0 (name_space, GNC_COMMODITY_NS_ISO_GUI) == 0) ||
669 (g_strcmp0 (name_space, _(GNC_COMMODITY_NS_ISO_GUI)) == 0))
670 return g_strdup(GNC_COMMODITY_NS_CURRENCY);
671 else
672 return g_strdup(name_space);
673}

◆ gnc_ui_new_commodity_modal()

gnc_commodity * gnc_ui_new_commodity_modal ( const char *  default_namespace,
GtkWidget *  parent 
)

Ask the user to provide the information necessary to create a new commodity.

Parameters
default_namespaceIf present, this will be the default namespace for the new commodity. This value will be ignored if it is the namespace for ISO 4217 currencies.
parentThe parent window of the new dialog.
Returns
The newly created commodity, or NULL if the user cancelled.

Definition at line 1192 of file dialog-commodity.cpp.

1194{
1195 gnc_commodity *result;
1196
1197 ENTER(" ");
1198 result = gnc_ui_common_commodity_modal(nullptr, parent, default_namespace, nullptr,
1199 nullptr, nullptr, nullptr, 0);
1200 LEAVE(" ");
1201 return result;
1202}

◆ gnc_ui_new_commodity_modal_full()

gnc_commodity * gnc_ui_new_commodity_modal_full ( const char *  name_space,
GtkWidget *  parent,
const char *  cusip,
const char *  fullname,
const char *  mnemonic,
const char *  user_symbol,
int  fraction 
)

Ask the user to provide the information necessary to create a new commodity.

Parameters
namespaceIf present, this will be the default namespace for the new commodity. This value will be ignored if it is the namespace for ISO 4217 currencies.
parentThe parent window of the new dialog.
cusipIf present, this will be the default exchange specific data for the new commodity.
fullnameIf present, this will be the default fullname for the new commodity.
mnemonicIf present, this will be the default mnemonic for the new commodity.
user_symbolIf present, this will be the default user symbol for the new commodity.
fractionIf present, this will be the default fraction for the new commodity. If absent, a default of 1000 will be used.
Returns
The newly created commodity, or NULL if the user cancelled.

Definition at line 1169 of file dialog-commodity.cpp.

1176{
1177 gnc_commodity *result;
1178
1179 ENTER(" ");
1180 result = gnc_ui_common_commodity_modal(nullptr, parent, name_space, cusip,
1181 fullname, mnemonic, user_symbol,
1182 10000);
1183 LEAVE(" ");
1184 return result;
1185}

◆ gnc_ui_select_commodity_changed_cb()

void gnc_ui_select_commodity_changed_cb ( GtkComboBox *  cbwe,
gpointer  user_data 
)

This function is called whenever the commodity combo box is changed.

Its function is to determine if a valid commodity has been selected, record the selection, and update the OK button.

Note
This function is an internal helper function for the Commodity Selection dialog. It should not be used outside of the dialog-commodity.c file.
Parameters
cbweA pointer to the commodity name entry widget in the dialog.
user_dataA pointer to the data structure describing the current state of the commodity picker.

Definition at line 370 of file dialog-commodity.cpp.

372{
373 auto w = static_cast<SelectCommodityWindow*>(user_data);
374 gchar *name_space;
375 const gchar *fullname;
376 gboolean ok;
377
378 ENTER("cbwe=%p, user_data=%p", cbwe, user_data);
379 name_space = gnc_ui_namespace_picker_ns (w->namespace_combo);
380 fullname = gtk_entry_get_text(GTK_ENTRY (gtk_bin_get_child(GTK_BIN (GTK_COMBO_BOX(w->commodity_combo)))));
381
382 DEBUG("namespace=%s, name=%s", name_space, fullname);
383 w->selection = gnc_commodity_table_find_full(gnc_get_current_commodities(),
384 name_space, fullname);
385 g_free(name_space);
386
387 ok = (w->selection != nullptr);
388 gtk_widget_set_sensitive(w->ok_button, ok);
389 gtk_dialog_set_default_response(GTK_DIALOG(w->dialog), ok ? 0 : 2);
390 LEAVE("sensitive=%d, default = %d", ok, ok ? 0 : 2);
391}

◆ gnc_ui_select_commodity_modal()

gnc_commodity * gnc_ui_select_commodity_modal ( gnc_commodity *  orig_sel,
GtkWidget *  parent,
dialog_commodity_mode  mode 
)

Ask the user to select a commodity from the existing set of commodities.

The user will also have the option of creating a new commodity from this dialog box.. If the user decides to create a new one, those provided values are used as default values for the new commodity.

Parameters
orig_selA pointer to a commodity that should initially be selected in the dialog box.
parentThe parent window for this new selection window.
modeDetermines which namespaces the user may select a commodity from.
Returns
The commodity selected. May or may not be a newly created commodity.

Definition at line 217 of file dialog-commodity.cpp.

220{
222 parent,
223 mode,
224 nullptr,
225 nullptr,
226 nullptr,
227 nullptr);
228}
gnc_commodity * gnc_ui_select_commodity_modal_full(gnc_commodity *orig_sel, GtkWidget *parent, dialog_commodity_mode mode, const char *user_message, const char *cusip, const char *fullname, const char *mnemonic)
Ask the user to select a commodity from the existing set of commodities.

◆ gnc_ui_select_commodity_modal_full()

gnc_commodity * gnc_ui_select_commodity_modal_full ( gnc_commodity *  orig_sel,
GtkWidget *  parent,
dialog_commodity_mode  mode,
const char *  user_message,
const char *  cusip,
const char *  fullname,
const char *  mnemonic 
)

Ask the user to select a commodity from the existing set of commodities.

Arguments to this function determine the message placed at the top of the dialog but force no restriction on the commodities that may be chosen. The user will also have the option of creating a new commodity from this dialog box.. If the user decides to create a new one, those provided values are used as default values for the new commodity.

Parameters
orig_selA pointer to a commodity that should initially be selected in the dialog box.
parentThe parent window of the new dialog.
user_messageA string that will be installed in the top of the dialog box as an instruction to the user. If NULL, a generic instruction will be used.
cusipIf present, a note will be added to the user instruction providing this exchange specific code, and this will be the default exchange specific data for any newly created commodities.
fullnameIf present, a note will be added to the user instruction providing this commodity's full name, and this will be the default fullname for any newly created commodities.
mnemonicIf present, a note will be added to the user instruction providing this commodity's mnemonic, and this will be the default mnemonic for any newly created commodities.
modeDetermines which namespaces the user may select a commodity from.
Returns
The commodity selected. May or may not be a newly created commodity.

Definition at line 135 of file dialog-commodity.cpp.

142{
143 gnc_commodity * retval = nullptr;
144 const gchar *initial;
145 gchar *user_prompt_text;
146 SelectCommodityWindow * win;
147 gboolean done;
148 gint value;
149
150 win = gnc_ui_select_commodity_create(orig_sel, mode);
151 win->default_cusip = cusip;
152 win->default_fullname = fullname;
153 win->default_mnemonic = mnemonic;
154 win->default_user_symbol = "";
155
156 if (parent)
157 gtk_window_set_transient_for (GTK_WINDOW (win->dialog), GTK_WINDOW (parent));
158
159 if (user_message != nullptr)
160 initial = user_message;
161 else if ((cusip != nullptr) || (fullname != nullptr) || (mnemonic != nullptr))
162 initial = _("\nPlease select a commodity to match");
163 else
164 initial = "";
165
166 user_prompt_text =
167 g_strdup_printf("%s%s%s%s%s%s%s",
168 initial,
169 fullname ? _("\nCommodity: ") : "",
170 fullname ? fullname : "",
171 /* Translators: Replace here and later CUSIP by the name of your local
172 National Securities Identifying Number
173 like gb:SEDOL, de:WKN, ch:Valorennummer, fr:SICOVAM ...
174 See https://en.wikipedia.org/wiki/ISIN and
175 https://en.wikipedia.org/wiki/National_numbering_agency for hints. */
176 cusip ? _("\nExchange code (ISIN, CUSIP or similar): ") : "",
177 cusip ? cusip : "",
178 mnemonic ? _("\nMnemonic (Ticker symbol or similar): ") : "",
179 mnemonic ? mnemonic : "");
180 gtk_label_set_text ((GtkLabel *)(win->select_user_prompt),
181 user_prompt_text);
182 g_free(user_prompt_text);
183
184 /* Run the dialog, handling the terminal conditions. */
185 done = FALSE;
186 while (!done)
187 {
188 switch (value = gtk_dialog_run(GTK_DIALOG(win->dialog)))
189 {
190 case GTK_RESPONSE_OK:
191 DEBUG("case OK");
192 retval = win->selection;
193 done = TRUE;
194 break;
195 case GNC_RESPONSE_NEW:
196 DEBUG("case NEW");
197 gnc_ui_select_commodity_new_cb (nullptr, win);
198 break;
199 default: /* Cancel, Escape, Close, etc. */
200 DEBUG("default: %d", value);
201 retval = nullptr;
202 done = TRUE;
203 break;
204 }
205 }
206 gtk_widget_destroy (GTK_WIDGET (win->dialog)); /* Close and destroy */
207 g_free(win);
208
209 return retval;
210}
void gnc_ui_select_commodity_new_cb(GtkButton *button, gpointer user_data)
This function is called whenever the user clicks on the "New" button in the commodity picker.

◆ gnc_ui_select_commodity_namespace_changed_cb()

void gnc_ui_select_commodity_namespace_changed_cb ( GtkComboBox *  cbwe,
gpointer  user_data 
)

This function is called whenever the commodity namespace combo box is changed.

Its function is to update the commodity name combo box with the strings that are appropriate to the selected namespace.

Note
This function is an internal helper function for the Commodity Selection dialog. It should not be used outside of the dialog-commodity.c file.
Parameters
cbweA pointer to the commodity namespace entry widget in the dialog.
user_dataA pointer to the data structure describing the current state of the commodity picker.

Definition at line 411 of file dialog-commodity.cpp.

413{
414 auto w = static_cast<SelectCommodityWindow*>(user_data);
415 gchar *name_space;
416
417 ENTER("cbwe=%p, user_data=%p", cbwe, user_data);
418 name_space = gnc_ui_namespace_picker_ns (w->namespace_combo);
419 DEBUG("name_space=%s", name_space);
420 gnc_ui_update_commodity_picker(w->commodity_combo, name_space, nullptr);
421 g_free(name_space);
422 LEAVE(" ");
423}
void gnc_ui_update_commodity_picker(GtkWidget *cbwe, const gchar *name_space, const gchar *init_string)
Given a combo box, fill in all the known commodities for the specified namespace, and then select one...

◆ gnc_ui_select_commodity_new_cb()

void gnc_ui_select_commodity_new_cb ( GtkButton *  button,
gpointer  user_data 
)

This function is called whenever the user clicks on the "New" button in the commodity picker.

Its function is pop up a new dialog alling the user to create a new commodity.

Note
This function is an internal helper function for the Commodity Selection dialog. It should not be used outside of the dialog-commodity.c file.
Parameters
buttonA pointer to the "new" button widget in the dialog.
user_dataA pointer to the data structure describing the current state of the commodity picker.

Definition at line 326 of file dialog-commodity.cpp.

328{
329 auto w = static_cast<SelectCommodityWindow*>(user_data);
330
331 gchar * name_space = gnc_ui_namespace_picker_ns (w->namespace_combo);
332
333 const gnc_commodity * new_commodity =
335 w->dialog,
336 w->default_cusip,
337 w->default_fullname,
338 w->default_mnemonic,
339 w->default_user_symbol,
340 w->default_fraction);
341 if (new_commodity)
342 {
343 gnc_ui_update_namespace_picker(w->namespace_combo,
344 gnc_commodity_get_namespace(new_commodity),
346 gnc_ui_update_commodity_picker(w->commodity_combo,
347 gnc_commodity_get_namespace(new_commodity),
348 gnc_commodity_get_printname(new_commodity));
349 }
350 g_free(name_space);
351}
const char * gnc_commodity_get_namespace(const gnc_commodity *cm)
Retrieve the namespace for the specified commodity.
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
Retrieve the 'print' name for the specified commodity.
gnc_commodity * gnc_ui_new_commodity_modal_full(const char *name_space, GtkWidget *parent, const char *cusip, const char *fullname, const char *mnemonic, const char *user_symbol, int fraction)
Ask the user to provide the information necessary to create a new commodity.

◆ gnc_ui_update_commodity_picker()

void gnc_ui_update_commodity_picker ( GtkWidget *  cbwe,
const gchar *  name_space,
const gchar *  sel 
)

Given a combo box, fill in all the known commodities for the specified namespace, and then select one.

Parameters
cbweThe widget to populate with information.
namespaceAll commodities with this namespace will be added to the combo box.
selThe commodity that should be initially selected when the combo box appears.

Definition at line 441 of file dialog-commodity.cpp.

444{
445 GList * commodities;
446 GList * iterator = nullptr;
447 GList * commodity_items = nullptr;
448 GtkComboBox *combo_box;
449 GtkEntry *entry;
450 GtkTreeModel *model;
451 GtkTreeIter iter;
452 gnc_commodity_table *table;
453 gint current = 0, match = 0;
454 gchar *name;
455
456 g_return_if_fail(GTK_IS_COMBO_BOX(cbwe));
457 g_return_if_fail(name_space);
458
459 /* Erase the old entries */
460 combo_box = GTK_COMBO_BOX(cbwe);
461 model = gtk_combo_box_get_model(combo_box);
462 gtk_list_store_clear(GTK_LIST_STORE(model));
463
464 /* Erase the entry text */
465 entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo_box)));
466 gtk_editable_delete_text(GTK_EDITABLE(entry), 0, -1);
467
468 gtk_combo_box_set_active(combo_box, -1);
469
470 table = gnc_commodity_table_get_table (gnc_get_current_book ());
471 commodities = gnc_commodity_table_get_commodities(table, name_space);
472 for (iterator = commodities; iterator; iterator = iterator->next)
473 {
474 commodity_items =
475 g_list_prepend (commodity_items,
476 (gpointer) gnc_commodity_get_printname(GNC_COMMODITY(iterator->data)));
477 }
478 g_list_free(commodities);
479
480 commodity_items = g_list_sort(commodity_items, collate);
481 for (iterator = commodity_items; iterator; iterator = iterator->next)
482 {
483 name = (char *)iterator->data;
484 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
485 gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0, name, -1);
486
487 if (init_string && g_utf8_collate(name, init_string) == 0)
488 match = current;
489 current++;
490 }
491
492 gtk_combo_box_set_active(combo_box, match);
493 g_list_free(commodity_items);
494}
gnc_commodity_table * gnc_commodity_table_get_table(QofBook *book)
Returns the commodity table associated with a book.
CommodityList * gnc_commodity_table_get_commodities(const gnc_commodity_table *table, const char *name_space)
Return a list of all commodities in the commodity table that are in the given namespace.

◆ gnc_ui_update_namespace_picker() [1/2]

void gnc_ui_update_namespace_picker ( GtkWidget *  cbwe,
const char *  init_string,
dialog_commodity_mode  mode 
)

Definition at line 556 of file dialog-commodity.cpp.

559{
560 GtkComboBox *combo_box;
561 GtkTreeModel *model;
562 GtkTreeIter iter, match;
563 GList *namespaces, *node;
564 gboolean matched = FALSE;
565
566 g_return_if_fail(GTK_IS_COMBO_BOX (cbwe));
567
568 /* Erase the old entries */
569 combo_box = GTK_COMBO_BOX(cbwe);
570 model = gtk_combo_box_get_model(combo_box);
571 gtk_list_store_clear(GTK_LIST_STORE(model));
572
573 /* fetch a list of the namespaces */
574 switch (mode)
575 {
576 case DIAG_COMM_ALL:
577 namespaces =
578 gnc_commodity_table_get_namespaces (gnc_get_current_commodities());
579 break;
580
583 namespaces =
584 gnc_commodity_table_get_namespaces (gnc_get_current_commodities());
585 node = g_list_find_custom (namespaces, GNC_COMMODITY_NS_CURRENCY, collate);
586 if (node)
587 {
588 namespaces = g_list_remove_link (namespaces, node);
589 g_list_free_1 (node);
590 }
591
592 if (gnc_commodity_namespace_is_iso (init_string))
593 init_string = nullptr;
594 break;
595
597 default:
598 namespaces = g_list_prepend (nullptr, (gpointer)GNC_COMMODITY_NS_CURRENCY);
599 break;
600 }
601
602 /* First insert "Currencies" entry if requested */
603 if (mode == DIAG_COMM_CURRENCY || mode == DIAG_COMM_ALL)
604 {
605 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
606 gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0,
607 _(GNC_COMMODITY_NS_ISO_GUI), -1);
608
609 if (init_string &&
610 (g_utf8_collate(GNC_COMMODITY_NS_ISO_GUI, init_string) == 0))
611 {
612 matched = TRUE;
613 match = iter;
614 }
615 }
616
617 /* Next insert "All non-currency" entry if requested */
618 if (mode == DIAG_COMM_NON_CURRENCY_SELECT || mode == DIAG_COMM_ALL)
619 {
620 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
621 gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0,
622 GNC_COMMODITY_NS_NONISO_GUI, -1);
623 }
624
625 /* add all others to the combobox */
626 namespaces = g_list_sort(namespaces, collate);
627 for (node = namespaces; node; node = node->next)
628 {
629 auto ns = static_cast<const char*>(node->data);
630 /* Skip template, legacy and currency namespaces.
631 The latter was added as first entry earlier */
632 if ((g_utf8_collate(ns, GNC_COMMODITY_NS_LEGACY) == 0) ||
633 (g_utf8_collate(ns, GNC_COMMODITY_NS_TEMPLATE ) == 0) ||
634 (g_utf8_collate(ns, GNC_COMMODITY_NS_CURRENCY ) == 0))
635 continue;
636
637 gtk_list_store_append(GTK_LIST_STORE(model), &iter);
638 gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0, ns, -1);
639
640 if (init_string &&
641 (g_utf8_collate(ns, init_string) == 0))
642 {
643 matched = TRUE;
644 match = iter;
645 }
646 }
647
648 if (!matched)
649 matched = gtk_tree_model_get_iter_first (model, &match);
650
651 if (matched)
652 gtk_combo_box_set_active_iter (combo_box, &match);
653 g_list_free(namespaces);
654}
GList * gnc_commodity_table_get_namespaces(const gnc_commodity_table *table)
Return a list of all namespaces in the commodity table.
#define GNC_COMMODITY_NS_LEGACY
The commodity namespace definitions are used to tag a commodity by its type, or a stocks by the excha...

◆ gnc_ui_update_namespace_picker() [2/2]

void gnc_ui_update_namespace_picker ( GtkWidget *  cbwe,
const gchar *  sel,
dialog_commodity_mode  mode 
)

Given a combo box, fill in the known commodity namespaces and then select one.

Parameters
cbweThe widget to populate with information.
selThe namespace that should be initially selected when the combo box appears.
modeDetermines in which namespaces the user may select a commodity