add option -d in order to indicate the path to configuration files
[zik.git] / data / systray.rb
blob938d4c348bf0e7962e520717dc6e47219a1bb698
1 =begin
2 Copyright 2007-2008 Vincent Carmona
4 This file is part of ZiK.
6     ZiK is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
11     ZiK is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
16     You should have received a copy of the GNU General Public License
17     along with ZiK; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19 =end
20 include GetText
21 bindtextdomain('ZiK',{:path=>Ldir})
23 class SysTray < Gtk::StatusIcon 
24         def initialize(window,player)
25                 @player=player
26                 
27                 @bplay_tray=Gtk::CheckMenuItem.new(_('Play'))
28                 @bplay_tray.signal_connect("toggled"){
29                         if @show_tray #Do not process when setting the toggled state on showing the  popup menu.
30                                 if  @player.playing?
31                                         @player.pause                           
32                                 else
33                                         if @showlistn==3
34                                                 @player.stop
35                                                 window.play_radio
36                                         else
37                                                 window.play
38                                         end
39                                 end
40                         end
41                 }
42                 @bprev_tray=Gtk::ImageMenuItem.new(Gtk::Stock::MEDIA_PREVIOUS)
43                 @bprev_tray.signal_connect("activate"){window.prev}
44                 @bnext_tray=Gtk::ImageMenuItem.new(Gtk::Stock::MEDIA_NEXT)
45                 @bnext_tray.signal_connect("activate"){window.next_s}
46                 @bquit_tray=Gtk::ImageMenuItem.new(Gtk::Stock::QUIT)
47                 @bshow_tray=Gtk::CheckMenuItem.new(_('Show player'))
48                 @bshow_tray.signal_connect("toggled"){
49                         if @show_tray #Do not process when setting the toggled state on showing the  popup menu.
50                                 if window.visible?
51                                         window.hide
52                                 else
53                                         window.show
54                                 end
55                         end
56                 }
57         #                       @bnotification_tray=Gtk::CheckMenuItem.new(_('Afficher les notifications'))
58                 @bquit_tray.signal_connect("activate"){window.quit}
59                 @popup_tray=Gtk::Menu.new
60                 @popup_tray.append(@bplay_tray)
61                 @popup_tray.append(@bprev_tray)
62                 @popup_tray.append(@bnext_tray)
63                 @popup_tray.append(Gtk::SeparatorMenuItem.new)
64                 @popup_tray.append(@bshow_tray)
65         #                       @popup_tray.append(@bnotification_tray)
66                 @popup_tray.append(Gtk::SeparatorMenuItem.new)
67                 @popup_tray.append(@bquit_tray)
68                 @popup_tray.show_all
69                 
70                 super()
71                 self.pixbuf=Gdk::Pixbuf.new(File.join(Pdir,'ZiK.svg'))
72                 self.tooltip=_('Audio player')
73                 self.signal_connect('activate'){
74                         if window.visible?
75                                 window.hide
76                         else
77                                 window.show
78                         end
79                 }
80                 self.signal_connect('popup-menu'){|tray, button, time|
81                         @show_tray=false
82                         @bplay_tray.active=@player.playing?
83                         @bshow_tray.active=window.visible?
84                         @show_tray=true
85                         @popup_tray.popup(nil, nil, button, time)
86                 }
87         end
88 end