summaryrefslogtreecommitdiff
path: root/src/import-roll
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2018-10-01 07:17:16 +0200
committerJörg Frings-Fürst <debian@jff.email>2018-10-01 07:17:16 +0200
commit71137cc5832110d91599d68790402cf196762ed3 (patch)
treee7985bbfb6ca50ea738b38a9f852ee51431d48a7 /src/import-roll
parent8ae550d463720d5d1c0e253af29843ff15de1a54 (diff)
parent1e92964463e564bb3359a7110342182fcfdc67f2 (diff)
Merge branch 'release/debian/0.30.1-1'debian/0.30.1-1
Diffstat (limited to 'src/import-roll')
-rw-r--r--src/import-roll/ImportRollBranch.vala45
-rw-r--r--src/import-roll/ImportRollEntry.vala34
2 files changed, 79 insertions, 0 deletions
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<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>((Gee.HashDataFunc<int64?>)GLib.int64_hash,
+ (Gee.EqualDataFunc<int64?>)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"));
+ }
+}
diff --git a/src/import-roll/ImportRollEntry.vala b/src/import-roll/ImportRollEntry.vala
new file mode 100644
index 0000000..cbc56ae
--- /dev/null
+++ b/src/import-roll/ImportRollEntry.vala
@@ -0,0 +1,34 @@
+/* Copyright 2016 Software Freedom Conservancy Inc.
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later). See the COPYING file in this distribution.
+ */
+
+public class ImportRoll.SidebarEntry : Library.HideablePageEntry {
+ private ImportID id;
+ private string name;
+
+ public SidebarEntry(ImportID id) {
+ base();
+
+ this.id = id;
+ this.name = new DateTime.from_unix_local(id.id).format("%c");
+ }
+
+ public ImportID get_id() {
+ return id;
+ }
+
+ public override string get_sidebar_name() {
+ return this.name;
+ }
+
+ public override string? get_sidebar_icon() {
+ return Resources.ICON_LAST_IMPORT;
+ }
+
+ protected override Page create_page() {
+ return new LastImportPage.for_id(this.id);
+ }
+}
+