Manually added devices can be persistent now.

This commit is contained in:
Alexander Shaduri
2025-04-28 11:19:44 +00:00
parent 10ad6b74eb
commit 1f7c2b6a92
5 changed files with 75 additions and 5 deletions
+1
View File
@@ -48,6 +48,7 @@ inline void init_default_settings()
rconfig::set_default_data("system/smartctl_options", ""); // default options on ALL commands
rconfig::set_default_data("system/smartctl_device_options", ""); // dev1:val1;dev2:val2;... format, each bin2ascii-encoded.
rconfig::set_default_data("system/auto_add_devices", ""); // Auto-add devices on startup
rconfig::set_default_data("system/linux_udev_byid_path", "/dev/disk/by-id"); // linux hard disk device links here
rconfig::set_default_data("system/linux_proc_partitions_path", "/proc/partitions"); // file in linux /proc/partitions format
+10 -4
View File
@@ -81,7 +81,11 @@ inline AppDeviceOptionMap app_config_get_device_option_map()
return rconfig::get_data<AppDeviceOptionMap>("system/smartctl_device_options");
}
/// Get auto-add device option map from config
inline AppDeviceOptionMap app_config_get_auto_add_device_map()
{
return rconfig::get_data<AppDeviceOptionMap>("system/auto_add_devices");
}
/// Read device option map from config and get the options for (dev, type_arg) pair.
inline std::vector<std::string> app_get_device_options(const std::string& dev, const std::string& type_arg)
@@ -106,9 +110,11 @@ inline std::vector<std::string> app_get_device_options(const std::string& dev, c
return {};
}
/// Read auto-add devices from configuration
inline AppDeviceOptionMap app_get_auto_add_devices()
{
return app_config_get_auto_add_device_map();
}
#endif
+27
View File
@@ -166,6 +166,33 @@ void GscAddDeviceWindow::on_window_ok_button_clicked()
}
}
}
// Check if the auto-add checkbox is checked
bool auto_add = false;
if (auto* check = lookup_widget<Gtk::CheckButton*>("auto_add_device_check")) {
auto_add = check->get_active();
}
// If auto-add is checked, save the device info to config
if (auto_add && !dev.empty()) {
// Get existing auto-add devices
AppDeviceOptionMap auto_add_devices = app_config_get_auto_add_device_map();
// Create params string from vector
std::string params_str;
for (const auto& param : params) {
if (!params_str.empty())
params_str += " ";
params_str += param;
}
// Add or update this device in the map
auto_add_devices.value.insert_or_assign({dev, type}, params_str);
// Save the updated map back to config
rconfig::set_data("system/auto_add_devices", auto_add_devices);
}
if (main_window_ && !dev.empty()) {
main_window_->add_device(dev, type, params);
}
+21
View File
@@ -146,6 +146,27 @@ void GscMainWindow::populate_iconview_on_startup(bool smartctl_valid)
}
}
}
// Add auto-add devices stored in configuration
auto auto_add_devices = app_get_auto_add_devices();
for (const auto& [dev_type, options_str] : auto_add_devices.value) {
const auto& dev = dev_type.first;
const auto& type_arg = dev_type.second;
if (!dev.empty()) {
std::vector<std::string> params;
if (!options_str.empty()) {
try {
params = Glib::shell_parse_argv(options_str);
}
catch(Glib::ShellError& e) {
// Skip this entry if we can't parse params
continue;
}
}
add_device(dev, type_arg, params);
}
}
}
for (auto&& virt : get_startup_settings().load_virtuals) {
+16 -1
View File
@@ -187,7 +187,6 @@ along with GSmartControl. If not, see <http://www.gnu.org/licenses/>.
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Note: To make this change permanent, you'll have to add the gsmartcontrol --add-device command line option to its shortcut.</property>
<property name="wrap">True</property>
</object>
<packing>
@@ -197,6 +196,22 @@ along with GSmartControl. If not, see <http://www.gnu.org/licenses/>.
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="auto_add_device_check">
<property name="label" translatable="yes">Automatically add this device on startup</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="halign">start</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="padding">0</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>