[gnc-budget] gnc_budget_get_account_period_note returns a const

to harmonize with all other char getters
This commit is contained in:
Christopher Lam
2022-11-18 17:57:21 +08:00
parent 2ee0c98200
commit 3d8a28898d
6 changed files with 9 additions and 16 deletions

View File

@@ -131,8 +131,6 @@ functions. */
%newobject gnc_localtime;
%newobject gnc_gmtime;
%newobject gnc_budget_get_account_period_note;
/* Parse the header file to generate wrappers */
%inline {
static QofIdType QOF_ID_BOOK_SCM (void) { return QOF_ID_BOOK; }

View File

@@ -927,7 +927,7 @@ query_tooltip_tree_view_cb (GtkWidget *widget, gint x, gint y,
GncBudgetViewPrivate *priv = GNC_BUDGET_VIEW_GET_PRIVATE(view);
GtkTreePath *path = NULL;
GtkTreeViewColumn *column = NULL;
gchar *note;
const gchar *note;
guint period_num;
Account *account;
@@ -964,7 +964,6 @@ query_tooltip_tree_view_cb (GtkWidget *widget, gint x, gint y,
gtk_tooltip_set_text (tooltip, note);
gtk_tree_view_set_tooltip_cell (tree_view, tooltip, path, column, NULL);
gtk_tree_path_free (path);
g_free (note);
return TRUE;
}
@@ -1093,7 +1092,7 @@ budget_col_source (Account *account, GtkTreeViewColumn *col,
guint period_num;
gnc_numeric numeric;
gchar amtbuff[100]; //FIXME: overkill, where's the #define?
gchar *note;
const gchar *note;
budget_view = GNC_BUDGET_VIEW(g_object_get_data (G_OBJECT(col), "budget_view"));
period_num = GPOINTER_TO_UINT(g_object_get_data (G_OBJECT(col), "period_num"));
@@ -1153,7 +1152,6 @@ budget_col_source (Account *account, GtkTreeViewColumn *col,
note = gnc_budget_get_account_period_note (priv->budget, account, period_num);
g_object_set (cell, "flagged", note != NULL, NULL);
g_free (note);
return g_strdup (amtbuff);
}

View File

@@ -1287,9 +1287,8 @@ gnc_plugin_page_budget_cmd_budget_note(GtkAction *action,
GTK_WINDOW(gnc_plugin_page_get_window(GNC_PLUGIN_PAGE(page))));
note = GTK_WIDGET(gtk_builder_get_object(builder, "BudgetNote"));
txt = gnc_budget_get_account_period_note(priv->budget, acc, period_num);
xxxgtk_textview_set_text(GTK_TEXT_VIEW(note), txt);
g_free (txt);
xxxgtk_textview_set_text(GTK_TEXT_VIEW(note),
gnc_budget_get_account_period_note(priv->budget, acc, period_num));
gtk_widget_show_all(dialog);
result = gtk_dialog_run(GTK_DIALOG(dialog));

View File

@@ -644,13 +644,13 @@ gnc_budget_set_account_period_note(GncBudget *budget, const Account *account,
}
gchar *
const gchar *
gnc_budget_get_account_period_note (const GncBudget *budget,
const Account *account, guint period_num)
{
g_return_val_if_fail (period_num < GET_PRIVATE(budget)->num_periods, nullptr);
auto& data = get_perioddata (budget, account, period_num);
return data.note.empty () ? nullptr : g_strdup (data.note.c_str());
return data.note.empty () ? nullptr : data.note.c_str();
}
time64

View File

@@ -161,11 +161,10 @@ gnc_numeric gnc_budget_get_account_period_value(
gnc_numeric gnc_budget_get_account_period_actual_value(
const GncBudget *budget, Account *account, guint period_num);
/* get/set the budget account period's note, beware when retrieving
the period note, the latter must be g_freed by the caller */
/* get/set the budget account period's note */
void gnc_budget_set_account_period_note(GncBudget *budget,
const Account *account, guint period_num, const gchar *note);
gchar *gnc_budget_get_account_period_note (const GncBudget *budget,
const gchar *gnc_budget_get_account_period_note (const GncBudget *budget,
const Account *account, guint period_num);
/* Returns some budget in the book, or NULL. */

View File

@@ -78,7 +78,7 @@ test_gnc_set_budget_num_periods_data_retention ()
QofBook *book = qof_book_new();
GncBudget* budget = gnc_budget_new(book);
Account *acc = gnc_account_create_root(book);
gchar *note;
const gchar *note;
/* initially has 20 periods */
gnc_budget_set_num_periods(budget, 20);
@@ -100,7 +100,6 @@ test_gnc_set_budget_num_periods_data_retention ()
g_assert (!gnc_budget_is_account_period_value_set(budget, acc, 15));
note = gnc_budget_get_account_period_note (budget, acc, 11);
g_assert_cmpstr (note, ==, NULL);
g_free (note);
gnc_budget_destroy(budget);
qof_book_destroy(book);