//
//  CyTVClient.h
//  CyTV Client
//
//  Created by Andreas Junghans on Thu Aug 21 2003.
//  Copyright (c) 2003-2004 Andreas Junghans. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>


/**
 * A class that serves as a facade for AppleScript to use the net browser
 * functionality.
 */

@interface BrowserFacade : NSObject {
    NSNetServiceBrowser *_browser;
    NSMutableArray *_services;
    NSMutableDictionary *_servicesDict;
    int _toResolveUntilFinished;
    BOOL _searchingFinished;
}

- (NSArray *) resultsOfBrowsing;
- (void) stopBrowsing;

// NSNetServiceBrowser delegate methods
- (void)netServiceBrowserWillSearch:(NSNetServiceBrowser *)browser;
- (void)netServiceBrowserDidStopSearch:(NSNetServiceBrowser *)browser;
- (void)netServiceBrowser:(NSNetServiceBrowser *)browser
        didNotSearch:(NSDictionary *)errorDict;
- (void)netServiceBrowser:(NSNetServiceBrowser *)browser
        didFindService:(NSNetService *)aNetService
        moreComing:(BOOL)moreComing;
- (void)netServiceBrowser:(NSNetServiceBrowser *)browser
        didRemoveService:(NSNetService *)aNetService
        moreComing:(BOOL)moreComing;

// NSNetService delegate methods
- (void)netServiceDidResolveAddress:(NSNetService *)netService;
- (void)netService:(NSNetService *)netService
        didNotResolve:(NSDictionary *)errorDict;

@end


/**
 * This is an additional category for the NSApplication class to make
 * Objective-C methods easily callable from AppleScript (see also
 * MultiLanguage sample provided with AppleScript Studio).
 */

@interface NSApplication (CyTVClientInterface)

- (BrowserFacade *) startBrowsing;
- (NSString *) getAddressOfService: (NSNetService *) netService;
- (NSString *) getDisplayNameOfService: (NSNetService *) netService;
- (NSString *) loadPreference: (NSString*) key;
- (void) savePreference: (NSString*) key value: (NSString*) value;
- (int)loadIntPreference:(NSString*)key;
- (void)saveIntPreference:(NSString*)key value:(int)value;
- (int)findPortStartingWith:(int)startPort;
- (NSString*)getCyTVLogPath;
- (NSString*)getCyTVSupportPath;

@end
