2
// UbuntuOneMusicStoreSource.cs
5
// Jo Shields <directhex@apebox.org>
7
// Copyright (C) 2010 Jo Shields
9
// Permission is hereby granted, free of charge, to any person obtaining
10
// a copy of this software and associated documentation files (the
11
// "Software"), to deal in the Software without restriction, including
12
// without limitation the rights to use, copy, modify, merge, publish,
13
// distribute, sublicense, and/or sell copies of the Software, and to
14
// permit persons to whom the Software is furnished to do so, subject to
15
// the following conditions:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34
using Banshee.Collection;
36
using Banshee.ServiceStack;
37
using Banshee.Sources;
38
using Banshee.Sources.Gui;
40
namespace Banshee.UbuntuOneMusicStore
42
public class UbuntuOneMusicStoreSource : Source
44
// In the sources TreeView, sets the order value for this source, small on top
45
const int sort_order = 190;
46
CustomView custom_view;
48
public UbuntuOneMusicStoreSource () : base (
49
Catalog.GetString ("Ubuntu One Music Store"),
50
Catalog.GetString ("Ubuntu One Music Store"),
51
sort_order, "ubuntu-one-music-store")
53
Properties.SetString ("Icon.Name", "ubuntuone");
56
// A count of 0 will be hidden in the source TreeView
57
public override int Count {
61
// Defer any UI creation until it's actually needed.
62
public override void Activate ()
64
if (custom_view == null) {
65
Properties.Set<ISourceContents> ("Nereid.SourceContents", custom_view = new CustomView ());
69
Log.Debug ("U1MS: Initialized");
72
public class StoreWrapper: UbuntuOne.U1MusicStore, IDisableKeybindings
74
string U1LibraryLocation = System.IO.Path.Combine (System.IO.Path.Combine (System.Environment.GetFolderPath (System.Environment.SpecialFolder.Personal), ".ubuntuone"), "Purchased from Ubuntu One");
76
public StoreWrapper (): base ()
78
this.PreviewMp3 += PlayMP3Preview;
79
this.DownloadFinished += AddDownloadToLibrary;
80
this.PlayLibrary += PlayU1MSLibrary;
81
this.UrlLoaded += U1MSUrlLoaded;
84
private void PlayMP3Preview (object Sender, UbuntuOne.PreviewMp3Args a)
86
Log.Debug ("U1MS: Playing preview: ", a.Url );
87
TrackInfo PreviewTrack = new TrackInfo ();
88
PreviewTrack.TrackTitle = a.Title;
89
PreviewTrack.ArtistName = Catalog.GetString ("Track Preview");
90
PreviewTrack.AlbumTitle = Catalog.GetString ("Ubuntu One Music Store");
91
PreviewTrack.Uri = new SafeUri (a.Url);
92
ServiceManager.PlayerEngine.OpenPlay (PreviewTrack);
93
ServiceManager.PlaybackController.StopWhenFinished = true;
96
private void AddDownloadToLibrary (object Sender, UbuntuOne.DownloadFinishedArgs a)
98
Log.Debug ("U1MS: Track downloaded: ", a.Path);
99
ServiceManager.Get<Banshee.Library.LibraryImportManager> ().ImportTrack (new SafeUri (a.Path));
100
ServiceManager.Get<Banshee.Library.LibraryImportManager> ().NotifyAllSources ();
103
private void PlayU1MSLibrary (object Sender, UbuntuOne.PlayLibraryArgs a)
105
Log.Debug ("U1MS: Playing from library: ", a.Path);
106
Log.Debug ("U1MS: U1 library location: ", U1LibraryLocation);
107
int track_id = Banshee.Collection.Database.DatabaseTrackInfo.GetTrackIdForUri (System.IO.Path.Combine (U1LibraryLocation, a.Path));
110
var track = Banshee.Collection.Database.DatabaseTrackInfo.Provider.FetchSingle (track_id);
111
ServiceManager.PlaybackController.NextSource = ServiceManager.SourceManager.MusicLibrary;
112
ServiceManager.PlayerEngine.OpenPlay (track);
116
private void U1MSUrlLoaded (object Sender, UbuntuOne.UrlLoadedArgs a)
118
Log.Debug ("U1MS: Url Loaded: ", a.Url);
122
private class CustomView : ISourceContents
124
StoreWrapper store = new StoreWrapper ();
126
public bool SetSource (ISource source) { return true; }
127
public void ResetSource () { }
128
public Gtk.Widget Widget { get { return store; } }
129
public ISource Source { get { return null; } }