2 This file is part of systemd.
4 Copyright 2010 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 static bool session = false;
27 public class LeftLabel : Label {
28 public LeftLabel(string? text = null) {
30 set_markup("<b>%s</b>".printf(text));
36 public class RightLabel : Label {
37 public RightLabel(string? text = null) {
40 set_ellipsize(EllipsizeMode.START);
44 public void set_text_or_na(string? text = null) {
45 if (text == null || text == "")
46 set_markup("<i>n/a</i>");
51 public void set_markup_or_na(string? text = null) {
52 if (text == null || text == "")
53 set_markup("<i>n/a</i>");
59 public class MainWindow : Window {
61 private string? current_unit_id;
62 private uint32 current_job_id;
64 private TreeView unit_view;
65 private TreeView job_view;
67 private ListStore unit_model;
68 private ListStore job_model;
70 private Button start_button;
71 private Button stop_button;
72 private Button restart_button;
73 private Button reload_button;
74 private Button cancel_button;
76 private Entry unit_load_entry;
77 private Button unit_load_button;
79 private Button server_snapshot_button;
80 private Button server_reload_button;
82 private Connection bus;
83 private Manager manager;
85 private RightLabel unit_id_label;
86 private RightLabel unit_aliases_label;
87 private RightLabel unit_dependency_label;
88 private RightLabel unit_description_label;
89 private RightLabel unit_load_state_label;
90 private RightLabel unit_active_state_label;
91 private RightLabel unit_sub_state_label;
92 private RightLabel unit_fragment_path_label;
93 private RightLabel unit_active_enter_timestamp_label;
94 private RightLabel unit_active_exit_timestamp_label;
95 private RightLabel unit_can_start_label;
96 private RightLabel unit_can_reload_label;
97 private RightLabel unit_cgroup_label;
99 private RightLabel job_id_label;
100 private RightLabel job_state_label;
101 private RightLabel job_type_label;
103 private ComboBox unit_type_combo_box;
105 public MainWindow() throws DBus.Error {
106 title = session ? "systemd Session Manager" : "systemd System Manager";
107 position = WindowPosition.CENTER;
108 set_default_size(1000, 700);
109 set_border_width(12);
110 destroy.connect(Gtk.main_quit);
112 Notebook notebook = new Notebook();
115 Box unit_vbox = new VBox(false, 12);
116 notebook.append_page(unit_vbox, new Label("Units"));
117 unit_vbox.set_border_width(12);
119 Box job_vbox = new VBox(false, 12);
120 notebook.append_page(job_vbox, new Label("Jobs"));
121 job_vbox.set_border_width(12);
123 unit_type_combo_box = new ComboBox.text();
124 Box type_hbox = new HBox(false, 6);
125 type_hbox.pack_start(unit_type_combo_box, false, false, 0);
126 unit_vbox.pack_start(type_hbox, false, false, 0);
128 unit_type_combo_box.append_text("Show All Units");
129 unit_type_combo_box.append_text("Show Only Live Units");
130 unit_type_combo_box.append_text("Services");
131 unit_type_combo_box.append_text("Sockets");
132 unit_type_combo_box.append_text("Devices");
133 unit_type_combo_box.append_text("Mounts");
134 unit_type_combo_box.append_text("Automounts");
135 unit_type_combo_box.append_text("Targets");
136 unit_type_combo_box.append_text("Snapshots");
137 unit_type_combo_box.set_active(1);
138 unit_type_combo_box.changed.connect(unit_type_changed);
140 unit_load_entry = new Entry();
141 unit_load_button = new Button.with_mnemonic("_Load");
142 unit_load_button.set_sensitive(false);
144 unit_load_entry.changed.connect(on_unit_load_entry_changed);
145 unit_load_entry.activate.connect(on_unit_load);
146 unit_load_button.clicked.connect(on_unit_load);
148 Box unit_load_hbox = new HBox(false, 6);
149 unit_load_hbox.pack_start(unit_load_entry, false, true, 0);
150 unit_load_hbox.pack_start(unit_load_button, false, true, 0);
152 server_snapshot_button = new Button.with_mnemonic("Take S_napshot");
153 server_reload_button = new Button.with_mnemonic("Reload _Configuration");
155 server_snapshot_button.clicked.connect(on_server_snapshot);
156 server_reload_button.clicked.connect(on_server_reload);
158 type_hbox.pack_end(server_snapshot_button, false, true, 0);
159 type_hbox.pack_end(server_reload_button, false, true, 0);
160 type_hbox.pack_end(unit_load_hbox, false, true, 24);
162 unit_model = new ListStore(7, typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(Unit));
163 job_model = new ListStore(6, typeof(string), typeof(string), typeof(string), typeof(string), typeof(Job), typeof(uint32));
165 TreeModelFilter unit_model_filter;
166 unit_model_filter = new TreeModelFilter(unit_model, null);
167 unit_model_filter.set_visible_func(unit_filter);
169 unit_view = new TreeView.with_model(unit_model_filter);
170 job_view = new TreeView.with_model(job_model);
172 unit_view.cursor_changed.connect(unit_changed);
173 job_view.cursor_changed.connect(job_changed);
175 unit_view.insert_column_with_attributes(-1, "Load State", new CellRendererText(), "text", 2);
176 unit_view.insert_column_with_attributes(-1, "Active State", new CellRendererText(), "text", 3);
177 unit_view.insert_column_with_attributes(-1, "Unit State", new CellRendererText(), "text", 4);
178 unit_view.insert_column_with_attributes(-1, "Unit", new CellRendererText(), "text", 0);
179 unit_view.insert_column_with_attributes(-1, "Job", new CellRendererText(), "text", 5);
181 job_view.insert_column_with_attributes(-1, "Job", new CellRendererText(), "text", 0);
182 job_view.insert_column_with_attributes(-1, "Unit", new CellRendererText(), "text", 1);
183 job_view.insert_column_with_attributes(-1, "Type", new CellRendererText(), "text", 2);
184 job_view.insert_column_with_attributes(-1, "State", new CellRendererText(), "text", 3);
186 ScrolledWindow scroll = new ScrolledWindow(null, null);
187 scroll.set_policy(PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
188 scroll.set_shadow_type(ShadowType.IN);
189 scroll.add(unit_view);
190 unit_vbox.pack_start(scroll, true, true, 0);
192 scroll = new ScrolledWindow(null, null);
193 scroll.set_policy(PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
194 scroll.set_shadow_type(ShadowType.IN);
195 scroll.add(job_view);
196 job_vbox.pack_start(scroll, true, true, 0);
198 unit_id_label = new RightLabel();
199 unit_aliases_label = new RightLabel();
200 unit_dependency_label = new RightLabel();
201 unit_description_label = new RightLabel();
202 unit_load_state_label = new RightLabel();
203 unit_active_state_label = new RightLabel();
204 unit_sub_state_label = new RightLabel();
205 unit_fragment_path_label = new RightLabel();
206 unit_active_enter_timestamp_label = new RightLabel();
207 unit_active_exit_timestamp_label = new RightLabel();
208 unit_can_start_label = new RightLabel();
209 unit_can_reload_label = new RightLabel();
210 unit_cgroup_label = new RightLabel();
212 job_id_label = new RightLabel();
213 job_state_label = new RightLabel();
214 job_type_label = new RightLabel();
216 unit_dependency_label.set_track_visited_links(false);
217 unit_dependency_label.set_selectable(false);
218 unit_dependency_label.activate_link.connect(on_activate_link);
220 unit_fragment_path_label.set_track_visited_links(false);
222 Table unit_table = new Table(8, 6, false);
223 unit_table.set_row_spacings(6);
224 unit_table.set_border_width(0);
225 unit_vbox.pack_start(unit_table, false, true, 0);
227 Table job_table = new Table(2, 2, false);
228 job_table.set_row_spacings(6);
229 job_table.set_border_width(0);
230 job_vbox.pack_start(job_table, false, true, 0);
232 unit_table.attach(new LeftLabel("Id:"), 0, 1, 0, 1, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
233 unit_table.attach(unit_id_label, 1, 6, 0, 1, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
234 unit_table.attach(new LeftLabel("Aliases:"), 0, 1, 1, 2, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
235 unit_table.attach(unit_aliases_label, 1, 6, 1, 2, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
236 unit_table.attach(new LeftLabel("Description:"), 0, 1, 2, 3, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
237 unit_table.attach(unit_description_label, 1, 6, 2, 3, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
238 unit_table.attach(new LeftLabel("Dependencies:"), 0, 1, 3, 4, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
239 unit_table.attach(unit_dependency_label, 1, 6, 3, 4, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
240 unit_table.attach(new LeftLabel("Fragment Path:"), 0, 1, 4, 5, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
241 unit_table.attach(unit_fragment_path_label, 1, 6, 4, 5, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
242 unit_table.attach(new LeftLabel("Control Group:"), 0, 1, 5, 6, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
243 unit_table.attach(unit_cgroup_label, 1, 6, 5, 6, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
245 unit_table.attach(new LeftLabel("Load State:"), 0, 1, 6, 7, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
246 unit_table.attach(unit_load_state_label, 1, 2, 6, 7, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
247 unit_table.attach(new LeftLabel("Active State:"), 0, 1, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
248 unit_table.attach(unit_active_state_label, 1, 2, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
249 unit_table.attach(new LeftLabel("Unit State:"), 0, 1, 8, 9, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
250 unit_table.attach(unit_sub_state_label, 1, 2, 8, 9, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
252 unit_table.attach(new LeftLabel("Active Enter Timestamp:"), 2, 3, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
253 unit_table.attach(unit_active_enter_timestamp_label, 3, 4, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
254 unit_table.attach(new LeftLabel("Active Exit Timestamp:"), 2, 3, 8, 9, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
255 unit_table.attach(unit_active_exit_timestamp_label, 3, 4, 8, 9, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
257 unit_table.attach(new LeftLabel("Can Start/Stop:"), 4, 5, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
258 unit_table.attach(unit_can_start_label, 5, 6, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
259 unit_table.attach(new LeftLabel("Can Reload:"), 4, 5, 8, 9, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
260 unit_table.attach(unit_can_reload_label, 5, 6, 8, 9, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
262 job_table.attach(new LeftLabel("Id:"), 0, 1, 0, 1, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
263 job_table.attach(job_id_label, 1, 2, 0, 1, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
264 job_table.attach(new LeftLabel("State:"), 0, 1, 1, 2, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
265 job_table.attach(job_state_label, 1, 2, 1, 2, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
266 job_table.attach(new LeftLabel("Type:"), 0, 1, 2, 3, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
267 job_table.attach(job_type_label, 1, 2, 2, 3, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
269 ButtonBox bbox = new HButtonBox();
270 bbox.set_layout(ButtonBoxStyle.START);
272 unit_vbox.pack_start(bbox, false, true, 0);
274 start_button = new Button.with_mnemonic("_Start");
275 stop_button = new Button.with_mnemonic("Sto_p");
276 reload_button = new Button.with_mnemonic("_Reload");
277 restart_button = new Button.with_mnemonic("Res_tart");
279 start_button.clicked.connect(on_start);
280 stop_button.clicked.connect(on_stop);
281 reload_button.clicked.connect(on_reload);
282 restart_button.clicked.connect(on_restart);
284 bbox.pack_start(start_button, false, true, 0);
285 bbox.pack_start(stop_button, false, true, 0);
286 bbox.pack_start(restart_button, false, true, 0);
287 bbox.pack_start(reload_button, false, true, 0);
289 bbox = new HButtonBox();
290 bbox.set_layout(ButtonBoxStyle.START);
292 job_vbox.pack_start(bbox, false, true, 0);
294 cancel_button = new Button.with_mnemonic("_Cancel");
296 cancel_button.clicked.connect(on_cancel);
298 bbox.pack_start(cancel_button, false, true, 0);
300 bus = Bus.get(session ? BusType.SESSION : BusType.SYSTEM);
302 manager = bus.get_object(
303 "org.freedesktop.systemd1",
304 "/org/freedesktop/systemd1",
305 "org.freedesktop.systemd1.Manager") as Manager;
307 manager.unit_new.connect(on_unit_new);
308 manager.job_new.connect(on_job_new);
309 manager.unit_removed.connect(on_unit_removed);
310 manager.job_removed.connect(on_job_removed);
316 populate_unit_model();
317 populate_job_model();
320 public void populate_unit_model() throws DBus.Error {
323 var list = manager.list_units();
325 foreach (var i in list) {
328 Unit u = bus.get_object(
329 "org.freedesktop.systemd1",
331 "org.freedesktop.systemd1.Unit") as Unit;
333 u.changed.connect(on_unit_changed);
335 unit_model.append(out iter);
342 5, i.job_type != "" ? "→ %s".printf(i.job_type) : "",
347 public void populate_job_model() throws DBus.Error {
350 var list = manager.list_jobs();
352 foreach (var i in list) {
355 Job j = bus.get_object(
356 "org.freedesktop.systemd1",
358 "org.freedesktop.systemd1.Job") as Job;
360 j.changed.connect(on_job_changed);
362 job_model.append(out iter);
364 0, "%u".printf(i.id),
366 2, "→ %s".printf(i.type),
373 public Unit? get_current_unit() {
375 unit_view.get_cursor(out p, null);
380 TreeModel model = unit_view.get_model();
384 model.get_iter(out iter, p);
385 model.get(iter, 6, out u);
390 public void unit_changed() {
391 Unit u = get_current_unit();
399 public void clear_unit() {
400 current_unit_id = null;
402 start_button.set_sensitive(false);
403 stop_button.set_sensitive(false);
404 reload_button.set_sensitive(false);
405 restart_button.set_sensitive(false);
407 unit_id_label.set_text_or_na();
408 unit_aliases_label.set_text_or_na();
409 unit_description_label.set_text_or_na();
410 unit_description_label.set_text_or_na();
411 unit_load_state_label.set_text_or_na();
412 unit_active_state_label.set_text_or_na();
413 unit_sub_state_label.set_text_or_na();
414 unit_fragment_path_label.set_text_or_na();
415 unit_active_enter_timestamp_label.set_text_or_na();
416 unit_active_exit_timestamp_label.set_text_or_na();
417 unit_can_reload_label.set_text_or_na();
418 unit_can_start_label.set_text_or_na();
419 unit_cgroup_label.set_text_or_na();
422 public string make_dependency_string(string? prefix, string word, string[] dependencies) {
431 foreach (string i in dependencies) {
433 r += first ? "\n" : ",";
440 r += " <a href=\"" + i + "\">" + i + "</a>";
446 public void show_unit(Unit unit) {
447 current_unit_id = unit.id;
449 unit_id_label.set_text_or_na(current_unit_id);
452 foreach (string i in unit.names) {
453 if (i == current_unit_id)
462 unit_aliases_label.set_text_or_na(a);
465 requires = unit.requires,
466 requires_overridable = unit.requires_overridable,
467 requisite = unit.requisite,
468 requisite_overridable = unit.requisite_overridable,
470 required_by = unit.required_by,
471 required_by_overridable = unit.required_by_overridable,
472 wanted_by = unit.wanted_by,
473 conflicts = unit.conflicts,
474 before = unit.before,
477 unit_dependency_label.set_markup_or_na(
478 make_dependency_string(
479 make_dependency_string(
480 make_dependency_string(
481 make_dependency_string(
482 make_dependency_string(
483 make_dependency_string(
484 make_dependency_string(
485 make_dependency_string(
486 make_dependency_string(
487 make_dependency_string(
488 make_dependency_string(null,
489 "requires", requires),
490 "overridable requires", requires_overridable),
491 "requisite", requisite),
492 "overridable requisite", requisite_overridable),
494 "conflicts", conflicts),
495 "required by", required_by),
496 "overridable required by", required_by_overridable),
497 "wanted by", wanted_by),
501 unit_description_label.set_text_or_na(unit.description);
502 unit_load_state_label.set_text_or_na(unit.load_state);
503 unit_active_state_label.set_text_or_na(unit.active_state);
504 unit_sub_state_label.set_text_or_na(unit.sub_state);
506 string fp = unit.fragment_path;
508 unit_fragment_path_label.set_markup_or_na("<a href=\"file://" + fp +"\">" + fp + "</a>" );
510 unit_fragment_path_label.set_text_or_na();
512 uint64 t = unit.active_enter_timestamp;
514 Time timestamp = Time.local((time_t) (t / 1000000));
515 unit_active_enter_timestamp_label.set_text_or_na(timestamp.format("%a, %d %b %Y %H:%M:%S %z"));
517 unit_active_enter_timestamp_label.set_text_or_na();
519 t = unit.active_exit_timestamp;
521 Time timestamp = Time.local((time_t) (t / 1000000));
522 unit_active_exit_timestamp_label.set_text_or_na(timestamp.format("%a, %d %b %Y %H:%M:%S %z"));
524 unit_active_exit_timestamp_label.set_text_or_na();
526 bool b = unit.can_start;
527 start_button.set_sensitive(b);
528 stop_button.set_sensitive(b);
529 restart_button.set_sensitive(b);
530 unit_can_start_label.set_text_or_na(b ? "Yes" : "No");
533 reload_button.set_sensitive(b);
534 unit_can_reload_label.set_text_or_na(b ? "Yes" : "No");
536 unit_cgroup_label.set_text_or_na(unit.default_control_group);
539 public Job? get_current_job() {
541 job_view.get_cursor(out p, null);
547 TreeModel model = job_view.get_model();
550 model.get_iter(out iter, p);
551 model.get(iter, 4, out j);
556 public void job_changed() {
557 Job j = get_current_job();
565 public void clear_job() {
568 job_id_label.set_text_or_na();
569 job_state_label.set_text_or_na();
570 job_type_label.set_text_or_na();
572 cancel_button.set_sensitive(false);
575 public void show_job(Job job) {
576 current_job_id = job.id;
578 job_id_label.set_text_or_na("%u".printf(current_job_id));
579 job_state_label.set_text_or_na(job.state);
580 job_type_label.set_text_or_na(job.job_type);
582 cancel_button.set_sensitive(true);
585 public void on_start() {
586 Unit u = get_current_unit();
593 } catch (DBus.Error e) {
594 show_error(e.message);
598 public void on_stop() {
599 Unit u = get_current_unit();
606 } catch (DBus.Error e) {
607 show_error(e.message);
611 public void on_reload() {
612 Unit u = get_current_unit();
619 } catch (DBus.Error e) {
620 show_error(e.message);
624 public void on_restart() {
625 Unit u = get_current_unit();
631 u.restart("replace");
632 } catch (DBus.Error e) {
633 show_error(e.message);
637 public void on_cancel() {
638 Job j = get_current_job();
645 } catch (DBus.Error e) {
646 show_error(e.message);
650 public void update_unit_iter(TreeIter iter, string id, Unit u) {
653 Unit.JobLink jl = u.job;
656 Job j = bus.get_object(
657 "org.freedesktop.systemd1",
659 "org.freedesktop.systemd1.Job") as Job;
670 5, t != "" ? "→ %s".printf(t) : "",
674 public void on_unit_new(string id, ObjectPath path) {
675 Unit u = bus.get_object(
676 "org.freedesktop.systemd1",
678 "org.freedesktop.systemd1.Unit") as Unit;
680 u.changed.connect(on_unit_changed);
683 unit_model.append(out iter);
684 update_unit_iter(iter, id, u);
687 public void update_job_iter(TreeIter iter, uint32 id, Job j) {
691 2, "→ %s".printf(j.job_type),
697 public void on_job_new(uint32 id, ObjectPath path) {
698 Job j = bus.get_object(
699 "org.freedesktop.systemd1",
701 "org.freedesktop.systemd1.Job") as Job;
703 j.changed.connect(on_job_changed);
706 job_model.append(out iter);
707 update_job_iter(iter, id, j);
710 public void on_unit_removed(string id, ObjectPath path) {
712 if (!(unit_model.get_iter_first(out iter)))
718 unit_model.get(iter, 0, out name);
721 if (current_unit_id == name)
724 unit_model.remove(iter);
728 } while (unit_model.iter_next(ref iter));
731 public void on_job_removed(uint32 id, ObjectPath path, bool success) {
733 if (!(job_model.get_iter_first(out iter)))
739 job_model.get(iter, 5, out j);
742 if (current_job_id == j)
745 job_model.remove(iter);
750 } while (job_model.iter_next(ref iter));
753 public void on_unit_changed(Unit u) {
757 if (!(unit_model.get_iter_first(out iter)))
765 unit_model.get(iter, 0, out name);
768 update_unit_iter(iter, id, u);
770 if (current_unit_id == id)
776 } while (unit_model.iter_next(ref iter));
779 public void on_job_changed(Job j) {
783 if (!(job_model.get_iter_first(out iter)))
791 job_model.get(iter, 5, out k);
794 update_job_iter(iter, id, j);
796 if (current_job_id == id)
802 } while (job_model.iter_next(ref iter));
805 public bool unit_filter(TreeModel model, TreeIter iter) {
806 string id, active_state, job;
808 model.get(iter, 0, out id, 3, out active_state, 5, out job);
813 switch (unit_type_combo_box.get_active()) {
819 return active_state != "inactive" || job != "";
822 return id.has_suffix(".service");
825 return id.has_suffix(".socket");
828 return id.has_suffix(".device");
831 return id.has_suffix(".mount");
834 return id.has_suffix(".automount");
837 return id.has_suffix(".target");
840 return id.has_suffix(".snapshot");
846 public void unit_type_changed() {
847 TreeModelFilter model = (TreeModelFilter) unit_view.get_model();
852 public void on_server_reload() {
855 } catch (DBus.Error e) {
856 show_error(e.message);
860 public void on_server_snapshot() {
862 manager.create_snapshot();
864 if (unit_type_combo_box.get_active() != 0)
865 unit_type_combo_box.set_active(8);
867 } catch (DBus.Error e) {
868 show_error(e.message);
872 public void on_unit_load() {
873 string t = unit_load_entry.get_text();
879 var path = manager.load_unit(t);
881 Unit u = bus.get_object(
882 "org.freedesktop.systemd1",
884 "org.freedesktop.systemd1.Unit") as Unit;
886 var m = new MessageDialog(this,
887 DialogFlags.DESTROY_WITH_PARENT,
890 "Unit available as id %s", u.id);
896 } catch (DBus.Error e) {
897 show_error(e.message);
901 public void on_unit_load_entry_changed() {
902 unit_load_button.set_sensitive(unit_load_entry.get_text() != "");
905 public bool on_activate_link(string uri) {
908 string path = manager.get_unit(uri);
910 Unit u = bus.get_object(
911 "org.freedesktop.systemd1",
913 "org.freedesktop.systemd1.Unit") as Unit;
916 } catch (DBus.Error e) {
917 show_error(e.message);
923 public void show_error(string e) {
924 var m = new MessageDialog(this,
925 DialogFlags.DESTROY_WITH_PARENT,
927 ButtonsType.CLOSE, "%s", e);
935 static const OptionEntry entries[] = {
936 { "session", 0, 0, OptionArg.NONE, out session, "Connect to session bus", null },
937 { "system", 0, OptionFlags.REVERSE, OptionArg.NONE, out session, "Connect to system bus", null },
941 void show_error(string e) {
942 var m = new MessageDialog(null, 0, MessageType.ERROR, ButtonsType.CLOSE, "%s", e);
947 int main (string[] args) {
950 Gtk.init_with_args(ref args, "[OPTION...]", entries, "systemadm");
952 MainWindow window = new MainWindow();
956 } catch (DBus.Error e) {
957 show_error(e.message);
958 } catch (GLib.Error e) {
959 show_error(e.message);