Class: Ektoplayer::Views::Info

Inherits:
UI::Pad show all
Defined in:
lib/ektoplayer/views/info.rb

Instance Attribute Summary

Attributes inherited from UI::Pad

#win

Attributes inherited from UI::Widget

#pos, #size

Instance Method Summary collapse

Methods inherited from UI::Pad

#bottom, #down, #initialize, #layout, #mouse_click, #noutrefresh, #pad_mincol=, #pad_minrow=, #pad_size=, #page_down, #page_up, #refresh, #top, #up, #with_mouse_section_event

Methods inherited from UI::Widget

#display, #events, #initialize, #invisible!, #invisible?, #key_press, #keys, #layout, #lock, #mouse, #mouse_click, #mouse_event_transform, #mouse_section, #on_key_press, #on_widget_raise, #raise_widget, #refresh, #sub, #unlock, #visible!, #visible=, #visible?, #want_layout, #want_redraw, #want_refresh, #with_lock

Constructor Details

This class inherits a constructor from UI::Pad

Instance Method Details

#attach(player, playlist, trackloader, database) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/ektoplayer/views/info.rb', line 18

def attach(player, playlist, trackloader, database)
   @player, @playlist, @trackloader, @database =
      player, playlist, trackloader, database

   Thread.new do
      loop { sleep 1; draw if visible? }
   end.priority=(-10)
end

#drawObject



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
# File 'lib/ektoplayer/views/info.rb', line 74

def draw
   return unless @player

   self.pad_size=(UI::Size.new(
      height: 200,
      width:  [@size.width, MIN_WIDTH].max
   ))

   mouse_section.clear
   @win.erase
   @win.move(0,0)

   if @track = (@playlist[@playlist.current_playing] rescue nil)
      draw_heading('Current track')
      draw_tag('Number', '%0.2d' % @track['number'])
      draw_tag('Title',  @track['title'])
      draw_tag('Remix',  @track['remix']) if @track['remix']
      draw_tag('Artist', @track['artist'])
      draw_tag('Album',  @track['album'])
      draw_tag('BPM',    @track['bpm'])
      draw_tag('Length', Common::to_time(@player.length))
      @win.next_line

      draw_heading('Current album')

      draw_tag('Album')
      draw_url(Application.album_url(@track['album_url']), @track['album'])
      draw_tag('Artist',       @track['album__artist']) if @track['album_artist']
      draw_tag('Date',         @track['date'])

      draw_tag('Styles',       @track['styles'].gsub(?,, ', '))
      draw_tag('Downloads',    @track['download_count'])
      draw_tag('Rating',  '%0.2d%% (%d Votes)' % [@track['rating'], @track['votes']])
      draw_tag('Cover')
      draw_url(Application.cover_url(@track['cover_url']), 'Cover')

      @win.next_line

      # -- description
      draw_heading('Description')
      description = @database.get_description(@track['album_url'])
      line_length = START_TAG
      wrap_length = @size.width.clamp(1, LINE_WRAP)
      @win.move(@win.cury + 1, START_TAG)

      Nokogiri::HTML("<p>#{description}</p>").css(?p).each do |p|
         p.children.each do |element|
            if element['href']
               if (line_length += element.text.size) > wrap_length
                  @win.move(@win.cury + 1, START_TAG)
                  line_length = START_TAG
               end

               @win.addch(32) # ' '
               draw_url(element['href'], element.text.strip)
            else
               element.text.split(' ').each do |text|
                  if (line_length += text.size) > wrap_length
                     @win.move(@win.cury + 1, START_TAG)
                     line_length = START_TAG
                  end

                  @win.addch(32) # ' '
                  @win.attrset(Theme[:'info.description'])
                  @win.mv_left(1) if text =~ /^[\.,:;]$/ 
                  @win << text
               end
            end
         end
      end

      @win.next_line
      # --/description
   end

   if not @trackloader.downloads.empty?
      draw_heading('Downloads')
      @trackloader.downloads.each do |dl|
         name = File.basename(dl.filename)
         percent = '%0.2f' % dl.progress
         draw_download(name, "(#{percent}%)", dl.error)
      end
      @win.next_line
   end

   draw_heading('Player')
   draw_info('Version', Application::VERSION)
   draw_info('Tracks in database', @database.track_count)
   draw_info('Albums in database', @database.album_count)
   draw_info('Tracks in playlist', @playlist.size)
   draw_info('Cache dir size', '%dMB' % (Dir.size(Config[:cache_dir]) / (1024 ** 2) rescue 0))
   draw_info('Archive dir size', '%dMB' % (Dir.size(Config[:archive_dir]) / (1024 ** 2) rescue 0))
   draw_info('Ektoplazm URL'); draw_url(Application::EKTOPLAZM_URL)
   draw_info('Github URL'); draw_url(Application::GITHUB_URL)

   self.pad_size=(@size.update(height: [@win.cursor.y + 2, @size.height].max))
   noutrefresh
end

#draw_download(file, percent, error) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ektoplayer/views/info.rb', line 59

def draw_download(file, percent, error)
   @win.attrset(Theme[:'info.download.file'])
   @win.mvaddstr(@win.cury + 1, START_TAG, file)
   @win.addch(32) # ' '

   @win.attrset(Theme[:'info.download.percent'])
   @win.addstr(percent.to_s)

   if error
      @win.addch(32) # ' '
      @win.attrset(Theme[:'info.download.error'])
      @win.addstr(error.to_s)
   end
end

#draw_heading(heading) ⇒ Object



27
28
29
30
# File 'lib/ektoplayer/views/info.rb', line 27

def draw_heading(heading)
   @win.attrset(Theme[:'info.head'])
   @win.mvaddstr(@win.cury + 1, START_HEADING, heading)
end

#draw_info(string, value = nil) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/ektoplayer/views/info.rb', line 40

def draw_info(string, value=nil)
   @win.attrset(Theme[:'info.tag'])
   @win.mvaddstr(@win.cury + 1, START_INFO, string)

   @win.attrset(Theme[:'info.value'])
   @win.mvaddstr(@win.cury, START_INFO_VALUE, value.to_s)
end

#draw_tag(tag, value = nil) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/ektoplayer/views/info.rb', line 32

def draw_tag(tag, value=nil)
   @win.attrset(Theme[:'info.tag'])
   @win.mvaddstr(@win.cury + 1, START_TAG, tag)

   @win.attrset(Theme[:'info.value'])
   @win.mvaddstr(@win.cury, START_TAG_VALUE, value.to_s)
end

#draw_url(url, title = nil) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/ektoplayer/views/info.rb', line 48

def draw_url(url, title=nil)
   title ||= url
   mevent = with_mouse_section_event do
      @win.attrset(Theme[:url])
      @win << title
   end
   mevent.on(ICurses::BUTTON1_CLICKED) do
      Common::open_url_extern(url)
   end
end