SnapshotListBox

1. Overview

The SnapshotListBox module renders, sorts, edits, and selects snapshots.

Its principal responsibilities are:

  • Displays snapshot metadata in custom rows
  • Supports multi-selection through check buttons
  • Allows description editing
  • Sorts by snapshot fields
  • Exposes selected Snapshot objects to parent workflows

The file defines multiple cooperating classes:

  • SnapshotRow – derives from Gtk.ListBoxRow
  • SnapshotListBox – derives from Gtk.Box

2. Class Structure and Dependencies

public class SnapshotRow : Gtk.ListBoxRow
public class SnapshotListBox : Gtk.Box

The source imports:

  • Gtk
  • Gee
  • TeeJee.Logging
  • TeeJee.FileSystem
  • TeeJee.JsonHelper
  • TeeJee.ProcessHelper
  • TeeJee.GtkHelper
  • TeeJee.System
  • TeeJee.Misc

The GTK inheritance and imported modules allow the component to participate in the application event loop, share the central backup state, and construct native GTK4 controls.


3. Primary Runtime State

The principal fields declared by the module include:

  • Snapshot snapshot – snapshot represented by a row
  • Gtk.CheckButton check – selection control associated with a snapshot or option
  • Gtk.Entry desc_entry – editable snapshot-description field
  • Gtk.ListBox treeview – ListBox widget used by the interface
  • Gtk.Window parent_window – parent GTK window used for transient dialogs
  • Gtk.ListBox listbox – GTK list used to render selectable rows
  • Gtk.ScrolledWindow scrolled – ScrolledWindow widget used by the interface
  • Gtk.Box header_actions – Box widget used by the interface
  • int sort_column_index – numeric state for sort column index
  • bool sort_desc – Boolean state for sort desc

4. User Interface Composition

The module directly constructs the following GTK widget types:

  • Gtk.Box – layout containers
  • Gtk.Button – action and navigation buttons
  • Gtk.CheckButton – Boolean or mutually exclusive choices
  • Gtk.Entry – editable text fields
  • Gtk.Label – headings, descriptions, and status text
  • Gtk.ListBox – dynamic selectable rows
  • Gtk.ScrolledWindow – scrollable content regions

Event-driven behavior is connected through signals such as:

changed
clicked
row_activated
toggled

5. Initialization

SnapshotRow()

public SnapshotRow(Snapshot bak)

Initializes the class instance, creates its GTK controls, and prepares the initial state.

SnapshotListBox()

public SnapshotListBox(Gtk.Window _parent_window)

Initializes the class instance, creates its GTK controls, and prepares the initial state.


6. Central Controller Integration

The module reads or modifies the following Main controller members through the global App object:

  • App.btrfs_mode
  • App.btrfs_qgroups_enabled
  • App.repo

7. Operational Workflow

  1. Load snapshots from the active repository
  2. Create one SnapshotRow per snapshot
  3. Apply the selected sort column and direction
  4. Return checked rows to backup, restore, or deletion workflows

8. Method Reference

build_ui()

private void build_ui()

Constructs the complete GTK widget hierarchy for the component. It creates Gtk.Box, Gtk.CheckButton, Gtk.Entry, Gtk.Label where required. It connects the changed, toggled signals.

build_meta_text()

private string build_meta_text()

Builds the meta text portion of the interface. It reads or updates central state through App.btrfs_qgroups_enabled.

add_sort_button()

private void add_sort_button(string label, int column, bool default_desc)

Adds or constructs sort button for the current interface or model. It creates Gtk.Button where required. It connects the clicked signal.

hide_context_menu()

public void hide_context_menu()

Hides context menu.

clear_rows()

private void clear_rows()

Implements the clear rows operation.

refresh()

public void refresh()

Reloads current application state and updates the visible controls. It reads or updates central state through App.repo.

selected_snapshots()

public Gee.ArrayList<Snapshot> selected_snapshots()

Returns the currently selected snapshots.


9. External Resources and Paths

The component does not directly define protected filesystem paths or external command strings.


10. Data and Event Flow

  1. Construct the component and initialize its child controls
  2. Load the current model state into the interface
  3. React to GTK signals generated by navigation, selections, and action controls
  4. Read or update central backup and restore state through the global controller

11. Runtime and Security Considerations

  • Shared controller state: the component reads and modifies the global App controller used by the surrounding workflow.
  • Signal-driven behavior: GTK callbacks update the model and interface when controls are activated or changed.

12. Implementation Considerations

  • Global coupling: the class depends on the process-wide App object rather than receiving a controller through dependency injection.

13. Licensing

The applicable licensing terms are defined by the source-file header and the containing BastionGuard Backup project.