diff --git a/src/applib/storage_device.cpp b/src/applib/storage_device.cpp index 6bef43e..a33528a 100644 --- a/src/applib/storage_device.cpp +++ b/src/applib/storage_device.cpp @@ -925,6 +925,20 @@ bool StorageDevice::get_test_is_active() const +StorageDevice::SelfTestSupportStatus StorageDevice::get_self_test_support_status() const +{ + if (get_parse_status() == ParseStatus::Full) { + return property_repository_.has_properties_for_section(StoragePropertySection::SelftestLog) ? + SelfTestSupportStatus::Supported : SelfTestSupportStatus::Unsupported; + } + if (get_parse_status() == ParseStatus::Basic) { + return get_smart_status() == SmartStatus::Enabled ? SelfTestSupportStatus::Unknown : SelfTestSupportStatus::Unsupported; + } + return StorageDevice::SelfTestSupportStatus::Unknown; +} + + + std::string StorageDevice::get_save_filename() const { const std::string model = this->get_model_name(); // may be empty diff --git a/src/applib/storage_device.h b/src/applib/storage_device.h index 1246275..5e22bf4 100644 --- a/src/applib/storage_device.h +++ b/src/applib/storage_device.h @@ -70,6 +70,14 @@ class StorageDevice { }; + /// Status of self-test support + enum class SelfTestSupportStatus { + Unknown, ///< Full info not parsed yet + Supported, ///< Supported + Unsupported, ///< Not supported + }; + + /// Constructor explicit StorageDevice(std::string dev_or_vfile, bool is_virtual = false); @@ -232,6 +240,10 @@ class StorageDevice { [[nodiscard]] bool get_test_is_active() const; + /// Get whether the tests are supported, based on parsed properties + [[nodiscard]] SelfTestSupportStatus get_self_test_support_status() const; + + /// Get the recommended filename to save output to. Includes model and date. [[nodiscard]] std::string get_save_filename() const; diff --git a/src/gui/gsc_info_window.cpp b/src/gui/gsc_info_window.cpp index 3393d44..4bbfe40 100644 --- a/src/gui/gsc_info_window.cpp +++ b/src/gui/gsc_info_window.cpp @@ -404,11 +404,16 @@ void GscInfoWindow::fill_ui_with_info(bool scan, bool clear_ui, bool clear_tests note_page_box->set_visible(has_statistics); } - bool has_selftest = prop_repo.has_properties_for_section(StoragePropertySection::SelftestLog); + const bool has_selftest = (drive_->get_self_test_support_status() == StorageDevice::SelfTestSupportStatus::Supported); if (note_page_box = lookup_widget("test_tab_vbox"); note_page_box != nullptr) { // Some USB flash drives erroneously report SMART as enabled. // note_page_box->set_visible(drive->get_smart_status() == StorageDevice::Status::Enabled); note_page_box->set_visible(has_selftest); + if (has_selftest) { + book_selftest_page_no_ = 4; + } else { + book_selftest_page_no_ = -1; + } } const bool has_ata_error_log = prop_repo.has_properties_for_section(StoragePropertySection::AtaErrorLog); @@ -781,8 +786,13 @@ void GscInfoWindow::refresh_info(bool clear_tests_too) void GscInfoWindow::show_tests() { - if (auto* book = lookup_widget("main_notebook")) - book->set_current_page(3); // the Tests tab + if (auto* book = lookup_widget("main_notebook")) { + if (book_selftest_page_no_ >= 0) { + book->set_current_page(book_selftest_page_no_); // the Tests tab + } else { + gui_show_warn_dialog(_("Self-Tests Not Supported"), _("Self-tests are not supported on this drive."), this); + } + } } diff --git a/src/gui/gsc_info_window.h b/src/gui/gsc_info_window.h index dd636e4..862142a 100644 --- a/src/gui/gsc_info_window.h +++ b/src/gui/gsc_info_window.h @@ -310,6 +310,8 @@ class GscInfoWindow : public AppBuilderWidget { /// Columns of treeviews inside GscInfoWindow std::unique_ptr columns_; + + int book_selftest_page_no_ = -1; ///< The page number of the self-test log in the notebook }; diff --git a/src/gui/gsc_main_window.cpp b/src/gui/gsc_main_window.cpp index e27032d..c881835 100644 --- a/src/gui/gsc_main_window.cpp +++ b/src/gui/gsc_main_window.cpp @@ -731,16 +731,20 @@ void GscMainWindow::set_drive_menu_status(const StorageDevicePtr& drive) { Glib::RefPtr action; - if ((action = actiongroup_device_->get_action(APP_ACTION_NAME(action_perform_tests)))) - action->set_sensitive(smart_status == StorageDevice::SmartStatus::Enabled); - if ((action = actiongroup_device_->get_action(APP_ACTION_NAME(action_reread_device_data)))) + if ((action = actiongroup_device_->get_action(APP_ACTION_NAME(action_perform_tests)))) { + auto status = drive->get_self_test_support_status(); + action->set_sensitive(status != StorageDevice::SelfTestSupportStatus::Unsupported); + } + if ((action = actiongroup_device_->get_action(APP_ACTION_NAME(action_reread_device_data)))) { action->set_visible(drive && !is_virtual); + } if ((action = actiongroup_device_->get_action(APP_ACTION_NAME(action_remove_device)))) { action->set_visible(drive && drive->get_is_manually_added()); // action->set_sensitive(drive && drive->get_is_manually_added()); } - if ((action = actiongroup_device_->get_action(APP_ACTION_NAME(action_remove_virtual_device)))) + if ((action = actiongroup_device_->get_action(APP_ACTION_NAME(action_remove_virtual_device)))) { action->set_visible(drive && is_virtual); + } if ((action = actiongroup_device_->get_action(APP_ACTION_NAME(action_enable_smart)))) { action->set_sensitive(drive && drive->get_smart_switch_supported()); }