From 1ae1972cd04c3ab043fb4efdd9b255b2beffbaf6 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Mon, 11 Aug 2014 01:26:34 +0200 Subject: [PATCH 1/6] Remove chart name when going back to chart list Fixes #47 --- src/ag-window.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ag-window.c b/src/ag-window.c index f05e0d2..596b41a 100644 --- a/src/ag-window.c +++ b/src/ag-window.c @@ -1086,6 +1086,7 @@ ag_window_back_action(GSimpleAction *action, ag_window_load_chart_list(window); gtk_stack_set_visible_child_name(GTK_STACK(priv->stack), "list"); + gtk_header_bar_set_subtitle(GTK_HEADER_BAR(priv->header_bar), NULL); } } From 8b5f99d5b4eee94e403bd60285a2619fdcac8ab1 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Mon, 11 Aug 2014 22:16:13 +0200 Subject: [PATCH 2/6] Rename chart_changed() to ag_window_chart_changed() Just to follow naming conventions --- src/ag-window.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ag-window.c b/src/ag-window.c index 596b41a..2a3c226 100644 --- a/src/ag-window.c +++ b/src/ag-window.c @@ -834,7 +834,7 @@ ag_window_update_from_chart(AgWindow *window) } static void -chart_changed(AgChart *chart, AgWindow *window) +ag_window_chart_changed(AgChart *chart, AgWindow *window) { ag_window_redraw_chart(window); } @@ -966,7 +966,7 @@ ag_window_recalculate_chart(AgWindow *window) g_signal_connect( priv->chart, "changed", - G_CALLBACK(chart_changed), + G_CALLBACK(ag_window_chart_changed), window ); ag_window_redraw_chart(window); @@ -1664,7 +1664,7 @@ ag_window_set_chart(AgWindow *window, AgChart *chart) if (priv->chart != NULL) { g_signal_handlers_disconnect_by_func( priv->chart, - chart_changed, + ag_window_chart_changed, window ); g_clear_object(&(priv->chart)); @@ -1673,7 +1673,12 @@ ag_window_set_chart(AgWindow *window, AgChart *chart) ag_db_save_data_free(priv->saved_data); priv->chart = chart; - g_signal_connect(priv->chart, "changed", G_CALLBACK(chart_changed), window); + g_signal_connect( + priv->chart, + "changed", + G_CALLBACK(ag_window_chart_changed), + window + ); g_object_ref(chart); priv->saved_data = ag_chart_get_db_save(chart, -1); } From 6e736c9b8761cb65b174e45d1f49b003813c6829 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Mon, 11 Aug 2014 13:12:34 +0200 Subject: [PATCH 3/6] Add AgChart::note property --- src/ag-chart.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/ag-chart.c b/src/ag-chart.c index 0277b7a..619207e 100644 --- a/src/ag-chart.c +++ b/src/ag-chart.c @@ -28,7 +28,8 @@ enum { PROP_0, PROP_NAME, PROP_COUNTRY, - PROP_CITY + PROP_CITY, + PROP_NOTE, }; typedef enum { @@ -98,6 +99,17 @@ ag_chart_class_init(AgChartClass *klass) G_PARAM_READWRITE ) ); + g_object_class_install_property( + gobject_class, + PROP_NOTE, + g_param_spec_string( + "note", + "Note", + "Chart notes", + NULL, + G_PARAM_READWRITE + ) + ); } static void @@ -132,6 +144,11 @@ ag_chart_set_property(GObject *gobject, case PROP_CITY: ag_chart_set_city(AG_CHART(gobject), g_value_get_string(value)); + break; + + case PROP_NOTE: + ag_chart_set_note(AG_CHART(gobject), g_value_get_string(value)); + break; } } @@ -160,6 +177,10 @@ ag_chart_get_property(GObject *gobject, break; + case PROP_NOTE: + g_value_set_string(value, priv->note); + + break; } } From 5d028b5e17bad3e7877d25ad52ff8fc19539585f Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Mon, 11 Aug 2014 13:21:26 +0200 Subject: [PATCH 4/6] Add notification for property setters --- src/ag-chart.c | 74 +++++++++++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 28 deletions(-) diff --git a/src/ag-chart.c b/src/ag-chart.c index 619207e..bb21521 100644 --- a/src/ag-chart.c +++ b/src/ag-chart.c @@ -30,6 +30,7 @@ enum { PROP_COUNTRY, PROP_CITY, PROP_NOTE, + PROP_LAST }; typedef enum { @@ -42,6 +43,8 @@ G_DEFINE_QUARK(ag_chart_error_quark, ag_chart_error); G_DEFINE_TYPE_WITH_PRIVATE(AgChart, ag_chart, GSWE_TYPE_MOMENT); +static GParamSpec *properties[PROP_LAST]; + #define ag_g_variant_unref(v) \ if ((v) != NULL) { \ g_variant_unref((v)); \ @@ -66,49 +69,56 @@ ag_chart_class_init(AgChartClass *klass) gobject_class->get_property = ag_chart_get_property; gobject_class->finalize = ag_chart_finalize; + properties[PROP_NAME] = g_param_spec_string( + "name", + "Chart name", + "Name of the person on this chart", + NULL, + G_PARAM_READWRITE + ); g_object_class_install_property( gobject_class, PROP_NAME, - g_param_spec_string( - "name", - "Chart name", - "Name of the person on this chart", - NULL, - G_PARAM_READWRITE - ) + properties[PROP_NAME] + ); + + properties[PROP_COUNTRY] = g_param_spec_string( + "country", + "Country", + "Name of the country of birth", + NULL, + G_PARAM_READWRITE ); g_object_class_install_property( gobject_class, PROP_COUNTRY, - g_param_spec_string( - "country", - "Country name", - "Name of the country of birth", - NULL, - G_PARAM_READWRITE - ) + properties[PROP_COUNTRY] + ); + + properties[PROP_CITY] = g_param_spec_string( + "city", + "City name", + "Name of the city of birth", + NULL, + G_PARAM_READWRITE ); g_object_class_install_property( gobject_class, PROP_CITY, - g_param_spec_string( - "city", - "City name", - "Name of the city of birth", - NULL, - G_PARAM_READWRITE - ) + properties[PROP_CITY] + ); + + properties[PROP_NOTE] = g_param_spec_string( + "note", + "Note", + "Chart notes", + NULL, + G_PARAM_READWRITE ); g_object_class_install_property( gobject_class, PROP_NOTE, - g_param_spec_string( - "note", - "Note", - "Chart notes", - NULL, - G_PARAM_READWRITE - ) + properties[PROP_NOTE] ); } @@ -388,6 +398,8 @@ ag_chart_set_name(AgChart *chart, const gchar *name) } priv->name = g_strdup(name); + + g_object_notify_by_pspec(G_OBJECT(chart), properties[PROP_NAME]); } gchar * @@ -408,6 +420,8 @@ ag_chart_set_country(AgChart *chart, const gchar *country) } priv->country = g_strdup(country); + + g_object_notify_by_pspec(G_OBJECT(chart), properties[PROP_COUNTRY]); } gchar * @@ -428,6 +442,8 @@ ag_chart_set_city(AgChart *chart, const gchar *city) } priv->city = g_strdup(city); + + g_object_notify_by_pspec(G_OBJECT(chart), properties[PROP_CITY]); } gchar * @@ -1868,6 +1884,8 @@ ag_chart_set_note(AgChart *chart, const gchar *note) AgChartPrivate *priv = ag_chart_get_instance_private(chart); priv->note = g_strdup(note); + + g_object_notify_by_pspec(G_OBJECT(chart), properties[PROP_NOTE]); } const gchar *ag_chart_get_note(AgChart *chart) From 085f2225ea1237e0b90dc08a2088247fe9d528c8 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Mon, 11 Aug 2014 19:38:56 +0200 Subject: [PATCH 5/6] Add debug messages to ag_db_save_identical() --- src/ag-db.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/ag-db.c b/src/ag-db.c index a9afa1d..2e28d93 100644 --- a/src/ag-db.c +++ b/src/ag-db.c @@ -1063,70 +1063,104 @@ gboolean ag_db_save_identical(const AgDbSave *a, const AgDbSave *b, gboolean chart_only) { if (a == b) { + g_debug("identical: Equal"); + return TRUE; } if ((a == NULL) || (b == NULL)) { + g_debug("identical: One is NULL"); + return FALSE; } if (!chart_only && string_collate(a->name, b->name) != 0) { + g_debug("identical: Names differ"); + return FALSE; } if (!chart_only && string_collate(a->country, b->country) != 0) { + g_debug("identical: Countries differ"); + return FALSE; } if (!chart_only && string_collate(a->city, b->city) != 0) { + g_debug("identical: Cities differ"); + return FALSE; } if (a->longitude != b->longitude) { + g_debug("identical: Longitudes differ"); + return FALSE; } if (a->latitude != b->latitude) { + g_debug("identical: Latitudes differ"); + return FALSE; } if (a->altitude != b->altitude) { + g_debug("identical: Altitudes differ"); + return FALSE; } if (a->year != b->year) { + g_debug("identical: Years differ"); + return FALSE; } if (a->month != b->month) { + g_debug("identical: Months differ"); + return FALSE; } if (a->day != b->day) { + g_debug("identical: Days differ"); + return FALSE; } if (a->hour != b->hour) { + g_debug("identical: Hours differ"); + return FALSE; } if (a->minute != b->minute) { + g_debug("identical: Minutes differ"); + return FALSE; } if (a->second != b->second) { + g_debug("identical: Seconds differ"); + return FALSE; } if (a->timezone != b->timezone) { + g_debug("identical: Timezones differ"); + return FALSE; } if (string_collate(a->house_system, b->house_system) != 0) { + g_debug("identical: House systems differ"); + return FALSE; } if (!chart_only && string_collate(a->note, b->note) != 0) { + g_debug("identical: Notes differ"); + return FALSE; } From bb38df71a71db19a57f6352f07c30a5b18f51e72 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Mon, 11 Aug 2014 23:46:22 +0200 Subject: [PATCH 6/6] Fix #46 --- src/ag-window.c | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/ag-window.c b/src/ag-window.c index 2a3c226..046c277 100644 --- a/src/ag-window.c +++ b/src/ag-window.c @@ -60,7 +60,8 @@ G_DEFINE_QUARK(ag_window_error_quark, ag_window_error); G_DEFINE_TYPE_WITH_PRIVATE(AgWindow, ag_window, GTK_TYPE_APPLICATION_WINDOW); -static void ag_window_recalculate_chart(AgWindow *window); +static void ag_window_recalculate_chart(AgWindow *window, + gboolean set_everything); static void ag_window_gear_menu_action(GSimpleAction *action, @@ -107,6 +108,7 @@ ag_window_can_close(AgWindow *window, gboolean display_dialog) gboolean ret = TRUE; if (priv->chart) { + ag_window_recalculate_chart(window, TRUE); save_data = ag_chart_get_db_save(priv->chart, db_id); if ( @@ -196,7 +198,7 @@ ag_window_export(AgWindow *window, GError **err) gint response; AgWindowPrivate *priv = ag_window_get_instance_private(window); - ag_window_recalculate_chart(window); + ag_window_recalculate_chart(window, FALSE); // We should never enter here, but who knows... if (priv->chart == NULL) { @@ -272,7 +274,7 @@ ag_window_save_action(GSimpleAction *action, gint old_id; AgDbSave *save_data; - ag_window_recalculate_chart(window); + ag_window_recalculate_chart(window, TRUE); if (!ag_window_can_close(window, FALSE)) { old_id = (priv->saved_data) ? priv->saved_data->db_id : -1; @@ -300,7 +302,7 @@ ag_window_export_action(GSimpleAction *action, AgWindow *window = AG_WINDOW(user_data); GError *err = NULL; - ag_window_recalculate_chart(window); + ag_window_recalculate_chart(window, TRUE); ag_window_export(window, &err); if (err) { @@ -321,7 +323,7 @@ ag_window_export_svg(AgWindow *window, GError **err) gint response; AgWindowPrivate *priv = ag_window_get_instance_private(window); - ag_window_recalculate_chart(window); + ag_window_recalculate_chart(window, TRUE); // We should never enter here, but who knows... if (priv->chart == NULL) { @@ -840,7 +842,7 @@ ag_window_chart_changed(AgChart *chart, AgWindow *window) } static void -ag_window_recalculate_chart(AgWindow *window) +ag_window_recalculate_chart(AgWindow *window, gboolean set_everything) { AgDbSave *edit_data, *chart_data; @@ -938,7 +940,7 @@ ag_window_recalculate_chart(AgWindow *window) : NULL ; - if (ag_db_save_identical(edit_data, chart_data, TRUE)) { + if (ag_db_save_identical(edit_data, chart_data, !set_everything)) { g_debug("No redrawing needed"); ag_db_save_data_free(edit_data); @@ -982,6 +984,13 @@ ag_window_recalculate_chart(AgWindow *window) ); } + if (set_everything) { + ag_chart_set_name(priv->chart, edit_data->name); + ag_chart_set_country(priv->chart, edit_data->country); + ag_chart_set_city(priv->chart, edit_data->city); + ag_chart_set_note(priv->chart, edit_data->note); + } + ag_db_save_data_free(edit_data); } @@ -1022,12 +1031,12 @@ ag_window_tab_changed_cb(GtkStack *stack, GParamSpec *pspec, AgWindow *window) GTK_STACK(priv->new_back_stack), "back" ); - } - // Note that priv->current_tab is actually the previously selected tab, not - // the real active one! - if (priv->current_tab == priv->tab_edit) { - ag_window_recalculate_chart(window); + // Note that priv->current_tab is actually the previously selected tab, + // not the real active one! + if (priv->current_tab == priv->tab_edit) { + ag_window_recalculate_chart(window, FALSE); + } } priv->current_tab = active_tab; @@ -1079,6 +1088,8 @@ ag_window_back_action(GSimpleAction *action, AgWindow *window = AG_WINDOW(user_data); AgWindowPrivate *priv = ag_window_get_instance_private(window); + g_debug("Back button pressed"); + if (ag_window_can_close(window, TRUE)) { g_clear_object(&(priv->chart)); ag_db_save_data_free(priv->saved_data); @@ -1292,6 +1303,8 @@ ag_window_list_item_activated_cb(GdMainView *view, return; } + g_debug("Loading chart with ID %d", row_id); + if ((priv->saved_data = ag_db_get_chart_data_by_id( db, row_id, @@ -1306,8 +1319,7 @@ ag_window_list_item_activated_cb(GdMainView *view, } if (priv->chart) { - g_object_unref(priv->chart); - priv->chart = NULL; + g_clear_object(&(priv->chart)); } if ((priv->chart = ag_chart_new_from_db_save(