~ricmm/+junk/unity-lens_music-sc

« back to all changes in this revision

Viewing changes to src/banshee-filter-parser-genre.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 BansheeGenreFilterParser : BansheeFilterParser, GenreFilterParser
 
25
  {
 
26
 
 
27
    public BansheeGenreFilterParser (GenreFilterParser parser)
 
28
    {
 
29
      base (parser.filter as CheckOptionFilterCompact);
 
30
    }
 
31
    
 
32
    public override string parse ()
 
33
    { 
 
34
      StringBuilder builder = new StringBuilder ();
 
35
      List<FilterOption> genres = get_all_selected_genres ();
 
36
 
 
37
      /* CoreTracks.Genre IS ___ OR CoreTracks.Genre IS ____ ... */
 
38
      foreach (FilterOption genre in genres)
 
39
      {
 
40
        string id = genre.id;
 
41
        if (genre.id == null)
 
42
          continue;
 
43
 
 
44
        foreach (string alt in map.get_genre_synonyms (id))
 
45
        {
 
46
          builder.append ("(CoreTracks.Genre LIKE '%");
 
47
          builder.append (alt);
 
48
          builder.append ("""%' ESCAPE '\' AND CoreTracks.Genre IS NOT NULL) OR """);
 
49
        }
 
50
      }
 
51
      builder.truncate (builder.len - (" OR ".length));
 
52
      builder.prepend ("(");
 
53
      builder.append (")");
 
54
     
 
55
      return builder.str;
 
56
    }
 
57
  }
 
58
}