private ComboBox unit_type_combo_box;
public MainWindow() throws DBus.Error {
- title = "systemdadm";
+ title = "systemadm";
position = WindowPosition.CENTER;
set_default_size(1000, 700);
set_border_width(12);
job_vbox.pack_start(job_table, false, true, 0);
unit_table.attach(new LeftLabel("Id:"), 0, 1, 0, 1, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
- unit_table.attach(unit_id_label, 1, 5, 0, 1, AttachOptions.EXPAND|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, 5, 1, 2, AttachOptions.EXPAND|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, 5, 2, 3, AttachOptions.EXPAND|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("Fragment Path:"), 0, 1, 3, 4, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
- unit_table.attach(unit_fragment_path_label, 1, 5, 3, 4, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
+ unit_table.attach(unit_fragment_path_label, 1, 6, 3, 4, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(new LeftLabel("Control Group:"), 0, 1, 4, 5, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
- unit_table.attach(unit_cgroup_label, 1, 5, 4, 5, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
+ unit_table.attach(unit_cgroup_label, 1, 6, 4, 5, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(new LeftLabel("Load State:"), 0, 1, 5, 6, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
unit_table.attach(unit_load_state_label, 1, 2, 5, 6, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
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,
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),
current_unit_id = unit.id;
unit_id_label.set_text_or_na(current_unit_id);
- unit_aliases_label.set_text_or_na(string.joinv("\n", unit.names));
+ string a = "";
+ foreach (string i in unit.names) {
+ if (i == current_unit_id)
+ continue;
+
+ if (a == "")
+ a = i;
+ else
+ a += "\n" + i;
+ }
+
+ unit_aliases_label.set_text_or_na(a);
unit_description_label.set_text_or_na(unit.description);
unit_load_state_label.set_text_or_na(unit.load_state);
unit_active_state_label.set_text_or_na(unit.active_state);
uint64 t = unit.active_enter_timestamp;
if (t > 0) {
- TimeVal tv = { (long) (t / 1000000), (long) (t % 1000000) };
- unit_active_enter_timestamp_label.set_text_or_na(tv.to_iso8601());
+ Time timestamp = Time.local((time_t) (t / 1000000));
+ unit_active_enter_timestamp_label.set_text_or_na(timestamp.format("%a, %d %b %Y %H:%M:%S %z"));
} else
unit_active_enter_timestamp_label.set_text_or_na();
t = unit.active_exit_timestamp;
if (t > 0) {
- TimeVal tv = { (long) (t / 1000000), (long) (t % 1000000) };
- unit_active_exit_timestamp_label.set_text_or_na(tv.to_iso8601());
+ Time timestamp = Time.local((time_t) (t / 1000000));
+ unit_active_exit_timestamp_label.set_text_or_na(timestamp.format("%a, %d %b %Y %H:%M:%S %z"));
} else
unit_active_exit_timestamp_label.set_text_or_na();
try {
u.start("replace");
} catch (DBus.Error e) {
- message("%s", e.message);
+ show_error(e.message);
}
}
try {
u.stop("replace");
} catch (DBus.Error e) {
- message("%s", e.message);
+ show_error(e.message);
}
}
try {
u.reload("replace");
} catch (DBus.Error e) {
- message("%s", e.message);
+ show_error(e.message);
}
}
try {
u.restart("replace");
} catch (DBus.Error e) {
- message("%s", e.message);
+ show_error(e.message);
}
}
try {
j.cancel();
} catch (DBus.Error e) {
- message("%s", e.message);
+ show_error(e.message);
}
}
- 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;
t = j.job_type;
}
- TreeIter iter;
- unit_model.append(out iter);
unit_model.set(iter,
0, id,
1, u.description,
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,
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)))
} 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;
return true;
case 1:
- return active_state != "inactive";
+ return active_state != "inactive" || job != "";
case 2:
return id.has_suffix(".service");
try {
manager.reload();
} catch (DBus.Error e) {
- message("%s", e.message);
+ show_error(e.message);
}
}
unit_type_combo_box.set_active(8);
} catch (DBus.Error e) {
- message("%s", e.message);
+ show_error(e.message);
}
}
+
+ public void show_error(string e) {
+ var m = new MessageDialog(this,
+ DialogFlags.DESTROY_WITH_PARENT,
+ MessageType.ERROR,
+ ButtonsType.CLOSE, "%s", e);
+ m.run();
+ m.destroy();
+ }
+
}
static const OptionEntry entries[] = {
{ null }
};
+void show_error(string e) {
+ var m = new MessageDialog(null, 0, MessageType.ERROR, ButtonsType.CLOSE, "%s", e);
+ m.run();
+ m.destroy();
+}
+
int main (string[] args) {
try {
MainWindow window = new MainWindow();
window.show_all();
+
+ Gtk.main();
} catch (DBus.Error e) {
- message("%s", e.message);
+ show_error(e.message);
} catch (GLib.Error e) {
- message("%s", e.message);
+ show_error(e.message);
}
- Gtk.main();
return 0;
}