29 #include <glib/gi18n.h>
31 #include "guile-mappings.h"
34 #include "dialog-utils.h"
35 #include "gnc-amount-edit.h"
36 #include "gnc-commodity-edit.h"
37 #include "gnc-general-select.h"
38 #include "gnc-component-manager.h"
40 #include "gnc-date-edit.h"
42 #include "gnc-gui-query.h"
44 #include "gnc-session.h"
48 #include "gnome-utils/gnc-warnings.h"
49 #include "guile-util.h"
50 #include "engine-helpers-guile.h"
51 #include "swig-runtime.h"
54 #define DIALOG_PRICE_DB_CM_CLASS "dialog-price-edit-db"
55 #define STATE_SECTION "dialogs/edit_prices"
56 #define GNC_PREFS_GROUP "dialogs.pricedb-editor"
62 void gnc_prices_dialog_window_destroy_cb (GtkObject *
object, gpointer data);
63 void gnc_prices_dialog_close_cb (GtkDialog *dialog, gpointer data);
64 void gnc_prices_dialog_response (GtkDialog *dialog, gint response_id, gpointer data);
65 void gnc_prices_dialog_edit_clicked (GtkWidget *widget, gpointer data);
66 void gnc_prices_dialog_remove_clicked (GtkWidget *widget, gpointer data);
67 void gnc_prices_dialog_remove_old_clicked (GtkWidget *widget, gpointer data);
68 void gnc_prices_dialog_add_clicked (GtkWidget *widget, gpointer data);
69 void gnc_prices_dialog_get_quotes_clicked (GtkWidget *widget, gpointer data);
81 GtkWidget * edit_button;
82 GtkWidget * remove_button;
87 gnc_prices_dialog_window_destroy_cb (GtkObject *
object, gpointer data)
92 gnc_unregister_gui_component_by_data (DIALOG_PRICE_DB_CM_CLASS, pdb_dialog);
94 if (pdb_dialog->dialog)
96 gtk_widget_destroy(pdb_dialog->dialog);
97 pdb_dialog->dialog = NULL;
106 gnc_prices_dialog_close_cb (GtkDialog *dialog, gpointer data)
111 gnc_close_gui_component_by_data (DIALOG_PRICE_DB_CM_CLASS, pdb_dialog);
117 gnc_prices_dialog_response (GtkDialog *dialog, gint response_id, gpointer data)
122 gnc_close_gui_component_by_data (DIALOG_PRICE_DB_CM_CLASS, pdb_dialog);
128 gnc_prices_dialog_edit_clicked (GtkWidget *widget, gpointer data)
137 LEAVE(
"no price selected");
140 if (g_list_next(price_list))
142 g_list_free(price_list);
143 LEAVE(
"too many prices selected");
147 gnc_price_edit_dialog (pdb_dialog->dialog, pdb_dialog->session,
148 price_list->data, GNC_PRICE_EDIT);
149 g_list_free(price_list);
162 gnc_prices_dialog_remove_clicked (GtkWidget *widget, gpointer data)
166 gint length, response;
173 LEAVE(
"no price selected");
177 length = g_list_length(price_list);
182 message = g_strdup_printf
185 ngettext(
"Are you sure you want to delete the selected price?",
186 "Are you sure you want to delete the %d selected prices?",
189 dialog = gtk_message_dialog_new(GTK_WINDOW(pdb_dialog->dialog),
190 GTK_DIALOG_DESTROY_WITH_PARENT,
191 GTK_MESSAGE_QUESTION,
193 "%s", _(
"Delete prices?"));
194 gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
197 gtk_dialog_add_buttons(GTK_DIALOG(dialog),
198 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
199 GTK_STOCK_DELETE, GTK_RESPONSE_YES,
201 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_YES);
202 response = gnc_dialog_run(GTK_DIALOG(dialog), GNC_PREF_WARN_PRICE_QUOTES_DEL);
203 gtk_widget_destroy(dialog);
207 response = GTK_RESPONSE_YES;
210 if (response == GTK_RESPONSE_YES)
212 g_list_foreach(price_list, (GFunc)remove_helper, pdb_dialog->price_db);
214 g_list_free(price_list);
220 gnc_prices_dialog_remove_old_clicked (GtkWidget *widget, gpointer data)
224 GtkWidget *dialog, *button, *date, *label, *box;
226 gboolean delete_user, delete_last;
229 builder = gtk_builder_new();
230 gnc_builder_add_from_file (builder,
"dialog-price.glade",
"Deletion Date");
232 dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"Deletion Date"));
234 box = GTK_WIDGET(gtk_builder_get_object (builder,
"date_hbox"));
235 date = gnc_date_edit_new (time (NULL), FALSE, FALSE);
237 gtk_box_pack_start (GTK_BOX (box), date, TRUE, TRUE, 0);
238 gtk_widget_show (date);
239 gtk_entry_set_activates_default(GTK_ENTRY(GNC_DATE_EDIT(date)->date_entry), TRUE);
240 label = GTK_WIDGET(gtk_builder_get_object (builder,
"date_label"));
241 gnc_date_make_mnemonic_target (GNC_DATE_EDIT(date), label);
243 gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, pdb_dialog);
245 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (pdb_dialog->dialog));
247 result = gtk_dialog_run (GTK_DIALOG (dialog));
248 if (result == GTK_RESPONSE_OK)
252 DEBUG(
"deleting prices");
253 ts.tv_sec = gnc_date_edit_get_date (GNC_DATE_EDIT (date));
256 button = GTK_WIDGET(gtk_builder_get_object (builder,
"delete_manual"));
257 delete_user = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
258 button = GTK_WIDGET(gtk_builder_get_object (builder,
"delete_last"));
259 delete_last = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
261 gnc_pricedb_remove_old_prices(pdb_dialog->price_db, ts,
262 delete_user, delete_last);
265 gtk_widget_destroy(dialog);
271 gnc_prices_dialog_add_clicked (GtkWidget *widget, gpointer data)
281 price = price_list->data;
282 g_list_free(price_list);
284 gnc_price_edit_dialog (pdb_dialog->dialog, pdb_dialog->session,
285 price, GNC_PRICE_NEW);
291 gnc_prices_dialog_get_quotes_clicked (GtkWidget *widget, gpointer data)
299 quotes_func = scm_c_eval_string (
"gnc:book-add-quotes");
300 if (!scm_is_procedure (quotes_func))
302 LEAVE(
" no procedure");
306 book_scm = gnc_book_to_scm (pdb_dialog->book);
307 if (scm_is_true (scm_not (book_scm)))
313 scm_window = SWIG_NewPointerObj(pdb_dialog->dialog,
314 SWIG_TypeQuery(
"_p_GtkWidget"), 0);
316 gnc_set_busy_cursor (NULL, TRUE);
317 scm_call_2 (quotes_func, scm_window, book_scm);
318 gnc_unset_busy_cursor (NULL);
322 gnc_gui_refresh_all ();
329 gnc_prices_dialog_selection_changed (GtkTreeSelection *treeselection,
338 length = g_list_length(price_list);
340 gtk_widget_set_sensitive (pdb_dialog->edit_button,
342 gtk_widget_set_sensitive (pdb_dialog->remove_button,
344 LEAVE(
"%d prices selected", length);
354 static GList *cm_list;
359 if (g_strcmp0 (name,
"template") == 0)
364 for (item = cm_list; item; item = g_list_next(item))
391 row_activated_cb (GtkTreeView *view, GtkTreePath *path,
392 GtkTreeViewColumn *column, gpointer data)
397 g_return_if_fail(view);
399 model = gtk_tree_view_get_model(view);
400 if (gtk_tree_model_get_iter(model, &iter, path))
402 if (gtk_tree_model_iter_has_child(model, &iter))
406 if (gtk_tree_view_row_expanded(view, path))
407 gtk_tree_view_collapse_row(view, path);
409 gtk_tree_view_expand_row(view, path, FALSE);
413 gnc_prices_dialog_edit_clicked(GTK_WIDGET(view), data);
419 gnc_prices_dialog_create (GtkWidget * parent,
PricesDialog *pdb_dialog)
421 GtkWidget *dialog, *scrolled_window;
424 GtkTreeSelection *selection;
427 builder = gtk_builder_new();
428 gnc_builder_add_from_file (builder,
"dialog-price.glade",
"Prices Dialog");
430 dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"Prices Dialog"));
431 pdb_dialog->dialog = dialog;
433 pdb_dialog->session = gnc_get_current_session();
439 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
442 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
445 scrolled_window = GTK_WIDGET(gtk_builder_get_object (builder,
"price_list_window"));
447 "state-section", STATE_SECTION,
448 "show-column-menu", TRUE,
450 pdb_dialog->price_tree = GNC_TREE_VIEW_PRICE(view);
451 gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET(view));
452 gnc_tree_view_price_set_filter (pdb_dialog->price_tree,
453 gnc_price_dialog_filter_ns_func,
454 gnc_price_dialog_filter_cm_func,
458 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
459 gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
460 g_signal_connect (G_OBJECT (selection),
"changed",
461 G_CALLBACK (gnc_prices_dialog_selection_changed), pdb_dialog);
463 g_signal_connect (G_OBJECT (view),
"row-activated",
464 G_CALLBACK (row_activated_cb), pdb_dialog);
470 button = GTK_WIDGET(gtk_builder_get_object (builder,
"edit_button"));
471 pdb_dialog->edit_button = button;
473 button = GTK_WIDGET(gtk_builder_get_object (builder,
"remove_button"));
474 pdb_dialog->remove_button = button;
478 button = GTK_WIDGET(gtk_builder_get_object (builder,
"get_quotes_button"));
479 gtk_widget_set_sensitive(button, FALSE);
483 gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, pdb_dialog);
485 g_object_unref(G_OBJECT(builder));
487 gnc_restore_window_size(GNC_PREFS_GROUP, GTK_WINDOW(pdb_dialog->dialog));
493 close_handler (gpointer user_data)
498 gnc_save_window_size(GNC_PREFS_GROUP, GTK_WINDOW(pdb_dialog->dialog));
500 gtk_widget_destroy (GTK_WIDGET (pdb_dialog->dialog));
506 refresh_handler (GHashTable *changes, gpointer user_data)
514 show_handler (
const char *klass, gint component_id,
515 gpointer user_data, gpointer iter_data)
522 LEAVE(
"no data strucure");
526 gtk_window_present (GTK_WINDOW(pdb_dialog->dialog));
540 gnc_prices_dialog (GtkWidget * parent)
546 if (gnc_forall_gui_components (DIALOG_PRICE_DB_CM_CLASS, show_handler, NULL))
548 LEAVE(
"existing dialog raised");
554 gnc_prices_dialog_create (parent, pdb_dialog);
556 component_id = gnc_register_gui_component (DIALOG_PRICE_DB_CM_CLASS,
557 refresh_handler, close_handler,
559 gnc_gui_component_set_session (component_id, pdb_dialog->session);
561 gtk_widget_grab_focus (GTK_WIDGET(pdb_dialog->price_tree));
563 gtk_widget_show (pdb_dialog->dialog);
a simple price database for gnucash
utility functions for the GnuCash UI
#define DEBUG(format, args...)
Use a 64-bit unsigned int timespec.
GList * gnc_tree_view_price_get_selected_prices(GncTreeViewPrice *view)
#define ENTER(format, args...)
GList * gnc_commodity_namespace_get_commodity_list(const gnc_commodity_namespace *name_space)
GNCPriceDB * gnc_pricedb_get_db(QofBook *book)
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
GtkTreeView implementation for gnucash price tree.
Currency selection widget.
QofBook * qof_session_get_book(const QofSession *session)
All type declarations for the whole Gnucash engine.
gboolean gnc_pricedb_remove_price(GNCPriceDB *db, GNCPrice *p)
gboolean gnc_pricedb_has_prices(GNCPriceDB *db, const gnc_commodity *commodity, const gnc_commodity *currency)
#define LEAVE(format, args...)
GtkTreeView * gnc_tree_view_price_new(QofBook *book, const gchar *first_property_name,...)
gboolean gnc_quote_source_fq_installed(void)
const gchar * QofLogModule