1
/* -*- Mode: vala; tab-width: 4; intend-tabs-mode: t -*- */
4
* Copyright (C) 2013 Jeremy Bicha <jbicha@ubuntu.com>
6
* alm is free software: you can redistribute it and/or modify it
7
* under the terms of the GNU Lesser General Public License as published
8
* by the Free Software Foundation, either version 2 of the License, or
9
* (at your option) any later version.
11
* alm is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
* See the GNU Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24
public class SecurityWidget : Gtk.Box {
26
private GLib.Settings power_settings;
27
private GLib.Settings screensaver_settings;
29
public SecurityWidget () {
30
Object (orientation: Orientation.VERTICAL);
32
this.set_border_width(12);
34
power_settings = new GLib.Settings ("org.gnome.settings-daemon.plugins.power");
35
screensaver_settings = new GLib.Settings ("org.gnome.desktop.screensaver");
40
private void set_up_ui () {
42
var liststore_delay = new ListStore (2, typeof (string), typeof (int));
44
liststore_delay.append (out iter);
45
liststore_delay.set (iter, 0, "1 second", 1, 0);
46
liststore_delay.append (out iter);
47
liststore_delay.set (iter, 0, "30 seconds", 1, 30);
48
liststore_delay.append (out iter);
49
liststore_delay.set (iter, 0, "1 minute", 1, 60);
50
liststore_delay.append (out iter);
51
liststore_delay.set (iter, 0, "2 minutes", 1, 120);
52
liststore_delay.append (out iter);
53
liststore_delay.set (iter, 0, "3 minutes", 1, 180);
54
liststore_delay.append (out iter);
55
liststore_delay.set (iter, 0, "5 minutes", 1, 300);
56
liststore_delay.append (out iter);
57
liststore_delay.set (iter, 0, "10 minutes", 1, 600);
58
liststore_delay.append (out iter);
59
liststore_delay.set (iter, 0, "30 minutes", 1, 1800);
60
liststore_delay.append (out iter);
61
liststore_delay.set (iter, 0, "1 hour", 1, 3600);
63
var grid = new Grid();
64
grid.set_halign(Align.START);
65
grid.set_valign(Align.START);
66
grid.set_column_spacing(25);
67
grid.set_row_spacing(5);
68
grid.set_row_homogeneous(true);
71
var list_focus = new GLib.List<Widget> ();
73
var header = new Label("");
74
header.set_markup("<b>%s</b>".printf(_("Require my password when:")));
75
grid.attach(header, 0, 0, 1, 1);
77
var checkbox_suspend = new CheckButton.with_mnemonic (_("_Waking from suspend"));
78
screensaver_settings.bind ("ubuntu-lock-on-suspend", checkbox_suspend, "active", SettingsBindFlags.DEFAULT);
79
list_focus.append(checkbox_suspend);
80
grid.attach(checkbox_suspend, 0, 1, 1, 1);
82
var checkbox_screensaver = new CheckButton.with_mnemonic (_("_Returning from blank screen"));
83
screensaver_settings.bind ("lock-enabled", checkbox_screensaver, "active", SettingsBindFlags.DEFAULT);
84
list_focus.append(checkbox_screensaver);
85
grid.attach(checkbox_screensaver, 0, 2, 1, 1);
87
var label_combo_delay = new Label(null);
88
label_combo_delay.set_markup_with_mnemonic(_("_if screen has been blank for"));
89
label_combo_delay.set_margin_left(18);
90
grid.attach(label_combo_delay, 0, 3, 1, 1);
92
var combo_delay = new ComboBox.with_model(liststore_delay);
93
combo_delay.changed.connect(set_delay_cb);
94
label_combo_delay.set_mnemonic_widget(combo_delay);
95
var cell = new CellRendererText();
96
combo_delay.pack_start(cell, false);
97
combo_delay.add_attribute(cell, "text", 0);
98
list_focus.append(combo_delay);
99
screensaver_settings.changed["lock-enabled"].connect (() => {
100
combo_delay.sensitive = screensaver_settings.get_boolean("lock-enabled");
102
combo_delay.sensitive = screensaver_settings.get_boolean("lock-enabled");
103
screensaver_settings.changed["lock-delay"].connect (() => {
104
get_delay_cb(combo_delay);
106
get_delay_cb(combo_delay);
107
grid.attach(combo_delay, 1, 3, 1, 1);
109
var link_password = new Gtk.LinkButton (_("Password Settings"));
110
link_password.activate_link.connect (() => {
112
Process.spawn_command_line_async ("gnome-control-center user-accounts");
113
} catch (SpawnError e) {
114
warning ("%s", e.message);
118
link_password.set_halign(Align.START);
119
list_focus.append(link_password);
120
grid.attach(link_password, 2, 0, 1, 1);
122
var link_power = new Gtk.LinkButton(_("Power Settings"));
123
link_power.activate_link.connect (() => {
125
Process.spawn_command_line_async ("gnome-control-center power");
126
} catch (SpawnError e) {
127
warning ("%s", e.message);
131
link_power.set_halign(Align.START);
132
list_focus.append(link_power);
133
grid.attach(link_power, 2, 1, 1, 1);
135
grid.set_focus_chain(list_focus);
139
private void set_delay_cb (Gtk.ComboBox combo)
143
combo.get_active_iter(out iter);
144
combo.model.get(iter, 1, out seconds);
145
screensaver_settings.set_uint("lock-delay", seconds);
148
private void get_delay_cb (Gtk.ComboBox combo)
150
/* try to make the UI match the lock setting */
154
TreeModel model = combo.get_model();
156
model.get_iter_first(out iter);
157
var value = screensaver_settings.get_uint("lock-delay");
159
model.get(iter, 1, out value_tmp);
160
if (value == value_tmp ||
161
(value_tmp > value_prev && value < value_tmp))
163
combo.set_active_iter(iter);
166
value_prev = value_tmp;
168
} while (model.iter_next(ref iter));
169
combo.set_active(i - 1);