Enhance the "remove old prices" code to have options to retain the

last price entered, and to retain any user entered prices.  The
"remove old" button should always be active.  Group the
"Add/Edit/Remove" buttons for a single price.  Allow the prices dialog
to be closed with the escape key.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@12033 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
David Hampton 2005-11-26 03:58:06 +00:00
parent 5f85820cd7
commit bf317b5a44
5 changed files with 344 additions and 117 deletions

View File

@ -1,5 +1,12 @@
2005-11-25 David Hampton <hampton@employees.org>
* src/gnome/dialog-price-edit-db.c: Enhance the "remove old
prices" code to have options to retain the last price entered, and
to retain any user entered prices. The "remove old" button should
always be active. Group the "Add/Edit/Remove" buttons for a
single price. Allow the prices dialog to be closed with the
escape key.
* src/gnome-utils/gnc-date-edit.c: Show widget by default when its
created for a glade dialog.

View File

@ -964,6 +964,8 @@ gnc_pricedb_remove_price(GNCPriceDB *db, GNCPrice *p)
typedef struct {
GNCPriceDB *db;
Timespec cutoff;
gboolean delete_user;
gboolean delete_last;
GSList *list;
} remove_info;
@ -971,27 +973,96 @@ static gboolean
check_one_price_date (GNCPrice *price, gpointer user_data)
{
remove_info *data = user_data;
const gchar *source;
Timespec pt;
ENTER("price %p (%s), data %p", price,
gnc_commodity_get_mnemonic(gnc_price_get_commodity(price)),
user_data);
if (!data->delete_user) {
source = gnc_price_get_source (price);
if (strcmp(source, "Finance::Quote") != 0) {
LEAVE("Not an automatic quote");
return TRUE;
}
}
pt = gnc_price_get_time (price);
if (timespec_cmp (&pt, &data->cutoff) < 0)
{
gchar buf[40];
gnc_timespec_to_iso8601_buff(pt , buf);
DEBUG("checking date %s", buf);
}
if (timespec_cmp (&pt, &data->cutoff) < 0) {
data->list = g_slist_prepend(data->list, price);
DEBUG("will delete");
}
LEAVE(" ");
return TRUE;
}
static void
pricedb_remove_foreach_pricelist (gpointer key,
gpointer val,
gpointer user_data)
{
GList *price_list = (GList *) val;
GList *node = price_list;
remove_info *data = (remove_info *) user_data;
ENTER("key %p, value %p, data %p", key, val, user_data);
/* The most recent price is the first in the list */
if (!data->delete_last)
node = g_list_next(node);
/* now check each item in the list */
g_list_foreach(node, (GFunc)check_one_price_date, data);
LEAVE(" ");
}
static void
pricedb_remove_foreach_currencies_hash (gpointer key,
gpointer val,
gpointer user_data)
{
GHashTable *currencies_hash = (GHashTable *) val;
ENTER("key %p, value %p, data %p", key, val, user_data);
g_hash_table_foreach(currencies_hash,
pricedb_remove_foreach_pricelist, user_data);
LEAVE(" ");
}
gboolean
gnc_pricedb_remove_old_prices(GNCPriceDB *db, Timespec cutoff)
gnc_pricedb_remove_old_prices(GNCPriceDB *db,
Timespec cutoff,
gboolean delete_user,
gboolean delete_last)
{
remove_info data;
GSList *item;
data.db = db;
data.cutoff = cutoff;
data.delete_user = delete_user;
data.delete_last = delete_last;
data.list = NULL;
ENTER("db %p, delet_user %d, delete_last %d", db, delete_user, delete_last);
{
gchar buf[40];
gnc_timespec_to_iso8601_buff(cutoff, buf);
DEBUG("checking date %s", buf);
}
/* Traverse the database once building up an external list of prices
* to be deleted */
gnc_pricedb_foreach_price(db, check_one_price_date, &data, FALSE);
g_hash_table_foreach(db->commodity_hash,
pricedb_remove_foreach_currencies_hash,
&data);
if (data.list == NULL)
return FALSE;
@ -1002,6 +1073,7 @@ gnc_pricedb_remove_old_prices(GNCPriceDB *db, Timespec cutoff)
}
g_slist_free(data.list);
LEAVE(" ");
return TRUE;
}

View File

@ -279,7 +279,8 @@ gboolean gnc_pricedb_add_price(GNCPriceDB *db, GNCPrice *p);
pricedb. Returns TRUE if successful, FALSE otherwise. */
gboolean gnc_pricedb_remove_price(GNCPriceDB *db, GNCPrice *p);
gboolean gnc_pricedb_remove_old_prices(GNCPriceDB *db, Timespec cutoff);
gboolean gnc_pricedb_remove_old_prices(GNCPriceDB *db, Timespec cutoff,
gboolean delete_user, gboolean delete_last);
/** gnc_pricedb_lookup_latest - find the most recent price for the
given commodity in the given currency. Returns NULL on

View File

@ -53,6 +53,7 @@ static QofLogModule log_module = GNC_MOD_GUI;
void gnc_prices_dialog_window_destroy_cb (GtkObject *object, gpointer data);
void gnc_prices_dialog_close_cb (GtkDialog *dialog, gpointer data);
void gnc_prices_dialog_response (GtkDialog *dialog, gint response_id, gpointer data);
void gnc_prices_dialog_edit_clicked (GtkWidget *widget, gpointer data);
void gnc_prices_dialog_remove_clicked (GtkWidget *widget, gpointer data);
@ -69,7 +70,6 @@ typedef struct
GtkWidget * edit_button;
GtkWidget * remove_button;
GtkWidget * remove_old_button;
GNCPriceDB *price_db;
GNCPrice * price; /* Currently selected price */
@ -90,10 +90,25 @@ gnc_prices_dialog_window_destroy_cb (GtkObject *object, gpointer data)
pdb_dialog->price = NULL;
}
if (pdb_dialog->dialog) {
gtk_widget_destroy(pdb_dialog->dialog);
pdb_dialog->dialog = NULL;
}
g_free (pdb_dialog);
LEAVE(" ");
}
void
gnc_prices_dialog_close_cb (GtkDialog *dialog, gpointer data)
{
PricesDialog *pdb_dialog = data;
ENTER(" ");
gnc_close_gui_component_by_data (DIALOG_PRICE_DB_CM_CLASS, pdb_dialog);
LEAVE(" ");
}
void
gnc_prices_dialog_response (GtkDialog *dialog, gint response_id, gpointer data)
{
@ -146,42 +161,20 @@ void
gnc_prices_dialog_remove_old_clicked (GtkWidget *widget, gpointer data)
{
PricesDialog *pdb_dialog = data;
GtkWidget *dialog;
GtkWidget *label;
GtkWidget *date;
GtkWidget *vbox;
GladeXML *xml;
GtkWidget *dialog, *button, *date;
gint result;
gboolean delete_user, delete_last;
ENTER(" ");
dialog = gtk_dialog_new_with_buttons (_("Remove old prices"),
GTK_WINDOW (pdb_dialog->dialog),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_STOCK_CANCEL,
GTK_RESPONSE_REJECT,
GTK_STOCK_OK,
GTK_RESPONSE_ACCEPT,
NULL);
vbox = GTK_DIALOG (dialog)->vbox;
gtk_box_set_spacing (GTK_BOX (vbox), 3);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 3);
label = gtk_label_new (_("All prices before the date below "
"will be deleted."));
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
date = gnc_date_edit_new (time (NULL), FALSE, FALSE);
g_object_ref (date);
gtk_object_sink (GTK_OBJECT (date));
gtk_box_pack_start (GTK_BOX (vbox), date, FALSE, FALSE, 0);
gtk_widget_show (date);
xml = gnc_glade_xml_new ("price.glade", "Deletion Date");
dialog = glade_xml_get_widget (xml, "Deletion Date");
date = glade_xml_get_widget (xml, "date");
glade_xml_signal_autoconnect_full(xml, gnc_glade_autoconnect_full_func, pdb_dialog);
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (pdb_dialog->dialog));
result = gtk_dialog_run (GTK_DIALOG (dialog));
if (result == GTK_RESPONSE_ACCEPT)
if (result == GTK_RESPONSE_OK)
{
GNCBook *book = gnc_get_current_book ();
GNCPriceDB *pdb = gnc_book_get_pricedb (book);
@ -191,10 +184,14 @@ gnc_prices_dialog_remove_old_clicked (GtkWidget *widget, gpointer data)
ts.tv_sec = gnc_date_edit_get_date (GNC_DATE_EDIT (date));
ts.tv_nsec = 0;
gnc_pricedb_remove_old_prices(pdb, ts);
button = glade_xml_get_widget (xml, "delete_manual");
delete_user = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
button = glade_xml_get_widget (xml, "delete_last");
delete_last = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
gnc_pricedb_remove_old_prices(pdb, ts, delete_user, delete_last);
}
g_object_unref (date);
gtk_widget_destroy(dialog);
LEAVE(" ");
}
@ -256,8 +253,6 @@ gnc_prices_dialog_selection_changed (GtkTreeSelection *treeselection,
pdb_dialog->price != NULL);
gtk_widget_set_sensitive (pdb_dialog->remove_button,
pdb_dialog->price != NULL);
gtk_widget_set_sensitive (pdb_dialog->remove_old_button,
pdb_dialog->price != NULL);
LEAVE(" ");
}
@ -364,9 +359,6 @@ gnc_prices_dialog_create (GtkWidget * parent, PricesDialog *pdb_dialog)
button = glade_xml_get_widget (xml, "remove_button");
pdb_dialog->remove_button = button;
button = glade_xml_get_widget (xml, "remove_old_button");
pdb_dialog->remove_old_button = button;
}
gnc_restore_window_size(GCONF_SECTION, GTK_WINDOW(pdb_dialog->dialog));

View File

@ -20,6 +20,7 @@
<property name="has_separator">True</property>
<signal name="response" handler="gnc_prices_dialog_response" last_modification_time="Tue, 25 Nov 2003 06:49:39 GMT"/>
<signal name="destroy" handler="gnc_prices_dialog_window_destroy_cb" last_modification_time="Tue, 25 Nov 2003 07:56:53 GMT"/>
<signal name="close" handler="gnc_prices_dialog_close_cb" after="yes" last_modification_time="Sat, 26 Nov 2005 02:15:35 GMT"/>
<child internal-child="vbox">
<widget class="GtkVBox" id="vbox121">
@ -123,79 +124,6 @@
</widget>
</child>
<child>
<widget class="GtkButton" id="remove_old_button">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="tooltip" translatable="yes">Remove prices older than a user-entered date</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="gnc_prices_dialog_remove_old_clicked" last_modification_time="Tue, 25 Nov 2003 06:48:20 GMT"/>
<child>
<widget class="GtkAlignment" id="alignment6">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<property name="top_padding">0</property>
<property name="bottom_padding">0</property>
<property name="left_padding">0</property>
<property name="right_padding">0</property>
<child>
<widget class="GtkHBox" id="hbox116">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">2</property>
<child>
<widget class="GtkImage" id="image6">
<property name="visible">True</property>
<property name="stock">gtk-remove</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label8477427">
<property name="visible">True</property>
<property name="label" translatable="yes">Remove _Old</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkButton" id="edit_button">
<property name="visible">True</property>
@ -269,6 +197,78 @@
</widget>
</child>
<child>
<widget class="GtkButton" id="remove_old_button">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Remove prices older than a user-entered date</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<signal name="clicked" handler="gnc_prices_dialog_remove_old_clicked" last_modification_time="Tue, 25 Nov 2003 06:48:20 GMT"/>
<child>
<widget class="GtkAlignment" id="alignment6">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<property name="top_padding">0</property>
<property name="bottom_padding">0</property>
<property name="left_padding">0</property>
<property name="right_padding">0</property>
<child>
<widget class="GtkHBox" id="hbox116">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">2</property>
<child>
<widget class="GtkImage" id="image6">
<property name="visible">True</property>
<property name="stock">gtk-remove</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label8477427">
<property name="visible">True</property>
<property name="label" translatable="yes">Remove _Old</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkButton" id="get_quotes_button">
<property name="visible">True</property>
@ -658,7 +658,7 @@
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char" translatable="yes">*</property>
<property name="invisible_char">*</property>
<property name="activates_default">False</property>
</widget>
<packing>
@ -762,4 +762,159 @@
</child>
</widget>
<widget class="GtkDialog" id="Deletion Date">
<property name="visible">True</property>
<property name="title" translatable="yes"></property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="has_separator">True</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox19">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area19">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="cancelbutton1">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-6</property>
</widget>
</child>
<child>
<widget class="GtkButton" id="okbutton1">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-ok</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-5</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
<child>
<widget class="GtkVBox" id="vbox123">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkLabel" id="label8477429">
<property name="visible">True</property>
<property name="label" translatable="yes">Delete all downloaded prices
dated earlier than this date.</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">True</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="Custom" id="date">
<property name="visible">True</property>
<property name="creation_function">gnc_date_edit_new_glade</property>
<property name="int1">0</property>
<property name="int2">0</property>
<property name="last_modification_time">Fri, 25 Nov 2005 22:13:25 GMT</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="delete_manual">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Delete _manually entered prices too</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="delete_last">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Delete _last price for a stock</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>