~ubuntu-branches/ubuntu/trusty/activity-log-manager/trusty-updates

« back to all changes in this revision

Viewing changes to .pc/14_seconds_combo.patch/src/security-widget.vala

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-03-25 12:56:33 UTC
  • Revision ID: package-import@ubuntu.com-20140325125633-epl6k2b3y7q52f0x
Tags: 0.9.7-0ubuntu12
* debian/patches/10_build-with-gee-0.8.patch: Port to gee 0.8 API to avoid
  loading two gee versions in the same process (LP: #1293036)
* 01_really_hide_automatic_reports.patch: Delete, this is obsolete given
  03_use_libwhoopsie-preferences.patch. Add 13_hide_automatic_reports.patch
  to achieve this with that new patch. (LP: #1203042)
* 11_make_all_widgets_sensitive.patch: Recursively make all widgets
  sensitive/insensitive when we need to, to avoid missing some.
* 12_hide_lock_unlock_button.patch: Hide Lock button when it doesn't do
  anything (when the user can't drop the permissions). (LP: #1239752)
* 14_seconds_combo.patch: Make the entries translatable. (LP: #1235627)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: vala; tab-width: 4; intend-tabs-mode: t -*- */
 
2
/* alm
 
3
 *
 
4
 * Copyright (C) 2013 Jeremy Bicha <jbicha@ubuntu.com>
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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/>.
 
18
 */
 
19
 
 
20
using Gtk;
 
21
 
 
22
namespace Alm {
 
23
 
 
24
        public class SecurityWidget : Gtk.Box {
 
25
 
 
26
                private GLib.Settings power_settings;
 
27
                private GLib.Settings screensaver_settings;
 
28
 
 
29
                public SecurityWidget () {
 
30
                        Object (orientation: Orientation.VERTICAL);
 
31
                        this.spacing = 5;
 
32
                        this.set_border_width(12);
 
33
 
 
34
                        power_settings = new GLib.Settings ("org.gnome.settings-daemon.plugins.power");
 
35
                        screensaver_settings = new GLib.Settings ("org.gnome.desktop.screensaver");
 
36
 
 
37
                        this.set_up_ui ();
 
38
                }
 
39
 
 
40
                private void set_up_ui () {
 
41
 
 
42
                        var liststore_delay = new ListStore (2, typeof (string), typeof (int));
 
43
                        TreeIter iter;
 
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);
 
62
 
 
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);
 
69
                        this.add(grid);
 
70
 
 
71
                        var list_focus = new GLib.List<Widget> ();
 
72
 
 
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);
 
76
 
 
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);
 
81
 
 
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);
 
86
 
 
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);
 
91
 
 
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");
 
101
                        });
 
102
                        combo_delay.sensitive = screensaver_settings.get_boolean("lock-enabled");
 
103
                        screensaver_settings.changed["lock-delay"].connect (() => {
 
104
                                get_delay_cb(combo_delay);
 
105
                        });
 
106
                        get_delay_cb(combo_delay);
 
107
                        grid.attach(combo_delay, 1, 3, 1, 1);
 
108
 
 
109
                        var link_password = new Gtk.LinkButton (_("Password Settings"));
 
110
                        link_password.activate_link.connect (() => {
 
111
                                try {
 
112
                                        Process.spawn_command_line_async ("gnome-control-center user-accounts");
 
113
                                } catch (SpawnError e) {
 
114
                                        warning ("%s", e.message);
 
115
                                }
 
116
                                return true;
 
117
                        });
 
118
                        link_password.set_halign(Align.START);
 
119
                        list_focus.append(link_password);
 
120
                        grid.attach(link_password, 2, 0, 1, 1);
 
121
 
 
122
                        var link_power = new Gtk.LinkButton(_("Power Settings"));
 
123
                        link_power.activate_link.connect (() => {
 
124
                                try {
 
125
                                        Process.spawn_command_line_async ("gnome-control-center power");
 
126
                                } catch (SpawnError e) {
 
127
                                        warning ("%s", e.message);
 
128
                                }
 
129
                                return true;
 
130
                        });
 
131
                        link_power.set_halign(Align.START);
 
132
                        list_focus.append(link_power);
 
133
                        grid.attach(link_power, 2, 1, 1, 1);
 
134
 
 
135
                        grid.set_focus_chain(list_focus);
 
136
 
 
137
                }
 
138
 
 
139
                private void set_delay_cb (Gtk.ComboBox combo)
 
140
                {
 
141
                        uint seconds;
 
142
                        TreeIter iter;
 
143
                        combo.get_active_iter(out iter);
 
144
                        combo.model.get(iter, 1, out seconds);
 
145
                        screensaver_settings.set_uint("lock-delay", seconds);
 
146
                }
 
147
 
 
148
                private void get_delay_cb (Gtk.ComboBox combo)
 
149
                {
 
150
                        /* try to make the UI match the lock setting */
 
151
                        int i = 0;
 
152
                        int value_prev = 0;
 
153
                        int value_tmp = 0;
 
154
                        TreeModel model = combo.get_model();
 
155
                        TreeIter iter;
 
156
                        model.get_iter_first(out iter);
 
157
                        var value = screensaver_settings.get_uint("lock-delay");
 
158
                        do {
 
159
                                model.get(iter, 1, out value_tmp);
 
160
                                if (value == value_tmp ||
 
161
                                        (value_tmp > value_prev && value < value_tmp))
 
162
                                {
 
163
                                        combo.set_active_iter(iter);
 
164
                                        return;
 
165
                                }
 
166
                                value_prev = value_tmp;
 
167
                                i++;
 
168
                        } while (model.iter_next(ref iter));
 
169
                        combo.set_active(i - 1);
 
170
                }
 
171
 
 
172
        }
 
173
}