~ricmm/+junk/unity-lens_music-sc

« back to all changes in this revision

Viewing changes to src/banshee-filter-parser-decade.vala

  • Committer: Ricardo Mendoza
  • Date: 2012-09-05 14:20:15 UTC
  • Revision ID: ricardo.mendoza@canonical.com-20120905142015-prem6hiyfshwgm8q
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2011 Canonical Ltd
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License version 3 as
 
6
 * published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by Alex Launi <alex.launi@canonical.com>
 
17
 *
 
18
 */
 
19
 
 
20
using GLib;
 
21
 
 
22
namespace Unity.MusicLens {
 
23
  
 
24
  public class BansheeDecadeFilterParser : BansheeFilterParser, DecadeFilterParser
 
25
  {
 
26
 
 
27
    public BansheeDecadeFilterParser (DecadeFilterParser parser)
 
28
    {
 
29
      base (parser.filter as MultiRangeFilter);
 
30
    }
 
31
    
 
32
    public override string parse ()
 
33
    {   
 
34
      int start_year, end_year;
 
35
 
 
36
      MultiRangeFilter range_filter = filter as MultiRangeFilter;
 
37
      FilterOption start = range_filter.get_first_active ();
 
38
      FilterOption end = range_filter.get_last_active ();
 
39
 
 
40
      start_year = int.parse (start.id);
 
41
      end_year = int.parse (end.id);
 
42
      
 
43
      // bump the end_year up to the beginning of the next range
 
44
      int end_index = range_filter.options.index (end);
 
45
      // if we have already selected the last option
 
46
      if (end_index == range_filter.options.length () - 1)
 
47
        end_year += 10;
 
48
      else
 
49
        end_year = int.parse (range_filter.options.nth_data (end_index + 1).id);
 
50
 
 
51
      return "(CoreTracks.Year >= %d AND CoreTracks.Year < %d) ".printf (start_year, end_year);
 
52
    }
 
53
  }
 
54
}
 
 
b'\\ No newline at end of file'