Merge lp:~dgelling/noise/artist-sort-secondary-year into lp:~elementary-apps/noise/trunk

Proposed by DGelling
Status: Merged
Approved by: Corentin Noël
Approved revision: 1566
Merged at revision: 1567
Proposed branch: lp:~dgelling/noise/artist-sort-secondary-year
Merge into: lp:~elementary-apps/noise/trunk
Diff against target: 105 lines (+32/-7)
4 files modified
core/Album.vala (+4/-0)
core/Utils/CompareFunctionHolder.vala (+5/-0)
src/GStreamer/GStreamerTagger.vala (+19/-6)
src/Views/GridView/GridView.vala (+4/-1)
To merge this branch: bzr merge lp:~dgelling/noise/artist-sort-secondary-year
Reviewer Review Type Date Requested Status
Corentin Noël Approve
Review via email: mp+215187@code.launchpad.net

Commit message

When sorting on Artist, secondarily sort on year before sorting on album.

Description of the change

Fixed reading year from tag, added year field to Album, changed sorting functions
for artist sort to secondarily sort on year. If still a tie, sorts on album name,
and track number if in list view, so that individual tracks of an album are ordered
properly and albums without a year are ordered sensibly.

Albums without year are sorted in front of albums with year (as default for year = 0),
perhaps better to sort them after albums with year?

Fixes bug #1021909.

To post a comment you must log in.
Revision history for this message
Corentin Noël (tintou) wrote :

It is working fine!

review: Approve
Revision history for this message
Corentin Noël (tintou) wrote :

"Albums without year are sorted in front of albums with year"
Hmm, I don't know, before or after is the same in my opinion because if you have the year column activated you'll see the difference.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'core/Album.vala'
2--- core/Album.vala 2013-03-29 15:33:42 +0000
3+++ core/Album.vala 2014-04-10 14:14:54 +0000
4@@ -51,6 +51,9 @@
5
6 //public uint rating { get; set; default = 0; }
7 //public Date release_date { get; set; }
8+
9+ // store release year, date is overkill and not stored in most tags.
10+ public uint year { get; set; default = 0; }
11
12 private Gee.HashSet<Media> media = new Gee.HashSet<Media> ();
13
14@@ -63,6 +66,7 @@
15 public Album.from_media (Media m) {
16 name = m.album;
17 artist = m.album_artist;
18+ year = m.year;
19
20 if (String.is_empty (artist, true))
21 artist = m.artist;
22
23=== modified file 'core/Utils/CompareFunctionHolder.vala'
24--- core/Utils/CompareFunctionHolder.vala 2013-06-25 18:24:42 +0000
25+++ core/Utils/CompareFunctionHolder.vala 2014-04-10 14:14:54 +0000
26@@ -52,6 +52,9 @@
27
28 public inline int artists (Media a, Media b) {
29 int order = String.compare (a.get_display_artist (), b.get_display_artist ());
30+ // secondarily compare by year
31+ if (order == 0)
32+ order = Numeric.compare(a.year, b.year);
33 if (order == 0)
34 order = albums (a, b);
35 return order;
36@@ -76,4 +79,6 @@
37 public inline int track_numbers (Media a, Media b) {
38 return Numeric.compare (a.track, b.track);
39 }
40+
41+
42 }
43
44=== modified file 'src/GStreamer/GStreamerTagger.vala'
45--- src/GStreamer/GStreamerTagger.vala 2013-11-15 15:54:19 +0000
46+++ src/GStreamer/GStreamerTagger.vala 2014-04-10 14:14:54 +0000
47@@ -148,6 +148,7 @@
48 unowned Gst.TagList? tags = info.get_tags ();
49
50 if (tags != null) {
51+
52 string title;
53 if (tags.get_string (Gst.Tags.TITLE, out title))
54 m.title = title;
55@@ -208,13 +209,25 @@
56 if (tags.get_uint (Gst.Tags.USER_RATING, out rating))
57 m.rating = rating; // Noise.Media will clamp the value
58
59- // Get the year
60- Date? date;
61- if (tags.get_date (Gst.Tags.DATE, out date)) {
62- // Don't let the assumption that @date is non-null deceive you.
63+ // Get the year, try datetime first, otherwise try date
64+ // NOTE: date might be superfluous, it was the original method,
65+ // but doesn't seem to be used.
66+ Gst.DateTime? datetime;
67+ if (tags.get_date_time (Gst.Tags.DATE_TIME, out datetime)) {
68+ // Don't let the assumption that @datetime is non-null deceive you.
69 // This is sometimes null even though get_date() returned true!
70- if (date != null)
71- m.year = date.get_year ();
72+ if (datetime != null) {
73+ m.year = datetime.get_year ();
74+ } else {
75+ Date? date;
76+ if (tags.get_date (Gst.Tags.DATE, out date)) {
77+ // Don't let the assumption that @date is non-null deceive you.
78+ // This is sometimes null even though get_date() returned true!
79+ if (date != null) {
80+ m.year = date.get_year ();
81+ }
82+ }
83+ }
84 }
85
86 double bpm;
87
88=== modified file 'src/Views/GridView/GridView.vala'
89--- src/Views/GridView/GridView.vala 2013-08-17 04:38:12 +0000
90+++ src/Views/GridView/GridView.vala 2014-04-10 14:14:54 +0000
91@@ -350,10 +350,13 @@
92
93 if (album_b == null)
94 return 1;
95-
96+
97 int order = String.compare (album_a.get_display_artist (), album_b.get_display_artist ());
98
99 if (order == 0)
100+ order = Numeric.compare (album_a.year, album_b.year);
101+
102+ if (order == 0)
103 order = String.compare (album_a.get_display_name (), album_b.get_display_name ());
104
105 return order;

Subscribers

People subscribed via source and target branches