Skip to content
API Documentation
BastionGuard™
DeleteBox.vala
Go to the documentation of this file.
1/*
2 * DeleteBox.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
27#if XAPP
28using XApp;
29#endif
30
31using TeeJee.Logging;
36using TeeJee.System;
37using TeeJee.Misc;
38
39class DeleteBox : Gtk.Box{
40 private Gtk.Spinner spinner;
41 public Gtk.Label lbl_msg;
42 public Gtk.Label lbl_status;
43 public Gtk.Label lbl_remaining;
44 public Gtk.ProgressBar progressbar;
45
46 private Gtk.Window parent_window;
47
48 public DeleteBox (Gtk.Window _parent_window) {
49
50 log_debug("DeleteBox: DeleteBox()");
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 // header
61 add_label_header(this, _("Deleting Snapshots..."), true);
62
63 var hbox_status = new Gtk.Box(Orientation.HORIZONTAL, 6);
64 append(hbox_status);
65
66 spinner = new Gtk.Spinner();
67 spinner.start();
68 hbox_status.append(spinner);
69
70 //lbl_msg
71 lbl_msg = add_label(hbox_status, _("Preparing..."));
72 lbl_msg.hexpand = true;
73 lbl_msg.ellipsize = Pango.EllipsizeMode.END;
74 lbl_msg.max_width_chars = 45;
75
76 lbl_remaining = add_label(hbox_status, "");
77
78 //progressbar
79 progressbar = new Gtk.ProgressBar();
80 //progressbar.set_size_request(-1,25);
81 //progressbar.show_text = true;
82 //progressbar.pulse_step = 0.1;
83 append(progressbar);
84
85 //lbl_status
86 lbl_status = add_label(this, "");
87 lbl_status.ellipsize = Pango.EllipsizeMode.MIDDLE;
88 lbl_status.max_width_chars = 45;
89 lbl_status.margin_bottom = 12;
90
91 log_debug("DeleteBox: DeleteBox(): exit");
92 }
93
94 public bool delete_snapshots(){
95
96 log_debug("DeleteBox: delete_snapshots()");
97
100 }
101
102 if (App.btrfs_mode){
103
105
106 lbl_msg.label = App.progress_text;
108 sleep(200);
109
110 #if XAPP
111 XApp.set_window_progress_pulse(parent_window, true);
112 #endif
113 }
114
115 #if XAPP
116 XApp.set_window_progress_pulse(parent_window, false);
117 #endif
118 }
119 else{
120
121 int wait_interval_millis = 100;
122 int status_line_counter = 0;
123 int status_line_counter_default = 1000 / wait_interval_millis;
124 string status_line = "";
125 string last_status_line = "";
126 int remaining_counter = 10;
127
129
131
132 if (status_line != last_status_line){
133 lbl_status.label = status_line;
134 last_status_line = status_line;
135 status_line_counter = status_line_counter_default;
136 }
137 else{
138 status_line_counter--;
139 if (status_line_counter < 0){
140 status_line_counter = status_line_counter_default;
141 lbl_status.label = "";
142 }
143 }
144
145 double fraction = App.delete_file_task.progress;
146
147 // time remaining
148 remaining_counter--;
149
150 if (remaining_counter == 0){
151
152 lbl_remaining.label = App.delete_file_task.stat_time_remaining + " " + _("remaining");
153
154 remaining_counter = 10;
155 }
156
157 if (fraction < 0.99){
158 progressbar.fraction = fraction;
159
160 #if XAPP
161 XApp.set_window_progress(parent_window, (int)(fraction * 100.0));
162 #endif
163 }
164
165 lbl_msg.label = App.delete_file_task.status_message;
166
168
169 sleep(100);
170 }
171
172 #if XAPP
173 XApp.set_window_progress(parent_window, 0);
174 #endif
175 }
176
177 //parent_window.destroy();
178
180 }
181}
Main App
#define _(s)
double progress
string status_line
Gtk.Label lbl_remaining
DeleteBox(Gtk.Window _parent_window)
bool delete_snapshots()
Gtk.Label lbl_status
Gtk.Spinner spinner
Gtk.Window parent_window
Gtk.Label lbl_msg
Gtk.ProgressBar progressbar
string progress_text
Definition Main.vala:156
void delete_begin()
Definition Main.vala:1882
bool btrfs_mode
Definition Main.vala:52
DeleteFileTask delete_file_task
Definition Main.vala:161
bool thread_delete_success
Definition Main.vala:109
bool thread_delete_running
Definition Main.vala:108
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)
void sleep(int milliseconds)