diff --git a/src/ag-chart.c b/src/ag-chart.c index 68caae2..60ea2cc 100644 --- a/src/ag-chart.c +++ b/src/ag-chart.c @@ -46,6 +46,7 @@ typedef struct _AgChartPrivate { gchar *save_buffer; GList *planet_list; gchar *note; + gint db_id; } AgChartPrivate; enum { @@ -54,6 +55,7 @@ enum { PROP_COUNTRY, PROP_CITY, PROP_NOTE, + PROP_DBID, PROP_LAST }; @@ -148,6 +150,24 @@ ag_chart_class_init(AgChartClass *klass) PROP_NOTE, properties[PROP_NOTE] ); + + properties[PROP_DBID] = g_param_spec_int( + "db-id", + "DB ID", + "Database ID", + -1, G_MAXINT, + -1, + G_PARAM_STATIC_NICK + | G_PARAM_STATIC_NAME + | G_PARAM_STATIC_BLURB + | G_PARAM_READABLE + | G_PARAM_WRITABLE + ); + g_object_class_install_property( + gobject_class, + PROP_DBID, + properties[PROP_DBID] + ); } static void @@ -187,6 +207,16 @@ ag_chart_set_property(GObject *gobject, case PROP_NOTE: ag_chart_set_note(AG_CHART(gobject), g_value_get_string(value)); + break; + + case PROP_DBID: + ag_chart_set_db_id(AG_CHART(gobject), g_value_get_int(value)); + + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, param_spec); + break; } } @@ -218,6 +248,16 @@ ag_chart_get_property(GObject *gobject, case PROP_NOTE: g_value_set_string(value, priv->note); + break; + + case PROP_DBID: + g_value_set_int(value, priv->db_id); + + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, param_spec); + break; } } @@ -1275,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; } @@ -2007,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); @@ -2050,3 +2091,21 @@ ag_chart_get_db_save(AgChart *chart, gint db_id) return save_data; } + +void +ag_chart_set_db_id(AgChart *chart, gint id) +{ + AgChartPrivate *priv = ag_chart_get_instance_private(chart); + + priv->db_id = id; + + g_object_notify_by_pspec(G_OBJECT(chart), properties[PROP_DBID]); +} + +int +ag_chart_get_db_id(AgChart *chart) +{ + AgChartPrivate *priv = ag_chart_get_instance_private(chart); + + return priv->db_id; +} diff --git a/src/ag-chart.h b/src/ag-chart.h index 0bf8bb3..6082762 100644 --- a/src/ag-chart.h +++ b/src/ag-chart.h @@ -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, @@ -147,6 +147,10 @@ GdkPixbuf *ag_chart_get_pixbuf(AgChart *chart, AgDisplayTheme *theme, GError **err); +void ag_chart_set_db_id(AgChart *chart, gint db_id); + +gint ag_chart_get_db_id(AgChart *chart); + #define AG_CHART_ERROR (ag_chart_error_quark()) GQuark ag_chart_error_quark(void); diff --git a/src/ag-window.c b/src/ag-window.c index 76670dc..e0a1b32 100644 --- a/src/ag-window.c +++ b/src/ag-window.c @@ -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; }