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 MusicStoreScopeProxy : SimpleScope
26
private MusicStoreCollection collection;
28
public MusicStoreScopeProxy ()
32
scope = new Unity.Scope ("/com/canonical/unity/scope/musicstore");
33
scope.search_in_global = true;
34
scope.activate_uri.connect (activate);
38
collection = new MusicStoreCollection ();
42
} catch (GLib.IOError e) {
43
stdout.printf (e.message);
47
protected override int num_results_without_search { get { return 100; } }
48
protected override int num_results_global_search { get { return 20; } }
49
protected override int num_results_lens_search { get { return 50; } }
51
public Unity.ActivationResponse activate (string uri)
53
/* launch the music store streaming client or the webstore or whatevz */
54
File file = File.new_for_uri (uri);
55
get_and_open_purchase_url.begin (file);
56
return new Unity.ActivationResponse (Unity.HandledType.HIDE_DASH);
59
public override void perform_search (LensSearch? search, Dee.Model results_model,
60
List<FilterParser> filters, int max_results = -1)
63
collection.search (search, results_model, filters, max_results);
65
stdout.printf (e.message);
69
private async void get_and_open_purchase_url (File file)
71
string url = "UNASSIGNED";
74
var dis = new DataInputStream (file.read ());
75
var parser = new Json.Parser ();
76
parser.load_from_stream (dis, new Cancellable ());
77
var root_object = parser.get_root ().get_object ();
79
url = root_object.get_string_member ("web_purchase_url");
80
AppInfo.launch_default_for_uri (url, null);
81
} catch (GLib.Error e) {
82
warning ("Failed to open url %s. %s", url, e.message);
b'\\ No newline at end of file'