Package org.jampa.gui.runnables

Source Code of org.jampa.gui.runnables.TagUpdater

/*
* 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.lang.reflect.InvocationTargetException;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

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.model.playlists.AudioItem;

public class TagUpdater implements IRunnableWithProgress {
 
  private List<AudioItem> _itemList;
 
  private Map<AudioItem, String> _problemItemList;
 
  private boolean _updateTrackNumber;
  private boolean _updateTitle;
  private boolean _updateArtist;
  private boolean _updateAlbum;
  private boolean _updateGenre;
  private boolean _updateYear;
  private boolean _updateComment;
  private String _trackNumber;
  private String _title;
  private String _artist;
  private String _album;
  private String _genre;
  private String _year;
  private String _comment;
 
  public TagUpdater(List<AudioItem> items,
      boolean updateTrackNumber, String trackNumber,
      boolean updateTitle, String title,
      boolean updateArtist, String artist,
      boolean updateAlbum, String album,
      boolean updateGenre, String genre,
      boolean updateYear, String year,
      boolean updateComment, String comment) {
   
    _itemList = items;
   
    _updateTrackNumber = updateTrackNumber;
    _updateTitle = updateTitle;
    _updateArtist = updateArtist;
    _updateAlbum = updateAlbum;
    _updateGenre = updateGenre;
    _updateYear = updateYear;
    _updateComment = updateComment;
   
    _trackNumber = trackNumber;
    _title = title;
    _artist = artist;
    _album = album;
    _genre = genre;
    _year = year;
    _comment = comment;
   
    _problemItemList = new Hashtable<AudioItem, String>();
  }
 
  private void internalProcessTags(IProgressMonitor monitor) {
    List<String> result;
    AudioItem item;
    Iterator<AudioItem> iter = _itemList.iterator();
    while (iter.hasNext()) {
      if (monitor.isCanceled())
        return;
     
      item = iter.next();
     
      monitor.subTask(Messages.getString("Controller.UpdatingTagsItem") + item.getFileName()); //$NON-NLS-1$
     
      result = Controller.getInstance().getHSQLController().updateLibraryItem(item.getFileName(),
            _updateTrackNumber, _trackNumber,
            _updateTitle, _title,
            _updateArtist, _artist,
            _updateAlbum, _album,
            _updateGenre, _genre,
            _updateYear, _year,
            _updateComment, _comment);
     
      if ((result != null) &&
          (result.size() > 0)) {
        for (int i = 0; i < result.size(); i++) {
          _problemItemList.put(item, result.get(i));
        }
      }
     
      monitor.worked(1);
    }
  }
 
  public Map<AudioItem, String> getProblemsList() {
    return _problemItemList;
  }

  @Override
  public void run(IProgressMonitor monitor) throws InvocationTargetException,  InterruptedException {
    int nbItems = _itemList.size();
    monitor.beginTask(Messages.getString("Controller.UpdatingTags"), nbItems); //$NON-NLS-1$
   
    internalProcessTags(monitor);
   
    monitor.done();
  }

}
TOP

Related Classes of org.jampa.gui.runnables.TagUpdater

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.