Fix rating menu.
[gmpc.git] / src / Widgets / gmpc-metadata-text-label.vala
blob067f66639f2e9914f59568d3e6e599bd2b417c4b
1 /* Gnome Music Player Client
2 * Copyright (C) 2011-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 GLib;
20 using Gmpc;
22 private const bool use_transition_mdtl = Gmpc.use_transition;
23 private const string some_unique_name_mdtl = Config.VERSION;
26 namespace Gmpc.MetaData.Widgets
28 public class TextLabel : Gtk.Label
30 private MPD.Song? cur_song = null;
31 private string song_checksum = null;
32 private Gmpc.MetaData.Type cur_type = Gmpc.MetaData.Type.ALBUM_TXT;
33 private void set_from_item(Gmpc.MetaData.Item? item)
35 if(item != null )
37 if(item.content_type == Gmpc.MetaData.ContentType.TEXT)
39 string res = item.get_text();
40 this.set_text(res);
42 else if(item.content_type == Gmpc.MetaData.ContentType.HTML)
45 string res = item.get_text_from_html();
46 this.set_text(res);
48 else if(item.content_type == Gmpc.MetaData.ContentType.URI )
50 string path = item.get_uri();
51 string res = null;
52 try
54 GLib.FileUtils.get_contents( path, out res);
55 this.set_text(res);
57 catch (Error e)
59 this.set_text(_("Error reading file: %s").printf(e.message));
62 else
64 this.set_text(_("Not available"));
67 else
69 this.set_text(_("Not available"));
73 /**
74 * @param song The #MPD.Song to display the text for.
75 * @param type The #Gmpc.MetaData.Type of metadata to display.
76 * Create a text label for Song, that displays
77 * Text metadata
78 * @return a #TextLabel or type #Gtk.Label
81 public TextLabel(MPD.Song song,Gmpc.MetaData.Type type)
83 this.set_line_wrap(true);
84 this.set_text("Not available");
85 this.set_alignment(0.0f, 0.0f);
86 this.set_padding(4,4);
87 this.set_selectable(true);
88 cur_type = type;
89 cur_song = song.copy();
90 song_checksum = Gmpc.Misc.song_checksum(song);
92 metawatcher.data_changed.connect((csong, type, result, met) =>
94 if(type == cur_type && song_checksum == Gmpc.Misc.song_checksum(csong))
96 if(result == Gmpc.MetaData.Result.AVAILABLE)
98 this.set_from_item(met);
100 else if (result == Gmpc.MetaData.Result.FETCHING)
102 this.set_text(_("Fetching..."));
104 else
106 this.set_from_item(null);
112 /** Query */
113 Gmpc.MetaData.Item item = null;
114 var a = MetaData.get_path(cur_song, type, out item);
115 if(a == Gmpc.MetaData.Result.AVAILABLE)
117 this.set_from_item(item);
119 else if (a == Gmpc.MetaData.Result.FETCHING)
121 this.set_text(_("Fetching..."));
123 else
125 this.set_from_item(null);
127 this.populate_popup.connect((source, menu)=>
129 /* Add refetch */
130 var mitem = new Gtk.ImageMenuItem.with_label(_("Refetch"));
131 mitem.set_image(
132 new Gtk.Image.from_stock("gtk-refresh", Gtk.IconSize.MENU));
133 mitem.activate.connect((source)=>{
134 MetaData.get_path(cur_song, type|Gmpc.MetaData.Type.QUERY_NO_CACHE, out item);
136 menu.append(mitem);
137 mitem.show();
139 /* Add selector */
140 mitem = new Gtk.ImageMenuItem.with_label(_("Metadata selector"));
141 mitem.set_image(
142 new Gtk.Image.from_stock("gtk-edit", Gtk.IconSize.MENU));
143 mitem.activate.connect((source)=>{
144 new Gmpc.MetaData.EditWindow(cur_song, cur_type);
146 menu.append(mitem);
147 mitem.show();
154 }// end namespace Gmpc.MetaData