~ricmm/+junk/unity-lens_music-sc

« back to all changes in this revision

Viewing changes to src/daemon.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) 2010 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 Mikkel Kamstrup Erlandsen <mikkel.kamstrup@canonical.com>
 
17
 *
 
18
 */
 
19
using Dee;
 
20
using Config;
 
21
using Gee;
 
22
 
 
23
namespace Unity.MusicLens {
 
24
  
 
25
  const string ICON_PATH = "/usr/share/icons/unity-icon-theme/places/svg/";
 
26
  
 
27
  public class Daemon : GLib.Object
 
28
  {
 
29
    private Unity.Lens lens;
 
30
    private BansheeScopeProxy banshee;
 
31
    private RhythmboxScope rb;
 
32
     
 
33
    construct
 
34
    {
 
35
      lens = new Unity.Lens("/com/canonical/unity/lens/music", "music");
 
36
      lens.search_in_global = true;
 
37
      lens.search_hint = _("Search Music Collection");
 
38
      lens.sources_display_name = _("Sources");
 
39
      lens.visible = true;
 
40
      
 
41
      populate_categories ();
 
42
      populate_filters();
 
43
 
 
44
      var app_check = new DesktopAppInfo ("banshee.desktop");
 
45
      if (app_check != null)
 
46
      {
 
47
        banshee = new BansheeScopeProxy ();
 
48
        lens.add_local_scope (banshee.scope);
 
49
      }
 
50
 
 
51
      app_check = new DesktopAppInfo ("rhythmbox.desktop");
 
52
      if (app_check != null)
 
53
      {
 
54
        rb = new RhythmboxScope ();
 
55
        lens.add_local_scope (rb.scope);
 
56
      }
 
57
 
 
58
      try {
 
59
        lens.export ();
 
60
      } catch (GLib.IOError e) {
 
61
        stdout.printf ("error %s\n", e.message);
 
62
      }
 
63
    }
 
64
 
 
65
    private void populate_filters ()
 
66
    {
 
67
      var filters = new GLib.List<Unity.Filter> ();
 
68
 
 
69
      /* Decade filter */
 
70
      {
 
71
        var filter = new MultiRangeFilter ("decade", _("Decade"));
 
72
 
 
73
        filter.add_option ("0", _("Old"));
 
74
        filter.add_option ("1960", _("60s"));
 
75
        filter.add_option ("1970", _("70s"));
 
76
        filter.add_option ("1980", _("80s"));
 
77
              filter.add_option ("1990", _("90s"));
 
78
        filter.add_option ("2000", _("00s"));
 
79
        filter.add_option ("2010", _("10s"));
 
80
 
 
81
        filters.append (filter);
 
82
      }
 
83
 
 
84
      /* Genre filter */
 
85
      {
 
86
        var filter = new CheckOptionFilterCompact ("genre", _("Genre"));
 
87
        filter.sort_type = OptionsFilter.SortType.DISPLAY_NAME;
 
88
 
 
89
        filter.add_option (Genre.BLUES_ID, _("Blues"));
 
90
        filter.add_option (Genre.CLASSIC_ID, _("Classic"));
 
91
        filter.add_option (Genre.COUNTRY_ID, _("Country"));
 
92
        filter.add_option (Genre.DISCO_ID, _("Disco"));
 
93
        filter.add_option (Genre.FUNK_ID, _("Funk"));
 
94
        filter.add_option (Genre.ROCK_ID, _("Rock"));
 
95
        filter.add_option (Genre.METAL_ID, _("Metal"));
 
96
        filter.add_option (Genre.HIPHOP_ID, _("Hip-hop"));
 
97
        filter.add_option (Genre.HOUSE_ID, _("House"));
 
98
        filter.add_option (Genre.NEWWAVE_ID, _("New-wave"));
 
99
        filter.add_option (Genre.RANDB_ID, _("R&B"));
 
100
        filter.add_option (Genre.PUNK_ID, _("Punk"));
 
101
        filter.add_option (Genre.JAZZ_ID, _("Jazz"));
 
102
        filter.add_option (Genre.POP_ID, _("Pop"));
 
103
        filter.add_option (Genre.REGGAE_ID, _("Reggae"));
 
104
        filter.add_option (Genre.SOUL_ID, _("Soul"));
 
105
        filter.add_option (Genre.TECHNO_ID, _("Techno"));
 
106
        filter.add_option (Genre.OTHER_ID, _("Other"));
 
107
 
 
108
        filters.append (filter);
 
109
      }
 
110
 
 
111
      lens.filters = filters;
 
112
    }
 
113
 
 
114
    // FIXME icons
 
115
    private void populate_categories ()
 
116
    {
 
117
      /* Offsets of categories must match up with the Category enum */
 
118
      
 
119
      var categories = new GLib.List<Unity.Category> ();
 
120
      var icon_dir = File.new_for_path (ICON_PATH);
 
121
 
 
122
      var cat = new Unity.Category (_("Songs"),
 
123
                                    new FileIcon (icon_dir.get_child ("group-songs.svg")));
 
124
      categories.append (cat);
 
125
 
 
126
      cat =  new Unity.Category (_("Albums"),
 
127
                                 new FileIcon (icon_dir.get_child ("group-albums.svg")));
 
128
      categories.append (cat);
 
129
 
 
130
      cat = new Unity.Category (_("Available for Purchase"),
 
131
                                new FileIcon (icon_dir.get_child ("group-purchase.svg")),
 
132
                                Unity.CategoryRenderer.FLOW);
 
133
      categories.append (cat);
 
134
      
 
135
      cat = new Unity.Category (_("Music"),
 
136
                                new FileIcon (icon_dir.get_child ("group-songs.svg")));
 
137
      categories.append (cat);
 
138
 
 
139
      cat = new Unity.Category (_("Radio"),
 
140
                                new FileIcon (icon_dir.get_child ("group-songs.svg")));
 
141
      categories.append (cat);
 
142
 
 
143
      lens.categories = categories;
 
144
    }
 
145
  }
 
146
} /* namespace */
 
147