/*
* Jampa
* Copyright (C) 2008-2009 J. Devauchelle and contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
package org.jampa.gui.runnables;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.jampa.controllers.Controller;
import org.jampa.gui.translations.Messages;
import org.jampa.logging.Log;
import org.jampa.model.playlists.AudioItem;
import org.jampa.model.playlists.Playlist;
public class PlaylistChecker implements IRunnableWithProgress {
private HashMap<AudioItem, String> _removedList = null;
private Object[] _playlists;
private void doCheckPlaylists(IProgressMonitor monitor) {
_removedList = new HashMap<AudioItem, String>();
Playlist item;
AudioItem audioItem;
File file;
List<AudioItem> _toRemove = new ArrayList<AudioItem>();
for (int i = 0; i < _playlists.length; i++) {
if (monitor.isCanceled())
return;
item = (Playlist)_playlists[i];
monitor.subTask(item.getName());
_toRemove.clear();
Iterator<AudioItem> iter = item.getAudioList().iterator();
while (iter.hasNext()) {
audioItem = iter.next();
file = new File(audioItem.getFileName());
if (!file.exists()) {
Log.getInstance(PlaylistChecker.class).info("File not found in playlist: " + item.getName() + " / " + audioItem.getFileName()); //$NON-NLS-1$ //$NON-NLS-2$
_removedList.put(audioItem, item.getName());
_toRemove.add(audioItem);
}
}
monitor.worked(1);
}
}
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
_playlists = Controller.getInstance().getPlaylistController().getPlaylistList();
monitor.beginTask(Messages.getString("Controller.ChekingPlaylists"), _playlists.length); //$NON-NLS-1$
doCheckPlaylists(monitor);
monitor.done();
}
//public List<String> getResults() {
public HashMap<AudioItem, String> getResults() {
return _removedList;
}
}