Commit 4f076e4b authored by Patrick Tierney's avatar Patrick Tierney

#1712: added No Event page

parent 80a242fa
......@@ -5,9 +5,34 @@
*/
public class EventSourceCollection : ContainerSourceCollection {
public signal void no_event_collection_altered();
private ViewCollection no_event;
private class NoEventViewManager : ViewManager {
public override bool include_in_view(DataSource source) {
// Note: this is not threadsafe
return (((LibraryPhoto) source).get_event_id().id != EventID.INVALID) ? false :
base.include_in_view(source);
}
public override DataView create_view(DataSource source) {
return new PhotoView((PhotoSource) source);
}
}
public EventSourceCollection() {
base(LibraryPhoto.global, Event.BACKLINK_NAME, "EventSourceCollection", get_event_key);
}
public void init() {
no_event = new ViewCollection("No Event View Collection");
no_event.monitor_source_collection(LibraryPhoto.global, new NoEventViewManager(),
new Alteration("metadata", "event"));
no_event.contents_altered.connect(on_no_event_collection_altered);
}
private static int64 get_event_key(DataSource source) {
Event event = (Event) source;
......@@ -45,6 +70,15 @@ public class EventSourceCollection : ContainerSourceCollection {
return null;
}
public Gee.Collection<DataObject> get_no_event_objects() {
return no_event.get_sources();
}
private void on_no_event_collection_altered(Gee.Iterable<DataObject>? added,
Gee.Iterable<DataObject>? removed) {
no_event_collection_altered();
}
}
public class Event : EventSource, ContainerSource, Proxyable {
......@@ -198,6 +232,7 @@ public class Event : EventSource, ContainerSource, Proxyable {
public static void init(ProgressMonitor? monitor = null) {
event_table = EventTable.get_instance();
global = new EventSourceCollection();
global.init();
// add all events to the global collection
Gee.ArrayList<Event> events = new Gee.ArrayList<Event>();
......
......@@ -332,6 +332,68 @@ public class EventsDirectoryPage : CheckerboardPage {
}
}
public class NoEventPage : CollectionPage {
static const string NO_EVENT_PAGE_NAME = "No Events";
public class Stub : PageStub {
public override string? get_icon_name() {
return Resources.ICON_MISSING_FILES;
}
public override string get_name() {
return NO_EVENT_PAGE_NAME;
}
public override bool is_renameable() {
return false;
}
protected override Page construct_page() {
return ((Page) new NoEventPage());
}
}
// This seems very similar to EventSourceCollection -> ViewManager
private class NoEventViewManager : CollectionViewManager {
public NoEventViewManager(NoEventPage page) {
base(page);
}
// this is not threadsafe
public override bool include_in_view(DataSource source) {
return (((LibraryPhoto) source).get_event_id().id != EventID.INVALID) ? false :
base.include_in_view(source);
}
}
private static Alteration no_event_page_alteration = new Alteration("metadata", "event");
private NoEventPage() {
base(NO_EVENT_PAGE_NAME);
// Adds one menu entry per alien database driver
AlienDatabaseHandler.get_instance().add_menu_entries(
ui, "/EventsDirectoryMenuBar/FileMenu/ImportFromAlienDbPlaceholder"
);
get_view().monitor_source_collection(LibraryPhoto.global, new NoEventViewManager(this),
no_event_page_alteration);
}
public static Stub create_stub() {
return new Stub();
}
protected override void get_config_photos_sort(out bool sort_order, out int sort_by) {
Config.get_instance().get_event_photos_sort(out sort_order, out sort_by);
}
protected override void set_config_photos_sort(bool sort_order, int sort_by) {
Config.get_instance().set_event_photos_sort(sort_order, sort_by);
}
}
public class EventPage : CollectionPage {
public class Stub : PageStub {
public Event event;
......
......@@ -95,6 +95,7 @@ public class LibraryWindow : AppWindow {
private MasterEventsDirectoryPage.Stub events_directory_page = null;
private LibraryPhotoPage photo_page = null;
private TrashPage.Stub trash_page = null;
private NoEventPage.Stub no_event_page = null;
private OfflinePage.Stub offline_page = null;
private LastImportPage.Stub last_import_page = null;
private ImportQueuePage import_queue_page = null;
......@@ -166,6 +167,10 @@ public class LibraryWindow : AppWindow {
// watch for photos placed offline
LibraryPhoto.global.offline_contents_altered.connect(on_offline_contents_altered);
enable_disable_offline_page(LibraryPhoto.global.get_offline().size > 0);
// watch for photos with no events
Event.global.no_event_collection_altered.connect(on_no_event_collection_altered);
enable_disable_no_event_page(Event.global.get_no_event_objects().size > 0);
// start in the collection page
sidebar.place_cursor(library_page);
......@@ -346,6 +351,12 @@ public class LibraryWindow : AppWindow {
if (a is SubEventsDirectoryPage.Stub && b is SubEventsDirectoryPage.Stub) {
start_a = get_event_directory_page_time((SubEventsDirectoryPage.Stub *) a);
start_b = get_event_directory_page_time((SubEventsDirectoryPage.Stub *) b);
} else if (a is NoEventPage.Stub) {
assert(b is SubEventsDirectoryPage.Stub || b is EventPage.Stub);
return events_sort_ascending ? 1 : -1;
} else if (b is NoEventPage.Stub) {
assert(a is SubEventsDirectoryPage.Stub || a is EventPage.Stub);
return events_sort_ascending ? -1 : 1;
} else {
assert(a is EventPage.Stub);
assert(b is EventPage.Stub);
......@@ -1040,6 +1051,20 @@ public class LibraryWindow : AppWindow {
}
}
private void on_no_event_collection_altered() {
enable_disable_no_event_page(Event.global.get_no_event_objects().size > 0);
}
private void enable_disable_no_event_page(bool enable) {
if (enable && no_event_page == null) {
no_event_page = NoEventPage.create_stub();
sidebar.add_child(events_directory_page.get_marker(), no_event_page);
} else if (!enable && no_event_page != null) {
remove_stub(no_event_page, null, events_directory_page);
no_event_page = null;
}
}
private void enable_disable_offline_page(bool enable) {
if (enable && offline_page == null) {
offline_page = OfflinePage.create_stub();
......@@ -1523,6 +1548,15 @@ public class LibraryWindow : AppWindow {
private bool is_event_selected(Gtk.TreePath path) {
return select_from_collection(path, event_list);
}
private bool is_no_event_selected(Gtk.TreePath path) {
if (is_page_selected(no_event_page, path)) {
switch_to_page(no_event_page.get_page());
return true;
}
return false;
}
private bool is_tag_selected(Gtk.TreePath path) {
return select_from_collection(path, tag_map.values);
......@@ -1544,6 +1578,8 @@ public class LibraryWindow : AppWindow {
// events directory page selected and updated
} else if (is_event_selected(path)) {
// event page selected and updated
} else if (is_no_event_selected(path)) {
// no event page selected and updated
} else if (is_tag_selected(path)) {
// tag page selected and updated
} else if (is_page_selected(trash_page, path)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment