21
21
using System.Text.RegularExpressions;
25
public class CoverImage : EventBox
29
public CoverImage () : base ()
28
public class CoverImage : EventBox
32
image.SetSizeRequest (CoverDatabase.AlbumCoverSize,
33
CoverDatabase.AlbumCoverSize);
31
// Static :: Variables
32
// Static :: Variables :: Drag-and-Drop
33
private static TargetEntry [] drag_entries = {
34
DndUtils.TargetUriList,
35
DndUtils.TargetGnomeIconList,
36
DndUtils.TargetNetscapeUrl
39
// Static :: Properties
40
// Static :: Properties :: DragEntries
41
public static TargetEntry [] DragEntries {
42
get { return drag_entries; }
46
// Static :: Methods :: HandleDrop
49
/// Handle a Drag-and-Drop event.
52
/// This is called from <see cref="AddAlbumWindow" /> when
53
/// a cover is dropped there, and also from
54
/// <see cref="OnDragDataReceived" />
55
/// when one is dropped somewhere else (e.g. in the
56
/// <see cref="PlaylistWindow" />).
58
/// <param name="song">
59
/// The <see cref="Song" /> which the cover is associated with.
61
/// <param name="args">
62
/// The <see cref="DragDataReceivedArgs" />.
64
public static void HandleDrop (Song song, DragDataReceivedArgs args)
66
string data = DndUtils.SelectionDataToString (args.SelectionData);
74
case (uint) DndUtils.TargetType.Uri:
75
uri_list = Regex.Split (data, "\n");
78
Uri uri = new Uri (fn);
80
if (uri.Scheme != "http")
84
Album a = Global.DB.GetAlbum (song);
85
a.SetCoverWeb (uri.AbsoluteUri);
88
song.SetCoverWeb (uri.AbsoluteUri);
95
case (uint) DndUtils.TargetType.UriList:
96
uri_list = DndUtils.SplitSelectionData (data);
97
fn = FileUtils.LocalPathFromUri (uri_list [0]);
104
Album a = Global.DB.GetAlbum (song);
105
a.SetCoverLocal (fn);
108
song.SetCoverLocal (fn);
123
Gtk.Drag.Finish (args.Context, success, false, args.Time);
127
private Gtk.Image image;
37
DragDataReceived += new DragDataReceivedHandler (HandleDragDataReceived);
39
Muine.CoverDB.DoneLoading += new CoverDatabase.DoneLoadingHandler (HandleDoneLoading);
47
private enum TargetType {
52
private static TargetEntry [] cover_drag_entries = new TargetEntry [] {
53
new TargetEntry ("text/uri-list", 0, (uint) TargetType.UriList),
54
new TargetEntry ("x-special/gnome-icon-list", 0, (uint) TargetType.UriList),
55
new TargetEntry ("_NETSCAPE_URL", 0, (uint) TargetType.Uri)
60
if (song != null && song.CoverImage != null)
61
image.FromPixbuf = song.CoverImage;
62
else if (song != null && Muine.CoverDB.Loading)
63
image.FromPixbuf = Muine.CoverDB.DownloadingPixbuf;
65
image.SetFromStock ("muine-default-cover",
66
StockIcons.AlbumCoverSize);
69
if (song != null && song.Album.Length > 0 && !Muine.CoverDB.Loading) {
70
Gtk.Drag.DestSet (this, DestDefaults.All,
71
cover_drag_entries, Gdk.DragAction.Copy);
73
Gtk.Drag.DestSet (this, DestDefaults.All,
74
null, Gdk.DragAction.Copy);
132
/// Create a new <see cref="CoverImage" />.
134
public CoverImage () : base ()
136
image = new Gtk.Image ();
137
image.SetSizeRequest (CoverDatabase.CoverSize,
138
CoverDatabase.CoverSize);
142
DragDataReceived += new DragDataReceivedHandler (OnDragDataReceived);
144
Global.CoverDB.DoneLoading += new CoverDatabase.DoneLoadingHandler (OnCoversDoneLoading);
154
// Properties :: Song (set;)
157
/// The <see cref="Song" /> associated with this cover.
159
/// <param name="value">
160
/// A <see cref="Song" />, or null to use a default cover.
170
// Methods :: Private
171
// Methods :: Private :: Sync
173
/// Synchronizes the image with the desired cover.
176
/// If a cover is located in the database that is associated
177
/// with the same song that we are associated with, use that.
178
/// If we are associated with a song whose cover is currently
179
/// being downloaded, show a temporary cover. If we have no
180
/// associated song, use a default cover.
185
if (song != null && song.CoverImage != null) {
186
image.FromPixbuf = song.CoverImage;
188
} else if (song != null && Global.CoverDB.Loading) {
189
image.FromPixbuf = Global.CoverDB.DownloadingPixbuf;
192
image.SetFromStock ("muine-default-cover", StockIcons.CoverSize);
196
TargetEntry [] entries;
198
if (song != null && !Global.CoverDB.Loading)
199
entries = drag_entries;
204
Gtk.Drag.DestSet (this, DestDefaults.All, entries, Gdk.DragAction.Copy);
208
// Handlers :: OnDragDataReceived
210
/// Handler called when Drag-and-Drop data is received.
213
/// This just calls <see cref="HandleDrop" />.
216
/// The calling object.
218
/// <param name="args">
219
/// The <see cref="DragDataReceivedArgs" />.
221
private void OnDragDataReceived (object o, DragDataReceivedArgs args)
223
HandleDrop (song, args);
226
// Handlers :: OnCoversDoneLoading
228
/// Handler called when covers are done loading.
231
/// This just calls <see cref="Sync" />.
233
private void OnCoversDoneLoading ()
87
public static void HandleDrop (Song song, DragDataReceivedArgs args)
89
string data = StringUtils.SelectionDataToString (args.SelectionData);
97
case (uint) TargetType.Uri:
98
uri_list = Regex.Split (data, "\n");
101
Uri uri = new Uri (fn);
103
if (!(uri.Scheme == "http"))
109
if (Muine.CoverDB.Covers.ContainsKey (song.AlbumKey))
110
Muine.CoverDB.RemoveCover (song.AlbumKey);
111
song.CoverImage = Muine.CoverDB.AddCoverDownloading (song.AlbumKey);
112
Muine.DB.SyncAlbumCoverImageWithSong (song);
114
song.DownloadNewCoverImage (uri.AbsoluteUri);
117
} catch (Exception e) {
124
case (uint) TargetType.UriList:
125
uri_list = Regex.Split (data, "\r\n");
126
fn = StringUtils.LocalPathFromUri (uri_list [0]);
132
if (Muine.CoverDB.Covers.ContainsKey (song.AlbumKey))
133
Muine.CoverDB.RemoveCover (song.AlbumKey);
134
song.CoverImage = Muine.CoverDB.AddCoverLocal (song.AlbumKey, fn);
135
Muine.DB.SyncAlbumCoverImageWithSong (song);
149
Drag.Finish (args.Context, success, false, args.Time);
152
private void HandleDragDataReceived (object o, DragDataReceivedArgs args)
154
HandleDrop (song, args);
157
private void HandleDoneLoading ()