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_NAME,
PROP_COUNTRY,
PROP_CITY
PROP_CITY,
PROP_NOTE,
PROP_LAST
};
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);
static GParamSpec *properties[PROP_LAST];
#define ag_g_variant_unref(v) \
if ((v) != NULL) { \
g_variant_unref((v)); \
@ -65,38 +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,
properties[PROP_NOTE]
);
}
@ -132,6 +154,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 +187,10 @@ ag_chart_get_property(GObject *gobject,
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);
g_object_notify_by_pspec(G_OBJECT(chart), properties[PROP_NAME]);
}
gchar *
@ -387,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 *
@ -407,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 *
@ -1847,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)

View File

@ -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;
}

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);
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) {
@ -834,13 +836,13 @@ 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);
}
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);
@ -966,7 +968,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);
@ -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);
@ -1086,6 +1097,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);
}
}
@ -1291,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,
@ -1305,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(
@ -1663,7 +1676,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));
@ -1672,7 +1685,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);
}