import javax.swing.Action import java.awt.* import org.slf4j.LoggerFactory import com.tagtraum.beatunes.action.standard.LibraryBatchAction import com.tagtraum.beatunes.action.standard.LibraryBatchAction.EachSongProcessor import com.tagtraum.beatunes.MessageDialog import javax.swing.JOptionPane import com.tagtraum.audiokern.AudioSong // An action that allows to reset all album ratings. // The corresponding menu item can be found in the 'Tools' menu. class ResetAlbumRatings extends LibraryBatchAction { // Inner class that implements the // com.tagtraum.beatunes.action.standard.LibraryBatchAction.EachSongProcessor // interface. Its process method is called for each song. class Resetter implements EachSongProcessor { static log = LoggerFactory.getLogger("ResetAlbumRatings.groovy") String file // Called once, before processing starts. def void startProcessing(int count) { "We are expecting to embed ratings for ${count} songs." } // Called for each song. def void process(AudioSong song, int index) { int rating = song.getAlbumRating() if (rating > 0) { song.setAlbumRating(0)"Reset album rating for " + song) } else {"No rating set in " + song) } } // Called once all songs were processed. def void finishProcessing() { "Done." new MessageDialog(getApplication().getMainWindow(), "Done.", JOptionPane.INFORMATION_MESSAGE, JOptionPane.DEFAULT_OPTION).showDialog() } // Message to be shown in progress dialog. def String getProgressDialogMessage(AudioSong song) { "Resetting album rating of ${song.getName()}" } // Title for progress dialog. def String getProgressDialogTitle() { "Resetting album ratings ..." } } // Unique id def String getId() { "Groovy.ResetAlbumRatings" } // Is called by beaTunes as part of the lifecycle after instantiation. // At this point all other plugins are instantiated and registered. // We use this to set the menu item's (i.e. action's) name. def void init() { putValue(Action.NAME, "Reset Album Ratings") } // We need to ask the user, whether he really wants to do this. // How we ask is defined here. def String getConfirmationMessage() { "Do you really want to the album ratings of all your files?" } // Factory method that creates the processor for each song. def EachSongProcessor createEachSongProcessor() { new Resetter() } }