Update vala version.
[gmpc.git] / src / vala / gmpc-mpddata-treeview-tooltip.vala
blob83a9f2cf996d12ad0a74eb9cbd1372dc02fd4f9d
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.
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
28 private Gtk.TreeView par_widget = null;
29 private Gtk.Image image = null;
30 public Gmpc.MetaData.Type mtype = Gmpc.MetaData.Type.ARTIST_ART;
31 public string? request_artist = null;
32 private string checksum = null;
33 private bool
34 query_tooltip_callback(int x, int y, bool keyboard_tip, Gtk.Tooltip tooltip)
36 string tag = null;
37 int row_type = 0;
38 Gtk.TreePath path = null;
39 Gtk.TreeIter iter ;
40 var model = this.par_widget.get_model();
41 if(config.get_int_with_default("GmpcTreeView", "show-tooltip", 1) != 1) return false;
42 if(this.mtype != Gmpc.MetaData.Type.ARTIST_ART && this.mtype != Gmpc.MetaData.Type.ALBUM_ART)
44 this.checksum = null;
45 return false;
47 #if VALA_0_18
48 if(!this.par_widget.get_tooltip_context(ref x, ref y,keyboard_tip, out model, out path, out iter))
49 #else
50 if(!this.par_widget.get_tooltip_context(out x, out y,keyboard_tip, out model, out path, out iter))
51 #endif
53 this.checksum = null;
54 return false;
57 MPD.Song song = new MPD.Song();
58 /* Get the row type */
59 model.get(iter, 26, out row_type);
60 if(row_type == MPD.Data.Type.SONG)
62 string album = null;
63 model.get(iter, 5, out tag, 6 , out album);
64 song.artist = tag;
65 song.album = album;
67 else if (row_type == MPD.Data.Type.TAG)
69 if(this.mtype == Gmpc.MetaData.Type.ARTIST_ART)
71 model.get(iter, 7, out tag);
72 song.artist = tag;
74 else if (this.mtype == Gmpc.MetaData.Type.ALBUM_ART)
76 model.get(iter, 7, out tag);
77 song.artist = this.request_artist;
78 song.album = tag;
82 string new_check = Gmpc.Misc.song_checksum(song);
83 if(new_check != this.checksum && this.checksum != null)
85 this.checksum = null;
86 return false;
88 if(new_check != this.checksum)
91 this.checksum = new_check;
92 Gmpc.MetaData.Item met = null;
93 var result = MetaData.get_path(song, this.mtype, out met);
94 metadata_changed(metawatcher, song, this.mtype,result, met);
96 if(this.image.get_storage_type() == Gtk.ImageType.EMPTY) return false;
97 return true;
100 private void metadata_changed(Meta.Watcher gmw2, MPD.Song song, Gmpc.MetaData.Type type, Gmpc.MetaData.Result result, Gmpc.MetaData.Item? met)
102 if(type != this.mtype) return;
104 if(this.checksum != Gmpc.Misc.song_checksum(song)) return;
105 if(result == Gmpc.MetaData.Result.UNAVAILABLE)
107 this.image.clear();
109 else if (result == Gmpc.MetaData.Result.FETCHING)
111 this.image.clear();
113 else if (result == Gmpc.MetaData.Result.AVAILABLE)
115 if(met.content_type == Gmpc.MetaData.ContentType.URI)
119 var pb = new Gdk.Pixbuf.from_file_at_scale(met.get_uri(), 150, 150, true);
120 image.set_from_pixbuf(pb);
122 catch (Error e)
124 this.image.clear();
127 else
129 this.image.clear();
134 construct
136 this.type = Gtk.WindowType.POPUP;
138 public
139 Tooltip(Gtk.TreeView pw, Gmpc.MetaData.Type type)
141 this.resizable = false;
142 this.par_widget = pw;
143 /*Set up all needed for tooltip */
144 pw.query_tooltip.connect(query_tooltip_callback);
145 this.par_widget.set_tooltip_window(this);
146 /* setup image */
147 this.image = new Gtk.Image();
148 this.image.show();
149 this.mtype = type;
150 this.add(image);
151 this.set_border_width(2);
152 this.modify_bg(Gtk.StateType.NORMAL, pw.style.black);
154 metawatcher.data_changed.connect(metadata_changed);