GnuCash  4.8a-134-g214de30c7+
Files | Data Structures | Enumerations | Functions
Commodity windows

Files

file  dialog-commodity.c
 "select" and "new" commodity windows
 
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 46 of file dialog-commodity.h.

47 {
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 1209 of file dialog-commodity.c.

1211 {
1212  gnc_commodity *result;
1213 
1214  ENTER(" ");
1215  result = gnc_ui_common_commodity_modal(commodity, parent, NULL, NULL,
1216  NULL, NULL, NULL, 0);
1217  LEAVE(" ");
1218  return result != NULL;
1219 }
#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 653 of file dialog-commodity.c.

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

◆ 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 1187 of file dialog-commodity.c.

1189 {
1190  gnc_commodity *result;
1191 
1192  ENTER(" ");
1193  result = gnc_ui_common_commodity_modal(NULL, parent, default_namespace, NULL,
1194  NULL, NULL, NULL, 0);
1195  LEAVE(" ");
1196  return result;
1197 }
#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 1164 of file dialog-commodity.c.

1171 {
1172  gnc_commodity *result;
1173 
1174  ENTER(" ");
1175  result = gnc_ui_common_commodity_modal(NULL, parent, name_space, cusip,
1176  fullname, mnemonic, user_symbol,
1177  10000);
1178  LEAVE(" ");
1179  return result;
1180 }
#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 368 of file dialog-commodity.c.

370 {
371  SelectCommodityWindow * w = user_data;
372  gchar *name_space;
373  const gchar *fullname;
374  gboolean ok;
375 
376  ENTER("cbwe=%p, user_data=%p", cbwe, user_data);
377  name_space = gnc_ui_namespace_picker_ns (w->namespace_combo);
378  fullname = gtk_entry_get_text(GTK_ENTRY (gtk_bin_get_child(GTK_BIN (GTK_COMBO_BOX(w->commodity_combo)))));
379 
380  DEBUG("namespace=%s, name=%s", name_space, fullname);
381  w->selection = gnc_commodity_table_find_full(gnc_get_current_commodities(),
382  name_space, fullname);
383  g_free(name_space);
384 
385  ok = (w->selection != NULL);
386  gtk_widget_set_sensitive(w->ok_button, ok);
387  gtk_dialog_set_default_response(GTK_DIALOG(w->dialog), ok ? 0 : 2);
388  LEAVE("sensitive=%d, default = %d", ok, ok ? 0 : 2);
389 }
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 215 of file dialog-commodity.c.

218 {
219  return gnc_ui_select_commodity_modal_full(orig_sel,
220  parent,
221  mode,
222  NULL,
223  NULL,
224  NULL,
225  NULL);
226 }
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 133 of file dialog-commodity.c.

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

411 {
412  SelectCommodityWindow * w = user_data;
413  gchar *name_space;
414 
415  ENTER("cbwe=%p, user_data=%p", cbwe, user_data);
416  name_space = gnc_ui_namespace_picker_ns (w->namespace_combo);
417  DEBUG("name_space=%s", name_space);
418  gnc_ui_update_commodity_picker(w->commodity_combo, name_space, NULL);
419  g_free(name_space);
420  LEAVE(" ");
421 }
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 324 of file dialog-commodity.c.

326 {
327  SelectCommodityWindow * w = user_data;
328 
329  gchar * name_space = gnc_ui_namespace_picker_ns (w->namespace_combo);
330 
331  const gnc_commodity * new_commodity =
333  w->dialog,
334  w->default_cusip,
335  w->default_fullname,
336  w->default_mnemonic,
337  w->default_user_symbol,
338  w->default_fraction);
339  if (new_commodity)
340  {
341  gnc_ui_update_namespace_picker(w->namespace_combo,
342  gnc_commodity_get_namespace(new_commodity),
343  DIAG_COMM_ALL);
344  gnc_ui_update_commodity_picker(w->commodity_combo,
345  gnc_commodity_get_namespace(new_commodity),
346  gnc_commodity_get_printname(new_commodity));
347  }
348  g_free(name_space);
349 }
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 'print' 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 439 of file dialog-commodity.c.

442 {
443  GList * commodities;
444  GList * iterator = NULL;
445  GList * commodity_items = NULL;
446  GtkComboBox *combo_box;
447  GtkEntry *entry;
448  GtkTreeModel *model;
449  GtkTreeIter iter;
450  gnc_commodity_table *table;
451  gint current = 0, match = 0;
452  gchar *name;
453 
454  g_return_if_fail(GTK_IS_COMBO_BOX(cbwe));
455  g_return_if_fail(name_space);
456 
457  /* Erase the old entries */
458  combo_box = GTK_COMBO_BOX(cbwe);
459  model = gtk_combo_box_get_model(combo_box);
460  gtk_list_store_clear(GTK_LIST_STORE(model));
461 
462  /* Erase the entry text */
463  entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo_box)));
464  gtk_editable_delete_text(GTK_EDITABLE(entry), 0, -1);
465 
466  gtk_combo_box_set_active(combo_box, -1);
467 
468  table = gnc_commodity_table_get_table (gnc_get_current_book ());
469  commodities = gnc_commodity_table_get_commodities(table, name_space);
470  for (iterator = commodities; iterator; iterator = iterator->next)
471  {
472  commodity_items =
473  g_list_prepend (commodity_items,
474  (gpointer) gnc_commodity_get_printname(iterator->data));
475  }
476  g_list_free(commodities);
477 
478  commodity_items = g_list_sort(commodity_items, collate);
479  for (iterator = commodity_items; iterator; iterator = iterator->next)
480  {
481  name = (char *)iterator->data;
482  gtk_list_store_append(GTK_LIST_STORE(model), &iter);
483  gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0, name, -1);
484 
485  if (init_string && g_utf8_collate(name, init_string) == 0)
486  match = current;
487  current++;
488  }
489 
490  gtk_combo_box_set_active(combo_box, match);
491  g_list_free(commodity_items);
492 }
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 'print' 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