X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=systemadm.vala;h=ac4c19ef652c857030094ca907955a7b905cea68;hp=d4b760ad1f0e7cb70b6e621077dd941947170ad1;hb=416f4a8457da80453dd69e67753a0190d6ec26d5;hpb=9ef5867847bcf8bce7aea5514f58a318359b84af diff --git a/systemadm.vala b/systemadm.vala index d4b760ad1..ac4c19ef6 100644 --- a/systemadm.vala +++ b/systemadm.vala @@ -66,6 +66,9 @@ public class MainWindow : Window { private Button reload_button; private Button cancel_button; + private Entry unit_load_entry; + private Button unit_load_button; + private Button server_snapshot_button; private Button server_reload_button; @@ -126,7 +129,19 @@ public class MainWindow : Window { unit_type_combo_box.set_active(1); unit_type_combo_box.changed += unit_type_changed; - server_snapshot_button = new Button.with_mnemonic("Take _Snapshot"); + unit_load_entry = new Entry(); + unit_load_button = new Button.with_mnemonic("_Load"); + unit_load_button.set_sensitive(false); + + unit_load_entry.changed += on_unit_load_entry_changed; + unit_load_entry.activate += on_unit_load; + unit_load_button.clicked += on_unit_load; + + Box unit_load_hbox = new HBox(false, 6); + unit_load_hbox.pack_start(unit_load_entry, false, true, 0); + unit_load_hbox.pack_start(unit_load_button, false, true, 0); + + server_snapshot_button = new Button.with_mnemonic("Take S_napshot"); server_reload_button = new Button.with_mnemonic("Reload _Configuration"); server_snapshot_button.clicked += on_server_snapshot; @@ -134,6 +149,7 @@ public class MainWindow : Window { type_hbox.pack_end(server_snapshot_button, false, true, 0); type_hbox.pack_end(server_reload_button, false, true, 0); + type_hbox.pack_end(unit_load_hbox, false, true, 24); 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)); @@ -297,6 +313,8 @@ public class MainWindow : Window { i.unit_path, "org.freedesktop.systemd1.Unit") as Unit; + u.changed += on_unit_changed; + unit_model.append(out iter); unit_model.set(iter, 0, i.id, @@ -322,6 +340,8 @@ public class MainWindow : Window { i.job_path, "org.freedesktop.systemd1.Job") as Job; + j.changed += on_job_changed; + job_model.append(out iter); job_model.set(iter, 0, "%u".printf(i.id), @@ -542,11 +562,7 @@ public class MainWindow : Window { } } - public void on_unit_new(string id, ObjectPath path) { - Unit u = bus.get_object( - "org.freedesktop.systemd1", - path, - "org.freedesktop.systemd1.Unit") as Unit; + public void update_unit_iter(TreeIter iter, string id, Unit u) { string t = ""; Unit.JobLink jl = u.job; @@ -560,8 +576,6 @@ public class MainWindow : Window { t = j.job_type; } - TreeIter iter; - unit_model.append(out iter); unit_model.set(iter, 0, id, 1, u.description, @@ -572,16 +586,22 @@ public class MainWindow : Window { 6, u); } - public void on_job_new(uint32 id, ObjectPath path) { - Job j = bus.get_object( + public void on_unit_new(string id, ObjectPath path) { + Unit u = bus.get_object( "org.freedesktop.systemd1", path, - "org.freedesktop.systemd1.Job") as Job; + "org.freedesktop.systemd1.Unit") as Unit; + + u.changed += on_unit_changed; TreeIter iter; - job_model.append(out iter); + unit_model.append(out iter); + update_unit_iter(iter, id, u); + } + + public void update_job_iter(TreeIter iter, uint32 id, Job j) { job_model.set(iter, - 0, "%u".printf(j.id), + 0, "%u".printf(id), 1, j.unit.id, 2, "→ %s".printf(j.job_type), 3, j.state, @@ -589,6 +609,19 @@ public class MainWindow : Window { 5, id); } + public void on_job_new(uint32 id, ObjectPath path) { + Job j = bus.get_object( + "org.freedesktop.systemd1", + path, + "org.freedesktop.systemd1.Job") as Job; + + j.changed += on_job_changed; + + TreeIter iter; + job_model.append(out iter); + update_job_iter(iter, id, j); + } + public void on_unit_removed(string id, ObjectPath path) { TreeIter iter; if (!(unit_model.get_iter_first(out iter))) @@ -632,10 +665,62 @@ public class MainWindow : Window { } while (job_model.iter_next(ref iter)); } + public void on_unit_changed(Unit u) { + TreeIter iter; + string id; + + if (!(unit_model.get_iter_first(out iter))) + return; + + id = u.id; + + do { + string name; + + unit_model.get(iter, 0, out name); + + if (id == name) { + update_unit_iter(iter, id, u); + + if (current_unit_id == id) + show_unit(u); + + break; + } + + } while (unit_model.iter_next(ref iter)); + } + + public void on_job_changed(Job j) { + TreeIter iter; + uint32 id; + + if (!(job_model.get_iter_first(out iter))) + return; + + id = j.id; + + do { + uint32 k; + + job_model.get(iter, 5, out k); + + if (id == k) { + update_job_iter(iter, id, j); + + if (current_job_id == id) + show_job(j); + + break; + } + + } while (job_model.iter_next(ref iter)); + } + public bool unit_filter(TreeModel model, TreeIter iter) { - string id, active_state; + string id, active_state, job; - model.get(iter, 0, out id, 3, out active_state); + model.get(iter, 0, out id, 3, out active_state, 5, out job); if (id == null) return false; @@ -646,7 +731,7 @@ public class MainWindow : Window { return true; case 1: - return active_state != "inactive"; + return active_state != "inactive" || job != ""; case 2: return id.has_suffix(".service"); @@ -699,11 +784,39 @@ public class MainWindow : Window { } } + public void on_unit_load() { + try { + var path = manager.load_unit(unit_load_entry.get_text()); + + Unit u = bus.get_object( + "org.freedesktop.systemd1", + path, + "org.freedesktop.systemd1.Unit") as Unit; + + var m = new MessageDialog(this, + DialogFlags.DESTROY_WITH_PARENT, + MessageType.INFO, + ButtonsType.CLOSE, + "Unit available as id %s", u.id); + m.title = "Unit"; + m.run(); + m.destroy(); + + } catch (DBus.Error e) { + show_error(e.message); + } + } + + public void on_unit_load_entry_changed() { + unit_load_button.set_sensitive(unit_load_entry.get_text() != ""); + } + public void show_error(string e) { var m = new MessageDialog(this, DialogFlags.DESTROY_WITH_PARENT, MessageType.ERROR, ButtonsType.CLOSE, "%s", e); + m.title = "Error"; m.run(); m.destroy(); }