chiark / gitweb /
manager: merge /etc/xdg/systemd/session and /etc/systemd/session
[elogind.git] / systemadm.vala
1 /***
2   This file is part of systemd.
3
4   Copyright 2010 Lennart Poettering
5
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.
10
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.
15
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/>.
18 ***/
19
20 using Gtk;
21 using GLib;
22 using DBus;
23 using Pango;
24
25 static bool session = false;
26
27 public class LeftLabel : Label {
28         public LeftLabel(string? text = null) {
29                 if (text != null)
30                         set_markup("<b>%s</b>".printf(text));
31                 set_alignment(0, 0);
32                 set_padding(6, 0);
33         }
34 }
35
36 public class RightLabel : Label {
37         public RightLabel(string? text = null) {
38                 set_text_or_na(text);
39                 set_alignment(0, 0);
40                 set_ellipsize(EllipsizeMode.START);
41                 set_selectable(true);
42         }
43
44         public void set_text_or_na(string? text = null) {
45                 if (text == null || text == "")
46                         set_markup("<i>n/a</i>");
47                 else
48                         set_text(text);
49         }
50 }
51
52 public class MainWindow : Window {
53
54         private string? current_unit_id;
55         private uint32 current_job_id;
56
57         private TreeView unit_view;
58         private TreeView job_view;
59
60         private ListStore unit_model;
61         private ListStore job_model;
62
63         private Button start_button;
64         private Button stop_button;
65         private Button restart_button;
66         private Button reload_button;
67         private Button cancel_button;
68
69         private Button server_snapshot_button;
70         private Button server_reload_button;
71
72         private Connection bus;
73         private Manager manager;
74
75         private RightLabel unit_id_label;
76         private RightLabel unit_aliases_label;
77         private RightLabel unit_description_label;
78         private RightLabel unit_load_state_label;
79         private RightLabel unit_active_state_label;
80         private RightLabel unit_sub_state_label;
81         private RightLabel unit_fragment_path_label;
82         private RightLabel unit_active_enter_timestamp_label;
83         private RightLabel unit_active_exit_timestamp_label;
84         private RightLabel unit_can_start_label;
85         private RightLabel unit_can_reload_label;
86         private RightLabel unit_cgroup_label;
87
88         private RightLabel job_id_label;
89         private RightLabel job_state_label;
90         private RightLabel job_type_label;
91
92         private ComboBox unit_type_combo_box;
93
94         public MainWindow() throws DBus.Error {
95                 title = "systemdadm";
96                 position = WindowPosition.CENTER;
97                 set_default_size(1000, 700);
98                 set_border_width(12);
99                 destroy += Gtk.main_quit;
100
101                 Notebook notebook = new Notebook();
102                 add(notebook);
103
104                 Box unit_vbox = new VBox(false, 12);
105                 notebook.append_page(unit_vbox, new Label("Units"));
106                 unit_vbox.set_border_width(12);
107
108                 Box job_vbox = new VBox(false, 12);
109                 notebook.append_page(job_vbox, new Label("Jobs"));
110                 job_vbox.set_border_width(12);
111
112                 unit_type_combo_box = new ComboBox.text();
113                 Box type_hbox = new HBox(false, 6);
114                 type_hbox.pack_start(unit_type_combo_box, false, false, 0);
115                 unit_vbox.pack_start(type_hbox, false, false, 0);
116
117                 unit_type_combo_box.append_text("Show All Units");
118                 unit_type_combo_box.append_text("Show Only Live Units");
119                 unit_type_combo_box.append_text("Services");
120                 unit_type_combo_box.append_text("Sockets");
121                 unit_type_combo_box.append_text("Devices");
122                 unit_type_combo_box.append_text("Mounts");
123                 unit_type_combo_box.append_text("Automounts");
124                 unit_type_combo_box.append_text("Targets");
125                 unit_type_combo_box.append_text("Snapshots");
126                 unit_type_combo_box.set_active(1);
127                 unit_type_combo_box.changed += unit_type_changed;
128
129                 server_snapshot_button = new Button.with_mnemonic("Take _Snapshot");
130                 server_reload_button = new Button.with_mnemonic("Reload _Configuration");
131
132                 server_snapshot_button.clicked += on_server_snapshot;
133                 server_reload_button.clicked += on_server_reload;
134
135                 type_hbox.pack_end(server_snapshot_button, false, true, 0);
136                 type_hbox.pack_end(server_reload_button, false, true, 0);
137
138                 unit_model = new ListStore(7, typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(Unit));
139                 job_model = new ListStore(6, typeof(string), typeof(string), typeof(string), typeof(string), typeof(Job), typeof(uint32));
140
141                 TreeModelFilter unit_model_filter;
142                 unit_model_filter = new TreeModelFilter(unit_model, null);
143                 unit_model_filter.set_visible_func(unit_filter);
144
145                 unit_view = new TreeView.with_model(unit_model_filter);
146                 job_view = new TreeView.with_model(job_model);
147
148                 unit_view.cursor_changed += unit_changed;
149                 job_view.cursor_changed += job_changed;
150
151                 unit_view.insert_column_with_attributes(-1, "Load State", new CellRendererText(), "text", 2);
152                 unit_view.insert_column_with_attributes(-1, "Active State", new CellRendererText(), "text", 3);
153                 unit_view.insert_column_with_attributes(-1, "Unit State", new CellRendererText(), "text", 4);
154                 unit_view.insert_column_with_attributes(-1, "Unit", new CellRendererText(), "text", 0);
155                 unit_view.insert_column_with_attributes(-1, "Job", new CellRendererText(), "text", 5);
156
157                 job_view.insert_column_with_attributes(-1, "Job", new CellRendererText(), "text", 0);
158                 job_view.insert_column_with_attributes(-1, "Unit", new CellRendererText(), "text", 1);
159                 job_view.insert_column_with_attributes(-1, "Type", new CellRendererText(), "text", 2);
160                 job_view.insert_column_with_attributes(-1, "State", new CellRendererText(), "text", 3);
161
162                 ScrolledWindow scroll = new ScrolledWindow(null, null);
163                 scroll.set_policy(PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
164                 scroll.set_shadow_type(ShadowType.IN);
165                 scroll.add(unit_view);
166                 unit_vbox.pack_start(scroll, true, true, 0);
167
168                 scroll = new ScrolledWindow(null, null);
169                 scroll.set_policy(PolicyType.AUTOMATIC, PolicyType.AUTOMATIC);
170                 scroll.set_shadow_type(ShadowType.IN);
171                 scroll.add(job_view);
172                 job_vbox.pack_start(scroll, true, true, 0);
173
174                 unit_id_label = new RightLabel();
175                 unit_aliases_label = new RightLabel();
176                 unit_description_label = new RightLabel();
177                 unit_load_state_label = new RightLabel();
178                 unit_active_state_label = new RightLabel();
179                 unit_sub_state_label = new RightLabel();
180                 unit_fragment_path_label = new RightLabel();
181                 unit_active_enter_timestamp_label = new RightLabel();
182                 unit_active_exit_timestamp_label = new RightLabel();
183                 unit_can_start_label = new RightLabel();
184                 unit_can_reload_label = new RightLabel();
185                 unit_cgroup_label = new RightLabel();
186
187                 job_id_label = new RightLabel();
188                 job_state_label = new RightLabel();
189                 job_type_label = new RightLabel();
190
191                 Table unit_table = new Table(8, 6, false);
192                 unit_table.set_row_spacings(6);
193                 unit_table.set_border_width(0);
194                 unit_vbox.pack_start(unit_table, false, true, 0);
195
196                 Table job_table = new Table(2, 2, false);
197                 job_table.set_row_spacings(6);
198                 job_table.set_border_width(0);
199                 job_vbox.pack_start(job_table, false, true, 0);
200
201                 unit_table.attach(new LeftLabel("Id:"),                     0, 1, 0, 1, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
202                 unit_table.attach(unit_id_label,                            1, 6, 0, 1, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
203                 unit_table.attach(new LeftLabel("Aliases:"),                0, 1, 1, 2, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
204                 unit_table.attach(unit_aliases_label,                       1, 6, 1, 2, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
205                 unit_table.attach(new LeftLabel("Description:"),            0, 1, 2, 3, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
206                 unit_table.attach(unit_description_label,                   1, 6, 2, 3, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
207                 unit_table.attach(new LeftLabel("Fragment Path:"),          0, 1, 3, 4, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
208                 unit_table.attach(unit_fragment_path_label,                 1, 6, 3, 4, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
209                 unit_table.attach(new LeftLabel("Control Group:"),          0, 1, 4, 5, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
210                 unit_table.attach(unit_cgroup_label,                        1, 6, 4, 5, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
211
212                 unit_table.attach(new LeftLabel("Load State:"),             0, 1, 5, 6, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
213                 unit_table.attach(unit_load_state_label,                    1, 2, 5, 6, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
214                 unit_table.attach(new LeftLabel("Active State:"),           0, 1, 6, 7, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
215                 unit_table.attach(unit_active_state_label,                  1, 2, 6, 7, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
216                 unit_table.attach(new LeftLabel("Unit State:"),             0, 1, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
217                 unit_table.attach(unit_sub_state_label,                     1, 2, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
218
219                 unit_table.attach(new LeftLabel("Active Enter Timestamp:"), 2, 3, 6, 7, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
220                 unit_table.attach(unit_active_enter_timestamp_label,        3, 4, 6, 7, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
221                 unit_table.attach(new LeftLabel("Active Exit Timestamp:"),  2, 3, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
222                 unit_table.attach(unit_active_exit_timestamp_label,         3, 4, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
223
224                 unit_table.attach(new LeftLabel("Can Start/Stop:"),         4, 5, 6, 7, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
225                 unit_table.attach(unit_can_start_label,                     5, 6, 6, 7, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
226                 unit_table.attach(new LeftLabel("Can Reload:"),             4, 5, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
227                 unit_table.attach(unit_can_reload_label,                    5, 6, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
228
229                 job_table.attach(new LeftLabel("Id:"),                      0, 1, 0, 1, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
230                 job_table.attach(job_id_label,                              1, 2, 0, 1, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
231                 job_table.attach(new LeftLabel("State:"),                   0, 1, 1, 2, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
232                 job_table.attach(job_state_label,                           1, 2, 1, 2, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
233                 job_table.attach(new LeftLabel("Type:"),                    0, 1, 2, 3, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
234                 job_table.attach(job_type_label,                            1, 2, 2, 3, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0);
235
236                 ButtonBox bbox = new HButtonBox();
237                 bbox.set_layout(ButtonBoxStyle.START);
238                 bbox.set_spacing(6);
239                 unit_vbox.pack_start(bbox, false, true, 0);
240
241                 start_button = new Button.with_mnemonic("_Start");
242                 stop_button = new Button.with_mnemonic("Sto_p");
243                 reload_button = new Button.with_mnemonic("_Reload");
244                 restart_button = new Button.with_mnemonic("Res_tart");
245
246                 start_button.clicked += on_start;
247                 stop_button.clicked += on_stop;
248                 reload_button.clicked += on_reload;
249                 restart_button.clicked += on_restart;
250
251                 bbox.pack_start(start_button, false, true, 0);
252                 bbox.pack_start(stop_button, false, true, 0);
253                 bbox.pack_start(restart_button, false, true, 0);
254                 bbox.pack_start(reload_button, false, true, 0);
255
256                 bbox = new HButtonBox();
257                 bbox.set_layout(ButtonBoxStyle.START);
258                 bbox.set_spacing(6);
259                 job_vbox.pack_start(bbox, false, true, 0);
260
261                 cancel_button = new Button.with_mnemonic("_Cancel");
262
263                 cancel_button.clicked += on_cancel;
264
265                 bbox.pack_start(cancel_button, false, true, 0);
266
267                 bus = Bus.get(session ? BusType.SESSION : BusType.SYSTEM);
268
269                 manager = bus.get_object(
270                                 "org.freedesktop.systemd1",
271                                 "/org/freedesktop/systemd1",
272                                 "org.freedesktop.systemd1.Manager") as Manager;
273
274                 manager.unit_new += on_unit_new;
275                 manager.job_new += on_job_new;
276                 manager.unit_removed += on_unit_removed;
277                 manager.job_removed += on_job_removed;
278
279                 manager.subscribe();
280
281                 clear_unit();
282                 clear_job();
283                 populate_unit_model();
284                 populate_job_model();
285         }
286
287         public void populate_unit_model() throws DBus.Error {
288                 unit_model.clear();
289
290                 var list = manager.list_units();
291
292                 foreach (var i in list) {
293                         TreeIter iter;
294
295                         Unit u = bus.get_object(
296                                         "org.freedesktop.systemd1",
297                                         i.unit_path,
298                                         "org.freedesktop.systemd1.Unit") as Unit;
299
300                         unit_model.append(out iter);
301                         unit_model.set(iter,
302                                        0, i.id,
303                                        1, i.description,
304                                        2, i.load_state,
305                                        3, i.active_state,
306                                        4, i.sub_state,
307                                        5, i.job_type != "" ? "→ %s".printf(i.job_type) : "",
308                                        6, u);
309                 }
310         }
311
312         public void populate_job_model() throws DBus.Error {
313                 job_model.clear();
314
315                 var list = manager.list_jobs();
316
317                 foreach (var i in list) {
318                         TreeIter iter;
319
320                         Job j = bus.get_object(
321                                         "org.freedesktop.systemd1",
322                                         i.job_path,
323                                         "org.freedesktop.systemd1.Job") as Job;
324
325                         job_model.append(out iter);
326                         job_model.set(iter,
327                                       0, "%u".printf(i.id),
328                                       1, i.name,
329                                       2, "→ %s".printf(i.type),
330                                       3, i.state,
331                                       4, j,
332                                       5, i.id);
333                 }
334         }
335
336         public Unit? get_current_unit() {
337                 TreePath p;
338                 unit_view.get_cursor(out p, null);
339
340                 if (p == null)
341                         return null;
342
343                 TreeModel model = unit_view.get_model();
344                 TreeIter iter;
345                 Unit u;
346
347                 model.get_iter(out iter, p);
348                 model.get(iter, 6, out u);
349
350                 return u;
351         }
352
353         public void unit_changed() {
354                 Unit u = get_current_unit();
355
356                 if (u == null)
357                         clear_unit();
358                 else
359                         show_unit(u);
360         }
361
362         public void clear_unit() {
363                 current_unit_id = null;
364
365                 start_button.set_sensitive(false);
366                 stop_button.set_sensitive(false);
367                 reload_button.set_sensitive(false);
368                 restart_button.set_sensitive(false);
369
370                 unit_id_label.set_text_or_na();
371                 unit_aliases_label.set_text_or_na();
372                 unit_description_label.set_text_or_na();
373                 unit_load_state_label.set_text_or_na();
374                 unit_active_state_label.set_text_or_na();
375                 unit_sub_state_label.set_text_or_na();
376                 unit_fragment_path_label.set_text_or_na();
377                 unit_active_enter_timestamp_label.set_text_or_na();
378                 unit_active_exit_timestamp_label.set_text_or_na();
379                 unit_can_reload_label.set_text_or_na();
380                 unit_can_start_label.set_text_or_na();
381                 unit_cgroup_label.set_text_or_na();
382         }
383
384         public void show_unit(Unit unit) {
385                 current_unit_id = unit.id;
386
387                 unit_id_label.set_text_or_na(current_unit_id);
388
389                 string a = "";
390                 foreach (string i in unit.names) {
391                         if (i == current_unit_id)
392                                 continue;
393
394                         if (a == "")
395                                 a = i;
396                         else
397                                 a += "\n" + i;
398                 }
399
400                 unit_aliases_label.set_text_or_na(a);
401                 unit_description_label.set_text_or_na(unit.description);
402                 unit_load_state_label.set_text_or_na(unit.load_state);
403                 unit_active_state_label.set_text_or_na(unit.active_state);
404                 unit_sub_state_label.set_text_or_na(unit.sub_state);
405                 unit_fragment_path_label.set_text_or_na(unit.fragment_path);
406
407                 uint64 t = unit.active_enter_timestamp;
408                 if (t > 0) {
409                         Time timestamp = Time.local((time_t) (t / 1000000));
410                         unit_active_enter_timestamp_label.set_text_or_na(timestamp.format("%a, %d %b %Y %H:%M:%S %z"));
411                 } else
412                         unit_active_enter_timestamp_label.set_text_or_na();
413
414                 t = unit.active_exit_timestamp;
415                 if (t > 0) {
416                         Time timestamp = Time.local((time_t) (t / 1000000));
417                         unit_active_exit_timestamp_label.set_text_or_na(timestamp.format("%a, %d %b %Y %H:%M:%S %z"));
418                 } else
419                         unit_active_exit_timestamp_label.set_text_or_na();
420
421                 bool b = unit.can_start;
422                 start_button.set_sensitive(b);
423                 stop_button.set_sensitive(b);
424                 restart_button.set_sensitive(b);
425                 unit_can_start_label.set_text_or_na(b ? "Yes" : "No");
426
427                 b = unit.can_reload;
428                 reload_button.set_sensitive(b);
429                 unit_can_reload_label.set_text_or_na(b ? "Yes" : "No");
430
431                 unit_cgroup_label.set_text_or_na(unit.default_control_group);
432         }
433
434         public Job? get_current_job() {
435                 TreePath p;
436                 job_view.get_cursor(out p, null);
437
438                 if (p == null)
439                         return null;
440
441                 TreeIter iter;
442                 TreeModel model = job_view.get_model();
443                 Job *j;
444
445                 model.get_iter(out iter, p);
446                 model.get(iter, 4, out j);
447
448                 return j;
449         }
450
451         public void job_changed() {
452                 Job j = get_current_job();
453
454                 if (j == null)
455                         clear_job();
456                 else
457                         show_job(j);
458         }
459
460         public void clear_job() {
461                 current_job_id = 0;
462
463                 job_id_label.set_text_or_na();
464                 job_state_label.set_text_or_na();
465                 job_type_label.set_text_or_na();
466
467                 cancel_button.set_sensitive(false);
468         }
469
470         public void show_job(Job job) {
471                 current_job_id = job.id;
472
473                 job_id_label.set_text_or_na("%u".printf(current_job_id));
474                 job_state_label.set_text_or_na(job.state);
475                 job_type_label.set_text_or_na(job.job_type);
476
477                 cancel_button.set_sensitive(true);
478         }
479
480         public void on_start() {
481                 Unit u = get_current_unit();
482
483                 if (u == null)
484                         return;
485
486                 try {
487                         u.start("replace");
488                 } catch (DBus.Error e) {
489                         show_error(e.message);
490                 }
491         }
492
493         public void on_stop() {
494                 Unit u = get_current_unit();
495
496                 if (u == null)
497                         return;
498
499                 try {
500                         u.stop("replace");
501                 } catch (DBus.Error e) {
502                         show_error(e.message);
503                 }
504         }
505
506         public void on_reload() {
507                 Unit u = get_current_unit();
508
509                 if (u == null)
510                         return;
511
512                 try {
513                         u.reload("replace");
514                 } catch (DBus.Error e) {
515                         show_error(e.message);
516                 }
517         }
518
519         public void on_restart() {
520                 Unit u = get_current_unit();
521
522                 if (u == null)
523                         return;
524
525                 try {
526                         u.restart("replace");
527                 } catch (DBus.Error e) {
528                         show_error(e.message);
529                 }
530         }
531
532         public void on_cancel() {
533                 Job j = get_current_job();
534
535                 if (j == null)
536                         return;
537
538                 try {
539                         j.cancel();
540                 } catch (DBus.Error e) {
541                         show_error(e.message);
542                 }
543         }
544
545         public void on_unit_new(string id, ObjectPath path) {
546                 Unit u = bus.get_object(
547                                 "org.freedesktop.systemd1",
548                                 path,
549                                 "org.freedesktop.systemd1.Unit") as Unit;
550
551                 string t = "";
552                 Unit.JobLink jl = u.job;
553
554                 if (jl.id != 0) {
555                         Job j = bus.get_object(
556                                         "org.freedesktop.systemd1",
557                                         jl.path,
558                                         "org.freedesktop.systemd1.Job") as Job;
559
560                         t = j.job_type;
561                 }
562
563                 TreeIter iter;
564                 unit_model.append(out iter);
565                 unit_model.set(iter,
566                                0, id,
567                                1, u.description,
568                                2, u.load_state,
569                                3, u.active_state,
570                                4, u.sub_state,
571                                5, t != "" ? "→ %s".printf(t) : "",
572                                6, u);
573         }
574
575         public void on_job_new(uint32 id, ObjectPath path) {
576                 Job j = bus.get_object(
577                                 "org.freedesktop.systemd1",
578                                 path,
579                                 "org.freedesktop.systemd1.Job") as Job;
580
581                 TreeIter iter;
582                 job_model.append(out iter);
583                 job_model.set(iter,
584                               0, "%u".printf(j.id),
585                               1, j.unit.id,
586                               2, "→ %s".printf(j.job_type),
587                               3, j.state,
588                               4, j,
589                               5, id);
590         }
591
592         public void on_unit_removed(string id, ObjectPath path) {
593                 TreeIter iter;
594                 if (!(unit_model.get_iter_first(out iter)))
595                         return;
596
597                 do {
598                         string name;
599
600                         unit_model.get(iter, 0, out name);
601
602                         if (id == name) {
603                                 if (current_unit_id == name)
604                                         clear_unit();
605
606                                 unit_model.remove(iter);
607                                 break;
608                         }
609
610                 } while (unit_model.iter_next(ref iter));
611         }
612
613         public void on_job_removed(uint32 id, ObjectPath path) {
614                 TreeIter iter;
615                 if (!(job_model.get_iter_first(out iter)))
616                         return;
617
618                 do {
619                         uint32 j;
620
621                         job_model.get(iter, 5, out j);
622
623                         if (id == j) {
624                                 if (current_job_id == j)
625                                         clear_job();
626
627                                 job_model.remove(iter);
628
629                                 break;
630                         }
631
632                 } while (job_model.iter_next(ref iter));
633         }
634
635         public bool unit_filter(TreeModel model, TreeIter iter) {
636                 string id, active_state;
637
638                 model.get(iter, 0, out id, 3, out active_state);
639
640                 if (id == null)
641                         return false;
642
643                 switch (unit_type_combo_box.get_active()) {
644
645                         case 0:
646                                 return true;
647
648                         case 1:
649                                 return active_state != "inactive";
650
651                         case 2:
652                                 return id.has_suffix(".service");
653
654                         case 3:
655                                 return id.has_suffix(".socket");
656
657                         case 4:
658                                 return id.has_suffix(".device");
659
660                         case 5:
661                                 return id.has_suffix(".mount");
662
663                         case 6:
664                                 return id.has_suffix(".automount");
665
666                         case 7:
667                                 return id.has_suffix(".target");
668
669                         case 8:
670                                 return id.has_suffix(".snapshot");
671                 }
672
673                 return false;
674         }
675
676         public void unit_type_changed() {
677                 TreeModelFilter model = (TreeModelFilter) unit_view.get_model();
678
679                 model.refilter();
680         }
681
682         public void on_server_reload() {
683                 try {
684                         manager.reload();
685                 } catch (DBus.Error e) {
686                         show_error(e.message);
687                 }
688         }
689
690         public void on_server_snapshot() {
691                 try {
692                         manager.create_snapshot();
693
694                         if (unit_type_combo_box.get_active() != 0)
695                                 unit_type_combo_box.set_active(8);
696
697                 } catch (DBus.Error e) {
698                         show_error(e.message);
699                 }
700         }
701
702         public void show_error(string e) {
703                 var m = new MessageDialog(this,
704                                           DialogFlags.DESTROY_WITH_PARENT,
705                                           MessageType.ERROR,
706                                           ButtonsType.CLOSE, "%s", e);
707                 m.run();
708                 m.destroy();
709         }
710
711 }
712
713 static const OptionEntry entries[] = {
714         { "session", 0,   0,                   OptionArg.NONE,   out session, "Connect to session bus", null },
715         { "system",  0,   OptionFlags.REVERSE, OptionArg.NONE,   out session, "Connect to system bus", null },
716         { null }
717 };
718
719 void show_error(string e) {
720         var m = new MessageDialog(null, 0, MessageType.ERROR, ButtonsType.CLOSE, "%s", e);
721         m.run();
722         m.destroy();
723 }
724
725 int main (string[] args) {
726
727         try {
728                 Gtk.init_with_args(ref args, "[OPTION...]", entries, "systemadm");
729
730                 MainWindow window = new MainWindow();
731                 window.show_all();
732
733                 Gtk.main();
734         } catch (DBus.Error e) {
735                 show_error(e.message);
736         } catch (GLib.Error e) {
737                 show_error(e.message);
738         }
739
740         return 0;
741 }