package com.dt.iTunesController;
import com.jacob.com.Dispatch;

/**
 * Represents the status of an asynchronous add or convert operation.
 *
 * When a track is added using TLibraryPlaylist.addFile(),
 * ITLibraryPlaylist.AddFiles(), IITUserPlaylist.addFile(), or
 * ITUserPlaylist.addFiles(), the add may not complete immediately if iTunes
 * needs to make a copy of the file.
 *
 * Similarly, when converting or importing a file or track using
 * <code>iTunes.convertFile()</code>, <code>iTunes.convertFiles()</code>,
 * <code>iTunes.convertTrack()</code> or <code>iTunes.convertTracks()</code>,
 * the conversion will never complete immediately.
 *
 * These methods return an <code>ITOperationStatus</code> object, which can be
 * polled todetermine when the operation is done. This object will also return
 * the collection of newly added or converted tracks.
 *
 * As of version 1.1 of the iTunes type library, you should use
 * <code>iTunes.convertFile2()</code>, <code>iTunes.convertFiles2()</code>,
 * <code>iTunes.convertTrack2()</code> or <code>iTunes.convertTracks2()</code>
 * instead of the original convert methods. These new methods return an
 * <code>ITConvertOperationStatus</code> object to allow clients to retrieve
 * additional conversion progress information.
 *
 * @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
 * @version 0.2
 */
public class ITOperationStatus {

    protected Dispatch object;

    public ITOperationStatus(Dispatch d) {
        object = d;
    }

    /**
     * Returns true if the operation is still in progress.
     * You cannot retrieve the <code>ITOperationStatus.getTracks()</code>
     * property until the operation completes.
     * @return Returns true if the operation is still in progress.
     */
    public boolean getInProgress() {
        return Dispatch.get(object, "InProgress").getBoolean();
    }

    /**
     * Returns a collection containing the tracks that were generated by the
     * operation.
     * You cannot retrieve this property until
     * <code>ITOperationStatus.getInProgress()</code> returns false
     * @return Returns a collection containing the tracks that were generated by
     * the operation.
     */
    public ITTrackCollection getTracks() {
        Dispatch tracks = Dispatch.get(object, "Tracks").toDispatch();
        return new ITTrackCollection(tracks);
    }

}
