GnuCash  5.6-150-g038405b370+
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. More...
 
void gnc_ui_select_commodity_changed_cb (GtkComboBox *cbwe, gpointer user_data)
 This function is called whenever the commodity combo box is changed. More...
 
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. More...
 
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. More...
 
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. More...
 

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. More...
 
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. More...
 
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. More...
 

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. More...
 
gchar * gnc_ui_namespace_picker_ns (GtkWidget *cbwe)
 Given a combo box, return the currently selected namespaces. More...
 
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. More...
 

Detailed Description

Enumeration Type Documentation

◆ 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 box should only allow selection of a currency.
Dialog box should allow selection of anything but a currency.
Dialog box should allow selection of anything.
Dialog box should allow selection of anything but a currency and should include the "ALL" namespace t...
dialog_commodity_mode
The dialog commodity types are used to determine what commodity namespaces the currency dialog will p...

Function Documentation

◆ 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 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282

◆ 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 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282

◆ 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 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282

◆ 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 }
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 ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282

◆ 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 {
221  return gnc_ui_select_commodity_modal_full(orig_sel,
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 }
#define DEBUG(format, args...)
Print a debugging message.
Definition: qoflog.h:264
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...
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 ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282

◆ 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),
345  DIAG_COMM_ALL);
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 }
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...
gchar * gnc_ui_namespace_picker_ns(GtkWidget *cbwe)
Given a combo box, return the currently selected namespaces.
const char * gnc_commodity_get_namespace(const gnc_commodity *cm)
Retrieve the namespace 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.
Dialog box should allow selection of anything.
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
Retrieve the &#39;print&#39; name for the specified commodity.
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.

◆ 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.
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
Retrieve the &#39;print&#39; name for the specified commodity.

◆ gnc_ui_update_namespace_picker()

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