/* Copyright (c) 2004, Noah Sorscher
 * 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.
 * 	• 	Neither the name of the Noah Sorscher nor the names of its
 * 	contributors may 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.
 */
//
//  MHChapters.h
//  Hootenanny
//
//  Created by Noah Sorscher on Wed Mar 26 2003.
//  Copyright (c) 2003 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import <QuickTime/Movies.h>
#import "MHUtil.h"
#import "tScanner.h"

@protocol MHChaptersChangeListenerProto
-(void)chaptersDidChange:(id)chapters;
@end


@interface MHChapters : NSObject {
    NSMutableArray *theChapters;
    NSArray *realChapters;
    //TimeScale timeScale;
    BOOL updating, multilangual, igtemp;
}

#define kBogusStartingTime		-1			// an invalid starting time

- (MHChapters *)init;
- (MHChapters *)initFromMovie:(NSMovie *)aMovie;
- (MHChapters *)copy;
- (void)dealloc;

+ (void)addChaptersChangeListener:(id)listener;  // chapters change listeners implement the method - (void)chaptersDidChange:(id)chapters
- (void) didChange;

// TableView Data Source
- (int)numberOfRowsInTableView:(NSTableView *)aTableView;
- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex;
- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex;

- (void)setMultilingual:(BOOL)flag languages:(NSArray *)langs;
- (BOOL)multilingual;
- (void)setUpdating:(BOOL)flag;
- (int)count;
- (void)empty;
- (BOOL)containsString:(NSString *)searchString;
- (void)addObjectsFromArray:(NSArray *)chapters;
- (NSArray *)array;
- (void) updateWithArray:(NSArray *)newChapters;
- (NSArray *)chapterNames;
- (NSArray *)chapterNamesForLanguage:(NSString *)language;
- (NSArray *)chapterTimes;
- (NSArray *)chapterTimesForLanguage:(NSString *)language;
- (void)addChapterAtIndex:(int)index;
- (void)removeChapterAtIndex:(int)index;
//- (void)setTime:(long)samples forIndex:(int)index;
- (void)offsetAll:(double)seconds;
- (void)setSeconds:(double)seconds forIndex:(int)index;
- (int)indexForTime:(double)seconds;
- (int)indexForTime:(double)seconds language:(NSString *)language;
- (NSString *)nameForTime:(double)seconds;
- (NSString *)nameForTime:(double)seconds language:(NSString *)language;
- (double)timeForChapterAtIndex:(int)index;
- (double)timeForChapterAtIndex:(int)index language:(NSString *)language;
- (double)timeForChapterWithName:(NSString *)name;
- (double)nextTimeForTime:(double)seconds;
- (double)nextTimeForTime:(double)seconds language:(NSString *)language;
- (double)prevTimeForTime:(double)seconds;
- (double)prevTimeForTime:(double)seconds language:(NSString *)language;

- (NSRange)rangeOfChapterContainingString:(NSString *)string index:(int)index;

- (NSArray *)defsEntry;

- (void)setIgnoresTempFile:(BOOL)flag;
- (void)copyToRealChapters;
- (BOOL) parseMovFile:(NSURL *)aURL scaleToMovie:(NSMovie *)movie;
- (BOOL) parseOgmFile:(NSURL *)aURL scaleToMovie:(NSMovie *)movie;
- (BOOL) parseMkvFile:(NSURL *)aURL scaleToMovie:(NSMovie *)movie;
- (BOOL) parseTextFile:(NSURL *)aURL;
- (BOOL) parseTextFile:(NSURL *)aURL scaleToMovie:(NSMovie *)movie;
- (BOOL) parseText:(NSString *)chaptherText scaleToMovie:(NSMovie *)movie;
+ (NSString *)dvdxchapWithArgs:(NSArray *)args;
+ (NSArray *) titlesOfDVD:(NSString *)path;
- (BOOL) parseDVD:(NSString *)path;
- (BOOL) parseDVD:(NSString *)path title:(int)title;
- (BOOL) parseDVD:(NSString *)path title:(int)title scaleToMovie:(NSMovie *)movie;
- (BOOL) addToMovie:(NSMovie *)aMovie;
- (BOOL) addToQTMovie:(Movie)qtMovie;
- (BOOL) addToQTTrack:(Track)targetTrack language:(NSString *)lang;
- (BOOL) getChaptersFromMovie:(NSMovie *)aMovie;
- (void)setContent:(NSString *)s forTime:(double)t language:(NSString *)l;
- (BOOL) removeChaptersFromMovie:(NSMovie *)aMovie;
- (BOOL) removeChaptersFromQTMovie:(Movie)mov;
- (BOOL) saveToFile:(NSString *)path;
- (NSString *)getQTChapters;
//- (void)setTimeScale:(TimeScale)ts;
//- (void)setTimeScaleFromMovie:(NSMovie *)movie;
@end
