[gnome-control-center] sound: Use g_auto for variables
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] sound: Use g_auto for variables
- Date: Fri, 26 Jan 2018 01:31:30 +0000 (UTC)
commit 911e7d4e4f5e27b580ff6b021437c7c941f1d3d0
Author: Robert Ancell <robert ancell canonical com>
Date: Tue Sep 26 21:35:10 2017 -0400
sound: Use g_auto for variables
https://bugzilla.gnome.org/show_bug.cgi?id=788223
panels/sound/cc-sound-panel.c | 14 ++----
panels/sound/gvc-channel-bar.c | 4 +-
panels/sound/gvc-combo-box.c | 3 +-
panels/sound/gvc-mixer-dialog.c | 69 ++++++++-----------------
panels/sound/gvc-sound-theme-chooser.c | 51 ++++++-------------
panels/sound/gvc-speaker-test.c | 4 +-
panels/sound/sound-theme-file-utils.c | 85 ++++++++++++-------------------
7 files changed, 79 insertions(+), 151 deletions(-)
---
diff --git a/panels/sound/cc-sound-panel.c b/panels/sound/cc-sound-panel.c
index 2d73f1b..3c566a7 100644
--- a/panels/sound/cc-sound-panel.c
+++ b/panels/sound/cc-sound-panel.c
@@ -63,10 +63,9 @@ cc_sound_panel_set_property (GObject *object,
parameters = g_value_get_variant (value);
if (parameters && g_variant_n_children (parameters) > 0) {
- GVariant *v;
+ g_autoptr(GVariant) v = NULL;
g_variant_get_child (parameters, 0, "v", &v);
gvc_mixer_dialog_set_page (self->dialog, g_variant_get_string (v, NULL));
- g_variant_unref (v);
}
break;
}
@@ -100,14 +99,9 @@ cc_sound_panel_finalize (GObject *object)
{
CcSoundPanel *panel = CC_SOUND_PANEL (object);
- if (panel->dialog != NULL)
- panel->dialog = NULL;
- if (panel->connecting_label != NULL)
- panel->connecting_label = NULL;
- if (panel->control != NULL) {
- g_object_unref (panel->control);
- panel->control = NULL;
- }
+ panel->dialog = NULL;
+ panel->connecting_label = NULL;
+ g_clear_object (&panel->control);
G_OBJECT_CLASS (cc_sound_panel_parent_class)->finalize (object);
}
diff --git a/panels/sound/gvc-channel-bar.c b/panels/sound/gvc-channel-bar.c
index e834af1..dd6f47d 100644
--- a/panels/sound/gvc-channel-bar.c
+++ b/panels/sound/gvc-channel-bar.c
@@ -604,7 +604,7 @@ gvc_channel_bar_set_is_amplified (GvcChannelBar *bar, gboolean amplified)
gtk_scale_clear_marks (GTK_SCALE (bar->scale));
if (amplified) {
- char *str;
+ g_autofree gchar *str = NULL;
if (bar->base_volume == ADJUSTMENT_MAX_NORMAL) {
str = g_strdup_printf ("<small>%s</small>", C_("volume", "100%"));
@@ -622,8 +622,6 @@ gvc_channel_bar_set_is_amplified (GvcChannelBar *bar, gboolean amplified)
}
}
- g_free (str);
-
/* Ideally we would use baseline alignment for all
* these widgets plus the scale but neither GtkScale
* nor GtkSwitch support baseline alignment yet. */
diff --git a/panels/sound/gvc-combo-box.c b/panels/sound/gvc-combo-box.c
index ee77b0d..5e09e68 100644
--- a/panels/sound/gvc-combo-box.c
+++ b/panels/sound/gvc-combo-box.c
@@ -269,7 +269,7 @@ on_combo_box_changed (GtkComboBox *widget,
GvcComboBox *combo_box)
{
GtkTreeIter iter;
- char *profile;
+ g_autofree gchar *profile = NULL;
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter) == FALSE) {
g_warning ("Could not find an active profile or port");
@@ -280,7 +280,6 @@ on_combo_box_changed (GtkComboBox *widget,
COL_NAME, &profile,
-1);
g_signal_emit (combo_box, signals[CHANGED], 0, profile);
- g_free (profile);
}
static void
diff --git a/panels/sound/gvc-mixer-dialog.c b/panels/sound/gvc-mixer-dialog.c
index a08d128..e3e1efc 100644
--- a/panels/sound/gvc-mixer-dialog.c
+++ b/panels/sound/gvc-mixer-dialog.c
@@ -635,7 +635,7 @@ on_adjustment_value_changed (GtkAdjustment *adjustment,
if (stream != NULL) {
GObject *bar;
gdouble volume, rounded;
- char *name;
+ g_autofree gchar *name = NULL;
volume = gtk_adjustment_get_value (adjustment);
rounded = round (volume);
@@ -643,7 +643,6 @@ on_adjustment_value_changed (GtkAdjustment *adjustment,
bar = g_object_get_data (G_OBJECT (adjustment), "gvc-mixer-dialog-bar");
g_object_get (bar, "name", &name, NULL);
g_debug ("Setting stream volume %lf (rounded: %lf) for bar '%s'", volume, rounded, name);
- g_free (name);
/* FIXME would need to do that in the balance bar really... */
/* Make sure we do not unmute muted streams, there's a button for that */
@@ -669,10 +668,9 @@ on_bar_is_muted_notify (GObject *object,
if (stream != NULL) {
gvc_mixer_stream_change_is_muted (stream, is_muted);
} else {
- char *name;
+ g_autofree gchar *name = NULL;
g_object_get (object, "name", &name, NULL);
g_warning ("Unable to find stream for bar '%s'", name);
- g_free (name);
}
}
@@ -802,13 +800,12 @@ create_app_bar (GvcMixerDialog *dialog,
if (name == NULL || strchr (name, '_') == NULL) {
gvc_channel_bar_set_name (GVC_CHANNEL_BAR (bar), name);
} else {
- char **tokens, *escaped;
+ g_auto(GStrv) tokens = NULL;
+ g_autofree gchar *escaped = NULL;
tokens = g_strsplit (name, "_", -1);
escaped = g_strjoinv ("__", tokens);
- g_strfreev (tokens);
gvc_channel_bar_set_name (GVC_CHANNEL_BAR (bar), escaped);
- g_free (escaped);
}
return bar;
@@ -944,12 +941,11 @@ bar_set_stream (GvcMixerDialog *dialog,
old_stream = g_object_get_data (G_OBJECT (bar), "gvc-mixer-dialog-stream");
if (old_stream != NULL) {
- char *name;
+ g_autofree gchar *name = NULL;
g_object_get (bar, "name", &name, NULL);
g_debug ("Disconnecting old stream '%s' from bar '%s'",
gvc_mixer_stream_get_name (old_stream), name);
- g_free (name);
g_signal_handlers_disconnect_by_func (old_stream, on_stream_is_muted_notify, dialog);
g_signal_handlers_disconnect_by_func (old_stream, on_stream_volume_notify, dialog);
@@ -1025,12 +1021,11 @@ add_stream (GvcMixerDialog *dialog,
if (bar != NULL) {
old_stream = g_object_get_data (G_OBJECT (bar), "gvc-mixer-dialog-stream");
if (old_stream != NULL) {
- char *name;
+ g_autofree gchar *name = NULL;
g_object_get (bar, "name", &name, NULL);
g_debug ("Disconnecting old stream '%s' from bar '%s'",
gvc_mixer_stream_get_name (old_stream), name);
- g_free (name);
g_signal_handlers_disconnect_by_func (old_stream, on_stream_is_muted_notify, dialog);
g_signal_handlers_disconnect_by_func (old_stream, on_stream_volume_notify, dialog);
@@ -1106,15 +1101,15 @@ static void
add_input_ui_entry (GvcMixerDialog *dialog,
GvcMixerUIDevice *input)
{
- gchar *final_name;
- gchar *port_name;
- gchar *origin;
- gchar *description;
+ g_autofree gchar *final_name = NULL;
+ g_autofree gchar *port_name = NULL;
+ g_autofree gchar *origin = NULL;
+ g_autofree gchar *description = NULL;
gboolean available;
gint stream_id;
GtkTreeModel *model;
GtkTreeIter iter;
- GIcon *icon;
+ g_autoptr(GIcon) icon = NULL;
g_debug ("Add input ui entry with id :%u",
gvc_mixer_ui_device_get_id (input));
@@ -1132,10 +1127,6 @@ add_input_ui_entry (GvcMixerDialog *dialog,
else
final_name = g_strdup (description);
- g_free (port_name);
- g_free (origin);
- g_free (description);
-
icon = gvc_mixer_ui_device_get_gicon (input);
if (icon == NULL) {
@@ -1144,7 +1135,6 @@ add_input_ui_entry (GvcMixerDialog *dialog,
stream = gvc_mixer_control_get_stream_from_device (dialog->mixer_control, input);
if (stream == NULL) {
g_warning ("tried to add the network source but the stream was null - fail ?!");
- g_free (final_name);
return;
}
icon = gvc_mixer_stream_get_gicon (stream);
@@ -1161,25 +1151,21 @@ add_input_ui_entry (GvcMixerDialog *dialog,
ICON_COLUMN, icon,
ID_COLUMN, gvc_mixer_ui_device_get_id (input),
-1);
-
- if (icon != NULL)
- g_object_unref (icon);
- g_free (final_name);
}
static void
add_output_ui_entry (GvcMixerDialog *dialog,
GvcMixerUIDevice *output)
{
- gchar *sink_port_name;
- gchar *origin;
- gchar *description;
- gchar *final_name;
- gboolean available;
- gint sink_stream_id;
- GtkTreeModel *model;
- GtkTreeIter iter;
- GIcon *icon;
+ g_autofree gchar *sink_port_name = NULL;
+ g_autofree gchar *origin = NULL;
+ g_autofree gchar *description = NULL;
+ g_autofree gchar *final_name = NULL;
+ gboolean available;
+ gint sink_stream_id;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ g_autoptr(GIcon) icon = NULL;
g_debug ("Add output ui entry with id :%u",
gvc_mixer_ui_device_get_id (output));
@@ -1197,10 +1183,6 @@ add_output_ui_entry (GvcMixerDialog *dialog,
else
final_name = g_strdup (description);
- g_free (sink_port_name);
- g_free (origin);
- g_free (description);
-
icon = gvc_mixer_ui_device_get_gicon (output);
if (icon == NULL) {
@@ -1211,7 +1193,6 @@ add_output_ui_entry (GvcMixerDialog *dialog,
if (stream == NULL) {
g_warning ("tried to add the network sink but the stream was null - fail ?!");
- g_free (final_name);
return;
}
icon = gvc_mixer_stream_get_gicon (stream);
@@ -1228,10 +1209,6 @@ add_output_ui_entry (GvcMixerDialog *dialog,
ICON_COLUMN, icon,
ID_COLUMN, gvc_mixer_ui_device_get_id (output),
-1);
-
- if (icon != NULL)
- g_object_unref (icon);
- g_free (final_name);
}
@@ -1398,11 +1375,10 @@ on_control_stream_removed (GvcMixerControl *control,
static void
_gtk_label_make_bold (GtkLabel *label)
{
- gchar *str;
+ g_autofree gchar *str = NULL;
str = g_strdup_printf ("<span font-weight='bold'>%s</span>",
gtk_label_get_label (label));
gtk_label_set_markup_with_mnemonic (label, str);
- g_free (str);
}
static void
@@ -1541,7 +1517,7 @@ on_test_speakers_clicked (GvcComboBox *widget,
GvcMixerUIDevice *output;
GvcMixerStream *stream;
GtkWidget *d, *speaker_test, *container;
- char *title;
+ g_autofree gchar *title = NULL;
model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->output_treeview));
@@ -1592,7 +1568,6 @@ on_test_speakers_clicked (GvcComboBox *widget,
"resizable", FALSE,
NULL);
- g_free (title);
speaker_test = gvc_speaker_test_new (dialog->mixer_control,
stream);
gtk_widget_show (speaker_test);
diff --git a/panels/sound/gvc-sound-theme-chooser.c b/panels/sound/gvc-sound-theme-chooser.c
index cd63dc9..93eeb15 100644
--- a/panels/sound/gvc-sound-theme-chooser.c
+++ b/panels/sound/gvc-sound-theme-chooser.c
@@ -242,7 +242,7 @@ populate_model_from_dir (GvcSoundThemeChooser *chooser,
}
while ((name = g_dir_read_name (d)) != NULL) {
- char *path;
+ g_autofree gchar *path = NULL;
if (! g_str_has_suffix (name, ".xml")) {
continue;
@@ -250,7 +250,6 @@ populate_model_from_dir (GvcSoundThemeChooser *chooser,
path = g_build_filename (dirname, name, NULL);
populate_model_from_file (chooser, model, path);
- g_free (path);
}
}
@@ -259,7 +258,7 @@ save_alert_sounds (GvcSoundThemeChooser *chooser,
const char *id)
{
const char *sounds[3] = { "bell-terminal", "bell-window-system", NULL };
- char *path;
+ g_autofree gchar *path = NULL;
if (strcmp (id, DEFAULT_ALERT_ID) == 0) {
delete_old_files (sounds);
@@ -276,7 +275,6 @@ save_alert_sounds (GvcSoundThemeChooser *chooser,
g_warning ("Failed to update mtime for directory '%s': %s",
path, g_strerror (errno));
}
- g_free (path);
return FALSE;
}
@@ -292,7 +290,7 @@ update_alert_model (GvcSoundThemeChooser *chooser,
model = gtk_tree_view_get_model (GTK_TREE_VIEW (chooser->treeview));
g_assert (gtk_tree_model_get_iter_first (model, &iter));
do {
- char *this_id;
+ g_autofree gchar *this_id = NULL;
gtk_tree_model_get (model, &iter,
ALERT_IDENTIFIER_COL, &this_id,
@@ -304,8 +302,6 @@ update_alert_model (GvcSoundThemeChooser *chooser,
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (chooser->treeview));
gtk_tree_selection_select_iter (selection, &iter);
}
-
- g_free (this_id);
} while (gtk_tree_model_iter_next (model, &iter));
}
@@ -333,12 +329,11 @@ static gboolean
load_theme_file (const char *path,
char **parent)
{
- GKeyFile *file;
+ g_autoptr(GKeyFile) file = NULL;
gboolean hidden;
file = g_key_file_new ();
if (g_key_file_load_from_file (file, path, G_KEY_FILE_KEEP_TRANSLATIONS, NULL) == FALSE) {
- g_key_file_free (file);
return FALSE;
}
/* Don't add hidden themes to the list */
@@ -353,8 +348,6 @@ load_theme_file (const char *path,
}
}
- g_key_file_free (file);
-
return TRUE;
}
@@ -364,22 +357,22 @@ load_theme_name (const char *name,
{
const char * const *data_dirs;
const char *data_dir;
- char *path;
+ g_autofree gchar *path = NULL;
guint i;
gboolean res;
data_dir = g_get_user_data_dir ();
path = g_build_filename (data_dir, "sounds", name, "index.theme", NULL);
res = load_theme_file (path, parent);
- g_free (path);
if (res)
return TRUE;
data_dirs = g_get_system_data_dirs ();
for (i = 0; data_dirs[i] != NULL; i++) {
- path = g_build_filename (data_dirs[i], "sounds", name, "index.theme", NULL);
- res = load_theme_file (path, parent);
- g_free (path);
+ g_autofree gchar *p = NULL;
+
+ p = g_build_filename (data_dirs[i], "sounds", name, "index.theme", NULL);
+ res = load_theme_file (p, parent);
if (res)
return TRUE;
}
@@ -495,14 +488,13 @@ on_treeview_row_activated (GtkTreeView *treeview,
{
GtkTreeModel *model;
GtkTreeIter iter;
- char *id;
+ g_autofree gchar *id = NULL;
model = gtk_tree_view_get_model (GTK_TREE_VIEW (chooser->treeview));
if (!gtk_tree_model_get_iter (model, &iter, path)) {
return;
}
- id = NULL;
gtk_tree_model_get (model, &iter,
ALERT_IDENTIFIER_COL, &id,
-1);
@@ -512,7 +504,6 @@ on_treeview_row_activated (GtkTreeView *treeview,
play_preview_for_id (chooser, id);
update_alert (chooser, id);
- g_free (id);
}
static GtkWidget *
@@ -573,32 +564,27 @@ static int
get_file_type (const char *sound_name,
char **linked_name)
{
- char *name, *filename;
+ g_autofree gchar *name = NULL;
+ g_autofree gchar *filename = NULL;
*linked_name = NULL;
name = g_strdup_printf ("%s.disabled", sound_name);
filename = custom_theme_dir_path (name);
- g_free (name);
if (g_file_test (filename, G_FILE_TEST_IS_REGULAR) != FALSE) {
- g_free (filename);
return SOUND_TYPE_OFF;
}
- g_free (filename);
/* We only check for .ogg files because those are the
* only ones we create */
name = g_strdup_printf ("%s.ogg", sound_name);
filename = custom_theme_dir_path (name);
- g_free (name);
if (g_file_test (filename, G_FILE_TEST_IS_SYMLINK) != FALSE) {
*linked_name = g_file_read_link (filename, NULL);
- g_free (filename);
return SOUND_TYPE_CUSTOM;
}
- g_free (filename);
return SOUND_TYPE_BUILTIN;
}
@@ -611,10 +597,9 @@ update_alerts_from_theme_name (GvcSoundThemeChooser *chooser,
/* reset alert to default */
update_alert (chooser, DEFAULT_ALERT_ID);
} else {
- int sound_type;
- char *linkname;
+ int sound_type;
+ g_autofree gchar *linkname = NULL;
- linkname = NULL;
sound_type = get_file_type ("bell-terminal", &linkname);
g_debug ("Found link: %s", linkname);
if (sound_type == SOUND_TYPE_CUSTOM) {
@@ -626,8 +611,8 @@ update_alerts_from_theme_name (GvcSoundThemeChooser *chooser,
static void
update_theme (GvcSoundThemeChooser *chooser)
{
- gboolean events_enabled;
- char *last_theme;
+ gboolean events_enabled;
+ g_autofree gchar *last_theme = NULL;
events_enabled = g_settings_get_boolean (chooser->sound_settings, EVENT_SOUNDS_KEY);
@@ -648,7 +633,6 @@ update_theme (GvcSoundThemeChooser *chooser)
&chooser->current_parent);
}
}
- g_free (last_theme);
gtk_widget_set_sensitive (chooser->selection_box, events_enabled);
@@ -725,7 +709,7 @@ gvc_sound_theme_chooser_init (GvcSoundThemeChooser *chooser)
GtkWidget *box;
GtkWidget *label;
GtkWidget *scrolled_window;
- char *str;
+ g_autofree gchar *str = NULL;
gtk_orientable_set_orientation (GTK_ORIENTABLE (chooser),
GTK_ORIENTATION_VERTICAL);
@@ -735,7 +719,6 @@ gvc_sound_theme_chooser_init (GvcSoundThemeChooser *chooser)
str = g_strdup_printf ("<b>%s</b>", _("C_hoose an alert sound:"));
chooser->selection_box = box = gtk_frame_new (str);
- g_free (str);
label = gtk_frame_get_label_widget (GTK_FRAME (box));
gtk_label_set_use_underline (GTK_LABEL (label), TRUE);
gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
diff --git a/panels/sound/gvc-speaker-test.c b/panels/sound/gvc-speaker-test.c
index a84ecf2..21fd9eb 100644
--- a/panels/sound/gvc-speaker-test.c
+++ b/panels/sound/gvc-speaker-test.c
@@ -397,7 +397,7 @@ static void
gvc_speaker_test_set_theme (ca_context *ca)
{
GtkSettings *settings;
- char *theme_name;
+ g_autofree gchar *theme_name = NULL;
settings = gtk_settings_get_for_screen (gdk_screen_get_default ());
@@ -407,8 +407,6 @@ gvc_speaker_test_set_theme (ca_context *ca)
if (theme_name)
ca_context_change_props (ca, CA_PROP_CANBERRA_XDG_THEME_NAME, theme_name, NULL);
-
- g_free (theme_name);
}
static void
diff --git a/panels/sound/sound-theme-file-utils.c b/panels/sound/sound-theme-file-utils.c
index ef80ec9..3863b25 100644
--- a/panels/sound/sound-theme-file-utils.c
+++ b/panels/sound/sound-theme-file-utils.c
@@ -31,11 +31,10 @@
void
custom_theme_update_time (void)
{
- char *path;
+ g_autofree gchar *path = NULL;
path = custom_theme_dir_path (NULL);
utime (path, NULL);
- g_free (path);
}
char *
@@ -102,7 +101,7 @@ directory_delete_recursive (GFile *directory, GError **error)
static gboolean
capplet_file_delete_recursive (GFile *file, GError **error)
{
- GFileInfo *info;
+ g_autoptr(GFileInfo) info = NULL;
GFileType type;
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
@@ -115,7 +114,6 @@ capplet_file_delete_recursive (GFile *file, GError **error)
return FALSE;
type = g_file_info_get_file_type (info);
- g_object_unref (info);
if (type == G_FILE_TYPE_DIRECTORY)
return directory_delete_recursive (file, error);
@@ -126,14 +124,12 @@ capplet_file_delete_recursive (GFile *file, GError **error)
void
delete_custom_theme_dir (void)
{
- char *dir;
- GFile *file;
+ g_autofree gchar *dir = NULL;
+ g_autoptr(GFile) file = NULL;
dir = custom_theme_dir_path (NULL);
file = g_file_new_for_path (dir);
- g_free (dir);
capplet_file_delete_recursive (file, NULL);
- g_object_unref (file);
g_debug ("deleted the custom theme dir");
}
@@ -141,16 +137,14 @@ delete_custom_theme_dir (void)
gboolean
custom_theme_dir_is_empty (void)
{
- char *dir;
- GFile *file;
- gboolean is_empty;
- GFileEnumerator *enumerator;
- GFileInfo *info;
- GError *error = NULL;
+ g_autofree gchar *dir = NULL;
+ g_autoptr(GFile) file = NULL;
+ gboolean is_empty;
+ GFileEnumerator *enumerator;
+ g_autoptr(GError) error = NULL;
dir = custom_theme_dir_path (NULL);
file = g_file_new_for_path (dir);
- g_free (dir);
is_empty = TRUE;
@@ -161,24 +155,22 @@ custom_theme_dir_is_empty (void)
NULL, &error);
if (enumerator == NULL) {
g_warning ("Unable to enumerate files: %s", error->message);
- g_error_free (error);
- goto out;
+ return TRUE;
}
- while (is_empty &&
- (info = g_file_enumerator_next_file (enumerator, NULL, NULL))) {
+ while (is_empty) {
+ g_autoptr(GFileInfo) info = NULL;
+
+ info = g_file_enumerator_next_file (enumerator, NULL, NULL);
+ if (info == NULL)
+ break;
if (strcmp ("index.theme", g_file_info_get_name (info)) != 0) {
is_empty = FALSE;
}
-
- g_object_unref (info);
}
g_file_enumerator_close (enumerator, NULL, NULL);
- out:
- g_object_unref (file);
-
return is_empty;
}
@@ -190,8 +182,9 @@ typedef enum {
static void
delete_one_file (const char *sound_name, SoundType sound_type)
{
- GFile *file;
- char *name, *filename;
+ g_autofree gchar *name = NULL;
+ g_autofree gchar *filename = NULL;
+ g_autoptr(GFile) file = NULL;
switch (sound_type) {
case SOUND_TYPE_OGG:
@@ -205,11 +198,8 @@ delete_one_file (const char *sound_name, SoundType sound_type)
}
filename = custom_theme_dir_path (name);
- g_free (name);
file = g_file_new_for_path (filename);
- g_free (filename);
capplet_file_delete_recursive (file, NULL);
- g_object_unref (file);
}
void
@@ -233,13 +223,11 @@ delete_disabled_files (const char **sounds)
static void
create_one_file (GFile *file)
{
- GFileOutputStream* stream;
+ g_autoptr(GFileOutputStream) stream = NULL;
stream = g_file_create (file, G_FILE_CREATE_NONE, NULL, NULL);
- if (stream != NULL) {
+ if (stream != NULL)
g_output_stream_close (G_OUTPUT_STREAM (stream), NULL, NULL);
- g_object_unref (stream);
- }
}
void
@@ -248,17 +236,15 @@ add_disabled_file (const char **sounds)
guint i;
for (i = 0; sounds[i] != NULL; i++) {
- GFile *file;
- char *name, *filename;
+ g_autofree gchar *name = NULL;
+ g_autofree gchar *filename = NULL;
+ g_autoptr(GFile) file = NULL;
name = g_strdup_printf ("%s.disabled", sounds[i]);
filename = custom_theme_dir_path (name);
- g_free (name);
file = g_file_new_for_path (filename);
- g_free (filename);
create_one_file (file);
- g_object_unref (file);
}
}
@@ -268,36 +254,34 @@ add_custom_file (const char **sounds, const char *filename)
guint i;
for (i = 0; sounds[i] != NULL; i++) {
- GFile *file;
- char *name, *path;
+ g_autofree gchar *name = NULL;
+ g_autofree gchar *path = NULL;
+ g_autoptr(GFile) file = NULL;
/* We use *.ogg because it's the first type of file that
* libcanberra looks at */
name = g_strdup_printf ("%s.ogg", sounds[i]);
path = custom_theme_dir_path (name);
- g_free (name);
/* In case there's already a link there, delete it */
g_unlink (path);
file = g_file_new_for_path (path);
- g_free (path);
/* Create the link */
g_file_make_symbolic_link (file, filename, NULL, NULL);
- g_object_unref (file);
}
}
void
create_custom_theme (const char *parent)
{
- GKeyFile *keyfile;
- char *data;
- char *path;
+ g_autofree gchar *path = NULL;
+ g_autoptr(GKeyFile) keyfile = NULL;
+ g_autofree gchar *data = NULL;
+ g_autofree gchar *index_path = NULL;
/* Create the custom directory */
path = custom_theme_dir_path (NULL);
g_mkdir_with_parents (path, USER_DIR_MODE);
- g_free (path);
/* Set the data for index.theme */
keyfile = g_key_file_new ();
@@ -305,13 +289,10 @@ create_custom_theme (const char *parent)
g_key_file_set_string (keyfile, "Sound Theme", "Inherits", parent);
g_key_file_set_string (keyfile, "Sound Theme", "Directories", ".");
data = g_key_file_to_data (keyfile, NULL, NULL);
- g_key_file_free (keyfile);
/* Save the index.theme */
- path = custom_theme_dir_path ("index.theme");
- g_file_set_contents (path, data, -1, NULL);
- g_free (path);
- g_free (data);
+ index_path = custom_theme_dir_path ("index.theme");
+ g_file_set_contents (index_path, data, -1, NULL);
custom_theme_update_time ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]