Skip to content
API Documentation
BastionGuard™
RestoreBox Class Reference
Inheritance diagram for RestoreBox:

Public Member Functions

 RestoreBox (Gtk.Window _parent_window)
bool restore ()

Public Attributes

Gtk.Label lbl_header
Gtk.Label lbl_msg
Gtk.Label lbl_status
Gtk.Label lbl_remaining
Gtk.ProgressBar progressbar
Gtk.Label lbl_unchanged
Gtk.Label lbl_created
Gtk.Label lbl_deleted
Gtk.Label lbl_modified
Gtk.Label lbl_checksum
Gtk.Label lbl_size
Gtk.Label lbl_timestamp
Gtk.Label lbl_permissions
Gtk.Label lbl_owner
Gtk.Label lbl_group

Private Member Functions

Gtk.Label add_count_label (Gtk.Box box, string text, ref Gtk.SizeGroup? sg_label, ref Gtk.SizeGroup? sg_value, int add_margin_bottom=0)
void restore_thread ()

Private Attributes

Gtk.Spinner spinner
Gtk.Window parent_window
bool thread_is_running = false

Detailed Description

Definition at line 39 of file RestoreBox.vala.

Constructor & Destructor Documentation

◆ RestoreBox()

RestoreBox.RestoreBox ( Gtk.Window _parent_window)
inline

Definition at line 63 of file RestoreBox.vala.

63 {
64
65 log_debug("RestoreBox: RestoreBox()");
66
67 //base(Gtk.Orientation.VERTICAL, 6); // issue with vala
68 GLib.Object(orientation: Gtk.Orientation.VERTICAL, spacing: 6); // work-around
69 parent_window = _parent_window;
70 margin_top = 12;
71 margin_bottom = 12;
72 margin_start = 12;
73 margin_end = 12;
74
75 // header
76 if (App.dry_run){
77 lbl_header = add_label_header(this, _("Comparing Files (Dry Run)..."), true);
78 }
79 else{
80 lbl_header = add_label_header(this, _("Restoring Snapshot..."), true);
81 }
82
83 var hbox_status = new Gtk.Box(Orientation.HORIZONTAL, 6);
84 append(hbox_status);
85
86 spinner = new Gtk.Spinner();
87 spinner.start();
88 hbox_status.append(spinner);
89
90 //lbl_msg
91 lbl_msg = add_label(hbox_status, _("Preparing..."));
92 lbl_msg.hexpand = true;
93 lbl_msg.ellipsize = Pango.EllipsizeMode.END;
94 lbl_msg.max_width_chars = 50;
95
96 lbl_remaining = add_label(hbox_status, "");
97
98 //progressbar
99 progressbar = new Gtk.ProgressBar();
100 //progressbar.set_size_request(-1,25);
101 //progressbar.show_text = true;
102 //progressbar.pulse_step = 0.1;
103 append(progressbar);
104
105 //lbl_status
106
107 lbl_status = add_label(this, "");
108 lbl_status.ellipsize = Pango.EllipsizeMode.MIDDLE;
109 lbl_status.max_width_chars = 45;
110 lbl_status.margin_bottom = 12;
111
112 // TODO: Add move to background button
113
114 var label = add_label(this, "");
115 label.vexpand = true;
116
117 // add count labels ---------------------------------
118
119 Gtk.SizeGroup sg_label = null;
120 Gtk.SizeGroup sg_value = null;
121
122 label = add_label(this, _("Files and directory counts:"), true);
123 label.margin_bottom = 6;
124
125 lbl_unchanged = add_count_label(this, _("No Change"), ref sg_label, ref sg_value);
126 lbl_created = add_count_label(this, _("Created"), ref sg_label, ref sg_value);
127 lbl_deleted = add_count_label(this, _("Deleted"), ref sg_label, ref sg_value);
128 lbl_modified = add_count_label(this, _("Changed"), ref sg_label, ref sg_value, 12);
129
130 label = add_label(this, _("Changed items:"), true);
131 label.margin_bottom = 6;
132
133 lbl_checksum = add_count_label(this, _("Checksum"), ref sg_label, ref sg_value);
134 lbl_size = add_count_label(this, _("Size"), ref sg_label, ref sg_value);
135 lbl_timestamp = add_count_label(this, _("Timestamp"), ref sg_label, ref sg_value);
136 lbl_permissions = add_count_label(this, _("Permissions"), ref sg_label, ref sg_value);
137 lbl_owner = add_count_label(this, _("Owner"), ref sg_label, ref sg_value);
138 lbl_group = add_count_label(this, _("Group"), ref sg_label, ref sg_value, 24);
139
140 log_debug("RestoreBox: RestoreBox(): exit");
141 }
Main App
#define _(s)
bool dry_run
Definition Main.vala:100
Gtk.Label lbl_group
Gtk.Label lbl_permissions
Gtk.Label lbl_size
Gtk.ProgressBar progressbar
Gtk.Label lbl_remaining
Gtk.Label lbl_checksum
Gtk.Label lbl_timestamp
Gtk.Label lbl_msg
Gtk.Label lbl_header
Gtk.Label lbl_status
Gtk.Label add_count_label(Gtk.Box box, string text, ref Gtk.SizeGroup? sg_label, ref Gtk.SizeGroup? sg_value, int add_margin_bottom=0)
Gtk.Label lbl_created
Gtk.Label lbl_deleted
Gtk.Spinner spinner
Gtk.Label lbl_unchanged
Gtk.Window parent_window
Gtk.Label lbl_modified
Gtk.Label lbl_owner
Gtk.Label add_label(Gtk.Box box, string text, bool bold=false, bool italic=false, bool large=false)
void log_debug(string message)

References _, add_count_label(), TeeJee.GtkHelper.add_label(), App, Main.dry_run, lbl_checksum, lbl_created, lbl_deleted, lbl_group, lbl_header, lbl_modified, lbl_msg, lbl_owner, lbl_permissions, lbl_remaining, lbl_size, lbl_status, lbl_timestamp, lbl_unchanged, TeeJee.Logging.log_debug(), parent_window, progressbar, and spinner.

Referenced by RestoreWindow.build_pages().

Member Function Documentation

◆ add_count_label()

Gtk.Label RestoreBox.add_count_label ( Gtk.Box box,
string text,
ref Gtk.SizeGroup? sg_label,
ref Gtk.SizeGroup? sg_value,
int add_margin_bottom = 0 )
inlineprivate

Definition at line 143 of file RestoreBox.vala.

145 {
146
147 var hbox = new Gtk.Box(Orientation.HORIZONTAL, 6);
148 box.append(hbox);
149
150 var label = add_label(hbox, text + ":");
151 label.xalign = (float) 1.0;
152 label.margin_start = 12;
153 label.margin_end = 6;
154
155 if (add_margin_bottom > 0){
156 label.margin_bottom = add_margin_bottom;
157 }
158
159 // add to size group
160 if (sg_label == null){
161 sg_label = new Gtk.SizeGroup(SizeGroupMode.HORIZONTAL);
162 }
163 sg_label.add_widget(label);
164
165 label = add_label(hbox, "");
166 label.xalign = (float) 0.0;
167
168 if (add_margin_bottom > 0){
169 label.margin_bottom = add_margin_bottom;
170 }
171
172 // add to size group
173 if (sg_value == null){
174 sg_value = new Gtk.SizeGroup(SizeGroupMode.HORIZONTAL);
175 }
176 sg_value.add_widget(label);
177
178 return label;
179 }

References TeeJee.GtkHelper.add_label().

Referenced by RestoreBox().

◆ restore()

bool RestoreBox.restore ( )
inline

Definition at line 181 of file RestoreBox.vala.

181 {
182
183 log_debug("RestoreBox: restore()");
184
186 parent_window.hide();
187 }
188
189 if (App.dry_run){
190 lbl_header.label = format_text(_("Comparing Files (Dry Run)..."), true, false, true);
191 }
192 else{
193 lbl_header.label = format_text(_("Restoring Snapshot..."), true, false, true);
194 }
195
196 try {
197 thread_is_running = true;
198 new Thread<void>.try ("restore", () => {restore_thread();});
199 }
200 catch (Error e) {
201 log_error (e.message);
202 }
203
204 //string last_message = "";
205 int wait_interval_millis = 100;
206 int status_line_counter = 0;
207 int status_line_counter_default = 1000 / wait_interval_millis;
208 string status_line = "";
209 string last_status_line = "";
210 int remaining_counter = 10;
211
212 while (thread_is_running){
213
214 status_line = escape_html(App.task.status_line);
215
216 if (status_line != last_status_line){
217
218 lbl_status.label = status_line;
219 last_status_line = status_line;
220 status_line_counter = status_line_counter_default;
221 }
222 else{
223 status_line_counter--;
224
225 if (status_line_counter < 0){
226 status_line_counter = status_line_counter_default;
227 lbl_status.label = "";
228 }
229 }
230
231 // TODO: show estimated time remaining and file counts
232
233 double fraction = App.task.progress;
234
235 // time remaining
236 remaining_counter--;
237
238 if (remaining_counter == 0){
239
240 lbl_remaining.label = App.task.stat_time_remaining + " " + _("remaining");
241
242 remaining_counter = 10;
243 }
244
245 if (fraction < 0.99){
246
247 progressbar.fraction = fraction;
248
249 #if XAPP
250 XApp.set_window_progress(parent_window, (int)(fraction * 100.0));
251 #endif
252 }
253
254 lbl_msg.label = App.progress_text;
255
256 lbl_unchanged.label = "%'d".printf(App.task.count_unchanged);
257 lbl_created.label = "%'d".printf(App.task.count_created);
258 lbl_deleted.label = "%'d".printf(App.task.count_deleted);
259 lbl_modified.label = "%'d".printf(App.task.count_modified);
260 lbl_checksum.label = "%'d".printf(App.task.count_checksum);
261 lbl_size.label = "%'d".printf(App.task.count_size);
262 lbl_timestamp.label = "%'d".printf(App.task.count_timestamp);
263 lbl_permissions.label = "%'d".printf(App.task.count_permissions);
264 lbl_owner.label = "%'d".printf(App.task.count_owner);
265 lbl_group.label = "%'d".printf(App.task.count_group);
266
268
269 sleep(100);
270 //gtk_do_events();
271 }
272
273 #if XAPP
274 XApp.set_window_progress(parent_window, 0);
275 #endif
276
278 parent_window.show();
279 }
280
281 log_debug("RestoreBox: restore(): exit");
282
283 return (App.task.exit_code == 0);
284 }
double progress
int exit_code
string status_line
bool restore_current_system
Definition Main.vala:2024
string progress_text
Definition Main.vala:156
RsyncTask task
Definition Main.vala:160
bool thread_is_running
void restore_thread()
int64 count_group
int64 count_deleted
int64 count_owner
int64 count_modified
int64 count_permissions
int64 count_size
int64 count_created
int64 count_timestamp
int64 count_unchanged
int64 count_checksum
void log_error(string message, bool highlight=false, bool is_warning=false)
string escape_html(string html)
void sleep(int milliseconds)

References _, App, RsyncTask.count_checksum, RsyncTask.count_created, RsyncTask.count_deleted, RsyncTask.count_group, RsyncTask.count_modified, RsyncTask.count_owner, RsyncTask.count_permissions, RsyncTask.count_size, RsyncTask.count_timestamp, RsyncTask.count_unchanged, Main.dry_run, Error, TeeJee.Misc.escape_html(), AsyncTask.exit_code, TeeJee.GtkHelper.gtk_do_events(), TeeJee.Logging.log_debug(), TeeJee.Logging.log_error(), parent_window, AsyncTask.progress, Main.progress_text, Main.restore_current_system, restore_thread(), TeeJee.System.sleep(), AsyncTask.status_line, Main.task, and thread_is_running.

Referenced by RestoreWindow.initialize_tab().

◆ restore_thread()

void RestoreBox.restore_thread ( )
inlineprivate

Definition at line 286 of file RestoreBox.vala.

286 {
287
288 log_debug("RestoreBox: restore_thread()");
290 thread_is_running = false;
291 log_debug("RestoreBox: restore_thread(): exit");
292 }
bool restore_snapshot(Gtk.Window? parent_win)
Definition Main.vala:2298

References App, TeeJee.Logging.log_debug(), parent_window, Main.restore_snapshot(), and thread_is_running.

Referenced by restore().

Member Data Documentation

◆ lbl_checksum

Gtk.Label RestoreBox.lbl_checksum

Definition at line 52 of file RestoreBox.vala.

Referenced by RestoreBox().

◆ lbl_created

Gtk.Label RestoreBox.lbl_created

Definition at line 49 of file RestoreBox.vala.

Referenced by RestoreBox().

◆ lbl_deleted

Gtk.Label RestoreBox.lbl_deleted

Definition at line 50 of file RestoreBox.vala.

Referenced by RestoreBox().

◆ lbl_group

Gtk.Label RestoreBox.lbl_group

Definition at line 57 of file RestoreBox.vala.

Referenced by RestoreBox().

◆ lbl_header

Gtk.Label RestoreBox.lbl_header

Definition at line 41 of file RestoreBox.vala.

Referenced by RestoreBox().

◆ lbl_modified

Gtk.Label RestoreBox.lbl_modified

Definition at line 51 of file RestoreBox.vala.

Referenced by RestoreBox().

◆ lbl_msg

Gtk.Label RestoreBox.lbl_msg

Definition at line 44 of file RestoreBox.vala.

Referenced by RestoreBox().

◆ lbl_owner

Gtk.Label RestoreBox.lbl_owner

Definition at line 56 of file RestoreBox.vala.

Referenced by RestoreBox().

◆ lbl_permissions

Gtk.Label RestoreBox.lbl_permissions

Definition at line 55 of file RestoreBox.vala.

Referenced by RestoreBox().

◆ lbl_remaining

Gtk.Label RestoreBox.lbl_remaining

Definition at line 46 of file RestoreBox.vala.

Referenced by RestoreBox().

◆ lbl_size

Gtk.Label RestoreBox.lbl_size

Definition at line 53 of file RestoreBox.vala.

Referenced by RestoreBox().

◆ lbl_status

Gtk.Label RestoreBox.lbl_status

Definition at line 45 of file RestoreBox.vala.

Referenced by RestoreBox().

◆ lbl_timestamp

Gtk.Label RestoreBox.lbl_timestamp

Definition at line 54 of file RestoreBox.vala.

Referenced by RestoreBox().

◆ lbl_unchanged

Gtk.Label RestoreBox.lbl_unchanged

Definition at line 48 of file RestoreBox.vala.

Referenced by RestoreBox().

◆ parent_window

Gtk.Window RestoreBox.parent_window
private

Definition at line 59 of file RestoreBox.vala.

Referenced by restore(), restore_thread(), and RestoreBox().

◆ progressbar

Gtk.ProgressBar RestoreBox.progressbar

Definition at line 47 of file RestoreBox.vala.

Referenced by RestoreBox().

◆ spinner

Gtk.Spinner RestoreBox.spinner
private

Definition at line 43 of file RestoreBox.vala.

Referenced by RestoreBox().

◆ thread_is_running

bool RestoreBox.thread_is_running = false
private

Definition at line 61 of file RestoreBox.vala.

Referenced by restore(), and restore_thread().


The documentation for this class was generated from the following file: