zik 0.16.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. data.tar.gz.sig +0 -0
  2. data/ChangeLog +222 -0
  3. data/INSTALL +34 -0
  4. data/Makefile.in +199 -0
  5. data/README +53 -0
  6. data/ZiK.desktop +11 -0
  7. data/ZiK.rb +377 -0
  8. data/configure +269 -0
  9. data/dependencies +142 -0
  10. data/doc/COPYING +340 -0
  11. data/doc/ChangeLog +222 -0
  12. data/doc/html/fr/index.html +128 -0
  13. data/doc/html/index.html +126 -0
  14. data/doc/html/pix/ZiK3.png +0 -0
  15. data/doc/html/pix/capture.png +0 -0
  16. data/doc/html/pix/capture_cd.png +0 -0
  17. data/doc/html/pix/capture_compact.png +0 -0
  18. data/doc/html/pix/capture_radio.png +0 -0
  19. data/doc/html/pix/icon.png +0 -0
  20. data/doc/html/pix/logo.png +0 -0
  21. data/doc/html/styles/main.css +47 -0
  22. data/doc/man/manpage.1 +43 -0
  23. data/gui/assistant.rb +133 -0
  24. data/gui/cdgui.rb +54 -0
  25. data/gui/common.rb +56 -0
  26. data/gui/config.rb +120 -0
  27. data/gui/edit.rb +413 -0
  28. data/gui/error.rb +124 -0
  29. data/gui/gui.rb +1383 -0
  30. data/gui/mod.rb +239 -0
  31. data/gui/preference.rb +496 -0
  32. data/gui/progress.rb +50 -0
  33. data/gui/radiogui.rb +404 -0
  34. data/gui/search.rb +249 -0
  35. data/gui/socket.rb +107 -0
  36. data/mod/brainz.rb +76 -0
  37. data/mod/brainz/dialogs.rb +132 -0
  38. data/mod/brainz/functions.rb +55 -0
  39. data/mod/brainz/ofa.rb +76 -0
  40. data/mod/brainz/song.rb +139 -0
  41. data/mod/brainz/widget.rb +34 -0
  42. data/mod/cover.rb +90 -0
  43. data/mod/cover/application-x-cd-image.svg +666 -0
  44. data/mod/cover/config.rb +79 -0
  45. data/mod/cover/configwidget.rb +35 -0
  46. data/mod/cover/widget.rb +147 -0
  47. data/mod/hotkeys.rb +137 -0
  48. data/mod/hotkeys/config.rb +84 -0
  49. data/mod/hotkeys/configwidget.rb +93 -0
  50. data/mod/interact.rb +131 -0
  51. data/mod/interact/configwidget.rb +107 -0
  52. data/mod/interact/interaction.rb +79 -0
  53. data/mod/notify.rb +128 -0
  54. data/mod/notify/config.rb +96 -0
  55. data/mod/notify/configwidget.rb +76 -0
  56. data/mod/notify/window.rb +56 -0
  57. data/mod/trayicon.rb +83 -0
  58. data/mod/trayicon/config.rb +79 -0
  59. data/mod/trayicon/configwidget.rb +35 -0
  60. data/mod/trayicon/icon.rb +99 -0
  61. data/pix/ZiK.svg +78 -0
  62. data/pix/ZiK3.png +0 -0
  63. data/pix/assistant/capture.png +0 -0
  64. data/pix/gtk-directory.svg +287 -0
  65. data/pix/media-cdrom.svg +292 -0
  66. data/pix/network-wireless.svg +429 -0
  67. data/pix/player_play.svg +286 -0
  68. data/pix/sound.svg +244 -0
  69. data/pix/sound_directory.svg +464 -0
  70. data/player/cdplayer.rb +108 -0
  71. data/player/player.rb +132 -0
  72. data/player/radioplayer.rb +124 -0
  73. data/playlist/cdlist.rb +140 -0
  74. data/playlist/common.rb +343 -0
  75. data/playlist/editlist.rb +50 -0
  76. data/playlist/export.rb +108 -0
  77. data/playlist/playlist.rb +143 -0
  78. data/playlist/radiolist.rb +148 -0
  79. data/playlist/song.rb +122 -0
  80. data/po/ZiK.pot +622 -0
  81. data/po/fr/ZiK.po +658 -0
  82. data/zik +2 -0
  83. metadata +265 -0
  84. metadata.gz.sig +0 -0
@@ -0,0 +1,93 @@
1
+ # encoding: UTF-8
2
+ =begin
3
+ Copyright 2007-2011 Vincent Carmona
4
+ vinc4mai@gmail.com
5
+
6
+ This file is part of ZiK.
7
+
8
+ ZiK is free software; you can redistribute it and/or modify
9
+ it under the terms of the GNU General Public License as published by
10
+ the Free Software Foundation; either version 2 of the License, or
11
+ (at your option) any later version.
12
+
13
+ ZiK is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU General Public License for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with ZiK; if not, write to the Free Software
20
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ =end
22
+
23
+ module Hotkeys
24
+ class ConfigWidget < Gtk::Table
25
+ attr_reader :eprev, :estop, :eplay, :enext, :bcprev, :bsprev, :baprev, :bcstop, :bsstop, :bastop,
26
+ :bcplay, :bsplay, :baplay, :bcnext, :bsnext, :banext
27
+
28
+ def initialize(config)
29
+ @lprev=Gtk::Label.new(_("Previous:\t"))
30
+ @bcprev=Gtk::CheckButton.new('Ctrl')
31
+ @bcprev.active=config[:prev_mask]&GlobalHotKeys::Modifier::CONTROL_MASK==GlobalHotKeys::Modifier::CONTROL_MASK
32
+ @bsprev=Gtk::CheckButton.new('Shift')
33
+ @bsprev.active=config[:prev_mask]&GlobalHotKeys::Modifier::SHIFT_MASK==GlobalHotKeys::Modifier::SHIFT_MASK
34
+ @baprev=Gtk::CheckButton.new('Alt')
35
+ @baprev.active=config[:prev_mask]&GlobalHotKeys::Modifier::MOD1_MASK==GlobalHotKeys::Modifier::MOD1_MASK
36
+ @eprev=Gtk::Entry.new
37
+ @eprev.text=config[:prev_key]
38
+
39
+ @lstop=Gtk::Label.new(_("Stop:\t"))
40
+ @bcstop=Gtk::CheckButton.new('Ctrl')
41
+ @bcstop.active=config[:stop_mask]&GlobalHotKeys::Modifier::CONTROL_MASK==GlobalHotKeys::Modifier::CONTROL_MASK
42
+ @bsstop=Gtk::CheckButton.new('Shift')
43
+ @bsstop.active=config[:stop_mask]&GlobalHotKeys::Modifier::SHIFT_MASK==GlobalHotKeys::Modifier::SHIFT_MASK
44
+ @bastop=Gtk::CheckButton.new('Alt')
45
+ @bastop.active=config[:stop_mask]&GlobalHotKeys::Modifier::MOD1_MASK==GlobalHotKeys::Modifier::MOD1_MASK
46
+ @estop=Gtk::Entry.new
47
+ @estop.text=config[:stop_key]
48
+
49
+ @lplay=Gtk::Label.new(_("Play/pause:\t"))
50
+ @bcplay=Gtk::CheckButton.new('Ctrl')
51
+ @bcplay.active=config[:play_mask]&GlobalHotKeys::Modifier::CONTROL_MASK==GlobalHotKeys::Modifier::CONTROL_MASK
52
+ @bsplay=Gtk::CheckButton.new('Shift')
53
+ @bsplay.active=config[:play_mask]&GlobalHotKeys::Modifier::SHIFT_MASK==GlobalHotKeys::Modifier::SHIFT_MASK
54
+ @baplay=Gtk::CheckButton.new('Alt')
55
+ @baplay.active=config[:play_mask]&GlobalHotKeys::Modifier::MOD1_MASK==GlobalHotKeys::Modifier::MOD1_MASK
56
+ @eplay=Gtk::Entry.new
57
+ @eplay.text=config[:play_key]
58
+
59
+ @lnext=Gtk::Label.new(_("Next:\t"))
60
+ @bcnext=Gtk::CheckButton.new('Ctrl')
61
+ @bcnext.active=config[:next_mask]&GlobalHotKeys::Modifier::CONTROL_MASK==GlobalHotKeys::Modifier::CONTROL_MASK
62
+ @bsnext=Gtk::CheckButton.new('Shift')
63
+ @bsnext.active=config[:next_mask]&GlobalHotKeys::Modifier::SHIFT_MASK==GlobalHotKeys::Modifier::SHIFT_MASK
64
+ @banext=Gtk::CheckButton.new('Alt')
65
+ @banext.active=config[:next_mask]&GlobalHotKeys::Modifier::MOD1_MASK==GlobalHotKeys::Modifier::MOD1_MASK
66
+ @enext=Gtk::Entry.new
67
+ @enext.text=config[:next_key]
68
+
69
+ super(4, 5)
70
+ #self.column_spacings=$border
71
+ self.attach(@lprev, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, $border)
72
+ self.attach(@bcprev, 1, 2, 0, 1)
73
+ self.attach(@bsprev, 2, 3, 0, 1)
74
+ self.attach(@baprev, 3, 4, 0, 1)
75
+ self.attach(@eprev, 4, 5, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, $border)
76
+ self.attach(@lstop, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, $border)
77
+ self.attach(@bcstop, 1, 2, 1, 2)
78
+ self.attach(@bsstop, 2, 3, 1, 2)
79
+ self.attach(@bastop, 3, 4, 1, 2)
80
+ self.attach(@estop, 4, 5, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, $border)
81
+ self.attach(@lplay, 0, 1, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, $border)
82
+ self.attach(@bcplay, 1, 2, 2, 3)
83
+ self.attach(@bsplay, 2, 3, 2, 3)
84
+ self.attach(@baplay, 3, 4, 2, 3)
85
+ self.attach(@eplay, 4, 5, 2, 3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, $border)
86
+ self.attach(@lnext, 0, 1, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, $border)
87
+ self.attach(@bcnext, 1, 2, 3, 4)
88
+ self.attach(@bsnext, 2, 3, 3, 4)
89
+ self.attach(@banext, 3, 4, 3, 4)
90
+ self.attach(@enext, 4, 5, 3, 4, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, $border)
91
+ end
92
+ end
93
+ end
data/mod/interact.rb ADDED
@@ -0,0 +1,131 @@
1
+ # encoding: UTF-8
2
+ =begin
3
+ Copyright 2007-2010 Vincent Carmona
4
+ vinc4mai@gmail.com
5
+
6
+ This file is part of ZiK.
7
+
8
+ ZiK is free software; you can redistribute it and/or modify
9
+ it under the terms of the GNU General Public License as published by
10
+ the Free Software Foundation; either version 2 of the License, or
11
+ (at your option) any later version.
12
+
13
+ ZiK is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU General Public License for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with ZiK; if not, write to the Free Software
20
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ =end
22
+
23
+ module Interact
24
+ Menu,LocalMenu=[], []
25
+ Arg, LocalArg=[], []
26
+ def self.menu_const_set(name, val, lval)
27
+ Menu.push(const_set(name, val))#Is it ok to push an object on a constant (not frozen) array ?
28
+ LocalMenu.push(const_set("LOCAL_"+name, lval))
29
+ end
30
+
31
+ def self.arg_const_set(name, val, lval)
32
+ Arg.push(const_set(name, val))
33
+ LocalArg.push(const_set("LOCAL_"+name, lval))
34
+ end
35
+
36
+ menu_const_set "MENU", "Menu", _("Menu")
37
+
38
+ arg_const_set "NONE", "None", _("None")
39
+ arg_const_set "PLAYLIST_FILES", "Playlit files", _("Playlit files")
40
+ arg_const_set "CURRENT_SONG", "Current Song", _("Current song")
41
+ arg_const_set "CURRENT_SONG_NAME", "Current song name", _("Current song name")
42
+
43
+ def Interact.mod
44
+ @m||=Mod.new('interact', "Interact", _("Add menu entries to interact with ZiK."),
45
+ 'Vincent Carmona <vinc4mai@gmail.com>', 'GPL-2')
46
+ end
47
+
48
+ Interact.mod
49
+ def @m.init(input)
50
+ @dir=input[:mod_dir]
51
+ require File.join(@dir, 'interact', 'interaction')
52
+ require File.join(@dir, 'interact', 'configwidget')
53
+ @interactions=Interaction.read(input[:config_dir])
54
+ @destroy_on_unload=[]
55
+ end
56
+
57
+ def @m.load
58
+ unless @loaded
59
+ @interactions.each{|interaction|
60
+ case interaction[:menu]
61
+ when MENU
62
+ it=Gtk::MenuItem.new(interaction[:name])
63
+ it.signal_connect('activate'){
64
+ arg=resolve_argument(interaction[:argument])
65
+ c=interaction[:command].split(' ')
66
+ t=[*c]+[*arg]
67
+ Thread.new{system(*t)}
68
+ }
69
+ menu_add(it.show)
70
+ @destroy_on_unload.push(it)
71
+ else
72
+ ModErrorError.new(self,
73
+ _("Cannot create interactions named #{interaction[:name]}(unknow menu type)."), true)
74
+ end
75
+ }
76
+ @loaded=true
77
+ else
78
+ false
79
+ end
80
+ end
81
+
82
+ def @m.unload
83
+ if @loaded
84
+ @destroy_on_unload.each{|w| w.destroy}
85
+ @destroy_on_unload.clear
86
+ menu_hide
87
+ @loaded=false
88
+ true
89
+ else
90
+ false
91
+ end
92
+ end
93
+
94
+ def @m.configwidget
95
+ @wconfig=ConfigWidget.new(@interactions)
96
+ end
97
+
98
+ def @m.saveconfig
99
+ old_interactions=@interactions
100
+ @interactions=@wconfig.interactions
101
+ reload if @loaded
102
+ end
103
+
104
+ def @m.quit
105
+ Interaction.write(@interactions)
106
+ end
107
+
108
+ private
109
+
110
+ def @m.reload
111
+ unload
112
+ self.load
113
+ end
114
+
115
+ def @m.resolve_argument(type)
116
+ #escape=/[\ \'\#\[\]\(\)\&\;\|\!]/; String#gsub(escape){|s| '\\'+s}
117
+ case type
118
+ when NONE
119
+ ""
120
+ when PLAYLIST_FILES
121
+ list=zik.playlist
122
+ list.songs.map{|song| song.path}
123
+ when CURRENT_SONG
124
+ list=zik.playlist
125
+ list.songs[list.current].path
126
+ when CURRENT_SONG_NAME
127
+ list=zik.playlist
128
+ list.songs[list.current].name
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,107 @@
1
+ # encoding: UTF-8
2
+ =begin
3
+ Copyright 2007-2010 Vincent Carmona
4
+ vinc4mai@gmail.com
5
+
6
+ This file is part of ZiK.
7
+
8
+ ZiK is free software; you can redistribute it and/or modify
9
+ it under the terms of the GNU General Public License as published by
10
+ the Free Software Foundation; either version 2 of the License, or
11
+ (at your option) any later version.
12
+
13
+ ZiK is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU General Public License for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with ZiK; if not, write to the Free Software
20
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ =end
22
+
23
+ module Interact
24
+ class InteractionWidget
25
+ attr_reader :menu, :name, :command, :argument, :rm
26
+
27
+ def initialize(interaction=nil)
28
+ @removed=false
29
+ if interaction
30
+ menu=Menu.index(interaction[:menu])
31
+ name=interaction[:name]
32
+ command=interaction[:command]
33
+ arg=Arg.index(interaction[:argument])
34
+ sensitive=true
35
+ end
36
+ menu||=-1
37
+ name||=""
38
+ command||=""
39
+ arg||=0
40
+ sensitive||=false
41
+
42
+ @menu=Gtk::ComboBox.new
43
+ @menu.append_text(LOCAL_MENU)
44
+ @menu.active=menu
45
+ @menu.signal_connect('changed'){
46
+ sensitive=@menu.active>=0
47
+ [@name, @command, @argument].each{|w| w.sensitive=sensitive}
48
+ }
49
+ @name=Gtk::Entry.new
50
+ @name.text=name
51
+ @command=Gtk::Entry.new
52
+ @command.text=command
53
+ @argument=Gtk::ComboBox.new
54
+ LocalArg.each{|c| @argument.append_text(c)}
55
+ @argument.active=arg
56
+ @rm=Gtk::Button.new
57
+ @rm.image=Gtk::Image.new(Gtk::Stock::REMOVE, Gtk::IconSize::BUTTON)
58
+ @rm.signal_connect('clicked'){
59
+ [@menu, @name, @command, @argument, @rm].each{|w| w.hide}
60
+ @removed=true
61
+ }
62
+ [@menu, @name, @command, @argument, @rm].each{|w| w.show}
63
+ [@name, @command, @argument].each{|w| w.sensitive=sensitive} unless sensitive
64
+ end
65
+
66
+ def to_h
67
+ if @removed||@menu.active<0
68
+ {}
69
+ else
70
+ {:menu=>Menu[LocalMenu.index(@menu.active_text)], :name=>@name.text,
71
+ :command=>@command.text, :argument=>Arg[LocalArg.index(@argument.active_text)]}
72
+ end
73
+ end
74
+ end
75
+
76
+ class ConfigWidget < Gtk::Table
77
+ def initialize(interactions)
78
+ @iwidgets=[]; @nb=0
79
+ badd=Gtk::Button.new
80
+ badd.image=Gtk::Image.new(Gtk::Stock::ADD, Gtk::IconSize::BUTTON)
81
+ badd.signal_connect('clicked'){add_interaction}
82
+ super(interactions.length+1, 5)
83
+ self.attach(badd, 0, 5, 0, 1)
84
+ self.attach(Gtk::Label.new(_("Menu")), 0, 1, 1, 2)
85
+ self.attach(Gtk::Label.new(_("Name")), 1, 2, 1, 2)
86
+ self.attach(Gtk::Label.new(_("Command")), 2, 3, 1, 2)
87
+ self.attach(Gtk::Label.new(_("Argument")), 3, 4, 1, 2)
88
+ interactions.each_with_index{|interact, i| add_interaction(interact)}
89
+ end
90
+
91
+ def add_interaction(interaction=nil)
92
+ @iwidgets.push(iwidget=InteractionWidget.new(interaction))
93
+ self.attach(iwidget.menu, 0, 1, @nb+2, @nb+3)
94
+ self.attach(iwidget.name, 1, 2, @nb+2, @nb+3)
95
+ self.attach(iwidget.command, 2, 3, @nb+2, @nb+3)
96
+ self.attach(iwidget.argument, 3, 4, @nb+2, @nb+3)
97
+ self.attach(iwidget.rm, 4, 5, @nb+2, @nb+3)
98
+ @nb+=1
99
+ end
100
+
101
+ def interactions
102
+ tmp=@iwidgets.map{|w| w.to_h}
103
+ tmp.reject!{|h| h.empty?||h[:name].empty?||h[:command].empty?}
104
+ tmp.map{|h| Interaction.new(h)}
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,79 @@
1
+ # encoding: UTF-8
2
+ =begin
3
+ Copyright 2007-2010 Vincent Carmona
4
+ vinc4mai@gmail.com
5
+
6
+ This file is part of ZiK.
7
+
8
+ ZiK is free software; you can redistribute it and/or modify
9
+ it under the terms of the GNU General Public License as published by
10
+ the Free Software Foundation; either version 2 of the License, or
11
+ (at your option) any later version.
12
+
13
+ ZiK is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU General Public License for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with ZiK; if not, write to the Free Software
20
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ =end
22
+
23
+ module Interact
24
+ class Interaction < Hash
25
+ def Interaction.read(dir)
26
+ @file=File.join(dir,'interactionrc')
27
+ if File.exist?(@file)
28
+ begin
29
+ f=File.open(@file,'r')
30
+ interactions=f.read.split("\n\n").map!{|i| i.split("\n").reject{|a| a =~ /^#/}.reject{|a| a =~ /^\n/}}
31
+ interactions.map!{|i| Interaction.from_a(i)}
32
+ interactions.reject!{|i| i.empty?}
33
+ rescue
34
+ interactions=[]
35
+ ModErrorError.new(Interact.mod, "reading configuration file.")
36
+ ensure
37
+ f.close if f
38
+ end
39
+ else
40
+ ModErrorError.new(Interact.mod, "Configuration file not found.")
41
+ end
42
+ interactions||[]
43
+ end
44
+
45
+ def Interaction.write(interactions)
46
+ if $write_config
47
+ begin
48
+ dir=File.dirname(@file)
49
+ Dir.mkdir(dir) unless File.exist?(dir)
50
+ f=File.open(@file,'w')
51
+ f.puts '##Configuration file for interact module (ZiK audio player).'
52
+ interactions.each{|i|
53
+ i.each_pair{|key, value| f.puts "#{key}=#{value}"}
54
+ f.puts ""
55
+ }
56
+ ModErrorInfo.new(Interact.mod, "configuration saved")
57
+ rescue
58
+ ModErrorError.new(Interact.mod, "writting configuration file.")
59
+ ensure
60
+ f.close if f
61
+ end
62
+ end
63
+ end
64
+
65
+ def Interaction.from_a(a)
66
+ i=Interaction.new
67
+ a.each{|l|
68
+ k, v=l.split('=', 2)
69
+ i[k.to_sym]=v
70
+ }
71
+ i
72
+ end
73
+
74
+ def initialize(hash=nil)
75
+ super()
76
+ self.merge!(hash) if hash
77
+ end
78
+ end
79
+ end
data/mod/notify.rb ADDED
@@ -0,0 +1,128 @@
1
+ # encoding: UTF-8
2
+ =begin
3
+ Copyright 2007-2011 Vincent Carmona
4
+ vinc4mai@gmail.com
5
+
6
+ This file is part of ZiK.
7
+
8
+ ZiK is free software; you can redistribute it and/or modify
9
+ it under the terms of the GNU General Public License as published by
10
+ the Free Software Foundation; either version 2 of the License, or
11
+ (at your option) any later version.
12
+
13
+ ZiK is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU General Public License for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with ZiK; if not, write to the Free Software
20
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ =end
22
+
23
+ module Notify
24
+ def Notify.mod
25
+ @m||=Mod.new('notify', "Notify", _("Display a notification when playing a new song."),
26
+ 'Vincent Carmona <vinc4mai@gmail.com>', 'GPL-2')
27
+ end
28
+
29
+ Notify.mod
30
+ def @m.init(input)
31
+ @dir=input[:mod_dir]
32
+ @zik=zik
33
+ @pix_dir=input[:pix_dir]
34
+ require File.join(@dir, 'notify', 'config')
35
+ @config=Configuration.new(input[:config_dir])
36
+ require File.join(@dir, 'notify', 'configwidget')
37
+ end
38
+
39
+ def @m.load
40
+ unless @loaded
41
+ require File.join(@dir, 'notify', 'window')
42
+ begin
43
+ Notify.init($name) if require 'RNotify'
44
+ @icon=File.join(@pix_dir,'ZiK.svg')
45
+ @rnotify=true
46
+ rescue LoadError
47
+ @rnotify=false
48
+ ModErrorLoadError.new(self,
49
+ _("Cannot use system notification. Please install ruby-libnotify."))
50
+ end
51
+ @zik.signal_connect('play'){|widget, song|
52
+ if @loaded
53
+ if @config[:native]
54
+ @window||=Notify::Window.new(@config)
55
+ @window.label.set_markup("\n"+'<span foreground="'+@config[:fg]+'"> '+song.name.gsub('&','&amp;')+' </span>'+"\n")#GLib::Markup.escape_text is not yet implemented
56
+ @window.resize(1, 1)
57
+ size=@window.size
58
+ @window.move(Gdk.screen_width-size[0]-10, 30)
59
+ @window.show
60
+ GLib::Timeout.add(@config[:time]*1000){@window.hide; false}
61
+ else
62
+ if @rnotify
63
+ if @notification
64
+ @notification.update(_('Playing'), song.name, @icon)
65
+ else
66
+ @notification=Notify::Notification.new(_('Playing'), song.name, @icon, nil)
67
+ end
68
+ @notification.timeout=(@config[:time]*1000).to_i
69
+ @notification.show
70
+ else
71
+ ModErrorError.new(self, "RNotify is not loaded.")
72
+ end
73
+ end
74
+ end
75
+ }
76
+ ModErrorInfo.new(self, "module loaded.")
77
+ @loaded=true
78
+ else
79
+ false
80
+ end
81
+ end
82
+
83
+ def @m.unload
84
+ if @loaded
85
+ @window.destroy if @window
86
+ if @rnotify
87
+ @notification.close if @notification
88
+ end
89
+ ModErrorInfo.new(self, "module unloaded.")
90
+ @loaded=false
91
+ true
92
+ else
93
+ false
94
+ end
95
+ end
96
+
97
+ def @m.configwidget
98
+ @wconfig=ConfigWidget.new(@config)
99
+ end
100
+
101
+ def @m.saveconfig
102
+ if @loaded
103
+ @config[:time]=@wconfig.btime.value
104
+ @config[:native]=@wconfig.bradio1.active?
105
+ begin
106
+ color=@wconfig.bg_entry.text
107
+ Gdk::Color.parse(color)
108
+ @config[:bg]=color
109
+ color=@wconfig.fg_entry.text
110
+ Gdk::Color.parse(color)
111
+ @config[:fg]=color
112
+ rescue
113
+ ModErrorError.new(self, "#{color} is not a valid color. Use previous value.")
114
+ end
115
+ true
116
+ else
117
+ false
118
+ end
119
+ end
120
+
121
+ def @m.quit
122
+ @config.save if @config
123
+ if @rnotify
124
+ @notification.close if @notification
125
+ Notify.uninit
126
+ end
127
+ end
128
+ end