~ubuntu-branches/ubuntu/wily/baobab/wily-proposed

« back to all changes in this revision

Viewing changes to src/baobab-location-widget.vala

  • Committer: Package Import Robot
  • Author(s): Jackson Doak
  • Date: 2014-10-15 23:15:13 UTC
  • mfrom: (2.2.1 experimental) (2.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20141015231513-6cpun88orgfpyzdv
Tags: 3.14.1-1ubuntu1
* Merge from Debian unstable. (LP: #1268721) Remaining changes:
* debian/patches/use_traditional_titlebars_in_unity.patch:
  - Use the traditional menubar under Unity
* debian/patches/git_fix_pie_chart.patch:
  - Fx top level pie chart. (LP: #1393333)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
 
/* Baobab - disk usage analyzer
3
 
 *
4
 
 * Copyright (C) 2012  Paolo Borelli <pborelli@gnome.org>
5
 
 * Copyright (C) 2012  Stefano Facchini <stefano.facchini@gmail.com>
6
 
 *
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.
11
 
 *
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.
16
 
 *
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.
20
 
 */
21
 
 
22
 
namespace Baobab {
23
 
 
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;
28
 
 
29
 
        public Location? location { get; private set; }
30
 
 
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);
36
 
            }
37
 
        }
38
 
 
39
 
        public LocationWidget (Location location_) {
40
 
            location = location_;
41
 
 
42
 
            orientation = Gtk.Orientation.HORIZONTAL;
43
 
            column_spacing = 12;
44
 
            margin = 6;
45
 
 
46
 
            ensure_size_groups ();
47
 
 
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);
51
 
 
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;
56
 
            label.hexpand = true;
57
 
            label.halign = Gtk.Align.START;
58
 
            label.valign = Gtk.Align.END;
59
 
            label.xalign = 0;
60
 
            attach (label, 1, 0, 1, 1);
61
 
 
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;
66
 
            label.hexpand = true;
67
 
            label.halign = Gtk.Align.START;
68
 
            label.valign = Gtk.Align.START;
69
 
            label.xalign = 0;
70
 
            label.get_style_context ().add_class ("dim-label");
71
 
            attach (label, 1, 1, 1, 1);
72
 
 
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);
80
 
 
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);
91
 
            }
92
 
 
93
 
            attach (new Gtk.Arrow (Gtk.ArrowType.RIGHT, Gtk.ShadowType.NONE), 3, 0, 1, 2);
94
 
 
95
 
            show_all ();
96
 
        }
97
 
    }
98
 
}