chiark / gitweb /
systemadm: coalesce id and decription fields
[elogind.git] / src / systemadm.vala
index c893da01da1fbc56f765fd70abff7f20c2a5666b..4cb5c55ef332403c8ee16601aa8cac12db357674 100644 (file)
@@ -96,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;
@@ -220,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();
@@ -238,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);
@@ -255,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);
@@ -443,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();
@@ -457,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 "<span color='grey'>" + i + "</span";
+
+                string color;
+                switch (u.sub_state) {
+                case "active": color = "blue"; break;
+                case "dead": color = "red"; break;
+                case "running": color = "green"; break;
+                default: color = "black"; break;
+                }
+                string span = "<span underline='none' color='" + color + "'>"
+                              + i + "(" +
+                              u.sub_state + ")" + "</span>";
+                return  " <a href='" + i + "'>" + span + "</a>";
+        }
+
+
         public string make_dependency_string(string? prefix, string word, string[] dependencies) {
+                Gee.Collection<unowned string> sorted = new Gee.TreeSet<string>();
+                foreach (string i in dependencies)
+                        sorted.add(i);
+
                 bool first = true;
                 string r;
 
@@ -466,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 += "<b>" + word + ":</b>";
                                 first = false;
                         }
 
-                        r += " <a href=\"" + i + "\">" + i + "</a>";
+                        r += format_unit_link(i);
                 }
 
                 return r;
@@ -484,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,
@@ -619,7 +640,7 @@ public class MainWindow : Window {
 
                 try {
                         u.start("replace");
-                } catch (IOError e) {
+                } catch (Error e) {
                         show_error(e.message);
                 }
         }
@@ -632,7 +653,7 @@ public class MainWindow : Window {
 
                 try {
                         u.stop("replace");
-                } catch (IOError e) {
+                } catch (Error e) {
                         show_error(e.message);
                 }
         }
@@ -645,7 +666,7 @@ public class MainWindow : Window {
 
                 try {
                         u.reload("replace");
-                } catch (IOError e) {
+                } catch (Error e) {
                         show_error(e.message);
                 }
         }
@@ -658,7 +679,7 @@ public class MainWindow : Window {
 
                 try {
                         u.restart("replace");
-                } catch (IOError e) {
+                } catch (Error e) {
                         show_error(e.message);
                 }
         }
@@ -671,7 +692,7 @@ public class MainWindow : Window {
 
                 try {
                         j.cancel();
-                } catch (IOError e) {
+                } catch (Error e) {
                         show_error(e.message);
                 }
         }
@@ -699,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);
                 }
         }
@@ -725,7 +746,7 @@ public class MainWindow : Window {
                         unit_map[id] = u;
 
                         update_unit_iter(iter, id, u);
-                } catch (IOError e) {
+                } catch (Error e) {
                         show_error(e.message);
                 }
         }
@@ -761,7 +782,7 @@ public class MainWindow : Window {
 
                         update_job_iter(iter, id, j);
 
-                } catch (IOError e) {
+                } catch (Error e) {
                         show_error(e.message);
                 }
         }
@@ -843,7 +864,7 @@ public class MainWindow : Window {
 
                         } while (unit_model.iter_next(ref iter));
 
-                } catch (IOError e) {
+                } catch (Error e) {
                         show_error(e.message);
                 }
         }
@@ -879,7 +900,7 @@ public class MainWindow : Window {
 
                         } while (job_model.iter_next(ref iter));
 
-                } catch (IOError e) {
+                } catch (Error e) {
                         show_error(e.message);
                 }
         }
@@ -934,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);
                 }
         }
@@ -946,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);
                 }
         }
@@ -975,7 +996,7 @@ public class MainWindow : Window {
                         m.destroy();
 
                         show_unit(u);
-                } catch (IOError e) {
+                } catch (Error e) {
                         show_error(e.message);
                 }
         }
@@ -995,7 +1016,7 @@ public class MainWindow : Window {
                                         path);
 
                         show_unit(u);
-                } catch (IOError e) {
+                } catch (Error e) {
                         show_error(e.message);
                 }