/
HouseKeepingPanel.vala
178 lines (151 loc) · 6.86 KB
/
HouseKeepingPanel.vala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
* Copyright (c) 2018 elementary, Inc. (https://elementary.io)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
public class SecurityPrivacy.HouseKeepingPanel : Switchboard.SettingsPage {
private Granite.HeaderLabel spin_header_label;
private Gtk.Label file_age_label;
private Gtk.SpinButton file_age_spinbutton;
private Gtk.CheckButton download_files_check;
private Gtk.CheckButton screenshot_files_check;
private Gtk.CheckButton temp_files_check;
private Gtk.CheckButton trash_files_check;
public HouseKeepingPanel () {
Object (
icon: new ThemedIcon ("preferences-system-privacy-housekeeping"),
title: _("Housekeeping")
);
}
construct {
var switch_header_label = new Granite.HeaderLabel (_("Automatically Delete:"));
temp_files_check = new Gtk.CheckButton () {
halign = Gtk.Align.START,
margin_start = 12
};
var temp_files_grid = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
temp_files_grid.append (new Gtk.Image.from_icon_name ("folder") {
margin_end = 6,
pixel_size = 24
});
temp_files_grid.append (new Gtk.Label (_("Old temporary files")));
temp_files_grid.set_parent (temp_files_check);
download_files_check = new Gtk.CheckButton () {
halign = Gtk.Align.START,
margin_start = 12
};
var download_files_box = new Gtk.Box (HORIZONTAL, 0);
download_files_box.append (new Gtk.Image.from_icon_name ("folder-download") {
margin_end = 6,
pixel_size = 24
});
download_files_box.append (new Gtk.Label (_("Downloaded files")));
download_files_box.set_parent (download_files_check);
var screenshot_files_grid = new Gtk.Box (HORIZONTAL, 0);
screenshot_files_grid.append (new Gtk.Image.from_icon_name ("folder-screenshots-icon") {
margin_end = 6,
pixel_size = 24
});
screenshot_files_grid.append (new Gtk.Label (_("Screenshot files")));
screenshot_files_check = new Gtk.CheckButton () {
halign = Gtk.Align.START,
margin_start = 12
};
screenshot_files_grid.set_parent (screenshot_files_check);
trash_files_check = new Gtk.CheckButton () {
halign = Gtk.Align.START,
margin_start = 12,
margin_bottom = 18
};
var trash_files_grid = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
trash_files_grid.append (new Gtk.Image.from_icon_name ("user-trash-full") {
margin_end = 6,
pixel_size = 24
});
trash_files_grid.append (new Gtk.Label (_("Trashed files")));
trash_files_grid.set_parent (trash_files_check);
spin_header_label = new Granite.HeaderLabel (_("Delete Old Files After:"));
file_age_spinbutton = new Gtk.SpinButton.with_range (0, 90, 5);
file_age_spinbutton.margin_start = 12;
file_age_spinbutton.max_width_chars = 2;
file_age_spinbutton.xalign = 1;
file_age_label = new Gtk.Label (null);
file_age_label.halign = Gtk.Align.START;
file_age_label.hexpand = true;
var grid = new Gtk.Grid () {
column_spacing = 6,
row_spacing = 6
};
grid.attach (switch_header_label, 0, 0, 2);
grid.attach (download_files_check, 0, 1, 2);
grid.attach (temp_files_check, 0, 2, 2);
grid.attach (screenshot_files_check, 0, 3, 2);
grid.attach (trash_files_check, 0, 4, 2);
grid.attach (spin_header_label, 0, 5, 2);
grid.attach (file_age_spinbutton, 0, 6);
grid.attach (file_age_label, 1, 6);
child = grid;
show_end_title_buttons = true;
var view_trash_button = add_button (_("Open Trash…"));
var housekeeping_settings = new Settings ("io.elementary.settings-daemon.housekeeping");
housekeeping_settings.bind ("cleanup-downloads-folder", download_files_check, "active", DEFAULT);
housekeeping_settings.bind ("cleanup-screenshots-folder", screenshot_files_check, "active", DEFAULT);
housekeeping_settings.bind ("cleanup-temp-folder", temp_files_check, "active", DEFAULT);
housekeeping_settings.bind ("cleanup-trash-folder", trash_files_check, "active", DEFAULT);
housekeeping_settings.bind ("old-files-age", file_age_spinbutton, "value", DEFAULT);
housekeeping_settings.changed.connect (update_status);
update_days ((uint) file_age_spinbutton.value);
file_age_spinbutton.value_changed.connect (() => {
update_days ((uint) file_age_spinbutton.value);
});
view_trash_button.clicked.connect (() => {
try {
AppInfo.launch_default_for_uri ("trash:///", null);
} catch (Error e) {
warning ("Failed to open trash: %s", e.message);
}
});
update_status ();
}
private void update_days (uint age) {
description = dngettext (Build.GETTEXT_PACKAGE,
"Old files can be automatically deleted after %u day to save space and help protect your privacy.",
"Old files can be automatically deleted after %u days to save space and help protect your privacy.",
age
).printf (age);
file_age_label.label = dngettext (Build.GETTEXT_PACKAGE,
"Day",
"Days",
age
);
}
private void update_status () {
var all_active = temp_files_check.active && trash_files_check.active && download_files_check.active && screenshot_files_check.active;
var any_active = temp_files_check.active || trash_files_check.active || download_files_check.active || screenshot_files_check.active;
if (all_active) {
status_type = SUCCESS;
status = _("Enabled");
} else if (any_active) {
status_type = WARNING;
status = _("Partially Enabled");
} else {
status_type = OFFLINE;
status = _("Disabled");
}
file_age_label.sensitive = any_active;
file_age_spinbutton.sensitive = any_active;
spin_header_label.sensitive = any_active;
}
}