1bf12a58580f69da05ff598b3d4fafc714fbc334
[platform/upstream/folks.git] / tools / inspect / command-backends.vala
1 /*
2  * Copyright (C) 2010 Collabora Ltd.
3  *
4  * This library is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 2.1 of the License, or
7  * (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16  *
17  * Authors:
18  *       Philip Withnall <philip.withnall@collabora.co.uk>
19  */
20
21 using Folks;
22 using Gee;
23 using GLib;
24
25 private class Folks.Inspect.Commands.Backends : Folks.Inspect.Command
26 {
27   public override string name
28     {
29       get { return "backends"; }
30     }
31
32   public override string description
33     {
34       get { return "Inspect the backends loaded by the aggregator."; }
35     }
36
37   public override string help
38     {
39       get
40         {
41           return "backends                   List all known backends.\n" +
42               "backends [backend name]    Display the details of the " +
43               "specified backend and list its persona stores.";
44         }
45     }
46
47   public Backends (Client client)
48     {
49       base (client);
50     }
51
52   public override void run (string? command_string)
53     {
54       if (command_string == null)
55         {
56           /* List all the backends */
57           Collection<Backend> backends =
58               this.client.backend_store.list_backends ();
59
60           Utils.print_line ("%u backends:", backends.size);
61
62           Utils.indent ();
63           foreach (Backend backend in backends)
64             Utils.print_line ("%s", backend.name);
65           Utils.unindent ();
66         }
67       else
68         {
69           /* Show the details of a particular backend */
70           Backend backend =
71               this.client.backend_store.dup_backend_by_name (command_string);
72
73           if (backend == null)
74             {
75               Utils.print_line ("Unrecognised backend name '%s'.",
76                   command_string);
77               return;
78             }
79
80           Utils.print_line ("Backend '%s' with %u persona stores " +
81               "(type ID, ID ('display name')):",
82               backend.name, backend.persona_stores.size ());
83
84           /* List the backend's persona stores */
85           Utils.indent ();
86           backend.persona_stores.foreach ((k, v) =>
87             {
88               PersonaStore store = (PersonaStore) v;
89               Utils.print_line ("%s, %s ('%s')", store.type_id, store.id,
90                   store.display_name);
91             });
92           Utils.unindent ();
93         }
94     }
95
96   public override string[]? complete_subcommand (string subcommand)
97     {
98       /* @subcommand should be a backend name */
99       return Readline.completion_matches (subcommand,
100           Utils.backend_name_completion_cb);
101     }
102 }