X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fsystemadm.vala;h=4cb5c55ef332403c8ee16601aa8cac12db357674;hb=8f38d5a4c6e627180809db739b2bdaa5ca0c645a;hp=e78fd7c4d40362597ebfd841546f93fc072099e4;hpb=a3c159a23c7cae889f89ed69bbe82c272bf163ca;p=elogind.git diff --git a/src/systemadm.vala b/src/systemadm.vala index e78fd7c4d..4cb5c55ef 100644 --- a/src/systemadm.vala +++ b/src/systemadm.vala @@ -46,12 +46,11 @@ public class LeftLabel : Label { } } -public class RightLabel : Label { +public class RightLabel : WrapLabel { + public RightLabel(string? text = null) { - set_text_or_na(text); - set_alignment(0, 0); - set_ellipsize(EllipsizeMode.START); set_selectable(true); + set_text_or_na(text); } public void set_text_or_na(string? text = null) { @@ -80,6 +79,8 @@ public class MainWindow : Window { private ListStore unit_model; private ListStore job_model; + private Gee.HashMap unit_map; + private Button start_button; private Button stop_button; private Button restart_button; @@ -95,7 +96,6 @@ public class MainWindow : Window { private Manager manager; private RightLabel unit_id_label; - private RightLabel unit_aliases_label; private RightLabel unit_dependency_label; private RightLabel unit_description_label; private RightLabel unit_load_state_label; @@ -138,13 +138,16 @@ public class MainWindow : Window { type_hbox.pack_start(unit_type_combo_box, false, false, 0); unit_vbox.pack_start(type_hbox, false, false, 0); - unit_type_combo_box.append_text("Show All"); + unit_type_combo_box.append_text("All unit types"); + unit_type_combo_box.append_text("Targets"); unit_type_combo_box.append_text("Services"); - unit_type_combo_box.append_text("Sockets"); unit_type_combo_box.append_text("Devices"); unit_type_combo_box.append_text("Mounts"); unit_type_combo_box.append_text("Automounts"); - unit_type_combo_box.append_text("Targets"); + unit_type_combo_box.append_text("Swaps"); + unit_type_combo_box.append_text("Sockets"); + unit_type_combo_box.append_text("Paths"); + unit_type_combo_box.append_text("Timers"); unit_type_combo_box.append_text("Snapshots"); unit_type_combo_box.set_active(0); // Show All unit_type_combo_box.changed.connect(unit_type_changed); @@ -178,6 +181,8 @@ public class MainWindow : Window { unit_model = new ListStore(7, typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(Unit)); job_model = new ListStore(6, typeof(string), typeof(string), typeof(string), typeof(string), typeof(Job), typeof(uint32)); + unit_map = new Gee.HashMap(); + TreeModelFilter unit_model_filter; unit_model_filter = new TreeModelFilter(unit_model, null); unit_model_filter.set_visible_func(unit_filter); @@ -214,7 +219,6 @@ public class MainWindow : Window { job_vbox.pack_start(scroll, true, true, 0); unit_id_label = new RightLabel(); - unit_aliases_label = new RightLabel(); unit_dependency_label = new RightLabel(); unit_description_label = new RightLabel(); unit_load_state_label = new RightLabel(); @@ -232,7 +236,7 @@ public class MainWindow : Window { job_type_label = new RightLabel(); unit_dependency_label.set_track_visited_links(false); - unit_dependency_label.set_selectable(false); + unit_dependency_label.set_selectable(true); unit_dependency_label.activate_link.connect(on_activate_link); unit_fragment_path_label.set_track_visited_links(false); @@ -249,8 +253,6 @@ public class MainWindow : Window { unit_table.attach(new LeftLabel("Id:"), 0, 1, 0, 1, AttachOptions.FILL, AttachOptions.FILL, 0, 0); unit_table.attach(unit_id_label, 1, 6, 0, 1, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(new LeftLabel("Aliases:"), 0, 1, 1, 2, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(unit_aliases_label, 1, 6, 1, 2, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); unit_table.attach(new LeftLabel("Description:"), 0, 1, 2, 3, AttachOptions.FILL, AttachOptions.FILL, 0, 0); unit_table.attach(unit_description_label, 1, 6, 2, 3, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); unit_table.attach(new LeftLabel("Dependencies:"), 0, 1, 3, 4, AttachOptions.FILL, AttachOptions.FILL, 0, 0); @@ -353,6 +355,8 @@ public class MainWindow : Window { "org.freedesktop.systemd1", i.unit_path); + unit_map[i.id] = u; + unit_model.append(out iter); unit_model.set(iter, 0, i.id, @@ -413,6 +417,10 @@ public class MainWindow : Window { return u; } + public Unit? get_unit(string id) { + return this.unit_map[id]; + } + public void unit_changed() { Unit u = get_current_unit(); @@ -431,7 +439,6 @@ public class MainWindow : Window { restart_button.set_sensitive(false); unit_id_label.set_text_or_na(); - unit_aliases_label.set_text_or_na(); unit_description_label.set_text_or_na(); unit_description_label.set_text_or_na(); unit_load_state_label.set_text_or_na(); @@ -445,7 +452,30 @@ public class MainWindow : Window { unit_cgroup_label.set_text_or_na(); } + public string format_unit_link(string i) { + Unit? u = get_unit(i); + if(u == null) + return "" + i + "" + + i + "(" + + u.sub_state + ")" + ""; + return " " + span + ""; + } + + public string make_dependency_string(string? prefix, string word, string[] dependencies) { + Gee.Collection sorted = new Gee.TreeSet(); + foreach (string i in dependencies) + sorted.add(i); + bool first = true; string r; @@ -454,16 +484,16 @@ public class MainWindow : Window { else r = prefix; - foreach (string i in dependencies) { + foreach (string i in sorted) { if (r != "") r += first ? "\n" : ","; if (first) { - r += word; + r += "" + word + ":"; first = false; } - r += " " + i + ""; + r += format_unit_link(i); } return r; @@ -472,20 +502,23 @@ public class MainWindow : Window { public void show_unit(Unit unit) { current_unit_id = unit.id; - unit_id_label.set_text_or_na(current_unit_id); - - string a = ""; + string id_display = current_unit_id; + bool has_alias = false; foreach (string i in unit.names) { if (i == current_unit_id) continue; - if (a == "") - a = i; - else - a += "\n" + i; + if (!has_alias) { + id_display += " (aliases:"; + has_alias = true; + } + + id_display += " " + i; } + if(has_alias) + id_display += ")"; - unit_aliases_label.set_text_or_na(a); + unit_id_label.set_text_or_na(id_display); string[] requires = unit.requires, @@ -607,7 +640,7 @@ public class MainWindow : Window { try { u.start("replace"); - } catch (IOError e) { + } catch (Error e) { show_error(e.message); } } @@ -620,7 +653,7 @@ public class MainWindow : Window { try { u.stop("replace"); - } catch (IOError e) { + } catch (Error e) { show_error(e.message); } } @@ -633,7 +666,7 @@ public class MainWindow : Window { try { u.reload("replace"); - } catch (IOError e) { + } catch (Error e) { show_error(e.message); } } @@ -646,7 +679,7 @@ public class MainWindow : Window { try { u.restart("replace"); - } catch (IOError e) { + } catch (Error e) { show_error(e.message); } } @@ -659,7 +692,7 @@ public class MainWindow : Window { try { j.cancel(); - } catch (IOError e) { + } catch (Error e) { show_error(e.message); } } @@ -687,7 +720,7 @@ public class MainWindow : Window { 4, u.sub_state, 5, t != "" ? "→ %s".printf(t) : "", 6, u); - } catch (IOError e) { + } catch (Error e) { show_error(e.message); } } @@ -710,8 +743,10 @@ public class MainWindow : Window { "org.freedesktop.systemd1", path); + unit_map[id] = u; + update_unit_iter(iter, id, u); - } catch (IOError e) { + } catch (Error e) { show_error(e.message); } } @@ -747,7 +782,7 @@ public class MainWindow : Window { update_job_iter(iter, id, j); - } catch (IOError e) { + } catch (Error e) { show_error(e.message); } } @@ -771,6 +806,8 @@ public class MainWindow : Window { } } while (unit_model.iter_next(ref iter)); + + unit_map.unset(id); } public void on_job_removed(uint32 id, ObjectPath path, string res) { @@ -827,7 +864,7 @@ public class MainWindow : Window { } while (unit_model.iter_next(ref iter)); - } catch (IOError e) { + } catch (Error e) { show_error(e.message); } } @@ -863,7 +900,7 @@ public class MainWindow : Window { } while (job_model.iter_next(ref iter)); - } catch (IOError e) { + } catch (Error e) { show_error(e.message); } } @@ -884,9 +921,9 @@ public class MainWindow : Window { case 0: return true; case 1: - return id.has_suffix(".service"); + return id.has_suffix(".target"); case 2: - return id.has_suffix(".socket"); + return id.has_suffix(".service"); case 3: return id.has_suffix(".device"); case 4: @@ -894,8 +931,14 @@ public class MainWindow : Window { case 5: return id.has_suffix(".automount"); case 6: - return id.has_suffix(".target"); + return id.has_suffix(".swap"); case 7: + return id.has_suffix(".socket"); + case 8: + return id.has_suffix(".path"); + case 9: + return id.has_suffix(".timer"); + case 10: return id.has_suffix(".snapshot"); default: assert(false); @@ -912,7 +955,7 @@ public class MainWindow : Window { public void on_server_reload() { try { manager.reload(); - } catch (IOError e) { + } catch (Error e) { show_error(e.message); } } @@ -924,7 +967,7 @@ public class MainWindow : Window { if (unit_type_combo_box.get_active() != 0) unit_type_combo_box.set_active(8); - } catch (IOError e) { + } catch (Error e) { show_error(e.message); } } @@ -953,7 +996,7 @@ public class MainWindow : Window { m.destroy(); show_unit(u); - } catch (IOError e) { + } catch (Error e) { show_error(e.message); } } @@ -973,7 +1016,7 @@ public class MainWindow : Window { path); show_unit(u); - } catch (IOError e) { + } catch (Error e) { show_error(e.message); }