diff options
Diffstat (limited to 'src/events')
-rw-r--r-- | src/events/EventDirectoryItem.vala | 2 | ||||
-rw-r--r-- | src/events/EventsBranch.vala | 40 | ||||
-rw-r--r-- | src/events/EventsDirectoryPage.vala | 40 |
3 files changed, 48 insertions, 34 deletions
diff --git a/src/events/EventDirectoryItem.vala b/src/events/EventDirectoryItem.vala index 5b177fb..dbab1b1 100644 --- a/src/events/EventDirectoryItem.vala +++ b/src/events/EventDirectoryItem.vala @@ -60,7 +60,7 @@ class EventDirectoryItem : CheckerboardItem { pixbuf = media.get_preview_pixbuf(squared_scaling); } catch (Error error) { ThumbnailCache.fetch_async_scaled(media, ThumbnailCache.Size.BIG, - new Dimensions(ThumbnailCache.Size.BIG, ThumbnailCache.Size.BIG), + Dimensions(ThumbnailCache.Size.BIG, ThumbnailCache.Size.BIG), ThumbnailCache.DEFAULT_INTERP, () => {}); if (media is LibraryPhoto) { LibraryPhoto photo = (LibraryPhoto) media; diff --git a/src/events/EventsBranch.vala b/src/events/EventsBranch.vala index 097a664..0550eb7 100644 --- a/src/events/EventsBranch.vala +++ b/src/events/EventsBranch.vala @@ -133,8 +133,8 @@ public class Events.Branch : Sidebar.Branch { b = swap; } - int64 result = ((Events.EventEntry) a).get_event().get_start_time() - - ((Events.EventEntry) b).get_event().get_start_time(); + int64 result = nullsafe_date_time_comperator(((Events.EventEntry) a).get_event().get_start_time(), + ((Events.EventEntry) b).get_event().get_start_time()); // to stabilize sort (events with the same start time are allowed) if (result == 0) { @@ -215,14 +215,14 @@ public class Events.Branch : Sidebar.Branch { } private void add_event(Event event) { - time_t event_time = event.get_start_time(); - if (event_time == 0) { + DateTime? event_time = event.get_start_time(); + if (event_time == null) { add_undated_event(event); return; } - Time event_tm = Time.local(event_time); + var event_tm = event_time.to_local(); Sidebar.Entry? year; Sidebar.Entry? month = find_event_month(event, event_tm, out year); @@ -246,14 +246,14 @@ public class Events.Branch : Sidebar.Branch { } private void move_event(Event event) { - time_t event_time = event.get_start_time(); - if (event_time == 0) { + DateTime? event_time = event.get_start_time(); + if (event_time == null) { move_to_undated_event(event); return; } - Time event_tm = Time.local(event_time); + var event_tm = event_time.to_local(); Sidebar.Entry? year; Sidebar.Entry? month = find_event_month(event, event_tm, out year); @@ -296,13 +296,13 @@ public class Events.Branch : Sidebar.Branch { } } - private Sidebar.Entry? find_event_month(Event event, Time event_tm, out Sidebar.Entry found_year) { + private Sidebar.Entry? find_event_month(Event event, DateTime event_tm, out Sidebar.Entry found_year) { // find the year first found_year = find_event_year(event, event_tm); if (found_year == null) return null; - int event_month = event_tm.month + 1; + int event_month = event_tm.get_month(); // found the year, traverse the months return find_first_child(found_year, (entry) => { @@ -310,8 +310,8 @@ public class Events.Branch : Sidebar.Branch { }); } - private Sidebar.Entry? find_event_year(Event event, Time event_tm) { - int event_year = event_tm.year + 1900; + private Sidebar.Entry? find_event_year(Event event, DateTime event_tm) { + int event_year = event_tm.get_year(); return find_first_child(get_root(), (entry) => { if ((entry is Events.UndatedDirectoryEntry) || (entry is Events.NoEventEntry) || @@ -400,9 +400,9 @@ public class Events.MasterDirectoryEntry : Events.DirectoryEntry { public class Events.YearDirectoryEntry : Events.DirectoryEntry { private string name; - private Time tm; + private DateTime tm; - public YearDirectoryEntry(string name, Time tm) { + public YearDirectoryEntry(string name, DateTime tm) { this.name = name; this.tm = tm; } @@ -412,7 +412,7 @@ public class Events.YearDirectoryEntry : Events.DirectoryEntry { } public int get_year() { - return tm.year + 1900; + return tm.get_year(); } protected override Page create_page() { @@ -422,9 +422,9 @@ public class Events.YearDirectoryEntry : Events.DirectoryEntry { public class Events.MonthDirectoryEntry : Events.DirectoryEntry { private string name; - private Time tm; + private DateTime tm; - public MonthDirectoryEntry(string name, Time tm) { + public MonthDirectoryEntry(string name, DateTime tm) { this.name = name; this.tm = tm; } @@ -434,11 +434,11 @@ public class Events.MonthDirectoryEntry : Events.DirectoryEntry { } public int get_year() { - return tm.year + 1900; + return tm.get_year(); } public int get_month() { - return tm.month + 1; + return tm.get_month(); } protected override Page create_page() { @@ -456,7 +456,7 @@ public class Events.UndatedDirectoryEntry : Events.DirectoryEntry { protected override Page create_page() { return new SubEventsDirectoryPage(SubEventsDirectoryPage.DirectoryType.UNDATED, - Time.local(0)); + new DateTime.now_local()); } } diff --git a/src/events/EventsDirectoryPage.vala b/src/events/EventsDirectoryPage.vala index 7ead1a0..c00e4bf 100644 --- a/src/events/EventsDirectoryPage.vala +++ b/src/events/EventsDirectoryPage.vala @@ -88,10 +88,10 @@ public abstract class EventsDirectoryPage : CheckerboardPage { } private static int64 event_ascending_comparator(void *a, void *b) { - time_t start_a = ((EventDirectoryItem *) a)->event.get_start_time(); - time_t start_b = ((EventDirectoryItem *) b)->event.get_start_time(); + DateTime start_a = ((EventDirectoryItem *) a)->event.get_start_time(); + DateTime start_b = ((EventDirectoryItem *) b)->event.get_start_time(); - return start_a - start_b; + return start_a.compare(start_b); } private static int64 event_descending_comparator(void *a, void *b) { @@ -239,21 +239,21 @@ public class SubEventsDirectoryPage : EventsDirectoryPage { } public const string UNDATED_PAGE_NAME = _("Undated"); - public const string YEAR_FORMAT = _("%Y"); - public const string MONTH_FORMAT = _("%B"); + public const string YEAR_FORMAT = "%Y"; + public const string MONTH_FORMAT = "%0B"; private class SubEventDirectoryManager : EventsDirectoryPage.EventDirectoryManager { private int month = 0; private int year = 0; DirectoryType type; - public SubEventDirectoryManager(DirectoryType type, Time time) { + public SubEventDirectoryManager(DirectoryType type, DateTime time) { base(); if (type == DirectoryType.MONTH) - month = time.month; + month = time.get_month(); this.type = type; - year = time.year; + year = time.get_year(); } public override bool include_in_view(DataSource source) { @@ -261,10 +261,10 @@ public class SubEventsDirectoryPage : EventsDirectoryPage { return false; EventSource event = (EventSource) source; - Time event_time = Time.local(event.get_start_time()); - if (event_time.year == year) { + var event_time = event.get_start_time().to_local(); + if (event_time.get_year() == year) { if (type == DirectoryType.MONTH) { - return (event_time.month == month); + return (event_time.get_month() == month); } return true; } @@ -284,12 +284,26 @@ public class SubEventsDirectoryPage : EventsDirectoryPage { } } - public SubEventsDirectoryPage(DirectoryType type, Time time) { + public SubEventsDirectoryPage(DirectoryType type, DateTime time) { string page_name; if (type == SubEventsDirectoryPage.DirectoryType.UNDATED) { page_name = UNDATED_PAGE_NAME; } else { - page_name = time.format((type == DirectoryType.YEAR) ? YEAR_FORMAT : MONTH_FORMAT); + switch (type) { + case DirectoryType.MONTH: { + page_name = time.format(MONTH_FORMAT); + if (page_name.index_of("%0B") != -1) { + page_name = time.format("%B"); + } + } + break; + case DirectoryType.YEAR: { + page_name = time.format(YEAR_FORMAT); + } + break; + default: + assert_not_reached(); + } } base(page_name, new SubEventDirectoryManager(type, time), null); |