Merge pull request #98 from gergelypolonkai/bug-97

Remove unneeded chart save notification popups
This commit is contained in:
Gergely Polonkai 2014-10-02 00:17:21 +02:00
commit 96221abec6
3 changed files with 70 additions and 12 deletions

View File

@ -46,6 +46,7 @@ typedef struct _AgChartPrivate {
gchar *save_buffer; gchar *save_buffer;
GList *planet_list; GList *planet_list;
gchar *note; gchar *note;
gint db_id;
} AgChartPrivate; } AgChartPrivate;
enum { enum {
@ -54,6 +55,7 @@ enum {
PROP_COUNTRY, PROP_COUNTRY,
PROP_CITY, PROP_CITY,
PROP_NOTE, PROP_NOTE,
PROP_DBID,
PROP_LAST PROP_LAST
}; };
@ -148,6 +150,24 @@ ag_chart_class_init(AgChartClass *klass)
PROP_NOTE, PROP_NOTE,
properties[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 static void
@ -187,6 +207,16 @@ ag_chart_set_property(GObject *gobject,
case PROP_NOTE: case PROP_NOTE:
ag_chart_set_note(AG_CHART(gobject), g_value_get_string(value)); 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; break;
} }
} }
@ -218,6 +248,16 @@ ag_chart_get_property(GObject *gobject,
case PROP_NOTE: case PROP_NOTE:
g_value_set_string(value, priv->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; 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_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;
} }
@ -2007,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);
@ -2050,3 +2091,21 @@ ag_chart_get_db_save(AgChart *chart, gint db_id)
return save_data; 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;
}

View File

@ -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,
@ -147,6 +147,10 @@ GdkPixbuf *ag_chart_get_pixbuf(AgChart *chart,
AgDisplayTheme *theme, AgDisplayTheme *theme,
GError **err); 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()) #define AG_CHART_ERROR (ag_chart_error_quark())
GQuark ag_chart_error_quark(void); GQuark ag_chart_error_quark(void);

View File

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