2
* Copyright (C) 2011 Canonical Ltd
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.
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.
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/>.
16
* Authored by Alex Launi <alex.launi@canonical.com>
22
namespace Unity.MusicLens {
24
public class RhythmboxScope : SimpleScope
26
private RhythmboxCollection collection;
27
private bool db_ready;
29
public RhythmboxScope ()
33
scope = new Unity.Scope ("/com/canonical/unity/scope/rhythmbox");
34
scope.search_in_global = true;
35
scope.activate_uri.connect (activate);
36
scope.sources.add_option ("rhythmbox", _("Rhythmbox"), null);
39
collection = new RhythmboxCollection ();
43
protected override int num_results_without_search { get {return 100; } }
44
protected override int num_results_global_search { get { return 20; } }
45
protected override int num_results_lens_search { get { return 50; } }
48
* Tells banshee to play the selected uri(s)
50
public Unity.ActivationResponse activate (string uri)
52
string[] exec = {"rhythmbox-client", "--play-uri"};
55
if (Uri.parse_scheme (uri) == "album")
57
debug (@"searching for tracks for $uri");
58
string[] split = uri.split ("/");
59
string artist = split[2];
60
string title = split[3];
62
Album album = new Album ();
63
album.artist = artist;
65
// FIXME there must be a better way..
66
// foreach (string track in collection.get_track_uris (album))
76
debug ("Spawning rb '%s'", string.joinv (" ", exec));
77
Process.spawn_async (null,
80
SpawnFlags.SEARCH_PATH,
84
return new Unity.ActivationResponse (Unity.HandledType.HIDE_DASH);
85
} catch (SpawnError error) {
86
warning ("Failed to launch URI %s", uri);
87
return new Unity.ActivationResponse (Unity.HandledType.NOT_HANDLED);
91
public override async void perform_search (LensSearch search,
92
SearchType search_type,
93
owned List<FilterParser> filters,
95
Cancellable? cancellable = null)
97
int category_override = -1;
98
if (search_type == SearchType.GLOBAL)
100
category_override = Category.MUSIC;
101
// the lens shouldn't display anything for empty search
102
if (is_search_empty (search)) return;
107
// parse the DB lazily
108
collection.parse_file ("%s/.local/share/rhythmbox/rhythmdb.xml".printf (Environment.get_home_dir ()));
112
collection.search (search, search_type, filters,
113
max_results, category_override);