Move DB ID handling deeper into AgChart

The AgWindow doesn’t have to send a DB ID any more.

Fixes #97
This commit is contained in:
Gergely Polonkai 2014-10-01 23:42:25 +02:00
parent a7afd80235
commit 32534da807
3 changed files with 8 additions and 12 deletions

View File

@ -1315,6 +1315,7 @@ ag_chart_new_from_db_save(AgDbChartSave *save_data,
ag_chart_set_country(chart, save_data->country);
ag_chart_set_city(chart, save_data->city);
ag_chart_set_note(chart, save_data->note);
ag_chart_set_db_id(chart, save_data->db_id);
return chart;
}
@ -2047,14 +2048,14 @@ ag_chart_get_note(AgChart *chart)
}
AgDbChartSave *
ag_chart_get_db_save(AgChart *chart, gint db_id)
ag_chart_get_db_save(AgChart *chart)
{
GsweCoordinates *coords;
AgChartPrivate *priv = ag_chart_get_instance_private(chart);
AgDbChartSave *save_data = ag_db_chart_save_new(TRUE);
GsweTimestamp *timestamp = gswe_moment_get_timestamp(GSWE_MOMENT(chart));
save_data->db_id = db_id;
save_data->db_id = priv->db_id;
save_data->name = g_strdup(priv->name);
save_data->country = g_strdup(priv->country);

View File

@ -139,7 +139,7 @@ void ag_chart_set_note(AgChart *chart, const gchar *note);
const gchar *ag_chart_get_note(AgChart *chart);
AgDbChartSave *ag_chart_get_db_save(AgChart *chart, gint db_id);
AgDbChartSave *ag_chart_get_db_save(AgChart *chart);
GdkPixbuf *ag_chart_get_pixbuf(AgChart *chart,
guint image_size,

View File

@ -811,7 +811,7 @@ ag_window_recalculate_chart(AgWindow *window, gboolean set_everything)
);
chart_data = (priv->chart)
? ag_chart_get_db_save(priv->chart, db_id)
? ag_chart_get_db_save(priv->chart)
: NULL
;
@ -1213,9 +1213,6 @@ gboolean
ag_window_can_close(AgWindow *window, gboolean display_dialog)
{
GET_PRIV(window);
gint db_id = (priv->saved_data)
? priv->saved_data->db_id
: -1;
AgDbChartSave *save_data = NULL;
AgDb *db = ag_db_get();
GError *err = NULL;
@ -1223,7 +1220,7 @@ ag_window_can_close(AgWindow *window, gboolean display_dialog)
if (priv->chart) {
ag_window_recalculate_chart(window, TRUE);
save_data = ag_chart_get_db_save(priv->chart, db_id);
save_data = ag_chart_get_db_save(priv->chart);
if (
!ag_db_chart_save_identical(priv->saved_data, save_data, FALSE)
@ -1292,14 +1289,12 @@ ag_window_save_action(GSimpleAction *action,
GET_PRIV(window);
AgDb *db = ag_db_get();
GError *err = NULL;
gint old_id;
AgDbChartSave *save_data;
ag_window_recalculate_chart(window, TRUE);
if (!ag_window_can_close(window, FALSE)) {
old_id = (priv->saved_data) ? priv->saved_data->db_id : -1;
save_data = ag_chart_get_db_save(priv->chart, old_id);
save_data = ag_chart_get_db_save(priv->chart);
if (!ag_db_chart_save(db, save_data, &err)) {
ag_app_message_dialog(
@ -2827,7 +2822,7 @@ ag_window_set_chart(AgWindow *window, AgChart *chart)
window
);
g_object_ref(chart);
priv->saved_data = ag_chart_get_db_save(chart, -1);
priv->saved_data = ag_chart_get_db_save(chart);
} else {
priv->saved_data = NULL;
}