[shotwell] Add import rolls to sidebar



commit 48f0839160270693c52d6681ee14592fbd638dad
Author: Jens Georg <mail+gitkraken jensge org>
Date:   Sun Apr 1 09:46:05 2018 +0200

    Add import rolls to sidebar
    
    https://bugzilla.gnome.org/show_bug.cgi?id=716284

 src/import-roll/ImportRollBranch.vala |   46 +++++++++++++++++++++++++++++++++
 src/import-roll/ImportRollEntry.vala  |   34 ++++++++++++++++++++++++
 src/library/LastImportPage.vala       |   14 ++++++++++
 src/library/LibraryWindow.vala        |    3 ++
 src/meson.build                       |    2 +
 5 files changed, 99 insertions(+), 0 deletions(-)
---
diff --git a/src/import-roll/ImportRollBranch.vala b/src/import-roll/ImportRollBranch.vala
new file mode 100644
index 0000000..314055d
--- /dev/null
+++ b/src/import-roll/ImportRollBranch.vala
@@ -0,0 +1,46 @@
+public class ImportRoll.Branch : Sidebar.Branch {
+    private Gee.HashMap<int64?, ImportRoll.SidebarEntry> entries;
+
+    public class Branch() {
+        base (new ImportRoll.Root(),
+              Sidebar.Branch.Options.STARTUP_OPEN_GROUPING
+              | 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);
+    }
+}
+
diff --git a/src/library/LastImportPage.vala b/src/library/LastImportPage.vala
index be30989..84f582e 100644
--- a/src/library/LastImportPage.vala
+++ b/src/library/LastImportPage.vala
@@ -35,6 +35,20 @@ public class LastImportPage : CollectionPage {
         // set up view manager for the last import roll
         on_import_rolls_altered();
     }
+
+    public LastImportPage.for_id(ImportID id) {
+        base(NAME);
+
+        this.last_import_id = id;
+
+        get_view().halt_all_monitoring();
+        get_view().clear();
+
+        foreach (MediaSourceCollection col in MediaCollectionRegistry.get_instance().get_all()) {
+            get_view().monitor_source_collection(col, new LastImportViewManager(this,
+                last_import_id), last_import_alteration);
+        }
+     }
     
     ~LastImportPage() {
         foreach (MediaSourceCollection col in MediaCollectionRegistry.get_instance().get_all()) {
diff --git a/src/library/LibraryWindow.vala b/src/library/LibraryWindow.vala
index b83b7d8..94a18d9 100644
--- a/src/library/LibraryWindow.vala
+++ b/src/library/LibraryWindow.vala
@@ -44,6 +44,7 @@ public class LibraryWindow : AppWindow {
         CAMERAS,
         SAVED_SEARCH,
         EVENTS,
+        IMPORT_ROLL,
         FOLDERS,
         TAGS
     }
@@ -112,6 +113,7 @@ public class LibraryWindow : AppWindow {
     private Events.Branch events_branch = new Events.Branch();
     private Camera.Branch camera_branch = new Camera.Branch();
     private Searches.Branch saved_search_branch = new Searches.Branch();
+    private ImportRoll.Branch import_roll_branch = new ImportRoll.Branch();
     private bool page_switching_enabled = true;
     
     private Gee.HashMap<Page, Sidebar.Entry> page_map = new Gee.HashMap<Page, Sidebar.Entry>();
@@ -166,6 +168,7 @@ public class LibraryWindow : AppWindow {
         sidebar_tree.graft(events_branch, SidebarRootPosition.EVENTS);
         sidebar_tree.graft(camera_branch, SidebarRootPosition.CAMERAS);
         sidebar_tree.graft(saved_search_branch, SidebarRootPosition.SAVED_SEARCH);
+        sidebar_tree.graft(import_roll_branch, SidebarRootPosition.IMPORT_ROLL);
         
         // create and connect extended properties window
         extended_properties = new ExtendedPropertiesWindow(this);
diff --git a/src/meson.build b/src/meson.build
index 6a901ef..7a3f775 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -142,6 +142,8 @@ executable('shotwell',
             'folders/Folders.vala',
             'folders/FoldersBranch.vala',
             'folders/FoldersPage.vala',
+            'import-roll/ImportRollBranch.vala',
+            'import-roll/ImportRollEntry.vala',
             'main.vala',
             'AppWindow.vala',
             'CollectionPage.vala',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]