1. Overview
The SambaPage.hpp header defines the SambaPage class, a GTKmm (GTK4) UI component responsible for configuring and managing Samba/network share scanning within BastionGuard. The page allows users to enable or disable Samba integration, manage a list of monitored directories, and trigger on-demand scans through the backend subsystem.
Functionally, SambaPage provides:
- Enable/disable control for Samba/network share monitoring
- Visualization of configured directories in a tabular view
- Add/remove management of monitored network paths
- Manual scan triggering for immediate verification
- Persistent configuration loading and saving
- Synchronization between backend state and UI representation
2. Dependencies and Includes
#include <gtkmm.h>
#include "Backend.hpp"
- gtkmm.h – GTK4 widgets, model/view components, and signal infrastructure
- Backend.hpp – interface to the scanning and configuration backend
3. Class Declaration and Scope
class SambaPage : public Gtk::Box
The class derives from Gtk::Box, making it suitable for inclusion as a page within stacked or tab-based navigation systems.
A virtual default destructor is provided as a best practice to ensure correct cleanup in polymorphic use cases.
virtual ~SambaPage() = default;
4. Public Interface
4.1 Constructor / Destructor
SambaPage();
virtual ~SambaPage() = default;
The constructor initializes the Samba configuration UI, creates the list model/view, binds controls to backend operations, and loads the persisted configuration.
5. UI Components
SambaPage is structured around a model/view table and a set of control widgets for configuration management.
5.1 Directory List Model
struct SambaColumns : public Gtk::TreeModel::ColumnRecord {
Gtk::TreeModelColumn<Glib::ustring> col_path;
Gtk::TreeModelColumn<Glib::ustring> col_color;
};
Defines the column schema for the directory list:
- col_path – network or local path of the monitored directory
- col_color – UI color/state indicator (e.g., scan status, warnings)
5.2 Model/View Components
SambaColumns sambaCols;
Glib::RefPtr<Gtk::ListStore> sambaStore;
Gtk::TreeView sambaView;
- sambaCols – column definition instance
- sambaStore – list model storing directory entries
- sambaView – tree view rendering the model in tabular form
5.3 Control Widgets
Gtk::Switch switchEnable;
Gtk::Button btnAdd, btnRemove, btnScan, btnSave;
- switchEnable – enables/disables Samba scanning integration
- btnAdd – adds a new directory/share
- btnRemove – removes the selected entry
- btnScan – triggers an immediate scan
- btnSave – persists current configuration
6. Internal State and Data Model
bool loading_ = false;
- loading_ – guards against unintended signal handling during configuration loading and UI initialization
This flag is typically used to suppress change callbacks while the UI is being programmatically updated.
7. User Actions (Callbacks)
void onAddDir();
void onRemoveDir();
void onScanNow();
- onAddDir() – opens a dialog or input flow to add a new Samba directory
- onRemoveDir() – removes the currently selected entry
- onScanNow() – requests an immediate backend scan
These handlers coordinate user input with backend operations.
8. Internal Logic
8.1 Configuration Management
void loadConfig();
void saveConfig();
void refreshUI();
- loadConfig() – loads persisted Samba configuration from backend storage
- saveConfig() – writes current settings to persistent storage
- refreshUI() – synchronizes widget states with the loaded configuration
9. Auto-Update (Scheduled Refresh)
This component does not declare an internal periodic timer. Configuration and status updates are typically driven by user actions or backend callbacks.
10. Settings Storage
Samba-related settings (enabled state, monitored directories, scan options) are persisted via loadConfig() and saveConfig(), typically through the backend subsystem defined in Backend.hpp.
11. Helper Functions and Filesystem / Network Layout
The page operates on network share paths and local mount points. Typical configurations may include:
//mnt/server/share
//nas/documents
smb://fileserver/public
The backend is responsible for resolving, authenticating, and accessing these resources securely.
12. Runtime and Security Considerations
- Credential handling: access to protected Samba shares should rely on secure credential storage and avoid hard-coded secrets.
- Network reliability: scans must handle transient network failures gracefully and provide actionable error feedback.
- UI consistency: the
loading_guard must be applied consistently to prevent unintended configuration overwrites. - Privilege boundaries: network scanning may require elevated permissions and must respect system security policies.
- Data validation: user-provided paths should be validated to prevent injection or unintended access to sensitive resources.