1/* 2* Copyright (c) 2011-2013 Yorba Foundation 3* 4* This program is free software; you can redistribute it and/or 5* modify it under the terms of the GNU Lesser General Public 6* License as published by the Free Software Foundation; either 7* version 2.1 of the License, or (at your option) any later version. 8* 9* This program is distributed in the hope that it will be useful, 10* but WITHOUT ANY WARRANTY; without even the implied warranty of 11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12* General Public License for more details. 13* 14* You should have received a copy of the GNU General Public 15* License along with this program; if not, write to the 16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17* Boston, MA 02110-1301 USA 18*/ 19 20public class Library.Branch : Sidebar.Branch { 21 private const string POSITION_DATA = "x-photos-entry-position"; 22 23 public Library.PhotosEntry photos_entry { 24 get; 25 private set; 26 } 27 public Library.VideosEntry videos_entry { 28 get; 29 private set; 30 } 31 public Library.RawsEntry raws_entry { 32 get; 33 private set; 34 } 35 public Library.FlaggedSidebarEntry flagged_entry { 36 get; 37 private set; 38 } 39 public Library.LastImportSidebarEntry last_imported_entry { 40 get; 41 private set; 42 } 43 public Library.ImportQueueSidebarEntry import_queue_entry { 44 get; 45 private set; 46 } 47 public Library.OfflineSidebarEntry offline_entry { 48 get; 49 private set; 50 } 51 public Library.TrashSidebarEntry trash_entry { 52 get; 53 private set; 54 } 55 56 // This lists the order of the library items in the sidebar. To re-order, simply move 57 // the item in this list to a new position. These numbers should *not* persist anywhere 58 // outside the app. 59 private enum EntryPosition { 60 PHOTOS, 61 RAWS, 62 VIDEOS, 63 FLAGGED, 64 LAST_IMPORTED, 65 IMPORT_QUEUE, 66 OFFLINE, 67 TRASH 68 } 69 70 public Branch () { 71 base (new Sidebar.Grouping (_ ("Library"), null), 72 Sidebar.Branch.Options.STARTUP_OPEN_GROUPING, comparator); 73 74 photos_entry = new Library.PhotosEntry (); 75 videos_entry = new Library.VideosEntry (); 76 raws_entry = new Library.RawsEntry (); 77 trash_entry = new Library.TrashSidebarEntry (); 78 last_imported_entry = new Library.LastImportSidebarEntry (); 79 flagged_entry = new Library.FlaggedSidebarEntry (); 80 offline_entry = new Library.OfflineSidebarEntry (); 81 import_queue_entry = new Library.ImportQueueSidebarEntry (); 82 83 insert (photos_entry, EntryPosition.PHOTOS); 84 insert (raws_entry, EntryPosition.RAWS); 85 insert (trash_entry, EntryPosition.TRASH); 86 87 videos_entry.visibility_changed.connect (on_videos_visibility_changed); 88 on_videos_visibility_changed (); 89 90 flagged_entry.visibility_changed.connect (on_flagged_visibility_changed); 91 on_flagged_visibility_changed (); 92 93 last_imported_entry.visibility_changed.connect (on_last_imported_visibility_changed); 94 on_last_imported_visibility_changed (); 95 96 import_queue_entry.visibility_changed.connect (on_import_queue_visibility_changed); 97 on_import_queue_visibility_changed (); 98 99 offline_entry.visibility_changed.connect (on_offline_visibility_changed); 100 on_offline_visibility_changed (); 101 } 102 103 private void insert (Sidebar.Entry entry, int position) { 104 entry.set_data<int> (POSITION_DATA, position); 105 graft (get_root (), entry); 106 } 107 108 private void on_videos_visibility_changed () { 109 update_entry_visibility (videos_entry, EntryPosition.VIDEOS); 110 } 111 112 private void on_flagged_visibility_changed () { 113 update_entry_visibility (flagged_entry, EntryPosition.FLAGGED); 114 } 115 116 private void on_last_imported_visibility_changed () { 117 update_entry_visibility (last_imported_entry, EntryPosition.LAST_IMPORTED); 118 } 119 120 private void on_import_queue_visibility_changed () { 121 update_entry_visibility (import_queue_entry, EntryPosition.IMPORT_QUEUE); 122 } 123 124 private void on_offline_visibility_changed () { 125 update_entry_visibility (offline_entry, EntryPosition.OFFLINE); 126 } 127 128 private void update_entry_visibility (Library.HideablePageEntry entry, int position) { 129 if (entry.visible) { 130 if (!has_entry (entry)) 131 insert (entry, position); 132 } else if (has_entry (entry)) { 133 prune (entry); 134 } 135 } 136 137 private static int comparator (Sidebar.Entry a, Sidebar.Entry b) { 138 return a.get_data<int> (POSITION_DATA) - b.get_data<int> (POSITION_DATA); 139 } 140} 141 142public abstract class Library.HideablePageEntry : Sidebar.SimplePageEntry { 143 // container branch should listen to this signal 144 public signal void visibility_changed (bool visible); 145 146 private bool show_entry = false; 147 public bool visible { 148 get { 149 return show_entry; 150 } set { 151 if (value == show_entry) 152 return; 153 154 show_entry = value; 155 visibility_changed (value); 156 } 157 } 158 159 protected HideablePageEntry () { 160 } 161} 162 163public class Library.MainPage : CollectionPage { 164 public const string NAME = _ ("Library"); 165 166 public MainPage (ProgressMonitor? monitor = null) { 167 base (NAME); 168 169 foreach (MediaSourceCollection sources in MediaCollectionRegistry.get_instance ().get_all ()) 170 get_view ().monitor_source_collection (sources, new CollectionViewManager (this), null, null, monitor); 171 } 172 173 public override string get_back_name () { 174 return _("All Photos"); 175 } 176} 177