1// Copyright © SixtyFPS GmbH <info@slint.dev>
2// SPDX-License-Identifier: MIT
3
4import { TabWidget, StandardButton, GridBox, VerticalBox, ListView } from "std-widgets.slint";
5
6
7export component SysInfo inherits Dialog {
8 in-out property os_name <=> os-name.text;
9 in-out property uptime <=> uptime.text;
10 in-out property cpu_count <=> cpu-count.text;
11 in-out property cpu_model <=> cpu-model.text;
12 in-out property cpu_vendor <=> cpu-vendor.text;
13 in-out property <int> mem_size_kb;
14 in-out property <int> buffer_mem_size_kb;
15 in-out property <int> swap_total_kb;
16 in-out property <int> swap_used_kb;
17 in-out property <int> swap_free_kb;
18 in-out property <[{dev: string, mnt: string, total: int, free: int}]> partitions;
19
20 function human-unit(unit : int) -> string {
21 if (unit > 900 * 1000 * 1000) {
22 return "\{round(unit / 1000 / 1000 / 100) / 10} GB";
23 } else if (unit > 900 * 1000) {
24 return "\{round(unit / 1000 / 100) / 10} MB";
25 } else if (unit > 900) {
26 return "\{round(unit / 100) / 10} kB";
27 }
28 return "\{unit} B";
29 }
30
31 title: "System information";
32 preferred-width: 600px;
33 preferred-height: 400px;
34
35 TabWidget {
36 Tab {
37 title: "General";
38
39 GridBox {
40 Row {
41 Image {
42 rowspan: 6;
43 source: @image-url("laptop.svg");
44 min-width: 128px;
45 }
46
47 Text {
48 col: 1;
49 text: "Operating System:";
50 max-width: self.min-width;
51 }
52 os-name := Text {}
53 }
54 Row {
55 Text {
56 col: 1;
57 text: "CPU Model:";
58 max-width: self.min-width;
59 }
60
61 cpu-model := Text {}
62 }
63 Row {
64 Text {
65 col: 1;
66 text: "CPU Vendor:";
67 max-width: self.min-width;
68 }
69
70 cpu-vendor := Text {}
71 }
72 Row {
73 Text {
74 col: 1;
75 text: "Number of logical cores:";
76 max-width: self.min-width;
77 }
78
79 cpu-count := Text {}
80 }
81 Row {
82 Text{
83 col: 1;
84 text: "Uptime:";
85 max-width: self.min-width;
86 }
87
88 uptime := Text {}
89 }
90
91 Rectangle {}
92 }
93 }
94
95 Tab {
96 title: "Memory";
97
98 GridBox {
99 Row {
100 Text {
101 text: "Installed Memory:";
102 max-width: self.min-width;
103 }
104
105 Text {
106 text: "\{floor(root.mem_size_kb / (1024*1024))} GiB";
107 }
108 }
109 Row {
110 Text {
111 text: "Buffer/Cache Memory:";
112 max-width: self.min-width;
113 }
114
115 Text {
116 text: "\{floor(root.buffer_mem_size_kb / (1024*1024))} GiB";
117 }
118 }
119 Row {
120 Text {
121 text: "Swap Total:";
122 max-width: self.min-width;
123 }
124
125 Text {
126 text: "\{floor(root.swap_total_kb / (1024*1024))} GiB";
127 }
128 }
129 Row {
130 Text {
131 text: "Swap Used:";
132 max-width: self.min-width;
133 }
134
135 Text {
136 text: "\{floor(root.swap_used_kb / (1024*1024))} GiB";
137 }
138 }
139 Row {
140 Text {
141 text: "Swap Free:";
142 max-width: self.min-width;
143 }
144
145 Text {
146 text: "\{floor(root.swap_free_kb / (1024*1024))} GiB";
147 }
148 }
149 Row {
150 Rectangle {}
151 }
152 }
153 }
154
155 Tab {
156 title: "Partitions";
157
158 VerticalBox {
159 padding: 5px;
160
161 HorizontalLayout {
162 padding: 5px; spacing: 5px;
163 t1 := Text { width: 25%; overflow: elide; text: "Device"; }
164 t2 := Text { width: 25%; overflow: elide; text: "Mount Point"; }
165 t3 := Text { width: self.preferred-width * 2; text: "Total"; }
166 t4 := Text { width: t3.width; text: "Free"; }
167 t5 := Text { horizontal-stretch: 1; text: "Usage"; }
168 }
169
170 ListView {
171 for disk in root.partitions : HorizontalLayout {
172 padding: 5px;
173 spacing: 5px;
174 accessible-role: list-item;
175
176 Text { width: t1.width; overflow: elide; text: disk.dev; }
177 Text { width: t2.width; overflow: elide; text: disk.mnt; }
178 Text { width: t3.width; text: root.human-unit(disk.total); }
179 Text { width: t4.width; text: root.human-unit(disk.free); }
180
181 Rectangle {
182 min-width: t.min-width + 10px;
183 background: lightblue;
184
185 Rectangle {
186 x:0;
187 background: lightgray;
188 width: (1 - (disk.free / disk.total)) * parent.width;
189 }
190 t := Text {
191 y:0;
192 x: 5px;
193 text: round(100 - 100 * (disk.free / disk.total)) + "%";
194 }
195 }
196 }
197 }
198 }
199 }
200 }
201
202 StandardButton { kind: close; }
203}
204