// Copyright (c) 2002, Peter Bentley
// All rights reserved.
// 
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
// 
//   Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 
//   Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 
//   The name Peter Bentley may not be used to endorse or promote
// products derived from this software without specific prior
// written permission.
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//

#import "OmdTrackInfo.h"
#import "OmdTime.h"
#import "OmdToc.h"
#import "OmdTocCtlr.h"

CVSID( "$Id: OmdTrackInfo.m,v 1.12 2002/11/24 17:07:31 pete Exp $" );

@implementation OmdTrackInfo

- (id) initWithId: (int) i andToc: (OmdToc *) toc
{
    if( (self = [super init]) != nil )
    {
        trkid = i;
        omdToc = toc;
    }
    return self;
}

- (int) id
{
    return trkid + 1;
}

- (NSString *) idString
{
    NSString *str = [[NSString alloc] initWithFormat: @"%d ", [self id]];
    // [str retain];
    return str;
}

- (NSString *) groupString
{
    return @"G";
}

- (int) group
{
    omd_track_t *track = [self getTrack];

    return track->group;
}


- (NSString *) titleString;
{
    omd_track_t *track = [self getTrack];
    
    NSString *str = [[NSString alloc] initWithCString: track->title];
    [str autorelease];

    slog( LOG_DEBUG, "Get title for track %d @ %p, loaded =  %d", trkid, track, track->loaded );

    
    return str;
}

- (void) setTitleString: (NSString *) str
{
    omd_track_t *track = [self getTrack];

    slog( LOG_DEBUG, "Set track %d @ %p title: %s loaded = %d", trkid, track,
    [str lossyCString], track->loaded );
    [omdToc setTitle: str forTrack: trkid];
}


- (OmdTime *) length
{
    omd_track_t *track = [self getTrack];
    OmdTime *t = [[OmdTime alloc] initWithTime: &track->length];

    [t autorelease];
    return t;
}

- (NSString *) lengthString
{
    OmdTime *t = [self length];
    return [t stringValue];
}

- (NSString *) codecString
{
    omd_track_t *track = [self getTrack];
    NSString *str = [[NSString alloc] initWithCString: track->codec_name];
    [str autorelease];
    return str;
}


- (NSString *) rateString
{
    omd_track_t *track = [self getTrack];
    NSString *str = [[NSString alloc] initWithCString: track->bitrate_name];
    [str autorelease];
    return str;
}


- (NSString *) lockedString
{
    omd_track_t *track = [self getTrack];
    return (track->flags == OMD_FLAG_LOCKED) ? @"Yes" : @"";
}

- (NSString *) nodeType
{
    return kOmdTrackNode;
}

// Outline view data

- (int) numberOfChildren
{
    return -1;
}

- (id) childAtIndex: (int) index
{
    return nil;
}


- (omd_track_t *) getTrack
{
    return [omdToc rawTrackInfo: trkid];
}


@end
