Class: GrooveDl::Widgets::Search

Inherits:
Events
  • Object
show all
Defined in:
lib/groove-dl/widgets/search.rb

Overview

Search section

Instance Attribute Summary collapse

Attributes inherited from Events

#app, #client

Instance Method Summary collapse

Methods inherited from Events

#initialize

Constructor Details

This class inherits a constructor from GrooveDl::Widgets::Events

Instance Attribute Details

#dataObject

Returns the value of attribute data.



7
8
9
# File 'lib/groove-dl/widgets/search.rb', line 7

def data
  @data
end

#storeObject

Returns the value of attribute store.



7
8
9
# File 'lib/groove-dl/widgets/search.rb', line 7

def store
  @store
end

Instance Method Details

#on_search_button_clickedObject



23
24
25
26
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
# File 'lib/groove-dl/widgets/search.rb', line 23

def on_search_button_clicked
  type = @app.get_object('search_type').active_id.to_i
  query = @app.get_object('search_entry').text
  return if query.empty?

  case type
  when TYPE_PLAYLISTS
    results = @client.search('Playlists', query)
  when TYPE_SONGS
    results = @client.search('Songs', query)
  when TYPE_PLAYLIST_ID
    playlist = Grooveshark::Playlist.new(@client, 'playlist_id' => query)
    results = playlist.load_songs
  end

  @data = {}
  @store = @app.get_object('search_list_store')
  @store.clear
  results.each do |element|
    iter = @store.append
    iter[COLUMN_CHECKBOX] = false
    if element.is_a?(Grooveshark::Song)
      @data[element.id.to_i] = element
      iter[COLUMN_ID] = element.id.to_i
      iter[COLUMN_NAME] = element.name
      iter[COLUMN_AUTHOR] = element.artist
      iter[COLUMN_SONG] = element.album
    else
      @data[element.id.to_i] = element
      iter[COLUMN_ID] = element.id.to_i.to_i
      iter[COLUMN_NAME] = element.name
      iter[COLUMN_AUTHOR] = element.username
      iter[COLUMN_SONG] = element.num_songs.to_s
    end
  end
end

#on_search_entry_activateObject



19
20
21
# File 'lib/groove-dl/widgets/search.rb', line 19

def on_search_entry_activate
  @app.get_object('search_button').signal_emit('clicked')
end

#on_search_list_selected_clickedObject



68
69
70
71
72
73
74
# File 'lib/groove-dl/widgets/search.rb', line 68

def on_search_list_selected_clicked
  @store.each do |_model, _path, iter|
    fixed = iter[COLUMN_CHECKBOX]
    fixed ^= 1
    iter[COLUMN_CHECKBOX] = fixed
  end
end

#on_search_list_toggle_toggled(_cell, path_str) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/groove-dl/widgets/search.rb', line 60

def on_search_list_toggle_toggled(_cell, path_str)
  path = Gtk::TreePath.new(path_str)
  iter = @store.get_iter(path)
  fixed = iter[COLUMN_CHECKBOX]
  fixed ^= 1
  iter[COLUMN_CHECKBOX] = fixed
end