diff --git a/src/applib/gsc_settings.h b/src/applib/gsc_settings.h index ca88801..3d53a05 100644 --- a/src/applib/gsc_settings.h +++ b/src/applib/gsc_settings.h @@ -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 diff --git a/src/applib/storage_settings.h b/src/applib/storage_settings.h index c7b91da..a31fd80 100644 --- a/src/applib/storage_settings.h +++ b/src/applib/storage_settings.h @@ -81,7 +81,11 @@ inline AppDeviceOptionMap app_config_get_device_option_map() return rconfig::get_data("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("system/auto_add_devices"); +} /// Read device option map from config and get the options for (dev, type_arg) pair. inline std::vector app_get_device_options(const std::string& dev, const std::string& type_arg) @@ -106,9 +110,11 @@ inline std::vector 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 diff --git a/src/gui/gsc_add_device_window.cpp b/src/gui/gsc_add_device_window.cpp index b3dcfb8..3654b38 100644 --- a/src/gui/gsc_add_device_window.cpp +++ b/src/gui/gsc_add_device_window.cpp @@ -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("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); } diff --git a/src/gui/gsc_main_window.cpp b/src/gui/gsc_main_window.cpp index 4828d08..24e1512 100644 --- a/src/gui/gsc_main_window.cpp +++ b/src/gui/gsc_main_window.cpp @@ -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 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) { diff --git a/src/gui/ui/gsc_add_device_window.glade b/src/gui/ui/gsc_add_device_window.glade index 18195a2..233f281 100644 --- a/src/gui/ui/gsc_add_device_window.glade +++ b/src/gui/ui/gsc_add_device_window.glade @@ -187,7 +187,6 @@ along with GSmartControl. If not, see . True False start - Note: To make this change permanent, you'll have to add the gsmartcontrol --add-device command line option to its shortcut. True @@ -197,6 +196,22 @@ along with GSmartControl. If not, see . 2 + + + Automatically add this device on startup + True + True + False + start + True + + + True + True + 0 + 3 + + False