59
56
return GTK_SPIN_BUTTON (object);
60
widget_name_for_option (const gchar *option)
62
g_return_val_if_fail (option, NULL);
63
if (g_str_equal (option, GCR_UNLOCK_OPTION_ALWAYS))
64
return "lock_always_choice";
65
else if (g_str_equal (option, GCR_UNLOCK_OPTION_SESSION))
66
return "lock_session_choice";
67
else if (g_str_equal (option, GCR_UNLOCK_OPTION_TIMEOUT))
68
return "lock_timeout_choice";
69
else if (g_str_equal (option, GCR_UNLOCK_OPTION_IDLE))
70
return "lock_idle_choice";
75
static GtkToggleButton*
76
widget_button_for_option (GcrUnlockOptionsWidget *self, const gchar *option)
78
const gchar *name = widget_name_for_option (option);
79
g_return_val_if_fail (name, NULL);
80
return builder_get_toggle_button (self->pv->builder, name);
84
widget_button_to_option (GcrUnlockOptionsWidget *self, GtkToggleButton *button)
87
g_return_val_if_fail (button, NULL);
88
option = g_object_get_data (G_OBJECT (button), "unlock-choice");
89
g_return_val_if_fail (option, NULL);
63
on_timeout_choices_toggled (GtkToggleButton *unused, GtkBuilder *builder)
94
on_choice_toggled (GtkToggleButton *button, GcrUnlockOptionsWidget *self)
66
97
GtkToggleButton *after, *idle;
68
spin = GTK_WIDGET (gtk_builder_get_object (builder, "lock_minutes_spin"));
69
after = builder_get_toggle_button (builder, "lock_after_choice");
70
idle = builder_get_toggle_button (builder, "lock_idle_choice");
99
spin = GTK_WIDGET (gtk_builder_get_object (self->pv->builder, "lock_minutes_spin"));
100
after = builder_get_toggle_button (self->pv->builder, "lock_timeout_choice");
101
idle = builder_get_toggle_button (self->pv->builder, "lock_idle_choice");
71
102
gtk_widget_set_sensitive (spin, gtk_toggle_button_get_active (after) ||
72
103
gtk_toggle_button_get_active (idle));
77
widget_name_for_option (guint option)
80
case GCR_UNLOCK_OPTION_SESSION:
81
return "lock_logout_choice";
82
case GCR_UNLOCK_OPTION_TIMEOUT:
83
return "lock_after_choice";
84
case GCR_UNLOCK_OPTION_IDLE:
85
return "lock_idle_choice";
105
if (gtk_toggle_button_get_active (button)) {
106
g_free (self->pv->choice);
107
self->pv->choice = g_strdup (widget_button_to_option (self, button));
112
132
gtk_container_add (GTK_CONTAINER (self), widget);
113
133
gtk_widget_show (widget);
115
button = builder_get_toggle_button (self->pv->builder, "lock_logout_choice");
116
g_signal_connect (button, "toggled", G_CALLBACK (on_timeout_choices_toggled), self->pv->builder);
117
button = builder_get_toggle_button (self->pv->builder, "lock_after_choice");
118
g_signal_connect (button, "toggled", G_CALLBACK (on_timeout_choices_toggled), self->pv->builder);
135
button = builder_get_toggle_button (self->pv->builder, "lock_always_choice");
136
g_signal_connect (button, "toggled", G_CALLBACK (on_choice_toggled), self);
137
g_object_set_data (G_OBJECT (button), "unlock-choice", GCR_UNLOCK_OPTION_ALWAYS);
139
button = builder_get_toggle_button (self->pv->builder, "lock_session_choice");
140
g_signal_connect (button, "toggled", G_CALLBACK (on_choice_toggled), self);
141
g_object_set_data (G_OBJECT (button), "unlock-choice", GCR_UNLOCK_OPTION_SESSION);
142
on_choice_toggled (button, self);
144
button = builder_get_toggle_button (self->pv->builder, "lock_timeout_choice");
145
g_signal_connect (button, "toggled", G_CALLBACK (on_choice_toggled), self);
146
g_object_set_data (G_OBJECT (button), "unlock-choice", GCR_UNLOCK_OPTION_TIMEOUT);
119
148
button = builder_get_toggle_button (self->pv->builder, "lock_idle_choice");
120
g_signal_connect (button, "toggled", G_CALLBACK (on_timeout_choices_toggled), self->pv->builder);
121
on_timeout_choices_toggled (button, self->pv->builder);
149
g_signal_connect (button, "toggled", G_CALLBACK (on_choice_toggled), self);
150
g_object_set_data (G_OBJECT (button), "unlock-choice", GCR_UNLOCK_OPTION_IDLE);
158
189
GParamSpec *pspec)
160
191
GcrUnlockOptionsWidget *self = GCR_UNLOCK_OPTIONS_WIDGET (obj);
161
GtkToggleButton *button;
165
spin = builder_get_spin_button (self->pv->builder, "lock_minutes_spin");
167
193
switch (prop_id) {
168
case PROP_UNLOCK_TIMEOUT:
169
button = builder_get_toggle_button (self->pv->builder, "lock_after_choice");
170
seconds = g_value_get_int (value);
172
gtk_toggle_button_set_active (button, FALSE);
174
gtk_toggle_button_set_active (button, TRUE);
175
spin = builder_get_spin_button (self->pv->builder, "lock_minutes_spin");
176
gtk_spin_button_set_value (spin, seconds / 60);
195
gcr_unlock_options_widget_set_choice (self, g_value_get_string (value));
179
case PROP_UNLOCK_IDLE:
180
button = builder_get_toggle_button (self->pv->builder, "lock_idle_choice");
181
seconds = g_value_get_int (value);
183
gtk_toggle_button_set_active (button, FALSE);
185
gtk_toggle_button_set_active (button, TRUE);
186
spin = builder_get_spin_button (self->pv->builder, "lock_minutes_spin");
187
gtk_spin_button_set_value (spin, seconds / 60);
198
gcr_unlock_options_widget_set_ttl (self, g_value_get_uint (value));
191
201
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
198
208
GParamSpec *pspec)
200
210
GcrUnlockOptionsWidget *self = GCR_UNLOCK_OPTIONS_WIDGET (obj);
201
GtkToggleButton *button;
205
spin = builder_get_spin_button (self->pv->builder, "lock_minutes_spin");
206
minutes = gtk_spin_button_get_value_as_int (spin);
208
212
switch (prop_id) {
209
case PROP_UNLOCK_TIMEOUT:
210
button = builder_get_toggle_button (self->pv->builder, "lock_after_choice");
211
if (!gtk_toggle_button_get_active (button))
212
g_value_set_int (value, 0);
214
g_value_set_int (value, minutes * 60);
214
g_value_set_string (value, gcr_unlock_options_widget_get_choice (self));
216
case PROP_UNLOCK_IDLE:
217
button = builder_get_toggle_button (self->pv->builder, "lock_idle_choice");
218
if (!gtk_toggle_button_get_active (button))
219
g_value_set_int (value, 0);
221
g_value_set_int (value, minutes * 60);
217
g_value_set_uint (value, gcr_unlock_options_widget_get_ttl (self));
224
220
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
240
236
gobject_class->set_property = gcr_unlock_options_widget_set_property;
241
237
gobject_class->get_property = gcr_unlock_options_widget_get_property;
243
g_object_class_install_property (gobject_class, PROP_UNLOCK_TIMEOUT,
244
g_param_spec_int ("unlock-timeout", "Unlock Timeout", "Unlock Timeout",
245
0, G_MAXINT, 0, G_PARAM_READWRITE));
239
g_object_class_install_property (gobject_class, PROP_CHOICE,
240
g_param_spec_string ("choice", "Choice", "Unlock Option Choice",
241
NULL, G_PARAM_READWRITE));
247
g_object_class_install_property (gobject_class, PROP_UNLOCK_IDLE,
248
g_param_spec_int ("unlock-idle", "Unlock Idle", "Unlock Idle Timeout",
249
0, G_MAXINT, 0, G_PARAM_READWRITE));
243
g_object_class_install_property (gobject_class, PROP_TTL,
244
g_param_spec_uint ("ttl", "TTL", "Unlock Option Timeout in Seconds",
245
0, G_MAXUINT, 0, G_PARAM_READWRITE));
252
248
/* -----------------------------------------------------------------------------
263
gcr_unlock_options_widget_get_label (GcrUnlockOptionsWidget *self, guint option)
259
gcr_unlock_options_widget_get_choice (GcrUnlockOptionsWidget *self)
261
g_return_val_if_fail (GCR_IS_UNLOCK_OPTIONS_WIDGET (self), NULL);
262
return self->pv->choice;
266
gcr_unlock_options_widget_set_choice (GcrUnlockOptionsWidget *self, const gchar *option)
268
GtkToggleButton *button;
270
g_return_if_fail (GCR_IS_UNLOCK_OPTIONS_WIDGET (self));
271
g_return_if_fail (option);
273
button = widget_button_for_option (self, option);
274
gtk_toggle_button_set_active (button, TRUE);
278
gcr_unlock_options_widget_get_ttl (GcrUnlockOptionsWidget *self)
283
g_return_val_if_fail (GCR_IS_UNLOCK_OPTIONS_WIDGET (self), 0);
285
spin = builder_get_spin_button (self->pv->builder, "lock_minutes_spin");
286
amount = gtk_spin_button_get_value_as_int (spin);
291
gcr_unlock_options_widget_set_ttl (GcrUnlockOptionsWidget *self, guint ttl)
296
g_return_if_fail (GCR_IS_UNLOCK_OPTIONS_WIDGET (self));
299
if (!amount || ttl % 60)
302
spin = builder_get_spin_button (self->pv->builder, "lock_minutes_spin");
303
gtk_spin_button_set_value (spin, amount);
307
gcr_unlock_options_widget_get_label (GcrUnlockOptionsWidget *self, const gchar *option)
265
309
GtkToggleButton *button;
266
310
const gchar *name;
268
312
g_return_val_if_fail (GCR_IS_UNLOCK_OPTIONS_WIDGET (self), NULL);
313
g_return_val_if_fail (option, NULL);
270
315
name = widget_name_for_option (option);
271
316
g_return_val_if_fail (name, NULL);
280
gcr_unlock_options_widget_set_label (GcrUnlockOptionsWidget *self, guint option,
325
gcr_unlock_options_widget_set_label (GcrUnlockOptionsWidget *self, const gchar *option,
281
326
const gchar *text)
283
328
GtkToggleButton *button;
284
329
const gchar *name;
286
331
g_return_if_fail (GCR_IS_UNLOCK_OPTIONS_WIDGET (self));
332
g_return_if_fail (option);
287
333
g_return_if_fail (text);
289
335
name = widget_name_for_option (option);
295
341
gtk_button_set_label (GTK_BUTTON (button), text);
345
gcr_unlock_options_widget_get_sensitive (GcrUnlockOptionsWidget *self, const gchar *option)
347
GtkToggleButton *button;
350
g_return_val_if_fail (GCR_IS_UNLOCK_OPTIONS_WIDGET (self), FALSE);
351
g_return_val_if_fail (option, FALSE);
353
button = widget_button_for_option (self, option);
354
state = gtk_widget_get_state (GTK_WIDGET (button));
355
return (state & GTK_STATE_INSENSITIVE) != GTK_STATE_INSENSITIVE;
359
gcr_unlock_options_widget_set_sensitive (GcrUnlockOptionsWidget *self, const gchar *option,
360
gboolean sensitive, const gchar *reason)
362
GtkToggleButton *button;
364
g_return_if_fail (GCR_IS_UNLOCK_OPTIONS_WIDGET (self));
365
g_return_if_fail (option);
367
button = widget_button_for_option (self, option);
368
gtk_widget_set_sensitive (GTK_WIDGET (button), sensitive);
370
if (!sensitive && reason)
371
gtk_widget_set_tooltip_text (GTK_WIDGET (button), reason);
373
gtk_widget_set_has_tooltip (GTK_WIDGET (button), FALSE);