Unverified Commit 39e31e91 authored by Iain Lane's avatar Iain Lane
Browse files

privacy: Remove {get,set}_on_off_label2

There's only one instance of this pattern - make the function specific
to that case rather than generic.

The current code is leaking the Label2Data struct and the GSettings
signal connection. The leak of the signal connection was causing a crash
in case the callback was called after the label was destroyed. Instead
of just directly fixing these problems, let's eliminate the intermediate
struct and just support the specific case we're interested in directly.
parent 2b7dab9c
......@@ -265,38 +265,52 @@ typedef struct
const gchar *key2;
} Label2Data;
static void
set_on_off_label2 (GSettings *settings,
const gchar *key,
gpointer user_data)
static const char *
update_purge_trash_label (GSettings *settings,
gchar *key,
gpointer user_data)
Label2Data *data = user_data;
gboolean v1, v2;
static const char * const interesting_keys[] = { REMOVE_OLD_TRASH_FILES,
gboolean remove_old_trash, remove_old_temp;
GtkLabel *label;
const char *label_text;
if (!g_strv_contains (interesting_keys, key))
return NULL;
v1 = g_settings_get_boolean (settings, data->key1);
v2 = g_settings_get_boolean (settings, data->key2);
label = GTK_LABEL (user_data);
gtk_label_set_label (data->label, (v1 || v2) ? _("On") : _("Off"));
remove_old_trash = g_settings_get_boolean (settings, REMOVE_OLD_TRASH_FILES);
remove_old_temp = g_settings_get_boolean (settings, REMOVE_OLD_TEMP_FILES);
label_text = (remove_old_trash || remove_old_temp) ? _("On") : _("Off");
if (label != NULL)
gtk_label_set_label (label, label_text);
return label_text;
static GtkLabel *
get_on_off_label2 (GSettings *settings,
const gchar *key1,
const gchar *key2)
get_purge_trash_label (GSettings *settings)
Label2Data *data;
GtkLabel *label;
const char *label_text;
data = g_new (Label2Data, 1);
data->label = GTK_LABEL (gtk_label_new (""));
data->key1 = g_strdup (key1);
data->key2 = g_strdup (key2);
label_text = update_purge_trash_label (settings, REMOVE_OLD_TEMP_FILES, NULL);
g_signal_connect (settings, "changed",
G_CALLBACK (set_on_off_label2), data);
label = GTK_LABEL (gtk_label_new (label_text));
set_on_off_label2 (settings, key1, data);
g_signal_connect_object (settings,
G_CALLBACK (update_purge_trash_label),
return data->label;
return label;
static GtkListBoxRow *
......@@ -1185,7 +1199,7 @@ add_trash_temp (CcPrivacyPanel *self)
GtkLabel *w;
w = get_on_off_label2 (self->privacy_settings, REMOVE_OLD_TRASH_FILES, REMOVE_OLD_TEMP_FILES);
w = get_purge_trash_label (self->privacy_settings);
gtk_widget_show (GTK_WIDGET (w));
add_row (self, _("Purge Trash & Temporary Files"), self->trash_dialog, GTK_WIDGET (w));
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment