]> git.ozlabs.org Git - petitboot/blob - ui/ncurses/nc-sysinfo.c
po: Minor Russian translation updates
[petitboot] / ui / ncurses / nc-sysinfo.c
1 /*
2  *  Copyright (C) 2013 IBM Corporation
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; version 2 of the License.
7  *
8  *  This program is distributed in the hope that it will be useful,
9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *  GNU General Public License for more details.
12  *
13  *  You should have received a copy of the GNU General Public License
14  *  along with this program; if not, write to the Free Software
15  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16  */
17
18 #if defined(HAVE_CONFIG_H)
19 #include "config.h"
20 #endif
21
22 #include <string.h>
23
24 #include <talloc/talloc.h>
25 #include <types/types.h>
26 #include <log/log.h>
27 #include <util/util.h>
28 #include <i18n/i18n.h>
29
30 #include "nc-cui.h"
31 #include "nc-textscreen.h"
32 #include "nc-sysinfo.h"
33
34 struct sysinfo_screen {
35         struct text_screen text_scr;
36 };
37
38 extern const struct help_text sysinfo_help_text;
39
40 struct nc_scr *sysinfo_screen_scr(struct sysinfo_screen *screen)
41 {
42         return text_screen_scr(&screen->text_scr);
43 }
44
45 static void if_info_mac_str(struct interface_info *info,
46                 char *buf, unsigned int buflen)
47 {
48         return mac_str(info->hwaddr, info->hwaddr_size, buf, buflen);
49 }
50
51 static void sysinfo_screen_populate(struct sysinfo_screen *screen,
52                 const struct system_info *sysinfo)
53 {
54         unsigned int i;
55
56         text_screen_clear(&screen->text_scr);
57
58 #define line(...) text_screen_append_line(&screen->text_scr, __VA_ARGS__)
59         if (!sysinfo) {
60                 line(_("Waiting for system information..."));
61                 return;
62         }
63
64         line("%-12s %s", _("System type:"), sysinfo->type ?: "");
65         line("%-12s %s", _("System id:"),   sysinfo->identifier ?: "");
66
67         if (sysinfo->n_blockdevs) {
68                 line(NULL);
69                 line(_("Storage devices"));
70         }
71
72         for (i = 0; i < sysinfo->n_blockdevs; i++) {
73                 struct blockdev_info *info = sysinfo->blockdevs[i];
74
75                 line("%s:", info->name);
76                 line(_(" UUID:       %s"), info->uuid);
77                 line(_(" mounted at: %s"), info->mountpoint);
78                 line(NULL);
79         }
80
81         if (sysinfo->n_interfaces) {
82                 line(NULL);
83                 line(_("Network interfaces"));
84         }
85
86         for (i = 0; i < sysinfo->n_interfaces; i++) {
87                 struct interface_info *info = sysinfo->interfaces[i];
88                 char macbuf[32];
89
90                 if_info_mac_str(info, macbuf, sizeof(macbuf));
91
92                 line("%s:", info->name);
93                 line(_(" MAC:  %s"), macbuf);
94                 /* TRANSLATORS: these "up" / "down" strings refer to the
95                  * link status for a network connection. */
96                 line(_(" link: %s"), info->link ? _("up") : _("down"));
97                 line(NULL);
98         }
99
100 #undef line
101 }
102
103 void sysinfo_screen_update(struct sysinfo_screen *screen,
104                 const struct system_info *sysinfo)
105 {
106         sysinfo_screen_populate(screen, sysinfo);
107         text_screen_draw(&screen->text_scr);
108 }
109
110 struct sysinfo_screen *sysinfo_screen_init(struct cui *cui,
111                 const struct system_info *sysinfo,
112                 void (*on_exit)(struct cui *))
113 {
114         struct sysinfo_screen *screen;
115
116         screen = talloc_zero(cui, struct sysinfo_screen);
117         text_screen_init(&screen->text_scr, cui,
118                         _("Petitboot System Information"), on_exit);
119         text_screen_set_help(&screen->text_scr,
120                         _("System Information"), &sysinfo_help_text);
121
122         sysinfo_screen_update(screen, sysinfo);
123
124         return screen;
125 }