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:
parent
a7afd80235
commit
32534da807
@ -1315,6 +1315,7 @@ ag_chart_new_from_db_save(AgDbChartSave *save_data,
|
|||||||
ag_chart_set_country(chart, save_data->country);
|
ag_chart_set_country(chart, save_data->country);
|
||||||
ag_chart_set_city(chart, save_data->city);
|
ag_chart_set_city(chart, save_data->city);
|
||||||
ag_chart_set_note(chart, save_data->note);
|
ag_chart_set_note(chart, save_data->note);
|
||||||
|
ag_chart_set_db_id(chart, save_data->db_id);
|
||||||
|
|
||||||
return chart;
|
return chart;
|
||||||
}
|
}
|
||||||
@ -2047,14 +2048,14 @@ ag_chart_get_note(AgChart *chart)
|
|||||||
}
|
}
|
||||||
|
|
||||||
AgDbChartSave *
|
AgDbChartSave *
|
||||||
ag_chart_get_db_save(AgChart *chart, gint db_id)
|
ag_chart_get_db_save(AgChart *chart)
|
||||||
{
|
{
|
||||||
GsweCoordinates *coords;
|
GsweCoordinates *coords;
|
||||||
AgChartPrivate *priv = ag_chart_get_instance_private(chart);
|
AgChartPrivate *priv = ag_chart_get_instance_private(chart);
|
||||||
AgDbChartSave *save_data = ag_db_chart_save_new(TRUE);
|
AgDbChartSave *save_data = ag_db_chart_save_new(TRUE);
|
||||||
GsweTimestamp *timestamp = gswe_moment_get_timestamp(GSWE_MOMENT(chart));
|
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->name = g_strdup(priv->name);
|
||||||
save_data->country = g_strdup(priv->country);
|
save_data->country = g_strdup(priv->country);
|
||||||
|
@ -139,7 +139,7 @@ void ag_chart_set_note(AgChart *chart, const gchar *note);
|
|||||||
|
|
||||||
const gchar *ag_chart_get_note(AgChart *chart);
|
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,
|
GdkPixbuf *ag_chart_get_pixbuf(AgChart *chart,
|
||||||
guint image_size,
|
guint image_size,
|
||||||
|
@ -811,7 +811,7 @@ ag_window_recalculate_chart(AgWindow *window, gboolean set_everything)
|
|||||||
);
|
);
|
||||||
|
|
||||||
chart_data = (priv->chart)
|
chart_data = (priv->chart)
|
||||||
? ag_chart_get_db_save(priv->chart, db_id)
|
? ag_chart_get_db_save(priv->chart)
|
||||||
: NULL
|
: NULL
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -1213,9 +1213,6 @@ gboolean
|
|||||||
ag_window_can_close(AgWindow *window, gboolean display_dialog)
|
ag_window_can_close(AgWindow *window, gboolean display_dialog)
|
||||||
{
|
{
|
||||||
GET_PRIV(window);
|
GET_PRIV(window);
|
||||||
gint db_id = (priv->saved_data)
|
|
||||||
? priv->saved_data->db_id
|
|
||||||
: -1;
|
|
||||||
AgDbChartSave *save_data = NULL;
|
AgDbChartSave *save_data = NULL;
|
||||||
AgDb *db = ag_db_get();
|
AgDb *db = ag_db_get();
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
@ -1223,7 +1220,7 @@ ag_window_can_close(AgWindow *window, gboolean display_dialog)
|
|||||||
|
|
||||||
if (priv->chart) {
|
if (priv->chart) {
|
||||||
ag_window_recalculate_chart(window, TRUE);
|
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 (
|
if (
|
||||||
!ag_db_chart_save_identical(priv->saved_data, save_data, FALSE)
|
!ag_db_chart_save_identical(priv->saved_data, save_data, FALSE)
|
||||||
@ -1292,14 +1289,12 @@ ag_window_save_action(GSimpleAction *action,
|
|||||||
GET_PRIV(window);
|
GET_PRIV(window);
|
||||||
AgDb *db = ag_db_get();
|
AgDb *db = ag_db_get();
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
gint old_id;
|
|
||||||
AgDbChartSave *save_data;
|
AgDbChartSave *save_data;
|
||||||
|
|
||||||
ag_window_recalculate_chart(window, TRUE);
|
ag_window_recalculate_chart(window, TRUE);
|
||||||
|
|
||||||
if (!ag_window_can_close(window, FALSE)) {
|
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);
|
||||||
save_data = ag_chart_get_db_save(priv->chart, old_id);
|
|
||||||
|
|
||||||
if (!ag_db_chart_save(db, save_data, &err)) {
|
if (!ag_db_chart_save(db, save_data, &err)) {
|
||||||
ag_app_message_dialog(
|
ag_app_message_dialog(
|
||||||
@ -2827,7 +2822,7 @@ ag_window_set_chart(AgWindow *window, AgChart *chart)
|
|||||||
window
|
window
|
||||||
);
|
);
|
||||||
g_object_ref(chart);
|
g_object_ref(chart);
|
||||||
priv->saved_data = ag_chart_get_db_save(chart, -1);
|
priv->saved_data = ag_chart_get_db_save(chart);
|
||||||
} else {
|
} else {
|
||||||
priv->saved_data = NULL;
|
priv->saved_data = NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user