summaryrefslogtreecommitdiff
path: root/src/import-roll/ImportRollBranch.vala
blob: 0c582ac8943b13f9eb7bc454d8594dfa3146683d (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
public class ImportRoll.Branch : Sidebar.Branch {
    private Gee.HashMap<int64?, ImportRoll.SidebarEntry> entries;

    public class Branch() {
        base (new ImportRoll.Root(),
              Sidebar.Branch.Options.HIDE_IF_EMPTY,
              ImportRoll.Branch.comparator);

        this.entries = new Gee.HashMap<int64?, ImportRoll.SidebarEntry>(int64_hash, int64_equal);

        foreach (var source in MediaCollectionRegistry.get_instance().get_all()) {
            on_import_rolls_altered(source);
            source.import_roll_altered.connect(on_import_rolls_altered);
        }

    }

    private static int comparator(Sidebar.Entry a, Sidebar.Entry b) {
        if (a == b)
            return 0;

        var entry_a = (ImportRoll.SidebarEntry) a;
        var entry_b = (ImportRoll.SidebarEntry) b;

        return -ImportID.compare_func(entry_a.get_id(), entry_b.get_id());
    }

    private void on_import_rolls_altered(MediaSourceCollection source) {
        var ids = source.get_import_roll_ids();
        foreach (var id in ids) {
            if (!this.entries.has_key (id.id)) {
                var entry = new ImportRoll.SidebarEntry(id);
                entries.set(id.id, entry);
                graft(get_root(), entry);
            }
        }
    }
}

private class ImportRoll.Root : Sidebar.Header {
    public Root() {
        base (_("Imports"), _("Browse the library’s import history"));
    }
}