27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
|
# File 'lib/sh_view.rb', line 27
def initialize
Log.warning 'Instance of View already created!' if @@instance
@@instance = self
GLib.application_name = "Shroom"
Gtk.init
@rnotify = try_require 'RNotify'
Notify.init 'Shroom' if @rnotify
if File.exists? Global.prefs[:library_dir]
dialog = Kelp::ProgressDialog.new("Updating database...")
cancelled = false
dialog.signal_connect('response') { cancelled = true }
new_songs = []
Find.find(Global.prefs[:library_dir]) do |path|
ext = File.extname path
if Global::SUPPORTED_EXTENSIONS.include? ext
new_songs << path if Song.first(:path => path).nil?
end
end
if new_songs.length > 0
dialog.show_all
Kelp.process_events
end
inc = 1 / new_songs.length.to_f
new_songs.each do |path|
dialog.message = path
begin
Database.add_song path
Log.debug "Added #{path} to database"
rescue
Log.info "Failed to add ${path} to database", $!
end
frac = dialog.fraction + inc
dialog.fraction = frac > 1 ? 1 : frac
Kelp.process_events
break if cancelled
end
dialog.message = "Cleaning out old entries..."
dialog.pulse
Song.clean_missing_songs
Album.clean_empty_albums
Artist.clean_empty_artists
dialog.destroy
new_songs = dialog = nil
end
Log.debug 'Synchronized library dir with database'
icon = Gdk::Pixbuf.new Global.locate('icon_16x16.png')
@window = Window.new "Shroom"
@window.icon = icon
@window.resize 800, 600
@window.signal_connect('destroy') do
quit
end
@status_icon = StatusIcon.new
@status_icon.pixbuf = icon
@status_icon.visible = true
@status_icon.signal_connect('activate') do |widget|
@window.visible = !@window.visible?
end
content_pane = VBox.new(false, 0)
@window.add content_pane
content_pane.pack_start(, false, true, 0)
vpaned = VBox.new
content_pane.add vpaned
vbox = VBox.new false, 0
vpaned.pack_start vbox, false, true, 8
hbox = HBox.new
lbl_song = Label.new
lbl_song.ellipsize = Pango::Layout::ELLIPSIZE_END
hbox.add lbl_song
lbl_time = Label.new(format_seconds(0) + "/" + format_seconds(0))
hbox.pack_start lbl_time, false, false, 8
vbox.pack_start hbox, false, false, 8
box_controls = HBox.new
vbox.add box_controls
@btn_play = ToggleButton.new
@btn_play.add Image.new Stock::MEDIA_PLAY, IconSize::SMALL_TOOLBAR
box_controls.pack_start @btn_play, false, true, 0
btn_prev = Button.new
btn_prev.add Image.new Stock::MEDIA_PREVIOUS, IconSize::SMALL_TOOLBAR
box_controls.pack_start btn_prev, false, true, 0
seeker = HScale.new 0, 1, 0.01
box_controls.add seeker
seeker.draw_value = false
btn_next = Button.new
btn_next.add Image.new Stock::MEDIA_NEXT, IconSize::SMALL_TOOLBAR
box_controls.pack_start btn_next, false, true, 0
seeker.signal_connect('change_value') do |range, scroll, value|
if @player
seeker.value = value if value < 0.999
pos = seeker.value * @player.duration
@player.seek pos
else
seeker.value = 0
end
end
GLib::Timeout.add(100) do
if @player
pos = @player.position.to_f
seeker.value = pos / @player.duration
lbl_time.text = format_seconds(pos) + "/" + format_seconds(@player.duration)
lbl_song.set_markup @player.song.to_html
else
seeker.value = 0
lbl_time.text = format_seconds(0) + "/" + format_seconds(0)
lbl_song.set_markup "<b>Not playing</b>"
end
true
end
@btn_play.signal_connect('clicked') do |toggle|
if toggle.active?
@player.play
else
@player.pause
end if @player
end
btn_next.signal_connect('clicked') do |btn|
next_song
end
btn_prev.signal_connect('clicked') do |btn|
prev_song
end
hpaned = HPaned.new
vpaned.add hpaned
frm_content = Frame.new
hpaned.add2 frm_content
= VBox.new(false, 0)
hpaned.add1
sw = ScrolledWindow.new(nil, nil)
sw.set_policy(POLICY_AUTOMATIC, POLICY_NEVER)
sw.width_request = 150
.add sw
sto_tabs = ListStore.new(String)
NUM_TABS.times do |tab|
iter = sto_tabs.append
iter[0] = TAB_NAMES[tab]
end
lst_tabs = TreeView.new sto_tabs
lst_tabs. = false
renderer = CellRendererText.new
column = TreeViewColumn.new('Invisible header',
renderer,
'text' => 0)
lst_tabs.append_column column
sw.add lst_tabs
@img_cover = Image.new
event_box = EventBox.new
event_box.add @img_cover
event_box.signal_connect('button-press-event') do |w, event|
Kelp::ImageDialog.new(@pixbuf, @player.song.album.title).show if @pixbuf and @player
end
Drag.dest_set(event_box, 0, [], 0)
event_box.signal_connect('drag-data-received') do |w, dc, x, y, data, info, time|
p data
dc.drop_finish(true, time)
true
end
event_box.signal_connect('drag-motion') do |w, dc, x, y, time|
dc.drag_status(Gdk::DragContext::ACTION_COPY, time)
true
end
event_box.signal_connect('drag-drop') do |w, dc, x, y, time|
Drag.get_data(w, dc, dc.targets.last, time)
true
end
@img_cover.height_request = 128
@img_cover.width_request = 128
bx = HBox.new false, 0
bx.pack_start event_box, false, false, 16
.pack_start bx, false, false, 16
@txt_lyrics = TextView.new
@txt_lyrics.editable = false
@txt_lyrics.cursor_visible = false
@txt_lyrics.left_margin = @txt_lyrics.right_margin = 8
scr_lyrics = ScrolledWindow.new(nil, nil)
scr_lyrics.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC)
scr_lyrics.add @txt_lyrics
@buf_lyrics = @txt_lyrics.buffer
@buf_lyrics.create_tag 'title', 'font' => 'Sans 18'
box_lyrics = VBox.new false, 0
box_lyrics.add scr_lyrics
@btn_refresh_lyrics = Button.new Stock::REFRESH
box_lyrics.pack_start @btn_refresh_lyrics, false, false
queue = Sh::Queue.new self
@browse = Sh::Browse.new self
cover_browse = Sh::CoverBrowse.new self
playlists = Sh::Playlists.new self
lst_tabs.selection.signal_connect('changed') do |selection|
frm_content.remove frm_content.child if frm_content.child
case selection.selected.path.indices[0]
when TAB_QUEUE
frm_content.child = queue.widget
queue.update
when TAB_BROWSE
frm_content.child = @browse.widget
when TAB_LYRICS
frm_content.child = box_lyrics
when TAB_COVER_BROWSE
frm_content.child = cover_browse.widget
when TAB_PLAYLISTS
frm_content.child = playlists.widget
end
frm_content.show_all
end
i = 0
lst_tabs.model.each do |row|
lst_tabs.selection.select_path row[1] if i == TAB_BROWSE
i += 1
end
MMKeys.new do |key|
case key
when 'Stop'
stop
when 'Next'
next_song
when 'Previous'
prev_song
when 'Play', 'PlayPause'
if playing?
pause
else
play
end
when 'Pause'
pause
end
end
ShroomActions.init
@window.show_all
end
|