Convert AgDbChartSave a boxed type
This commit is contained in:
parent
41f054bf6f
commit
7fe82cdc68
@ -1926,7 +1926,7 @@ ag_chart_get_db_save(AgChart *chart, gint db_id)
|
||||
{
|
||||
GsweCoordinates *coords;
|
||||
AgChartPrivate *priv = ag_chart_get_instance_private(chart);
|
||||
AgDbChartSave *save_data = g_new0(AgDbChartSave, 1);
|
||||
AgDbChartSave *save_data = ag_db_chart_save_new();
|
||||
GsweTimestamp *timestamp = gswe_moment_get_timestamp(GSWE_MOMENT(chart));
|
||||
GEnumClass *house_system_class;
|
||||
GEnumValue *house_system_enum;
|
||||
|
51
src/ag-db.c
51
src/ag-db.c
@ -39,6 +39,12 @@ typedef struct _AgDbPrivate {
|
||||
G_DEFINE_QUARK(ag_db_error_quark, ag_db_error);
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(AgDb, ag_db, G_TYPE_OBJECT);
|
||||
G_DEFINE_BOXED_TYPE(
|
||||
AgDbChartSave,
|
||||
ag_db_chart_save,
|
||||
(GBoxedCopyFunc)ag_db_chart_save_ref,
|
||||
(GBoxedFreeFunc)ag_db_chart_save_unref
|
||||
);
|
||||
|
||||
enum {
|
||||
COLUMN_CHART_ID,
|
||||
@ -564,7 +570,7 @@ ag_db_get(void)
|
||||
*
|
||||
* Frees @save_data and all its fields
|
||||
*/
|
||||
void
|
||||
static void
|
||||
ag_db_chart_save_free(AgDbChartSave *save_data)
|
||||
{
|
||||
if (!save_data) {
|
||||
@ -594,6 +600,30 @@ ag_db_chart_save_free(AgDbChartSave *save_data)
|
||||
g_free(save_data);
|
||||
}
|
||||
|
||||
AgDbChartSave *
|
||||
ag_db_chart_save_ref(AgDbChartSave *save_data)
|
||||
{
|
||||
if (save_data == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
save_data->refcount++;
|
||||
|
||||
return save_data;
|
||||
}
|
||||
|
||||
void
|
||||
ag_db_chart_save_unref(AgDbChartSave *save_data)
|
||||
{
|
||||
if (save_data == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (--save_data->refcount == 0) {
|
||||
ag_db_chart_save_free(save_data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ag_db_chart_save:
|
||||
* @db: the #AgDb object to operate on
|
||||
@ -797,6 +827,17 @@ ag_db_chart_save(AgDb *db, AgDbChartSave *save_data, GError **err)
|
||||
return save_success;
|
||||
}
|
||||
|
||||
AgDbChartSave *
|
||||
ag_db_chart_save_new(void)
|
||||
{
|
||||
AgDbChartSave *save_data;
|
||||
|
||||
save_data = g_new0(AgDbChartSave, 1);
|
||||
save_data->refcount = 1;
|
||||
|
||||
return save_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* ag_db_chart_get_list:
|
||||
* @db: the #AgDb object to operate on
|
||||
@ -833,7 +874,7 @@ ag_db_chart_get_list(AgDb *db, GError **err)
|
||||
|
||||
while (gda_data_model_iter_move_next(iter)) {
|
||||
const GValue *value;
|
||||
AgDbChartSave *save_data = g_new0(AgDbChartSave, 1);
|
||||
AgDbChartSave *save_data = ag_db_chart_save_new();
|
||||
|
||||
value = gda_data_model_iter_get_value_at(iter, 0);
|
||||
save_data->db_id = g_value_get_int(value);
|
||||
@ -910,7 +951,7 @@ ag_db_chart_get_data_by_id(AgDb *db, guint row_id, GError **err)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
save_data = g_new0(AgDbChartSave, 1);
|
||||
save_data = ag_db_chart_save_new();
|
||||
|
||||
/* id */
|
||||
value = gda_data_model_get_value_at(
|
||||
@ -1082,8 +1123,8 @@ string_collate(const gchar *str1, const gchar *str2)
|
||||
*/
|
||||
gboolean
|
||||
ag_db_chart_save_identical(const AgDbChartSave *a,
|
||||
const AgDbChartSave *b,
|
||||
gboolean chart_only)
|
||||
const AgDbChartSave *b,
|
||||
gboolean chart_only)
|
||||
{
|
||||
if (a == b) {
|
||||
g_debug("identical: Equal");
|
||||
|
12
src/ag-db.h
12
src/ag-db.h
@ -65,8 +65,12 @@ typedef struct _AgDbChartSave {
|
||||
gdouble timezone;
|
||||
gchar *house_system;
|
||||
gchar *note;
|
||||
gint refcount;
|
||||
} AgDbChartSave;
|
||||
|
||||
GType ag_db_chart_save_get_type(void);
|
||||
#define AG_TYPE_DB_CHART_SAVE (ag_db_chart_save_get_type())
|
||||
|
||||
typedef enum {
|
||||
AG_DB_ERROR_NO_CHART,
|
||||
AG_DB_ERROR_DATABASE_ERROR,
|
||||
@ -76,12 +80,16 @@ GType ag_db_get_type(void) G_GNUC_CONST;
|
||||
|
||||
AgDb *ag_db_get(void);
|
||||
|
||||
void ag_db_chart_save_free(AgDbChartSave *save_data);
|
||||
|
||||
gboolean ag_db_chart_save(AgDb *db,
|
||||
AgDbChartSave *save_data,
|
||||
GError **err);
|
||||
|
||||
AgDbChartSave *ag_db_chart_save_new(void);
|
||||
|
||||
AgDbChartSave *ag_db_chart_save_ref(AgDbChartSave *save_data);
|
||||
|
||||
void ag_db_chart_save_unref(AgDbChartSave *save_data);
|
||||
|
||||
GList *ag_db_chart_get_list(AgDb *db, GError **err);
|
||||
|
||||
AgDbChartSave *ag_db_chart_get_data_by_id(AgDb *db, guint row_id, GError **err);
|
||||
|
@ -720,7 +720,7 @@ ag_window_recalculate_chart(AgWindow *window, gboolean set_everything)
|
||||
gtk_spin_button_update(GTK_SPIN_BUTTON(current));
|
||||
}
|
||||
|
||||
edit_data = g_new0(AgDbChartSave, 1);
|
||||
edit_data = ag_db_chart_save_new();
|
||||
|
||||
edit_data->db_id = db_id;
|
||||
|
||||
@ -798,13 +798,13 @@ ag_window_recalculate_chart(AgWindow *window, gboolean set_everything)
|
||||
if (ag_db_chart_save_identical(edit_data, chart_data, !set_everything)) {
|
||||
g_debug("No redrawing needed");
|
||||
|
||||
ag_db_chart_save_free(edit_data);
|
||||
ag_db_chart_save_free(chart_data);
|
||||
ag_db_chart_save_unref(edit_data);
|
||||
ag_db_chart_save_unref(chart_data);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
ag_db_chart_save_free(chart_data);
|
||||
ag_db_chart_save_unref(chart_data);
|
||||
|
||||
g_debug("Recalculating chart data");
|
||||
|
||||
@ -846,7 +846,7 @@ ag_window_recalculate_chart(AgWindow *window, gboolean set_everything)
|
||||
ag_chart_set_note(priv->chart, edit_data->note);
|
||||
}
|
||||
|
||||
ag_db_chart_save_free(edit_data);
|
||||
ag_db_chart_save_unref(edit_data);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1257,7 +1257,7 @@ ag_window_can_close(AgWindow *window, gboolean display_dialog)
|
||||
}
|
||||
}
|
||||
|
||||
ag_db_chart_save_free(save_data);
|
||||
ag_db_chart_save_unref(save_data);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -1289,7 +1289,7 @@ ag_window_save_action(GSimpleAction *action,
|
||||
);
|
||||
}
|
||||
|
||||
ag_db_chart_save_free(priv->saved_data);
|
||||
ag_db_chart_save_unref(priv->saved_data);
|
||||
priv->saved_data = save_data;
|
||||
}
|
||||
}
|
||||
@ -1644,7 +1644,7 @@ ag_window_back_action(GSimpleAction *action,
|
||||
if (ag_window_can_close(window, TRUE)) {
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->toolbar_aspect), TRUE);
|
||||
g_clear_object(&(priv->chart));
|
||||
ag_db_chart_save_free(priv->saved_data);
|
||||
ag_db_chart_save_unref(priv->saved_data);
|
||||
priv->saved_data = NULL;
|
||||
|
||||
ag_window_load_chart_list(window);
|
||||
@ -1931,7 +1931,7 @@ ag_window_list_item_activated_cb(GdMainView *view,
|
||||
"Error: %s",
|
||||
err->message
|
||||
);
|
||||
ag_db_chart_save_free(priv->saved_data);
|
||||
ag_db_chart_save_unref(priv->saved_data);
|
||||
priv->saved_data = NULL;
|
||||
|
||||
return;
|
||||
@ -2657,7 +2657,7 @@ ag_window_set_chart(AgWindow *window, AgChart *chart)
|
||||
g_clear_object(&(priv->chart));
|
||||
}
|
||||
|
||||
ag_db_chart_save_free(priv->saved_data);
|
||||
ag_db_chart_save_unref(priv->saved_data);
|
||||
|
||||
priv->chart = chart;
|
||||
g_signal_connect(
|
||||
|
Loading…
Reference in New Issue
Block a user