From f7c01d6c7b5c0da210b96276753e4c59f6e9ca22 Mon Sep 17 00:00:00 2001 From: Alexander Shaduri Date: Tue, 5 Sep 2017 16:12:19 +0000 Subject: [PATCH] Implemented "Update Drive Database" item in main window menu. --- gsmartcontrol/TODO | 8 ------ gsmartcontrol/debian.dist/control | 2 +- gsmartcontrol/gsmartcontrol.spec.in | 4 +-- gsmartcontrol/src/gsc_main_window.cpp | 40 +++++++++++++++++++++++++++ gsmartcontrol/src/gsc_main_window.h | 5 ++++ 5 files changed, 48 insertions(+), 11 deletions(-) diff --git a/gsmartcontrol/TODO b/gsmartcontrol/TODO index d52abf6..a0eb70c 100644 --- a/gsmartcontrol/TODO +++ b/gsmartcontrol/TODO @@ -30,20 +30,12 @@ Add ability (through ctrl-C?) to copy selected rows from attributes and statisti in tab-separated format (for easy pasting into libreoffice). -Add menu item - "update drive database" - Run it in terminal in Linux for verbosity. - xterm -hold -e 'update-smart-drivedb' - require xterm in rpm/deb deps. - - Testing: If ETA time has elapsed, but it's still only at 10% completion, ETA 0 is displayed. Fix. Detect running tests on launch (maybe ask the user too? some tests may be stuck due to bad firmware, e.g. 3ware/windows). -Parse "==> WARNING" - Parse all test data. diff --git a/gsmartcontrol/debian.dist/control b/gsmartcontrol/debian.dist/control index 7467e2a..22a0809 100644 --- a/gsmartcontrol/debian.dist/control +++ b/gsmartcontrol/debian.dist/control @@ -9,7 +9,7 @@ Standards-Version: 3.7.3 Package: gsmartcontrol Architecture: any -Depends: ${shlibs:Depends}, smartmontools (>= 5.43), menu +Depends: ${shlibs:Depends}, smartmontools (>= 5.43), xterm, menu Description: Hard disk drive and SSD health inspection tool GSmartControl is a graphical user interface for smartctl (from smartmontools package), which is a tool for querying and controlling SMART diff --git a/gsmartcontrol/gsmartcontrol.spec.in b/gsmartcontrol/gsmartcontrol.spec.in index 0842588..d4a4c4b 100644 --- a/gsmartcontrol/gsmartcontrol.spec.in +++ b/gsmartcontrol/gsmartcontrol.spec.in @@ -24,7 +24,7 @@ Group: Hardware/Other # SUSE / OpenSUSE. SLES also defines the correct suse_version. %if 0%{?suse_version} -Requires: smartmontools >= 5.43, polkit, bash +Requires: smartmontools >= 5.43, polkit, bash, xterm BuildRequires: gcc-c++, libstdc++-devel, pcre-devel, gtkmm3-devel >= 3.4.0 BuildRequires: update-desktop-files BuildRequires: fdupes @@ -35,7 +35,7 @@ BuildRequires: fdupes # Fedora, CentOS, RHEL %if 0%{?fedora_version} || 0%{?rhel_version} || 0%{?centos_version} -Requires: smartmontools >= 5.43, polkit, bash +Requires: smartmontools >= 5.43, polkit, bash, xterm BuildRequires: gcc-c++, pcre-devel, gtkmm30-devel >= 3.4.0 %endif diff --git a/gsmartcontrol/src/gsc_main_window.cpp b/gsmartcontrol/src/gsc_main_window.cpp index 0832d49..bea36cd 100644 --- a/gsmartcontrol/src/gsc_main_window.cpp +++ b/gsmartcontrol/src/gsc_main_window.cpp @@ -262,6 +262,7 @@ bool GscMainWindow::create_widgets() " " " " + " " " " " " @@ -369,6 +370,10 @@ bool GscMainWindow::create_widgets() actiongroup_main->add((action_map[action_executor_log] = action), sigc::bind(sigc::mem_fun(*this, &self_type::on_action_activated), action_executor_log)); + action = Gtk::Action::create(APP_ACTION_NAME(action_update_drivedb), "Update Drive Database"); + actiongroup_main->add((action_map[action_update_drivedb] = action), + sigc::bind(sigc::mem_fun(*this, &self_type::on_action_activated), action_update_drivedb)); + action = Gtk::Action::create(APP_ACTION_NAME(action_preferences), Gtk::Stock::PREFERENCES); actiongroup_main->add((action_map[action_preferences] = action), Gtk::AccelKey("P"), sigc::bind(sigc::mem_fun(*this, &self_type::on_action_activated), action_preferences)); @@ -602,6 +607,12 @@ void GscMainWindow::on_action_activated(GscMainWindow::action_t action_type) break; } + case action_update_drivedb: + { + run_update_drivedb(); + break; + } + case action_preferences: { GscPreferencesWindow* win = GscPreferencesWindow::create(); // destroyed on close @@ -1125,6 +1136,35 @@ void GscMainWindow::rescan_devices() +void GscMainWindow::run_update_drivedb() +{ + std::string smartctl_binary = get_smartctl_binary(); + + if (smartctl_binary.empty()) { + gui_show_error_dialog("Error Updating Drive Database", "Smartctl binary is not specified in configuration.", this); + return; + } + + std::string update_binary; + hz::FsPath path(smartctl_binary); + if (path.is_absolute()) { + update_binary = path.get_dirname() + "/"; + } + update_binary += "update-smart-drivedb"; + update_binary = Glib::shell_quote(update_binary); + +#ifndef _WIN32 + update_binary = "xterm -hold -e " + update_binary; +#endif + + hz::scoped_ptr spawn_error(0, g_error_free); + if (!g_spawn_command_line_async(update_binary.c_str(), &spawn_error.get_ref())) { + gui_show_error_dialog("Error Updating Drive Database", spawn_error->message, this); + } +} + + + bool GscMainWindow::add_device(const std::string& file, const std::string& type_arg, const std::string& extra_args) { #ifndef _WIN32 // win32 doesn't have device files, so skip the check diff --git a/gsmartcontrol/src/gsc_main_window.h b/gsmartcontrol/src/gsc_main_window.h index bbfc918..444efa3 100644 --- a/gsmartcontrol/src/gsc_main_window.h +++ b/gsmartcontrol/src/gsc_main_window.h @@ -53,6 +53,10 @@ class GscMainWindow : public AppUIResWidget { void rescan_devices(); + /// Execute update-smart-drivedb + void run_update_drivedb(); + + /// Manually add device file to icon list bool add_device(const std::string& file, const std::string& type_arg, const std::string& extra_args); @@ -90,6 +94,7 @@ class GscMainWindow : public AppUIResWidget { action_rescan_devices, action_executor_log, + action_update_drivedb, action_preferences, action_general_help,