summaryrefslogtreecommitdiff
path: root/src/baobab-folder-display.vala
blob: a16fde84c2232c2e361df52a8e397eee23f2c2ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* Baobab - disk usage analyzer
 *
 * Copyright (C) 2020  Stefano Facchini <stefano.facchini@gmail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

namespace Baobab {

    [GtkTemplate (ui = "/org/gnome/baobab/ui/baobab-folder-display.ui")]
    public class FolderDisplay : Gtk.TreeView {
        [GtkChild]
        public Gtk.TreeViewColumn folder_column;
        [GtkChild]
        public Gtk.TreeViewColumn size_column;
        [GtkChild]
        public Gtk.TreeViewColumn contents_column;
        [GtkChild]
        public Gtk.TreeViewColumn time_modified_column;
        [GtkChild]
        private Gtk.CellRendererPixbuf folder_column_icon_renderer;

        construct {
            row_activated.connect (() => { activated (); });
            model = create_model ();
        }

        public signal void activated ();

        private ulong location_progress_handler;

        Location location_;
        public Location location {
            set {
                if (location_progress_handler > 0) {
                    SignalHandler.disconnect (location_, location_progress_handler);
                    location_progress_handler = 0;
                }

                location_ = value;

                var list_store = (Gtk.ListStore) model;
                list_store.clear ();
                list_store.insert_with_values (null, -1,
                           Scanner.Columns.NAME, location.name);

                folder_column_icon_renderer.visible = false;

                location_progress_handler = location_.progress.connect (() => {
                    Gtk.TreeIter iter;
                    list_store.get_iter_first (out iter);
                    list_store.set (iter,
                            Scanner.Columns.SIZE, location_.scanner.total_size,
                            Scanner.Columns.ELEMENTS, location_.scanner.total_elements);
                });
            }

            get {
                return location_;
            }
        }

        Gtk.TreePath path_;
        public new Gtk.TreePath path {
            set {
                path_ = value;

                Gtk.TreeIter iter;
                location.scanner.get_iter (out iter, value);

                string name;
                string display_name;
                uint64 size;
                int elements;
                uint64 time;
                Scanner.State state;

                location.scanner.get (iter,
                           Scanner.Columns.NAME, out name,
                           Scanner.Columns.DISPLAY_NAME, out display_name,
                           Scanner.Columns.SIZE, out size,
                           Scanner.Columns.ELEMENTS, out elements,
                           Scanner.Columns.TIME_MODIFIED, out time,
                           Scanner.Columns.STATE, out state);

                if (value.get_depth () == 1) {
                    name = location.name;
                    folder_column_icon_renderer.visible = false;
                } else {
                    folder_column_icon_renderer.visible = true;
                }

                var list_store = (Gtk.ListStore) model;
                list_store.clear ();
                list_store.insert_with_values (null, -1,
                           Scanner.Columns.NAME, name,
                           Scanner.Columns.DISPLAY_NAME, display_name,
                           Scanner.Columns.SIZE, size,
                           Scanner.Columns.ELEMENTS, elements,
                           Scanner.Columns.TIME_MODIFIED, time,
                           Scanner.Columns.STATE, state);
            }
            get {
                return path_;
            }
        }

        Gtk.ListStore create_model () {
            var list_store = new Gtk.ListStore.newv (new Type[] {
                typeof (string),  // NAME
                typeof (double),  // PERCENT
                typeof (uint64),  // SIZE
                typeof (uint64),  // TIME_MODIFIED
                typeof (string),  // DISPLAY_NAME
                typeof (int),     // ELEMENTS
                typeof (Scanner.State)    // STATE
            });
            list_store.set_sort_column_id (Scanner.Columns.SIZE, Gtk.SortType.DESCENDING);

            return list_store;
        }
    }
}