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 BansheeScopeProxy : SimpleScope
26
private BansheeCollection collection;
28
public BansheeScopeProxy ()
32
scope = new Unity.Scope ("/com/canonical/unity/scope/banshee");
33
scope.search_in_global = true;
34
scope.activate_uri.connect (activate);
35
scope.preview_uri.connect (preview);
36
scope.sources.add_option ("banshee", _("Banshee"), null);
41
collection = new BansheeCollection ();
42
} catch (DatabaseError error) {
43
printerr ("Failed to open the Banshee collection database\n");
48
protected override int num_results_without_search { get {return 100; } }
49
protected override int num_results_global_search { get { return 20; } }
50
protected override int num_results_lens_search { get { return 50; } }
52
public Unity.Preview preview (string uri)
54
Unity.MusicPreview? preview = null;
55
GLib.ThemedIcon? icon_file = null;
57
if (Uri.parse_scheme (uri) == "album")
59
string[] split = uri.split ("/");
60
string artist = split[2];
61
string title = split[3];
63
foreach (unowned Track track in collection.get_album_tracks_detailed (title, artist))
67
if (track.artwork_path != null)
69
icon_file = new GLib.ThemedIcon(track.artwork_path);
71
preview = new Unity.MusicPreview (title, artist, icon_file);
73
var tm = new Unity.TrackMetadata();
75
tm.track_no = track.track_number;
76
tm.title = track.title ?? "";
77
tm.length = track.duration;
78
preview.add_track(tm);
81
else // preview single track
83
Track? track = collection.get_album_track (uri);
86
if (track.artwork_path != null)
88
icon_file = new GLib.ThemedIcon(track.artwork_path);
90
preview = new Unity.MusicPreview (track.title, track.artist, icon_file);
91
var tm = new Unity.TrackMetadata();
93
tm.track_no = track.track_number;
94
tm.title = track.title ?? "";
95
tm.length = track.duration;
96
preview.add_track(tm);
104
* Tells banshee to play the selected uri(s)
106
public Unity.ActivationResponse activate (string uri)
108
string[] exec = {"banshee", "--play-enqueued"};
111
if (Uri.parse_scheme (uri) == "album")
113
debug (@"searching for tracks for $uri");
114
string[] split = uri.split ("/");
115
string artist = split[2];
116
string title = split[3];
118
Album album = new Album ();
119
album.artist = artist;
121
// FIXME there must be a better way..
122
foreach (string track in collection.get_track_uris (album))
132
debug (@"Spawning banshee '%s'", string.joinv (" ", exec));
133
Process.spawn_async (null,
136
SpawnFlags.SEARCH_PATH,
140
return new Unity.ActivationResponse (Unity.HandledType.HIDE_DASH);
141
} catch (SpawnError error) {
142
warning ("Failed to launch URI %s", uri);
143
return new Unity.ActivationResponse (Unity.HandledType.NOT_HANDLED);
147
public override async void perform_search (LensSearch search,
148
SearchType search_type,
149
owned List<FilterParser> filters,
150
int max_results = -1,
151
Cancellable? cancellable = null)
153
int category_override = -1;
154
if (search_type == SearchType.GLOBAL)
156
category_override = Category.MUSIC;
157
// the lens shouldn't display anything for empty search
158
if (is_search_empty (search)) return;
161
collection.search (search, search_type, filters,
162
max_results, category_override);