1/* Copyright 2016 Software Freedom Conservancy Inc. 2 * 3 * This software is licensed under the GNU Lesser General Public License 4 * (version 2.1 or later). See the COPYING file in this distribution. 5 */ 6 7public class EventPage : CollectionPage { 8 private Event page_event; 9 10 public EventPage(Event page_event) { 11 base (page_event.get_name()); 12 13 this.page_event = page_event; 14 page_event.mirror_photos(get_view(), create_thumbnail); 15 16 init_page_context_menu("EventContextMenu"); 17 18 Event.global.items_altered.connect(on_events_altered); 19 } 20 21 public Event get_event() { 22 return page_event; 23 } 24 25 protected override bool on_app_key_pressed(Gdk.EventKey event) { 26 // If and only if one image is selected, propagate F2 to the rest of 27 // the window, otherwise, consume it here - if we don't do this, it'll 28 // either let us re-title multiple images at the same time or 29 // spuriously highlight the event name in the sidebar for editing... 30 if (Gdk.keyval_name(event.keyval) == "F2") { 31 if (get_view().get_selected_count() != 1) { 32 return true; 33 } 34 } 35 36 return base.on_app_key_pressed(event); 37 } 38 39 ~EventPage() { 40 Event.global.items_altered.disconnect(on_events_altered); 41 get_view().halt_mirroring(); 42 } 43 44 protected override void init_collect_ui_filenames(Gee.List<string> ui_filenames) { 45 base.init_collect_ui_filenames(ui_filenames); 46 47 ui_filenames.add("event.ui"); 48 } 49 50 private const GLib.ActionEntry[] entries = { 51 { "MakePrimary", on_make_primary }, 52 { "Rename", on_rename }, 53 { "EditComment", on_edit_comment }, 54 { "EditEventComment", on_edit_event_comment } 55 }; 56 57 protected override void add_actions(GLib.ActionMap map) { 58 base.add_actions(map); 59 60 map.add_action_entries(entries, this); 61 } 62 63 protected override void remove_actions(GLib.ActionMap map) { 64 base.remove_actions(map); 65 foreach (var entry in entries) { 66 map.remove_action(entry.name); 67 } 68 } 69 70 protected override void init_actions(int selected_count, int count) { 71 base.init_actions(selected_count, count); 72 } 73 74 protected override void update_actions(int selected_count, int count) { 75 set_action_sensitive("MakePrimary", selected_count == 1); 76 77 // hide this command in CollectionPage, as it does not apply here 78 set_action_sensitive("CommonJumpToEvent", false); 79 80 base.update_actions(selected_count, count); 81 82 // this is always valid; if the user has right-clicked in an empty area, 83 // change the comment on the event itself. 84 set_action_sensitive("EditEventComment", true); 85 } 86 87 protected override void get_config_photos_sort(out bool sort_order, out int sort_by) { 88 Config.Facade.get_instance().get_event_photos_sort(out sort_order, out sort_by); 89 } 90 91 protected override void set_config_photos_sort(bool sort_order, int sort_by) { 92 Config.Facade.get_instance().set_event_photos_sort(sort_order, sort_by); 93 } 94 95 private void on_events_altered(Gee.Map<DataObject, Alteration> map) { 96 if (map.has_key(page_event)) 97 set_page_name(page_event.get_name()); 98 } 99 100 private void on_edit_event_comment() { 101 EditCommentDialog edit_comment_dialog = new EditCommentDialog(page_event.get_comment(), 102 true); 103 string? new_comment = edit_comment_dialog.execute(); 104 if (new_comment == null) 105 return; 106 107 EditEventCommentCommand command = new EditEventCommentCommand(page_event, new_comment); 108 get_command_manager().execute(command); 109 return; 110 } 111 112 protected override void on_edit_comment() { 113 base.on_edit_comment(); 114 } 115 116 private void on_make_primary() { 117 if (get_view().get_selected_count() != 1) 118 return; 119 120 page_event.set_primary_source((MediaSource) get_view().get_selected_at(0).get_source()); 121 } 122 123 private void on_rename() { 124 LibraryWindow.get_app().rename_event_in_sidebar(page_event); 125 } 126} 127 128public class NoEventPage : CollectionPage { 129 public const string NAME = _("No Event"); 130 131 // This seems very similar to EventSourceCollection -> ViewManager 132 private class NoEventViewManager : CollectionViewManager { 133 public NoEventViewManager(NoEventPage page) { 134 base (page); 135 } 136 137 // this is not threadsafe 138 public override bool include_in_view(DataSource source) { 139 return (((MediaSource) source).get_event_id().id != EventID.INVALID) ? false : 140 base.include_in_view(source); 141 } 142 } 143 144 private static Alteration no_event_page_alteration = new Alteration("metadata", "event"); 145 146 public NoEventPage() { 147 base (NAME); 148 149 ViewManager filter = new NoEventViewManager(this); 150 get_view().monitor_source_collection(LibraryPhoto.global, filter, no_event_page_alteration); 151 get_view().monitor_source_collection(Video.global, filter, no_event_page_alteration); 152 } 153 154 protected override void get_config_photos_sort(out bool sort_order, out int sort_by) { 155 Config.Facade.get_instance().get_event_photos_sort(out sort_order, out sort_by); 156 } 157 158 protected override void set_config_photos_sort(bool sort_order, int sort_by) { 159 Config.Facade.get_instance().set_event_photos_sort(sort_order, sort_by); 160 } 161} 162 163