Class: Sh::ShroomActions

Inherits:
Object show all
Defined in:
lib/sh_actions.rb

Class Method Summary collapse

Class Method Details

.initObject



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
# File 'lib/sh_actions.rb', line 40

def self.init
	action = Actions.new 'Add to queue', :song do |song|
		view = Sh::View.instance
		if view
      queue = view.queue
      if queue
        queue << song
      else
        view.queue = [song]
        view.queue_pos = 0
      end
      end
    end
    action[:stock_image] = Stock::ADD
          
	action = Actions.new 'Reread tags', :song do |song|
		browse = Sh::Browse.instance
		browse.remove_song song if browse
      song.read_tags!(true)
      $db.save_song song
      browse.insert_song song if browse
	end
	action[:stock_image] = Stock::HARDDISK
	
	action = Actions.new 'Lookup metadata automatically', :song do |song|
		if song.lookup!
			browse = Sh::Browse.instance
        browse.remove_song song if browse
        $db.save_song song
        browse.insert_song song if browse
      end
	end
	action[:stock_image] = Stock::FIND
	
	action = Actions.new 'Add to playlist', :song, :playlist do |song, playlist|
		playlist << song
		playlist.save!
	end
	action[:stock_image] = Stock::ADD
	
	action = Actions.new 'Properties', :song do |song|
		show_song_properties_dialog(song)
	end
	action[:stock_image] = Stock::PROPERTIES
end

.show_song_properties_dialog(song) ⇒ Object



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
# File 'lib/sh_actions.rb', line 86

def self.show_song_properties_dialog song
  glade = Global::GLADE['dlg_song']
  dlg_song = glade['dlg_song']
  txt_title = glade['txt_title']
  txt_title.text = song.title

  # Artists combo box
  sto_artists = ListStore.new(String, Artist)
  cmb_artist = glade['cmb_artist']
  sel = 0
  $db.artists.sort_by{|a| (a.name || '')}.each_with_index do |artist, i|
    iter = sto_artists.append
    iter[0] = artist.name
    iter[1] = artist
    sel = i if song.artist && artist.db_id == song.artist.db_id
  end
  cmb_artist.model = sto_artists
  cmb_artist.active = sel

  # Albums combo box
  sto_albums = ListStore.new(String, Album)
  cmb_album = glade['cmb_album']
  sel = 0
  $db.albums.sort_by{|a| (a.title || '')}.each_with_index do |album, i|
    iter = sto_albums.append
    iter[0] = album.title
    iter[1] = album
    sel = i if song.album && album.db_id == song.album.db_id
  end
  cmb_album.model = sto_albums
  cmb_album.active = sel

  glade['chk_image'].sensitive = false
  glade['fbtn_image'].sensitive = false
  glade['btn_add_artist'].sensitive = false
  glade['btn_add_album'].sensitive = false

  dlg_song.signal_connect('delete-event') do
    dlg_song.hide
  end
  btn_ok = glade['btn_ok']
  ok_handle = btn_ok.signal_connect('clicked') do
  	browse = Sh::Browse.instance
    song.title = txt_title.text
    song.artist = cmb_artist.active_iter[1]
    song.album = cmb_album.active_iter[1]
    browse.remove_song song if browse
    $db.save_song song
    browse.insert_song song if browse
    dlg_song.hide
  end
  btn_cancel = glade['btn_cancel']
  close_handle = btn_cancel.signal_connect('clicked') do
    dlg_song.hide
  end
  dlg_song.run
  btn_ok.signal_handler_disconnect ok_handle
  btn_cancel.signal_handler_disconnect close_handle
end