Remove some debug output.
[gmpc.git] / src / vala / gmpc-mpddata-treeview-tooltip.vala
blobe619fe7982026728a6c6078970b7bc3658cc29da
1 /* Gnome Music Player Client (GMPC)
2 * Copyright (C) 2004-2011 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.
19 using Config;
20 using Gtk;
21 using Gmpc;
23 private const bool use_transition_mtt = Gmpc.use_transition;
24 private const string some_unique_name_mtt = Config.VERSION;
26 public class Gmpc.MpdData.Treeview.Tooltip : Gtk.Window {
27 private Gtk.TreeView par_widget = null;
28 private Gtk.Image image = null;
29 public Gmpc.MetaData.Type mtype = Gmpc.MetaData.Type.ARTIST_ART;
30 public string? request_artist = null;
31 private string checksum = null;
32 private bool
33 query_tooltip_callback(int x, int y, bool keyboard_tip, Gtk.Tooltip tooltip)
35 string tag = null;
36 int row_type = 0;
37 Gtk.TreePath path = null;
38 Gtk.TreeIter iter ;
39 var model = this.par_widget.get_model();
40 if(config.get_int_with_default("GmpcTreeView", "show-tooltip", 1) != 1) return false;
41 if(this.mtype != Gmpc.MetaData.Type.ARTIST_ART && this.mtype != Gmpc.MetaData.Type.ALBUM_ART) {
42 this.checksum = null;
43 return false;
46 if(!this.par_widget.get_tooltip_context(out x, out y,keyboard_tip, out model, out path, out iter)){
47 this.checksum = null;
48 return false;
51 MPD.Song song = new MPD.Song();
52 /* Get the row type */
53 model.get(iter, 26, out row_type);
54 if(row_type == MPD.Data.Type.SONG)
56 string album = null;
57 model.get(iter, 5, out tag, 6 , out album);
58 song.artist = tag;
59 song.album = album;
61 else if (row_type == MPD.Data.Type.TAG)
63 if(this.mtype == Gmpc.MetaData.Type.ARTIST_ART)
65 model.get(iter, 7, out tag);
66 song.artist = tag;
67 }else if (this.mtype == Gmpc.MetaData.Type.ALBUM_ART)
69 model.get(iter, 7, out tag);
70 song.artist = this.request_artist;
71 song.album = tag;
75 string new_check = Gmpc.Misc.song_checksum(song);
76 if(new_check != this.checksum && this.checksum != null)
78 this.checksum = null;
79 return false;
81 if(new_check != this.checksum)
84 this.checksum = new_check;
85 Gmpc.MetaData.Item met = null;
86 var result = metawatcher.query(song, this.mtype, out met);
87 metadata_changed(metawatcher, song, this.mtype,result, met);
89 if(this.image.get_storage_type() == Gtk.ImageType.EMPTY) return false;
90 return true;
93 private void metadata_changed(MetaWatcher gmw2, MPD.Song song, Gmpc.MetaData.Type type, Gmpc.MetaData.Result result, Gmpc.MetaData.Item? met)
95 if(type != this.mtype) return;
97 if(this.checksum != Gmpc.Misc.song_checksum(song)) return;
98 if(result == Gmpc.MetaData.Result.UNAVAILABLE) {
99 this.image.clear();
101 else if (result == Gmpc.MetaData.Result.FETCHING) {
102 this.image.clear();
103 }else if (result == Gmpc.MetaData.Result.AVAILABLE) {
104 if(met.content_type == Gmpc.MetaData.ContentType.URI) {
105 try {
106 var pb = new Gdk.Pixbuf.from_file_at_scale(met.get_uri(), 150, 150, true);
107 image.set_from_pixbuf(pb);
108 } catch (Error e) {
109 this.image.clear();
111 } else {
112 this.image.clear();
117 construct{
118 this.type = Gtk.WindowType.POPUP;
120 public
121 Tooltip(Gtk.TreeView pw, Gmpc.MetaData.Type type){
122 this.resizable = false;
123 this.par_widget = pw;
124 /*Set up all needed for tooltip */
125 pw.query_tooltip.connect(query_tooltip_callback);
126 this.par_widget.set_tooltip_window(this);
127 /* setup image */
128 this.image = new Gtk.Image();
129 this.image.show();
130 this.mtype = type;
131 this.add(image);
132 this.set_border_width(2);
133 this.modify_bg(Gtk.StateType.NORMAL, pw.style.black);
135 metawatcher.data_changed.connect(metadata_changed);