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.
28 private const bool use_transition_sl
= Gmpc
.use_transition
;
30 static bool initialized
= false;
31 public class Gmpc
.MetaData
.Widgets
.SongLinks
: Gtk
.Frame
33 private const string some_unique_name
= Config
.VERSION
;
39 private Type type
= Type
.ARTIST
;
40 private MPD
.Song? song
= null;
46 static void open_uri_function(Gtk
.LinkButton but
, string uri
)
51 public SongLinks(Type type
, MPD
.Song song
)
53 debug("Links created");
55 this
.song
= song
.copy();
56 var event
= new Gtk
.EventBox();
57 var label
= new Gtk
.Label("");
59 event
.visible_window
= false;
60 this
.label_widget
= event
;
61 label
.set_markup("<b>%s:</b>".printf(_("Web Links")));
62 this
.shadow
= Gtk
.ShadowType
.NONE
;
67 Gtk
.LinkButton
.set_uri_hook(open_uri_function
);
72 private void parse_uris()
74 var child
= this
.get_child();
75 if(child
!= null) child
.destroy();
77 var file
= new GLib
.KeyFile();
78 var path
= Gmpc
.user_path("weblinks.list");
79 if(! FileUtils
.test(path
, FileTest
.EXISTS
))
81 path
= Gmpc
.data_path("weblinks.list");
82 if(! FileUtils
.test(path
, FileTest
.EXISTS
))
88 file
.load_from_file(path
, GLib
.KeyFileFlags
.NONE
);
94 var ali
= new Gtk
.Alignment(0.0f
, 0.0f
, 0.0f
,0.0f
);
95 ali
.set_padding(8,8,12,6);
98 var vbox
= new Gtk
.VBox(false, 0);
101 var groups
= file
.get_groups();
102 foreach(string entry
in groups
)
105 string typestr
= file
.get_string(entry
,"type");
106 string uri
= file
.get_string(entry
, "url");
112 if(this
.song
.artist
!= null)
113 uri
= uri
.replace("%ARTIST%", Gmpc
.AsyncDownload
.escape_uri(this
.song
.artist
));
118 if(this
.song
.album
!= null)
119 uri
= uri
.replace("%ALBUM%", Gmpc
.AsyncDownload
.escape_uri(this
.song
.album
));
121 if(this
.song
.artist
!= null)
122 uri
= uri
.replace("%ARTIST%", Gmpc
.AsyncDownload
.escape_uri(this
.song
.artist
));
128 if(this
.song
.title
!= null)
129 uri
= uri
.replace("%TITLE%", Gmpc
.AsyncDownload
.escape_uri(this
.song
.title
));
131 if(this
.song
.album
!= null)
132 uri
= uri
.replace("%ALBUM%", Gmpc
.AsyncDownload
.escape_uri(this
.song
.album
));
134 if(this
.song
.artist
!= null)
135 uri
= uri
.replace("%ARTIST%", Gmpc
.AsyncDownload
.escape_uri(this
.song
.artist
));
139 string sar
= file
.get_string(entry
, "search-and-replace");
141 string[] s
= sar
.split("::");
144 var regex
= new GLib
.Regex (s
[0]);
145 uri
= regex
.replace_literal(uri
,-1,0, s
[1]);
146 } catch (GLib
.RegexError e
) {
147 GLib
.debug("Failed to compile regex: '%s'\n", e
.message
);
155 if((int)type
<= (int)this
.type
)
157 var label
= new Gtk
.LinkButton(uri
);
158 label
.set_label(_("Lookup %s on %s").printf(_(typestr
),entry
));
159 label
.set_alignment(0.0f
, 0.5f
);
160 vbox
.pack_start(label
, false, true, 0);
163 GLib
.error("Failed to get entry from %s: '%s'\n", path
, e
.message
);