chiark / gitweb /
systemadm: add libgee as dependency and use it for a unit map
[elogind.git] / src / systemadm.vala
index 21177bf396b832674cad22b1e657c0fc7f7ca052..c893da01da1fbc56f765fd70abff7f20c2a5666b 100644 (file)
@@ -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<string, Unit> unit_map;
+
         private Button start_button;
         private Button stop_button;
         private Button restart_button;
@@ -113,6 +114,7 @@ public class MainWindow : Window {
         private RightLabel job_type_label;
 
         private ComboBox unit_type_combo_box;
+        private CheckButton inactive_checkbox;
 
         public MainWindow() throws IOError {
                 title = user ? "systemd User Service Manager" : "systemd System Manager";
@@ -137,18 +139,24 @@ 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 Units");
-                unit_type_combo_box.append_text("Show Only Live Units");
+                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(1);
+                unit_type_combo_box.set_active(0); // Show All
                 unit_type_combo_box.changed.connect(unit_type_changed);
 
+                inactive_checkbox = new CheckButton.with_label("inactive too");
+                inactive_checkbox.toggled.connect(unit_type_changed);
+                type_hbox.pack_start(inactive_checkbox, false, false, 0);
+
                 unit_load_entry = new Entry();
                 unit_load_button = new Button.with_mnemonic("_Load");
                 unit_load_button.set_sensitive(false);
@@ -174,6 +182,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<string, Unit>();
+
                 TreeModelFilter unit_model_filter;
                 unit_model_filter = new TreeModelFilter(unit_model, null);
                 unit_model_filter.set_visible_func(unit_filter);
@@ -349,6 +359,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,
@@ -409,6 +421,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();
 
@@ -706,6 +722,8 @@ public class MainWindow : Window {
                                         "org.freedesktop.systemd1",
                                         path);
 
+                        unit_map[id] = u;
+
                         update_unit_iter(iter, id, u);
                 } catch (IOError e) {
                         show_error(e.message);
@@ -767,6 +785,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) {
@@ -872,37 +892,37 @@ public class MainWindow : Window {
                 if (id == null)
                         return false;
 
-                switch (unit_type_combo_box.get_active()) {
-
-                        case 0:
-                                return true;
-
-                        case 1:
-                                return active_state != "inactive" || job != "";
-
-                        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");
+                if (!inactive_checkbox.get_active()
+                    && active_state == "inactive" && job == "")
+                        return false;
 
-                        case 8:
-                                return id.has_suffix(".snapshot");
+                switch (unit_type_combo_box.get_active()) {
+                case 0:
+                        return true;
+                case 1:
+                        return id.has_suffix(".target");
+                case 2:
+                        return id.has_suffix(".service");
+                case 3:
+                        return id.has_suffix(".device");
+                case 4:
+                        return id.has_suffix(".mount");
+                case 5:
+                        return id.has_suffix(".automount");
+                case 6:
+                        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);
+                        return false;
                 }
-
-                return false;
         }
 
         public void unit_type_changed() {