//
//  ApplicationController.h
//  CyTV Client
//
//  Created by Andreas Junghans on Sun Oct 26 2003.
//  Copyright (c) 2003-2004 Andreas Junghans. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import "ApplicationController.h"
#import "ApplicationControllerProtocol.h"
#import "BackgroundHelperProtocol.h"
#import "URLFetcher.h"
#import "ChooseServerController.h"
#import "PreferencesController.h"
#import "MyView.h"
#import "MyWindow.h"

enum {
    hotKeySkipForward = 1,
    hotKeySkipBackward = 2,
    hotKeyChannelUp = 3,
    hotKeyChannelDown = 4
};

@interface ApplicationController : NSObject <ApplicationControllerProtocol>
{
    NSConnection* _backgroundHelperConnection;
    id <BackgroundHelperProtocol> _backgroundHelper;

    IBOutlet id cacheStateBar;
    IBOutlet NSApplication *application;
    IBOutlet NSButton *channelDownButton;
    IBOutlet NSPopUpButton *channelPopUpButton;
    IBOutlet NSButton *channelUpButton;
    IBOutlet MyView *overlayView;
    IBOutlet MyWindow *overlayWindow;
    IBOutlet NSButton *recordButton;
    IBOutlet NSButton *scanButton;
    IBOutlet NSSlider *streamPosSlider;
    IBOutlet NSTableView *streamsTableView;
	IBOutlet NSTableColumn *streamsDateColumn;
    IBOutlet NSTextField *nowPlaying;

    IBOutlet ChooseServerController *chooseServerController;
    IBOutlet PreferencesController *preferencesController;

    BOOL _ignoreNextStreamInfo;
    
    BOOL _infoCollectorRunning;
    BOOL _channelScannerRunning;
    
    NSString* _baseURL;
    NSString* _clientId;
    
    URLFetcher* _urlFetcher;
    
    NSString* _currentQuality;
    int _currentStreamIndex;
    NSTableColumn* _sortedBy;
    BOOL _sortedDescending;
    
    NSDictionary* _hotKeyMap;
    NSTimer* _overlayTimer;
    int _timerCounter;
}

- (void) initBackgroundHelperWithBaseURL: (NSString*)baseURL
                                clientId: (NSString*)clientId
                                cacheURL: (NSString*)cacheURL;
- (void)startInfoCollector;
- (void)stopInfoCollector;
- (void)startChannelScanner;
- (void)stopChannelScanner;
- (NSString*)getSelectedStreamId;
- (double)getSelectedStreamSize;
- (NSString*)getSelectedStreamQuality;
- (void)updateButtonsWithRecordingState:(BOOL)recordingState;
- (BOOL)checkQuality;
- (void)ignoreNextStreamInfo;
- (void)skip:(int)skipTime;
- (void)processHotKey:(NSEvent *)theEvent;
- (void)channelUp;
- (void)channelDown;
- (void)setOverlay:(int)overlayConstant;
- (IBAction)selectCurrentStream:(id)sender;
- (void)sortStreamsByColumn:(NSTableColumn*)sortColumn;
- (void)initStreamInfo;
- (NSString*)getURL:(NSString*)url;
- (void)importServerKeyForHost:(NSString*)host;
- (NSString *)getCurrentStreamId;
- (double)getCurrentStreamSize;
- (void)becameActive;
- (void)becameInactive;

@end
