chiark / gitweb /
systemadm: destroy error dialog boxes properly
[elogind.git] / systemadm.vala
index bc4f9403e62c14709027ede7b7c323cf79e3dd67..fdc84648dc2cb1108ee214f5b1d761274b918c22 100644 (file)
@@ -22,11 +22,13 @@ using GLib;
 using DBus;
 using Pango;
 
+static bool session = false;
+
 public class LeftLabel : Label {
         public LeftLabel(string? text = null) {
                 if (text != null)
                         set_markup("<b>%s</b>".printf(text));
-                set_alignment(1, 0);
+                set_alignment(0, 0);
                 set_padding(6, 0);
         }
 }
@@ -34,7 +36,7 @@ public class LeftLabel : Label {
 public class RightLabel : Label {
         public RightLabel(string? text = null) {
                 set_text_or_na(text);
-                set_alignment(0, 1);
+                set_alignment(0, 0);
                 set_ellipsize(EllipsizeMode.START);
                 set_selectable(true);
         }
@@ -49,6 +51,9 @@ public class RightLabel : Label {
 
 public class MainWindow : Window {
 
+        private string? current_unit_id;
+        private uint32 current_job_id;
+
         private TreeView unit_view;
         private TreeView job_view;
 
@@ -61,23 +66,31 @@ public class MainWindow : Window {
         private Button reload_button;
         private Button cancel_button;
 
+        private Button server_snapshot_button;
+        private Button server_reload_button;
+
         private Connection bus;
         private Manager manager;
 
         private RightLabel unit_id_label;
+        private RightLabel unit_aliases_label;
         private RightLabel unit_description_label;
         private RightLabel unit_load_state_label;
         private RightLabel unit_active_state_label;
+        private RightLabel unit_sub_state_label;
         private RightLabel unit_fragment_path_label;
         private RightLabel unit_active_enter_timestamp_label;
         private RightLabel unit_active_exit_timestamp_label;
         private RightLabel unit_can_start_label;
         private RightLabel unit_can_reload_label;
+        private RightLabel unit_cgroup_label;
 
         private RightLabel job_id_label;
         private RightLabel job_state_label;
         private RightLabel job_type_label;
 
+        private ComboBox unit_type_combo_box;
+
         public MainWindow() throws DBus.Error {
                 title = "systemdadm";
                 position = WindowPosition.CENTER;
@@ -88,29 +101,58 @@ public class MainWindow : Window {
                 Notebook notebook = new Notebook();
                 add(notebook);
 
-                Box unit_vbox = new VBox(false, 6);
+                Box unit_vbox = new VBox(false, 12);
                 notebook.append_page(unit_vbox, new Label("Units"));
                 unit_vbox.set_border_width(12);
 
-                Box job_vbox = new VBox(false, 6);
+                Box job_vbox = new VBox(false, 12);
                 notebook.append_page(job_vbox, new Label("Jobs"));
                 job_vbox.set_border_width(12);
 
+                unit_type_combo_box = new ComboBox.text();
+                Box type_hbox = new HBox(false, 6);
+                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 Units");
+                unit_type_combo_box.append_text("Show Only Live Units");
+                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("Snapshots");
+                unit_type_combo_box.set_active(1);
+                unit_type_combo_box.changed += unit_type_changed;
 
-                unit_model = new ListStore(6, typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(Unit));
-                job_model = new ListStore(5, typeof(string), typeof(string), typeof(string), typeof(string), typeof(Job));
+                server_snapshot_button = new Button.with_mnemonic("Take _Snapshot");
+                server_reload_button = new Button.with_mnemonic("Reload _Configuration");
 
-                unit_view = new TreeView.with_model(unit_model);
+                server_snapshot_button.clicked += on_server_snapshot;
+                server_reload_button.clicked += on_server_reload;
+
+                type_hbox.pack_end(server_snapshot_button, false, true, 0);
+                type_hbox.pack_end(server_reload_button, false, true, 0);
+
+                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));
+
+                TreeModelFilter unit_model_filter;
+                unit_model_filter = new TreeModelFilter(unit_model, null);
+                unit_model_filter.set_visible_func(unit_filter);
+
+                unit_view = new TreeView.with_model(unit_model_filter);
                 job_view = new TreeView.with_model(job_model);
 
                 unit_view.cursor_changed += unit_changed;
                 job_view.cursor_changed += job_changed;
 
-                unit_view.insert_column_with_attributes(-1, "Unit", new CellRendererText(), "text", 0);
-                unit_view.insert_column_with_attributes(-1, "Description", new CellRendererText(), "text", 1);
                 unit_view.insert_column_with_attributes(-1, "Load State", new CellRendererText(), "text", 2);
                 unit_view.insert_column_with_attributes(-1, "Active State", new CellRendererText(), "text", 3);
-                unit_view.insert_column_with_attributes(-1, "Job", new CellRendererText(), "text", 4);
+                unit_view.insert_column_with_attributes(-1, "Unit State", new CellRendererText(), "text", 4);
+                unit_view.insert_column_with_attributes(-1, "Unit", new CellRendererText(), "text", 0);
+                unit_view.insert_column_with_attributes(-1, "Job", new CellRendererText(), "text", 5);
 
                 job_view.insert_column_with_attributes(-1, "Job", new CellRendererText(), "text", 0);
                 job_view.insert_column_with_attributes(-1, "Unit", new CellRendererText(), "text", 1);
@@ -130,54 +172,66 @@ public class MainWindow : Window {
                 job_vbox.pack_start(scroll, true, true, 0);
 
                 unit_id_label = new RightLabel();
+                unit_aliases_label = new RightLabel();
                 unit_description_label = new RightLabel();
                 unit_load_state_label = new RightLabel();
                 unit_active_state_label = new RightLabel();
+                unit_sub_state_label = new RightLabel();
                 unit_fragment_path_label = new RightLabel();
                 unit_active_enter_timestamp_label = new RightLabel();
                 unit_active_exit_timestamp_label = new RightLabel();
                 unit_can_start_label = new RightLabel();
                 unit_can_reload_label = new RightLabel();
+                unit_cgroup_label = new RightLabel();
 
                 job_id_label = new RightLabel();
                 job_state_label = new RightLabel();
                 job_type_label = new RightLabel();
 
-                Table unit_table = new Table(9, 2, false);
+                Table unit_table = new Table(8, 6, false);
                 unit_table.set_row_spacings(6);
-                unit_table.set_border_width(12);
+                unit_table.set_border_width(0);
                 unit_vbox.pack_start(unit_table, false, true, 0);
 
                 Table job_table = new Table(2, 2, false);
                 job_table.set_row_spacings(6);
-                job_table.set_border_width(12);
+                job_table.set_border_width(0);
                 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, 2, 0, 1, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-                unit_table.attach(new LeftLabel("Description:"), 0, 1, 1, 2, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-                unit_table.attach(unit_description_label, 1, 2, 1, 2, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-                unit_table.attach(new LeftLabel("Load State:"), 0, 1, 2, 3, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-                unit_table.attach(unit_load_state_label, 1, 2, 2, 3, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-                unit_table.attach(new LeftLabel("Active State:"), 0, 1, 3, 4, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-                unit_table.attach(unit_active_state_label, 1, 2, 3, 4, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-                unit_table.attach(new LeftLabel("Fragment Path:"), 0, 1, 4, 5, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-                unit_table.attach(unit_fragment_path_label, 1, 2, 4, 5, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-                unit_table.attach(new LeftLabel("Active Enter Timestamp:"), 0, 1, 5, 6, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-                unit_table.attach(unit_active_enter_timestamp_label, 1, 2, 5, 6, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-                unit_table.attach(new LeftLabel("Active Exit Timestamp:"), 0, 1, 6, 7, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-                unit_table.attach(unit_active_exit_timestamp_label, 1, 2, 6, 7, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-                unit_table.attach(new LeftLabel("Can Start/Stop:"), 0, 1, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-                unit_table.attach(unit_can_start_label, 1, 2, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-                unit_table.attach(new LeftLabel("Can Reload:"), 0, 1, 8, 9, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-                unit_table.attach(unit_can_reload_label, 1, 2, 8, 9, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-
-                job_table.attach(new LeftLabel("Id:"), 0, 1, 0, 1, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-                job_table.attach(job_id_label, 1, 2, 0, 1, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-                job_table.attach(new LeftLabel("State:"), 0, 1, 1, 2, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-                job_table.attach(job_state_label, 1, 2, 1, 2, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-                job_table.attach(new LeftLabel("Type:"), 0, 1, 2, 3, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
-                job_table.attach(job_type_label, 1, 2, 2, 3, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
+                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("Fragment Path:"),          0, 1, 3, 4, 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, 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);
+                unit_table.attach(new LeftLabel("Active State:"),           0, 1, 6, 7, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
+                unit_table.attach(unit_active_state_label,                  1, 2, 6, 7, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
+                unit_table.attach(new LeftLabel("Unit State:"),             0, 1, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
+                unit_table.attach(unit_sub_state_label,                     1, 2, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
+
+                unit_table.attach(new LeftLabel("Active Enter Timestamp:"), 2, 3, 6, 7, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
+                unit_table.attach(unit_active_enter_timestamp_label,        3, 4, 6, 7, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
+                unit_table.attach(new LeftLabel("Active Exit Timestamp:"),  2, 3, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
+                unit_table.attach(unit_active_exit_timestamp_label,         3, 4, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
+
+                unit_table.attach(new LeftLabel("Can Start/Stop:"),         4, 5, 6, 7, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
+                unit_table.attach(unit_can_start_label,                     5, 6, 6, 7, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
+                unit_table.attach(new LeftLabel("Can Reload:"),             4, 5, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
+                unit_table.attach(unit_can_reload_label,                    5, 6, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
+
+                job_table.attach(new LeftLabel("Id:"),                      0, 1, 0, 1, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
+                job_table.attach(job_id_label,                              1, 2, 0, 1, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
+                job_table.attach(new LeftLabel("State:"),                   0, 1, 1, 2, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
+                job_table.attach(job_state_label,                           1, 2, 1, 2, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
+                job_table.attach(new LeftLabel("Type:"),                    0, 1, 2, 3, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
+                job_table.attach(job_type_label,                            1, 2, 2, 3, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
 
                 ButtonBox bbox = new HButtonBox();
                 bbox.set_layout(ButtonBoxStyle.START);
@@ -210,12 +264,12 @@ public class MainWindow : Window {
 
                 bbox.pack_start(cancel_button, false, true, 0);
 
-                bus = Bus.get(BusType.SESSION);
+                bus = Bus.get(session ? BusType.SESSION : BusType.SYSTEM);
 
                 manager = bus.get_object(
                                 "org.freedesktop.systemd1",
                                 "/org/freedesktop/systemd1",
-                                "org.freedesktop.systemd1") as Manager;
+                                "org.freedesktop.systemd1.Manager") as Manager;
 
                 manager.unit_new += on_unit_new;
                 manager.job_new += on_job_new;
@@ -225,6 +279,7 @@ public class MainWindow : Window {
                 manager.subscribe();
 
                 clear_unit();
+                clear_job();
                 populate_unit_model();
                 populate_job_model();
         }
@@ -248,8 +303,9 @@ public class MainWindow : Window {
                                        1, i.description,
                                        2, i.load_state,
                                        3, i.active_state,
-                                       4, i.job_type != "" ? "→ %s".printf(i.job_type) : "",
-                                       5, u);
+                                       4, i.sub_state,
+                                       5, i.job_type != "" ? "→ %s".printf(i.job_type) : "",
+                                       6, u);
                 }
         }
 
@@ -272,7 +328,8 @@ public class MainWindow : Window {
                                       1, i.name,
                                       2, "→ %s".printf(i.type),
                                       3, i.state,
-                                      4, j);
+                                      4, j,
+                                      5, i.id);
                 }
         }
 
@@ -283,11 +340,12 @@ public class MainWindow : Window {
                 if (p == null)
                         return null;
 
+                TreeModel model = unit_view.get_model();
                 TreeIter iter;
                 Unit u;
 
-                unit_model.get_iter(out iter, p);
-                unit_model.get(iter, 5, out u);
+                model.get_iter(out iter, p);
+                model.get(iter, 6, out u);
 
                 return u;
         }
@@ -302,40 +360,61 @@ public class MainWindow : Window {
         }
 
         public void clear_unit() {
+                current_unit_id = null;
+
                 start_button.set_sensitive(false);
                 stop_button.set_sensitive(false);
                 reload_button.set_sensitive(false);
                 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_load_state_label.set_text_or_na();
                 unit_active_state_label.set_text_or_na();
+                unit_sub_state_label.set_text_or_na();
                 unit_fragment_path_label.set_text_or_na();
                 unit_active_enter_timestamp_label.set_text_or_na();
                 unit_active_exit_timestamp_label.set_text_or_na();
                 unit_can_reload_label.set_text_or_na();
                 unit_can_start_label.set_text_or_na();
+                unit_cgroup_label.set_text_or_na();
         }
 
         public void show_unit(Unit unit) {
-                unit_id_label.set_text_or_na(unit.id);
+                current_unit_id = unit.id;
+
+                unit_id_label.set_text_or_na(current_unit_id);
+
+                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);
+                unit_sub_state_label.set_text_or_na(unit.sub_state);
                 unit_fragment_path_label.set_text_or_na(unit.fragment_path);
 
                 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();
 
@@ -348,6 +427,8 @@ public class MainWindow : Window {
                 b = unit.can_reload;
                 reload_button.set_sensitive(b);
                 unit_can_reload_label.set_text_or_na(b ? "Yes" : "No");
+
+                unit_cgroup_label.set_text_or_na(unit.default_control_group);
         }
 
         public Job? get_current_job() {
@@ -358,10 +439,11 @@ public class MainWindow : Window {
                         return null;
 
                 TreeIter iter;
+                TreeModel model = job_view.get_model();
                 Job *j;
 
-                job_model.get_iter(out iter, p);
-                job_model.get(iter, 4, out j);
+                model.get_iter(out iter, p);
+                model.get(iter, 4, out j);
 
                 return j;
         }
@@ -376,15 +458,23 @@ public class MainWindow : Window {
         }
 
         public void clear_job() {
+                current_job_id = 0;
+
                 job_id_label.set_text_or_na();
                 job_state_label.set_text_or_na();
                 job_type_label.set_text_or_na();
+
+                cancel_button.set_sensitive(false);
         }
 
         public void show_job(Job job) {
-                job_id_label.set_text_or_na("%u".printf(job.id));
+                current_job_id = job.id;
+
+                job_id_label.set_text_or_na("%u".printf(current_job_id));
                 job_state_label.set_text_or_na(job.state);
                 job_type_label.set_text_or_na(job.job_type);
+
+                cancel_button.set_sensitive(true);
         }
 
         public void on_start() {
@@ -396,7 +486,7 @@ public class MainWindow : Window {
                 try {
                         u.start("replace");
                 } catch (DBus.Error e) {
-                        message("%s", e.message);
+                        show_error(e.message);
                 }
         }
 
@@ -409,7 +499,7 @@ public class MainWindow : Window {
                 try {
                         u.stop("replace");
                 } catch (DBus.Error e) {
-                        message("%s", e.message);
+                        show_error(e.message);
                 }
         }
 
@@ -422,7 +512,7 @@ public class MainWindow : Window {
                 try {
                         u.reload("replace");
                 } catch (DBus.Error e) {
-                        message("%s", e.message);
+                        show_error(e.message);
                 }
         }
 
@@ -435,7 +525,7 @@ public class MainWindow : Window {
                 try {
                         u.restart("replace");
                 } catch (DBus.Error e) {
-                        message("%s", e.message);
+                        show_error(e.message);
                 }
         }
 
@@ -448,13 +538,11 @@ public class MainWindow : Window {
                 try {
                         j.cancel();
                 } catch (DBus.Error e) {
-                        message("%s", e.message);
+                        show_error(e.message);
                 }
         }
 
         public void on_unit_new(string id, ObjectPath path) {
-                stderr.printf("new path %s", path);
-
                 Unit u = bus.get_object(
                                 "org.freedesktop.systemd1",
                                 path,
@@ -475,17 +563,16 @@ public class MainWindow : Window {
                 TreeIter iter;
                 unit_model.append(out iter);
                 unit_model.set(iter,
-                               0, u.id,
+                               0, id,
                                1, u.description,
                                2, u.load_state,
                                3, u.active_state,
-                               4, t != "" ? "→ %s".printf(t) : "",
-                               5, u);
+                               4, u.sub_state,
+                               5, t != "" ? "→ %s".printf(t) : "",
+                               6, u);
         }
 
         public void on_job_new(uint32 id, ObjectPath path) {
-                stderr.printf("new path %s", path);
-
                 Job j = bus.get_object(
                                 "org.freedesktop.systemd1",
                                 path,
@@ -498,32 +585,157 @@ public class MainWindow : Window {
                               1, j.unit.id,
                               2, "→ %s".printf(j.job_type),
                               3, j.state,
-                              4, j);
+                              4, j,
+                              5, id);
         }
 
         public void on_unit_removed(string id, ObjectPath path) {
-                stdout.printf("Unit %s removed.\n", id);
+                TreeIter iter;
+                if (!(unit_model.get_iter_first(out iter)))
+                        return;
+
+                do {
+                        string name;
+
+                        unit_model.get(iter, 0, out name);
+
+                        if (id == name) {
+                                if (current_unit_id == name)
+                                        clear_unit();
 
-                /* FIXME */
+                                unit_model.remove(iter);
+                                break;
+                        }
+
+                } while (unit_model.iter_next(ref iter));
         }
 
         public void on_job_removed(uint32 id, ObjectPath path) {
-                stdout.printf("Job %u removed.\n", id);
+                TreeIter iter;
+                if (!(job_model.get_iter_first(out iter)))
+                        return;
+
+                do {
+                        uint32 j;
+
+                        job_model.get(iter, 5, out j);
+
+                        if (id == j) {
+                                if (current_job_id == j)
+                                        clear_job();
+
+                                job_model.remove(iter);
+
+                                break;
+                        }
+
+                } while (job_model.iter_next(ref iter));
+        }
+
+        public bool unit_filter(TreeModel model, TreeIter iter) {
+                string id, active_state;
+
+                model.get(iter, 0, out id, 3, out active_state);
+
+                if (id == null)
+                        return false;
+
+                switch (unit_type_combo_box.get_active()) {
+
+                        case 0:
+                                return true;
+
+                        case 1:
+                                return active_state != "inactive";
+
+                        case 2:
+                                return id.has_suffix(".service");
+
+                        case 3:
+                                return id.has_suffix(".socket");
+
+                        case 4:
+                                return id.has_suffix(".device");
+
+                        case 5:
+                                return id.has_suffix(".mount");
+
+                        case 6:
+                                return id.has_suffix(".automount");
+
+                        case 7:
+                                return id.has_suffix(".target");
+
+                        case 8:
+                                return id.has_suffix(".snapshot");
+                }
+
+                return false;
+        }
+
+        public void unit_type_changed() {
+                TreeModelFilter model = (TreeModelFilter) unit_view.get_model();
+
+                model.refilter();
+        }
 
-                /* FIXME */
+        public void on_server_reload() {
+                try {
+                        manager.reload();
+                } catch (DBus.Error e) {
+                        show_error(e.message);
+                }
         }
+
+        public void on_server_snapshot() {
+                try {
+                        manager.create_snapshot();
+
+                        if (unit_type_combo_box.get_active() != 0)
+                                unit_type_combo_box.set_active(8);
+
+                } catch (DBus.Error e) {
+                        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[] = {
+        { "session", 0,   0,                   OptionArg.NONE,   out session, "Connect to session bus", null },
+        { "system",  0,   OptionFlags.REVERSE, OptionArg.NONE,   out session, "Connect to system bus", null },
+        { 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) {
-        Gtk.init(ref args);
 
         try {
+                Gtk.init_with_args(ref args, "[OPTION...]", entries, "systemadm");
+
                 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) {
+                show_error(e.message);
         }
 
-        Gtk.main();
         return 0;
 }