//
//  HTTPDownloadHandler.h
//  MaximusPluginTester
//
//  Created by Denis Gryzlov on 02.10.07.
//  Copyright 2007 Art Lebedev Studio. All rights reserved.
//

#import <Cocoa/Cocoa.h>

@protocol HTTPDownloaderDelegate<NSObject>
- (void) takeDownloadBack:(NSDictionary *)result;
- (void) errorOnDownload:(NSDictionary *)errorInfo;
@end

@interface SmartConnection : NSURLConnection {
	NSDictionary* info;
	
	NSURLResponse* response;
	NSMutableData* data;
}

-(id)initWithInfo:(NSDictionary*)connectionInfo;

-(NSDictionary*)info;
-(NSData*)data;
-(NSURLResponse*)response;

@end

@interface HTTPDownloadHandler : NSObject {
	NSMutableArray *tasksQueue;
	NSMutableArray *connectionsInProgress;
	int simultaneousDownloads;
	NSMutableArray *canceledTasksUUID;
}

//make public
+ (HTTPDownloadHandler*)sharedHTTPDownloadHelper;
- (void) downloadURL:(NSURL *)url username:(NSString*)username password:(NSString*)password andReturnTo:(id)delegate withToken:(NSString *)token;
- (void) downloadURL:(NSURL *)url andReturnTo:(id)delegate withToken:(NSString *)token;
- (void) cancelAllDownloadsForDelegate:(id)delegate;

-(void)onConnectionDownloadFinished:(SmartConnection*)connection;
-(void)onConnectionDownloadFailed:(SmartConnection*)connection withError:(NSDictionary*)error;

//make private
- (void) processTasksQueue;
- (int) simultaneousDownloads;
- (void) setSimultaneousDownloads:(int)newCount;


@end
