Skip to content
API Documentation
BastionGuard™
ScheduleBox.vala
Go to the documentation of this file.
1/*
2 * ScheduleBox.vala
3 *
4 * Copyright 2012-2018 Tony George <teejeetech@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 * MA 02110-1301, USA.
20 *
21 *
22 */
23
24using Gtk;
25using Gee;
26
27using TeeJee.Logging;
32using TeeJee.System;
33using TeeJee.Misc;
34
35class ScheduleBox : Gtk.Box{
36
37 private Gtk.Image img_shield;
38 private Gtk.Label lbl_shield;
39 private Gtk.Label lbl_shield_subnote;
40 private Gtk.SizeGroup sg_title;
41 private Gtk.SizeGroup sg_subtitle;
42 private Gtk.SizeGroup sg_count;
43
44 private Gtk.CheckButton chk_cron;
45
46 private Gtk.Window parent_window;
47
48 public ScheduleBox (Gtk.Window _parent_window) {
49
50 log_debug("ScheduleBox: ScheduleBox()");
51
52 //base(Gtk.Orientation.VERTICAL, 6); // issue with vala
53 GLib.Object(orientation: Gtk.Orientation.VERTICAL, spacing: 6); // work-around
54 parent_window = _parent_window;
55 margin_top = 12;
56 margin_bottom = 12;
57 margin_start = 12;
58 margin_end = 12;
59
60 add_label_header(this, _("Select Snapshot Levels"), true);
61
62 Gtk.CheckButton chk_m, chk_w, chk_d, chk_h, chk_b = null;
63 Gtk.SpinButton spin_m, spin_w, spin_d, spin_h, spin_b;
64
65 // monthly
66
67 add_schedule_option(this, _("Monthly"), _("Create one per month"), out chk_m, out spin_m);
68
69 chk_m.active = App.schedule_monthly;
70 chk_m.toggled.connect(()=>{
71 App.schedule_monthly = chk_m.active;
72 //spin_m.sensitive = chk_m.active;
73 chk_cron.sensitive = App.scheduled;
75 });
76
77 spin_m.set_value(App.count_monthly);
78 //spin_m.sensitive = chk_m.active;
79 spin_m.value_changed.connect(()=>{
80 App.count_monthly = (int) spin_m.get_value();
81 });
82
83 // weekly
84
85 add_schedule_option(this, _("Weekly"), _("Create one per week"), out chk_w, out spin_w);
86
87 chk_w.active = App.schedule_weekly;
88 chk_w.toggled.connect(()=>{
89 App.schedule_weekly = chk_w.active;
90 //spin_w.sensitive = chk_w.active;
91 chk_cron.sensitive = App.scheduled;
93 });
94
95 spin_w.set_value(App.count_weekly);
96 //spin_w.sensitive = chk_w.active;
97 spin_w.value_changed.connect(()=>{
98 App.count_weekly = (int) spin_w.get_value();
99 });
100
101 // daily
102
103 add_schedule_option(this, _("Daily"), _("Create one per day"), out chk_d, out spin_d);
104
105 chk_d.active = App.schedule_daily;
106 chk_d.toggled.connect(()=>{
107 App.schedule_daily = chk_d.active;
108 //spin_d.sensitive = chk_d.active;
109 chk_cron.sensitive = App.scheduled;
111 });
112
113 spin_d.set_value(App.count_daily);
114 //spin_d.sensitive = chk_d.active;
115 spin_d.value_changed.connect(()=>{
116 App.count_daily = (int) spin_d.get_value();
117 });
118
119 // hourly
120
121 add_schedule_option(this, _("Hourly"), _("Create one per hour"), out chk_h, out spin_h);
122
123 chk_h.active = App.schedule_hourly;
124 chk_h.toggled.connect(()=>{
125 App.schedule_hourly = chk_h.active;
126 //spin_h.sensitive = chk_h.active;
127 chk_cron.sensitive = App.scheduled;
129 });
130
131 spin_h.set_value(App.count_hourly);
132 //spin_h.sensitive = chk_h.active;
133 spin_h.value_changed.connect(()=>{
134 App.count_hourly = (int) spin_h.get_value();
135 });
136
137 // boot
138
139 add_schedule_option(this, _("Boot"), _("Create one per boot"), out chk_b, out spin_b);
140
141 chk_b.active = App.schedule_boot;
142 chk_b.toggled.connect(()=>{
143 App.schedule_boot = chk_b.active;
144 //spin_b.sensitive = chk_b.active;
145 chk_cron.sensitive = App.scheduled;
147 });
148
149 spin_b.set_value(App.count_boot);
150 //spin_b.sensitive = chk_b.active;
151 spin_b.value_changed.connect(()=>{
152 App.count_boot = (int) spin_b.get_value();
153 });
154
155 // cron emails --------------------------------------------------------------------
156
157 chk_cron = add_checkbox(this, _("Stop cron emails for scheduled tasks"));
158 //chk_cron.hexpand = true;
159 chk_cron.set_tooltip_text(_("The cron service sends the output of scheduled tasks as an email to the current user. Select this option to suppress the emails for cron tasks created by BastionGuard Backup."));
160
161 chk_cron.margin_start = 6;
162
163 chk_cron.margin_end = 6;
164
165 chk_cron.margin_top = 6;
166
167 chk_cron.margin_bottom = 6;
168 chk_cron.margin_top = 12;
169
170 chk_cron.active = App.stop_cron_emails;
171 chk_cron.toggled.connect(()=>{
172 App.stop_cron_emails = chk_cron.active;
173 });
174
175 var msg = "<i>• %s\n• %s\n• %s</i>".printf(
176 _("Snapshots are not scheduled at fixed times."),
177 _("A maintenance task runs once every hour and creates snapshots as needed."),
178 _("Boot snapshots are created with a delay of 10 minutes after system startup."));
179
180 // buffer
181 var label = new Gtk.Label("");
182 label.vexpand = true;
183 append(label);
184
185 // message area -------------------------------------------------------------------
186
187 var scrolled = new Gtk.ScrolledWindow();
188 scrolled.hscrollbar_policy = Gtk.PolicyType.NEVER;
189 scrolled.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC;
190 scrolled.set_size_request(-1, 100);
191 scrolled.margin_top = 6;
192 scrolled.margin_bottom = 6;
193 this.append(scrolled);
194
195 label = new Gtk.Label(msg);
196 label.set_use_markup(true);
197 label.xalign = 0.0f;
198 label.wrap = true;
199 label.wrap_mode = Pango.WrapMode.WORD;
200 label.margin_start = 6;
201 label.margin_end = 6;
202 label.margin_top = 6;
203 label.margin_bottom = 6;
204 scrolled.set_child(label);
205
206 // status area --------------------------------------------------------------------
207
208 scrolled = new Gtk.ScrolledWindow();
209 scrolled.hscrollbar_policy = Gtk.PolicyType.NEVER;
210 scrolled.vscrollbar_policy = Gtk.PolicyType.NEVER;
211 scrolled.set_size_request(-1, 100);
212 append(scrolled);
213
214 // hbox
215 var hbox = new Gtk.Box(Orientation.HORIZONTAL, 6);
216 hbox.margin_start = 6;
217 hbox.margin_end = 6;
218 hbox.margin_top = 6;
219 hbox.margin_bottom = 6;
220 hbox.margin_bottom = 12;
221 scrolled.set_child(hbox);
222
223 // img_shield
224 img_shield = new Gtk.Image();
226 img_shield.margin_bottom = 6;
227 hbox.append(img_shield);
228
229 var vbox = new Gtk.Box(Orientation.VERTICAL, 6);
230 vbox.margin_top = 6;
231 hbox.append(vbox);
232
233 // lbl_shield
234 lbl_shield = add_label(vbox, "");
235 lbl_shield.yalign = 0.5f;
236 //lbl_shield.hexpand = true;
237
238 // lbl_shield_subnote
239 lbl_shield_subnote = add_label(vbox, "");
240 lbl_shield_subnote.yalign = 0.5f;
241 //lbl_shield_subnote.hexpand = true;
242
243 lbl_shield_subnote.wrap = true;
244 lbl_shield_subnote.wrap_mode = Pango.WrapMode.WORD;
245
247
248 log_debug("ScheduleBox: ScheduleBox(): exit");
249 }
250
251 private void set_shield_label(
252 string text, bool is_bold = true, bool is_italic = false, bool is_large = true){
253
254 string msg = "<span%s%s%s>%s</span>".printf(
255 (is_bold ? " weight=\"bold\"" : ""),
256 (is_italic ? " style=\"italic\"" : ""),
257 (is_large ? " size=\"x-large\"" : ""),
258 escape_html(text));
259
260 lbl_shield.label = msg;
261 }
262
263 private void set_shield_subnote(
264 string text, bool is_bold = false, bool is_italic = true, bool is_large = false){
265
266 string msg = "<span%s%s%s>%s</span>".printf(
267 (is_bold ? " weight=\"bold\"" : ""),
268 (is_italic ? " style=\"italic\"" : ""),
269 (is_large ? " size=\"x-large\"" : ""),
270 escape_html(text));
271
272 lbl_shield_subnote.label = msg;
273 }
274
276 Gtk.Box box, string period, string period_desc,
277 out Gtk.CheckButton chk, out Gtk.SpinButton spin){
278
279 var hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 6);
280 hbox.margin_start = 6;
281 hbox.margin_end = 6;
282 hbox.margin_top = 6;
283 hbox.margin_bottom = 6;
284 hbox.margin_top = 1;
285 hbox.margin_bottom = 1;
286 box.append(hbox);
287
288 if (sg_title == null){
289 sg_title = new Gtk.SizeGroup(Gtk.SizeGroupMode.HORIZONTAL);
290 sg_subtitle = new Gtk.SizeGroup(Gtk.SizeGroupMode.HORIZONTAL);
291 sg_count = new Gtk.SizeGroup(Gtk.SizeGroupMode.HORIZONTAL);
292 }
293
294 var txt = "<b>%s</b>".printf(period);
295 chk = add_checkbox(hbox, txt);
296 sg_title.add_widget(chk);
297
298 var tt = _("Number of snapshots to keep.\nOlder snapshots will be removed once this limit is exceeded.");
299 var label = add_label(hbox, " " + _("Keep"));
300 label.set_tooltip_text(tt);
301
302 var spin2 = add_spin(hbox, 1, 999, 10);
303 spin2.set_tooltip_text(tt);
304 sg_count.add_widget(spin2);
305
306 spin2.notify["sensitive"].connect(()=>{
307 label.sensitive = spin2.sensitive;
308 });
309
310 spin = spin2;
311 }
312
313 public void update_statusbar(){
314
317
320
321 set_shield_label(_("Scheduled snapshots are enabled"));
322 set_shield_subnote(_("Snapshots will be created at selected intervals if snapshot disk has enough space (> 1 GB)"));
323 }
324 else{
327
328 set_shield_label(_("Scheduled snapshots are disabled"));
329 set_shield_subnote(_("Select the intervals for creating snapshots"));
330 }
331
332 chk_cron.sensitive = App.scheduled;
333 }
334}
Main App
#define _(s)
static Gdk.? Pixbuf lookup(string icon_name, int icon_size, bool symbolic=false, bool use_hardcoded=false, int scale=1)
const string SHIELD_LOW
const string SHIELD_HIGH
const int SHIELD_ICON_SIZE
bool schedule_hourly
Definition Main.vala:90
bool schedule_boot
Definition Main.vala:91
bool stop_cron_emails
Definition Main.vala:57
bool schedule_monthly
Definition Main.vala:87
int count_monthly
Definition Main.vala:92
int count_hourly
Definition Main.vala:95
bool scheduled
Definition Main.vala:1050
bool schedule_weekly
Definition Main.vala:88
bool schedule_daily
Definition Main.vala:89
int count_boot
Definition Main.vala:96
int count_weekly
Definition Main.vala:93
int count_daily
Definition Main.vala:94
Gtk.Label lbl_shield_subnote
Gtk.Window parent_window
void add_schedule_option(Gtk.Box box, string period, string period_desc, out Gtk.CheckButton chk, out Gtk.SpinButton spin)
void set_shield_subnote(string text, bool is_bold=false, bool is_italic=true, bool is_large=false)
Gtk.Label lbl_shield
Gtk.SizeGroup sg_count
ScheduleBox(Gtk.Window _parent_window)
void update_statusbar()
Gtk.SizeGroup sg_title
Gtk.SizeGroup sg_subtitle
Gtk.CheckButton chk_cron
Gtk.Image img_shield
void set_shield_label(string text, bool is_bold=true, bool is_italic=false, bool is_large=true)
Gtk.Label add_label(Gtk.Box box, string text, bool bold=false, bool italic=false, bool large=false)
void log_debug(string message)
string escape_html(string html)