2
* Copyright (c) 2011-2012 Scott Ringwelski <sgringwe@mtu.edu>
4
* Originally Written by Scott Ringwelski for BeatBox Music Player
5
* BeatBox Music Player: http://www.launchpad.net/beat-box
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Library General Public
9
* License as published by the Free Software Foundation; either
10
* version 2 of the License, or (at your option) any later version.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Library General Public License for more details.
17
* You should have received a copy of the GNU Library General Public
18
* License along with this library; if not, write to the
19
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
* Boston, MA 02111-1307, USA.
26
public class BeatBox.InfoPanel : ScrolledWindow {
27
private LibraryManager lm;
28
private LibraryWindow lw;
32
private Button loveMedia;
33
private Button banMedia;
34
private Gtk.Image coverArt;
35
private RatingWidget rating; // need to make custom widget in future
39
bool similars_fetched;
40
private SimilarMediasView ssv;
42
public InfoPanel(LibraryManager lmm, LibraryWindow lww) {
48
similars_fetched = false;
49
lm.medias_updated.connect(medias_updated);
50
lm.media_played.connect(media_played);
51
lm.lfm.logged_in.connect(logged_in_to_lastfm);
52
lm.lfm.similar_retrieved.connect(similar_retrieved);
55
private void buildUI() {
56
/* put it in event box so we can color background white */
57
EventBox eb = new EventBox();
60
eb.get_style_context ().add_class (Gtk.STYLE_CLASS_VIEW);
62
eb.set_size_request (Icons.ALBUM_VIEW_IMAGE_SIZE + 6, -1);
64
title = new Label("Title");
65
artist = new Label("Artist");
66
loveMedia = new Button();
67
banMedia = new Button();
68
coverArt = new Gtk.Image();
69
coverArt.set_size_request (Icons.ALBUM_VIEW_IMAGE_SIZE, Icons.ALBUM_VIEW_IMAGE_SIZE);
70
rating = new RatingWidget(true, IconSize.MENU, false, null);
71
album = new Label("Album");
72
year = new Label("Year");
73
ssv = new SimilarMediasView(lm, lw);
75
coverArt.set_no_show_all(true);
76
loveMedia.set_no_show_all(true);
77
banMedia.set_no_show_all(true);
80
title.set_markup("<span size=\"large\"><b>%s</b></span>".printf(_("Title")));
81
year.set_markup("<span size=\"x-small\">%s</span>".printf(_("Year")));
84
title.ellipsize = Pango.EllipsizeMode.END;
85
artist.ellipsize = Pango.EllipsizeMode.END;
86
album.ellipsize = Pango.EllipsizeMode.END;
87
year.ellipsize = Pango.EllipsizeMode.END;
89
loveMedia.relief = ReliefStyle.NONE;
90
banMedia.relief = ReliefStyle.NONE;
92
var lastfm_love_icon = Icons.LASTFM_LOVE.render (IconSize.MENU);
93
var lastfm_ban_icon = Icons.LASTFM_BAN.render (IconSize.MENU);
95
loveMedia.set_image(new Image.from_pixbuf(lastfm_love_icon));
96
banMedia.set_image(new Image.from_pixbuf(lastfm_ban_icon));
98
HBox padding = new HBox(false, 10);
99
VBox content = new VBox(false, 0);
101
HBox buttons = new HBox(false, 0);
102
buttons.pack_start(new Label(""), true, true, 0);
103
buttons.pack_start(loveMedia, false, false, 0);
104
buttons.pack_end(new Label(""), true, true, 0);
105
buttons.pack_end(banMedia, false, false, 0);
107
content.pack_start(wrap_alignment(title, 5, 0, 0, 5), false, true, 0);
108
content.pack_start(wrap_alignment(artist, 2, 0, 0, 5), false, true, 0);
109
content.pack_start(buttons, false, true, 0);
110
content.pack_start(wrap_alignment(coverArt, 5, 5, 0, 5), false, true, 0);
111
content.pack_start(wrap_alignment(rating, 5, 0, 0, 5), false, true, 0);
112
content.pack_start(wrap_alignment(album, 5, 0, 0, 5), false, true, 0);
113
content.pack_start(wrap_alignment(year, 0, 0, 20, 5), false, true, 0);
114
content.pack_start(ssv, true, true, 0);
118
padding.pack_start(eb, true, true, 0);
120
Viewport vp = new Viewport(null, null);
121
vp.set_shadow_type(ShadowType.NONE);
126
this.set_policy(PolicyType.NEVER, PolicyType.AUTOMATIC);
127
this.set_shadow_type(ShadowType.NONE);
130
rating.rating_changed.connect(ratingChanged);
131
title.button_press_event.connect(titleClicked);
132
loveMedia.clicked.connect(loveButtonClicked);
133
banMedia.clicked.connect(banButtonClicked);
135
drag_dest_set(this, DestDefaults.ALL, {}, Gdk.DragAction.MOVE);
136
Gtk.drag_dest_add_uri_targets(this);
138
drag_motion.connect(drag_motion_signal);
139
drag_leave.connect(drag_leave_signal);
140
drag_data_received.connect(drag_received);
142
update_visibilities();
145
Gtk.Alignment wrap_alignment (Gtk.Widget widget, int top, int right, int bottom, int left) {
146
var alignment = new Gtk.Alignment(0.0f, 0.0f, 1.0f, 1.0f);
147
alignment.top_padding = top;
148
alignment.right_padding = right;
149
alignment.bottom_padding = bottom;
150
alignment.left_padding = left;
152
alignment.add(widget);
156
public void logged_in_to_lastfm() {
157
update_visibilities();
160
public void update_visibilities() {
161
var lastfm_elements_visible = lm.settings.getLastFMSessionKey() != "";
163
loveMedia.set_no_show_all (!lastfm_elements_visible);
164
banMedia.set_no_show_all (!lastfm_elements_visible);
165
ssv.set_no_show_all (!lastfm_elements_visible);
166
loveMedia.set_visible(lastfm_elements_visible);
167
banMedia.set_visible(lastfm_elements_visible);
168
ssv.set_visible(similars_fetched);
171
void media_played(Media m, Media? old) {
174
update_visibilities ();
176
similars_fetched = false;
179
void medias_updated(Collection<int> ids) {
180
if(ids.contains(lm.media_info.media.rowid)) {
183
update_visibilities ();
187
void update_metadata() {
188
Media s = lm.media_info.media;
190
title.set_markup("<span size=\"large\"><b>" + Markup.escape_text(s.title) + "</b></span>");
191
artist.set_text(s.artist);
192
album.set_text(s.album);
195
rating.set_rating((int)s.rating);
198
year.set_markup("<span size=\"x-small\">" + s.year.to_string() + "</span>");
203
void update_cover_art() {
204
if(lm.media_info.media == null) {
209
var coverart_pixbuf = lm.get_cover_album_art(lm.media_info.media.rowid);
211
if(coverart_pixbuf != null) {
213
coverArt.set_from_pixbuf(coverart_pixbuf);
220
void similar_retrieved(LinkedList<int> similar_internal, LinkedList<Media> similar_external) {
221
update_similar_list(similar_external);
224
public void update_similar_list(Collection<Media> medias) {
225
if(medias.size > 8) {
226
similars_fetched = true;
227
ssv.populateView(medias);
230
update_visibilities ();
233
void ratingChanged(int new_rating) {
234
lm.media_info.media.rating = new_rating;
235
lm.update_media(lm.media_info.media, false, true, true);
238
bool titleClicked(Gdk.EventButton event) {
239
if(lm.media_info.track == null)
243
Thread.create<void*>(() => {
245
GLib.AppInfo.launch_default_for_uri (lm.media_info.track.url, null);
247
catch(GLib.Error err) {
248
message("Could not open url in Last FM: %s\n", err.message);
254
catch(GLib.ThreadError err) {
255
message("Could not create thread to open title:%s\n", err.message);
262
void loveButtonClicked() {
263
lm.lfm.loveTrack(lm.media_info.media.title, lm.media_info.media.artist);
266
void banButtonClicked() {
267
lm.lfm.banTrack(lm.media_info.media.title, lm.media_info.media.artist);
270
bool is_valid_image_type(string type) {
271
var typeDown = type.down();
273
return (typeDown.has_suffix(".jpg") || typeDown.has_suffix(".jpeg") ||
274
typeDown.has_suffix(".png"));
277
bool drag_motion_signal(Gdk.DragContext context, int x, int y, uint time) {
278
drag_highlight(coverArt);
280
coverArt.set_from_pixbuf(Icons.DROP_ALBUM_PIXBUF);
285
void drag_leave_signal(Gdk.DragContext context, uint time) {
286
drag_unhighlight(coverArt);
290
void drag_received(Gdk.DragContext context, int x, int y, Gtk.SelectionData data, uint info, uint timestamp) {
291
if(lm.media_info.media == null || lm.media_info.media.isTemporary)
296
foreach(string uri in data.get_uris()) {
298
if(is_valid_image_type(uri) && lm.media_info.media != null) {
299
message("Saving dragged album art as image\n");
300
lm.save_album_locally(lm.media_info.media.rowid, uri);
303
message("Dragged album art is not valid image\n");
306
Gtk.drag_finish (context, success, false, timestamp);