Class: Rubio::View::Radio

Inherits:
Object
  • Object
show all
Includes:
Glimmer::LibUI::Application
Defined in:
lib/rubio/view/radio.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#presenterObject (readonly)

Returns the value of attribute presenter.



23
24
25
# File 'lib/rubio/view/radio.rb', line 23

def presenter
  @presenter
end

Instance Method Details

#about_message_boxObject



220
221
222
223
224
225
226
227
228
229
# File 'lib/rubio/view/radio.rb', line 220

def about_message_box
  license = begin
    File.read(File.expand_path('../../../LICENSE.txt', __dir__))
  rescue => e
    puts e.full_message if debug
    ''
  end
  product = "rubio-radio #{Rubio::VERSION}"
  message_box(product, "#{product}\n\n#{license}")
end

#currently_playing_labelObject



174
175
176
177
178
179
180
181
# File 'lib/rubio/view/radio.rb', line 174

def currently_playing_label
  return unless show_currently_playing && backend == 'vlc -I rc' && !OS.windows?

  label do
    stretchy false
    text <= [@presenter.player, :currently_playing]
  end
end

#help_menuObject



164
165
166
167
168
169
170
171
172
# File 'lib/rubio/view/radio.rb', line 164

def help_menu
  menu('Help') do
    menu_item('About') do
      on_clicked do
        about_message_box
      end
    end
  end
end

#radio_menuObject



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
# File 'lib/rubio/view/radio.rb', line 79

def radio_menu
  menu('Radio') do
    menu_item('Stop') do
      enabled <= [@presenter, 'current_station', on_read: ->(value) { !!value }]
      
      on_clicked do
        @presenter.stop_station
      end
    end

    separator_menu_item

    menu_item('Bookmark') do
      enabled <= [@presenter, 'current_station.bookmarked', on_read: ->(value) { value == false }]
      
      on_clicked do
        toggle_bookmarked_station
      end
    end

    menu_item('Unbookmark') do
      enabled <= [@presenter, 'current_station.bookmarked', on_read: ->(value) { value == true }]
      
      on_clicked do
        toggle_bookmarked_station
      end
    end

    separator_menu_item

    if OS.mac?
      about_menu_item do
        on_clicked do
          about_message_box
        end
      end
    end

    quit_menu_item do
      on_clicked do
        @presenter.player.stop_all
      end
    end
  end
end

#radio_menu_barObject



71
72
73
74
75
76
77
# File 'lib/rubio/view/radio.rb', line 71

def radio_menu_bar
  return unless OS.mac? || show_menu

  radio_menu
  view_menu
  help_menu
end

#refresh_viewObject



249
250
251
252
253
254
255
256
257
258
# File 'lib/rubio/view/radio.rb', line 249

def refresh_view
  case @presenter.view
  when :all
    view_all
  when :bookmarks
    view_bookmarks
  when :playing
    view_playing
  end
end

#station_table_columnsObject



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
# File 'lib/rubio/view/radio.rb', line 183

def station_table_columns
  table_columns = {
    'Play' => {
      button: {
        on_clicked: lambda { |row|
          station = @station_table.refined_model_array[row]
          begin
            @presenter.select_station(station)
          rescue => e
            puts e.full_message if debug
            message_box(e.message)
          end
        }
      }
    }
  }

  if show_bookmarks
    table_columns.merge!(
      'Bookmark' => {
        button: {
          on_clicked: lambda { |row|
            station = @station_table.refined_model_array[row]
            toggle_bookmarked_station(station)
          }
        }
      }
    )
  end

  table_columns.merge!(
    'name' => :text,
    'language' => :text,
    'country' => :text
  )
end

#toggle_bookmarked_station(station = nil) ⇒ Object



231
232
233
234
235
# File 'lib/rubio/view/radio.rb', line 231

def toggle_bookmarked_station(station = nil)
  station ||= @presenter.current_station
  @presenter.toggle_bookmarked_station(station)
  view_bookmarks if @presenter.view == :bookmarks && !station.bookmarked
end

#view_allObject



237
238
239
# File 'lib/rubio/view/radio.rb', line 237

def view_all
  @station_table.model_array = @presenter.stations
end

#view_bookmarksObject



241
242
243
# File 'lib/rubio/view/radio.rb', line 241

def view_bookmarks
  @station_table.model_array = @presenter.stations.select(&:bookmarked?)
end

#view_menuObject



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
# File 'lib/rubio/view/radio.rb', line 125

def view_menu
  menu('View') do
    radio_menu_item('All') do
      checked <=> [@presenter, :view,
                    on_read: ->(value) { value == :all },
                    on_write: ->(value) { :all },
                  ]
      
      on_clicked do
        view_all
      end
    end

    radio_menu_item('Bookmarks') do
      checked <=> [@presenter, :view,
                    on_read: ->(value) { value == :bookmarks },
                    on_write: ->(value) { :bookmarks },
                  ]
                  
      on_clicked do
        view_bookmarks
      end
    end

    radio_menu_item('Playing') do
      checked <=> [@presenter, :view,
                    on_read: ->(value) { value == :playing },
                    on_write: ->(value) { :playing },
                  ]
                  
      on_clicked do
        view_playing
      end
    end

    separator_menu_item if OS.mac?
  end
end

#view_playingObject



245
246
247
# File 'lib/rubio/view/radio.rb', line 245

def view_playing
  @station_table.model_array = @presenter.stations.select(&:playing?)
end