don't show link to source if it doesn't appear to be a URL
[soepkiptng.git] / gtk_soepkiptng_status
blob2e3396fcb562a77b03cf2054d43bf8698b580f20
1 #!/usr/bin/perl
2 ############################################################################
3 # soepkiptng (c) copyright 2000 Eric Lammerts <eric@lammerts.org>.
4 # $Id$
5 ############################################################################
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License, version 2, as
8 # published by the Free Software Foundation.
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 # A copy of the GNU General Public License is available on the World Wide Web
16 # at `http://www.gnu.org/copyleft/gpl.html'. You can also obtain it by
17 # writing to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 # Boston, MA 02111-1307, USA.
19 ############################################################################
21 use Cwd 'abs_path';
22 use DBI;
23 use Getopt::Std;
24 use Gnome;
26 # find program directory
27 $_ = $0;
28 while(-l) {
29 my $l = readlink or die "readlink $_: $!\n";
30 if($l =~ m|^/|) { $_ = $l; } else { s|[^/]*$|/$l|; }
32 m|(.*)/|;
33 my $progdir = abs_path($1);
35 require "$progdir/soepkiptng.lib";
37 getopts('c:');
39 read_configfile(\%conf, $opt_c);
41 init Gnome "soepkiptng.pl";
43 #init Gnome::Panel::AppletWidget 'soepkiptng.pl';
45 $SIG{'HUP'} = sub {
46 exec $0;
47 die;
50 my $pause_xpm = (
51 "16 16 4 1",
52 " c None s None",
53 ". c black",
54 "X c #808080",
55 "o c white",
56 " ",
57 " ",
58 " ",
59 " ",
60 " ... ... ",
61 " ... ... ",
62 " ... ... ",
63 " ... ... ",
64 " ... ... ",
65 " ... ... ",
66 " ... ... ",
67 " ",
68 " ",
69 " ",
70 " ",
71 " ");
73 #my $window = new Gtk::Window;
74 my $window = new Gtk::Widget "GtkWindow",
75 type => -toplevel,
76 title => "SoepkipTNG status",
77 allow_grow => 1,
78 allow_shrink => 1,
81 #$window = new Gnome::Panel::AppletWidget 'soepkiptng.pl';
82 #realize $window;
84 #my $Label = Gtk::Widget->new("Gnome::CanvasText",
85 # text => "A string\nToinen rivi",
86 # font_gdk => load Gtk::Gdk::Font('-*-helvetica-*'),
87 # fill_color => 'steelblue',
88 # anchor => 'center',
89 #);
91 my $label = new Gtk::Label("Artist\nTitle\nAlbum");
92 $label->set_justify('left');
93 #$label->set_usize(300,40);
95 my $label2 = new Gtk::Label("");
97 $button_pause = Gtk::Widget->new("GtkButton",
98 -label => "Pause",
99 -border_width => 1,
100 -clicked => sub { pause(); },
101 -visible=>1,
104 $button_kill = Gtk::Widget->new("GtkButton",
105 -label => "Kill",
106 -border_width => 1,
107 -clicked => \&kill_song,
108 -visible=>1,
112 $hbox = new Gtk::HBox 0, 1;
113 show $hbox;
114 $window->add($hbox);
116 $vbox = new Gtk::VBox 0, 1;
118 $hbox->pack_start($label, 0, 1, 3);
119 $hbox->pack_start($label2, 1, 1, 3);
120 $hbox->pack_start($vbox, 0, 0, 0);
122 $vbox->pack_start($button_pause, 0, 0, 1);
123 #$vbox->pack_start($button_resume, 0, 0, 1);
124 $vbox->pack_start($button_kill, 0, 0, 1);
127 #$splashimage = new Gtk::Pixmap($p,$pause_xpm)
129 $mtime = -1;
130 $paused = -1;
131 update_song();
132 my $id = Gtk->timeout_add(1000, \&update_song);
134 $window->signal_connect('destroy', sub { Gtk->exit(0); });
136 $window->show_all;
138 Gtk->main;
139 # Gnome::Panel::AppletWidget;
142 sub update_song() {
143 my $newmtime = (stat $conf{statusfile})[9];
145 if($newmtime != $mtime) {
146 $mtime = $newmtime;
147 if(open F, $conf{statusfile}) {
148 my ($nowplaying, $filename);
149 chop($nowplaying = <F>);
150 chop($filename = <F>);
151 <F>;
152 $playerpid = 0 + <F>;
153 chop ((undef, undef, undef, undef,
154 $now_playing->{artist},
155 $now_playing->{title},
156 $now_playing->{album},
157 $now_playing->{track}) = <F>);
158 close F;
160 if($nowplaying > 0) {
161 my $query = "SELECT song.title as title,artist.name as artist,album.name as album,song.id,song.track" .
162 " FROM song,artist,album" .
163 " WHERE song.id=?" .
164 " AND song.artist_id=artist.id AND song.album_id=album.id";
166 if($dbh = DBI->connect("DBI:$conf{db_type}:$conf{db_name}:$conf{db_host}", $conf{db_user}, $conf{db_pass})) {
167 my $sth = $dbh->prepare($query);
168 my $rv = $sth->execute($nowplaying);
169 if(my $n = $sth->fetchrow_hashref) {
170 $now_playing = $n;
172 $sth->finish;
173 $dbh->disconnect;
175 $label->set_text(sprintf("%s\n%s\n[%02d] %s",
176 $now_playing->{artist},
177 $now_playing->{title},
178 $now_playing->{track},
179 $now_playing->{album}));
180 } else {
181 $filename =~ /^(.*)\/(.*?)$/;
182 $label->set_text("$1\n$2\n");
184 } else {
185 $label->set_text("** soepkiptngd not running!\n\n");
189 # if($playerpid) {
190 # my $p = is_paused($playerpid);
191 # if($p != $paused) {
192 # if($p) {
193 # $button_pause->set_title("Resume");
194 # } else {
195 # $button_pause->set_title("Pause");
197 # $paused = $p;
200 return 1;