// DTActivityLog.h
// Created by Rob Rix on 2011-04-14
// Copyright 2011 DEVONtechnologies, LLC

#import <Foundation/Foundation.h>

@class DTActivityLog;

typedef void (^DTActivityLogCancelBlock)(DTActivityLog *log);

@interface DTActivityLog : NSObject
{
@private
	NSDate *startDate, *endDate;
	NSString *title, *statusString;
	NSUInteger countOfFinishedActions, countOfTotalActions;
	NSNumber *percentComplete;
	BOOL percentCompleteDidChange, activeActionsDidChange;
	NSMutableArray *activeActions;
	NSTimer *updateTimer;
	
	DTActivityLogCancelBlock cancelBlock;
	SEL cancelAction;
	id cancelTarget;
}

+(DTActivityLog *)activityLog;

@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain, readonly) NSDate *startDate;
@property (nonatomic, retain, readonly) NSDate *endDate;
@property (nonatomic, readonly) BOOL cancellable;

// 10.6 only
@property (nonatomic, copy) DTActivityLogCancelBlock cancelBlock;

// Supports also 10.5
-(SEL)cancelAction;
-(id)cancelTarget;
-(void)setCancelAction:(SEL)action target:(id)target;

-(void)start;
-(void)cancel; // Calls the cancel block/action; does not do anything else to the activity log; the cancel block/action is responsible for removing the log from the window, etc
-(void)finish;

@property (nonatomic, readonly) NSUInteger countOfFinishedActions;
@property (nonatomic, readonly) NSUInteger countOfTotalActions;
@property (nonatomic, readonly, retain) NSArray *activeActions;

-(void)enqueueAction;
-(void)startAction:(NSString *)action;
-(void)finishAction:(NSString *)action;

-(NSString *)statusString; // Only displayed if there are no active actions
-(void)setStatusString:(NSString *)string;

-(NSNumber *)percentComplete; // By default based on count of finished/total actions
-(void)setPercentComplete:(NSNumber *)number;

@end
