1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
|
/* Gnome Music Player Client (GMPC)
* Copyright (C) 2004-2011 Qball Cow <qball@gmpclient.org>
* Project homepage: http://gmpclient.org/
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
using Config;
using Gtk;
using Gmpc;
using MPD;
private const bool use_transition_gsl = Gmpc.use_transition;
private const string some_unique_name_gsl = Config.VERSION;
public class Gmpc.Widgets.Songlist : Gmpc.Widgets.Qtable
{
private const int MAX_RESULTS = 125;
/* Constructor function */
public Songlist()
{
this.spacing = 6;
this.max_columns = 3;
}
/**
* Add a artist entry
*/
private void add_artist_entry(MPD.Song song, int level=0)
{
/* Event box */
var event = new Gtk.EventBox();
event.set_visible_window(false);
var box = new Gtk.HBox(false, 6);
/* Disc image */
/* add padding */
var ali = new Gtk.Alignment(0.0f, 0.5f,0f,0f);
ali.set_padding(0,0,level*32,0);
box.pack_start(ali, false, false, 0);
var image = new Gmpc.MetaData.Image(Gmpc.MetaData.Type.ARTIST_ART, 32);
image.set_no_cover_icon("no-artist");
image.set_loading_cover_icon("fetching-artist");
image.set_squared(false);
image.update_from_song(song);
/* add the image */
ali.add(image);
/* Create lLabel */
string label = null;
if(song.albumartist != null && song.albumartist.length > 0 )
{
label = "%s: %s".printf(_("Artist"), song.albumartist);
}else{
label = "%s: %s".printf(_("Artist"), song.artist);
}
var wlabel = new Clicklabel(label);
wlabel.set_do_bold(true);
wlabel.set_can_focus(true);
MPD.Song song_file = song.copy();
wlabel.clicked.connect((source, event) => {
artist_song_clicked(song_file);
});
/* add the label */
box.pack_start(wlabel, false, false, 0);
/* Add the entry */
event.add(box);
//this.pack_start(event, false, false, 0);
this.add_header(event);
}
/**
* Add a album entry
*/
private void add_album_entry(MPD.Song song, int level=0)
{
/* Event box */
var event = new Gtk.EventBox();
event.set_visible_window(false);
var box = new Gtk.HBox(false, 6);
/* Disc image */
/* add padding */
var ali = new Gtk.Alignment(0.0f, 0.5f,0f,0f);
ali.set_padding(0,0,level*32,0);
box.pack_start(ali, false, false, 0);
//var image = new Gtk.Image.from_icon_name("media-album", Gtk.IconSize.BUTTON);
var image = new Gmpc.MetaData.Image(Gmpc.MetaData.Type.ALBUM_ART, 32);
image.set_squared(false);
image.update_from_song(song);
/* add the image */
ali.add(image);
/* Create lLabel */
string label = "%s: %s".printf(_("Album"), song.album);
var wlabel = new Clicklabel(label);
wlabel.set_do_bold(true);
wlabel.set_can_focus(true);
MPD.Song song_file = song.copy();
wlabel.clicked.connect((source) => {
album_song_clicked(song_file);
});
/* add the label */
box.pack_start(wlabel, false, false, 0);
/* Add the entry */
event.add(box);
// this.pack_start(event, false, false, 0);
this.add_header(event);
}
/**
* Add a disc entry
*/
private void add_disc_entry(string entry, int level=0)
{
GLib.debug("Disc entry add: %s", entry);
/* */
var box = new Gtk.HBox(false, 6);
/* add padding */
var ali = new Gtk.Alignment(0.0f, 0.5f,0f,0f);
ali.set_padding(0,0,level*32,0);
box.pack_start(ali, false, false, 0);
/* Disc image */
var image = new Gtk.Image.from_icon_name("media-album", Gtk.IconSize.BUTTON);
/* add the image */
ali.add(image);
/* Create lLabel */
string label = "<b>%s: %s</b>".printf(_("Disc"), entry);
var wlabel = new Gtk.Label("");
wlabel.set_markup(label);
/* add the label */
box.pack_start(wlabel, false, false, 0);
/* Add the entry */
//this.pack_start(box, false, false, 0);
this.add_header(box);
}
/**
* Add a song entry
*/
private void add_song_entry(MPD.Song song, int level=0)
{
var event = new Gtk.EventBox();
event.set_visible_window(false);
GLib.debug("Song entry add: %s", song.file);
var box = new Gtk.HBox(false, 6);
/* add padding */
var ali = new Gtk.Alignment(0.0f, 0.5f,0f,0f);
ali.set_padding(0,0,level*32,0);
box.pack_start(ali, false, false, 0);
/* Title image */
var image = new Gtk.Image.from_icon_name("media-audiofile", Gtk.IconSize.MENU);
event.enter_notify_event.connect((source, event) => {
image.set_from_stock("gtk-media-play", Gtk.IconSize.MENU);
return false;
});
event.leave_notify_event.connect((source, event) => {
image.set_from_icon_name("media-audiofile",Gtk.IconSize.MENU);
return false;
});
/* add the image */
event.add(image);
ali.add(event);
MPD.Song song_file = song.copy();
event.button_release_event.connect((source, event) => {
if(event.button == 1) {
play_song_clicked(song_file);
return true;
}
return false;
});
/* add title label */
string label = null;
if(song.track != null && song.title != null) {
label = "%02s. %s".printf(song.track, song.title);
}else if (song.title != null) {
label = song.title;
}else {
label = GLib.Path.get_basename(song.file);
}
var wlabel = new Gmpc.Clicklabel(label);
wlabel.set_can_focus(true);
/* add the label */
box.pack_start(wlabel, false, false, 0);
wlabel.clicked.connect((source, alt) => {
if(alt)
play_song_clicked(song_file);
else
song_clicked(song_file);
});
/* Add the entry */
//this.pack_start(box, false, false, 0);
this.add(box);
}
/* User click on the title */
public signal void song_clicked(MPD.Song song);
/* user clicked on the play */
public signal void play_song_clicked(MPD.Song song);
/* user clicked on the album */
public signal void album_song_clicked(MPD.Song song);
/* user clicked on the artist */
public signal void artist_song_clicked(MPD.Song song);
/**
* Fill the widget from a song list
*/
public void set_from_data(owned MPD.Data.Item? list, bool show_album=false, bool show_artist=false)
{
int results = 0;
/* Removing everything it contains */
foreach(var child in this.get_children()) {
child.destroy();
}
if(list == null) return;
/* Sort the list so we can display it correctly */
list.sort_album_disc_track();
weak MPD.Data.Item iter = list;
/* itterating items */
string disc = null;
string album = null;
string artist = null;
/* Itterate over the songs */
int level = -1;
for(;iter != null; iter.next(false))
{
/* if it is no MPD.Song, skip */
if(iter.song == null) continue;
if(results > this.MAX_RESULTS) {
var bar = new Gtk.InfoBar();
var label = new Gtk.Label(_("Only the first %i results are shown. Please refine your search.".printf(MAX_RESULTS)));
label.set_alignment(0.0f,0.5f);
bar.set_message_type(Gtk.MessageType.WARNING);
(bar.get_content_area() as Gtk.Container).add(label);
// this.pack_start(bar, false, false);
this.add_header(bar);
break;
}
results++;
if(show_artist) {
if(iter.song.albumartist != null &&
iter.song.albumartist.length > 0)
{
if(artist == null || artist != iter.song.albumartist)
{
this.add_artist_entry(iter.song,0);
artist = iter.song.albumartist;
disc = null;
album = null;
}
}else if(iter.song.artist != null && (artist == null || artist != iter.song.artist))
{
this.add_artist_entry(iter.song,0);
artist = iter.song.artist;
disc = null;
album = null;
}
}
if(show_album) {
if(iter.song.album != null && (album == null || album != iter.song.album))
{
this.add_album_entry(iter.song,(artist != null)?1:0);
album = iter.song.album;
disc = null;
}
}
/* Check for a new disc */
if(iter.song.disc != null && (disc == null || disc != iter.song.disc))
{
this.add_disc_entry(iter.song.disc,((artist != null)?1:0)+((album!=null)?1:0));
/* Add a new disc button */
disc = iter.song.disc;
}
/* add song row */
level = 0;
if(disc != null) level++;
if(artist != null) level++;
if(album != null) level++;
this.add_song_entry(iter.song,level);
}
/* show everything */
this.show_all();
}
}
|