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 |
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) |
| gnc_commodity * | gnc_ui_select_commodity_modal (gnc_commodity *orig_sel, GtkWidget *parent, dialog_commodity_mode mode) |
Auxiliary Dialog Functions | |
| void | gnc_ui_update_commodity_picker (GtkWidget *cbe, const gchar *namespace, const gchar *init_string) |
| gchar * | gnc_ui_namespace_picker_ns (GtkWidget *cbe) |
| void | gnc_ui_update_namespace_picker (GtkWidget *cbe, const gchar *sel, dialog_commodity_mode mode) |
Commodity Creation or Modification | |
| gnc_commodity * | gnc_ui_new_commodity_modal_full (const char *namespace, GtkWidget *parent, const char *cusip, const char *fullname, const char *mnemonic, int fraction) |
| gnc_commodity * | gnc_ui_new_commodity_modal (const char *default_namespace, GtkWidget *parent) |
| gboolean | gnc_ui_edit_commodity_modal (gnc_commodity *commodity, GtkWidget *parent) |
Typedefs | |
| typedef select_commodity_window | SelectCommodityWindow |
| typedef 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 (GtkComboBoxEntry *cbe, gpointer user_data) |
| void | gnc_ui_select_commodity_namespace_changed_cb (GtkComboBoxEntry *cbe, 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 *cbe, const char *init_string, dialog_commodity_mode mode) |
| anonymous enum |
Definition at line 52 of file dialog-commodity.c.
00052 { 00053 SOURCE_COL_NAME = 0, 00054 SOURCE_COL_FQ_SUPPORTED, 00055 NUM_SOURCE_COLS 00056 };
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.
Definition at line 46 of file dialog-commodity.h.
00046 { 00047 DIAG_COMM_CURRENCY, 00049 DIAG_COMM_NON_CURRENCY, 00051 DIAG_COMM_ALL, 00053 } dialog_commodity_mode;
| 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.
| cb | The function to be called when the user clicks the help button. |
Definition at line 130 of file dialog-commodity.c.
| 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.
Definition at line 1163 of file dialog-commodity.c.
01165 { 01166 gnc_commodity *result; 01167 01168 ENTER(" "); 01169 result = gnc_ui_common_commodity_modal(commodity, parent, NULL, NULL, 01170 NULL, NULL, 0); 01171 LEAVE(" "); 01172 return result != NULL; 01173 }
| gchar * gnc_ui_namespace_picker_ns | ( | GtkWidget * | cbe | ) |
Given a combo box, return the currently selected namespaces.
| cbe | The combo box of namespaces. |
Definition at line 665 of file dialog-commodity.c.
00666 { 00667 char *namespace; 00668 00669 g_return_val_if_fail(GTK_IS_COMBO_BOX_ENTRY (cbe), NULL); 00670 00671 namespace = gtk_combo_box_get_active_text(GTK_COMBO_BOX(cbe)); 00672 00673 if (safe_strcmp (namespace, GNC_COMMODITY_NS_ISO) == 0) { 00674 /* In case the user types in ISO4217, map it to CURRENCY. */ 00675 g_free(namespace); 00676 return strdup(GNC_COMMODITY_NS_CURRENCY); 00677 } else 00678 return namespace; 00679 }
| gnc_commodity * gnc_ui_new_commodity_modal | ( | const char * | default_namespace, | |
| GtkWidget * | parent | |||
| ) |
External routine for popping up the new commodity dialog box.
Definition at line 1141 of file dialog-commodity.c.
01143 { 01144 gnc_commodity *result; 01145 01146 ENTER(" "); 01147 result = gnc_ui_common_commodity_modal(NULL, parent, default_namespace, NULL, 01148 NULL, NULL, 0); 01149 LEAVE(" "); 01150 return result; 01151 }
| gnc_commodity * gnc_ui_new_commodity_modal_full | ( | const char * | namespace, | |
| GtkWidget * | parent, | |||
| const char * | cusip, | |||
| const char * | fullname, | |||
| const char * | mnemonic, | |||
| int | fraction | |||
| ) |
Create and run the new/edit commodity dialog.
Definition at line 1122 of file dialog-commodity.c.
01128 { 01129 gnc_commodity *result; 01130 01131 ENTER(" "); 01132 result = gnc_ui_common_commodity_modal(NULL, parent, namespace, cusip, 01133 fullname, mnemonic, 10000); 01134 LEAVE(" "); 01135 return result; 01136 }
| void gnc_ui_select_commodity_changed_cb | ( | GtkComboBoxEntry * | cbe, | |
| 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.
| cbe | A pointer to the commodity name entry widget in the dialog. | |
| user_data | A pointer to the data structure describing the current state of the commodity picker. |
Definition at line 361 of file dialog-commodity.c.
00363 { 00364 SelectCommodityWindow * w = user_data; 00365 gchar *namespace, *fullname; 00366 gboolean ok; 00367 00368 ENTER("cbe=%p, user_data=%p", cbe, user_data); 00369 namespace = gnc_ui_namespace_picker_ns (w->namespace_combo); 00370 fullname = gtk_combo_box_get_active_text(GTK_COMBO_BOX(w->commodity_combo)); 00371 DEBUG("namespace=%s, name=%s", namespace, fullname); 00372 w->selection = gnc_commodity_table_find_full(gnc_get_current_commodities(), 00373 namespace, fullname); 00374 g_free(fullname); 00375 g_free(namespace); 00376 00377 ok = (w->selection != NULL); 00378 gtk_widget_set_sensitive(w->ok_button, ok); 00379 gtk_dialog_set_default_response(GTK_DIALOG(w->dialog), ok ? 0 : 2); 00380 LEAVE("sensitive=%d, default = %d", ok, ok ? 0 : 2); 00381 }
| 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.
| orig_sel | A pointer to a commodity that should initially be selected in the dialog box. | |
| parent | The parent window for this new selection window. | |
| mode | Determines which namespaces the user may select a commodity from. |
Definition at line 218 of file dialog-commodity.c.
00221 { 00222 return gnc_ui_select_commodity_modal_full(orig_sel, 00223 parent, 00224 mode, 00225 NULL, 00226 NULL, 00227 NULL, 00228 NULL); 00229 }
| 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.
| orig_sel | A pointer to a commodity that should initially be selected in the dialog box. | |
| parent | The parent window of the new dialog. | |
| user_message | A 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. | |
| cusip | If 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. | |
| fullname | If 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. | |
| mnemonic | If 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. | |
| mode | Determines which namespaces the user may select a commodity from. |
Definition at line 140 of file dialog-commodity.c.
00147 { 00148 gnc_commodity * retval = NULL; 00149 const gchar *initial; 00150 gchar *user_prompt_text; 00151 SelectCommodityWindow * win; 00152 gboolean done; 00153 gint value; 00154 00155 win = gnc_ui_select_commodity_create(orig_sel, mode); 00156 win->default_cusip=cusip; 00157 win->default_fullname=fullname; 00158 win->default_mnemonic=mnemonic; 00159 00160 if (parent) 00161 gtk_window_set_transient_for (GTK_WINDOW (win->dialog), GTK_WINDOW (parent)); 00162 00163 if (user_message != NULL) 00164 initial = user_message; 00165 else if ((cusip != NULL) || (fullname != NULL) || (mnemonic != NULL)) 00166 initial = _("\nPlease select a commodity to match:"); 00167 else 00168 initial = ""; 00169 00170 user_prompt_text = 00171 g_strdup_printf("%s%s%s%s%s%s%s", 00172 initial, 00173 fullname ? _("\nCommodity: ") : "", 00174 fullname ? fullname : "", 00175 /* Translators: Replace here and later CUSIP by the name of your local 00176 National Securities Identifying Number 00177 like gb:SEDOL, de:WKN, ch:Valorennummer, fr:SICOVAM ... 00178 See http://en.wikipedia.org/wiki/ISIN for hints. */ 00179 cusip ? _("\nExchange code (ISIN, CUSIP or similar): ") : "", 00180 cusip ? cusip : "", 00181 mnemonic ? _("\nMnemonic (Ticker symbol or similar): ") : "", 00182 mnemonic ? mnemonic : ""); 00183 gtk_label_set_text ((GtkLabel *)(win->select_user_prompt), 00184 user_prompt_text); 00185 g_free(user_prompt_text); 00186 00187 /* Run the dialog, handling the terminal conditions. */ 00188 done = FALSE; 00189 while (!done) { 00190 switch (value = gtk_dialog_run(GTK_DIALOG(win->dialog))) { 00191 case GTK_RESPONSE_OK: 00192 DEBUG("case OK"); 00193 retval = win->selection; 00194 done = TRUE; 00195 break; 00196 case GNC_RESPONSE_NEW: 00197 DEBUG("case NEW"); 00198 gnc_ui_select_commodity_new_cb(NULL, win); 00199 break; 00200 default: /* Cancel, Escape, Close, etc. */ 00201 DEBUG("default: %d", value); 00202 retval = NULL; 00203 done = TRUE; 00204 break; 00205 } 00206 } 00207 gtk_widget_destroy (GTK_WIDGET (win->dialog)); /* Close and destroy */ 00208 g_free(win); 00209 00210 return retval; 00211 }
| void gnc_ui_select_commodity_namespace_changed_cb | ( | GtkComboBoxEntry * | cbe, | |
| 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.
| cbe | A pointer to the commodity namespace entry widget in the dialog. | |
| user_data | A pointer to the data structure describing the current state of the commodity picker. |
Definition at line 401 of file dialog-commodity.c.
00403 { 00404 SelectCommodityWindow * w = user_data; 00405 gchar *namespace; 00406 00407 ENTER("cbe=%p, user_data=%p", cbe, user_data); 00408 namespace = gnc_ui_namespace_picker_ns (w->namespace_combo); 00409 DEBUG("namespace=%s", namespace); 00410 gnc_ui_update_commodity_picker(w->commodity_combo, namespace, NULL); 00411 g_free(namespace); 00412 LEAVE(" "); 00413 }
| 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.
| button | A pointer to the "new" button widget in the dialog. | |
| user_data | A pointer to the data structure describing the current state of the commodity picker. |
Definition at line 319 of file dialog-commodity.c.
00321 { 00322 SelectCommodityWindow * w = user_data; 00323 00324 gchar * namespace = gnc_ui_namespace_picker_ns (w->namespace_combo); 00325 00326 const gnc_commodity * new_commodity = 00327 gnc_ui_new_commodity_modal_full(namespace, 00328 w->dialog, 00329 w->default_cusip, 00330 w->default_fullname, 00331 w->default_mnemonic, 00332 w->default_fraction); 00333 if(new_commodity) { 00334 gnc_ui_update_namespace_picker(w->namespace_combo, 00335 gnc_commodity_get_namespace(new_commodity), 00336 DIAG_COMM_ALL); 00337 gnc_ui_update_commodity_picker(w->commodity_combo, 00338 gnc_commodity_get_namespace(new_commodity), 00339 gnc_commodity_get_printname(new_commodity)); 00340 } 00341 g_free(namespace); 00342 }
| void gnc_ui_update_commodity_picker | ( | GtkWidget * | cbe, | |
| const gchar * | namespace, | |||
| const gchar * | sel | |||
| ) |
Given a combo box, fill in all the known commodities for the specified namespace, and then select one.
| cbe | The widget to populate with information. | |
| namespace | All commodities with this namespace will be added to the combo box. | |
| sel | The commodity that should be initially selected when the combo box appears. |
Definition at line 431 of file dialog-commodity.c.
00434 { 00435 GList * commodities; 00436 GList * iterator = NULL; 00437 GList * commodity_items = NULL; 00438 GtkComboBox *combo_box; 00439 GtkTreeModel *model; 00440 gnc_commodity_table *table; 00441 gint current = 0, match = 0; 00442 gchar *name; 00443 00444 g_return_if_fail(GTK_IS_COMBO_BOX_ENTRY(cbe)); 00445 g_return_if_fail(namespace); 00446 00447 /* Erase the old entries */ 00448 combo_box = GTK_COMBO_BOX(cbe); 00449 model = gtk_combo_box_get_model(combo_box); 00450 gtk_list_store_clear(GTK_LIST_STORE(model)); 00451 gtk_combo_box_set_active(combo_box, -1); 00452 00453 table = gnc_book_get_commodity_table (gnc_get_current_book ()); 00454 commodities = gnc_commodity_table_get_commodities(table, namespace); 00455 for(iterator = commodities; iterator; iterator = iterator->next) { 00456 commodity_items = 00457 g_list_append(commodity_items, 00458 (gpointer) gnc_commodity_get_printname(iterator->data)); 00459 } 00460 g_list_free(commodities); 00461 00462 commodity_items = g_list_sort(commodity_items, collate); 00463 for (iterator = commodity_items; iterator; iterator = iterator->next) { 00464 name = (char *)iterator->data; 00465 gtk_combo_box_append_text(combo_box, name); 00466 if (init_string && g_utf8_collate(name, init_string) == 0) 00467 match = current; 00468 current++; 00469 } 00470 00471 gtk_combo_box_set_active(combo_box, match); 00472 g_list_free(commodity_items); 00473 }
| void gnc_ui_update_namespace_picker | ( | GtkWidget * | cbe, | |
| const gchar * | sel, | |||
| dialog_commodity_mode | mode | |||
| ) |
Given a combo box, fill in the known commodity namespaces and then select one.
| cbe | The widget to populate with information. | |
| sel | The namespace that should be initially selected when the combo box appears. | |
| mode | Determines which namespaces the user may select a commodity |
1.5.2