[zenity/gtk4-port] Use g_auto* where possible.
- From: Logan Rathbone <larathbone src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [zenity/gtk4-port] Use g_auto* where possible.
- Date: Thu, 30 Dec 2021 04:50:48 +0000 (UTC)
commit 6da301644c82049dc7d0b4a701a481000379893f
Author: Logan Rathbone <poprocks gmail com>
Date: Wed Dec 29 23:49:48 2021 -0500
Use g_auto* where possible.
src/calendar.c | 11 +++-------
src/entry.c | 4 +---
src/fileselection.c | 33 ++++++++--------------------
src/forms.c | 23 ++++++--------------
src/main.c | 14 ++++--------
src/msg.c | 4 +---
src/notification.c | 43 +++++++++++--------------------------
src/option.c | 62 -----------------------------------------------------
src/option.h | 2 --
src/progress.c | 15 +++++--------
src/scale.c | 4 +---
src/text.c | 30 +++++++++-----------------
src/tree.c | 23 ++++++--------------
src/util.c | 12 +++++------
src/zenity.ui | 5 -----
15 files changed, 65 insertions(+), 220 deletions(-)
---
diff --git a/src/calendar.c b/src/calendar.c
index 07696ab4..be8c8af1 100644
--- a/src/calendar.c
+++ b/src/calendar.c
@@ -41,7 +41,7 @@ static void zenity_calendar_dialog_response (GtkWidget *widget,
void
zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data)
{
- GtkBuilder *builder;
+ g_autoptr(GtkBuilder) builder = NULL;
GtkWidget *dialog;
GtkWidget *button;
GObject *text;
@@ -126,8 +126,6 @@ zenity_calendar (ZenityData *data, ZenityCalendarData *cal_data)
gtk_button_set_label (GTK_BUTTON (button), data->cancel_label);
}
- g_object_unref (builder);
-
zenity_util_gapp_main (GTK_WINDOW(dialog));
}
@@ -135,8 +133,8 @@ static void
zenity_calendar_dialog_output (void)
{
int day, month, year;
- char *time_string;
- GDateTime *date;
+ g_autofree char *time_string = NULL;
+ g_autoptr(GDateTime) date = NULL;
g_object_get (calendar,
"day", &day,
@@ -149,9 +147,6 @@ zenity_calendar_dialog_output (void)
time_string = g_date_time_format (date, zen_cal_data->date_format);
g_print ("%s\n", time_string);
-
- g_date_time_unref (date);
- g_free (time_string);
}
static void
diff --git a/src/entry.c b/src/entry.c
index f1160698..a6d67a4c 100644
--- a/src/entry.c
+++ b/src/entry.c
@@ -53,7 +53,7 @@ zenity_entry_combo_activate_default (GtkEntry *entry, gpointer window)
void
zenity_entry (ZenityData *data, ZenityEntryData *entry_data)
{
- GtkBuilder *builder = NULL;
+ g_autoptr(GtkBuilder) builder = NULL;
GtkWidget *dialog;
GtkWidget *button;
GObject *text;
@@ -170,8 +170,6 @@ zenity_entry (ZenityData *data, ZenityEntryData *entry_data)
gtk_label_set_mnemonic_widget (GTK_LABEL (text), entry);
- g_object_unref (builder);
-
zenity_util_show_dialog (dialog);
if (data->timeout_delay > 0) {
diff --git a/src/fileselection.c b/src/fileselection.c
index 0020b237..e495f761 100644
--- a/src/fileselection.c
+++ b/src/fileselection.c
@@ -70,37 +70,30 @@ zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
{
if (g_path_is_absolute (file_data->uri) == TRUE)
{
- char *dir = g_path_get_dirname (file_data->uri);
- GFile *dir_gfile = g_file_new_for_path (dir);
+ g_autofree char *dir = g_path_get_dirname (file_data->uri);
+ g_autoptr(GFile) dir_gfile = g_file_new_for_path (dir);
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(dialog),
dir_gfile,
NULL); /* GError */
-
- g_free (dir);
- g_object_unref (dir_gfile);
}
if (file_data->uri[strlen (file_data->uri) - 1] != '/')
{
if (file_data->save)
{
- char *basename = g_path_get_basename (file_data->uri);
+ g_autofree char *basename = g_path_get_basename (file_data->uri);
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog),
basename);
-
- g_free (basename);
}
else
{
- GFile *file = g_file_new_for_uri (file_data->uri);
+ g_autoptr(GFile) file = g_file_new_for_uri (file_data->uri);
gtk_file_chooser_set_file (GTK_FILE_CHOOSER(dialog),
file,
NULL); /* GError */
-
- g_object_unref (file);
}
}
}
@@ -115,8 +108,9 @@ zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
{
GtkFileFilter *filter = gtk_file_filter_new ();
char *filter_str = file_data->filter[filter_i];
- char **pattern, **patterns;
- char *name = NULL;
+ GStrv pattern;
+ g_auto(GStrv) patterns = NULL;
+ g_autofree char *name = NULL;
int i;
/* Set name */
@@ -146,11 +140,6 @@ zenity_fileselection (ZenityData *data, ZenityFileData *file_data)
for (pattern = patterns; *pattern; pattern++)
gtk_file_filter_add_pattern (filter, *pattern);
- if (name)
- g_free (name);
-
- g_strfreev (patterns);
-
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(dialog), filter);
}
}
@@ -174,23 +163,19 @@ static void
zenity_fileselection_dialog_output (GtkFileChooser *chooser,
ZenityFileData *file_data)
{
- GListModel *model = gtk_file_chooser_get_files (chooser);
+ g_autoptr(GListModel) model = gtk_file_chooser_get_files (chooser);
guint items = g_list_model_get_n_items (model);
for (guint i = 0; i < items; ++i)
{
- GFile *file = g_list_model_get_item (model, i);
+ g_autoptr(GFile) file = g_list_model_get_item (model, i);
g_print ("%s", g_file_get_path (file));
if (i != items - 1)
g_print ("%s", file_data->separator);
-
- g_object_unref (file);
}
g_print ("\n");
-
- g_object_unref (model);
}
static void
diff --git a/src/forms.c b/src/forms.c
index 86b8499b..ea503491 100644
--- a/src/forms.c
+++ b/src/forms.c
@@ -60,7 +60,7 @@ static GtkWidget *
zenity_forms_create_and_fill_combo (ZenityFormsData *forms_data,
int combo_number)
{
- GtkListStore *list_store;
+ g_autoptr(GtkListStore) list_store = NULL;
GtkWidget *combo_box;
GtkCellRenderer *renderer;
@@ -68,7 +68,7 @@ zenity_forms_create_and_fill_combo (ZenityFormsData *forms_data,
if (forms_data->combo_values)
{
- char *combo_values =
+ g_autofree char *combo_values =
g_slist_nth_data (forms_data->combo_values, combo_number);
if (combo_values)
@@ -89,12 +89,10 @@ zenity_forms_create_and_fill_combo (ZenityFormsData *forms_data,
}
g_strfreev (row_values);
}
- g_free (combo_values);
}
}
combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL(list_store));
- g_object_unref (list_store);
renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT(combo_box),
@@ -111,7 +109,7 @@ static GtkWidget *
zenity_forms_create_and_fill_list (ZenityFormsData *forms_data,
int list_number, char *header)
{
- GtkListStore *list_store;
+ g_autoptr(GtkListStore) list_store = NULL;
GtkWidget *tree_view;
GtkWidget *scrolled_window;
GType *column_types = NULL;
@@ -180,7 +178,7 @@ zenity_forms_create_and_fill_list (ZenityFormsData *forms_data,
if (forms_data->list_values)
{
- char *list_values =
+ g_autofree char *list_values =
g_slist_nth_data (forms_data->list_values, list_number);
if (list_values)
@@ -207,7 +205,6 @@ zenity_forms_create_and_fill_list (ZenityFormsData *forms_data,
}
g_strfreev (row_values);
}
- g_free (list_values);
}
}
@@ -215,7 +212,6 @@ zenity_forms_create_and_fill_list (ZenityFormsData *forms_data,
GTK_TREE_MODEL (list_store));
gtk_tree_view_set_headers_visible (
GTK_TREE_VIEW (tree_view), forms_data->show_header);
- g_object_unref (list_store);
scrolled_window = gtk_scrolled_window_new ();
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW(scrolled_window),
@@ -228,7 +224,7 @@ zenity_forms_create_and_fill_list (ZenityFormsData *forms_data,
void
zenity_forms_dialog (ZenityData *data, ZenityFormsData *forms_data)
{
- GtkBuilder *builder = NULL;
+ g_autoptr(GtkBuilder) builder = NULL;
GtkWidget *dialog;
GtkWidget *grid;
GtkWidget *text;
@@ -349,8 +345,6 @@ zenity_forms_dialog (ZenityData *data, ZenityFormsData *forms_data)
zenity_util_show_dialog (dialog);
- g_object_unref (builder);
-
if (data->timeout_delay > 0)
{
g_timeout_add_seconds (data->timeout_delay,
@@ -367,9 +361,9 @@ zenity_forms_dialog_output (ZenityFormsData *forms_data)
guint day, year, month;
GDate *date = NULL;
char time_string[128];
- char *combo_value = NULL;
+ g_autofree char *combo_value = NULL;
GtkTreeSelection *selection;
- GtkListStore *list_store;
+ g_autoptr(GtkListStore) list_store = NULL;
GtkTreeIter iter;
for (tmp = forms_data->list; tmp; tmp = tmp->next)
@@ -433,10 +427,7 @@ zenity_forms_dialog_output (ZenityFormsData *forms_data)
&combo_value,
-1);
- g_object_unref (G_OBJECT (list_store));
-
g_print ("%s", combo_value);
- g_free (combo_value);
}
else
g_print (" ");
diff --git a/src/main.c b/src/main.c
index 01545bec..86a816bc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -43,7 +43,7 @@ command_line_cb (GtkApplication *app,
GApplicationCommandLine *command_line,
gpointer user_data)
{
- ZenityArgs *args = user_data;
+ g_autofree ZenityArgs *args = user_data;
ZenityParsingOptions *results;
results = zenity_option_parse (args->argc, args->argv);
@@ -120,18 +120,13 @@ command_line_cb (GtkApplication *app,
case MODE_LAST:
g_printerr (_ ("You must specify a dialog type. See 'zenity "
"--help' for details\n"));
- zenity_option_free ();
exit (-1);
default:
g_assert_not_reached ();
- zenity_option_free ();
exit (-1);
}
- zenity_option_free ();
- g_free (args);
-
g_application_command_line_set_exit_status (command_line,
results->data->exit_code);
}
@@ -139,11 +134,11 @@ command_line_cb (GtkApplication *app,
int
main (int argc, char *argv[])
{
- ZenityArgs *args;
- GtkApplication *app;
+ g_autofree ZenityArgs *args = NULL;
+ g_autoptr(GtkApplication) app = NULL;
int status;
- /* boilerplate i18n stuff */
+ /* <i18n> */
setlocale (LC_ALL, "");
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
@@ -162,7 +157,6 @@ main (int argc, char *argv[])
G_CALLBACK(command_line_cb), args);
status = g_application_run (G_APPLICATION(app), 0, NULL);
- g_object_unref (app);
return status;
}
diff --git a/src/msg.c b/src/msg.c
index 5b8e7a9c..1fa3645b 100644
--- a/src/msg.c
+++ b/src/msg.c
@@ -84,7 +84,7 @@ zenity_label_widget_clipboard_selection (GtkWidget *widget)
void
zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
{
- GtkBuilder *builder;
+ g_autoptr(GtkBuilder) builder;
GtkWidget *dialog;
GtkWidget *ok_button;
GObject *text;
@@ -248,8 +248,6 @@ zenity_msg (ZenityData *data, ZenityMsgData *msg_data)
NULL);
}
- g_object_unref (builder);
-
zenity_util_gapp_main (GTK_WINDOW(dialog));
}
diff --git a/src/notification.c b/src/notification.c
index a813c1e8..70b65bc5 100644
--- a/src/notification.c
+++ b/src/notification.c
@@ -40,14 +40,11 @@
#define MAX_HINTS 16
-static char *icon_file;
-static GHashTable *notification_hints;
-
static NotifyNotification *
zenity_notification_new (char *message, char *icon_file)
{
NotifyNotification *notif;
- char **text;
+ g_auto(GStrv) text = NULL;
text = g_strsplit (g_strcompress (message), "\n", 2);
if (*text == NULL)
@@ -60,8 +57,6 @@ zenity_notification_new (char *message, char *icon_file)
text[1], /* summary */
icon_file);
- g_strfreev (text);
-
return notif;
}
@@ -81,8 +76,8 @@ on_notification_default_action (NotifyNotification *n,
static GHashTable *
zenity_notification_parse_hints_array (char **hints)
{
- GHashTable *result;
- char **pair;
+ g_autoptr(GHashTable) result = NULL;
+ g_auto(GStrv) pair = NULL;
int i;
result = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
@@ -91,11 +86,9 @@ zenity_notification_parse_hints_array (char **hints)
{
pair = g_strsplit (hints[i], ":", 2);
g_hash_table_replace (result, g_strdup (pair[0]), g_strdup (pair[1]));
- g_strfreev (pair);
}
if (g_hash_table_size (result) == 0) {
- g_hash_table_unref (result);
return NULL;
} else {
return result;
@@ -106,11 +99,10 @@ static GHashTable *
zenity_notification_parse_hints (char *hints)
{
GHashTable *result;
- char **hint_array;
+ g_auto(GStrv) hint_array = NULL;
hint_array = g_strsplit (g_strcompress (hints), "\n", MAX_HINTS);
result = zenity_notification_parse_hints_array (hint_array);
- g_strfreev (hint_array);
return result;
}
@@ -204,10 +196,13 @@ static gboolean
zenity_notification_handle_stdin (GIOChannel *channel, GIOCondition condition,
gpointer user_data)
{
+ g_autofree char *icon_file = NULL;
+ g_autoptr(GHashTable) notification_hints = NULL;
+
if ((condition & G_IO_IN) != 0)
{
- GString *string;
- GError *error = NULL;
+ g_autoptr(GString) string = NULL;
+ g_autoptr(GError) error = NULL;
while (channel->is_readable == FALSE)
;
@@ -216,7 +211,8 @@ zenity_notification_handle_stdin (GIOChannel *channel, GIOCondition condition,
do {
int status;
- char *command, *value, *colon;
+ g_autofree char *command = NULL;
+ char *value, *colon;
do {
status = g_io_channel_read_line_string (channel, string,
@@ -234,7 +230,6 @@ zenity_notification_handle_stdin (GIOChannel *channel, GIOCondition condition,
g_warning ("%s: %s",
__func__,
error->message);
- g_error_free (error);
error = NULL;
}
continue;
@@ -257,14 +252,10 @@ zenity_notification_handle_stdin (GIOChannel *channel, GIOCondition condition,
if (! g_ascii_strcasecmp (command, "icon"))
{
- g_free (icon_file);
icon_file = g_strdup (value);
}
else if (!g_ascii_strcasecmp (command, "hints"))
{
- if (notification_hints != NULL) {
- g_hash_table_unref (notification_hints);
- }
notification_hints = zenity_notification_parse_hints (value);
}
else if (!g_ascii_strcasecmp (command, "message"))
@@ -289,7 +280,6 @@ zenity_notification_handle_stdin (GIOChannel *channel, GIOCondition condition,
if (error) {
g_warning (
"Error showing notification: %s", error->message);
- g_error_free (error);
error = NULL;
}
@@ -317,7 +307,6 @@ zenity_notification_handle_stdin (GIOChannel *channel, GIOCondition condition,
{
g_warning ("Error showing notification: %s",
error->message);
- g_error_free (error);
error = NULL;
}
@@ -331,11 +320,8 @@ zenity_notification_handle_stdin (GIOChannel *channel, GIOCondition condition,
{
g_warning ("Unknown command '%s'", command);
}
- g_free (command);
} while (g_io_channel_get_buffer_condition (channel) == G_IO_IN);
-
- g_string_free (string, TRUE);
}
if ((condition & G_IO_HUP) != 0)
@@ -365,9 +351,9 @@ void
zenity_notification (ZenityData *data,
ZenityNotificationData *notification_data)
{
- GError *error;
+ g_autoptr(GError) error = NULL;
NotifyNotification *notification;
- GHashTable *notification_hints;
+ g_autoptr(GHashTable) notification_hints = NULL;
/* create the notification widget */
if (!notify_is_initted ()) {
@@ -407,8 +393,6 @@ zenity_notification (ZenityData *data,
notification_data->notification_hints);
zenity_notification_set_hints (notification, notification_hints);
-
- g_hash_table_unref (notification_hints);
}
/* Show icon and wait */
@@ -417,7 +401,6 @@ zenity_notification (ZenityData *data,
{
if (error != NULL) {
g_warning ("Error showing notification: %s", error->message);
- g_error_free (error);
}
exit (1);
}
diff --git a/src/option.c b/src/option.c
index 087c15ec..f46d6914 100644
--- a/src/option.c
+++ b/src/option.c
@@ -1068,65 +1068,6 @@ zenity_option_init (void)
results->forms_data = g_new0 (ZenityFormsData, 1);
}
-void
-zenity_option_free (void)
-{
- if (zenity_general_dialog_title)
- g_free (zenity_general_dialog_title);
- if (zenity_general_dialog_text)
- g_free (zenity_general_dialog_text);
- if (zenity_general_uri)
- g_free (zenity_general_uri);
- g_free (zenity_general_separator);
- if (zenity_general_ok_button)
- g_free (zenity_general_ok_button);
- if (zenity_general_cancel_button)
- g_free (zenity_general_cancel_button);
- if (zenity_general_extra_buttons)
- g_strfreev (zenity_general_extra_buttons);
-
- if (zenity_calendar_date_format)
- g_free (zenity_calendar_date_format);
-
- if (zenity_forms_date_format)
- g_free (zenity_forms_date_format);
- if (zenity_forms_list_values)
- g_strfreev (zenity_forms_list_values);
- if (zenity_forms_combo_values)
- g_strfreev (zenity_forms_combo_values);
- if (zenity_forms_column_values)
- g_strfreev (zenity_forms_column_values);
- if (zenity_entry_entry_text)
- g_free (zenity_entry_entry_text);
-
- if (zenity_file_filter)
- g_strfreev (zenity_file_filter);
-
- if (zenity_list_columns)
- g_strfreev (zenity_list_columns);
- if (zenity_list_print_column)
- g_free (zenity_list_print_column);
- if (zenity_list_hide_column)
- g_free (zenity_list_hide_column);
-
-#ifdef HAVE_LIBNOTIFY
- if (zenity_notification_hints)
- g_strfreev (zenity_notification_hints);
- if (zenity_notification_icon)
- g_free (zenity_notification_icon);
-#endif
-
- if (zenity_text_font)
- g_free (zenity_text_font);
- if (zenity_text_checkbox)
- g_free (zenity_text_checkbox);
-
- if (zenity_colorsel_color)
- g_free (zenity_colorsel_color);
-
- g_option_context_free (ctx);
-}
-
static void
zenity_option_set_dialog_mode (gboolean is_active, ZenityDialogMode mode)
{
@@ -2229,17 +2170,14 @@ zenity_option_error (char *string, ZenityError error)
case ERROR_SYNTAX:
g_printerr (_ ("This option is not available. Please see --help "
"for all possible usages.\n"));
- zenity_option_free ();
exit (-1);
case ERROR_SUPPORT:
g_printerr (_ ("--%s is not supported for this dialog\n"), string);
- zenity_option_free ();
exit (-1);
case ERROR_DIALOG:
g_printerr (_ ("Two or more dialog options specified\n"));
- zenity_option_free ();
exit (-1);
default:
diff --git a/src/option.h b/src/option.h
index 475f9aef..40cdcb0f 100644
--- a/src/option.h
+++ b/src/option.h
@@ -83,6 +83,4 @@ void zenity_option_error (char *string, ZenityError error);
ZenityParsingOptions *zenity_option_parse (int argc, char **argv);
-void zenity_option_free (void);
-
#endif /* OPTION_H */
diff --git a/src/progress.c b/src/progress.c
index 06e54e00..81d5e5f6 100644
--- a/src/progress.c
+++ b/src/progress.c
@@ -104,7 +104,7 @@ zenity_progress_update_time_remaining (ZenityProgressData *progress_data)
(time_t) (100.0 * elapsed_time / progress_data->percentage);
time_t remaining_time = total_time - elapsed_time;
gulong hours, minutes, seconds;
- char *remaining_message;
+ g_autofree char *remaining_message = NULL;
seconds = (gulong) (remaining_time % 60);
remaining_time /= 60;
@@ -116,8 +116,6 @@ zenity_progress_update_time_remaining (ZenityProgressData *progress_data)
g_strdup_printf (_("Time remaining: %lu:%02lu:%02lu"),
hours, minutes, seconds);
gtk_label_set_text (GTK_LABEL (progress_time), remaining_message);
-
- g_free (remaining_message);
}
}
@@ -167,8 +165,8 @@ zenity_progress_handle_stdin (GIOChannel *channel, GIOCondition condition,
if ((condition & G_IO_IN) != 0)
{
- GString *string = g_string_new (NULL);
- GError *error = NULL;
+ g_autoptr(GString) string = g_string_new (NULL);
+ g_autoptr(GError) error = NULL;
while (channel->is_readable != TRUE)
;
@@ -187,7 +185,6 @@ zenity_progress_handle_stdin (GIOChannel *channel, GIOCondition condition,
if (error) {
g_warning ("%s: %s",
__func__, error->message);
- g_error_free (error);
error = NULL;
}
continue;
@@ -206,7 +203,8 @@ zenity_progress_handle_stdin (GIOChannel *channel, GIOCondition condition,
}
else if (g_str_has_prefix (string->str, "pulsate"))
{
- char *colon, *command, *value;
+ char *colon, *value;
+ g_autofree char *command = NULL;
zenity_util_strip_newline (string->str);
@@ -233,8 +231,6 @@ zenity_progress_handle_stdin (GIOChannel *channel, GIOCondition condition,
else {
zenity_progress_pulsate_start (progress_bar);
}
-
- g_free (command);
}
else
{
@@ -274,7 +270,6 @@ zenity_progress_handle_stdin (GIOChannel *channel, GIOCondition condition,
} while ((g_io_channel_get_buffer_condition (channel) & G_IO_IN) ==
G_IO_IN &&
status != G_IO_STATUS_EOF);
- g_string_free (string, TRUE);
}
if ((condition & G_IO_IN) != G_IO_IN || status == G_IO_STATUS_EOF)
diff --git a/src/scale.c b/src/scale.c
index 62714a5b..28831c49 100644
--- a/src/scale.c
+++ b/src/scale.c
@@ -39,7 +39,7 @@ static void zenity_scale_dialog_response (GtkWidget *widget, int response,
void
zenity_scale (ZenityData *data, ZenityScaleData *scale_data)
{
- GtkBuilder *builder;
+ g_autoptr(GtkBuilder) builder = NULL;
GtkWidget *dialog;
GtkWidget *button;
GObject *text;
@@ -140,8 +140,6 @@ zenity_scale (ZenityData *data, ZenityScaleData *scale_data)
dialog);
}
- g_object_unref (builder);
-
zenity_util_gapp_main (GTK_WINDOW(dialog));
}
diff --git a/src/text.c b/src/text.c
index 09c8c438..1df25b2e 100644
--- a/src/text.c
+++ b/src/text.c
@@ -170,8 +170,8 @@ zenity_text_handle_stdin (GIOChannel *channel, GIOCondition condition,
if ((condition & G_IO_IN) || (condition & (G_IO_IN | G_IO_HUP)))
{
- GError *error = NULL;
- gint status;
+ g_autoptr(GError) error = NULL;
+ int status;
while (channel->is_readable != TRUE)
;
@@ -190,7 +190,6 @@ zenity_text_handle_stdin (GIOChannel *channel, GIOCondition condition,
if (error) {
g_warning ("%s: %s",
__func__, error->message);
- g_error_free (error);
error = NULL;
}
return FALSE;
@@ -199,7 +198,7 @@ zenity_text_handle_stdin (GIOChannel *channel, GIOCondition condition,
if (len > 0)
{
GtkTextIter end;
- char *utftext;
+ g_autofree char *utftext = NULL;
gsize localelen;
gsize utflen;
@@ -216,7 +215,6 @@ zenity_text_handle_stdin (GIOChannel *channel, GIOCondition condition,
&utflen,
NULL);
gtk_text_buffer_insert (buffer, &end, utftext, utflen);
- g_free (utftext);
}
else
{
@@ -253,7 +251,7 @@ zenity_text_fill_entries_from_stdin (GtkTextView *text_view)
void
zenity_text (ZenityData *data, ZenityTextData *text_data)
{
- GtkBuilder *builder;
+ g_autoptr(GtkBuilder) builder = NULL;
GtkWidget *dialog;
GtkWidget *ok_button;
GtkWidget *checkbox;
@@ -266,7 +264,7 @@ zenity_text (ZenityData *data, ZenityTextData *text_data)
GtkWidget *web_kit;
GtkWidget *scrolled_window;
GtkTextIter start_iter, end_iter;
- gchar *content;
+ g_autofree char *content = NULL;
#endif
zen_text_data = text_data;
@@ -312,14 +310,13 @@ zenity_text (ZenityData *data, ZenityTextData *text_data)
PangoFontDescription *desc;
GtkStyleContext *context;
GtkCssProvider *provider;
- char *css_str;
+ g_autofree char *css_str = NULL;
desc = pango_font_description_from_string (text_data->font);
css_str = zenity_util_pango_font_description_to_css (desc);
provider = gtk_css_provider_new ();
gtk_css_provider_load_from_data (provider, css_str, -1);
- g_free (css_str);
context = gtk_widget_get_style_context (GTK_WIDGET(text_view));
gtk_style_context_add_provider (context,
@@ -390,23 +387,19 @@ zenity_text (ZenityData *data, ZenityTextData *text_data)
webkit_web_view_load_uri (
WEBKIT_WEB_VIEW (web_kit), text_data->url);
} else {
- gchar *cwd;
- gchar *dirname;
- gchar *dirname_uri;
+ g_autoptr char *cwd = NULL;
+ g_autoptr char *dirname = NULL;
+ g_autoptr char *dirname_uri = NULL;
dirname = text_data->uri ? g_path_get_dirname (text_data->uri)
: g_strdup ("/");
cwd = g_get_current_dir ();
dirname_uri = g_strconcat ("file://", cwd, "/", dirname, "/", NULL);
- g_free (cwd);
- g_free (dirname);
gtk_text_buffer_get_start_iter (text_buffer, &start_iter);
gtk_text_buffer_get_end_iter (text_buffer, &end_iter);
content = gtk_text_buffer_get_text (
text_buffer, &start_iter, &end_iter, TRUE);
webkit_web_view_load_html (
WEBKIT_WEB_VIEW (web_kit), content, dirname_uri);
- g_free (dirname_uri);
- g_free (content);
}
// We don't want user to click on links and navigate to another page.
@@ -425,8 +418,6 @@ zenity_text (ZenityData *data, ZenityTextData *text_data)
zenity_util_show_dialog (dialog);
- g_object_unref (builder);
-
if (data->timeout_delay > 0)
{
g_timeout_add_seconds (data->timeout_delay,
@@ -451,13 +442,12 @@ zenity_text_dialog_output (ZenityData *zen_data)
if (zen_text_data->editable)
{
GtkTextIter start, end;
- char *text;
+ g_autofree char *text = NULL;
gtk_text_buffer_get_bounds (zen_text_data->buffer, &start, &end);
text = gtk_text_buffer_get_text (zen_text_data->buffer,
&start, &end, 0);
g_print ("%s", text);
- g_free (text);
}
}
diff --git a/src/tree.c b/src/tree.c
index 6890452c..6f079739 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -37,7 +37,6 @@
#define PRINT_HIDE_COLUMN_SEPARATOR ","
-static GtkBuilder *builder;
static GtkTreeView *tree_view;
static GSList *selected;
static char *separator;
@@ -99,7 +98,7 @@ zenity_load_pixbuf (GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
static GHashTable *pixbuf_cache = NULL;
GError *error = NULL;
GdkPixbuf *pixbuf;
- char *str;
+ g_autofree char *str = NULL;
gtk_tree_model_get (tree_model, iter, 0, &str, -1);
@@ -126,8 +125,6 @@ zenity_load_pixbuf (GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
if (pixbuf)
g_object_set (cell, "pixbuf", pixbuf, NULL);
-
- g_free (str);
}
static gboolean
@@ -164,8 +161,8 @@ zenity_tree_handle_stdin (GIOChannel *channel, GIOCondition condition,
if ((condition & G_IO_IN) == G_IO_IN)
{
- GString *string;
- GError *error = NULL;
+ g_autoptr(GString) string = NULL;
+ g_autoptr(GError) error = NULL;
string = g_string_new (NULL);
@@ -194,7 +191,6 @@ zenity_tree_handle_stdin (GIOChannel *channel, GIOCondition condition,
if (error) {
g_warning ("%s: %s",
__func__, error->message);
- g_error_free (error);
error = NULL;
}
continue;
@@ -241,8 +237,6 @@ zenity_tree_handle_stdin (GIOChannel *channel, GIOCondition condition,
} while ((g_io_channel_get_buffer_condition (channel) & G_IO_IN) ==
G_IO_IN &&
status != G_IO_STATUS_EOF); /* !do while */
-
- g_string_free (string, TRUE);
}
if ((condition & G_IO_IN) != G_IO_IN || status == G_IO_STATUS_EOF)
@@ -337,7 +331,7 @@ zenity_cell_edited_callback (GtkCellRendererText *cell,
const char *path_string, const char *new_text, gpointer data)
{
GtkTreeModel *model;
- GtkTreePath *path;
+ g_autoptr(GtkTreePath) path = NULL;
GtkTreeIter iter;
int column;
@@ -348,13 +342,12 @@ zenity_cell_edited_callback (GtkCellRendererText *cell,
gtk_tree_model_get_iter (model, &iter, path);
gtk_list_store_set (GTK_LIST_STORE (model), &iter, column, new_text, -1);
-
- gtk_tree_path_free (path);
}
void
zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
{
+ g_autoptr(GtkBuilder) builder = NULL;
GtkWidget *dialog;
GtkWidget *button;
GObject *text;
@@ -692,8 +685,6 @@ zenity_tree (ZenityData *data, ZenityTreeData *tree_data)
dialog);
}
- g_object_unref (builder);
-
zenity_util_gapp_main (GTK_WINDOW(dialog));
}
@@ -887,7 +878,7 @@ zenity_tree_column_is_hidden (int column_index)
static int *
zenity_tree_extract_column_indexes (char *indexes, int n_columns)
{
- char **tmp;
+ g_auto(GStrv) tmp;
int *result;
int i, j, index;
@@ -908,7 +899,5 @@ zenity_tree_extract_column_indexes (char *indexes, int n_columns)
}
result[j] = 0;
- g_strfreev (tmp);
-
return result;
}
diff --git a/src/util.c b/src/util.c
index f1268408..d0dcc3f3 100644
--- a/src/util.c
+++ b/src/util.c
@@ -55,7 +55,7 @@ zenity_util_load_ui_file (const char *root_widget, ...)
char *arg = NULL;
GPtrArray *ptrarray;
GtkBuilder *builder = gtk_builder_new ();
- GError *error = NULL;
+ g_autoptr(GError) error = NULL;
char **objects;
gboolean result = FALSE;
@@ -98,7 +98,6 @@ zenity_util_load_ui_file (const char *root_widget, ...)
if (error) {
g_debug ("%s: Error generated: %s",
__func__, error->message);
- g_error_free (error);
}
return builder;
@@ -180,13 +179,10 @@ zenity_util_fill_file_buffer (GtkTextBuffer *buffer, const char *filename) {
void
zenity_util_show_help (GError **error) {
- char *tmp;
- tmp = g_find_program_in_path ("yelp");
+ g_autofree char *tmp = g_find_program_in_path ("yelp");
- if (tmp) {
- g_free (tmp);
+ if (tmp)
g_spawn_command_line_async ("yelp help:zenity", error);
- }
}
int
@@ -305,6 +301,8 @@ zenity_util_pango_font_description_to_css (PangoFontDescription *desc)
case PANGO_VARIANT_SMALL_CAPS:
g_string_append (s, "font-variant: small-caps; ");
break;
+ default:
+ break;
}
}
if (set & PANGO_FONT_MASK_WEIGHT)
diff --git a/src/zenity.ui b/src/zenity.ui
index 82513a43..03f9684f 100644
--- a/src/zenity.ui
+++ b/src/zenity.ui
@@ -749,9 +749,4 @@
</object>
</child>
</object>
-
-
-
-
-
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]