1
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/* Baobab - disk usage analyzer
4
* Copyright (C) 2012 Paolo Borelli <pborelli@gnome.org>
5
* Copyright (C) 2012 Stefano Facchini <stefano.facchini@gmail.com>
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 2
10
* of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24
public class LocationWidget : Gtk.Grid {
25
private static Gtk.SizeGroup name_size_group = null;
26
private static Gtk.SizeGroup usage_size_group = null;
27
private static Gtk.IconSize icon_size;
29
public Location? location { get; private set; }
31
void ensure_size_groups () {
32
if (name_size_group == null) {
33
name_size_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL);
34
usage_size_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.HORIZONTAL);
35
icon_size = Gtk.icon_size_register ("baobab", 64, 64);
39
public LocationWidget (Location location_) {
42
orientation = Gtk.Orientation.HORIZONTAL;
46
ensure_size_groups ();
48
var image = new Gtk.Image.from_gicon (location.icon, icon_size);
49
image.set_pixel_size (64);
50
attach (image, 0, 0, 1, 2);
52
var escaped = GLib.Markup.escape_text (location.name, -1);
53
var label = new Gtk.Label ("<b>%s</b>".printf (escaped));
54
name_size_group.add_widget (label);
55
label.use_markup = true;
57
label.halign = Gtk.Align.START;
58
label.valign = Gtk.Align.END;
60
attach (label, 1, 0, 1, 1);
62
escaped = location.file != null ? GLib.Markup.escape_text (location.file.get_parse_name (), -1) : "";
63
label = new Gtk.Label ("<small>%s</small>".printf (escaped));
64
name_size_group.add_widget (label);
65
label.use_markup = true;
67
label.halign = Gtk.Align.START;
68
label.valign = Gtk.Align.START;
70
label.get_style_context ().add_class ("dim-label");
71
attach (label, 1, 1, 1, 1);
73
if (location.is_volume && location.used != null && location.size != null) {
74
label = new Gtk.Label ("<small>%s / %s</small>".printf (format_size (location.used), format_size (location.size)));
75
usage_size_group.add_widget (label);
76
label.use_markup = true;
77
label.halign = Gtk.Align.END;
78
label.valign = Gtk.Align.END;
79
attach (label, 2, 0, 1, 1);
81
var usagebar = new Gtk.LevelBar ();
82
usage_size_group.add_widget (usagebar);
83
usagebar.set_max_value (location.size);
84
// Set critical color at 90% of the size
85
usagebar.add_offset_value (Gtk.LEVEL_BAR_OFFSET_LOW, 0.9 * location.size);
86
usagebar.set_value (location.used);
87
usagebar.hexpand = true;
88
usagebar.halign = Gtk.Align.FILL;
89
usagebar.valign = Gtk.Align.START;
90
attach (usagebar, 2, 1, 1, 1);
93
attach (new Gtk.Arrow (Gtk.ArrowType.RIGHT, Gtk.ShadowType.NONE), 3, 0, 1, 2);