1 /* Gnome Music Player Client (GMPC)
2 * Copyright (C) 2004-2012 Qball Cow <qball@gmpclient.org>
3 * Project homepage: http://gmpclient.org/
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 private const bool use_transition_mdss
= Gmpc
.use_transition
;
26 private const string some_unique_name_mdss
= Config
.VERSION
;
28 public class Gmpc
.MetaData
.Widgets
.SimilarSongs
: Gtk
.Alignment
30 private MPD
.Song? song
= null;
31 private Gtk
.Widget pchild
= null;
32 private uint idle_add
= 0;
37 GLib
.Source
.remove(this
.idle_add
);
42 public SimilarSongs (MPD
.Song song
)
44 this
.song
= song
.copy();
45 this
.set(0.0f
, 0.0f
, 1.0f
, 0.0f
);
47 private void add_clicked(Gtk
.Widget item
)
49 Gtk
.TreeView tree
= (Gtk
.TreeView
)this
.pchild
;
51 var sel
= tree
.get_selection();
52 Gtk
.TreeModel model
= null;
54 List
<Gtk
.TreePath
> list
= sel
.get_selected_rows(out model
);
55 foreach(Gtk
.TreePath path
in list
)
57 if(model
.get_iter(out iter
, path
))
59 unowned MPD
.Song? song
= null;
60 model
.get(iter
, 0, out song
, -1);
63 MPD
.PlayQueue
.queue_add_song(server
, song
.file
);
67 MPD
.PlayQueue
.queue_commit(server
);
70 private void play_clicked(Gtk
.Widget item
)
72 Gtk
.TreeView tree
= (Gtk
.TreeView
)this
.pchild
;
74 var sel
= tree
.get_selection();
75 Gtk
.TreeModel model
= null;
77 List
<Gtk
.TreePath
> list
= sel
.get_selected_rows(out model
);
80 Gtk
.TreePath path
= list
.data
;
81 if(model
.get_iter(out iter
, path
))
83 unowned MPD
.Song? song
= null;
84 model
.get(iter
, 0, out song
, -1);
87 Gmpc
.MpdInteraction
.play_path(song
.file
);
92 private void replace_clicked(Gtk
.Widget item
)
95 Gtk
.TreeView tree
= (Gtk
.TreeView
)this
.pchild
;
96 var sel
= tree
.get_selection();
97 Gtk
.TreeModel model
= null;
99 List
<Gtk
.TreePath
> list
= sel
.get_selected_rows(out model
);
100 foreach(Gtk
.TreePath path
in list
)
102 if(model
.get_iter(out iter
, path
))
104 unowned MPD
.Song? song
= null;
105 model
.get(iter
, 0, out song
, -1);
108 MPD
.PlayQueue
.queue_add_song(server
, song
.file
);
115 MPD
.PlayQueue
.clear(server
);
116 MPD
.PlayQueue
.queue_commit(server
);
117 MPD
.Player
.play(server
);
121 this
.play_clicked(item
);
123 private Gmpc
.MetaData
.Item copy
= null;
124 MPD
.Data
.Item item
= null;
125 private unowned List
<unowned
string> current
= null;
126 private bool update_sim_song()
130 current
= copy
.get_text_list();
131 pchild
= new Gtk
.ProgressBar();
135 ((Gtk
.ProgressBar
)pchild
).pulse();
138 string entry
= current
.data
;
141 var split
= entry
.split("::",2);
142 if(split
.length
== 2)
144 MPD
.Database
.search_start(server
, false);
145 var art_split
= split
[0].split(" ");
146 foreach(string artist
in art_split
)
148 MPD
.Database
.search_add_constraint(server
, MPD
.Tag
.Type
.ARTIST
, artist
);
151 MPD
.Database
.search_add_constraint(server
, MPD
.Tag
.Type
.TITLE
, split
[1]);
152 var data
= MPD
.Database
.search_commit(server
);
155 item
.concatenate((owned
)data
);
159 current
= current
.next
;
160 if(current
!= null) return true;
162 this
.pchild
.destroy();
165 var model
= new Gmpc
.MpdData
.Model();
166 item
.remove_duplicate_songs();
167 model
.set_mpd_data((owned
)item
);
168 Gmpc
.DataView tree
= new Gmpc
.DataView("similar-song", Gmpc
.DataView
.ViewType
.SONG_LIST
);
169 tree
.set_model(model
);
176 var label
= new Gtk
.Label(_("Unavailable"));
177 label
.set_alignment(0.0f
, 0.0f
);
188 private void metadata_changed(Meta
.Watcher gmw2
, MPD
.Song song
, Gmpc
.MetaData
.Type type
, Gmpc
.MetaData
.Result result
, Gmpc
.MetaData
.Item? met
)
190 if(this
.song
.artist
.collate(song
.artist
)!=0) return;
191 if(type
!= Gmpc
.MetaData
.Type
.SONG_SIMILAR
) return;
193 if(this
.pchild
!= null) this
.pchild
.destroy();
195 if(result
== Gmpc
.MetaData
.Result
.FETCHING
)
197 var label
= new Gtk
.Label(_("Fetching .. "));
198 label
.set_alignment(0.0f
, 0.0f
);
202 else if (result
== Gmpc
.MetaData
.Result
.UNAVAILABLE
)
204 var label
= new Gtk
.Label(_("Unavailable"));
205 label
.set_alignment(0.0f
, 0.0f
);
211 if(met
.is_text_list())
213 this
.copy
= met
.dup_steal();
214 this
.idle_add
= GLib
.Idle
.add(this
.update_sim_song
);
219 var label
= new Gtk
.Label(_("Unavailable"));
220 label
.set_alignment(0.0f
, 0.0f
);
230 MetaData
.Item item
= null;
231 metawatcher
.data_changed
.connect(metadata_changed
);
232 Gmpc
.MetaData
.Result gm_result
= MetaData
.get_path(song
, Gmpc
.MetaData
.Type
.SONG_SIMILAR
,out item
);
233 this
.metadata_changed(metawatcher
, this
.song
, Gmpc
.MetaData
.Type
.SONG_SIMILAR
, gm_result
, item
);