Skip to content

Commit

Permalink
capplet: Use g_settings_bind() to simplify code
Browse files Browse the repository at this point in the history
Also unref the GSettings on dispose().
  • Loading branch information
vuntz committed Feb 2, 2011
1 parent 85f69aa commit 11d9ec5
Showing 1 changed file with 7 additions and 50 deletions.
57 changes: 7 additions & 50 deletions capplet/gsm-properties-dialog.c
Expand Up @@ -61,8 +61,6 @@ struct GsmPropertiesDialogPrivate
GtkWidget *delete_button;
GtkWidget *edit_button;

GtkWidget *remember_toggle;

GSettings *settings;

GspAppManager *manager;
Expand Down Expand Up @@ -456,41 +454,6 @@ on_row_activated (GtkTreeView *tree_view,
on_edit_app_clicked (NULL, dialog);
}

static void
on_autosave_value_setting_changed (GSettings *settings,
const gchar *key,
GsmPropertiesDialog *dialog)
{
gboolean gval;
gboolean bval;

gval = g_settings_get_boolean (dialog->priv->settings, key);
bval = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->remember_toggle));

if (bval != gval) {
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->remember_toggle),
gval);
}
}

static void
on_autosave_value_toggled (GtkToggleButton *button,
GsmPropertiesDialog *dialog)
{
gboolean gval;
gboolean bval;

gval = g_settings_get_boolean (dialog->priv->settings,
SPC_SETTINGS_AUTOSAVE_KEY);
bval = gtk_toggle_button_get_active (button);

if (gval != bval) {
g_settings_set_boolean (dialog->priv->settings,
SPC_SETTINGS_AUTOSAVE_KEY,
bval);
}
}

static void
on_save_session_clicked (GtkWidget *widget,
GsmPropertiesDialog *dialog)
Expand Down Expand Up @@ -661,19 +624,8 @@ setup_dialog (GsmPropertiesDialog *dialog)

button = GTK_WIDGET (gtk_builder_get_object (dialog->priv->xml,
CAPPLET_REMEMBER_WIDGET_NAME));
dialog->priv->remember_toggle = button;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
g_settings_get_boolean (dialog->priv->settings,
SPC_SETTINGS_AUTOSAVE_KEY));
g_signal_connect (dialog->priv->settings,
"changed::" SPC_SETTINGS_AUTOSAVE_KEY,
G_CALLBACK (on_autosave_value_setting_changed),
dialog);

g_signal_connect (button,
"toggled",
G_CALLBACK (on_autosave_value_toggled),
dialog);
g_settings_bind (dialog->priv->settings, SPC_SETTINGS_AUTOSAVE_KEY,
button, "active", G_SETTINGS_BIND_DEFAULT);

button = GTK_WIDGET (gtk_builder_get_object (dialog->priv->xml,
CAPPLET_SAVE_WIDGET_NAME));
Expand Down Expand Up @@ -725,6 +677,11 @@ gsm_properties_dialog_dispose (GObject *object)
dialog->priv->xml = NULL;
}

if (dialog->priv->settings != NULL) {
g_object_unref (dialog->priv->settings);
dialog->priv->settings = NULL;
}

G_OBJECT_CLASS (gsm_properties_dialog_parent_class)->dispose (object);

/* it's important to do this after chaining to the parent dispose
Expand Down

0 comments on commit 11d9ec5

Please sign in to comment.