33 * SPDX-License-Identifier: GPL-3.0-or-later
44 */
55
6- public class Monitor.SystemStorageView : Gtk .Grid {
7- private Chart storage_chart;
8- private Storage storage;
6+ public class Monitor.SystemStorageView : Gtk .Box {
7+ public Storage storage { get ; construct; }
98
10- private Granite . HeaderLabel storage_name_label ;
9+ private Chart storage_chart ;
1110 private LabelRoundy storage_read_label;
1211 private LabelRoundy storage_write_label;
1312
14- private Gtk . Box drive_cards_container;
15-
16- construct {
17- margin = 12 ;
18- column_spacing = 12 ;
19- set_vexpand (false );
20- }
21-
2213 public SystemStorageView (Storage _storage ) {
23- storage = _storage;
14+ Object (storage: _storage);
15+ }
2416
25- storage_name_label = new Granite .HeaderLabel (_(" Storage" ));
17+ construct {
18+ var storage_name_label = new Granite .HeaderLabel (_(" Storage" ));
2619
2720 storage_write_label = new LabelRoundy (_(" WRITE" ));
2821 storage_write_label. val. set_width_chars (7 );
@@ -37,86 +30,42 @@ public class Monitor.SystemStorageView : Gtk.Grid {
3730 storage_chart. set_serie_color (0 , { 155 / 255.0 , 219 / 255.0 , 77 / 255.0 , 1.0 });
3831 storage_chart. set_serie_color (1 , { 100 / 255.0 , 186 / 255.0 , 255 / 255.0 , 1.0 });
3932
40- var labels_grid = new Gtk .Grid ();
41- labels_grid. row_spacing = 6 ;
42- labels_grid. column_spacing = 6 ;
43- labels_grid. margin = 6 ;
44- labels_grid. attach (storage_write_label, 0 , 0 , 1 , 1 );
45- labels_grid. attach (storage_read_label, 1 , 0 , 1 , 1 );
46-
47- drive_cards_container = new Gtk .Box (Gtk . Orientation . HORIZONTAL , 0 );
48-
49- storage. get_drives (). foreach (add_drive_card);
50-
51- attach (storage_name_label, 0 , 0 , 1 , 1 );
52- attach (drive_cards_container, 0 , 1 , 1 , 1 );
53- attach (labels_grid, 0 , 2 , 2 , 2 );
54- attach (storage_chart, 0 , 2 , 2 , 2 );
55- }
56-
57- private bool add_drive_card (owned Disk ? drive ) {
58- drive_cards_container. add (build_drive_card (drive. model, drive. device, drive. size, drive. free));
59- return true ;
60- }
61-
62- private Gtk .Box build_drive_card (string model , string device , uint64 size , uint64 free ) {
63- var drive_card = new Gtk .Box (Gtk . Orientation . HORIZONTAL , 0 );
64- drive_card. get_style_context (). add_class (" card" );
65- drive_card. get_style_context (). add_class (" rounded" );
66-
67- drive_card. halign = Gtk . Align . START ;
68- drive_card. margin_end = 12 ;
69- drive_card. margin_top = 6 ;
70- drive_card. margin_bottom = 12 ;
71-
72- var drive_grid = new Gtk .Grid ();
73- // drive_grid.row_spacing = 6;
74- drive_grid. column_spacing = 6 ;
75- drive_grid. margin = 6 ;
76-
77- var drive_name_label = new Gtk .Label (model);
78- drive_name_label. get_style_context (). add_class (" h3" );
79- drive_name_label. margin = 6 ;
80- drive_name_label. margin_bottom = 0 ;
81- drive_name_label. halign = Gtk . Align . START ;
82-
83- string size_string = format_size ((uint64 ) size, IEC_UNITS );
84- string used_string = format_size ((uint64 ) (size - free), IEC_UNITS );
85-
86- string drive_block_name_and_size_string = " %s 𐄁 %s / %s " . printf (device, used_string, size_string);
87-
88- if (free == 0 )drive_block_name_and_size_string = " %s 𐄁 %s " . printf (device, size_string);
89-
90- var drive_block_name_and_size_label = new Gtk .Label (drive_block_name_and_size_string);
91- drive_block_name_and_size_label. get_style_context (). add_class (" h4" );
92- drive_block_name_and_size_label. get_style_context (). add_class (" text-secondary" );
93- drive_block_name_and_size_label. margin = 6 ;
94- drive_block_name_and_size_label. margin_top = 0 ;
95- drive_block_name_and_size_label. halign = Gtk . Align . START ;
96-
97- var drive_not_mounted_label = new Gtk .Label (_(" Not mounted" ));
98- drive_not_mounted_label. halign = Gtk . Align . START ;
99- drive_not_mounted_label. get_style_context (). add_class (" h4" );
100- drive_not_mounted_label. margin_start = 6 ;
101-
102- var usagebar = new Gtk .LevelBar ();
103- usagebar. get_style_context (). add_class (" flat" );
104- usagebar. margin = 6 ;
105- usagebar. margin_top = 0 ;
106- usagebar. set_max_value (100.0 );
107- usagebar. set_min_value (0.0 );
108- usagebar. set_value (100.0 * (size - free) / size);
109-
110- drive_grid. attach (drive_name_label, 0 , 0 , 1 , 1 );
111- drive_grid. attach (drive_block_name_and_size_label, 0 , 1 , 1 , 1 );
112- if (free == 0 ) {
113- drive_grid. attach (drive_not_mounted_label, 0 , 2 , 1 , 1 );
114- } else {
115- drive_grid. attach (usagebar, 0 , 2 , 1 , 1 );
116- }
117- drive_card. add (drive_grid);
118-
119- return drive_card;
33+ var labels_box = new Gtk .Box (HORIZONTAL , 6 ) {
34+ margin_top = 6 ,
35+ margin_end = 6 ,
36+ margin_bottom = 6 ,
37+ margin_start = 6
38+ };
39+ labels_box. add (storage_write_label);
40+ labels_box. add (storage_read_label);
41+
42+ var chart_overlay = new Gtk .Overlay () {
43+ child = storage_chart
44+ };
45+ chart_overlay. add_overlay (labels_box);
46+
47+ var drive_cards_container = new Gtk .Box (HORIZONTAL , 12 ) {
48+ margin_top = 6 ,
49+ margin_bottom = 12
50+ };
51+
52+ margin_top = 12 ;
53+ margin_end = 12 ;
54+ margin_bottom = 12 ;
55+ margin_start = 12 ;
56+ orientation = VERTICAL ;
57+
58+ add (storage_name_label);
59+ add (drive_cards_container);
60+ add (chart_overlay);
61+
62+ storage. get_drives (). foreach ((drive) = > {
63+ drive_cards_container. add (
64+ new DriveCard (drive)
65+ );
66+
67+ return GLib . Source . CONTINUE ;
68+ });
12069 }
12170
12271 public void update () {
@@ -130,4 +79,64 @@ public class Monitor.SystemStorageView : Gtk.Grid {
13079 }
13180 }
13281
82+ private class DriveCard : Gtk .Box {
83+ public Disk drive { get ; construct; }
84+
85+ public DriveCard (Disk drive ) {
86+ Object (drive: drive);
87+ }
88+
89+ construct {
90+ var drive_name_label = new Gtk .Label (drive. model) {
91+ halign = START
92+ };
93+ drive_name_label. get_style_context (). add_class (Granite . STYLE_CLASS_H3_LABEL );
94+
95+ string size_string = format_size ((uint64 ) drive. size, IEC_UNITS );
96+ string used_string = format_size ((uint64 ) (drive. size - drive. free), IEC_UNITS );
97+
98+ string drive_block_name_and_size_string = " %s 𐄁 %s / %s " . printf (drive. device, used_string, size_string);
99+
100+ if (drive. free == 0 ) {
101+ drive_block_name_and_size_string = " %s 𐄁 %s " . printf (drive. device, size_string);
102+ }
103+
104+ var drive_block_name_and_size_label = new Gtk .Label (drive_block_name_and_size_string) {
105+ halign = START ,
106+ margin_bottom = 6
107+ };
108+ drive_block_name_and_size_label. get_style_context (). add_class (Gtk . STYLE_CLASS_DIM_LABEL );
109+
110+ var drive_not_mounted_label = new Gtk .Label (_(" Not mounted" )) {
111+ halign = START
112+ };
113+ drive_not_mounted_label. get_style_context (). add_class (Gtk . STYLE_CLASS_DIM_LABEL );
114+
115+ var usagebar = new Gtk .LevelBar () {
116+ max_value = 100.0 ,
117+ min_value = 0.0 ,
118+ margin_bottom = 6
119+ };
120+ usagebar. get_style_context (). add_class (Gtk . STYLE_CLASS_FLAT );
121+ usagebar. set_value (100.0 * (drive. size - drive. free) / drive. size);
122+
123+ var drive_box = new Gtk .Box (VERTICAL , 0 ) {
124+ margin_top = 6 ,
125+ margin_end = 12 ,
126+ margin_bottom = 6 ,
127+ margin_start = 12
128+ };
129+ drive_box. add (drive_name_label);
130+ drive_box. add (drive_block_name_and_size_label);
131+ if (drive. free == 0 ) {
132+ drive_box. add (drive_not_mounted_label);
133+ } else {
134+ drive_box. add (usagebar);
135+ }
136+
137+ get_style_context (). add_class (Granite . STYLE_CLASS_CARD );
138+ get_style_context (). add_class (Granite . STYLE_CLASS_ROUNDED );
139+ add (drive_box);
140+ }
141+ }
133142}
0 commit comments