diff options
author | Lennart Poettering <lennart@poettering.net> | 2008-07-01 00:03:01 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2008-07-01 00:03:01 +0200 |
commit | bdae4343e1c34dbdc55af307419354a7cfd2afd4 (patch) | |
tree | e11210729533deb072d25a10665595173c388933 | |
parent | b4519b2230c2fdaa179d4e7b788b695d40cfeb4f (diff) |
add basic self test support to g-d-h
-rw-r--r-- | gnome-disk-health.glade | 279 | ||||
-rw-r--r-- | gnome-disk-health.vala | 140 |
2 files changed, 270 insertions, 149 deletions
diff --git a/gnome-disk-health.glade b/gnome-disk-health.glade index 5453e84..c345aba 100644 --- a/gnome-disk-health.glade +++ b/gnome-disk-health.glade @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd"> -<!--Generated with glade3 3.4.4 on Mon Jun 30 04:28:55 2008 --> +<!--Generated with glade3 3.4.4 on Mon Jun 30 23:57:51 2008 --> <glade-interface> <widget class="GtkDialog" id="DiskHealthDialog"> <property name="border_width">5</property> @@ -48,66 +48,54 @@ <property name="column_spacing">6</property> <property name="row_spacing">6</property> <child> - <widget class="GtkLabel" id="firmwareLabel"> + <widget class="GtkLabel" id="label5"> <property name="visible">True</property> - <property name="xalign">0</property> - <property name="label" translatable="yes">label</property> + <property name="xalign">1</property> + <property name="label" translatable="yes"><b>Path:</b></property> + <property name="use_markup">True</property> </widget> <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">4</property> - <property name="bottom_attach">5</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options">GTK_FILL</property> </packing> </child> <child> - <widget class="GtkLabel" id="serialLabel"> + <widget class="GtkLabel" id="label6"> <property name="visible">True</property> - <property name="xalign">0</property> - <property name="label" translatable="yes">label</property> + <property name="xalign">1</property> + <property name="label" translatable="yes"><b>Size:</b></property> + <property name="use_markup">True</property> </widget> <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">3</property> - <property name="bottom_attach">4</property> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + <property name="x_options">GTK_FILL</property> </packing> </child> <child> - <widget class="GtkLabel" id="modelLabel"> + <widget class="GtkLabel" id="label7"> <property name="visible">True</property> - <property name="xalign">0</property> - <property name="label" translatable="yes">label</property> + <property name="xalign">1</property> + <property name="label" translatable="yes"><b>Model:</b></property> + <property name="use_markup">True</property> </widget> <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> <property name="top_attach">2</property> <property name="bottom_attach">3</property> + <property name="x_options">GTK_FILL</property> </packing> </child> <child> - <widget class="GtkLabel" id="sizeLabel"> - <property name="visible">True</property> - <property name="xalign">0</property> - <property name="label" translatable="yes">label</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - </packing> - </child> - <child> - <widget class="GtkLabel" id="pathLabel"> + <widget class="GtkLabel" id="label8"> <property name="visible">True</property> - <property name="xalign">0</property> - <property name="label" translatable="yes">label</property> + <property name="xalign">1</property> + <property name="label" translatable="yes"><b>Serial Number:</b></property> + <property name="use_markup">True</property> </widget> <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> + <property name="top_attach">3</property> + <property name="bottom_attach">4</property> + <property name="x_options">GTK_FILL</property> </packing> </child> <child> @@ -124,54 +112,66 @@ </packing> </child> <child> - <widget class="GtkLabel" id="label8"> + <widget class="GtkLabel" id="pathLabel"> <property name="visible">True</property> - <property name="xalign">1</property> - <property name="label" translatable="yes"><b>Serial Number:</b></property> - <property name="use_markup">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">label</property> </widget> <packing> - <property name="top_attach">3</property> - <property name="bottom_attach">4</property> - <property name="x_options">GTK_FILL</property> + <property name="left_attach">1</property> + <property name="right_attach">2</property> </packing> </child> <child> - <widget class="GtkLabel" id="label7"> + <widget class="GtkLabel" id="sizeLabel"> <property name="visible">True</property> - <property name="xalign">1</property> - <property name="label" translatable="yes"><b>Model:</b></property> - <property name="use_markup">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">label</property> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + </packing> + </child> + <child> + <widget class="GtkLabel" id="modelLabel"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">label</property> </widget> <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> <property name="top_attach">2</property> <property name="bottom_attach">3</property> - <property name="x_options">GTK_FILL</property> </packing> </child> <child> - <widget class="GtkLabel" id="label6"> + <widget class="GtkLabel" id="serialLabel"> <property name="visible">True</property> - <property name="xalign">1</property> - <property name="label" translatable="yes"><b>Size:</b></property> - <property name="use_markup">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">label</property> </widget> <packing> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options">GTK_FILL</property> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">3</property> + <property name="bottom_attach">4</property> </packing> </child> <child> - <widget class="GtkLabel" id="label5"> + <widget class="GtkLabel" id="firmwareLabel"> <property name="visible">True</property> - <property name="xalign">1</property> - <property name="label" translatable="yes"><b>Path:</b></property> - <property name="use_markup">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">label</property> </widget> <packing> - <property name="x_options">GTK_FILL</property> - <property name="y_options">GTK_FILL</property> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">4</property> + <property name="bottom_attach">5</property> </packing> </child> </widget> @@ -299,58 +299,67 @@ <property name="column_spacing">6</property> <property name="row_spacing">6</property> <child> - <widget class="GtkLabel" id="verdictLabel"> + <widget class="GtkLabel" id="label21"> <property name="visible">True</property> - <property name="xalign">0</property> - <property name="label" translatable="yes">label</property> + <property name="xalign">1</property> + <property name="label" translatable="yes"><b>Name:</b></property> + <property name="use_markup">True</property> </widget> <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">6</property> - <property name="bottom_attach">7</property> <property name="x_options">GTK_FILL</property> <property name="y_options">GTK_FILL</property> </packing> </child> <child> - <widget class="GtkLabel" id="label33"> + <widget class="GtkLabel" id="label22"> <property name="visible">True</property> <property name="xalign">1</property> - <property name="label" translatable="yes"><b>Verdict:</b></property> + <property name="label" translatable="yes"><b>ID:</b></property> <property name="use_markup">True</property> </widget> <packing> - <property name="top_attach">6</property> - <property name="bottom_attach">7</property> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> <property name="x_options">GTK_FILL</property> <property name="y_options">GTK_FILL</property> </packing> </child> <child> - <widget class="GtkLabel" id="typeLabel"> + <widget class="GtkLabel" id="label23"> <property name="visible">True</property> - <property name="xalign">0</property> - <property name="label" translatable="yes">label</property> + <property name="xalign">1</property> + <property name="label" translatable="yes"><b>Current Value:</b></property> + <property name="use_markup">True</property> </widget> <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">5</property> - <property name="bottom_attach">6</property> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> <property name="x_options">GTK_FILL</property> <property name="y_options">GTK_FILL</property> </packing> </child> <child> - <widget class="GtkLabel" id="thresholdLabel"> + <widget class="GtkLabel" id="label24"> <property name="visible">True</property> - <property name="xalign">0</property> - <property name="label" translatable="yes">label</property> + <property name="xalign">1</property> + <property name="label" translatable="yes"><b>Worst Value:</b></property> + <property name="use_markup">True</property> + </widget> + <packing> + <property name="top_attach">3</property> + <property name="bottom_attach">4</property> + <property name="x_options">GTK_FILL</property> + <property name="y_options">GTK_FILL</property> + </packing> + </child> + <child> + <widget class="GtkLabel" id="label25"> + <property name="visible">True</property> + <property name="xalign">1</property> + <property name="label" translatable="yes"><b>Threshold:</b></property> + <property name="use_markup">True</property> </widget> <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> <property name="top_attach">4</property> <property name="bottom_attach">5</property> <property name="x_options">GTK_FILL</property> @@ -358,22 +367,21 @@ </packing> </child> <child> - <widget class="GtkLabel" id="worstLabel"> + <widget class="GtkLabel" id="label26"> <property name="visible">True</property> - <property name="xalign">0</property> - <property name="label" translatable="yes">label</property> + <property name="xalign">1</property> + <property name="label" translatable="yes"><b>Type:</b></property> + <property name="use_markup">True</property> </widget> <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">3</property> - <property name="bottom_attach">4</property> + <property name="top_attach">5</property> + <property name="bottom_attach">6</property> <property name="x_options">GTK_FILL</property> <property name="y_options">GTK_FILL</property> </packing> </child> <child> - <widget class="GtkLabel" id="currentLabel"> + <widget class="GtkLabel" id="nameLabel"> <property name="visible">True</property> <property name="xalign">0</property> <property name="label" translatable="yes">label</property> @@ -381,8 +389,6 @@ <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> - <property name="top_attach">2</property> - <property name="bottom_attach">3</property> <property name="x_options">GTK_FILL</property> <property name="y_options">GTK_FILL</property> </packing> @@ -403,7 +409,7 @@ </packing> </child> <child> - <widget class="GtkLabel" id="nameLabel"> + <widget class="GtkLabel" id="currentLabel"> <property name="visible">True</property> <property name="xalign">0</property> <property name="label" translatable="yes">label</property> @@ -411,32 +417,36 @@ <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> <property name="x_options">GTK_FILL</property> <property name="y_options">GTK_FILL</property> </packing> </child> <child> - <widget class="GtkLabel" id="label26"> + <widget class="GtkLabel" id="worstLabel"> <property name="visible">True</property> - <property name="xalign">1</property> - <property name="label" translatable="yes"><b>Type:</b></property> - <property name="use_markup">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">label</property> </widget> <packing> - <property name="top_attach">5</property> - <property name="bottom_attach">6</property> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">3</property> + <property name="bottom_attach">4</property> <property name="x_options">GTK_FILL</property> <property name="y_options">GTK_FILL</property> </packing> </child> <child> - <widget class="GtkLabel" id="label25"> + <widget class="GtkLabel" id="thresholdLabel"> <property name="visible">True</property> - <property name="xalign">1</property> - <property name="label" translatable="yes"><b>Threshold:</b></property> - <property name="use_markup">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">label</property> </widget> <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> <property name="top_attach">4</property> <property name="bottom_attach">5</property> <property name="x_options">GTK_FILL</property> @@ -444,55 +454,45 @@ </packing> </child> <child> - <widget class="GtkLabel" id="label24"> - <property name="visible">True</property> - <property name="xalign">1</property> - <property name="label" translatable="yes"><b>Worst Value:</b></property> - <property name="use_markup">True</property> - </widget> - <packing> - <property name="top_attach">3</property> - <property name="bottom_attach">4</property> - <property name="x_options">GTK_FILL</property> - <property name="y_options">GTK_FILL</property> - </packing> - </child> - <child> - <widget class="GtkLabel" id="label23"> + <widget class="GtkLabel" id="typeLabel"> <property name="visible">True</property> - <property name="xalign">1</property> - <property name="label" translatable="yes"><b>Current Value:</b></property> - <property name="use_markup">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">label</property> </widget> <packing> - <property name="top_attach">2</property> - <property name="bottom_attach">3</property> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">5</property> + <property name="bottom_attach">6</property> <property name="x_options">GTK_FILL</property> <property name="y_options">GTK_FILL</property> </packing> </child> <child> - <widget class="GtkLabel" id="label22"> + <widget class="GtkLabel" id="label33"> <property name="visible">True</property> <property name="xalign">1</property> - <property name="label" translatable="yes"><b>ID:</b></property> + <property name="label" translatable="yes"><b>Verdict:</b></property> <property name="use_markup">True</property> </widget> <packing> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> + <property name="top_attach">6</property> + <property name="bottom_attach">7</property> <property name="x_options">GTK_FILL</property> <property name="y_options">GTK_FILL</property> </packing> </child> <child> - <widget class="GtkLabel" id="label21"> + <widget class="GtkLabel" id="verdictLabel"> <property name="visible">True</property> - <property name="xalign">1</property> - <property name="label" translatable="yes"><b>Name:</b></property> - <property name="use_markup">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">label</property> </widget> <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">6</property> + <property name="bottom_attach">7</property> <property name="x_options">GTK_FILL</property> <property name="y_options">GTK_FILL</property> </packing> @@ -540,12 +540,12 @@ <property name="visible">True</property> <property name="spacing">6</property> <child> - <widget class="GtkProgressBar" id="progressbar1"> + <widget class="GtkProgressBar" id="selfTestProgressBar"> <property name="visible">True</property> </widget> </child> <child> - <widget class="GtkButton" id="button2"> + <widget class="GtkButton" id="selfTestButton"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> @@ -563,9 +563,10 @@ </packing> </child> <child> - <widget class="GtkLabel" id="label10"> + <widget class="GtkLabel" id="selfTestLabel"> <property name="visible">True</property> <property name="label" translatable="yes">Self-test functionality available. Approximate run-time is 120 min.</property> + <property name="justify">GTK_JUSTIFY_CENTER</property> <property name="wrap">True</property> </widget> <packing> @@ -599,7 +600,7 @@ <property name="visible">True</property> <property name="layout_style">GTK_BUTTONBOX_END</property> <child> - <widget class="GtkButton" id="button1"> + <widget class="GtkButton" id="closeButton"> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> diff --git a/gnome-disk-health.vala b/gnome-disk-health.vala index 6bf064c..9595f15 100644 --- a/gnome-disk-health.vala +++ b/gnome-disk-health.vala @@ -33,11 +33,17 @@ public class DiskHealth : Gtk.Builder { add_from_file (uifile); Gtk.Widget window = (Gtk.Widget) get_object("DiskHealthDialog"); - if (!fill_in_data(disk_string)) + if (!setup_connection(disk_string)) + return false; + + if (!fill_in_data()) return false; window.show_all(); window.destroy += Gtk.main_quit; + + ((Gtk.Button) get_object("closeButton")).clicked += Gtk.main_quit; + } catch (GLib.Error e) { stderr.printf("Failed to create main window: %s\n", e.message); return false; @@ -51,8 +57,7 @@ public class DiskHealth : Gtk.Builder { private DBus.ObjectPath dbus_path; private dynamic DBus.Object disk; - public bool fill_in_data(string disk_string) { - + public bool setup_connection(string disk_string) { try { connection = DBus.Bus.get(DBus.BusType.SYSTEM); @@ -73,7 +78,17 @@ public class DiskHealth : Gtk.Builder { stderr.printf("Using D-Bus path %s\n", p); disk = connection.get_object("net.poettering.SmartKit", p, "net.poettering.SmartKit.Disk"); + } catch (DBus.Error e) { + stderr.printf("D-Bus error: %s\n", e.message); + return false; + } + + return true; + } + + public bool fill_in_data() { + try { ((Gtk.Label) get_object("pathLabel")).set_label(disk.getPath()); ((Gtk.Label) get_object("sizeLabel")).set_label(pretty_size(disk.getSize())); @@ -92,15 +107,112 @@ public class DiskHealth : Gtk.Builder { if (b) b = disk.isSmartAvailable(); - if (b) { - ((Gtk.Label) get_object("smartLabel")).set_label("Disk health functionality (S.M.A.R.T.) is available."); - } else { - ((Gtk.Label) get_object("smartLabel")).set_markup("Disk health functionality (S.M.A.R.T.) is <b>not</b> available."); - ((Gtk.Label) get_object("healthLabel")).set_label(""); - ((Gtk.Label) get_object("badSectorsLabel")).set_label(""); - ((Gtk.Label) get_object("temperatureLabel")).set_label(""); + if (b) + return fill_in_smart_data(); + else + return fill_in_no_smart_data(); + + } catch (DBus.Error e) { + stderr.printf("D-Bus error: %s\n", e.message); + return false; + } + } + + public bool fill_in_no_smart_data() { + + ((Gtk.Label) get_object("smartLabel")).set_markup("Disk health functionality (S.M.A.R.T.) is <b>not</b> available."); + ((Gtk.Label) get_object("healthLabel")).set_label(""); + ((Gtk.Label) get_object("badSectorsLabel")).set_label(""); + ((Gtk.Label) get_object("temperatureLabel")).set_label(""); + + return fill_in_no_self_test_data(); + } + + public bool fill_in_smart_data() { + try { + + ((Gtk.Label) get_object("smartLabel")).set_label("Disk health functionality (S.M.A.R.T.) is available."); + + bool b = disk.checkSmartStatus(); + + if (b) + ((Gtk.Label) get_object("healthLabel")).set_label("Disk reports to be healthy."); + else + ((Gtk.Label) get_object("healthLabel")).set_label("Disk reports that it has already failed or is expected to fail in the next 24h."); + + bool a = disk.getStartTestAvailable(); + b = disk.getConveyanceTestAvailable(); + bool c = disk.getShortAndExtendedTestAvailable(); + + if (a && (b || c)) + return fill_in_self_test_data(); + else + return fill_in_no_self_test_data(); + + } catch (DBus.Error e) { + stderr.printf("D-Bus error: %s\n", e.message); + return false; + } + } + + public bool fill_in_self_test_data() { + try { + bool show_percent = false; + string text; + + string state = disk.getSelfTestExecutionStatus(); + + switch (state) { + case "success-or-never": + text = "The previous self-test completed without error or no self-test has ever been run."; + break; + case "aborted": + text = "The previous self-test was aborted by the user."; + break; + case "interrupted": + text = "The previous self-test was interrupted by the host with a hardware or software reset."; + break; + case "fatal": + text = "A fatal error or unknown test error occurred while the device was executing the previous self-test and the device was unable to complete the self-test."; + break; + case "error-unknown": + text = "The previous self-test completed having a test element that failed."; + break; + case "error-electrical": + text = "The previous self-test completed having the electrical element of the test failed."; + break; + case "eror-servo": + text = "The previous self-test completed having the servo (and/or seek) test element of the test failed."; + break; + case "error-read": + text = "The previous self-test completed having the read element of the test failed."; + break; + case "error-handling": + text = "The previous self-test completed having a test element that failed and the device is suspected of having handling damage."; + break; + case "inprogress": + text = "Self-test in progres..."; + show_percent = true; + break; + + default: + text = "Unknown state"; + break; } + + ((Gtk.Label) get_object("selfTestLabel")).set_label(text); + + if (show_percent) { + uint percent = disk.getSelfTestExecutionPercentRemaining(); + + ((Gtk.ProgressBar) get_object("selfTestProgressBar")).set_fraction((double) (100-percent)/100); + ((Gtk.ProgressBar) get_object("selfTestProgressBar")).set_text("%u%% remaining".printf(percent)); + } else + ((Gtk.ProgressBar) get_object("selfTestProgressBar")).set_text("n/a"); + + ((Gtk.ProgressBar) get_object("selfTestProgressBar")).set_sensitive(show_percent); + } catch (DBus.Error e) { stderr.printf("D-Bus error: %s\n", e.message); return false; @@ -109,6 +221,14 @@ public class DiskHealth : Gtk.Builder { return true; } + public bool fill_in_no_self_test_data() { + ((Gtk.Label) get_object("selfTestLabel")).set_label("Self-test functionality is not available."); + ((Gtk.Button) get_object("selfTestButton")).set_sensitive(false); + ((Gtk.ProgressBar) get_object("selfTestProgressBar")).set_sensitive(false); + + return true; + } + public static string pretty_size(uint64 size) { if (size >= (uint64)1024*(uint64)1024*(uint64)1024*(uint64)1024) |