Merge pull request #49 from gergelypolonkai/bugfix-46-47

Fix issues #46 and #47
This commit is contained in:
Gergely Polonkai 2014-08-11 23:50:52 +02:00
commit 9b1758c1ba
3 changed files with 131 additions and 40 deletions

View File

@ -28,7 +28,9 @@ enum {
PROP_0, PROP_0,
PROP_NAME, PROP_NAME,
PROP_COUNTRY, PROP_COUNTRY,
PROP_CITY PROP_CITY,
PROP_NOTE,
PROP_LAST
}; };
typedef enum { typedef enum {
@ -41,6 +43,8 @@ G_DEFINE_QUARK(ag_chart_error_quark, ag_chart_error);
G_DEFINE_TYPE_WITH_PRIVATE(AgChart, ag_chart, GSWE_TYPE_MOMENT); G_DEFINE_TYPE_WITH_PRIVATE(AgChart, ag_chart, GSWE_TYPE_MOMENT);
static GParamSpec *properties[PROP_LAST];
#define ag_g_variant_unref(v) \ #define ag_g_variant_unref(v) \
if ((v) != NULL) { \ if ((v) != NULL) { \
g_variant_unref((v)); \ g_variant_unref((v)); \
@ -65,38 +69,56 @@ ag_chart_class_init(AgChartClass *klass)
gobject_class->get_property = ag_chart_get_property; gobject_class->get_property = ag_chart_get_property;
gobject_class->finalize = ag_chart_finalize; gobject_class->finalize = ag_chart_finalize;
g_object_class_install_property( properties[PROP_NAME] = g_param_spec_string(
gobject_class,
PROP_NAME,
g_param_spec_string(
"name", "name",
"Chart name", "Chart name",
"Name of the person on this chart", "Name of the person on this chart",
NULL, NULL,
G_PARAM_READWRITE G_PARAM_READWRITE
) );
g_object_class_install_property(
gobject_class,
PROP_NAME,
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( g_object_class_install_property(
gobject_class, gobject_class,
PROP_COUNTRY, PROP_COUNTRY,
g_param_spec_string( properties[PROP_COUNTRY]
"country",
"Country name",
"Name of the country of birth",
NULL,
G_PARAM_READWRITE
)
); );
g_object_class_install_property(
gobject_class, properties[PROP_CITY] = g_param_spec_string(
PROP_CITY,
g_param_spec_string(
"city", "city",
"City name", "City name",
"Name of the city of birth", "Name of the city of birth",
NULL, NULL,
G_PARAM_READWRITE G_PARAM_READWRITE
) );
g_object_class_install_property(
gobject_class,
PROP_CITY,
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,
properties[PROP_NOTE]
); );
} }
@ -132,6 +154,11 @@ ag_chart_set_property(GObject *gobject,
case PROP_CITY: case PROP_CITY:
ag_chart_set_city(AG_CHART(gobject), g_value_get_string(value)); 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; break;
} }
} }
@ -160,6 +187,10 @@ ag_chart_get_property(GObject *gobject,
break; break;
case PROP_NOTE:
g_value_set_string(value, priv->note);
break;
} }
} }
@ -367,6 +398,8 @@ ag_chart_set_name(AgChart *chart, const gchar *name)
} }
priv->name = g_strdup(name); priv->name = g_strdup(name);
g_object_notify_by_pspec(G_OBJECT(chart), properties[PROP_NAME]);
} }
gchar * gchar *
@ -387,6 +420,8 @@ ag_chart_set_country(AgChart *chart, const gchar *country)
} }
priv->country = g_strdup(country); priv->country = g_strdup(country);
g_object_notify_by_pspec(G_OBJECT(chart), properties[PROP_COUNTRY]);
} }
gchar * gchar *
@ -407,6 +442,8 @@ ag_chart_set_city(AgChart *chart, const gchar *city)
} }
priv->city = g_strdup(city); priv->city = g_strdup(city);
g_object_notify_by_pspec(G_OBJECT(chart), properties[PROP_CITY]);
} }
gchar * gchar *
@ -1847,6 +1884,8 @@ ag_chart_set_note(AgChart *chart, const gchar *note)
AgChartPrivate *priv = ag_chart_get_instance_private(chart); AgChartPrivate *priv = ag_chart_get_instance_private(chart);
priv->note = g_strdup(note); priv->note = g_strdup(note);
g_object_notify_by_pspec(G_OBJECT(chart), properties[PROP_NOTE]);
} }
const gchar *ag_chart_get_note(AgChart *chart) const gchar *ag_chart_get_note(AgChart *chart)

View File

@ -1063,70 +1063,104 @@ gboolean
ag_db_save_identical(const AgDbSave *a, const AgDbSave *b, gboolean chart_only) ag_db_save_identical(const AgDbSave *a, const AgDbSave *b, gboolean chart_only)
{ {
if (a == b) { if (a == b) {
g_debug("identical: Equal");
return TRUE; return TRUE;
} }
if ((a == NULL) || (b == NULL)) { if ((a == NULL) || (b == NULL)) {
g_debug("identical: One is NULL");
return FALSE; return FALSE;
} }
if (!chart_only && string_collate(a->name, b->name) != 0) { if (!chart_only && string_collate(a->name, b->name) != 0) {
g_debug("identical: Names differ");
return FALSE; return FALSE;
} }
if (!chart_only && string_collate(a->country, b->country) != 0) { if (!chart_only && string_collate(a->country, b->country) != 0) {
g_debug("identical: Countries differ");
return FALSE; return FALSE;
} }
if (!chart_only && string_collate(a->city, b->city) != 0) { if (!chart_only && string_collate(a->city, b->city) != 0) {
g_debug("identical: Cities differ");
return FALSE; return FALSE;
} }
if (a->longitude != b->longitude) { if (a->longitude != b->longitude) {
g_debug("identical: Longitudes differ");
return FALSE; return FALSE;
} }
if (a->latitude != b->latitude) { if (a->latitude != b->latitude) {
g_debug("identical: Latitudes differ");
return FALSE; return FALSE;
} }
if (a->altitude != b->altitude) { if (a->altitude != b->altitude) {
g_debug("identical: Altitudes differ");
return FALSE; return FALSE;
} }
if (a->year != b->year) { if (a->year != b->year) {
g_debug("identical: Years differ");
return FALSE; return FALSE;
} }
if (a->month != b->month) { if (a->month != b->month) {
g_debug("identical: Months differ");
return FALSE; return FALSE;
} }
if (a->day != b->day) { if (a->day != b->day) {
g_debug("identical: Days differ");
return FALSE; return FALSE;
} }
if (a->hour != b->hour) { if (a->hour != b->hour) {
g_debug("identical: Hours differ");
return FALSE; return FALSE;
} }
if (a->minute != b->minute) { if (a->minute != b->minute) {
g_debug("identical: Minutes differ");
return FALSE; return FALSE;
} }
if (a->second != b->second) { if (a->second != b->second) {
g_debug("identical: Seconds differ");
return FALSE; return FALSE;
} }
if (a->timezone != b->timezone) { if (a->timezone != b->timezone) {
g_debug("identical: Timezones differ");
return FALSE; return FALSE;
} }
if (string_collate(a->house_system, b->house_system) != 0) { if (string_collate(a->house_system, b->house_system) != 0) {
g_debug("identical: House systems differ");
return FALSE; return FALSE;
} }
if (!chart_only && string_collate(a->note, b->note) != 0) { if (!chart_only && string_collate(a->note, b->note) != 0) {
g_debug("identical: Notes differ");
return FALSE; return FALSE;
} }

View File

@ -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); 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 static void
ag_window_gear_menu_action(GSimpleAction *action, ag_window_gear_menu_action(GSimpleAction *action,
@ -107,6 +108,7 @@ ag_window_can_close(AgWindow *window, gboolean display_dialog)
gboolean ret = TRUE; gboolean ret = TRUE;
if (priv->chart) { 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, db_id);
if ( if (
@ -196,7 +198,7 @@ ag_window_export(AgWindow *window, GError **err)
gint response; gint response;
AgWindowPrivate *priv = ag_window_get_instance_private(window); 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... // We should never enter here, but who knows...
if (priv->chart == NULL) { if (priv->chart == NULL) {
@ -272,7 +274,7 @@ ag_window_save_action(GSimpleAction *action,
gint old_id; gint old_id;
AgDbSave *save_data; AgDbSave *save_data;
ag_window_recalculate_chart(window); 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; 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); AgWindow *window = AG_WINDOW(user_data);
GError *err = NULL; GError *err = NULL;
ag_window_recalculate_chart(window); ag_window_recalculate_chart(window, TRUE);
ag_window_export(window, &err); ag_window_export(window, &err);
if (err) { if (err) {
@ -321,7 +323,7 @@ ag_window_export_svg(AgWindow *window, GError **err)
gint response; gint response;
AgWindowPrivate *priv = ag_window_get_instance_private(window); 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... // We should never enter here, but who knows...
if (priv->chart == NULL) { if (priv->chart == NULL) {
@ -834,13 +836,13 @@ ag_window_update_from_chart(AgWindow *window)
} }
static void static void
chart_changed(AgChart *chart, AgWindow *window) ag_window_chart_changed(AgChart *chart, AgWindow *window)
{ {
ag_window_redraw_chart(window); ag_window_redraw_chart(window);
} }
static void static void
ag_window_recalculate_chart(AgWindow *window) ag_window_recalculate_chart(AgWindow *window, gboolean set_everything)
{ {
AgDbSave *edit_data, AgDbSave *edit_data,
*chart_data; *chart_data;
@ -938,7 +940,7 @@ ag_window_recalculate_chart(AgWindow *window)
: NULL : 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"); g_debug("No redrawing needed");
ag_db_save_data_free(edit_data); ag_db_save_data_free(edit_data);
@ -966,7 +968,7 @@ ag_window_recalculate_chart(AgWindow *window)
g_signal_connect( g_signal_connect(
priv->chart, priv->chart,
"changed", "changed",
G_CALLBACK(chart_changed), G_CALLBACK(ag_window_chart_changed),
window window
); );
ag_window_redraw_chart(window); ag_window_redraw_chart(window);
@ -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); 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), GTK_STACK(priv->new_back_stack),
"back" "back"
); );
}
// Note that priv->current_tab is actually the previously selected tab, not // Note that priv->current_tab is actually the previously selected tab,
// the real active one! // not the real active one!
if (priv->current_tab == priv->tab_edit) { if (priv->current_tab == priv->tab_edit) {
ag_window_recalculate_chart(window); ag_window_recalculate_chart(window, FALSE);
}
} }
priv->current_tab = active_tab; priv->current_tab = active_tab;
@ -1079,6 +1088,8 @@ ag_window_back_action(GSimpleAction *action,
AgWindow *window = AG_WINDOW(user_data); AgWindow *window = AG_WINDOW(user_data);
AgWindowPrivate *priv = ag_window_get_instance_private(window); AgWindowPrivate *priv = ag_window_get_instance_private(window);
g_debug("Back button pressed");
if (ag_window_can_close(window, TRUE)) { if (ag_window_can_close(window, TRUE)) {
g_clear_object(&(priv->chart)); g_clear_object(&(priv->chart));
ag_db_save_data_free(priv->saved_data); ag_db_save_data_free(priv->saved_data);
@ -1086,6 +1097,7 @@ ag_window_back_action(GSimpleAction *action,
ag_window_load_chart_list(window); ag_window_load_chart_list(window);
gtk_stack_set_visible_child_name(GTK_STACK(priv->stack), "list"); gtk_stack_set_visible_child_name(GTK_STACK(priv->stack), "list");
gtk_header_bar_set_subtitle(GTK_HEADER_BAR(priv->header_bar), NULL);
} }
} }
@ -1291,6 +1303,8 @@ ag_window_list_item_activated_cb(GdMainView *view,
return; return;
} }
g_debug("Loading chart with ID %d", row_id);
if ((priv->saved_data = ag_db_get_chart_data_by_id( if ((priv->saved_data = ag_db_get_chart_data_by_id(
db, db,
row_id, row_id,
@ -1305,8 +1319,7 @@ ag_window_list_item_activated_cb(GdMainView *view,
} }
if (priv->chart) { if (priv->chart) {
g_object_unref(priv->chart); g_clear_object(&(priv->chart));
priv->chart = NULL;
} }
if ((priv->chart = ag_chart_new_from_db_save( if ((priv->chart = ag_chart_new_from_db_save(
@ -1663,7 +1676,7 @@ ag_window_set_chart(AgWindow *window, AgChart *chart)
if (priv->chart != NULL) { if (priv->chart != NULL) {
g_signal_handlers_disconnect_by_func( g_signal_handlers_disconnect_by_func(
priv->chart, priv->chart,
chart_changed, ag_window_chart_changed,
window window
); );
g_clear_object(&(priv->chart)); g_clear_object(&(priv->chart));
@ -1672,7 +1685,12 @@ ag_window_set_chart(AgWindow *window, AgChart *chart)
ag_db_save_data_free(priv->saved_data); ag_db_save_data_free(priv->saved_data);
priv->chart = chart; 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); g_object_ref(chart);
priv->saved_data = ag_chart_get_db_save(chart, -1); priv->saved_data = ag_chart_get_db_save(chart, -1);
} }