From 5e9f4eea451a77ba3b93db3747841ed2bd969e9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sun, 30 Sep 2018 14:09:20 +0200 Subject: New upstream version 0.30.1 --- src/import-roll/ImportRollBranch.vala | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/import-roll/ImportRollBranch.vala (limited to 'src/import-roll/ImportRollBranch.vala') diff --git a/src/import-roll/ImportRollBranch.vala b/src/import-roll/ImportRollBranch.vala new file mode 100644 index 0000000..32337cc --- /dev/null +++ b/src/import-roll/ImportRollBranch.vala @@ -0,0 +1,45 @@ +public class ImportRoll.Branch : Sidebar.Branch { + private Gee.HashMap entries; + + public class Branch() { + base (new ImportRoll.Root(), + Sidebar.Branch.Options.HIDE_IF_EMPTY, + ImportRoll.Branch.comparator); + + this.entries = new Gee.HashMap((Gee.HashDataFunc)GLib.int64_hash, + (Gee.EqualDataFunc)GLib.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")); + } +} -- cgit v1.2.3