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

Public Member Functions

 ExcludeBox (Gtk.Window _parent_window)
void set_users_box (UsersBox _users_box)
void refresh_treeview ()
void save_changes ()

Private Member Functions

void init_listbox ()
Gtk.Widget create_pattern_row (string pattern)
void update_row_pattern (Gtk.ListBoxRow row, string text, bool include)
void clear_listbox ()
void move_row (Gtk.ListBoxRow row, int delta)
void remove_row (Gtk.ListBoxRow row)
Gee.ArrayList< string > collect_patterns ()
void apply_patterns (Gee.ArrayList< string > patterns)
void init_actions ()
void remove_clicked ()
void add_files_clicked ()
void add_folder_clicked ()
SList< string > browse_files ()
SList< string > browse_folder ()

Private Attributes

Gtk.ListBox listbox
Gtk.Window parent_window
UsersBox users_box
Gtk.Label lbl_message
Gtk.ScrolledWindow scrolled

Detailed Description

Definition at line 16 of file ExcludeBox.vala.

Constructor & Destructor Documentation

◆ ExcludeBox()

ExcludeBox.ExcludeBox ( Gtk.Window _parent_window)
inline

Definition at line 23 of file ExcludeBox.vala.

23 {
24 log_debug("ExcludeBox: ExcludeBox()");
25 GLib.Object(orientation: Gtk.Orientation.VERTICAL, spacing: 6);
26 parent_window = _parent_window;
27 margin_top = 12;
28 margin_bottom = 12;
29 margin_start = 12;
30 margin_end = 12;
31
32 var header = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 6);
33 append(header);
34 add_label_header(header, _("Include / Exclude Patterns"), true);
35
36 var buffer = add_label(header, "");
37 buffer.hexpand = true;
38
39 lbl_message = add_label(header, _("Click to edit. Drag-drop to re-order."), false, true);
40
44 log_debug("ExcludeBox: ExcludeBox(): exit");
45 }
#define _(s)
void init_actions()
Gtk.Label lbl_message
Gtk.Window parent_window
void refresh_treeview()
void init_listbox()
Gtk.Label add_label(Gtk.Box box, string text, bool bold=false, bool italic=false, bool large=false)
void log_debug(string message)

References _, TeeJee.GtkHelper.add_label(), init_actions(), init_listbox(), lbl_message, TeeJee.Logging.log_debug(), parent_window, and refresh_treeview().

Referenced by RestoreWindow.build_pages(), SettingsWindow.build_pages(), and SetupWizardWindow.build_pages().

Member Function Documentation

◆ add_files_clicked()

void ExcludeBox.add_files_clicked ( )
inlineprivate

Definition at line 265 of file ExcludeBox.vala.

265 {
266 var list = browse_files();
267 if (list.length() > 0){
268 foreach(string item in list){
269 string pattern = item;
270 if (!App.exclude_list_user.contains(pattern)){
271 App.exclude_list_user.add(pattern);
272 Main.first_snapshot_size = 0;
273 }
274 }
275 }
277 save_changes();
278 }
Main App
void save_changes()
SList< string > browse_files()
Gee.ArrayList< string > exclude_list_user
Definition Main.vala:61

References App, browse_files(), Main.exclude_list_user, Main.first_snapshot_size, refresh_treeview(), and save_changes().

Referenced by init_actions().

◆ add_folder_clicked()

void ExcludeBox.add_folder_clicked ( )
inlineprivate

Definition at line 280 of file ExcludeBox.vala.

280 {
281 var list = browse_folder();
282 if (list.length() > 0){
283 foreach(string item in list){
284 string pattern = item;
285 if (!pattern.has_suffix("/***")){
286 pattern = "%s/***".printf(pattern);
287 }
288 if (!App.exclude_list_user.contains(pattern)){
289 App.exclude_list_user.add(pattern);
290 Main.first_snapshot_size = 0;
291 }
292 }
293 }
295 save_changes();
296 }
SList< string > browse_folder()

References App, browse_folder(), Main.exclude_list_user, Main.first_snapshot_size, refresh_treeview(), and save_changes().

Referenced by init_actions().

◆ apply_patterns()

void ExcludeBox.apply_patterns ( Gee.ArrayList< string > patterns)
inlineprivate

Definition at line 211 of file ExcludeBox.vala.

211 {
212 App.exclude_list_user.clear();
213 foreach(string pattern in patterns){
214 if (pattern.strip().length == 0){ continue; }
215 if (!App.exclude_list_user.contains(pattern)){
216 App.exclude_list_user.add(pattern);
217 }
218 }
220 save_changes();
221 }

References App, Main.exclude_list_user, refresh_treeview(), and save_changes().

Referenced by move_row().

◆ browse_files()

SList< string > ExcludeBox.browse_files ( )
inlineprivate

Definition at line 298 of file ExcludeBox.vala.

298 {
299 var list = new SList<string>();
300 return list;
301 }

Referenced by add_files_clicked().

◆ browse_folder()

SList< string > ExcludeBox.browse_folder ( )
inlineprivate

Definition at line 303 of file ExcludeBox.vala.

303 {
304 var list = new SList<string>();
305 return list;
306 }

Referenced by add_folder_clicked().

◆ clear_listbox()

void ExcludeBox.clear_listbox ( )
inlineprivate

Definition at line 161 of file ExcludeBox.vala.

161 {
162 Gtk.Widget? child = listbox.get_first_child();
163 while (child != null){
164 Gtk.Widget? next = child.get_next_sibling();
165 listbox.remove(child);
166 child = next;
167 }
168 }
Gtk.ListBox listbox

References listbox.

Referenced by refresh_treeview().

◆ collect_patterns()

Gee.ArrayList< string > ExcludeBox.collect_patterns ( )
inlineprivate

Definition at line 195 of file ExcludeBox.vala.

195 {
196 var patterns = new Gee.ArrayList<string>();
197 Gtk.Widget? child = listbox.get_first_child();
198 while (child != null){
199 var row = child as Gtk.ListBoxRow;
200 if (row != null){
201 string? pattern = row.get_data<string>("pattern");
202 if ((pattern != null) && (pattern.strip().length > 0)){
203 patterns.add(pattern);
204 }
205 }
206 child = child.get_next_sibling();
207 }
208 return patterns;
209 }
std::vector< Pattern > patterns()

References listbox.

Referenced by move_row(), and save_changes().

◆ create_pattern_row()

Gtk.Widget ExcludeBox.create_pattern_row ( string pattern)
inlineprivate

Definition at line 64 of file ExcludeBox.vala.

64 {
65 bool include = pattern.has_prefix("+ ");
66 string clean_pattern = include ? pattern[2:pattern.length] : pattern;
67
68 var row = new Gtk.ListBoxRow();
69 var outer = new Gtk.Box(Gtk.Orientation.VERTICAL, 6);
70 outer.margin_start = 8;
71 outer.margin_end = 8;
72 outer.margin_top = 8;
73 outer.margin_bottom = 8;
74 row.set_child(outer);
75
76 var top = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 12);
77 outer.append(top);
78
79 var toggles = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 12);
80 top.append(toggles);
81
82 var btn_include = new Gtk.CheckButton.with_label("+");
83 var btn_exclude = new Gtk.CheckButton.with_label("-");
84 btn_exclude.set_group(btn_include);
85 btn_include.active = include;
86 btn_exclude.active = !include;
87 toggles.append(btn_include);
88 toggles.append(btn_exclude);
89
90 var entry = new Gtk.Entry();
91 entry.hexpand = true;
92 entry.text = clean_pattern;
93 entry.placeholder_text = _("Pattern");
94 top.append(entry);
95
96 var icon = IconManager.lookup_image(include ? "list-add" : "list-remove", 16);
97 top.append(icon);
98
99 var actions = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 6);
100 actions.halign = Gtk.Align.END;
101 outer.append(actions);
102
103 var btn_up = IconManager.button_from_icon("go-up-symbolic", 16);
104 btn_up.tooltip_text = _("Move up");
105 actions.append(btn_up);
106
107 var btn_down = IconManager.button_from_icon("go-down-symbolic", 16);
108 btn_down.tooltip_text = _("Move down");
109 actions.append(btn_down);
110
111 var btn_remove = IconManager.button_from_icon("user-trash-symbolic", 16);
112 btn_remove.tooltip_text = _("Remove");
113 actions.append(btn_remove);
114
115 btn_include.toggled.connect(()=>{
116 if (!btn_include.active){ return; }
117 icon = IconManager.lookup_image("list-add", 16);
118 update_row_pattern(row, entry.text, true);
119 });
120
121 btn_exclude.toggled.connect(()=>{
122 if (!btn_exclude.active){ return; }
123 icon = IconManager.lookup_image("list-remove", 16);
124 update_row_pattern(row, entry.text, false);
125 });
126
127 entry.changed.connect(()=>{
128 update_row_pattern(row, entry.text, btn_include.active);
129 });
130
131 btn_up.clicked.connect(()=>{
132 move_row(row, -1);
133 });
134
135 btn_down.clicked.connect(()=>{
136 move_row(row, 1);
137 });
138
139 btn_remove.clicked.connect(()=>{
140 remove_row(row);
141 });
142
143 row.set_data<string>("pattern", pattern);
144 return row;
145 }
void update_row_pattern(Gtk.ListBoxRow row, string text, bool include)
void remove_row(Gtk.ListBoxRow row)
void move_row(Gtk.ListBoxRow row, int delta)

References _, IconManager.button_from_icon(), IconManager.lookup_image(), move_row(), remove_row(), and update_row_pattern().

Referenced by refresh_treeview().

◆ init_actions()

void ExcludeBox.init_actions ( )
inlineprivate

Definition at line 223 of file ExcludeBox.vala.

223 {
224 var hbox = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 6);
225 append(hbox);
226
227 var size_group = new Gtk.SizeGroup(SizeGroupMode.HORIZONTAL);
228 var button = add_button(hbox, _("Add"), _("Add custom pattern"), size_group, null);
229 button.clicked.connect(()=>{
230 string pattern = gtk_inputbox(
231 _("Exclude Pattern"),
232 _("Enter the pattern to exclude (Ex: *.mp3, *.bak)"),
233 parent_window, false);
234
235 if ((pattern != null) && (pattern.strip().length > 0)){
236 App.exclude_list_user.add(pattern);
237 Main.first_snapshot_size = 0;
239 }
240 save_changes();
241 });
242
243 button = add_button(hbox, _("Add Files"), _("Add files"), size_group, null);
244 button.clicked.connect(()=>{ add_files_clicked(); });
245
246 button = add_button(hbox, _("Add Folders"), _("Add directories"), size_group, null);
247 button.clicked.connect(()=>{ add_folder_clicked(); });
248
249 button = add_button(hbox, _("Remove"), "", size_group, null);
250 button.clicked.connect(()=>{ remove_clicked(); });
251
252 button = add_button(hbox, _("Summary"), "", size_group, null);
253 button.clicked.connect(()=>{
254 save_changes();
255 new ExcludeListSummaryWindow(false);
256 });
257 }
void add_files_clicked()
void add_folder_clicked()
void remove_clicked()
ExcludeListSummaryWindow(bool _for_restore)
string? gtk_inputbox(string title, string message, Gtk.Window? parent_win, bool mask_password=false)

References _, add_files_clicked(), add_folder_clicked(), App, Main.exclude_list_user, ExcludeListSummaryWindow.ExcludeListSummaryWindow(), Main.first_snapshot_size, TeeJee.GtkHelper.gtk_inputbox(), parent_window, refresh_treeview(), remove_clicked(), and save_changes().

Referenced by ExcludeBox().

◆ init_listbox()

void ExcludeBox.init_listbox ( )
inlineprivate

Definition at line 51 of file ExcludeBox.vala.

51 {
52 listbox = new Gtk.ListBox();
53 listbox.selection_mode = Gtk.SelectionMode.NONE;
54 listbox.add_css_class("boxed-list");
55
56 scrolled = new Gtk.ScrolledWindow();
57 scrolled.hexpand = true;
58 scrolled.vexpand = true;
59 scrolled.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
60 scrolled.set_child(listbox);
61 append(scrolled);
62 }
Gtk.ScrolledWindow scrolled

References listbox, and scrolled.

Referenced by ExcludeBox().

◆ move_row()

void ExcludeBox.move_row ( Gtk.ListBoxRow row,
int delta )
inlineprivate

Definition at line 170 of file ExcludeBox.vala.

170 {
172 string? current = row.get_data<string>("pattern");
173 if (current == null){ return; }
174 int index = -1;
175 for (int i = 0; i < patterns.size; i++){
176 if (patterns[i] == current){ index = i; break; }
177 }
178 if (index < 0){ return; }
179 int target = index + delta;
180 if (target < 0 || target >= patterns.size){ return; }
181 string tmp = patterns[index];
182 patterns[index] = patterns[target];
183 patterns[target] = tmp;
184 apply_patterns(patterns);
185 }
Gee.ArrayList< string > collect_patterns()
void apply_patterns(Gee.ArrayList< string > patterns)

References apply_patterns(), and collect_patterns().

Referenced by create_pattern_row().

◆ refresh_treeview()

void ExcludeBox.refresh_treeview ( )
inline

Definition at line 308 of file ExcludeBox.vala.

308 {
310 foreach(string pattern in App.exclude_list_user){
311 listbox.append(create_pattern_row(pattern));
312 }
313 show();
314 }
Gtk.Widget create_pattern_row(string pattern)
void clear_listbox()

References App, clear_listbox(), create_pattern_row(), Main.exclude_list_user, and listbox.

Referenced by add_files_clicked(), add_folder_clicked(), apply_patterns(), ExcludeBox(), init_actions(), UsersBox.refresh_treeview(), and remove_row().

◆ remove_clicked()

void ExcludeBox.remove_clicked ( )
inlineprivate

Definition at line 259 of file ExcludeBox.vala.

259 {
260 string title = _("Remove Pattern");
261 string message = _("Use the trash icon on each row to remove patterns in the GTK4 list view.");
262 gtk_messagebox(title, message, parent_window, true);
263 }

References _, and parent_window.

Referenced by init_actions().

◆ remove_row()

void ExcludeBox.remove_row ( Gtk.ListBoxRow row)
inlineprivate

Definition at line 187 of file ExcludeBox.vala.

187 {
188 string? pattern = row.get_data<string>("pattern");
189 if (pattern == null){ return; }
190 App.exclude_list_user.remove(pattern);
192 save_changes();
193 }

References App, Main.exclude_list_user, refresh_treeview(), and save_changes().

Referenced by create_pattern_row().

◆ save_changes()

void ExcludeBox.save_changes ( )
inline

Definition at line 316 of file ExcludeBox.vala.

316 {
317 App.exclude_list_user.clear();
318 foreach(string pattern in collect_patterns()){
319 if (!App.exclude_list_user.contains(pattern)
320 && !App.exclude_list_default.contains(pattern)
321 && !App.exclude_list_home.contains(pattern)){
322 App.exclude_list_user.add(pattern);
323 }
324 }
325
326 log_debug("save_changes(): exclude_list_user:");
327 foreach(var item in App.exclude_list_user){
328 log_debug(item);
329 }
330 log_debug("");
331
332 if (users_box != null){
334 }
335 }
UsersBox users_box
Gee.ArrayList< string > exclude_list_default
Definition Main.vala:62
Gee.ArrayList< string > exclude_list_home
Definition Main.vala:64
void refresh()

References App, collect_patterns(), Main.exclude_list_default, Main.exclude_list_home, Main.exclude_list_user, TeeJee.Logging.log_debug(), UsersBox.refresh(), and users_box.

Referenced by add_files_clicked(), add_folder_clicked(), apply_patterns(), init_actions(), remove_row(), SettingsWindow.save_changes(), and update_row_pattern().

◆ set_users_box()

void ExcludeBox.set_users_box ( UsersBox _users_box)
inline

Definition at line 47 of file ExcludeBox.vala.

47 {
48 users_box = _users_box;
49 }

References users_box.

Referenced by SettingsWindow.build_pages().

◆ update_row_pattern()

void ExcludeBox.update_row_pattern ( Gtk.ListBoxRow row,
string text,
bool include )
inlineprivate

Definition at line 147 of file ExcludeBox.vala.

147 {
148 string value = text;
149 if (include){
150 if (!value.has_prefix("+ ")){
151 value = "+ %s".printf(value);
152 }
153 }
154 else if (value.has_prefix("+ ")){
155 value = value[2:value.length];
156 }
157 row.set_data<string>("pattern", value);
158 save_changes();
159 }

References save_changes().

Referenced by create_pattern_row().

Member Data Documentation

◆ lbl_message

Gtk.Label ExcludeBox.lbl_message
private

Definition at line 20 of file ExcludeBox.vala.

Referenced by ExcludeBox().

◆ listbox

Gtk.ListBox ExcludeBox.listbox
private

Definition at line 17 of file ExcludeBox.vala.

Referenced by clear_listbox(), collect_patterns(), init_listbox(), and refresh_treeview().

◆ parent_window

Gtk.Window ExcludeBox.parent_window
private

Definition at line 18 of file ExcludeBox.vala.

Referenced by ExcludeBox(), init_actions(), and remove_clicked().

◆ scrolled

Gtk.ScrolledWindow ExcludeBox.scrolled
private

Definition at line 21 of file ExcludeBox.vala.

Referenced by init_listbox().

◆ users_box

UsersBox ExcludeBox.users_box
private

Definition at line 19 of file ExcludeBox.vala.

Referenced by save_changes(), and set_users_box().


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