GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Files | Data Structures | Typedefs | 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  select_commodity_window
 
struct  commodity_window
 

Typedefs

typedef struct
select_commodity_window 
SelectCommodityWindow
 
typedef struct commodity_window CommodityWindow
 
typedef void(* gnc_commodity_help_callback )(void)
 

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_ALL }
 

Functions

void gnc_ui_select_commodity_new_cb (GtkButton *button, gpointer user_data)
 
void gnc_ui_select_commodity_changed_cb (GtkComboBox *cbwe, gpointer user_data)
 
void gnc_ui_select_commodity_namespace_changed_cb (GtkComboBox *cbwe, gpointer user_data)
 
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_commodity_set_help_callback (gnc_commodity_help_callback cb)
 
void gnc_ui_update_namespace_picker (GtkWidget *cbwe, const char *init_string, dialog_commodity_mode mode)
 

Commodity Selection

gnc_commoditygnc_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)
 
gnc_commoditygnc_ui_select_commodity_modal (gnc_commodity *orig_sel, GtkWidget *parent, dialog_commodity_mode mode)
 

Commodity Creation or Modification

gnc_commoditygnc_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)
 
gnc_commoditygnc_ui_new_commodity_modal (const char *default_namespace, GtkWidget *parent)
 
gboolean gnc_ui_edit_commodity_modal (gnc_commodity *commodity, GtkWidget *parent)
 

Auxiliary Dialog Functions

void gnc_ui_update_commodity_picker (GtkWidget *cbwe, const gchar *name_space, const gchar *init_string)
 
gchar * gnc_ui_namespace_picker_ns (GtkWidget *cbwe)
 
void gnc_ui_update_namespace_picker (GtkWidget *cbwe, const gchar *sel, dialog_commodity_mode mode)
 

Detailed Description

Enumeration Type Documentation

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_ALL 

Dialog box should allow selection of anything.

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

Function Documentation

void gnc_ui_commodity_set_help_callback ( gnc_commodity_help_callback  cb)

This function is used to set the action routine for the help button in the commodity dialog windows. If the action routine is unset, the help button will not be visible to the user.

Parameters
cbThe function to be called when the user clicks the help button.

Definition at line 137 of file dialog-commodity.c.

138 {
139  help_callback = cb;
140 }
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 1265 of file dialog-commodity.c.

1267 {
1268  gnc_commodity *result;
1269 
1270  ENTER(" ");
1271  result = gnc_ui_common_commodity_modal(commodity, parent, NULL, NULL,
1272  NULL, NULL, NULL, 0);
1273  LEAVE(" ");
1274  return result != NULL;
1275 }
#define ENTER(format, args...)
Definition: qoflog.h:261
#define LEAVE(format, args...)
Definition: qoflog.h:271
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 is owned by the engine and must not be freed by the caller.

Definition at line 711 of file dialog-commodity.c.

712 {
713  const gchar *name_space;
714 
715  g_return_val_if_fail(GTK_IS_COMBO_BOX (cbwe), NULL);
716 
717  name_space = gtk_entry_get_text( GTK_ENTRY( gtk_bin_get_child( GTK_BIN( GTK_COMBO_BOX(cbwe)))));
718 
719  if (g_strcmp0 (name_space, GNC_COMMODITY_NS_ISO) == 0)
720  {
721  /* In case the user types in ISO4217, map it to CURRENCY. */
722  return g_strdup(GNC_COMMODITY_NS_CURRENCY);
723  }
724  else
725  return g_strdup(name_space);
726 }
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 1243 of file dialog-commodity.c.

1245 {
1246  gnc_commodity *result;
1247 
1248  ENTER(" ");
1249  result = gnc_ui_common_commodity_modal(NULL, parent, default_namespace, NULL,
1250  NULL, NULL, NULL, 0);
1251  LEAVE(" ");
1252  return result;
1253 }
#define ENTER(format, args...)
Definition: qoflog.h:261
#define LEAVE(format, args...)
Definition: qoflog.h:271
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 1220 of file dialog-commodity.c.

1227 {
1228  gnc_commodity *result;
1229 
1230  ENTER(" ");
1231  result = gnc_ui_common_commodity_modal(NULL, parent, name_space, cusip,
1232  fullname, mnemonic, user_symbol,
1233  10000);
1234  LEAVE(" ");
1235  return result;
1236 }
#define ENTER(format, args...)
Definition: qoflog.h:261
#define LEAVE(format, args...)
Definition: qoflog.h:271
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 376 of file dialog-commodity.c.

378 {
379  SelectCommodityWindow * w = user_data;
380  gchar *name_space;
381  const gchar *fullname;
382  gboolean ok;
383 
384  ENTER("cbwe=%p, user_data=%p", cbwe, user_data);
385  name_space = gnc_ui_namespace_picker_ns (w->namespace_combo);
386  fullname = gtk_entry_get_text(GTK_ENTRY (gtk_bin_get_child(GTK_BIN (GTK_COMBO_BOX(w->commodity_combo)))));
387 
388  DEBUG("namespace=%s, name=%s", name_space, fullname);
389  w->selection = gnc_commodity_table_find_full(gnc_get_current_commodities(),
390  name_space, fullname);
391  g_free(name_space);
392 
393  ok = (w->selection != NULL);
394  gtk_widget_set_sensitive(w->ok_button, ok);
395  gtk_dialog_set_default_response(GTK_DIALOG(w->dialog), ok ? 0 : 2);
396  LEAVE("sensitive=%d, default = %d", ok, ok ? 0 : 2);
397 }
gchar * gnc_ui_namespace_picker_ns(GtkWidget *cbwe)
#define DEBUG(format, args...)
Definition: qoflog.h:255
#define ENTER(format, args...)
Definition: qoflog.h:261
#define LEAVE(format, args...)
Definition: qoflog.h:271
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 228 of file dialog-commodity.c.

231 {
232  return gnc_ui_select_commodity_modal_full(orig_sel,
233  parent,
234  mode,
235  NULL,
236  NULL,
237  NULL,
238  NULL);
239 }
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)
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 147 of file dialog-commodity.c.

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

419 {
420  SelectCommodityWindow * w = user_data;
421  gchar *name_space;
422 
423  ENTER("cbwe=%p, user_data=%p", cbwe, user_data);
424  name_space = gnc_ui_namespace_picker_ns (w->namespace_combo);
425  DEBUG("name_space=%s", name_space);
426  gnc_ui_update_commodity_picker(w->commodity_combo, name_space, NULL);
427  g_free(name_space);
428  LEAVE(" ");
429 }
gchar * gnc_ui_namespace_picker_ns(GtkWidget *cbwe)
#define DEBUG(format, args...)
Definition: qoflog.h:255
#define ENTER(format, args...)
Definition: qoflog.h:261
void gnc_ui_update_commodity_picker(GtkWidget *cbwe, const gchar *name_space, const gchar *init_string)
#define LEAVE(format, args...)
Definition: qoflog.h:271
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 332 of file dialog-commodity.c.

334 {
335  SelectCommodityWindow * w = user_data;
336 
337  gchar * name_space = gnc_ui_namespace_picker_ns (w->namespace_combo);
338 
339  const gnc_commodity * new_commodity =
341  w->dialog,
342  w->default_cusip,
343  w->default_fullname,
344  w->default_mnemonic,
345  w->default_user_symbol,
346  w->default_fraction);
347  if (new_commodity)
348  {
349  gnc_ui_update_namespace_picker(w->namespace_combo,
350  gnc_commodity_get_namespace(new_commodity),
351  DIAG_COMM_ALL);
352  gnc_ui_update_commodity_picker(w->commodity_combo,
353  gnc_commodity_get_namespace(new_commodity),
354  gnc_commodity_get_printname(new_commodity));
355  }
356  g_free(name_space);
357 }
gchar * gnc_ui_namespace_picker_ns(GtkWidget *cbwe)
const char * gnc_commodity_get_namespace(const gnc_commodity *cm)
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)
void gnc_ui_update_commodity_picker(GtkWidget *cbwe, const gchar *name_space, const gchar *init_string)
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
void gnc_ui_update_namespace_picker(GtkWidget *cbwe, const gchar *sel, dialog_commodity_mode mode)
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 447 of file dialog-commodity.c.

450 {
451  GList * commodities;
452  GList * iterator = NULL;
453  GList * commodity_items = NULL;
454  GtkComboBox *combo_box;
455  GtkEntry *entry;
456  GtkTreeModel *model;
457  GtkTreeIter iter;
459  gint current = 0, match = 0;
460  gchar *name;
461 
462  g_return_if_fail(GTK_IS_COMBO_BOX(cbwe));
463  g_return_if_fail(name_space);
464 
465  /* Erase the old entries */
466  combo_box = GTK_COMBO_BOX(cbwe);
467  model = gtk_combo_box_get_model(combo_box);
468  gtk_list_store_clear(GTK_LIST_STORE(model));
469 
470  /* Erase the entry text */
471  entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo_box)));
472  gtk_editable_delete_text(GTK_EDITABLE(entry), 0, -1);
473 
474  gtk_combo_box_set_active(combo_box, -1);
475 
476  table = gnc_commodity_table_get_table (gnc_get_current_book ());
477  commodities = gnc_commodity_table_get_commodities(table, name_space);
478  for (iterator = commodities; iterator; iterator = iterator->next)
479  {
480  commodity_items =
481  g_list_append(commodity_items,
482  (gpointer) gnc_commodity_get_printname(iterator->data));
483  }
484  g_list_free(commodities);
485 
486  commodity_items = g_list_sort(commodity_items, collate);
487  for (iterator = commodity_items; iterator; iterator = iterator->next)
488  {
489  name = (char *)iterator->data;
490  gtk_list_store_append(GTK_LIST_STORE(model), &iter);
491  gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0, name, -1);
492 
493  if (init_string && g_utf8_collate(name, init_string) == 0)
494  match = current;
495  current++;
496  }
497 
498  gtk_combo_box_set_active(combo_box, match);
499  g_list_free(commodity_items);
500 }
gnc_commodity_table * gnc_commodity_table_get_table(QofBook *book)
CommodityList * gnc_commodity_table_get_commodities(const gnc_commodity_table *table, const char *name_space)
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
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 which namespaces the user may select a commodity
Returns
The currently selected namespace.
Note
The returned string must be freed by the caller.